?

Average Error: 0.28% → 0.23%
Time: 8.3s
Precision: binary64
Cost: 6852

?

\[\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} \]
(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}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if x < 1.80000000000000011e-4

    1. Initial program 0.02

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Applied egg-rr92.03

      \[\leadsto \color{blue}{\frac{x}{-x} \cdot 1 + \frac{x}{-x} \cdot \left(-\sqrt{x + 1}\right)} \]
    3. Simplified92.03

      \[\leadsto \color{blue}{\sqrt{x + 1} + -1} \]
      Proof

      [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} \]
    4. Taylor expanded in x around 0 0.28

      \[\leadsto \color{blue}{-0.125 \cdot {x}^{2} + \left(0.5 \cdot x + 0.0625 \cdot {x}^{3}\right)} \]
    5. Simplified0.29

      \[\leadsto \color{blue}{x \cdot \left(0.5 + x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)} \]
      Proof

      [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

    1. Initial program 0.79

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Applied egg-rr0.12

      \[\leadsto \color{blue}{\frac{x}{-x} \cdot 1 + \frac{x}{-x} \cdot \left(-\sqrt{x + 1}\right)} \]
    3. Simplified0.12

      \[\leadsto \color{blue}{\sqrt{x + 1} + -1} \]
      Proof

      [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} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.23

    \[\leadsto \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} \]

Alternatives

Alternative 1
Error0.28%
Cost6848
\[\frac{x}{1 + \sqrt{x + 1}} \]
Alternative 2
Error31.61%
Cost448
\[\frac{x}{x \cdot 0.5 + 2} \]
Alternative 3
Error32.4%
Cost192
\[\frac{x}{2} \]
Alternative 4
Error95.11%
Cost64
\[2 \]

Error

Reproduce?

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)))))