3 * Interface to GiNaC's light-weight expression handles. */
21 typedef vector<ex> exvector;
25 ex const & exZERO(void);
26 ex const & exONE(void);
27 ex const & exTWO(void);
28 ex const & exTHREE(void);
29 ex const & exMINUSONE(void);
30 ex const & exHALF(void);
31 ex const & exMINUSHALF(void);
33 #define INLINE_EX_CONSTRUCTORS
35 /** Lightweight interface to GiNaC's symbolic objects. Basically all it does is
36 * to hold a pointer to the other objects, manage the reference counting and
37 * provide methods for manipulation of these objects. */
44 // default constructor, destructor, copy constructor assignment operator and helpers
47 #ifdef INLINE_EX_CONSTRUCTORS
50 debugmsg("ex default constructor",LOGLEVEL_CONSTRUCT);
51 ASSERT(exZERO().bp!=0);
52 ASSERT(exZERO().bp->flags & status_flags::dynallocated);
58 #endif // def INLINE_EX_CONSTRUCTORS
61 #ifdef INLINE_EX_CONSTRUCTORS
63 debugmsg("ex destructor",LOGLEVEL_DESTRUCT);
65 ASSERT(bp->flags & status_flags::dynallocated);
66 if (--bp->refcount == 0) {
72 #endif // def INLINE_EX_CONSTRUCTORS
75 #ifdef INLINE_EX_CONSTRUCTORS
78 debugmsg("ex copy constructor",LOGLEVEL_CONSTRUCT);
80 ASSERT((bp->flags) & status_flags::dynallocated);
85 #endif // def INLINE_EX_CONSTRUCTORS
87 ex const & operator=(ex const & other)
88 #ifdef INLINE_EX_CONSTRUCTORS
90 debugmsg("ex operator=",LOGLEVEL_ASSIGNMENT);
92 ASSERT(bp->flags & status_flags::dynallocated);
94 ASSERT(other.bp->flags & status_flags::dynallocated);
96 basic * tmpbp=other.bp;
97 if (--bp->refcount==0) {
105 #endif // def INLINE_EX_CONSTRUCTORS
107 // other constructors
109 ex(basic const & other)
110 #ifdef INLINE_EX_CONSTRUCTORS
112 debugmsg("ex constructor from basic",LOGLEVEL_CONSTRUCT);
113 construct_from_basic(other);
117 #endif // def INLINE_EX_CONSTRUCTORS
120 ex(unsigned int const i);
122 ex(unsigned long const i);
125 // functions overriding virtual functions from bases classes
128 // new virtual functions which can be overridden by derived classes
131 // non-virtual functions in this class
133 void swap(ex & other);
134 void printraw(ostream & os) const;
135 void printtree(ostream & os, unsigned indent=0) const;
136 void print(ostream & os, unsigned upper_precedence=0) const;
137 void printcsrc(ostream & os, unsigned type, const char *var_name) const;
138 void dbgprint(void) const;
139 void dbgprinttree(void) const;
140 bool info(unsigned inf) const;
142 ex expand(unsigned options=0) const;
143 bool has(ex const & other) const;
144 int degree(symbol const & s) const;
145 int ldegree(symbol const & s) const;
146 ex coeff(symbol const & s, int const n=1) const;
147 ex lcoeff(symbol const & s) const { return coeff(s, degree(s)); }
148 ex tcoeff(symbol const & s) const { return coeff(s, ldegree(s)); }
149 ex numer(bool normalize = true) const;
150 ex denom(bool normalize = true) const;
151 ex unit(const symbol &x) const;
152 ex content(const symbol &x) const;
153 numeric integer_content(void) const;
154 ex primpart(const symbol &x) const;
155 ex primpart(const symbol &x, const ex &cont) const;
156 ex normal(int level = 0) const;
157 ex smod(const numeric &xi) const;
158 numeric max_coefficient(void) const;
159 ex collect(symbol const & s) const;
160 ex eval(int level = 0) const;
161 ex evalf(int level = 0) const;
162 ex diff(symbol const & s, unsigned nth = 1) const;
163 ex series(symbol const & s, ex const & point, int order = 6) const;
164 ex subs(lst const & ls, lst const & lr) const;
165 ex subs(ex const & e) const;
166 exvector get_indices(void) const;
167 ex simplify_ncmul(exvector const & v) const;
168 ex operator[](ex const & index) const;
169 ex operator[](int const i) const;
170 ex op(int const i) const;
171 ex & let_op(int const i);
172 int compare(ex const & other) const
173 #ifdef INLINE_EX_CONSTRUCTORS
178 // special case: both expression point to same basic, trivially equal
181 return bp->compare(*other.bp);
185 #endif // def INLINE_EX_CONSTRUCTORS
186 bool is_equal(ex const & other) const
187 #ifdef INLINE_EX_CONSTRUCTORS
192 // special case: both expression point to same basic, trivially equal
195 return bp->is_equal(*other.bp);
199 #endif // def INLINE_EX_CONSTRUCTORS
200 bool is_zero(void) const {return compare(exZERO()) == 0;};
202 unsigned return_type(void) const;
203 unsigned return_type_tinfo(void) const;
204 unsigned gethash(void) const;
206 ex exadd(ex const & rh) const;
207 ex exmul(ex const & rh) const;
208 ex exncmul(ex const & rh) const;
210 void construct_from_basic(basic const & other);
211 void makewriteable();
220 // wrapper functions around member functions
221 inline int nops(ex const & thisex)
222 { return thisex.nops(); }
224 inline ex expand(ex const & thisex, unsigned options = 0)
225 { return thisex.expand(options); }
227 inline bool has(ex const & thisex, ex const & other)
228 { return thisex.has(other); }
230 inline int degree(ex const & thisex, symbol const & s)
231 { return thisex.degree(s); }
233 inline int ldegree(ex const & thisex, symbol const & s)
234 { return thisex.ldegree(s); }
236 inline ex coeff(ex const & thisex, symbol const & s, int const n=1)
237 { return thisex.coeff(s, n); }
239 inline ex numer(ex const & thisex, bool normalize = true)
240 { return thisex.numer(normalize); }
242 inline ex denom(ex const & thisex, bool normalize = true)
243 { return thisex.denom(normalize); }
245 inline ex normal(ex const & thisex, int level=0)
246 { return thisex.normal(level); }
248 inline ex collect(ex const & thisex, symbol const & s)
249 { return thisex.collect(s); }
251 inline ex eval(ex const & thisex, int level = 0)
252 { return thisex.eval(level); }
254 inline ex evalf(ex const & thisex, int level = 0)
255 { return thisex.evalf(level); }
257 inline ex diff(ex const & thisex, symbol const & s, unsigned nth = 1)
258 { return thisex.diff(s, nth); }
260 inline ex subs(ex const & thisex, ex const & e)
261 { return thisex.subs(e); }
263 inline ex subs(ex const & thisex, lst const & ls, lst const & lr)
264 { return thisex.subs(ls, lr); }
266 inline void swap(ex & e1, ex & e2)
269 #endif // ndef _EX_H_