
(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 11 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 (/ (/ 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(Float64(2.0 / 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[(N[(2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{1 + x}}{x \cdot x - x}
\end{array}
Initial program 86.0%
associate-+l-86.0%
sub-neg86.0%
neg-mul-186.0%
metadata-eval86.0%
cancel-sign-sub-inv86.0%
+-commutative86.0%
*-lft-identity86.0%
sub-neg86.0%
metadata-eval86.0%
Simplified86.0%
frac-sub57.1%
frac-sub59.6%
*-un-lft-identity59.6%
distribute-rgt-in59.7%
neg-mul-159.7%
sub-neg59.7%
*-rgt-identity59.7%
distribute-rgt-in59.7%
metadata-eval59.7%
metadata-eval59.7%
fma-def59.7%
metadata-eval59.7%
distribute-rgt-in59.7%
neg-mul-159.7%
sub-neg59.7%
Applied egg-rr59.7%
Taylor expanded in x around 0 99.7%
*-un-lft-identity99.7%
*-commutative99.7%
associate-/r*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -0.65) (not (<= x 1.0))) (+ (/ 1.0 (+ 1.0 x)) (/ -1.0 x)) (- (* x -2.0) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -0.65) || !(x <= 1.0)) {
tmp = (1.0 / (1.0 + x)) + (-1.0 / 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.65d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (1.0d0 / (1.0d0 + x)) + ((-1.0d0) / 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.65) || !(x <= 1.0)) {
tmp = (1.0 / (1.0 + x)) + (-1.0 / x);
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.65) or not (x <= 1.0): tmp = (1.0 / (1.0 + x)) + (-1.0 / x) else: tmp = (x * -2.0) - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -0.65) || !(x <= 1.0)) tmp = Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-1.0 / 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.65) || ~((x <= 1.0))) tmp = (1.0 / (1.0 + x)) + (-1.0 / x); else tmp = (x * -2.0) - (2.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.65], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $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.65 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{1}{1 + x} + \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\end{array}
\end{array}
if x < -0.650000000000000022 or 1 < x Initial program 72.9%
associate-+l-72.9%
sub-neg72.9%
neg-mul-172.9%
metadata-eval72.9%
cancel-sign-sub-inv72.9%
+-commutative72.9%
*-lft-identity72.9%
sub-neg72.9%
metadata-eval72.9%
Simplified72.9%
Taylor expanded in x around inf 71.8%
if -0.650000000000000022 < 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.1%
associate-*r/99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification85.0%
(FPCore (x) :precision binary64 (if (or (<= x -0.85) (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.85) || !(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.85d0)) .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.85) || !(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.85) 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.85) || !(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.85) || ~((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.85], 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.85 \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.849999999999999978 or 1 < x Initial program 72.9%
associate-+l-72.9%
sub-neg72.9%
neg-mul-172.9%
metadata-eval72.9%
cancel-sign-sub-inv72.9%
+-commutative72.9%
*-lft-identity72.9%
sub-neg72.9%
metadata-eval72.9%
Simplified72.9%
frac-sub16.8%
frac-sub21.8%
*-un-lft-identity21.8%
distribute-rgt-in21.8%
neg-mul-121.8%
sub-neg21.8%
*-rgt-identity21.8%
distribute-rgt-in21.8%
metadata-eval21.8%
metadata-eval21.8%
fma-def21.8%
metadata-eval21.8%
distribute-rgt-in21.8%
neg-mul-121.8%
sub-neg21.8%
Applied egg-rr21.8%
Taylor expanded in x around 0 99.5%
Taylor expanded in x around inf 97.9%
unpow297.9%
Simplified97.9%
if -0.849999999999999978 < 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.1%
associate-*r/99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification98.5%
(FPCore (x) :precision binary64 (if (or (<= x -0.85) (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.85) || !(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.85d0)) .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.85) || !(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.85) 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.85) || !(x <= 1.0)) tmp = Float64(Float64(2.0 / 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.85) || ~((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.85], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(x * x), $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.85 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{\frac{2}{1 + x}}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\end{array}
\end{array}
if x < -0.849999999999999978 or 1 < x Initial program 72.9%
associate-+l-72.9%
sub-neg72.9%
neg-mul-172.9%
metadata-eval72.9%
cancel-sign-sub-inv72.9%
+-commutative72.9%
*-lft-identity72.9%
sub-neg72.9%
metadata-eval72.9%
Simplified72.9%
frac-sub16.8%
frac-sub21.8%
*-un-lft-identity21.8%
distribute-rgt-in21.8%
neg-mul-121.8%
sub-neg21.8%
*-rgt-identity21.8%
distribute-rgt-in21.8%
metadata-eval21.8%
metadata-eval21.8%
fma-def21.8%
metadata-eval21.8%
distribute-rgt-in21.8%
neg-mul-121.8%
sub-neg21.8%
Applied egg-rr21.8%
Taylor expanded in x around 0 99.5%
*-un-lft-identity99.5%
*-commutative99.5%
associate-/r*99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 98.2%
unpow297.9%
Simplified98.2%
if -0.849999999999999978 < 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.1%
associate-*r/99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x -0.85) (* (/ 2.0 x) (/ (/ 1.0 (+ 1.0 x)) x)) (if (<= x 1.0) (- (* x -2.0) (/ 2.0 x)) (/ 2.0 (* (+ 1.0 x) (* x x))))))
double code(double x) {
double tmp;
if (x <= -0.85) {
tmp = (2.0 / x) * ((1.0 / (1.0 + x)) / x);
} else if (x <= 1.0) {
tmp = (x * -2.0) - (2.0 / x);
} else {
tmp = 2.0 / ((1.0 + x) * (x * x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.85d0)) then
tmp = (2.0d0 / x) * ((1.0d0 / (1.0d0 + x)) / x)
else if (x <= 1.0d0) then
tmp = (x * (-2.0d0)) - (2.0d0 / x)
else
tmp = 2.0d0 / ((1.0d0 + x) * (x * x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -0.85) {
tmp = (2.0 / x) * ((1.0 / (1.0 + x)) / x);
} else if (x <= 1.0) {
tmp = (x * -2.0) - (2.0 / x);
} else {
tmp = 2.0 / ((1.0 + x) * (x * x));
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.85: tmp = (2.0 / x) * ((1.0 / (1.0 + x)) / x) elif x <= 1.0: tmp = (x * -2.0) - (2.0 / x) else: tmp = 2.0 / ((1.0 + x) * (x * x)) return tmp
function code(x) tmp = 0.0 if (x <= -0.85) tmp = Float64(Float64(2.0 / x) * Float64(Float64(1.0 / Float64(1.0 + x)) / x)); elseif (x <= 1.0) tmp = Float64(Float64(x * -2.0) - Float64(2.0 / x)); else tmp = Float64(2.0 / Float64(Float64(1.0 + x) * Float64(x * x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.85) tmp = (2.0 / x) * ((1.0 / (1.0 + x)) / x); elseif (x <= 1.0) tmp = (x * -2.0) - (2.0 / x); else tmp = 2.0 / ((1.0 + x) * (x * x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.85], N[(N[(2.0 / x), $MachinePrecision] * N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.85:\\
\;\;\;\;\frac{2}{x} \cdot \frac{\frac{1}{1 + x}}{x}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\left(1 + x\right) \cdot \left(x \cdot x\right)}\\
\end{array}
\end{array}
if x < -0.849999999999999978Initial program 69.9%
associate-+l-69.9%
sub-neg69.9%
neg-mul-169.9%
metadata-eval69.9%
cancel-sign-sub-inv69.9%
+-commutative69.9%
*-lft-identity69.9%
sub-neg69.9%
metadata-eval69.9%
Simplified69.9%
frac-sub15.6%
frac-sub21.6%
*-un-lft-identity21.6%
distribute-rgt-in21.7%
neg-mul-121.7%
sub-neg21.7%
*-rgt-identity21.7%
distribute-rgt-in21.7%
metadata-eval21.7%
metadata-eval21.7%
fma-def21.7%
metadata-eval21.7%
distribute-rgt-in21.7%
neg-mul-121.7%
sub-neg21.7%
Applied egg-rr21.7%
Taylor expanded in x around 0 99.3%
Taylor expanded in x around inf 98.7%
unpow298.7%
Simplified98.7%
associate-/r*99.2%
div-inv99.2%
times-frac99.2%
Applied egg-rr99.2%
if -0.849999999999999978 < 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.1%
associate-*r/99.1%
metadata-eval99.1%
Simplified99.1%
if 1 < x Initial program 75.8%
associate-+l-75.8%
sub-neg75.8%
neg-mul-175.8%
metadata-eval75.8%
cancel-sign-sub-inv75.8%
+-commutative75.8%
*-lft-identity75.8%
sub-neg75.8%
metadata-eval75.8%
Simplified75.8%
frac-sub17.9%
frac-sub21.9%
*-un-lft-identity21.9%
distribute-rgt-in21.9%
neg-mul-121.9%
sub-neg21.9%
*-rgt-identity21.9%
distribute-rgt-in21.9%
metadata-eval21.9%
metadata-eval21.9%
fma-def21.9%
metadata-eval21.9%
distribute-rgt-in21.9%
neg-mul-121.9%
sub-neg21.9%
Applied egg-rr21.9%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 97.3%
unpow297.3%
Simplified97.3%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= x -1.0) (/ -1.0 (* x x)) (if (<= x 1.0) (- (* x -2.0) (/ 2.0 x)) (/ 2.0 (* x x)))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = -1.0 / (x * x);
} else if (x <= 1.0) {
tmp = (x * -2.0) - (2.0 / x);
} else {
tmp = 2.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 * x)
else if (x <= 1.0d0) then
tmp = (x * (-2.0d0)) - (2.0d0 / x)
else
tmp = 2.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 * x);
} else if (x <= 1.0) {
tmp = (x * -2.0) - (2.0 / x);
} else {
tmp = 2.0 / (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = -1.0 / (x * x) elif x <= 1.0: tmp = (x * -2.0) - (2.0 / x) else: tmp = 2.0 / (x * x) return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = Float64(-1.0 / Float64(x * x)); elseif (x <= 1.0) tmp = Float64(Float64(x * -2.0) - Float64(2.0 / x)); else tmp = Float64(2.0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = -1.0 / (x * x); elseif (x <= 1.0) tmp = (x * -2.0) - (2.0 / x); else tmp = 2.0 / (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot x}\\
\end{array}
\end{array}
if x < -1Initial program 69.9%
associate-+l-69.9%
sub-neg69.9%
neg-mul-169.9%
metadata-eval69.9%
cancel-sign-sub-inv69.9%
+-commutative69.9%
*-lft-identity69.9%
sub-neg69.9%
metadata-eval69.9%
Simplified69.9%
Taylor expanded in x around inf 70.1%
Taylor expanded in x around inf 52.4%
unpow252.4%
Simplified52.4%
if -1 < 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.1%
associate-*r/99.1%
metadata-eval99.1%
Simplified99.1%
if 1 < x Initial program 75.8%
associate-+l-75.8%
sub-neg75.8%
neg-mul-175.8%
metadata-eval75.8%
cancel-sign-sub-inv75.8%
+-commutative75.8%
*-lft-identity75.8%
sub-neg75.8%
metadata-eval75.8%
Simplified75.8%
frac-sub17.9%
frac-sub21.9%
*-un-lft-identity21.9%
distribute-rgt-in21.9%
neg-mul-121.9%
sub-neg21.9%
*-rgt-identity21.9%
distribute-rgt-in21.9%
metadata-eval21.9%
metadata-eval21.9%
fma-def21.9%
metadata-eval21.9%
distribute-rgt-in21.9%
neg-mul-121.9%
sub-neg21.9%
Applied egg-rr21.9%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 97.3%
unpow297.3%
Simplified97.3%
Taylor expanded in x around 0 58.1%
unpow258.1%
Simplified58.1%
Final simplification76.5%
(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 86.0%
associate-+l-86.0%
sub-neg86.0%
neg-mul-186.0%
metadata-eval86.0%
cancel-sign-sub-inv86.0%
+-commutative86.0%
*-lft-identity86.0%
sub-neg86.0%
metadata-eval86.0%
Simplified86.0%
frac-sub57.1%
frac-sub59.6%
*-un-lft-identity59.6%
distribute-rgt-in59.7%
neg-mul-159.7%
sub-neg59.7%
*-rgt-identity59.7%
distribute-rgt-in59.7%
metadata-eval59.7%
metadata-eval59.7%
fma-def59.7%
metadata-eval59.7%
distribute-rgt-in59.7%
neg-mul-159.7%
sub-neg59.7%
Applied egg-rr59.7%
Taylor expanded in x around 0 99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (/ (/ 2.0 (- (* x x) x)) (+ 1.0 x)))
double code(double x) {
return (2.0 / ((x * x) - x)) / (1.0 + x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / ((x * x) - x)) / (1.0d0 + x)
end function
public static double code(double x) {
return (2.0 / ((x * x) - x)) / (1.0 + x);
}
def code(x): return (2.0 / ((x * x) - x)) / (1.0 + x)
function code(x) return Float64(Float64(2.0 / Float64(Float64(x * x) - x)) / Float64(1.0 + x)) end
function tmp = code(x) tmp = (2.0 / ((x * x) - x)) / (1.0 + x); end
code[x_] := N[(N[(2.0 / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x \cdot x - x}}{1 + x}
\end{array}
Initial program 86.0%
associate-+l-86.0%
sub-neg86.0%
neg-mul-186.0%
metadata-eval86.0%
cancel-sign-sub-inv86.0%
+-commutative86.0%
*-lft-identity86.0%
sub-neg86.0%
metadata-eval86.0%
Simplified86.0%
frac-sub57.1%
frac-sub59.6%
*-un-lft-identity59.6%
distribute-rgt-in59.7%
neg-mul-159.7%
sub-neg59.7%
*-rgt-identity59.7%
distribute-rgt-in59.7%
metadata-eval59.7%
metadata-eval59.7%
fma-def59.7%
metadata-eval59.7%
distribute-rgt-in59.7%
neg-mul-159.7%
sub-neg59.7%
Applied egg-rr59.7%
Taylor expanded in x around 0 99.7%
expm1-log1p-u72.6%
expm1-udef58.8%
associate-/r*58.8%
Applied egg-rr58.8%
expm1-def72.7%
expm1-log1p99.9%
associate-/l/99.7%
associate-/r*99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.38))) (/ -1.0 (* x x)) (/ -2.0 x)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.38)) {
tmp = -1.0 / (x * x);
} else {
tmp = -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.38d0))) then
tmp = (-1.0d0) / (x * x)
else
tmp = (-2.0d0) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.38)) {
tmp = -1.0 / (x * x);
} else {
tmp = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 0.38): tmp = -1.0 / (x * x) else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.38)) tmp = Float64(-1.0 / Float64(x * x)); else tmp = Float64(-2.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.38))) tmp = -1.0 / (x * x); else tmp = -2.0 / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.38]], $MachinePrecision]], N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.38\right):\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < -1 or 0.38 < x Initial program 73.1%
associate-+l-73.1%
sub-neg73.1%
neg-mul-173.1%
metadata-eval73.1%
cancel-sign-sub-inv73.1%
+-commutative73.1%
*-lft-identity73.1%
sub-neg73.1%
metadata-eval73.1%
Simplified73.1%
Taylor expanded in x around inf 71.4%
Taylor expanded in x around inf 54.4%
unpow254.4%
Simplified54.4%
if -1 < x < 0.38Initial 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.5%
Final simplification76.1%
(FPCore (x) :precision binary64 (if (<= x -1.0) (/ -1.0 (* x x)) (if (<= x 1.0) (/ -2.0 x) (/ 2.0 (* x x)))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = -1.0 / (x * x);
} else if (x <= 1.0) {
tmp = -2.0 / x;
} else {
tmp = 2.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 * x)
else if (x <= 1.0d0) then
tmp = (-2.0d0) / x
else
tmp = 2.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 * x);
} else if (x <= 1.0) {
tmp = -2.0 / x;
} else {
tmp = 2.0 / (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = -1.0 / (x * x) elif x <= 1.0: tmp = -2.0 / x else: tmp = 2.0 / (x * x) return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = Float64(-1.0 / Float64(x * x)); elseif (x <= 1.0) tmp = Float64(-2.0 / x); else tmp = Float64(2.0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = -1.0 / (x * x); elseif (x <= 1.0) tmp = -2.0 / x; else tmp = 2.0 / (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(-2.0 / x), $MachinePrecision], N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot x}\\
\end{array}
\end{array}
if x < -1Initial program 69.9%
associate-+l-69.9%
sub-neg69.9%
neg-mul-169.9%
metadata-eval69.9%
cancel-sign-sub-inv69.9%
+-commutative69.9%
*-lft-identity69.9%
sub-neg69.9%
metadata-eval69.9%
Simplified69.9%
Taylor expanded in x around inf 70.1%
Taylor expanded in x around inf 52.4%
unpow252.4%
Simplified52.4%
if -1 < 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 98.9%
if 1 < x Initial program 75.8%
associate-+l-75.8%
sub-neg75.8%
neg-mul-175.8%
metadata-eval75.8%
cancel-sign-sub-inv75.8%
+-commutative75.8%
*-lft-identity75.8%
sub-neg75.8%
metadata-eval75.8%
Simplified75.8%
frac-sub17.9%
frac-sub21.9%
*-un-lft-identity21.9%
distribute-rgt-in21.9%
neg-mul-121.9%
sub-neg21.9%
*-rgt-identity21.9%
distribute-rgt-in21.9%
metadata-eval21.9%
metadata-eval21.9%
fma-def21.9%
metadata-eval21.9%
distribute-rgt-in21.9%
neg-mul-121.9%
sub-neg21.9%
Applied egg-rr21.9%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around inf 97.3%
unpow297.3%
Simplified97.3%
Taylor expanded in x around 0 58.1%
unpow258.1%
Simplified58.1%
Final simplification76.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 86.0%
associate-+l-86.0%
sub-neg86.0%
neg-mul-186.0%
metadata-eval86.0%
cancel-sign-sub-inv86.0%
+-commutative86.0%
*-lft-identity86.0%
sub-neg86.0%
metadata-eval86.0%
Simplified86.0%
Taylor expanded in x around 0 50.5%
Final simplification50.5%
(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 2023178
(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))))