]> www.ginac.de Git - ginac.git/blob - ginac/symbol.h
Standard header cleanup.
[ginac.git] / ginac / symbol.h
1 /** @file symbol.h
2  *
3  *  Interface to GiNaC's symbolic objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2015 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 "basic.h"
27 #include "ex.h"
28 #include "ptr.h"
29 #include "archive.h"
30
31 #include <string>
32 #include <typeinfo>
33
34 namespace GiNaC {
35
36 /** Basic CAS symbol.  It has a name because it must know how to output itself.
37  */
38 class symbol : public basic
39 {
40         GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
41         // other constructors
42 public:
43         explicit symbol(const std::string & initname);
44         symbol(const std::string & initname, const std::string & texname);
45         
46         // functions overriding virtual functions from base classes
47 public:
48         bool info(unsigned inf) const;
49         ex eval(int level = 0) const { return *this; } // for performance reasons
50         ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
51         ex series(const relational & s, int order, unsigned options = 0) const;
52         ex subs(const exmap & m, unsigned options = 0) const { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
53         ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
54         ex to_rational(exmap & repl) const;
55         ex to_polynomial(exmap & repl) const;
56         ex conjugate() const;
57         ex real_part() const;
58         ex imag_part() const;
59         bool is_polynomial(const ex & var) const;
60         /** Save (a.k.a. serialize) object into archive. */
61         void archive(archive_node& n) const;
62         /** Read (a.k.a. deserialize) object from archive. */
63         void read_archive(const archive_node& n, lst& syms);
64 protected:
65         ex derivative(const symbol & s) const;
66         bool is_equal_same_type(const basic & other) const;
67         unsigned calchash() const;
68         
69         // non-virtual functions in this class
70 public:
71         void set_name(const std::string & n) { name = n; }
72         void set_TeX_name(const std::string & n) { TeX_name = n; }
73         std::string get_name() const;
74         virtual unsigned get_domain() const { return domain::complex; }
75 protected:
76         void do_print(const print_context & c, unsigned level) const;
77         void do_print_latex(const print_latex & c, unsigned level) const;
78         void do_print_tree(const print_tree & c, unsigned level) const;
79         void do_print_python_repr(const print_python_repr & c, unsigned level) const;
80
81 // member variables
82
83 protected:
84         unsigned serial;                 ///< unique serial number for comparison
85         mutable std::string name;        ///< printname of this symbol
86         std::string TeX_name;            ///< LaTeX name of this symbol
87 private:
88         static unsigned next_serial;
89 };
90 GINAC_DECLARE_UNARCHIVER(symbol);
91
92
93 /** Specialization of symbol to real domain */
94 class realsymbol : public symbol
95 {
96 public:
97         realsymbol();
98         explicit realsymbol(const std::string & initname);
99         realsymbol(const std::string & initname, const std::string & texname);
100
101         unsigned get_domain() const { return domain::real; }
102
103         ex conjugate() const { return *this; }
104         ex real_part() const { return *this; }
105         ex imag_part() const { return 0; }
106
107         realsymbol* duplicate() const { return new realsymbol(*this); }
108 };
109 GINAC_DECLARE_UNARCHIVER(realsymbol);
110
111
112 /** Specialization of symbol to real positive domain */
113 class possymbol : public realsymbol
114 {
115 public:
116         possymbol();
117         explicit possymbol(const std::string & initname);
118         possymbol(const std::string & initname, const std::string & texname);
119
120         unsigned get_domain() const { return domain::positive; }
121
122         possymbol* duplicate() const { return new possymbol(*this); }
123 };
124 GINAC_DECLARE_UNARCHIVER(possymbol);
125
126 } // namespace GiNaC
127
128 #endif // ndef GINAC_SYMBOL_H