
(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
(let* ((t_0 (+ (- (exp x) 2.0) (exp (- x)))))
(if (<= t_0 2e-6)
(fma
0.002777777777777778
(pow x 6.0)
(+ (* 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-6) {
tmp = fma(0.002777777777777778, pow(x, 6.0), ((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-6) tmp = fma(0.002777777777777778, (x ^ 6.0), Float64(Float64(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-6], 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], 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^{-6}:\\
\;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, x \cdot 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.99999999999999991e-6Initial program 56.3%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
Simplified100.0%
if 1.99999999999999991e-6 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (- (exp x) 2.0) (exp (- x))))) (if (<= t_0 2e-6) (+ (* 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-6) {
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-6) 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-6) {
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-6: 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-6) 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-6) 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-6], 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^{-6}:\\
\;\;\;\;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.99999999999999991e-6Initial program 56.3%
Taylor expanded in x around 0 99.9%
unpow299.9%
Simplified99.9%
if 1.99999999999999991e-6 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x -2.6) (expm1 (- x)) (if (<= x 2.6) (+ (* x x) (* 0.08333333333333333 (pow x 4.0))) (expm1 x))))
double code(double x) {
double tmp;
if (x <= -2.6) {
tmp = expm1(-x);
} else if (x <= 2.6) {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = expm1(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -2.6) {
tmp = Math.expm1(-x);
} else if (x <= 2.6) {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = Math.expm1(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.6: tmp = math.expm1(-x) elif x <= 2.6: tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0)) else: tmp = math.expm1(x) return tmp
function code(x) tmp = 0.0 if (x <= -2.6) tmp = expm1(Float64(-x)); elseif (x <= 2.6) tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = expm1(x); end return tmp end
code[x_] := If[LessEqual[x, -2.6], N[(Exp[(-x)] - 1), $MachinePrecision], If[LessEqual[x, 2.6], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6:\\
\;\;\;\;\mathsf{expm1}\left(-x\right)\\
\mathbf{elif}\;x \leq 2.6:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\end{array}
if x < -2.60000000000000009Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around inf 100.0%
expm1-def100.0%
Simplified100.0%
if -2.60000000000000009 < x < 2.60000000000000009Initial program 56.6%
Taylor expanded in x around 0 99.5%
unpow299.5%
Simplified99.5%
if 2.60000000000000009 < x Initial program 100.0%
Taylor expanded in x around 0 0.7%
+-commutative0.7%
add-sqr-sqrt0.7%
fma-def0.7%
metadata-eval0.7%
fma-neg0.7%
add-sqr-sqrt0.7%
expm1-udef0.7%
add-sqr-sqrt0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-prod100.0%
add-sqr-sqrt100.0%
expm1-udef100.0%
Applied egg-rr100.0%
expm1-def100.0%
Simplified100.0%
Final simplification99.7%
(FPCore (x)
:precision binary64
(if (<= x -1.5)
(-
(/
(* (* x x) (- 0.25 (* x (* x 0.027777777777777776))))
(+ 0.5 (* x 0.16666666666666666)))
x)
(if (<= x 1.6) (* x x) (expm1 x))))
double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
} else if (x <= 1.6) {
tmp = x * x;
} else {
tmp = expm1(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
} else if (x <= 1.6) {
tmp = x * x;
} else {
tmp = Math.expm1(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.5: tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x elif x <= 1.6: tmp = x * x else: tmp = math.expm1(x) return tmp
function code(x) tmp = 0.0 if (x <= -1.5) tmp = Float64(Float64(Float64(Float64(x * x) * Float64(0.25 - Float64(x * Float64(x * 0.027777777777777776)))) / Float64(0.5 + Float64(x * 0.16666666666666666))) - x); elseif (x <= 1.6) tmp = Float64(x * x); else tmp = expm1(x); end return tmp end
code[x_] := If[LessEqual[x, -1.5], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(0.25 - N[(x * N[(x * 0.027777777777777776), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 1.6], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\
\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\end{array}
if x < -1.5Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 75.4%
associate-+r+75.4%
neg-mul-175.4%
unsub-neg75.4%
+-commutative75.4%
unpow275.4%
*-commutative75.4%
*-commutative75.4%
unpow375.4%
associate-*l*75.4%
distribute-lft-out75.4%
Simplified75.4%
*-commutative75.4%
flip-+75.4%
associate-*l/81.0%
metadata-eval81.0%
swap-sqr81.0%
metadata-eval81.0%
*-commutative81.0%
cancel-sign-sub-inv81.0%
metadata-eval81.0%
Applied egg-rr81.0%
Taylor expanded in x around 0 81.0%
unpow281.0%
*-commutative81.0%
associate-*r*81.0%
Simplified81.0%
if -1.5 < x < 1.6000000000000001Initial program 56.6%
Taylor expanded in x around 0 99.0%
unpow299.0%
Simplified99.0%
if 1.6000000000000001 < x Initial program 100.0%
Taylor expanded in x around 0 0.7%
+-commutative0.7%
add-sqr-sqrt0.7%
fma-def0.7%
metadata-eval0.7%
fma-neg0.7%
add-sqr-sqrt0.7%
expm1-udef0.7%
add-sqr-sqrt0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-prod100.0%
add-sqr-sqrt100.0%
expm1-udef100.0%
Applied egg-rr100.0%
expm1-def100.0%
Simplified100.0%
Final simplification94.7%
(FPCore (x) :precision binary64 (if (<= x -1.65) (expm1 (- x)) (if (<= x 1.6) (* x x) (expm1 x))))
double code(double x) {
double tmp;
if (x <= -1.65) {
tmp = expm1(-x);
} else if (x <= 1.6) {
tmp = x * x;
} else {
tmp = expm1(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -1.65) {
tmp = Math.expm1(-x);
} else if (x <= 1.6) {
tmp = x * x;
} else {
tmp = Math.expm1(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.65: tmp = math.expm1(-x) elif x <= 1.6: tmp = x * x else: tmp = math.expm1(x) return tmp
function code(x) tmp = 0.0 if (x <= -1.65) tmp = expm1(Float64(-x)); elseif (x <= 1.6) tmp = Float64(x * x); else tmp = expm1(x); end return tmp end
code[x_] := If[LessEqual[x, -1.65], N[(Exp[(-x)] - 1), $MachinePrecision], If[LessEqual[x, 1.6], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65:\\
\;\;\;\;\mathsf{expm1}\left(-x\right)\\
\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\
\end{array}
\end{array}
if x < -1.6499999999999999Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around inf 100.0%
expm1-def100.0%
Simplified100.0%
if -1.6499999999999999 < x < 1.6000000000000001Initial program 56.6%
Taylor expanded in x around 0 99.0%
unpow299.0%
Simplified99.0%
if 1.6000000000000001 < x Initial program 100.0%
Taylor expanded in x around 0 0.7%
+-commutative0.7%
add-sqr-sqrt0.7%
fma-def0.7%
metadata-eval0.7%
fma-neg0.7%
add-sqr-sqrt0.7%
expm1-udef0.7%
add-sqr-sqrt0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-prod100.0%
add-sqr-sqrt100.0%
expm1-udef100.0%
Applied egg-rr100.0%
expm1-def100.0%
Simplified100.0%
Final simplification99.5%
(FPCore (x)
:precision binary64
(if (<= x -4.7)
(- (/ (* x x) (/ -6.0 x)) x)
(if (<= x 5.6)
(* x x)
(-
(*
(* x x)
(*
(- 0.25 (* (* x x) 0.027777777777777776))
(+ 2.0 (* x -0.6666666666666666))))
x))))
double code(double x) {
double tmp;
if (x <= -4.7) {
tmp = ((x * x) / (-6.0 / x)) - x;
} else if (x <= 5.6) {
tmp = x * x;
} else {
tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4.7d0)) then
tmp = ((x * x) / ((-6.0d0) / x)) - x
else if (x <= 5.6d0) then
tmp = x * x
else
tmp = ((x * x) * ((0.25d0 - ((x * x) * 0.027777777777777776d0)) * (2.0d0 + (x * (-0.6666666666666666d0))))) - x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -4.7) {
tmp = ((x * x) / (-6.0 / x)) - x;
} else if (x <= 5.6) {
tmp = x * x;
} else {
tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -4.7: tmp = ((x * x) / (-6.0 / x)) - x elif x <= 5.6: tmp = x * x else: tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x return tmp
function code(x) tmp = 0.0 if (x <= -4.7) tmp = Float64(Float64(Float64(x * x) / Float64(-6.0 / x)) - x); elseif (x <= 5.6) tmp = Float64(x * x); else tmp = Float64(Float64(Float64(x * x) * Float64(Float64(0.25 - Float64(Float64(x * x) * 0.027777777777777776)) * Float64(2.0 + Float64(x * -0.6666666666666666)))) - x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4.7) tmp = ((x * x) / (-6.0 / x)) - x; elseif (x <= 5.6) tmp = x * x; else tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4.7], N[(N[(N[(x * x), $MachinePrecision] / N[(-6.0 / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 5.6], N[(x * x), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * N[(N[(0.25 - N[(N[(x * x), $MachinePrecision] * 0.027777777777777776), $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(x * -0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7:\\
\;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\
\mathbf{elif}\;x \leq 5.6:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\
\end{array}
\end{array}
if x < -4.70000000000000018Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 75.4%
associate-+r+75.4%
neg-mul-175.4%
unsub-neg75.4%
+-commutative75.4%
unpow275.4%
*-commutative75.4%
*-commutative75.4%
unpow375.4%
associate-*l*75.4%
distribute-lft-out75.4%
Simplified75.4%
flip-+75.4%
associate-*r/81.0%
metadata-eval81.0%
swap-sqr81.0%
metadata-eval81.0%
*-commutative81.0%
cancel-sign-sub-inv81.0%
metadata-eval81.0%
Applied egg-rr81.0%
associate-/l*75.4%
*-commutative75.4%
Simplified75.4%
Taylor expanded in x around inf 75.4%
if -4.70000000000000018 < x < 5.5999999999999996Initial program 56.6%
Taylor expanded in x around 0 99.0%
unpow299.0%
Simplified99.0%
if 5.5999999999999996 < x Initial program 100.0%
Taylor expanded in x around 0 0.7%
Taylor expanded in x around 0 0.2%
associate-+r+0.2%
neg-mul-10.2%
unsub-neg0.2%
+-commutative0.2%
unpow20.2%
*-commutative0.2%
*-commutative0.2%
unpow30.2%
associate-*l*0.2%
distribute-lft-out0.2%
Simplified0.2%
flip-+0.2%
div-inv0.2%
metadata-eval0.2%
swap-sqr0.2%
metadata-eval0.2%
*-commutative0.2%
cancel-sign-sub-inv0.2%
metadata-eval0.2%
Applied egg-rr0.2%
Taylor expanded in x around 0 75.2%
*-commutative75.2%
Simplified75.2%
Final simplification86.6%
(FPCore (x)
:precision binary64
(if (<= x -1.5)
(-
(/
(* (* x x) (- 0.25 (* x (* x 0.027777777777777776))))
(+ 0.5 (* x 0.16666666666666666)))
x)
(if (<= x 5.6)
(* x x)
(-
(*
(* x x)
(*
(- 0.25 (* (* x x) 0.027777777777777776))
(+ 2.0 (* x -0.6666666666666666))))
x))))
double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
} else if (x <= 5.6) {
tmp = x * x;
} else {
tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.5d0)) then
tmp = (((x * x) * (0.25d0 - (x * (x * 0.027777777777777776d0)))) / (0.5d0 + (x * 0.16666666666666666d0))) - x
else if (x <= 5.6d0) then
tmp = x * x
else
tmp = ((x * x) * ((0.25d0 - ((x * x) * 0.027777777777777776d0)) * (2.0d0 + (x * (-0.6666666666666666d0))))) - x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
} else if (x <= 5.6) {
tmp = x * x;
} else {
tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.5: tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x elif x <= 5.6: tmp = x * x else: tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x return tmp
function code(x) tmp = 0.0 if (x <= -1.5) tmp = Float64(Float64(Float64(Float64(x * x) * Float64(0.25 - Float64(x * Float64(x * 0.027777777777777776)))) / Float64(0.5 + Float64(x * 0.16666666666666666))) - x); elseif (x <= 5.6) tmp = Float64(x * x); else tmp = Float64(Float64(Float64(x * x) * Float64(Float64(0.25 - Float64(Float64(x * x) * 0.027777777777777776)) * Float64(2.0 + Float64(x * -0.6666666666666666)))) - x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.5) tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x; elseif (x <= 5.6) tmp = x * x; else tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.5], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(0.25 - N[(x * N[(x * 0.027777777777777776), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 5.6], N[(x * x), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * N[(N[(0.25 - N[(N[(x * x), $MachinePrecision] * 0.027777777777777776), $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(x * -0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\
\mathbf{elif}\;x \leq 5.6:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\
\end{array}
\end{array}
if x < -1.5Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 75.4%
associate-+r+75.4%
neg-mul-175.4%
unsub-neg75.4%
+-commutative75.4%
unpow275.4%
*-commutative75.4%
*-commutative75.4%
unpow375.4%
associate-*l*75.4%
distribute-lft-out75.4%
Simplified75.4%
*-commutative75.4%
flip-+75.4%
associate-*l/81.0%
metadata-eval81.0%
swap-sqr81.0%
metadata-eval81.0%
*-commutative81.0%
cancel-sign-sub-inv81.0%
metadata-eval81.0%
Applied egg-rr81.0%
Taylor expanded in x around 0 81.0%
unpow281.0%
*-commutative81.0%
associate-*r*81.0%
Simplified81.0%
if -1.5 < x < 5.5999999999999996Initial program 56.6%
Taylor expanded in x around 0 99.0%
unpow299.0%
Simplified99.0%
if 5.5999999999999996 < x Initial program 100.0%
Taylor expanded in x around 0 0.7%
Taylor expanded in x around 0 0.2%
associate-+r+0.2%
neg-mul-10.2%
unsub-neg0.2%
+-commutative0.2%
unpow20.2%
*-commutative0.2%
*-commutative0.2%
unpow30.2%
associate-*l*0.2%
distribute-lft-out0.2%
Simplified0.2%
flip-+0.2%
div-inv0.2%
metadata-eval0.2%
swap-sqr0.2%
metadata-eval0.2%
*-commutative0.2%
cancel-sign-sub-inv0.2%
metadata-eval0.2%
Applied egg-rr0.2%
Taylor expanded in x around 0 75.2%
*-commutative75.2%
Simplified75.2%
Final simplification88.0%
(FPCore (x) :precision binary64 (if (<= x -4.7) (- (/ (* x x) (/ -6.0 x)) x) (* x x)))
double code(double x) {
double tmp;
if (x <= -4.7) {
tmp = ((x * x) / (-6.0 / x)) - x;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4.7d0)) then
tmp = ((x * x) / ((-6.0d0) / x)) - x
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -4.7) {
tmp = ((x * x) / (-6.0 / x)) - x;
} else {
tmp = x * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -4.7: tmp = ((x * x) / (-6.0 / x)) - x else: tmp = x * x return tmp
function code(x) tmp = 0.0 if (x <= -4.7) tmp = Float64(Float64(Float64(x * x) / Float64(-6.0 / x)) - x); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4.7) tmp = ((x * x) / (-6.0 / x)) - x; else tmp = x * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4.7], N[(N[(N[(x * x), $MachinePrecision] / N[(-6.0 / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7:\\
\;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -4.70000000000000018Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 75.4%
associate-+r+75.4%
neg-mul-175.4%
unsub-neg75.4%
+-commutative75.4%
unpow275.4%
*-commutative75.4%
*-commutative75.4%
unpow375.4%
associate-*l*75.4%
distribute-lft-out75.4%
Simplified75.4%
flip-+75.4%
associate-*r/81.0%
metadata-eval81.0%
swap-sqr81.0%
metadata-eval81.0%
*-commutative81.0%
cancel-sign-sub-inv81.0%
metadata-eval81.0%
Applied egg-rr81.0%
associate-/l*75.4%
*-commutative75.4%
Simplified75.4%
Taylor expanded in x around inf 75.4%
if -4.70000000000000018 < x Initial program 72.3%
Taylor expanded in x around 0 79.1%
unpow279.1%
Simplified79.1%
Final simplification78.2%
(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 79.3%
Taylor expanded in x around 0 74.8%
unpow274.8%
Simplified74.8%
Final simplification74.8%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 79.3%
Applied egg-rr27.1%
Final simplification27.1%
(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 2023172
(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))))