Re: Comparing terms of expression with Implied sum over indices

• To: mathgroup at smc.vnet.net
• Subject: [mg126604] Re: Comparing terms of expression with Implied sum over indices
• From: Christoph Lhotka <christoph.lhotka at fundp.ac.be>
• Date: Fri, 25 May 2012 04:53:43 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```Hello,

it depends on the actual form of your expressions, a possible
way to do it is the following:

Let assume two more complex expressions of the form

expr1=Sum[f[i,j] g[i+j]/(i-j)!,{i,imin},{j,jmin,jmax}];
expr2=Sum[f[l,m] g[l+m]/(l-m)!,{l,lmax},{m,mmin,mmax}];

To check if expr1==expr2 we compare sub-expression by sub-expression:

expr12=Transpose[{expr1,expr2}/.Sum[arg_,args__]:>{arg,args}]
{{(f[i,j] g[i+j])/(i-j)!,(f[l,m]
g[l+m])/(l-m)!},{{i,imin},{l,lmax}},{{j,jmin,jmax},{m,mmin,mmax}}}

A necessary but not sufficient requirement is that the first element of
expre12 is equal:

con1=Equal@@expr12[[1]]
(f[i,j] g[i+j])/(i-j)!==(f[l,m] g[l+m])/(l-m)!

An additional set of conditions must be fulfilled to make con1 true:

con2=Equal@@#&/@Flatten[Transpose/@Rest[expr12],1]
{i==l,imin==lmax,j==m,jmin==mmin,jmax==mmax}

Let's  make a set of rules out of con2:

rul12=Rule@@#&/@Flatten[Transpose/@Rest[expr12],1]
{i->l,imin->lmax,j->m,jmin->mmin,jmax->mmax}

And apply it to con1:

{con1/.rul12,con2}
{True,{i==l,imin==lmax,j==m,jmin==mmin,jmax==mmax}}

In words: expr1==expr2 under the condition con2. Alternatively you
could use the built in function Simplify together with the assumptions
defined by con2:

Simplify[expr1==Assuming[con2,expr1]]
True

Now the question is how to go on from this point.  First, above can be
easily
merged to a unique function, which returns con2 just and only if it renders
con1 true:

aux[expr1_,expr2_]:=Module[{con1,con2,expr12,rul12,arg,args},
expr12=Transpose[{expr1,expr2}/.Sum[arg_,args__]:>{arg,args}];
con1=Equal@@expr12[[1]];
con2=Equal@@#&/@Flatten[Transpose/@Rest[expr12],1];
rul12=Rule@@#&/@Flatten[Transpose/@Rest[expr12],1];
If[Simplify[expr1==Assuming[con2,expr1]],con2,False],
False]]

Notice that aux is just valid for a very specific type of expressions
and an additional test has to be made to check that expr1 and expr2
are of the correct "expressional structure" to be compared by aux,
e.g. something like:

aux2[expr1_, expr2_] :=

which should be defined to avoid that aux will compare expressions of
different expressional structure yielding unpredictable results. Maybe
expr1, expr2 can be brought into the same (normal)form so I would
also define a function putting expressions in normal form:

aux3[expr_] := FullSimplify[expr]

Now, I would collect the above to define one unique function, say IfEqual:

IfEqual[expr1_, expr2_] := Module[{nexpr1, nexpr2},
nexpr1 = aux3[expr1];
nexpr2 = aux3[expr2];
If[aux2[nexpr1, nexpr2], aux[nexpr1, nexpr2], nexpr1 == nexpr2]]

which returns the assumptions which need to be made
to evaluate expr1==expr2 to true.

Another story is of course to check if the assumptions returned by IfEqual
are consistent with other calculations...

Hope that helps,

Christoph

On 05/24/2012 09:33 AM, tom u wrote:
> Does anyone know of a general method to compare terms so that one can simplify expressions with terms that are sums over indices where the the index variables are different?  For example, following expression should symbolically equal 0:
>
> Sum[f[i],{i,imax}] - Sum[f[j],{j,imax}]
>
> The terms with sums can be more complicated and also implicit as in the case of tensor notation.  The goal is to have an automatic way to Simplify tensor equations that use different dummy indices.
>
> Thank you
>

```

• Prev by Date: Re: Question about ColorFunction
• Next by Date: Re: bubblechart axis scaling
• Previous by thread: Comparing terms of expression with Implied sum over indices
• Next by thread: Re: Comparing terms of expression with Implied sum over indices