Falkner and Boettcher, Appendix B, 2

Percentage Accurate: 100.0% → 100.0%
Time: 7.0s
Alternatives: 4
Speedup: 1.7×

Specification

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

\\
\left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

\\
\left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right)
\end{array}

Alternative 1: 100.0% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \sqrt{2} \cdot \left(\left(0.25 \cdot \sqrt{\mathsf{fma}\left(v \cdot v, -3, 1\right)}\right) \cdot \left(1 - v \cdot v\right)\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (* (sqrt 2.0) (* (* 0.25 (sqrt (fma (* v v) -3.0 1.0))) (- 1.0 (* v v)))))
double code(double v) {
	return sqrt(2.0) * ((0.25 * sqrt(fma((v * v), -3.0, 1.0))) * (1.0 - (v * v)));
}
function code(v)
	return Float64(sqrt(2.0) * Float64(Float64(0.25 * sqrt(fma(Float64(v * v), -3.0, 1.0))) * Float64(1.0 - Float64(v * v))))
end
code[v_] := N[(N[Sqrt[2.0], $MachinePrecision] * N[(N[(0.25 * N[Sqrt[N[(N[(v * v), $MachinePrecision] * -3.0 + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sqrt{2} \cdot \left(\left(0.25 \cdot \sqrt{\mathsf{fma}\left(v \cdot v, -3, 1\right)}\right) \cdot \left(1 - v \cdot v\right)\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1 - 3 \cdot \left(v \cdot v\right)}}{4} \cdot \sqrt{2}\right)} \cdot \left(1 - v \cdot v\right) \]
    7. div-invN/A

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

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

      \[\leadsto \left(\color{blue}{\left(\frac{1}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right)} \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    10. metadata-eval100.0

      \[\leadsto \left(\left(\color{blue}{0.25} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    11. lift--.f64N/A

      \[\leadsto \left(\left(\frac{1}{4} \cdot \sqrt{\color{blue}{1 - 3 \cdot \left(v \cdot v\right)}}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    12. sub-negN/A

      \[\leadsto \left(\left(\frac{1}{4} \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left(3 \cdot \left(v \cdot v\right)\right)\right)}}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    13. +-commutativeN/A

      \[\leadsto \left(\left(\frac{1}{4} \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(3 \cdot \left(v \cdot v\right)\right)\right) + 1}}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    14. lift-*.f64N/A

      \[\leadsto \left(\left(\frac{1}{4} \cdot \sqrt{\left(\mathsf{neg}\left(\color{blue}{3 \cdot \left(v \cdot v\right)}\right)\right) + 1}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    15. distribute-lft-neg-inN/A

      \[\leadsto \left(\left(\frac{1}{4} \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(3\right)\right) \cdot \left(v \cdot v\right)} + 1}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    16. lower-fma.f64N/A

      \[\leadsto \left(\left(\frac{1}{4} \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(3\right), v \cdot v, 1\right)}}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
    17. metadata-eval100.0

      \[\leadsto \left(\left(0.25 \cdot \sqrt{\mathsf{fma}\left(\color{blue}{-3}, v \cdot v, 1\right)}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right) \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\left(\left(0.25 \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}\right) \cdot \sqrt{2}\right)} \cdot \left(1 - v \cdot v\right) \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(\frac{1}{4} \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}\right) \cdot \sqrt{2}\right) \cdot \left(1 - v \cdot v\right)} \]
    2. *-commutativeN/A

      \[\leadsto \color{blue}{\left(1 - v \cdot v\right) \cdot \left(\left(\frac{1}{4} \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}\right) \cdot \sqrt{2}\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \left(1 - v \cdot v\right) \cdot \color{blue}{\left(\left(\frac{1}{4} \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}\right) \cdot \sqrt{2}\right)} \]
    4. associate-*r*N/A

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

      \[\leadsto \color{blue}{\left(\left(1 - v \cdot v\right) \cdot \left(\frac{1}{4} \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}\right)\right) \cdot \sqrt{2}} \]
    6. lower-*.f64100.0

      \[\leadsto \color{blue}{\left(\left(1 - v \cdot v\right) \cdot \left(0.25 \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}\right)\right)} \cdot \sqrt{2} \]
    7. lift-*.f64N/A

      \[\leadsto \left(\left(1 - v \cdot v\right) \cdot \color{blue}{\left(\frac{1}{4} \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}\right)}\right) \cdot \sqrt{2} \]
    8. *-commutativeN/A

      \[\leadsto \left(\left(1 - v \cdot v\right) \cdot \color{blue}{\left(\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)} \cdot \frac{1}{4}\right)}\right) \cdot \sqrt{2} \]
    9. lower-*.f64100.0

      \[\leadsto \left(\left(1 - v \cdot v\right) \cdot \color{blue}{\left(\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)} \cdot 0.25\right)}\right) \cdot \sqrt{2} \]
    10. lift-fma.f64N/A

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

      \[\leadsto \left(\left(1 - v \cdot v\right) \cdot \left(\sqrt{\color{blue}{\left(v \cdot v\right) \cdot -3} + 1} \cdot \frac{1}{4}\right)\right) \cdot \sqrt{2} \]
    12. lower-fma.f64100.0

      \[\leadsto \left(\left(1 - v \cdot v\right) \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(v \cdot v, -3, 1\right)}} \cdot 0.25\right)\right) \cdot \sqrt{2} \]
  6. Applied rewrites100.0%

    \[\leadsto \color{blue}{\left(\left(1 - v \cdot v\right) \cdot \left(\sqrt{\mathsf{fma}\left(v \cdot v, -3, 1\right)} \cdot 0.25\right)\right) \cdot \sqrt{2}} \]
  7. Final simplification100.0%

    \[\leadsto \sqrt{2} \cdot \left(\left(0.25 \cdot \sqrt{\mathsf{fma}\left(v \cdot v, -3, 1\right)}\right) \cdot \left(1 - v \cdot v\right)\right) \]
  8. Add Preprocessing

Alternative 2: 100.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \sqrt{\mathsf{fma}\left(-6, v \cdot v, 2\right)} \cdot \mathsf{fma}\left(-0.25, v \cdot v, 0.25\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (* (sqrt (fma -6.0 (* v v) 2.0)) (fma -0.25 (* v v) 0.25)))
double code(double v) {
	return sqrt(fma(-6.0, (v * v), 2.0)) * fma(-0.25, (v * v), 0.25);
}
function code(v)
	return Float64(sqrt(fma(-6.0, Float64(v * v), 2.0)) * fma(-0.25, Float64(v * v), 0.25))
end
code[v_] := N[(N[Sqrt[N[(-6.0 * N[(v * v), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision] * N[(-0.25 * N[(v * v), $MachinePrecision] + 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\mathsf{fma}\left(-6, v \cdot v, 2\right)} \cdot \mathsf{fma}\left(-0.25, v \cdot v, 0.25\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right) \]
  2. Add Preprocessing
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \cdot 0.25\right)} \cdot \left(1 - v \cdot v\right) \]
  4. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \cdot \frac{1}{4}\right) \cdot \left(1 - v \cdot v\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \cdot \frac{1}{4}\right)} \cdot \left(1 - v \cdot v\right) \]
    3. associate-*l*N/A

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \cdot \left(\frac{1}{4} \cdot \left(1 - v \cdot v\right)\right)} \]
    4. *-commutativeN/A

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

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

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

      \[\leadsto \left(\frac{1}{4} \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(v \cdot v\right)\right)\right)}\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    8. +-commutativeN/A

      \[\leadsto \left(\frac{1}{4} \cdot \color{blue}{\left(\left(\mathsf{neg}\left(v \cdot v\right)\right) + 1\right)}\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    9. distribute-lft-inN/A

      \[\leadsto \color{blue}{\left(\frac{1}{4} \cdot \left(\mathsf{neg}\left(v \cdot v\right)\right) + \frac{1}{4} \cdot 1\right)} \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    10. neg-mul-1N/A

      \[\leadsto \left(\frac{1}{4} \cdot \color{blue}{\left(-1 \cdot \left(v \cdot v\right)\right)} + \frac{1}{4} \cdot 1\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    11. associate-*r*N/A

      \[\leadsto \left(\color{blue}{\left(\frac{1}{4} \cdot -1\right) \cdot \left(v \cdot v\right)} + \frac{1}{4} \cdot 1\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    12. metadata-evalN/A

      \[\leadsto \left(\color{blue}{\frac{-1}{4}} \cdot \left(v \cdot v\right) + \frac{1}{4} \cdot 1\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    13. metadata-evalN/A

      \[\leadsto \left(\color{blue}{\frac{1}{-4}} \cdot \left(v \cdot v\right) + \frac{1}{4} \cdot 1\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    14. metadata-evalN/A

      \[\leadsto \left(\frac{1}{\color{blue}{\mathsf{neg}\left(4\right)}} \cdot \left(v \cdot v\right) + \frac{1}{4} \cdot 1\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    15. metadata-evalN/A

      \[\leadsto \left(\frac{1}{\mathsf{neg}\left(4\right)} \cdot \left(v \cdot v\right) + \color{blue}{\frac{1}{4}}\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    16. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\mathsf{neg}\left(4\right)}, v \cdot v, \frac{1}{4}\right)} \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    17. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{\color{blue}{-4}}, v \cdot v, \frac{1}{4}\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    18. metadata-eval100.0

      \[\leadsto \mathsf{fma}\left(\color{blue}{-0.25}, v \cdot v, 0.25\right) \cdot \sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2} \]
    19. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{-1}{4}, v \cdot v, \frac{1}{4}\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(-3, v \cdot v, 1\right) \cdot 2}} \]
    20. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\frac{-1}{4}, v \cdot v, \frac{1}{4}\right) \cdot \sqrt{\color{blue}{2 \cdot \mathsf{fma}\left(-3, v \cdot v, 1\right)}} \]
    21. lift-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{-1}{4}, v \cdot v, \frac{1}{4}\right) \cdot \sqrt{2 \cdot \color{blue}{\left(-3 \cdot \left(v \cdot v\right) + 1\right)}} \]
    22. distribute-lft-inN/A

      \[\leadsto \mathsf{fma}\left(\frac{-1}{4}, v \cdot v, \frac{1}{4}\right) \cdot \sqrt{\color{blue}{2 \cdot \left(-3 \cdot \left(v \cdot v\right)\right) + 2 \cdot 1}} \]
  5. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.25, v \cdot v, 0.25\right) \cdot \sqrt{\mathsf{fma}\left(-6, v \cdot v, 2\right)}} \]
  6. Final simplification100.0%

    \[\leadsto \sqrt{\mathsf{fma}\left(-6, v \cdot v, 2\right)} \cdot \mathsf{fma}\left(-0.25, v \cdot v, 0.25\right) \]
  7. Add Preprocessing

Alternative 3: 99.5% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(-0.625 \cdot v, v, 0.25\right) \cdot \sqrt{2} \end{array} \]
(FPCore (v) :precision binary64 (* (fma (* -0.625 v) v 0.25) (sqrt 2.0)))
double code(double v) {
	return fma((-0.625 * v), v, 0.25) * sqrt(2.0);
}
function code(v)
	return Float64(fma(Float64(-0.625 * v), v, 0.25) * sqrt(2.0))
end
code[v_] := N[(N[(N[(-0.625 * v), $MachinePrecision] * v + 0.25), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(-0.625 \cdot v, v, 0.25\right) \cdot \sqrt{2}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

      \[\leadsto \left(\sqrt{1 - 3 \cdot \left(v \cdot v\right)} \cdot \color{blue}{\frac{1}{\frac{4}{\sqrt{2}}}}\right) \cdot \left(1 - v \cdot v\right) \]
    5. un-div-invN/A

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

      \[\leadsto \color{blue}{\frac{\sqrt{1 - 3 \cdot \left(v \cdot v\right)}}{\frac{4}{\sqrt{2}}}} \cdot \left(1 - v \cdot v\right) \]
    7. lift--.f64N/A

      \[\leadsto \frac{\sqrt{\color{blue}{1 - 3 \cdot \left(v \cdot v\right)}}}{\frac{4}{\sqrt{2}}} \cdot \left(1 - v \cdot v\right) \]
    8. sub-negN/A

      \[\leadsto \frac{\sqrt{\color{blue}{1 + \left(\mathsf{neg}\left(3 \cdot \left(v \cdot v\right)\right)\right)}}}{\frac{4}{\sqrt{2}}} \cdot \left(1 - v \cdot v\right) \]
    9. +-commutativeN/A

      \[\leadsto \frac{\sqrt{\color{blue}{\left(\mathsf{neg}\left(3 \cdot \left(v \cdot v\right)\right)\right) + 1}}}{\frac{4}{\sqrt{2}}} \cdot \left(1 - v \cdot v\right) \]
    10. lift-*.f64N/A

      \[\leadsto \frac{\sqrt{\left(\mathsf{neg}\left(\color{blue}{3 \cdot \left(v \cdot v\right)}\right)\right) + 1}}{\frac{4}{\sqrt{2}}} \cdot \left(1 - v \cdot v\right) \]
    11. distribute-lft-neg-inN/A

      \[\leadsto \frac{\sqrt{\color{blue}{\left(\mathsf{neg}\left(3\right)\right) \cdot \left(v \cdot v\right)} + 1}}{\frac{4}{\sqrt{2}}} \cdot \left(1 - v \cdot v\right) \]
    12. lower-fma.f64N/A

      \[\leadsto \frac{\sqrt{\color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(3\right), v \cdot v, 1\right)}}}{\frac{4}{\sqrt{2}}} \cdot \left(1 - v \cdot v\right) \]
    13. metadata-evalN/A

      \[\leadsto \frac{\sqrt{\mathsf{fma}\left(\color{blue}{-3}, v \cdot v, 1\right)}}{\frac{4}{\sqrt{2}}} \cdot \left(1 - v \cdot v\right) \]
    14. lower-/.f64100.0

      \[\leadsto \frac{\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}}{\color{blue}{\frac{4}{\sqrt{2}}}} \cdot \left(1 - v \cdot v\right) \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(-3, v \cdot v, 1\right)}}{\frac{4}{\sqrt{2}}}} \cdot \left(1 - v \cdot v\right) \]
  5. Taylor expanded in v around 0

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{4} \cdot \left(\frac{-3}{2} \cdot \sqrt{2} + -1 \cdot \sqrt{2}\right)\right) \cdot {v}^{2}} + \frac{1}{4} \cdot \sqrt{2} \]
    4. unpow2N/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\frac{1}{4} \cdot \left(\frac{-3}{2} \cdot \sqrt{2} + -1 \cdot \sqrt{2}\right)\right) \cdot v, v, \frac{1}{4} \cdot \sqrt{2}\right)} \]
  7. Applied rewrites99.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\sqrt{2} \cdot -0.625\right) \cdot v, v, \sqrt{2} \cdot 0.25\right)} \]
  8. Taylor expanded in v around 0

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(\frac{-3}{2} \cdot \sqrt{2} + -1 \cdot \sqrt{2}\right) \cdot \frac{1}{4}\right)} \cdot {v}^{2} + \frac{1}{4} \cdot \sqrt{2} \]
    5. distribute-rgt-outN/A

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sqrt{2} \cdot \mathsf{fma}\left(-0.625 \cdot v, v, 0.25\right)} \]
  11. Final simplification99.3%

    \[\leadsto \mathsf{fma}\left(-0.625 \cdot v, v, 0.25\right) \cdot \sqrt{2} \]
  12. Add Preprocessing

Alternative 4: 98.8% accurate, 3.9× speedup?

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

\\
\sqrt{2} \cdot 0.25
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{\sqrt{2}}{4} \cdot \sqrt{1 - 3 \cdot \left(v \cdot v\right)}\right) \cdot \left(1 - v \cdot v\right) \]
  2. Add Preprocessing
  3. Taylor expanded in v around 0

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

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

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

      \[\leadsto \color{blue}{\sqrt{2}} \cdot 0.25 \]
  5. Applied rewrites98.6%

    \[\leadsto \color{blue}{\sqrt{2} \cdot 0.25} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2024270 
(FPCore (v)
  :name "Falkner and Boettcher, Appendix B, 2"
  :precision binary64
  (* (* (/ (sqrt 2.0) 4.0) (sqrt (- 1.0 (* 3.0 (* v v))))) (- 1.0 (* v v))))