
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}
(FPCore (x) :precision binary64 (* (/ (/ 1.0 (+ 1.0 x)) (fma x x (- x))) 2.0))
double code(double x) {
return ((1.0 / (1.0 + x)) / fma(x, x, -x)) * 2.0;
}
function code(x) return Float64(Float64(Float64(1.0 / Float64(1.0 + x)) / fma(x, x, Float64(-x))) * 2.0) end
code[x_] := N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(x * x + (-x)), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{1 + x}}{\mathsf{fma}\left(x, x, -x\right)} \cdot 2
\end{array}
Initial program 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
frac-sub55.2%
frac-sub55.9%
*-un-lft-identity55.9%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
*-rgt-identity55.6%
distribute-rgt-in55.6%
metadata-eval55.6%
metadata-eval55.6%
fma-def55.6%
metadata-eval55.6%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
Applied egg-rr55.6%
+-commutative55.6%
remove-double-neg55.6%
metadata-eval55.6%
distribute-neg-in55.6%
neg-mul-155.6%
*-commutative55.6%
fma-udef55.6%
distribute-lft-neg-in55.6%
distribute-lft-neg-in55.6%
fma-udef55.6%
*-commutative55.6%
neg-mul-155.6%
distribute-neg-in55.6%
remove-double-neg55.6%
metadata-eval55.6%
+-commutative55.6%
Simplified55.6%
Taylor expanded in x around 0 99.8%
clear-num99.8%
associate-/r/99.8%
associate-/r*99.9%
fma-neg99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (* (/ 2.0 (+ 1.0 x)) (/ 1.0 (fma x x (- x)))))
double code(double x) {
return (2.0 / (1.0 + x)) * (1.0 / fma(x, x, -x));
}
function code(x) return Float64(Float64(2.0 / Float64(1.0 + x)) * Float64(1.0 / fma(x, x, Float64(-x)))) end
code[x_] := N[(N[(2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(x * x + (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + x} \cdot \frac{1}{\mathsf{fma}\left(x, x, -x\right)}
\end{array}
Initial program 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
frac-sub55.2%
frac-sub55.9%
*-un-lft-identity55.9%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
*-rgt-identity55.6%
distribute-rgt-in55.6%
metadata-eval55.6%
metadata-eval55.6%
fma-def55.6%
metadata-eval55.6%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
Applied egg-rr55.6%
+-commutative55.6%
remove-double-neg55.6%
metadata-eval55.6%
distribute-neg-in55.6%
neg-mul-155.6%
*-commutative55.6%
fma-udef55.6%
distribute-lft-neg-in55.6%
distribute-lft-neg-in55.6%
fma-udef55.6%
*-commutative55.6%
neg-mul-155.6%
distribute-neg-in55.6%
remove-double-neg55.6%
metadata-eval55.6%
+-commutative55.6%
Simplified55.6%
Taylor expanded in x around 0 99.8%
associate-/r*99.9%
div-inv99.9%
fma-neg99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (/ 2.0 (- (pow x 3.0) x)))
double code(double x) {
return 2.0 / (pow(x, 3.0) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((x ** 3.0d0) - x)
end function
public static double code(double x) {
return 2.0 / (Math.pow(x, 3.0) - x);
}
def code(x): return 2.0 / (math.pow(x, 3.0) - x)
function code(x) return Float64(2.0 / Float64((x ^ 3.0) - x)) end
function tmp = code(x) tmp = 2.0 / ((x ^ 3.0) - x); end
code[x_] := N[(2.0 / N[(N[Power[x, 3.0], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{{x}^{3} - x}
\end{array}
Initial program 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
frac-sub55.2%
frac-sub55.9%
*-un-lft-identity55.9%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
*-rgt-identity55.6%
distribute-rgt-in55.6%
metadata-eval55.6%
metadata-eval55.6%
fma-def55.6%
metadata-eval55.6%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
Applied egg-rr55.6%
+-commutative55.6%
remove-double-neg55.6%
metadata-eval55.6%
distribute-neg-in55.6%
neg-mul-155.6%
*-commutative55.6%
fma-udef55.6%
distribute-lft-neg-in55.6%
distribute-lft-neg-in55.6%
fma-udef55.6%
*-commutative55.6%
neg-mul-155.6%
distribute-neg-in55.6%
remove-double-neg55.6%
metadata-eval55.6%
+-commutative55.6%
Simplified55.6%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
+-commutative99.8%
unsub-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (or (<= x -0.86) (not (<= x 1.0))) (* (/ 2.0 (+ 1.0 x)) (/ 1.0 (* x x))) (- (* x -2.0) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -0.86) || !(x <= 1.0)) {
tmp = (2.0 / (1.0 + x)) * (1.0 / (x * x));
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.86d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (2.0d0 / (1.0d0 + x)) * (1.0d0 / (x * x))
else
tmp = (x * (-2.0d0)) - (2.0d0 / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -0.86) || !(x <= 1.0)) {
tmp = (2.0 / (1.0 + x)) * (1.0 / (x * x));
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.86) or not (x <= 1.0): tmp = (2.0 / (1.0 + x)) * (1.0 / (x * x)) else: tmp = (x * -2.0) - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -0.86) || !(x <= 1.0)) tmp = Float64(Float64(2.0 / Float64(1.0 + x)) * Float64(1.0 / Float64(x * x))); else tmp = Float64(Float64(x * -2.0) - Float64(2.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.86) || ~((x <= 1.0))) tmp = (2.0 / (1.0 + x)) * (1.0 / (x * x)); else tmp = (x * -2.0) - (2.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.86], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.86 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{2}{1 + x} \cdot \frac{1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\end{array}
\end{array}
if x < -0.859999999999999987 or 1 < x Initial program 66.5%
associate-+l-66.5%
sub-neg66.5%
neg-mul-166.5%
metadata-eval66.5%
cancel-sign-sub-inv66.5%
+-commutative66.5%
*-lft-identity66.5%
sub-neg66.5%
metadata-eval66.5%
Simplified66.5%
frac-sub13.2%
frac-sub14.5%
*-un-lft-identity14.5%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
*-rgt-identity14.0%
distribute-rgt-in14.0%
metadata-eval14.0%
metadata-eval14.0%
fma-def14.0%
metadata-eval14.0%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
Applied egg-rr14.0%
+-commutative14.0%
remove-double-neg14.0%
metadata-eval14.0%
distribute-neg-in14.0%
neg-mul-114.0%
*-commutative14.0%
fma-udef14.0%
distribute-lft-neg-in14.0%
distribute-lft-neg-in14.0%
fma-udef14.0%
*-commutative14.0%
neg-mul-114.0%
distribute-neg-in14.0%
remove-double-neg14.0%
metadata-eval14.0%
+-commutative14.0%
Simplified14.0%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 97.4%
unpow297.4%
Simplified97.4%
associate-/r*97.7%
div-inv97.6%
+-commutative97.6%
Applied egg-rr97.6%
if -0.859999999999999987 < x < 1Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
neg-mul-1100.0%
metadata-eval100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-lft-identity100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
associate-*r/99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.85))) (/ 2.0 (* x (* x (+ x -1.0)))) (- (* x -2.0) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.85)) {
tmp = 2.0 / (x * (x * (x + -1.0)));
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 0.85d0))) then
tmp = 2.0d0 / (x * (x * (x + (-1.0d0))))
else
tmp = (x * (-2.0d0)) - (2.0d0 / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.85)) {
tmp = 2.0 / (x * (x * (x + -1.0)));
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 0.85): tmp = 2.0 / (x * (x * (x + -1.0))) else: tmp = (x * -2.0) - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.85)) tmp = Float64(2.0 / Float64(x * Float64(x * Float64(x + -1.0)))); else tmp = Float64(Float64(x * -2.0) - Float64(2.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.85))) tmp = 2.0 / (x * (x * (x + -1.0))); else tmp = (x * -2.0) - (2.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.85]], $MachinePrecision]], N[(2.0 / N[(x * N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.85\right):\\
\;\;\;\;\frac{2}{x \cdot \left(x \cdot \left(x + -1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\end{array}
\end{array}
if x < -1 or 0.849999999999999978 < x Initial program 66.5%
associate-+l-66.5%
sub-neg66.5%
neg-mul-166.5%
metadata-eval66.5%
cancel-sign-sub-inv66.5%
+-commutative66.5%
*-lft-identity66.5%
sub-neg66.5%
metadata-eval66.5%
Simplified66.5%
frac-sub13.2%
frac-sub14.5%
*-un-lft-identity14.5%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
*-rgt-identity14.0%
distribute-rgt-in14.0%
metadata-eval14.0%
metadata-eval14.0%
fma-def14.0%
metadata-eval14.0%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
Applied egg-rr14.0%
+-commutative14.0%
remove-double-neg14.0%
metadata-eval14.0%
distribute-neg-in14.0%
neg-mul-114.0%
*-commutative14.0%
fma-udef14.0%
distribute-lft-neg-in14.0%
distribute-lft-neg-in14.0%
fma-udef14.0%
*-commutative14.0%
neg-mul-114.0%
distribute-neg-in14.0%
remove-double-neg14.0%
metadata-eval14.0%
+-commutative14.0%
Simplified14.0%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 97.4%
unpow297.4%
Simplified97.4%
*-commutative97.4%
+-commutative97.4%
distribute-rgt-in71.7%
*-un-lft-identity71.7%
sqr-neg71.7%
neg-mul-171.7%
associate-*l*71.7%
add-sqr-sqrt25.7%
sqrt-unprod44.4%
sqr-neg44.4%
sqrt-prod18.7%
add-sqr-sqrt70.1%
cube-mult70.2%
fma-def70.2%
Applied egg-rr70.2%
fma-udef70.2%
associate-*r*70.2%
*-commutative70.2%
cube-mult70.1%
distribute-lft-out97.4%
distribute-rgt-out97.4%
Simplified97.4%
if -1 < x < 0.849999999999999978Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
neg-mul-1100.0%
metadata-eval100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-lft-identity100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
associate-*r/99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (or (<= x -0.86) (not (<= x 1.0))) (/ 2.0 (* (+ 1.0 x) (* x x))) (- (* x -2.0) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -0.86) || !(x <= 1.0)) {
tmp = 2.0 / ((1.0 + x) * (x * x));
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.86d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 2.0d0 / ((1.0d0 + x) * (x * x))
else
tmp = (x * (-2.0d0)) - (2.0d0 / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -0.86) || !(x <= 1.0)) {
tmp = 2.0 / ((1.0 + x) * (x * x));
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.86) or not (x <= 1.0): tmp = 2.0 / ((1.0 + x) * (x * x)) else: tmp = (x * -2.0) - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -0.86) || !(x <= 1.0)) tmp = Float64(2.0 / Float64(Float64(1.0 + x) * Float64(x * x))); else tmp = Float64(Float64(x * -2.0) - Float64(2.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.86) || ~((x <= 1.0))) tmp = 2.0 / ((1.0 + x) * (x * x)); else tmp = (x * -2.0) - (2.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.86], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(2.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.86 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{2}{\left(1 + x\right) \cdot \left(x \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\end{array}
\end{array}
if x < -0.859999999999999987 or 1 < x Initial program 66.5%
associate-+l-66.5%
sub-neg66.5%
neg-mul-166.5%
metadata-eval66.5%
cancel-sign-sub-inv66.5%
+-commutative66.5%
*-lft-identity66.5%
sub-neg66.5%
metadata-eval66.5%
Simplified66.5%
frac-sub13.2%
frac-sub14.5%
*-un-lft-identity14.5%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
*-rgt-identity14.0%
distribute-rgt-in14.0%
metadata-eval14.0%
metadata-eval14.0%
fma-def14.0%
metadata-eval14.0%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
Applied egg-rr14.0%
+-commutative14.0%
remove-double-neg14.0%
metadata-eval14.0%
distribute-neg-in14.0%
neg-mul-114.0%
*-commutative14.0%
fma-udef14.0%
distribute-lft-neg-in14.0%
distribute-lft-neg-in14.0%
fma-udef14.0%
*-commutative14.0%
neg-mul-114.0%
distribute-neg-in14.0%
remove-double-neg14.0%
metadata-eval14.0%
+-commutative14.0%
Simplified14.0%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 97.4%
unpow297.4%
Simplified97.4%
if -0.859999999999999987 < x < 1Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
neg-mul-1100.0%
metadata-eval100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-lft-identity100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
associate-*r/99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification98.6%
(FPCore (x) :precision binary64 (/ 2.0 (* (+ 1.0 x) (* x (+ x -1.0)))))
double code(double x) {
return 2.0 / ((1.0 + x) * (x * (x + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((1.0d0 + x) * (x * (x + (-1.0d0))))
end function
public static double code(double x) {
return 2.0 / ((1.0 + x) * (x * (x + -1.0)));
}
def code(x): return 2.0 / ((1.0 + x) * (x * (x + -1.0)))
function code(x) return Float64(2.0 / Float64(Float64(1.0 + x) * Float64(x * Float64(x + -1.0)))) end
function tmp = code(x) tmp = 2.0 / ((1.0 + x) * (x * (x + -1.0))); end
code[x_] := N[(2.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\end{array}
Initial program 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
frac-sub55.2%
frac-sub55.9%
*-un-lft-identity55.9%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
*-rgt-identity55.6%
distribute-rgt-in55.6%
metadata-eval55.6%
metadata-eval55.6%
fma-def55.6%
metadata-eval55.6%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
Applied egg-rr55.6%
+-commutative55.6%
remove-double-neg55.6%
metadata-eval55.6%
distribute-neg-in55.6%
neg-mul-155.6%
*-commutative55.6%
fma-udef55.6%
distribute-lft-neg-in55.6%
distribute-lft-neg-in55.6%
fma-udef55.6%
*-commutative55.6%
neg-mul-155.6%
distribute-neg-in55.6%
remove-double-neg55.6%
metadata-eval55.6%
+-commutative55.6%
Simplified55.6%
Taylor expanded in x around 0 99.8%
*-un-lft-identity99.8%
distribute-rgt-out--99.8%
sub-neg99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (/ 2.0 (* (+ 1.0 x) (- (* x x) x))))
double code(double x) {
return 2.0 / ((1.0 + x) * ((x * x) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((1.0d0 + x) * ((x * x) - x))
end function
public static double code(double x) {
return 2.0 / ((1.0 + x) * ((x * x) - x));
}
def code(x): return 2.0 / ((1.0 + x) * ((x * x) - x))
function code(x) return Float64(2.0 / Float64(Float64(1.0 + x) * Float64(Float64(x * x) - x))) end
function tmp = code(x) tmp = 2.0 / ((1.0 + x) * ((x * x) - x)); end
code[x_] := N[(2.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\end{array}
Initial program 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
frac-sub55.2%
frac-sub55.9%
*-un-lft-identity55.9%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
*-rgt-identity55.6%
distribute-rgt-in55.6%
metadata-eval55.6%
metadata-eval55.6%
fma-def55.6%
metadata-eval55.6%
distribute-rgt-in55.6%
neg-mul-155.6%
sub-neg55.6%
Applied egg-rr55.6%
+-commutative55.6%
remove-double-neg55.6%
metadata-eval55.6%
distribute-neg-in55.6%
neg-mul-155.6%
*-commutative55.6%
fma-udef55.6%
distribute-lft-neg-in55.6%
distribute-lft-neg-in55.6%
fma-udef55.6%
*-commutative55.6%
neg-mul-155.6%
distribute-neg-in55.6%
remove-double-neg55.6%
metadata-eval55.6%
+-commutative55.6%
Simplified55.6%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (or (<= x -0.56) (not (<= x 1.0))) (/ 2.0 (* x x)) (- (/ -2.0 x) x)))
double code(double x) {
double tmp;
if ((x <= -0.56) || !(x <= 1.0)) {
tmp = 2.0 / (x * x);
} else {
tmp = (-2.0 / x) - x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.56d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 2.0d0 / (x * x)
else
tmp = ((-2.0d0) / x) - x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -0.56) || !(x <= 1.0)) {
tmp = 2.0 / (x * x);
} else {
tmp = (-2.0 / x) - x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.56) or not (x <= 1.0): tmp = 2.0 / (x * x) else: tmp = (-2.0 / x) - x return tmp
function code(x) tmp = 0.0 if ((x <= -0.56) || !(x <= 1.0)) tmp = Float64(2.0 / Float64(x * x)); else tmp = Float64(Float64(-2.0 / x) - x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.56) || ~((x <= 1.0))) tmp = 2.0 / (x * x); else tmp = (-2.0 / x) - x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.56], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 / x), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.56 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{2}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x} - x\\
\end{array}
\end{array}
if x < -0.56000000000000005 or 1 < x Initial program 66.5%
associate-+l-66.5%
sub-neg66.5%
neg-mul-166.5%
metadata-eval66.5%
cancel-sign-sub-inv66.5%
+-commutative66.5%
*-lft-identity66.5%
sub-neg66.5%
metadata-eval66.5%
Simplified66.5%
frac-sub13.2%
frac-sub14.5%
*-un-lft-identity14.5%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
*-rgt-identity14.0%
distribute-rgt-in14.0%
metadata-eval14.0%
metadata-eval14.0%
fma-def14.0%
metadata-eval14.0%
distribute-rgt-in14.0%
neg-mul-114.0%
sub-neg14.0%
Applied egg-rr14.0%
+-commutative14.0%
remove-double-neg14.0%
metadata-eval14.0%
distribute-neg-in14.0%
neg-mul-114.0%
*-commutative14.0%
fma-udef14.0%
distribute-lft-neg-in14.0%
distribute-lft-neg-in14.0%
fma-udef14.0%
*-commutative14.0%
neg-mul-114.0%
distribute-neg-in14.0%
remove-double-neg14.0%
metadata-eval14.0%
+-commutative14.0%
Simplified14.0%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 97.4%
unpow297.4%
Simplified97.4%
Taylor expanded in x around 0 55.6%
unpow255.6%
Simplified55.6%
if -0.56000000000000005 < x < 1Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
neg-mul-1100.0%
metadata-eval100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-lft-identity100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.4%
Taylor expanded in x around 0 99.4%
neg-mul-199.4%
+-commutative99.4%
sub-neg99.4%
unpow299.4%
associate-*r/99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around 0 99.4%
sub-neg99.4%
neg-mul-199.4%
+-commutative99.4%
associate-*r/99.4%
metadata-eval99.4%
distribute-neg-frac99.4%
metadata-eval99.4%
unsub-neg99.4%
Simplified99.4%
Final simplification76.8%
(FPCore (x) :precision binary64 (+ 1.0 (- -1.0 (/ 2.0 x))))
double code(double x) {
return 1.0 + (-1.0 - (2.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + ((-1.0d0) - (2.0d0 / x))
end function
public static double code(double x) {
return 1.0 + (-1.0 - (2.0 / x));
}
def code(x): return 1.0 + (-1.0 - (2.0 / x))
function code(x) return Float64(1.0 + Float64(-1.0 - Float64(2.0 / x))) end
function tmp = code(x) tmp = 1.0 + (-1.0 - (2.0 / x)); end
code[x_] := N[(1.0 + N[(-1.0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(-1 - \frac{2}{x}\right)
\end{array}
Initial program 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
Taylor expanded in x around 0 49.9%
Taylor expanded in x around 0 81.4%
Final simplification81.4%
(FPCore (x) :precision binary64 (/ -2.0 x))
double code(double x) {
return -2.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / x
end function
public static double code(double x) {
return -2.0 / x;
}
def code(x): return -2.0 / x
function code(x) return Float64(-2.0 / x) end
function tmp = code(x) tmp = -2.0 / x; end
code[x_] := N[(-2.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x}
\end{array}
Initial program 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
Taylor expanded in x around 0 50.6%
Final simplification50.6%
(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 82.7%
associate-+l-82.7%
sub-neg82.7%
neg-mul-182.7%
metadata-eval82.7%
cancel-sign-sub-inv82.7%
+-commutative82.7%
*-lft-identity82.7%
sub-neg82.7%
metadata-eval82.7%
Simplified82.7%
Taylor expanded in x around 0 49.9%
Taylor expanded in x around inf 3.3%
Final simplification3.3%
(FPCore (x) :precision binary64 (/ 2.0 (* x (- (* x x) 1.0))))
double code(double x) {
return 2.0 / (x * ((x * x) - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (x * ((x * x) - 1.0d0))
end function
public static double code(double x) {
return 2.0 / (x * ((x * x) - 1.0));
}
def code(x): return 2.0 / (x * ((x * x) - 1.0))
function code(x) return Float64(2.0 / Float64(x * Float64(Float64(x * x) - 1.0))) end
function tmp = code(x) tmp = 2.0 / (x * ((x * x) - 1.0)); end
code[x_] := N[(2.0 / N[(x * N[(N[(x * x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x \cdot \left(x \cdot x - 1\right)}
\end{array}
herbie shell --seed 2023194
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:herbie-target
(/ 2.0 (* x (- (* x x) 1.0)))
(+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))