
(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 8 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 -3.0)) (/ 2.0 (pow x 7.0)))))
double code(double x) {
return (2.0 / pow(x, 5.0)) + ((2.0 * pow(x, -3.0)) + (2.0 / pow(x, 7.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x ** 5.0d0)) + ((2.0d0 * (x ** (-3.0d0))) + (2.0d0 / (x ** 7.0d0)))
end function
public static double code(double x) {
return (2.0 / Math.pow(x, 5.0)) + ((2.0 * Math.pow(x, -3.0)) + (2.0 / Math.pow(x, 7.0)));
}
def code(x): return (2.0 / math.pow(x, 5.0)) + ((2.0 * math.pow(x, -3.0)) + (2.0 / math.pow(x, 7.0)))
function code(x) return Float64(Float64(2.0 / (x ^ 5.0)) + Float64(Float64(2.0 * (x ^ -3.0)) + Float64(2.0 / (x ^ 7.0)))) end
function tmp = code(x) tmp = (2.0 / (x ^ 5.0)) + ((2.0 * (x ^ -3.0)) + (2.0 / (x ^ 7.0))); end
code[x_] := N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{{x}^{5}} + \left(2 \cdot {x}^{-3} + \frac{2}{{x}^{7}}\right)
\end{array}
Initial program 68.0%
sub-neg68.0%
distribute-neg-frac68.0%
metadata-eval68.0%
metadata-eval68.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
neg-mul-168.0%
+-commutative68.0%
associate-+l+68.0%
+-commutative68.0%
neg-mul-168.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
metadata-eval68.0%
+-commutative68.0%
+-commutative68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
Taylor expanded in x around inf 99.1%
associate-*r/99.1%
metadata-eval99.1%
+-commutative99.1%
associate-*r/99.1%
metadata-eval99.1%
associate-*r/99.1%
metadata-eval99.1%
Simplified99.1%
expm1-log1p-u99.1%
expm1-udef67.9%
div-inv67.9%
pow-flip67.9%
metadata-eval67.9%
Applied egg-rr67.9%
expm1-def99.5%
expm1-log1p99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 3.0))))
double code(double x) {
return (2.0 / pow(x, 5.0)) + (2.0 / pow(x, 3.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x ** 5.0d0)) + (2.0d0 / (x ** 3.0d0))
end function
public static double code(double x) {
return (2.0 / Math.pow(x, 5.0)) + (2.0 / Math.pow(x, 3.0));
}
def code(x): return (2.0 / math.pow(x, 5.0)) + (2.0 / math.pow(x, 3.0))
function code(x) return Float64(Float64(2.0 / (x ^ 5.0)) + Float64(2.0 / (x ^ 3.0))) end
function tmp = code(x) tmp = (2.0 / (x ^ 5.0)) + (2.0 / (x ^ 3.0)); end
code[x_] := N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}
\end{array}
Initial program 68.0%
sub-neg68.0%
distribute-neg-frac68.0%
metadata-eval68.0%
metadata-eval68.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
neg-mul-168.0%
+-commutative68.0%
associate-+l+68.0%
+-commutative68.0%
neg-mul-168.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
metadata-eval68.0%
+-commutative68.0%
+-commutative68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
Taylor expanded in x around inf 98.9%
associate-*r/98.9%
metadata-eval98.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(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 68.0%
sub-neg68.0%
distribute-neg-frac68.0%
metadata-eval68.0%
metadata-eval68.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
neg-mul-168.0%
+-commutative68.0%
associate-+l+68.0%
+-commutative68.0%
neg-mul-168.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
metadata-eval68.0%
+-commutative68.0%
+-commutative68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
Taylor expanded in x around inf 98.4%
expm1-log1p-u99.1%
expm1-udef67.9%
div-inv67.9%
pow-flip67.9%
metadata-eval67.9%
Applied egg-rr67.2%
expm1-def99.5%
expm1-log1p99.5%
Simplified98.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (let* ((t_0 (- (* x 0.5) (/ 0.5 x)))) (/ (+ x (* t_0 -2.0)) (* x t_0))))
double code(double x) {
double t_0 = (x * 0.5) - (0.5 / x);
return (x + (t_0 * -2.0)) / (x * t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = (x * 0.5d0) - (0.5d0 / x)
code = (x + (t_0 * (-2.0d0))) / (x * t_0)
end function
public static double code(double x) {
double t_0 = (x * 0.5) - (0.5 / x);
return (x + (t_0 * -2.0)) / (x * t_0);
}
def code(x): t_0 = (x * 0.5) - (0.5 / x) return (x + (t_0 * -2.0)) / (x * t_0)
function code(x) t_0 = Float64(Float64(x * 0.5) - Float64(0.5 / x)) return Float64(Float64(x + Float64(t_0 * -2.0)) / Float64(x * t_0)) end
function tmp = code(x) t_0 = (x * 0.5) - (0.5 / x); tmp = (x + (t_0 * -2.0)) / (x * t_0); end
code[x_] := Block[{t$95$0 = N[(N[(x * 0.5), $MachinePrecision] - N[(0.5 / x), $MachinePrecision]), $MachinePrecision]}, N[(N[(x + N[(t$95$0 * -2.0), $MachinePrecision]), $MachinePrecision] / N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot 0.5 - \frac{0.5}{x}\\
\frac{x + t\_0 \cdot -2}{x \cdot t\_0}
\end{array}
\end{array}
Initial program 68.0%
sub-neg68.0%
distribute-neg-frac68.0%
metadata-eval68.0%
metadata-eval68.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
neg-mul-168.0%
+-commutative68.0%
associate-+l+68.0%
+-commutative68.0%
neg-mul-168.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
metadata-eval68.0%
+-commutative68.0%
+-commutative68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
frac-add18.0%
clear-num20.7%
+-commutative20.7%
*-un-lft-identity20.7%
*-rgt-identity20.7%
+-commutative20.7%
+-commutative20.7%
Applied egg-rr20.7%
Taylor expanded in x around 0 68.0%
*-commutative68.0%
associate-*r/68.0%
metadata-eval68.0%
Simplified68.0%
+-commutative68.0%
frac-add68.1%
*-un-lft-identity68.1%
Applied egg-rr68.1%
Final simplification68.1%
(FPCore (x) :precision binary64 (+ (/ -2.0 x) (/ 1.0 (- (* x 0.5) (/ 0.5 x)))))
double code(double x) {
return (-2.0 / x) + (1.0 / ((x * 0.5) - (0.5 / x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / x) + (1.0d0 / ((x * 0.5d0) - (0.5d0 / x)))
end function
public static double code(double x) {
return (-2.0 / x) + (1.0 / ((x * 0.5) - (0.5 / x)));
}
def code(x): return (-2.0 / x) + (1.0 / ((x * 0.5) - (0.5 / x)))
function code(x) return Float64(Float64(-2.0 / x) + Float64(1.0 / Float64(Float64(x * 0.5) - Float64(0.5 / x)))) end
function tmp = code(x) tmp = (-2.0 / x) + (1.0 / ((x * 0.5) - (0.5 / x))); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] + N[(1.0 / N[(N[(x * 0.5), $MachinePrecision] - N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x} + \frac{1}{x \cdot 0.5 - \frac{0.5}{x}}
\end{array}
Initial program 68.0%
sub-neg68.0%
distribute-neg-frac68.0%
metadata-eval68.0%
metadata-eval68.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
neg-mul-168.0%
+-commutative68.0%
associate-+l+68.0%
+-commutative68.0%
neg-mul-168.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
metadata-eval68.0%
+-commutative68.0%
+-commutative68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
frac-add18.0%
clear-num20.7%
+-commutative20.7%
*-un-lft-identity20.7%
*-rgt-identity20.7%
+-commutative20.7%
+-commutative20.7%
Applied egg-rr20.7%
Taylor expanded in x around 0 68.0%
*-commutative68.0%
associate-*r/68.0%
metadata-eval68.0%
Simplified68.0%
Final simplification68.0%
(FPCore (x) :precision binary64 (+ (/ -2.0 x) (/ 2.0 x)))
double code(double x) {
return (-2.0 / x) + (2.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / x) + (2.0d0 / x)
end function
public static double code(double x) {
return (-2.0 / x) + (2.0 / x);
}
def code(x): return (-2.0 / x) + (2.0 / x)
function code(x) return Float64(Float64(-2.0 / x) + Float64(2.0 / x)) end
function tmp = code(x) tmp = (-2.0 / x) + (2.0 / x); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] + N[(2.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x} + \frac{2}{x}
\end{array}
Initial program 68.0%
sub-neg68.0%
distribute-neg-frac68.0%
metadata-eval68.0%
metadata-eval68.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
neg-mul-168.0%
+-commutative68.0%
associate-+l+68.0%
+-commutative68.0%
neg-mul-168.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
metadata-eval68.0%
+-commutative68.0%
+-commutative68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
Taylor expanded in x around inf 66.5%
Final simplification66.5%
(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.0%
sub-neg68.0%
distribute-neg-frac68.0%
metadata-eval68.0%
metadata-eval68.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
neg-mul-168.0%
+-commutative68.0%
associate-+l+68.0%
+-commutative68.0%
neg-mul-168.0%
metadata-eval68.0%
associate-/r*68.0%
metadata-eval68.0%
metadata-eval68.0%
+-commutative68.0%
+-commutative68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
Taylor expanded in x around 0 5.1%
Final simplification5.1%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 68.0%
associate-+l-68.0%
sub-neg68.0%
+-commutative68.0%
neg-sub068.0%
associate-+l-68.0%
neg-sub068.0%
distribute-neg-frac68.0%
metadata-eval68.0%
sub-neg68.0%
metadata-eval68.0%
Simplified68.0%
frac-2neg68.0%
metadata-eval68.0%
frac-add18.1%
+-commutative18.1%
distribute-neg-in18.1%
metadata-eval18.1%
sub-neg18.1%
*-commutative18.1%
neg-mul-118.1%
+-commutative18.1%
distribute-neg-in18.1%
metadata-eval18.1%
sub-neg18.1%
Applied egg-rr18.1%
unsub-neg18.1%
Simplified18.1%
Taylor expanded in x around inf 16.7%
Taylor expanded in x around 0 3.4%
Final simplification3.4%
(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 2024041
(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))))