
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0)); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0)); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}
(FPCore (x) :precision binary64 (/ (/ 2.0 (- 1.0 x)) (+ 1.0 x)))
double code(double x) {
return (2.0 / (1.0 - x)) / (1.0 + x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (1.0d0 - x)) / (1.0d0 + x)
end function
public static double code(double x) {
return (2.0 / (1.0 - x)) / (1.0 + x);
}
def code(x): return (2.0 / (1.0 - x)) / (1.0 + x)
function code(x) return Float64(Float64(2.0 / Float64(1.0 - x)) / Float64(1.0 + x)) end
function tmp = code(x) tmp = (2.0 / (1.0 - x)) / (1.0 + x); end
code[x_] := N[(N[(2.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{1 - x}}{1 + x}
\end{array}
Initial program 76.1%
sub-neg76.1%
+-commutative76.1%
distribute-neg-frac276.1%
neg-sub076.1%
associate-+l-76.1%
neg-sub076.1%
remove-double-neg76.1%
distribute-neg-in76.1%
sub-neg76.1%
distribute-neg-frac276.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
metadata-eval76.1%
Simplified76.1%
frac-sub76.2%
*-rgt-identity76.2%
metadata-eval76.2%
div-inv76.2%
associate-/r*76.3%
metadata-eval76.3%
div-inv76.3%
*-un-lft-identity76.3%
associate--l-79.7%
div-inv79.7%
metadata-eval79.7%
*-rgt-identity79.7%
div-inv79.7%
metadata-eval79.7%
*-rgt-identity79.7%
Applied egg-rr79.7%
Taylor expanded in x around 0 99.9%
*-un-lft-identity99.9%
add-sqr-sqrt24.5%
times-frac24.5%
Applied egg-rr52.6%
frac-times52.6%
*-un-lft-identity52.6%
frac-2neg52.6%
metadata-eval52.6%
distribute-neg-in52.6%
metadata-eval52.6%
*-rgt-identity52.6%
sub-neg52.6%
*-rgt-identity52.6%
hypot-undefine52.6%
metadata-eval52.6%
add-sqr-sqrt52.6%
hypot-undefine52.6%
metadata-eval52.6%
add-sqr-sqrt75.3%
add-sqr-sqrt99.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (/ -2.0 (* (- 1.0 x) (- -1.0 x))))
double code(double x) {
return -2.0 / ((1.0 - x) * (-1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((1.0d0 - x) * ((-1.0d0) - x))
end function
public static double code(double x) {
return -2.0 / ((1.0 - x) * (-1.0 - x));
}
def code(x): return -2.0 / ((1.0 - x) * (-1.0 - x))
function code(x) return Float64(-2.0 / Float64(Float64(1.0 - x) * Float64(-1.0 - x))) end
function tmp = code(x) tmp = -2.0 / ((1.0 - x) * (-1.0 - x)); end
code[x_] := N[(-2.0 / N[(N[(1.0 - x), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(1 - x\right) \cdot \left(-1 - x\right)}
\end{array}
Initial program 76.1%
sub-neg76.1%
+-commutative76.1%
distribute-neg-frac276.1%
neg-sub076.1%
associate-+l-76.1%
neg-sub076.1%
remove-double-neg76.1%
distribute-neg-in76.1%
sub-neg76.1%
distribute-neg-frac276.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
metadata-eval76.1%
Simplified76.1%
sub-neg76.1%
distribute-neg-frac76.1%
metadata-eval76.1%
Applied egg-rr76.1%
metadata-eval76.1%
distribute-neg-frac76.1%
unsub-neg76.1%
*-rgt-identity76.1%
*-inverses76.1%
associate-/r*58.0%
*-commutative58.0%
*-lft-identity58.0%
associate-/r*76.1%
associate-*r/76.1%
associate-*l/76.1%
distribute-lft-out--76.1%
*-inverses76.1%
div-sub76.2%
associate--r+79.7%
*-commutative79.7%
times-frac79.6%
Simplified99.9%
Final simplification99.9%
(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 76.1%
sub-neg76.1%
+-commutative76.1%
distribute-neg-frac276.1%
neg-sub076.1%
associate-+l-76.1%
neg-sub076.1%
remove-double-neg76.1%
distribute-neg-in76.1%
sub-neg76.1%
distribute-neg-frac276.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
metadata-eval76.1%
Simplified76.1%
sub-neg76.1%
distribute-neg-frac76.1%
metadata-eval76.1%
Applied egg-rr76.1%
metadata-eval76.1%
distribute-neg-frac76.1%
unsub-neg76.1%
*-rgt-identity76.1%
*-inverses76.1%
associate-/r*58.0%
*-commutative58.0%
*-lft-identity58.0%
associate-/r*76.1%
associate-*r/76.1%
associate-*l/76.1%
distribute-lft-out--76.1%
*-inverses76.1%
div-sub76.2%
associate--r+79.7%
*-commutative79.7%
times-frac79.6%
Simplified99.9%
associate-/r*99.9%
flip3--74.2%
associate-/r/69.4%
metadata-eval69.4%
metadata-eval69.4%
distribute-rgt-out69.4%
Applied egg-rr69.4%
metadata-eval69.4%
associate-*l/74.2%
associate-/l*74.2%
clear-num74.2%
metadata-eval74.2%
metadata-eval74.2%
distribute-rgt-in74.2%
flip3--99.8%
div-inv99.9%
Applied egg-rr45.5%
Taylor expanded in x around 0 2.7%
Final simplification2.7%
(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 76.1%
sub-neg76.1%
+-commutative76.1%
distribute-neg-frac276.1%
neg-sub076.1%
associate-+l-76.1%
neg-sub076.1%
remove-double-neg76.1%
distribute-neg-in76.1%
sub-neg76.1%
distribute-neg-frac276.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
sub-neg76.1%
+-commutative76.1%
unsub-neg76.1%
metadata-eval76.1%
Simplified76.1%
Taylor expanded in x around 0 56.0%
Final simplification56.0%
herbie shell --seed 2024080
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))