
(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 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 1e-9) (* (- (/ (/ -1.0 x) x) 1.0) (/ (- (pow x -1.0) -3.0) x)) (/ (fma -3.0 x -1.0) (+ x (fma x x (- -1.0 x))))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1e-9) {
tmp = (((-1.0 / x) / x) - 1.0) * ((pow(x, -1.0) - -3.0) / x);
} else {
tmp = fma(-3.0, x, -1.0) / (x + fma(x, x, (-1.0 - x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 1e-9) tmp = Float64(Float64(Float64(Float64(-1.0 / x) / x) - 1.0) * Float64(Float64((x ^ -1.0) - -3.0) / x)); else tmp = Float64(fma(-3.0, x, -1.0) / Float64(x + fma(x, x, Float64(-1.0 - x)))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-9], N[(N[(N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision] - 1.0), $MachinePrecision] * N[(N[(N[Power[x, -1.0], $MachinePrecision] - -3.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(-3.0 * x + -1.0), $MachinePrecision] / N[(x + N[(x * x + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 10^{-9}:\\
\;\;\;\;\left(\frac{\frac{-1}{x}}{x} - 1\right) \cdot \frac{{x}^{-1} - -3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-3, x, -1\right)}{x + \mathsf{fma}\left(x, x, -1 - x\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.00000000000000006e-9Initial program 8.5%
Taylor expanded in x around inf
div-subN/A
sub-negN/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
mul-1-negN/A
distribute-rgt-outN/A
metadata-evalN/A
sub-negN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.1%
if 1.00000000000000006e-9 < (-.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.8%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites99.8%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
lift-+.f64N/A
lift-fma.f64N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 1e-9) (pow (fma -0.3333333333333333 x 0.1111111111111111) -1.0) (/ (fma -3.0 x -1.0) (fma x x -1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1e-9) {
tmp = pow(fma(-0.3333333333333333, x, 0.1111111111111111), -1.0);
} else {
tmp = fma(-3.0, x, -1.0) / fma(x, x, -1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 1e-9) tmp = fma(-0.3333333333333333, x, 0.1111111111111111) ^ -1.0; else tmp = Float64(fma(-3.0, x, -1.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[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-9], N[Power[N[(-0.3333333333333333 * x + 0.1111111111111111), $MachinePrecision], -1.0], $MachinePrecision], N[(N[(-3.0 * x + -1.0), $MachinePrecision] / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 10^{-9}:\\
\;\;\;\;{\left(\mathsf{fma}\left(-0.3333333333333333, x, 0.1111111111111111\right)\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-3, x, -1\right)}{\mathsf{fma}\left(x, 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.00000000000000006e-9Initial program 8.5%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites5.7%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f6457.2
Applied rewrites57.2%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-fma.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
lift-fma.f6457.3
Applied rewrites57.3%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-fma.f6498.0
Applied rewrites98.0%
if 1.00000000000000006e-9 < (-.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.8%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites99.8%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification98.9%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.002) (pow (fma -0.3333333333333333 x 0.1111111111111111) -1.0) (fma (fma x x 1.0) (* 3.0 x) (fma x x 1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.002) {
tmp = pow(fma(-0.3333333333333333, x, 0.1111111111111111), -1.0);
} else {
tmp = fma(fma(x, x, 1.0), (3.0 * x), fma(x, x, 1.0));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.002) tmp = fma(-0.3333333333333333, x, 0.1111111111111111) ^ -1.0; else tmp = fma(fma(x, x, 1.0), Float64(3.0 * x), fma(x, x, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.002], N[Power[N[(-0.3333333333333333 * x + 0.1111111111111111), $MachinePrecision], -1.0], $MachinePrecision], N[(N[(x * x + 1.0), $MachinePrecision] * N[(3.0 * x), $MachinePrecision] + N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.002:\\
\;\;\;\;{\left(\mathsf{fma}\left(-0.3333333333333333, x, 0.1111111111111111\right)\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, x, 1\right), 3 \cdot x, \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)))) < 2e-3Initial program 9.0%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites6.3%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f6457.5
Applied rewrites57.5%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-fma.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
lift-fma.f6457.6
Applied rewrites57.6%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-fma.f6497.7
Applied rewrites97.7%
if 2e-3 < (-.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%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites99.9%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
lft-mult-inverseN/A
distribute-rgt-inN/A
+-commutativeN/A
lft-mult-inverseN/A
distribute-rgt-inN/A
+-commutativeN/A
associate-*r*N/A
unpow2N/A
distribute-rgt1-inN/A
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
Applied rewrites99.9%
Applied rewrites99.9%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.002) (pow (fma -0.3333333333333333 x 0.1111111111111111) -1.0) (* (fma x x 1.0) (fma 3.0 x 1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.002) {
tmp = pow(fma(-0.3333333333333333, x, 0.1111111111111111), -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(x + 1.0) / Float64(x - 1.0))) <= 0.002) tmp = fma(-0.3333333333333333, x, 0.1111111111111111) ^ -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[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.002], N[Power[N[(-0.3333333333333333 * x + 0.1111111111111111), $MachinePrecision], -1.0], $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{x + 1}{x - 1} \leq 0.002:\\
\;\;\;\;{\left(\mathsf{fma}\left(-0.3333333333333333, x, 0.1111111111111111\right)\right)}^{-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)))) < 2e-3Initial program 9.0%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites6.3%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f6457.5
Applied rewrites57.5%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-fma.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
lift-fma.f6457.6
Applied rewrites57.6%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-fma.f6497.7
Applied rewrites97.7%
if 2e-3 < (-.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
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 1e-9) (/ (- -3.0 (/ (- (/ 3.0 x) -1.0) x)) x) (/ (fma -3.0 x -1.0) (+ x (fma x x (- -1.0 x))))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1e-9) {
tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
} else {
tmp = fma(-3.0, x, -1.0) / (x + fma(x, x, (-1.0 - x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 1e-9) tmp = Float64(Float64(-3.0 - Float64(Float64(Float64(3.0 / x) - -1.0) / x)) / x); else tmp = Float64(fma(-3.0, x, -1.0) / Float64(x + fma(x, x, Float64(-1.0 - x)))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-9], N[(N[(-3.0 - N[(N[(N[(3.0 / x), $MachinePrecision] - -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(-3.0 * x + -1.0), $MachinePrecision] / N[(x + N[(x * x + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 10^{-9}:\\
\;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-3, x, -1\right)}{x + \mathsf{fma}\left(x, x, -1 - x\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.00000000000000006e-9Initial program 8.5%
Taylor expanded in x around inf
Applied rewrites98.9%
if 1.00000000000000006e-9 < (-.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.8%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites99.8%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
lift-+.f64N/A
lift-fma.f64N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 1e-9) (/ (- (/ -1.0 x) 3.0) x) (/ (fma -3.0 x -1.0) (+ x (fma x x (- -1.0 x))))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1e-9) {
tmp = ((-1.0 / x) - 3.0) / x;
} else {
tmp = fma(-3.0, x, -1.0) / (x + fma(x, x, (-1.0 - x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 1e-9) tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / x); else tmp = Float64(fma(-3.0, x, -1.0) / Float64(x + fma(x, x, Float64(-1.0 - x)))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-9], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(-3.0 * x + -1.0), $MachinePrecision] / N[(x + N[(x * x + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 10^{-9}:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-3, x, -1\right)}{x + \mathsf{fma}\left(x, x, -1 - x\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.00000000000000006e-9Initial program 8.5%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f64N/A
neg-mul-1N/A
+-commutativeN/A
distribute-neg-inN/A
sub-negN/A
lower--.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
if 1.00000000000000006e-9 < (-.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.8%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites99.8%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
lift-+.f64N/A
lift-fma.f64N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 1e-9) (/ (- (/ -1.0 x) 3.0) x) (/ (fma -3.0 x -1.0) (fma x x -1.0))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1e-9) {
tmp = ((-1.0 / x) - 3.0) / x;
} else {
tmp = fma(-3.0, x, -1.0) / fma(x, x, -1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 1e-9) tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / x); else tmp = Float64(fma(-3.0, x, -1.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[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-9], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(-3.0 * x + -1.0), $MachinePrecision] / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 10^{-9}:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-3, x, -1\right)}{\mathsf{fma}\left(x, 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.00000000000000006e-9Initial program 8.5%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f64N/A
neg-mul-1N/A
+-commutativeN/A
distribute-neg-inN/A
sub-negN/A
lower--.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6498.5
Applied rewrites98.5%
if 1.00000000000000006e-9 < (-.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.8%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
frac-addN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-sqr-1N/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites99.8%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.002) (/ -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)) - ((x + 1.0) / (x - 1.0))) <= 0.002) {
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(x + 1.0) / Float64(x - 1.0))) <= 0.002) 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[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.002], 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{x + 1}{x - 1} \leq 0.002:\\
\;\;\;\;\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)))) < 2e-3Initial program 9.0%
Taylor expanded in x around inf
lower-/.f6497.3
Applied rewrites97.3%
if 2e-3 < (-.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
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 0.002) (/ -3.0 x) (fma (+ 3.0 x) x 1.0)))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 0.002) {
tmp = -3.0 / x;
} else {
tmp = fma((3.0 + x), x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 0.002) tmp = Float64(-3.0 / x); else tmp = fma(Float64(3.0 + x), x, 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.002], N[(-3.0 / x), $MachinePrecision], N[(N[(3.0 + x), $MachinePrecision] * x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 0.002:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3 + x, 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)))) < 2e-3Initial program 9.0%
Taylor expanded in x around inf
lower-/.f6497.3
Applied rewrites97.3%
if 2e-3 < (-.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
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6499.7
Applied rewrites99.7%
(FPCore (x) :precision binary64 (fma (+ 3.0 x) x 1.0))
double code(double x) {
return fma((3.0 + x), x, 1.0);
}
function code(x) return fma(Float64(3.0 + x), x, 1.0) end
code[x_] := N[(N[(3.0 + x), $MachinePrecision] * x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3 + x, x, 1\right)
\end{array}
Initial program 48.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f6444.9
Applied rewrites44.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 48.8%
Taylor expanded in x around 0
Applied rewrites44.4%
herbie shell --seed 2024323
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))