3
$\begingroup$

I would much rather have the expression remain as an integral rather than have Mathematica convert it into $\mathrm{erf}$. Is this possible? I always end up differentiating the $\mathrm{erf}$ expression to understand what I am looking at.

Examples:

Erf[x]
Sqrt[π]Erf[x] + Exp[-x^2] - Sqrt[π] Erf[x + a]
Integrate[ChebyshevT[4, x] Exp[-x^2], x]
$\endgroup$
5
  • 1
    $\begingroup$ Please add a reproducible code of your problem. $\endgroup$
    – Mahdi
    Apr 30, 2015 at 17:49
  • 1
    $\begingroup$ See if this can be of some help: mathematica.stackexchange.com/questions/34589/… . You could use it as a starting point. $\endgroup$
    – Peltio
    Apr 30, 2015 at 17:50
  • $\begingroup$ Try HoldForm. $\endgroup$
    – bbgodfrey
    Apr 30, 2015 at 18:03
  • $\begingroup$ Try Inactivate[expr, Integrate]. $\endgroup$
    – Greg Hurst
    Apr 30, 2015 at 18:22
  • 3
    $\begingroup$ You could use Format to show Erf's integral def., but keep Erf in the internal code. (Should be more efficient to calculate with.) E.g.: Unprotect[Erf]; Erf /: Format[Erf[z_]] := HoldForm[2/Sqrt[Pi] Integrate[E^-K[1]^2, {K[1], 0, z}]]; Protect[Erf];. You might do similarly with Erfi and Erfc, although you might want to add parentheses. $\endgroup$
    – Michael E2
    Aug 5, 2017 at 11:21

2 Answers 2

11
$\begingroup$

Expanding on my comment above,

expr = Inactivate[x Integrate[Exp[-t^2], {t, 0, x}], Integrate];

D[expr, x]

enter image description here

You can also convert existing Erf's to Integrate:

ErfToIntegrate[e_] := e /. {
  Erf[z_] :> 2/Sqrt[π] Inactive[Integrate][Exp[-t^2], {t, 0, z}]
}

ErfToIntegrate[Sqrt[π]Erf[x] + Exp[-x^2] - Sqrt[π] Erf[x + a]]

enter image description here

$\endgroup$
3
$\begingroup$

You could use Format or MakeBoxes to show the integral definition of Erf, but keep Erf in the internal code. This should be more efficient to calculate with. One issue is the constant in front of the integral won't be combined with any coefficients of Erf[].

Unprotect[Erf];
(*Erf/:MakeBoxes[Erf[z_],form_]=.;*) (* will undo next definition *)
Erf /: Format[Erf[z_]] := 2/Sqrt[Pi] HoldForm[Integrate[E^-K[1]^2, {K[1], 0, z}]];
Protect[Erf];

Erf[z]
Sqrt[π] Erf[x] + Exp[-x^2] - Sqrt[π] Erf[x + a]
Integrate[ChebyshevT[4, x] Exp[-x^2], x]

Mathematica graphics

Here, we'll put the fraction in front of the integral sign:

Unprotect[Erf];
Format[Erf[z_]] =.;
Erf /: MakeBoxes[Erf[z_], form_] := 
  RowBox[{FractionBox[2, MakeBoxes[Sqrt[Pi], form]], 
    MakeBoxes[HoldForm[Integrate[E^-K[1]^2, {K[1], 0, z}]], form]}];
Protect[Erf];

Mathematica graphics

Here's a modification of J.M.'s method in a comment. The advantage J.M. points out is that copied output is interpreted as Erf[z] as input. The difference in the modification is that Erf[z] is parenthesized as in the second way above. At this moment, I prefer having the rewritten Erf[z] displayed this way.

Unprotect[Erf];
Erf /: MakeBoxes[Erf[z_], form_] := MakeBoxes[
   Interpretation[
    DisplayForm@FractionBox["2", SqrtBox["π"]]*
     HoldForm[Integrate[E^-K[1]^2, {K[1], 0, z}]], Erf[z]],
   form
   ];
Protect[Erf];
$\endgroup$
3
  • $\begingroup$ Maybe this can be combined with Chip's approach for versions that have Inactive[]. $\endgroup$ Aug 5, 2017 at 14:33
  • $\begingroup$ @J.M. Sure, but I'm not seeing a good reason one would want to. I'd rather put Tooltip[..., "Erf"[z]], or highlight the whole expression with Style instead of just the integral sign. (My answer basically treats the problem as an output-formatting issue, as such that's all that comes to mind.) $\endgroup$
    – Michael E2
    Aug 5, 2017 at 14:43
  • 1
    $\begingroup$ You got me thinking... it might even be nicer to use InterpretationBox[], so I modified your code: Unprotect[Erf]; Erf /: MakeBoxes[Erf[z_], StandardForm | TraditionalForm] := With[{xx = ToBoxes[z]}, InterpretationBox[RowBox[{FractionBox["2", SqrtBox["\[Pi]"]], SubsuperscriptBox["\[Integral]", "0", xx], RowBox[{SuperscriptBox["\[ExponentialE]", RowBox[{"-", SuperscriptBox[RowBox[{"K", "[", "1", "]"}], "2"]}]], RowBox[{"\[DifferentialD]", RowBox[{"K", "[", "1", "]"}]}]}]}], Erf[z]]]; Protect[Erf]; If you copy the output of those evaluations, you'll still see Erf[] in the InputForm[]. $\endgroup$ Aug 5, 2017 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.