
(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 7 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 (pow x 5.0)) (/ 2.0 (pow x 7.0))) (+ (* 2.0 (pow x -3.0)) (/ 2.0 (pow x 9.0)))))
double code(double x) {
return ((2.0 / pow(x, 5.0)) + (2.0 / pow(x, 7.0))) + ((2.0 * pow(x, -3.0)) + (2.0 / pow(x, 9.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((2.0d0 / (x ** 5.0d0)) + (2.0d0 / (x ** 7.0d0))) + ((2.0d0 * (x ** (-3.0d0))) + (2.0d0 / (x ** 9.0d0)))
end function
public static double code(double x) {
return ((2.0 / Math.pow(x, 5.0)) + (2.0 / Math.pow(x, 7.0))) + ((2.0 * Math.pow(x, -3.0)) + (2.0 / Math.pow(x, 9.0)));
}
def code(x): return ((2.0 / math.pow(x, 5.0)) + (2.0 / math.pow(x, 7.0))) + ((2.0 * math.pow(x, -3.0)) + (2.0 / math.pow(x, 9.0)))
function code(x) return Float64(Float64(Float64(2.0 / (x ^ 5.0)) + Float64(2.0 / (x ^ 7.0))) + Float64(Float64(2.0 * (x ^ -3.0)) + Float64(2.0 / (x ^ 9.0)))) end
function tmp = code(x) tmp = ((2.0 / (x ^ 5.0)) + (2.0 / (x ^ 7.0))) + ((2.0 * (x ^ -3.0)) + (2.0 / (x ^ 9.0))); end
code[x_] := N[(N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 9.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{7}}\right) + \left(2 \cdot {x}^{-3} + \frac{2}{{x}^{9}}\right)
\end{array}
Initial program 68.2%
+-commutative68.2%
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.2%
+-commutative68.2%
remove-double-neg68.2%
distribute-neg-frac268.2%
sub0-neg68.2%
associate-+l-68.2%
neg-sub068.2%
Simplified68.2%
Taylor expanded in x around inf 99.5%
associate-+r+99.5%
associate-*r/99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
+-commutative99.5%
associate-*r/99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
div-inv99.5%
pow-flip99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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(-2.0 / Float64(Float64(x + -1.0) * Float64(x * Float64(-1.0 - x)))) end
function tmp = code(x) tmp = -2.0 / ((x + -1.0) * (x * (-1.0 - x))); end
code[x_] := N[(-2.0 / N[(N[(x + -1.0), $MachinePrecision] * N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(x + -1\right) \cdot \left(x \cdot \left(-1 - x\right)\right)}
\end{array}
Initial program 68.2%
+-commutative68.2%
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.2%
+-commutative68.2%
remove-double-neg68.2%
distribute-neg-frac268.2%
sub0-neg68.2%
associate-+l-68.2%
neg-sub068.2%
Simplified68.2%
frac-sub17.9%
frac-add17.7%
*-un-lft-identity17.7%
fma-define16.3%
*-rgt-identity16.3%
fma-neg16.3%
Applied egg-rr16.3%
Simplified17.7%
Taylor expanded in x around 0 99.6%
Final simplification99.6%
(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.2%
+-commutative68.2%
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.2%
+-commutative68.2%
remove-double-neg68.2%
distribute-neg-frac268.2%
sub0-neg68.2%
associate-+l-68.2%
neg-sub068.2%
Simplified68.2%
frac-sub17.9%
frac-add17.7%
*-un-lft-identity17.7%
fma-define16.3%
*-rgt-identity16.3%
fma-neg16.3%
Applied egg-rr16.3%
Simplified17.7%
Taylor expanded in x around 0 99.6%
div-inv99.6%
*-commutative99.6%
associate-*l*99.6%
Applied egg-rr99.6%
associate-*r/99.6%
metadata-eval99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
distribute-neg-frac299.6%
distribute-rgt-neg-in99.6%
associate-/r*99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
distribute-neg-in99.8%
metadata-eval99.8%
sub-neg99.8%
Simplified99.8%
Final simplification99.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.2%
+-commutative68.2%
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.2%
+-commutative68.2%
remove-double-neg68.2%
distribute-neg-frac268.2%
sub0-neg68.2%
associate-+l-68.2%
neg-sub068.2%
Simplified68.2%
Taylor expanded in x around inf 66.8%
Final simplification66.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 68.2%
+-commutative68.2%
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.2%
+-commutative68.2%
remove-double-neg68.2%
distribute-neg-frac268.2%
sub0-neg68.2%
associate-+l-68.2%
neg-sub068.2%
Simplified68.2%
Taylor expanded in x around 0 5.1%
Final simplification5.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 68.2%
+-commutative68.2%
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.2%
+-commutative68.2%
remove-double-neg68.2%
distribute-neg-frac268.2%
sub0-neg68.2%
associate-+l-68.2%
neg-sub068.2%
Simplified68.2%
Taylor expanded in x around inf 66.8%
Taylor expanded in x around 0 5.1%
Final simplification5.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 68.2%
+-commutative68.2%
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.2%
+-commutative68.2%
remove-double-neg68.2%
distribute-neg-frac268.2%
sub0-neg68.2%
associate-+l-68.2%
neg-sub068.2%
Simplified68.2%
Taylor expanded in x around 0 3.5%
associate-*r/3.5%
metadata-eval3.5%
Simplified3.5%
Taylor expanded in x around inf 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 2024043
(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))))