]> www.ginac.de Git - ginac.git/blob - ginac/symbol.h
Implement modular multivariate GCD (based on chinese remaindering algorithm).
[ginac.git] / ginac / symbol.h
1 /** @file symbol.h
2  *
3  *  Interface to GiNaC's symbolic objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef __GINAC_SYMBOL_H__
24 #define __GINAC_SYMBOL_H__
25
26 #include <string>
27 #include <typeinfo>
28 #include "basic.h"
29 #include "ex.h"
30 #include "ptr.h"
31 #include "archive.h"
32
33 namespace GiNaC {
34
35 /** Basic CAS symbol.  It has a name because it must know how to output itself.
36  */
37 class symbol : public basic
38 {
39         GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
40         // other constructors
41 public:
42         explicit symbol(const std::string & initname);
43         symbol(const std::string & initname, const std::string & texname);
44         
45         // functions overriding virtual functions from base classes
46 public:
47         bool info(unsigned inf) const;
48         ex eval(int level = 0) const { return *this; } // for performance reasons
49         ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
50         ex series(const relational & s, int order, unsigned options = 0) const;
51         ex subs(const exmap & m, unsigned options = 0) const { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
52         ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
53         ex to_rational(exmap & repl) const;
54         ex to_polynomial(exmap & repl) const;
55         ex conjugate() const;
56         ex real_part() const;
57         ex imag_part() const;
58         bool is_polynomial(const ex & var) const;
59         /** Save (a.k.a. serialize) object into archive. */
60         void archive(archive_node& n) const;
61         /** Read (a.k.a. deserialize) object from archive. */
62         void read_archive(const archive_node& n, lst& syms);
63 protected:
64         ex derivative(const symbol & s) const;
65         bool is_equal_same_type(const basic & other) const;
66         unsigned calchash() const;
67         
68         // non-virtual functions in this class
69 public:
70         void set_name(const std::string & n) { name = n; }
71         std::string get_name() const { return name; }
72         virtual unsigned get_domain() const { return domain::complex; }
73 protected:
74         void do_print(const print_context & c, unsigned level) const;
75         void do_print_latex(const print_latex & c, unsigned level) const;
76         void do_print_tree(const print_tree & c, unsigned level) const;
77         void do_print_python_repr(const print_python_repr & c, unsigned level) const;
78
79 // member variables
80
81 protected:
82         unsigned serial;                 ///< unique serial number for comparison
83         std::string name;                ///< printname of this symbol
84         std::string TeX_name;            ///< LaTeX name of this symbol
85 private:
86         static unsigned next_serial;
87 };
88 GINAC_DECLARE_UNARCHIVER(symbol);
89
90
91 /** Specialization of symbol to real domain */
92 class realsymbol : public symbol
93 {
94 public:
95         realsymbol();
96         explicit realsymbol(const std::string & initname);
97         realsymbol(const std::string & initname, const std::string & texname);
98
99         unsigned get_domain() const { return domain::real; }
100
101         ex conjugate() const { return *this; }
102         ex real_part() const { return *this; }
103         ex imag_part() const { return 0; }
104
105         realsymbol* duplicate() const { return new realsymbol(*this); }
106 };
107 GINAC_DECLARE_UNARCHIVER(realsymbol);
108
109
110 /** Specialization of symbol to real domain */
111 class possymbol : public realsymbol
112 {
113 public:
114         possymbol();
115         explicit possymbol(const std::string & initname);
116         possymbol(const std::string & initname, const std::string & texname);
117
118         unsigned get_domain() const { return domain::positive; }
119
120         possymbol* duplicate() const { return new possymbol(*this); }
121 };
122 GINAC_DECLARE_UNARCHIVER(possymbol);
123
124 } // namespace GiNaC
125
126 #endif // ndef __GINAC_SYMBOL_H__