
(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 80.3%
sub-neg80.3%
+-commutative80.3%
neg-sub080.3%
associate-+l-80.3%
sub-neg80.3%
associate--r+80.3%
neg-sub080.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
sub0-neg80.3%
associate-+l-80.3%
neg-sub080.3%
+-commutative80.3%
unsub-neg80.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
Simplified80.3%
frac-sub81.0%
*-rgt-identity81.0%
metadata-eval81.0%
div-inv81.0%
associate-/r*81.0%
*-un-lft-identity81.0%
metadata-eval81.0%
div-inv81.0%
associate--l-83.6%
div-inv83.6%
metadata-eval83.6%
*-rgt-identity83.6%
div-inv83.6%
metadata-eval83.6%
*-rgt-identity83.6%
Applied egg-rr83.6%
frac-2neg83.6%
div-inv83.7%
distribute-neg-frac83.7%
associate--r+81.0%
associate--r-81.0%
neg-mul-181.0%
sub-neg81.0%
distribute-rgt-in81.0%
metadata-eval81.0%
cancel-sign-sub-inv81.0%
*-commutative81.0%
neg-mul-181.0%
Applied egg-rr81.0%
associate-*l/81.0%
sub-neg81.0%
remove-double-neg81.0%
associate-*r/81.0%
associate--l-81.0%
+-commutative81.0%
associate-+l-83.7%
associate--l+99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
+-commutative99.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 88.0%
sub-neg88.0%
+-commutative88.0%
neg-sub088.0%
associate-+l-88.0%
sub-neg88.0%
associate--r+88.0%
neg-sub088.0%
distribute-neg-frac88.0%
metadata-eval88.0%
metadata-eval88.0%
metadata-eval88.0%
associate-/r*88.0%
metadata-eval88.0%
neg-mul-188.0%
sub0-neg88.0%
associate-+l-88.0%
neg-sub088.0%
+-commutative88.0%
unsub-neg88.0%
distribute-neg-frac88.0%
metadata-eval88.0%
metadata-eval88.0%
metadata-eval88.0%
associate-/r*88.0%
metadata-eval88.0%
neg-mul-188.0%
Simplified88.0%
Taylor expanded in x around 0 69.7%
if 1 < x Initial program 55.0%
sub-neg55.0%
+-commutative55.0%
neg-sub055.0%
associate-+l-55.0%
sub-neg55.0%
associate--r+55.0%
neg-sub055.0%
distribute-neg-frac55.0%
metadata-eval55.0%
metadata-eval55.0%
metadata-eval55.0%
associate-/r*55.0%
metadata-eval55.0%
neg-mul-155.0%
sub0-neg55.0%
associate-+l-55.0%
neg-sub055.0%
+-commutative55.0%
unsub-neg55.0%
distribute-neg-frac55.0%
metadata-eval55.0%
metadata-eval55.0%
metadata-eval55.0%
associate-/r*55.0%
metadata-eval55.0%
neg-mul-155.0%
Simplified55.0%
frac-sub56.3%
*-rgt-identity56.3%
metadata-eval56.3%
div-inv56.3%
associate-/r*56.3%
*-un-lft-identity56.3%
metadata-eval56.3%
div-inv56.3%
associate--l-62.5%
div-inv62.5%
metadata-eval62.5%
*-rgt-identity62.5%
div-inv62.5%
metadata-eval62.5%
*-rgt-identity62.5%
Applied egg-rr62.5%
Taylor expanded in x around inf 97.4%
expm1-log1p-u97.4%
expm1-udef52.8%
associate-/l/52.8%
*-commutative52.8%
Applied egg-rr52.8%
expm1-def96.4%
expm1-log1p96.4%
Simplified96.4%
Final simplification76.0%
(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 88.0%
sub-neg88.0%
+-commutative88.0%
neg-sub088.0%
associate-+l-88.0%
sub-neg88.0%
associate--r+88.0%
neg-sub088.0%
distribute-neg-frac88.0%
metadata-eval88.0%
metadata-eval88.0%
metadata-eval88.0%
associate-/r*88.0%
metadata-eval88.0%
neg-mul-188.0%
sub0-neg88.0%
associate-+l-88.0%
neg-sub088.0%
+-commutative88.0%
unsub-neg88.0%
distribute-neg-frac88.0%
metadata-eval88.0%
metadata-eval88.0%
metadata-eval88.0%
associate-/r*88.0%
metadata-eval88.0%
neg-mul-188.0%
Simplified88.0%
Taylor expanded in x around 0 69.7%
if 1 < x Initial program 55.0%
sub-neg55.0%
+-commutative55.0%
neg-sub055.0%
associate-+l-55.0%
sub-neg55.0%
associate--r+55.0%
neg-sub055.0%
distribute-neg-frac55.0%
metadata-eval55.0%
metadata-eval55.0%
metadata-eval55.0%
associate-/r*55.0%
metadata-eval55.0%
neg-mul-155.0%
sub0-neg55.0%
associate-+l-55.0%
neg-sub055.0%
+-commutative55.0%
unsub-neg55.0%
distribute-neg-frac55.0%
metadata-eval55.0%
metadata-eval55.0%
metadata-eval55.0%
associate-/r*55.0%
metadata-eval55.0%
neg-mul-155.0%
Simplified55.0%
frac-sub56.3%
*-rgt-identity56.3%
metadata-eval56.3%
div-inv56.3%
associate-/r*56.3%
*-un-lft-identity56.3%
metadata-eval56.3%
div-inv56.3%
associate--l-62.5%
div-inv62.5%
metadata-eval62.5%
*-rgt-identity62.5%
div-inv62.5%
metadata-eval62.5%
*-rgt-identity62.5%
Applied egg-rr62.5%
Taylor expanded in x around inf 97.4%
Final simplification76.2%
(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 80.3%
sub-neg80.3%
+-commutative80.3%
neg-sub080.3%
associate-+l-80.3%
sub-neg80.3%
associate--r+80.3%
neg-sub080.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
sub0-neg80.3%
associate-+l-80.3%
neg-sub080.3%
+-commutative80.3%
unsub-neg80.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
Simplified80.3%
sub-neg80.3%
distribute-neg-frac80.3%
metadata-eval80.3%
Applied egg-rr80.3%
*-rgt-identity80.3%
cancel-sign-sub80.3%
distribute-neg-frac80.3%
metadata-eval80.3%
*-rgt-identity80.3%
*-inverses80.3%
associate-/r*57.4%
distribute-lft-neg-in57.4%
distribute-rgt-neg-in57.4%
*-commutative57.4%
*-lft-identity57.4%
*-inverses57.4%
times-frac80.3%
div-sub81.0%
Simplified99.5%
Final simplification99.5%
(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 88.0%
sub-neg88.0%
+-commutative88.0%
neg-sub088.0%
associate-+l-88.0%
sub-neg88.0%
associate--r+88.0%
neg-sub088.0%
distribute-neg-frac88.0%
metadata-eval88.0%
metadata-eval88.0%
metadata-eval88.0%
associate-/r*88.0%
metadata-eval88.0%
neg-mul-188.0%
sub0-neg88.0%
associate-+l-88.0%
neg-sub088.0%
+-commutative88.0%
unsub-neg88.0%
distribute-neg-frac88.0%
metadata-eval88.0%
metadata-eval88.0%
metadata-eval88.0%
associate-/r*88.0%
metadata-eval88.0%
neg-mul-188.0%
Simplified88.0%
Taylor expanded in x around 0 69.7%
if 1 < x Initial program 55.0%
sub-neg55.0%
+-commutative55.0%
neg-sub055.0%
associate-+l-55.0%
sub-neg55.0%
associate--r+55.0%
neg-sub055.0%
distribute-neg-frac55.0%
metadata-eval55.0%
metadata-eval55.0%
metadata-eval55.0%
associate-/r*55.0%
metadata-eval55.0%
neg-mul-155.0%
sub0-neg55.0%
associate-+l-55.0%
neg-sub055.0%
+-commutative55.0%
unsub-neg55.0%
distribute-neg-frac55.0%
metadata-eval55.0%
metadata-eval55.0%
metadata-eval55.0%
associate-/r*55.0%
metadata-eval55.0%
neg-mul-155.0%
Simplified55.0%
frac-sub56.3%
*-rgt-identity56.3%
metadata-eval56.3%
div-inv56.3%
associate-/r*56.3%
*-un-lft-identity56.3%
metadata-eval56.3%
div-inv56.3%
associate--l-62.5%
div-inv62.5%
metadata-eval62.5%
*-rgt-identity62.5%
div-inv62.5%
metadata-eval62.5%
*-rgt-identity62.5%
Applied egg-rr62.5%
Taylor expanded in x around inf 97.4%
Taylor expanded in x around 0 6.9%
Final simplification55.0%
(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 80.3%
sub-neg80.3%
+-commutative80.3%
neg-sub080.3%
associate-+l-80.3%
sub-neg80.3%
associate--r+80.3%
neg-sub080.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
sub0-neg80.3%
associate-+l-80.3%
neg-sub080.3%
+-commutative80.3%
unsub-neg80.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
Simplified80.3%
Taylor expanded in x around 0 53.4%
Taylor expanded in x around inf 11.2%
Final simplification11.2%
(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 80.3%
sub-neg80.3%
+-commutative80.3%
neg-sub080.3%
associate-+l-80.3%
sub-neg80.3%
associate--r+80.3%
neg-sub080.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
sub0-neg80.3%
associate-+l-80.3%
neg-sub080.3%
+-commutative80.3%
unsub-neg80.3%
distribute-neg-frac80.3%
metadata-eval80.3%
metadata-eval80.3%
metadata-eval80.3%
associate-/r*80.3%
metadata-eval80.3%
neg-mul-180.3%
Simplified80.3%
Taylor expanded in x around 0 54.0%
Final simplification54.0%
herbie shell --seed 2023305
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))