
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - e^{-x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - e^{-x}}{2}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (- (exp x) (exp (- x)))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 0.001)))
(/ t_0 2.0)
(/ (+ (* x (* x (* x 0.3333333333333333))) (+ x x)) 2.0))))
double code(double x) {
double t_0 = exp(x) - exp(-x);
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 0.001)) {
tmp = t_0 / 2.0;
} else {
tmp = ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.exp(x) - Math.exp(-x);
double tmp;
if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 0.001)) {
tmp = t_0 / 2.0;
} else {
tmp = ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0;
}
return tmp;
}
def code(x): t_0 = math.exp(x) - math.exp(-x) tmp = 0 if (t_0 <= -math.inf) or not (t_0 <= 0.001): tmp = t_0 / 2.0 else: tmp = ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0 return tmp
function code(x) t_0 = Float64(exp(x) - exp(Float64(-x))) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 0.001)) tmp = Float64(t_0 / 2.0); else tmp = Float64(Float64(Float64(x * Float64(x * Float64(x * 0.3333333333333333))) + Float64(x + x)) / 2.0); end return tmp end
function tmp_2 = code(x) t_0 = exp(x) - exp(-x); tmp = 0.0; if ((t_0 <= -Inf) || ~((t_0 <= 0.001))) tmp = t_0 / 2.0; else tmp = ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 0.001]], $MachinePrecision]], N[(t$95$0 / 2.0), $MachinePrecision], N[(N[(N[(x * N[(x * N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{x} - e^{-x}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0.001\right):\\
\;\;\;\;\frac{t_0}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(x \cdot \left(x \cdot 0.3333333333333333\right)\right) + \left(x + x\right)}{2}\\
\end{array}
\end{array}
if (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) < -inf.0 or 1e-3 < (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) Initial program 100.0%
if -inf.0 < (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) < 1e-3Initial program 8.2%
Taylor expanded in x around 0 100.0%
unpow3100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
*-commutative100.0%
+-commutative100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
distribute-rgt-in100.0%
*-commutative100.0%
add-log-exp8.7%
*-commutative8.7%
exp-lft-sqr8.6%
log-prod8.6%
add-log-exp20.7%
add-log-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= x -1e+154)
(* x (* x (* x 0.16666666666666666)))
(if (<= x 2000000.0)
(/
(/
(* x (- 4.0 (* 0.1111111111111111 (pow x 4.0))))
(+ 2.0 (* (* x x) -0.3333333333333333)))
2.0)
(sqrt (* (pow x 6.0) 0.027777777777777776)))))
double code(double x) {
double tmp;
if (x <= -1e+154) {
tmp = x * (x * (x * 0.16666666666666666));
} else if (x <= 2000000.0) {
tmp = ((x * (4.0 - (0.1111111111111111 * pow(x, 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0;
} else {
tmp = sqrt((pow(x, 6.0) * 0.027777777777777776));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1d+154)) then
tmp = x * (x * (x * 0.16666666666666666d0))
else if (x <= 2000000.0d0) then
tmp = ((x * (4.0d0 - (0.1111111111111111d0 * (x ** 4.0d0)))) / (2.0d0 + ((x * x) * (-0.3333333333333333d0)))) / 2.0d0
else
tmp = sqrt(((x ** 6.0d0) * 0.027777777777777776d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1e+154) {
tmp = x * (x * (x * 0.16666666666666666));
} else if (x <= 2000000.0) {
tmp = ((x * (4.0 - (0.1111111111111111 * Math.pow(x, 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0;
} else {
tmp = Math.sqrt((Math.pow(x, 6.0) * 0.027777777777777776));
}
return tmp;
}
def code(x): tmp = 0 if x <= -1e+154: tmp = x * (x * (x * 0.16666666666666666)) elif x <= 2000000.0: tmp = ((x * (4.0 - (0.1111111111111111 * math.pow(x, 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0 else: tmp = math.sqrt((math.pow(x, 6.0) * 0.027777777777777776)) return tmp
function code(x) tmp = 0.0 if (x <= -1e+154) tmp = Float64(x * Float64(x * Float64(x * 0.16666666666666666))); elseif (x <= 2000000.0) tmp = Float64(Float64(Float64(x * Float64(4.0 - Float64(0.1111111111111111 * (x ^ 4.0)))) / Float64(2.0 + Float64(Float64(x * x) * -0.3333333333333333))) / 2.0); else tmp = sqrt(Float64((x ^ 6.0) * 0.027777777777777776)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1e+154) tmp = x * (x * (x * 0.16666666666666666)); elseif (x <= 2000000.0) tmp = ((x * (4.0 - (0.1111111111111111 * (x ^ 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0; else tmp = sqrt(((x ^ 6.0) * 0.027777777777777776)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1e+154], N[(x * N[(x * N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2000000.0], N[(N[(N[(x * N[(4.0 - N[(0.1111111111111111 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(N[(x * x), $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[Sqrt[N[(N[Power[x, 6.0], $MachinePrecision] * 0.027777777777777776), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+154}:\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot 0.16666666666666666\right)\right)\\
\mathbf{elif}\;x \leq 2000000:\\
\;\;\;\;\frac{\frac{x \cdot \left(4 - 0.1111111111111111 \cdot {x}^{4}\right)}{2 + \left(x \cdot x\right) \cdot -0.3333333333333333}}{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{x}^{6} \cdot 0.027777777777777776}\\
\end{array}
\end{array}
if x < -1.00000000000000004e154Initial program 100.0%
Taylor expanded in x around 0 100.0%
unpow3100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
*-commutative100.0%
+-commutative100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
associate-/l*100.0%
un-div-inv100.0%
*-commutative100.0%
associate-/r/100.0%
metadata-eval100.0%
associate-*r*100.0%
associate-*r*100.0%
*-commutative100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if -1.00000000000000004e154 < x < 2e6Initial program 26.8%
Taylor expanded in x around 0 86.6%
unpow386.6%
associate-*r*86.6%
distribute-rgt-out86.5%
*-commutative86.5%
+-commutative86.5%
associate-*l*86.5%
fma-def86.5%
Simplified86.5%
fma-udef86.5%
distribute-rgt-in86.6%
*-commutative86.6%
add-log-exp25.5%
*-commutative25.5%
exp-lft-sqr25.5%
log-prod25.5%
add-log-exp35.1%
add-log-exp86.6%
Applied egg-rr86.6%
+-commutative86.6%
count-286.6%
distribute-rgt-out86.5%
*-commutative86.5%
associate-*l*86.5%
Applied egg-rr86.5%
*-commutative86.5%
flip-+89.6%
associate-*l/90.8%
metadata-eval90.8%
swap-sqr90.8%
metadata-eval90.8%
pow290.8%
pow290.8%
pow-prod-up90.8%
metadata-eval90.8%
sub-neg90.8%
*-commutative90.8%
distribute-rgt-neg-in90.8%
metadata-eval90.8%
Applied egg-rr90.8%
if 2e6 < x Initial program 100.0%
Taylor expanded in x around 0 60.9%
unpow360.9%
associate-*r*60.9%
distribute-rgt-out60.9%
*-commutative60.9%
+-commutative60.9%
associate-*l*60.9%
fma-def60.9%
Simplified60.9%
Taylor expanded in x around inf 60.9%
unpow260.9%
*-commutative60.9%
associate-*r*60.9%
Simplified60.9%
div-inv60.9%
associate-*r*60.9%
associate-*l*60.9%
*-commutative60.9%
metadata-eval60.9%
Applied egg-rr60.9%
add-sqr-sqrt60.9%
sqrt-unprod80.2%
*-commutative80.2%
*-commutative80.2%
swap-sqr80.2%
pow280.2%
*-commutative80.2%
associate-*l*80.2%
metadata-eval80.2%
pow280.2%
pow280.2%
pow-prod-up80.2%
metadata-eval80.2%
Applied egg-rr80.2%
*-commutative80.2%
metadata-eval80.2%
pow-sqr80.2%
unpow280.2%
unpow280.2%
unpow280.2%
swap-sqr80.2%
associate-*r*80.2%
unpow380.2%
associate-*r*80.2%
unpow380.2%
swap-sqr80.2%
pow-sqr80.2%
metadata-eval80.2%
metadata-eval80.2%
Simplified80.2%
Final simplification89.6%
(FPCore (x)
:precision binary64
(if (or (<= x -1e+158) (not (<= x 5e+102)))
(* x (* x (* x 0.16666666666666666)))
(/
(/
x
(/
(+ 2.0 (* x (* x -0.3333333333333333)))
(+ 4.0 (* (pow x 4.0) -0.1111111111111111))))
2.0)))
double code(double x) {
double tmp;
if ((x <= -1e+158) || !(x <= 5e+102)) {
tmp = x * (x * (x * 0.16666666666666666));
} else {
tmp = (x / ((2.0 + (x * (x * -0.3333333333333333))) / (4.0 + (pow(x, 4.0) * -0.1111111111111111)))) / 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1d+158)) .or. (.not. (x <= 5d+102))) then
tmp = x * (x * (x * 0.16666666666666666d0))
else
tmp = (x / ((2.0d0 + (x * (x * (-0.3333333333333333d0)))) / (4.0d0 + ((x ** 4.0d0) * (-0.1111111111111111d0))))) / 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1e+158) || !(x <= 5e+102)) {
tmp = x * (x * (x * 0.16666666666666666));
} else {
tmp = (x / ((2.0 + (x * (x * -0.3333333333333333))) / (4.0 + (Math.pow(x, 4.0) * -0.1111111111111111)))) / 2.0;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1e+158) or not (x <= 5e+102): tmp = x * (x * (x * 0.16666666666666666)) else: tmp = (x / ((2.0 + (x * (x * -0.3333333333333333))) / (4.0 + (math.pow(x, 4.0) * -0.1111111111111111)))) / 2.0 return tmp
function code(x) tmp = 0.0 if ((x <= -1e+158) || !(x <= 5e+102)) tmp = Float64(x * Float64(x * Float64(x * 0.16666666666666666))); else tmp = Float64(Float64(x / Float64(Float64(2.0 + Float64(x * Float64(x * -0.3333333333333333))) / Float64(4.0 + Float64((x ^ 4.0) * -0.1111111111111111)))) / 2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1e+158) || ~((x <= 5e+102))) tmp = x * (x * (x * 0.16666666666666666)); else tmp = (x / ((2.0 + (x * (x * -0.3333333333333333))) / (4.0 + ((x ^ 4.0) * -0.1111111111111111)))) / 2.0; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1e+158], N[Not[LessEqual[x, 5e+102]], $MachinePrecision]], N[(x * N[(x * N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / N[(N[(2.0 + N[(x * N[(x * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(4.0 + N[(N[Power[x, 4.0], $MachinePrecision] * -0.1111111111111111), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+158} \lor \neg \left(x \leq 5 \cdot 10^{+102}\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot 0.16666666666666666\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{\frac{2 + x \cdot \left(x \cdot -0.3333333333333333\right)}{4 + {x}^{4} \cdot -0.1111111111111111}}}{2}\\
\end{array}
\end{array}
if x < -9.99999999999999953e157 or 5e102 < x Initial program 100.0%
Taylor expanded in x around 0 100.0%
unpow3100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
*-commutative100.0%
+-commutative100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
associate-/l*100.0%
un-div-inv100.0%
*-commutative100.0%
associate-/r/100.0%
metadata-eval100.0%
associate-*r*100.0%
associate-*r*100.0%
*-commutative100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if -9.99999999999999953e157 < x < 5e102Initial program 37.4%
Taylor expanded in x around 0 74.8%
unpow374.8%
associate-*r*74.8%
distribute-rgt-out74.8%
*-commutative74.8%
+-commutative74.8%
associate-*l*74.8%
fma-def74.8%
Simplified74.8%
fma-udef74.8%
distribute-rgt-in74.8%
*-commutative74.8%
add-log-exp36.3%
*-commutative36.3%
exp-lft-sqr36.3%
log-prod36.3%
add-log-exp44.5%
add-log-exp74.8%
Applied egg-rr74.8%
+-commutative74.8%
count-274.8%
distribute-rgt-out74.8%
*-commutative74.8%
associate-*l*74.8%
Applied egg-rr74.8%
flip-+80.4%
associate-*r/84.1%
metadata-eval84.1%
swap-sqr84.1%
metadata-eval84.1%
pow284.1%
pow284.1%
pow-prod-up84.1%
metadata-eval84.1%
sub-neg84.1%
*-commutative84.1%
distribute-rgt-neg-in84.1%
metadata-eval84.1%
Applied egg-rr84.1%
associate-/l*80.4%
associate-*l*80.4%
cancel-sign-sub-inv80.4%
metadata-eval80.4%
Simplified80.4%
Final simplification86.3%
(FPCore (x)
:precision binary64
(if (or (<= x -1e+154) (not (<= x 5e+102)))
(* x (* x (* x 0.16666666666666666)))
(/
(/
(* x (- 4.0 (* 0.1111111111111111 (pow x 4.0))))
(+ 2.0 (* (* x x) -0.3333333333333333)))
2.0)))
double code(double x) {
double tmp;
if ((x <= -1e+154) || !(x <= 5e+102)) {
tmp = x * (x * (x * 0.16666666666666666));
} else {
tmp = ((x * (4.0 - (0.1111111111111111 * pow(x, 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1d+154)) .or. (.not. (x <= 5d+102))) then
tmp = x * (x * (x * 0.16666666666666666d0))
else
tmp = ((x * (4.0d0 - (0.1111111111111111d0 * (x ** 4.0d0)))) / (2.0d0 + ((x * x) * (-0.3333333333333333d0)))) / 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1e+154) || !(x <= 5e+102)) {
tmp = x * (x * (x * 0.16666666666666666));
} else {
tmp = ((x * (4.0 - (0.1111111111111111 * Math.pow(x, 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1e+154) or not (x <= 5e+102): tmp = x * (x * (x * 0.16666666666666666)) else: tmp = ((x * (4.0 - (0.1111111111111111 * math.pow(x, 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0 return tmp
function code(x) tmp = 0.0 if ((x <= -1e+154) || !(x <= 5e+102)) tmp = Float64(x * Float64(x * Float64(x * 0.16666666666666666))); else tmp = Float64(Float64(Float64(x * Float64(4.0 - Float64(0.1111111111111111 * (x ^ 4.0)))) / Float64(2.0 + Float64(Float64(x * x) * -0.3333333333333333))) / 2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1e+154) || ~((x <= 5e+102))) tmp = x * (x * (x * 0.16666666666666666)); else tmp = ((x * (4.0 - (0.1111111111111111 * (x ^ 4.0)))) / (2.0 + ((x * x) * -0.3333333333333333))) / 2.0; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1e+154], N[Not[LessEqual[x, 5e+102]], $MachinePrecision]], N[(x * N[(x * N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * N[(4.0 - N[(0.1111111111111111 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(N[(x * x), $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+154} \lor \neg \left(x \leq 5 \cdot 10^{+102}\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot 0.16666666666666666\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x \cdot \left(4 - 0.1111111111111111 \cdot {x}^{4}\right)}{2 + \left(x \cdot x\right) \cdot -0.3333333333333333}}{2}\\
\end{array}
\end{array}
if x < -1.00000000000000004e154 or 5e102 < x Initial program 100.0%
Taylor expanded in x around 0 100.0%
unpow3100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
*-commutative100.0%
+-commutative100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
associate-/l*100.0%
un-div-inv100.0%
*-commutative100.0%
associate-/r/100.0%
metadata-eval100.0%
associate-*r*100.0%
associate-*r*100.0%
*-commutative100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if -1.00000000000000004e154 < x < 5e102Initial program 37.4%
Taylor expanded in x around 0 74.8%
unpow374.8%
associate-*r*74.8%
distribute-rgt-out74.8%
*-commutative74.8%
+-commutative74.8%
associate-*l*74.8%
fma-def74.8%
Simplified74.8%
fma-udef74.8%
distribute-rgt-in74.8%
*-commutative74.8%
add-log-exp36.3%
*-commutative36.3%
exp-lft-sqr36.3%
log-prod36.3%
add-log-exp44.5%
add-log-exp74.8%
Applied egg-rr74.8%
+-commutative74.8%
count-274.8%
distribute-rgt-out74.8%
*-commutative74.8%
associate-*l*74.8%
Applied egg-rr74.8%
*-commutative74.8%
flip-+80.4%
associate-*l/84.1%
metadata-eval84.1%
swap-sqr84.1%
metadata-eval84.1%
pow284.1%
pow284.1%
pow-prod-up84.1%
metadata-eval84.1%
sub-neg84.1%
*-commutative84.1%
distribute-rgt-neg-in84.1%
metadata-eval84.1%
Applied egg-rr84.1%
Final simplification88.9%
(FPCore (x) :precision binary64 (/ (+ (* x (* x (* x 0.3333333333333333))) (+ x x)) 2.0))
double code(double x) {
return ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * (x * (x * 0.3333333333333333d0))) + (x + x)) / 2.0d0
end function
public static double code(double x) {
return ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0;
}
def code(x): return ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0
function code(x) return Float64(Float64(Float64(x * Float64(x * Float64(x * 0.3333333333333333))) + Float64(x + x)) / 2.0) end
function tmp = code(x) tmp = ((x * (x * (x * 0.3333333333333333))) + (x + x)) / 2.0; end
code[x_] := N[(N[(N[(x * N[(x * N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(x \cdot \left(x \cdot 0.3333333333333333\right)\right) + \left(x + x\right)}{2}
\end{array}
Initial program 56.2%
Taylor expanded in x around 0 82.4%
unpow382.4%
associate-*r*82.4%
distribute-rgt-out82.4%
*-commutative82.4%
+-commutative82.4%
associate-*l*82.4%
fma-def82.4%
Simplified82.4%
fma-udef82.4%
distribute-rgt-in82.4%
*-commutative82.4%
add-log-exp55.5%
*-commutative55.5%
exp-lft-sqr55.5%
log-prod55.4%
add-log-exp61.2%
add-log-exp82.4%
Applied egg-rr82.4%
Final simplification82.4%
(FPCore (x) :precision binary64 (if (or (<= x -2.4) (not (<= x 2.4))) (* x (* x (* x 0.16666666666666666))) (/ (* x 2.0) 2.0)))
double code(double x) {
double tmp;
if ((x <= -2.4) || !(x <= 2.4)) {
tmp = x * (x * (x * 0.16666666666666666));
} else {
tmp = (x * 2.0) / 2.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-2.4d0)) .or. (.not. (x <= 2.4d0))) then
tmp = x * (x * (x * 0.16666666666666666d0))
else
tmp = (x * 2.0d0) / 2.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -2.4) || !(x <= 2.4)) {
tmp = x * (x * (x * 0.16666666666666666));
} else {
tmp = (x * 2.0) / 2.0;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -2.4) or not (x <= 2.4): tmp = x * (x * (x * 0.16666666666666666)) else: tmp = (x * 2.0) / 2.0 return tmp
function code(x) tmp = 0.0 if ((x <= -2.4) || !(x <= 2.4)) tmp = Float64(x * Float64(x * Float64(x * 0.16666666666666666))); else tmp = Float64(Float64(x * 2.0) / 2.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -2.4) || ~((x <= 2.4))) tmp = x * (x * (x * 0.16666666666666666)); else tmp = (x * 2.0) / 2.0; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -2.4], N[Not[LessEqual[x, 2.4]], $MachinePrecision]], N[(x * N[(x * N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 2.0), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \lor \neg \left(x \leq 2.4\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot 0.16666666666666666\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot 2}{2}\\
\end{array}
\end{array}
if x < -2.39999999999999991 or 2.39999999999999991 < x Initial program 100.0%
Taylor expanded in x around 0 66.6%
unpow366.6%
associate-*r*66.6%
distribute-rgt-out66.6%
*-commutative66.6%
+-commutative66.6%
associate-*l*66.6%
fma-def66.6%
Simplified66.6%
Taylor expanded in x around inf 66.6%
unpow266.6%
Simplified66.6%
associate-/l*66.6%
un-div-inv66.6%
*-commutative66.6%
associate-/r/66.6%
metadata-eval66.6%
associate-*r*66.6%
associate-*r*66.6%
*-commutative66.6%
*-commutative66.6%
*-commutative66.6%
associate-*l*66.6%
metadata-eval66.6%
Applied egg-rr66.6%
if -2.39999999999999991 < x < 2.39999999999999991Initial program 8.9%
Taylor expanded in x around 0 98.7%
Final simplification82.0%
(FPCore (x) :precision binary64 (/ (* x (+ 2.0 (* 0.3333333333333333 (* x x)))) 2.0))
double code(double x) {
return (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * (2.0d0 + (0.3333333333333333d0 * (x * x)))) / 2.0d0
end function
public static double code(double x) {
return (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0;
}
def code(x): return (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0
function code(x) return Float64(Float64(x * Float64(2.0 + Float64(0.3333333333333333 * Float64(x * x)))) / 2.0) end
function tmp = code(x) tmp = (x * (2.0 + (0.3333333333333333 * (x * x)))) / 2.0; end
code[x_] := N[(N[(x * N[(2.0 + N[(0.3333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(2 + 0.3333333333333333 \cdot \left(x \cdot x\right)\right)}{2}
\end{array}
Initial program 56.2%
Taylor expanded in x around 0 82.4%
unpow382.4%
associate-*r*82.4%
distribute-rgt-out82.4%
*-commutative82.4%
+-commutative82.4%
associate-*l*82.4%
fma-def82.4%
Simplified82.4%
fma-udef82.4%
distribute-rgt-in82.4%
*-commutative82.4%
add-log-exp55.5%
*-commutative55.5%
exp-lft-sqr55.5%
log-prod55.4%
add-log-exp61.2%
add-log-exp82.4%
Applied egg-rr82.4%
+-commutative82.4%
count-282.4%
distribute-rgt-out82.4%
*-commutative82.4%
associate-*l*82.4%
Applied egg-rr82.4%
Final simplification82.4%
(FPCore (x) :precision binary64 (/ (* x 2.0) 2.0))
double code(double x) {
return (x * 2.0) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 2.0d0) / 2.0d0
end function
public static double code(double x) {
return (x * 2.0) / 2.0;
}
def code(x): return (x * 2.0) / 2.0
function code(x) return Float64(Float64(x * 2.0) / 2.0) end
function tmp = code(x) tmp = (x * 2.0) / 2.0; end
code[x_] := N[(N[(x * 2.0), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{2}
\end{array}
Initial program 56.2%
Taylor expanded in x around 0 50.2%
Final simplification50.2%
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 56.2%
Applied egg-rr2.7%
Final simplification2.7%
(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 56.2%
Applied egg-rr3.3%
Final simplification3.3%
herbie shell --seed 2023174
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))