bug333 (missed optimization)

Percentage Accurate: 8.4% → 99.8%
Time: 9.5s
Alternatives: 9
Speedup: 1.8×

Specification

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

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

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

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

Alternative 1: 99.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x \cdot x, 0.125 \cdot x, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), {x}^{5}, x\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (fma
  (* x x)
  (* 0.125 x)
  (fma (fma 0.0322265625 (* x x) 0.0546875) (pow x 5.0) x)))
double code(double x) {
	return fma((x * x), (0.125 * x), fma(fma(0.0322265625, (x * x), 0.0546875), pow(x, 5.0), x));
}
function code(x)
	return fma(Float64(x * x), Float64(0.125 * x), fma(fma(0.0322265625, Float64(x * x), 0.0546875), (x ^ 5.0), x))
end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(0.125 * x), $MachinePrecision] + N[(N[(0.0322265625 * N[(x * x), $MachinePrecision] + 0.0546875), $MachinePrecision] * N[Power[x, 5.0], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x \cdot x, 0.125 \cdot x, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), {x}^{5}, x\right)\right)
\end{array}
Derivation
  1. Initial program 8.9%

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

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

      \[\leadsto x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + 1\right)} \]
    2. distribute-lft-inN/A

      \[\leadsto \color{blue}{x \cdot \left({x}^{2} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right)\right) + x \cdot 1} \]
    3. associate-*r*N/A

      \[\leadsto \color{blue}{\left(x \cdot {x}^{2}\right) \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right)} + x \cdot 1 \]
    4. unpow2N/A

      \[\leadsto \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + x \cdot 1 \]
    5. cube-multN/A

      \[\leadsto \color{blue}{{x}^{3}} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + x \cdot 1 \]
    6. *-rgt-identityN/A

      \[\leadsto {x}^{3} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + \color{blue}{x} \]
    7. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, \frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right), x\right)} \]
    8. lower-pow.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{3}}, \frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right), x\right) \]
    9. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{{x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right) + \frac{1}{8}}, x\right) \]
    10. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{\left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right) \cdot {x}^{2}} + \frac{1}{8}, x\right) \]
    11. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{\mathsf{fma}\left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}, {x}^{2}, \frac{1}{8}\right)}, x\right) \]
    12. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\color{blue}{\frac{33}{1024} \cdot {x}^{2} + \frac{7}{128}}, {x}^{2}, \frac{1}{8}\right), x\right) \]
    13. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{33}{1024}, {x}^{2}, \frac{7}{128}\right)}, {x}^{2}, \frac{1}{8}\right), x\right) \]
    14. unpow2N/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, \color{blue}{x \cdot x}, \frac{7}{128}\right), {x}^{2}, \frac{1}{8}\right), x\right) \]
    15. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, \color{blue}{x \cdot x}, \frac{7}{128}\right), {x}^{2}, \frac{1}{8}\right), x\right) \]
    16. unpow2N/A

      \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, x \cdot x, \frac{7}{128}\right), \color{blue}{x \cdot x}, \frac{1}{8}\right), x\right) \]
    17. lower-*.f6499.4

      \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), \color{blue}{x \cdot x}, 0.125\right), x\right) \]
  5. Applied rewrites99.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), x \cdot x, 0.125\right), x\right)} \]
  6. Step-by-step derivation
    1. Applied rewrites99.4%

      \[\leadsto \mathsf{fma}\left(\left(\left(\mathsf{fma}\left(x \cdot x, 0.0322265625, 0.0546875\right) \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right), \color{blue}{x}, \mathsf{fma}\left(0.125, {x}^{3}, x\right)\right) \]
    2. Step-by-step derivation
      1. Applied rewrites99.4%

        \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{0.125 \cdot x}, x + \mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right) \cdot {x}^{5}\right) \]
      2. Step-by-step derivation
        1. Applied rewrites99.4%

          \[\leadsto \mathsf{fma}\left(x \cdot x, 0.125 \cdot x, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), {x}^{5}, x\right)\right) \]
        2. Add Preprocessing

        Alternative 2: 99.8% accurate, 0.8× speedup?

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

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

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

            \[\leadsto x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + 1\right)} \]
          2. distribute-lft-inN/A

            \[\leadsto \color{blue}{x \cdot \left({x}^{2} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right)\right) + x \cdot 1} \]
          3. associate-*r*N/A

            \[\leadsto \color{blue}{\left(x \cdot {x}^{2}\right) \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right)} + x \cdot 1 \]
          4. unpow2N/A

            \[\leadsto \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + x \cdot 1 \]
          5. cube-multN/A

            \[\leadsto \color{blue}{{x}^{3}} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + x \cdot 1 \]
          6. *-rgt-identityN/A

            \[\leadsto {x}^{3} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + \color{blue}{x} \]
          7. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, \frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right), x\right)} \]
          8. lower-pow.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{3}}, \frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right), x\right) \]
          9. +-commutativeN/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{{x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right) + \frac{1}{8}}, x\right) \]
          10. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{\left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right) \cdot {x}^{2}} + \frac{1}{8}, x\right) \]
          11. lower-fma.f64N/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{\mathsf{fma}\left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}, {x}^{2}, \frac{1}{8}\right)}, x\right) \]
          12. +-commutativeN/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\color{blue}{\frac{33}{1024} \cdot {x}^{2} + \frac{7}{128}}, {x}^{2}, \frac{1}{8}\right), x\right) \]
          13. lower-fma.f64N/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{33}{1024}, {x}^{2}, \frac{7}{128}\right)}, {x}^{2}, \frac{1}{8}\right), x\right) \]
          14. unpow2N/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, \color{blue}{x \cdot x}, \frac{7}{128}\right), {x}^{2}, \frac{1}{8}\right), x\right) \]
          15. lower-*.f64N/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, \color{blue}{x \cdot x}, \frac{7}{128}\right), {x}^{2}, \frac{1}{8}\right), x\right) \]
          16. unpow2N/A

            \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, x \cdot x, \frac{7}{128}\right), \color{blue}{x \cdot x}, \frac{1}{8}\right), x\right) \]
          17. lower-*.f6499.4

            \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), \color{blue}{x \cdot x}, 0.125\right), x\right) \]
        5. Applied rewrites99.4%

          \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), x \cdot x, 0.125\right), x\right)} \]
        6. Step-by-step derivation
          1. Applied rewrites99.4%

            \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0322265625, 0.0546875\right), x \cdot x, 0.125\right) \cdot \left(x \cdot x\right), \color{blue}{x}, x\right) \]
          2. Add Preprocessing

          Alternative 3: 99.8% accurate, 1.1× speedup?

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

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

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

              \[\leadsto x \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + 1\right)} \]
            2. distribute-lft-inN/A

              \[\leadsto \color{blue}{x \cdot \left({x}^{2} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right)\right) + x \cdot 1} \]
            3. associate-*r*N/A

              \[\leadsto \color{blue}{\left(x \cdot {x}^{2}\right) \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right)} + x \cdot 1 \]
            4. unpow2N/A

              \[\leadsto \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + x \cdot 1 \]
            5. cube-multN/A

              \[\leadsto \color{blue}{{x}^{3}} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + x \cdot 1 \]
            6. *-rgt-identityN/A

              \[\leadsto {x}^{3} \cdot \left(\frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right)\right) + \color{blue}{x} \]
            7. lower-fma.f64N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, \frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right), x\right)} \]
            8. lower-pow.f64N/A

              \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{3}}, \frac{1}{8} + {x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right), x\right) \]
            9. +-commutativeN/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{{x}^{2} \cdot \left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right) + \frac{1}{8}}, x\right) \]
            10. *-commutativeN/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{\left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}\right) \cdot {x}^{2}} + \frac{1}{8}, x\right) \]
            11. lower-fma.f64N/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \color{blue}{\mathsf{fma}\left(\frac{7}{128} + \frac{33}{1024} \cdot {x}^{2}, {x}^{2}, \frac{1}{8}\right)}, x\right) \]
            12. +-commutativeN/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\color{blue}{\frac{33}{1024} \cdot {x}^{2} + \frac{7}{128}}, {x}^{2}, \frac{1}{8}\right), x\right) \]
            13. lower-fma.f64N/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{33}{1024}, {x}^{2}, \frac{7}{128}\right)}, {x}^{2}, \frac{1}{8}\right), x\right) \]
            14. unpow2N/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, \color{blue}{x \cdot x}, \frac{7}{128}\right), {x}^{2}, \frac{1}{8}\right), x\right) \]
            15. lower-*.f64N/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, \color{blue}{x \cdot x}, \frac{7}{128}\right), {x}^{2}, \frac{1}{8}\right), x\right) \]
            16. unpow2N/A

              \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{33}{1024}, x \cdot x, \frac{7}{128}\right), \color{blue}{x \cdot x}, \frac{1}{8}\right), x\right) \]
            17. lower-*.f6499.4

              \[\leadsto \mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), \color{blue}{x \cdot x}, 0.125\right), x\right) \]
          5. Applied rewrites99.4%

            \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(0.0322265625, x \cdot x, 0.0546875\right), x \cdot x, 0.125\right), x\right)} \]
          6. Step-by-step derivation
            1. Applied rewrites99.4%

              \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0322265625, 0.0546875\right), x \cdot x, 0.125\right) \cdot \left(x \cdot x\right), \color{blue}{x}, x\right) \]
            2. Taylor expanded in x around 0

              \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{7}{128}, x \cdot x, \frac{1}{8}\right) \cdot \left(x \cdot x\right), x, x\right) \]
            3. Step-by-step derivation
              1. Applied rewrites99.3%

                \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(0.0546875, x \cdot x, 0.125\right) \cdot \left(x \cdot x\right), x, x\right) \]
              2. Add Preprocessing

              Alternative 4: 99.6% accurate, 1.8× speedup?

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

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

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

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

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

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

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

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

                  \[\leadsto \color{blue}{{x}^{3}} \cdot \frac{1}{8} + x \cdot 1 \]
                7. *-rgt-identityN/A

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

                  \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, \frac{1}{8}, x\right)} \]
                9. lower-pow.f6498.9

                  \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{3}}, 0.125, x\right) \]
              5. Applied rewrites98.9%

                \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, 0.125, x\right)} \]
              6. Step-by-step derivation
                1. Applied rewrites98.9%

                  \[\leadsto \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, 0.125, x\right) \]
                2. Add Preprocessing

                Alternative 5: 7.8% accurate, 1.9× speedup?

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

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

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

                    \[\leadsto \color{blue}{1} - \sqrt{1 - x} \]
                  2. Taylor expanded in x around 0

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

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

                      \[\leadsto 1 - \color{blue}{\mathsf{fma}\left(-0.5, x, 1\right)} \]
                  4. Applied rewrites6.2%

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

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

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

                      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, x, 1\right)} - \mathsf{fma}\left(-0.5, x, 1\right) \]
                  7. Applied rewrites7.6%

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

                  Alternative 6: 6.2% accurate, 1.9× speedup?

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

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

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

                      \[\leadsto \color{blue}{1} - \sqrt{1 - x} \]
                    2. Taylor expanded in x around 0

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

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

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

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

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

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

                        \[\leadsto 1 - \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(-0.125, x, -0.5\right)}, x, 1\right) \]
                    4. Applied rewrites6.2%

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

                    Alternative 7: 6.2% accurate, 3.0× speedup?

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

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

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

                        \[\leadsto \color{blue}{1} - \sqrt{1 - x} \]
                      2. Taylor expanded in x around 0

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

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

                          \[\leadsto 1 - \color{blue}{\mathsf{fma}\left(-0.5, x, 1\right)} \]
                      4. Applied rewrites6.2%

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

                      Alternative 8: 3.8% accurate, 3.3× speedup?

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

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

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

                          \[\leadsto \color{blue}{1} - \sqrt{1 - x} \]
                        2. Taylor expanded in x around 0

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

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

                            \[\leadsto 1 - \color{blue}{\mathsf{fma}\left(-0.5, x, 1\right)} \]
                        4. Applied rewrites6.2%

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

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

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

                          Alternative 9: 5.4% accurate, 7.5× speedup?

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

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

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

                              \[\leadsto \color{blue}{1} - \sqrt{1 - x} \]
                            2. Taylor expanded in x around 0

                              \[\leadsto 1 - \color{blue}{1} \]
                            3. Step-by-step derivation
                              1. Applied rewrites5.2%

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

                              Developer Target 1: 100.0% accurate, 0.7× speedup?

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

                              Reproduce

                              ?
                              herbie shell --seed 2024249 
                              (FPCore (x)
                                :name "bug333 (missed optimization)"
                                :precision binary64
                                :pre (and (<= -1.0 x) (<= x 1.0))
                              
                                :alt
                                (! :herbie-platform default (/ (* 2 x) (+ (sqrt (+ 1 x)) (sqrt (- 1 x)))))
                              
                                (- (sqrt (+ 1.0 x)) (sqrt (- 1.0 x))))