vermaseren / form

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

brackets in symbol substitution #469

Open jmbrod opened 4 months ago

jmbrod commented 4 months ago

Hi, another quick question of no urgency. Just came across this behaviour:

s x,y;
cf fun;

l exp = x^2;

id x?^y?pos_ = fun(x^y);

print +s;
.end

yields + fun(x^2) as expected, while enclosing the symbol in brackets within the substitution rule leaves it unsubstituted:

s x,y;
cf fun;

l exp = x^2;

id (x?)^y?pos_ = fun(x^y);

print +s;
.end

yields + x^2. Removing the restriction to the set in the exponent, it does get substituted:

s x,y;
cf fun;

l exp = x^2;

id (x?)^y? = fun(x^y);

print +s;
.end

gives + fun(x^2). I was just wondering about the reason, because it seems that including the brackets, though of course not necessary, is not wrong?

Thanks,

Joachim

tueda commented 4 months ago

For your 3rd example, both v4.3.1 and v5.0.0-beta.1-19-g6531a25 gave me the unsubstituted answer, + x^2.

Anyway, x?^y? and (x?)^y? are completely different objects. The former is an integer power of some symbol (note that x and y are declared as symbols). The latter is equivalent to exp_(x?,y?) (you can see this by turning on the codes switch, namely On codes; and comparing what is printed for the left-hand side with id (x?)^y? = ... and id exp_(x?,y?) = ...), meaning an arbitrary power of some subexpression. This matches with, for example, (1+x)^(1+y) but doesn't for x^2.

jmbrod commented 4 months ago

Thanks, I was not aware of this!

(And indeed, my 3rd example gives the unsubstituted answer, it was my mistake.)