+ // other constructors
+public:
+ ex(const basic & other);
+ ex(int i);
+ ex(unsigned int i);
+ ex(long i);
+ ex(unsigned long i);
+ ex(double const d);
+
+ /** Construct ex from string and a list of symbols. The input grammar is
+ * similar to the GiNaC output format. All symbols and indices to be used
+ * in the expression must be specified in a lst in the second argument.
+ * Undefined symbols and other parser errors will throw an exception. */
+ ex(const std::string &s, const ex &l);
+
+public:
+ // Iterators
+ class const_iterator : public std::iterator<std::random_access_iterator_tag, ex, ptrdiff_t, const ex *, const ex &>
+ {
+ friend class ex;
+
+ public:
+ const_iterator() {}
+ const_iterator(const basic *bp_, size_t i_) : bp(bp_), i(i_) {}
+
+ bool operator==(const const_iterator &other) const
+ {
+ return bp == other.bp && i == other.i;
+ }
+
+ bool operator!=(const const_iterator &other) const
+ {
+ return !(*this == other);
+ }
+
+ bool operator<(const const_iterator &other) const
+ {
+ return i < other.i;
+ }
+
+ bool operator>(const const_iterator &other) const
+ {
+ return other < *this;
+ }
+
+ bool operator<=(const const_iterator &other) const
+ {
+ return !(other < *this);
+ }
+
+ bool operator>=(const const_iterator &other) const
+ {
+ return !(*this < other);
+ }
+
+ // This should return an ex&, but that would be a reference to a
+ // temporary value
+ ex operator*() const
+ {
+ return bp->op(i);
+ }
+
+#if 0
+ // How do we make this work in the context of the "reference to
+ // temporary" problem? Return an auto_ptr?
+ pointer operator->() const
+ {
+ return &(operator*());
+ }
+#endif
+
+ const_iterator &operator++()
+ {
+ ++i;
+ return *this;
+ }
+
+ const_iterator operator++(int)
+ {
+ const_iterator tmp = *this;
+ ++i;
+ return tmp;
+ }
+
+ const_iterator &operator+=(difference_type n)
+ {
+ i += n;
+ return *this;
+ }
+
+ const_iterator operator+(difference_type n) const
+ {
+ return const_iterator(bp, i + n);
+ }
+
+ inline friend const_iterator operator+(difference_type n, const const_iterator &it)
+ {
+ return const_iterator(it.bp, it.i + n);
+ }
+
+ const_iterator &operator--()
+ {
+ --i;
+ return *this;
+ }
+
+ const_iterator operator--(int)
+ {
+ const_iterator tmp = *this;
+ --i;
+ return tmp;
+ }
+
+ const_iterator &operator-=(difference_type n)
+ {
+ i -= n;
+ return *this;
+ }
+
+ const_iterator operator-(difference_type n) const
+ {
+ return const_iterator(bp, i - n);
+ }
+
+ inline friend difference_type operator-(const const_iterator &lhs, const const_iterator &rhs)
+ {
+ return lhs.i - rhs.i;
+ }
+
+ reference operator[](difference_type n) const
+ {
+ }
+
+ protected:
+ const basic *bp;
+ size_t i;
+ };
+
+ const_iterator begin() const { return const_iterator(get_pointer(bp), 0); }
+ const_iterator end() const { return const_iterator(get_pointer(bp), bp->nops()); }
+
+#if 0
+ // This doesn't work because of the "reference to temporary" problem
+ // in operator*()
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
+ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
+#endif
+
+ // non-virtual functions in this class
+public:
+ /** Efficiently swap the contents of two expressions. */
+ void swap(ex & other)
+ {
+ GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+ GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
+ bp.swap(other.bp);
+ }
+
+ // evaluation
+ ex eval(int level = 0) const { return bp->eval(level); }
+ ex evalf(int level = 0) const { return bp->evalf(level); }
+ ex evalm() const { return bp->evalm(); }
+ ex eval_ncmul(const exvector & v) const { return bp->eval_ncmul(v); }
+
+ // printing
+ void print(const print_context & c, unsigned level = 0) const;
+ void dbgprint() const;
+ void dbgprinttree() const;
+
+ // info
+ bool info(unsigned inf) const { return bp->info(inf); }
+
+ // operand access
+ size_t nops() const { return bp->nops(); }
+ ex op(size_t i) const { return bp->op(i); }
+ ex operator[](const ex & index) const { return (*bp)[index]; }
+ ex operator[](size_t i) const { return (*bp)[i]; }
+ ex & let_op(size_t i);
+ ex & operator[](const ex & index);
+ ex & operator[](size_t i);
+ ex lhs() const;
+ ex rhs() const;
+
+ // pattern matching
+ bool has(const ex & pattern) const { return bp->has(pattern); }
+ bool find(const ex & pattern, lst & found) const;
+ bool match(const ex & pattern) const;
+ bool match(const ex & pattern, lst & repl_lst) const { return bp->match(pattern, repl_lst); }
+
+ // substitutions
+ ex subs(const exmap & m, unsigned options = 0) const;
+ ex subs(const lst & ls, const lst & lr, unsigned options = 0) const;
+ ex subs(const ex & e, unsigned options = 0) const;
+
+ // function mapping
+ ex map(map_function & f) const { return bp->map(f); }
+ ex map(ex (*f)(const ex & e)) const;
+
+ // visitors and tree traversal
+ void accept(visitor & v) const { bp->accept(v); }
+ void traverse_preorder(visitor & v) const;
+ void traverse_postorder(visitor & v) const;
+ void traverse(visitor & v) const { traverse_preorder(v); }
+
+ // degree/coeff
+ int degree(const ex & s) const { return bp->degree(s); }
+ int ldegree(const ex & s) const { return bp->ldegree(s); }
+ ex coeff(const ex & s, int n = 1) const { return bp->coeff(s, n); }
+ ex lcoeff(const ex & s) const { return coeff(s, degree(s)); }
+ ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); }
+
+ // expand/collect
+ ex expand(unsigned options=0) const;
+ ex collect(const ex & s, bool distributed = false) const { return bp->collect(s, distributed); }
+
+ // differentiation and series expansion
+ ex diff(const symbol & s, unsigned nth = 1) const;
+ ex series(const ex & r, int order, unsigned options = 0) const;
+
+ // rational functions
+ ex normal(int level = 0) const;
+ ex to_rational(lst &repl_lst) const;
+ ex to_polynomial(lst &repl_lst) const;
+ ex numer() const;
+ ex denom() const;
+ ex numer_denom() const;
+
+ // polynomial algorithms
+ ex unit(const symbol &x) const;
+ ex content(const symbol &x) const;
+ numeric integer_content() const;
+ ex primpart(const symbol &x) const;
+ ex primpart(const symbol &x, const ex &cont) const;
+ ex smod(const numeric &xi) const { return bp->smod(xi); }
+ numeric max_coefficient() const;
+
+ // indexed objects
+ exvector get_free_indices() const { return bp->get_free_indices(); }
+ ex simplify_indexed() const;
+ ex simplify_indexed(const scalar_products & sp) const;
+
+ // comparison
+ int compare(const ex & other) const;
+ bool is_equal(const ex & other) const;
+ bool is_zero() const { extern const ex _ex0; return is_equal(_ex0); }
+
+ // symmetry
+ ex symmetrize() const;
+ ex symmetrize(const lst & l) const;
+ ex antisymmetrize() const;
+ ex antisymmetrize(const lst & l) const;
+ ex symmetrize_cyclic() const;
+ ex symmetrize_cyclic(const lst & l) const;
+
+ // noncommutativity
+ unsigned return_type() const { return bp->return_type(); }
+ unsigned return_type_tinfo() const { return bp->return_type_tinfo(); }
+
+ unsigned gethash() const { return bp->gethash(); }