vermaseren / form

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

Beginner Q: functions with vector arguments #237

Closed fetchinson closed 6 years ago

fetchinson commented 6 years ago

If I have a momentum-dependent expression (propagator, vertex, etc.) is it possible to define it once and use it later with various arguments? I have something like this in mind (pseudo code):

Symbol t;
Indices a,b,c,d;
Vectors p1, p2, p3, p4, p, q;

* define the vertex generally
vertex(p1,p2,p3,p4,a,b,c,d) = p1(a)*p2(b)*d_(c,d) + p3(c)*p4(d)*d_(a,b);

* use it later with various arguments
vertex(p+t*q,p-t*q,p,q,a,b,c,d)*vertex(p,q,p-t*q,q-t*p,a,b,c,d)

So I'd like to avoid typing the vertex as many times as I use it with different arguments. I know this must be a very beginner's question but haven't found a way of doing it.

tueda commented 6 years ago

Functions in FORM are just objects with arguments. They are not functions in functional programming or other computer algebra systems. (But, advanced answer: see section 2.6 "Zero-dimensional sparse tables as pure functions" of arXiv:1707.06453.)

Maybe what you want is just an expansion like this?

CFunction vertex;
Symbol t;
Index a,b,c,d;
Vector p1,p2,p3,p4,p,q;
Local F = vertex(p+t*q,p-t*q,p,q,a,b,c,d)*vertex(p,q,p-t*q,q-t*p,a,b,c,d);
id vertex(p1?,p2?,p3?,p4?,a?,b?,c?,d?) = p1(a)*p2(b)*d_(c,d) + p3(c)*p4(d)*d_(a,b);
Print +s;
.end
   F =
       + 5*p.p*p.q
       - 4*p.p*p.q*t
       + p.p*p.q*t^2
       + 4*p.p*q.q
       - 5*p.p*q.q*t
       + p.p*q.q*t^3
       - p.p^2*t
       - 4*p.q*q.q*t
       - 5*p.q*q.q*t^2
       - p.q*q.q*t^4
       + p.q^2
       + 4*p.q^2*t
       + 4*p.q^2*t^2
       + q.q^2*t^3
      ;

You can make the substitution be a procedure if you want to call it many times later:

CFunction vertex;
Symbol t;
Index a,b,c,d;
Vector p1,p2,p3,p4,p,q;

#procedure ExpandVertex()
  id vertex(p1?,p2?,p3?,p4?,a?,b?,c?,d?) = p1(a)*p2(b)*d_(c,d) + p3(c)*p4(d)*d_(a,b);
#endprocedure

Local F = vertex(p+t*q,p-t*q,p,q,a,b,c,d)*vertex(p,q,p-t*q,q-t*p,a,b,c,d);
#call ExpandVertex()
Print +s;
.end
fetchinson commented 6 years ago

Fantastic, thanks a lot!