| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 6852 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 1.1 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{x \cdot 0.5 + 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + 1} + -1\\
\end{array}
\]

(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (if (<= x 1.1e-5) (/ x (+ (* x 0.5) 2.0)) (+ (sqrt (+ x 1.0)) -1.0)))
double code(double x) {
return x / (1.0 + sqrt((x + 1.0)));
}
double code(double x) {
double tmp;
if (x <= 1.1e-5) {
tmp = x / ((x * 0.5) + 2.0);
} else {
tmp = sqrt((x + 1.0)) + -1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (1.0d0 + sqrt((x + 1.0d0)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.1d-5) then
tmp = x / ((x * 0.5d0) + 2.0d0)
else
tmp = sqrt((x + 1.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x) {
return x / (1.0 + Math.sqrt((x + 1.0)));
}
public static double code(double x) {
double tmp;
if (x <= 1.1e-5) {
tmp = x / ((x * 0.5) + 2.0);
} else {
tmp = Math.sqrt((x + 1.0)) + -1.0;
}
return tmp;
}
def code(x): return x / (1.0 + math.sqrt((x + 1.0)))
def code(x): tmp = 0 if x <= 1.1e-5: tmp = x / ((x * 0.5) + 2.0) else: tmp = math.sqrt((x + 1.0)) + -1.0 return tmp
function code(x) return Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) end
function code(x) tmp = 0.0 if (x <= 1.1e-5) tmp = Float64(x / Float64(Float64(x * 0.5) + 2.0)); else tmp = Float64(sqrt(Float64(x + 1.0)) + -1.0); end return tmp end
function tmp = code(x) tmp = x / (1.0 + sqrt((x + 1.0))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.1e-5) tmp = x / ((x * 0.5) + 2.0); else tmp = sqrt((x + 1.0)) + -1.0; end tmp_2 = tmp; end
code[x_] := N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, 1.1e-5], N[(x / N[(N[(x * 0.5), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
\frac{x}{1 + \sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 1.1 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{x \cdot 0.5 + 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + 1} + -1\\
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if x < 1.1e-5Initial program 100.0%
Taylor expanded in x around 0 99.9%
if 1.1e-5 < x Initial program 99.4%
Applied egg-rr99.9%
[Start]99.4% | \[ \frac{x}{1 + \sqrt{x + 1}}
\] |
|---|---|
flip-+ [=>]99.4% | \[ \frac{x}{\color{blue}{\frac{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}}}
\] |
metadata-eval [=>]99.4% | \[ \frac{x}{\frac{\color{blue}{1} - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}}
\] |
add-sqr-sqrt [<=]100.0% | \[ \frac{x}{\frac{1 - \color{blue}{\left(x + 1\right)}}{1 - \sqrt{x + 1}}}
\] |
+-commutative [=>]100.0% | \[ \frac{x}{\frac{1 - \color{blue}{\left(1 + x\right)}}{1 - \sqrt{x + 1}}}
\] |
associate--r+ [=>]99.9% | \[ \frac{x}{\frac{\color{blue}{\left(1 - 1\right) - x}}{1 - \sqrt{x + 1}}}
\] |
metadata-eval [=>]99.9% | \[ \frac{x}{\frac{\color{blue}{0} - x}{1 - \sqrt{x + 1}}}
\] |
neg-sub0 [<=]99.9% | \[ \frac{x}{\frac{\color{blue}{-x}}{1 - \sqrt{x + 1}}}
\] |
associate-/r/ [=>]99.9% | \[ \color{blue}{\frac{x}{-x} \cdot \left(1 - \sqrt{x + 1}\right)}
\] |
Simplified99.9%
[Start]99.9% | \[ \frac{x}{-x} \cdot \left(1 - \sqrt{x + 1}\right)
\] |
|---|---|
sub-neg [=>]99.9% | \[ \frac{x}{-x} \cdot \color{blue}{\left(1 + \left(-\sqrt{x + 1}\right)\right)}
\] |
+-commutative [=>]99.9% | \[ \frac{x}{-x} \cdot \color{blue}{\left(\left(-\sqrt{x + 1}\right) + 1\right)}
\] |
remove-double-neg [<=]99.9% | \[ \frac{\color{blue}{-\left(-x\right)}}{-x} \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
distribute-frac-neg [=>]99.9% | \[ \color{blue}{\left(-\frac{-x}{-x}\right)} \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
*-inverses [=>]99.9% | \[ \left(-\color{blue}{1}\right) \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
metadata-eval [=>]99.9% | \[ \color{blue}{-1} \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
distribute-lft-in [=>]99.9% | \[ \color{blue}{-1 \cdot \left(-\sqrt{x + 1}\right) + -1 \cdot 1}
\] |
neg-mul-1 [<=]99.9% | \[ \color{blue}{\left(-\left(-\sqrt{x + 1}\right)\right)} + -1 \cdot 1
\] |
remove-double-neg [=>]99.9% | \[ \color{blue}{\sqrt{x + 1}} + -1 \cdot 1
\] |
metadata-eval [=>]99.9% | \[ \sqrt{x + 1} + \color{blue}{-1}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 6852 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 6848 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.8% |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Accuracy | 67.1% |
| Cost | 192 |
| Alternative 5 | |
|---|---|
| Accuracy | 4.8% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
:precision binary64
(/ x (+ 1.0 (sqrt (+ x 1.0)))))