]> www.ginac.de Git - ginac.git/commitdiff
Bug in expand_dummy_sum is fixed.
authorChris Dams <Chris.Dams@mi.infn.it>
Sat, 29 Jul 2006 02:34:27 +0000 (02:34 +0000)
committerChris Dams <Chris.Dams@mi.infn.it>
Sat, 29 Jul 2006 02:34:27 +0000 (02:34 +0000)
doc/tutorial/ginac.texi
ginac/container.h
ginac/indexed.cpp
ginac/indexed.h
ginac/inifcns.cpp

index bdea81b80a842aa0c6c71a5b193dbcf8e8754f60..9f2abc1c86cb4f12a2125ae3714eb25e79f98358 100644 (file)
@@ -2729,11 +2729,7 @@ arithmetic class, you just pass it to @code{simplify_indexed()}):
 The @code{scalar_products} object @code{sp} acts as a storage for the
 scalar products added to it with the @code{.add()} method. This method
 takes three arguments: the two expressions of which the scalar product is
-taken, and the expression to replace it with. After @code{sp.add(A, B, 0)},
-@code{simplify_indexed()} will replace all scalar products of indexed
-objects that have the symbols @code{A} and @code{B} as base expressions
-with the single value 0. The number, type and dimension of the indices
-don't matter; @samp{A~mu~nu*B.mu.nu} would also be replaced by 0.
+taken, and the expression to replace it with.
 
 @cindex @code{expand()}
 The example above also illustrates a feature of the @code{expand()} method:
index 28cf05e44546ee511ad8d888a2d046fb63afe634..7f9210027d9779c2974d794e9b0c6ee5c2779310 100644 (file)
@@ -129,6 +129,7 @@ template <template <class> class C>
 class container : public basic, public container_storage<C> {
        GINAC_DECLARE_REGISTERED_CLASS(container, basic)
 
+protected:
        typedef typename container_storage<C>::STLT STLT;
 
 public:
index 26867dcbfc4d9f424b622741ec8bbb6d9a215eb2..bd41f44b0b38a271d243564c945d674bea9acaa3 100644 (file)
@@ -1501,44 +1501,33 @@ ex expand_dummy_sum(const ex & e, bool subs_idx)
        pointer_to_map_function_1arg<bool> fcn(expand_dummy_sum, subs_idx);
        if (is_a<add>(e_expanded) || is_a<lst>(e_expanded) || is_a<matrix>(e_expanded)) {
                return e_expanded.map(fcn);
-       } else if (is_a<ncmul>(e_expanded) || is_a<mul>(e_expanded) || is_a<power>(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<varidx>(*it);
-                       if (nu.is_dim_numeric()) {
-                               ex en = 0;
-                               for (int i=0; i < ex_to<numeric>(nu.get_dim()).to_int(); i++) {
-                                       if (is_a<varidx>(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<indexed>(e_expanded)) {
-               exvector v = ex_to<indexed>(e_expanded).get_dummy_indices();
-               exvector::const_iterator it = v.begin(), itend = v.end();
-               while (it != itend) {
-                       varidx nu = ex_to<varidx>(*it);
-                       if (nu.is_dim_numeric()) {
+       } else if (is_a<ncmul>(e_expanded) || is_a<mul>(e_expanded) || is_a<power>(e_expanded) || is_a<indexed>(e_expanded)) {
+               exvector v;
+               if (is_a<indexed>(e_expanded))
+                       v = ex_to<indexed>(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<idx>(nu).get_dim().info(info_flags::nonnegint)) {
+                               int idim = ex_to<numeric>(ex_to<idx>(nu).get_dim()).to_int();
                                ex en = 0;
-                               for (int i=0; i < ex_to<numeric>(nu.get_dim()).to_int(); i++) {
-                                       if (is_a<varidx>(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<varidx>(nu)) {
+                                               ex other = ex_to<varidx>(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;
        }
index bbe94005672424dcb1805b0422150d9802228469..30719e7c38a80a8e6ffcdf14600288c63ed9912a 100644 (file)
@@ -270,7 +270,7 @@ lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb);
 
 /** This function returns the given expression with expanded sums
  *  for all dummy index summations, where the dimensionality of 
- *  the dummy index is numeric.
+ *  the dummy index is a nonnegative integer.
  *  Optionally all indices with a variance will be substituted by 
  *  indices with the corresponding numeric values without variance.
  *
index dad9d9e7702b1424300204de0acdc47c967f962b..f7821ed69efa01e7ee05fe5850327d980008ed9f 100644 (file)
@@ -884,7 +884,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options)
        
        // syntax checks
        if (!eqns.info(info_flags::list)) {
-               throw(std::invalid_argument("lsolve(): 1st argument must be a list"));
+               throw(std::invalid_argument("lsolve(): 1st argument must be a list or an equation"));
        }
        for (size_t i=0; i<eqns.nops(); i++) {
                if (!eqns.op(i).info(info_flags::relation_equal)) {
@@ -892,7 +892,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options)
                }
        }
        if (!symbols.info(info_flags::list)) {
-               throw(std::invalid_argument("lsolve(): 2nd argument must be a list"));
+               throw(std::invalid_argument("lsolve(): 2nd argument must be a list or a symbol"));
        }
        for (size_t i=0; i<symbols.nops(); i++) {
                if (!symbols.op(i).info(info_flags::symbol)) {