
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (/ 1.0 eps) 1.0)))
(if (<=
(-
(* t_0 (exp (* (- eps 1.0) x)))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
2.0)
(* 0.5 (* (/ (+ x 1.0) (exp x)) 2.0))
(/ (- (* t_0 (exp (* x eps))) (- (exp (- (fma x eps x))))) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (((t_0 * exp(((eps - 1.0) * x))) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 2.0) {
tmp = 0.5 * (((x + 1.0) / exp(x)) * 2.0);
} else {
tmp = ((t_0 * exp((x * eps))) - -exp(-fma(x, eps, x))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) + 1.0) tmp = 0.0 if (Float64(Float64(t_0 * exp(Float64(Float64(eps - 1.0) * x))) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 2.0) tmp = Float64(0.5 * Float64(Float64(Float64(x + 1.0) / exp(x)) * 2.0)); else tmp = Float64(Float64(Float64(t_0 * exp(Float64(x * eps))) - Float64(-exp(Float64(-fma(x, eps, x))))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[N[(N[(t$95$0 * N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(0.5 * N[(N[(N[(x + 1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$0 * N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - (-N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} + 1\\
\mathbf{if}\;t\_0 \cdot e^{\left(\varepsilon - 1\right) \cdot x} - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 2:\\
\;\;\;\;0.5 \cdot \left(\frac{x + 1}{e^{x}} \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot e^{x \cdot \varepsilon} - \left(-e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}\right)}{2}\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 2Initial program 47.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 2 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in eps around inf
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (/ 1.0 eps) 1.0)))
(if (<=
(-
(* t_0 (exp (* (- eps 1.0) x)))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
4.0)
(* 0.5 (* (/ (+ x 1.0) (exp x)) 2.0))
(/ (- t_0 (- (exp (- (fma x eps x))))) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (((t_0 * exp(((eps - 1.0) * x))) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 4.0) {
tmp = 0.5 * (((x + 1.0) / exp(x)) * 2.0);
} else {
tmp = (t_0 - -exp(-fma(x, eps, x))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) + 1.0) tmp = 0.0 if (Float64(Float64(t_0 * exp(Float64(Float64(eps - 1.0) * x))) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 4.0) tmp = Float64(0.5 * Float64(Float64(Float64(x + 1.0) / exp(x)) * 2.0)); else tmp = Float64(Float64(t_0 - Float64(-exp(Float64(-fma(x, eps, x))))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[N[(N[(t$95$0 * N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0], N[(0.5 * N[(N[(N[(x + 1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - (-N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} + 1\\
\mathbf{if}\;t\_0 \cdot e^{\left(\varepsilon - 1\right) \cdot x} - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 4:\\
\;\;\;\;0.5 \cdot \left(\frac{x + 1}{e^{x}} \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \left(-e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}\right)}{2}\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 4Initial program 48.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.1%
if 4 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in eps around inf
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6448.0
Applied rewrites48.0%
Final simplification77.2%
(FPCore (x eps)
:precision binary64
(if (<=
(-
(* (+ (/ 1.0 eps) 1.0) (exp (* (- eps 1.0) x)))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
4.0)
(/ (+ x 1.0) (fma (fma (fma 0.16666666666666666 x 0.5) x 1.0) x 1.0))
(fma (* 0.3333333333333333 x) (* x x) 1.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 / eps) + 1.0) * exp(((eps - 1.0) * x))) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 4.0) {
tmp = (x + 1.0) / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0);
} else {
tmp = fma((0.3333333333333333 * x), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 / eps) + 1.0) * exp(Float64(Float64(eps - 1.0) * x))) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 4.0) tmp = Float64(Float64(x + 1.0) / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0)); else tmp = fma(Float64(0.3333333333333333 * x), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision] * N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0], N[(N[(x + 1.0), $MachinePrecision] / N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(0.3333333333333333 * x), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\frac{1}{\varepsilon} + 1\right) \cdot e^{\left(\varepsilon - 1\right) \cdot x} - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 4:\\
\;\;\;\;\frac{x + 1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right), x, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x, x \cdot x, 1\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 4Initial program 48.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.1%
Taylor expanded in x around 0
Applied rewrites92.3%
Applied rewrites92.3%
if 4 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.4%
Taylor expanded in x around 0
Applied rewrites26.7%
Taylor expanded in x around inf
Applied rewrites26.7%
Final simplification64.1%
(FPCore (x eps)
:precision binary64
(if (<= x -1.52e+172)
(fma
(- eps 1.0)
(* (* 0.5 x) (+ (pow eps -1.0) 1.0))
(fma (* 0.5 x) (- eps) 1.0))
(if (<= x -2e-224)
(fma
(* 0.5 x)
(fma (- eps 1.0) (+ (/ 1.0 eps) 1.0) (/ (- 1.0 (* eps eps)) eps))
1.0)
(if (<= x 3.8e+155)
(* (exp (- x)) (+ x 1.0))
(* (* (fma 0.3333333333333333 x -0.5) x) x)))))
double code(double x, double eps) {
double tmp;
if (x <= -1.52e+172) {
tmp = fma((eps - 1.0), ((0.5 * x) * (pow(eps, -1.0) + 1.0)), fma((0.5 * x), -eps, 1.0));
} else if (x <= -2e-224) {
tmp = fma((0.5 * x), fma((eps - 1.0), ((1.0 / eps) + 1.0), ((1.0 - (eps * eps)) / eps)), 1.0);
} else if (x <= 3.8e+155) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = (fma(0.3333333333333333, x, -0.5) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -1.52e+172) tmp = fma(Float64(eps - 1.0), Float64(Float64(0.5 * x) * Float64((eps ^ -1.0) + 1.0)), fma(Float64(0.5 * x), Float64(-eps), 1.0)); elseif (x <= -2e-224) tmp = fma(Float64(0.5 * x), fma(Float64(eps - 1.0), Float64(Float64(1.0 / eps) + 1.0), Float64(Float64(1.0 - Float64(eps * eps)) / eps)), 1.0); elseif (x <= 3.8e+155) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(fma(0.3333333333333333, x, -0.5) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -1.52e+172], N[(N[(eps - 1.0), $MachinePrecision] * N[(N[(0.5 * x), $MachinePrecision] * N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 * x), $MachinePrecision] * (-eps) + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2e-224], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision] + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 3.8e+155], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x + -0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.52 \cdot 10^{+172}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon - 1, \left(0.5 \cdot x\right) \cdot \left({\varepsilon}^{-1} + 1\right), \mathsf{fma}\left(0.5 \cdot x, -\varepsilon, 1\right)\right)\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-224}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(\varepsilon - 1, \frac{1}{\varepsilon} + 1, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right), 1\right)\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{+155}:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(0.3333333333333333, x, -0.5\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < -1.5200000000000001e172Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.2%
Taylor expanded in eps around inf
Applied rewrites3.2%
Applied rewrites45.2%
if -1.5200000000000001e172 < x < -2e-224Initial program 72.5%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites38.3%
Taylor expanded in eps around 0
Applied rewrites46.3%
if -2e-224 < x < 3.8000000000000001e155Initial program 58.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.5%
Applied rewrites81.5%
if 3.8000000000000001e155 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.4%
Taylor expanded in x around 0
Applied rewrites70.2%
Taylor expanded in x around inf
Applied rewrites70.2%
Final simplification68.0%
(FPCore (x eps)
:precision binary64
(if (<= x -2e-224)
(fma
(* 0.5 x)
(fma (- eps 1.0) (+ (/ 1.0 eps) 1.0) (/ (- 1.0 (* eps eps)) eps))
1.0)
(if (<= x 3.8e+155)
(* (exp (- x)) (+ x 1.0))
(* (* (fma 0.3333333333333333 x -0.5) x) x))))
double code(double x, double eps) {
double tmp;
if (x <= -2e-224) {
tmp = fma((0.5 * x), fma((eps - 1.0), ((1.0 / eps) + 1.0), ((1.0 - (eps * eps)) / eps)), 1.0);
} else if (x <= 3.8e+155) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = (fma(0.3333333333333333, x, -0.5) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -2e-224) tmp = fma(Float64(0.5 * x), fma(Float64(eps - 1.0), Float64(Float64(1.0 / eps) + 1.0), Float64(Float64(1.0 - Float64(eps * eps)) / eps)), 1.0); elseif (x <= 3.8e+155) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(fma(0.3333333333333333, x, -0.5) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -2e-224], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision] + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 3.8e+155], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x + -0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-224}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(\varepsilon - 1, \frac{1}{\varepsilon} + 1, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right), 1\right)\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{+155}:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(0.3333333333333333, x, -0.5\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < -2e-224Initial program 78.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites30.3%
Taylor expanded in eps around 0
Applied rewrites40.7%
if -2e-224 < x < 3.8000000000000001e155Initial program 58.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.5%
Applied rewrites81.5%
if 3.8000000000000001e155 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.4%
Taylor expanded in x around 0
Applied rewrites70.2%
Taylor expanded in x around inf
Applied rewrites70.2%
Final simplification66.2%
(FPCore (x eps)
:precision binary64
(if (<= x -2e-224)
(fma
(* 0.5 x)
(fma (- eps 1.0) (+ (/ 1.0 eps) 1.0) (/ (- 1.0 (* eps eps)) eps))
1.0)
(if (<= x 1.6e+150)
(/
(- 1.0 (* x x))
(* (- 1.0 x) (fma (fma (fma 0.16666666666666666 x 0.5) x 1.0) x 1.0)))
(* (* (fma 0.3333333333333333 x -0.5) x) x))))
double code(double x, double eps) {
double tmp;
if (x <= -2e-224) {
tmp = fma((0.5 * x), fma((eps - 1.0), ((1.0 / eps) + 1.0), ((1.0 - (eps * eps)) / eps)), 1.0);
} else if (x <= 1.6e+150) {
tmp = (1.0 - (x * x)) / ((1.0 - x) * fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0));
} else {
tmp = (fma(0.3333333333333333, x, -0.5) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -2e-224) tmp = fma(Float64(0.5 * x), fma(Float64(eps - 1.0), Float64(Float64(1.0 / eps) + 1.0), Float64(Float64(1.0 - Float64(eps * eps)) / eps)), 1.0); elseif (x <= 1.6e+150) tmp = Float64(Float64(1.0 - Float64(x * x)) / Float64(Float64(1.0 - x) * fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0))); else tmp = Float64(Float64(fma(0.3333333333333333, x, -0.5) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -2e-224], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision] + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 1.6e+150], N[(N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x + -0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-224}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(\varepsilon - 1, \frac{1}{\varepsilon} + 1, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right), 1\right)\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+150}:\\
\;\;\;\;\frac{1 - x \cdot x}{\left(1 - x\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right), x, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(0.3333333333333333, x, -0.5\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < -2e-224Initial program 78.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites30.3%
Taylor expanded in eps around 0
Applied rewrites40.7%
if -2e-224 < x < 1.60000000000000008e150Initial program 57.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.4%
Taylor expanded in x around 0
Applied rewrites74.1%
Applied rewrites79.0%
if 1.60000000000000008e150 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites33.4%
Taylor expanded in x around 0
Applied rewrites68.2%
Taylor expanded in x around inf
Applied rewrites68.2%
Final simplification64.5%
(FPCore (x eps) :precision binary64 (if (<= x 4.1e+102) 1.0 (* (* (fma 0.3333333333333333 x -0.5) x) x)))
double code(double x, double eps) {
double tmp;
if (x <= 4.1e+102) {
tmp = 1.0;
} else {
tmp = (fma(0.3333333333333333, x, -0.5) * x) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 4.1e+102) tmp = 1.0; else tmp = Float64(Float64(fma(0.3333333333333333, x, -0.5) * x) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 4.1e+102], 1.0, N[(N[(N[(0.3333333333333333 * x + -0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.1 \cdot 10^{+102}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(0.3333333333333333, x, -0.5\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < 4.1e102Initial program 64.0%
Taylor expanded in x around 0
Applied rewrites56.9%
if 4.1e102 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites37.9%
Taylor expanded in x around 0
Applied rewrites61.8%
Taylor expanded in x around inf
Applied rewrites61.8%
(FPCore (x eps) :precision binary64 (fma (fma 0.3333333333333333 x -0.5) (* x x) 1.0))
double code(double x, double eps) {
return fma(fma(0.3333333333333333, x, -0.5), (x * x), 1.0);
}
function code(x, eps) return fma(fma(0.3333333333333333, x, -0.5), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(0.3333333333333333 * x + -0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, x, -0.5\right), x \cdot x, 1\right)
\end{array}
Initial program 70.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.1%
Taylor expanded in x around 0
Applied rewrites57.5%
(FPCore (x eps) :precision binary64 (fma (* 0.3333333333333333 x) (* x x) 1.0))
double code(double x, double eps) {
return fma((0.3333333333333333 * x), (x * x), 1.0);
}
function code(x, eps) return fma(Float64(0.3333333333333333 * x), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(0.3333333333333333 * x), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333 \cdot x, x \cdot x, 1\right)
\end{array}
Initial program 70.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.1%
Taylor expanded in x around 0
Applied rewrites57.5%
Taylor expanded in x around inf
Applied rewrites57.2%
(FPCore (x eps) :precision binary64 1.0)
double code(double x, double eps) {
return 1.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 1.0d0
end function
public static double code(double x, double eps) {
return 1.0;
}
def code(x, eps): return 1.0
function code(x, eps) return 1.0 end
function tmp = code(x, eps) tmp = 1.0; end
code[x_, eps_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 70.5%
Taylor expanded in x around 0
Applied rewrites47.3%
herbie shell --seed 2024308
(FPCore (x eps)
:name "NMSE Section 6.1 mentioned, A"
:precision binary64
(/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))