
(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}
(FPCore (x)
:precision binary64
(if (<= (+ (- (exp x) 2.0) (exp (- x))) 0.001)
(fma
0.002777777777777778
(pow x 6.0)
(fma
x
x
(fma
0.08333333333333333
(pow x 4.0)
(* 4.96031746031746e-5 (pow x 8.0)))))
(expm1 (log1p (fma 2.0 (cosh x) -2.0)))))
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 0.001) {
tmp = fma(0.002777777777777778, pow(x, 6.0), fma(x, x, fma(0.08333333333333333, pow(x, 4.0), (4.96031746031746e-5 * pow(x, 8.0)))));
} else {
tmp = expm1(log1p(fma(2.0, cosh(x), -2.0)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 0.001) tmp = fma(0.002777777777777778, (x ^ 6.0), fma(x, x, fma(0.08333333333333333, (x ^ 4.0), Float64(4.96031746031746e-5 * (x ^ 8.0))))); else tmp = expm1(log1p(fma(2.0, cosh(x), -2.0))); end return tmp end
code[x_] := If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.001], N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision] + N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision] + N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Exp[N[Log[1 + N[(2.0 * N[Cosh[x], $MachinePrecision] + -2.0), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.001:\\
\;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, \mathsf{fma}\left(0.08333333333333333, {x}^{4}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(2, \cosh x, -2\right)\right)\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1e-3Initial program 54.1%
associate-+l-54.1%
sub-neg54.1%
sub-neg54.1%
+-commutative54.1%
distribute-neg-in54.1%
remove-double-neg54.1%
metadata-eval54.1%
Simplified54.1%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
if 1e-3 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.9%
associate-+l-100.0%
sub-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
metadata-eval100.0%
Simplified100.0%
+-commutative100.0%
associate-+r+99.9%
metadata-eval99.9%
sub-neg99.9%
expm1-log1p-u99.9%
+-commutative99.9%
associate-+r-100.0%
+-commutative100.0%
cosh-undef100.0%
fma-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= (+ (- (exp x) 2.0) (exp (- x))) 0.001)
(+
(+ (* 0.002777777777777778 (pow x 6.0)) (* x x))
(+
(* 4.96031746031746e-5 (pow x 8.0))
(* 0.08333333333333333 (pow x 4.0))))
(expm1 (log1p (fma 2.0 (cosh x) -2.0)))))
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 0.001) {
tmp = ((0.002777777777777778 * pow(x, 6.0)) + (x * x)) + ((4.96031746031746e-5 * pow(x, 8.0)) + (0.08333333333333333 * pow(x, 4.0)));
} else {
tmp = expm1(log1p(fma(2.0, cosh(x), -2.0)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 0.001) tmp = Float64(Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + Float64(x * x)) + Float64(Float64(4.96031746031746e-5 * (x ^ 8.0)) + Float64(0.08333333333333333 * (x ^ 4.0)))); else tmp = expm1(log1p(fma(2.0, cosh(x), -2.0))); end return tmp end
code[x_] := If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Exp[N[Log[1 + N[(2.0 * N[Cosh[x], $MachinePrecision] + -2.0), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.001:\\
\;\;\;\;\left(0.002777777777777778 \cdot {x}^{6} + x \cdot x\right) + \left(4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(2, \cosh x, -2\right)\right)\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1e-3Initial program 54.1%
associate-+l-54.1%
sub-neg54.1%
sub-neg54.1%
+-commutative54.1%
distribute-neg-in54.1%
remove-double-neg54.1%
metadata-eval54.1%
Simplified54.1%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
fma-udef100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
if 1e-3 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.9%
associate-+l-100.0%
sub-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
metadata-eval100.0%
Simplified100.0%
+-commutative100.0%
associate-+r+99.9%
metadata-eval99.9%
sub-neg99.9%
expm1-log1p-u99.9%
+-commutative99.9%
associate-+r-100.0%
+-commutative100.0%
cosh-undef100.0%
fma-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= (+ (- (exp x) 2.0) (exp (- x))) 0.001)
(+
(+ (* 0.002777777777777778 (pow x 6.0)) (* x x))
(+
(* 4.96031746031746e-5 (pow x 8.0))
(* 0.08333333333333333 (pow x 4.0))))
(- (* 2.0 (cosh x)) 2.0)))
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 0.001) {
tmp = ((0.002777777777777778 * pow(x, 6.0)) + (x * x)) + ((4.96031746031746e-5 * pow(x, 8.0)) + (0.08333333333333333 * pow(x, 4.0)));
} else {
tmp = (2.0 * cosh(x)) - 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((exp(x) - 2.0d0) + exp(-x)) <= 0.001d0) then
tmp = ((0.002777777777777778d0 * (x ** 6.0d0)) + (x * x)) + ((4.96031746031746d-5 * (x ** 8.0d0)) + (0.08333333333333333d0 * (x ** 4.0d0)))
else
tmp = (2.0d0 * cosh(x)) - 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((Math.exp(x) - 2.0) + Math.exp(-x)) <= 0.001) {
tmp = ((0.002777777777777778 * Math.pow(x, 6.0)) + (x * x)) + ((4.96031746031746e-5 * Math.pow(x, 8.0)) + (0.08333333333333333 * Math.pow(x, 4.0)));
} else {
tmp = (2.0 * Math.cosh(x)) - 2.0;
}
return tmp;
}
def code(x): tmp = 0 if ((math.exp(x) - 2.0) + math.exp(-x)) <= 0.001: tmp = ((0.002777777777777778 * math.pow(x, 6.0)) + (x * x)) + ((4.96031746031746e-5 * math.pow(x, 8.0)) + (0.08333333333333333 * math.pow(x, 4.0))) else: tmp = (2.0 * math.cosh(x)) - 2.0 return tmp
function code(x) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 0.001) tmp = Float64(Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + Float64(x * x)) + Float64(Float64(4.96031746031746e-5 * (x ^ 8.0)) + Float64(0.08333333333333333 * (x ^ 4.0)))); else tmp = Float64(Float64(2.0 * cosh(x)) - 2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((exp(x) - 2.0) + exp(-x)) <= 0.001) tmp = ((0.002777777777777778 * (x ^ 6.0)) + (x * x)) + ((4.96031746031746e-5 * (x ^ 8.0)) + (0.08333333333333333 * (x ^ 4.0))); else tmp = (2.0 * cosh(x)) - 2.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.001:\\
\;\;\;\;\left(0.002777777777777778 \cdot {x}^{6} + x \cdot x\right) + \left(4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1e-3Initial program 54.1%
associate-+l-54.1%
sub-neg54.1%
sub-neg54.1%
+-commutative54.1%
distribute-neg-in54.1%
remove-double-neg54.1%
metadata-eval54.1%
Simplified54.1%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
fma-udef100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
if 1e-3 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.9%
associate-+l-100.0%
sub-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
metadata-eval100.0%
Simplified100.0%
associate-+r+100.0%
cosh-undef100.0%
fma-def100.0%
metadata-eval100.0%
fma-neg100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= (+ (- (exp x) 2.0) (exp (- x))) 0.001)
(+
(+ (* 0.002777777777777778 (pow x 6.0)) (* x x))
(* 0.08333333333333333 (pow x 4.0)))
(- (* 2.0 (cosh x)) 2.0)))
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 0.001) {
tmp = ((0.002777777777777778 * pow(x, 6.0)) + (x * x)) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = (2.0 * cosh(x)) - 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((exp(x) - 2.0d0) + exp(-x)) <= 0.001d0) then
tmp = ((0.002777777777777778d0 * (x ** 6.0d0)) + (x * x)) + (0.08333333333333333d0 * (x ** 4.0d0))
else
tmp = (2.0d0 * cosh(x)) - 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((Math.exp(x) - 2.0) + Math.exp(-x)) <= 0.001) {
tmp = ((0.002777777777777778 * Math.pow(x, 6.0)) + (x * x)) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = (2.0 * Math.cosh(x)) - 2.0;
}
return tmp;
}
def code(x): tmp = 0 if ((math.exp(x) - 2.0) + math.exp(-x)) <= 0.001: tmp = ((0.002777777777777778 * math.pow(x, 6.0)) + (x * x)) + (0.08333333333333333 * math.pow(x, 4.0)) else: tmp = (2.0 * math.cosh(x)) - 2.0 return tmp
function code(x) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 0.001) tmp = Float64(Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + Float64(x * x)) + Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = Float64(Float64(2.0 * cosh(x)) - 2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((exp(x) - 2.0) + exp(-x)) <= 0.001) tmp = ((0.002777777777777778 * (x ^ 6.0)) + (x * x)) + (0.08333333333333333 * (x ^ 4.0)); else tmp = (2.0 * cosh(x)) - 2.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.001:\\
\;\;\;\;\left(0.002777777777777778 \cdot {x}^{6} + x \cdot x\right) + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1e-3Initial program 54.1%
associate-+l-54.1%
sub-neg54.1%
sub-neg54.1%
+-commutative54.1%
distribute-neg-in54.1%
remove-double-neg54.1%
metadata-eval54.1%
Simplified54.1%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
fma-udef100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 99.9%
if 1e-3 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.9%
associate-+l-100.0%
sub-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
metadata-eval100.0%
Simplified100.0%
associate-+r+100.0%
cosh-undef100.0%
fma-def100.0%
metadata-eval100.0%
fma-neg100.0%
Applied egg-rr100.0%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= (+ (- (exp x) 2.0) (exp (- x))) 1e-6) (fma x x (* 0.08333333333333333 (pow x 4.0))) (- (* 2.0 (cosh x)) 2.0)))
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 1e-6) {
tmp = fma(x, x, (0.08333333333333333 * pow(x, 4.0)));
} else {
tmp = (2.0 * cosh(x)) - 2.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 1e-6) tmp = fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = Float64(Float64(2.0 * cosh(x)) - 2.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 1e-6], N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 9.99999999999999955e-7Initial program 53.9%
associate-+l-53.8%
sub-neg53.8%
sub-neg53.8%
+-commutative53.8%
distribute-neg-in53.8%
remove-double-neg53.8%
metadata-eval53.8%
Simplified53.8%
Taylor expanded in x around 0 99.9%
unpow299.9%
Simplified99.9%
fma-def99.9%
Applied egg-rr99.9%
if 9.99999999999999955e-7 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.8%
associate-+l-99.8%
sub-neg99.8%
sub-neg99.8%
+-commutative99.8%
distribute-neg-in99.8%
remove-double-neg99.8%
metadata-eval99.8%
Simplified99.8%
associate-+r+99.8%
cosh-undef99.8%
fma-def99.8%
metadata-eval99.8%
fma-neg99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= (+ (- (exp x) 2.0) (exp (- x))) 1e-6) (+ (* x x) (* 0.08333333333333333 (pow x 4.0))) (- (* 2.0 (cosh x)) 2.0)))
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 1e-6) {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = (2.0 * cosh(x)) - 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((exp(x) - 2.0d0) + exp(-x)) <= 1d-6) then
tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
else
tmp = (2.0d0 * cosh(x)) - 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((Math.exp(x) - 2.0) + Math.exp(-x)) <= 1e-6) {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = (2.0 * Math.cosh(x)) - 2.0;
}
return tmp;
}
def code(x): tmp = 0 if ((math.exp(x) - 2.0) + math.exp(-x)) <= 1e-6: tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0)) else: tmp = (2.0 * math.cosh(x)) - 2.0 return tmp
function code(x) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 1e-6) tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = Float64(Float64(2.0 * cosh(x)) - 2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((exp(x) - 2.0) + exp(-x)) <= 1e-6) tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0)); else tmp = (2.0 * cosh(x)) - 2.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 1e-6], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 10^{-6}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 9.99999999999999955e-7Initial program 53.9%
associate-+l-53.8%
sub-neg53.8%
sub-neg53.8%
+-commutative53.8%
distribute-neg-in53.8%
remove-double-neg53.8%
metadata-eval53.8%
Simplified53.8%
Taylor expanded in x around 0 99.9%
unpow299.9%
Simplified99.9%
if 9.99999999999999955e-7 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.8%
associate-+l-99.8%
sub-neg99.8%
sub-neg99.8%
+-commutative99.8%
distribute-neg-in99.8%
remove-double-neg99.8%
metadata-eval99.8%
Simplified99.8%
associate-+r+99.8%
cosh-undef99.8%
fma-def99.8%
metadata-eval99.8%
fma-neg99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 0.000195) (* x x) (- (* 2.0 (cosh x)) 2.0)))
double code(double x) {
double tmp;
if (x <= 0.000195) {
tmp = x * x;
} else {
tmp = (2.0 * cosh(x)) - 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.000195d0) then
tmp = x * x
else
tmp = (2.0d0 * cosh(x)) - 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.000195) {
tmp = x * x;
} else {
tmp = (2.0 * Math.cosh(x)) - 2.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.000195: tmp = x * x else: tmp = (2.0 * math.cosh(x)) - 2.0 return tmp
function code(x) tmp = 0.0 if (x <= 0.000195) tmp = Float64(x * x); else tmp = Float64(Float64(2.0 * cosh(x)) - 2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.000195) tmp = x * x; else tmp = (2.0 * cosh(x)) - 2.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.000195], N[(x * x), $MachinePrecision], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.000195:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\end{array}
if x < 1.94999999999999996e-4Initial program 71.1%
associate-+l-71.1%
sub-neg71.1%
sub-neg71.1%
+-commutative71.1%
distribute-neg-in71.1%
remove-double-neg71.1%
metadata-eval71.1%
Simplified71.1%
Taylor expanded in x around 0 81.0%
unpow281.0%
Simplified81.0%
if 1.94999999999999996e-4 < x Initial program 98.9%
associate-+l-98.9%
sub-neg98.9%
sub-neg98.9%
+-commutative98.9%
distribute-neg-in98.9%
remove-double-neg98.9%
metadata-eval98.9%
Simplified98.9%
associate-+r+98.8%
cosh-undef98.9%
fma-def98.9%
metadata-eval98.9%
fma-neg98.9%
Applied egg-rr98.9%
Final simplification85.4%
(FPCore (x) :precision binary64 (if (<= x 1.65) (* x x) (expm1 x)))
double code(double x) {
double tmp;
if (x <= 1.65) {
tmp = x * x;
} else {
tmp = expm1(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.65) {
tmp = x * x;
} else {
tmp = Math.expm1(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.65: tmp = x * x else: tmp = math.expm1(x) return tmp
function code(x) tmp = 0.0 if (x <= 1.65) tmp = Float64(x * x); else tmp = expm1(x); end return tmp end
code[x_] := If[LessEqual[x, 1.65], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.65:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\end{array}
if x < 1.6499999999999999Initial program 71.0%
associate-+l-71.0%
sub-neg71.0%
sub-neg71.0%
+-commutative71.0%
distribute-neg-in71.0%
remove-double-neg71.0%
metadata-eval71.0%
Simplified71.0%
Taylor expanded in x around 0 80.8%
unpow280.8%
Simplified80.8%
if 1.6499999999999999 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 98.8%
Taylor expanded in x around inf 98.8%
expm1-def98.8%
Simplified98.8%
Final simplification85.1%
(FPCore (x) :precision binary64 (* x x))
double code(double x) {
return x * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * x
end function
public static double code(double x) {
return x * x;
}
def code(x): return x * x
function code(x) return Float64(x * x) end
function tmp = code(x) tmp = x * x; end
code[x_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 77.9%
associate-+l-77.9%
sub-neg77.9%
sub-neg77.9%
+-commutative77.9%
distribute-neg-in77.9%
remove-double-neg77.9%
metadata-eval77.9%
Simplified77.9%
Taylor expanded in x around 0 72.1%
unpow272.1%
Simplified72.1%
Final simplification72.1%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 77.9%
associate-+l-77.9%
sub-neg77.9%
sub-neg77.9%
+-commutative77.9%
distribute-neg-in77.9%
remove-double-neg77.9%
metadata-eval77.9%
Simplified77.9%
Taylor expanded in x around 0 48.2%
Taylor expanded in x around 0 4.3%
Final simplification4.3%
(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 2023278
(FPCore (x)
:name "exp2 (problem 3.3.7)"
:precision binary64
:herbie-target
(* 4.0 (pow (sinh (/ x 2.0)) 2.0))
(+ (- (exp x) 2.0) (exp (- x))))