You could unprotect Erf
and redefine it as you like it.
Unprotect[Erf];
(* Here you define the constants and your erf approximation *)
a1=...; etc.
Erf[x_] := 1/(1 + a1 x + a2 x^2 + a3 x^3 + a4 x^4)^4;
(* Here you perform your calculations with the approximate value of erf *)
myComplexCalculation = Erf[x]/2
(* When you are done, clear your definition and reprotect Erf *)
Clear[Erf];
Protect[Erf];
This can be dangerous but, as long as you know what you are doing, it will work.
A more local workaround is to enclose your 'approximate' calculation within a Block
that blocks the definition of Erf
:
Block[ {Erf},
(* Here you define the constants and your erf approximation *)
a1=...; etc.
Erf[x_] := 1/(1 + a1 x + a2 x^2 + a3 x^3 + a4 x^4)^4;
(* Here you perform your calculations with the approximate value of erf *)
myComplexCalculation = Erf[x]/2
]
Is this what you were looking for or was it the actual expression for the approximation?
As a more general approach to temporarily modifying built-in functions within the walls of a scoping construct, you might also want to have a look at the undocumented function InheritedBlock
, described in this post on Stack Overflow. It appears that it will copy all definitions associated with the symbol you want to block, so that you can change, within the block only the part you need to. Basically, while
Block[ {builtinFun},
code redefining builtinFun from scratch
and using the new builtinFun
]
would give you a completely clean symbol for builtinFun
to code from scratch, using
Internal`InheritedBlock[ {builtinFun},
code redefining parts of the inherited builtinFun
and using the modified builtinFun
]
would give you a completely modifiable copy of builtinFun
, so that you can modify only the parts you need to modify.
Integrate[Erf[t],{t,0,x}] -> x*Erf[x] + (Exp[-x^2] - 1)/Sqrt[Pi]
?? $\endgroup$