diff --git a/FeynCalc/Shared/SharedTools.m b/FeynCalc/Shared/SharedTools.m index a0935e370..9fb000596 100644 --- a/FeynCalc/Shared/SharedTools.m +++ b/FeynCalc/Shared/SharedTools.m @@ -88,6 +88,10 @@ will generate a warning (when running with the frontend) or quit kernel (when \ FeynArts or QGAF into the FeynCalc notation. It uses memoization to improve the \ performance." +FCMapWithProgressBar::usage = +"FCMapWithProgressBar[f, expr] is like Map[f,@expr] but with a graphical +progress bar to show the progress of the evaluation."; + FCPatternFreeQ::usage = "FCPatternFreeQ[{exp}] yields True if {exp} does not contain any \ pattern objects, e.g. Pattern, Blank, BlankSequence and BlankNullSequence. \n @@ -247,7 +251,10 @@ an integer (even if it is symbolic). Furthermore \ appends the subset of remaining unmatched elements."; XYT::usage= -"XYT[exp, x,y] transforms (x y)^m away ..." +"XYT[exp, x,y] transforms (x y)^m away ..."; + +FCMapWithProgressBar::failmsg = "Error! FCMapWithProgressBar has encountered a fatal problem and must abort the computation. \n +The problem reads: `1`"; FCProductSplit::failmsg = "Error! FCProductSplit has encountered a fatal problem and must abort the computation. \n The problem reads: `1`"; @@ -512,6 +519,31 @@ an integer (even if it is symbolic). Furthermore \ head[ToExpression[x <> "Minus" <> ToString[-y]]] ]/; y < 0; + +FCMapWithProgressBar[x_, y_, OptionsPattern[]] := + Block[{iter = 0, len= Length[y], xNew, res}, + + If[ Head[x] =!= Function, + Message[FCMapWithProgressBar::failmsg,"The head of the first argument must be a Function"]; + Abort[] + ]; + + If[ $FrontEnd===Null, + (*No FrontEnd*) + FCPrint[0, "Unfortunately, the progress bar requires the graphical Front End."]; + (*TODO: Command line implementation, cf. https://mathematica.stackexchange.com/questions/183632/any-ergonomic-tools-for-the-command-line-kernel *) + res = Map[x,y], + (*FrontEnd is available*) + xNew = x /. Function[z_] :> Function[CompoundExpression[iter++, z]]; + Monitor[ + res = Map[xNew, y], + Grid[{{ProgressIndicator[iter, {1, len}]}, {Row[{iter, "/", len}]}}] + ] + ]; + + res + ]; + FCFactorOut[expr_,pref_,OptionsPattern[]]:= pref OptionValue[Head][OptionValue[Factoring][expr/pref]];