3 * Interface to GiNaC's light-weight expression handles.
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_EX_H__
23 #define __GINAC_EX_H__
34 typedef vector<ex> exvector;
38 ex const & exZERO(void);
39 ex const & exONE(void);
40 ex const & exTWO(void);
41 ex const & exTHREE(void);
42 ex const & exMINUSONE(void);
43 ex const & exHALF(void);
44 ex const & exMINUSHALF(void);
46 #define INLINE_EX_CONSTRUCTORS
48 /** Lightweight interface to GiNaC's symbolic objects. Basically all it does is
49 * to hold a pointer to the other objects, manage the reference counting and
50 * provide methods for manipulation of these objects. */
57 // default constructor, destructor, copy constructor assignment operator and helpers
60 #ifdef INLINE_EX_CONSTRUCTORS
63 debugmsg("ex default constructor",LOGLEVEL_CONSTRUCT);
64 ASSERT(exZERO().bp!=0);
65 ASSERT(exZERO().bp->flags & status_flags::dynallocated);
71 #endif // def INLINE_EX_CONSTRUCTORS
74 #ifdef INLINE_EX_CONSTRUCTORS
76 debugmsg("ex destructor",LOGLEVEL_DESTRUCT);
78 ASSERT(bp->flags & status_flags::dynallocated);
79 if (--bp->refcount == 0) {
85 #endif // def INLINE_EX_CONSTRUCTORS
88 #ifdef INLINE_EX_CONSTRUCTORS
91 debugmsg("ex copy constructor",LOGLEVEL_CONSTRUCT);
93 ASSERT((bp->flags) & status_flags::dynallocated);
98 #endif // def INLINE_EX_CONSTRUCTORS
100 ex const & operator=(ex const & other)
101 #ifdef INLINE_EX_CONSTRUCTORS
103 debugmsg("ex operator=",LOGLEVEL_ASSIGNMENT);
105 ASSERT(bp->flags & status_flags::dynallocated);
107 ASSERT(other.bp->flags & status_flags::dynallocated);
108 ++other.bp->refcount;
109 basic * tmpbp=other.bp;
110 if (--bp->refcount==0) {
118 #endif // def INLINE_EX_CONSTRUCTORS
120 // other constructors
122 ex(basic const & other)
123 #ifdef INLINE_EX_CONSTRUCTORS
125 debugmsg("ex constructor from basic",LOGLEVEL_CONSTRUCT);
126 construct_from_basic(other);
130 #endif // def INLINE_EX_CONSTRUCTORS
133 ex(unsigned int const i);
135 ex(unsigned long const i);
138 // functions overriding virtual functions from bases classes
141 // new virtual functions which can be overridden by derived classes
144 // non-virtual functions in this class
146 void swap(ex & other);
147 void printraw(ostream & os) const;
148 void printtree(ostream & os, unsigned indent=0) const;
149 void print(ostream & os, unsigned upper_precedence=0) const;
150 void printcsrc(ostream & os, unsigned type, const char *var_name) const;
151 void dbgprint(void) const;
152 void dbgprinttree(void) const;
153 bool info(unsigned inf) const;
155 ex expand(unsigned options=0) const;
156 bool has(ex const & other) const;
157 int degree(symbol const & s) const;
158 int ldegree(symbol const & s) const;
159 ex coeff(symbol const & s, int const n=1) const;
160 ex lcoeff(symbol const & s) const { return coeff(s, degree(s)); }
161 ex tcoeff(symbol const & s) const { return coeff(s, ldegree(s)); }
162 ex numer(bool normalize = true) const;
163 ex denom(bool normalize = true) const;
164 ex unit(const symbol &x) const;
165 ex content(const symbol &x) const;
166 numeric integer_content(void) const;
167 ex primpart(const symbol &x) const;
168 ex primpart(const symbol &x, const ex &cont) const;
169 ex normal(int level = 0) const;
170 ex smod(const numeric &xi) const;
171 numeric max_coefficient(void) const;
172 ex collect(symbol const & s) const;
173 ex eval(int level = 0) const;
174 ex evalf(int level = 0) const;
175 ex diff(symbol const & s, unsigned nth = 1) const;
176 ex series(symbol const & s, ex const & point, int order = 6) const;
177 ex subs(lst const & ls, lst const & lr) const;
178 ex subs(ex const & e) const;
179 exvector get_indices(void) const;
180 ex simplify_ncmul(exvector const & v) const;
181 ex operator[](ex const & index) const;
182 ex operator[](int const i) const;
183 ex op(int const i) const;
184 ex & let_op(int const i);
185 int compare(ex const & other) const
186 #ifdef INLINE_EX_CONSTRUCTORS
191 // special case: both expression point to same basic, trivially equal
194 return bp->compare(*other.bp);
198 #endif // def INLINE_EX_CONSTRUCTORS
199 bool is_equal(ex const & other) const
200 #ifdef INLINE_EX_CONSTRUCTORS
205 // special case: both expression point to same basic, trivially equal
208 return bp->is_equal(*other.bp);
212 #endif // def INLINE_EX_CONSTRUCTORS
213 bool is_zero(void) const {return compare(exZERO()) == 0;};
215 unsigned return_type(void) const;
216 unsigned return_type_tinfo(void) const;
217 unsigned gethash(void) const;
219 ex exadd(ex const & rh) const;
220 ex exmul(ex const & rh) const;
221 ex exncmul(ex const & rh) const;
223 void construct_from_basic(basic const & other);
224 void makewriteable();
233 // wrapper functions around member functions
234 inline int nops(ex const & thisex)
235 { return thisex.nops(); }
237 inline ex expand(ex const & thisex, unsigned options = 0)
238 { return thisex.expand(options); }
240 inline bool has(ex const & thisex, ex const & other)
241 { return thisex.has(other); }
243 inline int degree(ex const & thisex, symbol const & s)
244 { return thisex.degree(s); }
246 inline int ldegree(ex const & thisex, symbol const & s)
247 { return thisex.ldegree(s); }
249 inline ex coeff(ex const & thisex, symbol const & s, int const n=1)
250 { return thisex.coeff(s, n); }
252 inline ex numer(ex const & thisex, bool normalize = true)
253 { return thisex.numer(normalize); }
255 inline ex denom(ex const & thisex, bool normalize = true)
256 { return thisex.denom(normalize); }
258 inline ex normal(ex const & thisex, int level=0)
259 { return thisex.normal(level); }
261 inline ex collect(ex const & thisex, symbol const & s)
262 { return thisex.collect(s); }
264 inline ex eval(ex const & thisex, int level = 0)
265 { return thisex.eval(level); }
267 inline ex evalf(ex const & thisex, int level = 0)
268 { return thisex.evalf(level); }
270 inline ex diff(ex const & thisex, symbol const & s, unsigned nth = 1)
271 { return thisex.diff(s, nth); }
273 inline ex subs(ex const & thisex, ex const & e)
274 { return thisex.subs(e); }
276 inline ex subs(ex const & thisex, lst const & ls, lst const & lr)
277 { return thisex.subs(ls, lr); }
279 inline void swap(ex & e1, ex & e2)
282 #endif // ndef __GINAC_EX_H__