
(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 (+ (pow x -3.0) (pow x -5.0))))
double code(double x) {
return 2.0 * (pow(x, -3.0) + pow(x, -5.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 * ((x ** (-3.0d0)) + (x ** (-5.0d0)))
end function
public static double code(double x) {
return 2.0 * (Math.pow(x, -3.0) + Math.pow(x, -5.0));
}
def code(x): return 2.0 * (math.pow(x, -3.0) + math.pow(x, -5.0))
function code(x) return Float64(2.0 * Float64((x ^ -3.0) + (x ^ -5.0))) end
function tmp = code(x) tmp = 2.0 * ((x ^ -3.0) + (x ^ -5.0)); end
code[x_] := N[(2.0 * N[(N[Power[x, -3.0], $MachinePrecision] + N[Power[x, -5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left({x}^{-3} + {x}^{-5}\right)
\end{array}
Initial program 62.9%
sub-neg62.9%
associate-+l+62.9%
+-commutative62.9%
Simplified6.0%
Taylor expanded in x around inf 98.8%
associate-*r/98.8%
metadata-eval98.8%
associate-*r/98.8%
metadata-eval98.8%
Simplified98.8%
expm1-log1p-u98.8%
expm1-udef63.1%
div-inv63.1%
pow-flip63.1%
metadata-eval63.1%
Applied egg-rr63.1%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef62.4%
fma-def62.4%
div-inv62.4%
pow-flip62.4%
metadata-eval62.4%
Applied egg-rr62.4%
expm1-def100.0%
expm1-log1p100.0%
fma-udef100.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (/ (/ -2.0 x) (* (- 1.0 x) (+ x 1.0))))
double code(double x) {
return (-2.0 / x) / ((1.0 - x) * (x + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / x) / ((1.0d0 - x) * (x + 1.0d0))
end function
public static double code(double x) {
return (-2.0 / x) / ((1.0 - x) * (x + 1.0));
}
def code(x): return (-2.0 / x) / ((1.0 - x) * (x + 1.0))
function code(x) return Float64(Float64(-2.0 / x) / Float64(Float64(1.0 - x) * Float64(x + 1.0))) end
function tmp = code(x) tmp = (-2.0 / x) / ((1.0 - x) * (x + 1.0)); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)}
\end{array}
Initial program 62.9%
sub-neg62.9%
associate-+l+62.9%
+-commutative62.9%
Simplified6.0%
reciprocal-undefine6.0%
frac-sub5.6%
*-rgt-identity5.6%
Applied egg-rr5.6%
+-commutative5.6%
reciprocal-undefine15.7%
associate-/r*63.0%
frac-add63.0%
*-un-lft-identity63.0%
+-commutative63.0%
+-commutative63.0%
Applied egg-rr63.0%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (- (reciprocal (+ x 1.0)) (reciprocal x)))
\begin{array}{l}
\\
\mathsf{reciprocal}\left(\left(x + 1\right)\right) - \mathsf{reciprocal}\left(x\right)
\end{array}
Initial program 62.9%
sub-neg62.9%
associate-+l+62.9%
+-commutative62.9%
Simplified6.0%
Taylor expanded in x around inf 6.0%
expm1-log1p-u6.0%
expm1-udef62.2%
sub-div62.2%
metadata-eval62.2%
+-commutative62.2%
Applied egg-rr62.2%
expm1-def6.0%
expm1-log1p6.0%
Simplified6.0%
div-inv6.0%
fma-def6.0%
reciprocal-define62.1%
Applied egg-rr62.1%
fma-udef62.1%
neg-mul-162.1%
+-commutative62.1%
sub-neg62.1%
+-commutative62.1%
Simplified62.1%
Final simplification62.1%
(FPCore (x) :precision binary64 (/ 4.0 x))
double code(double x) {
return 4.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 4.0d0 / x
end function
public static double code(double x) {
return 4.0 / x;
}
def code(x): return 4.0 / x
function code(x) return Float64(4.0 / x) end
function tmp = code(x) tmp = 4.0 / x; end
code[x_] := N[(4.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{x}
\end{array}
Initial program 62.9%
sub-neg62.9%
associate-+l+62.9%
+-commutative62.9%
Simplified6.0%
Taylor expanded in x around inf 6.1%
reciprocal-define6.0%
Simplified6.0%
Applied egg-rr6.1%
reciprocal-define6.1%
fma-udef6.1%
associate-*r/6.1%
metadata-eval6.1%
+-commutative6.1%
Simplified6.1%
Taylor expanded in x around inf 6.1%
Final simplification6.1%
(FPCore (x) :precision binary64 (- (reciprocal x)))
\begin{array}{l}
\\
-\mathsf{reciprocal}\left(x\right)
\end{array}
Initial program 62.9%
sub-neg62.9%
associate-+l+62.9%
+-commutative62.9%
Simplified6.0%
reciprocal-undefine6.0%
frac-sub5.6%
*-rgt-identity5.6%
Applied egg-rr5.6%
Taylor expanded in x around inf 15.1%
Taylor expanded in x around 0 4.8%
div-inv4.8%
distribute-lft1-in4.8%
metadata-eval4.8%
mul-1-neg4.8%
reciprocal-define4.8%
Applied egg-rr4.8%
Final simplification4.8%
(FPCore (x) :precision binary64 (reciprocal x))
\begin{array}{l}
\\
\mathsf{reciprocal}\left(x\right)
\end{array}
Initial program 62.9%
sub-neg62.9%
associate-+l+62.9%
+-commutative62.9%
Simplified6.0%
reciprocal-undefine6.0%
frac-sub5.6%
*-rgt-identity5.6%
Applied egg-rr5.6%
Taylor expanded in x around inf 15.1%
Taylor expanded in x around 0 4.8%
div-inv4.8%
distribute-lft1-in4.8%
metadata-eval4.8%
div-inv4.8%
add-sqr-sqrt2.4%
sqrt-unprod45.8%
frac-times48.4%
metadata-eval48.4%
metadata-eval48.4%
frac-times45.8%
sqrt-unprod3.0%
add-sqr-sqrt6.1%
*-un-lft-identity6.1%
*-commutative6.1%
reciprocal-define6.1%
Applied egg-rr6.1%
Final simplification6.1%
(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 2024024
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (> (fabs x) 1.0)
:herbie-target
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))