3 * Interface to GiNaC's symbolic objects. */
6 * GiNaC Copyright (C) 1999 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__
27 #include <ginac/basic.h>
30 /** Basic CAS symbol. It has a name because it must know how to output itself.
31 * It may be assigned an expression, but this feature is only intended for
32 * programs like 'ginsh' that want to associate symbols with expressions.
33 * If you want to replace symbols by expressions in your code, you should
34 * use ex::subs() or use objects of class ex instead of class symbol in the
36 class symbol : public basic
39 /** Symbols as keys to expressions. */
40 class assigned_ex_info {
42 assigned_ex_info(); //!< Default ctor
43 bool is_assigned; //!< True if there is an expression assigned
44 ex assigned_expression; //!< The actual expression
45 unsigned refcount; //!< Yet another refcounter. PLEASE EXPLAIN!
50 // default constructor, destructor, copy constructor assignment operator and helpers
54 symbol(symbol const & other);
56 void copy(symbol const & other);
57 void destroy(bool call_parent);
61 explicit symbol(string const & initname);
63 // functions overriding virtual functions from base classes
65 basic * duplicate() const;
66 void printraw(ostream & os) const;
67 void printtree(ostream & os, unsigned indent) const;
68 void print(ostream & os, unsigned upper_precedence=0) const;
69 void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
70 bool info(unsigned inf) const;
71 ex expand(unsigned options=0) const;
72 bool has(ex const & other) const;
73 int degree(symbol const & s) const;
74 int ldegree(symbol const & s) const;
75 ex coeff(symbol const & s, int const n = 1) const;
76 ex eval(int level = 0) const;
77 ex diff(symbol const & s) const;
78 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
79 ex subs(lst const & ls, lst const & lr) const;
81 int compare_same_type(basic const & other) const;
82 bool is_equal_same_type(basic const & other) const;
83 unsigned return_type(void) const;
84 unsigned return_type_tinfo(void) const;
85 unsigned calchash(void) const;
87 // non-virtual functions in this class
89 void assign(ex const & value);
91 ex diff(symbol const & s, unsigned nth) const;
92 void setname(string const & n) {name=n;}
93 string getname(void) const {return name;}
95 string & autoname_prefix(void);
100 assigned_ex_info * asexinfop;
101 unsigned serial; //!< unique serial number for comparision
104 static unsigned next_serial;
109 extern const symbol some_symbol;
110 extern type_info const & typeid_symbol;
114 #define ex_to_symbol(X) static_cast<symbol const &>(*(X).bp)
116 // wrapper functions around member functions
117 inline void unassign(symbol & symarg)
118 { return symarg.unassign(); }
120 inline int degree(symbol const & a, symbol const & s)
121 { return a.degree(s); }
123 inline int ldegree(symbol const & a, symbol const & s)
124 { return a.ldegree(s); }
126 #endif // ndef __GINAC_SYMBOL_H__