
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (* (+ x_m 1.0) (- 1.0 x_m))))
(*
x_s
(if (<= (+ (- (/ 1.0 (+ x_m 1.0)) (/ 2.0 x_m)) (/ 1.0 (+ x_m -1.0))) 1e-27)
(* 2.0 (pow x_m -3.0))
(/ (+ (* x_m (* x_m -2.0)) (* -2.0 t_0)) (* x_m t_0))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = (x_m + 1.0) * (1.0 - x_m);
double tmp;
if ((((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27) {
tmp = 2.0 * pow(x_m, -3.0);
} else {
tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_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 = (x_m + 1.0d0) * (1.0d0 - x_m)
if ((((1.0d0 / (x_m + 1.0d0)) - (2.0d0 / x_m)) + (1.0d0 / (x_m + (-1.0d0)))) <= 1d-27) then
tmp = 2.0d0 * (x_m ** (-3.0d0))
else
tmp = ((x_m * (x_m * (-2.0d0))) + ((-2.0d0) * t_0)) / (x_m * t_0)
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 = (x_m + 1.0) * (1.0 - x_m);
double tmp;
if ((((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27) {
tmp = 2.0 * Math.pow(x_m, -3.0);
} else {
tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_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 = (x_m + 1.0) * (1.0 - x_m) tmp = 0 if (((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27: tmp = 2.0 * math.pow(x_m, -3.0) else: tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0) return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) t_0 = Float64(Float64(x_m + 1.0) * Float64(1.0 - x_m)) tmp = 0.0 if (Float64(Float64(Float64(1.0 / Float64(x_m + 1.0)) - Float64(2.0 / x_m)) + Float64(1.0 / Float64(x_m + -1.0))) <= 1e-27) tmp = Float64(2.0 * (x_m ^ -3.0)); else tmp = Float64(Float64(Float64(x_m * Float64(x_m * -2.0)) + Float64(-2.0 * t_0)) / Float64(x_m * t_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 = (x_m + 1.0) * (1.0 - x_m); tmp = 0.0; if ((((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27) tmp = 2.0 * (x_m ^ -3.0); else tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_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[(x$95$m + 1.0), $MachinePrecision] * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[N[(N[(N[(1.0 / N[(x$95$m + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x$95$m), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x$95$m + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-27], N[(2.0 * N[Power[x$95$m, -3.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(x$95$m * N[(x$95$m * -2.0), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x$95$m * t$95$0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \left(x_m + 1\right) \cdot \left(1 - x_m\right)\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;\left(\frac{1}{x_m + 1} - \frac{2}{x_m}\right) + \frac{1}{x_m + -1} \leq 10^{-27}:\\
\;\;\;\;2 \cdot {x_m}^{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{x_m \cdot \left(x_m \cdot -2\right) + -2 \cdot t_0}{x_m \cdot t_0}\\
\end{array}
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 1e-27Initial program 7.9%
sub-neg7.9%
distribute-neg-frac7.9%
metadata-eval7.9%
metadata-eval7.9%
metadata-eval7.9%
associate-/r*7.9%
metadata-eval7.9%
neg-mul-17.9%
+-commutative7.9%
associate-+l+7.8%
+-commutative7.8%
neg-mul-17.8%
metadata-eval7.8%
associate-/r*7.8%
metadata-eval7.8%
metadata-eval7.8%
+-commutative7.8%
+-commutative7.8%
Simplified7.8%
Taylor expanded in x around inf 97.9%
expm1-log1p-u97.9%
expm1-udef5.9%
div-inv5.9%
pow-flip5.9%
metadata-eval5.9%
Applied egg-rr5.9%
expm1-def98.3%
expm1-log1p98.3%
Simplified98.3%
if 1e-27 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 55.1%
sub-neg55.1%
distribute-neg-frac55.1%
metadata-eval55.1%
metadata-eval55.1%
metadata-eval55.1%
associate-/r*55.1%
metadata-eval55.1%
neg-mul-155.1%
+-commutative55.1%
associate-+l+53.5%
+-commutative53.5%
neg-mul-153.5%
metadata-eval53.5%
associate-/r*53.5%
metadata-eval53.5%
metadata-eval53.5%
+-commutative53.5%
+-commutative53.5%
Simplified53.5%
+-commutative53.5%
frac-add53.2%
frac-add82.8%
*-un-lft-identity82.8%
*-commutative82.8%
neg-mul-182.8%
distribute-neg-in82.8%
metadata-eval82.8%
+-commutative82.8%
+-commutative82.8%
Applied egg-rr82.8%
Taylor expanded in x around 0 83.2%
*-commutative83.2%
Simplified83.2%
Final simplification98.0%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (+ (/ 2.0 (pow x_m 5.0)) (+ (* 2.0 (pow x_m -3.0)) (/ 2.0 (pow x_m 7.0))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * ((2.0 / pow(x_m, 5.0)) + ((2.0 * pow(x_m, -3.0)) + (2.0 / pow(x_m, 7.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 * ((2.0d0 / (x_m ** 5.0d0)) + ((2.0d0 * (x_m ** (-3.0d0))) + (2.0d0 / (x_m ** 7.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 * ((2.0 / Math.pow(x_m, 5.0)) + ((2.0 * Math.pow(x_m, -3.0)) + (2.0 / Math.pow(x_m, 7.0))));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * ((2.0 / math.pow(x_m, 5.0)) + ((2.0 * math.pow(x_m, -3.0)) + (2.0 / math.pow(x_m, 7.0))))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(Float64(2.0 / (x_m ^ 5.0)) + Float64(Float64(2.0 * (x_m ^ -3.0)) + Float64(2.0 / (x_m ^ 7.0))))) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * ((2.0 / (x_m ^ 5.0)) + ((2.0 * (x_m ^ -3.0)) + (2.0 / (x_m ^ 7.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[(2.0 / N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * N[Power[x$95$m, -3.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(\frac{2}{{x_m}^{5}} + \left(2 \cdot {x_m}^{-3} + \frac{2}{{x_m}^{7}}\right)\right)
\end{array}
Initial program 9.0%
sub-neg9.0%
distribute-neg-frac9.0%
metadata-eval9.0%
metadata-eval9.0%
metadata-eval9.0%
associate-/r*9.0%
metadata-eval9.0%
neg-mul-19.0%
+-commutative9.0%
associate-+l+8.8%
+-commutative8.8%
neg-mul-18.8%
metadata-eval8.8%
associate-/r*8.8%
metadata-eval8.8%
metadata-eval8.8%
+-commutative8.8%
+-commutative8.8%
Simplified8.8%
Taylor expanded in x around inf 98.2%
associate-*r/98.2%
metadata-eval98.2%
+-commutative98.2%
associate-*r/98.2%
metadata-eval98.2%
associate-*r/98.2%
metadata-eval98.2%
Simplified98.2%
expm1-log1p-u97.1%
expm1-udef6.2%
div-inv6.2%
pow-flip6.2%
metadata-eval6.2%
Applied egg-rr8.1%
expm1-def97.6%
expm1-log1p97.6%
Simplified98.6%
Final simplification98.6%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (* 2.0 (+ (pow x_m -3.0) (pow x_m -5.0)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (2.0 * (pow(x_m, -3.0) + pow(x_m, -5.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 * (2.0d0 * ((x_m ** (-3.0d0)) + (x_m ** (-5.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 * (2.0 * (Math.pow(x_m, -3.0) + Math.pow(x_m, -5.0)));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (2.0 * (math.pow(x_m, -3.0) + math.pow(x_m, -5.0)))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(2.0 * Float64((x_m ^ -3.0) + (x_m ^ -5.0)))) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (2.0 * ((x_m ^ -3.0) + (x_m ^ -5.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[(2.0 * N[(N[Power[x$95$m, -3.0], $MachinePrecision] + N[Power[x$95$m, -5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(2 \cdot \left({x_m}^{-3} + {x_m}^{-5}\right)\right)
\end{array}
Initial program 9.0%
sub-neg9.0%
distribute-neg-frac9.0%
metadata-eval9.0%
metadata-eval9.0%
metadata-eval9.0%
associate-/r*9.0%
metadata-eval9.0%
neg-mul-19.0%
+-commutative9.0%
associate-+l+8.8%
+-commutative8.8%
neg-mul-18.8%
metadata-eval8.8%
associate-/r*8.8%
metadata-eval8.8%
metadata-eval8.8%
+-commutative8.8%
+-commutative8.8%
Simplified8.8%
Taylor expanded in x around inf 98.2%
associate-*r/98.2%
metadata-eval98.2%
+-commutative98.2%
associate-*r/98.2%
metadata-eval98.2%
associate-*r/98.2%
metadata-eval98.2%
Simplified98.2%
Taylor expanded in x around inf 98.0%
+-commutative98.0%
associate-*r/98.0%
metadata-eval98.0%
associate-*r/98.0%
metadata-eval98.0%
Simplified98.0%
expm1-log1p-u98.0%
expm1-udef6.2%
div-inv6.2%
fma-def6.2%
pow-flip6.2%
metadata-eval6.2%
div-inv6.2%
pow-flip6.2%
metadata-eval6.2%
Applied egg-rr6.2%
expm1-def98.4%
expm1-log1p98.4%
fma-udef98.4%
distribute-lft-out98.4%
Simplified98.4%
Final simplification98.4%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (let* ((t_0 (+ (- (/ 1.0 (+ x_m 1.0)) (/ 2.0 x_m)) (/ 1.0 (+ x_m -1.0))))) (* x_s (if (<= t_0 0.0) (/ -2.0 (* x_m (- 1.0 x_m))) t_0))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0));
double tmp;
if (t_0 <= 0.0) {
tmp = -2.0 / (x_m * (1.0 - x_m));
} else {
tmp = t_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 = ((1.0d0 / (x_m + 1.0d0)) - (2.0d0 / x_m)) + (1.0d0 / (x_m + (-1.0d0)))
if (t_0 <= 0.0d0) then
tmp = (-2.0d0) / (x_m * (1.0d0 - x_m))
else
tmp = t_0
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 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0));
double tmp;
if (t_0 <= 0.0) {
tmp = -2.0 / (x_m * (1.0 - x_m));
} else {
tmp = t_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 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0)) tmp = 0 if t_0 <= 0.0: tmp = -2.0 / (x_m * (1.0 - x_m)) else: tmp = t_0 return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) t_0 = Float64(Float64(Float64(1.0 / Float64(x_m + 1.0)) - Float64(2.0 / x_m)) + Float64(1.0 / Float64(x_m + -1.0))) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(-2.0 / Float64(x_m * Float64(1.0 - x_m))); else tmp = t_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 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0)); tmp = 0.0; if (t_0 <= 0.0) tmp = -2.0 / (x_m * (1.0 - x_m)); else tmp = t_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[(N[(1.0 / N[(x$95$m + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x$95$m), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x$95$m + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, 0.0], N[(-2.0 / N[(x$95$m * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \left(\frac{1}{x_m + 1} - \frac{2}{x_m}\right) + \frac{1}{x_m + -1}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;\frac{-2}{x_m \cdot \left(1 - x_m\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 7.9%
sub-neg7.9%
distribute-neg-frac7.9%
metadata-eval7.9%
metadata-eval7.9%
metadata-eval7.9%
associate-/r*7.9%
metadata-eval7.9%
neg-mul-17.9%
+-commutative7.9%
associate-+l+7.8%
+-commutative7.8%
neg-mul-17.8%
metadata-eval7.8%
associate-/r*7.8%
metadata-eval7.8%
metadata-eval7.8%
+-commutative7.8%
+-commutative7.8%
Simplified7.8%
frac-add7.5%
div-inv7.5%
*-un-lft-identity7.5%
*-commutative7.5%
neg-mul-17.5%
distribute-neg-in7.5%
metadata-eval7.5%
+-commutative7.5%
Applied egg-rr7.5%
unsub-neg7.5%
associate-/r*7.7%
Simplified7.7%
+-commutative7.7%
associate-*r/7.8%
frac-add7.4%
+-commutative7.4%
un-div-inv7.8%
associate-+l-7.8%
+-commutative7.8%
*-commutative7.8%
Applied egg-rr7.8%
Taylor expanded in x around 0 4.9%
if 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 34.8%
Final simplification6.0%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (* (+ x_m 1.0) (- 1.0 x_m))))
(*
x_s
(if (<= x_m 130000000.0)
(/ (+ (* x_m (* x_m -2.0)) (* -2.0 t_0)) (* x_m t_0))
(/ -2.0 (* x_m (- 1.0 x_m)))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = (x_m + 1.0) * (1.0 - x_m);
double tmp;
if (x_m <= 130000000.0) {
tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
} else {
tmp = -2.0 / (x_m * (1.0 - x_m));
}
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 = (x_m + 1.0d0) * (1.0d0 - x_m)
if (x_m <= 130000000.0d0) then
tmp = ((x_m * (x_m * (-2.0d0))) + ((-2.0d0) * t_0)) / (x_m * t_0)
else
tmp = (-2.0d0) / (x_m * (1.0d0 - x_m))
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 = (x_m + 1.0) * (1.0 - x_m);
double tmp;
if (x_m <= 130000000.0) {
tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
} else {
tmp = -2.0 / (x_m * (1.0 - x_m));
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): t_0 = (x_m + 1.0) * (1.0 - x_m) tmp = 0 if x_m <= 130000000.0: tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0) else: tmp = -2.0 / (x_m * (1.0 - x_m)) return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) t_0 = Float64(Float64(x_m + 1.0) * Float64(1.0 - x_m)) tmp = 0.0 if (x_m <= 130000000.0) tmp = Float64(Float64(Float64(x_m * Float64(x_m * -2.0)) + Float64(-2.0 * t_0)) / Float64(x_m * t_0)); else tmp = Float64(-2.0 / Float64(x_m * Float64(1.0 - x_m))); 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 = (x_m + 1.0) * (1.0 - x_m); tmp = 0.0; if (x_m <= 130000000.0) tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0); else tmp = -2.0 / (x_m * (1.0 - x_m)); 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[(x$95$m + 1.0), $MachinePrecision] * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[x$95$m, 130000000.0], N[(N[(N[(x$95$m * N[(x$95$m * -2.0), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x$95$m * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(x$95$m * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \left(x_m + 1\right) \cdot \left(1 - x_m\right)\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 130000000:\\
\;\;\;\;\frac{x_m \cdot \left(x_m \cdot -2\right) + -2 \cdot t_0}{x_m \cdot t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x_m \cdot \left(1 - x_m\right)}\\
\end{array}
\end{array}
\end{array}
if x < 1.3e8Initial program 11.6%
sub-neg11.6%
distribute-neg-frac11.6%
metadata-eval11.6%
metadata-eval11.6%
metadata-eval11.6%
associate-/r*11.6%
metadata-eval11.6%
neg-mul-111.6%
+-commutative11.6%
associate-+l+11.3%
+-commutative11.3%
neg-mul-111.3%
metadata-eval11.3%
associate-/r*11.3%
metadata-eval11.3%
metadata-eval11.3%
+-commutative11.3%
+-commutative11.3%
Simplified11.3%
+-commutative11.3%
frac-add10.9%
frac-add16.6%
*-un-lft-identity16.6%
*-commutative16.6%
neg-mul-116.6%
distribute-neg-in16.6%
metadata-eval16.6%
+-commutative16.6%
+-commutative16.6%
Applied egg-rr16.6%
Taylor expanded in x around 0 16.6%
*-commutative16.6%
Simplified16.6%
if 1.3e8 < x Initial program 5.4%
sub-neg5.4%
distribute-neg-frac5.4%
metadata-eval5.4%
metadata-eval5.4%
metadata-eval5.4%
associate-/r*5.4%
metadata-eval5.4%
neg-mul-15.4%
+-commutative5.4%
associate-+l+5.4%
+-commutative5.4%
neg-mul-15.4%
metadata-eval5.4%
associate-/r*5.4%
metadata-eval5.4%
metadata-eval5.4%
+-commutative5.4%
+-commutative5.4%
Simplified5.4%
frac-add5.3%
div-inv5.1%
*-un-lft-identity5.1%
*-commutative5.1%
neg-mul-15.1%
distribute-neg-in5.1%
metadata-eval5.1%
+-commutative5.1%
Applied egg-rr5.1%
unsub-neg5.1%
associate-/r*5.4%
Simplified5.4%
+-commutative5.4%
associate-*r/5.3%
frac-add4.9%
+-commutative4.9%
un-div-inv5.3%
associate-+l-5.4%
+-commutative5.4%
*-commutative5.4%
Applied egg-rr5.4%
Taylor expanded in x around 0 7.4%
Final simplification12.8%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (/ -2.0 (* x_m (- 1.0 x_m)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (-2.0 / (x_m * (1.0 - 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 * ((-2.0d0) / (x_m * (1.0d0 - 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 * (-2.0 / (x_m * (1.0 - x_m)));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (-2.0 / (x_m * (1.0 - x_m)))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(-2.0 / Float64(x_m * Float64(1.0 - x_m)))) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (-2.0 / (x_m * (1.0 - 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 * N[(-2.0 / N[(x$95$m * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \frac{-2}{x_m \cdot \left(1 - x_m\right)}
\end{array}
Initial program 9.0%
sub-neg9.0%
distribute-neg-frac9.0%
metadata-eval9.0%
metadata-eval9.0%
metadata-eval9.0%
associate-/r*9.0%
metadata-eval9.0%
neg-mul-19.0%
+-commutative9.0%
associate-+l+8.8%
+-commutative8.8%
neg-mul-18.8%
metadata-eval8.8%
associate-/r*8.8%
metadata-eval8.8%
metadata-eval8.8%
+-commutative8.8%
+-commutative8.8%
Simplified8.8%
frac-add8.5%
div-inv8.4%
*-un-lft-identity8.4%
*-commutative8.4%
neg-mul-18.4%
distribute-neg-in8.4%
metadata-eval8.4%
+-commutative8.4%
Applied egg-rr8.4%
unsub-neg8.4%
associate-/r*8.7%
Simplified8.7%
+-commutative8.7%
associate-*r/8.7%
frac-add8.4%
+-commutative8.4%
un-div-inv8.8%
associate-+l-8.8%
+-commutative8.8%
*-commutative8.8%
Applied egg-rr8.8%
Taylor expanded in x around 0 5.0%
Final simplification5.0%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (/ 1.0 x_m)))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (1.0 / 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 * (1.0d0 / 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 * (1.0 / x_m);
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (1.0 / x_m)
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(1.0 / x_m)) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (1.0 / 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 * N[(1.0 / x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \frac{1}{x_m}
\end{array}
Initial program 9.0%
associate-+l-9.0%
sub-neg9.0%
+-commutative9.0%
sub-neg9.0%
distribute-neg-in9.0%
distribute-neg-frac9.0%
metadata-eval9.0%
remove-double-neg9.0%
sub-neg9.0%
metadata-eval9.0%
Simplified9.0%
frac-2neg9.0%
metadata-eval9.0%
frac-add8.9%
+-commutative8.9%
distribute-neg-in8.9%
metadata-eval8.9%
sub-neg8.9%
*-commutative8.9%
neg-mul-18.9%
+-commutative8.9%
distribute-neg-in8.9%
metadata-eval8.9%
sub-neg8.9%
Applied egg-rr8.9%
Taylor expanded in x around 0 6.4%
Taylor expanded in x around inf 6.3%
Final simplification6.3%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s 2.0))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * 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 * 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 * 2.0;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * 2.0
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * 2.0) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * 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 * 2.0), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot 2
\end{array}
Initial program 9.0%
associate-+l-9.0%
sub-neg9.0%
+-commutative9.0%
sub-neg9.0%
distribute-neg-in9.0%
distribute-neg-frac9.0%
metadata-eval9.0%
remove-double-neg9.0%
sub-neg9.0%
metadata-eval9.0%
Simplified9.0%
frac-2neg9.0%
metadata-eval9.0%
frac-add8.9%
+-commutative8.9%
distribute-neg-in8.9%
metadata-eval8.9%
sub-neg8.9%
*-commutative8.9%
neg-mul-18.9%
+-commutative8.9%
distribute-neg-in8.9%
metadata-eval8.9%
sub-neg8.9%
Applied egg-rr8.9%
Taylor expanded in x around inf 5.8%
Taylor expanded in x around 0 3.5%
Final simplification3.5%
(FPCore (x) :precision binary64 (/ 2.0 (* x (- (* x x) 1.0))))
double code(double x) {
return 2.0 / (x * ((x * x) - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (x * ((x * x) - 1.0d0))
end function
public static double code(double x) {
return 2.0 / (x * ((x * x) - 1.0));
}
def code(x): return 2.0 / (x * ((x * x) - 1.0))
function code(x) return Float64(2.0 / Float64(x * Float64(Float64(x * x) - 1.0))) end
function tmp = code(x) tmp = 2.0 / (x * ((x * x) - 1.0)); end
code[x_] := N[(2.0 / N[(x * N[(N[(x * x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x \cdot \left(x \cdot x - 1\right)}
\end{array}
herbie shell --seed 2023334
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (and (> (fabs x) 1.0) (< (fabs x) 1e+100))
:herbie-target
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))