[GiNaC-devel] [PATCH 5/5, GiNaC 1.3] introduce
expand_options::expand_idx_rename and use it in mul::expand().
Alexei Sheplyakov
varg at theor.jinr.ru
Mon Sep 17 17:05:24 CEST 2007
Helps to avoid useless (and expansive) rename_dummy_indices_uniquely().
---
ginac/flags.h | 3 ++-
ginac/mul.cpp | 10 +++++++---
ginac/power.cpp | 7 ++++++-
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/ginac/flags.h b/ginac/flags.h
index 33622f9..478da32 100644
--- a/ginac/flags.h
+++ b/ginac/flags.h
@@ -30,7 +30,8 @@ class expand_options {
public:
enum {
expand_indexed = 0x0001, ///< expands (a+b).i to a.i+b.i
- expand_function_args = 0x0002 ///< expands the arguments of functions
+ expand_function_args = 0x0002, ///< expands the arguments of functions
+ expand_rename_idx = 0x0004 ///< used internally by mul::expand()
};
};
diff --git a/ginac/mul.cpp b/ginac/mul.cpp
index d6ff7cb..b7e0e82 100644
--- a/ginac/mul.cpp
+++ b/ginac/mul.cpp
@@ -950,9 +950,13 @@ ex mul::expand(unsigned options) const
return (new mul(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
}
- const bool skip_idx_rename = ! info(info_flags::has_indices);
- if (skip_idx_rename)
- ++(mul_expand_stats::n_indexless);
+ // do not rename indices if the object has no indices at all
+ if ((!(options & expand_options::expand_rename_idx)) &&
+ this->info(info_flags::has_indices))
+ options |= expand_options::expand_rename_idx;
+
+ const bool skip_idx_rename = !(options & expand_options::expand_rename_idx);
+
// First, expand the children
std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);
diff --git a/ginac/power.cpp b/ginac/power.cpp
index 010af6c..42e14c1 100644
--- a/ginac/power.cpp
+++ b/ginac/power.cpp
@@ -918,8 +918,13 @@ ex power::expand_mul(const mul & m, const numeric & n, unsigned options, bool fr
return _ex1;
}
+ // do not bother to rename indices if there are no any.
+ if ((!(options & expand_options::expand_rename_idx))
+ && m.info(info_flags::has_indices))
+ options |= expand_options::expand_rename_idx;
// Leave it to multiplication since dummy indices have to be renamed
- if (m.info(info_flags::has_indices) && (get_all_dummy_indices(m).size() > 0) && n.is_positive()) {
+ if ((!(options & expand_options::expand_rename_idx)) &&
+ (get_all_dummy_indices(m).size() > 0) && n.is_positive()) {
ex result = m;
for (int i=1; i < n.to_int(); i++)
result *= rename_dummy_indices_uniquely(m,m);
--
1.5.2.4
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-devel/attachments/20070917/a65f0de1/attachment.pgp
More information about the GiNaC-devel
mailing list