
(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 10 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 (+ x 1.0)) (* x (+ x -1.0))))
double code(double x) {
return (2.0 / (x + 1.0)) / (x * (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x + 1.0d0)) / (x * (x + (-1.0d0)))
end function
public static double code(double x) {
return (2.0 / (x + 1.0)) / (x * (x + -1.0));
}
def code(x): return (2.0 / (x + 1.0)) / (x * (x + -1.0))
function code(x) return Float64(Float64(2.0 / Float64(x + 1.0)) / Float64(x * Float64(x + -1.0))) end
function tmp = code(x) tmp = (2.0 / (x + 1.0)) / (x * (x + -1.0)); end
code[x_] := N[(N[(2.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x + 1}}{x \cdot \left(x + -1\right)}
\end{array}
Initial program 82.4%
associate-+l-82.4%
sub-neg82.4%
neg-mul-182.4%
metadata-eval82.4%
cancel-sign-sub-inv82.4%
+-commutative82.4%
*-lft-identity82.4%
sub-neg82.4%
metadata-eval82.4%
Simplified82.4%
frac-sub59.5%
frac-sub60.1%
*-un-lft-identity60.1%
distribute-rgt-in60.1%
neg-mul-160.1%
sub-neg60.1%
*-rgt-identity60.1%
distribute-rgt-in60.1%
metadata-eval60.1%
metadata-eval60.1%
fma-def60.1%
metadata-eval60.1%
distribute-rgt-in60.1%
neg-mul-160.1%
sub-neg60.1%
Applied egg-rr60.1%
+-commutative60.1%
remove-double-neg60.1%
metadata-eval60.1%
distribute-neg-in60.1%
neg-mul-160.1%
*-commutative60.1%
fma-udef60.1%
distribute-lft-neg-in60.1%
distribute-lft-neg-in60.1%
fma-udef60.1%
*-commutative60.1%
neg-mul-160.1%
distribute-neg-in60.1%
remove-double-neg60.1%
metadata-eval60.1%
+-commutative60.1%
Simplified60.1%
Taylor expanded in x around 0 99.6%
expm1-log1p-u70.5%
expm1-udef53.0%
associate-/r*53.0%
fma-neg53.0%
Applied egg-rr53.0%
expm1-def70.7%
expm1-log1p99.9%
fma-neg99.9%
Simplified99.9%
*-un-lft-identity99.9%
distribute-rgt-out--99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -0.5) (not (<= x 1.0))) (+ (/ 1.0 (+ x 1.0)) (/ -1.0 x)) (/ -2.0 x)))
double code(double x) {
double tmp;
if ((x <= -0.5) || !(x <= 1.0)) {
tmp = (1.0 / (x + 1.0)) + (-1.0 / x);
} else {
tmp = -2.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-0.5d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (1.0d0 / (x + 1.0d0)) + ((-1.0d0) / x)
else
tmp = (-2.0d0) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -0.5) || !(x <= 1.0)) {
tmp = (1.0 / (x + 1.0)) + (-1.0 / x);
} else {
tmp = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.5) or not (x <= 1.0): tmp = (1.0 / (x + 1.0)) + (-1.0 / x) else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if ((x <= -0.5) || !(x <= 1.0)) tmp = Float64(Float64(1.0 / Float64(x + 1.0)) + Float64(-1.0 / x)); else tmp = Float64(-2.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -0.5) || ~((x <= 1.0))) tmp = (1.0 / (x + 1.0)) + (-1.0 / x); else tmp = -2.0 / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.5], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision], N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.5 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{1}{x + 1} + \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < -0.5 or 1 < x Initial program 63.3%
associate-+l-63.3%
sub-neg63.3%
neg-mul-163.3%
metadata-eval63.3%
cancel-sign-sub-inv63.3%
+-commutative63.3%
*-lft-identity63.3%
sub-neg63.3%
metadata-eval63.3%
Simplified63.3%
frac-2neg63.3%
metadata-eval63.3%
frac-sub15.7%
+-commutative15.7%
distribute-neg-in15.7%
metadata-eval15.7%
sub-neg15.7%
*-commutative15.7%
neg-mul-115.7%
+-commutative15.7%
distribute-neg-in15.7%
metadata-eval15.7%
sub-neg15.7%
Applied egg-rr15.7%
Taylor expanded in x around inf 62.1%
if -0.5 < 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 100.0%
Final simplification81.8%
(FPCore (x) :precision binary64 (if (or (<= x -0.75) (not (<= x 1.0))) (/ 2.0 (* (+ x 1.0) (* x x))) (/ -2.0 x)))
double code(double x) {
double tmp;
if ((x <= -0.75) || !(x <= 1.0)) {
tmp = 2.0 / ((x + 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 <= (-0.75d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 2.0d0 / ((x + 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 <= -0.75) || !(x <= 1.0)) {
tmp = 2.0 / ((x + 1.0) * (x * x));
} else {
tmp = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.75) or not (x <= 1.0): tmp = 2.0 / ((x + 1.0) * (x * x)) else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if ((x <= -0.75) || !(x <= 1.0)) tmp = Float64(2.0 / Float64(Float64(x + 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 <= -0.75) || ~((x <= 1.0))) tmp = 2.0 / ((x + 1.0) * (x * x)); else tmp = -2.0 / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -0.75], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(2.0 / N[(N[(x + 1.0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.75 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < -0.75 or 1 < x Initial program 63.3%
associate-+l-63.3%
sub-neg63.3%
neg-mul-163.3%
metadata-eval63.3%
cancel-sign-sub-inv63.3%
+-commutative63.3%
*-lft-identity63.3%
sub-neg63.3%
metadata-eval63.3%
Simplified63.3%
frac-sub15.7%
frac-sub17.1%
*-un-lft-identity17.1%
distribute-rgt-in17.0%
neg-mul-117.0%
sub-neg17.0%
*-rgt-identity17.0%
distribute-rgt-in17.0%
metadata-eval17.0%
metadata-eval17.0%
fma-def17.0%
metadata-eval17.0%
distribute-rgt-in17.0%
neg-mul-117.0%
sub-neg17.0%
Applied egg-rr17.0%
+-commutative17.0%
remove-double-neg17.0%
metadata-eval17.0%
distribute-neg-in17.0%
neg-mul-117.0%
*-commutative17.0%
fma-udef17.0%
distribute-lft-neg-in17.0%
distribute-lft-neg-in17.0%
fma-udef17.0%
*-commutative17.0%
neg-mul-117.0%
distribute-neg-in17.0%
remove-double-neg17.0%
metadata-eval17.0%
+-commutative17.0%
Simplified17.0%
Taylor expanded in x around 0 99.3%
Taylor expanded in x around inf 97.6%
unpow297.6%
Simplified97.6%
if -0.75 < 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 100.0%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= x -0.75) (/ 2.0 (* (+ x 1.0) (* x x))) (if (<= x 0.76) (/ -2.0 x) (/ (/ 2.0 x) (- (* x x) x)))))
double code(double x) {
double tmp;
if (x <= -0.75) {
tmp = 2.0 / ((x + 1.0) * (x * x));
} else if (x <= 0.76) {
tmp = -2.0 / x;
} else {
tmp = (2.0 / x) / ((x * x) - x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.75d0)) then
tmp = 2.0d0 / ((x + 1.0d0) * (x * x))
else if (x <= 0.76d0) then
tmp = (-2.0d0) / x
else
tmp = (2.0d0 / x) / ((x * x) - x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -0.75) {
tmp = 2.0 / ((x + 1.0) * (x * x));
} else if (x <= 0.76) {
tmp = -2.0 / x;
} else {
tmp = (2.0 / x) / ((x * x) - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.75: tmp = 2.0 / ((x + 1.0) * (x * x)) elif x <= 0.76: tmp = -2.0 / x else: tmp = (2.0 / x) / ((x * x) - x) return tmp
function code(x) tmp = 0.0 if (x <= -0.75) tmp = Float64(2.0 / Float64(Float64(x + 1.0) * Float64(x * x))); elseif (x <= 0.76) tmp = Float64(-2.0 / x); else tmp = Float64(Float64(2.0 / x) / Float64(Float64(x * x) - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.75) tmp = 2.0 / ((x + 1.0) * (x * x)); elseif (x <= 0.76) tmp = -2.0 / x; else tmp = (2.0 / x) / ((x * x) - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.75], N[(2.0 / N[(N[(x + 1.0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.76], N[(-2.0 / x), $MachinePrecision], N[(N[(2.0 / x), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.75:\\
\;\;\;\;\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x\right)}\\
\mathbf{elif}\;x \leq 0.76:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{x \cdot x - x}\\
\end{array}
\end{array}
if x < -0.75Initial program 67.2%
associate-+l-67.2%
sub-neg67.2%
neg-mul-167.2%
metadata-eval67.2%
cancel-sign-sub-inv67.2%
+-commutative67.2%
*-lft-identity67.2%
sub-neg67.2%
metadata-eval67.2%
Simplified67.2%
frac-sub15.8%
frac-sub16.4%
*-un-lft-identity16.4%
distribute-rgt-in16.2%
neg-mul-116.2%
sub-neg16.2%
*-rgt-identity16.2%
distribute-rgt-in16.2%
metadata-eval16.2%
metadata-eval16.2%
fma-def16.2%
metadata-eval16.2%
distribute-rgt-in16.2%
neg-mul-116.2%
sub-neg16.2%
Applied egg-rr16.2%
+-commutative16.2%
remove-double-neg16.2%
metadata-eval16.2%
distribute-neg-in16.2%
neg-mul-116.2%
*-commutative16.2%
fma-udef16.2%
distribute-lft-neg-in16.2%
distribute-lft-neg-in16.2%
fma-udef16.2%
*-commutative16.2%
neg-mul-116.2%
distribute-neg-in16.2%
remove-double-neg16.2%
metadata-eval16.2%
+-commutative16.2%
Simplified16.2%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 97.6%
unpow297.6%
Simplified97.6%
if -0.75 < x < 0.76000000000000001Initial 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 100.0%
if 0.76000000000000001 < x Initial program 59.3%
associate-+l-59.3%
sub-neg59.3%
neg-mul-159.3%
metadata-eval59.3%
cancel-sign-sub-inv59.3%
+-commutative59.3%
*-lft-identity59.3%
sub-neg59.3%
metadata-eval59.3%
Simplified59.3%
frac-sub15.7%
frac-sub17.8%
*-un-lft-identity17.8%
distribute-rgt-in17.8%
neg-mul-117.8%
sub-neg17.8%
*-rgt-identity17.8%
distribute-rgt-in17.8%
metadata-eval17.8%
metadata-eval17.8%
fma-def17.8%
metadata-eval17.8%
distribute-rgt-in17.8%
neg-mul-117.8%
sub-neg17.8%
Applied egg-rr17.8%
+-commutative17.8%
remove-double-neg17.8%
metadata-eval17.8%
distribute-neg-in17.8%
neg-mul-117.8%
*-commutative17.8%
fma-udef17.8%
distribute-lft-neg-in17.8%
distribute-lft-neg-in17.8%
fma-udef17.8%
*-commutative17.8%
neg-mul-117.8%
distribute-neg-in17.8%
remove-double-neg17.8%
metadata-eval17.8%
+-commutative17.8%
Simplified17.8%
Taylor expanded in x around 0 98.7%
expm1-log1p-u98.7%
expm1-udef58.8%
associate-/r*58.8%
fma-neg58.8%
Applied egg-rr58.8%
expm1-def99.8%
expm1-log1p99.8%
fma-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 98.7%
Final simplification99.1%
(FPCore (x) :precision binary64 (/ -2.0 (* (+ x -1.0) (* x (- -1.0 x)))))
double code(double x) {
return -2.0 / ((x + -1.0) * (x * (-1.0 - x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((x + (-1.0d0)) * (x * ((-1.0d0) - x)))
end function
public static double code(double x) {
return -2.0 / ((x + -1.0) * (x * (-1.0 - x)));
}
def code(x): return -2.0 / ((x + -1.0) * (x * (-1.0 - x)))
function code(x) return Float64(-2.0 / Float64(Float64(x + -1.0) * Float64(x * Float64(-1.0 - x)))) end
function tmp = code(x) tmp = -2.0 / ((x + -1.0) * (x * (-1.0 - x))); end
code[x_] := N[(-2.0 / N[(N[(x + -1.0), $MachinePrecision] * N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(x + -1\right) \cdot \left(x \cdot \left(-1 - x\right)\right)}
\end{array}
Initial program 82.4%
associate-+l-82.4%
sub-neg82.4%
neg-mul-182.4%
metadata-eval82.4%
cancel-sign-sub-inv82.4%
+-commutative82.4%
*-lft-identity82.4%
sub-neg82.4%
metadata-eval82.4%
Simplified82.4%
frac-sub59.5%
frac-sub60.1%
*-un-lft-identity60.1%
distribute-rgt-in60.1%
neg-mul-160.1%
sub-neg60.1%
*-rgt-identity60.1%
distribute-rgt-in60.1%
metadata-eval60.1%
metadata-eval60.1%
fma-def60.1%
metadata-eval60.1%
distribute-rgt-in60.1%
neg-mul-160.1%
sub-neg60.1%
Applied egg-rr60.1%
+-commutative60.1%
remove-double-neg60.1%
metadata-eval60.1%
distribute-neg-in60.1%
neg-mul-160.1%
*-commutative60.1%
fma-udef60.1%
distribute-lft-neg-in60.1%
distribute-lft-neg-in60.1%
fma-udef60.1%
*-commutative60.1%
neg-mul-160.1%
distribute-neg-in60.1%
remove-double-neg60.1%
metadata-eval60.1%
+-commutative60.1%
Simplified60.1%
Taylor expanded in x around 0 99.6%
frac-2neg99.6%
div-inv99.6%
metadata-eval99.6%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-neg99.6%
+-commutative99.6%
distribute-neg-in99.6%
neg-mul-199.6%
metadata-eval99.6%
fma-def99.6%
Applied egg-rr99.6%
associate-*r/99.6%
metadata-eval99.6%
fma-def99.6%
neg-mul-199.6%
distribute-rgt-in99.6%
*-commutative99.6%
associate-*l*99.6%
fma-udef99.6%
neg-mul-199.6%
+-commutative99.6%
sub-neg99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 2.0 (* (+ x 1.0) (- (* x x) x))))
double code(double x) {
return 2.0 / ((x + 1.0) * ((x * x) - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((x + 1.0d0) * ((x * x) - x))
end function
public static double code(double x) {
return 2.0 / ((x + 1.0) * ((x * x) - x));
}
def code(x): return 2.0 / ((x + 1.0) * ((x * x) - x))
function code(x) return Float64(2.0 / Float64(Float64(x + 1.0) * Float64(Float64(x * x) - x))) end
function tmp = code(x) tmp = 2.0 / ((x + 1.0) * ((x * x) - x)); end
code[x_] := N[(2.0 / N[(N[(x + 1.0), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}
\end{array}
Initial program 82.4%
associate-+l-82.4%
sub-neg82.4%
neg-mul-182.4%
metadata-eval82.4%
cancel-sign-sub-inv82.4%
+-commutative82.4%
*-lft-identity82.4%
sub-neg82.4%
metadata-eval82.4%
Simplified82.4%
frac-sub59.5%
frac-sub60.1%
*-un-lft-identity60.1%
distribute-rgt-in60.1%
neg-mul-160.1%
sub-neg60.1%
*-rgt-identity60.1%
distribute-rgt-in60.1%
metadata-eval60.1%
metadata-eval60.1%
fma-def60.1%
metadata-eval60.1%
distribute-rgt-in60.1%
neg-mul-160.1%
sub-neg60.1%
Applied egg-rr60.1%
+-commutative60.1%
remove-double-neg60.1%
metadata-eval60.1%
distribute-neg-in60.1%
neg-mul-160.1%
*-commutative60.1%
fma-udef60.1%
distribute-lft-neg-in60.1%
distribute-lft-neg-in60.1%
fma-udef60.1%
*-commutative60.1%
neg-mul-160.1%
distribute-neg-in60.1%
remove-double-neg60.1%
metadata-eval60.1%
+-commutative60.1%
Simplified60.1%
Taylor expanded in x around 0 99.6%
Final simplification99.6%
(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 63.3%
associate-+l-63.3%
sub-neg63.3%
neg-mul-163.3%
metadata-eval63.3%
cancel-sign-sub-inv63.3%
+-commutative63.3%
*-lft-identity63.3%
sub-neg63.3%
metadata-eval63.3%
Simplified63.3%
Taylor expanded in x around inf 62.1%
Taylor expanded in x around inf 50.4%
unpow250.4%
Simplified50.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 100.0%
Final simplification76.2%
(FPCore (x) :precision binary64 (if (<= x -1.0) (/ -1.0 (* x x)) (if (<= x 1.0) (/ -2.0 x) (/ 1.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 = 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 * x)
else if (x <= 1.0d0) then
tmp = (-2.0d0) / x
else
tmp = 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 * x);
} else if (x <= 1.0) {
tmp = -2.0 / x;
} else {
tmp = 1.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 = 1.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(1.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 = 1.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[(1.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{1}{x \cdot x}\\
\end{array}
\end{array}
if x < -1Initial program 67.2%
associate-+l-67.2%
sub-neg67.2%
neg-mul-167.2%
metadata-eval67.2%
cancel-sign-sub-inv67.2%
+-commutative67.2%
*-lft-identity67.2%
sub-neg67.2%
metadata-eval67.2%
Simplified67.2%
Taylor expanded in x around inf 65.3%
Taylor expanded in x around inf 55.5%
unpow255.5%
Simplified55.5%
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 100.0%
if 1 < x Initial program 59.3%
associate-+l-59.3%
sub-neg59.3%
neg-mul-159.3%
metadata-eval59.3%
cancel-sign-sub-inv59.3%
+-commutative59.3%
*-lft-identity59.3%
sub-neg59.3%
metadata-eval59.3%
Simplified59.3%
Taylor expanded in x around inf 58.8%
Taylor expanded in x around inf 45.3%
unpow245.3%
Simplified45.3%
associate-/r*41.7%
div-inv41.7%
Applied egg-rr41.7%
add-sqr-sqrt41.7%
sqrt-unprod41.7%
frac-times45.3%
metadata-eval45.3%
metadata-eval45.3%
frac-times41.7%
sqrt-unprod0.0%
add-sqr-sqrt43.5%
frac-times47.1%
metadata-eval47.1%
Applied egg-rr47.1%
Final simplification76.6%
(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.4%
associate-+l-82.4%
sub-neg82.4%
neg-mul-182.4%
metadata-eval82.4%
cancel-sign-sub-inv82.4%
+-commutative82.4%
*-lft-identity82.4%
sub-neg82.4%
metadata-eval82.4%
Simplified82.4%
Taylor expanded in x around 0 54.3%
Final simplification54.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 82.4%
associate-+l-82.4%
sub-neg82.4%
neg-mul-182.4%
metadata-eval82.4%
cancel-sign-sub-inv82.4%
+-commutative82.4%
*-lft-identity82.4%
sub-neg82.4%
metadata-eval82.4%
Simplified82.4%
Taylor expanded in x around inf 39.6%
Taylor expanded in x around 0 11.3%
Taylor expanded in x around inf 3.2%
Final simplification3.2%
(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 2023252
(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))))