
(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 (+ 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 76.8%
sub-neg76.8%
+-commutative76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
metadata-eval76.8%
metadata-eval76.8%
associate-/r*76.8%
metadata-eval76.8%
neg-mul-176.8%
sub0-neg76.8%
associate-+l-76.8%
neg-sub076.8%
metadata-eval76.8%
metadata-eval76.8%
metadata-eval76.8%
associate-/r*76.8%
metadata-eval76.8%
neg-mul-176.8%
distribute-neg-in76.8%
sub-neg76.8%
distribute-neg-frac76.8%
neg-mul-176.8%
Simplified76.8%
frac-sub78.0%
*-rgt-identity78.0%
metadata-eval78.0%
div-inv78.0%
associate-/r*78.0%
*-un-lft-identity78.0%
metadata-eval78.0%
div-inv78.0%
associate--l-81.0%
div-inv81.0%
metadata-eval81.0%
*-rgt-identity81.0%
div-inv81.0%
metadata-eval81.0%
*-rgt-identity81.0%
Applied egg-rr81.0%
div-sub81.0%
sub-neg81.0%
+-commutative81.0%
associate-+l-99.9%
Applied egg-rr99.9%
+-inverses99.9%
metadata-eval99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
count-299.9%
sub-neg99.9%
metadata-eval99.9%
distribute-neg-in99.9%
neg-mul-199.9%
associate-/r*99.9%
metadata-eval99.9%
associate-*r/99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ 2.0 (* 2.0 (* x x))) (/ (/ -2.0 x) x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0 + (2.0 * (x * x));
} 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 + (2.0d0 * (x * x))
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 + (2.0 * (x * x));
} else {
tmp = (-2.0 / x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 + (2.0 * (x * x)) else: tmp = (-2.0 / x) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(2.0 + Float64(2.0 * Float64(x * x))); 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 + (2.0 * (x * x)); else tmp = (-2.0 / x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(2.0 + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2 + 2 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 82.5%
sub-neg82.5%
+-commutative82.5%
distribute-neg-frac82.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
sub0-neg82.5%
associate-+l-82.5%
neg-sub082.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
distribute-neg-in82.5%
sub-neg82.5%
distribute-neg-frac82.5%
neg-mul-182.5%
Simplified82.5%
Taylor expanded in x around 0 67.3%
unpow232.9%
Applied egg-rr67.3%
if 1 < x Initial program 53.8%
sub-neg53.8%
+-commutative53.8%
distribute-neg-frac53.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
sub0-neg53.8%
associate-+l-53.8%
neg-sub053.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
distribute-neg-in53.8%
sub-neg53.8%
distribute-neg-frac53.8%
neg-mul-153.8%
Simplified53.8%
Taylor expanded in x around inf 96.5%
clear-num96.5%
associate-/r/96.5%
pow-flip97.7%
metadata-eval97.7%
Applied egg-rr97.7%
metadata-eval97.7%
pow-flip96.5%
pow296.4%
associate-/r/96.4%
clear-num96.4%
associate-/r*97.6%
Applied egg-rr97.6%
Final simplification73.4%
(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(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 82.5%
sub-neg82.5%
+-commutative82.5%
distribute-neg-frac82.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
sub0-neg82.5%
associate-+l-82.5%
neg-sub082.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
distribute-neg-in82.5%
sub-neg82.5%
distribute-neg-frac82.5%
neg-mul-182.5%
Simplified82.5%
Taylor expanded in x around 0 67.6%
if 1 < x Initial program 53.8%
sub-neg53.8%
+-commutative53.8%
distribute-neg-frac53.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
sub0-neg53.8%
associate-+l-53.8%
neg-sub053.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
distribute-neg-in53.8%
sub-neg53.8%
distribute-neg-frac53.8%
neg-mul-153.8%
Simplified53.8%
Taylor expanded in x around inf 96.5%
unpow296.4%
Applied egg-rr96.4%
Final simplification73.4%
(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 82.5%
sub-neg82.5%
+-commutative82.5%
distribute-neg-frac82.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
sub0-neg82.5%
associate-+l-82.5%
neg-sub082.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
distribute-neg-in82.5%
sub-neg82.5%
distribute-neg-frac82.5%
neg-mul-182.5%
Simplified82.5%
Taylor expanded in x around 0 67.6%
if 1 < x Initial program 53.8%
sub-neg53.8%
+-commutative53.8%
distribute-neg-frac53.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
sub0-neg53.8%
associate-+l-53.8%
neg-sub053.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
distribute-neg-in53.8%
sub-neg53.8%
distribute-neg-frac53.8%
neg-mul-153.8%
Simplified53.8%
Taylor expanded in x around inf 96.5%
clear-num96.5%
associate-/r/96.5%
pow-flip97.7%
metadata-eval97.7%
Applied egg-rr97.7%
metadata-eval97.7%
pow-flip96.5%
pow296.4%
associate-/r/96.4%
clear-num96.4%
associate-/r*97.6%
Applied egg-rr97.6%
Final simplification73.6%
(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(2.0 / Float64(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[(2.0 / N[(N[(x + -1.0), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(x + -1\right) \cdot \left(-1 - x\right)}
\end{array}
Initial program 76.8%
sub-neg76.8%
+-commutative76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
metadata-eval76.8%
metadata-eval76.8%
associate-/r*76.8%
metadata-eval76.8%
neg-mul-176.8%
sub0-neg76.8%
associate-+l-76.8%
neg-sub076.8%
metadata-eval76.8%
metadata-eval76.8%
metadata-eval76.8%
associate-/r*76.8%
metadata-eval76.8%
neg-mul-176.8%
distribute-neg-in76.8%
sub-neg76.8%
distribute-neg-frac76.8%
neg-mul-176.8%
Simplified76.8%
sub-neg76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
Applied egg-rr76.8%
*-rgt-identity76.8%
cancel-sign-sub76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
*-inverses76.8%
associate-/r*58.2%
distribute-lft-neg-in58.2%
distribute-rgt-neg-in58.2%
*-commutative58.2%
*-commutative58.2%
*-inverses58.2%
times-frac76.8%
div-sub78.0%
Simplified99.3%
Final simplification99.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 82.5%
sub-neg82.5%
+-commutative82.5%
distribute-neg-frac82.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
sub0-neg82.5%
associate-+l-82.5%
neg-sub082.5%
metadata-eval82.5%
metadata-eval82.5%
metadata-eval82.5%
associate-/r*82.5%
metadata-eval82.5%
neg-mul-182.5%
distribute-neg-in82.5%
sub-neg82.5%
distribute-neg-frac82.5%
neg-mul-182.5%
Simplified82.5%
Taylor expanded in x around 0 67.6%
if 1 < x Initial program 53.8%
sub-neg53.8%
+-commutative53.8%
distribute-neg-frac53.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
sub0-neg53.8%
associate-+l-53.8%
neg-sub053.8%
metadata-eval53.8%
metadata-eval53.8%
metadata-eval53.8%
associate-/r*53.8%
metadata-eval53.8%
neg-mul-153.8%
distribute-neg-in53.8%
sub-neg53.8%
distribute-neg-frac53.8%
neg-mul-153.8%
Simplified53.8%
frac-sub56.5%
*-rgt-identity56.5%
metadata-eval56.5%
div-inv56.5%
associate-/r*56.5%
*-un-lft-identity56.5%
metadata-eval56.5%
div-inv56.5%
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 96.5%
Taylor expanded in x around 0 7.7%
Final simplification55.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 76.8%
sub-neg76.8%
+-commutative76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
metadata-eval76.8%
metadata-eval76.8%
associate-/r*76.8%
metadata-eval76.8%
neg-mul-176.8%
sub0-neg76.8%
associate-+l-76.8%
neg-sub076.8%
metadata-eval76.8%
metadata-eval76.8%
metadata-eval76.8%
associate-/r*76.8%
metadata-eval76.8%
neg-mul-176.8%
distribute-neg-in76.8%
sub-neg76.8%
distribute-neg-frac76.8%
neg-mul-176.8%
Simplified76.8%
Taylor expanded in x around 0 54.7%
Final simplification54.7%
herbie shell --seed 2024020
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))