3 * Interface to GiNaC's symbolic objects. */
6 * GiNaC Copyright (C) 1999-2017 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
36 /** Basic CAS symbol. It has a name because it must know how to output itself.
38 class symbol : public basic
40 GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
43 explicit symbol(const std::string & initname);
44 symbol(const std::string & initname, const std::string & texname);
46 // functions overriding virtual functions from base classes
48 bool info(unsigned inf) const override;
49 ex eval() const override { return *this; } // for performance reasons
50 ex evalf() const override { return *this; } // overwrites basic::evalf() for performance reasons
51 ex series(const relational & s, int order, unsigned options = 0) const override;
52 ex subs(const exmap & m, unsigned options = 0) const override { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
53 ex normal(exmap & repl, exmap & rev_lookup) const override;
54 ex to_rational(exmap & repl) const override;
55 ex to_polynomial(exmap & repl) const override;
56 ex conjugate() const override;
57 ex real_part() const override;
58 ex imag_part() const override;
59 bool is_polynomial(const ex & var) const override;
60 /** Save (a.k.a. serialize) object into archive. */
61 void archive(archive_node& n) const override;
62 /** Read (a.k.a. deserialize) object from archive. */
63 void read_archive(const archive_node& n, lst& syms) override;
65 ex derivative(const symbol & s) const override;
66 bool is_equal_same_type(const basic & other) const override;
67 unsigned calchash() const override;
69 // new virtual functions which can be overridden by derived classes
71 virtual unsigned get_domain() const { return domain::complex; }
73 // non-virtual functions in this class
75 void set_name(const std::string & n) { name = n; }
76 void set_TeX_name(const std::string & n) { TeX_name = n; }
77 std::string get_name() const;
78 std::string get_TeX_name() const;
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;
88 unsigned serial; ///< unique serial number for comparison
89 mutable std::string name; ///< printname of this symbol
90 std::string TeX_name; ///< LaTeX name of this symbol
92 static unsigned next_serial;
94 GINAC_DECLARE_UNARCHIVER(symbol);
97 /** Specialization of symbol to real domain */
98 class realsymbol : public symbol
102 explicit realsymbol(const std::string & initname);
103 realsymbol(const std::string & initname, const std::string & texname);
105 unsigned get_domain() const override { return domain::real; }
107 ex conjugate() const override { return *this; }
108 ex real_part() const override { return *this; }
109 ex imag_part() const override { return 0; }
111 realsymbol* duplicate() const override
113 realsymbol * bp = new realsymbol(*this);
114 bp->setflag(status_flags::dynallocated);
118 GINAC_DECLARE_UNARCHIVER(realsymbol);
121 /** Specialization of symbol to real positive domain */
122 class possymbol : public realsymbol
126 explicit possymbol(const std::string & initname);
127 possymbol(const std::string & initname, const std::string & texname);
129 unsigned get_domain() const override { return domain::positive; }
131 possymbol* duplicate() const override
133 possymbol * bp = new possymbol(*this);
134 bp->setflag(status_flags::dynallocated);
138 GINAC_DECLARE_UNARCHIVER(possymbol);
142 #endif // ndef GINAC_SYMBOL_H