| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 6848 |
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (if (<= x 8e-6) (+ (* x (* x -0.125)) (* x 0.5)) (+ (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 <= 8e-6) {
tmp = (x * (x * -0.125)) + (x * 0.5);
} 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 <= 8d-6) then
tmp = (x * (x * (-0.125d0))) + (x * 0.5d0)
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 <= 8e-6) {
tmp = (x * (x * -0.125)) + (x * 0.5);
} 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 <= 8e-6: tmp = (x * (x * -0.125)) + (x * 0.5) 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 <= 8e-6) tmp = Float64(Float64(x * Float64(x * -0.125)) + Float64(x * 0.5)); 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 <= 8e-6) tmp = (x * (x * -0.125)) + (x * 0.5); 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, 8e-6], N[(N[(x * N[(x * -0.125), $MachinePrecision]), $MachinePrecision] + N[(x * 0.5), $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 8 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \left(x \cdot -0.125\right) + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + 1} + -1\\
\end{array}
Results
if x < 7.99999999999999964e-6Initial program 100.0%
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0 | \[ -0.125 \cdot {x}^{2} + 0.5 \cdot x
\] |
|---|---|
+-commutative [=>]100.0 | \[ \color{blue}{0.5 \cdot x + -0.125 \cdot {x}^{2}}
\] |
unpow2 [=>]100.0 | \[ 0.5 \cdot x + -0.125 \cdot \color{blue}{\left(x \cdot x\right)}
\] |
associate-*r* [=>]100.0 | \[ 0.5 \cdot x + \color{blue}{\left(-0.125 \cdot x\right) \cdot x}
\] |
distribute-rgt-out [=>]100.0 | \[ \color{blue}{x \cdot \left(0.5 + -0.125 \cdot x\right)}
\] |
Applied egg-rr100.0%
[Start]100.0 | \[ x \cdot \left(0.5 + -0.125 \cdot x\right)
\] |
|---|---|
+-commutative [=>]100.0 | \[ x \cdot \color{blue}{\left(-0.125 \cdot x + 0.5\right)}
\] |
distribute-lft-in [=>]100.0 | \[ \color{blue}{x \cdot \left(-0.125 \cdot x\right) + x \cdot 0.5}
\] |
*-commutative [=>]100.0 | \[ x \cdot \color{blue}{\left(x \cdot -0.125\right)} + x \cdot 0.5
\] |
if 7.99999999999999964e-6 < x Initial program 99.1%
Applied egg-rr99.8%
[Start]99.1 | \[ \frac{x}{1 + \sqrt{x + 1}}
\] |
|---|---|
flip-+ [=>]99.0 | \[ \frac{x}{\color{blue}{\frac{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}}}
\] |
metadata-eval [=>]99.0 | \[ \frac{x}{\frac{\color{blue}{1} - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}}
\] |
add-sqr-sqrt [<=]99.8 | \[ \frac{x}{\frac{1 - \color{blue}{\left(x + 1\right)}}{1 - \sqrt{x + 1}}}
\] |
+-commutative [=>]99.8 | \[ \frac{x}{\frac{1 - \color{blue}{\left(1 + x\right)}}{1 - \sqrt{x + 1}}}
\] |
associate--r+ [=>]99.8 | \[ \frac{x}{\frac{\color{blue}{\left(1 - 1\right) - x}}{1 - \sqrt{x + 1}}}
\] |
metadata-eval [=>]99.8 | \[ \frac{x}{\frac{\color{blue}{0} - x}{1 - \sqrt{x + 1}}}
\] |
neg-sub0 [<=]99.8 | \[ \frac{x}{\frac{\color{blue}{-x}}{1 - \sqrt{x + 1}}}
\] |
associate-/r/ [=>]99.8 | \[ \color{blue}{\frac{x}{-x} \cdot \left(1 - \sqrt{x + 1}\right)}
\] |
Simplified99.8%
[Start]99.8 | \[ \frac{x}{-x} \cdot \left(1 - \sqrt{x + 1}\right)
\] |
|---|---|
sub-neg [=>]99.8 | \[ \frac{x}{-x} \cdot \color{blue}{\left(1 + \left(-\sqrt{x + 1}\right)\right)}
\] |
+-commutative [=>]99.8 | \[ \frac{x}{-x} \cdot \color{blue}{\left(\left(-\sqrt{x + 1}\right) + 1\right)}
\] |
remove-double-neg [<=]99.8 | \[ \frac{\color{blue}{-\left(-x\right)}}{-x} \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
distribute-frac-neg [=>]99.8 | \[ \color{blue}{\left(-\frac{-x}{-x}\right)} \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
*-inverses [=>]99.8 | \[ \left(-\color{blue}{1}\right) \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
metadata-eval [=>]99.8 | \[ \color{blue}{-1} \cdot \left(\left(-\sqrt{x + 1}\right) + 1\right)
\] |
distribute-lft-in [=>]99.8 | \[ \color{blue}{-1 \cdot \left(-\sqrt{x + 1}\right) + -1 \cdot 1}
\] |
neg-mul-1 [<=]99.8 | \[ \color{blue}{\left(-\left(-\sqrt{x + 1}\right)\right)} + -1 \cdot 1
\] |
remove-double-neg [=>]99.8 | \[ \color{blue}{\sqrt{x + 1}} + -1 \cdot 1
\] |
metadata-eval [=>]99.8 | \[ \sqrt{x + 1} + \color{blue}{-1}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 6848 |
| Alternative 2 | |
|---|---|
| Accuracy | 68.1% |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.4% |
| Cost | 192 |
| Alternative 4 | |
|---|---|
| Accuracy | 4.9% |
| Cost | 64 |
herbie shell --seed 2023160
(FPCore (x)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
:precision binary64
(/ x (+ 1.0 (sqrt (+ x 1.0)))))