
(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.0%
sub-neg76.0%
+-commutative76.0%
distribute-neg-frac276.0%
neg-sub076.0%
associate-+l-76.0%
neg-sub076.0%
remove-double-neg76.0%
distribute-neg-in76.0%
sub-neg76.0%
distribute-neg-frac276.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
metadata-eval76.0%
Simplified76.0%
frac-sub77.3%
*-rgt-identity77.3%
metadata-eval77.3%
div-inv77.3%
associate-/r*77.3%
metadata-eval77.3%
div-inv77.3%
*-un-lft-identity77.3%
associate--l-80.4%
div-inv80.4%
metadata-eval80.4%
*-rgt-identity80.4%
div-inv80.4%
metadata-eval80.4%
*-rgt-identity80.4%
Applied egg-rr80.4%
flip3--57.3%
associate-/r/56.9%
+-commutative56.9%
associate-+l-65.8%
metadata-eval65.8%
metadata-eval65.8%
distribute-rgt-out65.8%
+-commutative65.8%
Applied egg-rr65.8%
associate-/l/65.2%
+-inverses65.2%
metadata-eval65.2%
metadata-eval65.2%
+-commutative65.2%
Simplified65.2%
*-commutative65.2%
associate-/r*65.8%
metadata-eval65.8%
associate-/r/68.9%
metadata-eval68.9%
metadata-eval68.9%
distribute-rgt-in68.9%
flip3--99.9%
metadata-eval99.9%
associate-/l/99.0%
*-commutative99.0%
Applied egg-rr99.0%
associate-/l/99.9%
Simplified99.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.0%
sub-neg76.0%
+-commutative76.0%
distribute-neg-frac276.0%
neg-sub076.0%
associate-+l-76.0%
neg-sub076.0%
remove-double-neg76.0%
distribute-neg-in76.0%
sub-neg76.0%
distribute-neg-frac276.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
metadata-eval76.0%
Simplified76.0%
sub-neg76.0%
distribute-neg-frac76.0%
metadata-eval76.0%
Applied egg-rr76.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (* -2.0 (+ -1.0 x)))
double code(double x) {
return -2.0 * (-1.0 + x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) * ((-1.0d0) + x)
end function
public static double code(double x) {
return -2.0 * (-1.0 + x);
}
def code(x): return -2.0 * (-1.0 + x)
function code(x) return Float64(-2.0 * Float64(-1.0 + x)) end
function tmp = code(x) tmp = -2.0 * (-1.0 + x); end
code[x_] := N[(-2.0 * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(-1 + x\right)
\end{array}
Initial program 76.0%
sub-neg76.0%
+-commutative76.0%
distribute-neg-frac276.0%
neg-sub076.0%
associate-+l-76.0%
neg-sub076.0%
remove-double-neg76.0%
distribute-neg-in76.0%
sub-neg76.0%
distribute-neg-frac276.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
metadata-eval76.0%
Simplified76.0%
frac-sub77.3%
*-rgt-identity77.3%
metadata-eval77.3%
div-inv77.3%
associate-/r*77.3%
metadata-eval77.3%
div-inv77.3%
*-un-lft-identity77.3%
associate--l-80.4%
div-inv80.4%
metadata-eval80.4%
*-rgt-identity80.4%
div-inv80.4%
metadata-eval80.4%
*-rgt-identity80.4%
Applied egg-rr80.4%
Taylor expanded in x around 0 99.9%
flip--98.9%
+-commutative98.9%
associate-/r/91.3%
metadata-eval91.3%
metadata-eval91.3%
pow291.3%
+-commutative91.3%
Applied egg-rr91.3%
*-commutative91.3%
+-commutative91.3%
associate-/l/91.1%
Simplified91.1%
Taylor expanded in x around 0 52.3%
Final simplification52.3%
(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.0%
sub-neg76.0%
+-commutative76.0%
distribute-neg-frac276.0%
neg-sub076.0%
associate-+l-76.0%
neg-sub076.0%
remove-double-neg76.0%
distribute-neg-in76.0%
sub-neg76.0%
distribute-neg-frac276.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
sub-neg76.0%
+-commutative76.0%
unsub-neg76.0%
metadata-eval76.0%
Simplified76.0%
Taylor expanded in x around 0 52.5%
Final simplification52.5%
herbie shell --seed 2024067
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))