
(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 (* (fma 2.0 (pow x -2.0) (fma 2.0 (pow x -4.0) 2.0)) (pow x -3.0)))
double code(double x) {
return fma(2.0, pow(x, -2.0), fma(2.0, pow(x, -4.0), 2.0)) * pow(x, -3.0);
}
function code(x) return Float64(fma(2.0, (x ^ -2.0), fma(2.0, (x ^ -4.0), 2.0)) * (x ^ -3.0)) end
code[x_] := N[(N[(2.0 * N[Power[x, -2.0], $MachinePrecision] + N[(2.0 * N[Power[x, -4.0], $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, {x}^{-2}, \mathsf{fma}\left(2, {x}^{-4}, 2\right)\right) \cdot {x}^{-3}
\end{array}
Initial program 68.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
Taylor expanded in x around inf 98.5%
associate-+r+98.5%
+-commutative98.5%
associate-+l+98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
div-inv98.5%
div-inv98.5%
fma-define98.5%
pow-flip98.5%
metadata-eval98.5%
+-commutative98.5%
div-inv98.5%
fma-define98.5%
pow-flip98.5%
metadata-eval98.5%
pow-flip99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (+ (/ (+ 1.0 (/ 1.0 x)) x) (/ -1.0 x)))
double code(double x) {
return ((1.0 + (1.0 / x)) / x) + (-1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 + (1.0d0 / x)) / x) + ((-1.0d0) / x)
end function
public static double code(double x) {
return ((1.0 + (1.0 / x)) / x) + (-1.0 / x);
}
def code(x): return ((1.0 + (1.0 / x)) / x) + (-1.0 / x)
function code(x) return Float64(Float64(Float64(1.0 + Float64(1.0 / x)) / x) + Float64(-1.0 / x)) end
function tmp = code(x) tmp = ((1.0 + (1.0 / x)) / x) + (-1.0 / x); end
code[x_] := N[(N[(N[(1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 + \frac{1}{x}}{x} + \frac{-1}{x}
\end{array}
Initial program 68.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
Taylor expanded in x around inf 66.7%
Taylor expanded in x around inf 66.7%
Final simplification66.7%
(FPCore (x) :precision binary64 (/ -2.0 (* x (* (+ x -1.0) (- -1.0 x)))))
double code(double x) {
return -2.0 / (x * ((x + -1.0) * (-1.0 - x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / (x * ((x + (-1.0d0)) * ((-1.0d0) - x)))
end function
public static double code(double x) {
return -2.0 / (x * ((x + -1.0) * (-1.0 - x)));
}
def code(x): return -2.0 / (x * ((x + -1.0) * (-1.0 - x)))
function code(x) return Float64(-2.0 / Float64(x * Float64(Float64(x + -1.0) * Float64(-1.0 - x)))) end
function tmp = code(x) tmp = -2.0 / (x * ((x + -1.0) * (-1.0 - x))); end
code[x_] := N[(-2.0 / N[(x * N[(N[(x + -1.0), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x \cdot \left(\left(x + -1\right) \cdot \left(-1 - x\right)\right)}
\end{array}
Initial program 68.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
+-commutative68.8%
associate-+l-68.8%
Applied egg-rr68.8%
frac-sub19.5%
*-un-lft-identity19.5%
Applied egg-rr19.5%
frac-sub20.3%
*-rgt-identity20.3%
*-commutative20.3%
*-rgt-identity20.3%
associate--l+20.3%
*-rgt-identity20.3%
*-rgt-identity20.3%
*-commutative20.3%
*-rgt-identity20.3%
Applied egg-rr20.3%
distribute-rgt-in20.3%
associate--r-20.3%
metadata-eval20.3%
+-lft-identity20.3%
distribute-lft-in20.3%
+-lft-identity20.3%
Simplified20.3%
Taylor expanded in x around 0 99.2%
Final simplification99.2%
(FPCore (x) :precision binary64 (+ (/ -1.0 x) (/ 1.0 (+ x -1.0))))
double code(double x) {
return (-1.0 / x) + (1.0 / (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) + (1.0d0 / (x + (-1.0d0)))
end function
public static double code(double x) {
return (-1.0 / x) + (1.0 / (x + -1.0));
}
def code(x): return (-1.0 / x) + (1.0 / (x + -1.0))
function code(x) return Float64(Float64(-1.0 / x) + Float64(1.0 / Float64(x + -1.0))) end
function tmp = code(x) tmp = (-1.0 / x) + (1.0 / (x + -1.0)); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x} + \frac{1}{x + -1}
\end{array}
Initial program 68.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
Taylor expanded in x around inf 66.7%
Final simplification66.7%
(FPCore (x) :precision binary64 (+ -1.0 (/ (- x 2.0) x)))
double code(double x) {
return -1.0 + ((x - 2.0) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + ((x - 2.0d0) / x)
end function
public static double code(double x) {
return -1.0 + ((x - 2.0) / x);
}
def code(x): return -1.0 + ((x - 2.0) / x)
function code(x) return Float64(-1.0 + Float64(Float64(x - 2.0) / x)) end
function tmp = code(x) tmp = -1.0 + ((x - 2.0) / x); end
code[x_] := N[(-1.0 + N[(N[(x - 2.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \frac{x - 2}{x}
\end{array}
Initial program 68.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
Taylor expanded in x around 0 3.3%
Taylor expanded in x around 0 66.4%
Final simplification66.4%
(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.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
+-commutative68.8%
associate-+l-68.8%
Applied egg-rr68.8%
frac-sub19.5%
*-un-lft-identity19.5%
Applied egg-rr19.5%
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.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
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 68.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
Taylor expanded in x around inf 66.7%
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 68.8%
+-commutative68.8%
associate-+r-68.8%
sub-neg68.8%
remove-double-neg68.8%
neg-sub068.8%
associate-+l-68.8%
neg-sub068.8%
distribute-neg-frac268.8%
distribute-frac-neg268.8%
associate-+r+68.8%
+-commutative68.8%
remove-double-neg68.8%
distribute-neg-frac268.8%
sub0-neg68.8%
associate-+l-68.8%
neg-sub068.8%
Simplified68.8%
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 2024115
(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))))