
(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 10 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)) (/ (- -1.0 x) (+ x -1.0))))) (if (<= t_0 2e-11) (/ (fma (/ 1.0 (* x x)) (+ x 3.0) 3.0) (- 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 = fma((1.0 / (x * x)), (x + 3.0), 3.0) / -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(fma(Float64(1.0 / Float64(x * x)), Float64(x + 3.0), 3.0) / Float64(-x)); else tmp = t_0; end return 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[(N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(x + 3.0), $MachinePrecision] + 3.0), $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{\mathsf{fma}\left(\frac{1}{x \cdot x}, x + 3, 3\right)}{-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 8.3%
sub-negN/A
+-commutativeN/A
clear-numN/A
distribute-neg-fracN/A
frac-addN/A
flip-+N/A
clear-numN/A
clear-numN/A
flip-+N/A
clear-numN/A
times-fracN/A
*-commutativeN/A
difference-of-sqr-1N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
Applied egg-rr9.4%
Taylor expanded in x around inf
Simplified98.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 99.9%
Final simplification99.3%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))))) (if (<= t_0 2e-11) (/ (+ -3.0 (/ 2.0 x)) (+ x -1.0)) 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 + (2.0 / x)) / (x + -1.0);
} 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) + (2.0d0 / x)) / (x + (-1.0d0))
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 + (2.0 / x)) / (x + -1.0);
} 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 + (2.0 / x)) / (x + -1.0) 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(2.0 / x)) / Float64(x + -1.0)); 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 + (2.0 / x)) / (x + -1.0); 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[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $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{2}{x}}{x + -1}\\
\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 8.3%
sub-negN/A
+-commutativeN/A
clear-numN/A
distribute-neg-fracN/A
frac-addN/A
flip-+N/A
clear-numN/A
clear-numN/A
flip-+N/A
clear-numN/A
times-fracN/A
*-commutativeN/A
difference-of-sqr-1N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
Applied egg-rr9.4%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6498.6
Simplified98.6%
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 99.9%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ (+ -3.0 (/ 2.0 x)) (+ x -1.0)) (fma (fma x x 1.0) (* x 3.0) (fma x 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 + (2.0 / x)) / (x + -1.0);
} else {
tmp = fma(fma(x, x, 1.0), (x * 3.0), fma(x, 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(2.0 / x)) / Float64(x + -1.0)); else tmp = fma(fma(x, x, 1.0), Float64(x * 3.0), fma(x, 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[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * x + 1.0), $MachinePrecision] * N[(x * 3.0), $MachinePrecision] + N[(x * 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 + \frac{2}{x}}{x + -1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, x, 1\right), x \cdot 3, \mathsf{fma}\left(x, x, 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 8.3%
sub-negN/A
+-commutativeN/A
clear-numN/A
distribute-neg-fracN/A
frac-addN/A
flip-+N/A
clear-numN/A
clear-numN/A
flip-+N/A
clear-numN/A
times-fracN/A
*-commutativeN/A
difference-of-sqr-1N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
Applied egg-rr9.4%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6498.6
Simplified98.6%
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 99.9%
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
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
accelerator-lowering-fma.f6499.4
Simplified99.4%
*-commutativeN/A
distribute-lft-inN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f6499.4
Applied egg-rr99.4%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ (+ -3.0 (/ 2.0 x)) (+ x -1.0)) (* (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 + (2.0 / x)) / (x + -1.0);
} 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(Float64(-3.0 + Float64(2.0 / x)) / Float64(x + -1.0)); 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[(N[(-3.0 + N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $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 + \frac{2}{x}}{x + -1}\\
\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 8.3%
sub-negN/A
+-commutativeN/A
clear-numN/A
distribute-neg-fracN/A
frac-addN/A
flip-+N/A
clear-numN/A
clear-numN/A
flip-+N/A
clear-numN/A
times-fracN/A
*-commutativeN/A
difference-of-sqr-1N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
Applied egg-rr9.4%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6498.6
Simplified98.6%
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 99.9%
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
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
accelerator-lowering-fma.f6499.4
Simplified99.4%
Final simplification99.0%
(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 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 + (-1.0 / x)) / 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(Float64(-3.0 + Float64(-1.0 / x)) / 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[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / 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 + \frac{-1}{x}}{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 8.3%
Taylor expanded in x around inf
associate-*r/N/A
/-lowering-/.f64N/A
neg-mul-1N/A
distribute-neg-inN/A
metadata-evalN/A
+-lowering-+.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f6498.6
Simplified98.6%
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 99.9%
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
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
accelerator-lowering-fma.f6499.4
Simplified99.4%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 2e-11) (/ 1.0 (fma x -0.3333333333333333 0.1111111111111111)) (* (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 = 1.0 / fma(x, -0.3333333333333333, 0.1111111111111111);
} 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(1.0 / fma(x, -0.3333333333333333, 0.1111111111111111)); 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[(1.0 / N[(x * -0.3333333333333333 + 0.1111111111111111), $MachinePrecision]), $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{1}{\mathsf{fma}\left(x, -0.3333333333333333, 0.1111111111111111\right)}\\
\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 8.3%
sub-negN/A
+-commutativeN/A
clear-numN/A
distribute-neg-fracN/A
frac-addN/A
flip-+N/A
clear-numN/A
clear-numN/A
flip-+N/A
clear-numN/A
times-fracN/A
*-commutativeN/A
difference-of-sqr-1N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
Applied egg-rr9.4%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-*l/N/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f648.3
Applied egg-rr8.3%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
rgt-mult-inverseN/A
metadata-evalN/A
accelerator-lowering-fma.f6498.1
Simplified98.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 99.9%
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
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
accelerator-lowering-fma.f6499.4
Simplified99.4%
Final simplification98.7%
(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 8.3%
Taylor expanded in x around inf
/-lowering-/.f6498.1
Simplified98.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 99.9%
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
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
accelerator-lowering-fma.f6499.4
Simplified99.4%
Final simplification98.7%
(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 8.3%
Taylor expanded in x around inf
/-lowering-/.f6498.1
Simplified98.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 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6499.2
Simplified99.2%
Final simplification98.6%
(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.1%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6450.8
Simplified50.8%
Final simplification50.8%
(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.1%
Taylor expanded in x around 0
Simplified50.3%
herbie shell --seed 2024204
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))