Average Error: 58.4 → 1.1
Time: 9.6s
Precision: binary64
Cost: 59652
\[-1.79 \cdot 10^{+308} \leq x \land x \leq 1.79 \cdot 10^{+308}\]
\[\sqrt{1 + x} - {2}^{x} \]
\[\begin{array}{l} t_0 := \sqrt{1 + x} - {2}^{x}\\ \mathbf{if}\;t_0 \leq -0.02:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \left(0.5 - \log 2\right) + \left(0.0625 - 0.16666666666666666 \cdot {\log 2}^{3}\right) \cdot {x}^{3}\right) - \left(0.125 + 0.5 \cdot {\log 2}^{2}\right) \cdot {x}^{2}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) (pow 2.0 x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (sqrt (+ 1.0 x)) (pow 2.0 x))))
   (if (<= t_0 -0.02)
     t_0
     (-
      (+
       (* x (- 0.5 (log 2.0)))
       (* (- 0.0625 (* 0.16666666666666666 (pow (log 2.0) 3.0))) (pow x 3.0)))
      (* (+ 0.125 (* 0.5 (pow (log 2.0) 2.0))) (pow x 2.0))))))
double code(double x) {
	return sqrt((1.0 + x)) - pow(2.0, x);
}
double code(double x) {
	double t_0 = sqrt((1.0 + x)) - pow(2.0, x);
	double tmp;
	if (t_0 <= -0.02) {
		tmp = t_0;
	} else {
		tmp = ((x * (0.5 - log(2.0))) + ((0.0625 - (0.16666666666666666 * pow(log(2.0), 3.0))) * pow(x, 3.0))) - ((0.125 + (0.5 * pow(log(2.0), 2.0))) * pow(x, 2.0));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((1.0d0 + x)) - (2.0d0 ** x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((1.0d0 + x)) - (2.0d0 ** x)
    if (t_0 <= (-0.02d0)) then
        tmp = t_0
    else
        tmp = ((x * (0.5d0 - log(2.0d0))) + ((0.0625d0 - (0.16666666666666666d0 * (log(2.0d0) ** 3.0d0))) * (x ** 3.0d0))) - ((0.125d0 + (0.5d0 * (log(2.0d0) ** 2.0d0))) * (x ** 2.0d0))
    end if
    code = tmp
end function
public static double code(double x) {
	return Math.sqrt((1.0 + x)) - Math.pow(2.0, x);
}
public static double code(double x) {
	double t_0 = Math.sqrt((1.0 + x)) - Math.pow(2.0, x);
	double tmp;
	if (t_0 <= -0.02) {
		tmp = t_0;
	} else {
		tmp = ((x * (0.5 - Math.log(2.0))) + ((0.0625 - (0.16666666666666666 * Math.pow(Math.log(2.0), 3.0))) * Math.pow(x, 3.0))) - ((0.125 + (0.5 * Math.pow(Math.log(2.0), 2.0))) * Math.pow(x, 2.0));
	}
	return tmp;
}
def code(x):
	return math.sqrt((1.0 + x)) - math.pow(2.0, x)
def code(x):
	t_0 = math.sqrt((1.0 + x)) - math.pow(2.0, x)
	tmp = 0
	if t_0 <= -0.02:
		tmp = t_0
	else:
		tmp = ((x * (0.5 - math.log(2.0))) + ((0.0625 - (0.16666666666666666 * math.pow(math.log(2.0), 3.0))) * math.pow(x, 3.0))) - ((0.125 + (0.5 * math.pow(math.log(2.0), 2.0))) * math.pow(x, 2.0))
	return tmp
function code(x)
	return Float64(sqrt(Float64(1.0 + x)) - (2.0 ^ x))
end
function code(x)
	t_0 = Float64(sqrt(Float64(1.0 + x)) - (2.0 ^ x))
	tmp = 0.0
	if (t_0 <= -0.02)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(x * Float64(0.5 - log(2.0))) + Float64(Float64(0.0625 - Float64(0.16666666666666666 * (log(2.0) ^ 3.0))) * (x ^ 3.0))) - Float64(Float64(0.125 + Float64(0.5 * (log(2.0) ^ 2.0))) * (x ^ 2.0)));
	end
	return tmp
end
function tmp = code(x)
	tmp = sqrt((1.0 + x)) - (2.0 ^ x);
end
function tmp_2 = code(x)
	t_0 = sqrt((1.0 + x)) - (2.0 ^ x);
	tmp = 0.0;
	if (t_0 <= -0.02)
		tmp = t_0;
	else
		tmp = ((x * (0.5 - log(2.0))) + ((0.0625 - (0.16666666666666666 * (log(2.0) ^ 3.0))) * (x ^ 3.0))) - ((0.125 + (0.5 * (log(2.0) ^ 2.0))) * (x ^ 2.0));
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Power[2.0, x], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Power[2.0, x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.02], t$95$0, N[(N[(N[(x * N[(0.5 - N[Log[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.0625 - N[(0.16666666666666666 * N[Power[N[Log[2.0], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(0.125 + N[(0.5 * N[Power[N[Log[2.0], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\sqrt{1 + x} - {2}^{x}
\begin{array}{l}
t_0 := \sqrt{1 + x} - {2}^{x}\\
\mathbf{if}\;t_0 \leq -0.02:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot \left(0.5 - \log 2\right) + \left(0.0625 - 0.16666666666666666 \cdot {\log 2}^{3}\right) \cdot {x}^{3}\right) - \left(0.125 + 0.5 \cdot {\log 2}^{2}\right) \cdot {x}^{2}\\


\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 (-.f64 (sqrt.f64 (+.f64 1 x)) (pow.f64 2 x)) < -0.0200000000000000004

    1. Initial program 0.8

      \[\sqrt{1 + x} - {2}^{x} \]

    if -0.0200000000000000004 < (-.f64 (sqrt.f64 (+.f64 1 x)) (pow.f64 2 x))

    1. Initial program 58.8

      \[\sqrt{1 + x} - {2}^{x} \]
    2. Taylor expanded in x around 0 1.1

      \[\leadsto \color{blue}{-1 \cdot \left(\left(0.125 + 0.5 \cdot {\log 2}^{2}\right) \cdot {x}^{2}\right) + \left(\left(0.5 - \log 2\right) \cdot x + \left(0.0625 - 0.16666666666666666 \cdot {\log 2}^{3}\right) \cdot {x}^{3}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{1 + x} - {2}^{x} \leq -0.02:\\ \;\;\;\;\sqrt{1 + x} - {2}^{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \left(0.5 - \log 2\right) + \left(0.0625 - 0.16666666666666666 \cdot {\log 2}^{3}\right) \cdot {x}^{3}\right) - \left(0.125 + 0.5 \cdot {\log 2}^{2}\right) \cdot {x}^{2}\\ \end{array} \]

Alternatives

Alternative 1
Error1.1
Cost59268
\[\begin{array}{l} t_0 := \sqrt{1 + x} - {2}^{x}\\ \mathbf{if}\;t_0 \leq -0.02:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(0.5 - \log 2\right) + x \cdot \left(x \cdot \mathsf{fma}\left({\log 2}^{3}, -0.16666666666666666, 0.0625\right) - \mathsf{fma}\left(0.5, {\log 2}^{2}, 0.125\right)\right)\right)\\ \end{array} \]
Alternative 2
Error1.2
Cost33348
\[\begin{array}{l} t_0 := \sqrt{1 + x} - {2}^{x}\\ \mathbf{if}\;t_0 \leq -0.02:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(0.5 - \log 2\right) - x \cdot \left(0.125 + 0.5 \cdot {\log 2}^{2}\right)\right)\\ \end{array} \]
Alternative 3
Error1.8
Cost26436
\[\begin{array}{l} t_0 := \sqrt{1 + x} - {2}^{x}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{-8}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(0.5 - \log 2\right)\\ \end{array} \]
Alternative 4
Error2.4
Cost6720
\[x \cdot \left(0.5 - \log 2\right) \]
Alternative 5
Error52.9
Cost6656
\[\log 2 \cdot \left(-x\right) \]

Error

Reproduce

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