
(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 8 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 83.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
frac-sub55.8%
frac-sub56.7%
*-un-lft-identity56.7%
distribute-rgt-in56.7%
neg-mul-156.7%
sub-neg56.7%
*-rgt-identity56.7%
distribute-rgt-in56.7%
metadata-eval56.7%
metadata-eval56.7%
fma-def56.7%
metadata-eval56.7%
distribute-rgt-in56.7%
neg-mul-156.7%
sub-neg56.7%
Applied egg-rr56.7%
+-commutative56.7%
remove-double-neg56.7%
metadata-eval56.7%
distribute-neg-in56.7%
neg-mul-156.7%
*-commutative56.7%
fma-udef56.7%
distribute-lft-neg-in56.7%
distribute-lft-neg-in56.7%
fma-udef56.7%
*-commutative56.7%
neg-mul-156.7%
distribute-neg-in56.7%
remove-double-neg56.7%
metadata-eval56.7%
+-commutative56.7%
Simplified56.7%
Taylor expanded in x around 0 99.8%
frac-2neg99.8%
div-inv99.8%
metadata-eval99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
+-commutative99.8%
distribute-neg-in99.8%
neg-mul-199.8%
metadata-eval99.8%
fma-def99.8%
Applied egg-rr99.8%
associate-*r/99.8%
metadata-eval99.8%
*-commutative99.8%
associate-/r*99.9%
fma-udef99.9%
neg-mul-199.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -0.86) (not (<= x 1.0))) (/ 2.0 (* (* x x) (+ x 1.0))) (- (* -2.0 x) (/ 2.0 x))))
double code(double x) {
double tmp;
if ((x <= -0.86) || !(x <= 1.0)) {
tmp = 2.0 / ((x * x) * (x + 1.0));
} else {
tmp = (-2.0 * x) - (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 / ((x * x) * (x + 1.0d0))
else
tmp = ((-2.0d0) * x) - (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 / ((x * x) * (x + 1.0));
} else {
tmp = (-2.0 * x) - (2.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -0.86) or not (x <= 1.0): tmp = 2.0 / ((x * x) * (x + 1.0)) else: tmp = (-2.0 * x) - (2.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -0.86) || !(x <= 1.0)) tmp = Float64(2.0 / Float64(Float64(x * x) * Float64(x + 1.0))); else tmp = Float64(Float64(-2.0 * x) - 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 / ((x * x) * (x + 1.0)); else tmp = (-2.0 * x) - (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[(x * x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * x), $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(x \cdot x\right) \cdot \left(x + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot x - \frac{2}{x}\\
\end{array}
\end{array}
if x < -0.859999999999999987 or 1 < x Initial program 68.2%
associate-+l-68.2%
sub-neg68.2%
neg-mul-168.2%
metadata-eval68.2%
cancel-sign-sub-inv68.2%
+-commutative68.2%
*-lft-identity68.2%
sub-neg68.2%
metadata-eval68.2%
Simplified68.2%
frac-sub15.5%
frac-sub17.3%
*-un-lft-identity17.3%
distribute-rgt-in17.3%
neg-mul-117.3%
sub-neg17.3%
*-rgt-identity17.3%
distribute-rgt-in17.3%
metadata-eval17.3%
metadata-eval17.3%
fma-def17.3%
metadata-eval17.3%
distribute-rgt-in17.3%
neg-mul-117.3%
sub-neg17.3%
Applied egg-rr17.3%
+-commutative17.3%
remove-double-neg17.3%
metadata-eval17.3%
distribute-neg-in17.3%
neg-mul-117.3%
*-commutative17.3%
fma-udef17.3%
distribute-lft-neg-in17.3%
distribute-lft-neg-in17.3%
fma-udef17.3%
*-commutative17.3%
neg-mul-117.3%
distribute-neg-in17.3%
remove-double-neg17.3%
metadata-eval17.3%
+-commutative17.3%
Simplified17.3%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around inf 98.3%
unpow298.3%
Simplified98.3%
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 100.0%
associate-*r/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (or (<= x -0.86) (not (<= x 1.0))) (/ (/ -2.0 (- -1.0 x)) (* x x)) (- (* -2.0 x) (/ 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 = (-2.0 * x) - (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 = ((-2.0d0) * x) - (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 = (-2.0 * x) - (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 = (-2.0 * x) - (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(x * x)); else tmp = Float64(Float64(-2.0 * x) - 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 = (-2.0 * x) - (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[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * x), $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{\frac{-2}{-1 - x}}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot x - \frac{2}{x}\\
\end{array}
\end{array}
if x < -0.859999999999999987 or 1 < x Initial program 68.2%
associate-+l-68.2%
sub-neg68.2%
neg-mul-168.2%
metadata-eval68.2%
cancel-sign-sub-inv68.2%
+-commutative68.2%
*-lft-identity68.2%
sub-neg68.2%
metadata-eval68.2%
Simplified68.2%
frac-sub15.5%
frac-sub17.3%
*-un-lft-identity17.3%
distribute-rgt-in17.3%
neg-mul-117.3%
sub-neg17.3%
*-rgt-identity17.3%
distribute-rgt-in17.3%
metadata-eval17.3%
metadata-eval17.3%
fma-def17.3%
metadata-eval17.3%
distribute-rgt-in17.3%
neg-mul-117.3%
sub-neg17.3%
Applied egg-rr17.3%
+-commutative17.3%
remove-double-neg17.3%
metadata-eval17.3%
distribute-neg-in17.3%
neg-mul-117.3%
*-commutative17.3%
fma-udef17.3%
distribute-lft-neg-in17.3%
distribute-lft-neg-in17.3%
fma-udef17.3%
*-commutative17.3%
neg-mul-117.3%
distribute-neg-in17.3%
remove-double-neg17.3%
metadata-eval17.3%
+-commutative17.3%
Simplified17.3%
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%
+-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%
*-commutative99.6%
associate-/r*99.8%
fma-udef99.8%
neg-mul-199.8%
+-commutative99.8%
sub-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 98.5%
unpow298.3%
Simplified98.5%
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 100.0%
associate-*r/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification99.2%
(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 83.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
frac-sub55.8%
frac-sub56.7%
*-un-lft-identity56.7%
distribute-rgt-in56.7%
neg-mul-156.7%
sub-neg56.7%
*-rgt-identity56.7%
distribute-rgt-in56.7%
metadata-eval56.7%
metadata-eval56.7%
fma-def56.7%
metadata-eval56.7%
distribute-rgt-in56.7%
neg-mul-156.7%
sub-neg56.7%
Applied egg-rr56.7%
+-commutative56.7%
remove-double-neg56.7%
metadata-eval56.7%
distribute-neg-in56.7%
neg-mul-156.7%
*-commutative56.7%
fma-udef56.7%
distribute-lft-neg-in56.7%
distribute-lft-neg-in56.7%
fma-udef56.7%
*-commutative56.7%
neg-mul-156.7%
distribute-neg-in56.7%
remove-double-neg56.7%
metadata-eval56.7%
+-commutative56.7%
Simplified56.7%
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 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -1.0 (* x x)) (/ -2.0 x)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
tmp = -1.0 / (x * x);
} else {
tmp = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -1.0 / (x * x) else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;\frac{-1}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 68.2%
associate-+l-68.2%
sub-neg68.2%
neg-mul-168.2%
metadata-eval68.2%
cancel-sign-sub-inv68.2%
+-commutative68.2%
*-lft-identity68.2%
sub-neg68.2%
metadata-eval68.2%
Simplified68.2%
Taylor expanded in x around inf 67.7%
Taylor expanded in x around inf 54.2%
unpow254.2%
Simplified54.2%
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.9%
Final simplification76.0%
(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 64.7%
associate-+l-64.7%
sub-neg64.7%
neg-mul-164.7%
metadata-eval64.7%
cancel-sign-sub-inv64.7%
+-commutative64.7%
*-lft-identity64.7%
sub-neg64.7%
metadata-eval64.7%
Simplified64.7%
Taylor expanded in x around inf 63.8%
Taylor expanded in x around inf 52.7%
unpow252.7%
Simplified52.7%
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.9%
if 1 < x Initial program 73.0%
associate-+l-73.0%
sub-neg73.0%
neg-mul-173.0%
metadata-eval73.0%
cancel-sign-sub-inv73.0%
+-commutative73.0%
*-lft-identity73.0%
sub-neg73.0%
metadata-eval73.0%
Simplified73.0%
Taylor expanded in x around inf 73.2%
unpow273.2%
Simplified73.2%
Taylor expanded in x around 0 57.5%
unpow257.5%
Simplified57.5%
Final simplification76.3%
(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 83.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
Taylor expanded in x around 0 49.3%
Taylor expanded in x around 0 82.9%
Final simplification82.9%
(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.3%
associate-+l-83.3%
sub-neg83.3%
neg-mul-183.3%
metadata-eval83.3%
cancel-sign-sub-inv83.3%
+-commutative83.3%
*-lft-identity83.3%
sub-neg83.3%
metadata-eval83.3%
Simplified83.3%
Taylor expanded in x around 0 50.2%
Final simplification50.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 2023222
(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))))