2isqrt (example 3.6)

Percentage Accurate: 69.0% → 99.7%
Time: 12.2s
Alternatives: 9
Speedup: 2.0×

Specification

?
\[\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 9 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: 69.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 0:\\ \;\;\;\;{x}^{-1.5} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{\sqrt{\mathsf{fma}\left(x, x, 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)) 0.0)
     (* (pow x -1.5) 0.5)
     (/ (/ 1.0 (+ (sqrt x) t_0)) (sqrt (fma x x x))))))
double code(double x) {
	double t_0 = sqrt((1.0 + x));
	double tmp;
	if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 0.0) {
		tmp = pow(x, -1.5) * 0.5;
	} else {
		tmp = (1.0 / (sqrt(x) + t_0)) / sqrt(fma(x, x, 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)) <= 0.0)
		tmp = Float64((x ^ -1.5) * 0.5);
	else
		tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / sqrt(fma(x, x, 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], 0.0], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * x + x), $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 0:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{\sqrt{\mathsf{fma}\left(x, x, x\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0

    1. Initial program 38.4%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. flip--38.4%

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}} \]
      2. clear-num38.4%

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}}}} \]
      6. pow1/238.4%

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{{x}^{\left(-0.5\right)}} - \frac{1}{\sqrt{x + 1}}}} \]
      8. metadata-eval27.0%

        \[\leadsto \frac{1}{\frac{1}{{x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}}} \]
      9. pow1/227.0%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}}} \]
      10. pow-flip38.4%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}}} \]
      11. +-commutative38.4%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}}} \]
      12. metadata-eval38.4%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}}} \]
    3. Applied egg-rr38.4%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}}} \]
    4. Taylor expanded in x around inf 65.4%

      \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{{x}^{3}}}} \]
    5. Step-by-step derivation
      1. div-inv65.4%

        \[\leadsto \color{blue}{1 \cdot \frac{1}{2 \cdot \sqrt{{x}^{3}}}} \]
      2. associate-/r*65.4%

        \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{2}}{\sqrt{{x}^{3}}}} \]
      3. metadata-eval65.4%

        \[\leadsto 1 \cdot \frac{\color{blue}{0.5}}{\sqrt{{x}^{3}}} \]
      4. sqrt-pow197.7%

        \[\leadsto 1 \cdot \frac{0.5}{\color{blue}{{x}^{\left(\frac{3}{2}\right)}}} \]
      5. metadata-eval97.7%

        \[\leadsto 1 \cdot \frac{0.5}{{x}^{\color{blue}{1.5}}} \]
    6. Applied egg-rr97.7%

      \[\leadsto \color{blue}{1 \cdot \frac{0.5}{{x}^{1.5}}} \]
    7. Step-by-step derivation
      1. *-lft-identity97.7%

        \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    8. Simplified97.7%

      \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    9. Step-by-step derivation
      1. div-inv97.7%

        \[\leadsto \color{blue}{0.5 \cdot \frac{1}{{x}^{1.5}}} \]
      2. *-commutative97.7%

        \[\leadsto \color{blue}{\frac{1}{{x}^{1.5}} \cdot 0.5} \]
      3. pow-flip100.0%

        \[\leadsto \color{blue}{{x}^{\left(-1.5\right)}} \cdot 0.5 \]
      4. metadata-eval100.0%

        \[\leadsto {x}^{\color{blue}{-1.5}} \cdot 0.5 \]
    10. Applied egg-rr100.0%

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

    if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1))))

    1. Initial program 97.5%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. frac-sub97.5%

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

        \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      3. *-rgt-identity97.5%

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

        \[\leadsto \frac{\color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      5. associate-/l/97.9%

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

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

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

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

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

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

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

        \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{\color{blue}{1 \cdot x + x \cdot x}} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)} \]
      13. *-un-lft-identity99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{1 + \left(x - x\right)}{\sqrt{x + {x}^{2}} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}} \]
    4. Step-by-step derivation
      1. +-inverses99.6%

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(\sqrt{x} + \sqrt{1 + x}\right) \cdot \sqrt{x + {x}^{2}}}} \]
      4. associate-/r*99.6%

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\sqrt{x + {x}^{2}}}} \]
      5. +-commutative99.6%

        \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{1 + x} + \sqrt{x}}}}{\sqrt{x + {x}^{2}}} \]
      6. +-commutative99.6%

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

        \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{\color{blue}{x \cdot x} + x}} \]
      8. fma-def99.6%

        \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{\color{blue}{\mathsf{fma}\left(x, x, x\right)}}} \]
    5. Simplified99.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}} \leq 0:\\ \;\;\;\;{x}^{-1.5} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\sqrt{\mathsf{fma}\left(x, x, x\right)}}\\ \end{array} \]

Alternative 2: 99.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 10^{-6}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + \left(0.5 - \frac{0.125}{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ 1.0 x))))
   (if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 t_0)) 1e-6)
     (/ (/ 1.0 (+ (sqrt x) t_0)) (+ x (- 0.5 (/ 0.125 x))))
     (- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
	double t_0 = sqrt((1.0 + x));
	double tmp;
	if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 1e-6) {
		tmp = (1.0 / (sqrt(x) + t_0)) / (x + (0.5 - (0.125 / 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) :: t_0
    real(8) :: tmp
    t_0 = sqrt((1.0d0 + x))
    if (((1.0d0 / sqrt(x)) - (1.0d0 / t_0)) <= 1d-6) then
        tmp = (1.0d0 / (sqrt(x) + t_0)) / (x + (0.5d0 - (0.125d0 / x)))
    else
        tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = Math.sqrt((1.0 + x));
	double tmp;
	if (((1.0 / Math.sqrt(x)) - (1.0 / t_0)) <= 1e-6) {
		tmp = (1.0 / (Math.sqrt(x) + t_0)) / (x + (0.5 - (0.125 / x)));
	} else {
		tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
	}
	return tmp;
}
def code(x):
	t_0 = math.sqrt((1.0 + x))
	tmp = 0
	if ((1.0 / math.sqrt(x)) - (1.0 / t_0)) <= 1e-6:
		tmp = (1.0 / (math.sqrt(x) + t_0)) / (x + (0.5 - (0.125 / x)))
	else:
		tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5)
	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)) <= 1e-6)
		tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / Float64(x + Float64(0.5 - Float64(0.125 / x))));
	else
		tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5));
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = sqrt((1.0 + x));
	tmp = 0.0;
	if (((1.0 / sqrt(x)) - (1.0 / t_0)) <= 1e-6)
		tmp = (1.0 / (sqrt(x) + t_0)) / (x + (0.5 - (0.125 / x)));
	else
		tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5);
	end
	tmp_2 = 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], 1e-6], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x + N[(0.5 - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{t_0} \leq 10^{-6}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + \left(0.5 - \frac{0.125}{x}\right)}\\

\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 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 9.99999999999999955e-7

    1. Initial program 39.0%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. frac-sub39.0%

        \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
      2. *-un-lft-identity39.0%

        \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      3. *-rgt-identity39.0%

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

        \[\leadsto \frac{\color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      5. associate-/l/39.6%

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

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

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

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

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

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

        \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{x \cdot \color{blue}{\left(1 + x\right)}} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)} \]
      12. distribute-rgt-in84.4%

        \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{\color{blue}{1 \cdot x + x \cdot x}} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)} \]
      13. *-un-lft-identity84.4%

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

        \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{x + \color{blue}{{x}^{2}}} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)} \]
      15. +-commutative84.4%

        \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{x + {x}^{2}} \cdot \color{blue}{\left(\sqrt{x} + \sqrt{x + 1}\right)}} \]
      16. +-commutative84.4%

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

      \[\leadsto \color{blue}{\frac{1 + \left(x - x\right)}{\sqrt{x + {x}^{2}} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}} \]
    4. Step-by-step derivation
      1. +-inverses84.4%

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(\sqrt{x} + \sqrt{1 + x}\right) \cdot \sqrt{x + {x}^{2}}}} \]
      4. associate-/r*84.3%

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\sqrt{x + {x}^{2}}}} \]
      5. +-commutative84.3%

        \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{1 + x} + \sqrt{x}}}}{\sqrt{x + {x}^{2}}} \]
      6. +-commutative84.3%

        \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{\color{blue}{{x}^{2} + x}}} \]
      7. unpow284.3%

        \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{\color{blue}{x \cdot x} + x}} \]
      8. fma-def84.3%

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

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

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

        \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\color{blue}{\left(x + 0.5\right)} - 0.125 \cdot \frac{1}{x}} \]
      2. associate--l+99.5%

        \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\color{blue}{x + \left(0.5 - 0.125 \cdot \frac{1}{x}\right)}} \]
      3. associate-*r/99.5%

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

        \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{x + \left(0.5 - \frac{\color{blue}{0.125}}{x}\right)} \]
    8. Simplified99.5%

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

    if 9.99999999999999955e-7 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1))))

    1. Initial program 99.7%

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

        \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)\right)} \]
      2. expm1-udef99.6%

        \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)} - 1\right)} \]
      3. associate--r-99.6%

        \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{x}} - e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)}\right) + 1} \]
      4. pow1/299.7%

        \[\leadsto \left(\frac{1}{\color{blue}{{x}^{0.5}}} - e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)}\right) + 1 \]
      5. pow-flip100.0%

        \[\leadsto \left(\color{blue}{{x}^{\left(-0.5\right)}} - e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)}\right) + 1 \]
      6. metadata-eval100.0%

        \[\leadsto \left({x}^{\color{blue}{-0.5}} - e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)}\right) + 1 \]
      7. pow1/2100.0%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left(\frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}\right)}\right) + 1 \]
      8. pow-flip100.0%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left(\color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}\right)}\right) + 1 \]
      9. +-commutative100.0%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left({\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}\right)}\right) + 1 \]
      10. metadata-eval100.0%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left({\left(1 + x\right)}^{\color{blue}{-0.5}}\right)}\right) + 1 \]
    3. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left({x}^{-0.5} - e^{\mathsf{log1p}\left({\left(1 + x\right)}^{-0.5}\right)}\right) + 1} \]
    4. Step-by-step derivation
      1. associate-+l-100.0%

        \[\leadsto \color{blue}{{x}^{-0.5} - \left(e^{\mathsf{log1p}\left({\left(1 + x\right)}^{-0.5}\right)} - 1\right)} \]
      2. expm1-def100.0%

        \[\leadsto {x}^{-0.5} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(1 + x\right)}^{-0.5}\right)\right)} \]
      3. expm1-log1p100.0%

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

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

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

Alternative 3: 99.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}} \leq 10^{-20}:\\ \;\;\;\;{x}^{-1.5} \cdot 0.5\\ \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)))) 1e-20)
   (* (pow x -1.5) 0.5)
   (- (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)))) <= 1e-20) {
		tmp = pow(x, -1.5) * 0.5;
	} 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)))) <= 1d-20) then
        tmp = (x ** (-1.5d0)) * 0.5d0
    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)))) <= 1e-20) {
		tmp = Math.pow(x, -1.5) * 0.5;
	} 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)))) <= 1e-20:
		tmp = math.pow(x, -1.5) * 0.5
	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)))) <= 1e-20)
		tmp = Float64((x ^ -1.5) * 0.5);
	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)))) <= 1e-20)
		tmp = (x ^ -1.5) * 0.5;
	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], 1e-20], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $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 10^{-20}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\

\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 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 9.99999999999999945e-21

    1. Initial program 38.1%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. flip--38.1%

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}}}} \]
      6. pow1/238.1%

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{{x}^{\left(-0.5\right)}} - \frac{1}{\sqrt{x + 1}}}} \]
      8. metadata-eval27.0%

        \[\leadsto \frac{1}{\frac{1}{{x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}}} \]
      9. pow1/227.0%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}}} \]
      10. pow-flip38.2%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}}} \]
      11. +-commutative38.2%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}}} \]
      12. metadata-eval38.2%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}}} \]
    3. Applied egg-rr38.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}}} \]
    4. Taylor expanded in x around inf 66.1%

      \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{{x}^{3}}}} \]
    5. Step-by-step derivation
      1. div-inv66.1%

        \[\leadsto \color{blue}{1 \cdot \frac{1}{2 \cdot \sqrt{{x}^{3}}}} \]
      2. associate-/r*66.1%

        \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{2}}{\sqrt{{x}^{3}}}} \]
      3. metadata-eval66.1%

        \[\leadsto 1 \cdot \frac{\color{blue}{0.5}}{\sqrt{{x}^{3}}} \]
      4. sqrt-pow197.6%

        \[\leadsto 1 \cdot \frac{0.5}{\color{blue}{{x}^{\left(\frac{3}{2}\right)}}} \]
      5. metadata-eval97.6%

        \[\leadsto 1 \cdot \frac{0.5}{{x}^{\color{blue}{1.5}}} \]
    6. Applied egg-rr97.6%

      \[\leadsto \color{blue}{1 \cdot \frac{0.5}{{x}^{1.5}}} \]
    7. Step-by-step derivation
      1. *-lft-identity97.6%

        \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    8. Simplified97.6%

      \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    9. Step-by-step derivation
      1. div-inv97.6%

        \[\leadsto \color{blue}{0.5 \cdot \frac{1}{{x}^{1.5}}} \]
      2. *-commutative97.6%

        \[\leadsto \color{blue}{\frac{1}{{x}^{1.5}} \cdot 0.5} \]
      3. pow-flip99.8%

        \[\leadsto \color{blue}{{x}^{\left(-1.5\right)}} \cdot 0.5 \]
      4. metadata-eval99.8%

        \[\leadsto {x}^{\color{blue}{-1.5}} \cdot 0.5 \]
    10. Applied egg-rr99.8%

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

    if 9.99999999999999945e-21 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1))))

    1. Initial program 99.1%

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

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

        \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)} - 1\right)} \]
      3. associate--r-98.8%

        \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{x}} - e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)}\right) + 1} \]
      4. pow1/298.8%

        \[\leadsto \left(\frac{1}{\color{blue}{{x}^{0.5}}} - e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)}\right) + 1 \]
      5. pow-flip99.1%

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

        \[\leadsto \left({x}^{\color{blue}{-0.5}} - e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x + 1}}\right)}\right) + 1 \]
      7. pow1/299.1%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left(\frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}\right)}\right) + 1 \]
      8. pow-flip99.1%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left(\color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}\right)}\right) + 1 \]
      9. +-commutative99.1%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left({\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}\right)}\right) + 1 \]
      10. metadata-eval99.1%

        \[\leadsto \left({x}^{-0.5} - e^{\mathsf{log1p}\left({\left(1 + x\right)}^{\color{blue}{-0.5}}\right)}\right) + 1 \]
    3. Applied egg-rr99.1%

      \[\leadsto \color{blue}{\left({x}^{-0.5} - e^{\mathsf{log1p}\left({\left(1 + x\right)}^{-0.5}\right)}\right) + 1} \]
    4. Step-by-step derivation
      1. associate-+l-99.1%

        \[\leadsto \color{blue}{{x}^{-0.5} - \left(e^{\mathsf{log1p}\left({\left(1 + x\right)}^{-0.5}\right)} - 1\right)} \]
      2. expm1-def99.5%

        \[\leadsto {x}^{-0.5} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(1 + x\right)}^{-0.5}\right)\right)} \]
      3. expm1-log1p99.5%

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

      \[\leadsto \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}} \]
  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 10^{-20}:\\ \;\;\;\;{x}^{-1.5} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]

Alternative 4: 98.6% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\

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


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

    1. Initial program 99.7%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. flip--99.5%

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}} \]
      2. clear-num99.4%

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}}}} \]
      6. pow1/299.6%

        \[\leadsto \frac{1}{\frac{1}{\frac{1}{\color{blue}{{x}^{0.5}}} - \frac{1}{\sqrt{x + 1}}}} \]
      7. pow-flip99.9%

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{{x}^{\left(-0.5\right)}} - \frac{1}{\sqrt{x + 1}}}} \]
      8. metadata-eval99.9%

        \[\leadsto \frac{1}{\frac{1}{{x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}}} \]
      9. pow1/299.9%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}}} \]
      10. pow-flip99.9%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}}} \]
      11. +-commutative99.9%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}}} \]
      12. metadata-eval99.9%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}}} \]
    3. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}}} \]
    4. Taylor expanded in x around 0 98.8%

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\left(0.5 \cdot x + {x}^{-0.5}\right) - 1}}} \]
    5. Taylor expanded in x around 0 98.9%

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

    if 1 < x

    1. Initial program 39.0%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. flip--39.0%

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}} \]
      2. clear-num39.0%

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}}}} \]
      6. pow1/239.0%

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{{x}^{\left(-0.5\right)}} - \frac{1}{\sqrt{x + 1}}}} \]
      8. metadata-eval28.1%

        \[\leadsto \frac{1}{\frac{1}{{x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}}} \]
      9. pow1/228.1%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}}} \]
      10. pow-flip39.1%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}}} \]
      11. +-commutative39.1%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}}} \]
      12. metadata-eval39.1%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}}} \]
    3. Applied egg-rr39.1%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}}} \]
    4. Taylor expanded in x around inf 65.5%

      \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{{x}^{3}}}} \]
    5. Step-by-step derivation
      1. div-inv65.5%

        \[\leadsto \color{blue}{1 \cdot \frac{1}{2 \cdot \sqrt{{x}^{3}}}} \]
      2. associate-/r*65.5%

        \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{2}}{\sqrt{{x}^{3}}}} \]
      3. metadata-eval65.5%

        \[\leadsto 1 \cdot \frac{\color{blue}{0.5}}{\sqrt{{x}^{3}}} \]
      4. sqrt-pow196.3%

        \[\leadsto 1 \cdot \frac{0.5}{\color{blue}{{x}^{\left(\frac{3}{2}\right)}}} \]
      5. metadata-eval96.3%

        \[\leadsto 1 \cdot \frac{0.5}{{x}^{\color{blue}{1.5}}} \]
    6. Applied egg-rr96.3%

      \[\leadsto \color{blue}{1 \cdot \frac{0.5}{{x}^{1.5}}} \]
    7. Step-by-step derivation
      1. *-lft-identity96.3%

        \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    8. Simplified96.3%

      \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    9. Step-by-step derivation
      1. div-inv96.3%

        \[\leadsto \color{blue}{0.5 \cdot \frac{1}{{x}^{1.5}}} \]
      2. *-commutative96.3%

        \[\leadsto \color{blue}{\frac{1}{{x}^{1.5}} \cdot 0.5} \]
      3. pow-flip98.5%

        \[\leadsto \color{blue}{{x}^{\left(-1.5\right)}} \cdot 0.5 \]
      4. metadata-eval98.5%

        \[\leadsto {x}^{\color{blue}{-1.5}} \cdot 0.5 \]
    10. Applied egg-rr98.5%

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

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

Alternative 5: 98.3% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} + -1\\

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


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

    1. Initial program 99.7%

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

      \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{1} \]
    3. Step-by-step derivation
      1. expm1-log1p-u92.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{x}}\right)\right)} - 1 \]
      2. expm1-udef92.2%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{\sqrt{x}}\right)} - 1\right)} - 1 \]
      3. pow1/292.2%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\frac{1}{\color{blue}{{x}^{0.5}}}\right)} - 1\right) - 1 \]
      4. pow-flip92.2%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{{x}^{\left(-0.5\right)}}\right)} - 1\right) - 1 \]
      5. metadata-eval92.2%

        \[\leadsto \left(e^{\mathsf{log1p}\left({x}^{\color{blue}{-0.5}}\right)} - 1\right) - 1 \]
    4. Applied egg-rr92.2%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left({x}^{-0.5}\right)} - 1\right)} - 1 \]
    5. Step-by-step derivation
      1. expm1-def92.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{-0.5}\right)\right)} - 1 \]
      2. expm1-log1p99.4%

        \[\leadsto \color{blue}{{x}^{-0.5}} - 1 \]
    6. Simplified99.4%

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

    if 0.660000000000000031 < x

    1. Initial program 39.5%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Step-by-step derivation
      1. flip--39.5%

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}} \]
      2. clear-num39.5%

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}}}} \]
      6. pow1/239.5%

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

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

        \[\leadsto \frac{1}{\frac{1}{{x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}}} \]
      9. pow1/228.7%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}}} \]
      10. pow-flip39.5%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}}} \]
      11. +-commutative39.5%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}}} \]
      12. metadata-eval39.5%

        \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}}} \]
    3. Applied egg-rr39.5%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}}} \]
    4. Taylor expanded in x around inf 65.2%

      \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{{x}^{3}}}} \]
    5. Step-by-step derivation
      1. div-inv65.2%

        \[\leadsto \color{blue}{1 \cdot \frac{1}{2 \cdot \sqrt{{x}^{3}}}} \]
      2. associate-/r*65.2%

        \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{2}}{\sqrt{{x}^{3}}}} \]
      3. metadata-eval65.2%

        \[\leadsto 1 \cdot \frac{\color{blue}{0.5}}{\sqrt{{x}^{3}}} \]
      4. sqrt-pow195.7%

        \[\leadsto 1 \cdot \frac{0.5}{\color{blue}{{x}^{\left(\frac{3}{2}\right)}}} \]
      5. metadata-eval95.7%

        \[\leadsto 1 \cdot \frac{0.5}{{x}^{\color{blue}{1.5}}} \]
    6. Applied egg-rr95.7%

      \[\leadsto \color{blue}{1 \cdot \frac{0.5}{{x}^{1.5}}} \]
    7. Step-by-step derivation
      1. *-lft-identity95.7%

        \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    8. Simplified95.7%

      \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
    9. Step-by-step derivation
      1. div-inv95.7%

        \[\leadsto \color{blue}{0.5 \cdot \frac{1}{{x}^{1.5}}} \]
      2. *-commutative95.7%

        \[\leadsto \color{blue}{\frac{1}{{x}^{1.5}} \cdot 0.5} \]
      3. pow-flip97.9%

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

        \[\leadsto {x}^{\color{blue}{-1.5}} \cdot 0.5 \]
    10. Applied egg-rr97.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.66:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;{x}^{-1.5} \cdot 0.5\\ \end{array} \]

Alternative 6: 51.7% accurate, 2.0× speedup?

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

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

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Step-by-step derivation
    1. flip--68.8%

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

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

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

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

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}}}} \]
    6. pow1/268.9%

      \[\leadsto \frac{1}{\frac{1}{\frac{1}{\color{blue}{{x}^{0.5}}} - \frac{1}{\sqrt{x + 1}}}} \]
    7. pow-flip63.4%

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{{x}^{\left(-0.5\right)}} - \frac{1}{\sqrt{x + 1}}}} \]
    8. metadata-eval63.4%

      \[\leadsto \frac{1}{\frac{1}{{x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}}} \]
    9. pow1/263.4%

      \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}}} \]
    10. pow-flip69.0%

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

      \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}}} \]
    12. metadata-eval69.0%

      \[\leadsto \frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}}} \]
  3. Applied egg-rr69.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{1}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}}} \]
  4. Taylor expanded in x around inf 36.0%

    \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{{x}^{3}}}} \]
  5. Step-by-step derivation
    1. div-inv36.0%

      \[\leadsto \color{blue}{1 \cdot \frac{1}{2 \cdot \sqrt{{x}^{3}}}} \]
    2. associate-/r*36.0%

      \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{2}}{\sqrt{{x}^{3}}}} \]
    3. metadata-eval36.0%

      \[\leadsto 1 \cdot \frac{\color{blue}{0.5}}{\sqrt{{x}^{3}}} \]
    4. sqrt-pow151.7%

      \[\leadsto 1 \cdot \frac{0.5}{\color{blue}{{x}^{\left(\frac{3}{2}\right)}}} \]
    5. metadata-eval51.7%

      \[\leadsto 1 \cdot \frac{0.5}{{x}^{\color{blue}{1.5}}} \]
  6. Applied egg-rr51.7%

    \[\leadsto \color{blue}{1 \cdot \frac{0.5}{{x}^{1.5}}} \]
  7. Step-by-step derivation
    1. *-lft-identity51.7%

      \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
  8. Simplified51.7%

    \[\leadsto \color{blue}{\frac{0.5}{{x}^{1.5}}} \]
  9. Step-by-step derivation
    1. div-inv51.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{{x}^{1.5}}} \]
    2. *-commutative51.7%

      \[\leadsto \color{blue}{\frac{1}{{x}^{1.5}} \cdot 0.5} \]
    3. pow-flip52.9%

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

      \[\leadsto {x}^{\color{blue}{-1.5}} \cdot 0.5 \]
  10. Applied egg-rr52.9%

    \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} \]
  11. Final simplification52.9%

    \[\leadsto {x}^{-1.5} \cdot 0.5 \]

Alternative 7: 7.4% accurate, 69.7× speedup?

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

\\
\frac{1}{x}
\end{array}
Derivation
  1. Initial program 68.9%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Step-by-step derivation
    1. frac-sub68.9%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
    2. *-un-lft-identity68.9%

      \[\leadsto \frac{\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    3. *-rgt-identity68.9%

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
    5. associate-/l/69.1%

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

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

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

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

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

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

      \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{x \cdot \color{blue}{\left(1 + x\right)}} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)} \]
    12. distribute-rgt-in91.9%

      \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{\color{blue}{1 \cdot x + x \cdot x}} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)} \]
    13. *-un-lft-identity91.9%

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

      \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{x + \color{blue}{{x}^{2}}} \cdot \left(\sqrt{x + 1} + \sqrt{x}\right)} \]
    15. +-commutative91.9%

      \[\leadsto \frac{1 + \left(x - x\right)}{\sqrt{x + {x}^{2}} \cdot \color{blue}{\left(\sqrt{x} + \sqrt{x + 1}\right)}} \]
    16. +-commutative91.9%

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

    \[\leadsto \color{blue}{\frac{1 + \left(x - x\right)}{\sqrt{x + {x}^{2}} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}} \]
  4. Step-by-step derivation
    1. +-inverses91.9%

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\sqrt{x} + \sqrt{1 + x}\right) \cdot \sqrt{x + {x}^{2}}}} \]
    4. associate-/r*91.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\sqrt{x + {x}^{2}}}} \]
    5. +-commutative91.9%

      \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{1 + x} + \sqrt{x}}}}{\sqrt{x + {x}^{2}}} \]
    6. +-commutative91.9%

      \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{\color{blue}{{x}^{2} + x}}} \]
    7. unpow291.9%

      \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{\color{blue}{x \cdot x} + x}} \]
    8. fma-def91.9%

      \[\leadsto \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{\color{blue}{\mathsf{fma}\left(x, x, x\right)}}} \]
  5. Simplified91.9%

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

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

    \[\leadsto \color{blue}{\frac{1}{x}} \]
  8. Final simplification7.3%

    \[\leadsto \frac{1}{x} \]

Alternative 8: 1.9% accurate, 209.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
	return -1.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = -1.0d0
end function
public static double code(double x) {
	return -1.0;
}
def code(x):
	return -1.0
function code(x)
	return -1.0
end
function tmp = code(x)
	tmp = -1.0;
end
code[x_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 68.9%

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

    \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{1} \]
  3. Taylor expanded in x around inf 2.0%

    \[\leadsto \color{blue}{-1} \]
  4. Final simplification2.0%

    \[\leadsto -1 \]

Alternative 9: 5.8% accurate, 209.0× speedup?

\[\begin{array}{l} \\ 2 \end{array} \]
(FPCore (x) :precision binary64 2.0)
double code(double x) {
	return 2.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 2.0d0
end function
public static double code(double x) {
	return 2.0;
}
def code(x):
	return 2.0
function code(x)
	return 2.0
end
function tmp = code(x)
	tmp = 2.0;
end
code[x_] := 2.0
\begin{array}{l}

\\
2
\end{array}
Derivation
  1. Initial program 68.9%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Step-by-step derivation
    1. frac-sub68.9%

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

      \[\leadsto \color{blue}{\left(1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1\right) \cdot \frac{1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
    3. *-un-lft-identity68.9%

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

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

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

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

      \[\leadsto \frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}} \cdot \color{blue}{\left(\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x + 1}}\right)} \]
    8. associate-*l/69.1%

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

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

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

    \[\leadsto \frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{\color{blue}{x + 0.5}}}{\sqrt{x} + \sqrt{1 + x}} \]
  6. Taylor expanded in x around 0 5.7%

    \[\leadsto \color{blue}{2} \]
  7. Final simplification5.7%

    \[\leadsto 2 \]

Developer target: 98.8% 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 2023301 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))

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