
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))))
(-
1.0
(*
(*
t_0
(+
0.254829592
(*
t_0
(+
-0.284496736
(*
t_0
(+ 1.421413741 (* t_0 (+ -1.453152027 (* t_0 1.061405429)))))))))
(exp (- (* (fabs x) (fabs x))))))))
double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * fabs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(fabs(x) * fabs(x))));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = 1.0d0 / (1.0d0 + (0.3275911d0 * abs(x)))
code = 1.0d0 - ((t_0 * (0.254829592d0 + (t_0 * ((-0.284496736d0) + (t_0 * (1.421413741d0 + (t_0 * ((-1.453152027d0) + (t_0 * 1.061405429d0))))))))) * exp(-(abs(x) * abs(x))))
end function
public static double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * Math.abs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * Math.exp(-(Math.abs(x) * Math.abs(x))));
}
def code(x): t_0 = 1.0 / (1.0 + (0.3275911 * math.fabs(x))) return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * math.exp(-(math.fabs(x) * math.fabs(x))))
function code(x) t_0 = Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) return Float64(1.0 - Float64(Float64(t_0 * Float64(0.254829592 + Float64(t_0 * Float64(-0.284496736 + Float64(t_0 * Float64(1.421413741 + Float64(t_0 * Float64(-1.453152027 + Float64(t_0 * 1.061405429))))))))) * exp(Float64(-Float64(abs(x) * abs(x)))))) end
function tmp = code(x) t_0 = 1.0 / (1.0 + (0.3275911 * abs(x))); tmp = 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(abs(x) * abs(x)))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(1.0 - N[(N[(t$95$0 * N[(0.254829592 + N[(t$95$0 * N[(-0.284496736 + N[(t$95$0 * N[(1.421413741 + N[(t$95$0 * N[(-1.453152027 + N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\
1 - \left(t\_0 \cdot \left(0.254829592 + t\_0 \cdot \left(-0.284496736 + t\_0 \cdot \left(1.421413741 + t\_0 \cdot \left(-1.453152027 + t\_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))))
(-
1.0
(*
(*
t_0
(+
0.254829592
(*
t_0
(+
-0.284496736
(*
t_0
(+ 1.421413741 (* t_0 (+ -1.453152027 (* t_0 1.061405429)))))))))
(exp (- (* (fabs x) (fabs x))))))))
double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * fabs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(fabs(x) * fabs(x))));
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = 1.0d0 / (1.0d0 + (0.3275911d0 * abs(x)))
code = 1.0d0 - ((t_0 * (0.254829592d0 + (t_0 * ((-0.284496736d0) + (t_0 * (1.421413741d0 + (t_0 * ((-1.453152027d0) + (t_0 * 1.061405429d0))))))))) * exp(-(abs(x) * abs(x))))
end function
public static double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * Math.abs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * Math.exp(-(Math.abs(x) * Math.abs(x))));
}
def code(x): t_0 = 1.0 / (1.0 + (0.3275911 * math.fabs(x))) return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * math.exp(-(math.fabs(x) * math.fabs(x))))
function code(x) t_0 = Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) return Float64(1.0 - Float64(Float64(t_0 * Float64(0.254829592 + Float64(t_0 * Float64(-0.284496736 + Float64(t_0 * Float64(1.421413741 + Float64(t_0 * Float64(-1.453152027 + Float64(t_0 * 1.061405429))))))))) * exp(Float64(-Float64(abs(x) * abs(x)))))) end
function tmp = code(x) t_0 = 1.0 / (1.0 + (0.3275911 * abs(x))); tmp = 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(abs(x) * abs(x)))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(1.0 - N[(N[(t$95$0 * N[(0.254829592 + N[(t$95$0 * N[(-0.284496736 + N[(t$95$0 * N[(1.421413741 + N[(t$95$0 * N[(-1.453152027 + N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\
1 - \left(t\_0 \cdot \left(0.254829592 + t\_0 \cdot \left(-0.284496736 + t\_0 \cdot \left(1.421413741 + t\_0 \cdot \left(-1.453152027 + t\_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}
\end{array}
\end{array}
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= (fabs x_m) 1e-9)
(/
(+ (pow (* x_m 1.128386358070218) 3.0) 1e-27)
(+
(* (pow x_m 2.0) 1.2732557730789702)
(- 1e-18 (* (* x_m 1.128386358070218) 1e-9))))
1.0))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (fabs(x_m) <= 1e-9) {
tmp = (pow((x_m * 1.128386358070218), 3.0) + 1e-27) / ((pow(x_m, 2.0) * 1.2732557730789702) + (1e-18 - ((x_m * 1.128386358070218) * 1e-9)));
} else {
tmp = 1.0;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (abs(x_m) <= 1d-9) then
tmp = (((x_m * 1.128386358070218d0) ** 3.0d0) + 1d-27) / (((x_m ** 2.0d0) * 1.2732557730789702d0) + (1d-18 - ((x_m * 1.128386358070218d0) * 1d-9)))
else
tmp = 1.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (Math.abs(x_m) <= 1e-9) {
tmp = (Math.pow((x_m * 1.128386358070218), 3.0) + 1e-27) / ((Math.pow(x_m, 2.0) * 1.2732557730789702) + (1e-18 - ((x_m * 1.128386358070218) * 1e-9)));
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if math.fabs(x_m) <= 1e-9: tmp = (math.pow((x_m * 1.128386358070218), 3.0) + 1e-27) / ((math.pow(x_m, 2.0) * 1.2732557730789702) + (1e-18 - ((x_m * 1.128386358070218) * 1e-9))) else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (abs(x_m) <= 1e-9) tmp = Float64(Float64((Float64(x_m * 1.128386358070218) ^ 3.0) + 1e-27) / Float64(Float64((x_m ^ 2.0) * 1.2732557730789702) + Float64(1e-18 - Float64(Float64(x_m * 1.128386358070218) * 1e-9)))); else tmp = 1.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (abs(x_m) <= 1e-9) tmp = (((x_m * 1.128386358070218) ^ 3.0) + 1e-27) / (((x_m ^ 2.0) * 1.2732557730789702) + (1e-18 - ((x_m * 1.128386358070218) * 1e-9))); else tmp = 1.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[N[Abs[x$95$m], $MachinePrecision], 1e-9], N[(N[(N[Power[N[(x$95$m * 1.128386358070218), $MachinePrecision], 3.0], $MachinePrecision] + 1e-27), $MachinePrecision] / N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 1.2732557730789702), $MachinePrecision] + N[(1e-18 - N[(N[(x$95$m * 1.128386358070218), $MachinePrecision] * 1e-9), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;\left|x\_m\right| \leq 10^{-9}:\\
\;\;\;\;\frac{{\left(x\_m \cdot 1.128386358070218\right)}^{3} + 10^{-27}}{{x\_m}^{2} \cdot 1.2732557730789702 + \left(10^{-18} - \left(x\_m \cdot 1.128386358070218\right) \cdot 10^{-9}\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (fabs.f64 x) < 1.00000000000000006e-9Initial program 57.7%
Simplified57.7%
fma-undefine57.7%
Applied egg-rr57.7%
fma-define57.7%
Simplified57.7%
Taylor expanded in x around 0 99.0%
*-commutative99.0%
Simplified99.0%
+-commutative99.0%
flip3-+99.0%
metadata-eval99.0%
swap-sqr99.0%
pow299.0%
metadata-eval99.0%
metadata-eval99.0%
Applied egg-rr99.0%
if 1.00000000000000006e-9 < (fabs.f64 x) Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
add-sqr-sqrt44.1%
fabs-sqr44.1%
add-sqr-sqrt98.3%
log1p-expm1-u99.4%
Applied egg-rr99.4%
Taylor expanded in x around inf 100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= (fabs x_m) 1e-9) (+ 1e-9 (exp (log (* x_m 1.128386358070218)))) 1.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (fabs(x_m) <= 1e-9) {
tmp = 1e-9 + exp(log((x_m * 1.128386358070218)));
} else {
tmp = 1.0;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (abs(x_m) <= 1d-9) then
tmp = 1d-9 + exp(log((x_m * 1.128386358070218d0)))
else
tmp = 1.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (Math.abs(x_m) <= 1e-9) {
tmp = 1e-9 + Math.exp(Math.log((x_m * 1.128386358070218)));
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if math.fabs(x_m) <= 1e-9: tmp = 1e-9 + math.exp(math.log((x_m * 1.128386358070218))) else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (abs(x_m) <= 1e-9) tmp = Float64(1e-9 + exp(log(Float64(x_m * 1.128386358070218)))); else tmp = 1.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (abs(x_m) <= 1e-9) tmp = 1e-9 + exp(log((x_m * 1.128386358070218))); else tmp = 1.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[N[Abs[x$95$m], $MachinePrecision], 1e-9], N[(1e-9 + N[Exp[N[Log[N[(x$95$m * 1.128386358070218), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;\left|x\_m\right| \leq 10^{-9}:\\
\;\;\;\;10^{-9} + e^{\log \left(x\_m \cdot 1.128386358070218\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (fabs.f64 x) < 1.00000000000000006e-9Initial program 57.7%
Simplified57.7%
fma-undefine57.7%
Applied egg-rr57.7%
fma-define57.7%
Simplified57.7%
Taylor expanded in x around 0 99.0%
*-commutative99.0%
Simplified99.0%
add-exp-log42.8%
Applied egg-rr42.8%
if 1.00000000000000006e-9 < (fabs.f64 x) Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
add-sqr-sqrt44.1%
fabs-sqr44.1%
add-sqr-sqrt98.3%
log1p-expm1-u99.4%
Applied egg-rr99.4%
Taylor expanded in x around inf 100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= (fabs x_m) 1e-9) (+ (* x_m 1.128386358070218) 1e-9) 1.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (fabs(x_m) <= 1e-9) {
tmp = (x_m * 1.128386358070218) + 1e-9;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (abs(x_m) <= 1d-9) then
tmp = (x_m * 1.128386358070218d0) + 1d-9
else
tmp = 1.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (Math.abs(x_m) <= 1e-9) {
tmp = (x_m * 1.128386358070218) + 1e-9;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if math.fabs(x_m) <= 1e-9: tmp = (x_m * 1.128386358070218) + 1e-9 else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (abs(x_m) <= 1e-9) tmp = Float64(Float64(x_m * 1.128386358070218) + 1e-9); else tmp = 1.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (abs(x_m) <= 1e-9) tmp = (x_m * 1.128386358070218) + 1e-9; else tmp = 1.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[N[Abs[x$95$m], $MachinePrecision], 1e-9], N[(N[(x$95$m * 1.128386358070218), $MachinePrecision] + 1e-9), $MachinePrecision], 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;\left|x\_m\right| \leq 10^{-9}:\\
\;\;\;\;x\_m \cdot 1.128386358070218 + 10^{-9}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (fabs.f64 x) < 1.00000000000000006e-9Initial program 57.7%
Simplified57.7%
fma-undefine57.7%
Applied egg-rr57.7%
fma-define57.7%
Simplified57.7%
Taylor expanded in x around 0 99.0%
*-commutative99.0%
Simplified99.0%
if 1.00000000000000006e-9 < (fabs.f64 x) Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
add-sqr-sqrt44.1%
fabs-sqr44.1%
add-sqr-sqrt98.3%
log1p-expm1-u99.4%
Applied egg-rr99.4%
Taylor expanded in x around inf 100.0%
Final simplification99.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 2.8e-5) 1e-9 1.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.8e-5) {
tmp = 1e-9;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 2.8d-5) then
tmp = 1d-9
else
tmp = 1.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 2.8e-5) {
tmp = 1e-9;
} else {
tmp = 1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 2.8e-5: tmp = 1e-9 else: tmp = 1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.8e-5) tmp = 1e-9; else tmp = 1.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 2.8e-5) tmp = 1e-9; else tmp = 1.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 2.8e-5], 1e-9, 1.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.8 \cdot 10^{-5}:\\
\;\;\;\;10^{-9}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.79999999999999996e-5Initial program 72.7%
Simplified72.7%
fma-undefine72.7%
Applied egg-rr38.4%
fma-define38.4%
Simplified38.4%
Taylor expanded in x around 0 67.1%
if 2.79999999999999996e-5 < x Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 97.3%
add-sqr-sqrt97.3%
fabs-sqr97.3%
add-sqr-sqrt97.3%
log1p-expm1-u98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 1e-9)
x_m = fabs(x);
double code(double x_m) {
return 1e-9;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 1d-9
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 1e-9;
}
x_m = math.fabs(x) def code(x_m): return 1e-9
x_m = abs(x) function code(x_m) return 1e-9 end
x_m = abs(x); function tmp = code(x_m) tmp = 1e-9; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 1e-9
\begin{array}{l}
x_m = \left|x\right|
\\
10^{-9}
\end{array}
Initial program 78.8%
Simplified78.8%
fma-undefine78.8%
Applied egg-rr29.8%
fma-define29.8%
Simplified29.8%
Taylor expanded in x around 0 54.4%
herbie shell --seed 2024155
(FPCore (x)
:name "Jmat.Real.erf"
:precision binary64
(- 1.0 (* (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ 0.254829592 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ -0.284496736 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ 1.421413741 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ -1.453152027 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) 1.061405429))))))))) (exp (- (* (fabs x) (fabs x)))))))