
(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 79.9%
frac-sub80.9%
*-rgt-identity80.9%
metadata-eval80.9%
div-inv80.9%
associate-/r*80.9%
*-un-lft-identity80.9%
*-rgt-identity80.9%
+-commutative80.9%
div-inv80.9%
metadata-eval80.9%
*-rgt-identity80.9%
+-commutative80.9%
Applied egg-rr80.9%
Taylor expanded in x around 0 99.9%
Final simplification99.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 79.9%
frac-sub80.9%
*-rgt-identity80.9%
metadata-eval80.9%
div-inv80.9%
associate-/r*80.9%
*-un-lft-identity80.9%
*-rgt-identity80.9%
+-commutative80.9%
div-inv80.9%
metadata-eval80.9%
*-rgt-identity80.9%
+-commutative80.9%
Applied egg-rr80.9%
*-un-lft-identity80.9%
associate-/l/80.9%
associate-/r*80.8%
associate--r+80.8%
div-sub79.8%
div-sub79.8%
*-inverses79.8%
add-exp-log46.1%
sub-neg46.1%
mul-1-neg46.1%
div-inv46.1%
log1p-undefine46.1%
*-inverses46.1%
expm1-undefine66.1%
expm1-log1p-u99.8%
+-commutative99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
associate-/l/99.6%
Simplified99.6%
Final simplification99.6%
(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(Float64(-1.0 / x) / Float64(1.0 + x)) end
function tmp = code(x) tmp = (-1.0 / x) / (1.0 + x); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{x}}{1 + x}
\end{array}
Initial program 79.9%
frac-sub80.9%
*-rgt-identity80.9%
metadata-eval80.9%
div-inv80.9%
associate-/r*80.9%
*-un-lft-identity80.9%
*-rgt-identity80.9%
+-commutative80.9%
div-inv80.9%
metadata-eval80.9%
*-rgt-identity80.9%
+-commutative80.9%
Applied egg-rr80.9%
associate-/l/80.9%
associate-/r*80.8%
flip-+80.9%
associate-/r/80.9%
associate--r+80.9%
div-sub79.9%
div-sub79.9%
*-inverses79.9%
add-exp-log46.1%
sub-neg46.1%
mul-1-neg46.1%
div-inv46.1%
log1p-undefine46.1%
*-inverses46.1%
expm1-undefine60.8%
expm1-log1p-u94.6%
metadata-eval94.6%
pow294.6%
Applied egg-rr94.6%
associate-/r/99.6%
metadata-eval99.6%
unpow299.6%
flip-+99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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 79.9%
Taylor expanded in x around 0 57.2%
Final simplification57.2%
(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 79.9%
Taylor expanded in x around 0 56.4%
div-sub56.4%
sub-neg56.4%
*-commutative56.4%
associate-/l*56.5%
*-inverses56.5%
*-rgt-identity56.5%
neg-mul-156.5%
unsub-neg56.5%
distribute-neg-frac56.5%
metadata-eval56.5%
Simplified56.5%
Taylor expanded in x around inf 3.4%
neg-mul-13.4%
Simplified3.4%
Final simplification3.4%
(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 79.9%
Taylor expanded in x around 0 56.3%
Taylor expanded in x around inf 2.9%
Final simplification2.9%
herbie shell --seed 2024077
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))