
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 2.0d0) + exp(-x)
end function
public static double code(double x) {
return (Math.exp(x) - 2.0) + Math.exp(-x);
}
def code(x): return (math.exp(x) - 2.0) + math.exp(-x)
function code(x) return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) end
function tmp = code(x) tmp = (exp(x) - 2.0) + exp(-x); end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(e^{x} - 2\right) + e^{-x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 2.0d0) + exp(-x)
end function
public static double code(double x) {
return (Math.exp(x) - 2.0) + Math.exp(-x);
}
def code(x): return (math.exp(x) - 2.0) + math.exp(-x)
function code(x) return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) end
function tmp = code(x) tmp = (exp(x) - 2.0) + exp(-x); end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(e^{x} - 2\right) + e^{-x}
\end{array}
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) 2.0)))
(if (<= (+ (exp (- x_m)) t_0) 2e-7)
(fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m))
(/
(+ (pow t_0 3.0) (pow (exp x_m) -3.0))
(fma t_0 (+ (* (sinh x_m) 2.0) -2.0) (exp (* -2.0 x_m)))))))x_m = fabs(x);
double code(double x_m) {
double t_0 = exp(x_m) - 2.0;
double tmp;
if ((exp(-x_m) + t_0) <= 2e-7) {
tmp = fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
} else {
tmp = (pow(t_0, 3.0) + pow(exp(x_m), -3.0)) / fma(t_0, ((sinh(x_m) * 2.0) + -2.0), exp((-2.0 * x_m)));
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(exp(x_m) - 2.0) tmp = 0.0 if (Float64(exp(Float64(-x_m)) + t_0) <= 2e-7) tmp = fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)); else tmp = Float64(Float64((t_0 ^ 3.0) + (exp(x_m) ^ -3.0)) / fma(t_0, Float64(Float64(sinh(x_m) * 2.0) + -2.0), exp(Float64(-2.0 * x_m)))); end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision]}, If[LessEqual[N[(N[Exp[(-x$95$m)], $MachinePrecision] + t$95$0), $MachinePrecision], 2e-7], N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[t$95$0, 3.0], $MachinePrecision] + N[Power[N[Exp[x$95$m], $MachinePrecision], -3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(N[(N[Sinh[x$95$m], $MachinePrecision] * 2.0), $MachinePrecision] + -2.0), $MachinePrecision] + N[Exp[N[(-2.0 * x$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := e^{x\_m} - 2\\
\mathbf{if}\;e^{-x\_m} + t\_0 \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{t\_0}^{3} + {\left(e^{x\_m}\right)}^{-3}}{\mathsf{fma}\left(t\_0, \sinh x\_m \cdot 2 + -2, e^{-2 \cdot x\_m}\right)}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) < 1.9999999999999999e-7Initial program 47.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.9999999999999999e-7 < (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) Initial program 98.8%
lift-+.f64N/A
flip3-+N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
associate-+r-N/A
Applied rewrites98.6%
lift-pow.f64N/A
lift-exp.f64N/A
pow-expN/A
lower-exp.f64N/A
*-commutativeN/A
lower-*.f6498.3
Applied rewrites98.3%
Final simplification100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) 2.0)))
(if (<= (+ (exp (- x_m)) t_0) 2e-7)
(fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m))
(/ (fma t_0 t_0 (- (pow (exp x_m) -2.0))) (+ (* (sinh x_m) 2.0) -2.0)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = exp(x_m) - 2.0;
double tmp;
if ((exp(-x_m) + t_0) <= 2e-7) {
tmp = fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
} else {
tmp = fma(t_0, t_0, -pow(exp(x_m), -2.0)) / ((sinh(x_m) * 2.0) + -2.0);
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(exp(x_m) - 2.0) tmp = 0.0 if (Float64(exp(Float64(-x_m)) + t_0) <= 2e-7) tmp = fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)); else tmp = Float64(fma(t_0, t_0, Float64(-(exp(x_m) ^ -2.0))) / Float64(Float64(sinh(x_m) * 2.0) + -2.0)); end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision]}, If[LessEqual[N[(N[Exp[(-x$95$m)], $MachinePrecision] + t$95$0), $MachinePrecision], 2e-7], N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * t$95$0 + (-N[Power[N[Exp[x$95$m], $MachinePrecision], -2.0], $MachinePrecision])), $MachinePrecision] / N[(N[(N[Sinh[x$95$m], $MachinePrecision] * 2.0), $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := e^{x\_m} - 2\\
\mathbf{if}\;e^{-x\_m} + t\_0 \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(t\_0, t\_0, -{\left(e^{x\_m}\right)}^{-2}\right)}{\sinh x\_m \cdot 2 + -2}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) < 1.9999999999999999e-7Initial program 47.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.9999999999999999e-7 < (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) Initial program 98.8%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
pow2N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
Applied rewrites97.9%
lift--.f64N/A
sub-negN/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f64N/A
lower-neg.f6498.2
Applied rewrites98.2%
Final simplification100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) 2.0)))
(if (<= (+ (exp (- x_m)) t_0) 2e-7)
(fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m))
(/ (- (pow t_0 2.0) (exp (* -2.0 x_m))) (+ (* (sinh x_m) 2.0) -2.0)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = exp(x_m) - 2.0;
double tmp;
if ((exp(-x_m) + t_0) <= 2e-7) {
tmp = fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
} else {
tmp = (pow(t_0, 2.0) - exp((-2.0 * x_m))) / ((sinh(x_m) * 2.0) + -2.0);
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(exp(x_m) - 2.0) tmp = 0.0 if (Float64(exp(Float64(-x_m)) + t_0) <= 2e-7) tmp = fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)); else tmp = Float64(Float64((t_0 ^ 2.0) - exp(Float64(-2.0 * x_m))) / Float64(Float64(sinh(x_m) * 2.0) + -2.0)); end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision]}, If[LessEqual[N[(N[Exp[(-x$95$m)], $MachinePrecision] + t$95$0), $MachinePrecision], 2e-7], N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] - N[Exp[N[(-2.0 * x$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Sinh[x$95$m], $MachinePrecision] * 2.0), $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := e^{x\_m} - 2\\
\mathbf{if}\;e^{-x\_m} + t\_0 \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{t\_0}^{2} - e^{-2 \cdot x\_m}}{\sinh x\_m \cdot 2 + -2}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) < 1.9999999999999999e-7Initial program 47.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.9999999999999999e-7 < (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) Initial program 98.8%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
pow2N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
Applied rewrites97.9%
lift-pow.f64N/A
lift-exp.f64N/A
pow-expN/A
lower-exp.f64N/A
*-commutativeN/A
lower-*.f6498.9
Applied rewrites98.9%
Final simplification100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= (+ (exp (- x_m)) (- (exp x_m) 2.0)) 2e-7) (fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m)) (/ 1.0 (/ (fma (cosh x_m) 2.0 2.0) (fma (pow (cosh x_m) 2.0) 4.0 -4.0)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if ((exp(-x_m) + (exp(x_m) - 2.0)) <= 2e-7) {
tmp = fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
} else {
tmp = 1.0 / (fma(cosh(x_m), 2.0, 2.0) / fma(pow(cosh(x_m), 2.0), 4.0, -4.0));
}
return tmp;
}
x_m = abs(x) function code(x_m) tmp = 0.0 if (Float64(exp(Float64(-x_m)) + Float64(exp(x_m) - 2.0)) <= 2e-7) tmp = fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)); else tmp = Float64(1.0 / Float64(fma(cosh(x_m), 2.0, 2.0) / fma((cosh(x_m) ^ 2.0), 4.0, -4.0))); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[N[(N[Exp[(-x$95$m)], $MachinePrecision] + N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision], 2e-7], N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[Cosh[x$95$m], $MachinePrecision] * 2.0 + 2.0), $MachinePrecision] / N[(N[Power[N[Cosh[x$95$m], $MachinePrecision], 2.0], $MachinePrecision] * 4.0 + -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;e^{-x\_m} + \left(e^{x\_m} - 2\right) \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(\cosh x\_m, 2, 2\right)}{\mathsf{fma}\left({\cosh x\_m}^{2}, 4, -4\right)}}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) < 1.9999999999999999e-7Initial program 47.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.9999999999999999e-7 < (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) Initial program 98.8%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
sub-negN/A
associate--r+N/A
lift--.f64N/A
lower--.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
lift--.f64N/A
lift--.f64N/A
associate--l-N/A
lift-/.f64N/A
div-invN/A
lift-exp.f64N/A
exp-negN/A
mul-1-negN/A
sub-negN/A
associate-+l-N/A
lift--.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negN/A
metadata-evalN/A
associate-+r+N/A
+-commutativeN/A
lift-exp.f64N/A
cosh-undefN/A
lift-cosh.f64N/A
*-commutativeN/A
lower-fma.f6498.4
Applied rewrites98.4%
lift-fma.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
swap-sqrN/A
unpow2N/A
lift-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval99.0
Applied rewrites99.0%
Final simplification100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) 2.0)))
(if (<= (+ (exp (- x_m)) t_0) 2e-7)
(fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m))
(- t_0 (/ -1.0 (exp x_m))))))x_m = fabs(x);
double code(double x_m) {
double t_0 = exp(x_m) - 2.0;
double tmp;
if ((exp(-x_m) + t_0) <= 2e-7) {
tmp = fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
} else {
tmp = t_0 - (-1.0 / exp(x_m));
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(exp(x_m) - 2.0) tmp = 0.0 if (Float64(exp(Float64(-x_m)) + t_0) <= 2e-7) tmp = fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)); else tmp = Float64(t_0 - Float64(-1.0 / exp(x_m))); end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision]}, If[LessEqual[N[(N[Exp[(-x$95$m)], $MachinePrecision] + t$95$0), $MachinePrecision], 2e-7], N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[(-1.0 / N[Exp[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := e^{x\_m} - 2\\
\mathbf{if}\;e^{-x\_m} + t\_0 \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 - \frac{-1}{e^{x\_m}}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) < 1.9999999999999999e-7Initial program 47.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.9999999999999999e-7 < (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) Initial program 98.8%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
sub-negN/A
associate--r+N/A
lift--.f64N/A
lower--.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
Final simplification100.0%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(let* ((t_0 (+ (exp (- x_m)) (- (exp x_m) 2.0))))
(if (<= t_0 2e-7)
(fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m))
t_0)))x_m = fabs(x);
double code(double x_m) {
double t_0 = exp(-x_m) + (exp(x_m) - 2.0);
double tmp;
if (t_0 <= 2e-7) {
tmp = fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
} else {
tmp = t_0;
}
return tmp;
}
x_m = abs(x) function code(x_m) t_0 = Float64(exp(Float64(-x_m)) + Float64(exp(x_m) - 2.0)) tmp = 0.0 if (t_0 <= 2e-7) tmp = fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)); else tmp = t_0; end return tmp end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(N[Exp[(-x$95$m)], $MachinePrecision] + N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-7], N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := e^{-x\_m} + \left(e^{x\_m} - 2\right)\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) < 1.9999999999999999e-7Initial program 47.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.9999999999999999e-7 < (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) Initial program 98.8%
Final simplification100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= (+ (exp (- x_m)) (- (exp x_m) 2.0)) 2e-7) (fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m)) (fma 2.0 (cosh x_m) -2.0)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if ((exp(-x_m) + (exp(x_m) - 2.0)) <= 2e-7) {
tmp = fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
} else {
tmp = fma(2.0, cosh(x_m), -2.0);
}
return tmp;
}
x_m = abs(x) function code(x_m) tmp = 0.0 if (Float64(exp(Float64(-x_m)) + Float64(exp(x_m) - 2.0)) <= 2e-7) tmp = fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)); else tmp = fma(2.0, cosh(x_m), -2.0); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[N[(N[Exp[(-x$95$m)], $MachinePrecision] + N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision], 2e-7], N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Cosh[x$95$m], $MachinePrecision] + -2.0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;e^{-x\_m} + \left(e^{x\_m} - 2\right) \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, \cosh x\_m, -2\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) < 1.9999999999999999e-7Initial program 47.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.9999999999999999e-7 < (+.f64 (-.f64 (exp.f64 x) #s(literal 2 binary64)) (exp.f64 (neg.f64 x))) Initial program 98.8%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negN/A
associate-+r+N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-undefN/A
lower-fma.f64N/A
lower-cosh.f64N/A
metadata-eval98.4
Applied rewrites98.4%
Final simplification100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (fma x_m x_m (* (* (* 0.08333333333333333 (* x_m x_m)) x_m) x_m)))
x_m = fabs(x);
double code(double x_m) {
return fma(x_m, x_m, (((0.08333333333333333 * (x_m * x_m)) * x_m) * x_m));
}
x_m = abs(x) function code(x_m) return fma(x_m, x_m, Float64(Float64(Float64(0.08333333333333333 * Float64(x_m * x_m)) * x_m) * x_m)) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * x$95$m + N[(N[(N[(0.08333333333333333 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\mathsf{fma}\left(x\_m, x\_m, \left(\left(0.08333333333333333 \cdot \left(x\_m \cdot x\_m\right)\right) \cdot x\_m\right) \cdot x\_m\right)
\end{array}
Initial program 49.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f6497.8
Applied rewrites97.8%
Applied rewrites97.8%
Applied rewrites97.8%
Final simplification97.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* x_m x_m))
x_m = fabs(x);
double code(double x_m) {
return x_m * x_m;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m * x_m
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m * x_m;
}
x_m = math.fabs(x) def code(x_m): return x_m * x_m
x_m = abs(x) function code(x_m) return Float64(x_m * x_m) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m * x_m; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot x\_m
\end{array}
Initial program 49.2%
Taylor expanded in x around 0
unpow2N/A
lower-*.f6497.3
Applied rewrites97.3%
(FPCore (x) :precision binary64 (let* ((t_0 (sinh (/ x 2.0)))) (* 4.0 (* t_0 t_0))))
double code(double x) {
double t_0 = sinh((x / 2.0));
return 4.0 * (t_0 * t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sinh((x / 2.0d0))
code = 4.0d0 * (t_0 * t_0)
end function
public static double code(double x) {
double t_0 = Math.sinh((x / 2.0));
return 4.0 * (t_0 * t_0);
}
def code(x): t_0 = math.sinh((x / 2.0)) return 4.0 * (t_0 * t_0)
function code(x) t_0 = sinh(Float64(x / 2.0)) return Float64(4.0 * Float64(t_0 * t_0)) end
function tmp = code(x) t_0 = sinh((x / 2.0)); tmp = 4.0 * (t_0 * t_0); end
code[x_] := Block[{t$95$0 = N[Sinh[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sinh \left(\frac{x}{2}\right)\\
4 \cdot \left(t\_0 \cdot t\_0\right)
\end{array}
\end{array}
herbie shell --seed 2024277
(FPCore (x)
:name "exp2 (problem 3.3.7)"
:precision binary64
:pre (<= (fabs x) 710.0)
:alt
(! :herbie-platform default (* 4 (* (sinh (/ x 2)) (sinh (/ x 2)))))
(+ (- (exp x) 2.0) (exp (- x))))