*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-// default constructor, destructor, copy constructor assignment operator and helpers
+// default ctor, dtor, copy ctor, assignment operator and helpers
idx::idx(const ex & v, const ex & d) : inherited(TINFO_idx), value(v), dim(d)
{
idx::idx(const ex & v, const ex & d) : inherited(TINFO_idx), value(v), dim(d)
{
if (is_dim_numeric())
if (!dim.info(info_flags::posint))
throw(std::invalid_argument("dimension of space must be a positive integer"));
if (is_dim_numeric())
if (!dim.info(info_flags::posint))
throw(std::invalid_argument("dimension of space must be a positive integer"));
varidx::varidx(const ex & v, const ex & d, bool cov) : inherited(v, d), covariant(cov)
{
varidx::varidx(const ex & v, const ex & d, bool cov) : inherited(v, d), covariant(cov)
{
tinfo_key = TINFO_varidx;
}
spinidx::spinidx(const ex & v, const ex & d, bool cov, bool dot) : inherited(v, d, cov), dotted(dot)
{
tinfo_key = TINFO_varidx;
}
spinidx::spinidx(const ex & v, const ex & d, bool cov, bool dot) : inherited(v, d, cov), dotted(dot)
{
n.find_ex("value", value, sym_lst);
n.find_ex("dim", dim, sym_lst);
}
varidx::varidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
{
n.find_ex("value", value, sym_lst);
n.find_ex("dim", dim, sym_lst);
}
varidx::varidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
{
n.find_bool("covariant", covariant);
}
spinidx::spinidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
{
n.find_bool("covariant", covariant);
}
spinidx::spinidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
{
c.s << std::string(level, ' ') << class_name()
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
c.s << std::string(level, ' ') << class_name()
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
c.s << std::string(level, ' ') << class_name()
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
c.s << std::string(level, ' ') << class_name()
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
c.s << std::string(level, ' ') << class_name()
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
c.s << std::string(level, ' ') << class_name()
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
* must be such that dummy indices lie next to each other. */
int idx::compare_same_type(const basic & other) const
{
* must be such that dummy indices lie next to each other. */
int idx::compare_same_type(const basic & other) const
{
const varidx &o = static_cast<const varidx &>(other);
int cmpval = inherited::compare_same_type(other);
const varidx &o = static_cast<const varidx &>(other);
int cmpval = inherited::compare_same_type(other);
+bool varidx::match_same_type(const basic & other) const
+{
+ GINAC_ASSERT(is_a<varidx>(other));
+ const varidx &o = static_cast<const varidx &>(other);
+
+ if (covariant != o.covariant)
+ return false;
+ return inherited::match_same_type(other);
+}
+
const spinidx &o = static_cast<const spinidx &>(other);
// Check dottedness first so dummy indices will end up next to each other
const spinidx &o = static_cast<const spinidx &>(other);
// Check dottedness first so dummy indices will end up next to each other
- if (!is_ex_of_type(pattern, idx))
- return false;
- const idx &o = ex_to<idx>(pattern);
- if (!dim.is_equal(o.dim))
- return false;
- return value.match(o.value, repl_lst);
-}
+ GINAC_ASSERT(is_a<spinidx>(other));
+ const spinidx &o = static_cast<const spinidx &>(other);
-bool varidx::match(const ex & pattern, lst & repl_lst) const
-{
- if (!is_ex_of_type(pattern, varidx))
- return false;
- const varidx &o = ex_to<varidx>(pattern);
- if (covariant != o.covariant)
+ if (dotted != o.dotted)
-bool spinidx::match(const ex & pattern, lst & repl_lst) const
+/** By default, basic::evalf would evaluate the index value but we don't want
+ * a.1 to become a.(1.0). */
+ex idx::evalf(int level) const
- if (!is_ex_of_type(pattern, spinidx))
- return false;
- const spinidx &o = ex_to<spinidx>(pattern);
- if (dotted != o.dotted)
- return false;
- return inherited::match(pattern, repl_lst);
const idx &o = static_cast<const idx &>(other);
// Only pure symbols form dummy pairs, "2n+1" doesn't
const idx &o = static_cast<const idx &>(other);
// Only pure symbols form dummy pairs, "2n+1" doesn't
bool is_dummy_pair(const ex & e1, const ex & e2)
{
// The expressions must be indices
bool is_dummy_pair(const ex & e1, const ex & e2)
{
// The expressions must be indices