
(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.2%
sub-neg79.2%
+-commutative79.2%
distribute-neg-frac279.2%
neg-sub079.2%
associate-+l-79.2%
neg-sub079.2%
remove-double-neg79.2%
distribute-neg-in79.2%
sub-neg79.2%
distribute-neg-frac279.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
metadata-eval79.2%
Simplified79.2%
sub-neg79.2%
distribute-neg-frac79.2%
metadata-eval79.2%
Applied egg-rr79.2%
metadata-eval79.2%
distribute-neg-frac79.2%
unsub-neg79.2%
*-rgt-identity79.2%
*-inverses79.2%
associate-/r*54.1%
*-commutative54.1%
*-lft-identity54.1%
associate-/r*79.2%
associate-*r/79.2%
associate-*l/79.2%
distribute-lft-out--79.2%
*-inverses79.2%
div-sub79.5%
associate--r+82.3%
*-commutative82.3%
times-frac82.3%
Simplified99.4%
associate-/r*99.9%
div-inv99.8%
Applied egg-rr99.8%
un-div-inv99.9%
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ -2.0 (+ 1.0 x)) x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.0 / (1.0 + x)) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 2.0d0
else
tmp = ((-2.0d0) / (1.0d0 + x)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.0 / (1.0 + x)) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (-2.0 / (1.0 + x)) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(-2.0 / Float64(1.0 + x)) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = (-2.0 / (1.0 + x)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(-2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{1 + x}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 87.6%
sub-neg87.6%
+-commutative87.6%
distribute-neg-frac287.6%
neg-sub087.6%
associate-+l-87.6%
neg-sub087.6%
remove-double-neg87.6%
distribute-neg-in87.6%
sub-neg87.6%
distribute-neg-frac287.6%
sub-neg87.6%
+-commutative87.6%
unsub-neg87.6%
sub-neg87.6%
+-commutative87.6%
unsub-neg87.6%
metadata-eval87.6%
Simplified87.6%
Taylor expanded in x around 0 69.0%
if 1 < x Initial program 56.5%
sub-neg56.5%
+-commutative56.5%
distribute-neg-frac256.5%
neg-sub056.5%
associate-+l-56.5%
neg-sub056.5%
remove-double-neg56.5%
distribute-neg-in56.5%
sub-neg56.5%
distribute-neg-frac256.5%
sub-neg56.5%
+-commutative56.5%
unsub-neg56.5%
sub-neg56.5%
+-commutative56.5%
unsub-neg56.5%
metadata-eval56.5%
Simplified56.5%
sub-neg56.5%
distribute-neg-frac56.5%
metadata-eval56.5%
Applied egg-rr56.5%
metadata-eval56.5%
distribute-neg-frac56.5%
unsub-neg56.5%
*-rgt-identity56.5%
*-inverses56.5%
associate-/r*6.7%
*-commutative6.7%
*-lft-identity6.7%
associate-/r*56.5%
associate-*r/56.5%
associate-*l/56.5%
distribute-lft-out--56.5%
*-inverses56.5%
div-sub56.5%
associate--r+62.4%
*-commutative62.4%
times-frac62.4%
Simplified98.7%
flip3--30.0%
associate-*r/19.0%
metadata-eval19.0%
metadata-eval19.0%
distribute-rgt-out19.0%
Applied egg-rr19.0%
associate-/l*30.0%
Simplified30.0%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
Simplified98.7%
associate-/r*99.7%
div-inv99.5%
flip3--29.8%
flip3--99.5%
sub-neg99.5%
add-sqr-sqrt0.0%
sqrt-unprod55.8%
sqr-neg55.8%
sqrt-unprod55.7%
add-sqr-sqrt55.7%
add-sqr-sqrt0.0%
sqrt-unprod98.4%
sqr-neg98.4%
sqrt-unprod99.4%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
associate-*r/99.7%
*-rgt-identity99.7%
+-commutative99.7%
Simplified99.7%
Final simplification77.3%
(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.2%
sub-neg79.2%
+-commutative79.2%
distribute-neg-frac279.2%
neg-sub079.2%
associate-+l-79.2%
neg-sub079.2%
remove-double-neg79.2%
distribute-neg-in79.2%
sub-neg79.2%
distribute-neg-frac279.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
metadata-eval79.2%
Simplified79.2%
sub-neg79.2%
distribute-neg-frac79.2%
metadata-eval79.2%
Applied egg-rr79.2%
metadata-eval79.2%
distribute-neg-frac79.2%
unsub-neg79.2%
*-rgt-identity79.2%
*-inverses79.2%
associate-/r*54.1%
*-commutative54.1%
*-lft-identity54.1%
associate-/r*79.2%
associate-*r/79.2%
associate-*l/79.2%
distribute-lft-out--79.2%
*-inverses79.2%
div-sub79.5%
associate--r+82.3%
*-commutative82.3%
times-frac82.3%
Simplified99.4%
(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.2%
sub-neg79.2%
+-commutative79.2%
distribute-neg-frac279.2%
neg-sub079.2%
associate-+l-79.2%
neg-sub079.2%
remove-double-neg79.2%
distribute-neg-in79.2%
sub-neg79.2%
distribute-neg-frac279.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
metadata-eval79.2%
Simplified79.2%
sub-neg79.2%
distribute-neg-frac79.2%
metadata-eval79.2%
Applied egg-rr79.2%
metadata-eval79.2%
distribute-neg-frac79.2%
unsub-neg79.2%
*-rgt-identity79.2%
*-inverses79.2%
associate-/r*54.1%
*-commutative54.1%
*-lft-identity54.1%
associate-/r*79.2%
associate-*r/79.2%
associate-*l/79.2%
distribute-lft-out--79.2%
*-inverses79.2%
div-sub79.5%
associate--r+82.3%
*-commutative82.3%
times-frac82.3%
Simplified99.4%
flip3--65.0%
associate-*r/59.4%
metadata-eval59.4%
metadata-eval59.4%
distribute-rgt-out59.4%
Applied egg-rr59.4%
associate-/l*65.0%
Simplified65.0%
Taylor expanded in x around 0 52.7%
Final simplification52.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 79.2%
sub-neg79.2%
+-commutative79.2%
distribute-neg-frac279.2%
neg-sub079.2%
associate-+l-79.2%
neg-sub079.2%
remove-double-neg79.2%
distribute-neg-in79.2%
sub-neg79.2%
distribute-neg-frac279.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
metadata-eval79.2%
Simplified79.2%
Taylor expanded in x around 0 51.1%
(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.2%
sub-neg79.2%
+-commutative79.2%
distribute-neg-frac279.2%
neg-sub079.2%
associate-+l-79.2%
neg-sub079.2%
remove-double-neg79.2%
distribute-neg-in79.2%
sub-neg79.2%
distribute-neg-frac279.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
sub-neg79.2%
+-commutative79.2%
unsub-neg79.2%
metadata-eval79.2%
Simplified79.2%
Taylor expanded in x around 0 51.1%
Taylor expanded in x around inf 10.8%
herbie shell --seed 2024086
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))