sqrt(x + 9) - sqrt(x)

Percentage Accurate: 53.2% → 99.8%
Time: 4.1s
Alternatives: 7
Speedup: 1.1×

Specification

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

\\
\sqrt{x + 9} - \sqrt{x}
\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: 53.2% accurate, 1.0× speedup?

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

\\
\sqrt{x + 9} - \sqrt{x}
\end{array}

Alternative 1: 99.8% accurate, 0.7× speedup?

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

\\
\frac{9}{\sqrt{x} + \sqrt{9 + x}}
\end{array}
Derivation
  1. Initial program 52.9%

    \[\sqrt{x + 9} - \sqrt{x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\sqrt{x + 9} - \sqrt{x}} \]
    2. flip--N/A

      \[\leadsto \color{blue}{\frac{\sqrt{x + 9} \cdot \sqrt{x + 9} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}}} \]
    3. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\sqrt{x + 9} \cdot \sqrt{x + 9} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}}} \]
    4. lift-sqrt.f64N/A

      \[\leadsto \frac{\color{blue}{\sqrt{x + 9}} \cdot \sqrt{x + 9} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}} \]
    5. lift-sqrt.f64N/A

      \[\leadsto \frac{\sqrt{x + 9} \cdot \color{blue}{\sqrt{x + 9}} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}} \]
    6. rem-square-sqrtN/A

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(9 + x\right) - x}{\color{blue}{\sqrt{x} + \sqrt{x + 9}}} \]
    15. lower-+.f6454.5

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

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

      \[\leadsto \frac{\left(9 + x\right) - x}{\sqrt{x} + \sqrt{\color{blue}{9 + x}}} \]
    18. lower-+.f6454.5

      \[\leadsto \frac{\left(9 + x\right) - x}{\sqrt{x} + \sqrt{\color{blue}{9 + x}}} \]
  4. Applied rewrites54.5%

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

    \[\leadsto \frac{\color{blue}{9}}{\sqrt{x} + \sqrt{9 + x}} \]
  6. Step-by-step derivation
    1. Applied rewrites99.8%

      \[\leadsto \frac{\color{blue}{9}}{\sqrt{x} + \sqrt{9 + x}} \]
    2. Add Preprocessing

    Alternative 2: 98.3% accurate, 0.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sqrt{x + 9} - \sqrt{x} \leq 0.001:\\ \;\;\;\;\sqrt{{x}^{-1}} \cdot 4.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right), x, 3\right) - \sqrt{x}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= (- (sqrt (+ x 9.0)) (sqrt x)) 0.001)
       (* (sqrt (pow x -1.0)) 4.5)
       (- (fma (fma -0.004629629629629629 x 0.16666666666666666) x 3.0) (sqrt x))))
    double code(double x) {
    	double tmp;
    	if ((sqrt((x + 9.0)) - sqrt(x)) <= 0.001) {
    		tmp = sqrt(pow(x, -1.0)) * 4.5;
    	} else {
    		tmp = fma(fma(-0.004629629629629629, x, 0.16666666666666666), x, 3.0) - sqrt(x);
    	}
    	return tmp;
    }
    
    function code(x)
    	tmp = 0.0
    	if (Float64(sqrt(Float64(x + 9.0)) - sqrt(x)) <= 0.001)
    		tmp = Float64(sqrt((x ^ -1.0)) * 4.5);
    	else
    		tmp = Float64(fma(fma(-0.004629629629629629, x, 0.16666666666666666), x, 3.0) - sqrt(x));
    	end
    	return tmp
    end
    
    code[x_] := If[LessEqual[N[(N[Sqrt[N[(x + 9.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[Sqrt[N[Power[x, -1.0], $MachinePrecision]], $MachinePrecision] * 4.5), $MachinePrecision], N[(N[(N[(-0.004629629629629629 * x + 0.16666666666666666), $MachinePrecision] * x + 3.0), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\sqrt{x + 9} - \sqrt{x} \leq 0.001:\\
    \;\;\;\;\sqrt{{x}^{-1}} \cdot 4.5\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right), x, 3\right) - \sqrt{x}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (sqrt.f64 (+.f64 x #s(literal 9 binary64))) (sqrt.f64 x)) < 1e-3

      1. Initial program 5.8%

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

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

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

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

          \[\leadsto \color{blue}{\sqrt{\frac{1}{x}}} \cdot \frac{9}{2} \]
        4. lower-/.f6498.7

          \[\leadsto \sqrt{\color{blue}{\frac{1}{x}}} \cdot 4.5 \]
      5. Applied rewrites98.7%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} \cdot 4.5} \]

      if 1e-3 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 9 binary64))) (sqrt.f64 x))

      1. Initial program 100.0%

        \[\sqrt{x + 9} - \sqrt{x} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

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

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{6} + \frac{-1}{216} \cdot x, x, 3\right)} - \sqrt{x} \]
        4. +-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{-1}{216} \cdot x + \frac{1}{6}}, x, 3\right) - \sqrt{x} \]
        5. lower-fma.f6498.2

          \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right)}, x, 3\right) - \sqrt{x} \]
      5. Applied rewrites98.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right), x, 3\right)} - \sqrt{x} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification98.4%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{x + 9} - \sqrt{x} \leq 0.001:\\ \;\;\;\;\sqrt{{x}^{-1}} \cdot 4.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right), x, 3\right) - \sqrt{x}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 3: 99.3% accurate, 0.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 9} - \sqrt{x}\\ \mathbf{if}\;t\_0 \leq 10^{-5}:\\ \;\;\;\;\frac{4.5 \cdot \sqrt{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (let* ((t_0 (- (sqrt (+ x 9.0)) (sqrt x))))
       (if (<= t_0 1e-5) (/ (* 4.5 (sqrt x)) x) t_0)))
    double code(double x) {
    	double t_0 = sqrt((x + 9.0)) - sqrt(x);
    	double tmp;
    	if (t_0 <= 1e-5) {
    		tmp = (4.5 * sqrt(x)) / x;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        real(8) :: t_0
        real(8) :: tmp
        t_0 = sqrt((x + 9.0d0)) - sqrt(x)
        if (t_0 <= 1d-5) then
            tmp = (4.5d0 * sqrt(x)) / x
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double t_0 = Math.sqrt((x + 9.0)) - Math.sqrt(x);
    	double tmp;
    	if (t_0 <= 1e-5) {
    		tmp = (4.5 * Math.sqrt(x)) / x;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(x):
    	t_0 = math.sqrt((x + 9.0)) - math.sqrt(x)
    	tmp = 0
    	if t_0 <= 1e-5:
    		tmp = (4.5 * math.sqrt(x)) / x
    	else:
    		tmp = t_0
    	return tmp
    
    function code(x)
    	t_0 = Float64(sqrt(Float64(x + 9.0)) - sqrt(x))
    	tmp = 0.0
    	if (t_0 <= 1e-5)
    		tmp = Float64(Float64(4.5 * sqrt(x)) / x);
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	t_0 = sqrt((x + 9.0)) - sqrt(x);
    	tmp = 0.0;
    	if (t_0 <= 1e-5)
    		tmp = (4.5 * sqrt(x)) / x;
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(x + 9.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(N[(4.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], t$95$0]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sqrt{x + 9} - \sqrt{x}\\
    \mathbf{if}\;t\_0 \leq 10^{-5}:\\
    \;\;\;\;\frac{4.5 \cdot \sqrt{x}}{x}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (sqrt.f64 (+.f64 x #s(literal 9 binary64))) (sqrt.f64 x)) < 1.00000000000000008e-5

      1. Initial program 5.3%

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

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

          \[\leadsto \color{blue}{\frac{\frac{-81}{8} \cdot \sqrt{\frac{1}{x}} + \frac{9}{2} \cdot \sqrt{x}}{x}} \]
        2. lower-fma.f64N/A

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{-81}{8}, \sqrt{\frac{1}{x}}, \frac{9}{2} \cdot \sqrt{x}\right)}}{x} \]
        3. lower-sqrt.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(\frac{-81}{8}, \color{blue}{\sqrt{\frac{1}{x}}}, \frac{9}{2} \cdot \sqrt{x}\right)}{x} \]
        4. lower-/.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(\frac{-81}{8}, \sqrt{\color{blue}{\frac{1}{x}}}, \frac{9}{2} \cdot \sqrt{x}\right)}{x} \]
        5. lower-*.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(\frac{-81}{8}, \sqrt{\frac{1}{x}}, \color{blue}{\frac{9}{2} \cdot \sqrt{x}}\right)}{x} \]
        6. lower-sqrt.f6499.5

          \[\leadsto \frac{\mathsf{fma}\left(-10.125, \sqrt{\frac{1}{x}}, 4.5 \cdot \color{blue}{\sqrt{x}}\right)}{x} \]
      5. Applied rewrites99.5%

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

        \[\leadsto \frac{\frac{-9}{2} \cdot \left(\sqrt{x} \cdot {\left(\sqrt{-1}\right)}^{2}\right)}{x} \]
      7. Step-by-step derivation
        1. Applied rewrites99.0%

          \[\leadsto \frac{4.5 \cdot \sqrt{x}}{x} \]

        if 1.00000000000000008e-5 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 9 binary64))) (sqrt.f64 x))

        1. Initial program 99.7%

          \[\sqrt{x + 9} - \sqrt{x} \]
        2. Add Preprocessing
      8. Recombined 2 regimes into one program.
      9. Add Preprocessing

      Alternative 4: 98.2% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sqrt{x + 9} - \sqrt{x} \leq 0.001:\\ \;\;\;\;\frac{4.5 \cdot \sqrt{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right), x, 3\right) - \sqrt{x}\\ \end{array} \end{array} \]
      (FPCore (x)
       :precision binary64
       (if (<= (- (sqrt (+ x 9.0)) (sqrt x)) 0.001)
         (/ (* 4.5 (sqrt x)) x)
         (- (fma (fma -0.004629629629629629 x 0.16666666666666666) x 3.0) (sqrt x))))
      double code(double x) {
      	double tmp;
      	if ((sqrt((x + 9.0)) - sqrt(x)) <= 0.001) {
      		tmp = (4.5 * sqrt(x)) / x;
      	} else {
      		tmp = fma(fma(-0.004629629629629629, x, 0.16666666666666666), x, 3.0) - sqrt(x);
      	}
      	return tmp;
      }
      
      function code(x)
      	tmp = 0.0
      	if (Float64(sqrt(Float64(x + 9.0)) - sqrt(x)) <= 0.001)
      		tmp = Float64(Float64(4.5 * sqrt(x)) / x);
      	else
      		tmp = Float64(fma(fma(-0.004629629629629629, x, 0.16666666666666666), x, 3.0) - sqrt(x));
      	end
      	return tmp
      end
      
      code[x_] := If[LessEqual[N[(N[Sqrt[N[(x + 9.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(4.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(N[(-0.004629629629629629 * x + 0.16666666666666666), $MachinePrecision] * x + 3.0), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\sqrt{x + 9} - \sqrt{x} \leq 0.001:\\
      \;\;\;\;\frac{4.5 \cdot \sqrt{x}}{x}\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right), x, 3\right) - \sqrt{x}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (sqrt.f64 (+.f64 x #s(literal 9 binary64))) (sqrt.f64 x)) < 1e-3

        1. Initial program 5.8%

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

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

            \[\leadsto \color{blue}{\frac{\frac{-81}{8} \cdot \sqrt{\frac{1}{x}} + \frac{9}{2} \cdot \sqrt{x}}{x}} \]
          2. lower-fma.f64N/A

            \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{-81}{8}, \sqrt{\frac{1}{x}}, \frac{9}{2} \cdot \sqrt{x}\right)}}{x} \]
          3. lower-sqrt.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left(\frac{-81}{8}, \color{blue}{\sqrt{\frac{1}{x}}}, \frac{9}{2} \cdot \sqrt{x}\right)}{x} \]
          4. lower-/.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left(\frac{-81}{8}, \sqrt{\color{blue}{\frac{1}{x}}}, \frac{9}{2} \cdot \sqrt{x}\right)}{x} \]
          5. lower-*.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left(\frac{-81}{8}, \sqrt{\frac{1}{x}}, \color{blue}{\frac{9}{2} \cdot \sqrt{x}}\right)}{x} \]
          6. lower-sqrt.f6499.5

            \[\leadsto \frac{\mathsf{fma}\left(-10.125, \sqrt{\frac{1}{x}}, 4.5 \cdot \color{blue}{\sqrt{x}}\right)}{x} \]
        5. Applied rewrites99.5%

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

          \[\leadsto \frac{\frac{-9}{2} \cdot \left(\sqrt{x} \cdot {\left(\sqrt{-1}\right)}^{2}\right)}{x} \]
        7. Step-by-step derivation
          1. Applied rewrites98.7%

            \[\leadsto \frac{4.5 \cdot \sqrt{x}}{x} \]

          if 1e-3 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 9 binary64))) (sqrt.f64 x))

          1. Initial program 100.0%

            \[\sqrt{x + 9} - \sqrt{x} \]
          2. Add Preprocessing
          3. Taylor expanded in x around 0

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

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

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{6} + \frac{-1}{216} \cdot x, x, 3\right)} - \sqrt{x} \]
            4. +-commutativeN/A

              \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{-1}{216} \cdot x + \frac{1}{6}}, x, 3\right) - \sqrt{x} \]
            5. lower-fma.f6498.2

              \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right)}, x, 3\right) - \sqrt{x} \]
          5. Applied rewrites98.2%

            \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(-0.004629629629629629, x, 0.16666666666666666\right), x, 3\right)} - \sqrt{x} \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 5: 58.4% accurate, 1.1× speedup?

        \[\begin{array}{l} \\ \frac{9}{3 + \sqrt{x}} \end{array} \]
        (FPCore (x) :precision binary64 (/ 9.0 (+ 3.0 (sqrt x))))
        double code(double x) {
        	return 9.0 / (3.0 + sqrt(x));
        }
        
        real(8) function code(x)
            real(8), intent (in) :: x
            code = 9.0d0 / (3.0d0 + sqrt(x))
        end function
        
        public static double code(double x) {
        	return 9.0 / (3.0 + Math.sqrt(x));
        }
        
        def code(x):
        	return 9.0 / (3.0 + math.sqrt(x))
        
        function code(x)
        	return Float64(9.0 / Float64(3.0 + sqrt(x)))
        end
        
        function tmp = code(x)
        	tmp = 9.0 / (3.0 + sqrt(x));
        end
        
        code[x_] := N[(9.0 / N[(3.0 + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \frac{9}{3 + \sqrt{x}}
        \end{array}
        
        Derivation
        1. Initial program 52.9%

          \[\sqrt{x + 9} - \sqrt{x} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift--.f64N/A

            \[\leadsto \color{blue}{\sqrt{x + 9} - \sqrt{x}} \]
          2. flip--N/A

            \[\leadsto \color{blue}{\frac{\sqrt{x + 9} \cdot \sqrt{x + 9} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}}} \]
          3. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{\sqrt{x + 9} \cdot \sqrt{x + 9} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}}} \]
          4. lift-sqrt.f64N/A

            \[\leadsto \frac{\color{blue}{\sqrt{x + 9}} \cdot \sqrt{x + 9} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}} \]
          5. lift-sqrt.f64N/A

            \[\leadsto \frac{\sqrt{x + 9} \cdot \color{blue}{\sqrt{x + 9}} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 9} + \sqrt{x}} \]
          6. rem-square-sqrtN/A

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\left(9 + x\right) - x}{\color{blue}{\sqrt{x} + \sqrt{x + 9}}} \]
          15. lower-+.f6454.5

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

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

            \[\leadsto \frac{\left(9 + x\right) - x}{\sqrt{x} + \sqrt{\color{blue}{9 + x}}} \]
          18. lower-+.f6454.5

            \[\leadsto \frac{\left(9 + x\right) - x}{\sqrt{x} + \sqrt{\color{blue}{9 + x}}} \]
        4. Applied rewrites54.5%

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

          \[\leadsto \color{blue}{\frac{9}{3 + \sqrt{x}}} \]
        6. Step-by-step derivation
          1. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{9}{3 + \sqrt{x}}} \]
          2. lower-+.f64N/A

            \[\leadsto \frac{9}{\color{blue}{3 + \sqrt{x}}} \]
          3. lower-sqrt.f6458.0

            \[\leadsto \frac{9}{3 + \color{blue}{\sqrt{x}}} \]
        7. Applied rewrites58.0%

          \[\leadsto \color{blue}{\frac{9}{3 + \sqrt{x}}} \]
        8. Add Preprocessing

        Alternative 6: 51.8% accurate, 1.4× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(0.16666666666666666, x, 3 - \sqrt{x}\right) \end{array} \]
        (FPCore (x) :precision binary64 (fma 0.16666666666666666 x (- 3.0 (sqrt x))))
        double code(double x) {
        	return fma(0.16666666666666666, x, (3.0 - sqrt(x)));
        }
        
        function code(x)
        	return fma(0.16666666666666666, x, Float64(3.0 - sqrt(x)))
        end
        
        code[x_] := N[(0.16666666666666666 * x + N[(3.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \mathsf{fma}\left(0.16666666666666666, x, 3 - \sqrt{x}\right)
        \end{array}
        
        Derivation
        1. Initial program 52.9%

          \[\sqrt{x + 9} - \sqrt{x} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{6}, x, 3 - \sqrt{x}\right)} \]
          4. lower--.f64N/A

            \[\leadsto \mathsf{fma}\left(\frac{1}{6}, x, \color{blue}{3 - \sqrt{x}}\right) \]
          5. lower-sqrt.f6451.1

            \[\leadsto \mathsf{fma}\left(0.16666666666666666, x, 3 - \color{blue}{\sqrt{x}}\right) \]
        5. Applied rewrites51.1%

          \[\leadsto \color{blue}{\mathsf{fma}\left(0.16666666666666666, x, 3 - \sqrt{x}\right)} \]
        6. Add Preprocessing

        Alternative 7: 49.8% accurate, 1.9× speedup?

        \[\begin{array}{l} \\ 3 - \sqrt{x} \end{array} \]
        (FPCore (x) :precision binary64 (- 3.0 (sqrt x)))
        double code(double x) {
        	return 3.0 - sqrt(x);
        }
        
        real(8) function code(x)
            real(8), intent (in) :: x
            code = 3.0d0 - sqrt(x)
        end function
        
        public static double code(double x) {
        	return 3.0 - Math.sqrt(x);
        }
        
        def code(x):
        	return 3.0 - math.sqrt(x)
        
        function code(x)
        	return Float64(3.0 - sqrt(x))
        end
        
        function tmp = code(x)
        	tmp = 3.0 - sqrt(x);
        end
        
        code[x_] := N[(3.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        3 - \sqrt{x}
        \end{array}
        
        Derivation
        1. Initial program 52.9%

          \[\sqrt{x + 9} - \sqrt{x} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{3} - \sqrt{x} \]
        4. Step-by-step derivation
          1. Applied rewrites49.4%

            \[\leadsto \color{blue}{3} - \sqrt{x} \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 1 
          (FPCore (x)
            :name "sqrt(x + 9) - sqrt(x)"
            :precision binary64
            :pre (and (<= 0.0 x) (<= x 1.79e+308))
            (- (sqrt (+ x 9.0)) (sqrt x)))