
(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 (* (+ x 1.0) (+ x -1.0))))
double code(double x) {
return -2.0 / ((x + 1.0) * (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((x + 1.0d0) * (x + (-1.0d0)))
end function
public static double code(double x) {
return -2.0 / ((x + 1.0) * (x + -1.0));
}
def code(x): return -2.0 / ((x + 1.0) * (x + -1.0))
function code(x) return Float64(-2.0 / Float64(Float64(x + 1.0) * Float64(x + -1.0))) end
function tmp = code(x) tmp = -2.0 / ((x + 1.0) * (x + -1.0)); end
code[x_] := N[(-2.0 / N[(N[(x + 1.0), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(x + 1\right) \cdot \left(x + -1\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%
Simplified99.7%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ 2.0 x) (- -1.0 x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (-1.0 - 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 / x) / ((-1.0d0) - 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 / x) / (-1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (2.0 / x) / (-1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(2.0 / x) / Float64(-1.0 - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = (2.0 / x) / (-1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{-1 - x}\\
\end{array}
\end{array}
if x < 1Initial program 85.6%
sub-neg85.6%
+-commutative85.6%
distribute-neg-frac285.6%
neg-sub085.6%
associate-+l-85.6%
neg-sub085.6%
remove-double-neg85.6%
distribute-neg-in85.6%
sub-neg85.6%
distribute-neg-frac285.6%
sub-neg85.6%
+-commutative85.6%
unsub-neg85.6%
sub-neg85.6%
+-commutative85.6%
unsub-neg85.6%
metadata-eval85.6%
Simplified85.6%
Taylor expanded in x around 0 69.7%
if 1 < x Initial program 62.2%
sub-neg62.2%
+-commutative62.2%
distribute-neg-frac262.2%
neg-sub062.2%
associate-+l-62.2%
neg-sub062.2%
remove-double-neg62.2%
distribute-neg-in62.2%
sub-neg62.2%
distribute-neg-frac262.2%
sub-neg62.2%
+-commutative62.2%
unsub-neg62.2%
sub-neg62.2%
+-commutative62.2%
unsub-neg62.2%
metadata-eval62.2%
Simplified62.2%
frac-sub62.3%
*-rgt-identity62.3%
metadata-eval62.3%
div-inv62.3%
associate-/r*62.3%
metadata-eval62.3%
div-inv62.3%
*-un-lft-identity62.3%
associate--l-67.6%
div-inv67.6%
metadata-eval67.6%
*-rgt-identity67.6%
div-inv67.6%
metadata-eval67.6%
*-rgt-identity67.6%
Applied egg-rr67.6%
Taylor expanded in x around inf 97.8%
(FPCore (x) :precision binary64 (if (<= x 0.75) 2.0 (/ -2.0 (* x (+ x -1.0)))))
double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.75d0) then
tmp = 2.0d0
else
tmp = (-2.0d0) / (x * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.75: tmp = 2.0 else: tmp = -2.0 / (x * (x + -1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.75) tmp = 2.0; else tmp = Float64(-2.0 / Float64(x * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.75) tmp = 2.0; else tmp = -2.0 / (x * (x + -1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.75], 2.0, N[(-2.0 / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + -1\right)}\\
\end{array}
\end{array}
if x < 0.75Initial program 85.6%
sub-neg85.6%
+-commutative85.6%
distribute-neg-frac285.6%
neg-sub085.6%
associate-+l-85.6%
neg-sub085.6%
remove-double-neg85.6%
distribute-neg-in85.6%
sub-neg85.6%
distribute-neg-frac285.6%
sub-neg85.6%
+-commutative85.6%
unsub-neg85.6%
sub-neg85.6%
+-commutative85.6%
unsub-neg85.6%
metadata-eval85.6%
Simplified85.6%
Taylor expanded in x around 0 69.7%
if 0.75 < x Initial program 62.2%
sub-neg62.2%
+-commutative62.2%
distribute-neg-frac262.2%
neg-sub062.2%
associate-+l-62.2%
neg-sub062.2%
remove-double-neg62.2%
distribute-neg-in62.2%
sub-neg62.2%
distribute-neg-frac262.2%
sub-neg62.2%
+-commutative62.2%
unsub-neg62.2%
sub-neg62.2%
+-commutative62.2%
unsub-neg62.2%
metadata-eval62.2%
Simplified62.2%
sub-neg62.2%
distribute-neg-frac62.2%
metadata-eval62.2%
Applied egg-rr62.2%
Simplified99.4%
Taylor expanded in x around inf 97.3%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / 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) / 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 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = -2.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < 1Initial program 85.6%
sub-neg85.6%
+-commutative85.6%
distribute-neg-frac285.6%
neg-sub085.6%
associate-+l-85.6%
neg-sub085.6%
remove-double-neg85.6%
distribute-neg-in85.6%
sub-neg85.6%
distribute-neg-frac285.6%
sub-neg85.6%
+-commutative85.6%
unsub-neg85.6%
sub-neg85.6%
+-commutative85.6%
unsub-neg85.6%
metadata-eval85.6%
Simplified85.6%
Taylor expanded in x around 0 69.7%
if 1 < x Initial program 62.2%
sub-neg62.2%
+-commutative62.2%
distribute-neg-frac262.2%
neg-sub062.2%
associate-+l-62.2%
neg-sub062.2%
remove-double-neg62.2%
distribute-neg-in62.2%
sub-neg62.2%
distribute-neg-frac262.2%
sub-neg62.2%
+-commutative62.2%
unsub-neg62.2%
sub-neg62.2%
+-commutative62.2%
unsub-neg62.2%
metadata-eval62.2%
Simplified62.2%
frac-sub62.3%
*-rgt-identity62.3%
metadata-eval62.3%
div-inv62.3%
associate-/r*62.3%
metadata-eval62.3%
div-inv62.3%
*-un-lft-identity62.3%
associate--l-67.6%
div-inv67.6%
metadata-eval67.6%
*-rgt-identity67.6%
div-inv67.6%
metadata-eval67.6%
*-rgt-identity67.6%
Applied egg-rr67.6%
Taylor expanded in x around inf 97.8%
Taylor expanded in x around 0 7.1%
(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}
\\
\frac{-2}{-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-sub79.9%
*-rgt-identity79.9%
metadata-eval79.9%
div-inv79.9%
associate-/r*79.9%
metadata-eval79.9%
div-inv79.9%
*-un-lft-identity79.9%
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%
Taylor expanded in x around 0 53.6%
(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 52.4%
herbie shell --seed 2024132
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))