?

Average Error: 0.2 → 0.2
Time: 2.8s
Precision: binary64
Cost: 6852

?

\[\frac{x}{1 + \sqrt{x + 1}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 6.8 \cdot 10^{-6}:\\ \;\;\;\;-0.125 \cdot \left(x \cdot x\right) + x \cdot 0.5\\ \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 6.8e-6) (+ (* -0.125 (* x x)) (* 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 <= 6.8e-6) {
		tmp = (-0.125 * (x * x)) + (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 <= 6.8d-6) then
        tmp = ((-0.125d0) * (x * x)) + (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 <= 6.8e-6) {
		tmp = (-0.125 * (x * x)) + (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 <= 6.8e-6:
		tmp = (-0.125 * (x * x)) + (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 <= 6.8e-6)
		tmp = Float64(Float64(-0.125 * Float64(x * x)) + 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 <= 6.8e-6)
		tmp = (-0.125 * (x * x)) + (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, 6.8e-6], N[(N[(-0.125 * N[(x * x), $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 6.8 \cdot 10^{-6}:\\
\;\;\;\;-0.125 \cdot \left(x \cdot x\right) + x \cdot 0.5\\

\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 < 6.80000000000000012e-6

    1. Initial program 0.0

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Taylor expanded in x around 0 0.3

      \[\leadsto \color{blue}{-0.125 \cdot {x}^{2} + 0.5 \cdot x} \]
    3. Simplified0.3

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

      [Start]0.3

      \[ -0.125 \cdot {x}^{2} + 0.5 \cdot x \]

      +-commutative [=>]0.3

      \[ \color{blue}{0.5 \cdot x + -0.125 \cdot {x}^{2}} \]

      *-commutative [=>]0.3

      \[ \color{blue}{x \cdot 0.5} + -0.125 \cdot {x}^{2} \]

      *-commutative [=>]0.3

      \[ x \cdot 0.5 + \color{blue}{{x}^{2} \cdot -0.125} \]

      unpow2 [=>]0.3

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

      associate-*l* [=>]0.3

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

      distribute-lft-out [=>]0.3

      \[ \color{blue}{x \cdot \left(0.5 + x \cdot -0.125\right)} \]
    4. Applied egg-rr0.3

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

    if 6.80000000000000012e-6 < x

    1. Initial program 0.5

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

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

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

      [Start]0.1

      \[ \frac{x}{-x} \cdot 1 + \frac{x}{-x} \cdot \left(-\sqrt{x + 1}\right) \]

      distribute-lft-out [=>]0.1

      \[ \color{blue}{\frac{x}{-x} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right)} \]

      remove-double-neg [<=]0.1

      \[ \frac{\color{blue}{-\left(-x\right)}}{-x} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right) \]

      distribute-frac-neg [=>]0.1

      \[ \color{blue}{\left(-\frac{-x}{-x}\right)} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right) \]

      *-inverses [=>]0.1

      \[ \left(-\color{blue}{1}\right) \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right) \]

      metadata-eval [=>]0.1

      \[ \color{blue}{-1} \cdot \left(1 + \left(-\sqrt{x + 1}\right)\right) \]

      sub-neg [<=]0.1

      \[ -1 \cdot \color{blue}{\left(1 - \sqrt{x + 1}\right)} \]

      neg-mul-1 [<=]0.1

      \[ \color{blue}{-\left(1 - \sqrt{x + 1}\right)} \]

      neg-sub0 [=>]0.1

      \[ \color{blue}{0 - \left(1 - \sqrt{x + 1}\right)} \]

      associate--r- [=>]0.1

      \[ \color{blue}{\left(0 - 1\right) + \sqrt{x + 1}} \]

      metadata-eval [=>]0.1

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

      +-commutative [<=]0.1

      \[ \color{blue}{\sqrt{x + 1} + -1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 6.8 \cdot 10^{-6}:\\ \;\;\;\;-0.125 \cdot \left(x \cdot x\right) + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost6848
\[\frac{x}{1 + \sqrt{x + 1}} \]
Alternative 2
Error20.3
Cost448
\[\frac{x}{x \cdot 0.5 + 2} \]
Alternative 3
Error20.7
Cost192
\[\frac{x}{2} \]
Alternative 4
Error60.9
Cost64
\[2 \]

Error

Reproduce?

herbie shell --seed 2023083 
(FPCore (x)
  :name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
  :precision binary64
  (/ x (+ 1.0 (sqrt (+ x 1.0)))))