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