2isqrt (example 3.6)

Percentage Accurate: 38.7% → 99.9%
Time: 13.8s
Alternatives: 7
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 38.7% 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.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \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 + \left(x - x\right)}{x + {x}^{2}}}{{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)))) 0.0)
   (* (pow x -1.5) 0.5)
   (/
    (/ (+ 1.0 (- x x)) (+ x (pow x 2.0)))
    (+ (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)))) <= 0.0) {
		tmp = pow(x, -1.5) * 0.5;
	} else {
		tmp = ((1.0 + (x - x)) / (x + pow(x, 2.0))) / (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)))) <= 0.0d0) then
        tmp = (x ** (-1.5d0)) * 0.5d0
    else
        tmp = ((1.0d0 + (x - x)) / (x + (x ** 2.0d0))) / ((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)))) <= 0.0) {
		tmp = Math.pow(x, -1.5) * 0.5;
	} else {
		tmp = ((1.0 + (x - x)) / (x + Math.pow(x, 2.0))) / (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)))) <= 0.0:
		tmp = math.pow(x, -1.5) * 0.5
	else:
		tmp = ((1.0 + (x - x)) / (x + math.pow(x, 2.0))) / (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)))) <= 0.0)
		tmp = Float64((x ^ -1.5) * 0.5);
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(x - x)) / Float64(x + (x ^ 2.0))) / 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)))) <= 0.0)
		tmp = (x ^ -1.5) * 0.5;
	else
		tmp = ((1.0 + (x - x)) / (x + (x ^ 2.0))) / ((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], 0.0], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(x + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\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 + \left(x - x\right)}{x + {x}^{2}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\


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

    1. Initial program 39.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
      7. *-rgt-identity99.7%

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \color{blue}{\frac{\sqrt{\frac{1}{x}}}{x} \cdot \frac{0.375}{1}}}{x} \]
      9. metadata-eval99.7%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
    7. Step-by-step derivation
      1. div-sub99.7%

        \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5}{x} - \frac{\frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
      2. sub-neg99.7%

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

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-1.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right)} \]
    9. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right) \]
      2. distribute-rgt-neg-in100.0%

        \[\leadsto {x}^{-1.5} \cdot 0.5 + \color{blue}{{x}^{-1.5} \cdot \left(-\frac{0.375}{x}\right)} \]
      3. distribute-lft-out100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \left(-\frac{0.375}{x}\right)\right)} \]
      4. distribute-neg-frac100.0%

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

        \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \frac{\color{blue}{-0.375}}{x}\right) \]
    10. Simplified100.0%

      \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)} \]
    11. Taylor expanded in x around inf 100.0%

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

    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 67.7%

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

        \[\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-times67.4%

        \[\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-eval67.4%

        \[\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-sqrt67.6%

        \[\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-times68.0%

        \[\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-eval68.0%

        \[\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-sqrt69.3%

        \[\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. +-commutative69.3%

        \[\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-pow69.3%

        \[\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-pow269.3%

        \[\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-eval69.3%

        \[\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/269.3%

        \[\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-flip69.2%

        \[\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. +-commutative69.2%

        \[\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-eval69.2%

        \[\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-rr69.2%

      \[\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/69.2%

        \[\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-identity69.2%

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

      \[\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.2%

        \[\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.2%

        \[\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}} \]
      3. distribute-rgt-in99.2%

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

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

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

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

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

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

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

    \[\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 + \left(x - x\right)}{x + {x}^{2}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \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}{x \cdot \left(1 + x\right)}}{{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)))) 0.0)
   (* (pow x -1.5) 0.5)
   (/ (/ 1.0 (* x (+ 1.0 x))) (+ (pow x -0.5) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
	double tmp;
	if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 0.0) {
		tmp = pow(x, -1.5) * 0.5;
	} else {
		tmp = (1.0 / (x * (1.0 + x))) / (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)))) <= 0.0d0) then
        tmp = (x ** (-1.5d0)) * 0.5d0
    else
        tmp = (1.0d0 / (x * (1.0d0 + x))) / ((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)))) <= 0.0) {
		tmp = Math.pow(x, -1.5) * 0.5;
	} else {
		tmp = (1.0 / (x * (1.0 + x))) / (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)))) <= 0.0:
		tmp = math.pow(x, -1.5) * 0.5
	else:
		tmp = (1.0 / (x * (1.0 + x))) / (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)))) <= 0.0)
		tmp = Float64((x ^ -1.5) * 0.5);
	else
		tmp = Float64(Float64(1.0 / Float64(x * Float64(1.0 + x))) / 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)))) <= 0.0)
		tmp = (x ^ -1.5) * 0.5;
	else
		tmp = (1.0 / (x * (1.0 + x))) / ((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], 0.0], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(1.0 / N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\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}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\


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

    1. Initial program 39.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
      7. *-rgt-identity99.7%

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \color{blue}{\frac{\sqrt{\frac{1}{x}}}{x} \cdot \frac{0.375}{1}}}{x} \]
      9. metadata-eval99.7%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
    7. Step-by-step derivation
      1. div-sub99.7%

        \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5}{x} - \frac{\frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
      2. sub-neg99.7%

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

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-1.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right)} \]
    9. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right) \]
      2. distribute-rgt-neg-in100.0%

        \[\leadsto {x}^{-1.5} \cdot 0.5 + \color{blue}{{x}^{-1.5} \cdot \left(-\frac{0.375}{x}\right)} \]
      3. distribute-lft-out100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \left(-\frac{0.375}{x}\right)\right)} \]
      4. distribute-neg-frac100.0%

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

        \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \frac{\color{blue}{-0.375}}{x}\right) \]
    10. Simplified100.0%

      \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)} \]
    11. Taylor expanded in x around inf 100.0%

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

    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 67.7%

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

        \[\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-times67.4%

        \[\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-eval67.4%

        \[\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-sqrt67.6%

        \[\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-times68.0%

        \[\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-eval68.0%

        \[\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-sqrt69.3%

        \[\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. +-commutative69.3%

        \[\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-pow69.3%

        \[\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-pow269.3%

        \[\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-eval69.3%

        \[\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/269.3%

        \[\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-flip69.2%

        \[\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. +-commutative69.2%

        \[\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-eval69.2%

        \[\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-rr69.2%

      \[\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/69.2%

        \[\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-identity69.2%

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

      \[\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.2%

        \[\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.2%

        \[\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}} \]
      3. distribute-rgt-in99.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{x \cdot 1 + \color{blue}{x \cdot x}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
      7. distribute-lft-out99.7%

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

      \[\leadsto \frac{\color{blue}{\frac{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 simplification100.0%

    \[\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}{x \cdot \left(1 + x\right)}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.5% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{1}{\sqrt{x}}\\
\mathbf{if}\;t\_0 + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-12}:\\
\;\;\;\;{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 - {\left(1 + x\right)}^{-0.5}\\


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

    1. Initial program 40.1%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
      7. *-rgt-identity99.7%

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \color{blue}{\frac{\sqrt{\frac{1}{x}}}{x} \cdot \frac{0.375}{1}}}{x} \]
      9. metadata-eval99.7%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
    7. Step-by-step derivation
      1. div-sub99.7%

        \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5}{x} - \frac{\frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
      2. sub-neg99.7%

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

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-1.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right)} \]
    9. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right) \]
      2. distribute-rgt-neg-in100.0%

        \[\leadsto {x}^{-1.5} \cdot 0.5 + \color{blue}{{x}^{-1.5} \cdot \left(-\frac{0.375}{x}\right)} \]
      3. distribute-lft-out100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \left(-\frac{0.375}{x}\right)\right)} \]
      4. distribute-neg-frac100.0%

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

        \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \frac{\color{blue}{-0.375}}{x}\right) \]
    10. Simplified100.0%

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

    if 1.99999999999999996e-12 < (-.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 90.2%

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

        \[\leadsto \color{blue}{\frac{-1}{-\sqrt{x}}} - \frac{1}{\sqrt{x + 1}} \]
      2. metadata-eval90.2%

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

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

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

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

        \[\leadsto -1 \cdot \frac{1}{-\sqrt{x}} - \color{blue}{-1 \cdot \frac{1}{-\sqrt{x + 1}}} \]
      7. distribute-neg-frac290.2%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \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)} \]
      9. distribute-neg-frac90.2%

        \[\leadsto \mathsf{fma}\left(-1, \frac{1}{-\sqrt{x}}, -\color{blue}{\frac{-1}{\sqrt{x + 1}}} \cdot -1\right) + \mathsf{fma}\left(-\left(-\frac{1}{\sqrt{x + 1}}\right), -1, \left(-\frac{1}{\sqrt{x + 1}}\right) \cdot -1\right) \]
      10. metadata-eval90.2%

        \[\leadsto \mathsf{fma}\left(-1, \frac{1}{-\sqrt{x}}, -\frac{\color{blue}{-1}}{\sqrt{x + 1}} \cdot -1\right) + \mathsf{fma}\left(-\left(-\frac{1}{\sqrt{x + 1}}\right), -1, \left(-\frac{1}{\sqrt{x + 1}}\right) \cdot -1\right) \]
      11. +-commutative90.2%

        \[\leadsto \mathsf{fma}\left(-1, \frac{1}{-\sqrt{x}}, -\frac{-1}{\sqrt{\color{blue}{1 + x}}} \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-rr91.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{1}{-\sqrt{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. +-commutative91.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(-1, \frac{1}{-\sqrt{x}}, -\frac{-1}{\sqrt{1 + x}} \cdot -1\right)} \]
      2. fma-undefine91.4%

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

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

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

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

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

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

Alternative 4: 99.7% accurate, 1.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)\\


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

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 235000 < x

    1. Initial program 40.1%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
      7. *-rgt-identity99.7%

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \color{blue}{\frac{\sqrt{\frac{1}{x}}}{x} \cdot \frac{0.375}{1}}}{x} \]
      9. metadata-eval99.7%

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

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
    7. Step-by-step derivation
      1. div-sub99.7%

        \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5}{x} - \frac{\frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
      2. sub-neg99.7%

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

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-1.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right)} \]
    9. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right) \]
      2. distribute-rgt-neg-in100.0%

        \[\leadsto {x}^{-1.5} \cdot 0.5 + \color{blue}{{x}^{-1.5} \cdot \left(-\frac{0.375}{x}\right)} \]
      3. distribute-lft-out100.0%

        \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \left(-\frac{0.375}{x}\right)\right)} \]
      4. distribute-neg-frac100.0%

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

        \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \frac{\color{blue}{-0.375}}{x}\right) \]
    10. Simplified100.0%

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

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

Alternative 5: 99.0% accurate, 1.9× speedup?

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

\\
{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)
\end{array}
Derivation
  1. Initial program 41.9%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
    7. *-rgt-identity97.6%

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

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

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

    \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
  7. Step-by-step derivation
    1. div-sub97.6%

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

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

    \[\leadsto \color{blue}{0.5 \cdot {x}^{-1.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right)} \]
  9. Step-by-step derivation
    1. *-commutative97.8%

      \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right) \]
    2. distribute-rgt-neg-in97.8%

      \[\leadsto {x}^{-1.5} \cdot 0.5 + \color{blue}{{x}^{-1.5} \cdot \left(-\frac{0.375}{x}\right)} \]
    3. distribute-lft-out97.8%

      \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \left(-\frac{0.375}{x}\right)\right)} \]
    4. distribute-neg-frac97.8%

      \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \color{blue}{\frac{-0.375}{x}}\right) \]
    5. metadata-eval97.8%

      \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \frac{\color{blue}{-0.375}}{x}\right) \]
  10. Simplified97.8%

    \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)} \]
  11. Final simplification97.8%

    \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right) \]
  12. Add Preprocessing

Alternative 6: 98.0% 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 41.9%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
    7. *-rgt-identity97.6%

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

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

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

    \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
  7. Step-by-step derivation
    1. div-sub97.6%

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

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

    \[\leadsto \color{blue}{0.5 \cdot {x}^{-1.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right)} \]
  9. Step-by-step derivation
    1. *-commutative97.8%

      \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} + \left(-{x}^{-1.5} \cdot \frac{0.375}{x}\right) \]
    2. distribute-rgt-neg-in97.8%

      \[\leadsto {x}^{-1.5} \cdot 0.5 + \color{blue}{{x}^{-1.5} \cdot \left(-\frac{0.375}{x}\right)} \]
    3. distribute-lft-out97.8%

      \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \left(-\frac{0.375}{x}\right)\right)} \]
    4. distribute-neg-frac97.8%

      \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \color{blue}{\frac{-0.375}{x}}\right) \]
    5. metadata-eval97.8%

      \[\leadsto {x}^{-1.5} \cdot \left(0.5 + \frac{\color{blue}{-0.375}}{x}\right) \]
  10. Simplified97.8%

    \[\leadsto \color{blue}{{x}^{-1.5} \cdot \left(0.5 + \frac{-0.375}{x}\right)} \]
  11. Taylor expanded in x around inf 96.6%

    \[\leadsto {x}^{-1.5} \cdot \color{blue}{0.5} \]
  12. Final simplification96.6%

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

Alternative 7: 35.9% 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 41.9%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} + -1 \cdot \sqrt{\frac{1}{x}}} \]
  6. Step-by-step derivation
    1. distribute-rgt1-in37.3%

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

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

      \[\leadsto \color{blue}{0} \]
  7. Simplified37.3%

    \[\leadsto \color{blue}{0} \]
  8. Final simplification37.3%

    \[\leadsto 0 \]
  9. 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 2024077 
(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)))))