
(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))) 5e-5)
(fma
0.002777777777777778
(pow x 6.0)
(fma
x
x
(fma
0.08333333333333333
(pow x 4.0)
(* 4.96031746031746e-5 (pow x 8.0)))))
(- (* 2.0 (cosh x)) 2.0)))
double code(double x) {
double tmp;
if (((exp(x) - 2.0) + exp(-x)) <= 5e-5) {
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 = (2.0 * cosh(x)) - 2.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 5e-5) 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 = 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], 5e-5], 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[(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 5 \cdot 10^{-5}:\\
\;\;\;\;\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}:\\
\;\;\;\;2 \cdot \cosh x - 2\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 5.00000000000000024e-5Initial program 47.2%
associate-+l-47.2%
sub-neg47.2%
sub-neg47.2%
+-commutative47.2%
distribute-neg-in47.2%
remove-double-neg47.2%
metadata-eval47.2%
Simplified47.2%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
if 5.00000000000000024e-5 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 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%
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))) 5e-5)
(fma
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)) <= 5e-5) {
tmp = fma(0.002777777777777778, pow(x, 6.0), ((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))) <= 5e-5) tmp = fma(0.002777777777777778, (x ^ 6.0), Float64(Float64(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], 5e-5], N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision] + N[(N[(x * x), $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 5 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, x \cdot 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))) < 5.00000000000000024e-5Initial program 47.2%
associate-+l-47.2%
sub-neg47.2%
sub-neg47.2%
+-commutative47.2%
distribute-neg-in47.2%
remove-double-neg47.2%
metadata-eval47.2%
Simplified47.2%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
Simplified100.0%
if 5.00000000000000024e-5 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 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%
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 (let* ((t_0 (+ (- (exp x) 2.0) (exp (- x))))) (if (<= t_0 2e-11) (+ (* x x) (* 0.08333333333333333 (pow x 4.0))) t_0)))
double code(double x) {
double t_0 = (exp(x) - 2.0) + exp(-x);
double tmp;
if (t_0 <= 2e-11) {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (exp(x) - 2.0d0) + exp(-x)
if (t_0 <= 2d-11) then
tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (Math.exp(x) - 2.0) + Math.exp(-x);
double tmp;
if (t_0 <= 2e-11) {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (math.exp(x) - 2.0) + math.exp(-x) tmp = 0 if t_0 <= 2e-11: tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0)) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) tmp = 0.0 if (t_0 <= 2e-11) tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (exp(x) - 2.0) + exp(-x); tmp = 0.0; if (t_0 <= 2e-11) tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0)); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-11], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(e^{x} - 2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.99999999999999988e-11Initial program 46.9%
associate-+l-46.9%
sub-neg46.9%
sub-neg46.9%
+-commutative46.9%
distribute-neg-in46.9%
remove-double-neg46.9%
metadata-eval46.9%
Simplified46.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
if 1.99999999999999988e-11 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (- (exp x) 2.0) (exp (- x))))) (if (<= t_0 2e-11) (fma x x (* 0.08333333333333333 (pow x 4.0))) t_0)))
double code(double x) {
double t_0 = (exp(x) - 2.0) + exp(-x);
double tmp;
if (t_0 <= 2e-11) {
tmp = fma(x, x, (0.08333333333333333 * pow(x, 4.0)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) tmp = 0.0 if (t_0 <= 2e-11) tmp = fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = t_0; end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-11], N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(e^{x} - 2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.99999999999999988e-11Initial program 46.9%
associate-+l-46.9%
sub-neg46.9%
sub-neg46.9%
+-commutative46.9%
distribute-neg-in46.9%
remove-double-neg46.9%
metadata-eval46.9%
Simplified46.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
fma-def100.0%
Applied egg-rr100.0%
if 1.99999999999999988e-11 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -0.0056) (not (<= x 0.0055))) (- (* 2.0 (cosh x)) 2.0) (+ (* x x) (* 0.08333333333333333 (pow x 4.0)))))
double code(double x) {
double tmp;
if ((x <= -0.0056) || !(x <= 0.0055)) {
tmp = (2.0 * cosh(x)) - 2.0;
} else {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.0056d0)) .or. (.not. (x <= 0.0055d0))) then
tmp = (2.0d0 * cosh(x)) - 2.0d0
else
tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -0.0056) || !(x <= 0.0055)) {
tmp = (2.0 * Math.cosh(x)) - 2.0;
} else {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.0056) or not (x <= 0.0055): tmp = (2.0 * math.cosh(x)) - 2.0 else: tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -0.0056) || !(x <= 0.0055)) tmp = Float64(Float64(2.0 * cosh(x)) - 2.0); else tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.0056) || ~((x <= 0.0055))) tmp = (2.0 * cosh(x)) - 2.0; else tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.0056], N[Not[LessEqual[x, 0.0055]], $MachinePrecision]], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0056 \lor \neg \left(x \leq 0.0055\right):\\
\;\;\;\;2 \cdot \cosh x - 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\end{array}
\end{array}
if x < -0.00559999999999999994 or 0.0054999999999999997 < x Initial program 99.9%
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%
if -0.00559999999999999994 < x < 0.0054999999999999997Initial program 46.9%
associate-+l-46.9%
sub-neg46.9%
sub-neg46.9%
+-commutative46.9%
distribute-neg-in46.9%
remove-double-neg46.9%
metadata-eval46.9%
Simplified46.9%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -0.0002) (not (<= x 0.00018))) (- (* 2.0 (cosh x)) 2.0) (* x x)))
double code(double x) {
double tmp;
if ((x <= -0.0002) || !(x <= 0.00018)) {
tmp = (2.0 * cosh(x)) - 2.0;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.0002d0)) .or. (.not. (x <= 0.00018d0))) then
tmp = (2.0d0 * cosh(x)) - 2.0d0
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -0.0002) || !(x <= 0.00018)) {
tmp = (2.0 * Math.cosh(x)) - 2.0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.0002) or not (x <= 0.00018): tmp = (2.0 * math.cosh(x)) - 2.0 else: tmp = x * x return tmp
function code(x) tmp = 0.0 if ((x <= -0.0002) || !(x <= 0.00018)) tmp = Float64(Float64(2.0 * cosh(x)) - 2.0); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.0002) || ~((x <= 0.00018))) tmp = (2.0 * cosh(x)) - 2.0; else tmp = x * x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.0002], N[Not[LessEqual[x, 0.00018]], $MachinePrecision]], N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0002 \lor \neg \left(x \leq 0.00018\right):\\
\;\;\;\;2 \cdot \cosh x - 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -2.0000000000000001e-4 or 1.80000000000000011e-4 < x Initial program 99.9%
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%
if -2.0000000000000001e-4 < x < 1.80000000000000011e-4Initial program 46.9%
associate-+l-46.9%
sub-neg46.9%
sub-neg46.9%
+-commutative46.9%
distribute-neg-in46.9%
remove-double-neg46.9%
metadata-eval46.9%
Simplified46.9%
Taylor expanded in x around 0 99.7%
unpow299.7%
Simplified99.7%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x -4.5) (* 0.002777777777777778 (pow x 6.0)) (if (<= x 1.66) (* x x) (expm1 x))))
double code(double x) {
double tmp;
if (x <= -4.5) {
tmp = 0.002777777777777778 * pow(x, 6.0);
} else if (x <= 1.66) {
tmp = x * x;
} else {
tmp = expm1(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -4.5) {
tmp = 0.002777777777777778 * Math.pow(x, 6.0);
} else if (x <= 1.66) {
tmp = x * x;
} else {
tmp = Math.expm1(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -4.5: tmp = 0.002777777777777778 * math.pow(x, 6.0) elif x <= 1.66: tmp = x * x else: tmp = math.expm1(x) return tmp
function code(x) tmp = 0.0 if (x <= -4.5) tmp = Float64(0.002777777777777778 * (x ^ 6.0)); elseif (x <= 1.66) tmp = Float64(x * x); else tmp = expm1(x); end return tmp end
code[x_] := If[LessEqual[x, -4.5], N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.66], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6}\\
\mathbf{elif}\;x \leq 1.66:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\end{array}
if x < -4.5Initial 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 85.8%
fma-def85.8%
unpow285.8%
Simplified85.8%
Taylor expanded in x around inf 85.8%
if -4.5 < x < 1.65999999999999992Initial program 47.2%
associate-+l-47.2%
sub-neg47.2%
sub-neg47.2%
+-commutative47.2%
distribute-neg-in47.2%
remove-double-neg47.2%
metadata-eval47.2%
Simplified47.2%
Taylor expanded in x around 0 99.3%
unpow299.3%
Simplified99.3%
if 1.65999999999999992 < 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.9%
Taylor expanded in x around inf 98.9%
expm1-def98.9%
Simplified98.9%
Final simplification95.6%
(FPCore (x) :precision binary64 (if (<= x 1.66) (* x x) (expm1 x)))
double code(double x) {
double tmp;
if (x <= 1.66) {
tmp = x * x;
} else {
tmp = expm1(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.66) {
tmp = x * x;
} else {
tmp = Math.expm1(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.66: tmp = x * x else: tmp = math.expm1(x) return tmp
function code(x) tmp = 0.0 if (x <= 1.66) tmp = Float64(x * x); else tmp = expm1(x); end return tmp end
code[x_] := If[LessEqual[x, 1.66], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.66:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\end{array}
if x < 1.65999999999999992Initial program 66.2%
associate-+l-66.2%
sub-neg66.2%
sub-neg66.2%
+-commutative66.2%
distribute-neg-in66.2%
remove-double-neg66.2%
metadata-eval66.2%
Simplified66.2%
Taylor expanded in x around 0 82.2%
unpow282.2%
Simplified82.2%
if 1.65999999999999992 < 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.9%
Taylor expanded in x around inf 98.9%
expm1-def98.9%
Simplified98.9%
Final simplification86.8%
(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 75.5%
associate-+l-75.4%
sub-neg75.4%
sub-neg75.4%
+-commutative75.4%
distribute-neg-in75.4%
remove-double-neg75.4%
metadata-eval75.4%
Simplified75.4%
Taylor expanded in x around 0 76.8%
unpow276.8%
Simplified76.8%
Final simplification76.8%
(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 75.5%
associate-+l-75.4%
sub-neg75.4%
sub-neg75.4%
+-commutative75.4%
distribute-neg-in75.4%
remove-double-neg75.4%
metadata-eval75.4%
Simplified75.4%
Taylor expanded in x around 0 48.6%
Taylor expanded in x around 0 4.4%
Final simplification4.4%
(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 2023194
(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))))