
(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 5 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 (+ x -1.0)))))
double code(double x) {
return -2.0 / ((x + -1.0) + (x * (x + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((x + (-1.0d0)) + (x * (x + (-1.0d0))))
end function
public static double code(double x) {
return -2.0 / ((x + -1.0) + (x * (x + -1.0)));
}
def code(x): return -2.0 / ((x + -1.0) + (x * (x + -1.0)))
function code(x) return Float64(-2.0 / Float64(Float64(x + -1.0) + Float64(x * Float64(x + -1.0)))) end
function tmp = code(x) tmp = -2.0 / ((x + -1.0) + (x * (x + -1.0))); end
code[x_] := N[(-2.0 / N[(N[(x + -1.0), $MachinePrecision] + N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(x + -1\right) + x \cdot \left(x + -1\right)}
\end{array}
Initial program 82.8%
sub-neg82.8%
+-commutative82.8%
distribute-neg-frac282.8%
neg-sub082.8%
associate-+l-82.8%
neg-sub082.8%
remove-double-neg82.8%
distribute-neg-in82.8%
sub-neg82.8%
distribute-neg-frac282.8%
sub-neg82.8%
+-commutative82.8%
unsub-neg82.8%
sub-neg82.8%
+-commutative82.8%
unsub-neg82.8%
metadata-eval82.8%
Simplified82.8%
sub-neg82.8%
distribute-neg-frac82.8%
metadata-eval82.8%
Applied egg-rr82.8%
Simplified99.6%
*-commutative99.6%
+-commutative99.6%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
Applied egg-rr99.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ -2.0 x) x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.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) / 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 / x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (-2.0 / x) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(-2.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 / x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(-2.0 / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 90.0%
sub-neg90.0%
+-commutative90.0%
distribute-neg-frac290.0%
neg-sub090.0%
associate-+l-90.0%
neg-sub090.0%
remove-double-neg90.0%
distribute-neg-in90.0%
sub-neg90.0%
distribute-neg-frac290.0%
sub-neg90.0%
+-commutative90.0%
unsub-neg90.0%
sub-neg90.0%
+-commutative90.0%
unsub-neg90.0%
metadata-eval90.0%
Simplified90.0%
Taylor expanded in x around 0 70.3%
if 1 < x Initial program 57.1%
sub-neg57.1%
+-commutative57.1%
distribute-neg-frac257.1%
neg-sub057.1%
associate-+l-57.1%
neg-sub057.1%
remove-double-neg57.1%
distribute-neg-in57.1%
sub-neg57.1%
distribute-neg-frac257.1%
sub-neg57.1%
+-commutative57.1%
unsub-neg57.1%
sub-neg57.1%
+-commutative57.1%
unsub-neg57.1%
metadata-eval57.1%
Simplified57.1%
sub-neg57.1%
distribute-neg-frac57.1%
metadata-eval57.1%
Applied egg-rr57.1%
Simplified98.5%
Taylor expanded in x around inf 97.0%
div-inv97.0%
Applied egg-rr97.0%
associate-*r/97.0%
metadata-eval97.0%
associate-/r*98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in x around inf 99.5%
(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 82.8%
sub-neg82.8%
+-commutative82.8%
distribute-neg-frac282.8%
neg-sub082.8%
associate-+l-82.8%
neg-sub082.8%
remove-double-neg82.8%
distribute-neg-in82.8%
sub-neg82.8%
distribute-neg-frac282.8%
sub-neg82.8%
+-commutative82.8%
unsub-neg82.8%
sub-neg82.8%
+-commutative82.8%
unsub-neg82.8%
metadata-eval82.8%
Simplified82.8%
sub-neg82.8%
distribute-neg-frac82.8%
metadata-eval82.8%
Applied egg-rr82.8%
Simplified99.6%
Final simplification99.6%
(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 90.0%
sub-neg90.0%
+-commutative90.0%
distribute-neg-frac290.0%
neg-sub090.0%
associate-+l-90.0%
neg-sub090.0%
remove-double-neg90.0%
distribute-neg-in90.0%
sub-neg90.0%
distribute-neg-frac290.0%
sub-neg90.0%
+-commutative90.0%
unsub-neg90.0%
sub-neg90.0%
+-commutative90.0%
unsub-neg90.0%
metadata-eval90.0%
Simplified90.0%
Taylor expanded in x around 0 70.3%
if 1 < x Initial program 57.1%
sub-neg57.1%
+-commutative57.1%
distribute-neg-frac257.1%
neg-sub057.1%
associate-+l-57.1%
neg-sub057.1%
remove-double-neg57.1%
distribute-neg-in57.1%
sub-neg57.1%
distribute-neg-frac257.1%
sub-neg57.1%
+-commutative57.1%
unsub-neg57.1%
sub-neg57.1%
+-commutative57.1%
unsub-neg57.1%
metadata-eval57.1%
Simplified57.1%
frac-sub59.9%
*-rgt-identity59.9%
metadata-eval59.9%
div-inv59.9%
associate-/r*59.9%
metadata-eval59.9%
div-inv59.9%
*-un-lft-identity59.9%
associate--l-65.3%
div-inv65.3%
metadata-eval65.3%
*-rgt-identity65.3%
div-inv65.3%
metadata-eval65.3%
*-rgt-identity65.3%
Applied egg-rr65.3%
Taylor expanded in x around inf 98.4%
Taylor expanded in x around 0 6.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 82.8%
sub-neg82.8%
+-commutative82.8%
distribute-neg-frac282.8%
neg-sub082.8%
associate-+l-82.8%
neg-sub082.8%
remove-double-neg82.8%
distribute-neg-in82.8%
sub-neg82.8%
distribute-neg-frac282.8%
sub-neg82.8%
+-commutative82.8%
unsub-neg82.8%
sub-neg82.8%
+-commutative82.8%
unsub-neg82.8%
metadata-eval82.8%
Simplified82.8%
Taylor expanded in x around 0 55.5%
herbie shell --seed 2024155
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))