
(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(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 71.8%
sub-neg71.8%
+-commutative71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
sub0-neg71.8%
associate-+l-71.8%
neg-sub071.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
distribute-neg-in71.8%
sub-neg71.8%
distribute-neg-frac71.8%
neg-mul-171.8%
Simplified71.8%
sub-neg71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
Applied egg-rr71.8%
*-rgt-identity71.8%
cancel-sign-sub71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
*-inverses71.8%
associate-/r*52.5%
distribute-lft-neg-in52.5%
distribute-rgt-neg-in52.5%
*-commutative52.5%
*-commutative52.5%
*-inverses52.5%
times-frac71.9%
div-sub72.4%
Simplified99.9%
Final simplification99.9%
(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 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
sub0-neg79.9%
associate-+l-79.9%
neg-sub079.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac79.9%
neg-mul-179.9%
Simplified79.9%
Taylor expanded in x around 0 67.7%
if 1 < x Initial program 51.4%
sub-neg51.4%
+-commutative51.4%
distribute-neg-frac51.4%
metadata-eval51.4%
metadata-eval51.4%
metadata-eval51.4%
associate-/r*51.4%
metadata-eval51.4%
neg-mul-151.4%
sub0-neg51.4%
associate-+l-51.4%
neg-sub051.4%
metadata-eval51.4%
metadata-eval51.4%
metadata-eval51.4%
associate-/r*51.4%
metadata-eval51.4%
neg-mul-151.4%
distribute-neg-in51.4%
sub-neg51.4%
distribute-neg-frac51.4%
neg-mul-151.4%
Simplified51.4%
sub-neg51.4%
distribute-neg-frac51.4%
metadata-eval51.4%
Applied egg-rr51.4%
*-rgt-identity51.4%
cancel-sign-sub51.4%
distribute-neg-frac51.4%
metadata-eval51.4%
*-inverses51.4%
associate-/r*7.0%
distribute-lft-neg-in7.0%
distribute-rgt-neg-in7.0%
*-commutative7.0%
*-commutative7.0%
*-inverses7.0%
times-frac51.4%
div-sub52.3%
Simplified99.9%
associate-/r*99.8%
div-inv99.7%
Applied egg-rr99.7%
associate-*l/99.8%
un-div-inv99.8%
+-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 99.6%
Final simplification76.7%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (* -2.0 (/ 1.0 x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 * (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) * (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 * (1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 * (1.0 / x) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 * 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 * (1.0 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{1}{x}\\
\end{array}
\end{array}
if x < 1Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
sub0-neg79.9%
associate-+l-79.9%
neg-sub079.9%
metadata-eval79.9%
metadata-eval79.9%
metadata-eval79.9%
associate-/r*79.9%
metadata-eval79.9%
neg-mul-179.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac79.9%
neg-mul-179.9%
Simplified79.9%
Taylor expanded in x around 0 67.7%
if 1 < x Initial program 51.4%
sub-neg51.4%
+-commutative51.4%
distribute-neg-frac51.4%
metadata-eval51.4%
metadata-eval51.4%
metadata-eval51.4%
associate-/r*51.4%
metadata-eval51.4%
neg-mul-151.4%
sub0-neg51.4%
associate-+l-51.4%
neg-sub051.4%
metadata-eval51.4%
metadata-eval51.4%
metadata-eval51.4%
associate-/r*51.4%
metadata-eval51.4%
neg-mul-151.4%
distribute-neg-in51.4%
sub-neg51.4%
distribute-neg-frac51.4%
neg-mul-151.4%
Simplified51.4%
sub-neg51.4%
distribute-neg-frac51.4%
metadata-eval51.4%
Applied egg-rr51.4%
*-rgt-identity51.4%
cancel-sign-sub51.4%
distribute-neg-frac51.4%
metadata-eval51.4%
*-inverses51.4%
associate-/r*7.0%
distribute-lft-neg-in7.0%
distribute-rgt-neg-in7.0%
*-commutative7.0%
*-commutative7.0%
*-inverses7.0%
times-frac51.4%
div-sub52.3%
Simplified99.9%
associate-/r*99.8%
div-inv99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 6.4%
Taylor expanded in x around inf 6.4%
Final simplification50.5%
(FPCore (x) :precision binary64 (* -2.0 (/ 1.0 (+ -1.0 x))))
double code(double x) {
return -2.0 * (1.0 / (-1.0 + x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) * (1.0d0 / ((-1.0d0) + x))
end function
public static double code(double x) {
return -2.0 * (1.0 / (-1.0 + x));
}
def code(x): return -2.0 * (1.0 / (-1.0 + x))
function code(x) return Float64(-2.0 * Float64(1.0 / Float64(-1.0 + x))) end
function tmp = code(x) tmp = -2.0 * (1.0 / (-1.0 + x)); end
code[x_] := N[(-2.0 * N[(1.0 / N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \frac{1}{-1 + x}
\end{array}
Initial program 71.8%
sub-neg71.8%
+-commutative71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
sub0-neg71.8%
associate-+l-71.8%
neg-sub071.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
distribute-neg-in71.8%
sub-neg71.8%
distribute-neg-frac71.8%
neg-mul-171.8%
Simplified71.8%
sub-neg71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
Applied egg-rr71.8%
*-rgt-identity71.8%
cancel-sign-sub71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
*-inverses71.8%
associate-/r*52.5%
distribute-lft-neg-in52.5%
distribute-rgt-neg-in52.5%
*-commutative52.5%
*-commutative52.5%
*-inverses52.5%
times-frac71.9%
div-sub72.4%
Simplified99.9%
associate-/r*99.9%
div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 50.6%
Final simplification50.6%
(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 71.8%
sub-neg71.8%
+-commutative71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
sub0-neg71.8%
associate-+l-71.8%
neg-sub071.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
distribute-neg-in71.8%
sub-neg71.8%
distribute-neg-frac71.8%
neg-mul-171.8%
Simplified71.8%
Taylor expanded in x around 0 49.2%
Taylor expanded in x around inf 10.5%
Final simplification10.5%
(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 71.8%
sub-neg71.8%
+-commutative71.8%
distribute-neg-frac71.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
sub0-neg71.8%
associate-+l-71.8%
neg-sub071.8%
metadata-eval71.8%
metadata-eval71.8%
metadata-eval71.8%
associate-/r*71.8%
metadata-eval71.8%
neg-mul-171.8%
distribute-neg-in71.8%
sub-neg71.8%
distribute-neg-frac71.8%
neg-mul-171.8%
Simplified71.8%
Taylor expanded in x around 0 49.4%
Final simplification49.4%
herbie shell --seed 2024031
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))