
(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 6 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 (/ (/ 2.0 x) (* (- -1.0 x) (- 1.0 x))))
double code(double x) {
return (2.0 / x) / ((-1.0 - x) * (1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / x) / (((-1.0d0) - x) * (1.0d0 - x))
end function
public static double code(double x) {
return (2.0 / x) / ((-1.0 - x) * (1.0 - x));
}
def code(x): return (2.0 / x) / ((-1.0 - x) * (1.0 - x))
function code(x) return Float64(Float64(2.0 / x) / Float64(Float64(-1.0 - x) * Float64(1.0 - x))) end
function tmp = code(x) tmp = (2.0 / x) / ((-1.0 - x) * (1.0 - x)); end
code[x_] := N[(N[(2.0 / x), $MachinePrecision] / N[(N[(-1.0 - x), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x}}{\left(-1 - x\right) \cdot \left(1 - x\right)}
\end{array}
Initial program 68.3%
+-commutative68.3%
associate-+r-68.2%
sub-neg68.2%
remove-double-neg68.2%
neg-sub068.2%
associate-+l-68.2%
neg-sub068.2%
distribute-neg-frac268.2%
distribute-frac-neg268.2%
associate-+r+68.3%
+-commutative68.3%
remove-double-neg68.3%
distribute-neg-frac268.3%
sub0-neg68.3%
associate-+l-68.3%
neg-sub068.3%
Simplified68.3%
frac-2neg68.3%
frac-2neg68.3%
metadata-eval68.3%
frac-sub19.7%
metadata-eval19.7%
sub-neg19.7%
distribute-neg-in19.7%
metadata-eval19.7%
neg-mul-119.7%
*-commutative19.7%
sub-neg19.7%
*-commutative19.7%
neg-mul-119.7%
sub-neg19.7%
distribute-neg-in19.7%
metadata-eval19.7%
neg-mul-119.7%
*-commutative19.7%
sub-neg19.7%
*-commutative19.7%
Applied egg-rr19.7%
sub-neg19.7%
remove-double-neg19.7%
distribute-lft-in19.7%
metadata-eval19.7%
*-commutative19.7%
neg-mul-119.7%
remove-double-neg19.7%
sub-neg19.7%
remove-double-neg19.7%
distribute-lft-in19.7%
*-rgt-identity19.7%
neg-mul-119.7%
distribute-rgt-in19.7%
sub-neg19.7%
Simplified19.7%
Taylor expanded in x around 0 19.7%
+-commutative19.7%
associate-/r*68.3%
frac-2neg68.3%
metadata-eval68.3%
frac-add68.3%
Applied egg-rr68.3%
*-commutative68.3%
*-commutative68.3%
mul-1-neg68.3%
unsub-neg68.3%
*-commutative68.3%
associate-*l/19.9%
associate-/l*68.3%
distribute-neg-in68.3%
metadata-eval68.3%
+-commutative68.3%
unsub-neg68.3%
distribute-neg-in68.3%
metadata-eval68.3%
+-commutative68.3%
unsub-neg68.3%
Simplified68.3%
Taylor expanded in x around 0 99.8%
(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 68.3%
+-commutative68.3%
associate-+r-68.2%
sub-neg68.2%
remove-double-neg68.2%
neg-sub068.2%
associate-+l-68.2%
neg-sub068.2%
distribute-neg-frac268.2%
distribute-frac-neg268.2%
associate-+r+68.3%
+-commutative68.3%
remove-double-neg68.3%
distribute-neg-frac268.3%
sub0-neg68.3%
associate-+l-68.3%
neg-sub068.3%
Simplified68.3%
Taylor expanded in x around inf 66.0%
(FPCore (x) :precision binary64 (/ (+ 1.0 (/ -1.0 x)) x))
double code(double x) {
return (1.0 + (-1.0 / x)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + ((-1.0d0) / x)) / x
end function
public static double code(double x) {
return (1.0 + (-1.0 / x)) / x;
}
def code(x): return (1.0 + (-1.0 / x)) / x
function code(x) return Float64(Float64(1.0 + Float64(-1.0 / x)) / x) end
function tmp = code(x) tmp = (1.0 + (-1.0 / x)) / x; end
code[x_] := N[(N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 + \frac{-1}{x}}{x}
\end{array}
Initial program 68.3%
+-commutative68.3%
associate-+r-68.2%
sub-neg68.2%
remove-double-neg68.2%
neg-sub068.2%
associate-+l-68.2%
neg-sub068.2%
distribute-neg-frac268.2%
distribute-frac-neg268.2%
associate-+r+68.3%
+-commutative68.3%
remove-double-neg68.3%
distribute-neg-frac268.3%
sub0-neg68.3%
associate-+l-68.3%
neg-sub068.3%
Simplified68.3%
frac-sub19.7%
associate-/r*68.3%
*-rgt-identity68.3%
fma-neg68.3%
Applied egg-rr68.3%
Taylor expanded in x around 0 6.3%
Taylor expanded in x around inf 6.3%
Final simplification6.3%
(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 68.3%
+-commutative68.3%
associate-+r-68.2%
sub-neg68.2%
remove-double-neg68.2%
neg-sub068.2%
associate-+l-68.2%
neg-sub068.2%
distribute-neg-frac268.2%
distribute-frac-neg268.2%
associate-+r+68.3%
+-commutative68.3%
remove-double-neg68.3%
distribute-neg-frac268.3%
sub0-neg68.3%
associate-+l-68.3%
neg-sub068.3%
Simplified68.3%
frac-sub19.7%
associate-/r*68.3%
*-rgt-identity68.3%
fma-neg68.3%
Applied egg-rr68.3%
Taylor expanded in x around 0 6.3%
Taylor expanded in x around inf 6.3%
(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 68.3%
+-commutative68.3%
associate-+r-68.2%
sub-neg68.2%
remove-double-neg68.2%
neg-sub068.2%
associate-+l-68.2%
neg-sub068.2%
distribute-neg-frac268.2%
distribute-frac-neg268.2%
associate-+r+68.3%
+-commutative68.3%
remove-double-neg68.3%
distribute-neg-frac268.3%
sub0-neg68.3%
associate-+l-68.3%
neg-sub068.3%
Simplified68.3%
Taylor expanded in x around inf 66.4%
associate-*r/66.4%
neg-mul-166.4%
distribute-neg-in66.4%
metadata-eval66.4%
distribute-neg-frac66.4%
metadata-eval66.4%
Simplified66.4%
Taylor expanded in x around 0 48.9%
sub-neg48.9%
neg-mul-148.9%
metadata-eval48.9%
+-commutative48.9%
sub-neg48.9%
unpow248.9%
associate-/r*4.9%
sub-neg4.9%
+-commutative4.9%
metadata-eval4.9%
neg-mul-14.9%
sub-neg4.9%
div-sub4.9%
associate-/l*4.9%
*-inverses4.9%
metadata-eval4.9%
Simplified4.9%
Taylor expanded in x around inf 4.9%
(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 68.3%
+-commutative68.3%
associate-+r-68.2%
sub-neg68.2%
remove-double-neg68.2%
neg-sub068.2%
associate-+l-68.2%
neg-sub068.2%
distribute-neg-frac268.2%
distribute-frac-neg268.2%
associate-+r+68.3%
+-commutative68.3%
remove-double-neg68.3%
distribute-neg-frac268.3%
sub0-neg68.3%
associate-+l-68.3%
neg-sub068.3%
Simplified68.3%
Taylor expanded in x around 0 4.9%
(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 2024121
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (> (fabs x) 1.0)
:alt
(! :herbie-platform default (/ 2 (* x (- (* x x) 1))))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))