| Alternative 1 | |
|---|---|
| Error | 0.28% |
| Cost | 6848 |
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (if (<= x 0.00018) (* x (+ 0.5 (* x (+ -0.125 (* x 0.0625))))) (+ (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 <= 0.00018) {
tmp = x * (0.5 + (x * (-0.125 + (x * 0.0625))));
} 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 <= 0.00018d0) then
tmp = x * (0.5d0 + (x * ((-0.125d0) + (x * 0.0625d0))))
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 <= 0.00018) {
tmp = x * (0.5 + (x * (-0.125 + (x * 0.0625))));
} 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 <= 0.00018: tmp = x * (0.5 + (x * (-0.125 + (x * 0.0625)))) 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 <= 0.00018) tmp = Float64(x * Float64(0.5 + Float64(x * Float64(-0.125 + Float64(x * 0.0625))))); 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 <= 0.00018) tmp = x * (0.5 + (x * (-0.125 + (x * 0.0625)))); 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, 0.00018], N[(x * N[(0.5 + N[(x * N[(-0.125 + N[(x * 0.0625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 0.00018:\\
\;\;\;\;x \cdot \left(0.5 + x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + 1} + -1\\
\end{array}
Results
if x < 1.80000000000000011e-4Initial program 0.02
Applied egg-rr92.03
Simplified92.03
[Start]92.03 | \[ \frac{x}{-x} \cdot 1 + \frac{x}{-x} \cdot \left(-\sqrt{x + 1}\right)
\] |
|---|---|
distribute-lft-out [=>]92.03 | \[ \color{blue}{\frac{x}{-x} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)}
\] |
remove-double-neg [<=]92.03 | \[ \frac{\color{blue}{-\left(-x\right)}}{-x} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
distribute-frac-neg [=>]92.03 | \[ \color{blue}{\left(-\frac{-x}{-x}\right)} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
*-inverses [=>]92.03 | \[ \left(-\color{blue}{1}\right) \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
metadata-eval [=>]92.03 | \[ \color{blue}{-1} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
sub-neg [<=]92.03 | \[ -1 \cdot \color{blue}{\left(1 - \sqrt{x + 1}\right)}
\] |
neg-mul-1 [<=]92.03 | \[ \color{blue}{-\left(1 - \sqrt{x + 1}\right)}
\] |
neg-sub0 [=>]92.03 | \[ \color{blue}{0 - \left(1 - \sqrt{x + 1}\right)}
\] |
associate--r- [=>]92.03 | \[ \color{blue}{\left(0 - 1\right) + \sqrt{x + 1}}
\] |
metadata-eval [=>]92.03 | \[ \color{blue}{-1} + \sqrt{x + 1}
\] |
+-commutative [<=]92.03 | \[ \color{blue}{\sqrt{x + 1} + -1}
\] |
Taylor expanded in x around 0 0.28
Simplified0.29
[Start]0.28 | \[ -0.125 \cdot {x}^{2} + \left(0.5 \cdot x + 0.0625 \cdot {x}^{3}\right)
\] |
|---|---|
+-commutative [=>]0.28 | \[ \color{blue}{\left(0.5 \cdot x + 0.0625 \cdot {x}^{3}\right) + -0.125 \cdot {x}^{2}}
\] |
associate-+l+ [=>]0.27 | \[ \color{blue}{0.5 \cdot x + \left(0.0625 \cdot {x}^{3} + -0.125 \cdot {x}^{2}\right)}
\] |
*-commutative [=>]0.27 | \[ \color{blue}{x \cdot 0.5} + \left(0.0625 \cdot {x}^{3} + -0.125 \cdot {x}^{2}\right)
\] |
unpow3 [=>]0.27 | \[ x \cdot 0.5 + \left(0.0625 \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} + -0.125 \cdot {x}^{2}\right)
\] |
unpow2 [<=]0.27 | \[ x \cdot 0.5 + \left(0.0625 \cdot \left(\color{blue}{{x}^{2}} \cdot x\right) + -0.125 \cdot {x}^{2}\right)
\] |
associate-*r* [=>]0.27 | \[ x \cdot 0.5 + \left(\color{blue}{\left(0.0625 \cdot {x}^{2}\right) \cdot x} + -0.125 \cdot {x}^{2}\right)
\] |
unpow2 [=>]0.27 | \[ x \cdot 0.5 + \left(\left(0.0625 \cdot {x}^{2}\right) \cdot x + -0.125 \cdot \color{blue}{\left(x \cdot x\right)}\right)
\] |
associate-*r* [=>]0.27 | \[ x \cdot 0.5 + \left(\left(0.0625 \cdot {x}^{2}\right) \cdot x + \color{blue}{\left(-0.125 \cdot x\right) \cdot x}\right)
\] |
distribute-rgt-out [=>]0.27 | \[ x \cdot 0.5 + \color{blue}{x \cdot \left(0.0625 \cdot {x}^{2} + -0.125 \cdot x\right)}
\] |
distribute-lft-out [=>]0.29 | \[ \color{blue}{x \cdot \left(0.5 + \left(0.0625 \cdot {x}^{2} + -0.125 \cdot x\right)\right)}
\] |
unpow2 [=>]0.29 | \[ x \cdot \left(0.5 + \left(0.0625 \cdot \color{blue}{\left(x \cdot x\right)} + -0.125 \cdot x\right)\right)
\] |
associate-*r* [=>]0.29 | \[ x \cdot \left(0.5 + \left(\color{blue}{\left(0.0625 \cdot x\right) \cdot x} + -0.125 \cdot x\right)\right)
\] |
*-commutative [<=]0.29 | \[ x \cdot \left(0.5 + \left(\color{blue}{\left(x \cdot 0.0625\right)} \cdot x + -0.125 \cdot x\right)\right)
\] |
distribute-rgt-out [=>]0.29 | \[ x \cdot \left(0.5 + \color{blue}{x \cdot \left(x \cdot 0.0625 + -0.125\right)}\right)
\] |
+-commutative [=>]0.29 | \[ x \cdot \left(0.5 + x \cdot \color{blue}{\left(-0.125 + x \cdot 0.0625\right)}\right)
\] |
if 1.80000000000000011e-4 < x Initial program 0.79
Applied egg-rr0.12
Simplified0.12
[Start]0.12 | \[ \frac{x}{-x} \cdot 1 + \frac{x}{-x} \cdot \left(-\sqrt{x + 1}\right)
\] |
|---|---|
distribute-lft-out [=>]0.12 | \[ \color{blue}{\frac{x}{-x} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)}
\] |
remove-double-neg [<=]0.12 | \[ \frac{\color{blue}{-\left(-x\right)}}{-x} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
distribute-frac-neg [=>]0.12 | \[ \color{blue}{\left(-\frac{-x}{-x}\right)} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
*-inverses [=>]0.12 | \[ \left(-\color{blue}{1}\right) \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
metadata-eval [=>]0.12 | \[ \color{blue}{-1} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)
\] |
sub-neg [<=]0.12 | \[ -1 \cdot \color{blue}{\left(1 - \sqrt{x + 1}\right)}
\] |
neg-mul-1 [<=]0.12 | \[ \color{blue}{-\left(1 - \sqrt{x + 1}\right)}
\] |
neg-sub0 [=>]0.12 | \[ \color{blue}{0 - \left(1 - \sqrt{x + 1}\right)}
\] |
associate--r- [=>]0.12 | \[ \color{blue}{\left(0 - 1\right) + \sqrt{x + 1}}
\] |
metadata-eval [=>]0.12 | \[ \color{blue}{-1} + \sqrt{x + 1}
\] |
+-commutative [<=]0.12 | \[ \color{blue}{\sqrt{x + 1} + -1}
\] |
Final simplification0.23
| Alternative 1 | |
|---|---|
| Error | 0.28% |
| Cost | 6848 |
| Alternative 2 | |
|---|---|
| Error | 31.61% |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Error | 32.4% |
| Cost | 192 |
| Alternative 4 | |
|---|---|
| Error | 95.11% |
| Cost | 64 |
herbie shell --seed 2023089
(FPCore (x)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
:precision binary64
(/ x (+ 1.0 (sqrt (+ x 1.0)))))