From: Christian Bauer Date: Fri, 1 Jun 2001 18:37:00 +0000 (+0000) Subject: - added numer_denom() to get numerator and denominator in one pass X-Git-Tag: release_0-9-0~25 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=9961dfdd7a383f09b1040e195a8817a85d945e58;ds=sidebyside - added numer_denom() to get numerator and denominator in one pass - symmetrize() and antisymmetrize() are available as ex methods - minor cleanups --- diff --git a/ginac/ex.cpp b/ginac/ex.cpp index e8ce2da1..18497898 100644 --- a/ginac/ex.cpp +++ b/ginac/ex.cpp @@ -29,9 +29,8 @@ #include "ncmul.h" #include "numeric.h" #include "power.h" -#include "relational.h" -#include "indexed.h" #include "lst.h" +#include "relational.h" #include "input_lexer.h" #include "debugmsg.h" #include "utils.h" @@ -144,28 +143,6 @@ bool ex::match(const ex & pattern) const return bp->match(pattern, repl_lst); } -/** Simplify/canonicalize expression containing indexed objects. This - * performs contraction of dummy indices where possible and checks whether - * the free indices in sums are consistent. - * - * @return simplified expression */ -ex ex::simplify_indexed(void) const -{ - return GiNaC::simplify_indexed(*this); -} - -/** Simplify/canonicalize expression containing indexed objects. This - * performs contraction of dummy indices where possible, checks whether - * the free indices in sums are consistent, and automatically replaces - * scalar products by known values if desired. - * - * @param sp Scalar products to be replaced automatically - * @return simplified expression */ -ex ex::simplify_indexed(const scalar_products & sp) const -{ - return GiNaC::simplify_indexed(*this, sp); -} - ex ex::operator[](const ex & index) const { debugmsg("ex operator[ex]",LOGLEVEL_OPERATOR); diff --git a/ginac/ex.h b/ginac/ex.h index 34ce8b8c..499229e0 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -91,6 +91,7 @@ public: ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); } ex numer(void) const; ex denom(void) const; + ex numer_denom(void) const; ex unit(const symbol &x) const; ex content(const symbol &x) const; numeric integer_content(void) const; @@ -112,6 +113,10 @@ public: exvector get_free_indices(void) const { return bp->get_free_indices(); } ex simplify_indexed(void) const; ex simplify_indexed(const scalar_products & sp) const; + ex symmetrize(void) const; + ex symmetrize(const lst & l) const; + ex antisymmetrize(void) const; + ex antisymmetrize(const lst & l) const; ex simplify_ncmul(const exvector & v) const { return bp->simplify_ncmul(v); } ex operator[](const ex & index) const; ex operator[](int i) const; @@ -351,6 +356,9 @@ inline ex numer(const ex & thisex) inline ex denom(const ex & thisex) { return thisex.denom(); } +inline ex numer_denom(const ex & thisex) +{ return thisex.numer_denom(); } + inline ex normal(const ex & thisex, int level=0) { return thisex.normal(level); } @@ -381,6 +389,24 @@ inline ex subs(const ex & thisex, const ex & e) inline ex subs(const ex & thisex, const lst & ls, const lst & lr) { return thisex.subs(ls, lr); } +inline ex simplify_indexed(const ex & thisex) +{ return thisex.simplify_indexed(); } + +inline ex simplify_indexed(const ex & thisex, const scalar_products & sp) +{ return thisex.simplify_indexed(sp); } + +inline ex symmetrize(const ex & thisex) +{ return thisex.symmetrize(); } + +inline ex symmetrize(const ex & thisex, const lst & l) +{ return thisex.symmetrize(l); } + +inline ex antisymmetrize(const ex & thisex) +{ return thisex.antisymmetrize(); } + +inline ex antisymmetrize(const ex & thisex, const lst & l) +{ return thisex.antisymmetrize(l); } + inline ex op(const ex & thisex, int i) { return thisex.op(i); } diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index f0726915..a2eda2c4 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -30,7 +30,7 @@ #include "ncmul.h" #include "power.h" #include "lst.h" -#include "inifcns.h" +#include "inifcns.h" // for symmetrize() #include "print.h" #include "archive.h" #include "utils.h" @@ -815,27 +815,41 @@ ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indi return e_expanded; } -ex simplify_indexed(const ex & e) +/** Simplify/canonicalize expression containing indexed objects. This + * performs contraction of dummy indices where possible and checks whether + * the free indices in sums are consistent. + * + * @return simplified expression */ +ex ex::simplify_indexed(void) const { exvector free_indices, dummy_indices; scalar_products sp; - return simplify_indexed(e, free_indices, dummy_indices, sp); + return GiNaC::simplify_indexed(*this, free_indices, dummy_indices, sp); } -ex simplify_indexed(const ex & e, const scalar_products & sp) +/** Simplify/canonicalize expression containing indexed objects. This + * performs contraction of dummy indices where possible, checks whether + * the free indices in sums are consistent, and automatically replaces + * scalar products by known values if desired. + * + * @param sp Scalar products to be replaced automatically + * @return simplified expression */ +ex ex::simplify_indexed(const scalar_products & sp) const { exvector free_indices, dummy_indices; - return simplify_indexed(e, free_indices, dummy_indices, sp); + return GiNaC::simplify_indexed(*this, free_indices, dummy_indices, sp); } -ex symmetrize(const ex & e) +/** Symmetrize expression over its free indices. */ +ex ex::symmetrize(void) const { - return symmetrize(e, e.get_free_indices()); + return GiNaC::symmetrize(*this, get_free_indices()); } -ex antisymmetrize(const ex & e) +/** Antisymmetrize expression over its free indices. */ +ex ex::antisymmetrize(void) const { - return antisymmetrize(e, e.get_free_indices()); + return GiNaC::antisymmetrize(*this, get_free_indices()); } ////////// diff --git a/ginac/indexed.h b/ginac/indexed.h index fd85b8db..babb9c22 100644 --- a/ginac/indexed.h +++ b/ginac/indexed.h @@ -244,31 +244,6 @@ inline const indexed &ex_to_indexed(const ex &e) return static_cast(*e.bp); } - -/** Simplify/canonicalize expression containing indexed objects. This - * performs contraction of dummy indices where possible and checks whether - * the free indices in sums are consistent. - * - * @param e The expression to be simplified - * @return simplified expression */ -ex simplify_indexed(const ex & e); - -/** Simplify/canonicalize expression containing indexed objects. This - * performs contraction of dummy indices where possible, checks whether - * the free indices in sums are consistent, and automatically replaces - * scalar products by known values if desired. - * - * @param e The expression to be simplified - * @param sp Scalar products to be replaced automatically - * @return simplified expression */ -ex simplify_indexed(const ex & e, const scalar_products & sp); - -/** Symmetrize expression over its free indices. */ -ex symmetrize(const ex & e); - -/** Antisymmetrize expression over its free indices. */ -ex antisymmetrize(const ex & e); - } // namespace GiNaC #endif // ndef __GINAC_INDEXED_H__ diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index 03acbc7f..7081eb5b 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -562,22 +562,24 @@ ex antisymmetrize(const ex & e, exvector::const_iterator first, exvector::const_ return symm(e, first, last, true); } -ex symmetrize(const ex & e, const lst & l) +/** Symmetrize expression over a list of objects (symbols, indices). */ +ex ex::symmetrize(const lst & l) const { exvector v; v.reserve(l.nops()); for (unsigned i=0; inormal(sym_lst, repl_lst, 0); + GINAC_ASSERT(is_ex_of_type(e, lst)); + + // Re-insert replaced symbols + if (sym_lst.nops() > 0) + return e.subs(sym_lst, repl_lst); + else + return e; +} + /** Default implementation of ex::to_rational(). It replaces the object with a * temporary symbol.