2isqrt (example 3.6)

Percentage Accurate: 39.0% → 99.7%
Time: 10.0s
Alternatives: 7
Speedup: 2.0×

Specification

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

\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\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 7 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: 39.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t\_0} \leq 2 \cdot 10^{-23}:\\ \;\;\;\;\frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) + \left({x}^{-2.5} \cdot 0.5 - {x}^{-0.5} \cdot \frac{0.375}{x}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(1 + x\right) - x}{\sqrt{x} + t\_0}}{\sqrt{x \cdot \left(1 + x\right)}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ 1.0 x))))
   (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-23)
     (/
      (+
       (fma (pow x -2.5) -0.25 (* (pow x -0.5) 0.5))
       (- (* (pow x -2.5) 0.5) (* (pow x -0.5) (/ 0.375 x))))
      x)
     (/ (/ (- (+ 1.0 x) x) (+ (sqrt x) t_0)) (sqrt (* x (+ 1.0 x)))))))
double code(double x) {
	double t_0 = sqrt((1.0 + x));
	double tmp;
	if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-23) {
		tmp = (fma(pow(x, -2.5), -0.25, (pow(x, -0.5) * 0.5)) + ((pow(x, -2.5) * 0.5) - (pow(x, -0.5) * (0.375 / x)))) / x;
	} else {
		tmp = (((1.0 + x) - x) / (sqrt(x) + t_0)) / sqrt((x * (1.0 + x)));
	}
	return tmp;
}
function code(x)
	t_0 = sqrt(Float64(1.0 + x))
	tmp = 0.0
	if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 2e-23)
		tmp = Float64(Float64(fma((x ^ -2.5), -0.25, Float64((x ^ -0.5) * 0.5)) + Float64(Float64((x ^ -2.5) * 0.5) - Float64((x ^ -0.5) * Float64(0.375 / x)))) / x);
	else
		tmp = Float64(Float64(Float64(Float64(1.0 + x) - x) / Float64(sqrt(x) + t_0)) / sqrt(Float64(x * Float64(1.0 + x))));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 2e-23], N[(N[(N[(N[Power[x, -2.5], $MachinePrecision] * -0.25 + N[(N[Power[x, -0.5], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, -2.5], $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[Power[x, -0.5], $MachinePrecision] * N[(0.375 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(N[(1.0 + x), $MachinePrecision] - x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t\_0} \leq 2 \cdot 10^{-23}:\\
\;\;\;\;\frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) + \left({x}^{-2.5} \cdot 0.5 - {x}^{-0.5} \cdot \frac{0.375}{x}\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(1 + x\right) - x}{\sqrt{x} + t\_0}}{\sqrt{x \cdot \left(1 + x\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 1.99999999999999992e-23

    1. Initial program 36.7%

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

      \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + 0.5 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + \left(-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
    4. Taylor expanded in x around inf 99.6%

      \[\leadsto \color{blue}{\frac{\left(-1 \cdot \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x} + \left(-0.25 \cdot \sqrt{\frac{1}{{x}^{5}}} + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right) - -0.5 \cdot \sqrt{\frac{1}{{x}^{5}}}}{x}} \]
    5. Step-by-step derivation
      1. Simplified99.6%

        \[\leadsto \color{blue}{\frac{\left(\mathsf{fma}\left(\sqrt{{x}^{-5}}, -0.25, \sqrt{\frac{1}{x}} \cdot 0.5\right) - \frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x}\right) + \sqrt{{x}^{-5}} \cdot 0.5}{x}} \]
      2. Step-by-step derivation
        1. associate-+l-99.6%

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt{{x}^{-5}}, -0.25, \sqrt{\frac{1}{x}} \cdot 0.5\right) - \left(\frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}}{x} \]
        2. sqrt-pow199.6%

          \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{{x}^{\left(\frac{-5}{2}\right)}}, -0.25, \sqrt{\frac{1}{x}} \cdot 0.5\right) - \left(\frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        3. metadata-eval99.6%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{-2.5}}, -0.25, \sqrt{\frac{1}{x}} \cdot 0.5\right) - \left(\frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        4. pow1/299.6%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, \color{blue}{{\left(\frac{1}{x}\right)}^{0.5}} \cdot 0.5\right) - \left(\frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        5. inv-pow99.6%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {\color{blue}{\left({x}^{-1}\right)}}^{0.5} \cdot 0.5\right) - \left(\frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        6. pow-pow99.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, \color{blue}{{x}^{\left(-1 \cdot 0.5\right)}} \cdot 0.5\right) - \left(\frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        7. metadata-eval99.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{\color{blue}{-0.5}} \cdot 0.5\right) - \left(\frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        8. associate-/l*99.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left(\color{blue}{\sqrt{\frac{1}{x}} \cdot \frac{0.375}{x}} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        9. pow1/299.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left(\color{blue}{{\left(\frac{1}{x}\right)}^{0.5}} \cdot \frac{0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        10. inv-pow99.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left({\color{blue}{\left({x}^{-1}\right)}}^{0.5} \cdot \frac{0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        11. pow-pow99.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left(\color{blue}{{x}^{\left(-1 \cdot 0.5\right)}} \cdot \frac{0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        12. metadata-eval99.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left({x}^{\color{blue}{-0.5}} \cdot \frac{0.375}{x} - \sqrt{{x}^{-5}} \cdot 0.5\right)}{x} \]
        13. sqrt-pow199.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left({x}^{-0.5} \cdot \frac{0.375}{x} - \color{blue}{{x}^{\left(\frac{-5}{2}\right)}} \cdot 0.5\right)}{x} \]
        14. metadata-eval99.7%

          \[\leadsto \frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left({x}^{-0.5} \cdot \frac{0.375}{x} - {x}^{\color{blue}{-2.5}} \cdot 0.5\right)}{x} \]
      3. Applied egg-rr99.7%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) - \left({x}^{-0.5} \cdot \frac{0.375}{x} - {x}^{-2.5} \cdot 0.5\right)}}{x} \]

      if 1.99999999999999992e-23 < (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

      1. Initial program 60.7%

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

          \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
        2. *-rgt-identity61.6%

          \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
        3. *-un-lft-identity61.6%

          \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
        4. +-commutative61.6%

          \[\leadsto \frac{\sqrt{\color{blue}{1 + x}} - \sqrt{x}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
        5. sqrt-unprod61.6%

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

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

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \left(1 + x\right)}}} \]
      5. Step-by-step derivation
        1. flip--82.8%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\left(x + 1\right) - x}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x \cdot \left(1 + x\right)}} \]
    6. Recombined 2 regimes into one program.
    7. Final simplification99.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-23}:\\ \;\;\;\;\frac{\mathsf{fma}\left({x}^{-2.5}, -0.25, {x}^{-0.5} \cdot 0.5\right) + \left({x}^{-2.5} \cdot 0.5 - {x}^{-0.5} \cdot \frac{0.375}{x}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(1 + x\right) - x}{\sqrt{x} + \sqrt{1 + x}}}{\sqrt{x \cdot \left(1 + x\right)}}\\ \end{array} \]
    8. Add Preprocessing

    Alternative 2: 99.7% accurate, 0.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{1}{x}}\\ t_1 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t\_1} \leq 2 \cdot 10^{-23}:\\ \;\;\;\;\frac{0.5 \cdot t\_0 - \frac{0.375 \cdot t\_0}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(1 + x\right) - x}{\sqrt{x} + t\_1}}{\sqrt{x \cdot \left(1 + x\right)}}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (let* ((t_0 (sqrt (/ 1.0 x))) (t_1 (sqrt (+ 1.0 x))))
       (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_1)) 2e-23)
         (/ (- (* 0.5 t_0) (/ (* 0.375 t_0) x)) x)
         (/ (/ (- (+ 1.0 x) x) (+ (sqrt x) t_1)) (sqrt (* x (+ 1.0 x)))))))
    double code(double x) {
    	double t_0 = sqrt((1.0 / x));
    	double t_1 = sqrt((1.0 + x));
    	double tmp;
    	if (((1.0 / sqrt(x)) + (-1.0 / t_1)) <= 2e-23) {
    		tmp = ((0.5 * t_0) - ((0.375 * t_0) / x)) / x;
    	} else {
    		tmp = (((1.0 + x) - x) / (sqrt(x) + t_1)) / sqrt((x * (1.0 + x)));
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = sqrt((1.0d0 / x))
        t_1 = sqrt((1.0d0 + x))
        if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_1)) <= 2d-23) then
            tmp = ((0.5d0 * t_0) - ((0.375d0 * t_0) / x)) / x
        else
            tmp = (((1.0d0 + x) - x) / (sqrt(x) + t_1)) / sqrt((x * (1.0d0 + x)))
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double t_0 = Math.sqrt((1.0 / x));
    	double t_1 = Math.sqrt((1.0 + x));
    	double tmp;
    	if (((1.0 / Math.sqrt(x)) + (-1.0 / t_1)) <= 2e-23) {
    		tmp = ((0.5 * t_0) - ((0.375 * t_0) / x)) / x;
    	} else {
    		tmp = (((1.0 + x) - x) / (Math.sqrt(x) + t_1)) / Math.sqrt((x * (1.0 + x)));
    	}
    	return tmp;
    }
    
    def code(x):
    	t_0 = math.sqrt((1.0 / x))
    	t_1 = math.sqrt((1.0 + x))
    	tmp = 0
    	if ((1.0 / math.sqrt(x)) + (-1.0 / t_1)) <= 2e-23:
    		tmp = ((0.5 * t_0) - ((0.375 * t_0) / x)) / x
    	else:
    		tmp = (((1.0 + x) - x) / (math.sqrt(x) + t_1)) / math.sqrt((x * (1.0 + x)))
    	return tmp
    
    function code(x)
    	t_0 = sqrt(Float64(1.0 / x))
    	t_1 = sqrt(Float64(1.0 + x))
    	tmp = 0.0
    	if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_1)) <= 2e-23)
    		tmp = Float64(Float64(Float64(0.5 * t_0) - Float64(Float64(0.375 * t_0) / x)) / x);
    	else
    		tmp = Float64(Float64(Float64(Float64(1.0 + x) - x) / Float64(sqrt(x) + t_1)) / sqrt(Float64(x * Float64(1.0 + x))));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	t_0 = sqrt((1.0 / x));
    	t_1 = sqrt((1.0 + x));
    	tmp = 0.0;
    	if (((1.0 / sqrt(x)) + (-1.0 / t_1)) <= 2e-23)
    		tmp = ((0.5 * t_0) - ((0.375 * t_0) / x)) / x;
    	else
    		tmp = (((1.0 + x) - x) / (sqrt(x) + t_1)) / sqrt((x * (1.0 + x)));
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$1), $MachinePrecision]), $MachinePrecision], 2e-23], N[(N[(N[(0.5 * t$95$0), $MachinePrecision] - N[(N[(0.375 * t$95$0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(N[(1.0 + x), $MachinePrecision] - x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sqrt{\frac{1}{x}}\\
    t_1 := \sqrt{1 + x}\\
    \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t\_1} \leq 2 \cdot 10^{-23}:\\
    \;\;\;\;\frac{0.5 \cdot t\_0 - \frac{0.375 \cdot t\_0}{x}}{x}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{\frac{\left(1 + x\right) - x}{\sqrt{x} + t\_1}}{\sqrt{x \cdot \left(1 + x\right)}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 1.99999999999999992e-23

      1. Initial program 36.7%

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

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + 0.5 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + \left(-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
      4. Taylor expanded in x around inf 99.6%

        \[\leadsto \color{blue}{\frac{-1 \cdot \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}} \]
      5. Step-by-step derivation
        1. +-commutative99.6%

          \[\leadsto \frac{\color{blue}{0.5 \cdot \sqrt{\frac{1}{x}} + -1 \cdot \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}}}{x} \]
        2. mul-1-neg99.6%

          \[\leadsto \frac{0.5 \cdot \sqrt{\frac{1}{x}} + \color{blue}{\left(-\frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}\right)}}{x} \]
        3. unsub-neg99.6%

          \[\leadsto \frac{\color{blue}{0.5 \cdot \sqrt{\frac{1}{x}} - \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}}}{x} \]
        4. *-commutative99.6%

          \[\leadsto \frac{\color{blue}{\sqrt{\frac{1}{x}} \cdot 0.5} - \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}}{x} \]
        5. distribute-rgt-out99.6%

          \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\color{blue}{\sqrt{\frac{1}{x}} \cdot \left(-0.125 + 0.5\right)}}{x}}{x} \]
        6. metadata-eval99.6%

          \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
      6. Simplified99.6%

        \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x}}{x}} \]

      if 1.99999999999999992e-23 < (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

      1. Initial program 60.7%

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

          \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
        2. *-rgt-identity61.6%

          \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \color{blue}{\sqrt{x}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
        3. *-un-lft-identity61.6%

          \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
        4. +-commutative61.6%

          \[\leadsto \frac{\sqrt{\color{blue}{1 + x}} - \sqrt{x}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
        5. sqrt-unprod61.6%

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

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

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x \cdot \left(1 + x\right)}}} \]
      5. Step-by-step derivation
        1. flip--82.8%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\left(x + 1\right) - x}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x \cdot \left(1 + x\right)}} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification99.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-23}:\\ \;\;\;\;\frac{0.5 \cdot \sqrt{\frac{1}{x}} - \frac{0.375 \cdot \sqrt{\frac{1}{x}}}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(1 + x\right) - x}{\sqrt{x} + \sqrt{1 + x}}}{\sqrt{x \cdot \left(1 + x\right)}}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 3: 98.7% accurate, 0.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-13}:\\ \;\;\;\;\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{x}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-13)
       (/ (* 0.5 (sqrt (/ 1.0 x))) x)
       (- (pow x -0.5) (pow (+ 1.0 x) -0.5))))
    double code(double x) {
    	double tmp;
    	if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-13) {
    		tmp = (0.5 * sqrt((1.0 / x))) / x;
    	} else {
    		tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: tmp
        if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 2d-13) then
            tmp = (0.5d0 * sqrt((1.0d0 / x))) / x
        else
            tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 2e-13) {
    		tmp = (0.5 * Math.sqrt((1.0 / x))) / x;
    	} else {
    		tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 2e-13:
    		tmp = (0.5 * math.sqrt((1.0 / x))) / x
    	else:
    		tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5)
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 2e-13)
    		tmp = Float64(Float64(0.5 * sqrt(Float64(1.0 / x))) / x);
    	else
    		tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-13)
    		tmp = (0.5 * sqrt((1.0 / x))) / x;
    	else
    		tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-13], N[(N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-13}:\\
    \;\;\;\;\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{x}\\
    
    \mathbf{else}:\\
    \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 2.0000000000000001e-13

      1. Initial program 36.7%

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

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + 0.5 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + \left(-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
      4. Taylor expanded in x around inf 99.6%

        \[\leadsto \color{blue}{\frac{\left(-1 \cdot \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x} + \left(-0.25 \cdot \sqrt{\frac{1}{{x}^{5}}} + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right) - -0.5 \cdot \sqrt{\frac{1}{{x}^{5}}}}{x}} \]
      5. Step-by-step derivation
        1. Simplified99.6%

          \[\leadsto \color{blue}{\frac{\left(\mathsf{fma}\left(\sqrt{{x}^{-5}}, -0.25, \sqrt{\frac{1}{x}} \cdot 0.5\right) - \frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x}\right) + \sqrt{{x}^{-5}} \cdot 0.5}{x}} \]
        2. Taylor expanded in x around inf 98.9%

          \[\leadsto \frac{\color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}}}{x} \]

        if 2.0000000000000001e-13 < (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

        1. Initial program 81.4%

          \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. sub-neg81.4%

            \[\leadsto \color{blue}{\frac{1}{\sqrt{x}} + \left(-\frac{1}{\sqrt{x + 1}}\right)} \]
          2. inv-pow81.4%

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

            \[\leadsto \color{blue}{{x}^{\left(\frac{-1}{2}\right)}} + \left(-\frac{1}{\sqrt{x + 1}}\right) \]
          4. metadata-eval81.0%

            \[\leadsto {x}^{\color{blue}{-0.5}} + \left(-\frac{1}{\sqrt{x + 1}}\right) \]
          5. distribute-neg-frac81.0%

            \[\leadsto {x}^{-0.5} + \color{blue}{\frac{-1}{\sqrt{x + 1}}} \]
          6. metadata-eval81.0%

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

            \[\leadsto {x}^{-0.5} + \frac{-1}{\sqrt{\color{blue}{1 + x}}} \]
        4. Applied egg-rr81.0%

          \[\leadsto \color{blue}{{x}^{-0.5} + \frac{-1}{\sqrt{1 + x}}} \]
        5. Step-by-step derivation
          1. *-rgt-identity81.0%

            \[\leadsto {x}^{-0.5} + \color{blue}{\frac{-1}{\sqrt{1 + x}} \cdot 1} \]
          2. cancel-sign-sub81.0%

            \[\leadsto \color{blue}{{x}^{-0.5} - \left(-\frac{-1}{\sqrt{1 + x}}\right) \cdot 1} \]
          3. distribute-lft-neg-in81.0%

            \[\leadsto {x}^{-0.5} - \color{blue}{\left(-\frac{-1}{\sqrt{1 + x}} \cdot 1\right)} \]
          4. *-rgt-identity81.0%

            \[\leadsto {x}^{-0.5} - \left(-\color{blue}{\frac{-1}{\sqrt{1 + x}}}\right) \]
          5. distribute-neg-frac81.0%

            \[\leadsto {x}^{-0.5} - \color{blue}{\frac{--1}{\sqrt{1 + x}}} \]
          6. metadata-eval81.0%

            \[\leadsto {x}^{-0.5} - \frac{\color{blue}{1}}{\sqrt{1 + x}} \]
          7. unpow1/281.0%

            \[\leadsto {x}^{-0.5} - \frac{1}{\color{blue}{{\left(1 + x\right)}^{0.5}}} \]
          8. exp-to-pow77.9%

            \[\leadsto {x}^{-0.5} - \frac{1}{\color{blue}{e^{\log \left(1 + x\right) \cdot 0.5}}} \]
          9. log1p-undefine77.9%

            \[\leadsto {x}^{-0.5} - \frac{1}{e^{\color{blue}{\mathsf{log1p}\left(x\right)} \cdot 0.5}} \]
          10. *-commutative77.9%

            \[\leadsto {x}^{-0.5} - \frac{1}{e^{\color{blue}{0.5 \cdot \mathsf{log1p}\left(x\right)}}} \]
          11. exp-neg79.1%

            \[\leadsto {x}^{-0.5} - \color{blue}{e^{-0.5 \cdot \mathsf{log1p}\left(x\right)}} \]
          12. *-commutative79.1%

            \[\leadsto {x}^{-0.5} - e^{-\color{blue}{\mathsf{log1p}\left(x\right) \cdot 0.5}} \]
          13. distribute-rgt-neg-in79.1%

            \[\leadsto {x}^{-0.5} - e^{\color{blue}{\mathsf{log1p}\left(x\right) \cdot \left(-0.5\right)}} \]
          14. log1p-undefine79.1%

            \[\leadsto {x}^{-0.5} - e^{\color{blue}{\log \left(1 + x\right)} \cdot \left(-0.5\right)} \]
          15. metadata-eval79.1%

            \[\leadsto {x}^{-0.5} - e^{\log \left(1 + x\right) \cdot \color{blue}{-0.5}} \]
          16. exp-to-pow82.0%

            \[\leadsto {x}^{-0.5} - \color{blue}{{\left(1 + x\right)}^{-0.5}} \]
        6. Simplified82.0%

          \[\leadsto \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}} \]
      6. Recombined 2 regimes into one program.
      7. Final simplification98.1%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-13}:\\ \;\;\;\;\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{x}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
      8. Add Preprocessing

      Alternative 4: 98.5% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{1}{x}}\\ \frac{0.5 \cdot t\_0 - \frac{0.375 \cdot t\_0}{x}}{x} \end{array} \end{array} \]
      (FPCore (x)
       :precision binary64
       (let* ((t_0 (sqrt (/ 1.0 x)))) (/ (- (* 0.5 t_0) (/ (* 0.375 t_0) x)) x)))
      double code(double x) {
      	double t_0 = sqrt((1.0 / x));
      	return ((0.5 * t_0) - ((0.375 * t_0) / x)) / x;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          real(8) :: t_0
          t_0 = sqrt((1.0d0 / x))
          code = ((0.5d0 * t_0) - ((0.375d0 * t_0) / x)) / x
      end function
      
      public static double code(double x) {
      	double t_0 = Math.sqrt((1.0 / x));
      	return ((0.5 * t_0) - ((0.375 * t_0) / x)) / x;
      }
      
      def code(x):
      	t_0 = math.sqrt((1.0 / x))
      	return ((0.5 * t_0) - ((0.375 * t_0) / x)) / x
      
      function code(x)
      	t_0 = sqrt(Float64(1.0 / x))
      	return Float64(Float64(Float64(0.5 * t_0) - Float64(Float64(0.375 * t_0) / x)) / x)
      end
      
      function tmp = code(x)
      	t_0 = sqrt((1.0 / x));
      	tmp = ((0.5 * t_0) - ((0.375 * t_0) / x)) / x;
      end
      
      code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(0.5 * t$95$0), $MachinePrecision] - N[(N[(0.375 * t$95$0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \sqrt{\frac{1}{x}}\\
      \frac{0.5 \cdot t\_0 - \frac{0.375 \cdot t\_0}{x}}{x}
      \end{array}
      \end{array}
      
      Derivation
      1. Initial program 38.6%

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

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + 0.5 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + \left(-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
      4. Taylor expanded in x around inf 97.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}} \]
      5. Step-by-step derivation
        1. +-commutative97.8%

          \[\leadsto \frac{\color{blue}{0.5 \cdot \sqrt{\frac{1}{x}} + -1 \cdot \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}}}{x} \]
        2. mul-1-neg97.8%

          \[\leadsto \frac{0.5 \cdot \sqrt{\frac{1}{x}} + \color{blue}{\left(-\frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}\right)}}{x} \]
        3. unsub-neg97.8%

          \[\leadsto \frac{\color{blue}{0.5 \cdot \sqrt{\frac{1}{x}} - \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}}}{x} \]
        4. *-commutative97.8%

          \[\leadsto \frac{\color{blue}{\sqrt{\frac{1}{x}} \cdot 0.5} - \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}}{x} \]
        5. distribute-rgt-out97.8%

          \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\color{blue}{\sqrt{\frac{1}{x}} \cdot \left(-0.125 + 0.5\right)}}{x}}{x} \]
        6. metadata-eval97.8%

          \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
      6. Simplified97.8%

        \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x}}{x}} \]
      7. Final simplification97.8%

        \[\leadsto \frac{0.5 \cdot \sqrt{\frac{1}{x}} - \frac{0.375 \cdot \sqrt{\frac{1}{x}}}{x}}{x} \]
      8. Add Preprocessing

      Alternative 5: 37.2% accurate, 2.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 8.5 \cdot 10^{+122}:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
      (FPCore (x) :precision binary64 (if (<= x 8.5e+122) (pow x -0.5) 0.0))
      double code(double x) {
      	double tmp;
      	if (x <= 8.5e+122) {
      		tmp = pow(x, -0.5);
      	} else {
      		tmp = 0.0;
      	}
      	return tmp;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          real(8) :: tmp
          if (x <= 8.5d+122) then
              tmp = x ** (-0.5d0)
          else
              tmp = 0.0d0
          end if
          code = tmp
      end function
      
      public static double code(double x) {
      	double tmp;
      	if (x <= 8.5e+122) {
      		tmp = Math.pow(x, -0.5);
      	} else {
      		tmp = 0.0;
      	}
      	return tmp;
      }
      
      def code(x):
      	tmp = 0
      	if x <= 8.5e+122:
      		tmp = math.pow(x, -0.5)
      	else:
      		tmp = 0.0
      	return tmp
      
      function code(x)
      	tmp = 0.0
      	if (x <= 8.5e+122)
      		tmp = x ^ -0.5;
      	else
      		tmp = 0.0;
      	end
      	return tmp
      end
      
      function tmp_2 = code(x)
      	tmp = 0.0;
      	if (x <= 8.5e+122)
      		tmp = x ^ -0.5;
      	else
      		tmp = 0.0;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_] := If[LessEqual[x, 8.5e+122], N[Power[x, -0.5], $MachinePrecision], 0.0]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq 8.5 \cdot 10^{+122}:\\
      \;\;\;\;{x}^{-0.5}\\
      
      \mathbf{else}:\\
      \;\;\;\;0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < 8.50000000000000003e122

        1. Initial program 15.8%

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

          \[\leadsto \color{blue}{\sqrt{\frac{1}{x}}} \]
        4. Step-by-step derivation
          1. pow1/27.9%

            \[\leadsto \color{blue}{{\left(\frac{1}{x}\right)}^{0.5}} \]
          2. inv-pow7.9%

            \[\leadsto {\color{blue}{\left({x}^{-1}\right)}}^{0.5} \]
          3. pow-pow7.9%

            \[\leadsto \color{blue}{{x}^{\left(-1 \cdot 0.5\right)}} \]
          4. metadata-eval7.9%

            \[\leadsto {x}^{\color{blue}{-0.5}} \]
          5. *-un-lft-identity7.9%

            \[\leadsto \color{blue}{1 \cdot {x}^{-0.5}} \]
        5. Applied egg-rr7.9%

          \[\leadsto \color{blue}{1 \cdot {x}^{-0.5}} \]
        6. Step-by-step derivation
          1. *-lft-identity7.9%

            \[\leadsto \color{blue}{{x}^{-0.5}} \]
        7. Simplified7.9%

          \[\leadsto \color{blue}{{x}^{-0.5}} \]

        if 8.50000000000000003e122 < x

        1. Initial program 54.0%

          \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
        2. Add Preprocessing
        3. Applied egg-rr4.5%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{x} - \frac{1}{1 + x}, \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}, \mathsf{fma}\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}, \sqrt[3]{\frac{1}{1 + x}}, {\left(1 + x\right)}^{-0.5}\right)\right)} \]
        4. Step-by-step derivation
          1. fma-undefine4.5%

            \[\leadsto \color{blue}{\left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} + \mathsf{fma}\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}, \sqrt[3]{\frac{1}{1 + x}}, {\left(1 + x\right)}^{-0.5}\right)} \]
          2. +-commutative4.5%

            \[\leadsto \color{blue}{\mathsf{fma}\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}, \sqrt[3]{\frac{1}{1 + x}}, {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
          3. fma-undefine19.0%

            \[\leadsto \color{blue}{\left(\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right) \cdot \sqrt[3]{\frac{1}{1 + x}} + {\left(1 + x\right)}^{-0.5}\right)} + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          4. distribute-lft-neg-out19.0%

            \[\leadsto \left(\color{blue}{\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{\frac{1}{1 + x}}\right)} + {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          5. *-commutative19.0%

            \[\leadsto \left(\left(-\color{blue}{\sqrt[3]{\frac{1}{1 + x}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}}\right) + {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          6. distribute-lft-neg-out19.0%

            \[\leadsto \left(\color{blue}{\left(-\sqrt[3]{\frac{1}{1 + x}}\right) \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}} + {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          7. fma-undefine4.5%

            \[\leadsto \color{blue}{\mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right)} + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          8. associate-*r/4.5%

            \[\leadsto \mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{\frac{\left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot 1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
          9. *-rgt-identity4.5%

            \[\leadsto \mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right) + \frac{\color{blue}{\frac{1}{x} - \frac{1}{1 + x}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
        5. Simplified4.5%

          \[\leadsto \color{blue}{\mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right) + \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
        6. Taylor expanded in x around inf 54.0%

          \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} + -1 \cdot \sqrt{\frac{1}{x}}} \]
        7. Step-by-step derivation
          1. distribute-rgt1-in54.0%

            \[\leadsto \color{blue}{\left(-1 + 1\right) \cdot \sqrt{\frac{1}{x}}} \]
          2. metadata-eval54.0%

            \[\leadsto \color{blue}{0} \cdot \sqrt{\frac{1}{x}} \]
          3. mul0-lft54.0%

            \[\leadsto \color{blue}{0} \]
        8. Simplified54.0%

          \[\leadsto \color{blue}{0} \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 6: 97.4% accurate, 2.0× speedup?

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

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

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + 0.5 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + \left(-0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
      4. Taylor expanded in x around inf 98.0%

        \[\leadsto \color{blue}{\frac{\left(-1 \cdot \frac{-0.125 \cdot \sqrt{\frac{1}{x}} + 0.5 \cdot \sqrt{\frac{1}{x}}}{x} + \left(-0.25 \cdot \sqrt{\frac{1}{{x}^{5}}} + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right) - -0.5 \cdot \sqrt{\frac{1}{{x}^{5}}}}{x}} \]
      5. Step-by-step derivation
        1. Simplified98.0%

          \[\leadsto \color{blue}{\frac{\left(\mathsf{fma}\left(\sqrt{{x}^{-5}}, -0.25, \sqrt{\frac{1}{x}} \cdot 0.5\right) - \frac{\sqrt{\frac{1}{x}} \cdot 0.375}{x}\right) + \sqrt{{x}^{-5}} \cdot 0.5}{x}} \]
        2. Taylor expanded in x around inf 96.3%

          \[\leadsto \frac{\color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}}}{x} \]
        3. Add Preprocessing

        Alternative 7: 35.8% accurate, 209.0× speedup?

        \[\begin{array}{l} \\ 0 \end{array} \]
        (FPCore (x) :precision binary64 0.0)
        double code(double x) {
        	return 0.0;
        }
        
        real(8) function code(x)
            real(8), intent (in) :: x
            code = 0.0d0
        end function
        
        public static double code(double x) {
        	return 0.0;
        }
        
        def code(x):
        	return 0.0
        
        function code(x)
        	return 0.0
        end
        
        function tmp = code(x)
        	tmp = 0.0;
        end
        
        code[x_] := 0.0
        
        \begin{array}{l}
        
        \\
        0
        \end{array}
        
        Derivation
        1. Initial program 38.6%

          \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
        2. Add Preprocessing
        3. Applied egg-rr9.8%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{x} - \frac{1}{1 + x}, \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}, \mathsf{fma}\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}, \sqrt[3]{\frac{1}{1 + x}}, {\left(1 + x\right)}^{-0.5}\right)\right)} \]
        4. Step-by-step derivation
          1. fma-undefine9.8%

            \[\leadsto \color{blue}{\left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} + \mathsf{fma}\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}, \sqrt[3]{\frac{1}{1 + x}}, {\left(1 + x\right)}^{-0.5}\right)} \]
          2. +-commutative9.8%

            \[\leadsto \color{blue}{\mathsf{fma}\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}, \sqrt[3]{\frac{1}{1 + x}}, {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
          3. fma-undefine18.3%

            \[\leadsto \color{blue}{\left(\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right) \cdot \sqrt[3]{\frac{1}{1 + x}} + {\left(1 + x\right)}^{-0.5}\right)} + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          4. distribute-lft-neg-out18.3%

            \[\leadsto \left(\color{blue}{\left(-\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{\frac{1}{1 + x}}\right)} + {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          5. *-commutative18.3%

            \[\leadsto \left(\left(-\color{blue}{\sqrt[3]{\frac{1}{1 + x}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}}\right) + {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          6. distribute-lft-neg-out18.3%

            \[\leadsto \left(\color{blue}{\left(-\sqrt[3]{\frac{1}{1 + x}}\right) \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}} + {\left(1 + x\right)}^{-0.5}\right) + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          7. fma-undefine9.8%

            \[\leadsto \color{blue}{\mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right)} + \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
          8. associate-*r/9.8%

            \[\leadsto \mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{\frac{\left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot 1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
          9. *-rgt-identity9.8%

            \[\leadsto \mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right) + \frac{\color{blue}{\frac{1}{x} - \frac{1}{1 + x}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
        5. Simplified9.8%

          \[\leadsto \color{blue}{\mathsf{fma}\left(-\sqrt[3]{\frac{1}{1 + x}}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {\left(1 + x\right)}^{-0.5}\right) + \frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
        6. Taylor expanded in x around inf 33.8%

          \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} + -1 \cdot \sqrt{\frac{1}{x}}} \]
        7. Step-by-step derivation
          1. distribute-rgt1-in33.8%

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

            \[\leadsto \color{blue}{0} \cdot \sqrt{\frac{1}{x}} \]
          3. mul0-lft33.8%

            \[\leadsto \color{blue}{0} \]
        8. Simplified33.8%

          \[\leadsto \color{blue}{0} \]
        9. Add Preprocessing

        Developer Target 1: 98.3% accurate, 1.0× speedup?

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

        Reproduce

        ?
        herbie shell --seed 2024136 
        (FPCore (x)
          :name "2isqrt (example 3.6)"
          :precision binary64
          :pre (and (> x 1.0) (< x 1e+308))
        
          :alt
          (! :herbie-platform default (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1))))))
        
          (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))