vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
1.15k stars 136 forks source link

strange behavior of result of order of vector definitions #376

Open Aradzh opened 3 years ago

Aradzh commented 3 years ago

In my form program I try to realize the id change of some vector combinations

v q1,q2,e1,e2,t1,vq1,v1,v2;

g Tst1  = q1.t1^2*e1.t1*e2.t1 ;
g Tst2  = q2.t1^2*e1.t1*e2.t1 ;

id (vq1?.t1)^2*t1.v2?*t1.v1?  = (vq1.vq1*v1.v2+v2.vq1*v1.vq1+v1.vq1*v2.vq1)*t1.t1*t1.t1/24 ;

Print +s;
Bracket t1 ;
.end

the result was as expected

   Tst1 =

       + t1.t1^2 * (
          + 1/24*q1.q1*e1.e2
          + 1/12*q1.e1*q1.e2
          );

   Tst2 =

       + t1.t1^2 * (
          + 1/24*q2.q2*e1.e2
          + 1/12*q2.e1*q2.e2
          );

However in my original code the definitions section is

v k,k1,q,p,p1,p2,p3,p4,p5,p6,q1,q2,q3,q4,l;
v v1,v2,v3,v4,v5,v6;
v e1,e2,ep1,ep2;
v vq1,vq2,vq3,vq4;
v t1,XX;  

and leads to wrong result (without id substitution )

   Tst1 =

       + q1.t1^2*e1.t1*e2.t1 * (
          + 1
          );

   Tst2 =

       + q2.t1^2*e1.t1*e2.t1 * (
          + 1
          );

if I change the order of lines in definition section - put four line to the first place

v vq1,vq2,vq3,vq4;
v k,k1,q,p,p1,p2,p3,p4,p5,p6,q1,q2,q3,q4,l;
v v1,v2,v3,v4,v5,v6;
v e1,e2,ep1,ep2;
v t1,XX;

result again becomes correct. Please find attached files in TstJp.zip - TstJp1.frm - correct result, TstJp2.frm - incorrect result, TstJp2a.frm - two lines interchanged in TstJp2.frm and correct result TstJp.zip

tueda commented 3 years ago

I think the root of the problem is a known issue of pattern matching. See also, for example,

To understand the problem, let's consider the following small example:

V p1,p2,v1,v2,t;
CF f;

L F = p1.t^2 * p2.t;
id v1?.t^2 * v2?.t = f(v1,v2);

P;
.end

which gives

   F =
      f(p1,p2);

because the term in the expression F matches with the pattern given as the left-hand side of the id statement.

Now, if I change the pattern a bit,

V p1,p2,v1,v2,t;
CF f;

L F = p1.t^2 * p2.t;
id v1?.t * v2?.t^2 = f(v1,v2);  * <-- LHS changed 

P;
.end

then the term doesn't match with the pattern, so leads to

   F =
      p1.t^2*p2.t;

You may think v1?.t^2 * v2?.t and v1?.t * v2?.t^2 are the same (up to the exchange of the wildcards v1 and v2). That should be true, but unfortunately FORM doesn't work with the latter in this case.

Note that the declaration order of vectors affects how terms (even with wildcards) are normalized (effectively, v1?.t^2 * v2?.t or v1?.t * v2?.t^2).

A workaround is to put elements that possibley match into function arguments:

V p1,p2,v1,v2,t;
CF f;
CF tmp(symmetric);

L F = p1.t^2 * p2.t;

id p1?.p2? = tmp(p1,p2);
id tmp(v1?,t) * tmp(v2?,t)^2 = f(v1,v2);

P;
.end

because a backtracking algorithm in pattern matching for products of functions is implemented in FORM. ToTensor may also be useful to put vectors into functions.

Aradzh commented 3 years ago

Thanks for description and workaround.