
(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 5 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(Float64(2.0 / Float64(x + -1.0)) / Float64(x + 1.0)) / x) end
function tmp = code(x) tmp = ((2.0 / (x + -1.0)) / (x + 1.0)) / x; end
code[x_] := N[(N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{2}{x + -1}}{x + 1}}{x}
\end{array}
Initial program 10.7%
sub-neg10.7%
distribute-neg-frac10.7%
metadata-eval10.7%
metadata-eval10.7%
metadata-eval10.7%
associate-/r*10.7%
metadata-eval10.7%
neg-mul-110.7%
+-commutative10.7%
associate-+l+10.6%
+-commutative10.6%
neg-mul-110.6%
metadata-eval10.6%
associate-/r*10.6%
metadata-eval10.6%
metadata-eval10.6%
+-commutative10.6%
+-commutative10.6%
Simplified10.6%
frac-2neg10.6%
metadata-eval10.6%
frac-add10.2%
*-un-lft-identity10.2%
*-commutative10.2%
+-commutative10.2%
*-un-lft-identity10.2%
+-commutative10.2%
Applied egg-rr10.2%
associate-/r*10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
associate-/r*10.2%
associate-+l+10.2%
+-commutative10.2%
associate-+r+10.2%
metadata-eval10.2%
Simplified10.2%
+-commutative10.2%
clear-num10.3%
frac-add10.3%
*-un-lft-identity10.3%
+-lft-identity10.3%
+-lft-identity10.3%
Applied egg-rr10.3%
Taylor expanded in x around 0 99.5%
expm1-log1p-u99.5%
expm1-udef8.8%
Applied egg-rr8.8%
expm1-def99.2%
expm1-log1p99.2%
associate-*r/99.2%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 2.0 (* x (* (+ x -1.0) (+ x 1.0)))))
double code(double x) {
return 2.0 / (x * ((x + -1.0) * (x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (x * ((x + (-1.0d0)) * (x + 1.0d0)))
end function
public static double code(double x) {
return 2.0 / (x * ((x + -1.0) * (x + 1.0)));
}
def code(x): return 2.0 / (x * ((x + -1.0) * (x + 1.0)))
function code(x) return Float64(2.0 / Float64(x * Float64(Float64(x + -1.0) * Float64(x + 1.0)))) end
function tmp = code(x) tmp = 2.0 / (x * ((x + -1.0) * (x + 1.0))); end
code[x_] := N[(2.0 / N[(x * N[(N[(x + -1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x \cdot \left(\left(x + -1\right) \cdot \left(x + 1\right)\right)}
\end{array}
Initial program 10.7%
sub-neg10.7%
distribute-neg-frac10.7%
metadata-eval10.7%
metadata-eval10.7%
metadata-eval10.7%
associate-/r*10.7%
metadata-eval10.7%
neg-mul-110.7%
+-commutative10.7%
associate-+l+10.6%
+-commutative10.6%
neg-mul-110.6%
metadata-eval10.6%
associate-/r*10.6%
metadata-eval10.6%
metadata-eval10.6%
+-commutative10.6%
+-commutative10.6%
Simplified10.6%
frac-2neg10.6%
metadata-eval10.6%
frac-add10.2%
*-un-lft-identity10.2%
*-commutative10.2%
+-commutative10.2%
*-un-lft-identity10.2%
+-commutative10.2%
Applied egg-rr10.2%
associate-/r*10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
associate-/r*10.2%
associate-+l+10.2%
+-commutative10.2%
associate-+r+10.2%
metadata-eval10.2%
Simplified10.2%
+-commutative10.2%
frac-add13.8%
+-lft-identity13.8%
Applied egg-rr13.8%
Taylor expanded in x around 0 99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (/ (/ 1.0 x) (* x (* x 0.5))))
double code(double x) {
return (1.0 / x) / (x * (x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) / (x * (x * 0.5d0))
end function
public static double code(double x) {
return (1.0 / x) / (x * (x * 0.5));
}
def code(x): return (1.0 / x) / (x * (x * 0.5))
function code(x) return Float64(Float64(1.0 / x) / Float64(x * Float64(x * 0.5))) end
function tmp = code(x) tmp = (1.0 / x) / (x * (x * 0.5)); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{x \cdot \left(x \cdot 0.5\right)}
\end{array}
Initial program 10.7%
sub-neg10.7%
distribute-neg-frac10.7%
metadata-eval10.7%
metadata-eval10.7%
metadata-eval10.7%
associate-/r*10.7%
metadata-eval10.7%
neg-mul-110.7%
+-commutative10.7%
associate-+l+10.6%
+-commutative10.6%
neg-mul-110.6%
metadata-eval10.6%
associate-/r*10.6%
metadata-eval10.6%
metadata-eval10.6%
+-commutative10.6%
+-commutative10.6%
Simplified10.6%
frac-2neg10.6%
metadata-eval10.6%
frac-add10.2%
*-un-lft-identity10.2%
*-commutative10.2%
+-commutative10.2%
*-un-lft-identity10.2%
+-commutative10.2%
Applied egg-rr10.2%
associate-/r*10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
associate-/r*10.2%
associate-+l+10.2%
+-commutative10.2%
associate-+r+10.2%
metadata-eval10.2%
Simplified10.2%
+-commutative10.2%
clear-num10.3%
frac-add10.3%
*-un-lft-identity10.3%
+-lft-identity10.3%
+-lft-identity10.3%
Applied egg-rr10.3%
Taylor expanded in x around 0 99.5%
Taylor expanded in x around inf 95.8%
*-commutative95.8%
Simplified95.8%
Final simplification95.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 10.7%
sub-neg10.7%
distribute-neg-frac10.7%
metadata-eval10.7%
metadata-eval10.7%
metadata-eval10.7%
associate-/r*10.7%
metadata-eval10.7%
neg-mul-110.7%
+-commutative10.7%
associate-+l+10.6%
+-commutative10.6%
neg-mul-110.6%
metadata-eval10.6%
associate-/r*10.6%
metadata-eval10.6%
metadata-eval10.6%
+-commutative10.6%
+-commutative10.6%
Simplified10.6%
Taylor expanded in x around 0 2.6%
Final simplification2.6%
(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 10.7%
sub-neg10.7%
distribute-neg-frac10.7%
metadata-eval10.7%
metadata-eval10.7%
metadata-eval10.7%
associate-/r*10.7%
metadata-eval10.7%
neg-mul-110.7%
+-commutative10.7%
associate-+l+10.6%
+-commutative10.6%
neg-mul-110.6%
metadata-eval10.6%
associate-/r*10.6%
metadata-eval10.6%
metadata-eval10.6%
+-commutative10.6%
+-commutative10.6%
Simplified10.6%
frac-2neg10.6%
metadata-eval10.6%
frac-add10.2%
*-un-lft-identity10.2%
*-commutative10.2%
+-commutative10.2%
*-un-lft-identity10.2%
+-commutative10.2%
Applied egg-rr10.2%
associate-/r*10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
neg-sub010.6%
associate--r-10.6%
metadata-eval10.6%
+-commutative10.6%
associate-/r*10.2%
associate-+l+10.2%
+-commutative10.2%
associate-+r+10.2%
metadata-eval10.2%
Simplified10.2%
+-commutative10.2%
associate-/r*10.6%
frac-2neg10.6%
metadata-eval10.6%
frac-add10.5%
+-lft-identity10.5%
add-sqr-sqrt4.2%
sqrt-unprod5.8%
sqr-neg5.8%
sqrt-unprod1.3%
add-sqr-sqrt2.6%
add-sqr-sqrt1.3%
sqrt-unprod4.5%
sqr-neg4.5%
sqrt-unprod3.2%
add-sqr-sqrt6.3%
Applied egg-rr6.3%
Taylor expanded in x around 0 6.3%
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 2023333
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:pre (and (> (fabs x) 1.0) (< (fabs x) 1e+100))
:herbie-target
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))