patch for
Chris Dams
chrisd at sci.kun.nl
Wed Jan 28 13:13:07 CET 2004
Hi,
I found that the code
ex e=indexed(a+b*(c+d),idx(i,3));
e=e.expand(expand_options::expand_indexed);
cout << e << endl;
cout << e.expand(expand_options::expand_indexed) << endl;
gives the output
a.i+(d*b+c*b).i
(c*b).i+a.i+(d*b).i
I would have expected to see the second result twice instead. A patch is
attached.
Bye,
Chris
-------------- next part --------------
Index: indexed.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/indexed.cpp,v
retrieving revision 1.88
diff -r1.88 indexed.cpp
328,333c328,339
< if ((options & expand_options::expand_indexed) && is_exactly_a<add>(seq[0])) {
<
< // expand_indexed expands (a+b).i -> a.i + b.i
< const ex & base = seq[0];
< ex sum = _ex0;
< for (size_t i=0; i<base.nops(); i++) {
---
> if (options & expand_options::expand_indexed) {
> ex newbase=seq[0].expand(options);
> if(is_exactly_a<add>(newbase)) {
> ex sum = _ex0;
> for (size_t i=0; i<newbase.nops(); i++) {
> exvector s = seq;
> s[0] = newbase.op(i);
> sum += thiscontainer(s).expand(options);
> }
> return sum;
> }
> if(!are_ex_trivially_equal(newbase, seq[0])) {
335,336c341,342
< s[0] = base.op(i);
< sum += thiscontainer(s).expand();
---
> s[0] = newbase;
> return ex_to<indexed>(thiscontainer(s)).inherited::expand(options);
338,341c344,345
< return sum;
<
< } else
< return inherited::expand(options);
---
> }
> return inherited::expand(options);
More information about the GiNaC-devel
mailing list