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>
32 /** Basic CAS symbol. It has a name because it must know how to output itself.
33 * It may be assigned an expression, but this feature is only intended for
34 * programs like 'ginsh' that want to associate symbols with expressions.
35 * If you want to replace symbols by expressions in your code, you should
36 * use ex::subs() or use objects of class ex instead of class symbol in the
38 class symbol : public basic
41 /** Symbols as keys to expressions. */
42 class assigned_ex_info {
44 assigned_ex_info(); //!< Default ctor
45 bool is_assigned; //!< True if there is an expression assigned
46 ex assigned_expression; //!< The actual expression
47 unsigned refcount; //!< Yet another refcounter. PLEASE EXPLAIN!
52 // default constructor, destructor, copy constructor assignment operator and helpers
56 symbol(symbol const & other);
58 void copy(symbol const & other);
59 void destroy(bool call_parent);
63 explicit symbol(string const & initname);
65 // functions overriding virtual functions from base classes
67 basic * duplicate() const;
68 void printraw(ostream & os) const;
69 void printtree(ostream & os, unsigned indent) const;
70 void print(ostream & os, unsigned upper_precedence=0) const;
71 void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
72 bool info(unsigned inf) const;
73 ex expand(unsigned options=0) const;
74 bool has(ex const & other) const;
75 int degree(symbol const & s) const;
76 int ldegree(symbol const & s) const;
77 ex coeff(symbol const & s, int const n = 1) const;
78 ex eval(int level = 0) const;
79 ex diff(symbol const & s) const;
80 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
81 ex subs(lst const & ls, lst const & lr) const;
83 int compare_same_type(basic const & other) const;
84 bool is_equal_same_type(basic const & other) const;
85 unsigned return_type(void) const;
86 unsigned return_type_tinfo(void) const;
87 unsigned calchash(void) const;
89 // non-virtual functions in this class
91 void assign(ex const & value);
93 ex diff(symbol const & s, unsigned nth) const;
94 void setname(string const & n) {name=n;}
95 string getname(void) const {return name;}
97 string & autoname_prefix(void);
102 assigned_ex_info * asexinfop;
103 unsigned serial; //!< unique serial number for comparision
106 static unsigned next_serial;
111 extern const symbol some_symbol;
112 extern type_info const & typeid_symbol;
115 inline const symbol &ex_to_symbol(const ex &e)
117 return static_cast<const symbol &>(*e.bp);
120 // wrapper functions around member functions
121 inline void unassign(symbol & symarg)
122 { return symarg.unassign(); }
124 inline int degree(symbol const & a, symbol const & s)
125 { return a.degree(s); }
127 inline int ldegree(symbol const & a, symbol const & s)
128 { return a.ldegree(s); }
132 #endif // ndef __GINAC_SYMBOL_H__