
(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 11 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 (fma x x -1.0))))
double code(double x) {
return (2.0 / x) * (1.0 / fma(x, x, -1.0));
}
function code(x) return Float64(Float64(2.0 / x) * Float64(1.0 / fma(x, x, -1.0))) end
code[x_] := N[(N[(2.0 / x), $MachinePrecision] * N[(1.0 / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x} \cdot \frac{1}{\mathsf{fma}\left(x, x, -1\right)}
\end{array}
Initial program 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
frac-2neg67.0%
metadata-eval67.0%
frac-sub16.0%
frac-add16.8%
fma-define16.8%
distribute-neg-in16.8%
neg-mul-116.8%
*-commutative16.8%
metadata-eval16.8%
fma-define16.8%
*-rgt-identity16.8%
fma-neg16.8%
distribute-neg-in16.8%
neg-mul-116.8%
*-commutative16.8%
metadata-eval16.8%
fma-define16.8%
Applied egg-rr16.8%
fma-undefine16.8%
neg-mul-116.8%
distribute-rgt-neg-in16.8%
fma-define15.2%
sub-neg15.2%
distribute-neg-in15.2%
metadata-eval15.2%
remove-double-neg15.2%
+-commutative15.2%
*-commutative15.2%
fma-neg15.2%
fma-undefine15.2%
*-commutative15.2%
neg-mul-115.2%
+-commutative15.2%
unsub-neg15.2%
*-commutative15.2%
associate-*l*15.2%
*-commutative15.2%
Simplified15.2%
Taylor expanded in x around 0 99.7%
associate-/r*99.8%
div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (/ 2.0 (* x (fma x x -1.0))))
double code(double x) {
return 2.0 / (x * fma(x, x, -1.0));
}
function code(x) return Float64(2.0 / Float64(x * fma(x, x, -1.0))) end
code[x_] := N[(2.0 / N[(x * N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x \cdot \mathsf{fma}\left(x, x, -1\right)}
\end{array}
Initial program 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
frac-2neg67.0%
metadata-eval67.0%
frac-sub16.0%
frac-add16.8%
fma-define16.8%
distribute-neg-in16.8%
neg-mul-116.8%
*-commutative16.8%
metadata-eval16.8%
fma-define16.8%
*-rgt-identity16.8%
fma-neg16.8%
distribute-neg-in16.8%
neg-mul-116.8%
*-commutative16.8%
metadata-eval16.8%
fma-define16.8%
Applied egg-rr16.8%
fma-undefine16.8%
neg-mul-116.8%
distribute-rgt-neg-in16.8%
fma-define15.2%
sub-neg15.2%
distribute-neg-in15.2%
metadata-eval15.2%
remove-double-neg15.2%
+-commutative15.2%
*-commutative15.2%
fma-neg15.2%
fma-undefine15.2%
*-commutative15.2%
neg-mul-115.2%
+-commutative15.2%
unsub-neg15.2%
*-commutative15.2%
associate-*l*15.2%
*-commutative15.2%
Simplified15.2%
Taylor expanded in x around 0 99.7%
Final simplification99.7%
(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 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
Taylor expanded in x around inf 98.9%
div-inv98.9%
pow-flip99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Final simplification99.2%
(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 67.0%
Final simplification67.0%
(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 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
Taylor expanded in x around inf 66.1%
associate-*r/66.1%
neg-mul-166.1%
distribute-neg-in66.1%
metadata-eval66.1%
distribute-neg-frac66.1%
metadata-eval66.1%
Simplified66.1%
Final simplification66.1%
(FPCore (x) :precision binary64 (/ (+ x (- 1.0 x)) (* x (+ x -1.0))))
double code(double x) {
return (x + (1.0 - x)) / (x * (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (1.0d0 - x)) / (x * (x + (-1.0d0)))
end function
public static double code(double x) {
return (x + (1.0 - x)) / (x * (x + -1.0));
}
def code(x): return (x + (1.0 - x)) / (x * (x + -1.0))
function code(x) return Float64(Float64(x + Float64(1.0 - x)) / Float64(x * Float64(x + -1.0))) end
function tmp = code(x) tmp = (x + (1.0 - x)) / (x * (x + -1.0)); end
code[x_] := N[(N[(x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \left(1 - x\right)}{x \cdot \left(x + -1\right)}
\end{array}
Initial program 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
Taylor expanded in x around inf 65.8%
frac-add65.8%
*-un-lft-identity65.8%
Applied egg-rr65.8%
*-commutative65.8%
distribute-lft-in65.8%
neg-mul-165.8%
metadata-eval65.8%
+-commutative65.8%
sub-neg65.8%
*-commutative65.8%
Simplified65.8%
Final simplification65.8%
(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 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
Taylor expanded in x around inf 65.8%
Final simplification65.8%
(FPCore (x) :precision binary64 (/ (/ 1.0 x) (+ x -1.0)))
double code(double x) {
return (1.0 / x) / (x + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) / (x + (-1.0d0))
end function
public static double code(double x) {
return (1.0 / x) / (x + -1.0);
}
def code(x): return (1.0 / x) / (x + -1.0)
function code(x) return Float64(Float64(1.0 / x) / Float64(x + -1.0)) end
function tmp = code(x) tmp = (1.0 / x) / (x + -1.0); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{x + -1}
\end{array}
Initial program 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
Taylor expanded in x around inf 65.8%
frac-add65.8%
*-un-lft-identity65.8%
Applied egg-rr65.8%
*-commutative65.8%
distribute-lft-in65.8%
neg-mul-165.8%
metadata-eval65.8%
+-commutative65.8%
sub-neg65.8%
*-commutative65.8%
Simplified65.8%
*-un-lft-identity65.8%
Applied egg-rr65.8%
*-lft-identity65.8%
+-commutative65.8%
associate--r-54.0%
+-inverses54.0%
metadata-eval54.0%
associate-/r*52.7%
Simplified52.7%
Final simplification52.7%
(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 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.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 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
Taylor expanded in x around inf 65.8%
Taylor expanded in x around 0 4.9%
Final simplification4.9%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 67.0%
+-commutative67.0%
associate-+r-67.0%
sub-neg67.0%
remove-double-neg67.0%
neg-sub067.0%
associate-+l-67.0%
neg-sub067.0%
distribute-neg-frac267.0%
distribute-frac-neg267.0%
associate-+r+67.0%
+-commutative67.0%
remove-double-neg67.0%
distribute-neg-frac267.0%
sub0-neg67.0%
associate-+l-67.0%
neg-sub067.0%
Simplified67.0%
Taylor expanded in x around 0 3.3%
Taylor expanded in x around inf 3.3%
Final simplification3.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 2024069
(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))))