3 * Interface to GiNaC's symbolic objects. */
6 * GiNaC Copyright (C) 1999-2002 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__
32 /** Basic CAS symbol. It has a name because it must know how to output itself.
33 * It may be assigned an expression, but this feature is only intended for
34 * programs like 'ginsh' that want to associate symbols with expressions.
35 * If you want to replace symbols by expressions in your code, you should
36 * use ex::subs() or use objects of class ex instead of class symbol in the
38 class symbol : public basic
40 GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(symbol, basic)
44 /** Symbols as keys to expressions - this is deprecated. */
45 class assigned_ex_info {
47 assigned_ex_info(); ///< Default ctor
48 bool is_assigned; ///< True if there is an expression assigned
49 ex assigned_expression; ///< The actual expression
50 unsigned refcount; ///< Reference counter
55 // default ctor, dtor, copy ctor, assignment operator and helpers
58 ~symbol() { destroy(false); }
59 symbol(const symbol & other);
61 void copy(const symbol & other);
62 void destroy(bool call_parent);
66 explicit symbol(const std::string & initname);
67 explicit symbol(const std::string & initname, const std::string & texname);
69 // functions overriding virtual functions from base classes
71 basic * duplicate() const;
72 void print(const print_context & c, unsigned level = 0) const;
73 bool info(unsigned inf) const;
74 ex eval(int level = 0) const;
75 ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
76 ex series(const relational & s, int order, unsigned options = 0) const;
77 ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
78 ex to_rational(lst &repl_lst) const;
80 ex derivative(const symbol & s) const;
81 int compare_same_type(const basic & other) const;
82 bool is_equal_same_type(const basic & other) const;
83 unsigned calchash(void) const;
85 // non-virtual functions in this class
87 void assign(const ex & value);
89 void set_name(const std::string & n) { name = n; }
90 std::string get_name(void) const { return name; }
92 std::string & autoname_prefix(void);
93 std::string default_TeX_name(void) const;
98 assigned_ex_info * asexinfop; ///< ptr to assigned expression, deprecated
99 unsigned serial; ///< unique serial number for comparison
100 std::string name; ///< printname of this symbol
101 std::string TeX_name; ///< LaTeX name of this symbol
103 static unsigned next_serial;
109 /** Specialization of is_exactly_a<symbol>(obj) for symbol objects. */
110 template<> inline bool is_exactly_a<symbol>(const basic & obj)
112 return obj.tinfo()==TINFO_symbol;
115 // wrapper functions around member functions
116 inline void unassign(symbol & symarg)
117 { symarg.unassign(); }
119 inline int degree(const symbol & a, const ex & s)
120 { return a.degree(s); }
122 inline int ldegree(const symbol & a, const ex & s)
123 { return a.ldegree(s); }
127 #endif // ndef __GINAC_SYMBOL_H__