
(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)) (fma x x x)))
double code(double x) {
return (2.0 / (x + -1.0)) / fma(x, x, x);
}
function code(x) return Float64(Float64(2.0 / Float64(x + -1.0)) / fma(x, x, x)) end
code[x_] := N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x * x + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x + -1}}{\mathsf{fma}\left(x, x, x\right)}
\end{array}
Initial program 83.7%
+-commutative83.7%
sub-neg83.7%
metadata-eval83.7%
frac-sub55.3%
frac-add55.8%
*-un-lft-identity55.8%
*-commutative55.8%
+-commutative55.8%
/-rgt-identity55.8%
*-un-lft-identity55.8%
/-rgt-identity55.8%
+-commutative55.8%
*-commutative55.8%
+-commutative55.8%
Applied egg-rr55.8%
Taylor expanded in x around 0 99.7%
expm1-log1p-u71.5%
expm1-udef55.2%
+-commutative55.2%
distribute-lft-in55.2%
*-rgt-identity55.2%
fma-def55.2%
Applied egg-rr55.2%
expm1-def71.5%
expm1-log1p99.7%
associate-/r*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.85))) (/ 2.0 (* (+ x -1.0) (* x x))) (- (* x -2.0) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.85)) {
tmp = 2.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 <= (-1.0d0)) .or. (.not. (x <= 0.85d0))) then
tmp = 2.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 <= -1.0) || !(x <= 0.85)) {
tmp = 2.0 / ((x + -1.0) * (x * x));
} 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 + -1.0) * (x * x)) 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(Float64(x + -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 <= -1.0) || ~((x <= 0.85))) tmp = 2.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, -1.0], N[Not[LessEqual[x, 0.85]], $MachinePrecision]], N[(2.0 / N[(N[(x + -1.0), $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 -1 \lor \neg \left(x \leq 0.85\right):\\
\;\;\;\;\frac{2}{\left(x + -1\right) \cdot \left(x \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\end{array}
\end{array}
if x < -1 or 0.849999999999999978 < x Initial program 69.9%
+-commutative69.9%
sub-neg69.9%
metadata-eval69.9%
frac-sub17.7%
frac-add18.6%
*-un-lft-identity18.6%
*-commutative18.6%
+-commutative18.6%
/-rgt-identity18.6%
*-un-lft-identity18.6%
/-rgt-identity18.6%
+-commutative18.6%
*-commutative18.6%
+-commutative18.6%
Applied egg-rr18.6%
Taylor expanded in x around 0 99.5%
Taylor expanded in x around inf 96.6%
unpow296.6%
Simplified96.6%
if -1 < x < 0.849999999999999978Initial program 100.0%
Taylor expanded in x around 0 98.0%
associate-*r/98.0%
metadata-eval98.0%
Simplified98.0%
Final simplification97.2%
(FPCore (x)
:precision binary64
(if (<= x -1.0)
(- (/ 2.0 x) (/ 2.0 x))
(if (<= x 0.65)
(- (* x -2.0) (/ 2.0 x))
(+ (/ -1.0 x) (/ 1.0 (+ x -1.0))))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = (2.0 / x) - (2.0 / x);
} else if (x <= 0.65) {
tmp = (x * -2.0) - (2.0 / x);
} else {
tmp = (-1.0 / x) + (1.0 / (x + -1.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = (2.0d0 / x) - (2.0d0 / x)
else if (x <= 0.65d0) then
tmp = (x * (-2.0d0)) - (2.0d0 / x)
else
tmp = ((-1.0d0) / x) + (1.0d0 / (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = (2.0 / x) - (2.0 / x);
} else if (x <= 0.65) {
tmp = (x * -2.0) - (2.0 / x);
} else {
tmp = (-1.0 / x) + (1.0 / (x + -1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = (2.0 / x) - (2.0 / x) elif x <= 0.65: tmp = (x * -2.0) - (2.0 / x) else: tmp = (-1.0 / x) + (1.0 / (x + -1.0)) return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(2.0 / x) - Float64(2.0 / x)); elseif (x <= 0.65) tmp = Float64(Float64(x * -2.0) - Float64(2.0 / x)); else tmp = Float64(Float64(-1.0 / x) + Float64(1.0 / Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = (2.0 / x) - (2.0 / x); elseif (x <= 0.65) tmp = (x * -2.0) - (2.0 / x); else tmp = (-1.0 / x) + (1.0 / (x + -1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], N[(N[(2.0 / x), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.65], N[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / x), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{2}{x} - \frac{2}{x}\\
\mathbf{elif}\;x \leq 0.65:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x} + \frac{1}{x + -1}\\
\end{array}
\end{array}
if x < -1Initial program 69.6%
+-commutative69.6%
sub-neg69.6%
metadata-eval69.6%
associate-+r-69.7%
frac-2neg69.7%
metadata-eval69.7%
+-commutative69.7%
distribute-neg-in69.7%
metadata-eval69.7%
sub-neg69.7%
+-commutative69.7%
Applied egg-rr69.7%
Taylor expanded in x around inf 67.5%
if -1 < x < 0.650000000000000022Initial program 100.0%
Taylor expanded in x around 0 98.0%
associate-*r/98.0%
metadata-eval98.0%
Simplified98.0%
if 0.650000000000000022 < x Initial program 70.3%
Taylor expanded in x around inf 66.9%
Final simplification81.3%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (- (/ 2.0 x) (/ 2.0 x)) (- (* x -2.0) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (2.0 / x) - (2.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 <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (2.0d0 / x) - (2.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 <= -1.0) || !(x <= 1.0)) {
tmp = (2.0 / x) - (2.0 / x);
} else {
tmp = (x * -2.0) - (2.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = (2.0 / x) - (2.0 / x) else: tmp = (x * -2.0) - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(2.0 / x) - Float64(2.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 <= -1.0) || ~((x <= 1.0))) tmp = (2.0 / x) - (2.0 / x); 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, 1.0]], $MachinePrecision]], N[(N[(2.0 / x), $MachinePrecision] - N[(2.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 -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{2}{x} - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 69.9%
+-commutative69.9%
sub-neg69.9%
metadata-eval69.9%
associate-+r-69.9%
frac-2neg69.9%
metadata-eval69.9%
+-commutative69.9%
distribute-neg-in69.9%
metadata-eval69.9%
sub-neg69.9%
+-commutative69.9%
Applied egg-rr69.9%
Taylor expanded in x around inf 66.9%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.0%
associate-*r/98.0%
metadata-eval98.0%
Simplified98.0%
Final simplification81.1%
(FPCore (x) :precision binary64 (if (<= x -1.0) (/ -1.0 (* x x)) (if (<= x 1.0) (- (* x -2.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 = (x * -2.0) - (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 = (x * (-2.0d0)) - (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 = (x * -2.0) - (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 = (x * -2.0) - (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(Float64(x * -2.0) - 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 = (x * -2.0) - (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[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $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:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot x}\\
\end{array}
\end{array}
if x < -1Initial program 69.6%
+-commutative69.6%
sub-neg69.6%
metadata-eval69.6%
associate-+r-69.7%
frac-2neg69.7%
metadata-eval69.7%
+-commutative69.7%
distribute-neg-in69.7%
metadata-eval69.7%
sub-neg69.7%
+-commutative69.7%
Applied egg-rr69.7%
Taylor expanded in x around inf 67.9%
Taylor expanded in x around inf 56.3%
unpow256.3%
Simplified56.3%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.0%
associate-*r/98.0%
metadata-eval98.0%
Simplified98.0%
if 1 < x Initial program 70.3%
Taylor expanded in x around inf 66.9%
Taylor expanded in x around inf 56.3%
unpow256.3%
Simplified56.3%
Final simplification75.4%
(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 83.7%
associate-+l-83.7%
sub-neg83.7%
metadata-eval83.7%
frac-sub55.3%
frac-sub55.8%
*-un-lft-identity55.8%
distribute-rgt-in55.7%
neg-mul-155.7%
sub-neg55.7%
+-commutative55.7%
*-rgt-identity55.7%
+-commutative55.7%
distribute-lft-in55.7%
metadata-eval55.7%
+-commutative55.7%
distribute-rgt-in55.7%
Applied egg-rr55.7%
Taylor expanded in x around 0 99.7%
Final simplification99.7%
(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 70.2%
+-commutative70.2%
sub-neg70.2%
metadata-eval70.2%
associate-+r-70.1%
frac-2neg70.1%
metadata-eval70.1%
+-commutative70.1%
distribute-neg-in70.1%
metadata-eval70.1%
sub-neg70.1%
+-commutative70.1%
Applied egg-rr70.1%
Taylor expanded in x around inf 66.8%
Taylor expanded in x around inf 55.3%
unpow255.3%
Simplified55.3%
if -1 < x < 0.38Initial program 100.0%
Taylor expanded in x around 0 98.1%
Final simplification74.7%
(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 69.6%
+-commutative69.6%
sub-neg69.6%
metadata-eval69.6%
associate-+r-69.7%
frac-2neg69.7%
metadata-eval69.7%
+-commutative69.7%
distribute-neg-in69.7%
metadata-eval69.7%
sub-neg69.7%
+-commutative69.7%
Applied egg-rr69.7%
Taylor expanded in x around inf 67.9%
Taylor expanded in x around inf 56.3%
unpow256.3%
Simplified56.3%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 97.4%
if 1 < x Initial program 70.3%
Taylor expanded in x around inf 66.9%
Taylor expanded in x around inf 56.3%
unpow256.3%
Simplified56.3%
Final simplification75.1%
(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 83.7%
Taylor expanded in x around 0 47.3%
Final simplification47.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 83.7%
Taylor expanded in x around 0 46.4%
Taylor expanded in x around inf 10.4%
Taylor expanded in x around inf 3.4%
Final simplification3.4%
(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 2023213
(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))))