3 * Interface to GiNaC's light-weight expression handles. */
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_EX_H__
24 #define __GINAC_EX_H__
27 #include <ginac/basic.h>
28 #include <ginac/operators.h>
30 #ifndef NO_GINAC_NAMESPACE
32 #endif // ndef NO_GINAC_NAMESPACE
41 // typedef vector<ex> exvector;
45 ex const & exZERO(void);
46 ex const & exONE(void);
47 ex const & exTWO(void);
48 ex const & exTHREE(void);
49 ex const & exMINUSONE(void);
50 ex const & exHALF(void);
51 ex const & exMINUSHALF(void);
53 #define INLINE_EX_CONSTRUCTORS
55 /** Lightweight interface to GiNaC's symbolic objects. Basically all it does is
56 * to hold a pointer to the other objects, manage the reference counting and
57 * provide methods for manipulation of these objects. */
64 // default constructor, destructor, copy constructor assignment operator and helpers
67 #ifdef INLINE_EX_CONSTRUCTORS
70 GINAC_ASSERT(exZERO().bp!=0);
71 GINAC_ASSERT(exZERO().bp->flags & status_flags::dynallocated);
77 #endif // def INLINE_EX_CONSTRUCTORS
80 #ifdef INLINE_EX_CONSTRUCTORS
83 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
84 if (--bp->refcount == 0) {
90 #endif // def INLINE_EX_CONSTRUCTORS
93 #ifdef INLINE_EX_CONSTRUCTORS
97 GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
102 #endif // def INLINE_EX_CONSTRUCTORS
104 ex const & operator=(ex const & other)
105 #ifdef INLINE_EX_CONSTRUCTORS
108 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
109 GINAC_ASSERT(other.bp!=0);
110 GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
111 ++other.bp->refcount;
112 basic * tmpbp=other.bp;
113 if (--bp->refcount==0) {
121 #endif // def INLINE_EX_CONSTRUCTORS
123 // other constructors
125 ex(basic const & other)
126 #ifdef INLINE_EX_CONSTRUCTORS
128 construct_from_basic(other);
132 #endif // def INLINE_EX_CONSTRUCTORS
135 ex(unsigned int const i);
137 ex(unsigned long const i);
140 // functions overriding virtual functions from bases classes
143 // new virtual functions which can be overridden by derived classes
146 // non-virtual functions in this class
148 void swap(ex & other);
149 void printraw(ostream & os) const;
150 void printtree(ostream & os, unsigned indent=0) const;
151 void print(ostream & os, unsigned upper_precedence=0) const;
152 void printcsrc(ostream & os, unsigned type, const char *var_name) const;
153 void dbgprint(void) const;
154 void dbgprinttree(void) const;
155 bool info(unsigned inf) const;
157 ex expand(unsigned options=0) const;
158 bool has(ex const & other) const;
159 int degree(symbol const & s) const;
160 int ldegree(symbol const & s) const;
161 ex coeff(symbol const & s, int const n=1) const;
162 ex lcoeff(symbol const & s) const { return coeff(s, degree(s)); }
163 ex tcoeff(symbol const & s) const { return coeff(s, ldegree(s)); }
164 ex numer(bool normalize = true) const;
165 ex denom(bool normalize = true) const;
166 ex unit(const symbol &x) const;
167 ex content(const symbol &x) const;
168 numeric integer_content(void) const;
169 ex primpart(const symbol &x) const;
170 ex primpart(const symbol &x, const ex &cont) const;
171 ex normal(int level = 0) const;
172 ex smod(const numeric &xi) const;
173 numeric max_coefficient(void) const;
174 ex collect(symbol const & s) const;
175 ex eval(int level = 0) const;
176 ex evalf(int level = 0) const;
177 ex diff(symbol const & s, unsigned nth = 1) const;
178 ex series(symbol const & s, ex const & point, int order = 6) const;
179 ex subs(lst const & ls, lst const & lr) const;
180 ex subs(ex const & e) const;
181 exvector get_indices(void) const;
182 ex simplify_ncmul(exvector const & v) const;
183 ex operator[](ex const & index) const;
184 ex operator[](int const i) const;
185 ex op(int const i) const;
186 ex & let_op(int const i);
187 int compare(ex const & other) const
188 #ifdef INLINE_EX_CONSTRUCTORS
191 GINAC_ASSERT(other.bp!=0);
193 // special case: both expression point to same basic, trivially equal
196 return bp->compare(*other.bp);
200 #endif // def INLINE_EX_CONSTRUCTORS
201 bool is_equal(ex const & other) const
202 #ifdef INLINE_EX_CONSTRUCTORS
205 GINAC_ASSERT(other.bp!=0);
207 // special case: both expression point to same basic, trivially equal
210 return bp->is_equal(*other.bp);
214 #endif // def INLINE_EX_CONSTRUCTORS
215 bool is_zero(void) const {return compare(exZERO()) == 0;};
217 unsigned return_type(void) const;
218 unsigned return_type_tinfo(void) const;
219 unsigned gethash(void) const;
221 ex exadd(ex const & rh) const;
222 ex exmul(ex const & rh) const;
223 ex exncmul(ex const & rh) const;
225 void construct_from_basic(basic const & other);
226 void makewriteable();
235 inline bool are_ex_trivially_equal(const ex &e1, const ex &e2)
237 return e1.bp == e2.bp;
240 // wrapper functions around member functions
241 inline int nops(ex const & thisex)
242 { return thisex.nops(); }
244 inline ex expand(ex const & thisex, unsigned options = 0)
245 { return thisex.expand(options); }
247 inline bool has(ex const & thisex, ex const & other)
248 { return thisex.has(other); }
250 inline int degree(ex const & thisex, symbol const & s)
251 { return thisex.degree(s); }
253 inline int ldegree(ex const & thisex, symbol const & s)
254 { return thisex.ldegree(s); }
256 inline ex coeff(ex const & thisex, symbol const & s, int const n=1)
257 { return thisex.coeff(s, n); }
259 inline ex numer(ex const & thisex, bool normalize = true)
260 { return thisex.numer(normalize); }
262 inline ex denom(ex const & thisex, bool normalize = true)
263 { return thisex.denom(normalize); }
265 inline ex normal(ex const & thisex, int level=0)
266 { return thisex.normal(level); }
268 inline ex collect(ex const & thisex, symbol const & s)
269 { return thisex.collect(s); }
271 inline ex eval(ex const & thisex, int level = 0)
272 { return thisex.eval(level); }
274 inline ex evalf(ex const & thisex, int level = 0)
275 { return thisex.evalf(level); }
277 inline ex diff(ex const & thisex, symbol const & s, unsigned nth = 1)
278 { return thisex.diff(s, nth); }
280 inline ex subs(ex const & thisex, ex const & e)
281 { return thisex.subs(e); }
283 inline ex subs(ex const & thisex, lst const & ls, lst const & lr)
284 { return thisex.subs(ls, lr); }
286 inline void swap(ex & e1, ex & e2)
289 #ifndef NO_GINAC_NAMESPACE
291 #endif // ndef NO_GINAC_NAMESPACE
293 #endif // ndef __GINAC_EX_H__