
(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 9 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 (* (fma 2.0 (/ (/ 1.0 x) x) (fma 2.0 (pow x -4.0) 2.0)) (pow x -3.0)))
double code(double x) {
return fma(2.0, ((1.0 / x) / x), fma(2.0, pow(x, -4.0), 2.0)) * pow(x, -3.0);
}
function code(x) return Float64(fma(2.0, Float64(Float64(1.0 / x) / x), fma(2.0, (x ^ -4.0), 2.0)) * (x ^ -3.0)) end
code[x_] := N[(N[(2.0 * N[(N[(1.0 / x), $MachinePrecision] / x), $MachinePrecision] + N[(2.0 * N[Power[x, -4.0], $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, \frac{\frac{1}{x}}{x}, \mathsf{fma}\left(2, {x}^{-4}, 2\right)\right) \cdot {x}^{-3}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around inf 99.2%
associate-+r+99.2%
+-commutative99.2%
associate-+l+99.2%
associate-*r/99.2%
metadata-eval99.2%
Simplified99.2%
div-inv99.2%
div-inv99.2%
fma-define99.2%
pow-flip99.2%
metadata-eval99.2%
+-commutative99.2%
div-inv99.2%
fma-define99.2%
pow-flip99.2%
metadata-eval99.2%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr100.0%
metadata-eval100.0%
pow-prod-up100.0%
inv-pow100.0%
inv-pow100.0%
Applied egg-rr100.0%
un-div-inv100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (/ (+ (/ 2.0 (pow x 2.0)) (+ 2.0 (/ 2.0 (pow x 4.0)))) (pow x 3.0)))
double code(double x) {
return ((2.0 / pow(x, 2.0)) + (2.0 + (2.0 / pow(x, 4.0)))) / pow(x, 3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((2.0d0 / (x ** 2.0d0)) + (2.0d0 + (2.0d0 / (x ** 4.0d0)))) / (x ** 3.0d0)
end function
public static double code(double x) {
return ((2.0 / Math.pow(x, 2.0)) + (2.0 + (2.0 / Math.pow(x, 4.0)))) / Math.pow(x, 3.0);
}
def code(x): return ((2.0 / math.pow(x, 2.0)) + (2.0 + (2.0 / math.pow(x, 4.0)))) / math.pow(x, 3.0)
function code(x) return Float64(Float64(Float64(2.0 / (x ^ 2.0)) + Float64(2.0 + Float64(2.0 / (x ^ 4.0)))) / (x ^ 3.0)) end
function tmp = code(x) tmp = ((2.0 / (x ^ 2.0)) + (2.0 + (2.0 / (x ^ 4.0)))) / (x ^ 3.0); end
code[x_] := N[(N[(N[(2.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 + N[(2.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{{x}^{2}} + \left(2 + \frac{2}{{x}^{4}}\right)}{{x}^{3}}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around inf 99.2%
associate-+r+99.2%
+-commutative99.2%
associate-+l+99.2%
associate-*r/99.2%
metadata-eval99.2%
Simplified99.2%
(FPCore (x) :precision binary64 (/ (+ 2.0 (/ 2.0 (pow x 2.0))) (pow x 3.0)))
double code(double x) {
return (2.0 + (2.0 / pow(x, 2.0))) / pow(x, 3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 + (2.0d0 / (x ** 2.0d0))) / (x ** 3.0d0)
end function
public static double code(double x) {
return (2.0 + (2.0 / Math.pow(x, 2.0))) / Math.pow(x, 3.0);
}
def code(x): return (2.0 + (2.0 / math.pow(x, 2.0))) / math.pow(x, 3.0)
function code(x) return Float64(Float64(2.0 + Float64(2.0 / (x ^ 2.0))) / (x ^ 3.0)) end
function tmp = code(x) tmp = (2.0 + (2.0 / (x ^ 2.0))) / (x ^ 3.0); end
code[x_] := N[(N[(2.0 + N[(2.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2 + \frac{2}{{x}^{2}}}{{x}^{3}}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around inf 99.1%
associate-*r/99.1%
metadata-eval99.1%
Simplified99.1%
(FPCore (x) :precision binary64 (/ (+ -4.0 (/ 4.0 x)) (* (pow x 3.0) (+ (/ 2.0 x) -2.0))))
double code(double x) {
return (-4.0 + (4.0 / x)) / (pow(x, 3.0) * ((2.0 / x) + -2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-4.0d0) + (4.0d0 / x)) / ((x ** 3.0d0) * ((2.0d0 / x) + (-2.0d0)))
end function
public static double code(double x) {
return (-4.0 + (4.0 / x)) / (Math.pow(x, 3.0) * ((2.0 / x) + -2.0));
}
def code(x): return (-4.0 + (4.0 / x)) / (math.pow(x, 3.0) * ((2.0 / x) + -2.0))
function code(x) return Float64(Float64(-4.0 + Float64(4.0 / x)) / Float64((x ^ 3.0) * Float64(Float64(2.0 / x) + -2.0))) end
function tmp = code(x) tmp = (-4.0 + (4.0 / x)) / ((x ^ 3.0) * ((2.0 / x) + -2.0)); end
code[x_] := N[(N[(-4.0 + N[(4.0 / x), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, 3.0], $MachinePrecision] * N[(N[(2.0 / x), $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-4 + \frac{4}{x}}{{x}^{3} \cdot \left(\frac{2}{x} + -2\right)}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
associate-+r-71.1%
flip--71.1%
inv-pow71.1%
inv-pow71.1%
pow-prod-up62.9%
metadata-eval62.9%
Applied egg-rr62.9%
Taylor expanded in x around inf 91.2%
sub-neg91.2%
associate-*r/91.2%
metadata-eval91.2%
metadata-eval91.2%
Simplified91.2%
*-un-lft-identity91.2%
associate-/l/91.2%
+-commutative91.2%
Applied egg-rr91.2%
Taylor expanded in x around inf 98.4%
sub-neg98.4%
associate-*r/98.4%
metadata-eval98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x) :precision binary64 (/ 2.0 (pow x 3.0)))
double code(double x) {
return 2.0 / pow(x, 3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (x ** 3.0d0)
end function
public static double code(double x) {
return 2.0 / Math.pow(x, 3.0);
}
def code(x): return 2.0 / math.pow(x, 3.0)
function code(x) return Float64(2.0 / (x ^ 3.0)) end
function tmp = code(x) tmp = 2.0 / (x ^ 3.0); end
code[x_] := N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{{x}^{3}}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around inf 98.4%
(FPCore (x) :precision binary64 (/ (/ 1.0 x) (* x (+ x -1.0))))
double code(double x) {
return (1.0 / x) / (x * (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) / (x * (x + (-1.0d0)))
end function
public static double code(double x) {
return (1.0 / x) / (x * (x + -1.0));
}
def code(x): return (1.0 / x) / (x * (x + -1.0))
function code(x) return Float64(Float64(1.0 / x) / Float64(x * Float64(x + -1.0))) end
function tmp = code(x) tmp = (1.0 / x) / (x * (x + -1.0)); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{x \cdot \left(x + -1\right)}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around inf 70.2%
associate-*r/70.2%
neg-mul-170.2%
distribute-neg-in70.2%
metadata-eval70.2%
distribute-neg-frac70.2%
metadata-eval70.2%
Simplified70.2%
frac-add70.3%
*-un-lft-identity70.3%
Applied egg-rr70.3%
Taylor expanded in x around 0 74.0%
Final simplification74.0%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ x -1.0)) (/ -1.0 x)))
double code(double x) {
return (1.0 / (x + -1.0)) + (-1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + (-1.0d0))) + ((-1.0d0) / x)
end function
public static double code(double x) {
return (1.0 / (x + -1.0)) + (-1.0 / x);
}
def code(x): return (1.0 / (x + -1.0)) + (-1.0 / x)
function code(x) return Float64(Float64(1.0 / Float64(x + -1.0)) + Float64(-1.0 / x)) end
function tmp = code(x) tmp = (1.0 / (x + -1.0)) + (-1.0 / x); end
code[x_] := N[(N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + -1} + \frac{-1}{x}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around inf 70.1%
(FPCore (x) :precision binary64 (/ -1.0 x))
double code(double x) {
return -1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) / x
end function
public static double code(double x) {
return -1.0 / x;
}
def code(x): return -1.0 / x
function code(x) return Float64(-1.0 / x) end
function tmp = code(x) tmp = -1.0 / x; end
code[x_] := N[(-1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around inf 70.1%
Taylor expanded in x around 0 5.3%
(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 71.1%
+-commutative71.1%
associate-+r-71.1%
sub-neg71.1%
remove-double-neg71.1%
neg-sub071.1%
associate-+l-71.1%
neg-sub071.1%
distribute-neg-frac271.1%
distribute-frac-neg271.1%
associate-+r+71.1%
+-commutative71.1%
remove-double-neg71.1%
distribute-neg-frac271.1%
sub0-neg71.1%
associate-+l-71.1%
neg-sub071.1%
Simplified71.1%
Taylor expanded in x around 0 5.3%
(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 2024089
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (> (fabs x) 1.0)
:alt
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))