
(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 5 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) (- -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 76.4%
sub-neg76.4%
add-exp-log51.6%
log-rec51.6%
+-commutative51.6%
log1p-define51.6%
distribute-neg-frac51.6%
metadata-eval51.6%
Applied egg-rr51.6%
*-rgt-identity51.6%
fma-undefine51.6%
*-inverses51.6%
metadata-eval51.6%
distribute-neg-frac51.6%
fma-neg51.6%
*-inverses51.6%
*-rgt-identity51.6%
exp-neg51.6%
log1p-undefine51.6%
rem-exp-log76.4%
*-inverses76.4%
associate-/l/54.2%
associate-/r*76.4%
div-sub76.4%
*-inverses76.4%
div-sub77.0%
associate-/l/77.0%
+-commutative77.0%
associate--r+99.3%
Simplified99.9%
Final simplification99.9%
(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 52.9%
Taylor expanded in x around inf 97.3%
unpow297.3%
associate-/r*98.4%
Applied egg-rr98.4%
if -1 < x < 0.75Initial program 100.0%
Taylor expanded in x around 0 99.2%
Final simplification98.8%
(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(-1.0 / Float64(x * Float64(x + 1.0))) end
function tmp = code(x) tmp = -1.0 / (x * (x + 1.0)); end
code[x_] := N[(-1.0 / N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{x \cdot \left(x + 1\right)}
\end{array}
Initial program 76.4%
sub-neg76.4%
add-exp-log51.6%
log-rec51.6%
+-commutative51.6%
log1p-define51.6%
distribute-neg-frac51.6%
metadata-eval51.6%
Applied egg-rr51.6%
*-rgt-identity51.6%
fma-undefine51.6%
*-inverses51.6%
metadata-eval51.6%
distribute-neg-frac51.6%
fma-neg51.6%
*-inverses51.6%
*-rgt-identity51.6%
exp-neg51.6%
log1p-undefine51.6%
rem-exp-log76.4%
*-inverses76.4%
associate-/l/54.2%
associate-/r*76.4%
div-sub76.4%
*-inverses76.4%
div-sub77.0%
associate-/l/77.0%
+-commutative77.0%
associate--r+99.3%
Simplified99.9%
div-inv99.9%
associate-/l*99.9%
add-sqr-sqrt42.0%
sqrt-unprod51.2%
frac-times51.1%
metadata-eval51.1%
metadata-eval51.1%
frac-times51.2%
sqrt-unprod17.4%
add-sqr-sqrt25.4%
div-inv25.4%
metadata-eval25.4%
associate-/r*25.4%
associate-*l/25.4%
*-un-lft-identity25.4%
add-exp-log8.2%
rec-exp8.2%
+-commutative8.2%
log1p-define8.2%
add-sqr-sqrt0.2%
sqrt-unprod33.0%
mul-1-neg33.0%
mul-1-neg33.0%
sqr-neg33.0%
Applied egg-rr68.2%
associate-*r/68.2%
associate-*l/68.2%
exp-neg68.2%
log1p-undefine68.2%
+-commutative68.2%
rem-exp-log99.8%
associate-*r/99.9%
*-rgt-identity99.9%
associate-/r*99.3%
Simplified99.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 76.4%
Taylor expanded in x around 0 51.8%
(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 76.4%
Taylor expanded in x around inf 50.4%
unpow250.4%
associate-/r*50.9%
Applied egg-rr50.9%
div-inv50.8%
frac-2neg50.8%
metadata-eval50.8%
frac-times50.4%
metadata-eval50.4%
Applied egg-rr50.4%
Applied egg-rr3.6%
+-lft-identity3.6%
mul0-lft3.6%
+-rgt-identity3.6%
associate-/r*3.6%
*-inverses3.6%
metadata-eval3.6%
Simplified3.6%
herbie shell --seed 2024095
(FPCore (x)
:name "2frac (problem 3.3.1)"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))