
(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 11 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 (* 0.5 (+ (exp (* (- -1.0 eps) x)) (exp (* (- eps 1.0) x)))))
double code(double x, double eps) {
return 0.5 * (exp(((-1.0 - eps) * x)) + exp(((eps - 1.0) * x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.5d0 * (exp((((-1.0d0) - eps) * x)) + exp(((eps - 1.0d0) * x)))
end function
public static double code(double x, double eps) {
return 0.5 * (Math.exp(((-1.0 - eps) * x)) + Math.exp(((eps - 1.0) * x)));
}
def code(x, eps): return 0.5 * (math.exp(((-1.0 - eps) * x)) + math.exp(((eps - 1.0) * x)))
function code(x, eps) return Float64(0.5 * Float64(exp(Float64(Float64(-1.0 - eps) * x)) + exp(Float64(Float64(eps - 1.0) * x)))) end
function tmp = code(x, eps) tmp = 0.5 * (exp(((-1.0 - eps) * x)) + exp(((eps - 1.0) * x))); end
code[x_, eps_] := N[(0.5 * N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(e^{\left(-1 - \varepsilon\right) \cdot x} + e^{\left(\varepsilon - 1\right) \cdot x}\right)
\end{array}
Initial program 70.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.3%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (* eps eps) eps)))
(if (<=
(-
(* (exp (* (- eps 1.0) x)) (+ (/ 1.0 eps) 1.0))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
2.000000005377993)
(* (* (+ (+ 2.0 x) x) (exp (- x))) 0.5)
(fma (/ (* (fma (* t_0 0.125) t_0 -0.125) x) 0.25) x 1.0))))
double code(double x, double eps) {
double t_0 = (eps * eps) * eps;
double tmp;
if (((exp(((eps - 1.0) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 2.000000005377993) {
tmp = (((2.0 + x) + x) * exp(-x)) * 0.5;
} else {
tmp = fma(((fma((t_0 * 0.125), t_0, -0.125) * x) / 0.25), x, 1.0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(eps * eps) * eps) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(eps - 1.0) * x)) * Float64(Float64(1.0 / eps) + 1.0)) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 2.000000005377993) tmp = Float64(Float64(Float64(Float64(2.0 + x) + x) * exp(Float64(-x))) * 0.5); else tmp = fma(Float64(Float64(fma(Float64(t_0 * 0.125), t_0, -0.125) * x) / 0.25), x, 1.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(eps * eps), $MachinePrecision] * eps), $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $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.000000005377993], N[(N[(N[(N[(2.0 + x), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(N[(t$95$0 * 0.125), $MachinePrecision] * t$95$0 + -0.125), $MachinePrecision] * x), $MachinePrecision] / 0.25), $MachinePrecision] * x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\varepsilon \cdot \varepsilon\right) \cdot \varepsilon\\
\mathbf{if}\;e^{\left(\varepsilon - 1\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right) - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 2.000000005377993:\\
\;\;\;\;\left(\left(\left(2 + x\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(t\_0 \cdot 0.125, t\_0, -0.125\right) \cdot x}{0.25}, 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))))) < 2.0000000053779932Initial program 50.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.6%
if 2.0000000053779932 < (-.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 99.2%
Taylor expanded in x around 0
Applied rewrites80.3%
Taylor expanded in eps around 0
Applied rewrites80.3%
Applied rewrites16.5%
Taylor expanded in eps around 0
Applied rewrites94.7%
Final simplification97.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (* eps eps) eps)))
(if (<=
(-
(* (exp (* (- eps 1.0) x)) (+ (/ 1.0 eps) 1.0))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
2.000000005377993)
(exp (- x))
(fma (/ (* (fma (* t_0 0.125) t_0 -0.125) x) 0.25) x 1.0))))
double code(double x, double eps) {
double t_0 = (eps * eps) * eps;
double tmp;
if (((exp(((eps - 1.0) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 2.000000005377993) {
tmp = exp(-x);
} else {
tmp = fma(((fma((t_0 * 0.125), t_0, -0.125) * x) / 0.25), x, 1.0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(eps * eps) * eps) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(eps - 1.0) * x)) * Float64(Float64(1.0 / eps) + 1.0)) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 2.000000005377993) tmp = exp(Float64(-x)); else tmp = fma(Float64(Float64(fma(Float64(t_0 * 0.125), t_0, -0.125) * x) / 0.25), x, 1.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(eps * eps), $MachinePrecision] * eps), $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $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.000000005377993], N[Exp[(-x)], $MachinePrecision], N[(N[(N[(N[(N[(t$95$0 * 0.125), $MachinePrecision] * t$95$0 + -0.125), $MachinePrecision] * x), $MachinePrecision] / 0.25), $MachinePrecision] * x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\varepsilon \cdot \varepsilon\right) \cdot \varepsilon\\
\mathbf{if}\;e^{\left(\varepsilon - 1\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right) - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 2.000000005377993:\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(t\_0 \cdot 0.125, t\_0, -0.125\right) \cdot x}{0.25}, 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))))) < 2.0000000053779932Initial program 50.3%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.7%
Taylor expanded in eps around 0
Applied rewrites98.4%
if 2.0000000053779932 < (-.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 99.2%
Taylor expanded in x around 0
Applied rewrites80.3%
Taylor expanded in eps around 0
Applied rewrites80.3%
Applied rewrites16.5%
Taylor expanded in eps around 0
Applied rewrites94.7%
Final simplification96.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (* eps eps) eps)))
(if (<=
(-
(* (exp (* (- eps 1.0) x)) (+ (/ 1.0 eps) 1.0))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
2.000000005377993)
(fma (* (* (* x eps) eps) 0.5) x 1.0)
(fma (/ (* (fma (* t_0 0.125) t_0 -0.125) x) 0.25) x 1.0))))
double code(double x, double eps) {
double t_0 = (eps * eps) * eps;
double tmp;
if (((exp(((eps - 1.0) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 2.000000005377993) {
tmp = fma((((x * eps) * eps) * 0.5), x, 1.0);
} else {
tmp = fma(((fma((t_0 * 0.125), t_0, -0.125) * x) / 0.25), x, 1.0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(eps * eps) * eps) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(eps - 1.0) * x)) * Float64(Float64(1.0 / eps) + 1.0)) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 2.000000005377993) tmp = fma(Float64(Float64(Float64(x * eps) * eps) * 0.5), x, 1.0); else tmp = fma(Float64(Float64(fma(Float64(t_0 * 0.125), t_0, -0.125) * x) / 0.25), x, 1.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(eps * eps), $MachinePrecision] * eps), $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $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.000000005377993], N[(N[(N[(N[(x * eps), $MachinePrecision] * eps), $MachinePrecision] * 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision], N[(N[(N[(N[(N[(t$95$0 * 0.125), $MachinePrecision] * t$95$0 + -0.125), $MachinePrecision] * x), $MachinePrecision] / 0.25), $MachinePrecision] * x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\varepsilon \cdot \varepsilon\right) \cdot \varepsilon\\
\mathbf{if}\;e^{\left(\varepsilon - 1\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right) - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 2.000000005377993:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(x \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot 0.5, x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(t\_0 \cdot 0.125, t\_0, -0.125\right) \cdot x}{0.25}, 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))))) < 2.0000000053779932Initial program 50.3%
Taylor expanded in x around 0
Applied rewrites73.3%
Taylor expanded in eps around inf
Applied rewrites77.8%
if 2.0000000053779932 < (-.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 99.2%
Taylor expanded in x around 0
Applied rewrites80.3%
Taylor expanded in eps around 0
Applied rewrites80.3%
Applied rewrites16.5%
Taylor expanded in eps around 0
Applied rewrites94.7%
Final simplification84.8%
(FPCore (x eps)
:precision binary64
(if (<=
(-
(* (exp (* (- eps 1.0) x)) (+ (/ 1.0 eps) 1.0))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
5.0)
1.0
(* (* x x) (* (* eps eps) 0.5))))
double code(double x, double eps) {
double tmp;
if (((exp(((eps - 1.0) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 5.0) {
tmp = 1.0;
} else {
tmp = (x * x) * ((eps * eps) * 0.5);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (((exp(((eps - 1.0d0) * x)) * ((1.0d0 / eps) + 1.0d0)) - (exp((((-1.0d0) - eps) * x)) * ((1.0d0 / eps) - 1.0d0))) <= 5.0d0) then
tmp = 1.0d0
else
tmp = (x * x) * ((eps * eps) * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (((Math.exp(((eps - 1.0) * x)) * ((1.0 / eps) + 1.0)) - (Math.exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 5.0) {
tmp = 1.0;
} else {
tmp = (x * x) * ((eps * eps) * 0.5);
}
return tmp;
}
def code(x, eps): tmp = 0 if ((math.exp(((eps - 1.0) * x)) * ((1.0 / eps) + 1.0)) - (math.exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 5.0: tmp = 1.0 else: tmp = (x * x) * ((eps * eps) * 0.5) return tmp
function code(x, eps) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(eps - 1.0) * x)) * Float64(Float64(1.0 / eps) + 1.0)) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 5.0) tmp = 1.0; else tmp = Float64(Float64(x * x) * Float64(Float64(eps * eps) * 0.5)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (((exp(((eps - 1.0) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 5.0) tmp = 1.0; else tmp = (x * x) * ((eps * eps) * 0.5); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[(N[Exp[N[(N[(eps - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $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], 5.0], 1.0, N[(N[(x * x), $MachinePrecision] * N[(N[(eps * eps), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{\left(\varepsilon - 1\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right) - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 5:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(\varepsilon \cdot \varepsilon\right) \cdot 0.5\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))))) < 5Initial program 50.1%
Taylor expanded in x around 0
Applied rewrites77.6%
if 5 < (-.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 x around 0
Applied rewrites80.1%
Taylor expanded in eps around 0
Applied rewrites80.1%
Taylor expanded in eps around inf
Applied rewrites68.7%
Final simplification73.9%
(FPCore (x eps) :precision binary64 (if (<= x 45.0) (fma (* (fma (* 0.5 eps) eps -0.5) x) x 1.0) (if (<= x 1.5e+80) 0.0 (* (* x x) (* (* eps eps) 0.5)))))
double code(double x, double eps) {
double tmp;
if (x <= 45.0) {
tmp = fma((fma((0.5 * eps), eps, -0.5) * x), x, 1.0);
} else if (x <= 1.5e+80) {
tmp = 0.0;
} else {
tmp = (x * x) * ((eps * eps) * 0.5);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 45.0) tmp = fma(Float64(fma(Float64(0.5 * eps), eps, -0.5) * x), x, 1.0); elseif (x <= 1.5e+80) tmp = 0.0; else tmp = Float64(Float64(x * x) * Float64(Float64(eps * eps) * 0.5)); end return tmp end
code[x_, eps_] := If[LessEqual[x, 45.0], N[(N[(N[(N[(0.5 * eps), $MachinePrecision] * eps + -0.5), $MachinePrecision] * x), $MachinePrecision] * x + 1.0), $MachinePrecision], If[LessEqual[x, 1.5e+80], 0.0, N[(N[(x * x), $MachinePrecision] * N[(N[(eps * eps), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 45:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5 \cdot \varepsilon, \varepsilon, -0.5\right) \cdot x, x, 1\right)\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+80}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(\varepsilon \cdot \varepsilon\right) \cdot 0.5\right)\\
\end{array}
\end{array}
if x < 45Initial program 60.4%
Taylor expanded in x around 0
Applied rewrites89.6%
Taylor expanded in eps around 0
Applied rewrites89.7%
if 45 < x < 1.49999999999999993e80Initial program 96.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.2%
Taylor expanded in x around inf
Applied rewrites59.2%
Taylor expanded in eps around 0
Applied rewrites59.1%
if 1.49999999999999993e80 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites51.8%
Taylor expanded in eps around 0
Applied rewrites51.2%
Taylor expanded in eps around inf
Applied rewrites64.5%
Final simplification82.5%
(FPCore (x eps) :precision binary64 (if (<= x 780.0) (fma (* (* (* eps eps) x) 0.5) x 1.0) (if (<= x 1.5e+80) 0.0 (* (* x x) (* (* eps eps) 0.5)))))
double code(double x, double eps) {
double tmp;
if (x <= 780.0) {
tmp = fma((((eps * eps) * x) * 0.5), x, 1.0);
} else if (x <= 1.5e+80) {
tmp = 0.0;
} else {
tmp = (x * x) * ((eps * eps) * 0.5);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 780.0) tmp = fma(Float64(Float64(Float64(eps * eps) * x) * 0.5), x, 1.0); elseif (x <= 1.5e+80) tmp = 0.0; else tmp = Float64(Float64(x * x) * Float64(Float64(eps * eps) * 0.5)); end return tmp end
code[x_, eps_] := If[LessEqual[x, 780.0], N[(N[(N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision] * 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision], If[LessEqual[x, 1.5e+80], 0.0, N[(N[(x * x), $MachinePrecision] * N[(N[(eps * eps), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 780:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\varepsilon \cdot \varepsilon\right) \cdot x\right) \cdot 0.5, x, 1\right)\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+80}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(\varepsilon \cdot \varepsilon\right) \cdot 0.5\right)\\
\end{array}
\end{array}
if x < 780Initial program 60.1%
Taylor expanded in x around 0
Applied rewrites89.2%
Taylor expanded in eps around inf
Applied rewrites86.1%
Applied rewrites89.2%
if 780 < x < 1.49999999999999993e80Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites2.9%
Taylor expanded in x around inf
Applied rewrites61.6%
Taylor expanded in eps around 0
Applied rewrites61.5%
if 1.49999999999999993e80 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites51.8%
Taylor expanded in eps around 0
Applied rewrites51.2%
Taylor expanded in eps around inf
Applied rewrites64.5%
Final simplification82.4%
(FPCore (x eps) :precision binary64 (if (<= x 1.0) (- 1.0 x) (if (<= x 1e+215) 0.0 (* (fma (fma x 0.5 -1.0) x 1.0) x))))
double code(double x, double eps) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 - x;
} else if (x <= 1e+215) {
tmp = 0.0;
} else {
tmp = fma(fma(x, 0.5, -1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 - x); elseif (x <= 1e+215) tmp = 0.0; else tmp = Float64(fma(fma(x, 0.5, -1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 1.0], N[(1.0 - x), $MachinePrecision], If[LessEqual[x, 1e+215], 0.0, N[(N[(N[(x * 0.5 + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 - x\\
\mathbf{elif}\;x \leq 10^{+215}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, 0.5, -1\right), x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 1Initial program 60.4%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites62.9%
if 1 < x < 9.99999999999999907e214Initial program 98.1%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites52.7%
Taylor expanded in eps around 0
Applied rewrites54.6%
if 9.99999999999999907e214 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites32.3%
Taylor expanded in x around inf
Applied rewrites32.3%
Taylor expanded in x around 0
Applied rewrites69.2%
(FPCore (x eps) :precision binary64 (if (<= x 1.0) (- 1.0 x) 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 - x;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 1.0d0 - x
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 - x;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 1.0: tmp = 1.0 - x else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 - x); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 1.0) tmp = 1.0 - x; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 1.0], N[(1.0 - x), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1Initial program 60.4%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites62.9%
if 1 < x Initial program 98.6%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites47.9%
Taylor expanded in eps around 0
Applied rewrites49.4%
(FPCore (x eps) :precision binary64 (if (<= x 550.0) 1.0 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 550.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 550.0d0) then
tmp = 1.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 550.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 550.0: tmp = 1.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 550.0) tmp = 1.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 550.0) tmp = 1.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 550.0], 1.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 550:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 550Initial program 60.1%
Taylor expanded in x around 0
Applied rewrites62.6%
if 550 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.0%
Taylor expanded in x around inf
Applied rewrites48.6%
Taylor expanded in eps around 0
Applied rewrites50.0%
(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.0%
herbie shell --seed 2024235
(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))