
(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.8%
sub-neg77.8%
+-commutative77.8%
distribute-neg-frac77.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
associate-/r*77.8%
metadata-eval77.8%
neg-mul-177.8%
sub0-neg77.8%
associate-+l-77.8%
neg-sub077.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
associate-/r*77.8%
metadata-eval77.8%
neg-mul-177.8%
distribute-neg-in77.8%
sub-neg77.8%
distribute-neg-frac77.8%
neg-mul-177.8%
Simplified77.8%
frac-sub78.9%
*-rgt-identity78.9%
metadata-eval78.9%
div-inv78.9%
associate-/r*78.9%
*-un-lft-identity78.9%
metadata-eval78.9%
div-inv78.9%
associate--l-81.8%
div-inv81.8%
metadata-eval81.8%
*-rgt-identity81.8%
div-inv81.8%
metadata-eval81.8%
*-rgt-identity81.8%
Applied egg-rr81.8%
div-sub81.8%
sub-neg81.8%
associate-+r-81.8%
+-commutative81.8%
associate--l+99.9%
Applied egg-rr99.9%
sub-neg99.9%
metadata-eval99.9%
associate-*l/99.9%
+-inverses99.9%
metadata-eval99.9%
*-rgt-identity99.9%
distribute-lft-out--99.9%
metadata-eval99.9%
+-inverses99.9%
associate-+r-81.8%
+-commutative81.8%
associate-+l-78.9%
associate--l-78.9%
associate-*l/78.9%
sub-neg78.9%
metadata-eval78.9%
distribute-neg-in78.9%
neg-mul-178.9%
times-frac78.9%
metadata-eval78.9%
associate-*r/78.9%
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(2.0 / Float64(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[(2.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot \left(-1 - x\right)}\\
\end{array}
\end{array}
if x < 1Initial program 84.9%
sub-neg84.9%
+-commutative84.9%
distribute-neg-frac84.9%
metadata-eval84.9%
metadata-eval84.9%
metadata-eval84.9%
associate-/r*84.9%
metadata-eval84.9%
neg-mul-184.9%
sub0-neg84.9%
associate-+l-84.9%
neg-sub084.9%
metadata-eval84.9%
metadata-eval84.9%
metadata-eval84.9%
associate-/r*84.9%
metadata-eval84.9%
neg-mul-184.9%
distribute-neg-in84.9%
sub-neg84.9%
distribute-neg-frac84.9%
neg-mul-184.9%
Simplified84.9%
Taylor expanded in x around 0 63.6%
if 1 < x Initial program 53.6%
sub-neg53.6%
+-commutative53.6%
distribute-neg-frac53.6%
metadata-eval53.6%
metadata-eval53.6%
metadata-eval53.6%
associate-/r*53.6%
metadata-eval53.6%
neg-mul-153.6%
sub0-neg53.6%
associate-+l-53.6%
neg-sub053.6%
metadata-eval53.6%
metadata-eval53.6%
metadata-eval53.6%
associate-/r*53.6%
metadata-eval53.6%
neg-mul-153.6%
distribute-neg-in53.6%
sub-neg53.6%
distribute-neg-frac53.6%
neg-mul-153.6%
Simplified53.6%
frac-sub57.4%
*-rgt-identity57.4%
metadata-eval57.4%
div-inv57.4%
associate-/r*57.4%
*-un-lft-identity57.4%
metadata-eval57.4%
div-inv57.4%
associate--l-63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
Applied egg-rr63.1%
Taylor expanded in x around inf 94.3%
expm1-log1p-u94.3%
expm1-udef48.0%
associate-/l/48.0%
*-commutative48.0%
Applied egg-rr48.0%
expm1-def92.5%
expm1-log1p92.5%
Simplified92.5%
Final simplification70.1%
(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 84.9%
sub-neg84.9%
+-commutative84.9%
distribute-neg-frac84.9%
metadata-eval84.9%
metadata-eval84.9%
metadata-eval84.9%
associate-/r*84.9%
metadata-eval84.9%
neg-mul-184.9%
sub0-neg84.9%
associate-+l-84.9%
neg-sub084.9%
metadata-eval84.9%
metadata-eval84.9%
metadata-eval84.9%
associate-/r*84.9%
metadata-eval84.9%
neg-mul-184.9%
distribute-neg-in84.9%
sub-neg84.9%
distribute-neg-frac84.9%
neg-mul-184.9%
Simplified84.9%
Taylor expanded in x around 0 63.6%
if 1 < x Initial program 53.6%
sub-neg53.6%
+-commutative53.6%
distribute-neg-frac53.6%
metadata-eval53.6%
metadata-eval53.6%
metadata-eval53.6%
associate-/r*53.6%
metadata-eval53.6%
neg-mul-153.6%
sub0-neg53.6%
associate-+l-53.6%
neg-sub053.6%
metadata-eval53.6%
metadata-eval53.6%
metadata-eval53.6%
associate-/r*53.6%
metadata-eval53.6%
neg-mul-153.6%
distribute-neg-in53.6%
sub-neg53.6%
distribute-neg-frac53.6%
neg-mul-153.6%
Simplified53.6%
frac-sub57.4%
*-rgt-identity57.4%
metadata-eval57.4%
div-inv57.4%
associate-/r*57.4%
*-un-lft-identity57.4%
metadata-eval57.4%
div-inv57.4%
associate--l-63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
Applied egg-rr63.1%
Taylor expanded in x around inf 94.3%
Final simplification70.5%
(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 77.8%
sub-neg77.8%
+-commutative77.8%
distribute-neg-frac77.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
associate-/r*77.8%
metadata-eval77.8%
neg-mul-177.8%
sub0-neg77.8%
associate-+l-77.8%
neg-sub077.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
associate-/r*77.8%
metadata-eval77.8%
neg-mul-177.8%
distribute-neg-in77.8%
sub-neg77.8%
distribute-neg-frac77.8%
neg-mul-177.8%
Simplified77.8%
sub-neg77.8%
distribute-neg-frac77.8%
metadata-eval77.8%
Applied egg-rr77.8%
*-rgt-identity77.8%
cancel-sign-sub77.8%
distribute-neg-frac77.8%
metadata-eval77.8%
*-inverses77.8%
associate-/r*54.6%
distribute-lft-neg-in54.6%
distribute-rgt-neg-in54.6%
*-commutative54.6%
*-commutative54.6%
*-inverses54.6%
times-frac77.8%
div-sub78.9%
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 84.9%
sub-neg84.9%
+-commutative84.9%
distribute-neg-frac84.9%
metadata-eval84.9%
metadata-eval84.9%
metadata-eval84.9%
associate-/r*84.9%
metadata-eval84.9%
neg-mul-184.9%
sub0-neg84.9%
associate-+l-84.9%
neg-sub084.9%
metadata-eval84.9%
metadata-eval84.9%
metadata-eval84.9%
associate-/r*84.9%
metadata-eval84.9%
neg-mul-184.9%
distribute-neg-in84.9%
sub-neg84.9%
distribute-neg-frac84.9%
neg-mul-184.9%
Simplified84.9%
Taylor expanded in x around 0 63.6%
if 1 < x Initial program 53.6%
sub-neg53.6%
+-commutative53.6%
distribute-neg-frac53.6%
metadata-eval53.6%
metadata-eval53.6%
metadata-eval53.6%
associate-/r*53.6%
metadata-eval53.6%
neg-mul-153.6%
sub0-neg53.6%
associate-+l-53.6%
neg-sub053.6%
metadata-eval53.6%
metadata-eval53.6%
metadata-eval53.6%
associate-/r*53.6%
metadata-eval53.6%
neg-mul-153.6%
distribute-neg-in53.6%
sub-neg53.6%
distribute-neg-frac53.6%
neg-mul-153.6%
Simplified53.6%
frac-sub57.4%
*-rgt-identity57.4%
metadata-eval57.4%
div-inv57.4%
associate-/r*57.4%
*-un-lft-identity57.4%
metadata-eval57.4%
div-inv57.4%
associate--l-63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
Applied egg-rr63.1%
Taylor expanded in x around inf 94.3%
Taylor expanded in x around 0 7.4%
Final simplification50.8%
(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.8%
sub-neg77.8%
+-commutative77.8%
distribute-neg-frac77.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
associate-/r*77.8%
metadata-eval77.8%
neg-mul-177.8%
sub0-neg77.8%
associate-+l-77.8%
neg-sub077.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
associate-/r*77.8%
metadata-eval77.8%
neg-mul-177.8%
distribute-neg-in77.8%
sub-neg77.8%
distribute-neg-frac77.8%
neg-mul-177.8%
Simplified77.8%
Taylor expanded in x around 0 49.8%
Final simplification49.8%
herbie shell --seed 2024021
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))