
(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)) (- -1.0 x)))
double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x + (-1.0d0))) / ((-1.0d0) - x)
end function
public static double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
def code(x): return (2.0 / (x + -1.0)) / (-1.0 - x)
function code(x) return Float64(Float64(2.0 / Float64(x + -1.0)) / Float64(-1.0 - x)) end
function tmp = code(x) tmp = (2.0 / (x + -1.0)) / (-1.0 - x); end
code[x_] := N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x + -1}}{-1 - x}
\end{array}
Initial program 77.7%
sub-neg77.7%
+-commutative77.7%
distribute-neg-frac277.7%
neg-sub077.7%
associate-+l-77.7%
neg-sub077.7%
remove-double-neg77.7%
distribute-neg-in77.7%
sub-neg77.7%
distribute-neg-frac277.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
metadata-eval77.7%
Simplified77.7%
frac-sub78.4%
*-rgt-identity78.4%
metadata-eval78.4%
div-inv78.4%
associate-/r*78.4%
metadata-eval78.4%
div-inv78.4%
*-un-lft-identity78.4%
associate--l-81.3%
div-inv81.3%
metadata-eval81.3%
*-rgt-identity81.3%
div-inv81.3%
metadata-eval81.3%
*-rgt-identity81.3%
Applied egg-rr81.3%
div-sub81.3%
sub-neg81.3%
frac-2neg81.3%
metadata-eval81.3%
flip--81.3%
metadata-eval81.3%
metadata-eval81.3%
+-commutative81.3%
distribute-neg-frac281.3%
mul-1-neg81.3%
+-commutative81.3%
distribute-lft-in81.3%
metadata-eval81.3%
neg-mul-181.3%
sub-neg81.3%
flip-+81.3%
+-commutative81.3%
associate-+r-81.3%
+-commutative81.3%
associate--l+99.9%
Applied egg-rr99.9%
distribute-neg-frac299.9%
+-inverses99.9%
metadata-eval99.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
count-299.9%
associate-*r/99.9%
metadata-eval99.9%
Simplified99.9%
(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(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 86.6%
sub-neg86.6%
+-commutative86.6%
distribute-neg-frac286.6%
neg-sub086.6%
associate-+l-86.6%
neg-sub086.6%
remove-double-neg86.6%
distribute-neg-in86.6%
sub-neg86.6%
distribute-neg-frac286.6%
sub-neg86.6%
+-commutative86.6%
unsub-neg86.6%
sub-neg86.6%
+-commutative86.6%
unsub-neg86.6%
metadata-eval86.6%
Simplified86.6%
Taylor expanded in x around 0 69.0%
if 1 < x Initial program 51.6%
sub-neg51.6%
+-commutative51.6%
distribute-neg-frac251.6%
neg-sub051.6%
associate-+l-51.6%
neg-sub051.6%
remove-double-neg51.6%
distribute-neg-in51.6%
sub-neg51.6%
distribute-neg-frac251.6%
sub-neg51.6%
+-commutative51.6%
unsub-neg51.6%
sub-neg51.6%
+-commutative51.6%
unsub-neg51.6%
metadata-eval51.6%
Simplified51.6%
frac-sub52.9%
*-rgt-identity52.9%
metadata-eval52.9%
div-inv52.9%
associate-/r*52.9%
metadata-eval52.9%
div-inv52.9%
*-un-lft-identity52.9%
associate--l-59.4%
div-inv59.4%
metadata-eval59.4%
*-rgt-identity59.4%
div-inv59.4%
metadata-eval59.4%
*-rgt-identity59.4%
Applied egg-rr59.4%
div-sub59.4%
sub-neg59.4%
frac-2neg59.4%
metadata-eval59.4%
flip--59.4%
metadata-eval59.4%
metadata-eval59.4%
+-commutative59.4%
distribute-neg-frac259.4%
mul-1-neg59.4%
+-commutative59.4%
distribute-lft-in59.4%
metadata-eval59.4%
neg-mul-159.4%
sub-neg59.4%
flip-+59.4%
+-commutative59.4%
associate-+r-59.4%
+-commutative59.4%
associate--l+99.8%
Applied egg-rr99.8%
distribute-neg-frac299.8%
+-inverses99.8%
metadata-eval99.8%
neg-sub099.8%
associate--r-99.8%
metadata-eval99.8%
+-commutative99.8%
count-299.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 98.6%
neg-mul-198.6%
Simplified98.6%
Taylor expanded in x around inf 99.2%
Final simplification76.7%
(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 77.7%
sub-neg77.7%
+-commutative77.7%
distribute-neg-frac277.7%
neg-sub077.7%
associate-+l-77.7%
neg-sub077.7%
remove-double-neg77.7%
distribute-neg-in77.7%
sub-neg77.7%
distribute-neg-frac277.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
metadata-eval77.7%
Simplified77.7%
sub-neg77.7%
distribute-neg-frac77.7%
metadata-eval77.7%
Applied egg-rr77.7%
Simplified98.9%
Final simplification98.9%
(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 86.6%
sub-neg86.6%
+-commutative86.6%
distribute-neg-frac286.6%
neg-sub086.6%
associate-+l-86.6%
neg-sub086.6%
remove-double-neg86.6%
distribute-neg-in86.6%
sub-neg86.6%
distribute-neg-frac286.6%
sub-neg86.6%
+-commutative86.6%
unsub-neg86.6%
sub-neg86.6%
+-commutative86.6%
unsub-neg86.6%
metadata-eval86.6%
Simplified86.6%
Taylor expanded in x around 0 69.0%
if 1 < x Initial program 51.6%
sub-neg51.6%
+-commutative51.6%
distribute-neg-frac251.6%
neg-sub051.6%
associate-+l-51.6%
neg-sub051.6%
remove-double-neg51.6%
distribute-neg-in51.6%
sub-neg51.6%
distribute-neg-frac251.6%
sub-neg51.6%
+-commutative51.6%
unsub-neg51.6%
sub-neg51.6%
+-commutative51.6%
unsub-neg51.6%
metadata-eval51.6%
Simplified51.6%
sub-neg51.6%
distribute-neg-frac51.6%
metadata-eval51.6%
Applied egg-rr51.6%
Simplified97.9%
Taylor expanded in x around inf 96.8%
Taylor expanded in x around 0 6.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 77.7%
sub-neg77.7%
+-commutative77.7%
distribute-neg-frac277.7%
neg-sub077.7%
associate-+l-77.7%
neg-sub077.7%
remove-double-neg77.7%
distribute-neg-in77.7%
sub-neg77.7%
distribute-neg-frac277.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
metadata-eval77.7%
Simplified77.7%
Taylor expanded in x around 0 52.2%
(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 77.7%
sub-neg77.7%
+-commutative77.7%
distribute-neg-frac277.7%
neg-sub077.7%
associate-+l-77.7%
neg-sub077.7%
remove-double-neg77.7%
distribute-neg-in77.7%
sub-neg77.7%
distribute-neg-frac277.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
sub-neg77.7%
+-commutative77.7%
unsub-neg77.7%
metadata-eval77.7%
Simplified77.7%
Taylor expanded in x around 0 51.6%
Taylor expanded in x around inf 10.9%
herbie shell --seed 2024110
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))