
(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 6 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 (/ (/ -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}
Initial program 77.7%
frac-sub78.4%
*-commutative78.4%
associate-/r*78.4%
*-un-lft-identity78.4%
*-rgt-identity78.4%
sub-neg78.4%
neg-sub078.4%
+-commutative78.4%
associate--r+78.4%
metadata-eval78.4%
+-commutative78.4%
Applied egg-rr78.4%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x -1.0) 0.0 (if (<= x 3.9e+61) (+ (- 1.0 x) (/ -1.0 x)) 0.0)))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = 0.0;
} else if (x <= 3.9e+61) {
tmp = (1.0 - x) + (-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 <= 3.9d+61) then
tmp = (1.0d0 - x) + ((-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 <= 3.9e+61) {
tmp = (1.0 - x) + (-1.0 / x);
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = 0.0 elif x <= 3.9e+61: tmp = (1.0 - x) + (-1.0 / x) else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = 0.0; elseif (x <= 3.9e+61) tmp = Float64(Float64(1.0 - x) + 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 <= 3.9e+61) tmp = (1.0 - x) + (-1.0 / x); else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], 0.0, If[LessEqual[x, 3.9e+61], N[(N[(1.0 - x), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{+61}:\\
\;\;\;\;\left(1 - x\right) + \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -1 or 3.89999999999999987e61 < x Initial program 55.8%
frac-sub56.4%
div-inv56.4%
metadata-eval56.4%
frac-times56.4%
*-commutative56.4%
un-div-inv56.4%
associate-/l/56.4%
+-commutative56.4%
*-un-lft-identity56.4%
*-rgt-identity56.4%
sub-neg56.4%
neg-sub056.4%
+-commutative56.4%
associate--r+56.4%
metadata-eval56.4%
Applied egg-rr56.4%
associate-*l/56.4%
*-lft-identity56.4%
associate-+r-56.4%
+-commutative56.4%
associate--l+97.5%
+-commutative97.5%
Simplified97.5%
Applied egg-rr52.0%
if -1 < x < 3.89999999999999987e61Initial program 93.9%
Taylor expanded in x around 0 91.2%
mul-1-neg91.2%
sub-neg91.2%
Simplified91.2%
Final simplification74.5%
(FPCore (x) :precision binary64 (if (<= x -1.0) 0.0 (if (<= x 1.0) (+ 1.0 (/ -1.0 x)) 0.0)))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = 0.0;
} else if (x <= 1.0) {
tmp = 1.0 + (-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 <= 1.0d0) then
tmp = 1.0d0 + ((-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 <= 1.0) {
tmp = 1.0 + (-1.0 / x);
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = 0.0 elif x <= 1.0: tmp = 1.0 + (-1.0 / x) else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = 0.0; elseif (x <= 1.0) tmp = Float64(1.0 + 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 <= 1.0) tmp = 1.0 + (-1.0 / x); else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], 0.0, If[LessEqual[x, 1.0], N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 + \frac{-1}{x}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 52.8%
frac-sub54.3%
div-inv54.3%
metadata-eval54.3%
frac-times54.3%
*-commutative54.3%
un-div-inv54.3%
associate-/l/54.3%
+-commutative54.3%
*-un-lft-identity54.3%
*-rgt-identity54.3%
sub-neg54.3%
neg-sub054.3%
+-commutative54.3%
associate--r+54.3%
metadata-eval54.3%
Applied egg-rr54.3%
associate-*l/54.3%
*-lft-identity54.3%
associate-+r-54.3%
+-commutative54.3%
associate--l+97.7%
+-commutative97.7%
Simplified97.7%
Applied egg-rr47.2%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.4%
Final simplification74.2%
(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 59.8%
frac-sub60.5%
div-inv60.5%
metadata-eval60.5%
frac-times60.4%
*-commutative60.4%
un-div-inv60.4%
associate-/l/60.5%
+-commutative60.5%
*-un-lft-identity60.5%
*-rgt-identity60.5%
sub-neg60.5%
neg-sub060.5%
+-commutative60.5%
associate--r+60.5%
metadata-eval60.5%
Applied egg-rr60.5%
associate-*l/60.5%
*-lft-identity60.5%
associate-+r-60.5%
+-commutative60.5%
associate--l+97.4%
+-commutative97.4%
Simplified97.4%
Applied egg-rr55.7%
if -1 < x < 4.50000000000000021e102Initial program 89.3%
Taylor expanded in x around 0 85.7%
Final simplification73.8%
(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}
Initial program 77.7%
frac-sub78.4%
*-commutative78.4%
associate-/r*78.4%
*-un-lft-identity78.4%
*-rgt-identity78.4%
sub-neg78.4%
neg-sub078.4%
+-commutative78.4%
associate--r+78.4%
metadata-eval78.4%
+-commutative78.4%
Applied egg-rr78.4%
Taylor expanded in x around 0 99.9%
frac-2neg99.9%
distribute-frac-neg99.9%
neg-sub099.9%
associate--r+99.9%
metadata-eval99.9%
Applied egg-rr99.9%
neg-mul-199.9%
associate-/l/98.9%
associate-*r/98.9%
metadata-eval98.9%
*-commutative98.9%
Simplified98.9%
Final simplification98.9%
(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 77.7%
frac-sub78.4%
div-inv78.4%
metadata-eval78.4%
frac-times78.4%
*-commutative78.4%
un-div-inv78.4%
associate-/l/78.4%
+-commutative78.4%
*-un-lft-identity78.4%
*-rgt-identity78.4%
sub-neg78.4%
neg-sub078.4%
+-commutative78.4%
associate--r+78.4%
metadata-eval78.4%
Applied egg-rr78.4%
associate-*l/78.4%
*-lft-identity78.4%
associate-+r-78.4%
+-commutative78.4%
associate--l+98.9%
+-commutative98.9%
Simplified98.9%
Applied egg-rr23.5%
Final simplification23.5%
herbie shell --seed 2023336
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))