3 * Interface to GiNaC's symbolic objects. */
6 * GiNaC Copyright (C) 1999-2000 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__
30 #ifndef NO_NAMESPACE_GINAC
32 #endif // ndef NO_NAMESPACE_GINAC
34 /** Basic CAS symbol. It has a name because it must know how to output itself.
35 * It may be assigned an expression, but this feature is only intended for
36 * programs like 'ginsh' that want to associate symbols with expressions.
37 * If you want to replace symbols by expressions in your code, you should
38 * use ex::subs() or use objects of class ex instead of class symbol in the
40 class symbol : public basic
42 GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
46 /** Symbols as keys to expressions. */
47 class 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
52 unsigned refcount; //!< Yet another refcounter. PLEASE EXPLAIN!
57 // default constructor, destructor, copy constructor assignment operator and helpers
61 symbol(const symbol & other);
63 void copy(const symbol & other);
64 void destroy(bool call_parent);
68 explicit symbol(const string & initname);
70 // functions overriding virtual functions from base classes
72 basic * duplicate() const;
73 void print(ostream & os, unsigned upper_precedence=0) const;
74 void printraw(ostream & os) const;
75 void printtree(ostream & os, unsigned indent) const;
76 void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
77 bool info(unsigned inf) const;
78 ex expand(unsigned options=0) const;
79 bool has(const ex & other) const;
80 int degree(const symbol & s) const;
81 int ldegree(const symbol & s) const;
82 ex coeff(const symbol & s, int n = 1) const;
83 ex eval(int level = 0) const;
84 ex series(const relational & s, int order) const;
85 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
86 ex to_rational(lst &repl_lst) const;
87 ex subs(const lst & ls, const lst & lr) const;
89 ex derivative(const symbol & s) const;
90 int compare_same_type(const basic & other) const;
91 bool is_equal_same_type(const basic & other) const;
92 unsigned return_type(void) const;
93 unsigned return_type_tinfo(void) const;
94 unsigned calchash(void) const;
96 // non-virtual functions in this class
98 void assign(const ex & value);
100 void setname(const string & n) {name=n;}
101 string getname(void) const {return name;}
103 string & autoname_prefix(void);
108 assigned_ex_info * asexinfop;
109 unsigned serial; //!< unique serial number for comparision
112 static unsigned next_serial;
117 extern const symbol some_symbol;
118 extern const type_info & typeid_symbol;
121 inline const symbol &ex_to_symbol(const ex &e)
123 return static_cast<const symbol &>(*e.bp);
126 // wrapper functions around member functions
127 inline void unassign(symbol & symarg)
128 { return symarg.unassign(); }
130 inline int degree(const symbol & a, const symbol & s)
131 { return a.degree(s); }
133 inline int ldegree(const symbol & a, const symbol & s)
134 { return a.ldegree(s); }
136 #ifndef NO_NAMESPACE_GINAC
138 #endif // ndef NO_NAMESPACE_GINAC
140 #endif // ndef __GINAC_SYMBOL_H__