
(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
(let* ((t_0 (/ 1.0 (+ 1.0 x))) (t_1 (+ (- t_0 (/ 2.0 x)) (/ 1.0 (+ x -1.0)))))
(if (<= t_1 -20.0)
t_1
(if (<= t_1 1e-31)
(/ 2.0 (pow x 3.0))
(+ t_0 (/ (- 2.0 x) (- (* x x) x)))))))
double code(double x) {
double t_0 = 1.0 / (1.0 + x);
double t_1 = (t_0 - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_1 <= -20.0) {
tmp = t_1;
} else if (t_1 <= 1e-31) {
tmp = 2.0 / pow(x, 3.0);
} else {
tmp = t_0 + ((2.0 - x) / ((x * x) - x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 / (1.0d0 + x)
t_1 = (t_0 - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
if (t_1 <= (-20.0d0)) then
tmp = t_1
else if (t_1 <= 1d-31) then
tmp = 2.0d0 / (x ** 3.0d0)
else
tmp = t_0 + ((2.0d0 - x) / ((x * x) - x))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 / (1.0 + x);
double t_1 = (t_0 - (2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_1 <= -20.0) {
tmp = t_1;
} else if (t_1 <= 1e-31) {
tmp = 2.0 / Math.pow(x, 3.0);
} else {
tmp = t_0 + ((2.0 - x) / ((x * x) - x));
}
return tmp;
}
def code(x): t_0 = 1.0 / (1.0 + x) t_1 = (t_0 - (2.0 / x)) + (1.0 / (x + -1.0)) tmp = 0 if t_1 <= -20.0: tmp = t_1 elif t_1 <= 1e-31: tmp = 2.0 / math.pow(x, 3.0) else: tmp = t_0 + ((2.0 - x) / ((x * x) - x)) return tmp
function code(x) t_0 = Float64(1.0 / Float64(1.0 + x)) t_1 = Float64(Float64(t_0 - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) tmp = 0.0 if (t_1 <= -20.0) tmp = t_1; elseif (t_1 <= 1e-31) tmp = Float64(2.0 / (x ^ 3.0)); else tmp = Float64(t_0 + Float64(Float64(2.0 - x) / Float64(Float64(x * x) - x))); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 / (1.0 + x); t_1 = (t_0 - (2.0 / x)) + (1.0 / (x + -1.0)); tmp = 0.0; if (t_1 <= -20.0) tmp = t_1; elseif (t_1 <= 1e-31) tmp = 2.0 / (x ^ 3.0); else tmp = t_0 + ((2.0 - x) / ((x * x) - x)); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -20.0], t$95$1, If[LessEqual[t$95$1, 1e-31], N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(N[(2.0 - x), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + x}\\
t_1 := \left(t_0 - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_1 \leq -20:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 10^{-31}:\\
\;\;\;\;\frac{2}{{x}^{3}}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \frac{2 - x}{x \cdot x - x}\\
\end{array}
\end{array}
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -20Initial program 100.0%
if -20 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 1e-31Initial program 71.3%
associate-+l-71.3%
sub-neg71.3%
neg-mul-171.3%
metadata-eval71.3%
cancel-sign-sub-inv71.3%
+-commutative71.3%
*-lft-identity71.3%
sub-neg71.3%
metadata-eval71.3%
Simplified71.3%
Taylor expanded in x around inf 97.9%
if 1e-31 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 99.9%
associate-+l-99.9%
sub-neg99.9%
neg-mul-199.9%
metadata-eval99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-lft-identity99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
frac-2neg99.9%
frac-2neg99.9%
metadata-eval99.9%
frac-sub99.9%
metadata-eval99.9%
+-commutative99.9%
distribute-neg-in99.9%
metadata-eval99.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
metadata-eval99.9%
sub-neg99.9%
Applied egg-rr99.9%
cancel-sign-sub99.9%
*-commutative99.9%
neg-mul-199.9%
unsub-neg99.9%
sub-neg99.9%
+-commutative99.9%
distribute-lft-in99.9%
sqr-neg99.9%
unpow299.9%
*-rgt-identity99.9%
sub-neg99.9%
unpow299.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.0%
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0))))
double code(double x) {
return ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (1.0d0 + x)) - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
end function
public static double code(double x) {
return ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
}
def code(x): return ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0))
function code(x) return Float64(Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) end
function tmp = code(x) tmp = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0)); end
code[x_] := N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}
\end{array}
Initial program 86.1%
Final simplification86.1%
(FPCore (x) :precision binary64 (if (<= x -1.0) (/ -1.0 (* x x)) (if (<= x 1.0) (- (- x) (/ 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 / 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 / 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 / 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 / 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) - 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 / 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[((-x) - 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:\\
\;\;\;\;\left(-x\right) - \frac{2}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot x}\\
\end{array}
\end{array}
if x < -1Initial program 75.2%
associate-+l-75.2%
sub-neg75.2%
neg-mul-175.2%
metadata-eval75.2%
cancel-sign-sub-inv75.2%
+-commutative75.2%
*-lft-identity75.2%
sub-neg75.2%
metadata-eval75.2%
Simplified75.2%
Taylor expanded in x around inf 75.3%
flip-+24.1%
sub-neg24.1%
metadata-eval24.1%
distribute-neg-in24.1%
+-commutative24.1%
associate-/r/18.6%
metadata-eval18.6%
+-commutative18.6%
distribute-neg-in18.6%
metadata-eval18.6%
sub-neg18.6%
Applied egg-rr18.6%
associate-*l/19.1%
*-lft-identity19.1%
Simplified19.1%
Taylor expanded in x around inf 58.3%
unpow258.3%
Simplified58.3%
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.2%
Taylor expanded in x around 0 99.2%
neg-mul-199.2%
associate-*r/99.2%
metadata-eval99.2%
Simplified99.2%
if 1 < x Initial program 66.9%
associate-+l-66.9%
sub-neg66.9%
neg-mul-166.9%
metadata-eval66.9%
cancel-sign-sub-inv66.9%
+-commutative66.9%
*-lft-identity66.9%
sub-neg66.9%
metadata-eval66.9%
Simplified66.9%
flip-+18.4%
sub-neg18.4%
metadata-eval18.4%
distribute-neg-in18.4%
+-commutative18.4%
associate-/r/18.4%
metadata-eval18.4%
+-commutative18.4%
distribute-neg-in18.4%
metadata-eval18.4%
sub-neg18.4%
Applied egg-rr20.4%
Taylor expanded in x around inf 65.8%
Taylor expanded in x around inf 54.1%
unpow254.1%
Simplified54.1%
Final simplification78.3%
(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 71.5%
associate-+l-71.5%
sub-neg71.5%
neg-mul-171.5%
metadata-eval71.5%
cancel-sign-sub-inv71.5%
+-commutative71.5%
*-lft-identity71.5%
sub-neg71.5%
metadata-eval71.5%
Simplified71.5%
Taylor expanded in x around inf 70.8%
flip-+21.6%
sub-neg21.6%
metadata-eval21.6%
distribute-neg-in21.6%
+-commutative21.6%
associate-/r/18.5%
metadata-eval18.5%
+-commutative18.5%
distribute-neg-in18.5%
metadata-eval18.5%
sub-neg18.5%
Applied egg-rr18.5%
associate-*l/16.5%
*-lft-identity16.5%
Simplified16.5%
Taylor expanded in x around inf 55.6%
unpow255.6%
Simplified55.6%
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.2%
Final simplification77.9%
(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 75.2%
associate-+l-75.2%
sub-neg75.2%
neg-mul-175.2%
metadata-eval75.2%
cancel-sign-sub-inv75.2%
+-commutative75.2%
*-lft-identity75.2%
sub-neg75.2%
metadata-eval75.2%
Simplified75.2%
Taylor expanded in x around inf 75.3%
flip-+24.1%
sub-neg24.1%
metadata-eval24.1%
distribute-neg-in24.1%
+-commutative24.1%
associate-/r/18.6%
metadata-eval18.6%
+-commutative18.6%
distribute-neg-in18.6%
metadata-eval18.6%
sub-neg18.6%
Applied egg-rr18.6%
associate-*l/19.1%
*-lft-identity19.1%
Simplified19.1%
Taylor expanded in x around inf 58.3%
unpow258.3%
Simplified58.3%
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.2%
if 1 < x Initial program 66.9%
associate-+l-66.9%
sub-neg66.9%
neg-mul-166.9%
metadata-eval66.9%
cancel-sign-sub-inv66.9%
+-commutative66.9%
*-lft-identity66.9%
sub-neg66.9%
metadata-eval66.9%
Simplified66.9%
flip-+18.4%
sub-neg18.4%
metadata-eval18.4%
distribute-neg-in18.4%
+-commutative18.4%
associate-/r/18.4%
metadata-eval18.4%
+-commutative18.4%
distribute-neg-in18.4%
metadata-eval18.4%
sub-neg18.4%
Applied egg-rr20.4%
Taylor expanded in x around inf 65.8%
Taylor expanded in x around inf 54.1%
unpow254.1%
Simplified54.1%
Final simplification78.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 86.1%
associate-+l-86.1%
sub-neg86.1%
neg-mul-186.1%
metadata-eval86.1%
cancel-sign-sub-inv86.1%
+-commutative86.1%
*-lft-identity86.1%
sub-neg86.1%
metadata-eval86.1%
Simplified86.1%
Taylor expanded in x around 0 52.3%
Taylor expanded in x around 0 85.3%
Final simplification85.3%
(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.1%
associate-+l-86.1%
sub-neg86.1%
neg-mul-186.1%
metadata-eval86.1%
cancel-sign-sub-inv86.1%
+-commutative86.1%
*-lft-identity86.1%
sub-neg86.1%
metadata-eval86.1%
Simplified86.1%
Taylor expanded in x around 0 53.3%
Final simplification53.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 86.1%
associate-+l-86.1%
sub-neg86.1%
neg-mul-186.1%
metadata-eval86.1%
cancel-sign-sub-inv86.1%
+-commutative86.1%
*-lft-identity86.1%
sub-neg86.1%
metadata-eval86.1%
Simplified86.1%
Taylor expanded in x around 0 52.3%
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 2023200
(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))))