
(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 76.6%
frac-2neg76.6%
frac-2neg76.6%
frac-sub77.0%
distribute-rgt-neg-in77.0%
distribute-lft-neg-in77.0%
metadata-eval77.0%
metadata-eval77.0%
*-un-lft-identity77.0%
cancel-sign-sub77.0%
distribute-rgt-neg-in77.0%
*-rgt-identity77.0%
neg-sub077.0%
+-commutative77.0%
associate--r+77.0%
metadata-eval77.0%
*-commutative77.0%
neg-sub077.0%
+-commutative77.0%
associate--r+77.0%
metadata-eval77.0%
Applied egg-rr77.0%
associate-+r-77.0%
+-commutative77.0%
associate--l+99.4%
distribute-lft-neg-out99.4%
distribute-rgt-neg-in99.4%
Simplified99.4%
associate-/r*99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
distribute-neg-frac99.9%
clear-num99.3%
associate-/r/99.8%
neg-sub099.8%
+-inverses99.8%
metadata-eval99.8%
+-inverses99.8%
associate--r-99.8%
+-inverses99.8%
+-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
+-commutative99.8%
distribute-neg-frac99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r/99.9%
*-commutative99.9%
Applied egg-rr47.7%
div-inv47.7%
add-sqr-sqrt21.7%
sqrt-unprod48.6%
frac-times48.4%
metadata-eval48.4%
metadata-eval48.4%
frac-times48.6%
sqrt-unprod38.6%
add-sqr-sqrt74.6%
div-inv74.6%
mul-1-neg74.6%
distribute-rgt-neg-in74.6%
add-sqr-sqrt35.6%
associate-*r*35.6%
distribute-rgt-neg-in35.6%
Applied egg-rr46.6%
associate-*l/46.6%
associate-*l/46.6%
*-lft-identity46.6%
distribute-rgt-neg-out46.6%
pow-sqr99.9%
metadata-eval99.9%
unpow-199.9%
distribute-neg-frac99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(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 51.4%
frac-2neg51.4%
frac-2neg51.4%
frac-sub52.1%
distribute-rgt-neg-in52.1%
distribute-lft-neg-in52.1%
metadata-eval52.1%
metadata-eval52.1%
*-un-lft-identity52.1%
cancel-sign-sub52.1%
distribute-rgt-neg-in52.1%
*-rgt-identity52.1%
neg-sub052.1%
+-commutative52.1%
associate--r+52.1%
metadata-eval52.1%
*-commutative52.1%
neg-sub052.1%
+-commutative52.1%
associate--r+52.1%
metadata-eval52.1%
Applied egg-rr52.1%
associate-+r-52.1%
+-commutative52.1%
associate--l+98.8%
distribute-lft-neg-out98.8%
distribute-rgt-neg-in98.8%
Simplified98.8%
associate-/r*99.8%
+-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
distribute-neg-frac99.8%
clear-num98.6%
associate-/r/99.6%
neg-sub099.6%
+-inverses99.6%
metadata-eval99.6%
+-inverses99.6%
associate--r-99.6%
+-inverses99.6%
+-inverses99.6%
metadata-eval99.6%
metadata-eval99.6%
+-commutative99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-*r/99.8%
*-commutative99.8%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.7%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.6%
mul-1-neg99.6%
sub-neg99.6%
Simplified99.6%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.75))) (/ (/ -1.0 x) x) (+ 1.0 (/ -1.0 x))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.75)) {
tmp = (-1.0 / x) / x;
} else {
tmp = 1.0 + (-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 = 1.0d0 + ((-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 = 1.0 + (-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 = 1.0 + (-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(1.0 + Float64(-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 = 1.0 + (-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[(1.0 + N[(-1.0 / x), $MachinePrecision]), $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}:\\
\;\;\;\;1 + \frac{-1}{x}\\
\end{array}
\end{array}
if x < -1 or 0.75 < x Initial program 51.4%
frac-2neg51.4%
frac-2neg51.4%
frac-sub52.1%
distribute-rgt-neg-in52.1%
distribute-lft-neg-in52.1%
metadata-eval52.1%
metadata-eval52.1%
*-un-lft-identity52.1%
cancel-sign-sub52.1%
distribute-rgt-neg-in52.1%
*-rgt-identity52.1%
neg-sub052.1%
+-commutative52.1%
associate--r+52.1%
metadata-eval52.1%
*-commutative52.1%
neg-sub052.1%
+-commutative52.1%
associate--r+52.1%
metadata-eval52.1%
Applied egg-rr52.1%
associate-+r-52.1%
+-commutative52.1%
associate--l+98.8%
distribute-lft-neg-out98.8%
distribute-rgt-neg-in98.8%
Simplified98.8%
associate-/r*99.8%
+-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
distribute-neg-frac99.8%
clear-num98.6%
associate-/r/99.6%
neg-sub099.6%
+-inverses99.6%
metadata-eval99.6%
+-inverses99.6%
associate--r-99.6%
+-inverses99.6%
+-inverses99.6%
metadata-eval99.6%
metadata-eval99.6%
+-commutative99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-*r/99.8%
*-commutative99.8%
Applied egg-rr98.6%
Taylor expanded in x around inf 98.7%
if -1 < x < 0.75Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification99.1%
(FPCore (x) :precision binary64 (/ -1.0 x))
double code(double x) {
return -1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-1.0d0) / x
end function
public static double code(double x) {
return -1.0 / x;
}
def code(x): return -1.0 / x
function code(x) return Float64(-1.0 / x) end
function tmp = code(x) tmp = -1.0 / x; end
code[x_] := N[(-1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x}
\end{array}
Initial program 76.6%
Taylor expanded in x around 0 53.8%
Final simplification53.8%
(FPCore (x) :precision binary64 (- x))
double code(double x) {
return -x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -x
end function
public static double code(double x) {
return -x;
}
def code(x): return -x
function code(x) return Float64(-x) end
function tmp = code(x) tmp = -x; end
code[x_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 76.6%
Taylor expanded in x around 0 52.9%
mul-1-neg52.9%
sub-neg52.9%
Simplified52.9%
Taylor expanded in x around inf 3.1%
mul-1-neg3.1%
Simplified3.1%
Final simplification3.1%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 76.6%
Taylor expanded in x around 0 52.9%
mul-1-neg52.9%
sub-neg52.9%
Simplified52.9%
sub-neg52.9%
+-commutative52.9%
flip--52.8%
metadata-eval52.8%
metadata-eval52.8%
metadata-eval52.8%
+-inverses52.8%
metadata-eval52.8%
+-inverses52.8%
associate--r-52.8%
+-inverses52.8%
+-inverses52.8%
metadata-eval52.8%
neg-sub052.8%
metadata-eval52.8%
+-inverses52.8%
metadata-eval52.8%
+-inverses52.8%
add-sqr-sqrt52.4%
sqrt-unprod52.8%
sqr-neg52.8%
sqrt-unprod0.8%
add-sqr-sqrt52.3%
Applied egg-rr52.3%
Taylor expanded in x around inf 2.0%
Final simplification2.0%
herbie shell --seed 2023305
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))