
(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)) (/ (- -1.0 x) (+ x -1.0)))))
(if (<= t_0 0.0001)
(- (/ -3.0 x) (+ (/ 3.0 (pow x 3.0)) (+ (pow x -2.0) (pow x -4.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 <= 0.0001) {
tmp = (-3.0 / x) - ((3.0 / pow(x, 3.0)) + (pow(x, -2.0) + pow(x, -4.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 <= 0.0001d0) then
tmp = ((-3.0d0) / x) - ((3.0d0 / (x ** 3.0d0)) + ((x ** (-2.0d0)) + (x ** (-4.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 <= 0.0001) {
tmp = (-3.0 / x) - ((3.0 / Math.pow(x, 3.0)) + (Math.pow(x, -2.0) + Math.pow(x, -4.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 <= 0.0001: tmp = (-3.0 / x) - ((3.0 / math.pow(x, 3.0)) + (math.pow(x, -2.0) + math.pow(x, -4.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 <= 0.0001) tmp = Float64(Float64(-3.0 / x) - Float64(Float64(3.0 / (x ^ 3.0)) + Float64((x ^ -2.0) + (x ^ -4.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 <= 0.0001) tmp = (-3.0 / x) - ((3.0 / (x ^ 3.0)) + ((x ^ -2.0) + (x ^ -4.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, 0.0001], N[(N[(-3.0 / x), $MachinePrecision] - N[(N[(3.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, -2.0], $MachinePrecision] + N[Power[x, -4.0], $MachinePrecision]), $MachinePrecision]), $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 0.0001:\\
\;\;\;\;\frac{-3}{x} - \left(\frac{3}{{x}^{3}} + \left({x}^{-2} + {x}^{-4}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000005e-4Initial program 9.6%
clear-num9.5%
associate-/r/9.4%
Applied egg-rr9.4%
Taylor expanded in x around inf 99.1%
+-commutative99.1%
associate-+r+99.1%
+-commutative99.1%
distribute-neg-in99.1%
unsub-neg99.1%
associate-*r/99.5%
metadata-eval99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
if 1.00000000000000005e-4 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 100.0%
Final simplification99.8%
(FPCore (x)
:precision binary64
(if (<= (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))) 0.0)
(+ (* 3.0 (/ -1.0 (pow x 3.0))) (/ (- (/ -1.0 x) 3.0) x))
(/
(+
(fma x (- 1.0 x) (* (+ x 1.0) (+ x 1.0)))
(fma (+ x 1.0) (+ x 1.0) (* (+ x 1.0) (- -1.0 x))))
(* (+ x 1.0) (- 1.0 x)))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0))) <= 0.0) {
tmp = (3.0 * (-1.0 / pow(x, 3.0))) + (((-1.0 / x) - 3.0) / x);
} else {
tmp = (fma(x, (1.0 - x), ((x + 1.0) * (x + 1.0))) + fma((x + 1.0), (x + 1.0), ((x + 1.0) * (-1.0 - x)))) / ((x + 1.0) * (1.0 - x));
}
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))) <= 0.0) tmp = Float64(Float64(3.0 * Float64(-1.0 / (x ^ 3.0))) + Float64(Float64(Float64(-1.0 / x) - 3.0) / x)); else tmp = Float64(Float64(fma(x, Float64(1.0 - x), Float64(Float64(x + 1.0) * Float64(x + 1.0))) + fma(Float64(x + 1.0), Float64(x + 1.0), Float64(Float64(x + 1.0) * Float64(-1.0 - x)))) / Float64(Float64(x + 1.0) * Float64(1.0 - x))); 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], 0.0], N[(N[(3.0 * N[(-1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * N[(1.0 - x), $MachinePrecision] + N[(N[(x + 1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(x + 1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision] + N[(N[(x + 1.0), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 0:\\
\;\;\;\;3 \cdot \frac{-1}{{x}^{3}} + \frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, 1 - x, \left(x + 1\right) \cdot \left(x + 1\right)\right) + \mathsf{fma}\left(x + 1, x + 1, \left(x + 1\right) \cdot \left(-1 - x\right)\right)}{\left(x + 1\right) \cdot \left(1 - x\right)}\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 0.0Initial program 8.0%
Taylor expanded in x around inf 98.9%
metadata-eval98.4%
unpow298.4%
frac-times98.4%
Applied egg-rr98.9%
distribute-rgt-out98.9%
associate-*l/99.3%
*-un-lft-identity99.3%
Applied egg-rr99.3%
if 0.0 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 99.4%
clear-num99.4%
associate-/r/99.4%
Applied egg-rr99.4%
associate-*l/99.4%
*-un-lft-identity99.4%
frac-2neg99.4%
frac-sub99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
distribute-neg-in99.3%
metadata-eval99.3%
*-rgt-identity99.3%
sub-neg99.3%
*-rgt-identity99.3%
+-commutative99.3%
+-commutative99.3%
distribute-neg-in99.3%
metadata-eval99.3%
+-commutative99.3%
sub-neg99.3%
Applied egg-rr99.3%
metadata-eval99.3%
remove-double-neg99.3%
distribute-neg-in99.3%
distribute-neg-in99.3%
metadata-eval99.3%
remove-double-neg99.3%
unsub-neg99.3%
Simplified99.3%
prod-diff99.9%
*-commutative99.9%
*-commutative99.9%
Applied egg-rr99.9%
distribute-lft-neg-in99.9%
distribute-neg-in99.9%
metadata-eval99.9%
sub-neg99.9%
Simplified99.9%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0)))))
(if (<= t_0 0.0001)
(+ (* 3.0 (/ -1.0 (pow x 3.0))) (/ (- (/ -1.0 x) 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 <= 0.0001) {
tmp = (3.0 * (-1.0 / pow(x, 3.0))) + (((-1.0 / x) - 3.0) / 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 <= 0.0001d0) then
tmp = (3.0d0 * ((-1.0d0) / (x ** 3.0d0))) + ((((-1.0d0) / x) - 3.0d0) / 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 <= 0.0001) {
tmp = (3.0 * (-1.0 / Math.pow(x, 3.0))) + (((-1.0 / x) - 3.0) / 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 <= 0.0001: tmp = (3.0 * (-1.0 / math.pow(x, 3.0))) + (((-1.0 / x) - 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 <= 0.0001) tmp = Float64(Float64(3.0 * Float64(-1.0 / (x ^ 3.0))) + Float64(Float64(Float64(-1.0 / x) - 3.0) / 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 <= 0.0001) tmp = (3.0 * (-1.0 / (x ^ 3.0))) + (((-1.0 / x) - 3.0) / 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, 0.0001], N[(N[(3.0 * N[(-1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-1.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $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 0.0001:\\
\;\;\;\;3 \cdot \frac{-1}{{x}^{3}} + \frac{\frac{-1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000005e-4Initial program 9.6%
Taylor expanded in x around inf 98.8%
metadata-eval97.9%
unpow297.9%
frac-times97.9%
Applied egg-rr98.8%
distribute-rgt-out98.8%
associate-*l/99.2%
*-un-lft-identity99.2%
Applied egg-rr99.2%
if 1.00000000000000005e-4 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 100.0%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ x (+ x 1.0))))
(if (<= (+ t_0 (/ (- -1.0 x) (+ x -1.0))) 2e-10)
(/ (+ -3.0 (/ -1.0 x)) x)
(+ t_0 (* (+ x 1.0) (/ -1.0 (+ x -1.0)))))))
double code(double x) {
double t_0 = x / (x + 1.0);
double tmp;
if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 2e-10) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = t_0 + ((x + 1.0) * (-1.0 / (x + -1.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)
if ((t_0 + (((-1.0d0) - x) / (x + (-1.0d0)))) <= 2d-10) then
tmp = ((-3.0d0) + ((-1.0d0) / x)) / x
else
tmp = t_0 + ((x + 1.0d0) * ((-1.0d0) / (x + (-1.0d0))))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = x / (x + 1.0);
double tmp;
if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 2e-10) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = t_0 + ((x + 1.0) * (-1.0 / (x + -1.0)));
}
return tmp;
}
def code(x): t_0 = x / (x + 1.0) tmp = 0 if (t_0 + ((-1.0 - x) / (x + -1.0))) <= 2e-10: tmp = (-3.0 + (-1.0 / x)) / x else: tmp = t_0 + ((x + 1.0) * (-1.0 / (x + -1.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-10) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = Float64(t_0 + Float64(Float64(x + 1.0) * Float64(-1.0 / Float64(x + -1.0)))); end return tmp end
function tmp_2 = code(x) t_0 = x / (x + 1.0); tmp = 0.0; if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 2e-10) tmp = (-3.0 + (-1.0 / x)) / x; else tmp = t_0 + ((x + 1.0) * (-1.0 / (x + -1.0))); end tmp_2 = 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-10], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(t$95$0 + N[(N[(x + 1.0), $MachinePrecision] * N[(-1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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^{-10}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \left(x + 1\right) \cdot \frac{-1}{x + -1}\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 2.00000000000000007e-10Initial program 8.4%
clear-num8.3%
associate-/r/8.2%
Applied egg-rr8.2%
Taylor expanded in x around inf 98.4%
distribute-neg-in98.4%
exp-to-pow49.4%
*-commutative49.4%
exp-neg49.4%
distribute-lft-neg-in49.4%
metadata-eval49.4%
log-pow98.4%
rem-exp-log98.4%
unsub-neg98.4%
associate-*r/98.8%
metadata-eval98.8%
distribute-neg-frac98.8%
metadata-eval98.8%
Simplified98.8%
metadata-eval98.8%
pow-div98.8%
inv-pow98.8%
pow198.8%
sub-div98.8%
Applied egg-rr98.8%
if 2.00000000000000007e-10 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 99.7%
clear-num99.7%
associate-/r/99.7%
sub-neg99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.3%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0))))) (if (<= t_0 2e-10) (/ (+ -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-10) {
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-10) 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-10) {
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-10: 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-10) 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-10) 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-10], 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^{-10}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 2.00000000000000007e-10Initial program 8.4%
clear-num8.3%
associate-/r/8.2%
Applied egg-rr8.2%
Taylor expanded in x around inf 98.4%
distribute-neg-in98.4%
exp-to-pow49.4%
*-commutative49.4%
exp-neg49.4%
distribute-lft-neg-in49.4%
metadata-eval49.4%
log-pow98.4%
rem-exp-log98.4%
unsub-neg98.4%
associate-*r/98.8%
metadata-eval98.8%
distribute-neg-frac98.8%
metadata-eval98.8%
Simplified98.8%
metadata-eval98.8%
pow-div98.8%
inv-pow98.8%
pow198.8%
sub-div98.8%
Applied egg-rr98.8%
if 2.00000000000000007e-10 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 99.7%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-3.0d0) / x
else
tmp = 1.0d0 + (x * (x + 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 + (x * (x + 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0 + (x * (x + 3.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.6%
Taylor expanded in x around inf 97.1%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.7%
unpow299.7%
distribute-rgt-out99.7%
Simplified99.7%
Final simplification98.5%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ (+ -3.0 (/ -1.0 x)) x) (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = ((-3.0d0) + ((-1.0d0) / x)) / x
else
tmp = 1.0d0 + (x * (x + 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = (-3.0 + (-1.0 / x)) / x else: tmp = 1.0 + (x * (x + 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = (-3.0 + (-1.0 / x)) / x; else tmp = 1.0 + (x * (x + 3.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.6%
clear-num9.5%
associate-/r/9.4%
Applied egg-rr9.4%
Taylor expanded in x around inf 97.9%
distribute-neg-in97.9%
exp-to-pow48.6%
*-commutative48.6%
exp-neg48.6%
distribute-lft-neg-in48.6%
metadata-eval48.6%
log-pow97.9%
rem-exp-log97.9%
unsub-neg97.9%
associate-*r/98.3%
metadata-eval98.3%
distribute-neg-frac98.3%
metadata-eval98.3%
Simplified98.3%
metadata-eval98.3%
pow-div98.3%
inv-pow98.3%
pow198.3%
sub-div98.3%
Applied egg-rr98.3%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.7%
unpow299.7%
distribute-rgt-out99.7%
Simplified99.7%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= x -1.0) (- (* (/ 1.0 x) (/ -1.0 x)) (/ 3.0 x)) (if (<= x 1.0) (+ 1.0 (* x (+ x 3.0))) (/ (+ -3.0 (/ -1.0 x)) x))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = ((1.0 / x) * (-1.0 / x)) - (3.0 / x);
} else if (x <= 1.0) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = (-3.0 + (-1.0 / x)) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = ((1.0d0 / x) * ((-1.0d0) / x)) - (3.0d0 / x)
else if (x <= 1.0d0) then
tmp = 1.0d0 + (x * (x + 3.0d0))
else
tmp = ((-3.0d0) + ((-1.0d0) / x)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = ((1.0 / x) * (-1.0 / x)) - (3.0 / x);
} else if (x <= 1.0) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = (-3.0 + (-1.0 / x)) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = ((1.0 / x) * (-1.0 / x)) - (3.0 / x) elif x <= 1.0: tmp = 1.0 + (x * (x + 3.0)) else: tmp = (-3.0 + (-1.0 / x)) / x return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(Float64(1.0 / x) * Float64(-1.0 / x)) - Float64(3.0 / x)); elseif (x <= 1.0) tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); else tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = ((1.0 / x) * (-1.0 / x)) - (3.0 / x); elseif (x <= 1.0) tmp = 1.0 + (x * (x + 3.0)); else tmp = (-3.0 + (-1.0 / x)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], N[(N[(N[(1.0 / x), $MachinePrecision] * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] - N[(3.0 / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{1}{x} \cdot \frac{-1}{x} - \frac{3}{x}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\end{array}
\end{array}
if x < -1Initial program 8.7%
Taylor expanded in x around inf 98.5%
metadata-eval98.5%
unpow298.5%
frac-times98.5%
Applied egg-rr98.5%
Taylor expanded in x around 0 98.9%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.7%
unpow299.7%
distribute-rgt-out99.7%
Simplified99.7%
if 1 < x Initial program 10.5%
clear-num10.2%
associate-/r/10.7%
Applied egg-rr10.7%
Taylor expanded in x around inf 97.2%
distribute-neg-in97.2%
exp-to-pow97.2%
*-commutative97.2%
exp-neg97.2%
distribute-lft-neg-in97.2%
metadata-eval97.2%
log-pow97.2%
rem-exp-log97.2%
unsub-neg97.2%
associate-*r/97.6%
metadata-eval97.6%
distribute-neg-frac97.6%
metadata-eval97.6%
Simplified97.6%
metadata-eval97.6%
pow-div97.6%
inv-pow97.6%
pow197.6%
sub-div97.7%
Applied egg-rr97.7%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) (+ 1.0 (* x 3.0))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * 3.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-3.0d0) / x
else
tmp = 1.0d0 + (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * 3.0);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 + (x * 3.0) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = Float64(1.0 + Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0 + (x * 3.0); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], N[(1.0 + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot 3\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.6%
Taylor expanded in x around inf 97.1%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification98.4%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) 1.0))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-3.0d0) / x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.6%
Taylor expanded in x around inf 97.1%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 97.5%
Final simplification97.3%
(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 57.6%
Taylor expanded in x around 0 53.6%
Final simplification53.6%
herbie shell --seed 2024017
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))