
(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 6 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 79.5%
sub-neg79.5%
+-commutative79.5%
distribute-neg-frac279.5%
neg-sub079.5%
associate-+l-79.5%
neg-sub079.5%
remove-double-neg79.5%
distribute-neg-in79.5%
sub-neg79.5%
distribute-neg-frac279.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
metadata-eval79.5%
Simplified79.5%
frac-sub80.0%
*-rgt-identity80.0%
metadata-eval80.0%
div-inv80.0%
associate-/r*80.0%
metadata-eval80.0%
div-inv80.0%
*-un-lft-identity80.0%
associate--l-82.7%
div-inv82.7%
metadata-eval82.7%
*-rgt-identity82.7%
div-inv82.7%
metadata-eval82.7%
*-rgt-identity82.7%
Applied egg-rr82.7%
+-commutative82.7%
associate-+l-99.9%
Applied egg-rr99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
*-lft-identity99.9%
Simplified99.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(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 79.5%
sub-neg79.5%
+-commutative79.5%
distribute-neg-frac279.5%
neg-sub079.5%
associate-+l-79.5%
neg-sub079.5%
remove-double-neg79.5%
distribute-neg-in79.5%
sub-neg79.5%
distribute-neg-frac279.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
metadata-eval79.5%
Simplified79.5%
sub-neg79.5%
distribute-neg-frac79.5%
metadata-eval79.5%
Applied egg-rr79.5%
metadata-eval79.5%
distribute-neg-frac79.5%
unsub-neg79.5%
*-rgt-identity79.5%
*-inverses79.5%
associate-/r*57.4%
*-commutative57.4%
*-lft-identity57.4%
associate-/r*79.5%
associate-*r/79.5%
associate-*l/79.5%
distribute-lft-out--79.5%
*-inverses79.5%
div-sub80.0%
associate--r+82.7%
*-commutative82.7%
times-frac82.7%
Simplified99.7%
associate-/r*99.9%
div-inv99.8%
Applied egg-rr99.8%
metadata-eval99.8%
metadata-eval99.8%
+-inverses99.8%
associate-*l/99.9%
un-div-inv99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
Applied egg-rr99.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 79.5%
sub-neg79.5%
+-commutative79.5%
distribute-neg-frac279.5%
neg-sub079.5%
associate-+l-79.5%
neg-sub079.5%
remove-double-neg79.5%
distribute-neg-in79.5%
sub-neg79.5%
distribute-neg-frac279.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
metadata-eval79.5%
Simplified79.5%
sub-neg79.5%
distribute-neg-frac79.5%
metadata-eval79.5%
Applied egg-rr79.5%
metadata-eval79.5%
distribute-neg-frac79.5%
unsub-neg79.5%
*-rgt-identity79.5%
*-inverses79.5%
associate-/r*57.4%
*-commutative57.4%
*-lft-identity57.4%
associate-/r*79.5%
associate-*r/79.5%
associate-*l/79.5%
distribute-lft-out--79.5%
*-inverses79.5%
div-sub80.0%
associate--r+82.7%
*-commutative82.7%
times-frac82.7%
Simplified99.7%
(FPCore (x) :precision binary64 (/ -2.0 (+ x -1.0)))
double code(double x) {
return -2.0 / (x + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / (x + (-1.0d0))
end function
public static double code(double x) {
return -2.0 / (x + -1.0);
}
def code(x): return -2.0 / (x + -1.0)
function code(x) return Float64(-2.0 / Float64(x + -1.0)) end
function tmp = code(x) tmp = -2.0 / (x + -1.0); end
code[x_] := N[(-2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x + -1}
\end{array}
Initial program 79.5%
sub-neg79.5%
+-commutative79.5%
distribute-neg-frac279.5%
neg-sub079.5%
associate-+l-79.5%
neg-sub079.5%
remove-double-neg79.5%
distribute-neg-in79.5%
sub-neg79.5%
distribute-neg-frac279.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
metadata-eval79.5%
Simplified79.5%
sub-neg79.5%
distribute-neg-frac79.5%
metadata-eval79.5%
Applied egg-rr79.5%
metadata-eval79.5%
distribute-neg-frac79.5%
unsub-neg79.5%
*-rgt-identity79.5%
*-inverses79.5%
associate-/r*57.4%
*-commutative57.4%
*-lft-identity57.4%
associate-/r*79.5%
associate-*r/79.5%
associate-*l/79.5%
distribute-lft-out--79.5%
*-inverses79.5%
div-sub80.0%
associate--r+82.7%
*-commutative82.7%
times-frac82.7%
Simplified99.7%
associate-/r*99.9%
div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 54.9%
Final simplification54.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 79.5%
sub-neg79.5%
+-commutative79.5%
distribute-neg-frac279.5%
neg-sub079.5%
associate-+l-79.5%
neg-sub079.5%
remove-double-neg79.5%
distribute-neg-in79.5%
sub-neg79.5%
distribute-neg-frac279.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
metadata-eval79.5%
Simplified79.5%
Taylor expanded in x around 0 54.0%
(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 79.5%
sub-neg79.5%
+-commutative79.5%
distribute-neg-frac279.5%
neg-sub079.5%
associate-+l-79.5%
neg-sub079.5%
remove-double-neg79.5%
distribute-neg-in79.5%
sub-neg79.5%
distribute-neg-frac279.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
sub-neg79.5%
+-commutative79.5%
unsub-neg79.5%
metadata-eval79.5%
Simplified79.5%
Taylor expanded in x around 0 53.5%
Taylor expanded in x around inf 11.2%
herbie shell --seed 2024096
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))