
(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 (* (/ (/ 1.0 x) (* (+ x -1.0) (- -1.0 x))) -2.0))
double code(double x) {
return ((1.0 / x) / ((x + -1.0) * (-1.0 - x))) * -2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / x) / ((x + (-1.0d0)) * ((-1.0d0) - x))) * (-2.0d0)
end function
public static double code(double x) {
return ((1.0 / x) / ((x + -1.0) * (-1.0 - x))) * -2.0;
}
def code(x): return ((1.0 / x) / ((x + -1.0) * (-1.0 - x))) * -2.0
function code(x) return Float64(Float64(Float64(1.0 / x) / Float64(Float64(x + -1.0) * Float64(-1.0 - x))) * -2.0) end
function tmp = code(x) tmp = ((1.0 / x) / ((x + -1.0) * (-1.0 - x))) * -2.0; end
code[x_] := N[(N[(N[(1.0 / x), $MachinePrecision] / N[(N[(x + -1.0), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{\left(x + -1\right) \cdot \left(-1 - x\right)} \cdot -2
\end{array}
Initial program 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
+-commutative66.0%
frac-sub17.2%
frac-add19.5%
fma-define18.7%
*-rgt-identity18.7%
fma-neg18.7%
Applied egg-rr18.7%
Taylor expanded in x around 0 99.4%
clear-num99.4%
associate-/r/99.4%
associate-*l*99.4%
associate-/r*99.9%
*-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (* (/ (/ -2.0 x) (- -1.0 x)) (/ 1.0 (+ x -1.0))))
double code(double x) {
return ((-2.0 / x) / (-1.0 - x)) * (1.0 / (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((-2.0d0) / x) / ((-1.0d0) - x)) * (1.0d0 / (x + (-1.0d0)))
end function
public static double code(double x) {
return ((-2.0 / x) / (-1.0 - x)) * (1.0 / (x + -1.0));
}
def code(x): return ((-2.0 / x) / (-1.0 - x)) * (1.0 / (x + -1.0))
function code(x) return Float64(Float64(Float64(-2.0 / x) / Float64(-1.0 - x)) * Float64(1.0 / Float64(x + -1.0))) end
function tmp = code(x) tmp = ((-2.0 / x) / (-1.0 - x)) * (1.0 / (x + -1.0)); end
code[x_] := N[(N[(N[(-2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{x}}{-1 - x} \cdot \frac{1}{x + -1}
\end{array}
Initial program 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
+-commutative66.0%
frac-sub17.2%
frac-add19.5%
fma-define18.7%
*-rgt-identity18.7%
fma-neg18.7%
Applied egg-rr18.7%
Taylor expanded in x around 0 99.4%
associate-/r*99.8%
div-inv99.8%
associate-/r*99.7%
Applied egg-rr99.7%
Final simplification99.7%
(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 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
+-commutative66.0%
frac-sub17.2%
frac-add19.5%
fma-define18.7%
*-rgt-identity18.7%
fma-neg18.7%
Applied egg-rr18.7%
Taylor expanded in x around 0 99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (/ 2.0 (* (- -1.0 x) (* x (- 1.0 x)))))
double code(double x) {
return 2.0 / ((-1.0 - x) * (x * (1.0 - x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (((-1.0d0) - x) * (x * (1.0d0 - x)))
end function
public static double code(double x) {
return 2.0 / ((-1.0 - x) * (x * (1.0 - x)));
}
def code(x): return 2.0 / ((-1.0 - x) * (x * (1.0 - x)))
function code(x) return Float64(2.0 / Float64(Float64(-1.0 - x) * Float64(x * Float64(1.0 - x)))) end
function tmp = code(x) tmp = 2.0 / ((-1.0 - x) * (x * (1.0 - x))); end
code[x_] := N[(2.0 / N[(N[(-1.0 - x), $MachinePrecision] * N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(-1 - x\right) \cdot \left(x \cdot \left(1 - x\right)\right)}
\end{array}
Initial program 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
+-commutative66.0%
frac-sub17.2%
frac-add19.5%
fma-define18.7%
*-rgt-identity18.7%
fma-neg18.7%
Applied egg-rr18.7%
Taylor expanded in x around 0 99.4%
frac-2neg99.4%
metadata-eval99.4%
div-inv99.4%
*-commutative99.4%
distribute-lft-neg-in99.4%
+-commutative99.4%
distribute-neg-in99.4%
metadata-eval99.4%
sub-neg99.4%
Applied egg-rr99.4%
associate-*r/99.4%
metadata-eval99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
(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 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
Taylor expanded in x around inf 64.6%
Final simplification64.6%
(FPCore (x) :precision binary64 (/ -2.0 (* x (- (- -1.0) x))))
double code(double x) {
return -2.0 / (x * (-(-1.0) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / (x * (-(-1.0d0) - x))
end function
public static double code(double x) {
return -2.0 / (x * (-(-1.0) - x));
}
def code(x): return -2.0 / (x * (-(-1.0) - x))
function code(x) return Float64(-2.0 / Float64(x * Float64(Float64(-(-1.0)) - x))) end
function tmp = code(x) tmp = -2.0 / (x * (-(-1.0) - x)); end
code[x_] := N[(-2.0 / N[(x * N[((--1.0) - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x \cdot \left(\left(--1\right) - x\right)}
\end{array}
Initial program 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
+-commutative66.0%
frac-sub17.2%
frac-add19.5%
fma-define18.7%
*-rgt-identity18.7%
fma-neg18.7%
Applied egg-rr18.7%
Taylor expanded in x around 0 99.4%
Taylor expanded in x around 0 50.1%
mul-1-neg50.1%
Simplified50.1%
Final simplification50.1%
(FPCore (x) :precision binary64 (/ 1.0 (* x (- 1.0 x))))
double code(double x) {
return 1.0 / (x * (1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * (1.0d0 - x))
end function
public static double code(double x) {
return 1.0 / (x * (1.0 - x));
}
def code(x): return 1.0 / (x * (1.0 - x))
function code(x) return Float64(1.0 / Float64(x * Float64(1.0 - x))) end
function tmp = code(x) tmp = 1.0 / (x * (1.0 - x)); end
code[x_] := N[(1.0 / N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(1 - x\right)}
\end{array}
Initial program 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
Taylor expanded in x around inf 64.6%
frac-2neg64.6%
metadata-eval64.6%
frac-2neg64.6%
metadata-eval64.6%
frac-add64.6%
add-sqr-sqrt26.2%
sqrt-unprod10.9%
sqr-neg10.9%
sqrt-prod27.0%
add-sqr-sqrt48.1%
neg-mul-148.1%
add-sqr-sqrt21.1%
sqrt-unprod8.5%
sqr-neg8.5%
sqrt-prod30.0%
add-sqr-sqrt64.6%
add-sqr-sqrt30.4%
sqrt-unprod64.4%
sqr-neg64.4%
sqrt-prod34.0%
add-sqr-sqrt64.8%
Applied egg-rr64.8%
*-rgt-identity64.8%
sub-neg64.8%
associate--r+50.1%
+-inverses50.1%
metadata-eval50.1%
*-commutative50.1%
distribute-rgt-neg-in50.1%
neg-mul-150.1%
*-commutative50.1%
associate-*l*50.1%
*-commutative50.1%
neg-mul-150.1%
neg-sub050.1%
+-commutative50.1%
associate--r+50.1%
metadata-eval50.1%
Simplified50.1%
Final simplification50.1%
(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 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
Taylor expanded in x around 0 4.9%
Final simplification4.9%
(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 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
Taylor expanded in x around inf 64.6%
Taylor expanded in x around 0 4.9%
Final simplification4.9%
(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 66.0%
+-commutative66.0%
associate-+r-65.9%
sub-neg65.9%
remove-double-neg65.9%
neg-sub065.9%
associate-+l-65.9%
neg-sub065.9%
distribute-neg-frac265.9%
distribute-frac-neg265.9%
associate-+r+66.0%
+-commutative66.0%
remove-double-neg66.0%
distribute-neg-frac266.0%
sub0-neg66.0%
associate-+l-66.0%
neg-sub066.0%
Simplified66.0%
Taylor expanded in x around inf 64.6%
frac-2neg64.6%
metadata-eval64.6%
frac-2neg64.6%
metadata-eval64.6%
frac-add64.6%
add-sqr-sqrt26.2%
sqrt-unprod10.9%
sqr-neg10.9%
sqrt-prod27.0%
add-sqr-sqrt48.1%
neg-mul-148.1%
add-sqr-sqrt21.1%
sqrt-unprod8.5%
sqr-neg8.5%
sqrt-prod30.0%
add-sqr-sqrt64.6%
add-sqr-sqrt30.4%
sqrt-unprod64.4%
sqr-neg64.4%
sqrt-prod34.0%
add-sqr-sqrt64.8%
Applied egg-rr64.8%
*-rgt-identity64.8%
sub-neg64.8%
associate--r+50.1%
+-inverses50.1%
metadata-eval50.1%
*-commutative50.1%
distribute-rgt-neg-in50.1%
neg-mul-150.1%
*-commutative50.1%
associate-*l*50.1%
*-commutative50.1%
neg-mul-150.1%
neg-sub050.1%
+-commutative50.1%
associate--r+50.1%
metadata-eval50.1%
Simplified50.1%
Taylor expanded in x around 0 6.3%
Final simplification6.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 2024073
(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))))