
(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 4 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}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (+ 1e-9 (+ (* x (* x -0.00011824294398844343)) (+ (* -0.37545125292247583 (pow x 3.0)) (* x 1.128386358070218)))))
x = abs(x);
double code(double x) {
return 1e-9 + ((x * (x * -0.00011824294398844343)) + ((-0.37545125292247583 * pow(x, 3.0)) + (x * 1.128386358070218)));
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 1d-9 + ((x * (x * (-0.00011824294398844343d0))) + (((-0.37545125292247583d0) * (x ** 3.0d0)) + (x * 1.128386358070218d0)))
end function
x = Math.abs(x);
public static double code(double x) {
return 1e-9 + ((x * (x * -0.00011824294398844343)) + ((-0.37545125292247583 * Math.pow(x, 3.0)) + (x * 1.128386358070218)));
}
x = abs(x) def code(x): return 1e-9 + ((x * (x * -0.00011824294398844343)) + ((-0.37545125292247583 * math.pow(x, 3.0)) + (x * 1.128386358070218)))
x = abs(x) function code(x) return Float64(1e-9 + Float64(Float64(x * Float64(x * -0.00011824294398844343)) + Float64(Float64(-0.37545125292247583 * (x ^ 3.0)) + Float64(x * 1.128386358070218)))) end
x = abs(x) function tmp = code(x) tmp = 1e-9 + ((x * (x * -0.00011824294398844343)) + ((-0.37545125292247583 * (x ^ 3.0)) + (x * 1.128386358070218))); end
NOTE: x should be positive before calling this function code[x_] := N[(1e-9 + N[(N[(x * N[(x * -0.00011824294398844343), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.37545125292247583 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(x * 1.128386358070218), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
10^{-9} + \left(x \cdot \left(x \cdot -0.00011824294398844343\right) + \left(-0.37545125292247583 \cdot {x}^{3} + x \cdot 1.128386358070218\right)\right)
\end{array}
Initial program 58.2%
associate-*l*58.2%
Simplified58.2%
Applied egg-rr58.3%
Simplified56.8%
Taylor expanded in x around 0 96.8%
Taylor expanded in x around 0 96.9%
pow196.9%
pow296.9%
Applied egg-rr96.9%
unpow196.9%
unpow296.9%
*-commutative96.9%
unpow296.9%
associate-*l*96.9%
Simplified96.9%
Final simplification96.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (+ 1e-9 (* x (+ 1.128386358070218 (* x -0.00011824294398844343)))))
x = abs(x);
double code(double x) {
return 1e-9 + (x * (1.128386358070218 + (x * -0.00011824294398844343)));
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 1d-9 + (x * (1.128386358070218d0 + (x * (-0.00011824294398844343d0))))
end function
x = Math.abs(x);
public static double code(double x) {
return 1e-9 + (x * (1.128386358070218 + (x * -0.00011824294398844343)));
}
x = abs(x) def code(x): return 1e-9 + (x * (1.128386358070218 + (x * -0.00011824294398844343)))
x = abs(x) function code(x) return Float64(1e-9 + Float64(x * Float64(1.128386358070218 + Float64(x * -0.00011824294398844343)))) end
x = abs(x) function tmp = code(x) tmp = 1e-9 + (x * (1.128386358070218 + (x * -0.00011824294398844343))); end
NOTE: x should be positive before calling this function code[x_] := N[(1e-9 + N[(x * N[(1.128386358070218 + N[(x * -0.00011824294398844343), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
10^{-9} + x \cdot \left(1.128386358070218 + x \cdot -0.00011824294398844343\right)
\end{array}
Initial program 58.2%
associate-*l*58.2%
Simplified58.2%
Applied egg-rr58.3%
Simplified56.8%
Taylor expanded in x around 0 96.8%
Taylor expanded in x around 0 96.9%
Taylor expanded in x around 0 96.7%
+-commutative96.7%
unpow296.7%
associate-*r*96.7%
distribute-rgt-out96.7%
Simplified96.7%
Final simplification96.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (+ 1e-9 (* x 1.128386358070218)))
x = abs(x);
double code(double x) {
return 1e-9 + (x * 1.128386358070218);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 1d-9 + (x * 1.128386358070218d0)
end function
x = Math.abs(x);
public static double code(double x) {
return 1e-9 + (x * 1.128386358070218);
}
x = abs(x) def code(x): return 1e-9 + (x * 1.128386358070218)
x = abs(x) function code(x) return Float64(1e-9 + Float64(x * 1.128386358070218)) end
x = abs(x) function tmp = code(x) tmp = 1e-9 + (x * 1.128386358070218); end
NOTE: x should be positive before calling this function code[x_] := N[(1e-9 + N[(x * 1.128386358070218), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
10^{-9} + x \cdot 1.128386358070218
\end{array}
Initial program 58.2%
associate-*l*58.2%
Simplified58.2%
Applied egg-rr58.3%
Simplified56.8%
Taylor expanded in x around 0 96.8%
Taylor expanded in x around 0 96.7%
*-commutative96.7%
Simplified96.7%
Final simplification96.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 1e-9)
x = abs(x);
double code(double x) {
return 1e-9;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 1d-9
end function
x = Math.abs(x);
public static double code(double x) {
return 1e-9;
}
x = abs(x) def code(x): return 1e-9
x = abs(x) function code(x) return 1e-9 end
x = abs(x) function tmp = code(x) tmp = 1e-9; end
NOTE: x should be positive before calling this function code[x_] := 1e-9
\begin{array}{l}
x = |x|\\
\\
10^{-9}
\end{array}
Initial program 58.2%
associate-*l*58.2%
Simplified58.2%
Applied egg-rr58.3%
Simplified56.8%
Taylor expanded in x around 0 96.8%
Taylor expanded in x around 0 95.6%
Final simplification95.6%
herbie shell --seed 2023278
(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)))))))