
(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 (* (/ (/ 1.0 (+ x -1.0)) (+ 1.0 x)) -2.0))
double code(double x) {
return ((1.0 / (x + -1.0)) / (1.0 + x)) * -2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + (-1.0d0))) / (1.0d0 + x)) * (-2.0d0)
end function
public static double code(double x) {
return ((1.0 / (x + -1.0)) / (1.0 + x)) * -2.0;
}
def code(x): return ((1.0 / (x + -1.0)) / (1.0 + x)) * -2.0
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + -1.0)) / Float64(1.0 + x)) * -2.0) end
function tmp = code(x) tmp = ((1.0 / (x + -1.0)) / (1.0 + x)) * -2.0; end
code[x_] := N[(N[(N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x + -1}}{1 + x} \cdot -2
\end{array}
Initial program 77.8%
sub-neg77.8%
+-commutative77.8%
distribute-neg-frac277.8%
neg-sub077.8%
associate-+l-77.8%
neg-sub077.8%
remove-double-neg77.8%
distribute-neg-in77.8%
sub-neg77.8%
distribute-neg-frac277.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
metadata-eval77.8%
Simplified77.8%
sub-neg77.8%
distribute-neg-frac77.8%
metadata-eval77.8%
Applied egg-rr77.8%
Simplified99.6%
metadata-eval99.6%
sub-neg99.6%
flip3--63.5%
metadata-eval63.5%
metadata-eval63.5%
*-commutative63.5%
neg-mul-163.5%
sub-neg63.5%
*-rgt-identity63.5%
metadata-eval63.5%
fma-define63.5%
metadata-eval63.5%
*-rgt-identity63.5%
Applied egg-rr63.5%
clear-num63.5%
associate-/r/63.5%
*-commutative63.5%
associate-/r*63.5%
metadata-eval63.5%
fma-undefine63.5%
sub-neg63.5%
metadata-eval63.5%
neg-mul-163.5%
*-commutative63.5%
flip3--99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.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(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.1%
sub-neg88.1%
+-commutative88.1%
distribute-neg-frac288.1%
neg-sub088.1%
associate-+l-88.1%
neg-sub088.1%
remove-double-neg88.1%
distribute-neg-in88.1%
sub-neg88.1%
distribute-neg-frac288.1%
sub-neg88.1%
+-commutative88.1%
unsub-neg88.1%
sub-neg88.1%
+-commutative88.1%
unsub-neg88.1%
metadata-eval88.1%
Simplified88.1%
Taylor expanded in x around 0 68.8%
if 1 < x Initial program 53.4%
sub-neg53.4%
+-commutative53.4%
distribute-neg-frac253.4%
neg-sub053.4%
associate-+l-53.4%
neg-sub053.4%
remove-double-neg53.4%
distribute-neg-in53.4%
sub-neg53.4%
distribute-neg-frac253.4%
sub-neg53.4%
+-commutative53.4%
unsub-neg53.4%
sub-neg53.4%
+-commutative53.4%
unsub-neg53.4%
metadata-eval53.4%
Simplified53.4%
frac-sub54.5%
*-rgt-identity54.5%
metadata-eval54.5%
div-inv54.5%
associate-/r*54.5%
metadata-eval54.5%
div-inv54.5%
*-un-lft-identity54.5%
associate--l-60.6%
div-inv60.6%
metadata-eval60.6%
*-rgt-identity60.6%
div-inv60.6%
metadata-eval60.6%
*-rgt-identity60.6%
Applied egg-rr60.6%
Taylor expanded in x around inf 98.9%
(FPCore (x) :precision binary64 (if (<= x 0.75) 2.0 (/ -2.0 (* x (+ x -1.0)))))
double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.75d0) then
tmp = 2.0d0
else
tmp = (-2.0d0) / (x * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.75: tmp = 2.0 else: tmp = -2.0 / (x * (x + -1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.75) tmp = 2.0; else tmp = Float64(-2.0 / Float64(x * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.75) tmp = 2.0; else tmp = -2.0 / (x * (x + -1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.75], 2.0, N[(-2.0 / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + -1\right)}\\
\end{array}
\end{array}
if x < 0.75Initial program 88.1%
sub-neg88.1%
+-commutative88.1%
distribute-neg-frac288.1%
neg-sub088.1%
associate-+l-88.1%
neg-sub088.1%
remove-double-neg88.1%
distribute-neg-in88.1%
sub-neg88.1%
distribute-neg-frac288.1%
sub-neg88.1%
+-commutative88.1%
unsub-neg88.1%
sub-neg88.1%
+-commutative88.1%
unsub-neg88.1%
metadata-eval88.1%
Simplified88.1%
Taylor expanded in x around 0 68.8%
if 0.75 < x Initial program 53.4%
sub-neg53.4%
+-commutative53.4%
distribute-neg-frac253.4%
neg-sub053.4%
associate-+l-53.4%
neg-sub053.4%
remove-double-neg53.4%
distribute-neg-in53.4%
sub-neg53.4%
distribute-neg-frac253.4%
sub-neg53.4%
+-commutative53.4%
unsub-neg53.4%
sub-neg53.4%
+-commutative53.4%
unsub-neg53.4%
metadata-eval53.4%
Simplified53.4%
sub-neg53.4%
distribute-neg-frac53.4%
metadata-eval53.4%
Applied egg-rr53.4%
Simplified98.9%
Taylor expanded in x around inf 98.0%
(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-frac277.8%
neg-sub077.8%
associate-+l-77.8%
neg-sub077.8%
remove-double-neg77.8%
distribute-neg-in77.8%
sub-neg77.8%
distribute-neg-frac277.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
metadata-eval77.8%
Simplified77.8%
sub-neg77.8%
distribute-neg-frac77.8%
metadata-eval77.8%
Applied egg-rr77.8%
Simplified99.6%
Final simplification99.6%
(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.1%
sub-neg88.1%
+-commutative88.1%
distribute-neg-frac288.1%
neg-sub088.1%
associate-+l-88.1%
neg-sub088.1%
remove-double-neg88.1%
distribute-neg-in88.1%
sub-neg88.1%
distribute-neg-frac288.1%
sub-neg88.1%
+-commutative88.1%
unsub-neg88.1%
sub-neg88.1%
+-commutative88.1%
unsub-neg88.1%
metadata-eval88.1%
Simplified88.1%
Taylor expanded in x around 0 68.8%
if 1 < x Initial program 53.4%
sub-neg53.4%
+-commutative53.4%
distribute-neg-frac253.4%
neg-sub053.4%
associate-+l-53.4%
neg-sub053.4%
remove-double-neg53.4%
distribute-neg-in53.4%
sub-neg53.4%
distribute-neg-frac253.4%
sub-neg53.4%
+-commutative53.4%
unsub-neg53.4%
sub-neg53.4%
+-commutative53.4%
unsub-neg53.4%
metadata-eval53.4%
Simplified53.4%
frac-sub54.5%
*-rgt-identity54.5%
metadata-eval54.5%
div-inv54.5%
associate-/r*54.5%
metadata-eval54.5%
div-inv54.5%
*-un-lft-identity54.5%
associate--l-60.6%
div-inv60.6%
metadata-eval60.6%
*-rgt-identity60.6%
div-inv60.6%
metadata-eval60.6%
*-rgt-identity60.6%
Applied egg-rr60.6%
Taylor expanded in x around inf 98.9%
Taylor expanded in x around 0 7.0%
(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-frac277.8%
neg-sub077.8%
associate-+l-77.8%
neg-sub077.8%
remove-double-neg77.8%
distribute-neg-in77.8%
sub-neg77.8%
distribute-neg-frac277.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
metadata-eval77.8%
Simplified77.8%
Taylor expanded in x around 0 49.2%
(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 77.8%
sub-neg77.8%
+-commutative77.8%
distribute-neg-frac277.8%
neg-sub077.8%
associate-+l-77.8%
neg-sub077.8%
remove-double-neg77.8%
distribute-neg-in77.8%
sub-neg77.8%
distribute-neg-frac277.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
sub-neg77.8%
+-commutative77.8%
unsub-neg77.8%
metadata-eval77.8%
Simplified77.8%
Taylor expanded in x around 0 48.5%
Taylor expanded in x around inf 10.4%
herbie shell --seed 2024185
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))