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 #ifndef NO_GINAC_NAMESPACE
32 #endif // ndef NO_GINAC_NAMESPACE
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
43 /** Symbols as keys to expressions. */
44 class assigned_ex_info {
46 assigned_ex_info(); //!< Default ctor
47 bool is_assigned; //!< True if there is an expression assigned
48 ex assigned_expression; //!< The actual expression
49 unsigned refcount; //!< Yet another refcounter. PLEASE EXPLAIN!
54 // default constructor, destructor, copy constructor assignment operator and helpers
58 symbol(symbol const & other);
60 void copy(symbol const & other);
61 void destroy(bool call_parent);
65 explicit symbol(string const & initname);
67 // functions overriding virtual functions from base classes
69 basic * duplicate() const;
70 void print(ostream & os, unsigned upper_precedence=0) const;
71 void printraw(ostream & os) const;
72 void printtree(ostream & os, unsigned indent) const;
73 void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
74 bool info(unsigned inf) const;
75 ex expand(unsigned options=0) const;
76 bool has(ex const & other) const;
77 int degree(symbol const & s) const;
78 int ldegree(symbol const & s) const;
79 ex coeff(symbol const & s, int const n = 1) const;
80 ex eval(int level = 0) const;
81 ex diff(symbol const & s) const;
82 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
83 ex subs(lst const & ls, lst const & lr) const;
85 int compare_same_type(basic const & other) const;
86 bool is_equal_same_type(basic const & other) const;
87 unsigned return_type(void) const;
88 unsigned return_type_tinfo(void) const;
89 unsigned calchash(void) const;
91 // non-virtual functions in this class
93 void assign(ex const & value);
95 ex diff(symbol const & s, unsigned nth) const;
96 void setname(string const & n) {name=n;}
97 string getname(void) const {return name;}
99 string & autoname_prefix(void);
104 assigned_ex_info * asexinfop;
105 unsigned serial; //!< unique serial number for comparision
108 static unsigned next_serial;
113 extern const symbol some_symbol;
114 extern type_info const & typeid_symbol;
117 inline const symbol &ex_to_symbol(const ex &e)
119 return static_cast<const symbol &>(*e.bp);
122 // wrapper functions around member functions
123 inline void unassign(symbol & symarg)
124 { return symarg.unassign(); }
126 inline int degree(symbol const & a, symbol const & s)
127 { return a.degree(s); }
129 inline int ldegree(symbol const & a, symbol const & s)
130 { return a.ldegree(s); }
132 #ifndef NO_GINAC_NAMESPACE
134 #endif // ndef NO_GINAC_NAMESPACE
136 #endif // ndef __GINAC_SYMBOL_H__