#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"
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);
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;
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;
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); }
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); }
#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"
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());
}
//////////
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__
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
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);
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);
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 */
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 */
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.