(**  
     FeynMultiplication.m : manipulating Feynman amplitudes  
**)

BeginPackage["FeynMultiplication`","FeynArts`"]

FeynMultiplication::usage ="
applied to a topology with PV- and SpinorChain-functions constructs \n
the analytical expressions as `FeynAmp[ scalars * spinorchains ]'."

Begin["`Private`"]

SpCrule1 = { 
	  SpinorChain[ PV[ NonCommutative[ gp1__ ]  sc1_. ] ,
               PV[ NonCommutative[ gp2__ ]  sc2_. ] , sth___ ] :>
          SpinorChain[ PV[ NonCommutative[ gp1 , gp2 ]  sc1 sc2 ] , sth ],
	  SpinorChain[ PV[ sc1_ ] ,
               PV[ NonCommutative[ gp2__ ]  sc2_. ] , sth___ ] :>
          SpinorChain[ PV[ NonCommutative[ gp2 ]  sc1 sc2 ] , sth ],
	  SpinorChain[ PV[ NonCommutative[ gp1__ ]  sc1_. ] ,
               PV[  sc2_ ] , sth___ ] :>
          SpinorChain[ PV[ NonCommutative[ gp1 ]  sc1 sc2 ] , sth ]
	   }

SpCrule2 =	   
          SpinorChain[ PV[ NonCommutative[ sth___ ]  scal_. ] ] :> 
              PV[ SpinorChain[ sth ]  scal ]

Multrule = {
	   Topology[sym_][ pat:PV[ _ ].. ]:>
	   FeynAmp[ Times[ sym ,
		  (Times[pat]/.PV->Times) ] ]
	   }
	   

FeynMultiplication[ tt:Topology[_][__] ] := 
		     tt//.SpCrule1//.SpCrule2/.Multrule

End[]

EndPackage[]

