2sqrt (example 3.1)

Percentage Accurate: 7.0% → 99.3%
Time: 7.3s
Alternatives: 10
Speedup: 1.2×

Specification

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

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

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

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

Alternative 1: 99.3% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{{x}^{-1}}\\
\mathsf{fma}\left(t\_0, 0.5, \frac{\mathsf{fma}\left(0.125, t\_0, \frac{\mathsf{fma}\left({x}^{-1.5}, 0.0390625, \frac{-0.0625}{\sqrt{x}}\right)}{x}\right)}{-x}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 6.1%

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \left(\frac{-5}{128} \cdot \sqrt{\frac{1}{{x}^{5}}} + \left(\frac{1}{16} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{x}\right)\right)}{x}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \left(\frac{-5}{128} \cdot \sqrt{\frac{1}{{x}^{5}}} + \left(\frac{1}{16} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{x}\right)\right)}{x}} \]
  5. Applied rewrites99.5%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sqrt{\frac{1}{{x}^{5}}}, -0.0390625, \mathsf{fma}\left(\sqrt{\frac{1}{{x}^{3}}}, 0.0625, \mathsf{fma}\left(\sqrt{\frac{1}{x}}, -0.125, 0.5 \cdot \sqrt{x}\right)\right)\right)}{x}} \]
  6. Applied rewrites99.5%

    \[\leadsto \mathsf{fma}\left({x}^{-3.5}, \color{blue}{-0.0390625}, \frac{\mathsf{fma}\left(\sqrt{x}, 0.5, \mathsf{fma}\left(0.0625, {x}^{-1.5}, \frac{-0.125}{\sqrt{x}}\right)\right)}{x}\right) \]
  7. Taylor expanded in x around -inf

    \[\leadsto -1 \cdot \frac{-1 \cdot \frac{\frac{-1}{16} \cdot \left(\sqrt{\frac{1}{x}} \cdot {\left(\sqrt{-1}\right)}^{2}\right) + \frac{5}{128} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot {\left(\sqrt{-1}\right)}^{2}\right)}{x} + \frac{1}{8} \cdot \sqrt{\frac{1}{x}}}{x} + \color{blue}{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{x}} \cdot {\left(\sqrt{-1}\right)}^{2}\right)} \]
  8. Applied rewrites99.7%

    \[\leadsto \mathsf{fma}\left(\sqrt{\frac{1}{x}}, \color{blue}{0.5}, \frac{\mathsf{fma}\left(0.125, \sqrt{\frac{1}{x}}, \frac{\mathsf{fma}\left(0.0390625, \sqrt{\frac{1}{{x}^{3}}}, -0.0625 \cdot \sqrt{\frac{1}{x}}\right)}{x}\right)}{-x}\right) \]
  9. Step-by-step derivation
    1. Applied rewrites99.7%

      \[\leadsto \mathsf{fma}\left(\sqrt{\frac{1}{x}}, 0.5, \frac{\mathsf{fma}\left(0.125, \sqrt{\frac{1}{x}}, \frac{\mathsf{fma}\left({x}^{-1.5}, 0.0390625, \frac{-0.0625}{\sqrt{x}}\right)}{x}\right)}{-x}\right) \]
    2. Final simplification99.7%

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

    Alternative 2: 99.2% accurate, 0.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{{x}^{-1}}\\ \mathsf{fma}\left(t\_0, 0.5, \frac{\mathsf{fma}\left(-0.125, t\_0, 0.0625 \cdot \sqrt{{\left({x}^{3}\right)}^{-1}}\right)}{x}\right) \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (let* ((t_0 (sqrt (pow x -1.0))))
       (fma
        t_0
        0.5
        (/ (fma -0.125 t_0 (* 0.0625 (sqrt (pow (pow x 3.0) -1.0)))) x))))
    double code(double x) {
    	double t_0 = sqrt(pow(x, -1.0));
    	return fma(t_0, 0.5, (fma(-0.125, t_0, (0.0625 * sqrt(pow(pow(x, 3.0), -1.0)))) / x));
    }
    
    function code(x)
    	t_0 = sqrt((x ^ -1.0))
    	return fma(t_0, 0.5, Float64(fma(-0.125, t_0, Float64(0.0625 * sqrt(((x ^ 3.0) ^ -1.0)))) / x))
    end
    
    code[x_] := Block[{t$95$0 = N[Sqrt[N[Power[x, -1.0], $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * 0.5 + N[(N[(-0.125 * t$95$0 + N[(0.0625 * N[Sqrt[N[Power[N[Power[x, 3.0], $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sqrt{{x}^{-1}}\\
    \mathsf{fma}\left(t\_0, 0.5, \frac{\mathsf{fma}\left(-0.125, t\_0, 0.0625 \cdot \sqrt{{\left({x}^{3}\right)}^{-1}}\right)}{x}\right)
    \end{array}
    \end{array}
    
    Derivation
    1. Initial program 6.1%

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

      \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \left(\frac{-5}{128} \cdot \sqrt{\frac{1}{{x}^{5}}} + \left(\frac{1}{16} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{x}\right)\right)}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \left(\frac{-5}{128} \cdot \sqrt{\frac{1}{{x}^{5}}} + \left(\frac{1}{16} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{x}\right)\right)}{x}} \]
    5. Applied rewrites99.5%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sqrt{\frac{1}{{x}^{5}}}, -0.0390625, \mathsf{fma}\left(\sqrt{\frac{1}{{x}^{3}}}, 0.0625, \mathsf{fma}\left(\sqrt{\frac{1}{x}}, -0.125, 0.5 \cdot \sqrt{x}\right)\right)\right)}{x}} \]
    6. Applied rewrites99.5%

      \[\leadsto \mathsf{fma}\left({x}^{-3.5}, \color{blue}{-0.0390625}, \frac{\mathsf{fma}\left(\sqrt{x}, 0.5, \mathsf{fma}\left(0.0625, {x}^{-1.5}, \frac{-0.125}{\sqrt{x}}\right)\right)}{x}\right) \]
    7. Taylor expanded in x around -inf

      \[\leadsto -1 \cdot \frac{\frac{1}{16} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot {\left(\sqrt{-1}\right)}^{2}\right) + \frac{1}{8} \cdot \sqrt{\frac{1}{x}}}{x} + \color{blue}{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{x}} \cdot {\left(\sqrt{-1}\right)}^{2}\right)} \]
    8. Step-by-step derivation
      1. Applied rewrites99.6%

        \[\leadsto \mathsf{fma}\left(\sqrt{\frac{1}{x}}, \color{blue}{0.5}, \frac{\mathsf{fma}\left(-0.125, \sqrt{\frac{1}{x}}, 0.0625 \cdot \sqrt{\frac{1}{{x}^{3}}}\right)}{x}\right) \]
      2. Final simplification99.6%

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

      Alternative 3: 99.0% accurate, 0.1× speedup?

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

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

        \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \left(\frac{1}{16} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{x}\right)}{x}} \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

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

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

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

      Alternative 4: 98.9% accurate, 0.1× speedup?

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

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

        \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \left(\frac{-5}{128} \cdot \sqrt{\frac{1}{{x}^{5}}} + \left(\frac{1}{16} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{x}\right)\right)}{x}} \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \left(\frac{-5}{128} \cdot \sqrt{\frac{1}{{x}^{5}}} + \left(\frac{1}{16} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{x}\right)\right)}{x}} \]
      5. Applied rewrites99.5%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sqrt{\frac{1}{{x}^{5}}}, -0.0390625, \mathsf{fma}\left(\sqrt{\frac{1}{{x}^{3}}}, 0.0625, \mathsf{fma}\left(\sqrt{\frac{1}{x}}, -0.125, 0.5 \cdot \sqrt{x}\right)\right)\right)}{x}} \]
      6. Taylor expanded in x around inf

        \[\leadsto \frac{-1}{8} \cdot \sqrt{\frac{1}{{x}^{3}}} + \color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{x}}} \]
      7. Step-by-step derivation
        1. Applied rewrites99.4%

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

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

        Alternative 5: 97.7% accurate, 0.2× speedup?

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} \cdot 0.5} \]
        6. Final simplification98.4%

          \[\leadsto \sqrt{{x}^{-1}} \cdot 0.5 \]
        7. Add Preprocessing

        Alternative 6: 98.7% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sqrt{\frac{1}{x}}, -0.125, 0.5 \cdot \sqrt{x}\right)}{x}} \]
        6. Step-by-step derivation
          1. Applied rewrites99.2%

            \[\leadsto \mathsf{fma}\left(\sqrt{x}, \color{blue}{\frac{-0.125}{x \cdot x}}, \frac{0.5}{\sqrt{x}}\right) \]
          2. Add Preprocessing

          Alternative 7: 98.7% accurate, 0.6× speedup?

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\sqrt{\frac{1}{x}}, -0.125, 0.5 \cdot \sqrt{x}\right)}{x}} \]
          6. Step-by-step derivation
            1. Applied rewrites99.1%

              \[\leadsto \frac{\mathsf{fma}\left(\sqrt{x}, 0.5, \frac{-0.125}{\sqrt{x}}\right)}{\color{blue}{x}} \]
            2. Add Preprocessing

            Alternative 8: 97.6% accurate, 1.2× speedup?

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

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

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

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

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

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

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

              \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} \cdot 0.5} \]
            6. Step-by-step derivation
              1. Applied rewrites98.2%

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

              Alternative 9: 4.4% accurate, 1.4× speedup?

              \[\begin{array}{l} \\ 0.5 \cdot x - \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(Float64(0.5 * x) - sqrt(x))
              end
              
              function tmp = code(x)
              	tmp = (0.5 * x) - sqrt(x);
              end
              
              code[x_] := N[(N[(0.5 * x), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              0.5 \cdot x - \sqrt{x}
              \end{array}
              
              Derivation
              1. Initial program 6.1%

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

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

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

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

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

                \[\leadsto \frac{1}{2} \cdot \color{blue}{x} - \sqrt{x} \]
              7. Step-by-step derivation
                1. Applied rewrites4.5%

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

                Alternative 10: 1.6% accurate, 1.9× speedup?

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

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

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

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

                  Developer Target 1: 97.9% accurate, 0.3× speedup?

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

                  Reproduce

                  ?
                  herbie shell --seed 2024340 
                  (FPCore (x)
                    :name "2sqrt (example 3.1)"
                    :precision binary64
                    :pre (and (> x 1.0) (< x 1e+308))
                  
                    :alt
                    (! :herbie-platform default (* 1/2 (pow x -1/2)))
                  
                    (- (sqrt (+ x 1.0)) (sqrt x)))