vermaseren / form

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

Parameters of expressions #384

Open FeelUsM opened 3 years ago

FeelUsM commented 3 years ago

Why this code works fine:

cfun f;
Symbol a,i,k;
.global
G G(k) = sum_(i,1,k,f(i));
.store

L L = G(a);
argument;
    id a=5;
endargument;
Print;
.end

but this code

cfun f;
Symbol a,i,k;
.global
G G(k) = sum_(i,1,k,f(i));
.store

L L = G(5);
Print;
.end

says Parameters of expression G don't match. ?

and one more question along the way: Is there any function like sum_ but for product (prod_(i,1,5,f(i)) -> f(1)*f(2)*f(3)*f(4)*f(5))?

tueda commented 3 years ago

I guess this is because 5 is not a symbol; you need to put a symbol as the parameter of G (which can be different from k).

Is there any function like sum but for product (prod(i,1,5,f(i)) -> f(1)f(2)f(3)f(4)f(5))?

Currently no, but hopefully in future: https://github.com/vermaseren/form/issues/201.

vermaseren commented 3 years ago

Good guess. There is a very simple workaround:

L L = G(k)*replace_(k,5);

This matching of these types of arguments is a bit tricky and one does not want to make the program infinitely complicated (and hence slower and more error prone). The replace_ function invokes basically the wildcard routines and is very powerful. It can be used for many things.

On 27 Apr 2021, at 15:58, Takahiro Ueda @.***> wrote:

I guess this is because 5 is not a symbol; you need to put a symbol as a parameter of G (which can be different from k).

Is there any function like sum but for product (prod(i,1,5,f(i)) -> f(1)f(2)f(3)f(4)f(5))?

Currently no, but hopefully in future: #201 https://github.com/vermaseren/form/issues/201.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/issues/384#issuecomment-827628051, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPCEUFHCAZJAJ72KG3FODTK27HVANCNFSM43VAV4SA.

FeelUsM commented 3 years ago

Is there more simple workaround for this code: ?

cfun f,S;
Symbol i,k;
.global

G G(k) = S(sum_(i,1,k,f(i)));
.store

L L = G(k);
argument;
    mul replace_(k,5);
endargument;
splitarg;
transform S,mulargs(1,last);
id S(a?) = a;
Print;
.end
vermaseren commented 3 years ago

If this is a workaround for the missing prod_ that could be as follows:

L F = prod(j,1,5,f(j)); id prod(j,?a) = prod(?a); we get rid of the first j. The replace_ later would mess it up. repeat; id prod(n1?,n1?,x?) = xreplace_(j,n1); id prod(n1?,n2?,x?) =prod(n1+1,n2,x)xreplace(j,n1); endrepeat;

This leaves the case that n1 > n2 for which you have to replace it by 1 presumably. This can be done in a single statement as well: id prod(n1?,n2?,x?) = prod(n1,n2,x)^theta_(n2-n1); Of course if this case can never happen, you can omit that statement.

On 27 Apr 2021, at 16:37, Feel @.***> wrote:

Is there more simple workaround for this code: ?

cfun f,S; Symbol i,k; .global

G G(k) = S(sum_(i,1,k,f(i))); .store

L L = G(k); argument; mul replace_(k,5); endargument; splitarg; transform S,mulargs(1,last); id S(a?) = a; Print; .end — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/issues/384#issuecomment-827657140, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPCESDVQVBO7WQO7NANZLTK3D2HANCNFSM43VAV4SA.

FeelUsM commented 3 years ago

Thankyou for lifehacks! I have one more question: why this example faults?: L L = S(sum_(i,1,k,f(i)))*replace_(k,5);

tueda commented 3 years ago

I have one more question: why this example faults?: L L = S(sum_(i,1,k,f(i)))*replace_(k,5);

Crashing by multiplying replace_ with nested functions sounds like a bug, maybe related to #106 or #307 etc. but haven't been fixed yet because of the special function sum_ there...

FYI: I wrote a FORM implementation of prod(i,1,5,f(i)) -> f(1)*f(2)*f(3)*f(4)*f(5) in https://github.com/vermaseren/form/issues/201#issuecomment-828203723.