# ?

Average Error: 29.3 → 0.2
Time: 6.3s
Precision: binary64
Cost: 6980

# ?

$0 \leq x \land x \leq 1.79 \cdot 10^{+308}$
$\sqrt{x + 1} - 1$
$\begin{array}{l} \mathbf{if}\;x + 1 \leq 1.02:\\ \;\;\;\;x \cdot \left(x \cdot -0.125\right) + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array}$
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) 1.0))
(FPCore (x)
:precision binary64
(if (<= (+ x 1.0) 1.02)
(+ (* x (* x -0.125)) (* x 0.5))
(+ (sqrt (+ x 1.0)) -1.0)))
double code(double x) {
return sqrt((x + 1.0)) - 1.0;
}
double code(double x) {
double tmp;
if ((x + 1.0) <= 1.02) {
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 = sqrt((x + 1.0d0)) - 1.0d0
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x + 1.0d0) <= 1.02d0) 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 Math.sqrt((x + 1.0)) - 1.0;
}
public static double code(double x) {
double tmp;
if ((x + 1.0) <= 1.02) {
tmp = (x * (x * -0.125)) + (x * 0.5);
} else {
tmp = Math.sqrt((x + 1.0)) + -1.0;
}
return tmp;
}
def code(x):
return math.sqrt((x + 1.0)) - 1.0
def code(x):
tmp = 0
if (x + 1.0) <= 1.02:
tmp = (x * (x * -0.125)) + (x * 0.5)
else:
tmp = math.sqrt((x + 1.0)) + -1.0
return tmp
function code(x)
return Float64(sqrt(Float64(x + 1.0)) - 1.0)
end
function code(x)
tmp = 0.0
if (Float64(x + 1.0) <= 1.02)
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 = sqrt((x + 1.0)) - 1.0;
end
function tmp_2 = code(x)
tmp = 0.0;
if ((x + 1.0) <= 1.02)
tmp = (x * (x * -0.125)) + (x * 0.5);
else
tmp = sqrt((x + 1.0)) + -1.0;
end
tmp_2 = tmp;
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]],$MachinePrecision] - 1.0), $MachinePrecision] code[x_] := If[LessEqual[N[(x + 1.0),$MachinePrecision], 1.02], 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]]
\sqrt{x + 1} - 1
\begin{array}{l}
\mathbf{if}\;x + 1 \leq 1.02:\\
\;\;\;\;x \cdot \left(x \cdot -0.125\right) + x \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\sqrt{x + 1} + -1\\

\end{array}

# Try it out?

Results

 In Out
Enter valid numbers for all inputs

# Derivation?

1. Split input into 2 regimes
2. ## if (+.f64 x 1) < 1.02

1. Initial program 58.9

$\sqrt{x + 1} - 1$
2. Taylor expanded in x around 0 0.4

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

$\leadsto \color{blue}{\mathsf{fma}\left(0.5, x, x \cdot \left(x \cdot -0.125\right)\right)}$
Proof
[Start]0.4 $-0.125 \cdot {x}^{2} + 0.5 \cdot x$ $\color{blue}{0.5 \cdot x + -0.125 \cdot {x}^{2}}$ $\color{blue}{\mathsf{fma}\left(0.5, x, -0.125 \cdot {x}^{2}\right)}$ $\mathsf{fma}\left(0.5, x, \color{blue}{{x}^{2} \cdot -0.125}\right)$ $\mathsf{fma}\left(0.5, x, \color{blue}{\left(x \cdot x\right)} \cdot -0.125\right)$ $\mathsf{fma}\left(0.5, x, \color{blue}{x \cdot \left(x \cdot -0.125\right)}\right)$
4. Applied egg-rr0.4

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

## if 1.02 < (+.f64 x 1)

1. Initial program 0.0

$\sqrt{x + 1} - 1$
3. Recombined 2 regimes into one program.
4. Final simplification0.2

$\leadsto \begin{array}{l} \mathbf{if}\;x + 1 \leq 1.02:\\ \;\;\;\;x \cdot \left(x \cdot -0.125\right) + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array}$

# Alternatives

Alternative 1
Error0.3
Cost6848
$\frac{x}{1 + \sqrt{x + 1}}$
Alternative 2
Error30.1
Cost448
$\frac{x}{x \cdot 0.5 + 2}$
Alternative 3
Error30.5
Cost192
$x \cdot 0.5$

# Reproduce?

herbie shell --seed 1
(FPCore (x)
:name "sqrt(x + 1) - 1"
:precision binary64
:pre (and (<= 0.0 x) (<= x 1.79e+308))
(- (sqrt (+ x 1.0)) 1.0))