
(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 10 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) (fma x x -1.0)))
double code(double x) {
return (2.0 / x) / fma(x, x, -1.0);
}
function code(x) return Float64(Float64(2.0 / x) / fma(x, x, -1.0)) end
code[x_] := N[(N[(2.0 / x), $MachinePrecision] / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x}}{\mathsf{fma}\left(x, x, -1\right)}
\end{array}
Initial program 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
frac-sub18.6%
frac-add19.2%
*-un-lft-identity19.2%
fma-define18.5%
*-rgt-identity18.5%
fma-neg18.5%
Applied egg-rr18.5%
Simplified19.2%
Taylor expanded in x around 0 99.4%
*-un-lft-identity99.4%
associate-/r*99.8%
metadata-eval99.8%
frac-2neg99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (/ 2.0 (- (pow x 3.0) x)))
double code(double x) {
return 2.0 / (pow(x, 3.0) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((x ** 3.0d0) - x)
end function
public static double code(double x) {
return 2.0 / (Math.pow(x, 3.0) - x);
}
def code(x): return 2.0 / (math.pow(x, 3.0) - x)
function code(x) return Float64(2.0 / Float64((x ^ 3.0) - x)) end
function tmp = code(x) tmp = 2.0 / ((x ^ 3.0) - x); end
code[x_] := N[(2.0 / N[(N[Power[x, 3.0], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{{x}^{3} - x}
\end{array}
Initial program 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
frac-sub18.6%
frac-add19.2%
*-un-lft-identity19.2%
fma-define18.5%
*-rgt-identity18.5%
fma-neg18.5%
Applied egg-rr18.5%
Simplified19.2%
Taylor expanded in x around 0 99.4%
*-un-lft-identity99.4%
associate-/r*99.8%
metadata-eval99.8%
frac-2neg99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
associate-/l/99.4%
*-commutative99.4%
fma-undefine99.4%
unpow299.4%
distribute-rgt-in99.4%
unpow299.4%
unpow399.5%
neg-mul-199.5%
unsub-neg99.5%
Simplified99.5%
Final simplification99.5%
(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 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
Taylor expanded in x around inf 98.4%
clear-num98.4%
associate-/r/98.4%
pow-flip98.9%
metadata-eval98.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ x -1.0)) (/ (/ (- -1.0 (+ x (* x -0.5))) (* x -0.5)) (- -1.0 x))))
double code(double x) {
return (1.0 / (x + -1.0)) + (((-1.0 - (x + (x * -0.5))) / (x * -0.5)) / (-1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + (-1.0d0))) + ((((-1.0d0) - (x + (x * (-0.5d0)))) / (x * (-0.5d0))) / ((-1.0d0) - x))
end function
public static double code(double x) {
return (1.0 / (x + -1.0)) + (((-1.0 - (x + (x * -0.5))) / (x * -0.5)) / (-1.0 - x));
}
def code(x): return (1.0 / (x + -1.0)) + (((-1.0 - (x + (x * -0.5))) / (x * -0.5)) / (-1.0 - x))
function code(x) return Float64(Float64(1.0 / Float64(x + -1.0)) + Float64(Float64(Float64(-1.0 - Float64(x + Float64(x * -0.5))) / Float64(x * -0.5)) / Float64(-1.0 - x))) end
function tmp = code(x) tmp = (1.0 / (x + -1.0)) + (((-1.0 - (x + (x * -0.5))) / (x * -0.5)) / (-1.0 - x)); end
code[x_] := N[(N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-1.0 - N[(x + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * -0.5), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + -1} + \frac{\frac{-1 - \left(x + x \cdot -0.5\right)}{x \cdot -0.5}}{-1 - x}
\end{array}
Initial program 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
clear-num70.7%
frac-sub18.6%
*-un-lft-identity18.6%
div-inv18.6%
metadata-eval18.6%
div-inv18.6%
metadata-eval18.6%
Applied egg-rr18.6%
associate-/r*70.8%
*-rgt-identity70.8%
associate--r+70.8%
Simplified70.8%
Final simplification70.8%
(FPCore (x) :precision binary64 (+ (/ 1.0 (+ x -1.0)) (- (/ 1.0 (+ x 1.0)) (/ 2.0 x))))
double code(double x) {
return (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + (-1.0d0))) + ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x))
end function
public static double code(double x) {
return (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x));
}
def code(x): return (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x))
function code(x) return Float64(Float64(1.0 / Float64(x + -1.0)) + Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x))) end
function tmp = code(x) tmp = (1.0 / (x + -1.0)) + ((1.0 / (x + 1.0)) - (2.0 / x)); end
code[x_] := N[(N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + -1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)
\end{array}
Initial program 70.7%
Final simplification70.7%
(FPCore (x) :precision binary64 (- (/ -2.0 x) (+ (/ -1.0 (- x -1.0)) (/ -1.0 (+ x -1.0)))))
double code(double x) {
return (-2.0 / x) - ((-1.0 / (x - -1.0)) + (-1.0 / (x + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / x) - (((-1.0d0) / (x - (-1.0d0))) + ((-1.0d0) / (x + (-1.0d0))))
end function
public static double code(double x) {
return (-2.0 / x) - ((-1.0 / (x - -1.0)) + (-1.0 / (x + -1.0)));
}
def code(x): return (-2.0 / x) - ((-1.0 / (x - -1.0)) + (-1.0 / (x + -1.0)))
function code(x) return Float64(Float64(-2.0 / x) - Float64(Float64(-1.0 / Float64(x - -1.0)) + Float64(-1.0 / Float64(x + -1.0)))) end
function tmp = code(x) tmp = (-2.0 / x) - ((-1.0 / (x - -1.0)) + (-1.0 / (x + -1.0))); end
code[x_] := N[(N[(-2.0 / x), $MachinePrecision] - N[(N[(-1.0 / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x} - \left(\frac{-1}{x - -1} + \frac{-1}{x + -1}\right)
\end{array}
Initial program 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
+-commutative70.7%
associate-+l-70.8%
Applied egg-rr70.8%
Final simplification70.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 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
Taylor expanded in x around inf 69.6%
Final simplification69.6%
(FPCore (x) :precision binary64 (+ -1.0 (+ (/ 2.0 x) 1.0)))
double code(double x) {
return -1.0 + ((2.0 / x) + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) + ((2.0d0 / x) + 1.0d0)
end function
public static double code(double x) {
return -1.0 + ((2.0 / x) + 1.0);
}
def code(x): return -1.0 + ((2.0 / x) + 1.0)
function code(x) return Float64(-1.0 + Float64(Float64(2.0 / x) + 1.0)) end
function tmp = code(x) tmp = -1.0 + ((2.0 / x) + 1.0); end
code[x_] := N[(-1.0 + N[(N[(2.0 / x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left(\frac{2}{x} + 1\right)
\end{array}
Initial program 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
+-commutative70.7%
associate-+l-70.8%
Applied egg-rr70.8%
Applied egg-rr6.3%
expm1-define69.5%
sub-neg69.5%
metadata-eval69.5%
+-commutative69.5%
log1p-undefine69.5%
rem-exp-log69.6%
+-commutative69.6%
associate-+l+69.6%
associate-+r+69.6%
metadata-eval69.6%
distribute-neg-frac69.6%
sub-neg69.6%
+-inverses69.6%
metadata-eval69.6%
Simplified69.6%
Final simplification69.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 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
Taylor expanded in x around 0 5.2%
Final simplification5.2%
(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 70.7%
+-commutative70.7%
associate-+r-70.8%
sub-neg70.8%
remove-double-neg70.8%
neg-sub070.8%
associate-+l-70.8%
neg-sub070.8%
distribute-neg-frac270.8%
distribute-frac-neg270.8%
associate-+r+70.7%
+-commutative70.7%
remove-double-neg70.7%
distribute-neg-frac270.7%
sub0-neg70.7%
associate-+l-70.7%
neg-sub070.7%
Simplified70.7%
+-commutative70.7%
associate-+l-70.8%
Applied egg-rr70.8%
Applied egg-rr6.3%
associate-+r+6.3%
metadata-eval6.3%
distribute-neg-frac6.3%
sub-neg6.3%
associate--l+6.3%
+-inverses6.3%
+-rgt-identity6.3%
Simplified6.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 2024074
(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))))