Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about addargs #277

Closed
vsht opened this issue Apr 11, 2018 · 6 comments
Closed

A question about addargs #277

vsht opened this issue Apr 11, 2018 · 6 comments
Labels
bug Something isn't working

Comments

@vsht
Copy link

vsht commented Apr 11, 2018

Could someone please explain me how to deal with cases where the application of addargs creates a function with zero arguments?

Consider for example

CFunction f,g,h;
S x,y;
Local test = f(-1,1)*g(2);
Transform f addargs(1,last);
Print +s;
.sort
id f(x?{>=0,<=0}) = 0;
id f(x?neg0_) = 0;
id f(0) = 0;
id f() = 0;
id f = 0;
Print +s;
.end

Actually I would expect to see f(0) instead of f(), but perhaps it is some FORM convention. Now none of the obvious id statements I tried allows me to pick up this f() and transform it into something else (e.g. set it to zero). On the other hand, this

id f(x?) = g(10,x);

and this

id f(x?)*g(y?) = h(x,y);

rule obviously work and return a correct result, while this

id f(?x)*g(y?) = h(y,?x);

creates a weird h(2,).

I wonder whether I'm missing something here or if this behavior is a consequence of a bug.

@vermaseren
Copy link
Owner

vermaseren commented Apr 11, 2018 via email

@vsht
Copy link
Author

vsht commented Apr 12, 2018

Hi Jos,

thanks a lot, now it works as expected!

Just a small related question: Why is it actually not to possible to do

CFunction f;
S x;
Local test = f(-1,1);
Transform f addargs(1,last);
id f(x?{0}) = 0;
Print +s;
.end

while the funny workaround with

id f(x?{<=0,>=0}) = 0;

works nonetheless? A similar code with a symbolic set element works as well

CFunction f;
S x,y;
Local test = f(y);
id f(x?{y}) = 0;
Print +s;
.end

Cheers,
Vladyslav

@vermaseren
Copy link
Owner

vermaseren commented Apr 12, 2018 via email

@vsht
Copy link
Author

vsht commented Apr 12, 2018

Hi Jos,

my bad, I should have studied the chapter about the preprocessor calculator more carefully.

Actually, my original motivation to use addargs was to find a fast way to add arguments of function products like f(a,b,c)*f(d,e,f) -> f(a+d,b+e,c+f).

The naive approach

cfunction f;
Autodeclare symbol xx,yy;
Autodeclare cfunction ff;

#define NP "8"

Local test = (f(1,0,2,3,7,1,5,2)+f(1,1,0,3,4,1,2,2))^10*(f(1,-1,0,-3,2,1,-5,0)+f(1,2,0,3,4,1,-2,-2))^12*(f(-1,0,0,-2,3,0,0,0)+f(0,0,0,0,0,0,-1,-1))^23;

repeat;
id f(<xx1?int_>,...,<xx`NP'?int_>)*f(<yy1?int_>,...,<yy`NP'?int_>) = f(<xx1+yy1>,...,<xx`NP'+yy`NP'>);
endrepeat;
.end

is painfully slow and hence not good. With addargs the same calculation becomes much faster

cfunction f;
Autodeclare symbol xx,yy;
Autodeclare cfunction ff;

#define NP "8"

Local test = (f(1,0,2,3,7,1,5,2)+f(1,1,0,3,4,1,2,2))^10*(f(1,-1,0,-3,2,1,-5,0)+f(1,2,0,3,4,1,-2,-2))^12*(f(-1,0,0,-2,3,0,0,0)+f(0,0,0,0,0,0,-1,-1))^23;

id f(<xx1?int_>,...,<xx`NP'?int_>) =  <ff1(xx1)>*...*<ff`NP'(xx`NP')>;

#do i=1,`NP'
  chainin ff`i';
#enddo

#do i=1,`NP'
  transform ff`i', addargs(1,last);
#enddo

id <ff1(xx1?)>*...*<ff`NP'(xx`NP'?)> = ff(<xx1>,...,<xx`NP'>);
.end

Probably it can be made even faster without using addargs (otherwise the bug I have reported would have been discovered much earlier), but I was not able to find a more direct way to add the arguments in one step.

Cheers,
Vladyslav

@vsht vsht closed this as completed Apr 12, 2018
@vermaseren
Copy link
Owner

vermaseren commented Apr 12, 2018 via email

@tueda tueda added the bug Something isn't working label Apr 13, 2018
@vsht
Copy link
Author

vsht commented Apr 13, 2018

Dear Jos,

many thanks! It's always amazing to learn new tricks that make FORM work even faster than anticipated.

Cheers,
Vladyslav

tueda added a commit that referenced this issue Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants