If you are using FeynCalc in your research activities on a regular basis, sooner or later you will encounter situations, where FeynCalc is missing something that you need. Provided that you have some knowledge in Mathematica programming, you can in principle extend FeynCalc with whatever you want, where the only limits are your skills and the amount of time you want to invest into it.
Here we collect some tips and recommendations for extending/modifying FeynCalc
To improve the code quality of FeynCalc and avoid new bugs or
regressions we employ a large number of unit tests. The
tests are written using Mathematica’s native framework
MUnit
and can be found in the Tests
directory of the FeynCalc repository
The unit tests are useful not only for the developers. If you are modifying the source code of FeynCalc for your own needs or using FeynCalc together with other packages on the same kernel, it might be useful to check if FeynCalc is still working properly. This can be done by running the test suite and analyzing the results.
In general, it is not a very good idea to modify the source code of FeynCalc directly, since this may give you a lot of troubles when updating to a newer version. Also, there is a fair chance to break existing functionality which might lead to erroneous results. However, for some deep modifications this might be sometimes necessary.
Still, if you think that the feature that you want to implement could be useful also for other people, it won’t harm to publish your request on the mailing list.
$FeynCalcDirectory
directory. The package is loaded via the
FeynCalc.m
file.FeynCalc.m
there is a code snippet that starts with
boostrappingList = ...
. This is where different parts of
the FeynCalc package are loaded. Those parts are contained in different
directories inside $FeynCalcDirectory
(e.g. Shared
, NonCommAlgebra
,
Lorentz
) depending on their purpose. Every .m file from
those directories is loaded into Mathematica.Starting with the version 9.0, FeynCalc features a new add-on system. The purpose of add-ons is to extend FeynCalc with new features without the need to modify FeynCalc itself.
The add-ons are placed in the directory AddOns
inside
$FeynCalcDirectory
. They are loaded in the same fashion as
regular FeynCalc objects and functions and live in the context
FeynCalc`NameOfTheAddon`
.
A toy add-on FVProjection
that represents a minimal working example is shipped together with
FeynCalc. You can use its source code as a template for writing your own
addons. The general structure of the main .m file
(e.g. MyAddon.m
) for an add-on looks like
=
Foo::usage"Description of Foo";
=
Bar::usage"Description of Bar";
=
$MyAddonVersion::usage"$MyAddonVersion is the string that represents the version of MyAddon";
=
$MyAddonDirectory::usage"$MyAddonDirectory is the string that represents the full path to the MyAddon directory";
Begin["`Package`"]
End[]
="1.0.0";
$MyAddonVersion
=
$MyAddonDirectory [{$FeynCalcDirectory, "AddOns", "MyAddon"}];
ToFileName
Begin["`MyAddon`Private`"];
[x_,y_]:= Pair[Momentum[x],Momentum[y]];
Foo[x_,y_]:= DiracGamma[LorentzIndex[x]].DiracGamma[Momentum[y]];
Bar
(* Print startup message *)
If[ Global`$FeynCalcStartupMessages =!= False,
Print[Style["MyAddon ", "Text", Bold], Style[$MyAddonVersion <> " loaded.", "Text"]]
];
End[]
Starting with FeynCalc 9.0 one can easily write something like
``mathematica BeginPackage["MyPackage
“,{”FeynCalc`“}]
MySP::usage= “Description of MySP”;
Begin[“Private
”];
MySP[a_,b_]:= FCI[SP[a,b]];
End[] EndPackage[]
```mathematica
The decision, whether you want to write an add-on or a separate package that requires FeynCalc should be made depending on your working style.