
(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 9 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 (* (pow x -3.0) 2.0))
double code(double x) {
return pow(x, -3.0) * 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-3.0d0)) * 2.0d0
end function
public static double code(double x) {
return Math.pow(x, -3.0) * 2.0;
}
def code(x): return math.pow(x, -3.0) * 2.0
function code(x) return Float64((x ^ -3.0) * 2.0) end
function tmp = code(x) tmp = (x ^ -3.0) * 2.0; end
code[x_] := N[(N[Power[x, -3.0], $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-3} \cdot 2
\end{array}
Initial program 68.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around inf 98.1%
clear-num98.1%
associate-/r/98.0%
pow-flip99.0%
metadata-eval99.0%
Applied egg-rr99.0%
Final simplification99.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 68.5%
Final simplification68.5%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ x -1.0)) (/ (+ -1.0 (/ -1.0 x)) x)))
double code(double x) {
return (1.0 / (x + -1.0)) + ((-1.0 + (-1.0 / x)) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + (-1.0d0))) + (((-1.0d0) + ((-1.0d0) / x)) / x)
end function
public static double code(double x) {
return (1.0 / (x + -1.0)) + ((-1.0 + (-1.0 / x)) / x);
}
def code(x): return (1.0 / (x + -1.0)) + ((-1.0 + (-1.0 / x)) / x)
function code(x) return Float64(Float64(1.0 / Float64(x + -1.0)) + Float64(Float64(-1.0 + Float64(-1.0 / x)) / x)) end
function tmp = code(x) tmp = (1.0 / (x + -1.0)) + ((-1.0 + (-1.0 / x)) / x); end
code[x_] := N[(N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + -1} + \frac{-1 + \frac{-1}{x}}{x}
\end{array}
Initial program 68.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around inf 67.5%
associate-*r/67.5%
neg-mul-167.5%
distribute-neg-in67.5%
metadata-eval67.5%
distribute-neg-frac67.5%
metadata-eval67.5%
Simplified67.5%
Final simplification67.5%
(FPCore (x) :precision binary64 (+ (/ -1.0 x) (/ (- 1.0 (/ -1.0 x)) x)))
double code(double x) {
return (-1.0 / x) + ((1.0 - (-1.0 / x)) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) + ((1.0d0 - ((-1.0d0) / x)) / x)
end function
public static double code(double x) {
return (-1.0 / x) + ((1.0 - (-1.0 / x)) / x);
}
def code(x): return (-1.0 / x) + ((1.0 - (-1.0 / x)) / x)
function code(x) return Float64(Float64(-1.0 / x) + Float64(Float64(1.0 - Float64(-1.0 / x)) / x)) end
function tmp = code(x) tmp = (-1.0 / x) + ((1.0 - (-1.0 / x)) / x); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] + N[(N[(1.0 - N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x} + \frac{1 - \frac{-1}{x}}{x}
\end{array}
Initial program 68.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around inf 67.3%
Taylor expanded in x around inf 67.3%
remove-double-neg67.3%
distribute-frac-neg267.3%
unsub-neg67.3%
distribute-frac-neg267.3%
distribute-neg-frac67.3%
metadata-eval67.3%
Simplified67.3%
Final simplification67.3%
(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 68.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around inf 67.3%
Final simplification67.3%
(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(Float64(-1.0 / x) + Float64(1.0 / x)) end
function tmp = code(x) tmp = (-1.0 / x) + (1.0 / x); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x} + \frac{1}{x}
\end{array}
Initial program 68.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around inf 67.3%
Taylor expanded in x around inf 67.0%
Final simplification67.0%
(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.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around 0 5.0%
Final simplification5.0%
(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 68.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around inf 67.3%
Taylor expanded in x around 0 5.1%
Final simplification5.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 68.5%
+-commutative68.5%
associate-+r-68.5%
sub-neg68.5%
remove-double-neg68.5%
neg-sub068.5%
associate-+l-68.5%
neg-sub068.5%
distribute-neg-frac268.5%
distribute-frac-neg268.5%
associate-+r+68.5%
+-commutative68.5%
remove-double-neg68.5%
distribute-neg-frac268.5%
sub0-neg68.5%
associate-+l-68.5%
neg-sub068.5%
Simplified68.5%
Taylor expanded in x around inf 67.5%
associate-*r/67.5%
neg-mul-167.5%
distribute-neg-in67.5%
metadata-eval67.5%
distribute-neg-frac67.5%
metadata-eval67.5%
Simplified67.5%
frac-2neg67.5%
div-inv67.5%
add-sqr-sqrt20.5%
sqrt-unprod14.8%
sqr-neg14.8%
unpow214.8%
sqrt-pow16.4%
metadata-eval6.4%
pow16.4%
cancel-sign-sub-inv6.4%
div-inv6.4%
clear-num6.4%
frac-sub51.8%
Applied egg-rr51.8%
div-sub51.8%
*-commutative51.8%
associate-/r*6.4%
*-inverses6.4%
associate-/r*6.4%
*-inverses6.4%
associate-/r/6.4%
associate-*l/6.4%
*-lft-identity6.4%
Simplified6.4%
Taylor expanded in x around inf 6.4%
Final simplification6.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 2024053
(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))))