
(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 10 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}
(FPCore (x)
:precision binary64
(let* ((t_0 (- (* x x) x))
(t_1 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0)))))
(if (<= t_1 -1e-7)
(/ (+ t_0 (* (+ 1.0 x) (- x (fma x 2.0 -2.0)))) (* (+ 1.0 x) t_0))
(if (<= t_1 0.0)
(* 2.0 (pow x -3.0))
(/
(+ (* x (- 1.0 x)) (* (fma 2.0 (- 1.0 x) x) (- -1.0 x)))
(* (- 1.0 x) (* x (+ 1.0 x))))))))
double code(double x) {
double t_0 = (x * x) - x;
double t_1 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_1 <= -1e-7) {
tmp = (t_0 + ((1.0 + x) * (x - fma(x, 2.0, -2.0)))) / ((1.0 + x) * t_0);
} else if (t_1 <= 0.0) {
tmp = 2.0 * pow(x, -3.0);
} else {
tmp = ((x * (1.0 - x)) + (fma(2.0, (1.0 - x), x) * (-1.0 - x))) / ((1.0 - x) * (x * (1.0 + x)));
}
return tmp;
}
function code(x) t_0 = Float64(Float64(x * x) - x) t_1 = Float64(Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) tmp = 0.0 if (t_1 <= -1e-7) tmp = Float64(Float64(t_0 + Float64(Float64(1.0 + x) * Float64(x - fma(x, 2.0, -2.0)))) / Float64(Float64(1.0 + x) * t_0)); elseif (t_1 <= 0.0) tmp = Float64(2.0 * (x ^ -3.0)); else tmp = Float64(Float64(Float64(x * Float64(1.0 - x)) + Float64(fma(2.0, Float64(1.0 - x), x) * Float64(-1.0 - x))) / Float64(Float64(1.0 - x) * Float64(x * Float64(1.0 + x)))); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-7], N[(N[(t$95$0 + N[(N[(1.0 + x), $MachinePrecision] * N[(x - N[(x * 2.0 + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot x - x\\
t_1 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-7}:\\
\;\;\;\;\frac{t_0 + \left(1 + x\right) \cdot \left(x - \mathsf{fma}\left(x, 2, -2\right)\right)}{\left(1 + x\right) \cdot t_0}\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;2 \cdot {x}^{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(1 - x\right) + \mathsf{fma}\left(2, 1 - x, x\right) \cdot \left(-1 - x\right)}{\left(1 - x\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -9.9999999999999995e-8Initial program 99.5%
associate-+l-99.5%
sub-neg99.5%
neg-mul-199.5%
metadata-eval99.5%
cancel-sign-sub-inv99.5%
+-commutative99.5%
*-lft-identity99.5%
sub-neg99.5%
metadata-eval99.5%
Simplified99.5%
frac-sub99.5%
frac-sub100.0%
*-un-lft-identity100.0%
distribute-rgt-in100.0%
neg-mul-1100.0%
sub-neg100.0%
*-rgt-identity100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
metadata-eval100.0%
fma-def100.0%
metadata-eval100.0%
distribute-rgt-in100.0%
neg-mul-1100.0%
sub-neg100.0%
Applied egg-rr100.0%
+-commutative100.0%
remove-double-neg100.0%
metadata-eval100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
fma-udef100.0%
distribute-lft-neg-in100.0%
distribute-lft-neg-in100.0%
fma-udef100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
if -9.9999999999999995e-8 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 67.0%
associate-+l-67.0%
sub-neg67.0%
neg-mul-167.0%
metadata-eval67.0%
cancel-sign-sub-inv67.0%
+-commutative67.0%
*-lft-identity67.0%
sub-neg67.0%
metadata-eval67.0%
Simplified67.0%
Taylor expanded in x around inf 99.4%
div-inv99.4%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 99.7%
associate-+l-99.7%
sub-neg99.7%
neg-mul-199.7%
metadata-eval99.7%
cancel-sign-sub-inv99.7%
+-commutative99.7%
*-lft-identity99.7%
sub-neg99.7%
metadata-eval99.7%
Simplified99.7%
frac-2neg99.7%
metadata-eval99.7%
frac-sub99.8%
+-commutative99.8%
distribute-neg-in99.8%
metadata-eval99.8%
sub-neg99.8%
*-commutative99.8%
neg-mul-199.8%
+-commutative99.8%
distribute-neg-in99.8%
metadata-eval99.8%
sub-neg99.8%
Applied egg-rr99.8%
frac-sub99.9%
*-un-lft-identity99.9%
+-commutative99.9%
*-un-lft-identity99.9%
fma-def99.9%
metadata-eval99.9%
fma-neg99.9%
*-un-lft-identity99.9%
fma-neg99.9%
+-commutative99.9%
*-un-lft-identity99.9%
fma-def99.9%
metadata-eval99.9%
fma-neg99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
*-commutative99.9%
remove-double-neg99.9%
sub-neg99.9%
metadata-eval99.9%
associate-*r*99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (* x (- 1.0 x)))
(t_1 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0)))))
(if (<= t_1 -1e-7)
(/ (+ t_0 (* (+ 1.0 x) (- x 2.0))) (* (- -1.0 x) (* x (+ x -1.0))))
(if (<= t_1 0.0)
(* 2.0 (pow x -3.0))
(/
(+ t_0 (* (fma 2.0 (- 1.0 x) x) (- -1.0 x)))
(* (- 1.0 x) (* x (+ 1.0 x))))))))
double code(double x) {
double t_0 = x * (1.0 - x);
double t_1 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_1 <= -1e-7) {
tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((-1.0 - x) * (x * (x + -1.0)));
} else if (t_1 <= 0.0) {
tmp = 2.0 * pow(x, -3.0);
} else {
tmp = (t_0 + (fma(2.0, (1.0 - x), x) * (-1.0 - x))) / ((1.0 - x) * (x * (1.0 + x)));
}
return tmp;
}
function code(x) t_0 = Float64(x * Float64(1.0 - x)) t_1 = Float64(Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) tmp = 0.0 if (t_1 <= -1e-7) tmp = Float64(Float64(t_0 + Float64(Float64(1.0 + x) * Float64(x - 2.0))) / Float64(Float64(-1.0 - x) * Float64(x * Float64(x + -1.0)))); elseif (t_1 <= 0.0) tmp = Float64(2.0 * (x ^ -3.0)); else tmp = Float64(Float64(t_0 + Float64(fma(2.0, Float64(1.0 - x), x) * Float64(-1.0 - x))) / Float64(Float64(1.0 - x) * Float64(x * Float64(1.0 + x)))); end return tmp end
code[x_] := Block[{t$95$0 = N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-7], N[(N[(t$95$0 + N[(N[(1.0 + x), $MachinePrecision] * N[(x - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 - x), $MachinePrecision] * N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 + N[(N[(2.0 * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - x\right)\\
t_1 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-7}:\\
\;\;\;\;\frac{t_0 + \left(1 + x\right) \cdot \left(x - 2\right)}{\left(-1 - x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;2 \cdot {x}^{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 + \mathsf{fma}\left(2, 1 - x, x\right) \cdot \left(-1 - x\right)}{\left(1 - x\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -9.9999999999999995e-8Initial program 99.5%
associate-+l-99.5%
sub-neg99.5%
neg-mul-199.5%
metadata-eval99.5%
cancel-sign-sub-inv99.5%
+-commutative99.5%
*-lft-identity99.5%
sub-neg99.5%
metadata-eval99.5%
Simplified99.5%
frac-2neg99.5%
metadata-eval99.5%
frac-sub99.5%
+-commutative99.5%
distribute-neg-in99.5%
metadata-eval99.5%
sub-neg99.5%
*-commutative99.5%
neg-mul-199.5%
+-commutative99.5%
distribute-neg-in99.5%
metadata-eval99.5%
sub-neg99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 99.4%
neg-mul-199.4%
unsub-neg99.4%
Simplified99.4%
frac-sub100.0%
*-un-lft-identity100.0%
+-commutative100.0%
+-commutative100.0%
Applied egg-rr100.0%
if -9.9999999999999995e-8 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 67.0%
associate-+l-67.0%
sub-neg67.0%
neg-mul-167.0%
metadata-eval67.0%
cancel-sign-sub-inv67.0%
+-commutative67.0%
*-lft-identity67.0%
sub-neg67.0%
metadata-eval67.0%
Simplified67.0%
Taylor expanded in x around inf 99.4%
div-inv99.4%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 99.7%
associate-+l-99.7%
sub-neg99.7%
neg-mul-199.7%
metadata-eval99.7%
cancel-sign-sub-inv99.7%
+-commutative99.7%
*-lft-identity99.7%
sub-neg99.7%
metadata-eval99.7%
Simplified99.7%
frac-2neg99.7%
metadata-eval99.7%
frac-sub99.8%
+-commutative99.8%
distribute-neg-in99.8%
metadata-eval99.8%
sub-neg99.8%
*-commutative99.8%
neg-mul-199.8%
+-commutative99.8%
distribute-neg-in99.8%
metadata-eval99.8%
sub-neg99.8%
Applied egg-rr99.8%
frac-sub99.9%
*-un-lft-identity99.9%
+-commutative99.9%
*-un-lft-identity99.9%
fma-def99.9%
metadata-eval99.9%
fma-neg99.9%
*-un-lft-identity99.9%
fma-neg99.9%
+-commutative99.9%
*-un-lft-identity99.9%
fma-def99.9%
metadata-eval99.9%
fma-neg99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
*-commutative99.9%
remove-double-neg99.9%
sub-neg99.9%
metadata-eval99.9%
associate-*r*99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0)))))
(if (or (<= t_0 -1e-7) (not (<= t_0 0.0)))
(/
(+ (* x (- 1.0 x)) (* (+ 1.0 x) (- x 2.0)))
(* (- -1.0 x) (* x (+ x -1.0))))
(* 2.0 (pow x -3.0)))))
double code(double x) {
double t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if ((t_0 <= -1e-7) || !(t_0 <= 0.0)) {
tmp = ((x * (1.0 - x)) + ((1.0 + x) * (x - 2.0))) / ((-1.0 - x) * (x * (x + -1.0)));
} else {
tmp = 2.0 * pow(x, -3.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = ((1.0d0 / (1.0d0 + x)) - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
if ((t_0 <= (-1d-7)) .or. (.not. (t_0 <= 0.0d0))) then
tmp = ((x * (1.0d0 - x)) + ((1.0d0 + x) * (x - 2.0d0))) / (((-1.0d0) - x) * (x * (x + (-1.0d0))))
else
tmp = 2.0d0 * (x ** (-3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if ((t_0 <= -1e-7) || !(t_0 <= 0.0)) {
tmp = ((x * (1.0 - x)) + ((1.0 + x) * (x - 2.0))) / ((-1.0 - x) * (x * (x + -1.0)));
} else {
tmp = 2.0 * Math.pow(x, -3.0);
}
return tmp;
}
def code(x): t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0)) tmp = 0 if (t_0 <= -1e-7) or not (t_0 <= 0.0): tmp = ((x * (1.0 - x)) + ((1.0 + x) * (x - 2.0))) / ((-1.0 - x) * (x * (x + -1.0))) else: tmp = 2.0 * math.pow(x, -3.0) return tmp
function code(x) t_0 = Float64(Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) tmp = 0.0 if ((t_0 <= -1e-7) || !(t_0 <= 0.0)) tmp = Float64(Float64(Float64(x * Float64(1.0 - x)) + Float64(Float64(1.0 + x) * Float64(x - 2.0))) / Float64(Float64(-1.0 - x) * Float64(x * Float64(x + -1.0)))); else tmp = Float64(2.0 * (x ^ -3.0)); end return tmp end
function tmp_2 = code(x) t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0)); tmp = 0.0; if ((t_0 <= -1e-7) || ~((t_0 <= 0.0))) tmp = ((x * (1.0 - x)) + ((1.0 + x) * (x - 2.0))) / ((-1.0 - x) * (x * (x + -1.0))); else tmp = 2.0 * (x ^ -3.0); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e-7], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], N[(N[(N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] * N[(x - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 - x), $MachinePrecision] * N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-7} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;\frac{x \cdot \left(1 - x\right) + \left(1 + x\right) \cdot \left(x - 2\right)}{\left(-1 - x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot {x}^{-3}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -9.9999999999999995e-8 or 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 99.6%
associate-+l-99.6%
sub-neg99.6%
neg-mul-199.6%
metadata-eval99.6%
cancel-sign-sub-inv99.6%
+-commutative99.6%
*-lft-identity99.6%
sub-neg99.6%
metadata-eval99.6%
Simplified99.6%
frac-2neg99.6%
metadata-eval99.6%
frac-sub99.6%
+-commutative99.6%
distribute-neg-in99.6%
metadata-eval99.6%
sub-neg99.6%
*-commutative99.6%
neg-mul-199.6%
+-commutative99.6%
distribute-neg-in99.6%
metadata-eval99.6%
sub-neg99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 99.6%
neg-mul-199.6%
unsub-neg99.6%
Simplified99.6%
frac-sub99.9%
*-un-lft-identity99.9%
+-commutative99.9%
+-commutative99.9%
Applied egg-rr99.9%
if -9.9999999999999995e-8 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 67.0%
associate-+l-67.0%
sub-neg67.0%
neg-mul-167.0%
metadata-eval67.0%
cancel-sign-sub-inv67.0%
+-commutative67.0%
*-lft-identity67.0%
sub-neg67.0%
metadata-eval67.0%
Simplified67.0%
Taylor expanded in x around inf 99.4%
div-inv99.4%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (/ (+ (- 1.0 x) (* (+ 1.0 x) (/ (- x 2.0) x))) (* (+ 1.0 x) (- 1.0 x))))
double code(double x) {
return ((1.0 - x) + ((1.0 + x) * ((x - 2.0) / x))) / ((1.0 + x) * (1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 - x) + ((1.0d0 + x) * ((x - 2.0d0) / x))) / ((1.0d0 + x) * (1.0d0 - x))
end function
public static double code(double x) {
return ((1.0 - x) + ((1.0 + x) * ((x - 2.0) / x))) / ((1.0 + x) * (1.0 - x));
}
def code(x): return ((1.0 - x) + ((1.0 + x) * ((x - 2.0) / x))) / ((1.0 + x) * (1.0 - x))
function code(x) return Float64(Float64(Float64(1.0 - x) + Float64(Float64(1.0 + x) * Float64(Float64(x - 2.0) / x))) / Float64(Float64(1.0 + x) * Float64(1.0 - x))) end
function tmp = code(x) tmp = ((1.0 - x) + ((1.0 + x) * ((x - 2.0) / x))) / ((1.0 + x) * (1.0 - x)); end
code[x_] := N[(N[(N[(1.0 - x), $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] * N[(N[(x - 2.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 - x\right) + \left(1 + x\right) \cdot \frac{x - 2}{x}}{\left(1 + x\right) \cdot \left(1 - x\right)}
\end{array}
Initial program 83.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
frac-2neg83.3%
metadata-eval83.3%
frac-sub56.0%
+-commutative56.0%
distribute-neg-in56.0%
metadata-eval56.0%
sub-neg56.0%
*-commutative56.0%
neg-mul-156.0%
+-commutative56.0%
distribute-neg-in56.0%
metadata-eval56.0%
sub-neg56.0%
Applied egg-rr56.0%
Taylor expanded in x around 0 55.9%
neg-mul-155.9%
unsub-neg55.9%
Simplified55.9%
associate-/r*83.3%
frac-sub83.3%
*-un-lft-identity83.3%
+-commutative83.3%
+-commutative83.3%
Applied egg-rr83.3%
*-commutative83.3%
*-commutative83.3%
Simplified83.3%
Final simplification83.3%
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0))))
double code(double x) {
return ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (1.0d0 + x)) - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
end function
public static double code(double x) {
return ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
}
def code(x): return ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) end
function tmp = code(x) tmp = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}
\end{array}
Initial program 83.3%
Final simplification83.3%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -1.0 (* x x)) (- (- x) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -1.0 / (x * x);
} else {
tmp = -x - (2.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-1.0d0) / (x * x)
else
tmp = -x - (2.0d0 / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -1.0 / (x * x);
} else {
tmp = -x - (2.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -1.0 / (x * x) else: tmp = -x - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-1.0 / Float64(x * x)); else tmp = Float64(Float64(-x) - Float64(2.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -1.0 / (x * x); else tmp = -x - (2.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], N[((-x) - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) - \frac{2}{x}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 67.4%
associate-+l-67.4%
sub-neg67.4%
neg-mul-167.4%
metadata-eval67.4%
cancel-sign-sub-inv67.4%
+-commutative67.4%
*-lft-identity67.4%
sub-neg67.4%
metadata-eval67.4%
Simplified67.4%
flip-+14.6%
sub-neg14.6%
metadata-eval14.6%
distribute-neg-in14.6%
+-commutative14.6%
associate-/r/12.3%
metadata-eval12.3%
+-commutative12.3%
distribute-neg-in12.3%
metadata-eval12.3%
sub-neg12.3%
Applied egg-rr12.3%
associate-*l/13.9%
*-lft-identity13.9%
Simplified13.9%
Taylor expanded in x around inf 12.2%
Taylor expanded in x around inf 58.0%
unpow258.0%
Simplified58.0%
if -1 < x < 1Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
neg-mul-1100.0%
metadata-eval100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-lft-identity100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around 0 99.6%
neg-mul-199.6%
associate-*r/99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification78.3%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -1.0 (* x x)) (/ -2.0 x)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -1.0 / (x * x);
} else {
tmp = -2.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-1.0d0) / (x * x)
else
tmp = (-2.0d0) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -1.0 / (x * x);
} else {
tmp = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -1.0 / (x * x) else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-1.0 / Float64(x * x)); else tmp = Float64(-2.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -1.0 / (x * x); else tmp = -2.0 / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 67.4%
associate-+l-67.4%
sub-neg67.4%
neg-mul-167.4%
metadata-eval67.4%
cancel-sign-sub-inv67.4%
+-commutative67.4%
*-lft-identity67.4%
sub-neg67.4%
metadata-eval67.4%
Simplified67.4%
flip-+14.6%
sub-neg14.6%
metadata-eval14.6%
distribute-neg-in14.6%
+-commutative14.6%
associate-/r/12.3%
metadata-eval12.3%
+-commutative12.3%
distribute-neg-in12.3%
metadata-eval12.3%
sub-neg12.3%
Applied egg-rr12.3%
associate-*l/13.9%
*-lft-identity13.9%
Simplified13.9%
Taylor expanded in x around inf 12.2%
Taylor expanded in x around inf 58.0%
unpow258.0%
Simplified58.0%
if -1 < x < 1Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
neg-mul-1100.0%
metadata-eval100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-lft-identity100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.6%
Final simplification78.3%
(FPCore (x) :precision binary64 (+ 1.0 (- -1.0 (/ 2.0 x))))
double code(double x) {
return 1.0 + (-1.0 - (2.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + ((-1.0d0) - (2.0d0 / x))
end function
public static double code(double x) {
return 1.0 + (-1.0 - (2.0 / x));
}
def code(x): return 1.0 + (-1.0 - (2.0 / x))
function code(x) return Float64(1.0 + Float64(-1.0 - Float64(2.0 / x))) end
function tmp = code(x) tmp = 1.0 + (-1.0 - (2.0 / x)); end
code[x_] := N[(1.0 + N[(-1.0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(-1 - \frac{2}{x}\right)
\end{array}
Initial program 83.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
Taylor expanded in x around 0 50.3%
Taylor expanded in x around 0 82.2%
Final simplification82.2%
(FPCore (x) :precision binary64 (/ -2.0 x))
double code(double x) {
return -2.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / x
end function
public static double code(double x) {
return -2.0 / x;
}
def code(x): return -2.0 / x
function code(x) return Float64(-2.0 / x) end
function tmp = code(x) tmp = -2.0 / x; end
code[x_] := N[(-2.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x}
\end{array}
Initial program 83.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
Taylor expanded in x around 0 51.3%
Final simplification51.3%
(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 83.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
Taylor expanded in x around 0 50.3%
Taylor expanded in x around inf 3.2%
Final simplification3.2%
(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 2023256
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:herbie-target
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))