(* ::Package:: *)

(* ::Title:: *)
(*CHYLightConeUtils*)


(* ::Subtitle:: *)
(*\:6148\:6d69\:827a\:7684\:5149\:9525\:5de5\:5177\:5305*)


(*\:7248\:672c\:58f0\:660e*)
CHYLightConeUtils`CHYLCUVerison="0.2-alpha"
CHYLightConeUtils`FCRecommandVersion = "10.1.0"


(* ::Chapter:: *)
(*Introduction*)


(* ::Text:: *)
(*\:672c\:7a0b\:5e8f\:5305\:7531\:6148\:6d69\:827a\:7f16\:5199\:ff0c\:7528\:4e8e\:8865\:5145 FeynCalc \:7a0b\:5e8f\:5305\:ff0c\:4ee5\:4f7f\:5f97\:5149\:9525\:8fd0\:7b97\:66f4\:52a0\:65b9\:4fbf\:3002*)
(*You can find the instructions in English at https://www.cihaoyi.com/CHYLightConeUtils*)


(* ::Section:: *)
(*\:4f7f\:7528\:ff08\:5bfc\:5165\:ff09\:8bf4\:660e*)


(* ::Text:: *)
(*\:8bf7\:5728\:5bfc\:5165 FeynCalc \:540e\:5bfc\:5165\:672c\:7a0b\:5e8f\:5305\:3002\:4f60\:53ef\:4ee5\:4f7f\:7528*)


(* ::Program:: *)
(*Needs["CHYLightConeUtils`"];*)


(* ::Text:: *)
(*\:6765\:5bfc\:5165\:7a0b\:5e8f\:5305\:3002\:6216\:8005\:5982\:679c\:9700\:8981\:6307\:5b9a\:7a0b\:5e8f\:5305\:8def\:5f84*)


(* ::Program:: *)
(*Needs["CHYLightConeUtils`","Path of this package .wl file"];*)


(* ::Text:: *)
(*\:4e00\:4e2a\:5728\:7ebf\:7684\:8def\:5f84\:4e3a https://www.cihaoyi.com/CHYLightConeUtils/CHYLightConeUtils.wl \:ff0c\:6216\:8005\:4f7f\:7528 https://www.cihaoyi.com/CHYLightConeUtils/CHYLightConeUtils-<version>.wl \:6765\:83b7\:53d6\:7279\:5b9a\:7248\:672c\:7684\:3002\:5f53\:524d\:ff0c\:5b58\:5728\:4ee5\:4e0b\:7248\:672c\:522b\:540d\:ff1a*)
(*latest\:ff1a\:8868\:793a\:6700\:65b0\:7684\:7a33\:5b9a\:7248\:672c\:ff08\:5982\:679c\:7a33\:5b9a\:7248\:4e0d\:5b58\:5728\:ff0c\:5219\:6307\:5411\:6700\:65b0\:7684\:63a8\:8350\:7248\:672c\:ff09\:3002*)
(*\:60a8\:53ef\:4ee5\:59cb\:7ec8\:4f7f\:7528\:5728\:7ebf\:5730\:5740\:83b7\:53d6\:6700\:65b0\:7684\:63a8\:8350\:7248\:672c\:3002*)


(* ::Text:: *)
(*\:4f60\:6700\:597d\:5728\:5bfc\:5165\:7a0b\:5e8f\:5305\:524d\:ff0c\:58f0\:660e\:672c\:7a0b\:5e8f\:6240\:4f7f\:7528\:7684\:5185\:7f6e\:53d8\:91cf $CHYLCUDefaultLightconeVectorN\:3001$CHYLCUDefaultLightconeVectorNB \:548c $CHYLCUDefaultParallelVectorV\:ff0c\:5426\:5219\:5176\:9ed8\:8ba4\:503c\:5c06\:4e3a $FCDefaultLightconeVectorN\:3001$FCDefaultLightconeVectorNB\:3001FCGV["v"]\:3002\:5728\:672c\:7a0b\:5e8f\:5305\:4e2d\:ff0c\:5f53\:60a8\:4e0d\:7ed9\:51fa\:5149\:9525\:7ec4\:4ef6\:5e73\:884c\:5206\:91cf\:7684\:5750\:6807\:57fa\:7b26\:53f7\:65f6\:ff0c\:5c06\:59cb\:7ec8\:4f7f\:7528 $CHYLCUDefaultLightconeVectorN \:548c $CHYLCUDefaultLightconeVectorNB \:4f5c\:4e3a\:9ed8\:8ba4\:503c\:3002\:4f60\:53ef\:4ee5\:4f7f\:7528\:5982\:4e0b\:4ee3\:7801\:8bbe\:7f6e\:5176\:9ed8\:8ba4\:503c\:ff08\:8bf7\:6ce8\:610f\:ff0c\:4f60\:9700\:8981\:660e\:786e\:58f0\:660e\:547d\:540d\:7a7a\:95f4 CHYLightConeUtils`\:ff09*)


(* ::Program:: *)
(*CHYLightConeUtils`$CHYLCUDefaultLightconeVectorN(*=$FCDefaultLightconeVectorN*)= n;*)
(*CHYLightConeUtils`$CHYLCUDefaultLightconeVectorNB(*=$FCDefaultLightconeVectorNB*)= nb;*)
(*CHYLightConeUtils`$CHYLCUDefaultParallelVectorV = v;*)
(*Needs["CHYLightConeUtils`"];*)


(* ::Text:: *)
(*\:6ce8\:610f\:ff0c\:5982\:679c\:4f60\:4e00\:5e76\:8bbe\:7f6e $FCDefaultLightconeVectorN \:548c $FCDefaultLightconeVectorNB \:5c06\:4f1a\:5bfc\:81f4 FeynCalc \:7a0b\:5e8f\:5305\:542f\:7528\:5f3a\:5236\:6392\:5e8f\:ff0c\:5149\:9525\:5206\:91cf n \:5c06\:5c06\:4f1a\:88ab\:5f3a\:5236\:6392\:5e8f\:5230 nb \:4e4b\:524d\:3002\:7531\:4e8e Gamma \:77e9\:9635\:7684\:975e\:5bf9\:5f02\:6027\:ff0c\:8fd0\:7b97\:7ed3\:679c\:5c06"\:770b\:8d77\:6765"\:6709\:6240\:4e0d\:540c\:ff0c\:4f46\:5b9e\:9645\:4e0a\:7b49\:4ef7\:3002*)


(* ::Section:: *)
(*\:9884\:5b9a\:4e49\:5173\:7cfb*)


(* ::Text:: *)
(*\:5bfc\:5165\:672c\:7a0b\:5e8f\:5305\:65f6\:ff0c\:4f1a\:81ea\:52a8\:5b9a\:4e49\:5982\:4e0b\:5173\:7cfb*)
(*n\[CenterDot]n=0, \!\(\*OverscriptBox[\(n\), \(_\)]\)\[CenterDot]\!\(\*OverscriptBox[\(n\), \(_\)]\)=0, n\[CenterDot]\!\(\*OverscriptBox[\(n\), \(_\)]\)=2*)
(*v\[CenterDot]n=1, v\[CenterDot]\!\(\*OverscriptBox[\(n\), \(_\)]\)=1, v\[CenterDot]v=1*)
(*\:5728\:7a0b\:5e8f\:4e2d\:ff0cn \:4e3a $CHYLCUDefaultLightconeVectorN \:7684\:503c\:ff0c\!\(\*OverscriptBox[\(n\), \(_\)]\) \:4e3a $FCDefaultLightconeVectorNB\:ff0cv \:4e3a $CHYLCUDefaultParallelVectorV\:7684\:503c\:3002*)
(*\:5982\:679c\:60a8\:60f3\:963b\:6b62\:7a0b\:5e8f\:5305\:81ea\:52a8\:5b9a\:4e49\:5982\:4e0a\:5173\:7cfb\:ff0c\:8bf7\:5728\:7a0b\:5e8f\:5305\:5bfc\:5165\:4e4b\:524d\:58f0\:660e CHYLightConeUtils`$CHYLCUEnableLightConeRelation=False\:3002*)


(* ::Section:: *)
(*\:5e38\:91cf*)


(* ::Text:: *)
(*\:65e0*)


(* ::Section:: *)
(*\:5149\:9525\:7269\:7406\:91cf*)


(* ::Subsection:: *)
(*Gamma \:77e9\:9635*)


(* ::Text:: *)
(*GAL[u_,n_,nb_]\:ff0cGALD[u_,n_,nb_]\:ff0c\:5206\:522b\:4e3a 4 \:7ef4\:548c D \:7ef4\:4e0b\:7684 Gamma \:77e9\:9635\:7684\:5149\:9525\:5206\:89e3\:ff08\:7ec4\:4ef6\:ff09\:3002\:5176\:4e2d u_ \:4e3a Gamma \:77e9\:9635\:7684\:6307\:6807\:ff0cn_ \:548c nb_ \:5206\:522b\:662f\:5e73\:884c\:5206\:91cf\:548c\:53cd\:5e73\:884c\:5206\:91cf\:7684\:57fa\:5e95\:7b26\:53f7*)


(* ::Subsection:: *)
(*Levi-Civita \:7b26\:53f7*)


(* ::Text:: *)
(*LCR[\[Mu]_,\[Nu]_,n_,nb_]\:ff0cLCRD[\[Mu]_,\[Nu]_,n_,nb_]\:ff0c\:5206\:522b\:4e3a 4 \:7ef4\:548c D \:7ef4\:4e0b\:7684 Levi-Civita \:7b26\:53f7\:7684\:5782\:76f4\:5206\:91cf\:ff0c\:5373 \!\(\*SubscriptBox[\(( *)
(*\*SuperscriptBox[\(\[Epsilon]\), \(\[Mu]\[Nu]\)])\), \(\[Perpendicular]\)]\) \:6216 \[Epsilon]^(\[Mu]\[Nu]n \!\(\*OverscriptBox[\(n\), \(_\)]\))*)


(* ::Section:: *)
(*\:51fd\:6570*)


(* ::Subsection:: *)
(*EpsIndexDeduplicate*)


(* ::Text:: *)
(*EpsIndexDeduplicate[expr_]\:ff0c\:53bb\:9664\:5305\:542b\:91cd\:590d\:6307\:6807\:ff08\:6216\:52a8\:91cf\:ff09\:7684Levi-Civita\:7b26\:53f7*)


(* ::Subsection:: *)
(*GetLowestNPowerList*)


(* ::Text:: *)
(*GetLowestNPowerList[expr_,var_,n_]\:ff0c\:83b7\:53d6\:8868\:8fbe\:5f0f\:5173\:4e8e\:6307\:5b9a\:53d8\:91cf\:7684\:6700\:4f4e N \:9636\:975e\:96f6\:5e42\:9879\:7684\:5217\:8868\:3002n \:4ece 0 \:5f00\:59cb\:3002*)
(*\:4f8b\:5982\:ff0c\:5bf9\:4e8e\:8868\:8fbe\:5f0f a x^2+c x^4*)


(* ::Program:: *)
(*GetLowestNPowerList[a x^2+c x^4,x,0]*)


(* ::Text:: *)
(*\:7684\:7ed3\:679c\:4e3a {a}\:ff0c*)


(* ::Program:: *)
(*GetLowestNPowerList[a x^2+c x^4,x,1]*)


(* ::Text:: *)
(*\:7684\:7ed3\:679c\:4e3a {a, b}\:3002*)


(* ::Subsection:: *)
(*TLCC*)


(* ::Text:: *)
(*ToLightConeComponents \:7684\:7f29\:5199*)


(* ::Subsection:: *)
(*Momentum2LightConeCompoent*)


(* ::Text:: *)
(*Momentum2LightConeCompoent[expr_,momenta_List]\:ff0c\:5bf9\:8868\:8fbe\:5f0f expr \:4e2d\:7684\:52a8\:91cf\:8fdb\:884c\:5149\:9525\:5206\:89e3\:3002\:5f53 momenta \:53c2\:6570\:4e3a\:7a7a\:5217\:8868\:6216\:4e0d\:7ed9\:51fa\:65f6\:ff0c\:5c06\:5206\:89e3\:6240\:6709\:7684\:52a8\:91cf\:ff1b\:5426\:5219\:5c06\:53ea\:5206\:89e3\:4f4d\:4e8e\:5217\:8868\:4e2d\:7684\:52a8\:91cf\:3002*)
(*\:4e00\:4e2a\:53ef\:9009\:7684\:65b9\:5f0f\:662f\:4f7f\:7528 Momentum2LightConeCompoentReplacement[args_List,n_,nb_,all_] \:8fd9\:4e2a Rule \:5217\:8868\:ff0c\:4f46\:8fd9\:4e0d\:662f\:4e00\:4e2a\:5e38\:89c4\:7684\:4f7f\:7528\:65b9\:5f0f\:ff0c\:4e0d\:63a8\:8350\:3002*)


(* ::Subsection:: *)
(*Gamma2LightConeConeCompoent*)


(* ::Text:: *)
(*Gamma2LightConeConeCompoent[expr_,indexs_List] \:5bf9\:8868\:8fbe\:8868\:8fbe\:5f0f\:4e2d\:7684Gamma\:77e9\:9635\:5149\:9525\:5206\:89e3\:ff0c\:5f53 indexs \:53c2\:6570\:4e3a\:7a7a\:5217\:8868\:6216\:4e0d\:7ed9\:51fa\:65f6\:ff0c\:5c06\:5206\:89e3\:6240\:6709 Gamma \:77e9\:9635\:ff1b\:5426\:5219\:5c06\:53ea\:5206\:89e3\:4f4d\:4e8e\:5217\:8868\:4e2d\:7684\:6307\:6807\:6216\:52a8\:91cf\:3002*)


(* ::Subsection:: *)
(*SpliteSlash2Gamma*)


(* ::Text:: *)
(*SpliteSlash2Gamma[expr_] \:5c06Slash\:7684gamma\:77e9\:9635\:ff08\:5373 GSD[p]\:ff09\:4e0e\:52a8\:91cf\:62c6\:5206\:4e3a\:6307\:6807\:6240\:5e76\:7684\:5f62\:5f0f\:ff0c\:4f1a\:751f\:6210\:552f\:4e00\:6307\:6807\:5e76\:5e94\:7528 DotSimplify\:3002*)


(* ::Chapter:: *)
(*Codes*)


(* ::Section:: *)
(*\:5168\:5c40\:53d8\:91cf\:58f0\:660e*)


(*\:5728Global`\:4e0b\:7684\:53d8\:91cf\:ff0c\:5373 \:5168\:5c40\:53d8\:91cf\:58f0\:660e*)
{};


(* ::Section:: *)
(*BeginPackage*)


BeginPackage["CHYLightConeUtils`",{"FeynCalc`"}];


(* ::Subsection:: *)
(*\:7a0b\:5e8f\:5305\:521d\:59cb\:5316*)


(*\:5411 $ContextPath \:6dfb\:52a0 Global`*)
$ContextPath=Join[$ContextPath,{"Global`"}];


Print["\!\(\*
StyleBox[\"CHYLightConeUtils\",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\" \",\nFontWeight->\"Bold\"]\)(Version:"<>CHYLCUVerison<>") Before importing, make sure that CHYLightConeUtils`$CHYLCUDefaultLightconeVectorN, CHYLightConeUtils`$CHYLCUDefaultLightconeVectorNB and CHYLightConeUtils`$CHYLCUDefaultParallelVectorV are correctly assigned."]


(*\:68c0\:67e5FeynCalc\:7248\:672c*)
If[$FeynCalcVersion=!=FCRecommandVersion,
Print["\!\(\*
StyleBox[\"Warning\",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\"!\",\nFontWeight->\"Bold\"]\) The current version of FeynCalc is "<>$FeynCalcVersion<>", which does not match the recommended version "<>FCRecommandVersion<>". \!\(\*
StyleBox[\"CHYLightConeUtils\",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\"may\",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\"not\",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\"work\",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\"correctly\",\nFontWeight->\"Bold\"]\)\!\(\*
StyleBox[\"!\",\nFontWeight->\"Bold\"]\)"];
];


(*\:521d\:59cb\:5316\:53d8\:91cf*)
If[Not[ValueQ[$CHYLCUDefaultLightconeVectorN]],$CHYLCUDefaultLightconeVectorN:=$FCDefaultLightconeVectorN];
If[Not[ValueQ[$CHYLCUDefaultLightconeVectorNB]],$CHYLCUDefaultLightconeVectorNB:=$FCDefaultLightconeVectorNB];
If[Not[ValueQ[$CHYLCUDefaultParallelVectorV]],$CHYLCUDefaultParallelVectorV:=FCGV["v"]];
If[Not[ValueQ[$CHYLCUEnableLightConeRelation]],$CHYLCUEnableLightConeRelation=True];


(* ::Subsection:: *)
(*\:9884\:5b9a\:4e49\:5173\:7cfb*)


If[$CHYLCUEnableLightConeRelation,
(*\:5149\:9525\:77e2\:91cf\:5b9a\:4e49*)
SP[$CHYLCUDefaultLightconeVectorN]=0;SPD[$CHYLCUDefaultLightconeVectorN]=0;
SP[$CHYLCUDefaultLightconeVectorNB]=0;SPD[$CHYLCUDefaultLightconeVectorNB]=0;
SP[$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB]=2;SPD[$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB]=2;

(*\:5b9a\:4e49\:5e73\:884c\:65b9\:5411*)
SP[$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultParallelVectorV]=1;SPD[$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultParallelVectorV]=1;
SP[$CHYLCUDefaultLightconeVectorNB,$CHYLCUDefaultParallelVectorV]=1;SPD[$CHYLCUDefaultLightconeVectorNB,$CHYLCUDefaultParallelVectorV]=1;
SP[$CHYLCUDefaultParallelVectorV,$CHYLCUDefaultParallelVectorV]=1;SPD[$CHYLCUDefaultParallelVectorV,$CHYLCUDefaultParallelVectorV]=1;
];


(* ::Subsection:: *)
(*Exported \:51fd\:6570\:3001\:5e38\:91cf\:548c\:53d8\:91cf*)


GAL::usage="GAL[u_,n_,nb_] \:662f\:4e00\:4e2a4\:7ef4\:5149\:9525\:5206\:89e3\:540e\:7684\:4f3d\:9a6c\:77e9\:9635\:7684\:7b80\:5199\:5f62\:5f0f,#1\:4e3a\:6307\:6807\:ff0c#2\:4e3a\:5e73\:884c\:57fa\:5e95\:7b26\:53f7\:ff0c#3\:4e3a\:53cd\:5e73\:884c\:57fa\:5e95\:7b26\:53f7";
GALD::usage="GALD[u_,n_,nb_] \:662f\:4e00\:4e2aD\:7ef4\:5149\:9525\:5206\:89e3\:540e\:7684\:4f3d\:9a6c\:77e9\:9635\:7684\:7b80\:5199\:5f62\:5f0f,#1\:4e3a\:6307\:6807\:ff0c#2\:4e3a\:5e73\:884c\:57fa\:5e95\:7b26\:53f7\:ff0c#3\:4e3a\:53cd\:5e73\:884c\:57fa\:5e95\:7b26\:53f7";


LCR::usage="LCR[\[Mu]_,\[Nu]_,n_,nb_] \:4e3a4\:7ef4\:5782\:76f4Levi-Civita\:7b26\:53f7,\!\(\*SuperscriptBox[SubscriptBox[\(\[Epsilon]\), \(\[Perpendicular]\)], \(\[Mu]\[Nu]\)]\)=\!\(\*SuperscriptBox[\(\[Epsilon]\), \(\[Mu]\[Nu]nnb\)]\)\:ff0c\:53ef\:4ee5\:901a\:8fc7LCR[\[Mu]_,\[Nu]_,n_,nb_]\:ff0c#3,#4\:4fee\:6539\:5149\:9525\:57fa\:5e95\:7b26\:53f7";
LCRD::usage="LCRD[\[Mu]_,\[Nu]_,n_,nb_] \:4e3aD\:7ef4\:5782\:76f4Levi-Civita\:7b26\:53f7,\!\(\*SuperscriptBox[SubscriptBox[\(\[Epsilon]\), \(\[Perpendicular]\)], \(\[Mu]\[Nu]\)]\)=\!\(\*SuperscriptBox[\(\[Epsilon]\), \(\[Mu]\[Nu]nnb\)]\)\:ff0c\:53ef\:4ee5\:901a\:8fc7LCR[\[Mu]_,\[Nu]_,n_,nb_]\:ff0c#3,#4\:4fee\:6539\:5149\:9525\:57fa\:5e95\:7b26\:53f7";


EpsIndexDeduplicate::usage="EpsIndexDeduplicate[expr_] \:6d88\:9664\:542b\:6709\:91cd\:590d\:6307\:6807\:7684 Levi-Civita \:7b26\:53f7";


GetLowestNPowerList::usage="GetLowestNPowerList[expr_,var_,n_] \:83b7\:53d6\:8868\:8fbe\:5f0f\:5173\:4e8e\:6307\:5b9a\:53d8\:91cf\:7684\:6700\:4f4e N \:9636\:975e\:96f6\:5e42\:9879\:7684\:5217\:8868\:ff0cexpr \:4e3a\:8f93\:5165\:8868\:8fbe\:5f0f\:ff0cvar \:8ba1\:7b97\:5e42\:6b21\:7684\:53d8\:91cf\:ff0cn \:4fdd\:7559\:7684\:5e42\:6b21\:6570\:91cf\:ff0c\:4ece0\:5f00\:59cb\:4e3a leading power\:ff0c1\:4e3a next leading power.";


TLCC::usage="ToLightConeComponents \:7684\:7f29\:5199";


Momentum2LightConeCompoentReplacement::usage="Momentum2LightConeCompoentReplacement[args_List,n_,nb_,all_] \:81ea\:52a8\:5149\:9525\:5206\:89e3\:8868\:8fbe\:8868\:8fbe\:5f0f\:4e2d\:7684\:52a8\:91cf(\:7684\:66ff\:6362\:ff09\:ff0c\:9700\:8981\:5206\:89e3\:7684\:52a8\:91cf\:4f4d\:4e8e#1\:ff0c\:540e\:7eed\:53c2\:6570\:6709\:9ed8\:8ba4\:503c"
Momentum2LightConeCompoent::usage="Momentum2LightConeCompoentReplacement[args_List,n_,nb_,all_] \:81ea\:52a8\:5149\:9525\:5206\:89e3\:8868\:8fbe\:8868\:8fbe\:5f0f\:4e2d\:7684\:52a8\:91cf\:ff0c\:9700\:8981\:5206\:89e3\:7684\:52a8\:91cf\:4f4d\:4e8e#2"
Gamma2LightConeConeCompoent::usage="Gamma2LightConeConeCompoent[expr_,indexs_List] \:5bf9\:8868\:8fbe\:8868\:8fbe\:5f0f\:4e2d\:7684Gamma\:77e9\:9635\:5149\:9525\:5206\:89e3"


(*\:62c6\:5206GSD[p]\:4e3a \[Gamma]^\[Mu]Subscript[p, \[Mu]]*)
SpliteSlash2GammaReplacement::usage="\:5c06Slash\:7684gamma\:77e9\:9635\:4e0e\:52a8\:91cf\:62c6\:5206\:4e3a\:6307\:6807\:6240\:5e76\:5f62\:5f0f\:7684Rule\:5217\:8868\:ff0c\:4e0d\:4f1a\:5e94\:7528DotSimplify";
SpliteSlash2Gamma::usage="SpliteSlash2Gamma[expr_] \:5c06Slash\:7684gamma\:77e9\:9635\:4e0e\:52a8\:91cf\:62c6\:5206\:4e3a\:6307\:6807\:6240\:5e76\:7684\:5f62\:5f0f\:ff0c\:4f1a\:81ea\:52a8\:5e94\:7528DotSimplify";


(* ::Subsection:: *)
(*Begin Private*)


Begin["`Private`"];


(*\:5149\:9525\:5c55\:5f00\:51fd\:6570*)
GAL[u_]:=GAL[u,$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB]
GAL[u_,n_,nb_]:=FCE[ToLightConeComponents[GA[u],n,nb]];
GALD[u_]:=GALD[u,$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB];
GALD[u_,n_,nb_]:=FCE[ToLightConeComponents[GAD[u],n,nb]];


(*\:5782\:76f4\:7684\:5168\:53cd\:5bf9\:79f0\:5f20\:91cf*)
LCR[\[Mu]_,\[Nu]_]:=LC[\[Mu],\[Nu]][$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB];
LCR[\[Mu]_,\[Nu]_,n_,nb_]:=LC[\[Mu],\[Nu]][n,nb];
LCRD[\[Mu]_,\[Nu]_]:=LCD[\[Mu],\[Nu]][$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB];
LCRD[\[Mu]_,\[Nu]_,n_,nb_]:=LCD[\[Mu],\[Nu]][n,nb];


TLCC[expr_]:=TLCC[expr,$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB];
TLCC[expr_,n_,nb_]:=ToLightConeComponents[expr,n,nb];


(*\:6d88\:9664\:542b\:6709\:91cd\:590d\:6307\:6807\:7684 Levi-Civita \:7b26\:53f7*)
EpsIndexDeduplicateReplacement=Eps[a__]/;Not[DuplicateFreeQ[Cases[{a},LorentzIndex[idx_],Infinity]/. LorentzIndex[idx_]:>idx] && DuplicateFreeQ[Cases[{a},Momentum[idx_],Infinity]/. Momentum[idx_]:>idx]]->0;
EpsIndexDeduplicate[expr_]:=FCI[expr]/.EpsIndexDeduplicateReplacement;


(*Momentum2LightConeCompoentReplacement[args_List,n_,nb_,all_] \:81ea\:52a8\:5149\:9525\:5206\:89e3\:8868\:8fbe\:8868\:8fbe\:5f0f\:4e2d\:7684\:52a8\:91cf(\:7684\:66ff\:6362\:ff09\:ff0c\:9700\:8981\:5206\:89e3\:7684\:52a8\:91cf\:4f4d\:4e8e#1\:ff0c\:540e\:7eed\:53c2\:6570\:6709\:9ed8\:8ba4\:503c*)
Momentum2LightConeCompoentReplacement[args_List]:=Momentum2LightConeCompoentReplacement[args,$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB];
Momentum2LightConeCompoentReplacement[args_List,n_,nb_]:=If[args==={},Momentum2LightConeCompoentReplacement[args,n,nb,True],Momentum2LightConeCompoentReplacement[args,n,nb,False]];
Momentum2LightConeCompoentReplacement[args_List,n_,nb_,all_]:={
	(*GS|GSD\:5149\:9525\:5206\:89e3*)
	GS[p_]/;MemberQ[args,p]||all:>FCE[TLCC[GS[p]]],
	GSD[p_]/;MemberQ[args,p]||all:>FCE[TLCC[GSD[p]]],
	(*\:56db\:52a8\:91cf\:5149\:9525\:5206\:89e3*)
	FV[p_,index_]/;MemberQ[args,p]||all:>FCE[TLCC[FV[p,index]]],
	FVD[p_,index_]/;MemberQ[args,p]||all:>FCE[TLCC[FVD[p,index]]],
	(*\:6807\:91cf\:79ef\:7684\:5149\:9525\:5206\:89e3*)
	SP[p1_,p2_]/;(MemberQ[args,p1]||MemberQ[args,p2]||all):>FCE[TLCC[SP[p1,p2]]],
	SPD[p1_,p2_]/;(MemberQ[args,p1]||MemberQ[args,p2]||all):>FCE[TLCC[SPD[p1,p2]]],
	(*Levi-Civita\:7b26\:53f7\:7684\:5149\:9525\:5206\:89e3*)
	LC[o___][p__]/;(IntersectingQ[{p},args]||all):>Module[{indexList,momentumList},momentumList={p};
		(*\:904d\:5386 p \:4e2d\:7684\:6bcf\:4e2a\:5143\:7d20\:ff0c\:751f\:6210\:552f\:4e00\:7684\:7d22\:5f15\:5e76\:5c06\:5176\:52a0\:5165 indexList*)
		indexList=Table[Unique[tempIndex],Length[momentumList]];
		(*\:8ba1\:7b97 FV[p[i],indexList[i]] \:5e76\:8fd4\:56de\:8868\:8fbe\:5f0f*)
		FCE[Calc[Times[
			FCE[TLCC[Times @@ Table[FV[momentumList[[j]],indexList[[j]]],{j,1,Length[momentumList]}]]],
			LC[o,Sequence@@indexList]
		]]]
	],
	LCD[o___][p__]/;(IntersectingQ[{p},args]||all):>Module[{indexList,momentumList},
		momentumList={p};
		(*\:904d\:5386 p \:4e2d\:7684\:6bcf\:4e2a\:5143\:7d20\:ff0c\:751f\:6210\:552f\:4e00\:7684\:7d22\:5f15\:5e76\:5c06\:5176\:52a0\:5165 indexList*)
		indexList=Table[Unique[tempIndex],Length[momentumList]];
		(*\:8ba1\:7b97 FV[p[i],indexList[i]] \:5e76\:8fd4\:56de\:8868\:8fbe\:5f0f*)
		FCE[Calc[Times[
			FCE[TLCC[Times @@ Table[FVD[momentumList[[j]],indexList[[j]]],{j,1,Length[momentumList]}]]],
			LCD[o,Sequence@@indexList]
		]]]
	]
};
Momentum2LightConeCompoent[expr_]=Momentum2LightConeCompoent[expr,{}];
Momentum2LightConeCompoent[expr_,momenta_List]:=FCE[expr]/.Momentum2LightConeCompoentReplacement[momenta];


Gamma2LightConeConeCompoent[expr_]:=Gamma2LightConeConeCompoent[expr,{}];
Gamma2LightConeConeCompoent[expr_,indexs_List]:=FCE[expr]/.{GA[\[Mu]_]/;(MemberQ[indexs,\[Mu]]||(indexs==={})):>GAL[\[Mu]],GAD[\[Mu]_]/;(MemberQ[indexs,\[Mu]]||(indexs==={})):>GALD[\[Mu]],GSD[p_]/;(MemberQ[indexs,p]||(indexs==={})):>FCE[TLCC[GSD[p]]]}


(**
* \:83b7\:53d6\:8868\:8fbe\:5f0f\:5173\:4e8e\:6307\:5b9a\:53d8\:91cf\:7684\:6700\:4f4e N \:9636\:5e42\:9879\:7684\:5217\:8868
* expr \:4e3a\:8f93\:5165\:8868\:8fbe\:5f0f
* var \:8ba1\:7b97\:5e42\:6b21\:7684\:53d8\:91cf
* n \:4fdd\:7559\:7684\:5e42\:6b21\:6570\:91cf\:ff0c\:4ece0\:5f00\:59cb\:4e3a leading power\:ff0c1\:4e3a next leading power.
**)
(*OldGetLowestNPowerList[expr_,var_,n_]:=Module[{colist,i,nn,result},
	result={}; nn=n; colist=CoefficientList[expr, var];
	For[i=1,i<=Length[colist]&&nn>=0,i++,
		If[colist[[i]]=!=0,AppendTo[result,colist[[i]]];nn--]
	];
	result
];*)
(*Series\:5b9e\:73b0*)
GetLowestNPowerList[expr_,var_,n_]:=GetLowestNPowerList[expr,var,0,n];
(*GetLowestNPowerList[expr_,var_,expandNear_,n_]:=Module[{zeroSeries,i,nn,result,tmpCoeff},
	result={}; nn=0;
	zeroSeries=Series[expr,{var,0,0}]//Normal;
	If[zeroSeries===0,(*\:6ca1\:6709\:96f6\:9636*)i=1,(*\:6709\:96f6\:9636\:548c\:8d1f\:6570\:9636*)i=Exponent[zeroSeries,var,Min]];
	For[i,i<100&&nn<=n,i++,
			tmpCoeff=SeriesCoefficient[expr,{var,expandNear,i}];
			If[tmpCoeff=!=0,
				AppendTo[result,tmpCoeff];
				nn++;
			]
	];
	result
];*)
GetLowestNPowerList[expr_,var_,expandNear_,n_]:=Module[{i,nn,result,tmpCoeff,limit},
	result={}; nn=0;
	i=Exponent[expr,var,Min];
	limit=i+100;
	For[i,i<limit&&nn<=n,i++,
			tmpCoeff=SeriesCoefficient[expr,{var,expandNear,i}];
			If[tmpCoeff=!=0,
				AppendTo[result,tmpCoeff];
				nn++;
			]
	];
	result
];


SpliteSlash2GammaReplacement[momentums_]:=Module[{j=0,tmpIndex},{
GSD[p0_]/;MemberQ[momentums,p0]:>(tmpIndex=FCMakeIndex["SS2GTmpIndex",j++];GAD[tmpIndex] FVD[p0,tmpIndex]),
GSLRD[p0_,$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB]/;MemberQ[momentums,p0]:>(tmpIndex=FCMakeIndex["SS2GTmpIndex",j++];GALRD[tmpIndex,$CHYLCUDefaultLightconeVectorN,$CHYLCUDefaultLightconeVectorNB] FVD[p0,tmpIndex])
}];
SpliteSlash2Gamma[expr_,momentums_]:=expr/.SpliteSlash2GammaReplacement[momentums]//DotSimplify//FCE;


(*\:5f20\:91cf\:6781\:5316\:6c42\:548c*)


End[];


Print["\!\(\*
StyleBox[\"CHYLightConeUtils\",\nFontWeight->\"Bold\"]\)(version:"<>CHYLCUVerison<>") has been successfully loaded! Current settings are: \n$CHYLCUDefaultLightconeVectorN="<>ToString[$CHYLCUDefaultLightconeVectorN]<>",\n$CHYLCUDefaultLightconeVectorNB="<>ToString[$CHYLCUDefaultLightconeVectorNB]<>", \n$CHYLCUDefaultParallelVectorV="<>ToString[$CHYLCUDefaultParallelVectorV]<>""]


EndPackage[];
