2isqrt (example 3.6)

Percentage Accurate: 37.9% → 99.7%
Time: 14.1s
Alternatives: 6
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 6 alternatives:

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

Initial Program: 37.9% 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.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 0:\\ \;\;\;\;\frac{-0.5 \cdot {x}^{-0.5} + -0.625 \cdot \frac{{x}^{-0.5}}{x}}{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(x + 1\right) - x}{x \cdot \left(x + 1\right)}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ x 1.0)))) 0.0)
   (/ (+ (* -0.5 (pow x -0.5)) (* -0.625 (/ (pow x -0.5) x))) (- x))
   (/
    (/ (- (+ x 1.0) x) (* x (+ x 1.0)))
    (+ (pow x -0.5) (pow (+ x 1.0) -0.5)))))
double code(double x) {
	double tmp;
	if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 0.0) {
		tmp = ((-0.5 * pow(x, -0.5)) + (-0.625 * (pow(x, -0.5) / x))) / -x;
	} else {
		tmp = (((x + 1.0) - x) / (x * (x + 1.0))) / (pow(x, -0.5) + pow((x + 1.0), -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((x + 1.0d0)))) <= 0.0d0) then
        tmp = (((-0.5d0) * (x ** (-0.5d0))) + ((-0.625d0) * ((x ** (-0.5d0)) / x))) / -x
    else
        tmp = (((x + 1.0d0) - x) / (x * (x + 1.0d0))) / ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-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((x + 1.0)))) <= 0.0) {
		tmp = ((-0.5 * Math.pow(x, -0.5)) + (-0.625 * (Math.pow(x, -0.5) / x))) / -x;
	} else {
		tmp = (((x + 1.0) - x) / (x * (x + 1.0))) / (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((x + 1.0)))) <= 0.0:
		tmp = ((-0.5 * math.pow(x, -0.5)) + (-0.625 * (math.pow(x, -0.5) / x))) / -x
	else:
		tmp = (((x + 1.0) - x) / (x * (x + 1.0))) / (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))
	return tmp
function code(x)
	tmp = 0.0
	if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(x + 1.0)))) <= 0.0)
		tmp = Float64(Float64(Float64(-0.5 * (x ^ -0.5)) + Float64(-0.625 * Float64((x ^ -0.5) / x))) / Float64(-x));
	else
		tmp = Float64(Float64(Float64(Float64(x + 1.0) - x) / Float64(x * Float64(x + 1.0))) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 0.0)
		tmp = ((-0.5 * (x ^ -0.5)) + (-0.625 * ((x ^ -0.5) / x))) / -x;
	else
		tmp = (((x + 1.0) - x) / (x * (x + 1.0))) / ((x ^ -0.5) + ((x + 1.0) ^ -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[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(-0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] + N[(-0.625 * N[(N[Power[x, -0.5], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[(N[(N[(N[(x + 1.0), $MachinePrecision] - x), $MachinePrecision] / N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 0:\\
\;\;\;\;\frac{-0.5 \cdot {x}^{-0.5} + -0.625 \cdot \frac{{x}^{-0.5}}{x}}{-x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x + 1\right) - x}{x \cdot \left(x + 1\right)}}{{x}^{-0.5} + {\left(x + 1\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))))) < 0.0

    1. Initial program 34.0%

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

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

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

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

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

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

    if 0.0 < (-.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 51.9%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--51.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. div-inv51.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{\color{blue}{-0.5}} + \frac{1}{\sqrt{x + 1}}} \]
      13. pow1/253.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
    7. Step-by-step derivation
      1. frac-sub99.4%

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot \left(1 + x\right) - x \cdot 1}{x \cdot \left(1 + x\right)}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      2. *-un-lft-identity99.4%

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

      \[\leadsto \frac{\color{blue}{\frac{\left(1 + x\right) - x \cdot 1}{x \cdot \left(1 + x\right)}}}{{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{x + 1}} \leq 0:\\ \;\;\;\;\frac{-0.5 \cdot {x}^{-0.5} + -0.625 \cdot \frac{{x}^{-0.5}}{x}}{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(x + 1\right) - x}{x \cdot \left(x + 1\right)}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (/
   (-
    (* (* 0.5 (fma x 0.25 1.0)) (pow x -1.5))
    (fma 0.5 (pow x -0.5) (* -0.5 (sqrt x))))
   x)
  x))
double code(double x) {
	return ((((0.5 * fma(x, 0.25, 1.0)) * pow(x, -1.5)) - fma(0.5, pow(x, -0.5), (-0.5 * sqrt(x)))) / x) / x;
}
function code(x)
	return Float64(Float64(Float64(Float64(Float64(0.5 * fma(x, 0.25, 1.0)) * (x ^ -1.5)) - fma(0.5, (x ^ -0.5), Float64(-0.5 * sqrt(x)))) / x) / x)
end
code[x_] := N[(N[(N[(N[(N[(0.5 * N[(x * 0.25 + 1.0), $MachinePrecision]), $MachinePrecision] * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[Power[x, -0.5], $MachinePrecision] + N[(-0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x}
\end{array}
Derivation
  1. Initial program 35.0%

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + 0.5 \cdot \sqrt{\frac{1}{x}}\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. *-un-lft-identity84.3%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{0.5 \cdot \left({x}^{-1.5} \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}} \]
  6. Step-by-step derivation
    1. associate-*l/98.9%

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{0.5 \cdot \left({x}^{-1.5} \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x}} \]
    2. *-lft-identity98.9%

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

      \[\leadsto \frac{\frac{0.5 \cdot \color{blue}{\left(\mathsf{fma}\left(x, 0.25, 1\right) \cdot {x}^{-1.5}\right)} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    4. fma-undefine98.9%

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

      \[\leadsto \frac{\frac{0.5 \cdot \left(\left(\color{blue}{0.25 \cdot x} + 1\right) \cdot {x}^{-1.5}\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    6. +-commutative98.9%

      \[\leadsto \frac{\frac{0.5 \cdot \left(\color{blue}{\left(1 + 0.25 \cdot x\right)} \cdot {x}^{-1.5}\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    7. associate-*r*98.9%

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

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

      \[\leadsto \frac{\frac{\left(0.5 \cdot \left(\color{blue}{x \cdot 0.25} + 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    10. fma-undefine98.9%

      \[\leadsto \frac{\frac{\left(0.5 \cdot \color{blue}{\mathsf{fma}\left(x, 0.25, 1\right)}\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    11. *-commutative98.9%

      \[\leadsto \frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, \color{blue}{\sqrt{x} \cdot -0.5}\right)}{x}}{x} \]
  7. Simplified98.9%

    \[\leadsto \color{blue}{\frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, \sqrt{x} \cdot -0.5\right)}{x}}{x}} \]
  8. Final simplification98.9%

    \[\leadsto \frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
  9. Add Preprocessing

Alternative 3: 99.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 0:\\ \;\;\;\;\frac{-0.5 \cdot {x}^{-0.5} + -0.625 \cdot \frac{{x}^{-0.5}}{x}}{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ x 1.0)))) 0.0)
   (/ (+ (* -0.5 (pow x -0.5)) (* -0.625 (/ (pow x -0.5) x))) (- x))
   (/ (/ (/ 1.0 x) (+ x 1.0)) (+ (pow x -0.5) (pow (+ x 1.0) -0.5)))))
double code(double x) {
	double tmp;
	if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 0.0) {
		tmp = ((-0.5 * pow(x, -0.5)) + (-0.625 * (pow(x, -0.5) / x))) / -x;
	} else {
		tmp = ((1.0 / x) / (x + 1.0)) / (pow(x, -0.5) + pow((x + 1.0), -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((x + 1.0d0)))) <= 0.0d0) then
        tmp = (((-0.5d0) * (x ** (-0.5d0))) + ((-0.625d0) * ((x ** (-0.5d0)) / x))) / -x
    else
        tmp = ((1.0d0 / x) / (x + 1.0d0)) / ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-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((x + 1.0)))) <= 0.0) {
		tmp = ((-0.5 * Math.pow(x, -0.5)) + (-0.625 * (Math.pow(x, -0.5) / x))) / -x;
	} else {
		tmp = ((1.0 / x) / (x + 1.0)) / (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((x + 1.0)))) <= 0.0:
		tmp = ((-0.5 * math.pow(x, -0.5)) + (-0.625 * (math.pow(x, -0.5) / x))) / -x
	else:
		tmp = ((1.0 / x) / (x + 1.0)) / (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))
	return tmp
function code(x)
	tmp = 0.0
	if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(x + 1.0)))) <= 0.0)
		tmp = Float64(Float64(Float64(-0.5 * (x ^ -0.5)) + Float64(-0.625 * Float64((x ^ -0.5) / x))) / Float64(-x));
	else
		tmp = Float64(Float64(Float64(1.0 / x) / Float64(x + 1.0)) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 0.0)
		tmp = ((-0.5 * (x ^ -0.5)) + (-0.625 * ((x ^ -0.5) / x))) / -x;
	else
		tmp = ((1.0 / x) / (x + 1.0)) / ((x ^ -0.5) + ((x + 1.0) ^ -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[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(-0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] + N[(-0.625 * N[(N[Power[x, -0.5], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 0:\\
\;\;\;\;\frac{-0.5 \cdot {x}^{-0.5} + -0.625 \cdot \frac{{x}^{-0.5}}{x}}{-x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\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))))) < 0.0

    1. Initial program 34.0%

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

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

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

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

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

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

    if 0.0 < (-.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 51.9%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--51.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. div-inv51.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{\color{blue}{-0.5}} + \frac{1}{\sqrt{x + 1}}} \]
      13. pow1/253.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{x} - \frac{1}{1 + x}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
    7. Step-by-step derivation
      1. frac-sub99.4%

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot \left(1 + x\right) - x \cdot 1}{x \cdot \left(1 + x\right)}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      2. *-un-lft-identity99.4%

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

      \[\leadsto \frac{\color{blue}{\frac{\left(1 + x\right) - x \cdot 1}{x \cdot \left(1 + x\right)}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
    9. Step-by-step derivation
      1. /-rgt-identity99.4%

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

        \[\leadsto \frac{\frac{\color{blue}{1 \cdot \frac{1 + x}{1}} - x \cdot 1}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      3. /-rgt-identity99.4%

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

        \[\leadsto \frac{\frac{\color{blue}{\frac{1 + x}{1}} - \frac{x}{1} \cdot 1}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      5. /-rgt-identity99.4%

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

        \[\leadsto \frac{\frac{\left(1 + x\right) - \color{blue}{\frac{x}{1}}}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      7. /-rgt-identity99.4%

        \[\leadsto \frac{\frac{\left(1 + x\right) - \color{blue}{x}}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      8. associate--l+99.4%

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

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

        \[\leadsto \frac{\frac{\color{blue}{1}}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      11. associate-/r*99.3%

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

      \[\leadsto \frac{\color{blue}{\frac{\frac{1}{x}}{1 + x}}}{{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{x + 1}} \leq 0:\\ \;\;\;\;\frac{-0.5 \cdot {x}^{-0.5} + -0.625 \cdot \frac{{x}^{-0.5}}{x}}{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 98.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \frac{\frac{0.125 \cdot \sqrt{\frac{1}{x}} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (/ (- (* 0.125 (sqrt (/ 1.0 x))) (fma 0.5 (pow x -0.5) (* -0.5 (sqrt x)))) x)
  x))
double code(double x) {
	return (((0.125 * sqrt((1.0 / x))) - fma(0.5, pow(x, -0.5), (-0.5 * sqrt(x)))) / x) / x;
}
function code(x)
	return Float64(Float64(Float64(Float64(0.125 * sqrt(Float64(1.0 / x))) - fma(0.5, (x ^ -0.5), Float64(-0.5 * sqrt(x)))) / x) / x)
end
code[x_] := N[(N[(N[(N[(0.125 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[Power[x, -0.5], $MachinePrecision] + N[(-0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{0.125 \cdot \sqrt{\frac{1}{x}} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x}
\end{array}
Derivation
  1. Initial program 35.0%

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + 0.5 \cdot \sqrt{\frac{1}{x}}\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. *-un-lft-identity84.3%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{0.5 \cdot \left({x}^{-1.5} \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}} \]
  6. Step-by-step derivation
    1. associate-*l/98.9%

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{0.5 \cdot \left({x}^{-1.5} \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x}} \]
    2. *-lft-identity98.9%

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

      \[\leadsto \frac{\frac{0.5 \cdot \color{blue}{\left(\mathsf{fma}\left(x, 0.25, 1\right) \cdot {x}^{-1.5}\right)} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    4. fma-undefine98.9%

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

      \[\leadsto \frac{\frac{0.5 \cdot \left(\left(\color{blue}{0.25 \cdot x} + 1\right) \cdot {x}^{-1.5}\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    6. +-commutative98.9%

      \[\leadsto \frac{\frac{0.5 \cdot \left(\color{blue}{\left(1 + 0.25 \cdot x\right)} \cdot {x}^{-1.5}\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    7. associate-*r*98.9%

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

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

      \[\leadsto \frac{\frac{\left(0.5 \cdot \left(\color{blue}{x \cdot 0.25} + 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    10. fma-undefine98.9%

      \[\leadsto \frac{\frac{\left(0.5 \cdot \color{blue}{\mathsf{fma}\left(x, 0.25, 1\right)}\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    11. *-commutative98.9%

      \[\leadsto \frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, \color{blue}{\sqrt{x} \cdot -0.5}\right)}{x}}{x} \]
  7. Simplified98.9%

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

    \[\leadsto \frac{\frac{\color{blue}{0.125 \cdot \sqrt{\frac{1}{x}}} - \mathsf{fma}\left(0.5, {x}^{-0.5}, \sqrt{x} \cdot -0.5\right)}{x}}{x} \]
  9. Final simplification98.9%

    \[\leadsto \frac{\frac{0.125 \cdot \sqrt{\frac{1}{x}} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
  10. Add Preprocessing

Alternative 5: 97.8% 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 35.0%

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + 0.25 \cdot x\right)\right) - \left(-0.5 \cdot \sqrt{x} + 0.5 \cdot \sqrt{\frac{1}{x}}\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. *-un-lft-identity84.3%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{0.5 \cdot \left({x}^{-1.5} \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}} \]
  6. Step-by-step derivation
    1. associate-*l/98.9%

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{0.5 \cdot \left({x}^{-1.5} \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x}} \]
    2. *-lft-identity98.9%

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

      \[\leadsto \frac{\frac{0.5 \cdot \color{blue}{\left(\mathsf{fma}\left(x, 0.25, 1\right) \cdot {x}^{-1.5}\right)} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    4. fma-undefine98.9%

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

      \[\leadsto \frac{\frac{0.5 \cdot \left(\left(\color{blue}{0.25 \cdot x} + 1\right) \cdot {x}^{-1.5}\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    6. +-commutative98.9%

      \[\leadsto \frac{\frac{0.5 \cdot \left(\color{blue}{\left(1 + 0.25 \cdot x\right)} \cdot {x}^{-1.5}\right) - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    7. associate-*r*98.9%

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

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

      \[\leadsto \frac{\frac{\left(0.5 \cdot \left(\color{blue}{x \cdot 0.25} + 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    10. fma-undefine98.9%

      \[\leadsto \frac{\frac{\left(0.5 \cdot \color{blue}{\mathsf{fma}\left(x, 0.25, 1\right)}\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, -0.5 \cdot \sqrt{x}\right)}{x}}{x} \]
    11. *-commutative98.9%

      \[\leadsto \frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, \color{blue}{\sqrt{x} \cdot -0.5}\right)}{x}}{x} \]
  7. Simplified98.9%

    \[\leadsto \color{blue}{\frac{\frac{\left(0.5 \cdot \mathsf{fma}\left(x, 0.25, 1\right)\right) \cdot {x}^{-1.5} - \mathsf{fma}\left(0.5, {x}^{-0.5}, \sqrt{x} \cdot -0.5\right)}{x}}{x}} \]
  8. Taylor expanded in x around inf 98.0%

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

Alternative 6: 35.1% 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 35.0%

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-cube-cbrt10.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{1}{\sqrt{x}}}, \sqrt[3]{\frac{1}{\sqrt{x}}} \cdot \sqrt[3]{\frac{1}{\sqrt{x}}}, -\left(-\frac{1}{\sqrt{x + 1}}\right) \cdot -1\right) + \mathsf{fma}\left(-\left(-\frac{1}{\sqrt{x + 1}}\right), -1, \left(-\frac{1}{\sqrt{x + 1}}\right) \cdot -1\right)} \]
  4. Applied egg-rr6.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{0} \]
  9. Simplified32.4%

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

Developer target: 98.4% 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 2024086 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64
  :pre (and (> x 1.0) (< x 1e+308))

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

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