vermaseren / form

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

Mystery of count_ in functions #167

Closed tueda closed 7 years ago

tueda commented 7 years ago

Consider the following example:

S x;
CF f;
L F = 1 + x + x^2;
multiply f(count_(x,1));
P;
.end

The intention is that count_ would get the power counting of x for each term in the expression F so that the result would be F = f(0) + f(1)*x + f(2)*x^2. But this could be wrong because count_ may be evaluated in the argument of f. Then count_ get replaced with 0 because there is no x in the argument. The result should be F = f(0) + f(0)*x + f(0)*x^2.

Now the problem is: both expectations are wrong. One gets

FORM 4.1 (Jan 21 2017, v4.1-20131025-294-g43ddc01) 64-bits  Run: Wed Feb  1 16:16:03 2017

   F =
      f(1) + f(1)*x + f(1)*x^2;

Sounds like somehow count_ gets 1. What is the origin of this behaviour?

By the way, the intended result can be obtained by putting it into a $-variable:

S x;
CF f;
L F = 1 + x + x^2;
$x = f(count_(x,1));
multiply $x;
P;
.end

giving

FORM 4.1 (Jan 21 2017, v4.1-20131025-294-g43ddc01) 64-bits  Run: Wed Feb  1 16:20:06 2017

   F =
      f(0) + f(1)*x + f(2)*x^2;