
(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 12 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 (* 2.0 (+ (pow x -4.0) (pow x -2.0)))) (pow x -3.0)))
double code(double x) {
return (2.0 + (2.0 * (pow(x, -4.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 ** (-4.0d0)) + (x ** (-2.0d0))))) * (x ** (-3.0d0))
end function
public static double code(double x) {
return (2.0 + (2.0 * (Math.pow(x, -4.0) + Math.pow(x, -2.0)))) * Math.pow(x, -3.0);
}
def code(x): return (2.0 + (2.0 * (math.pow(x, -4.0) + math.pow(x, -2.0)))) * math.pow(x, -3.0)
function code(x) return Float64(Float64(2.0 + Float64(2.0 * Float64((x ^ -4.0) + (x ^ -2.0)))) * (x ^ -3.0)) end
function tmp = code(x) tmp = (2.0 + (2.0 * ((x ^ -4.0) + (x ^ -2.0)))) * (x ^ -3.0); end
code[x_] := N[(N[(2.0 + N[(2.0 * N[(N[Power[x, -4.0], $MachinePrecision] + N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(2 + 2 \cdot \left({x}^{-4} + {x}^{-2}\right)\right) \cdot {x}^{-3}
\end{array}
Initial program 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around inf 98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
div-inv98.5%
+-commutative98.5%
div-inv98.5%
fma-define98.5%
pow-flip98.5%
metadata-eval98.5%
div-inv98.5%
pow-flip98.5%
metadata-eval98.5%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
fma-undefine99.8%
distribute-lft-out99.8%
Simplified99.8%
(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}
\\
2 \cdot {x}^{-3}
\end{array}
Initial program 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around inf 98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
div-inv98.5%
+-commutative98.5%
div-inv98.5%
fma-define98.5%
pow-flip98.5%
metadata-eval98.5%
div-inv98.5%
pow-flip98.5%
metadata-eval98.5%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
fma-undefine99.8%
distribute-lft-out99.8%
Simplified99.8%
Taylor expanded in x around inf 99.2%
(FPCore (x) :precision binary64 (- (/ -2.0 x) (* (/ 2.0 (- -1.0 x)) (/ x (+ x -1.0)))))
double code(double x) {
return (-2.0 / x) - ((2.0 / (-1.0 - x)) * (x / (x + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / x) - ((2.0d0 / ((-1.0d0) - x)) * (x / (x + (-1.0d0))))
end function
public static double code(double x) {
return (-2.0 / x) - ((2.0 / (-1.0 - x)) * (x / (x + -1.0)));
}
def code(x): return (-2.0 / x) - ((2.0 / (-1.0 - x)) * (x / (x + -1.0)))
function code(x) return Float64(Float64(-2.0 / x) - Float64(Float64(2.0 / Float64(-1.0 - x)) * Float64(x / Float64(x + -1.0)))) end
function tmp = code(x) tmp = (-2.0 / x) - ((2.0 / (-1.0 - x)) * (x / (x + -1.0))); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] - N[(N[(2.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] * N[(x / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x} - \frac{2}{-1 - x} \cdot \frac{x}{x + -1}
\end{array}
Initial program 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
+-commutative79.1%
associate-+l-79.0%
Applied egg-rr79.0%
frac-sub23.9%
*-un-lft-identity23.9%
Applied egg-rr23.9%
*-rgt-identity23.9%
associate--l+23.9%
sub-neg23.9%
associate--r+23.9%
metadata-eval23.9%
neg-sub023.9%
remove-double-neg23.9%
*-commutative23.9%
Simplified23.9%
count-223.9%
*-commutative23.9%
times-frac79.0%
Applied egg-rr79.0%
(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}
Initial program 79.1%
Final simplification79.1%
(FPCore (x) :precision binary64 (+ (/ (+ 1.0 (/ 1.0 x)) x) (/ -1.0 x)))
double code(double x) {
return ((1.0 + (1.0 / x)) / x) + (-1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 + (1.0d0 / x)) / x) + ((-1.0d0) / x)
end function
public static double code(double x) {
return ((1.0 + (1.0 / x)) / x) + (-1.0 / x);
}
def code(x): return ((1.0 + (1.0 / x)) / x) + (-1.0 / x)
function code(x) return Float64(Float64(Float64(1.0 + Float64(1.0 / x)) / x) + Float64(-1.0 / x)) end
function tmp = code(x) tmp = ((1.0 + (1.0 / x)) / x) + (-1.0 / x); end
code[x_] := N[(N[(N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 + \frac{1}{x}}{x} + \frac{-1}{x}
\end{array}
Initial program 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around inf 78.0%
Taylor expanded in x around inf 78.0%
(FPCore (x) :precision binary64 (+ (/ -1.0 x) (/ 1.0 (+ x -1.0))))
double code(double x) {
return (-1.0 / x) + (1.0 / (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) + (1.0d0 / (x + (-1.0d0)))
end function
public static double code(double x) {
return (-1.0 / x) + (1.0 / (x + -1.0));
}
def code(x): return (-1.0 / x) + (1.0 / (x + -1.0))
function code(x) return Float64(Float64(-1.0 / x) + Float64(1.0 / Float64(x + -1.0))) end
function tmp = code(x) tmp = (-1.0 / x) + (1.0 / (x + -1.0)); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x} + \frac{1}{x + -1}
\end{array}
Initial program 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around inf 78.0%
Final simplification78.0%
(FPCore (x) :precision binary64 (+ 1.0 (+ -1.0 (/ 1.0 x))))
double code(double x) {
return 1.0 + (-1.0 + (1.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + ((-1.0d0) + (1.0d0 / x))
end function
public static double code(double x) {
return 1.0 + (-1.0 + (1.0 / x));
}
def code(x): return 1.0 + (-1.0 + (1.0 / x))
function code(x) return Float64(1.0 + Float64(-1.0 + Float64(1.0 / x))) end
function tmp = code(x) tmp = 1.0 + (-1.0 + (1.0 / x)); end
code[x_] := N[(1.0 + N[(-1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(-1 + \frac{1}{x}\right)
\end{array}
Initial program 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around inf 78.0%
Taylor expanded in x around 0 5.4%
add-sqr-sqrt2.7%
sqrt-unprod53.3%
frac-times55.1%
metadata-eval55.1%
metadata-eval55.1%
frac-times53.3%
sqrt-prod3.0%
expm1-log1p-u3.0%
add-sqr-sqrt6.1%
log1p-define78.1%
expm1-undefine78.1%
add-exp-log78.1%
Applied egg-rr78.1%
associate--l+78.1%
sub-neg78.1%
metadata-eval78.1%
Simplified78.1%
Final simplification78.1%
(FPCore (x) :precision binary64 (+ -1.0 (/ (- x 2.0) x)))
double code(double x) {
return -1.0 + ((x - 2.0) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + ((x - 2.0d0) / x)
end function
public static double code(double x) {
return -1.0 + ((x - 2.0) / x);
}
def code(x): return -1.0 + ((x - 2.0) / x)
function code(x) return Float64(-1.0 + Float64(Float64(x - 2.0) / x)) end
function tmp = code(x) tmp = -1.0 + ((x - 2.0) / x); end
code[x_] := N[(-1.0 + N[(N[(x - 2.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \frac{x - 2}{x}
\end{array}
Initial program 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around 0 3.2%
Taylor expanded in x around 0 77.8%
(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 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
+-commutative79.1%
associate-+l-79.0%
Applied egg-rr79.0%
Taylor expanded in x around inf 78.0%
associate--r-78.0%
sub-div78.0%
metadata-eval78.0%
+-commutative78.0%
add-sqr-sqrt22.9%
sqrt-unprod20.8%
frac-times17.8%
metadata-eval17.8%
metadata-eval17.8%
frac-times20.8%
sqrt-prod3.0%
add-sqr-sqrt6.1%
Applied egg-rr6.1%
Taylor expanded in x around 0 6.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 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around inf 78.0%
Taylor expanded in x around 0 5.4%
(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 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around 0 5.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 79.1%
+-commutative79.1%
associate-+r-79.0%
sub-neg79.0%
remove-double-neg79.0%
neg-sub079.0%
associate-+l-79.0%
neg-sub079.0%
distribute-neg-frac279.0%
distribute-frac-neg279.0%
associate-+r+79.1%
+-commutative79.1%
remove-double-neg79.1%
distribute-neg-frac279.1%
sub0-neg79.1%
associate-+l-79.1%
neg-sub079.1%
Simplified79.1%
Taylor expanded in x around 0 3.2%
Taylor expanded in x around inf 3.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 2024143
(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))))