
(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 82.3%
sub-neg82.3%
+-commutative82.3%
distribute-neg-frac82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
neg-mul-182.3%
sub0-neg82.3%
associate-+l-82.3%
neg-sub082.3%
remove-double-neg82.3%
distribute-neg-in82.3%
sub-neg82.3%
mul-1-neg82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-*l/82.3%
Simplified82.3%
frac-sub82.6%
*-rgt-identity82.6%
metadata-eval82.6%
div-inv82.6%
associate-/r*82.6%
*-un-lft-identity82.6%
metadata-eval82.6%
div-inv82.6%
associate--l-85.1%
div-inv85.1%
metadata-eval85.1%
*-rgt-identity85.1%
div-inv85.1%
metadata-eval85.1%
*-rgt-identity85.1%
Applied egg-rr85.1%
div-sub85.1%
sub-neg85.1%
Applied egg-rr85.1%
metadata-eval85.1%
associate-*r/85.1%
neg-mul-185.1%
+-commutative85.1%
associate--r-99.9%
+-inverses99.9%
metadata-eval99.9%
distribute-rgt-out99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
+-inverses99.9%
associate--l+85.1%
associate-+l-82.6%
+-commutative82.6%
associate--l-82.6%
associate-*l/82.6%
associate-*r/82.6%
metadata-eval82.6%
times-frac82.6%
neg-mul-182.6%
neg-mul-182.6%
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 87.8%
sub-neg87.8%
+-commutative87.8%
distribute-neg-frac87.8%
metadata-eval87.8%
metadata-eval87.8%
metadata-eval87.8%
associate-/r*87.8%
metadata-eval87.8%
neg-mul-187.8%
sub0-neg87.8%
associate-+l-87.8%
neg-sub087.8%
remove-double-neg87.8%
distribute-neg-in87.8%
sub-neg87.8%
mul-1-neg87.8%
metadata-eval87.8%
associate-/r*87.8%
metadata-eval87.8%
metadata-eval87.8%
metadata-eval87.8%
metadata-eval87.8%
associate-*l/87.8%
Simplified87.8%
Taylor expanded in x around 0 68.3%
if 1 < x Initial program 60.3%
sub-neg60.3%
+-commutative60.3%
distribute-neg-frac60.3%
metadata-eval60.3%
metadata-eval60.3%
metadata-eval60.3%
associate-/r*60.3%
metadata-eval60.3%
neg-mul-160.3%
sub0-neg60.3%
associate-+l-60.3%
neg-sub060.3%
remove-double-neg60.3%
distribute-neg-in60.3%
sub-neg60.3%
mul-1-neg60.3%
metadata-eval60.3%
associate-/r*60.3%
metadata-eval60.3%
metadata-eval60.3%
metadata-eval60.3%
metadata-eval60.3%
associate-*l/60.3%
Simplified60.3%
frac-sub61.2%
*-rgt-identity61.2%
metadata-eval61.2%
div-inv61.2%
associate-/r*61.2%
*-un-lft-identity61.2%
metadata-eval61.2%
div-inv61.2%
associate--l-66.5%
div-inv66.5%
metadata-eval66.5%
*-rgt-identity66.5%
div-inv66.5%
metadata-eval66.5%
*-rgt-identity66.5%
Applied egg-rr66.5%
Taylor expanded in x around inf 96.2%
expm1-log1p-u96.2%
expm1-udef57.3%
associate-/l/57.3%
Applied egg-rr57.3%
expm1-def96.1%
expm1-log1p96.1%
*-commutative96.1%
Simplified96.1%
Final simplification73.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 87.8%
sub-neg87.8%
+-commutative87.8%
distribute-neg-frac87.8%
metadata-eval87.8%
metadata-eval87.8%
metadata-eval87.8%
associate-/r*87.8%
metadata-eval87.8%
neg-mul-187.8%
sub0-neg87.8%
associate-+l-87.8%
neg-sub087.8%
remove-double-neg87.8%
distribute-neg-in87.8%
sub-neg87.8%
mul-1-neg87.8%
metadata-eval87.8%
associate-/r*87.8%
metadata-eval87.8%
metadata-eval87.8%
metadata-eval87.8%
metadata-eval87.8%
associate-*l/87.8%
Simplified87.8%
Taylor expanded in x around 0 68.3%
if 1 < x Initial program 60.3%
sub-neg60.3%
+-commutative60.3%
distribute-neg-frac60.3%
metadata-eval60.3%
metadata-eval60.3%
metadata-eval60.3%
associate-/r*60.3%
metadata-eval60.3%
neg-mul-160.3%
sub0-neg60.3%
associate-+l-60.3%
neg-sub060.3%
remove-double-neg60.3%
distribute-neg-in60.3%
sub-neg60.3%
mul-1-neg60.3%
metadata-eval60.3%
associate-/r*60.3%
metadata-eval60.3%
metadata-eval60.3%
metadata-eval60.3%
metadata-eval60.3%
associate-*l/60.3%
Simplified60.3%
frac-sub61.2%
*-rgt-identity61.2%
metadata-eval61.2%
div-inv61.2%
associate-/r*61.2%
*-un-lft-identity61.2%
metadata-eval61.2%
div-inv61.2%
associate--l-66.5%
div-inv66.5%
metadata-eval66.5%
*-rgt-identity66.5%
div-inv66.5%
metadata-eval66.5%
*-rgt-identity66.5%
Applied egg-rr66.5%
Taylor expanded in x around inf 96.2%
Final simplification73.9%
(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 82.3%
sub-neg82.3%
+-commutative82.3%
distribute-neg-frac82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
neg-mul-182.3%
sub0-neg82.3%
associate-+l-82.3%
neg-sub082.3%
remove-double-neg82.3%
distribute-neg-in82.3%
sub-neg82.3%
mul-1-neg82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-*l/82.3%
Simplified82.3%
sub-neg82.3%
distribute-neg-frac82.3%
metadata-eval82.3%
Applied egg-rr82.3%
*-rgt-identity82.3%
cancel-sign-sub82.3%
distribute-neg-frac82.3%
metadata-eval82.3%
*-rgt-identity82.3%
*-inverses82.3%
associate-/r*60.1%
distribute-lft-neg-in60.1%
distribute-rgt-neg-in60.1%
*-commutative60.1%
*-lft-identity60.1%
*-inverses60.1%
times-frac82.3%
div-sub82.6%
Simplified99.9%
Final simplification99.9%
(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 82.3%
sub-neg82.3%
+-commutative82.3%
distribute-neg-frac82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
neg-mul-182.3%
sub0-neg82.3%
associate-+l-82.3%
neg-sub082.3%
remove-double-neg82.3%
distribute-neg-in82.3%
sub-neg82.3%
mul-1-neg82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-*l/82.3%
Simplified82.3%
frac-sub82.6%
*-rgt-identity82.6%
metadata-eval82.6%
div-inv82.6%
associate-/r*82.6%
*-un-lft-identity82.6%
metadata-eval82.6%
div-inv82.6%
associate--l-85.1%
div-inv85.1%
metadata-eval85.1%
*-rgt-identity85.1%
div-inv85.1%
metadata-eval85.1%
*-rgt-identity85.1%
Applied egg-rr85.1%
Taylor expanded in x around 0 55.9%
Final simplification55.9%
(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 82.3%
sub-neg82.3%
+-commutative82.3%
distribute-neg-frac82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
neg-mul-182.3%
sub0-neg82.3%
associate-+l-82.3%
neg-sub082.3%
remove-double-neg82.3%
distribute-neg-in82.3%
sub-neg82.3%
mul-1-neg82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-*l/82.3%
Simplified82.3%
Taylor expanded in x around 0 54.4%
Taylor expanded in x around inf 11.5%
Final simplification11.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 82.3%
sub-neg82.3%
+-commutative82.3%
distribute-neg-frac82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
neg-mul-182.3%
sub0-neg82.3%
associate-+l-82.3%
neg-sub082.3%
remove-double-neg82.3%
distribute-neg-in82.3%
sub-neg82.3%
mul-1-neg82.3%
metadata-eval82.3%
associate-/r*82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
metadata-eval82.3%
associate-*l/82.3%
Simplified82.3%
Taylor expanded in x around 0 55.2%
Final simplification55.2%
herbie shell --seed 2023338
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))