
(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 (- 1.0 x)))
(t_1 (/ 1.0 (+ 1.0 x)))
(t_2 (+ (- t_1 (/ 2.0 x)) (/ 1.0 (+ x -1.0)))))
(if (<= t_2 -1e-8)
(/ (+ t_0 (* (+ 1.0 x) (- x 2.0))) (* (+ 1.0 x) t_0))
(if (<= t_2 5e-26)
(+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 3.0)))
(+ t_1 (* (/ 2.0 x) (/ (- (- 1.0 x) (* x -0.5)) (+ x -1.0))))))))
double code(double x) {
double t_0 = x * (1.0 - x);
double t_1 = 1.0 / (1.0 + x);
double t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_2 <= -1e-8) {
tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0);
} else if (t_2 <= 5e-26) {
tmp = (2.0 / pow(x, 5.0)) + (2.0 / pow(x, 3.0));
} else {
tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = x * (1.0d0 - x)
t_1 = 1.0d0 / (1.0d0 + x)
t_2 = (t_1 - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
if (t_2 <= (-1d-8)) then
tmp = (t_0 + ((1.0d0 + x) * (x - 2.0d0))) / ((1.0d0 + x) * t_0)
else if (t_2 <= 5d-26) then
tmp = (2.0d0 / (x ** 5.0d0)) + (2.0d0 / (x ** 3.0d0))
else
tmp = t_1 + ((2.0d0 / x) * (((1.0d0 - x) - (x * (-0.5d0))) / (x + (-1.0d0))))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = x * (1.0 - x);
double t_1 = 1.0 / (1.0 + x);
double t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_2 <= -1e-8) {
tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0);
} else if (t_2 <= 5e-26) {
tmp = (2.0 / Math.pow(x, 5.0)) + (2.0 / Math.pow(x, 3.0));
} else {
tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0)));
}
return tmp;
}
def code(x): t_0 = x * (1.0 - x) t_1 = 1.0 / (1.0 + x) t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0)) tmp = 0 if t_2 <= -1e-8: tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0) elif t_2 <= 5e-26: tmp = (2.0 / math.pow(x, 5.0)) + (2.0 / math.pow(x, 3.0)) else: tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0))) return tmp
function code(x) t_0 = Float64(x * Float64(1.0 - x)) t_1 = Float64(1.0 / Float64(1.0 + x)) t_2 = Float64(Float64(t_1 - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) tmp = 0.0 if (t_2 <= -1e-8) tmp = Float64(Float64(t_0 + Float64(Float64(1.0 + x) * Float64(x - 2.0))) / Float64(Float64(1.0 + x) * t_0)); elseif (t_2 <= 5e-26) tmp = Float64(Float64(2.0 / (x ^ 5.0)) + Float64(2.0 / (x ^ 3.0))); else tmp = Float64(t_1 + Float64(Float64(2.0 / x) * Float64(Float64(Float64(1.0 - x) - Float64(x * -0.5)) / Float64(x + -1.0)))); end return tmp end
function tmp_2 = code(x) t_0 = x * (1.0 - x); t_1 = 1.0 / (1.0 + x); t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0)); tmp = 0.0; if (t_2 <= -1e-8) tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0); elseif (t_2 <= 5e-26) tmp = (2.0 / (x ^ 5.0)) + (2.0 / (x ^ 3.0)); else tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0))); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e-8], N[(N[(t$95$0 + N[(N[(1.0 + x), $MachinePrecision] * N[(x - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e-26], N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(2.0 / x), $MachinePrecision] * N[(N[(N[(1.0 - x), $MachinePrecision] - N[(x * -0.5), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - x\right)\\
t_1 := \frac{1}{1 + x}\\
t_2 := \left(t_1 - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{-8}:\\
\;\;\;\;\frac{t_0 + \left(1 + x\right) \cdot \left(x - 2\right)}{\left(1 + x\right) \cdot t_0}\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{-26}:\\
\;\;\;\;\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \frac{2}{x} \cdot \frac{\left(1 - x\right) - x \cdot -0.5}{x + -1}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -1e-8Initial program 99.3%
associate-+l-99.3%
sub-neg99.3%
neg-mul-199.3%
metadata-eval99.3%
cancel-sign-sub-inv99.3%
+-commutative99.3%
*-lft-identity99.3%
sub-neg99.3%
metadata-eval99.3%
Simplified99.3%
frac-2neg99.3%
metadata-eval99.3%
frac-sub99.3%
+-commutative99.3%
distribute-neg-in99.3%
metadata-eval99.3%
sub-neg99.3%
*-commutative99.3%
neg-mul-199.3%
+-commutative99.3%
distribute-neg-in99.3%
metadata-eval99.3%
sub-neg99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 99.3%
neg-mul-199.3%
unsub-neg99.3%
Simplified99.3%
frac-sub99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
if -1e-8 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 5.00000000000000019e-26Initial program 59.9%
associate-+l-59.9%
sub-neg59.9%
neg-mul-159.9%
metadata-eval59.9%
cancel-sign-sub-inv59.9%
+-commutative59.9%
*-lft-identity59.9%
sub-neg59.9%
metadata-eval59.9%
Simplified59.9%
Taylor expanded in x around inf 98.4%
associate-*r/98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
if 5.00000000000000019e-26 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 99.9%
associate-+l-99.9%
sub-neg99.9%
neg-mul-199.9%
metadata-eval99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-lft-identity99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
clear-num99.9%
frac-sub99.9%
*-un-lft-identity99.9%
div-inv99.9%
metadata-eval99.9%
div-inv99.9%
metadata-eval99.9%
Applied egg-rr99.9%
associate-/r*100.0%
*-rgt-identity100.0%
associate--l+99.9%
Simplified99.9%
sub-neg99.9%
associate-/l/99.9%
Applied egg-rr99.9%
sub-neg99.9%
*-lft-identity99.9%
+-commutative99.9%
associate-*r/99.9%
*-commutative99.9%
times-frac99.9%
*-commutative99.9%
associate-/r*99.9%
metadata-eval99.9%
associate-+r-100.0%
sub-neg100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification99.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (* x (- 1.0 x)))
(t_1 (/ 1.0 (+ 1.0 x)))
(t_2 (+ (- t_1 (/ 2.0 x)) (/ 1.0 (+ x -1.0)))))
(if (<= t_2 -1e-13)
(/ (+ t_0 (* (+ 1.0 x) (- x 2.0))) (* (+ 1.0 x) t_0))
(if (<= t_2 5e-26)
(/ 2.0 (pow x 3.0))
(+ t_1 (* (/ 2.0 x) (/ (- (- 1.0 x) (* x -0.5)) (+ x -1.0))))))))
double code(double x) {
double t_0 = x * (1.0 - x);
double t_1 = 1.0 / (1.0 + x);
double t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_2 <= -1e-13) {
tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0);
} else if (t_2 <= 5e-26) {
tmp = 2.0 / pow(x, 3.0);
} else {
tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = x * (1.0d0 - x)
t_1 = 1.0d0 / (1.0d0 + x)
t_2 = (t_1 - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
if (t_2 <= (-1d-13)) then
tmp = (t_0 + ((1.0d0 + x) * (x - 2.0d0))) / ((1.0d0 + x) * t_0)
else if (t_2 <= 5d-26) then
tmp = 2.0d0 / (x ** 3.0d0)
else
tmp = t_1 + ((2.0d0 / x) * (((1.0d0 - x) - (x * (-0.5d0))) / (x + (-1.0d0))))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = x * (1.0 - x);
double t_1 = 1.0 / (1.0 + x);
double t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_2 <= -1e-13) {
tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0);
} else if (t_2 <= 5e-26) {
tmp = 2.0 / Math.pow(x, 3.0);
} else {
tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0)));
}
return tmp;
}
def code(x): t_0 = x * (1.0 - x) t_1 = 1.0 / (1.0 + x) t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0)) tmp = 0 if t_2 <= -1e-13: tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0) elif t_2 <= 5e-26: tmp = 2.0 / math.pow(x, 3.0) else: tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0))) return tmp
function code(x) t_0 = Float64(x * Float64(1.0 - x)) t_1 = Float64(1.0 / Float64(1.0 + x)) t_2 = Float64(Float64(t_1 - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) tmp = 0.0 if (t_2 <= -1e-13) tmp = Float64(Float64(t_0 + Float64(Float64(1.0 + x) * Float64(x - 2.0))) / Float64(Float64(1.0 + x) * t_0)); elseif (t_2 <= 5e-26) tmp = Float64(2.0 / (x ^ 3.0)); else tmp = Float64(t_1 + Float64(Float64(2.0 / x) * Float64(Float64(Float64(1.0 - x) - Float64(x * -0.5)) / Float64(x + -1.0)))); end return tmp end
function tmp_2 = code(x) t_0 = x * (1.0 - x); t_1 = 1.0 / (1.0 + x); t_2 = (t_1 - (2.0 / x)) + (1.0 / (x + -1.0)); tmp = 0.0; if (t_2 <= -1e-13) tmp = (t_0 + ((1.0 + x) * (x - 2.0))) / ((1.0 + x) * t_0); elseif (t_2 <= 5e-26) tmp = 2.0 / (x ^ 3.0); else tmp = t_1 + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0))); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e-13], N[(N[(t$95$0 + N[(N[(1.0 + x), $MachinePrecision] * N[(x - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e-26], N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(2.0 / x), $MachinePrecision] * N[(N[(N[(1.0 - x), $MachinePrecision] - N[(x * -0.5), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - x\right)\\
t_1 := \frac{1}{1 + x}\\
t_2 := \left(t_1 - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{-13}:\\
\;\;\;\;\frac{t_0 + \left(1 + x\right) \cdot \left(x - 2\right)}{\left(1 + x\right) \cdot t_0}\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{-26}:\\
\;\;\;\;\frac{2}{{x}^{3}}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \frac{2}{x} \cdot \frac{\left(1 - x\right) - x \cdot -0.5}{x + -1}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -1e-13Initial program 98.5%
associate-+l-98.5%
sub-neg98.5%
neg-mul-198.5%
metadata-eval98.5%
cancel-sign-sub-inv98.5%
+-commutative98.5%
*-lft-identity98.5%
sub-neg98.5%
metadata-eval98.5%
Simplified98.5%
frac-2neg98.5%
metadata-eval98.5%
frac-sub98.5%
+-commutative98.5%
distribute-neg-in98.5%
metadata-eval98.5%
sub-neg98.5%
*-commutative98.5%
neg-mul-198.5%
+-commutative98.5%
distribute-neg-in98.5%
metadata-eval98.5%
sub-neg98.5%
Applied egg-rr98.5%
Taylor expanded in x around 0 98.5%
neg-mul-198.5%
unsub-neg98.5%
Simplified98.5%
frac-sub99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
if -1e-13 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 5.00000000000000019e-26Initial program 59.9%
associate-+l-59.9%
sub-neg59.9%
neg-mul-159.9%
metadata-eval59.9%
cancel-sign-sub-inv59.9%
+-commutative59.9%
*-lft-identity59.9%
sub-neg59.9%
metadata-eval59.9%
Simplified59.9%
Taylor expanded in x around inf 98.4%
if 5.00000000000000019e-26 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 99.9%
associate-+l-99.9%
sub-neg99.9%
neg-mul-199.9%
metadata-eval99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-lft-identity99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
clear-num99.9%
frac-sub99.9%
*-un-lft-identity99.9%
div-inv99.9%
metadata-eval99.9%
div-inv99.9%
metadata-eval99.9%
Applied egg-rr99.9%
associate-/r*100.0%
*-rgt-identity100.0%
associate--l+99.9%
Simplified99.9%
sub-neg99.9%
associate-/l/99.9%
Applied egg-rr99.9%
sub-neg99.9%
*-lft-identity99.9%
+-commutative99.9%
associate-*r/99.9%
*-commutative99.9%
times-frac99.9%
*-commutative99.9%
associate-/r*99.9%
metadata-eval99.9%
associate-+r-100.0%
sub-neg100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification99.1%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ 1.0 x)) (* (/ 2.0 x) (/ (- (- 1.0 x) (* x -0.5)) (+ x -1.0)))))
double code(double x) {
return (1.0 / (1.0 + x)) + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (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) - (x * (-0.5d0))) / (x + (-1.0d0))))
end function
public static double code(double x) {
return (1.0 / (1.0 + x)) + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0)));
}
def code(x): return (1.0 / (1.0 + x)) + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0)))
function code(x) return Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(Float64(2.0 / x) * Float64(Float64(Float64(1.0 - x) - Float64(x * -0.5)) / Float64(x + -1.0)))) end
function tmp = code(x) tmp = (1.0 / (1.0 + x)) + ((2.0 / x) * (((1.0 - x) - (x * -0.5)) / (x + -1.0))); end
code[x_] := N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 / x), $MachinePrecision] * N[(N[(N[(1.0 - x), $MachinePrecision] - N[(x * -0.5), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + x} + \frac{2}{x} \cdot \frac{\left(1 - x\right) - x \cdot -0.5}{x + -1}
\end{array}
Initial program 78.7%
associate-+l-78.7%
sub-neg78.7%
neg-mul-178.7%
metadata-eval78.7%
cancel-sign-sub-inv78.7%
+-commutative78.7%
*-lft-identity78.7%
sub-neg78.7%
metadata-eval78.7%
Simplified78.7%
clear-num78.7%
frac-sub55.8%
*-un-lft-identity55.8%
div-inv55.8%
metadata-eval55.8%
div-inv55.8%
metadata-eval55.8%
Applied egg-rr55.8%
associate-/r*78.7%
*-rgt-identity78.7%
associate--l+78.7%
Simplified78.7%
sub-neg78.7%
associate-/l/55.8%
Applied egg-rr55.8%
sub-neg55.8%
*-lft-identity55.8%
+-commutative55.8%
associate-*r/55.8%
*-commutative55.8%
times-frac78.8%
*-commutative78.8%
associate-/r*78.8%
metadata-eval78.8%
associate-+r-78.8%
sub-neg78.8%
distribute-rgt-neg-in78.8%
metadata-eval78.8%
Simplified78.8%
Final simplification78.8%
(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 78.7%
Final simplification78.7%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ 1.0 x)) (/ (/ (- 2.0 x) x) (+ x -1.0))))
double code(double x) {
return (1.0 / (1.0 + x)) + (((2.0 - x) / x) / (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (1.0d0 + x)) + (((2.0d0 - x) / x) / (x + (-1.0d0)))
end function
public static double code(double x) {
return (1.0 / (1.0 + x)) + (((2.0 - x) / x) / (x + -1.0));
}
def code(x): return (1.0 / (1.0 + x)) + (((2.0 - x) / x) / (x + -1.0))
function code(x) return Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(Float64(Float64(2.0 - x) / x) / Float64(x + -1.0))) end
function tmp = code(x) tmp = (1.0 / (1.0 + x)) + (((2.0 - x) / x) / (x + -1.0)); end
code[x_] := N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(2.0 - x), $MachinePrecision] / x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + x} + \frac{\frac{2 - x}{x}}{x + -1}
\end{array}
Initial program 78.7%
associate-+l-78.7%
sub-neg78.7%
neg-mul-178.7%
metadata-eval78.7%
cancel-sign-sub-inv78.7%
+-commutative78.7%
*-lft-identity78.7%
sub-neg78.7%
metadata-eval78.7%
Simplified78.7%
frac-sub55.7%
associate-/r*78.4%
*-rgt-identity78.4%
distribute-rgt-in78.4%
metadata-eval78.4%
metadata-eval78.4%
fma-def78.4%
metadata-eval78.4%
Applied egg-rr78.4%
Taylor expanded in x around 0 78.7%
Final simplification78.7%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.39))) (/ -1.0 (* x x)) (- (- x) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.39)) {
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 <= 0.39d0))) 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 <= 0.39)) {
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 <= 0.39): tmp = -1.0 / (x * x) else: tmp = -x - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.39)) 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 <= 0.39))) 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, 0.39]], $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 0.39\right):\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) - \frac{2}{x}\\
\end{array}
\end{array}
if x < -1 or 0.39000000000000001 < x Initial program 60.5%
associate-+l-60.5%
sub-neg60.5%
neg-mul-160.5%
metadata-eval60.5%
cancel-sign-sub-inv60.5%
+-commutative60.5%
*-lft-identity60.5%
sub-neg60.5%
metadata-eval60.5%
Simplified60.5%
Taylor expanded in x around inf 58.6%
Taylor expanded in x around inf 48.3%
unpow248.3%
Simplified48.3%
if -1 < x < 0.39000000000000001Initial 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 98.8%
Taylor expanded in x around 0 98.8%
neg-mul-198.8%
associate-*r/98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification71.6%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.38))) (/ -1.0 (* x x)) (/ -2.0 x)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.38)) {
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 <= 0.38d0))) 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 <= 0.38)) {
tmp = -1.0 / (x * x);
} else {
tmp = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 0.38): tmp = -1.0 / (x * x) else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.38)) 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 <= 0.38))) 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, 0.38]], $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 0.38\right):\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < -1 or 0.38 < x Initial program 60.5%
associate-+l-60.5%
sub-neg60.5%
neg-mul-160.5%
metadata-eval60.5%
cancel-sign-sub-inv60.5%
+-commutative60.5%
*-lft-identity60.5%
sub-neg60.5%
metadata-eval60.5%
Simplified60.5%
Taylor expanded in x around inf 58.6%
Taylor expanded in x around inf 48.3%
unpow248.3%
Simplified48.3%
if -1 < x < 0.38Initial 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 98.8%
Final simplification71.6%
(FPCore (x) :precision binary64 (- 1.0 (- (/ 2.0 x) -1.0)))
double code(double x) {
return 1.0 - ((2.0 / x) - -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - ((2.0d0 / x) - (-1.0d0))
end function
public static double code(double x) {
return 1.0 - ((2.0 / x) - -1.0);
}
def code(x): return 1.0 - ((2.0 / x) - -1.0)
function code(x) return Float64(1.0 - Float64(Float64(2.0 / x) - -1.0)) end
function tmp = code(x) tmp = 1.0 - ((2.0 / x) - -1.0); end
code[x_] := N[(1.0 - N[(N[(2.0 / x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \left(\frac{2}{x} - -1\right)
\end{array}
Initial program 78.7%
associate-+l-78.7%
sub-neg78.7%
neg-mul-178.7%
metadata-eval78.7%
cancel-sign-sub-inv78.7%
+-commutative78.7%
*-lft-identity78.7%
sub-neg78.7%
metadata-eval78.7%
Simplified78.7%
Taylor expanded in x around 0 47.4%
Taylor expanded in x around 0 76.8%
Final simplification76.8%
(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 78.7%
associate-+l-78.7%
sub-neg78.7%
neg-mul-178.7%
metadata-eval78.7%
cancel-sign-sub-inv78.7%
+-commutative78.7%
*-lft-identity78.7%
sub-neg78.7%
metadata-eval78.7%
Simplified78.7%
Taylor expanded in x around 0 48.1%
Final simplification48.1%
(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 78.7%
associate-+l-78.7%
sub-neg78.7%
neg-mul-178.7%
metadata-eval78.7%
cancel-sign-sub-inv78.7%
+-commutative78.7%
*-lft-identity78.7%
sub-neg78.7%
metadata-eval78.7%
Simplified78.7%
Taylor expanded in x around 0 47.4%
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 2023257
(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))))