
(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 10 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))))
(if (<= (+ (- (exp x_m) 2.0) t_0) 2e-9)
(pow x_m 2.0)
(+ (exp x_m) (+ t_0 -2.0)))))x_m = fabs(x);
double code(double x_m) {
double t_0 = exp(-x_m);
double tmp;
if (((exp(x_m) - 2.0) + t_0) <= 2e-9) {
tmp = pow(x_m, 2.0);
} else {
tmp = exp(x_m) + (t_0 + -2.0);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-x_m)
if (((exp(x_m) - 2.0d0) + t_0) <= 2d-9) then
tmp = x_m ** 2.0d0
else
tmp = exp(x_m) + (t_0 + (-2.0d0))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double t_0 = Math.exp(-x_m);
double tmp;
if (((Math.exp(x_m) - 2.0) + t_0) <= 2e-9) {
tmp = Math.pow(x_m, 2.0);
} else {
tmp = Math.exp(x_m) + (t_0 + -2.0);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): t_0 = math.exp(-x_m) tmp = 0 if ((math.exp(x_m) - 2.0) + t_0) <= 2e-9: tmp = math.pow(x_m, 2.0) else: tmp = math.exp(x_m) + (t_0 + -2.0) return tmp
x_m = abs(x) function code(x_m) t_0 = exp(Float64(-x_m)) tmp = 0.0 if (Float64(Float64(exp(x_m) - 2.0) + t_0) <= 2e-9) tmp = x_m ^ 2.0; else tmp = Float64(exp(x_m) + Float64(t_0 + -2.0)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) t_0 = exp(-x_m); tmp = 0.0; if (((exp(x_m) - 2.0) + t_0) <= 2e-9) tmp = x_m ^ 2.0; else tmp = exp(x_m) + (t_0 + -2.0); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[Exp[(-x$95$m)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x$95$m], $MachinePrecision] - 2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 2e-9], N[Power[x$95$m, 2.0], $MachinePrecision], N[(N[Exp[x$95$m], $MachinePrecision] + N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := e^{-x_m}\\
\mathbf{if}\;\left(e^{x_m} - 2\right) + t_0 \leq 2 \cdot 10^{-9}:\\
\;\;\;\;{x_m}^{2}\\
\mathbf{else}:\\
\;\;\;\;e^{x_m} + \left(t_0 + -2\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 2.00000000000000012e-9Initial program 52.6%
associate-+l-52.6%
sub-neg52.6%
sub-neg52.6%
distribute-neg-in52.6%
remove-double-neg52.6%
+-commutative52.6%
metadata-eval52.6%
Simplified52.6%
Taylor expanded in x around 0 99.7%
if 2.00000000000000012e-9 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 89.7%
associate-+l-89.4%
sub-neg89.4%
sub-neg89.4%
distribute-neg-in89.4%
remove-double-neg89.4%
+-commutative89.4%
metadata-eval89.4%
Simplified89.4%
Final simplification99.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (+ (* 4.96031746031746e-5 (pow x_m 8.0)) (+ (* 0.002777777777777778 (pow x_m 6.0)) (fma x_m x_m (* 0.08333333333333333 (pow x_m 4.0))))))
x_m = fabs(x);
double code(double x_m) {
return (4.96031746031746e-5 * pow(x_m, 8.0)) + ((0.002777777777777778 * pow(x_m, 6.0)) + fma(x_m, x_m, (0.08333333333333333 * pow(x_m, 4.0))));
}
x_m = abs(x) function code(x_m) return Float64(Float64(4.96031746031746e-5 * (x_m ^ 8.0)) + Float64(Float64(0.002777777777777778 * (x_m ^ 6.0)) + fma(x_m, x_m, Float64(0.08333333333333333 * (x_m ^ 4.0))))) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(4.96031746031746e-5 * N[Power[x$95$m, 8.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.002777777777777778 * N[Power[x$95$m, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x$95$m * x$95$m + N[(0.08333333333333333 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
4.96031746031746 \cdot 10^{-5} \cdot {x_m}^{8} + \left(0.002777777777777778 \cdot {x_m}^{6} + \mathsf{fma}\left(x_m, x_m, 0.08333333333333333 \cdot {x_m}^{4}\right)\right)
\end{array}
Initial program 53.8%
associate-+l-53.7%
sub-neg53.7%
sub-neg53.7%
distribute-neg-in53.7%
remove-double-neg53.7%
+-commutative53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in x around 0 98.8%
+-commutative98.8%
unpow298.8%
fma-def98.8%
Applied egg-rr98.8%
Final simplification98.8%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(pow
(+
x_m
(+
(* 0.0005208333333333333 (pow x_m 5.0))
(* 0.041666666666666664 (pow x_m 3.0))))
2.0))x_m = fabs(x);
double code(double x_m) {
return pow((x_m + ((0.0005208333333333333 * pow(x_m, 5.0)) + (0.041666666666666664 * pow(x_m, 3.0)))), 2.0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (x_m + ((0.0005208333333333333d0 * (x_m ** 5.0d0)) + (0.041666666666666664d0 * (x_m ** 3.0d0)))) ** 2.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow((x_m + ((0.0005208333333333333 * Math.pow(x_m, 5.0)) + (0.041666666666666664 * Math.pow(x_m, 3.0)))), 2.0);
}
x_m = math.fabs(x) def code(x_m): return math.pow((x_m + ((0.0005208333333333333 * math.pow(x_m, 5.0)) + (0.041666666666666664 * math.pow(x_m, 3.0)))), 2.0)
x_m = abs(x) function code(x_m) return Float64(x_m + Float64(Float64(0.0005208333333333333 * (x_m ^ 5.0)) + Float64(0.041666666666666664 * (x_m ^ 3.0)))) ^ 2.0 end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m + ((0.0005208333333333333 * (x_m ^ 5.0)) + (0.041666666666666664 * (x_m ^ 3.0)))) ^ 2.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Power[N[(x$95$m + N[(N[(0.0005208333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision] + N[(0.041666666666666664 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{\left(x_m + \left(0.0005208333333333333 \cdot {x_m}^{5} + 0.041666666666666664 \cdot {x_m}^{3}\right)\right)}^{2}
\end{array}
Initial program 53.8%
associate-+l-53.7%
sub-neg53.7%
sub-neg53.7%
distribute-neg-in53.7%
remove-double-neg53.7%
+-commutative53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in x around 0 98.8%
+-commutative98.8%
unpow298.8%
fma-def98.8%
Applied egg-rr98.8%
add-sqr-sqrt98.8%
pow298.8%
fma-def98.8%
fma-def98.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 98.7%
Final simplification98.7%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (+ (* 0.002777777777777778 (pow x_m 6.0)) (fma x_m x_m (* 0.08333333333333333 (pow x_m 4.0)))))
x_m = fabs(x);
double code(double x_m) {
return (0.002777777777777778 * pow(x_m, 6.0)) + fma(x_m, x_m, (0.08333333333333333 * pow(x_m, 4.0)));
}
x_m = abs(x) function code(x_m) return Float64(Float64(0.002777777777777778 * (x_m ^ 6.0)) + fma(x_m, x_m, Float64(0.08333333333333333 * (x_m ^ 4.0)))) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(0.002777777777777778 * N[Power[x$95$m, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x$95$m * x$95$m + N[(0.08333333333333333 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
0.002777777777777778 \cdot {x_m}^{6} + \mathsf{fma}\left(x_m, x_m, 0.08333333333333333 \cdot {x_m}^{4}\right)
\end{array}
Initial program 53.8%
associate-+l-53.7%
sub-neg53.7%
sub-neg53.7%
distribute-neg-in53.7%
remove-double-neg53.7%
+-commutative53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in x around 0 98.7%
+-commutative98.8%
unpow298.8%
fma-def98.8%
Applied egg-rr98.7%
Final simplification98.7%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (fma x_m x_m (* 0.08333333333333333 (pow x_m 4.0))))
x_m = fabs(x);
double code(double x_m) {
return fma(x_m, x_m, (0.08333333333333333 * pow(x_m, 4.0)));
}
x_m = abs(x) function code(x_m) return fma(x_m, x_m, Float64(0.08333333333333333 * (x_m ^ 4.0))) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * x$95$m + N[(0.08333333333333333 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\mathsf{fma}\left(x_m, x_m, 0.08333333333333333 \cdot {x_m}^{4}\right)
\end{array}
Initial program 53.8%
associate-+l-53.7%
sub-neg53.7%
sub-neg53.7%
distribute-neg-in53.7%
remove-double-neg53.7%
+-commutative53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in x around 0 98.3%
+-commutative98.8%
unpow298.8%
fma-def98.8%
Applied egg-rr98.3%
Final simplification98.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.000175) (pow x_m 2.0) (- (* 2.0 (cosh x_m)) 2.0)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.000175) {
tmp = pow(x_m, 2.0);
} else {
tmp = (2.0 * cosh(x_m)) - 2.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 <= 0.000175d0) then
tmp = x_m ** 2.0d0
else
tmp = (2.0d0 * cosh(x_m)) - 2.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.000175) {
tmp = Math.pow(x_m, 2.0);
} else {
tmp = (2.0 * Math.cosh(x_m)) - 2.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.000175: tmp = math.pow(x_m, 2.0) else: tmp = (2.0 * math.cosh(x_m)) - 2.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.000175) tmp = x_m ^ 2.0; else tmp = Float64(Float64(2.0 * cosh(x_m)) - 2.0); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.000175) tmp = x_m ^ 2.0; else tmp = (2.0 * cosh(x_m)) - 2.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.000175], N[Power[x$95$m, 2.0], $MachinePrecision], N[(N[(2.0 * N[Cosh[x$95$m], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.000175:\\
\;\;\;\;{x_m}^{2}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x_m - 2\\
\end{array}
\end{array}
if x < 1.74999999999999998e-4Initial program 53.3%
associate-+l-53.3%
sub-neg53.3%
sub-neg53.3%
distribute-neg-in53.3%
remove-double-neg53.3%
+-commutative53.3%
metadata-eval53.3%
Simplified53.3%
Taylor expanded in x around 0 98.5%
if 1.74999999999999998e-4 < x Initial program 93.8%
associate-+l-93.7%
sub-neg93.7%
sub-neg93.7%
distribute-neg-in93.7%
remove-double-neg93.7%
+-commutative93.7%
metadata-eval93.7%
Simplified93.7%
+-commutative93.7%
associate-+r+93.8%
metadata-eval93.8%
sub-neg93.8%
+-commutative93.8%
associate-+r-92.9%
+-commutative92.9%
cosh-undef92.9%
Applied egg-rr92.9%
Final simplification98.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 2.3e-103) 0.0 (expm1 x_m)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.3e-103) {
tmp = 0.0;
} else {
tmp = expm1(x_m);
}
return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 2.3e-103) {
tmp = 0.0;
} else {
tmp = Math.expm1(x_m);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 2.3e-103: tmp = 0.0 else: tmp = math.expm1(x_m) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.3e-103) tmp = 0.0; else tmp = expm1(x_m); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 2.3e-103], 0.0, N[(Exp[x$95$m] - 1), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 2.3 \cdot 10^{-103}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x_m\right)\\
\end{array}
\end{array}
if x < 2.3000000000000001e-103Initial program 62.0%
associate-+l-62.0%
sub-neg62.0%
sub-neg62.0%
distribute-neg-in62.0%
remove-double-neg62.0%
+-commutative62.0%
metadata-eval62.0%
Simplified62.0%
+-commutative62.0%
associate-+r+62.0%
metadata-eval62.0%
sub-neg62.0%
+-commutative62.0%
associate-+r-62.0%
+-commutative62.0%
cosh-undef62.0%
Applied egg-rr62.0%
Taylor expanded in x around 0 59.9%
if 2.3000000000000001e-103 < x Initial program 12.9%
associate-+l-12.8%
sub-neg12.8%
sub-neg12.8%
distribute-neg-in12.8%
remove-double-neg12.8%
+-commutative12.8%
metadata-eval12.8%
Simplified12.8%
Taylor expanded in x around 0 7.7%
Taylor expanded in x around inf 7.7%
expm1-def10.1%
Simplified10.1%
Final simplification51.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (pow x_m 2.0))
x_m = fabs(x);
double code(double x_m) {
return pow(x_m, 2.0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m ** 2.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(x_m, 2.0);
}
x_m = math.fabs(x) def code(x_m): return math.pow(x_m, 2.0)
x_m = abs(x) function code(x_m) return x_m ^ 2.0 end
x_m = abs(x); function tmp = code(x_m) tmp = x_m ^ 2.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Power[x$95$m, 2.0], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{x_m}^{2}
\end{array}
Initial program 53.8%
associate-+l-53.7%
sub-neg53.7%
sub-neg53.7%
distribute-neg-in53.7%
remove-double-neg53.7%
+-commutative53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in x around 0 97.6%
Final simplification97.6%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 x_m)
x_m = fabs(x);
double code(double x_m) {
return x_m;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m;
}
x_m = math.fabs(x) def code(x_m): return x_m
x_m = abs(x) function code(x_m) return x_m end
x_m = abs(x); function tmp = code(x_m) tmp = x_m; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := x$95$m
\begin{array}{l}
x_m = \left|x\right|
\\
x_m
\end{array}
Initial program 53.8%
associate-+l-53.7%
sub-neg53.7%
sub-neg53.7%
distribute-neg-in53.7%
remove-double-neg53.7%
+-commutative53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in x around 0 51.1%
Taylor expanded in x around 0 5.8%
Final simplification5.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 0.0)
x_m = fabs(x);
double code(double x_m) {
return 0.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 0.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 0.0;
}
x_m = math.fabs(x) def code(x_m): return 0.0
x_m = abs(x) function code(x_m) return 0.0 end
x_m = abs(x); function tmp = code(x_m) tmp = 0.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 0.0
\begin{array}{l}
x_m = \left|x\right|
\\
0
\end{array}
Initial program 53.8%
associate-+l-53.7%
sub-neg53.7%
sub-neg53.7%
distribute-neg-in53.7%
remove-double-neg53.7%
+-commutative53.7%
metadata-eval53.7%
Simplified53.7%
+-commutative53.7%
associate-+r+53.8%
metadata-eval53.8%
sub-neg53.8%
+-commutative53.8%
associate-+r-53.7%
+-commutative53.7%
cosh-undef53.7%
Applied egg-rr53.7%
Taylor expanded in x around 0 50.6%
Final simplification50.6%
(FPCore (x) :precision binary64 (* 4.0 (pow (sinh (/ x 2.0)) 2.0)))
double code(double x) {
return 4.0 * pow(sinh((x / 2.0)), 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 4.0d0 * (sinh((x / 2.0d0)) ** 2.0d0)
end function
public static double code(double x) {
return 4.0 * Math.pow(Math.sinh((x / 2.0)), 2.0);
}
def code(x): return 4.0 * math.pow(math.sinh((x / 2.0)), 2.0)
function code(x) return Float64(4.0 * (sinh(Float64(x / 2.0)) ^ 2.0)) end
function tmp = code(x) tmp = 4.0 * (sinh((x / 2.0)) ^ 2.0); end
code[x_] := N[(4.0 * N[Power[N[Sinh[N[(x / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot {\sinh \left(\frac{x}{2}\right)}^{2}
\end{array}
herbie shell --seed 2024019
(FPCore (x)
:name "exp2 (problem 3.3.7)"
:precision binary64
:pre (<= (fabs x) 710.0)
:herbie-target
(* 4.0 (pow (sinh (/ x 2.0)) 2.0))
(+ (- (exp x) 2.0) (exp (- x))))