
(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 12 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
(let* ((t_0 (exp (- x))))
(if (<= (+ (- (exp x) 2.0) t_0) 0.001)
(fma
4.96031746031746e-5
(pow x 8.0)
(+
(+
(* 0.08333333333333333 (pow x 4.0))
(* 0.002777777777777778 (pow x 6.0)))
(* x x)))
(+ (exp x) (+ t_0 -2.0)))))
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (((exp(x) - 2.0) + t_0) <= 0.001) {
tmp = fma(4.96031746031746e-5, pow(x, 8.0), (((0.08333333333333333 * pow(x, 4.0)) + (0.002777777777777778 * pow(x, 6.0))) + (x * x)));
} else {
tmp = exp(x) + (t_0 + -2.0);
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + t_0) <= 0.001) tmp = fma(4.96031746031746e-5, (x ^ 8.0), Float64(Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(0.002777777777777778 * (x ^ 6.0))) + Float64(x * x))); else tmp = Float64(exp(x) + Float64(t_0 + -2.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 0.001], N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision] + N[(N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 0.001:\\
\;\;\;\;\mathsf{fma}\left(4.96031746031746 \cdot 10^{-5}, {x}^{8}, \left(0.08333333333333333 \cdot {x}^{4} + 0.002777777777777778 \cdot {x}^{6}\right) + x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1e-3Initial program 52.5%
associate-+l-52.6%
sub-neg52.6%
sub-neg52.6%
+-commutative52.6%
distribute-neg-in52.6%
remove-double-neg52.6%
metadata-eval52.6%
Simplified52.6%
Taylor expanded in x around 0 99.9%
fma-def99.9%
fma-def99.9%
+-commutative99.9%
unpow299.9%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
fma-udef99.9%
unpow299.9%
+-commutative99.9%
associate-+r+100.0%
fma-def100.0%
unpow2100.0%
Applied egg-rr100.0%
fma-udef100.0%
+-commutative100.0%
Applied egg-rr100.0%
if 1e-3 < (+.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%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (+ (- (exp x) 2.0) t_0) 0.0009)
(+
(* 0.002777777777777778 (pow x 6.0))
(fma x x (* 0.08333333333333333 (pow x 4.0))))
(- t_0 (log (+ 1.0 (expm1 (- 2.0 (exp x)))))))))
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (((exp(x) - 2.0) + t_0) <= 0.0009) {
tmp = (0.002777777777777778 * pow(x, 6.0)) + fma(x, x, (0.08333333333333333 * pow(x, 4.0)));
} else {
tmp = t_0 - log((1.0 + expm1((2.0 - exp(x)))));
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + t_0) <= 0.0009) tmp = Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0)))); else tmp = Float64(t_0 - log(Float64(1.0 + expm1(Float64(2.0 - exp(x)))))); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 0.0009], N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[Log[N[(1.0 + N[(Exp[N[(2.0 - N[Exp[x], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 0.0009:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6} + \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 - \log \left(1 + \mathsf{expm1}\left(2 - e^{x}\right)\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 8.9999999999999998e-4Initial program 52.3%
associate-+l-52.3%
sub-neg52.3%
sub-neg52.3%
+-commutative52.3%
distribute-neg-in52.3%
remove-double-neg52.3%
metadata-eval52.3%
Simplified52.3%
Taylor expanded in x around 0 99.7%
+-commutative99.7%
unpow299.7%
fma-udef99.8%
Applied egg-rr99.8%
if 8.9999999999999998e-4 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.9%
+-commutative99.9%
associate-+r-99.8%
+-commutative99.8%
associate-+r-99.9%
+-commutative99.9%
associate-+l-99.9%
Simplified99.9%
log1p-expm1-u99.9%
log1p-udef99.9%
Applied egg-rr99.9%
Final simplification99.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (+ (- (exp x) 2.0) t_0) 0.001)
(+
(* 0.002777777777777778 (pow x 6.0))
(fma x x (* 0.08333333333333333 (pow x 4.0))))
(+ (exp x) (+ t_0 -2.0)))))
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (((exp(x) - 2.0) + t_0) <= 0.001) {
tmp = (0.002777777777777778 * pow(x, 6.0)) + fma(x, x, (0.08333333333333333 * pow(x, 4.0)));
} else {
tmp = exp(x) + (t_0 + -2.0);
}
return tmp;
}
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + t_0) <= 0.001) tmp = Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0)))); else tmp = Float64(exp(x) + Float64(t_0 + -2.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 0.001], N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 0.001:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6} + \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1e-3Initial program 52.5%
associate-+l-52.6%
sub-neg52.6%
sub-neg52.6%
+-commutative52.6%
distribute-neg-in52.6%
remove-double-neg52.6%
metadata-eval52.6%
Simplified52.6%
Taylor expanded in x around 0 99.6%
+-commutative99.6%
unpow299.6%
fma-udef99.6%
Applied egg-rr99.6%
if 1e-3 < (+.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%
Final simplification99.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (+ (- (exp x) 2.0) t_0) 0.001)
(+
(* 0.002777777777777778 (pow x 6.0))
(+ (* 0.08333333333333333 (pow x 4.0)) (* x x)))
(+ (exp x) (+ t_0 -2.0)))))
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (((exp(x) - 2.0) + t_0) <= 0.001) {
tmp = (0.002777777777777778 * pow(x, 6.0)) + ((0.08333333333333333 * pow(x, 4.0)) + (x * x));
} else {
tmp = exp(x) + (t_0 + -2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-x)
if (((exp(x) - 2.0d0) + t_0) <= 0.001d0) then
tmp = (0.002777777777777778d0 * (x ** 6.0d0)) + ((0.08333333333333333d0 * (x ** 4.0d0)) + (x * x))
else
tmp = exp(x) + (t_0 + (-2.0d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.exp(-x);
double tmp;
if (((Math.exp(x) - 2.0) + t_0) <= 0.001) {
tmp = (0.002777777777777778 * Math.pow(x, 6.0)) + ((0.08333333333333333 * Math.pow(x, 4.0)) + (x * x));
} else {
tmp = Math.exp(x) + (t_0 + -2.0);
}
return tmp;
}
def code(x): t_0 = math.exp(-x) tmp = 0 if ((math.exp(x) - 2.0) + t_0) <= 0.001: tmp = (0.002777777777777778 * math.pow(x, 6.0)) + ((0.08333333333333333 * math.pow(x, 4.0)) + (x * x)) else: tmp = math.exp(x) + (t_0 + -2.0) return tmp
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + t_0) <= 0.001) tmp = Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(x * x))); else tmp = Float64(exp(x) + Float64(t_0 + -2.0)); end return tmp end
function tmp_2 = code(x) t_0 = exp(-x); tmp = 0.0; if (((exp(x) - 2.0) + t_0) <= 0.001) tmp = (0.002777777777777778 * (x ^ 6.0)) + ((0.08333333333333333 * (x ^ 4.0)) + (x * x)); else tmp = exp(x) + (t_0 + -2.0); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 0.001], N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 0.001:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6} + \left(0.08333333333333333 \cdot {x}^{4} + x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 + -2\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1e-3Initial program 52.5%
associate-+l-52.6%
sub-neg52.6%
sub-neg52.6%
+-commutative52.6%
distribute-neg-in52.6%
remove-double-neg52.6%
metadata-eval52.6%
Simplified52.6%
Taylor expanded in x around 0 99.6%
+-commutative99.6%
unpow299.6%
fma-udef99.6%
Applied egg-rr99.6%
fma-udef99.6%
Applied egg-rr99.6%
if 1e-3 < (+.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%
Final simplification99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (- (exp x) 2.0) (exp (- x))))) (if (<= t_0 2e-5) (+ (* 0.08333333333333333 (pow x 4.0)) (* x x)) t_0)))
double code(double x) {
double t_0 = (exp(x) - 2.0) + exp(-x);
double tmp;
if (t_0 <= 2e-5) {
tmp = (0.08333333333333333 * pow(x, 4.0)) + (x * x);
} 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-5) then
tmp = (0.08333333333333333d0 * (x ** 4.0d0)) + (x * x)
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-5) {
tmp = (0.08333333333333333 * Math.pow(x, 4.0)) + (x * x);
} 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-5: tmp = (0.08333333333333333 * math.pow(x, 4.0)) + (x * x) 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-5) tmp = Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(x * x)); 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-5) tmp = (0.08333333333333333 * (x ^ 4.0)) + (x * x); 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-5], N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $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^{-5}:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 2.00000000000000016e-5Initial program 51.4%
associate-+l-51.5%
sub-neg51.5%
sub-neg51.5%
+-commutative51.5%
distribute-neg-in51.5%
remove-double-neg51.5%
metadata-eval51.5%
Simplified51.5%
Taylor expanded in x around 0 99.8%
fma-def99.8%
unpow299.8%
Simplified99.8%
fma-udef99.8%
+-commutative99.8%
Applied egg-rr99.8%
if 2.00000000000000016e-5 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 99.5%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 0.0046) (+ (* 0.08333333333333333 (pow x 4.0)) (* x x)) (+ (exp x) (+ (exp (- x)) -2.0))))
double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = (0.08333333333333333 * pow(x, 4.0)) + (x * x);
} else {
tmp = exp(x) + (exp(-x) + -2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0046d0) then
tmp = (0.08333333333333333d0 * (x ** 4.0d0)) + (x * x)
else
tmp = exp(x) + (exp(-x) + (-2.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.0046) {
tmp = (0.08333333333333333 * Math.pow(x, 4.0)) + (x * x);
} else {
tmp = Math.exp(x) + (Math.exp(-x) + -2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.0046: tmp = (0.08333333333333333 * math.pow(x, 4.0)) + (x * x) else: tmp = math.exp(x) + (math.exp(-x) + -2.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.0046) tmp = Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(x * x)); else tmp = Float64(exp(x) + Float64(exp(Float64(-x)) + -2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0046) tmp = (0.08333333333333333 * (x ^ 4.0)) + (x * x); else tmp = exp(x) + (exp(-x) + -2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.0046], N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(N[Exp[(-x)], $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0046:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(e^{-x} + -2\right)\\
\end{array}
\end{array}
if x < 0.0045999999999999999Initial program 69.3%
associate-+l-69.3%
sub-neg69.3%
sub-neg69.3%
+-commutative69.3%
distribute-neg-in69.3%
remove-double-neg69.3%
metadata-eval69.3%
Simplified69.3%
Taylor expanded in x around 0 88.1%
fma-def88.1%
unpow288.1%
Simplified88.1%
fma-udef88.1%
+-commutative88.1%
Applied egg-rr88.1%
if 0.0045999999999999999 < x Initial program 99.6%
associate-+l-99.6%
sub-neg99.6%
sub-neg99.6%
+-commutative99.6%
distribute-neg-in99.6%
remove-double-neg99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification91.5%
(FPCore (x) :precision binary64 (if (<= x 0.0052) (+ (* 0.08333333333333333 (pow x 4.0)) (* x x)) (+ -2.0 (* 2.0 (cosh x)))))
double code(double x) {
double tmp;
if (x <= 0.0052) {
tmp = (0.08333333333333333 * pow(x, 4.0)) + (x * x);
} else {
tmp = -2.0 + (2.0 * cosh(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0052d0) then
tmp = (0.08333333333333333d0 * (x ** 4.0d0)) + (x * x)
else
tmp = (-2.0d0) + (2.0d0 * cosh(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.0052) {
tmp = (0.08333333333333333 * Math.pow(x, 4.0)) + (x * x);
} else {
tmp = -2.0 + (2.0 * Math.cosh(x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.0052: tmp = (0.08333333333333333 * math.pow(x, 4.0)) + (x * x) else: tmp = -2.0 + (2.0 * math.cosh(x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.0052) tmp = Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(x * x)); else tmp = Float64(-2.0 + Float64(2.0 * cosh(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0052) tmp = (0.08333333333333333 * (x ^ 4.0)) + (x * x); else tmp = -2.0 + (2.0 * cosh(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.0052], N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(-2.0 + N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0052:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\
\mathbf{else}:\\
\;\;\;\;-2 + 2 \cdot \cosh x\\
\end{array}
\end{array}
if x < 0.0051999999999999998Initial program 69.3%
associate-+l-69.3%
sub-neg69.3%
sub-neg69.3%
+-commutative69.3%
distribute-neg-in69.3%
remove-double-neg69.3%
metadata-eval69.3%
Simplified69.3%
Taylor expanded in x around 0 88.1%
fma-def88.1%
unpow288.1%
Simplified88.1%
fma-udef88.1%
+-commutative88.1%
Applied egg-rr88.1%
if 0.0051999999999999998 < x Initial program 99.6%
+-commutative99.6%
associate-+r-99.6%
+-commutative99.6%
associate-+r-99.6%
+-commutative99.6%
associate-+l-99.6%
Simplified99.6%
associate--r-99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
associate-+r+99.6%
cosh-undef99.6%
Applied egg-rr99.6%
Final simplification91.5%
(FPCore (x) :precision binary64 (if (<= x 0.000185) (* x x) (+ -2.0 (* 2.0 (cosh x)))))
double code(double x) {
double tmp;
if (x <= 0.000185) {
tmp = x * x;
} else {
tmp = -2.0 + (2.0 * cosh(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.000185d0) then
tmp = x * x
else
tmp = (-2.0d0) + (2.0d0 * cosh(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.000185) {
tmp = x * x;
} else {
tmp = -2.0 + (2.0 * Math.cosh(x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.000185: tmp = x * x else: tmp = -2.0 + (2.0 * math.cosh(x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.000185) tmp = Float64(x * x); else tmp = Float64(-2.0 + Float64(2.0 * cosh(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.000185) tmp = x * x; else tmp = -2.0 + (2.0 * cosh(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.000185], N[(x * x), $MachinePrecision], N[(-2.0 + N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.000185:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;-2 + 2 \cdot \cosh x\\
\end{array}
\end{array}
if x < 1.85e-4Initial program 69.3%
associate-+l-69.3%
sub-neg69.3%
sub-neg69.3%
+-commutative69.3%
distribute-neg-in69.3%
remove-double-neg69.3%
metadata-eval69.3%
Simplified69.3%
Taylor expanded in x around 0 81.2%
unpow281.2%
Simplified81.2%
if 1.85e-4 < x Initial program 99.6%
+-commutative99.6%
associate-+r-99.6%
+-commutative99.6%
associate-+r-99.6%
+-commutative99.6%
associate-+l-99.6%
Simplified99.6%
associate--r-99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
associate-+r+99.6%
cosh-undef99.6%
Applied egg-rr99.6%
Final simplification86.7%
(FPCore (x) :precision binary64 (if (<= x 1.7) (* x x) (expm1 x)))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = x * x;
} else {
tmp = expm1(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = x * x;
} else {
tmp = Math.expm1(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = x * x else: tmp = math.expm1(x) return tmp
function code(x) tmp = 0.0 if (x <= 1.7) tmp = Float64(x * x); else tmp = expm1(x); end return tmp end
code[x_] := If[LessEqual[x, 1.7], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 69.7%
associate-+l-69.7%
sub-neg69.7%
sub-neg69.7%
+-commutative69.7%
distribute-neg-in69.7%
remove-double-neg69.7%
metadata-eval69.7%
Simplified69.7%
Taylor expanded in x around 0 80.5%
unpow280.5%
Simplified80.5%
if 1.69999999999999996 < 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 100.0%
Taylor expanded in x around inf 100.0%
expm1-def100.0%
Simplified100.0%
Final simplification86.0%
(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 78.3%
associate-+l-78.3%
sub-neg78.3%
sub-neg78.3%
+-commutative78.3%
distribute-neg-in78.3%
remove-double-neg78.3%
metadata-eval78.3%
Simplified78.3%
Taylor expanded in x around 0 72.3%
unpow272.3%
Simplified72.3%
Final simplification72.3%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 78.3%
associate-+l-78.3%
sub-neg78.3%
sub-neg78.3%
+-commutative78.3%
distribute-neg-in78.3%
remove-double-neg78.3%
metadata-eval78.3%
Simplified78.3%
+-commutative78.3%
metadata-eval78.3%
sub-neg78.3%
associate--r-78.3%
add-sqr-sqrt38.0%
sqrt-unprod77.4%
sqr-neg77.4%
sqrt-unprod39.3%
add-sqr-sqrt51.2%
Applied egg-rr51.2%
associate--r-51.2%
sub-neg51.2%
metadata-eval51.2%
+-commutative51.2%
rem-square-sqrt28.5%
fabs-sqr28.5%
rem-square-sqrt31.5%
metadata-eval31.5%
sub-neg31.5%
fabs-sub31.5%
rem-square-sqrt3.0%
fabs-sqr3.0%
rem-square-sqrt3.0%
remove-double-neg3.0%
remove-double-neg3.0%
distribute-neg-out3.0%
+-commutative3.0%
neg-sub03.0%
associate--r-3.0%
metadata-eval3.0%
Simplified3.9%
Final simplification3.9%
(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 78.3%
associate-+l-78.3%
sub-neg78.3%
sub-neg78.3%
+-commutative78.3%
distribute-neg-in78.3%
remove-double-neg78.3%
metadata-eval78.3%
Simplified78.3%
Taylor expanded in x around 0 51.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 2023280
(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))))