2isqrt (example 3.6)

Percentage Accurate: 39.1% → 99.0%
Time: 9.6s
Alternatives: 4
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 4 alternatives:

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

Initial Program: 39.1% 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.0% accurate, 1.0× speedup?

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

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

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

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

      \[\leadsto \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(\color{blue}{\left(1 \cdot \sqrt{\frac{1}{{x}^{3}}}\right)} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    2. pow1/284.8%

      \[\leadsto \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(\left(1 \cdot \color{blue}{{\left(\frac{1}{{x}^{3}}\right)}^{0.5}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    3. pow-flip84.8%

      \[\leadsto \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(\left(1 \cdot {\color{blue}{\left({x}^{\left(-3\right)}\right)}}^{0.5}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    4. pow-pow84.8%

      \[\leadsto \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(\left(1 \cdot \color{blue}{{x}^{\left(\left(-3\right) \cdot 0.5\right)}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    5. metadata-eval84.8%

      \[\leadsto \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(\left(1 \cdot {x}^{\left(\color{blue}{-3} \cdot 0.5\right)}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    6. metadata-eval84.8%

      \[\leadsto \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(\left(1 \cdot {x}^{\color{blue}{-1.5}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  5. Applied egg-rr84.8%

    \[\leadsto \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(\color{blue}{\left(1 \cdot {x}^{-1.5}\right)} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  6. Step-by-step derivation
    1. *-lft-identity84.8%

      \[\leadsto \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(\color{blue}{{x}^{-1.5}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  7. Simplified84.8%

    \[\leadsto \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(\color{blue}{{x}^{-1.5}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  8. Taylor expanded in x around inf 98.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}} \]
  9. Step-by-step derivation
    1. +-commutative98.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-neg98.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-neg98.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. *-commutative98.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-out98.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-eval98.6%

      \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
    7. *-rgt-identity98.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-frac98.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-eval98.6%

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5}{x} - \frac{\frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
  12. Applied egg-rr98.9%

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

Alternative 2: 98.7% accurate, 1.0× speedup?

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

\\
\frac{\frac{0.5}{\sqrt{x}} + {x}^{-1.5} \cdot -0.375}{x}
\end{array}
Derivation
  1. Initial program 43.0%

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

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

      \[\leadsto \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(\color{blue}{\left(1 \cdot \sqrt{\frac{1}{{x}^{3}}}\right)} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    2. pow1/284.8%

      \[\leadsto \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(\left(1 \cdot \color{blue}{{\left(\frac{1}{{x}^{3}}\right)}^{0.5}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    3. pow-flip84.8%

      \[\leadsto \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(\left(1 \cdot {\color{blue}{\left({x}^{\left(-3\right)}\right)}}^{0.5}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    4. pow-pow84.8%

      \[\leadsto \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(\left(1 \cdot \color{blue}{{x}^{\left(\left(-3\right) \cdot 0.5\right)}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    5. metadata-eval84.8%

      \[\leadsto \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(\left(1 \cdot {x}^{\left(\color{blue}{-3} \cdot 0.5\right)}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    6. metadata-eval84.8%

      \[\leadsto \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(\left(1 \cdot {x}^{\color{blue}{-1.5}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  5. Applied egg-rr84.8%

    \[\leadsto \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(\color{blue}{\left(1 \cdot {x}^{-1.5}\right)} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  6. Step-by-step derivation
    1. *-lft-identity84.8%

      \[\leadsto \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(\color{blue}{{x}^{-1.5}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  7. Simplified84.8%

    \[\leadsto \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(\color{blue}{{x}^{-1.5}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  8. Taylor expanded in x around inf 98.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}} \]
  9. Step-by-step derivation
    1. +-commutative98.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-neg98.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-neg98.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. *-commutative98.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-out98.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-eval98.6%

      \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
    7. *-rgt-identity98.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-frac98.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-eval98.6%

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

    \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
  11. Step-by-step derivation
    1. *-un-lft-identity98.6%

      \[\leadsto \color{blue}{1 \cdot \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
  12. Applied egg-rr98.5%

    \[\leadsto \color{blue}{1 \cdot \frac{\frac{0.5}{\sqrt{x}} + -0.375 \cdot {x}^{-1.5}}{x}} \]
  13. Step-by-step derivation
    1. *-lft-identity98.5%

      \[\leadsto \color{blue}{\frac{\frac{0.5}{\sqrt{x}} + -0.375 \cdot {x}^{-1.5}}{x}} \]
  14. Simplified98.5%

    \[\leadsto \color{blue}{\frac{\frac{0.5}{\sqrt{x}} + -0.375 \cdot {x}^{-1.5}}{x}} \]
  15. Final simplification98.5%

    \[\leadsto \frac{\frac{0.5}{\sqrt{x}} + {x}^{-1.5} \cdot -0.375}{x} \]
  16. Add Preprocessing

Alternative 3: 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 43.0%

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

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

      \[\leadsto \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(\color{blue}{\left(1 \cdot \sqrt{\frac{1}{{x}^{3}}}\right)} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    2. pow1/284.8%

      \[\leadsto \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(\left(1 \cdot \color{blue}{{\left(\frac{1}{{x}^{3}}\right)}^{0.5}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    3. pow-flip84.8%

      \[\leadsto \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(\left(1 \cdot {\color{blue}{\left({x}^{\left(-3\right)}\right)}}^{0.5}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    4. pow-pow84.8%

      \[\leadsto \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(\left(1 \cdot \color{blue}{{x}^{\left(\left(-3\right) \cdot 0.5\right)}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    5. metadata-eval84.8%

      \[\leadsto \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(\left(1 \cdot {x}^{\left(\color{blue}{-3} \cdot 0.5\right)}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
    6. metadata-eval84.8%

      \[\leadsto \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(\left(1 \cdot {x}^{\color{blue}{-1.5}}\right) \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  5. Applied egg-rr84.8%

    \[\leadsto \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(\color{blue}{\left(1 \cdot {x}^{-1.5}\right)} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  6. Step-by-step derivation
    1. *-lft-identity84.8%

      \[\leadsto \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(\color{blue}{{x}^{-1.5}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  7. Simplified84.8%

    \[\leadsto \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(\color{blue}{{x}^{-1.5}} \cdot \left(1 + 0.25 \cdot x\right)\right) + 0.5 \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}} \]
  8. Taylor expanded in x around inf 98.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}} \]
  9. Step-by-step derivation
    1. +-commutative98.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-neg98.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-neg98.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. *-commutative98.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-out98.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-eval98.6%

      \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}} \cdot \color{blue}{0.375}}{x}}{x} \]
    7. *-rgt-identity98.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-frac98.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-eval98.6%

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

    \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}} \cdot 0.5 - \frac{\sqrt{\frac{1}{x}}}{x} \cdot 0.375}{x}} \]
  11. Taylor expanded in x around inf 97.7%

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

Alternative 4: 5.6% accurate, 2.0× speedup?

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{x}} - \sqrt{\frac{\color{blue}{1}}{\sqrt{x + 1} \cdot \sqrt{x + 1}}} \]
    5. add-sqr-sqrt32.7%

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

      \[\leadsto \frac{1}{\sqrt{x}} - \sqrt{\frac{1}{\color{blue}{1 + x}}} \]
  4. Applied egg-rr32.7%

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

    \[\leadsto \color{blue}{\sqrt{\frac{1}{x}}} \]
  6. Step-by-step derivation
    1. unpow-15.7%

      \[\leadsto \sqrt{\color{blue}{{x}^{-1}}} \]
    2. metadata-eval5.7%

      \[\leadsto \sqrt{{x}^{\color{blue}{\left(2 \cdot -0.5\right)}}} \]
    3. pow-sqr5.7%

      \[\leadsto \sqrt{\color{blue}{{x}^{-0.5} \cdot {x}^{-0.5}}} \]
    4. rem-sqrt-square5.7%

      \[\leadsto \color{blue}{\left|{x}^{-0.5}\right|} \]
    5. rem-square-sqrt5.7%

      \[\leadsto \left|\color{blue}{\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}}\right| \]
    6. fabs-sqr5.7%

      \[\leadsto \color{blue}{\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}} \]
    7. rem-square-sqrt5.7%

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

    \[\leadsto \color{blue}{{x}^{-0.5}} \]
  8. Add Preprocessing

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

  :alt
  (! :herbie-platform default (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1))))))

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