3 * Interface to GiNaC's symbolic objects.
5 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef __GINAC_SYMBOL_H__
23 #define __GINAC_SYMBOL_H__
27 /** Basic CAS symbol. It has a name because it must know how to output itself.
28 * It may be assigned an expression, but this feature is only intended for
29 * programs like 'ginsh' that want to associate symbols with expressions.
30 * If you want to replace symbols by expressions in your code, you should
31 * use ex::subs() or use objects of class ex instead of class symbol in the
33 class symbol : public basic
36 /** Symbols as keys to expressions. */
37 class assigned_ex_info {
39 assigned_ex_info(); //!< Default ctor
40 bool is_assigned; //!< True if there is an expression assigned
41 ex assigned_expression; //!< The actual expression
42 unsigned refcount; //!< Yet another refcounter. PLEASE EXPLAIN!
47 // default constructor, destructor, copy constructor assignment operator and helpers
51 symbol(symbol const & other);
53 void copy(symbol const & other);
54 void destroy(bool call_parent);
58 explicit symbol(string const & initname);
60 // functions overriding virtual functions from base classes
62 basic * duplicate() const;
63 void printraw(ostream & os) const;
64 void printtree(ostream & os, unsigned indent) const;
65 void print(ostream & os, unsigned upper_precedence=0) const;
66 void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
67 bool info(unsigned inf) const;
68 ex expand(unsigned options=0) const;
69 bool has(ex const & other) const;
70 int degree(symbol const & s) const;
71 int ldegree(symbol const & s) const;
72 ex coeff(symbol const & s, int const n = 1) const;
73 ex eval(int level = 0) const;
74 ex diff(symbol const & s) const;
75 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
76 ex subs(lst const & ls, lst const & lr) const;
78 int compare_same_type(basic const & other) const;
79 bool is_equal_same_type(basic const & other) const;
80 unsigned return_type(void) const;
81 unsigned return_type_tinfo(void) const;
82 unsigned calchash(void) const;
84 // non-virtual functions in this class
86 void assign(ex const & value);
88 ex diff(symbol const & s, unsigned nth) const;
89 void setname(string const & n) {name=n;}
90 string getname(void) const {return name;}
92 string & autoname_prefix(void);
97 assigned_ex_info * asexinfop;
98 unsigned serial; //!< unique serial number for comparision
101 static unsigned next_serial;
106 extern const symbol some_symbol;
107 extern type_info const & typeid_symbol;
111 #define ex_to_symbol(X) static_cast<symbol const &>(*(X).bp)
113 // wrapper functions around member functions
114 inline void unassign(symbol & symarg)
115 { return symarg.unassign(); }
117 inline int degree(symbol const & a, symbol const & s)
118 { return a.degree(s); }
120 inline int ldegree(symbol const & a, symbol const & s)
121 { return a.ldegree(s); }
123 #endif // ndef __GINAC_SYMBOL_H__