
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / x)
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / x);
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / x)
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / x)) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / x); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / x)
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / x);
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / x)
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / x)) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / x); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (/ 1.0 (+ 1.0 x)) (/ -1.0 x))))
(if (<= t_0 -4e-24)
(/ (/ (+ x (- -1.0 x)) (+ 1.0 x)) x)
(if (<= t_0 0.0) (- (pow x -2.0)) t_0))))
double code(double x) {
double t_0 = (1.0 / (1.0 + x)) + (-1.0 / x);
double tmp;
if (t_0 <= -4e-24) {
tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x;
} else if (t_0 <= 0.0) {
tmp = -pow(x, -2.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / (1.0d0 + x)) + ((-1.0d0) / x)
if (t_0 <= (-4d-24)) then
tmp = ((x + ((-1.0d0) - x)) / (1.0d0 + x)) / x
else if (t_0 <= 0.0d0) then
tmp = -(x ** (-2.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (1.0 / (1.0 + x)) + (-1.0 / x);
double tmp;
if (t_0 <= -4e-24) {
tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x;
} else if (t_0 <= 0.0) {
tmp = -Math.pow(x, -2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (1.0 / (1.0 + x)) + (-1.0 / x) tmp = 0 if t_0 <= -4e-24: tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x elif t_0 <= 0.0: tmp = -math.pow(x, -2.0) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-1.0 / x)) tmp = 0.0 if (t_0 <= -4e-24) tmp = Float64(Float64(Float64(x + Float64(-1.0 - x)) / Float64(1.0 + x)) / x); elseif (t_0 <= 0.0) tmp = Float64(-(x ^ -2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (1.0 / (1.0 + x)) + (-1.0 / x); tmp = 0.0; if (t_0 <= -4e-24) tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x; elseif (t_0 <= 0.0) tmp = -(x ^ -2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e-24], N[(N[(N[(x + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[t$95$0, 0.0], (-N[Power[x, -2.0], $MachinePrecision]), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + x} + \frac{-1}{x}\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{-24}:\\
\;\;\;\;\frac{\frac{x + \left(-1 - x\right)}{1 + x}}{x}\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;-{x}^{-2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) < -3.99999999999999969e-24Initial program 98.3%
frac-sub100.0%
*-rgt-identity100.0%
metadata-eval100.0%
div-inv100.0%
associate-/r*100.0%
*-un-lft-identity100.0%
*-rgt-identity100.0%
+-commutative100.0%
div-inv100.0%
metadata-eval100.0%
*-rgt-identity100.0%
+-commutative100.0%
Applied egg-rr100.0%
if -3.99999999999999969e-24 < (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) < 0.0Initial program 55.4%
Taylor expanded in x around inf 99.4%
unpow299.4%
associate-/r*99.8%
*-lft-identity99.8%
associate-*l/99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
distribute-rgt-neg-out99.6%
unpow-199.6%
unpow-199.6%
pow-sqr100.0%
metadata-eval100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) Initial program 100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (/ 1.0 (+ 1.0 x)) (/ -1.0 x))))
(if (<= t_0 -4e-24)
(/ (/ (+ x (- -1.0 x)) (+ 1.0 x)) x)
(if (<= t_0 0.0) (/ (/ -1.0 x) x) t_0))))
double code(double x) {
double t_0 = (1.0 / (1.0 + x)) + (-1.0 / x);
double tmp;
if (t_0 <= -4e-24) {
tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x;
} else if (t_0 <= 0.0) {
tmp = (-1.0 / x) / x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / (1.0d0 + x)) + ((-1.0d0) / x)
if (t_0 <= (-4d-24)) then
tmp = ((x + ((-1.0d0) - x)) / (1.0d0 + x)) / x
else if (t_0 <= 0.0d0) then
tmp = ((-1.0d0) / x) / x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (1.0 / (1.0 + x)) + (-1.0 / x);
double tmp;
if (t_0 <= -4e-24) {
tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x;
} else if (t_0 <= 0.0) {
tmp = (-1.0 / x) / x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (1.0 / (1.0 + x)) + (-1.0 / x) tmp = 0 if t_0 <= -4e-24: tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x elif t_0 <= 0.0: tmp = (-1.0 / x) / x else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-1.0 / x)) tmp = 0.0 if (t_0 <= -4e-24) tmp = Float64(Float64(Float64(x + Float64(-1.0 - x)) / Float64(1.0 + x)) / x); elseif (t_0 <= 0.0) tmp = Float64(Float64(-1.0 / x) / x); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (1.0 / (1.0 + x)) + (-1.0 / x); tmp = 0.0; if (t_0 <= -4e-24) tmp = ((x + (-1.0 - x)) / (1.0 + x)) / x; elseif (t_0 <= 0.0) tmp = (-1.0 / x) / x; else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e-24], N[(N[(N[(x + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + x} + \frac{-1}{x}\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{-24}:\\
\;\;\;\;\frac{\frac{x + \left(-1 - x\right)}{1 + x}}{x}\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) < -3.99999999999999969e-24Initial program 98.3%
frac-sub100.0%
*-rgt-identity100.0%
metadata-eval100.0%
div-inv100.0%
associate-/r*100.0%
*-un-lft-identity100.0%
*-rgt-identity100.0%
+-commutative100.0%
div-inv100.0%
metadata-eval100.0%
*-rgt-identity100.0%
+-commutative100.0%
Applied egg-rr100.0%
if -3.99999999999999969e-24 < (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) < 0.0Initial program 55.4%
frac-sub55.4%
*-rgt-identity55.4%
metadata-eval55.4%
div-inv55.4%
associate-/r*55.4%
*-un-lft-identity55.4%
*-rgt-identity55.4%
+-commutative55.4%
div-inv55.4%
metadata-eval55.4%
*-rgt-identity55.4%
+-commutative55.4%
Applied egg-rr55.4%
Taylor expanded in x around inf 99.8%
if 0.0 < (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) Initial program 100.0%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (/ 1.0 (+ 1.0 x)) (/ -1.0 x))))
(if (<= t_0 -2e-7)
(/ (+ (/ x (+ 1.0 x)) -1.0) x)
(if (<= t_0 0.0) (/ (/ (+ (/ 1.0 x) -1.0) x) x) t_0))))
double code(double x) {
double t_0 = (1.0 / (1.0 + x)) + (-1.0 / x);
double tmp;
if (t_0 <= -2e-7) {
tmp = ((x / (1.0 + x)) + -1.0) / x;
} else if (t_0 <= 0.0) {
tmp = (((1.0 / x) + -1.0) / x) / x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / (1.0d0 + x)) + ((-1.0d0) / x)
if (t_0 <= (-2d-7)) then
tmp = ((x / (1.0d0 + x)) + (-1.0d0)) / x
else if (t_0 <= 0.0d0) then
tmp = (((1.0d0 / x) + (-1.0d0)) / x) / x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (1.0 / (1.0 + x)) + (-1.0 / x);
double tmp;
if (t_0 <= -2e-7) {
tmp = ((x / (1.0 + x)) + -1.0) / x;
} else if (t_0 <= 0.0) {
tmp = (((1.0 / x) + -1.0) / x) / x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (1.0 / (1.0 + x)) + (-1.0 / x) tmp = 0 if t_0 <= -2e-7: tmp = ((x / (1.0 + x)) + -1.0) / x elif t_0 <= 0.0: tmp = (((1.0 / x) + -1.0) / x) / x else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-1.0 / x)) tmp = 0.0 if (t_0 <= -2e-7) tmp = Float64(Float64(Float64(x / Float64(1.0 + x)) + -1.0) / x); elseif (t_0 <= 0.0) tmp = Float64(Float64(Float64(Float64(1.0 / x) + -1.0) / x) / x); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (1.0 / (1.0 + x)) + (-1.0 / x); tmp = 0.0; if (t_0 <= -2e-7) tmp = ((x / (1.0 + x)) + -1.0) / x; elseif (t_0 <= 0.0) tmp = (((1.0 / x) + -1.0) / x) / x; else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-7], N[(N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[(N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + x} + \frac{-1}{x}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-7}:\\
\;\;\;\;\frac{\frac{x}{1 + x} + -1}{x}\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\frac{\frac{1}{x} + -1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) < -1.9999999999999999e-7Initial program 99.5%
frac-sub100.0%
*-rgt-identity100.0%
metadata-eval100.0%
div-inv100.0%
associate-/r*100.0%
*-un-lft-identity100.0%
*-rgt-identity100.0%
+-commutative100.0%
div-inv100.0%
metadata-eval100.0%
*-rgt-identity100.0%
+-commutative100.0%
Applied egg-rr100.0%
div-sub99.7%
+-commutative99.7%
*-inverses99.7%
Applied egg-rr99.7%
if -1.9999999999999999e-7 < (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) < 0.0Initial program 55.4%
frac-sub56.2%
*-rgt-identity56.2%
metadata-eval56.2%
div-inv56.2%
associate-/r*56.2%
*-un-lft-identity56.2%
*-rgt-identity56.2%
+-commutative56.2%
div-inv56.2%
metadata-eval56.2%
*-rgt-identity56.2%
+-commutative56.2%
Applied egg-rr56.2%
Taylor expanded in x around inf 99.7%
if 0.0 < (-.f64 (/.f64 #s(literal 1 binary64) (+.f64 x #s(literal 1 binary64))) (/.f64 #s(literal 1 binary64) x)) Initial program 100.0%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (or (<= x -122000000.0) (not (<= x 240000000.0))) (/ (/ -1.0 x) x) (/ (+ (/ x (+ 1.0 x)) -1.0) x)))
double code(double x) {
double tmp;
if ((x <= -122000000.0) || !(x <= 240000000.0)) {
tmp = (-1.0 / x) / x;
} else {
tmp = ((x / (1.0 + x)) + -1.0) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-122000000.0d0)) .or. (.not. (x <= 240000000.0d0))) then
tmp = ((-1.0d0) / x) / x
else
tmp = ((x / (1.0d0 + x)) + (-1.0d0)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -122000000.0) || !(x <= 240000000.0)) {
tmp = (-1.0 / x) / x;
} else {
tmp = ((x / (1.0 + x)) + -1.0) / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -122000000.0) or not (x <= 240000000.0): tmp = (-1.0 / x) / x else: tmp = ((x / (1.0 + x)) + -1.0) / x return tmp
function code(x) tmp = 0.0 if ((x <= -122000000.0) || !(x <= 240000000.0)) tmp = Float64(Float64(-1.0 / x) / x); else tmp = Float64(Float64(Float64(x / Float64(1.0 + x)) + -1.0) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -122000000.0) || ~((x <= 240000000.0))) tmp = (-1.0 / x) / x; else tmp = ((x / (1.0 + x)) + -1.0) / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -122000000.0], N[Not[LessEqual[x, 240000000.0]], $MachinePrecision]], N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -122000000 \lor \neg \left(x \leq 240000000\right):\\
\;\;\;\;\frac{\frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{1 + x} + -1}{x}\\
\end{array}
\end{array}
if x < -1.22e8 or 2.4e8 < x Initial program 55.3%
frac-sub55.8%
*-rgt-identity55.8%
metadata-eval55.8%
div-inv55.8%
associate-/r*55.8%
*-un-lft-identity55.8%
*-rgt-identity55.8%
+-commutative55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
+-commutative55.8%
Applied egg-rr55.8%
Taylor expanded in x around inf 99.6%
if -1.22e8 < x < 2.4e8Initial program 99.5%
frac-sub100.0%
*-rgt-identity100.0%
metadata-eval100.0%
div-inv100.0%
associate-/r*100.0%
*-un-lft-identity100.0%
*-rgt-identity100.0%
+-commutative100.0%
div-inv100.0%
metadata-eval100.0%
*-rgt-identity100.0%
+-commutative100.0%
Applied egg-rr100.0%
div-sub99.6%
+-commutative99.6%
*-inverses99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (or (<= x -200000000.0) (not (<= x 155000000.0))) (/ (/ -1.0 x) x) (+ (/ 1.0 (+ 1.0 x)) (/ -1.0 x))))
double code(double x) {
double tmp;
if ((x <= -200000000.0) || !(x <= 155000000.0)) {
tmp = (-1.0 / x) / x;
} else {
tmp = (1.0 / (1.0 + x)) + (-1.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-200000000.0d0)) .or. (.not. (x <= 155000000.0d0))) then
tmp = ((-1.0d0) / x) / x
else
tmp = (1.0d0 / (1.0d0 + x)) + ((-1.0d0) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -200000000.0) || !(x <= 155000000.0)) {
tmp = (-1.0 / x) / x;
} else {
tmp = (1.0 / (1.0 + x)) + (-1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -200000000.0) or not (x <= 155000000.0): tmp = (-1.0 / x) / x else: tmp = (1.0 / (1.0 + x)) + (-1.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -200000000.0) || !(x <= 155000000.0)) tmp = Float64(Float64(-1.0 / x) / x); else tmp = Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-1.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -200000000.0) || ~((x <= 155000000.0))) tmp = (-1.0 / x) / x; else tmp = (1.0 / (1.0 + x)) + (-1.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -200000000.0], N[Not[LessEqual[x, 155000000.0]], $MachinePrecision]], N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision], N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -200000000 \lor \neg \left(x \leq 155000000\right):\\
\;\;\;\;\frac{\frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + x} + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -2e8 or 1.55e8 < x Initial program 55.3%
frac-sub55.8%
*-rgt-identity55.8%
metadata-eval55.8%
div-inv55.8%
associate-/r*55.8%
*-un-lft-identity55.8%
*-rgt-identity55.8%
+-commutative55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
+-commutative55.8%
Applied egg-rr55.8%
Taylor expanded in x around inf 99.6%
if -2e8 < x < 1.55e8Initial program 99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ (/ -1.0 x) x) (+ (- 1.0 x) (/ -1.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (-1.0 / x) / x;
} else {
tmp = (1.0 - x) + (-1.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 = (1.0d0 - x) + ((-1.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 = (1.0 - x) + (-1.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 = (1.0 - x) + (-1.0 / x) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(-1.0 / x) / x); else tmp = Float64(Float64(1.0 - x) + Float64(-1.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 = (1.0 - x) + (-1.0 / x); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{\frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 56.2%
frac-sub57.3%
*-rgt-identity57.3%
metadata-eval57.3%
div-inv57.3%
associate-/r*57.3%
*-un-lft-identity57.3%
*-rgt-identity57.3%
+-commutative57.3%
div-inv57.3%
metadata-eval57.3%
*-rgt-identity57.3%
+-commutative57.3%
Applied egg-rr57.3%
Taylor expanded in x around inf 97.5%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.75))) (/ (/ -1.0 x) x) (/ (+ x -1.0) x)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.75)) {
tmp = (-1.0 / x) / x;
} else {
tmp = (x + -1.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.75d0))) then
tmp = ((-1.0d0) / x) / x
else
tmp = (x + (-1.0d0)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.75)) {
tmp = (-1.0 / x) / x;
} else {
tmp = (x + -1.0) / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 0.75): tmp = (-1.0 / x) / x else: tmp = (x + -1.0) / x return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.75)) tmp = Float64(Float64(-1.0 / x) / x); else tmp = Float64(Float64(x + -1.0) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.75))) tmp = (-1.0 / x) / x; else tmp = (x + -1.0) / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.75]], $MachinePrecision]], N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision], N[(N[(x + -1.0), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.75\right):\\
\;\;\;\;\frac{\frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + -1}{x}\\
\end{array}
\end{array}
if x < -1 or 0.75 < x Initial program 56.2%
frac-sub57.3%
*-rgt-identity57.3%
metadata-eval57.3%
div-inv57.3%
associate-/r*57.3%
*-un-lft-identity57.3%
*-rgt-identity57.3%
+-commutative57.3%
div-inv57.3%
metadata-eval57.3%
*-rgt-identity57.3%
+-commutative57.3%
Applied egg-rr57.3%
Taylor expanded in x around inf 97.5%
if -1 < x < 0.75Initial program 100.0%
Taylor expanded in x around 0 99.8%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x -1.0) 0.0 (if (<= x 4.5e+102) (/ -1.0 x) 0.0)))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = 0.0;
} else if (x <= 4.5e+102) {
tmp = -1.0 / x;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = 0.0d0
else if (x <= 4.5d+102) then
tmp = (-1.0d0) / x
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = 0.0;
} else if (x <= 4.5e+102) {
tmp = -1.0 / x;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = 0.0 elif x <= 4.5e+102: tmp = -1.0 / x else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = 0.0; elseif (x <= 4.5e+102) tmp = Float64(-1.0 / x); else tmp = 0.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -1.0) tmp = 0.0; elseif (x <= 4.5e+102) tmp = -1.0 / x; else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], 0.0, If[LessEqual[x, 4.5e+102], N[(-1.0 / x), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -1 or 4.50000000000000021e102 < x Initial program 61.1%
Taylor expanded in x around inf 59.2%
Taylor expanded in x around 0 59.2%
if -1 < x < 4.50000000000000021e102Initial program 92.7%
Taylor expanded in x around 0 91.6%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 79.5%
Taylor expanded in x around inf 26.1%
Taylor expanded in x around 0 26.1%
(FPCore (x) :precision binary64 (/ (/ -1.0 x) (+ x 1.0)))
double code(double x) {
return (-1.0 / x) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) / (x + 1.0d0)
end function
public static double code(double x) {
return (-1.0 / x) / (x + 1.0);
}
def code(x): return (-1.0 / x) / (x + 1.0)
function code(x) return Float64(Float64(-1.0 / x) / Float64(x + 1.0)) end
function tmp = code(x) tmp = (-1.0 / x) / (x + 1.0); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{x}}{x + 1}
\end{array}
(FPCore (x) :precision binary64 (/ 1.0 (* x (- -1.0 x))))
double code(double x) {
return 1.0 / (x * (-1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * ((-1.0d0) - x))
end function
public static double code(double x) {
return 1.0 / (x * (-1.0 - x));
}
def code(x): return 1.0 / (x * (-1.0 - x))
function code(x) return Float64(1.0 / Float64(x * Float64(-1.0 - x))) end
function tmp = code(x) tmp = 1.0 / (x * (-1.0 - x)); end
code[x_] := N[(1.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(-1 - x\right)}
\end{array}
herbie shell --seed 2024185
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
:alt
(! :herbie-platform default (/ (/ -1 x) (+ x 1)))
:alt
(! :herbie-platform default (/ 1 (* x (- -1 x))))
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))