
(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 7 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 75.7%
sub-neg75.7%
+-commutative75.7%
distribute-neg-frac275.7%
neg-sub075.7%
associate-+l-75.7%
neg-sub075.7%
remove-double-neg75.7%
distribute-neg-in75.7%
sub-neg75.7%
distribute-neg-frac275.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
metadata-eval75.7%
Simplified75.7%
frac-sub77.1%
*-rgt-identity77.1%
metadata-eval77.1%
div-inv77.1%
associate-/r*77.1%
metadata-eval77.1%
div-inv77.1%
*-un-lft-identity77.1%
associate--l-80.2%
div-inv80.2%
metadata-eval80.2%
*-rgt-identity80.2%
div-inv80.2%
metadata-eval80.2%
*-rgt-identity80.2%
Applied egg-rr80.2%
div-sub80.2%
sub-neg80.2%
frac-2neg80.2%
metadata-eval80.2%
flip--80.2%
metadata-eval80.2%
unpow280.2%
+-commutative80.2%
distribute-neg-frac280.2%
metadata-eval80.2%
unpow280.2%
mul-1-neg80.2%
+-commutative80.2%
distribute-lft-in80.2%
metadata-eval80.2%
neg-mul-180.2%
sub-neg80.2%
flip-+80.2%
+-commutative80.2%
Applied egg-rr80.2%
sub-neg80.2%
+-commutative80.2%
metadata-eval80.2%
associate--r-80.2%
neg-sub080.2%
distribute-frac-neg280.2%
distribute-neg-frac80.2%
metadata-eval80.2%
*-rgt-identity80.2%
cancel-sign-sub80.2%
neg-sub080.2%
associate--r-80.2%
metadata-eval80.2%
+-commutative80.2%
*-rgt-identity80.2%
div-sub80.2%
associate-+l-77.1%
*-lft-identity77.1%
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(2.0 / Float64(-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 81.9%
sub-neg81.9%
+-commutative81.9%
distribute-neg-frac281.9%
neg-sub081.9%
associate-+l-81.9%
neg-sub081.9%
remove-double-neg81.9%
distribute-neg-in81.9%
sub-neg81.9%
distribute-neg-frac281.9%
sub-neg81.9%
+-commutative81.9%
unsub-neg81.9%
sub-neg81.9%
+-commutative81.9%
unsub-neg81.9%
metadata-eval81.9%
Simplified81.9%
Taylor expanded in x around 0 63.6%
if 1 < x Initial program 55.8%
sub-neg55.8%
+-commutative55.8%
distribute-neg-frac255.8%
neg-sub055.8%
associate-+l-55.8%
neg-sub055.8%
remove-double-neg55.8%
distribute-neg-in55.8%
sub-neg55.8%
distribute-neg-frac255.8%
sub-neg55.8%
+-commutative55.8%
unsub-neg55.8%
sub-neg55.8%
+-commutative55.8%
unsub-neg55.8%
metadata-eval55.8%
Simplified55.8%
frac-sub56.4%
*-rgt-identity56.4%
metadata-eval56.4%
div-inv56.4%
associate-/r*56.4%
metadata-eval56.4%
div-inv56.4%
*-un-lft-identity56.4%
associate--l-62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in x around inf 97.9%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
Simplified98.7%
Final simplification71.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(2.0 / Float64(-Float64(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[(2.0 / (-N[(x * x), $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{-x \cdot x}\\
\end{array}
\end{array}
if x < 1Initial program 81.9%
sub-neg81.9%
+-commutative81.9%
distribute-neg-frac281.9%
neg-sub081.9%
associate-+l-81.9%
neg-sub081.9%
remove-double-neg81.9%
distribute-neg-in81.9%
sub-neg81.9%
distribute-neg-frac281.9%
sub-neg81.9%
+-commutative81.9%
unsub-neg81.9%
sub-neg81.9%
+-commutative81.9%
unsub-neg81.9%
metadata-eval81.9%
Simplified81.9%
Taylor expanded in x around 0 63.6%
if 1 < x Initial program 55.8%
sub-neg55.8%
+-commutative55.8%
distribute-neg-frac255.8%
neg-sub055.8%
associate-+l-55.8%
neg-sub055.8%
remove-double-neg55.8%
distribute-neg-in55.8%
sub-neg55.8%
distribute-neg-frac255.8%
sub-neg55.8%
+-commutative55.8%
unsub-neg55.8%
sub-neg55.8%
+-commutative55.8%
unsub-neg55.8%
metadata-eval55.8%
Simplified55.8%
frac-sub56.4%
*-rgt-identity56.4%
metadata-eval56.4%
div-inv56.4%
associate-/r*56.4%
metadata-eval56.4%
div-inv56.4%
*-un-lft-identity56.4%
associate--l-62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in x around inf 97.9%
*-un-lft-identity97.9%
Applied egg-rr97.9%
*-lft-identity97.9%
associate-/l/96.2%
*-commutative96.2%
Simplified96.2%
Taylor expanded in x around inf 97.0%
neg-mul-198.7%
Simplified97.0%
Final simplification71.5%
(FPCore (x) :precision binary64 (/ -2.0 (* (+ 1.0 x) (+ x -1.0))))
double code(double x) {
return -2.0 / ((1.0 + x) * (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((1.0d0 + x) * (x + (-1.0d0)))
end function
public static double code(double x) {
return -2.0 / ((1.0 + x) * (x + -1.0));
}
def code(x): return -2.0 / ((1.0 + x) * (x + -1.0))
function code(x) return Float64(-2.0 / Float64(Float64(1.0 + x) * Float64(x + -1.0))) end
function tmp = code(x) tmp = -2.0 / ((1.0 + x) * (x + -1.0)); end
code[x_] := N[(-2.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(1 + x\right) \cdot \left(x + -1\right)}
\end{array}
Initial program 75.7%
sub-neg75.7%
+-commutative75.7%
distribute-neg-frac275.7%
neg-sub075.7%
associate-+l-75.7%
neg-sub075.7%
remove-double-neg75.7%
distribute-neg-in75.7%
sub-neg75.7%
distribute-neg-frac275.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
metadata-eval75.7%
Simplified75.7%
sub-neg75.7%
distribute-neg-frac75.7%
metadata-eval75.7%
Applied egg-rr75.7%
Simplified99.4%
Final simplification99.4%
(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 81.9%
sub-neg81.9%
+-commutative81.9%
distribute-neg-frac281.9%
neg-sub081.9%
associate-+l-81.9%
neg-sub081.9%
remove-double-neg81.9%
distribute-neg-in81.9%
sub-neg81.9%
distribute-neg-frac281.9%
sub-neg81.9%
+-commutative81.9%
unsub-neg81.9%
sub-neg81.9%
+-commutative81.9%
unsub-neg81.9%
metadata-eval81.9%
Simplified81.9%
Taylor expanded in x around 0 63.6%
if 1 < x Initial program 55.8%
sub-neg55.8%
+-commutative55.8%
distribute-neg-frac255.8%
neg-sub055.8%
associate-+l-55.8%
neg-sub055.8%
remove-double-neg55.8%
distribute-neg-in55.8%
sub-neg55.8%
distribute-neg-frac255.8%
sub-neg55.8%
+-commutative55.8%
unsub-neg55.8%
sub-neg55.8%
+-commutative55.8%
unsub-neg55.8%
metadata-eval55.8%
Simplified55.8%
frac-sub56.4%
*-rgt-identity56.4%
metadata-eval56.4%
div-inv56.4%
associate-/r*56.4%
metadata-eval56.4%
div-inv56.4%
*-un-lft-identity56.4%
associate--l-62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
div-inv62.3%
metadata-eval62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in x around inf 97.9%
Taylor expanded in x around 0 6.8%
(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 75.7%
sub-neg75.7%
+-commutative75.7%
distribute-neg-frac275.7%
neg-sub075.7%
associate-+l-75.7%
neg-sub075.7%
remove-double-neg75.7%
distribute-neg-in75.7%
sub-neg75.7%
distribute-neg-frac275.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
metadata-eval75.7%
Simplified75.7%
frac-sub77.1%
*-rgt-identity77.1%
metadata-eval77.1%
div-inv77.1%
associate-/r*77.1%
metadata-eval77.1%
div-inv77.1%
*-un-lft-identity77.1%
associate--l-80.2%
div-inv80.2%
metadata-eval80.2%
*-rgt-identity80.2%
div-inv80.2%
metadata-eval80.2%
*-rgt-identity80.2%
Applied egg-rr80.2%
Taylor expanded in x around 0 50.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 75.7%
sub-neg75.7%
+-commutative75.7%
distribute-neg-frac275.7%
neg-sub075.7%
associate-+l-75.7%
neg-sub075.7%
remove-double-neg75.7%
distribute-neg-in75.7%
sub-neg75.7%
distribute-neg-frac275.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
sub-neg75.7%
+-commutative75.7%
unsub-neg75.7%
metadata-eval75.7%
Simplified75.7%
Taylor expanded in x around 0 49.1%
herbie shell --seed 2024117
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))