3 * Interface to GiNaC's light-weight expression handles. */
6 * GiNaC Copyright (C) 1999-2022 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 // MSVC produces a different symbol for _ex0 when it is declared inside
38 // ex::is_zero() than when it is declared at top level as follows
42 /** Helper class to initialize the library. There must be one static object
43 * of this class in every object file that makes use of our flyweights in
44 * order to guarantee proper initialization. Hence we put it into this
45 * file which is included by every relevant file anyways. This is modeled
46 * after section [ios::Init] of the C++ standard, where cout and friends are
51 static void init_unarchivers();
58 /** For construction of flyweights, etc. */
59 static library_init library_initializer;
61 class scalar_products;
63 class const_preorder_iterator;
64 class const_postorder_iterator;
67 /** Lightweight wrapper for GiNaC's symbolic objects. It holds a pointer to
68 * the other object in order to do garbage collection by the method of
69 * reference counting. I.e., it is a smart pointer. Also, the constructor
70 * ex::ex(const basic & other) calls the methods that do automatic
71 * evaluation. E.g., x-x turns automatically into 0. */
73 friend class archive_node;
74 friend inline bool are_ex_trivially_equal(const ex &, const ex &);
75 template<class T> friend inline const T &ex_to(const ex &);
76 template<class T> friend inline bool is_a(const ex &);
77 template<class T> friend inline bool is_exactly_a(const ex &);
79 // default constructor, copy constructor and assignment operator
85 ex(const basic & other);
91 ex(unsigned long long i);
94 /** Construct ex from string and a list of symbols. The input grammar is
95 * similar to the GiNaC output format. All symbols and indices to be used
96 * in the expression must be specified in a lst in the second argument.
97 * Undefined symbols and other parser errors will throw an exception. */
98 ex(const std::string &s, const ex &l);
101 // non-virtual functions in this class
103 /** Efficiently swap the contents of two expressions. */
104 void swap(ex & other) noexcept
106 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
107 GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
112 const_iterator begin() const noexcept;
113 const_iterator end() const noexcept;
114 const_preorder_iterator preorder_begin() const;
115 const_preorder_iterator preorder_end() const noexcept;
116 const_postorder_iterator postorder_begin() const;
117 const_postorder_iterator postorder_end() const noexcept;
120 ex eval() const { return bp->eval(); }
121 ex evalf() const { return bp->evalf(); }
122 ex evalm() const { return bp->evalm(); }
123 ex eval_ncmul(const exvector & v) const { return bp->eval_ncmul(v); }
124 ex eval_integ() const { return bp->eval_integ(); }
127 void print(const print_context & c, unsigned level = 0) const;
128 void dbgprint() const;
129 void dbgprinttree() const;
132 bool info(unsigned inf) const { return bp->info(inf); }
135 size_t nops() const { return bp->nops(); }
136 ex op(size_t i) const { return bp->op(i); }
137 ex operator[](const ex & index) const { return (const_cast<const basic&>(*bp))[index]; }
138 ex operator[](size_t i) const { return (const_cast<const basic&>(*bp))[i]; }
139 ex & let_op(size_t i);
140 ex & operator[](const ex & index);
141 ex & operator[](size_t i);
145 // function for complex expressions
146 ex conjugate() const { return bp->conjugate(); }
147 ex real_part() const { return bp->real_part(); }
148 ex imag_part() const { return bp->imag_part(); }
151 bool has(const ex & pattern, unsigned options = 0) const { return bp->has(pattern, options); }
152 bool find(const ex & pattern, exset& found) const;
153 bool match(const ex & pattern) const;
154 bool match(const ex & pattern, exmap & repls) const { return bp->match(pattern, repls); }
157 ex subs(const exmap & m, unsigned options = 0) const;
158 ex subs(const lst & ls, const lst & lr, unsigned options = 0) const;
159 ex subs(const ex & e, unsigned options = 0) const;
162 ex map(map_function & f) const { return bp->map(f); }
163 ex map(ex (*f)(const ex & e)) const;
165 // visitors and tree traversal
166 void accept(visitor & v) const { bp->accept(v); }
167 void traverse_preorder(visitor & v) const;
168 void traverse_postorder(visitor & v) const;
169 void traverse(visitor & v) const { traverse_preorder(v); }
172 bool is_polynomial(const ex & vars) const;
173 int degree(const ex & s) const { return bp->degree(s); }
174 int ldegree(const ex & s) const { return bp->ldegree(s); }
175 ex coeff(const ex & s, int n = 1) const { return bp->coeff(s, n); }
176 ex lcoeff(const ex & s) const { return coeff(s, degree(s)); }
177 ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); }
180 ex expand(unsigned options=0) const;
181 ex collect(const ex & s, bool distributed = false) const { return bp->collect(s, distributed); }
183 // differentiation and series expansion
184 ex diff(const symbol & s, unsigned nth = 1) const;
185 ex series(const ex & r, int order, unsigned options = 0) const;
187 // rational functions
189 ex to_rational(exmap & repl) const;
190 ex to_polynomial(exmap & repl) const;
193 ex numer_denom() const;
195 // polynomial algorithms
196 ex unit(const ex &x) const;
197 ex content(const ex &x) const;
198 numeric integer_content() const;
199 ex primpart(const ex &x) const;
200 ex primpart(const ex &x, const ex &cont) const;
201 void unitcontprim(const ex &x, ex &u, ex &c, ex &p) const;
202 ex smod(const numeric &xi) const { return bp->smod(xi); }
203 numeric max_coefficient() const;
206 exvector get_free_indices() const { return bp->get_free_indices(); }
207 ex simplify_indexed(unsigned options = 0) const;
208 ex simplify_indexed(const scalar_products & sp, unsigned options = 0) const;
211 int compare(const ex & other) const;
212 bool is_equal(const ex & other) const;
213 bool is_zero() const {
215 extern const ex _ex0;
217 return is_equal(_ex0);
219 bool is_zero_matrix() const;
222 ex symmetrize() const;
223 ex symmetrize(const lst & l) const;
224 ex antisymmetrize() const;
225 ex antisymmetrize(const lst & l) const;
226 ex symmetrize_cyclic() const;
227 ex symmetrize_cyclic(const lst & l) const;
230 unsigned return_type() const { return bp->return_type(); }
231 return_type_t return_type_tinfo() const { return bp->return_type_tinfo(); }
233 unsigned gethash() const { return bp->gethash(); }
236 static ptr<basic> construct_from_basic(const basic & other);
237 static basic & construct_from_int(int i);
238 static basic & construct_from_uint(unsigned int i);
239 static basic & construct_from_long(long i);
240 static basic & construct_from_ulong(unsigned long i);
241 static basic & construct_from_longlong(long long i);
242 static basic & construct_from_ulonglong(unsigned long long i);
243 static basic & construct_from_double(double d);
244 static ptr<basic> construct_from_string_and_lst(const std::string &s, const ex &l);
245 void makewriteable();
246 void share(const ex & other) const;
251 mutable ptr<basic> bp; ///< pointer to basic object managed by this
255 // performance-critical inlined method implementations
257 // This needs to be a basic* because we don't know that numeric is derived
258 // from basic and we need a basic& for the ex default constructor
259 extern const basic *_num0_bp;
262 ex::ex() noexcept : bp(*const_cast<basic *>(_num0_bp))
264 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
268 ex::ex(const basic & other) : bp(construct_from_basic(other))
270 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
274 ex::ex(int i) : bp(construct_from_int(i))
276 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
280 ex::ex(unsigned int i) : bp(construct_from_uint(i))
282 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
286 ex::ex(long i) : bp(construct_from_long(i))
288 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
292 ex::ex(unsigned long i) : bp(construct_from_ulong(i))
294 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
298 ex::ex(long long i) : bp(construct_from_longlong(i))
300 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
304 ex::ex(unsigned long long i) : bp(construct_from_ulonglong(i))
306 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
310 ex::ex(double const d) : bp(construct_from_double(d))
312 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
316 ex::ex(const std::string &s, const ex &l) : bp(construct_from_string_and_lst(s, l))
318 GINAC_ASSERT(bp->flags & status_flags::dynallocated);
322 int ex::compare(const ex & other) const
324 #ifdef GINAC_COMPARE_STATISTICS
325 compare_statistics.total_compares++;
327 if (bp == other.bp) // trivial case: both expressions point to same basic
329 #ifdef GINAC_COMPARE_STATISTICS
330 compare_statistics.nontrivial_compares++;
332 const int cmpval = bp->compare(*other.bp);
335 // Expressions point to different, but equal, trees: conserve
336 // memory and make subsequent compare() operations faster by
337 // making both expressions point to the same tree.
345 bool ex::is_equal(const ex & other) const
347 #ifdef GINAC_COMPARE_STATISTICS
348 compare_statistics.total_is_equals++;
350 if (bp == other.bp) // trivial case: both expressions point to same basic
352 #ifdef GINAC_COMPARE_STATISTICS
353 compare_statistics.nontrivial_is_equals++;
355 const bool equal = bp->is_equal(*other.bp);
358 // Expressions point to different, but equal, trees: conserve
359 // memory and make subsequent compare() operations faster by
360 // making both expressions point to the same tree.
370 class const_iterator : public std::iterator<std::random_access_iterator_tag, ex, ptrdiff_t, const ex *, const ex &> {
372 friend class const_preorder_iterator;
373 friend class const_postorder_iterator;
376 const_iterator() noexcept {}
379 const_iterator(const ex &e_, size_t i_) noexcept : e(e_), i(i_) {}
382 // This should return an ex&, but that would be a reference to a
389 // This should return an ex*, but that would be a pointer to a
391 std::unique_ptr<ex> operator->() const
393 return std::unique_ptr<ex>(new ex(operator*()));
396 ex operator[](difference_type n) const
401 const_iterator &operator++() noexcept
407 const_iterator operator++(int) noexcept
409 const_iterator tmp = *this;
414 const_iterator &operator+=(difference_type n) noexcept
420 const_iterator operator+(difference_type n) const noexcept
422 return const_iterator(e, i + n);
425 inline friend const_iterator operator+(difference_type n, const const_iterator &it) noexcept
427 return const_iterator(it.e, it.i + n);
430 const_iterator &operator--() noexcept
436 const_iterator operator--(int) noexcept
438 const_iterator tmp = *this;
443 const_iterator &operator-=(difference_type n) noexcept
449 const_iterator operator-(difference_type n) const noexcept
451 return const_iterator(e, i - n);
454 inline friend difference_type operator-(const const_iterator &lhs, const const_iterator &rhs) noexcept
456 return lhs.i - rhs.i;
459 bool operator==(const const_iterator &other) const noexcept
461 return are_ex_trivially_equal(e, other.e) && i == other.i;
464 bool operator!=(const const_iterator &other) const noexcept
466 return !(*this == other);
469 bool operator<(const const_iterator &other) const noexcept
474 bool operator>(const const_iterator &other) const noexcept
476 return other < *this;
479 bool operator<=(const const_iterator &other) const noexcept
481 return !(other < *this);
484 bool operator>=(const const_iterator &other) const noexcept
486 return !(*this < other);
490 ex e; // this used to be a "const basic *", but in view of object fusion that wouldn't be safe
497 _iter_rep(const ex &e_, size_t i_, size_t i_end_) : e(e_), i(i_), i_end(i_end_) {}
499 bool operator==(const _iter_rep &other) const noexcept
501 return are_ex_trivially_equal(e, other.e) && i == other.i;
504 bool operator!=(const _iter_rep &other) const noexcept
506 return !(*this == other);
514 } // namespace internal
516 class const_preorder_iterator : public std::iterator<std::forward_iterator_tag, ex, ptrdiff_t, const ex *, const ex &> {
518 const_preorder_iterator() noexcept {}
520 const_preorder_iterator(const ex &e, size_t n)
522 s.push(internal::_iter_rep(e, 0, n));
526 reference operator*() const
531 pointer operator->() const
536 const_preorder_iterator &operator++()
542 const_preorder_iterator operator++(int)
544 const_preorder_iterator tmp = *this;
549 bool operator==(const const_preorder_iterator &other) const noexcept
554 bool operator!=(const const_preorder_iterator &other) const noexcept
556 return !(*this == other);
560 std::stack<internal::_iter_rep, std::vector<internal::_iter_rep>> s;
564 while (!s.empty() && s.top().i == s.top().i_end) {
571 internal::_iter_rep & current = s.top();
573 if (current.i != current.i_end) {
574 const ex & child = current.e.op(current.i);
575 s.push(internal::_iter_rep(child, 0, child.nops()));
580 class const_postorder_iterator : public std::iterator<std::forward_iterator_tag, ex, ptrdiff_t, const ex *, const ex &> {
582 const_postorder_iterator() noexcept {}
584 const_postorder_iterator(const ex &e, size_t n)
586 s.push(internal::_iter_rep(e, 0, n));
591 reference operator*() const
596 pointer operator->() const
601 const_postorder_iterator &operator++()
607 const_postorder_iterator operator++(int)
609 const_postorder_iterator tmp = *this;
614 bool operator==(const const_postorder_iterator &other) const noexcept
619 bool operator!=(const const_postorder_iterator &other) const noexcept
621 return !(*this == other);
625 std::stack<internal::_iter_rep, std::vector<internal::_iter_rep>> s;
629 while (s.top().i != s.top().i_end) {
630 internal::_iter_rep & current = s.top();
631 const ex & child = current.e.op(current.i);
632 s.push(internal::_iter_rep(child, 0, child.nops()));
638 if (s.top().i == s.top().i_end)
647 inline const_iterator ex::begin() const noexcept
649 return const_iterator(*this, 0);
652 inline const_iterator ex::end() const noexcept
654 return const_iterator(*this, nops());
657 inline const_preorder_iterator ex::preorder_begin() const
659 return const_preorder_iterator(*this, nops());
662 inline const_preorder_iterator ex::preorder_end() const noexcept
664 return const_preorder_iterator();
667 inline const_postorder_iterator ex::postorder_begin() const
669 return const_postorder_iterator(*this, nops());
672 inline const_postorder_iterator ex::postorder_end() const noexcept
674 return const_postorder_iterator();
680 /** Compare two objects of class quickly without doing a deep tree traversal.
681 * @return "true" if they are equal
682 * "false" if equality cannot be established quickly (e1 and e2 may
683 * still be equal, in this case. */
684 inline bool are_ex_trivially_equal(const ex &e1, const ex &e2)
686 return e1.bp == e2.bp;
689 /* Function objects for STL sort() etc. */
691 bool operator() (const ex &lh, const ex &rh) const { return lh.compare(rh) < 0; }
695 bool operator() (const ex &lh, const ex &rh) const { return lh.is_equal(rh); }
698 struct op0_is_equal {
699 bool operator() (const ex &lh, const ex &rh) const { return lh.op(0).is_equal(rh.op(0)); }
703 void operator() (ex &lh, ex &rh) const { lh.swap(rh); }
706 // Make it possible to print exvectors and exmaps
707 std::ostream & operator<<(std::ostream & os, const exvector & e);
708 std::ostream & operator<<(std::ostream & os, const exset & e);
709 std::ostream & operator<<(std::ostream & os, const exmap & e);
711 // wrapper functions around member functions
712 inline size_t nops(const ex & thisex)
713 { return thisex.nops(); }
715 inline ex expand(const ex & thisex, unsigned options = 0)
716 { return thisex.expand(options); }
718 inline ex conjugate(const ex & thisex)
719 { return thisex.conjugate(); }
721 inline ex real_part(const ex & thisex)
722 { return thisex.real_part(); }
724 inline ex imag_part(const ex & thisex)
725 { return thisex.imag_part(); }
727 inline bool has(const ex & thisex, const ex & pattern, unsigned options = 0)
728 { return thisex.has(pattern, options); }
730 inline bool find(const ex & thisex, const ex & pattern, exset& found)
731 { return thisex.find(pattern, found); }
733 inline bool is_polynomial(const ex & thisex, const ex & vars)
734 { return thisex.is_polynomial(vars); }
736 inline int degree(const ex & thisex, const ex & s)
737 { return thisex.degree(s); }
739 inline int ldegree(const ex & thisex, const ex & s)
740 { return thisex.ldegree(s); }
742 inline ex coeff(const ex & thisex, const ex & s, int n=1)
743 { return thisex.coeff(s, n); }
745 inline ex numer(const ex & thisex)
746 { return thisex.numer(); }
748 inline ex denom(const ex & thisex)
749 { return thisex.denom(); }
751 inline ex numer_denom(const ex & thisex)
752 { return thisex.numer_denom(); }
754 inline ex normal(const ex & thisex)
755 { return thisex.normal(); }
757 inline ex to_rational(const ex & thisex, exmap & repl)
758 { return thisex.to_rational(repl); }
760 inline ex to_polynomial(const ex & thisex, exmap & repl)
761 { return thisex.to_polynomial(repl); }
763 inline ex collect(const ex & thisex, const ex & s, bool distributed = false)
764 { return thisex.collect(s, distributed); }
766 inline ex eval(const ex & thisex)
767 { return thisex.eval(); }
769 inline ex evalf(const ex & thisex)
770 { return thisex.evalf(); }
772 inline ex evalm(const ex & thisex)
773 { return thisex.evalm(); }
775 inline ex eval_integ(const ex & thisex)
776 { return thisex.eval_integ(); }
778 inline ex diff(const ex & thisex, const symbol & s, unsigned nth = 1)
779 { return thisex.diff(s, nth); }
781 inline ex series(const ex & thisex, const ex & r, int order, unsigned options = 0)
782 { return thisex.series(r, order, options); }
784 inline bool match(const ex & thisex, const ex & pattern, exmap& repl_lst)
785 { return thisex.match(pattern, repl_lst); }
787 inline ex simplify_indexed(const ex & thisex, unsigned options = 0)
788 { return thisex.simplify_indexed(options); }
790 inline ex simplify_indexed(const ex & thisex, const scalar_products & sp, unsigned options = 0)
791 { return thisex.simplify_indexed(sp, options); }
793 inline ex symmetrize(const ex & thisex)
794 { return thisex.symmetrize(); }
796 inline ex symmetrize(const ex & thisex, const lst & l)
797 { return thisex.symmetrize(l); }
799 inline ex antisymmetrize(const ex & thisex)
800 { return thisex.antisymmetrize(); }
802 inline ex antisymmetrize(const ex & thisex, const lst & l)
803 { return thisex.antisymmetrize(l); }
805 inline ex symmetrize_cyclic(const ex & thisex)
806 { return thisex.symmetrize_cyclic(); }
808 inline ex symmetrize_cyclic(const ex & thisex, const lst & l)
809 { return thisex.symmetrize_cyclic(l); }
811 inline ex op(const ex & thisex, size_t i)
812 { return thisex.op(i); }
814 inline ex lhs(const ex & thisex)
815 { return thisex.lhs(); }
817 inline ex rhs(const ex & thisex)
818 { return thisex.rhs(); }
820 inline bool is_zero(const ex & thisex)
821 { return thisex.is_zero(); }
823 inline void swap(ex & e1, ex & e2)
826 inline ex ex::subs(const exmap & m, unsigned options) const
828 return bp->subs(m, options);
831 inline ex subs(const ex & thisex, const exmap & m, unsigned options = 0)
832 { return thisex.subs(m, options); }
834 inline ex subs(const ex & thisex, const lst & ls, const lst & lr, unsigned options = 0)
835 { return thisex.subs(ls, lr, options); }
837 inline ex subs(const ex & thisex, const ex & e, unsigned options = 0)
838 { return thisex.subs(e, options); }
841 /* Convert function pointer to function object suitable for map(). */
842 class pointer_to_map_function : public map_function {
844 ex (*ptr)(const ex &);
846 explicit pointer_to_map_function(ex x(const ex &)) : ptr(x) {}
847 ex operator()(const ex & e) override { return ptr(e); }
851 class pointer_to_map_function_1arg : public map_function {
853 ex (*ptr)(const ex &, T1);
856 explicit pointer_to_map_function_1arg(ex x(const ex &, T1), T1 a1) : ptr(x), arg1(a1) {}
857 ex operator()(const ex & e) override { return ptr(e, arg1); }
860 template<class T1, class T2>
861 class pointer_to_map_function_2args : public map_function {
863 ex (*ptr)(const ex &, T1, T2);
867 explicit pointer_to_map_function_2args(ex x(const ex &, T1, T2), T1 a1, T2 a2) : ptr(x), arg1(a1), arg2(a2) {}
868 ex operator()(const ex & e) override { return ptr(e, arg1, arg2); }
871 template<class T1, class T2, class T3>
872 class pointer_to_map_function_3args : public map_function {
874 ex (*ptr)(const ex &, T1, T2, T3);
879 explicit pointer_to_map_function_3args(ex x(const ex &, T1, T2, T3), T1 a1, T2 a2, T3 a3) : ptr(x), arg1(a1), arg2(a2), arg3(a3) {}
880 ex operator()(const ex & e) override { return ptr(e, arg1, arg2, arg3); }
884 class pointer_to_member_to_map_function : public map_function {
886 ex (C::*ptr)(const ex &);
889 explicit pointer_to_member_to_map_function(ex (C::*member)(const ex &), C &obj) : ptr(member), c(obj) {}
890 ex operator()(const ex & e) override { return (c.*ptr)(e); }
893 template<class C, class T1>
894 class pointer_to_member_to_map_function_1arg : public map_function {
896 ex (C::*ptr)(const ex &, T1);
900 explicit pointer_to_member_to_map_function_1arg(ex (C::*member)(const ex &, T1), C &obj, T1 a1) : ptr(member), c(obj), arg1(a1) {}
901 ex operator()(const ex & e) override { return (c.*ptr)(e, arg1); }
904 template<class C, class T1, class T2>
905 class pointer_to_member_to_map_function_2args : public map_function {
907 ex (C::*ptr)(const ex &, T1, T2);
912 explicit pointer_to_member_to_map_function_2args(ex (C::*member)(const ex&, T1, T2), C &obj, T1 a1, T2 a2) : ptr(member), c(obj), arg1(a1), arg2(a2) {}
913 ex operator()(const ex & e) override { return (c.*ptr)(e, arg1, arg2); }
916 template<class C, class T1, class T2, class T3>
917 class pointer_to_member_to_map_function_3args : public map_function {
919 ex (C::*ptr)(const ex &, T1, T2, T3);
925 explicit pointer_to_member_to_map_function_3args(ex (C::*member)(const ex &, T1, T2, T3), C &obj, T1 a1, T2 a2, T3 a3) : ptr(member), c(obj), arg1(a1), arg2(a2), arg3(a3) {}
926 ex operator()(const ex & e) override { return (c.*ptr)(e, arg1, arg2, arg3); }
929 inline ex ex::map(ex f(const ex &)) const
931 pointer_to_map_function fcn(f);
935 // convenience type checker template functions
937 /** Check if ex is a handle to a T, including base classes. */
939 inline bool is_a(const ex &obj)
941 return is_a<T>(*obj.bp);
944 /** Check if ex is a handle to a T, not including base classes. */
946 inline bool is_exactly_a(const ex &obj)
948 return is_exactly_a<T>(*obj.bp);
951 /** Return a reference to the basic-derived class T object embedded in an
952 * expression. This is fast but unsafe: the result is undefined if the
953 * expression does not contain a T object at its top level. Hence, you
954 * should generally check the type of e first. Also, you shouldn't cache
955 * the returned reference because GiNaC's garbage collector may destroy
956 * the referenced object any time it's used in another expression.
958 * @param e expression
959 * @return reference to object of class T
960 * @see is_exactly_a<class T>() */
962 inline const T &ex_to(const ex &e)
964 GINAC_ASSERT(is_a<T>(e));
965 return static_cast<const T &>(*e.bp);
971 // Specializations of Standard Library algorithms
974 /** Specialization of std::swap() for ex objects. */
976 inline void swap(GiNaC::ex &a, GiNaC::ex &b)
981 /** Specialization of std::hash() for ex objects. */
983 struct hash<GiNaC::ex>
985 std::size_t operator()(const GiNaC::ex & e) const noexcept
991 /** Specialization of std::equal_to() for ex objects. */
993 struct equal_to<GiNaC::ex>
995 bool operator()(const GiNaC::ex &e1, const GiNaC::ex &e2) const noexcept
997 return e1.is_equal(e2);
1003 #endif // ndef GINAC_EX_H