X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Findexed.cpp;h=bd41f44b0b38a271d243564c945d674bea9acaa3;hp=b8b70f7e9d5ae853649c85c709fb895182aaf91d;hb=ef2ed9a711c416722c34548015b4ae3621948c1c;hpb=3ac17e18ada69428fe170c10abcc5f33a30f0676 diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index b8b70f7e..bd41f44b 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -39,6 +39,7 @@ #include "utils.h" #include "integral.h" #include "matrix.h" +#include "inifcns.h" namespace GiNaC { @@ -317,6 +318,20 @@ ex indexed::eval(int level) const return ex_to(base).eval_indexed(*this); } +ex indexed::real_part() const +{ + if(op(0).info(info_flags::real)) + return *this; + return real_part_function(*this).hold(); +} + +ex indexed::imag_part() const +{ + if(op(0).info(info_flags::real)) + return 0; + return imag_part_function(*this).hold(); +} + ex indexed::thiscontainer(const exvector & v) const { return indexed(ex_to(symtree), v); @@ -1486,44 +1501,33 @@ ex expand_dummy_sum(const ex & e, bool subs_idx) pointer_to_map_function_1arg fcn(expand_dummy_sum, subs_idx); if (is_a(e_expanded) || is_a(e_expanded) || is_a(e_expanded)) { return e_expanded.map(fcn); - } else if (is_a(e_expanded) || is_a(e_expanded) || is_a(e_expanded)) { - exvector v = get_all_dummy_indices(e_expanded); - exvector::const_iterator it = v.begin(), itend = v.end(); - while (it != itend) { - varidx nu = ex_to(*it); - if (nu.is_dim_numeric()) { - ex en = 0; - for (int i=0; i < ex_to(nu.get_dim()).to_int(); i++) { - if (is_a(nu) && !subs_idx) { - en += e_expanded.subs(lst(nu == varidx(i, nu.get_dim(), true), nu.toggle_variance() == varidx(i, nu.get_dim()))); - } else { - en += e_expanded.subs(lst(nu == idx(i, nu.get_dim()), nu.toggle_variance() == idx(i, nu.get_dim()))); - } - } - return expand_dummy_sum(en, subs_idx); - } - ++it; - } - return e; - } else if (is_a(e_expanded)) { - exvector v = ex_to(e_expanded).get_dummy_indices(); - exvector::const_iterator it = v.begin(), itend = v.end(); - while (it != itend) { - varidx nu = ex_to(*it); - if (nu.is_dim_numeric()) { + } else if (is_a(e_expanded) || is_a(e_expanded) || is_a(e_expanded) || is_a(e_expanded)) { + exvector v; + if (is_a(e_expanded)) + v = ex_to(e_expanded).get_dummy_indices(); + else + v = get_all_dummy_indices(e_expanded); + ex result = e_expanded; + for(exvector::const_iterator it=v.begin(); it!=v.end(); ++it) { + ex nu = *it; + if (ex_to(nu).get_dim().info(info_flags::nonnegint)) { + int idim = ex_to(ex_to(nu).get_dim()).to_int(); ex en = 0; - for (int i=0; i < ex_to(nu.get_dim()).to_int(); i++) { - if (is_a(nu) && !subs_idx) { - en += e_expanded.subs(lst(nu == varidx(i, nu.get_dim(), true), nu.toggle_variance() == varidx(i, nu.get_dim()))); + for (int i=0; i < idim; i++) { + if (subs_idx && is_a(nu)) { + ex other = ex_to(nu).toggle_variance(); + en += result.subs(lst( + nu == idx(i, idim), + other == idx(i, idim) + )); } else { - en += e_expanded.subs(lst(nu == idx(i, nu.get_dim()), nu.toggle_variance() == idx(i, nu.get_dim()))); + en += result.subs( nu.op(0) == i ); } } - return expand_dummy_sum(en, subs_idx); - } - ++it; + result = en; + } } - return e; + return result; } else { return e; }