vermaseren / form

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

Behavior of implicit sets containing linear combinations of vectors #458

Open vsht opened 10 months ago

vsht commented 10 months ago

Hi,

as I understand, FORM actually only supports implicit vectors sets where each element is a single vector. Nevertheless, the following code "works" with a somewhat unexpected result:

off statistics;

CF prop, F;
S mq, s;
Auto V k,p, v;

L amp = prop(k1,mq)*prop(-k1+k2,mq)*prop(k3,mq)*prop(k1-p1+k2,0);
id prop(v?{k1,-k1, k2,-k2,k1+k2,k1-k2,-k1-k2,-k1+k2,k3,-k3},mq) = prop(v,mq)*F(v);

print;
.end

yields

amp =
      prop(k1,mq)*prop(k3,mq)*prop( - k1 + k2,mq)*prop(k1 + k2 - p1,0)*F(k1)*
      F(k3);

It seems that in this case the compiler interprets {k1,-k1, k2,-k2,k1+k2,k1-k2,-k1-k2,-k1+k2,k3,-k3} as {k1,-k1, k2,-k2,k1,k2,k1,-k2,-k1,-k2,-k1,+k2,k3,-k3} which can be confirmed by trying to write an id statement that uses the position of the element in a set

id prop(v?{k1,-k1, k2,-k2,k1+k2,k1-k2,-k1-k2,-k1+k2,k3,-k3}[n],mq) = prop(v,mq)*F({1,2,3,4,5,6,7,8,9,10}[n]);

leads to

Array bound check during set substitution
    value is 13

Is this behavior mentioned somewhere in a manual, or would one rather classify it as a bug?

Cheers, Vlad

tueda commented 10 months ago

In a discussion of Issue #78, Jos said

Vector sets can only consist of vectors like p, not -p.

So, I guess there was an implicit assumption that the definition of a set in the reference manual,

A set is a (non-empty) collection of variables that should all be of the same type.

was also applied to implicitly declared sets; sums of variables are not expected. Then, it was extended to allow "minus vectors" like -p in v4.2.0.

Indeed, usual Set statements and implicitly declared sets seem to share the parser (which sounds reasonable); the same happens also for usual set declarations.

On names;
V p1,p2;
Set pp: p1,p2,p1+p2;
.end

and

On names;
V p1,p2;
CF f;
id f(p1?{p1,p2,p1+p2}) = 1;
.end

are accepted by FORM but print the set as p1 p2 p1 -p2. Interestingly, the last element of the set (-p2) has a minus sign. If I change Vectors to Symbols,

S p1,p2;
Set pp: p1,p2,p1+p2;
.end

then this gives an error:

test.frm Line 2 --> Illegal use of - sign in set. Can use only with vector or n
umber

which sounds like the routine is very "optimized" to parse minus vectors.

Having said that, FORM should give appropriate errors if they are not allowed (as Ben said in #78), so I would call it a kind of "bug".