2isqrt (example 3.6)

Percentage Accurate: 39.4% → 98.6%
Time: 10.3s
Alternatives: 9
Speedup: 1.8×

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 9 alternatives:

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

Initial Program: 39.4% 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: 98.6% accurate, 0.9× speedup?

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

\\
\frac{0.5 \cdot \left(\sqrt{\frac{1}{x}} \cdot \left(1 + \frac{-0.75}{x}\right)\right)}{x}
\end{array}
Derivation
  1. Initial program 39.0%

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

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\mathsf{fma}\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}}, \mathsf{fma}\left(x, 0.25, 1\right), \sqrt{x}\right) - \sqrt{\frac{1}{x}}\right)}{x \cdot x}} \]
  5. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\left(\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}} \cdot \left(x \cdot \frac{1}{4} + 1\right) + \sqrt{x}\right) - \sqrt{\frac{1}{x}}\right) \cdot \frac{1}{2}}}{x \cdot x} \]
    2. times-fracN/A

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}} \cdot \left(x \cdot \frac{1}{4} + 1\right) + \sqrt{x}\right) - \sqrt{\frac{1}{x}}}{x} \cdot \frac{\frac{1}{2}}{x}} \]
    3. *-lowering-*.f64N/A

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

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

    \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \frac{-1 \cdot \sqrt{\frac{1}{x}} + \frac{1}{4} \cdot \sqrt{\frac{1}{x}}}{x}}{x}} \]
  8. Step-by-step derivation
    1. /-lowering-/.f64N/A

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\sqrt{\frac{1}{x}} \cdot \left(1 + \frac{-0.75}{x}\right)\right)}{x}} \]
  10. Add Preprocessing

Alternative 2: 98.7% accurate, 1.2× speedup?

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

\\
\frac{\frac{1}{0.5 + \left(x + x\right)}}{\sqrt{1 + x}}
\end{array}
Derivation
  1. Initial program 39.0%

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

    \[\leadsto \color{blue}{\frac{\left(1 + x\right) - x}{x + \sqrt{\mathsf{fma}\left(x, x, x\right)}} \cdot \frac{1}{\sqrt{1 + x}}} \]
  4. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \color{blue}{\frac{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}{\sqrt{1 + x}}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    3. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    5. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    6. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    7. associate--l+N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1 + \left(x - x\right)}}{x + \sqrt{x \cdot x + x}}}} \]
    8. +-inversesN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1 + \color{blue}{0}}{x + \sqrt{x \cdot x + x}}}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1}}{x + \sqrt{x \cdot x + x}}}} \]
    10. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\color{blue}{\frac{1}{x + \sqrt{x \cdot x + x}}}}} \]
    11. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{\color{blue}{x + \sqrt{x \cdot x + x}}}}} \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\sqrt{x \cdot x + x}}}}} \]
    13. accelerator-lowering-fma.f6483.4

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

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

    \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{x \cdot \left(1 + \frac{1}{2} \cdot \frac{1}{x}\right)}}}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + x \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{x} + 1\right)}}}} \]
    2. distribute-rgt-inN/A

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

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x\right)}}} \]
    4. lft-mult-inverseN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} \cdot \color{blue}{1} + 1 \cdot x\right)}}} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2}} + 1 \cdot x\right)}}} \]
    6. *-lft-identityN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} + \color{blue}{x}\right)}}} \]
    7. +-lowering-+.f6498.0

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

    \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\left(0.5 + x\right)}}}} \]
  9. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{x + 1}}}{\frac{1}{x + \left(\frac{1}{2} + x\right)}}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{\frac{1}{x + \left(\frac{1}{2} + x\right)}}{\sqrt{x + 1}}} \]
    3. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{x + \left(\frac{1}{2} + x\right)}}{\sqrt{x + 1}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \frac{\color{blue}{\frac{1}{x + \left(\frac{1}{2} + x\right)}}}{\sqrt{x + 1}} \]
    5. associate-+r+N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\left(x + \frac{1}{2}\right) + x}}}{\sqrt{x + 1}} \]
    6. +-commutativeN/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\left(\frac{1}{2} + x\right)} + x}}{\sqrt{x + 1}} \]
    7. associate-+l+N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{2} + \left(x + x\right)}}}{\sqrt{x + 1}} \]
    8. +-lowering-+.f64N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{2} + \left(x + x\right)}}}{\sqrt{x + 1}} \]
    9. +-lowering-+.f64N/A

      \[\leadsto \frac{\frac{1}{\frac{1}{2} + \color{blue}{\left(x + x\right)}}}{\sqrt{x + 1}} \]
    10. +-commutativeN/A

      \[\leadsto \frac{\frac{1}{\frac{1}{2} + \left(x + x\right)}}{\sqrt{\color{blue}{1 + x}}} \]
    11. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{\frac{1}{\frac{1}{2} + \left(x + x\right)}}{\color{blue}{\sqrt{1 + x}}} \]
    12. +-lowering-+.f6499.3

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

    \[\leadsto \color{blue}{\frac{\frac{1}{0.5 + \left(x + x\right)}}{\sqrt{1 + x}}} \]
  11. Add Preprocessing

Alternative 3: 97.5% accurate, 1.3× 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 39.0%

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

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\mathsf{fma}\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}}, \mathsf{fma}\left(x, 0.25, 1\right), \sqrt{x}\right) - \sqrt{\frac{1}{x}}\right)}{x \cdot x}} \]
  5. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\left(\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}} \cdot \left(x \cdot \frac{1}{4} + 1\right) + \sqrt{x}\right) - \sqrt{\frac{1}{x}}\right) \cdot \frac{1}{2}}}{x \cdot x} \]
    2. times-fracN/A

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}} \cdot \left(x \cdot \frac{1}{4} + 1\right) + \sqrt{x}\right) - \sqrt{\frac{1}{x}}}{x} \cdot \frac{\frac{1}{2}}{x}} \]
    3. *-lowering-*.f64N/A

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

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

    \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \frac{-1 \cdot \sqrt{\frac{1}{x}} + \frac{1}{4} \cdot \sqrt{\frac{1}{x}}}{x}}{x}} \]
  8. Step-by-step derivation
    1. /-lowering-/.f64N/A

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\sqrt{\frac{1}{x}} \cdot \left(1 + \frac{-0.75}{x}\right)\right)}{x}} \]
  10. Taylor expanded in x around inf

    \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{x}}}}{x} \]
  11. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{x}}}}{x} \]
    2. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{\frac{1}{2} \cdot \color{blue}{\sqrt{\frac{1}{x}}}}{x} \]
    3. /-lowering-/.f6498.8

      \[\leadsto \frac{0.5 \cdot \sqrt{\color{blue}{\frac{1}{x}}}}{x} \]
  12. Simplified98.8%

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

Alternative 4: 97.3% accurate, 1.3× speedup?

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

\\
\sqrt{\frac{1}{x}} \cdot \frac{0.5}{x}
\end{array}
Derivation
  1. Initial program 39.0%

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

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

    \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\mathsf{fma}\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}}, \mathsf{fma}\left(x, 0.25, 1\right), \sqrt{x}\right) - \sqrt{\frac{1}{x}}\right)}{x \cdot x}} \]
  5. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\left(\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}} \cdot \left(x \cdot \frac{1}{4} + 1\right) + \sqrt{x}\right) - \sqrt{\frac{1}{x}}\right) \cdot \frac{1}{2}}}{x \cdot x} \]
    2. times-fracN/A

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\frac{1}{x \cdot \left(x \cdot x\right)}} \cdot \left(x \cdot \frac{1}{4} + 1\right) + \sqrt{x}\right) - \sqrt{\frac{1}{x}}}{x} \cdot \frac{\frac{1}{2}}{x}} \]
    3. *-lowering-*.f64N/A

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

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

    \[\leadsto \color{blue}{\sqrt{\frac{1}{x}}} \cdot \frac{\frac{1}{2}}{x} \]
  8. Step-by-step derivation
    1. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \color{blue}{\sqrt{\frac{1}{x}}} \cdot \frac{\frac{1}{2}}{x} \]
    2. /-lowering-/.f6498.6

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

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

Alternative 5: 97.4% accurate, 1.4× speedup?

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

\\
\frac{1}{\left(0.5 + \left(x + x\right)\right) \cdot \sqrt{1 + x}}
\end{array}
Derivation
  1. Initial program 39.0%

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

    \[\leadsto \color{blue}{\frac{\left(1 + x\right) - x}{x + \sqrt{\mathsf{fma}\left(x, x, x\right)}} \cdot \frac{1}{\sqrt{1 + x}}} \]
  4. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \color{blue}{\frac{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}{\sqrt{1 + x}}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    3. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    5. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    6. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    7. associate--l+N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1 + \left(x - x\right)}}{x + \sqrt{x \cdot x + x}}}} \]
    8. +-inversesN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1 + \color{blue}{0}}{x + \sqrt{x \cdot x + x}}}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1}}{x + \sqrt{x \cdot x + x}}}} \]
    10. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\color{blue}{\frac{1}{x + \sqrt{x \cdot x + x}}}}} \]
    11. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{\color{blue}{x + \sqrt{x \cdot x + x}}}}} \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\sqrt{x \cdot x + x}}}}} \]
    13. accelerator-lowering-fma.f6483.4

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

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

    \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{x \cdot \left(1 + \frac{1}{2} \cdot \frac{1}{x}\right)}}}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + x \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{x} + 1\right)}}}} \]
    2. distribute-rgt-inN/A

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

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x\right)}}} \]
    4. lft-mult-inverseN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} \cdot \color{blue}{1} + 1 \cdot x\right)}}} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2}} + 1 \cdot x\right)}}} \]
    6. *-lft-identityN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} + \color{blue}{x}\right)}}} \]
    7. +-lowering-+.f6498.0

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

    \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\left(0.5 + x\right)}}}} \]
  9. Step-by-step derivation
    1. associate-/r/N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + x}}{1} \cdot \left(x + \left(\frac{1}{2} + x\right)\right)}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{x + 1}}}{1} \cdot \left(x + \left(\frac{1}{2} + x\right)\right)} \]
    3. /-rgt-identityN/A

      \[\leadsto \frac{1}{\color{blue}{\sqrt{x + 1}} \cdot \left(x + \left(\frac{1}{2} + x\right)\right)} \]
    4. *-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\left(x + \left(\frac{1}{2} + x\right)\right) \cdot \sqrt{x + 1}}} \]
    5. *-lowering-*.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\left(x + \left(\frac{1}{2} + x\right)\right) \cdot \sqrt{x + 1}}} \]
    6. associate-+r+N/A

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\frac{1}{2} + \left(x + x\right)\right)} \cdot \sqrt{x + 1}} \]
    9. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\left(\frac{1}{2} + \left(x + x\right)\right)} \cdot \sqrt{x + 1}} \]
    10. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\left(\frac{1}{2} + \color{blue}{\left(x + x\right)}\right) \cdot \sqrt{x + 1}} \]
    11. +-commutativeN/A

      \[\leadsto \frac{1}{\left(\frac{1}{2} + \left(x + x\right)\right) \cdot \sqrt{\color{blue}{1 + x}}} \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\left(\frac{1}{2} + \left(x + x\right)\right) \cdot \color{blue}{\sqrt{1 + x}}} \]
    13. +-lowering-+.f6498.1

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

    \[\leadsto \frac{1}{\color{blue}{\left(0.5 + \left(x + x\right)\right) \cdot \sqrt{1 + x}}} \]
  11. Add Preprocessing

Alternative 6: 96.2% accurate, 1.8× speedup?

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

\\
\frac{0.5}{x \cdot \sqrt{x}}
\end{array}
Derivation
  1. Initial program 39.0%

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

    \[\leadsto \color{blue}{\frac{\left(1 + x\right) - x}{x + \sqrt{\mathsf{fma}\left(x, x, x\right)}} \cdot \frac{1}{\sqrt{1 + x}}} \]
  4. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \color{blue}{\frac{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}{\sqrt{1 + x}}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    3. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    5. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    6. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    7. associate--l+N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1 + \left(x - x\right)}}{x + \sqrt{x \cdot x + x}}}} \]
    8. +-inversesN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1 + \color{blue}{0}}{x + \sqrt{x \cdot x + x}}}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1}}{x + \sqrt{x \cdot x + x}}}} \]
    10. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\color{blue}{\frac{1}{x + \sqrt{x \cdot x + x}}}}} \]
    11. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{\color{blue}{x + \sqrt{x \cdot x + x}}}}} \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\sqrt{x \cdot x + x}}}}} \]
    13. accelerator-lowering-fma.f6483.4

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

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

    \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{{x}^{3}}}} \]
  7. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{x}^{3}} \cdot 2}} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{x}^{3}} \cdot 2}} \]
    3. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{x}^{3}}} \cdot 2} \]
    4. cube-multN/A

      \[\leadsto \frac{1}{\sqrt{\color{blue}{x \cdot \left(x \cdot x\right)}} \cdot 2} \]
    5. unpow2N/A

      \[\leadsto \frac{1}{\sqrt{x \cdot \color{blue}{{x}^{2}}} \cdot 2} \]
    6. *-lowering-*.f64N/A

      \[\leadsto \frac{1}{\sqrt{\color{blue}{x \cdot {x}^{2}}} \cdot 2} \]
    7. unpow2N/A

      \[\leadsto \frac{1}{\sqrt{x \cdot \color{blue}{\left(x \cdot x\right)}} \cdot 2} \]
    8. *-lowering-*.f6466.1

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

    \[\leadsto \frac{1}{\color{blue}{\sqrt{x \cdot \left(x \cdot x\right)} \cdot 2}} \]
  9. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{2 \cdot \sqrt{x \cdot \left(x \cdot x\right)}}} \]
    2. associate-/r*N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{\sqrt{x \cdot \left(x \cdot x\right)}}} \]
    3. metadata-evalN/A

      \[\leadsto \frac{\color{blue}{\frac{1}{2}}}{\sqrt{x \cdot \left(x \cdot x\right)}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{\sqrt{x \cdot \left(x \cdot x\right)}}} \]
    5. cube-unmultN/A

      \[\leadsto \frac{\frac{1}{2}}{\sqrt{\color{blue}{{x}^{3}}}} \]
    6. sqrt-pow1N/A

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{{x}^{\left(\frac{3}{2}\right)}}} \]
    7. sqrt-pow2N/A

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{{\left(\sqrt{x}\right)}^{3}}} \]
    8. unpow3N/A

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right) \cdot \sqrt{x}}} \]
    9. rem-square-sqrtN/A

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{x} \cdot \sqrt{x}} \]
    10. *-lowering-*.f64N/A

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{x \cdot \sqrt{x}}} \]
    11. sqrt-lowering-sqrt.f6497.5

      \[\leadsto \frac{0.5}{x \cdot \color{blue}{\sqrt{x}}} \]
  10. Applied egg-rr97.5%

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

Alternative 7: 38.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.9375, 2.25\right), 0.5\right)} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (fma x (fma x 0.9375 2.25) 0.5)))
double code(double x) {
	return 1.0 / fma(x, fma(x, 0.9375, 2.25), 0.5);
}
function code(x)
	return Float64(1.0 / fma(x, fma(x, 0.9375, 2.25), 0.5))
end
code[x_] := N[(1.0 / N[(x * N[(x * 0.9375 + 2.25), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.9375, 2.25\right), 0.5\right)}
\end{array}
Derivation
  1. Initial program 39.0%

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

    \[\leadsto \color{blue}{\frac{\left(1 + x\right) - x}{x + \sqrt{\mathsf{fma}\left(x, x, x\right)}} \cdot \frac{1}{\sqrt{1 + x}}} \]
  4. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \color{blue}{\frac{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}{\sqrt{1 + x}}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    3. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    5. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    6. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    7. associate--l+N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1 + \left(x - x\right)}}{x + \sqrt{x \cdot x + x}}}} \]
    8. +-inversesN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1 + \color{blue}{0}}{x + \sqrt{x \cdot x + x}}}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1}}{x + \sqrt{x \cdot x + x}}}} \]
    10. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\color{blue}{\frac{1}{x + \sqrt{x \cdot x + x}}}}} \]
    11. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{\color{blue}{x + \sqrt{x \cdot x + x}}}}} \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\sqrt{x \cdot x + x}}}}} \]
    13. accelerator-lowering-fma.f6483.4

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

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

    \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{x \cdot \left(1 + \frac{1}{2} \cdot \frac{1}{x}\right)}}}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + x \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{x} + 1\right)}}}} \]
    2. distribute-rgt-inN/A

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

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x\right)}}} \]
    4. lft-mult-inverseN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} \cdot \color{blue}{1} + 1 \cdot x\right)}}} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2}} + 1 \cdot x\right)}}} \]
    6. *-lft-identityN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} + \color{blue}{x}\right)}}} \]
    7. +-lowering-+.f6498.0

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{2} + x \cdot \left(\frac{9}{4} + \frac{15}{16} \cdot x\right)}} \]
  10. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{9}{4} + \frac{15}{16} \cdot x\right) + \frac{1}{2}}} \]
    2. accelerator-lowering-fma.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{9}{4} + \frac{15}{16} \cdot x, \frac{1}{2}\right)}} \]
    3. +-commutativeN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(x, \color{blue}{\frac{15}{16} \cdot x + \frac{9}{4}}, \frac{1}{2}\right)} \]
    4. *-commutativeN/A

      \[\leadsto \frac{1}{\mathsf{fma}\left(x, \color{blue}{x \cdot \frac{15}{16}} + \frac{9}{4}, \frac{1}{2}\right)} \]
    5. accelerator-lowering-fma.f6439.3

      \[\leadsto \frac{1}{\mathsf{fma}\left(x, \color{blue}{\mathsf{fma}\left(x, 0.9375, 2.25\right)}, 0.5\right)} \]
  11. Simplified39.3%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.9375, 2.25\right), 0.5\right)}} \]
  12. Add Preprocessing

Alternative 8: 7.9% accurate, 2.7× speedup?

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

\\
\frac{1}{\mathsf{fma}\left(x, 2.25, 0.5\right)}
\end{array}
Derivation
  1. Initial program 39.0%

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

    \[\leadsto \color{blue}{\frac{\left(1 + x\right) - x}{x + \sqrt{\mathsf{fma}\left(x, x, x\right)}} \cdot \frac{1}{\sqrt{1 + x}}} \]
  4. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \color{blue}{\frac{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}{\sqrt{1 + x}}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    3. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    5. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    6. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    7. associate--l+N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1 + \left(x - x\right)}}{x + \sqrt{x \cdot x + x}}}} \]
    8. +-inversesN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1 + \color{blue}{0}}{x + \sqrt{x \cdot x + x}}}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1}}{x + \sqrt{x \cdot x + x}}}} \]
    10. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\color{blue}{\frac{1}{x + \sqrt{x \cdot x + x}}}}} \]
    11. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{\color{blue}{x + \sqrt{x \cdot x + x}}}}} \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\sqrt{x \cdot x + x}}}}} \]
    13. accelerator-lowering-fma.f6483.4

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

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

    \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{x \cdot \left(1 + \frac{1}{2} \cdot \frac{1}{x}\right)}}}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + x \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{x} + 1\right)}}}} \]
    2. distribute-rgt-inN/A

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

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x\right)}}} \]
    4. lft-mult-inverseN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} \cdot \color{blue}{1} + 1 \cdot x\right)}}} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2}} + 1 \cdot x\right)}}} \]
    6. *-lft-identityN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} + \color{blue}{x}\right)}}} \]
    7. +-lowering-+.f6498.0

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{2} + \frac{9}{4} \cdot x}} \]
  10. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{9}{4} \cdot x + \frac{1}{2}}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{9}{4}} + \frac{1}{2}} \]
    3. accelerator-lowering-fma.f647.7

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, 2.25, 0.5\right)}} \]
  11. Simplified7.7%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, 2.25, 0.5\right)}} \]
  12. Add Preprocessing

Alternative 9: 4.6% accurate, 49.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{\left(1 + x\right) - x}{x + \sqrt{\mathsf{fma}\left(x, x, x\right)}} \cdot \frac{1}{\sqrt{1 + x}}} \]
  4. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \color{blue}{\frac{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}{\sqrt{1 + x}}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    3. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + x}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}}} \]
    5. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    6. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{\color{blue}{1 + x}}}{\frac{\left(1 + x\right) - x}{x + \sqrt{x \cdot x + x}}}} \]
    7. associate--l+N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1 + \left(x - x\right)}}{x + \sqrt{x \cdot x + x}}}} \]
    8. +-inversesN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1 + \color{blue}{0}}{x + \sqrt{x \cdot x + x}}}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{\color{blue}{1}}{x + \sqrt{x \cdot x + x}}}} \]
    10. /-lowering-/.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\color{blue}{\frac{1}{x + \sqrt{x \cdot x + x}}}}} \]
    11. +-lowering-+.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{\color{blue}{x + \sqrt{x \cdot x + x}}}}} \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{\sqrt{x \cdot x + x}}}}} \]
    13. accelerator-lowering-fma.f6483.4

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

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

    \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \color{blue}{x \cdot \left(1 + \frac{1}{2} \cdot \frac{1}{x}\right)}}}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + x \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{x} + 1\right)}}}} \]
    2. distribute-rgt-inN/A

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

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2} \cdot \left(\frac{1}{x} \cdot x\right)} + 1 \cdot x\right)}}} \]
    4. lft-mult-inverseN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} \cdot \color{blue}{1} + 1 \cdot x\right)}}} \]
    5. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\color{blue}{\frac{1}{2}} + 1 \cdot x\right)}}} \]
    6. *-lft-identityN/A

      \[\leadsto \frac{1}{\frac{\sqrt{1 + x}}{\frac{1}{x + \left(\frac{1}{2} + \color{blue}{x}\right)}}} \]
    7. +-lowering-+.f6498.0

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

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

    \[\leadsto \color{blue}{2} \]
  10. Step-by-step derivation
    1. Simplified4.5%

      \[\leadsto \color{blue}{2} \]
    2. Add Preprocessing

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

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

    Developer Target 2: 39.4% accurate, 0.2× speedup?

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

    Reproduce

    ?
    herbie shell --seed 2024198 
    (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))))))
    
      :alt
      (! :herbie-platform default (- (pow x -1/2) (pow (+ x 1) -1/2)))
    
      (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))