3 * Interface to GiNaC's symbolic objects. */
6 * GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
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.
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.
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
23 #ifndef __GINAC_SYMBOL_H__
24 #define __GINAC_SYMBOL_H__
34 /** Basic CAS symbol. It has a name because it must know how to output itself.
36 class symbol : public basic
38 GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
40 friend class realsymbol;
41 friend class possymbol;
47 explicit symbol(const std::string & initname, unsigned domain = domain::complex);
48 symbol(const std::string & initname, const std::string & texname, unsigned domain = domain::complex);
49 symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned domain);
50 symbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::complex);
51 symbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::complex);
53 // functions overriding virtual functions from base classes
55 bool info(unsigned inf) const;
56 ex eval(int level = 0) const { return *this; } // for performance reasons
57 ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
58 ex series(const relational & s, int order, unsigned options = 0) const;
59 ex subs(const exmap & m, unsigned options = 0) const { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
60 ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
61 ex to_rational(exmap & repl) const;
62 ex to_polynomial(exmap & repl) const;
63 unsigned return_type() const { return ret_type; }
64 tinfo_t return_type_tinfo() const { return ret_type_tinfo; }
68 bool is_polynomial(const ex & var) const;
70 ex derivative(const symbol & s) const;
71 bool is_equal_same_type(const basic & other) const;
72 unsigned calchash() const;
74 // non-virtual functions in this class
76 void set_name(const std::string & n) { name = n; }
77 std::string get_name() const { return name; }
78 unsigned get_domain() const { return domain; }
80 void do_print(const print_context & c, unsigned level) const;
81 void do_print_latex(const print_latex & c, unsigned level) const;
82 void do_print_tree(const print_tree & c, unsigned level) const;
83 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
85 std::string & autoname_prefix();
86 std::string default_TeX_name() const;
91 unsigned serial; ///< unique serial number for comparison
92 std::string name; ///< printname of this symbol
93 std::string TeX_name; ///< LaTeX name of this symbol
94 unsigned domain; ///< domain of symbol, complex (default) or real
95 unsigned ret_type; ///< value returned by return_type()
96 tinfo_t ret_type_tinfo; ///< value returned by return_type_tinfo()
98 static unsigned next_serial;
102 /** Specialization of symbol to real domain */
103 class realsymbol : public symbol
108 explicit realsymbol(const std::string & initname, unsigned domain = domain::real);
109 realsymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::real);
110 realsymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::real);
111 realsymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::real);
115 /** Specialization of symbol to real domain */
116 class possymbol : public symbol
121 explicit possymbol(const std::string & initname, unsigned domain = domain::positive);
122 possymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::positive);
123 possymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::positive);
124 possymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::positive);
130 /** Specialization of is_exactly_a<realsymbol>(obj) for realsymbol objects. */
131 template<> inline bool is_exactly_a<realsymbol>(const basic & obj)
133 if (!is_a<symbol>(obj))
135 unsigned domain = static_cast<const symbol &>(obj).get_domain();
136 return domain==domain::real || domain==domain::positive;
139 /** Specialization of is_exactly_a<possymbol>(obj) for possymbol objects. */
140 template<> inline bool is_exactly_a<possymbol>(const basic & obj)
142 if (!is_a<symbol>(obj))
144 unsigned domain = static_cast<const symbol &>(obj).get_domain();
145 return domain == domain::positive;
150 #endif // ndef __GINAC_SYMBOL_H__