3 * Interface to GiNaC's symbolic objects. */
15 /** Basic CAS symbol. It has a name because it must know how to output itself.
16 * It may be assigned an expression, but this feature is only intended for
17 * programs like 'ginsh' that want to associate symbols with expressions.
18 * If you want to replace symbols by expressions in your code, you should
19 * use ex::subs() or use objects of class ex instead of class symbol in the
21 class symbol : public basic
24 /** Symbols as keys to expressions. */
25 class assigned_ex_info {
27 assigned_ex_info(); //!< Default ctor
28 bool is_assigned; //!< True if there is an expression assigned
29 ex assigned_expression; //!< The actual expression
30 unsigned refcount; //!< Yet another refcounter. PLEASE EXPLAIN!
35 // default constructor, destructor, copy constructor assignment operator and helpers
39 symbol(symbol const & other);
41 void copy(symbol const & other);
42 void destroy(bool call_parent);
46 explicit symbol(string const & initname);
48 // functions overriding virtual functions from base classes
50 basic * duplicate() const;
51 void printraw(ostream & os) const;
52 void printtree(ostream & os, unsigned indent) const;
53 void print(ostream & os, unsigned upper_precedence=0) const;
54 void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
55 bool info(unsigned inf) const;
56 ex expand(unsigned options=0) const;
57 bool has(ex const & other) const;
58 int degree(symbol const & s) const;
59 int ldegree(symbol const & s) const;
60 ex coeff(symbol const & s, int const n = 1) const;
61 ex eval(int level = 0) const;
62 ex diff(symbol const & s) const;
63 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
64 ex subs(lst const & ls, lst const & lr) const;
66 int compare_same_type(basic const & other) const;
67 bool is_equal_same_type(basic const & other) const;
68 unsigned return_type(void) const;
69 unsigned return_type_tinfo(void) const;
70 unsigned calchash(void) const;
72 // non-virtual functions in this class
74 void assign(ex const & value);
76 ex diff(symbol const & s, unsigned nth) const;
77 void setname(string const & n) {name=n;}
78 string getname(void) const {return name;}
80 string & autoname_prefix(void);
85 assigned_ex_info * asexinfop;
86 unsigned serial; //!< unique serial number for comparision
89 static unsigned next_serial;
94 extern const symbol some_symbol;
95 extern type_info const & typeid_symbol;
99 #define ex_to_symbol(X) static_cast<symbol const &>(*(X).bp)
101 // wrapper functions around member functions
102 inline void unassign(symbol & symarg)
103 { return symarg.unassign(); }
105 inline int degree(symbol const & a, symbol const & s)
106 { return a.degree(s); }
108 inline int ldegree(symbol const & a, symbol const & s)
109 { return a.ldegree(s); }
111 #endif // ndef _SYMBOL_H_