
(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 7 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 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) (exp (- x_m)))))
(*
x_s
(if (<= t_0 0.1)
(+
x_m
(+
(* 0.0001984126984126984 (pow x_m 7.0))
(+
(* 0.008333333333333333 (pow x_m 5.0))
(* 0.16666666666666666 (pow x_m 3.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.1) {
tmp = x_m + ((0.0001984126984126984 * pow(x_m, 7.0)) + ((0.008333333333333333 * pow(x_m, 5.0)) + (0.16666666666666666 * pow(x_m, 3.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.1d0) then
tmp = x_m + ((0.0001984126984126984d0 * (x_m ** 7.0d0)) + ((0.008333333333333333d0 * (x_m ** 5.0d0)) + (0.16666666666666666d0 * (x_m ** 3.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.1) {
tmp = x_m + ((0.0001984126984126984 * Math.pow(x_m, 7.0)) + ((0.008333333333333333 * Math.pow(x_m, 5.0)) + (0.16666666666666666 * Math.pow(x_m, 3.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.1: tmp = x_m + ((0.0001984126984126984 * math.pow(x_m, 7.0)) + ((0.008333333333333333 * math.pow(x_m, 5.0)) + (0.16666666666666666 * math.pow(x_m, 3.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.1) tmp = Float64(x_m + Float64(Float64(0.0001984126984126984 * (x_m ^ 7.0)) + Float64(Float64(0.008333333333333333 * (x_m ^ 5.0)) + Float64(0.16666666666666666 * (x_m ^ 3.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.1) tmp = x_m + ((0.0001984126984126984 * (x_m ^ 7.0)) + ((0.008333333333333333 * (x_m ^ 5.0)) + (0.16666666666666666 * (x_m ^ 3.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.1], N[(x$95$m + N[(N[(0.0001984126984126984 * N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.008333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision] + N[(0.16666666666666666 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.1:\\
\;\;\;\;x\_m + \left(0.0001984126984126984 \cdot {x\_m}^{7} + \left(0.008333333333333333 \cdot {x\_m}^{5} + 0.16666666666666666 \cdot {x\_m}^{3}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2}\\
\end{array}
\end{array}
\end{array}
if (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) < 0.10000000000000001Initial program 41.3%
Taylor expanded in x around 0 92.2%
Taylor expanded in x around 0 92.2%
if 0.10000000000000001 < (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) Initial program 100.0%
Final simplification94.1%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (- (exp x_m) (exp (- x_m)))))
(*
x_s
(if (<= t_0 5e-7)
(+ x_m (* 0.16666666666666666 (pow x_m 3.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 <= 5e-7) {
tmp = x_m + (0.16666666666666666 * pow(x_m, 3.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 <= 5d-7) then
tmp = x_m + (0.16666666666666666d0 * (x_m ** 3.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 <= 5e-7) {
tmp = x_m + (0.16666666666666666 * Math.pow(x_m, 3.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 <= 5e-7: tmp = x_m + (0.16666666666666666 * math.pow(x_m, 3.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 <= 5e-7) tmp = Float64(x_m + Float64(0.16666666666666666 * (x_m ^ 3.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 <= 5e-7) tmp = x_m + (0.16666666666666666 * (x_m ^ 3.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, 5e-7], N[(x$95$m + N[(0.16666666666666666 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $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 5 \cdot 10^{-7}:\\
\;\;\;\;x\_m + 0.16666666666666666 \cdot {x\_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2}\\
\end{array}
\end{array}
\end{array}
if (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) < 4.99999999999999977e-7Initial program 41.0%
Taylor expanded in x around 0 92.1%
Taylor expanded in x around 0 85.9%
if 4.99999999999999977e-7 < (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) Initial program 99.9%
Final simplification89.4%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 5.6)
(+ x_m (* 0.16666666666666666 (pow x_m 3.0)))
(pow (* (pow x_m 42.0) 6.101221350130783e-23) 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 <= 5.6) {
tmp = x_m + (0.16666666666666666 * pow(x_m, 3.0));
} else {
tmp = pow((pow(x_m, 42.0) * 6.101221350130783e-23), 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 <= 5.6d0) then
tmp = x_m + (0.16666666666666666d0 * (x_m ** 3.0d0))
else
tmp = ((x_m ** 42.0d0) * 6.101221350130783d-23) ** 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 <= 5.6) {
tmp = x_m + (0.16666666666666666 * Math.pow(x_m, 3.0));
} else {
tmp = Math.pow((Math.pow(x_m, 42.0) * 6.101221350130783e-23), 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 <= 5.6: tmp = x_m + (0.16666666666666666 * math.pow(x_m, 3.0)) else: tmp = math.pow((math.pow(x_m, 42.0) * 6.101221350130783e-23), 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 <= 5.6) tmp = Float64(x_m + Float64(0.16666666666666666 * (x_m ^ 3.0))); else tmp = Float64((x_m ^ 42.0) * 6.101221350130783e-23) ^ 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 <= 5.6) tmp = x_m + (0.16666666666666666 * (x_m ^ 3.0)); else tmp = ((x_m ^ 42.0) * 6.101221350130783e-23) ^ 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, 5.6], N[(x$95$m + N[(0.16666666666666666 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(N[Power[x$95$m, 42.0], $MachinePrecision] * 6.101221350130783e-23), $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 5.6:\\
\;\;\;\;x\_m + 0.16666666666666666 \cdot {x\_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;{\left({x\_m}^{42} \cdot 6.101221350130783 \cdot 10^{-23}\right)}^{0.16666666666666666}\\
\end{array}
\end{array}
if x < 5.5999999999999996Initial program 41.6%
Taylor expanded in x around 0 92.0%
Taylor expanded in x around 0 85.4%
if 5.5999999999999996 < x Initial program 100.0%
Taylor expanded in x around 0 88.0%
Taylor expanded in x around inf 88.0%
add-sqr-sqrt88.0%
sqrt-unprod93.9%
*-commutative93.9%
*-commutative93.9%
swap-sqr93.9%
pow-prod-up93.9%
metadata-eval93.9%
metadata-eval93.9%
Applied egg-rr93.9%
add-cbrt-cube100.0%
pow1/3100.0%
sqrt-pow1100.0%
pow3100.0%
unpow-prod-down100.0%
pow-pow100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification89.0%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 5.6)
(+ x_m (* 0.16666666666666666 (pow x_m 3.0)))
(cbrt (* (pow x_m 21.0) 7.811031526073099e-12)))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 5.6) {
tmp = x_m + (0.16666666666666666 * pow(x_m, 3.0));
} else {
tmp = cbrt((pow(x_m, 21.0) * 7.811031526073099e-12));
}
return x_s * tmp;
}
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 <= 5.6) {
tmp = x_m + (0.16666666666666666 * Math.pow(x_m, 3.0));
} else {
tmp = Math.cbrt((Math.pow(x_m, 21.0) * 7.811031526073099e-12));
}
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 <= 5.6) tmp = Float64(x_m + Float64(0.16666666666666666 * (x_m ^ 3.0))); else tmp = cbrt(Float64((x_m ^ 21.0) * 7.811031526073099e-12)); 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_] := N[(x$95$s * If[LessEqual[x$95$m, 5.6], N[(x$95$m + N[(0.16666666666666666 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(N[Power[x$95$m, 21.0], $MachinePrecision] * 7.811031526073099e-12), $MachinePrecision], 1/3], $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 5.6:\\
\;\;\;\;x\_m + 0.16666666666666666 \cdot {x\_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{x\_m}^{21} \cdot 7.811031526073099 \cdot 10^{-12}}\\
\end{array}
\end{array}
if x < 5.5999999999999996Initial program 41.6%
Taylor expanded in x around 0 92.0%
Taylor expanded in x around 0 85.4%
if 5.5999999999999996 < x Initial program 100.0%
Taylor expanded in x around 0 88.0%
Taylor expanded in x around inf 88.0%
add-sqr-sqrt88.0%
sqrt-unprod93.9%
*-commutative93.9%
*-commutative93.9%
swap-sqr93.9%
pow-prod-up93.9%
metadata-eval93.9%
metadata-eval93.9%
Applied egg-rr93.9%
pow193.9%
metadata-eval93.9%
pow-pow93.9%
sqrt-prod93.9%
unpow-prod-down95.4%
pow395.4%
add-sqr-sqrt95.4%
sqrt-pow195.4%
pow-prod-up95.4%
metadata-eval95.4%
metadata-eval95.4%
metadata-eval95.4%
metadata-eval95.4%
Applied egg-rr95.4%
unpow1/395.4%
Simplified95.4%
Final simplification87.9%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 5.6)
(+ x_m (* 0.16666666666666666 (pow x_m 3.0)))
(* 0.0001984126984126984 (pow x_m 7.0)))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 5.6) {
tmp = x_m + (0.16666666666666666 * pow(x_m, 3.0));
} else {
tmp = 0.0001984126984126984 * pow(x_m, 7.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 <= 5.6d0) then
tmp = x_m + (0.16666666666666666d0 * (x_m ** 3.0d0))
else
tmp = 0.0001984126984126984d0 * (x_m ** 7.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 <= 5.6) {
tmp = x_m + (0.16666666666666666 * Math.pow(x_m, 3.0));
} else {
tmp = 0.0001984126984126984 * Math.pow(x_m, 7.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 <= 5.6: tmp = x_m + (0.16666666666666666 * math.pow(x_m, 3.0)) else: tmp = 0.0001984126984126984 * math.pow(x_m, 7.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 <= 5.6) tmp = Float64(x_m + Float64(0.16666666666666666 * (x_m ^ 3.0))); else tmp = Float64(0.0001984126984126984 * (x_m ^ 7.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 <= 5.6) tmp = x_m + (0.16666666666666666 * (x_m ^ 3.0)); else tmp = 0.0001984126984126984 * (x_m ^ 7.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, 5.6], N[(x$95$m + N[(0.16666666666666666 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.0001984126984126984 * N[Power[x$95$m, 7.0], $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 5.6:\\
\;\;\;\;x\_m + 0.16666666666666666 \cdot {x\_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;0.0001984126984126984 \cdot {x\_m}^{7}\\
\end{array}
\end{array}
if x < 5.5999999999999996Initial program 41.6%
Taylor expanded in x around 0 92.0%
Taylor expanded in x around 0 85.4%
if 5.5999999999999996 < x Initial program 100.0%
Taylor expanded in x around 0 88.0%
Taylor expanded in x around inf 88.0%
Final simplification86.1%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (if (<= x_m 4.2) x_m (* 0.0001984126984126984 (pow x_m 7.0)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 4.2) {
tmp = x_m;
} else {
tmp = 0.0001984126984126984 * pow(x_m, 7.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 <= 4.2d0) then
tmp = x_m
else
tmp = 0.0001984126984126984d0 * (x_m ** 7.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 <= 4.2) {
tmp = x_m;
} else {
tmp = 0.0001984126984126984 * Math.pow(x_m, 7.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 <= 4.2: tmp = x_m else: tmp = 0.0001984126984126984 * math.pow(x_m, 7.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 <= 4.2) tmp = x_m; else tmp = Float64(0.0001984126984126984 * (x_m ^ 7.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 <= 4.2) tmp = x_m; else tmp = 0.0001984126984126984 * (x_m ^ 7.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, 4.2], x$95$m, N[(0.0001984126984126984 * N[Power[x$95$m, 7.0], $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 4.2:\\
\;\;\;\;x\_m\\
\mathbf{else}:\\
\;\;\;\;0.0001984126984126984 \cdot {x\_m}^{7}\\
\end{array}
\end{array}
if x < 4.20000000000000018Initial program 41.6%
Taylor expanded in x around 0 92.0%
Taylor expanded in x around 0 66.0%
if 4.20000000000000018 < x Initial program 100.0%
Taylor expanded in x around 0 88.0%
Taylor expanded in x around inf 88.0%
Final simplification71.4%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s x_m))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * x_m;
}
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
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;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * x_m
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * x_m) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * x_m; 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 * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot x\_m
\end{array}
Initial program 55.9%
Taylor expanded in x around 0 91.0%
Taylor expanded in x around 0 51.1%
Final simplification51.1%
herbie shell --seed 2024031
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))