
(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}
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) (exp (- x_m)))))
(*
x_s
(if (<= t_0 0.01)
(/
(*
x_m
(+
2.0
(fma
(* x_m 0.3333333333333333)
x_m
(* 0.016666666666666666 (pow x_m 4.0)))))
2.0)
(/ t_0 2.0)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = exp(x_m) - exp(-x_m);
double tmp;
if (t_0 <= 0.01) {
tmp = (x_m * (2.0 + fma((x_m * 0.3333333333333333), x_m, (0.016666666666666666 * pow(x_m, 4.0))))) / 2.0;
} else {
tmp = t_0 / 2.0;
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) t_0 = Float64(exp(x_m) - exp(Float64(-x_m))) tmp = 0.0 if (t_0 <= 0.01) tmp = Float64(Float64(x_m * Float64(2.0 + fma(Float64(x_m * 0.3333333333333333), x_m, Float64(0.016666666666666666 * (x_m ^ 4.0))))) / 2.0); else tmp = Float64(t_0 / 2.0); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[(N[Exp[x$95$m], $MachinePrecision] - N[Exp[(-x$95$m)], $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, 0.01], N[(N[(x$95$m * N[(2.0 + N[(N[(x$95$m * 0.3333333333333333), $MachinePrecision] * x$95$m + N[(0.016666666666666666 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(t$95$0 / 2.0), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := e^{x\_m} - e^{-x\_m}\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0.01:\\
\;\;\;\;\frac{x\_m \cdot \left(2 + \mathsf{fma}\left(x\_m \cdot 0.3333333333333333, x\_m, 0.016666666666666666 \cdot {x\_m}^{4}\right)\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2}\\
\end{array}
\end{array}
\end{array}
if (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) < 0.0100000000000000002Initial program 41.8%
Taylor expanded in x around 0 90.7%
*-commutative90.7%
Simplified90.7%
distribute-lft-in90.7%
*-commutative90.7%
unpow290.7%
associate-*r*90.7%
fma-define90.7%
*-commutative90.7%
*-commutative90.7%
associate-*l*90.7%
pow-prod-up90.7%
metadata-eval90.7%
Applied egg-rr90.7%
if 0.0100000000000000002 < (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) Initial program 100.0%
Final simplification93.1%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) (exp (- x_m)))))
(*
x_s
(if (<= t_0 0.0002)
(/ (+ (* x_m 2.0) (* 0.3333333333333333 (pow x_m 3.0))) 2.0)
(/ t_0 2.0)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = exp(x_m) - exp(-x_m);
double tmp;
if (t_0 <= 0.0002) {
tmp = ((x_m * 2.0) + (0.3333333333333333 * pow(x_m, 3.0))) / 2.0;
} else {
tmp = t_0 / 2.0;
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: t_0
real(8) :: tmp
t_0 = exp(x_m) - exp(-x_m)
if (t_0 <= 0.0002d0) then
tmp = ((x_m * 2.0d0) + (0.3333333333333333d0 * (x_m ** 3.0d0))) / 2.0d0
else
tmp = t_0 / 2.0d0
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double t_0 = Math.exp(x_m) - Math.exp(-x_m);
double tmp;
if (t_0 <= 0.0002) {
tmp = ((x_m * 2.0) + (0.3333333333333333 * Math.pow(x_m, 3.0))) / 2.0;
} else {
tmp = t_0 / 2.0;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): t_0 = math.exp(x_m) - math.exp(-x_m) tmp = 0 if t_0 <= 0.0002: tmp = ((x_m * 2.0) + (0.3333333333333333 * math.pow(x_m, 3.0))) / 2.0 else: tmp = t_0 / 2.0 return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) t_0 = Float64(exp(x_m) - exp(Float64(-x_m))) tmp = 0.0 if (t_0 <= 0.0002) tmp = Float64(Float64(Float64(x_m * 2.0) + Float64(0.3333333333333333 * (x_m ^ 3.0))) / 2.0); else tmp = Float64(t_0 / 2.0); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) t_0 = exp(x_m) - exp(-x_m); tmp = 0.0; if (t_0 <= 0.0002) tmp = ((x_m * 2.0) + (0.3333333333333333 * (x_m ^ 3.0))) / 2.0; else tmp = t_0 / 2.0; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[(N[Exp[x$95$m], $MachinePrecision] - N[Exp[(-x$95$m)], $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, 0.0002], N[(N[(N[(x$95$m * 2.0), $MachinePrecision] + N[(0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(t$95$0 / 2.0), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := e^{x\_m} - e^{-x\_m}\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0.0002:\\
\;\;\;\;\frac{x\_m \cdot 2 + 0.3333333333333333 \cdot {x\_m}^{3}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2}\\
\end{array}
\end{array}
\end{array}
if (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) < 2.0000000000000001e-4Initial program 41.5%
Taylor expanded in x around 0 90.6%
*-commutative90.6%
Simplified90.6%
Taylor expanded in x around 0 86.9%
distribute-rgt-in86.9%
*-commutative86.9%
*-commutative86.9%
associate-*r*86.9%
unpow286.9%
unpow386.9%
Applied egg-rr86.9%
if 2.0000000000000001e-4 < (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) Initial program 99.9%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 2e+49)
(/ (+ (* x_m 2.0) (* 0.3333333333333333 (pow x_m 3.0))) 2.0)
(sqrt (* (pow x_m 6.0) 0.027777777777777776)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 2e+49) {
tmp = ((x_m * 2.0) + (0.3333333333333333 * pow(x_m, 3.0))) / 2.0;
} else {
tmp = sqrt((pow(x_m, 6.0) * 0.027777777777777776));
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 2d+49) then
tmp = ((x_m * 2.0d0) + (0.3333333333333333d0 * (x_m ** 3.0d0))) / 2.0d0
else
tmp = sqrt(((x_m ** 6.0d0) * 0.027777777777777776d0))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 2e+49) {
tmp = ((x_m * 2.0) + (0.3333333333333333 * Math.pow(x_m, 3.0))) / 2.0;
} else {
tmp = Math.sqrt((Math.pow(x_m, 6.0) * 0.027777777777777776));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 2e+49: tmp = ((x_m * 2.0) + (0.3333333333333333 * math.pow(x_m, 3.0))) / 2.0 else: tmp = math.sqrt((math.pow(x_m, 6.0) * 0.027777777777777776)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 2e+49) tmp = Float64(Float64(Float64(x_m * 2.0) + Float64(0.3333333333333333 * (x_m ^ 3.0))) / 2.0); else tmp = sqrt(Float64((x_m ^ 6.0) * 0.027777777777777776)); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 2e+49) tmp = ((x_m * 2.0) + (0.3333333333333333 * (x_m ^ 3.0))) / 2.0; else tmp = sqrt(((x_m ^ 6.0) * 0.027777777777777776)); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 2e+49], N[(N[(N[(x$95$m * 2.0), $MachinePrecision] + N[(0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[Sqrt[N[(N[Power[x$95$m, 6.0], $MachinePrecision] * 0.027777777777777776), $MachinePrecision]], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 2 \cdot 10^{+49}:\\
\;\;\;\;\frac{x\_m \cdot 2 + 0.3333333333333333 \cdot {x\_m}^{3}}{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{x\_m}^{6} \cdot 0.027777777777777776}\\
\end{array}
\end{array}
if x < 1.99999999999999989e49Initial program 45.8%
Taylor expanded in x around 0 84.7%
*-commutative84.7%
Simplified84.7%
Taylor expanded in x around 0 81.1%
distribute-rgt-in81.1%
*-commutative81.1%
*-commutative81.1%
associate-*r*81.1%
unpow281.1%
unpow381.1%
Applied egg-rr81.1%
if 1.99999999999999989e49 < x Initial program 100.0%
Taylor expanded in x around 0 96.6%
*-commutative96.6%
Simplified96.6%
Taylor expanded in x around 0 82.7%
Taylor expanded in x around inf 82.7%
add-sqr-sqrt82.7%
sqrt-unprod100.0%
div-inv100.0%
div-inv100.0%
swap-sqr100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
pow-prod-up100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s (/ (+ (* x_m 2.0) (* (pow x_m 4.0) (* x_m 0.016666666666666666))) 2.0)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (((x_m * 2.0) + (pow(x_m, 4.0) * (x_m * 0.016666666666666666))) / 2.0);
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * (((x_m * 2.0d0) + ((x_m ** 4.0d0) * (x_m * 0.016666666666666666d0))) / 2.0d0)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * (((x_m * 2.0) + (Math.pow(x_m, 4.0) * (x_m * 0.016666666666666666))) / 2.0);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (((x_m * 2.0) + (math.pow(x_m, 4.0) * (x_m * 0.016666666666666666))) / 2.0)
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(Float64(Float64(x_m * 2.0) + Float64((x_m ^ 4.0) * Float64(x_m * 0.016666666666666666))) / 2.0)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (((x_m * 2.0) + ((x_m ^ 4.0) * (x_m * 0.016666666666666666))) / 2.0); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[(N[(x$95$m * 2.0), $MachinePrecision] + N[(N[Power[x$95$m, 4.0], $MachinePrecision] * N[(x$95$m * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \frac{x\_m \cdot 2 + {x\_m}^{4} \cdot \left(x\_m \cdot 0.016666666666666666\right)}{2}
\end{array}
Initial program 57.3%
Taylor expanded in x around 0 87.2%
*-commutative87.2%
Simplified87.2%
Taylor expanded in x around inf 86.8%
+-commutative86.8%
distribute-lft-in86.8%
*-commutative86.8%
*-commutative86.8%
associate-*l*86.8%
Applied egg-rr86.8%
Final simplification86.8%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 3.3)
(/ (* x_m 2.0) 2.0)
(/ (* 0.016666666666666666 (pow x_m 5.0)) 2.0))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 3.3) {
tmp = (x_m * 2.0) / 2.0;
} else {
tmp = (0.016666666666666666 * pow(x_m, 5.0)) / 2.0;
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 3.3d0) then
tmp = (x_m * 2.0d0) / 2.0d0
else
tmp = (0.016666666666666666d0 * (x_m ** 5.0d0)) / 2.0d0
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 3.3) {
tmp = (x_m * 2.0) / 2.0;
} else {
tmp = (0.016666666666666666 * Math.pow(x_m, 5.0)) / 2.0;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 3.3: tmp = (x_m * 2.0) / 2.0 else: tmp = (0.016666666666666666 * math.pow(x_m, 5.0)) / 2.0 return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 3.3) tmp = Float64(Float64(x_m * 2.0) / 2.0); else tmp = Float64(Float64(0.016666666666666666 * (x_m ^ 5.0)) / 2.0); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 3.3) tmp = (x_m * 2.0) / 2.0; else tmp = (0.016666666666666666 * (x_m ^ 5.0)) / 2.0; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 3.3], N[(N[(x$95$m * 2.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(0.016666666666666666 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 3.3:\\
\;\;\;\;\frac{x\_m \cdot 2}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.016666666666666666 \cdot {x\_m}^{5}}{2}\\
\end{array}
\end{array}
if x < 3.2999999999999998Initial program 41.8%
Taylor expanded in x around 0 65.1%
if 3.2999999999999998 < x Initial program 100.0%
Taylor expanded in x around 0 77.8%
*-commutative77.8%
Simplified77.8%
Taylor expanded in x around inf 77.8%
Final simplification68.5%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s (/ (* x_m (+ 2.0 (* 0.016666666666666666 (pow x_m 4.0)))) 2.0)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * ((x_m * (2.0 + (0.016666666666666666 * pow(x_m, 4.0)))) / 2.0);
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * ((x_m * (2.0d0 + (0.016666666666666666d0 * (x_m ** 4.0d0)))) / 2.0d0)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * ((x_m * (2.0 + (0.016666666666666666 * Math.pow(x_m, 4.0)))) / 2.0);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * ((x_m * (2.0 + (0.016666666666666666 * math.pow(x_m, 4.0)))) / 2.0)
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(Float64(x_m * Float64(2.0 + Float64(0.016666666666666666 * (x_m ^ 4.0)))) / 2.0)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * ((x_m * (2.0 + (0.016666666666666666 * (x_m ^ 4.0)))) / 2.0); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[(x$95$m * N[(2.0 + N[(0.016666666666666666 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \frac{x\_m \cdot \left(2 + 0.016666666666666666 \cdot {x\_m}^{4}\right)}{2}
\end{array}
Initial program 57.3%
Taylor expanded in x around 0 87.2%
*-commutative87.2%
Simplified87.2%
Taylor expanded in x around inf 86.8%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s (if (<= x_m 2.4) (/ (* x_m 2.0) 2.0) (* (pow x_m 3.0) 0.16666666666666666))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 2.4) {
tmp = (x_m * 2.0) / 2.0;
} else {
tmp = pow(x_m, 3.0) * 0.16666666666666666;
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 2.4d0) then
tmp = (x_m * 2.0d0) / 2.0d0
else
tmp = (x_m ** 3.0d0) * 0.16666666666666666d0
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 2.4) {
tmp = (x_m * 2.0) / 2.0;
} else {
tmp = Math.pow(x_m, 3.0) * 0.16666666666666666;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 2.4: tmp = (x_m * 2.0) / 2.0 else: tmp = math.pow(x_m, 3.0) * 0.16666666666666666 return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 2.4) tmp = Float64(Float64(x_m * 2.0) / 2.0); else tmp = Float64((x_m ^ 3.0) * 0.16666666666666666); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 2.4) tmp = (x_m * 2.0) / 2.0; else tmp = (x_m ^ 3.0) * 0.16666666666666666; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 2.4], N[(N[(x$95$m * 2.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[Power[x$95$m, 3.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 2.4:\\
\;\;\;\;\frac{x\_m \cdot 2}{2}\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{3} \cdot 0.16666666666666666\\
\end{array}
\end{array}
if x < 2.39999999999999991Initial program 41.8%
Taylor expanded in x around 0 65.1%
if 2.39999999999999991 < x Initial program 100.0%
Taylor expanded in x around 0 77.8%
*-commutative77.8%
Simplified77.8%
Taylor expanded in x around 0 66.5%
Taylor expanded in x around inf 66.5%
*-commutative66.5%
associate-/l*66.5%
metadata-eval66.5%
Applied egg-rr66.5%
Final simplification65.5%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s (/ (* x_m 2.0) 2.0)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * ((x_m * 2.0) / 2.0);
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * ((x_m * 2.0d0) / 2.0d0)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * ((x_m * 2.0) / 2.0);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * ((x_m * 2.0) / 2.0)
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(Float64(x_m * 2.0) / 2.0)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * ((x_m * 2.0) / 2.0); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[(x$95$m * 2.0), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \frac{x\_m \cdot 2}{2}
\end{array}
Initial program 57.3%
Taylor expanded in x around 0 49.2%
Final simplification49.2%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s 0.25))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * 0.25;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * 0.25d0
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * 0.25;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * 0.25
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * 0.25) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * 0.25; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * 0.25), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot 0.25
\end{array}
Initial program 57.3%
Applied egg-rr3.0%
Final simplification3.0%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s 0.0))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * 0.0;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * 0.0d0
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * 0.0;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * 0.0
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * 0.0) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * 0.0; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * 0.0), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot 0
\end{array}
Initial program 57.3%
Applied egg-rr3.4%
Final simplification3.4%
herbie shell --seed 2024085
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))