3 * Interface to GiNaC's symbolic objects. */
6 * GiNaC Copyright (C) 1999-2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef __GINAC_SYMBOL_H__
24 #define __GINAC_SYMBOL_H__
33 /** Basic CAS symbol. It has a name because it must know how to output itself.
34 * It may be assigned an expression, but this feature is only intended for
35 * programs like 'ginsh' that want to associate symbols with expressions.
36 * If you want to replace symbols by expressions in your code, you should
37 * use ex::subs() or use objects of class ex instead of class symbol in the
39 class symbol : public basic
41 GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
45 /** Symbols as keys to expressions - only for ginsh. */
46 class assigned_ex_info {
47 friend class ptr<assigned_ex_info>;
49 assigned_ex_info(); ///< Default ctor
50 bool is_assigned; ///< True if there is an expression assigned
51 ex assigned_expression; ///< The actual expression
53 size_t refcount; ///< Reference counter, managed by ptr<assigned_ex_info>
60 explicit symbol(const std::string & initname);
61 explicit symbol(const std::string & initname, const std::string & texname);
63 // functions overriding virtual functions from base classes
65 void print(const print_context & c, unsigned level = 0) const;
66 bool info(unsigned inf) const;
67 ex eval(int level = 0) const;
68 ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
69 ex series(const relational & s, int order, unsigned options = 0) const;
70 ex subs(const exmap & m, unsigned options = 0) const { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
71 ex normal(exmap & repl, int level = 0) const;
72 ex to_rational(lst &repl_lst) const;
73 ex to_polynomial(lst &repl_lst) const;
75 ex derivative(const symbol & s) const;
76 bool is_equal_same_type(const basic & other) const;
77 unsigned calchash() const;
79 // non-virtual functions in this class
81 void assign(const ex & value);
83 void set_name(const std::string & n) { name = n; }
84 std::string get_name() const { return name; }
86 std::string & autoname_prefix();
87 std::string default_TeX_name() const;
92 ptr<assigned_ex_info> asexinfop; ///< assigned expression, only for private use by ginsh
93 unsigned serial; ///< unique serial number for comparison
94 std::string name; ///< printname of this symbol
95 std::string TeX_name; ///< LaTeX name of this symbol
97 static unsigned next_serial;
103 /** Specialization of is_exactly_a<symbol>(obj) for symbol objects. */
104 template<> inline bool is_exactly_a<symbol>(const basic & obj)
106 return obj.tinfo()==TINFO_symbol;
109 // wrapper functions around member functions
110 inline void unassign(symbol & symarg)
111 { symarg.unassign(); }
113 inline int degree(const symbol & a, const ex & s)
114 { return a.degree(s); }
116 inline int ldegree(const symbol & a, const ex & s)
117 { return a.ldegree(s); }
121 #endif // ndef __GINAC_SYMBOL_H__