
(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 (- -1.0 x)) x))
double code(double x) {
return (1.0 / (-1.0 - x)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / ((-1.0d0) - x)) / x
end function
public static double code(double x) {
return (1.0 / (-1.0 - x)) / x;
}
def code(x): return (1.0 / (-1.0 - x)) / x
function code(x) return Float64(Float64(1.0 / Float64(-1.0 - x)) / x) end
function tmp = code(x) tmp = (1.0 / (-1.0 - x)) / x; end
code[x_] := N[(N[(1.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{-1 - x}}{x}
\end{array}
Initial program 78.6%
frac-sub79.9%
*-rgt-identity79.9%
metadata-eval79.9%
div-inv79.9%
associate-/r*79.9%
*-un-lft-identity79.9%
*-rgt-identity79.9%
+-commutative79.9%
div-inv79.9%
metadata-eval79.9%
*-rgt-identity79.9%
+-commutative79.9%
Applied egg-rr79.9%
frac-2neg79.9%
div-inv79.9%
sub-neg79.9%
distribute-neg-in79.9%
metadata-eval79.9%
sub-neg79.9%
distribute-neg-in79.9%
metadata-eval79.9%
sub-neg79.9%
Applied egg-rr79.9%
associate-+r-79.9%
+-commutative79.9%
associate--l+99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
*-lft-identity99.9%
Simplified99.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 56.8%
frac-sub59.5%
div-inv59.5%
*-un-lft-identity59.5%
*-rgt-identity59.5%
+-commutative59.5%
metadata-eval59.5%
frac-times59.5%
clear-num59.5%
associate-*l/59.5%
*-un-lft-identity59.5%
div-inv59.5%
metadata-eval59.5%
*-rgt-identity59.5%
+-commutative59.5%
Applied egg-rr59.5%
Taylor expanded in x around 0 99.8%
add-sqr-sqrt48.8%
sqrt-unprod52.3%
swap-sqr52.3%
metadata-eval52.3%
*-un-lft-identity52.3%
sqrt-unprod51.9%
add-sqr-sqrt51.9%
associate-/l/51.9%
associate-/r*51.9%
frac-2neg51.9%
metadata-eval51.9%
distribute-neg-in51.9%
metadata-eval51.9%
add-sqr-sqrt34.0%
sqrt-unprod76.3%
sqr-neg76.3%
sqrt-unprod42.6%
add-sqr-sqrt96.8%
Applied egg-rr96.8%
Taylor expanded in x around inf 97.0%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.1%
neg-mul-199.1%
sub-neg99.1%
Simplified99.1%
Final simplification98.0%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.76))) (/ (/ -1.0 x) x) (/ (+ -1.0 x) x)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.76)) {
tmp = (-1.0 / x) / 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)) .or. (.not. (x <= 0.76d0))) then
tmp = ((-1.0d0) / x) / 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) || !(x <= 0.76)) {
tmp = (-1.0 / x) / x;
} else {
tmp = (-1.0 + x) / x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 0.76): tmp = (-1.0 / x) / x else: tmp = (-1.0 + x) / x return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.76)) tmp = Float64(Float64(-1.0 / x) / x); else tmp = Float64(Float64(-1.0 + x) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.76))) tmp = (-1.0 / x) / x; else tmp = (-1.0 + x) / x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.76]], $MachinePrecision]], N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision], N[(N[(-1.0 + x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.76\right):\\
\;\;\;\;\frac{\frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 + x}{x}\\
\end{array}
\end{array}
if x < -1 or 0.76000000000000001 < x Initial program 57.1%
frac-sub59.9%
div-inv59.9%
*-un-lft-identity59.9%
*-rgt-identity59.9%
+-commutative59.9%
metadata-eval59.9%
frac-times59.9%
clear-num59.9%
associate-*l/59.8%
*-un-lft-identity59.8%
div-inv59.8%
metadata-eval59.8%
*-rgt-identity59.8%
+-commutative59.8%
Applied egg-rr59.8%
Taylor expanded in x around 0 99.8%
add-sqr-sqrt48.4%
sqrt-unprod51.9%
swap-sqr51.9%
metadata-eval51.9%
*-un-lft-identity51.9%
sqrt-unprod51.5%
add-sqr-sqrt51.5%
associate-/l/51.6%
associate-/r*51.5%
frac-2neg51.5%
metadata-eval51.5%
distribute-neg-in51.5%
metadata-eval51.5%
add-sqr-sqrt33.8%
sqrt-unprod75.7%
sqr-neg75.7%
sqrt-unprod42.3%
add-sqr-sqrt96.1%
Applied egg-rr96.1%
Taylor expanded in x around inf 96.3%
if -1 < x < 0.76000000000000001Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification97.9%
(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 78.6%
clear-num78.6%
frac-sub79.9%
*-un-lft-identity79.9%
div-inv79.9%
metadata-eval79.9%
*-rgt-identity79.9%
*-rgt-identity79.9%
+-commutative79.9%
*-commutative79.9%
div-inv79.9%
metadata-eval79.9%
*-rgt-identity79.9%
+-commutative79.9%
Applied egg-rr79.9%
Taylor expanded in x around 0 99.3%
(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 78.6%
Taylor expanded in x around 0 52.6%
(FPCore (x) :precision binary64 -2.0)
double code(double x) {
return -2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -2.0d0
end function
public static double code(double x) {
return -2.0;
}
def code(x): return -2.0
function code(x) return -2.0 end
function tmp = code(x) tmp = -2.0; end
code[x_] := -2.0
\begin{array}{l}
\\
-2
\end{array}
Initial program 78.6%
Taylor expanded in x around 0 52.6%
add-sqr-sqrt25.6%
sqrt-unprod39.5%
frac-times40.0%
metadata-eval40.0%
metadata-eval40.0%
frac-times39.5%
sqrt-unprod1.1%
add-sqr-sqrt3.3%
clear-num3.3%
associate-/r/3.3%
Applied egg-rr3.3%
Applied egg-rr2.5%
fma-undefine2.5%
distribute-rgt-in2.5%
associate-*r/2.5%
metadata-eval2.5%
associate-+l+2.5%
associate-*r/2.5%
*-commutative2.5%
mul-1-neg2.5%
distribute-frac-neg2.5%
*-inverses2.5%
metadata-eval2.5%
metadata-eval2.5%
Simplified2.5%
Taylor expanded in x around inf 3.8%
herbie shell --seed 2024114
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))