
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (/ x (+ x 1.0))))
(if (<= (+ t_0 (/ (- -1.0 x) (+ x -1.0))) 2e-11)
(* (/ (+ 3.0 (/ 1.0 x)) x) (+ -1.0 (/ -1.0 (* x x))))
(fma (/ -1.0 (- 1.0 x)) (- -1.0 x) t_0))))
double code(double x) {
double t_0 = x / (x + 1.0);
double tmp;
if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = ((3.0 + (1.0 / x)) / x) * (-1.0 + (-1.0 / (x * x)));
} else {
tmp = fma((-1.0 / (1.0 - x)), (-1.0 - x), t_0);
}
return tmp;
}
function code(x) t_0 = Float64(x / Float64(x + 1.0)) tmp = 0.0 if (Float64(t_0 + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(Float64(Float64(3.0 + Float64(1.0 / x)) / x) * Float64(-1.0 + Float64(-1.0 / Float64(x * x)))); else tmp = fma(Float64(-1.0 / Float64(1.0 - x)), Float64(-1.0 - x), t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(N[(N[(3.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * N[(-1.0 + N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;t\_0 + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{3 + \frac{1}{x}}{x} \cdot \left(-1 + \frac{-1}{x \cdot x}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{1 - x}, -1 - x, t\_0\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
div-subN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
associate-*r/N/A
associate-/r*N/A
times-fracN/A
metadata-evalN/A
distribute-neg-fracN/A
unpow2N/A
associate-/r*N/A
distribute-rgt-outN/A
metadata-evalN/A
associate-/r*N/A
unpow2N/A
Applied rewrites100.0%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-+.f64N/A
distribute-neg-inN/A
lower-+.f64N/A
lower-neg.f64N/A
metadata-evalN/A
lower-/.f64100.0
lift--.f64N/A
sub-negN/A
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lift-+.f64N/A
metadata-evalN/A
sub-negN/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
*-rgt-identityN/A
sub-negN/A
*-rgt-identityN/A
lower--.f64100.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ x (+ x 1.0))))
(if (<= (+ t_0 (/ (- -1.0 x) (+ x -1.0))) 2e-11)
(/ (+ -3.0 (/ (+ -1.0 (/ -3.0 x)) x)) x)
(fma (/ -1.0 (- 1.0 x)) (- -1.0 x) t_0))))
double code(double x) {
double t_0 = x / (x + 1.0);
double tmp;
if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = (-3.0 + ((-1.0 + (-3.0 / x)) / x)) / x;
} else {
tmp = fma((-1.0 / (1.0 - x)), (-1.0 - x), t_0);
}
return tmp;
}
function code(x) t_0 = Float64(x / Float64(x + 1.0)) tmp = 0.0 if (Float64(t_0 + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(Float64(-3.0 + Float64(Float64(-1.0 + Float64(-3.0 / x)) / x)) / x); else tmp = fma(Float64(-1.0 / Float64(1.0 - x)), Float64(-1.0 - x), t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(N[(-3.0 + N[(N[(-1.0 + N[(-3.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(-1.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;t\_0 + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3 + \frac{-1 + \frac{-3}{x}}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{1 - x}, -1 - x, t\_0\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
Applied rewrites99.9%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-+.f64N/A
distribute-neg-inN/A
lower-+.f64N/A
lower-neg.f64N/A
metadata-evalN/A
lower-/.f64100.0
lift--.f64N/A
sub-negN/A
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lift-+.f64N/A
metadata-evalN/A
sub-negN/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
*-rgt-identityN/A
sub-negN/A
*-rgt-identityN/A
lower--.f64100.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ x (+ x 1.0))))
(if (<= (+ t_0 (/ (- -1.0 x) (+ x -1.0))) 2e-11)
(/ (+ -3.0 (/ -1.0 x)) x)
(fma (/ -1.0 (- 1.0 x)) (- -1.0 x) t_0))))
double code(double x) {
double t_0 = x / (x + 1.0);
double tmp;
if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = fma((-1.0 / (1.0 - x)), (-1.0 - x), t_0);
}
return tmp;
}
function code(x) t_0 = Float64(x / Float64(x + 1.0)) tmp = 0.0 if (Float64(t_0 + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = fma(Float64(-1.0 / Float64(1.0 - x)), Float64(-1.0 - x), t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(-1.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;t\_0 + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{1 - x}, -1 - x, t\_0\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f64N/A
neg-mul-1N/A
distribute-neg-inN/A
metadata-evalN/A
lower-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6499.7
Applied rewrites99.7%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-+.f64N/A
distribute-neg-inN/A
lower-+.f64N/A
lower-neg.f64N/A
metadata-evalN/A
lower-/.f64100.0
lift--.f64N/A
sub-negN/A
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lift-+.f64N/A
metadata-evalN/A
sub-negN/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
*-rgt-identityN/A
sub-negN/A
*-rgt-identityN/A
lower--.f64100.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification99.9%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))))) (if (<= t_0 2e-11) (/ (+ -3.0 (/ -1.0 x)) x) t_0)))
double code(double x) {
double t_0 = (x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0));
double tmp;
if (t_0 <= 2e-11) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x / (x + 1.0d0)) + (((-1.0d0) - x) / (x + (-1.0d0)))
if (t_0 <= 2d-11) then
tmp = ((-3.0d0) + ((-1.0d0) / x)) / x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0));
double tmp;
if (t_0 <= 2e-11) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0)) tmp = 0 if t_0 <= 2e-11: tmp = (-3.0 + (-1.0 / x)) / x else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) tmp = 0.0 if (t_0 <= 2e-11) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0)); tmp = 0.0; if (t_0 <= 2e-11) tmp = (-3.0 + (-1.0 / x)) / x; else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-11], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f64N/A
neg-mul-1N/A
distribute-neg-inN/A
metadata-evalN/A
lower-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6499.7
Applied rewrites99.7%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ (+ -3.0 (/ -1.0 x)) x) (fma x (fma (fma x x 1.0) 3.0 x) 1.0)))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = fma(x, fma(fma(x, x, 1.0), 3.0, x), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = fma(x, fma(fma(x, x, 1.0), 3.0, x), 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(x * N[(N[(x * x + 1.0), $MachinePrecision] * 3.0 + x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(x, x, 1\right), 3, x\right), 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f64N/A
neg-mul-1N/A
distribute-neg-inN/A
metadata-evalN/A
lower-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6499.7
Applied rewrites99.7%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
associate-*r*N/A
unpow2N/A
distribute-rgt1-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-fma.f6499.2
Applied rewrites99.2%
Applied rewrites99.3%
Applied rewrites99.3%
Taylor expanded in x around 0
Applied rewrites99.3%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ -3.0 x) (fma x (fma (fma x x 1.0) 3.0 x) 1.0)))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = -3.0 / x;
} else {
tmp = fma(x, fma(fma(x, x, 1.0), 3.0, x), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(-3.0 / x); else tmp = fma(x, fma(fma(x, x, 1.0), 3.0, x), 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(-3.0 / x), $MachinePrecision], N[(x * N[(N[(x * x + 1.0), $MachinePrecision] * 3.0 + x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(x, x, 1\right), 3, x\right), 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
associate-*r*N/A
unpow2N/A
distribute-rgt1-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-fma.f6499.2
Applied rewrites99.2%
Applied rewrites99.3%
Applied rewrites99.3%
Taylor expanded in x around 0
Applied rewrites99.3%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ -3.0 x) (* (fma x x 1.0) (fma 3.0 x 1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = -3.0 / x;
} else {
tmp = fma(x, x, 1.0) * fma(3.0, x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(-3.0 / x); else tmp = Float64(fma(x, x, 1.0) * fma(3.0, x, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(-3.0 / x), $MachinePrecision], N[(N[(x * x + 1.0), $MachinePrecision] * N[(3.0 * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 1\right) \cdot \mathsf{fma}\left(3, x, 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
associate-*r*N/A
unpow2N/A
distribute-rgt1-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-fma.f6499.2
Applied rewrites99.2%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ -3.0 x) (fma x x (fma x 3.0 1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = -3.0 / x;
} else {
tmp = fma(x, x, fma(x, 3.0, 1.0));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(-3.0 / x); else tmp = fma(x, x, fma(x, 3.0, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(-3.0 / x), $MachinePrecision], N[(x * x + N[(x * 3.0 + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \mathsf{fma}\left(x, 3, 1\right)\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-+.f6499.0
Applied rewrites99.0%
Applied rewrites99.0%
Applied rewrites99.0%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ -3.0 x) (fma x (+ x 3.0) 1.0)))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0))) <= 2e-11) {
tmp = -3.0 / x;
} else {
tmp = fma(x, (x + 3.0), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 2e-11) tmp = Float64(-3.0 / x); else tmp = fma(x, Float64(x + 3.0), 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-11], N[(-3.0 / x), $MachinePrecision], N[(x * N[(x + 3.0), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x + 3, 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 1.99999999999999988e-11Initial program 6.7%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
if 1.99999999999999988e-11 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-+.f6499.0
Applied rewrites99.0%
Final simplification99.1%
(FPCore (x) :precision binary64 (fma x (+ x 3.0) 1.0))
double code(double x) {
return fma(x, (x + 3.0), 1.0);
}
function code(x) return fma(x, Float64(x + 3.0), 1.0) end
code[x_] := N[(x * N[(x + 3.0), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x + 3, 1\right)
\end{array}
Initial program 54.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-+.f6452.2
Applied rewrites52.2%
Final simplification52.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 54.8%
Taylor expanded in x around 0
Applied rewrites52.0%
herbie shell --seed 2024238
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))