2sqrt (example 3.1)

Percentage Accurate: 9.2% → 99.6%
Time: 17.3s
Alternatives: 6
Speedup: 2.0×

Specification

?
\[x > 1 \land x < 10^{+308}\]
\[\begin{array}{l} \\ \sqrt{x + 1} - \sqrt{x} \end{array} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
	return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sqrt{x + 1} - \sqrt{x}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 9.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{x + 1} - \sqrt{x} \end{array} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
	return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sqrt{x + 1} - \sqrt{x}
\end{array}

Alternative 1: 99.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sqrt{1 + x} + \sqrt{x}}\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (log1p (expm1 (/ 1.0 (+ (sqrt (+ 1.0 x)) (sqrt x))))))
double code(double x) {
	return log1p(expm1((1.0 / (sqrt((1.0 + x)) + sqrt(x)))));
}
public static double code(double x) {
	return Math.log1p(Math.expm1((1.0 / (Math.sqrt((1.0 + x)) + Math.sqrt(x)))));
}
def code(x):
	return math.log1p(math.expm1((1.0 / (math.sqrt((1.0 + x)) + math.sqrt(x)))))
function code(x)
	return log1p(expm1(Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + sqrt(x)))))
end
code[x_] := N[Log[1 + N[(Exp[N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sqrt{1 + x} + \sqrt{x}}\right)\right)
\end{array}
Derivation
  1. Initial program 10.1%

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. flip--12.2%

      \[\leadsto \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. div-inv12.2%

      \[\leadsto \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    3. add-sqr-sqrt13.2%

      \[\leadsto \left(\color{blue}{\left(x + 1\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    4. add-sqr-sqrt15.8%

      \[\leadsto \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    5. associate--l+15.8%

      \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right)} \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
  4. Applied egg-rr15.8%

    \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
  5. Step-by-step derivation
    1. associate-*r/15.8%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. *-rgt-identity15.8%

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

      \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}} \]
    4. associate-+l-99.7%

      \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}} \]
    5. div-sub99.7%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{x - x}{\sqrt{x + 1} + \sqrt{x}}} \]
    6. +-inverses99.7%

      \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{\color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}} \]
    7. div099.7%

      \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \color{blue}{0} \]
    8. --rgt-identity99.7%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    9. +-commutative99.7%

      \[\leadsto \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}} \]
  6. Simplified99.7%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \]
  7. Step-by-step derivation
    1. log1p-expm1-u99.7%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sqrt{1 + x} + \sqrt{x}}\right)\right)} \]
  8. Applied egg-rr99.7%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sqrt{1 + x} + \sqrt{x}}\right)\right)} \]
  9. Final simplification99.7%

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sqrt{1 + x} + \sqrt{x}}\right)\right) \]
  10. Add Preprocessing

Alternative 2: 98.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 68000000:\\ \;\;\;\;\sqrt{1 + x} - \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 68000000.0) (- (sqrt (+ 1.0 x)) (sqrt x)) (* 0.5 (pow x -0.5))))
double code(double x) {
	double tmp;
	if (x <= 68000000.0) {
		tmp = sqrt((1.0 + x)) - sqrt(x);
	} else {
		tmp = 0.5 * pow(x, -0.5);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 68000000.0d0) then
        tmp = sqrt((1.0d0 + x)) - sqrt(x)
    else
        tmp = 0.5d0 * (x ** (-0.5d0))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 68000000.0) {
		tmp = Math.sqrt((1.0 + x)) - Math.sqrt(x);
	} else {
		tmp = 0.5 * Math.pow(x, -0.5);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 68000000.0:
		tmp = math.sqrt((1.0 + x)) - math.sqrt(x)
	else:
		tmp = 0.5 * math.pow(x, -0.5)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 68000000.0)
		tmp = Float64(sqrt(Float64(1.0 + x)) - sqrt(x));
	else
		tmp = Float64(0.5 * (x ^ -0.5));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 68000000.0)
		tmp = sqrt((1.0 + x)) - sqrt(x);
	else
		tmp = 0.5 * (x ^ -0.5);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 68000000.0], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 68000000:\\
\;\;\;\;\sqrt{1 + x} - \sqrt{x}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 6.8e7

    1. Initial program 76.7%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing

    if 6.8e7 < x

    1. Initial program 6.0%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--7.7%

        \[\leadsto \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}} \]
      2. div-inv7.7%

        \[\leadsto \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
      3. add-sqr-sqrt8.6%

        \[\leadsto \left(\color{blue}{\left(x + 1\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
      4. add-sqr-sqrt10.6%

        \[\leadsto \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
      5. associate--l+10.6%

        \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right)} \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    4. Applied egg-rr10.6%

      \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    5. Step-by-step derivation
      1. associate-*r/10.6%

        \[\leadsto \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}} \]
      2. *-rgt-identity10.6%

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

        \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}} \]
      4. associate-+l-99.7%

        \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}} \]
      5. div-sub99.7%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{x - x}{\sqrt{x + 1} + \sqrt{x}}} \]
      6. +-inverses99.7%

        \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{\color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}} \]
      7. div099.7%

        \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \color{blue}{0} \]
      8. --rgt-identity99.7%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
      9. +-commutative99.7%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}} \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \]
    7. Taylor expanded in x around inf 98.7%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
    8. Step-by-step derivation
      1. rem-exp-log93.0%

        \[\leadsto 0.5 \cdot \sqrt{\frac{1}{\color{blue}{e^{\log x}}}} \]
      2. exp-neg93.0%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{e^{-\log x}}} \]
      3. unpow1/293.0%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(e^{-\log x}\right)}^{0.5}} \]
      4. exp-prod93.0%

        \[\leadsto 0.5 \cdot \color{blue}{e^{\left(-\log x\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out93.0%

        \[\leadsto 0.5 \cdot e^{\color{blue}{-\log x \cdot 0.5}} \]
      6. distribute-rgt-neg-in93.0%

        \[\leadsto 0.5 \cdot e^{\color{blue}{\log x \cdot \left(-0.5\right)}} \]
      7. metadata-eval93.0%

        \[\leadsto 0.5 \cdot e^{\log x \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow98.9%

        \[\leadsto 0.5 \cdot \color{blue}{{x}^{-0.5}} \]
    9. Simplified98.9%

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 68000000:\\ \;\;\;\;\sqrt{1 + x} - \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\sqrt{1 + x} + \sqrt{x}} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ 1.0 x)) (sqrt x))))
double code(double x) {
	return 1.0 / (sqrt((1.0 + x)) + sqrt(x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / (sqrt((1.0d0 + x)) + sqrt(x))
end function
public static double code(double x) {
	return 1.0 / (Math.sqrt((1.0 + x)) + Math.sqrt(x));
}
def code(x):
	return 1.0 / (math.sqrt((1.0 + x)) + math.sqrt(x))
function code(x)
	return Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + sqrt(x)))
end
function tmp = code(x)
	tmp = 1.0 / (sqrt((1.0 + x)) + sqrt(x));
end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\sqrt{1 + x} + \sqrt{x}}
\end{array}
Derivation
  1. Initial program 10.1%

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. flip--12.2%

      \[\leadsto \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. div-inv12.2%

      \[\leadsto \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    3. add-sqr-sqrt13.2%

      \[\leadsto \left(\color{blue}{\left(x + 1\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    4. add-sqr-sqrt15.8%

      \[\leadsto \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    5. associate--l+15.8%

      \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right)} \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
  4. Applied egg-rr15.8%

    \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
  5. Step-by-step derivation
    1. associate-*r/15.8%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. *-rgt-identity15.8%

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

      \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}} \]
    4. associate-+l-99.7%

      \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}} \]
    5. div-sub99.7%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{x - x}{\sqrt{x + 1} + \sqrt{x}}} \]
    6. +-inverses99.7%

      \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{\color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}} \]
    7. div099.7%

      \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \color{blue}{0} \]
    8. --rgt-identity99.7%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    9. +-commutative99.7%

      \[\leadsto \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}} \]
  6. Simplified99.7%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \]
  7. Final simplification99.7%

    \[\leadsto \frac{1}{\sqrt{1 + x} + \sqrt{x}} \]
  8. Add Preprocessing

Alternative 4: 96.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot {x}^{-0.5} \end{array} \]
(FPCore (x) :precision binary64 (* 0.5 (pow x -0.5)))
double code(double x) {
	return 0.5 * pow(x, -0.5);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.5d0 * (x ** (-0.5d0))
end function
public static double code(double x) {
	return 0.5 * Math.pow(x, -0.5);
}
def code(x):
	return 0.5 * math.pow(x, -0.5)
function code(x)
	return Float64(0.5 * (x ^ -0.5))
end
function tmp = code(x)
	tmp = 0.5 * (x ^ -0.5);
end
code[x_] := N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot {x}^{-0.5}
\end{array}
Derivation
  1. Initial program 10.1%

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. flip--12.2%

      \[\leadsto \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. div-inv12.2%

      \[\leadsto \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    3. add-sqr-sqrt13.2%

      \[\leadsto \left(\color{blue}{\left(x + 1\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    4. add-sqr-sqrt15.8%

      \[\leadsto \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    5. associate--l+15.8%

      \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right)} \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
  4. Applied egg-rr15.8%

    \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
  5. Step-by-step derivation
    1. associate-*r/15.8%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. *-rgt-identity15.8%

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

      \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}} \]
    4. associate-+l-99.7%

      \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}} \]
    5. div-sub99.7%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{x - x}{\sqrt{x + 1} + \sqrt{x}}} \]
    6. +-inverses99.7%

      \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \frac{\color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}} \]
    7. div099.7%

      \[\leadsto \frac{1}{\sqrt{x + 1} + \sqrt{x}} - \color{blue}{0} \]
    8. --rgt-identity99.7%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    9. +-commutative99.7%

      \[\leadsto \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}} \]
  6. Simplified99.7%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \]
  7. Taylor expanded in x around inf 95.6%

    \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
  8. Step-by-step derivation
    1. rem-exp-log90.2%

      \[\leadsto 0.5 \cdot \sqrt{\frac{1}{\color{blue}{e^{\log x}}}} \]
    2. exp-neg90.2%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{e^{-\log x}}} \]
    3. unpow1/290.2%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(e^{-\log x}\right)}^{0.5}} \]
    4. exp-prod90.2%

      \[\leadsto 0.5 \cdot \color{blue}{e^{\left(-\log x\right) \cdot 0.5}} \]
    5. distribute-lft-neg-out90.2%

      \[\leadsto 0.5 \cdot e^{\color{blue}{-\log x \cdot 0.5}} \]
    6. distribute-rgt-neg-in90.2%

      \[\leadsto 0.5 \cdot e^{\color{blue}{\log x \cdot \left(-0.5\right)}} \]
    7. metadata-eval90.2%

      \[\leadsto 0.5 \cdot e^{\log x \cdot \color{blue}{-0.5}} \]
    8. exp-to-pow95.8%

      \[\leadsto 0.5 \cdot \color{blue}{{x}^{-0.5}} \]
  9. Simplified95.8%

    \[\leadsto \color{blue}{0.5 \cdot {x}^{-0.5}} \]
  10. Final simplification95.8%

    \[\leadsto 0.5 \cdot {x}^{-0.5} \]
  11. Add Preprocessing

Alternative 5: 95.8% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \frac{0.5}{\sqrt{x}} \end{array} \]
(FPCore (x) :precision binary64 (/ 0.5 (sqrt x)))
double code(double x) {
	return 0.5 / sqrt(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.5d0 / sqrt(x)
end function
public static double code(double x) {
	return 0.5 / Math.sqrt(x);
}
def code(x):
	return 0.5 / math.sqrt(x)
function code(x)
	return Float64(0.5 / sqrt(x))
end
function tmp = code(x)
	tmp = 0.5 / sqrt(x);
end
code[x_] := N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.5}{\sqrt{x}}
\end{array}
Derivation
  1. Initial program 10.1%

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 98.0%

    \[\leadsto \color{blue}{\frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{x}}{x}} \]
  4. Taylor expanded in x around inf 95.4%

    \[\leadsto \frac{\color{blue}{0.5 \cdot \sqrt{x}}}{x} \]
  5. Step-by-step derivation
    1. *-commutative95.4%

      \[\leadsto \frac{\color{blue}{\sqrt{x} \cdot 0.5}}{x} \]
  6. Simplified95.4%

    \[\leadsto \frac{\color{blue}{\sqrt{x} \cdot 0.5}}{x} \]
  7. Step-by-step derivation
    1. add-sqr-sqrt95.3%

      \[\leadsto \frac{\sqrt{x} \cdot 0.5}{\color{blue}{\sqrt{x} \cdot \sqrt{x}}} \]
    2. times-frac95.5%

      \[\leadsto \color{blue}{\frac{\sqrt{x}}{\sqrt{x}} \cdot \frac{0.5}{\sqrt{x}}} \]
  8. Applied egg-rr95.5%

    \[\leadsto \color{blue}{\frac{\sqrt{x}}{\sqrt{x}} \cdot \frac{0.5}{\sqrt{x}}} \]
  9. Step-by-step derivation
    1. *-inverses95.5%

      \[\leadsto \color{blue}{1} \cdot \frac{0.5}{\sqrt{x}} \]
    2. *-lft-identity95.5%

      \[\leadsto \color{blue}{\frac{0.5}{\sqrt{x}}} \]
  10. Simplified95.5%

    \[\leadsto \color{blue}{\frac{0.5}{\sqrt{x}}} \]
  11. Final simplification95.5%

    \[\leadsto \frac{0.5}{\sqrt{x}} \]
  12. Add Preprocessing

Alternative 6: 6.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \sqrt{x} \end{array} \]
(FPCore (x) :precision binary64 (sqrt x))
double code(double x) {
	return sqrt(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt(x)
end function
public static double code(double x) {
	return Math.sqrt(x);
}
def code(x):
	return math.sqrt(x)
function code(x)
	return sqrt(x)
end
function tmp = code(x)
	tmp = sqrt(x);
end
code[x_] := N[Sqrt[x], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{x}
\end{array}
Derivation
  1. Initial program 10.1%

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 1.6%

    \[\leadsto \color{blue}{1 - \sqrt{x}} \]
  4. Step-by-step derivation
    1. sub-neg1.6%

      \[\leadsto \color{blue}{1 + \left(-\sqrt{x}\right)} \]
    2. rem-square-sqrt0.0%

      \[\leadsto 1 + \color{blue}{\sqrt{-\sqrt{x}} \cdot \sqrt{-\sqrt{x}}} \]
    3. fabs-sqr0.0%

      \[\leadsto 1 + \color{blue}{\left|\sqrt{-\sqrt{x}} \cdot \sqrt{-\sqrt{x}}\right|} \]
    4. rem-square-sqrt7.0%

      \[\leadsto 1 + \left|\color{blue}{-\sqrt{x}}\right| \]
    5. rem-sqrt-square7.0%

      \[\leadsto 1 + \color{blue}{\sqrt{\left(-\sqrt{x}\right) \cdot \left(-\sqrt{x}\right)}} \]
    6. sqr-neg7.0%

      \[\leadsto 1 + \sqrt{\color{blue}{\sqrt{x} \cdot \sqrt{x}}} \]
    7. rem-square-sqrt7.0%

      \[\leadsto 1 + \sqrt{\color{blue}{x}} \]
  5. Simplified7.0%

    \[\leadsto \color{blue}{1 + \sqrt{x}} \]
  6. Taylor expanded in x around inf 7.0%

    \[\leadsto \color{blue}{\sqrt{x}} \]
  7. Final simplification7.0%

    \[\leadsto \sqrt{x} \]
  8. Add Preprocessing

Developer target: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\sqrt{x + 1} + \sqrt{x}} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x))))
double code(double x) {
	return 1.0 / (sqrt((x + 1.0)) + sqrt(x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / (sqrt((x + 1.0d0)) + sqrt(x))
end function
public static double code(double x) {
	return 1.0 / (Math.sqrt((x + 1.0)) + Math.sqrt(x));
}
def code(x):
	return 1.0 / (math.sqrt((x + 1.0)) + math.sqrt(x))
function code(x)
	return Float64(1.0 / Float64(sqrt(Float64(x + 1.0)) + sqrt(x)))
end
function tmp = code(x)
	tmp = 1.0 / (sqrt((x + 1.0)) + sqrt(x));
end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\sqrt{x + 1} + \sqrt{x}}
\end{array}

Reproduce

?
herbie shell --seed 2024084 
(FPCore (x)
  :name "2sqrt (example 3.1)"
  :precision binary64
  :pre (and (> x 1.0) (< x 1e+308))

  :alt
  (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))

  (- (sqrt (+ x 1.0)) (sqrt x)))