
(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 9 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 1.0) (+ 1.0 x))))
(if (<= (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))) 1e-5)
(/ (- -3.0 (/ (- (/ 3.0 x) -1.0) x)) x)
(fma (/ t_0 (+ 1.0 x)) (/ x t_0) (/ (- -1.0 x) (- x 1.0))))))
double code(double x) {
double t_0 = (x - 1.0) / (1.0 + x);
double tmp;
if (((x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))) <= 1e-5) {
tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
} else {
tmp = fma((t_0 / (1.0 + x)), (x / t_0), ((-1.0 - x) / (x - 1.0)));
}
return tmp;
}
function code(x) t_0 = Float64(Float64(x - 1.0) / Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) <= 1e-5) tmp = Float64(Float64(-3.0 - Float64(Float64(Float64(3.0 / x) - -1.0) / x)) / x); else tmp = fma(Float64(t_0 / Float64(1.0 + x)), Float64(x / t_0), Float64(Float64(-1.0 - x) / Float64(x - 1.0))); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(x - 1.0), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-5], N[(N[(-3.0 - N[(N[(N[(3.0 / x), $MachinePrecision] - -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(x / t$95$0), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - 1}{1 + x}\\
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 10^{-5}:\\
\;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t\_0}{1 + x}, \frac{x}{t\_0}, \frac{-1 - 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.00000000000000008e-5Initial program 8.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 1.00000000000000008e-5 < (-.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
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-subN/A
lower-/.f64N/A
lift-+.f64N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
lift-+.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
Applied rewrites99.9%
Applied rewrites99.9%
Applied rewrites100.0%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))) 3e-14) (/ (- -3.0 (/ (- (/ 3.0 x) -1.0) x)) x) (/ (/ (fma (fma -3.0 x 2.0) x 1.0) (fma x x -1.0)) (- x 1.0))))
double code(double x) {
double tmp;
if (((x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))) <= 3e-14) {
tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
} else {
tmp = (fma(fma(-3.0, x, 2.0), x, 1.0) / fma(x, x, -1.0)) / (x - 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) <= 3e-14) tmp = Float64(Float64(-3.0 - Float64(Float64(Float64(3.0 / x) - -1.0) / x)) / x); else tmp = Float64(Float64(fma(fma(-3.0, x, 2.0), x, 1.0) / fma(x, x, -1.0)) / Float64(x - 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3e-14], N[(N[(-3.0 - N[(N[(N[(3.0 / x), $MachinePrecision] - -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(N[(-3.0 * x + 2.0), $MachinePrecision] * x + 1.0), $MachinePrecision] / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 3 \cdot 10^{-14}:\\
\;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\mathsf{fma}\left(-3, x, 2\right), x, 1\right)}{\mathsf{fma}\left(x, x, -1\right)}}{x - 1}\\
\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)))) < 2.9999999999999998e-14Initial program 7.2%
Taylor expanded in x around inf
Applied rewrites99.7%
if 2.9999999999999998e-14 < (-.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.0%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-subN/A
lower-/.f64N/A
lift-+.f64N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
lift-+.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
Applied rewrites99.5%
Applied rewrites99.4%
lift--.f64N/A
lift-fma.f64N/A
lift-+.f64N/A
lift-/.f64N/A
associate-*l/N/A
+-commutativeN/A
associate-*r/N/A
lift--.f64N/A
metadata-evalN/A
sub-negN/A
associate--r+N/A
lift--.f64N/A
associate-*r/N/A
+-commutativeN/A
flip-+N/A
lift--.f64N/A
frac-subN/A
Applied rewrites99.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Final simplification99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))))) (if (<= t_0 1e-5) (/ (- -3.0 (/ (- (/ 3.0 x) -1.0) x)) x) t_0)))
double code(double x) {
double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
double tmp;
if (t_0 <= 1e-5) {
tmp = (-3.0 - (((3.0 / x) - -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 / (1.0d0 + x)) - ((1.0d0 + x) / (x - 1.0d0))
if (t_0 <= 1d-5) then
tmp = ((-3.0d0) - (((3.0d0 / x) - (-1.0d0)) / x)) / x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
double tmp;
if (t_0 <= 1e-5) {
tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0)) tmp = 0 if t_0 <= 1e-5: tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) tmp = 0.0 if (t_0 <= 1e-5) tmp = Float64(Float64(-3.0 - Float64(Float64(Float64(3.0 / x) - -1.0) / x)) / x); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0)); tmp = 0.0; if (t_0 <= 1e-5) tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x; else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(N[(-3.0 - N[(N[(N[(3.0 / x), $MachinePrecision] - -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 + x} - \frac{1 + x}{x - 1}\\
\mathbf{if}\;t\_0 \leq 10^{-5}:\\
\;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -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.00000000000000008e-5Initial program 8.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if 1.00000000000000008e-5 < (-.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.8%
(FPCore (x) :precision binary64 (let* ((t_0 (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))))) (if (<= t_0 1e-5) (/ (- (/ 2.0 x) 3.0) (- x 1.0)) t_0)))
double code(double x) {
double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
double tmp;
if (t_0 <= 1e-5) {
tmp = ((2.0 / x) - 3.0) / (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 / (1.0d0 + x)) - ((1.0d0 + x) / (x - 1.0d0))
if (t_0 <= 1d-5) then
tmp = ((2.0d0 / x) - 3.0d0) / (x - 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
double tmp;
if (t_0 <= 1e-5) {
tmp = ((2.0 / x) - 3.0) / (x - 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0)) tmp = 0 if t_0 <= 1e-5: tmp = ((2.0 / x) - 3.0) / (x - 1.0) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) tmp = 0.0 if (t_0 <= 1e-5) tmp = Float64(Float64(Float64(2.0 / x) - 3.0) / Float64(x - 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0)); tmp = 0.0; if (t_0 <= 1e-5) tmp = ((2.0 / x) - 3.0) / (x - 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(N[(N[(2.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 + x} - \frac{1 + x}{x - 1}\\
\mathbf{if}\;t\_0 \leq 10^{-5}:\\
\;\;\;\;\frac{\frac{2}{x} - 3}{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.00000000000000008e-5Initial program 8.5%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-subN/A
lower-/.f64N/A
lift-+.f64N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
lift-+.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
Applied rewrites9.6%
Applied rewrites10.1%
Taylor expanded in x around inf
lower--.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6499.3
Applied rewrites99.3%
if 1.00000000000000008e-5 < (-.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.6%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))) 0.005) (/ (- (/ 2.0 x) 3.0) (- x 1.0)) (* (fma x 3.0 1.0) (fma x x 1.0))))
double code(double x) {
double tmp;
if (((x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))) <= 0.005) {
tmp = ((2.0 / x) - 3.0) / (x - 1.0);
} else {
tmp = fma(x, 3.0, 1.0) * fma(x, x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) <= 0.005) tmp = Float64(Float64(Float64(2.0 / x) - 3.0) / Float64(x - 1.0)); else tmp = Float64(fma(x, 3.0, 1.0) * fma(x, x, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.005], N[(N[(N[(2.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * 3.0 + 1.0), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 1\right) \cdot \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)))) < 0.0050000000000000001Initial program 9.1%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-subN/A
lower-/.f64N/A
lift-+.f64N/A
distribute-rgt1-inN/A
*-rgt-identityN/A
+-commutativeN/A
lift-+.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
Applied rewrites10.3%
Applied rewrites10.7%
Taylor expanded in x around inf
lower--.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.9
Applied rewrites98.9%
if 0.0050000000000000001 < (-.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
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.7
Applied rewrites99.7%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))) 0.005) (/ (- (/ -1.0 x) 3.0) x) (* (fma x 3.0 1.0) (fma x x 1.0))))
double code(double x) {
double tmp;
if (((x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))) <= 0.005) {
tmp = ((-1.0 / x) - 3.0) / x;
} else {
tmp = fma(x, 3.0, 1.0) * fma(x, x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) <= 0.005) tmp = Float64(Float64(Float64(-1.0 / x) - 3.0) / x); else tmp = Float64(fma(x, 3.0, 1.0) * fma(x, x, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.005], N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(x * 3.0 + 1.0), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 1\right) \cdot \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)))) < 0.0050000000000000001Initial program 9.1%
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.8
Applied rewrites98.8%
if 0.0050000000000000001 < (-.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
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.7
Applied rewrites99.7%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))) 0.005) (/ -3.0 x) (* (fma x 3.0 1.0) (fma x x 1.0))))
double code(double x) {
double tmp;
if (((x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))) <= 0.005) {
tmp = -3.0 / x;
} else {
tmp = fma(x, 3.0, 1.0) * fma(x, x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) <= 0.005) tmp = Float64(-3.0 / x); else tmp = Float64(fma(x, 3.0, 1.0) * fma(x, x, 1.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.005], N[(-3.0 / x), $MachinePrecision], N[(N[(x * 3.0 + 1.0), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 1\right) \cdot \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)))) < 0.0050000000000000001Initial program 9.1%
Taylor expanded in x around inf
lower-/.f6497.8
Applied rewrites97.8%
if 0.0050000000000000001 < (-.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
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.7
Applied rewrites99.7%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))) 0.005) (/ -3.0 x) (fma (+ 3.0 x) x 1.0)))
double code(double x) {
double tmp;
if (((x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))) <= 0.005) {
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(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) <= 0.005) 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[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.005], 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}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\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)))) < 0.0050000000000000001Initial program 9.1%
Taylor expanded in x around inf
lower-/.f6497.8
Applied rewrites97.8%
if 0.0050000000000000001 < (-.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
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
Final simplification98.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 55.6%
Taylor expanded in x around 0
Applied rewrites52.5%
herbie shell --seed 2024268
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))