]> www.ginac.de Git - ginac.git/commitdiff
- added numer_denom() to get numerator and denominator in one pass
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 1 Jun 2001 18:37:00 +0000 (18:37 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 1 Jun 2001 18:37:00 +0000 (18:37 +0000)
- symmetrize() and antisymmetrize() are available as ex methods
- minor cleanups

ginac/ex.cpp
ginac/ex.h
ginac/indexed.cpp
ginac/indexed.h
ginac/inifcns.cpp
ginac/inifcns.h
ginac/normal.cpp

index e8ce2da1eabce3e5ba12b0ad1e60f415ceb62d42..1849789871585a3d96318454d8f49e86769bae2c 100644 (file)
@@ -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);
index 34ce8b8c489634528271e1612585d734f12036c5..499229e09072e4c972a61bf691457cab0bf76b0b 100644 (file)
@@ -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); }
 
index f0726915674bf13ce8df0383013ba0bb4ed7fe24..a2eda2c482b1621e7a94798a5db3ebece9ffbff4 100644 (file)
@@ -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());
 }
 
 //////////
index fd85b8db25cfa055805e78a2547d63b40229b273..babb9c224de0ab72b994ed9b33eec8b6abafd4b9 100644 (file)
@@ -244,31 +244,6 @@ inline const indexed &ex_to_indexed(const ex &e)
        return static_cast<const indexed &>(*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__
index 03acbc7f2f42d4c221905652a39b21cdd3e041e2..7081eb5b333ebe22f7fd365e80a0a513d60e0603 100644 (file)
@@ -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; i<l.nops(); i++)
                v.push_back(l.op(i));
-       return symm(e, v.begin(), v.end(), false);
+       return symm(*this, v.begin(), v.end(), false);
 }
 
-ex antisymmetrize(const ex & e, const lst & l)
+/** Antisymmetrize expression over a list of objects (symbols, indices). */
+ex ex::antisymmetrize(const lst & l) const
 {
        exvector v;
        v.reserve(l.nops());
        for (unsigned i=0; i<l.nops(); i++)
                v.push_back(l.op(i));
-       return symm(e, v.begin(), v.end(), true);
+       return symm(*this, v.begin(), v.end(), true);
 }
 
 /** Force inclusion of functions from initcns_gamma and inifcns_zeta
index 6a7efbe610a24930690b1462eb42f02427585f9a..96c256077f92f0964c4f7fa8360f407e61e8405d 100644 (file)
@@ -145,9 +145,6 @@ inline ex symmetrize(const ex & e, const exvector & v)
        return symmetrize(e, v.begin(), v.end());
 }
 
-/** Symmetrize expression over a list of objects (symbols, indices). */
-ex symmetrize(const ex & e, const lst & l);
-
 /** Antisymmetrize expression over a set of objects (symbols, indices). */
 ex antisymmetrize(const ex & e, exvector::const_iterator first, exvector::const_iterator last);
 
@@ -157,9 +154,7 @@ inline ex antisymmetrize(const ex & e, const exvector & v)
        return antisymmetrize(e, v.begin(), v.end());
 }
 
-/** Antisymmetrize expression over a list of objects (symbols, indices). */
-ex antisymmetrize(const ex & e, const lst & l);
-
+/** Check whether a function is the Order (O(n)) function. */
 inline bool is_order_function(const ex & e)
 {
        return is_ex_the_function(e, Order);
index d3a407d50e713ba633054784f263976360f5dc49..f985573a5f6da669dba179ba91049f6b242c6cac 100644 (file)
@@ -2118,9 +2118,9 @@ ex ex::normal(int level) const
        return e.op(0) / e.op(1);
 }
 
-/** Numerator of an expression. If the expression is not of the normal form
- *  "numerator/denominator", it is first converted to this form and then the
- *  numerator is returned.
+/** Get numerator of an expression. If the expression is not of the normal
+ *  form "numerator/denominator", it is first converted to this form and
+ *  then the numerator is returned.
  *
  *  @see ex::normal
  *  @return numerator */
@@ -2138,9 +2138,9 @@ ex ex::numer(void) const
                return e.op(0);
 }
 
-/** Denominator of an expression. If the expression is not of the normal form
- *  "numerator/denominator", it is first converted to this form and then the
- *  denominator is returned.
+/** Get denominator of an expression. If the expression is not of the normal
+ *  form "numerator/denominator", it is first converted to this form and
+ *  then the denominator is returned.
  *
  *  @see ex::normal
  *  @return denominator */
@@ -2158,6 +2158,26 @@ ex ex::denom(void) const
                return e.op(1);
 }
 
+/** Get numerator and denominator of an expression. If the expresison is not
+ *  of the normal form "numerator/denominator", it is first converted to this
+ *  form and then a list [numerator, denominator] is returned.
+ *
+ *  @see ex::normal
+ *  @return a list [numerator, denominator] */
+ex ex::numer_denom(void) const
+{
+       lst sym_lst, repl_lst;
+
+       ex e = bp->normal(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.