
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (fabs x)))
(t_1 (* (* t_0 t_0) t_0))
(t_2 (* (* t_1 t_0) t_0)))
(*
(* (/ 1.0 (sqrt PI)) (exp (* (fabs x) (fabs x))))
(+
(+ (+ t_0 (* (/ 1.0 2.0) t_1)) (* (/ 3.0 4.0) t_2))
(* (/ 15.0 8.0) (* (* t_2 t_0) t_0))))))
double code(double x) {
double t_0 = 1.0 / fabs(x);
double t_1 = (t_0 * t_0) * t_0;
double t_2 = (t_1 * t_0) * t_0;
return ((1.0 / sqrt(((double) M_PI))) * exp((fabs(x) * fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
public static double code(double x) {
double t_0 = 1.0 / Math.abs(x);
double t_1 = (t_0 * t_0) * t_0;
double t_2 = (t_1 * t_0) * t_0;
return ((1.0 / Math.sqrt(Math.PI)) * Math.exp((Math.abs(x) * Math.abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
def code(x): t_0 = 1.0 / math.fabs(x) t_1 = (t_0 * t_0) * t_0 t_2 = (t_1 * t_0) * t_0 return ((1.0 / math.sqrt(math.pi)) * math.exp((math.fabs(x) * math.fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)))
function code(x) t_0 = Float64(1.0 / abs(x)) t_1 = Float64(Float64(t_0 * t_0) * t_0) t_2 = Float64(Float64(t_1 * t_0) * t_0) return Float64(Float64(Float64(1.0 / sqrt(pi)) * exp(Float64(abs(x) * abs(x)))) * Float64(Float64(Float64(t_0 + Float64(Float64(1.0 / 2.0) * t_1)) + Float64(Float64(3.0 / 4.0) * t_2)) + Float64(Float64(15.0 / 8.0) * Float64(Float64(t_2 * t_0) * t_0)))) end
function tmp = code(x) t_0 = 1.0 / abs(x); t_1 = (t_0 * t_0) * t_0; t_2 = (t_1 * t_0) * t_0; tmp = ((1.0 / sqrt(pi)) * exp((abs(x) * abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Abs[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(t$95$0 + N[(N[(1.0 / 2.0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(3.0 / 4.0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(N[(15.0 / 8.0), $MachinePrecision] * N[(N[(t$95$2 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\
t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\
\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\right)\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (fabs x)))
(t_1 (* (* t_0 t_0) t_0))
(t_2 (* (* t_1 t_0) t_0)))
(*
(* (/ 1.0 (sqrt PI)) (exp (* (fabs x) (fabs x))))
(+
(+ (+ t_0 (* (/ 1.0 2.0) t_1)) (* (/ 3.0 4.0) t_2))
(* (/ 15.0 8.0) (* (* t_2 t_0) t_0))))))
double code(double x) {
double t_0 = 1.0 / fabs(x);
double t_1 = (t_0 * t_0) * t_0;
double t_2 = (t_1 * t_0) * t_0;
return ((1.0 / sqrt(((double) M_PI))) * exp((fabs(x) * fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
public static double code(double x) {
double t_0 = 1.0 / Math.abs(x);
double t_1 = (t_0 * t_0) * t_0;
double t_2 = (t_1 * t_0) * t_0;
return ((1.0 / Math.sqrt(Math.PI)) * Math.exp((Math.abs(x) * Math.abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
def code(x): t_0 = 1.0 / math.fabs(x) t_1 = (t_0 * t_0) * t_0 t_2 = (t_1 * t_0) * t_0 return ((1.0 / math.sqrt(math.pi)) * math.exp((math.fabs(x) * math.fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)))
function code(x) t_0 = Float64(1.0 / abs(x)) t_1 = Float64(Float64(t_0 * t_0) * t_0) t_2 = Float64(Float64(t_1 * t_0) * t_0) return Float64(Float64(Float64(1.0 / sqrt(pi)) * exp(Float64(abs(x) * abs(x)))) * Float64(Float64(Float64(t_0 + Float64(Float64(1.0 / 2.0) * t_1)) + Float64(Float64(3.0 / 4.0) * t_2)) + Float64(Float64(15.0 / 8.0) * Float64(Float64(t_2 * t_0) * t_0)))) end
function tmp = code(x) t_0 = 1.0 / abs(x); t_1 = (t_0 * t_0) * t_0; t_2 = (t_1 * t_0) * t_0; tmp = ((1.0 / sqrt(pi)) * exp((abs(x) * abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Abs[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(t$95$0 + N[(N[(1.0 / 2.0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(3.0 / 4.0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(N[(15.0 / 8.0), $MachinePrecision] * N[(N[(t$95$2 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\
t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\
\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\right)\right)
\end{array}
\end{array}
(FPCore (x)
:precision binary64
(/
(/
(*
(exp (* x x))
(fma
0.75
(pow x -5.0)
(/ (+ 1.0 (+ (/ 0.5 (* x x)) (/ 1.875 (pow x 6.0)))) x)))
(pow PI 0.25))
(pow PI 0.25)))
double code(double x) {
return ((exp((x * x)) * fma(0.75, pow(x, -5.0), ((1.0 + ((0.5 / (x * x)) + (1.875 / pow(x, 6.0)))) / x))) / pow(((double) M_PI), 0.25)) / pow(((double) M_PI), 0.25);
}
function code(x) return Float64(Float64(Float64(exp(Float64(x * x)) * fma(0.75, (x ^ -5.0), Float64(Float64(1.0 + Float64(Float64(0.5 / Float64(x * x)) + Float64(1.875 / (x ^ 6.0)))) / x))) / (pi ^ 0.25)) / (pi ^ 0.25)) end
code[x_] := N[(N[(N[(N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision] * N[(0.75 * N[Power[x, -5.0], $MachinePrecision] + N[(N[(1.0 + N[(N[(0.5 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(1.875 / N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[Pi, 0.25], $MachinePrecision]), $MachinePrecision] / N[Power[Pi, 0.25], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{e^{x \cdot x} \cdot \mathsf{fma}\left(0.75, {x}^{-5}, \frac{1 + \left(\frac{0.5}{x \cdot x} + \frac{1.875}{{x}^{6}}\right)}{x}\right)}{{\pi}^{0.25}}}{{\pi}^{0.25}}
\end{array}
Initial program 100.0%
Simplified100.0%
associate-*l/100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 100.0%
associate-*r/100.0%
metadata-eval100.0%
Simplified100.0%
unpow2100.0%
Applied egg-rr100.0%
unpow2100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (/ (* (pow PI -0.5) (* (exp (pow x 2.0)) (+ 1.0 (/ 0.5 (pow x 2.0))))) x))
double code(double x) {
return (pow(((double) M_PI), -0.5) * (exp(pow(x, 2.0)) * (1.0 + (0.5 / pow(x, 2.0))))) / x;
}
public static double code(double x) {
return (Math.pow(Math.PI, -0.5) * (Math.exp(Math.pow(x, 2.0)) * (1.0 + (0.5 / Math.pow(x, 2.0))))) / x;
}
def code(x): return (math.pow(math.pi, -0.5) * (math.exp(math.pow(x, 2.0)) * (1.0 + (0.5 / math.pow(x, 2.0))))) / x
function code(x) return Float64(Float64((pi ^ -0.5) * Float64(exp((x ^ 2.0)) * Float64(1.0 + Float64(0.5 / (x ^ 2.0))))) / x) end
function tmp = code(x) tmp = ((pi ^ -0.5) * (exp((x ^ 2.0)) * (1.0 + (0.5 / (x ^ 2.0))))) / x; end
code[x_] := N[(N[(N[Power[Pi, -0.5], $MachinePrecision] * N[(N[Exp[N[Power[x, 2.0], $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(0.5 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\pi}^{-0.5} \cdot \left(e^{{x}^{2}} \cdot \left(1 + \frac{0.5}{{x}^{2}}\right)\right)}{x}
\end{array}
Initial program 100.0%
Simplified100.0%
associate-*l/100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 48.5%
associate-*r*48.5%
*-commutative48.5%
distribute-rgt-out48.5%
unpow1/248.5%
rem-exp-log48.5%
exp-neg48.5%
exp-prod48.5%
distribute-lft-neg-out48.5%
distribute-rgt-neg-in48.5%
metadata-eval48.5%
exp-to-pow48.5%
fma-define48.5%
Simplified48.5%
unpow2100.0%
Applied egg-rr48.5%
Taylor expanded in x around inf 48.5%
associate-*r/48.5%
associate-*l/48.5%
metadata-eval48.5%
associate-*r/48.5%
*-lft-identity48.5%
distribute-rgt-out99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
(FPCore (x) :precision binary64 (/ (* (pow PI -0.5) (fma 0.5 (pow x -2.0) (exp (* x x)))) x))
double code(double x) {
return (pow(((double) M_PI), -0.5) * fma(0.5, pow(x, -2.0), exp((x * x)))) / x;
}
function code(x) return Float64(Float64((pi ^ -0.5) * fma(0.5, (x ^ -2.0), exp(Float64(x * x)))) / x) end
code[x_] := N[(N[(N[Power[Pi, -0.5], $MachinePrecision] * N[(0.5 * N[Power[x, -2.0], $MachinePrecision] + N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\pi}^{-0.5} \cdot \mathsf{fma}\left(0.5, {x}^{-2}, e^{x \cdot x}\right)}{x}
\end{array}
Initial program 100.0%
Simplified100.0%
associate-*l/100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 48.5%
associate-*r*48.5%
*-commutative48.5%
distribute-rgt-out48.5%
unpow1/248.5%
rem-exp-log48.5%
exp-neg48.5%
exp-prod48.5%
distribute-lft-neg-out48.5%
distribute-rgt-neg-in48.5%
metadata-eval48.5%
exp-to-pow48.5%
fma-define48.5%
Simplified48.5%
unpow2100.0%
Applied egg-rr48.5%
Taylor expanded in x around 0 99.7%
exp-to-pow99.7%
*-commutative99.7%
rec-exp99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
exp-to-pow99.7%
Simplified99.7%
(FPCore (x) :precision binary64 (* (exp (cbrt (pow x 6.0))) (/ (pow PI -0.5) x)))
double code(double x) {
return exp(cbrt(pow(x, 6.0))) * (pow(((double) M_PI), -0.5) / x);
}
public static double code(double x) {
return Math.exp(Math.cbrt(Math.pow(x, 6.0))) * (Math.pow(Math.PI, -0.5) / x);
}
function code(x) return Float64(exp(cbrt((x ^ 6.0))) * Float64((pi ^ -0.5) / x)) end
code[x_] := N[(N[Exp[N[Power[N[Power[x, 6.0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision] * N[(N[Power[Pi, -0.5], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{\sqrt[3]{{x}^{6}}} \cdot \frac{{\pi}^{-0.5}}{x}
\end{array}
Initial program 100.0%
Simplified100.0%
associate-*l/100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.7%
associate-*l/99.7%
associate-/l*99.7%
unpow1/299.7%
rem-exp-log99.7%
exp-neg99.7%
exp-prod99.7%
distribute-lft-neg-out99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
exp-to-pow99.7%
Simplified99.7%
add-cbrt-cube99.7%
pow399.7%
unpow299.7%
pow-prod-down99.7%
pow-prod-up99.7%
metadata-eval99.7%
Applied egg-rr99.7%
(FPCore (x) :precision binary64 (* (exp (* x x)) (/ (pow PI -0.5) x)))
double code(double x) {
return exp((x * x)) * (pow(((double) M_PI), -0.5) / x);
}
public static double code(double x) {
return Math.exp((x * x)) * (Math.pow(Math.PI, -0.5) / x);
}
def code(x): return math.exp((x * x)) * (math.pow(math.pi, -0.5) / x)
function code(x) return Float64(exp(Float64(x * x)) * Float64((pi ^ -0.5) / x)) end
function tmp = code(x) tmp = exp((x * x)) * ((pi ^ -0.5) / x); end
code[x_] := N[(N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision] * N[(N[Power[Pi, -0.5], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{x \cdot x} \cdot \frac{{\pi}^{-0.5}}{x}
\end{array}
Initial program 100.0%
Simplified100.0%
associate-*l/100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.7%
associate-*l/99.7%
associate-/l*99.7%
unpow1/299.7%
rem-exp-log99.7%
exp-neg99.7%
exp-prod99.7%
distribute-lft-neg-out99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
exp-to-pow99.7%
Simplified99.7%
unpow2100.0%
Applied egg-rr99.7%
(FPCore (x) :precision binary64 (/ (pow PI -0.5) x))
double code(double x) {
return pow(((double) M_PI), -0.5) / x;
}
public static double code(double x) {
return Math.pow(Math.PI, -0.5) / x;
}
def code(x): return math.pow(math.pi, -0.5) / x
function code(x) return Float64((pi ^ -0.5) / x) end
function tmp = code(x) tmp = (pi ^ -0.5) / x; end
code[x_] := N[(N[Power[Pi, -0.5], $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\pi}^{-0.5}}{x}
\end{array}
Initial program 100.0%
Simplified100.0%
associate-*l/100.0%
add-sqr-sqrt100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.7%
associate-*l/99.7%
associate-/l*99.7%
unpow1/299.7%
rem-exp-log99.7%
exp-neg99.7%
exp-prod99.7%
distribute-lft-neg-out99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
exp-to-pow99.7%
Simplified99.7%
Taylor expanded in x around 0 2.3%
associate-*l/2.3%
*-lft-identity2.3%
rem-exp-log2.3%
exp-neg2.3%
unpow1/22.3%
exp-prod2.3%
distribute-lft-neg-out2.3%
distribute-rgt-neg-in2.3%
metadata-eval2.3%
exp-to-pow2.3%
Simplified2.3%
herbie shell --seed 2024177
(FPCore (x)
:name "Jmat.Real.erfi, branch x greater than or equal to 5"
:precision binary64
:pre (>= x 0.5)
(* (* (/ 1.0 (sqrt PI)) (exp (* (fabs x) (fabs x)))) (+ (+ (+ (/ 1.0 (fabs x)) (* (/ 1.0 2.0) (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))))) (* (/ 3.0 4.0) (* (* (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))))) (* (/ 15.0 8.0) (* (* (* (* (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x)))))))