Functions Introduction and Examples

Brett van de Sande
March 18, 1992

Functions.m is a general purpose package centered around the function 
ipoly[f,x,a,b] which integrates f over an arbitrary polytope with finite volume.  
It includes routines for linear coordinate transforms, handling delta functions, 
moving the integration to the inside or outside of an expression and evaluating 
the integral for some or all of the coordinates.  The polytope is described by 
the J inequalities a.x<=b where x is the n dimensional coordinate vector, a is a 
J by n matrix and b is a J-vector.  (ipoly, transform, translate, rotate, 
ipolyexpand, ipolyfactor, delta Big, showpoly, TestValue and convert)

In the same manner, it defines the summation function sum[?] which works like 
Sum[?].  It includes routines for handling Kronecker delta functions and moving 
the summation to the inside or outside of expressions and evaluating the 
summation for some or all of the coordinates.  (sum, sumexpand, sumfactor, 
delta, and convert)

The complex conjugate operator is extended to handle algebraic expressions and a 
normal ordering operator NormalOrder is defined. (NormalOrder)

There are also rules for expanding expressions involving Dot and 
NonCommutativeMultiply.  The trace of a matrix is defined.  (Dotexpand, 
timesexpand, trace, CnumberQ, ScalarQ)

I am a graduate student in the Ohio State University department of physics where 
I am specializing in Quantum Field theory.  I wrote this package to help with 
some rather long algebraic calculations in Light Cone QCD.  Although, this 
package provides a mathematical framework for defining the physical theory, none 
of the physics itself has been included.
I may be contacted by E-mail at vandesande@ohstpy or by phone at 614 292 0556.

<<Functions.m

Extensions to Replace and ReplaceRepeated

Define a rule that is automatically associated with Plus for the purposes of 
pattern matching.

rule=g[a_]+g[b_]:>g[a+b];

When the rule is used, Mma tries to apply the rule to all occurances of Plus, 
taking a large amount of time for large expressions:

tt=Sum[g[h[i]],{i,1,250}];
Timing[tt//.rule;]

Using the extension to ReplaceRepeated applies the rule only to expressions 
containing g as a subexpression, using much less time:

Timing[tt//.(rule,g);]

An example where this is a real time saver is in the application of sumfactor or 
ipolyfactor to very large expressions.

Extensions to inequalities and Sign

Use TestValue do define a numerical value for various quantities.

f/:TestValue[f]=1;
g/:TestValue[g]=2;
h/:TestValue[h]=-3/2;

When an inequality or Sign is evaluated, the TestValue of any symbols are used.

f<=2-g

f h<g

Sign[f+g+h]

The expression is left unevaluated if TestValue does not return a number.

i<h

This can be quite useful for integrations which use Sign internally

Integrate[1/(x^2+h),x]

Integrate[1/(x^2+g),x]

Integrate over polytopes

Define a polytope; the inequalities must use LessEqual and be linear in the 
coordinates.  The output form does not display the limits explicitly.

ipoly[
	a f[x,y] delta[2 x-y]+g[x,y],
	{x,y},
	{0<=x,x<=1-y,-1<=y,x+2 y<=2}
]

Use showpoly to see the inequalities that define the polytope.  Note that any 
unneeded inequalities are removed.

showpoly[%]

Use transform to make a linear coordinate transform

transform[%,{x+y,x/2-y/2}]

ipolyexpand moves ipoly to the inside of an expression as much as possible, 
removing delta functions.  It can also handle expressions involving 
NonCommutativeMultiply and Dot.

%//.ipolyexpand

ipolyfactor moves ipoly to the outside of the expression as much as possible.  
It can also handle expressions involving NonCommutativeMultiply and Dot.  Use 
%//.(ipolyfactor,ipoly) for very large expressions.

%//.ipolyfactor

convert converts some or all of the coordinates to a format suitable for the 
internal function Integrate.

convert[%[[2]],Integrate,{2}]

Using Big, one can define integrals from -Infinity to Infinity.  Any symbol used 
in defining the polytope (such as bb below) must have a TestValue assigned to 
it:

bb/:TestValue[bb]=5;
ipoly[
	f[p,q] Exp[I k c(p-q)],
	{p,q,k},
	{0<=p,0<=q,p+q<=2 bb-1,k<=Big,-Big<=k}
]

Dirac delta functions are produced in the correct manner,

convert[%,Integrate,{3}]

ipolyfactor also combines various products of ipoly,

ipoly[f[x],{x},{0<=x,x<=1}]*
ipoly[g[x],{x},{1<=x,x<=2}]//.ipolyfactor

Summations

sum evaluates the summations from left to right.

sum[
	g[i,j,k]+a delta[i,j] f[i,j,k],
	{i,1,k},{j,1,k},{k,1,5}
]

ipolyexpand moves ipoly to the inside of an expression as much as possible, 
removing Kronecker delta functions.  It can also handle expressions involving 
NonCommutativeMultiply and Dot.  It handles only the simplest delta functions.

%//.sumexpand

ipolyfactor moves ipoly to the outside of the expression as much as possible.  
It can also handle expressions involving NonCommutativeMultiply and Dot.  Use 
%//.(sumfactor,sum) for very large expressions.

%//.sumfactor

convert converts some or all of the coordinates to a format suitable for the 
internal function Sum.

convert[%[[2]],Sum,{2}]

sumfactor also combines various products of sums.

sum[f[i],{i,1,3,1/2}] sum[g[i],{i,2,5}]/.sumfactor

Manupulating non-commutative symbols

Define some symbols to be noncommutative:

c1/:CnumberQ[c1]=False;
c2/:CnumberQ[c2]=False;
c3/:CnumberQ[c3]=False;

timesexpand will simplify expressions involving NonCommutativeMultiply

(2 c1)**(c1+c2**a**c3)**c1//.timesexpand

Conjugate works for algebraic expressions:

Conjugate[%]

A normal ordering operator is defined in a manner consistant with standard 
creation and annihilation operators used in quantum mechanics.  The hermetian 
conjugates must be explicit.

NormalOrder[c2**Conjugate[c3]**c1]

In a similar way nonscalar symbols can be defined for Dot

s1/:ScalarQ[s1]=False;
s2/:ScalarQ[s2]=False;

Dotexpand expands expressions involving Dot allowing for the case of 
non-commuting symbols

(c3 s1).(c2 s2+s1 a)//.Dotexpand

%//.timesexpand

trace is also expanded by Dotexpand

trace[s1.(a s2+s1)]//.Join[Dotexpand,timesexpand]