Falkner and Boettcher, Appendix B, 1

Percentage Accurate: 99.2% → 99.2%
Time: 21.4s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
	return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
    real(8), intent (in) :: v
    code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
	return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v):
	return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v)
	return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0)))
end
function tmp = code(v)
	tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\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 8 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: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
	return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
    real(8), intent (in) :: v
    code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
	return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v):
	return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v)
	return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0)))
end
function tmp = code(v)
	tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}

Alternative 1: 99.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\\ \frac{\left(\pi \cdot \left(\pi \cdot \pi\right)\right) \cdot 0.125 - {t\_0}^{3}}{\mathsf{fma}\left(t\_0, \mathsf{fma}\left(\pi, 0.5, t\_0\right), \left(\pi \cdot \pi\right) \cdot 0.25\right)} \end{array} \end{array} \]
(FPCore (v)
 :precision binary64
 (let* ((t_0 (asin (/ (fma v (* v -5.0) 1.0) (fma v v -1.0)))))
   (/
    (- (* (* PI (* PI PI)) 0.125) (pow t_0 3.0))
    (fma t_0 (fma PI 0.5 t_0) (* (* PI PI) 0.25)))))
double code(double v) {
	double t_0 = asin((fma(v, (v * -5.0), 1.0) / fma(v, v, -1.0)));
	return (((((double) M_PI) * (((double) M_PI) * ((double) M_PI))) * 0.125) - pow(t_0, 3.0)) / fma(t_0, fma(((double) M_PI), 0.5, t_0), ((((double) M_PI) * ((double) M_PI)) * 0.25));
}
function code(v)
	t_0 = asin(Float64(fma(v, Float64(v * -5.0), 1.0) / fma(v, v, -1.0)))
	return Float64(Float64(Float64(Float64(pi * Float64(pi * pi)) * 0.125) - (t_0 ^ 3.0)) / fma(t_0, fma(pi, 0.5, t_0), Float64(Float64(pi * pi) * 0.25)))
end
code[v_] := Block[{t$95$0 = N[ArcSin[N[(N[(v * N[(v * -5.0), $MachinePrecision] + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(Pi * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision] - N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(Pi * 0.5 + t$95$0), $MachinePrecision] + N[(N[(Pi * Pi), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\\
\frac{\left(\pi \cdot \left(\pi \cdot \pi\right)\right) \cdot 0.125 - {t\_0}^{3}}{\mathsf{fma}\left(t\_0, \mathsf{fma}\left(\pi, 0.5, t\_0\right), \left(\pi \cdot \pi\right) \cdot 0.25\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\frac{\left(\pi \cdot \left(\pi \cdot \pi\right)\right) \cdot 0.125 - {\sin^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}^{3}}{\mathsf{fma}\left(\sin^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right), \mathsf{fma}\left(\pi, 0.5, \sin^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right), \left(\pi \cdot \pi\right) \cdot 0.25\right)}} \]
  4. Add Preprocessing

Alternative 2: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (acos (/ (fma -5.0 (* v v) 1.0) (fma v v -1.0))))
double code(double v) {
	return acos((fma(-5.0, (v * v), 1.0) / fma(v, v, -1.0)));
}
function code(v)
	return acos(Float64(fma(-5.0, Float64(v * v), 1.0) / fma(v, v, -1.0)))
end
code[v_] := N[ArcCos[N[(N[(-5.0 * N[(v * v), $MachinePrecision] + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Derivation
  1. Initial program 99.1%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. acos-lowering-acos.f64N/A

      \[\leadsto \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)} \]
    3. sub-negN/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{1 + \left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)}}{v \cdot v - 1}\right) \]
    4. +-commutativeN/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{\left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right) + 1}}{v \cdot v - 1}\right) \]
    5. associate-*r*N/A

      \[\leadsto \cos^{-1} \left(\frac{\left(\mathsf{neg}\left(\color{blue}{\left(5 \cdot v\right) \cdot v}\right)\right) + 1}{v \cdot v - 1}\right) \]
    6. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\frac{\left(\mathsf{neg}\left(\color{blue}{v \cdot \left(5 \cdot v\right)}\right)\right) + 1}{v \cdot v - 1}\right) \]
    7. distribute-rgt-neg-inN/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{v \cdot \left(\mathsf{neg}\left(5 \cdot v\right)\right)} + 1}{v \cdot v - 1}\right) \]
    8. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{\mathsf{fma}\left(v, \mathsf{neg}\left(5 \cdot v\right), 1\right)}}{v \cdot v - 1}\right) \]
    9. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, \mathsf{neg}\left(\color{blue}{v \cdot 5}\right), 1\right)}{v \cdot v - 1}\right) \]
    10. distribute-rgt-neg-inN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, \color{blue}{v \cdot \left(\mathsf{neg}\left(5\right)\right)}, 1\right)}{v \cdot v - 1}\right) \]
    11. *-lowering-*.f64N/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, \color{blue}{v \cdot \left(\mathsf{neg}\left(5\right)\right)}, 1\right)}{v \cdot v - 1}\right) \]
    12. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot \color{blue}{-5}, 1\right)}{v \cdot v - 1}\right) \]
    13. sub-negN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\color{blue}{v \cdot v + \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
    14. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\color{blue}{\mathsf{fma}\left(v, v, \mathsf{neg}\left(1\right)\right)}}\right) \]
    15. metadata-eval99.0

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, \color{blue}{-1}\right)}\right) \]
  4. Applied egg-rr99.0%

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

    \[\leadsto \color{blue}{\cos^{-1} \left(\frac{1 + -5 \cdot {v}^{2}}{{v}^{2} - 1}\right)} \]
  6. Step-by-step derivation
    1. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(\frac{1 + \color{blue}{\left(\mathsf{neg}\left(5\right)\right)} \cdot {v}^{2}}{{v}^{2} - 1}\right) \]
    2. cancel-sign-sub-invN/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{1 - 5 \cdot {v}^{2}}}{{v}^{2} - 1}\right) \]
    3. acos-lowering-acos.f64N/A

      \[\leadsto \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot {v}^{2}}{{v}^{2} - 1}\right)} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\frac{1 - 5 \cdot {v}^{2}}{{v}^{2} - 1}\right)} \]
    5. cancel-sign-sub-invN/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{1 + \left(\mathsf{neg}\left(5\right)\right) \cdot {v}^{2}}}{{v}^{2} - 1}\right) \]
    6. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(\frac{1 + \color{blue}{-5} \cdot {v}^{2}}{{v}^{2} - 1}\right) \]
    7. +-commutativeN/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{-5 \cdot {v}^{2} + 1}}{{v}^{2} - 1}\right) \]
    8. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos^{-1} \left(\frac{\color{blue}{\mathsf{fma}\left(-5, {v}^{2}, 1\right)}}{{v}^{2} - 1}\right) \]
    9. unpow2N/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(-5, \color{blue}{v \cdot v}, 1\right)}{{v}^{2} - 1}\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(-5, \color{blue}{v \cdot v}, 1\right)}{{v}^{2} - 1}\right) \]
    11. sub-negN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\color{blue}{{v}^{2} + \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
    12. unpow2N/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\color{blue}{v \cdot v} + \left(\mathsf{neg}\left(1\right)\right)}\right) \]
    13. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{v \cdot v + \color{blue}{-1}}\right) \]
    14. accelerator-lowering-fma.f6499.1

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\color{blue}{\mathsf{fma}\left(v, v, -1\right)}}\right) \]
  7. Simplified99.1%

    \[\leadsto \color{blue}{\cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
  8. Add Preprocessing

Alternative 3: 98.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \pi - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(v, v \cdot -4, -4\right), 1\right)\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (- PI (acos (fma v (* v (fma v (* v -4.0) -4.0)) 1.0))))
double code(double v) {
	return ((double) M_PI) - acos(fma(v, (v * fma(v, (v * -4.0), -4.0)), 1.0));
}
function code(v)
	return Float64(pi - acos(fma(v, Float64(v * fma(v, Float64(v * -4.0), -4.0)), 1.0)))
end
code[v_] := N[(Pi - N[ArcCos[N[(v * N[(v * N[(v * N[(v * -4.0), $MachinePrecision] + -4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(v, v \cdot -4, -4\right), 1\right)\right)
\end{array}
Derivation
  1. Initial program 99.1%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-2negN/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    2. distribute-frac-negN/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{neg}\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)\right)} \]
    3. acos-negN/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    4. --lowering--.f64N/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    5. PI-lowering-PI.f64N/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right)} - \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right) \]
    6. acos-lowering-acos.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    7. distribute-frac-neg2N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\mathsf{neg}\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)\right)} \]
    8. distribute-frac-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{v \cdot v - 1}\right)} \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{v \cdot v - 1}\right)} \]
    10. sub-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right)}\right)}{v \cdot v - 1}\right) \]
    11. +-commutativeN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right) + 1\right)}\right)}{v \cdot v - 1}\right) \]
    12. distribute-neg-inN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right)\right) + \left(\mathsf{neg}\left(1\right)\right)}}{v \cdot v - 1}\right) \]
    13. remove-double-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\color{blue}{5 \cdot \left(v \cdot v\right)} + \left(\mathsf{neg}\left(1\right)\right)}{v \cdot v - 1}\right) \]
    14. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\color{blue}{\mathsf{fma}\left(5, v \cdot v, \mathsf{neg}\left(1\right)\right)}}{v \cdot v - 1}\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, \color{blue}{v \cdot v}, \mathsf{neg}\left(1\right)\right)}{v \cdot v - 1}\right) \]
    16. metadata-evalN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, \color{blue}{-1}\right)}{v \cdot v - 1}\right) \]
    17. sub-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\color{blue}{v \cdot v + \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
    18. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\color{blue}{\mathsf{fma}\left(v, v, \mathsf{neg}\left(1\right)\right)}}\right) \]
    19. metadata-eval99.0

      \[\leadsto \pi - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\mathsf{fma}\left(v, v, \color{blue}{-1}\right)}\right) \]
  4. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\pi - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
  5. Taylor expanded in v around 0

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

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

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

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\color{blue}{v \cdot \left(v \cdot \left(-4 \cdot {v}^{2} - 4\right)\right)} + 1\right) \]
    4. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, v \cdot \left(-4 \cdot {v}^{2} - 4\right), 1\right)\right)} \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot \left(-4 \cdot {v}^{2} - 4\right)}, 1\right)\right) \]
    6. sub-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \color{blue}{\left(-4 \cdot {v}^{2} + \left(\mathsf{neg}\left(4\right)\right)\right)}, 1\right)\right) \]
    7. unpow2N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \left(-4 \cdot \color{blue}{\left(v \cdot v\right)} + \left(\mathsf{neg}\left(4\right)\right)\right), 1\right)\right) \]
    8. associate-*r*N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \left(\color{blue}{\left(-4 \cdot v\right) \cdot v} + \left(\mathsf{neg}\left(4\right)\right)\right), 1\right)\right) \]
    9. *-commutativeN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \left(\color{blue}{v \cdot \left(-4 \cdot v\right)} + \left(\mathsf{neg}\left(4\right)\right)\right), 1\right)\right) \]
    10. metadata-evalN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \left(v \cdot \left(-4 \cdot v\right) + \color{blue}{-4}\right), 1\right)\right) \]
    11. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \color{blue}{\mathsf{fma}\left(v, -4 \cdot v, -4\right)}, 1\right)\right) \]
    12. *-commutativeN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(v, \color{blue}{v \cdot -4}, -4\right), 1\right)\right) \]
    13. *-lowering-*.f6498.8

      \[\leadsto \pi - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(v, \color{blue}{v \cdot -4}, -4\right), 1\right)\right) \]
  7. Simplified98.8%

    \[\leadsto \pi - \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(v, v \cdot -4, -4\right), 1\right)\right)} \]
  8. Add Preprocessing

Alternative 4: 98.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(v \cdot \mathsf{fma}\left(v, v \cdot 4, 4\right), v, -1\right)\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (acos (fma (* v (fma v (* v 4.0) 4.0)) v -1.0)))
double code(double v) {
	return acos(fma((v * fma(v, (v * 4.0), 4.0)), v, -1.0));
}
function code(v)
	return acos(fma(Float64(v * fma(v, Float64(v * 4.0), 4.0)), v, -1.0))
end
code[v_] := N[ArcCos[N[(N[(v * N[(v * N[(v * 4.0), $MachinePrecision] + 4.0), $MachinePrecision]), $MachinePrecision] * v + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\mathsf{fma}\left(v \cdot \mathsf{fma}\left(v, v \cdot 4, 4\right), v, -1\right)\right)
\end{array}
Derivation
  1. Initial program 99.1%

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

    \[\leadsto \cos^{-1} \color{blue}{\left({v}^{2} \cdot \left(4 + 4 \cdot {v}^{2}\right) - 1\right)} \]
  4. Step-by-step derivation
    1. sub-negN/A

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

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

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

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

      \[\leadsto \cos^{-1} \left(v \cdot \left(\left(4 + 4 \cdot {v}^{2}\right) \cdot v\right) + \color{blue}{-1}\right) \]
    6. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, \left(4 + 4 \cdot {v}^{2}\right) \cdot v, -1\right)\right)} \]
    7. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot \left(4 + 4 \cdot {v}^{2}\right)}, -1\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot \left(4 + 4 \cdot {v}^{2}\right)}, -1\right)\right) \]
    9. +-commutativeN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \color{blue}{\left(4 \cdot {v}^{2} + 4\right)}, -1\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \left(\color{blue}{{v}^{2} \cdot 4} + 4\right), -1\right)\right) \]
    11. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \color{blue}{\mathsf{fma}\left({v}^{2}, 4, 4\right)}, -1\right)\right) \]
    12. remove-double-negN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left({v}^{2}\right)\right)\right)}, 4, 4\right), -1\right)\right) \]
    13. +-rgt-identityN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left({v}^{2}\right)\right) + 0\right)}\right), 4, 4\right), -1\right)\right) \]
    14. distribute-neg-inN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left({v}^{2}\right)\right)\right)\right) + \left(\mathsf{neg}\left(0\right)\right)}, 4, 4\right), -1\right)\right) \]
    15. remove-double-negN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(\color{blue}{{v}^{2}} + \left(\mathsf{neg}\left(0\right)\right), 4, 4\right), -1\right)\right) \]
    16. unpow2N/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(\color{blue}{v \cdot v} + \left(\mathsf{neg}\left(0\right)\right), 4, 4\right), -1\right)\right) \]
    17. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(v \cdot v + \color{blue}{0}, 4, 4\right), -1\right)\right) \]
    18. accelerator-lowering-fma.f6498.8

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(v, v, 0\right)}, 4, 4\right), -1\right)\right) \]
  5. Simplified98.8%

    \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, v \cdot \mathsf{fma}\left(\mathsf{fma}\left(v, v, 0\right), 4, 4\right), -1\right)\right)} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\color{blue}{\left(v \cdot \left(\left(v \cdot v + 0\right) \cdot 4 + 4\right)\right) \cdot v} + -1\right) \]
    2. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v \cdot \left(\left(v \cdot v + 0\right) \cdot 4 + 4\right), v, -1\right)\right)} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(\color{blue}{v \cdot \left(\left(v \cdot v + 0\right) \cdot 4 + 4\right)}, v, -1\right)\right) \]
    4. +-rgt-identityN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v \cdot \left(\color{blue}{\left(v \cdot v\right)} \cdot 4 + 4\right), v, -1\right)\right) \]
    5. associate-*l*N/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v \cdot \left(\color{blue}{v \cdot \left(v \cdot 4\right)} + 4\right), v, -1\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v \cdot \left(v \cdot \color{blue}{\left(4 \cdot v\right)} + 4\right), v, -1\right)\right) \]
    7. accelerator-lowering-fma.f64N/A

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

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v \cdot \mathsf{fma}\left(v, \color{blue}{v \cdot 4}, 4\right), v, -1\right)\right) \]
    9. *-lowering-*.f6498.8

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v \cdot \mathsf{fma}\left(v, \color{blue}{v \cdot 4}, 4\right), v, -1\right)\right) \]
  7. Applied egg-rr98.8%

    \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v \cdot \mathsf{fma}\left(v, v \cdot 4, 4\right), v, -1\right)\right)} \]
  8. Add Preprocessing

Alternative 5: 98.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \pi - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot -4, 1\right)\right) \end{array} \]
(FPCore (v) :precision binary64 (- PI (acos (fma v (* v -4.0) 1.0))))
double code(double v) {
	return ((double) M_PI) - acos(fma(v, (v * -4.0), 1.0));
}
function code(v)
	return Float64(pi - acos(fma(v, Float64(v * -4.0), 1.0)))
end
code[v_] := N[(Pi - N[ArcCos[N[(v * N[(v * -4.0), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi - \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot -4, 1\right)\right)
\end{array}
Derivation
  1. Initial program 99.1%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-2negN/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    2. distribute-frac-negN/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{neg}\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)\right)} \]
    3. acos-negN/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    4. --lowering--.f64N/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    5. PI-lowering-PI.f64N/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right)} - \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right) \]
    6. acos-lowering-acos.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    7. distribute-frac-neg2N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\mathsf{neg}\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)\right)} \]
    8. distribute-frac-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{v \cdot v - 1}\right)} \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{v \cdot v - 1}\right)} \]
    10. sub-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right)}\right)}{v \cdot v - 1}\right) \]
    11. +-commutativeN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right) + 1\right)}\right)}{v \cdot v - 1}\right) \]
    12. distribute-neg-inN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right)\right) + \left(\mathsf{neg}\left(1\right)\right)}}{v \cdot v - 1}\right) \]
    13. remove-double-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\color{blue}{5 \cdot \left(v \cdot v\right)} + \left(\mathsf{neg}\left(1\right)\right)}{v \cdot v - 1}\right) \]
    14. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\color{blue}{\mathsf{fma}\left(5, v \cdot v, \mathsf{neg}\left(1\right)\right)}}{v \cdot v - 1}\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, \color{blue}{v \cdot v}, \mathsf{neg}\left(1\right)\right)}{v \cdot v - 1}\right) \]
    16. metadata-evalN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, \color{blue}{-1}\right)}{v \cdot v - 1}\right) \]
    17. sub-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\color{blue}{v \cdot v + \left(\mathsf{neg}\left(1\right)\right)}}\right) \]
    18. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\color{blue}{\mathsf{fma}\left(v, v, \mathsf{neg}\left(1\right)\right)}}\right) \]
    19. metadata-eval99.0

      \[\leadsto \pi - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\mathsf{fma}\left(v, v, \color{blue}{-1}\right)}\right) \]
  4. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\pi - \cos^{-1} \left(\frac{\mathsf{fma}\left(5, v \cdot v, -1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
  5. Taylor expanded in v around 0

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

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

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

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\color{blue}{\left(-4 \cdot v\right) \cdot v} + 1\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\color{blue}{v \cdot \left(-4 \cdot v\right)} + 1\right) \]
    5. accelerator-lowering-fma.f64N/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, -4 \cdot v, 1\right)\right)} \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{PI}\left(\right) - \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot -4}, 1\right)\right) \]
    7. *-lowering-*.f6498.7

      \[\leadsto \pi - \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot -4}, 1\right)\right) \]
  7. Simplified98.7%

    \[\leadsto \pi - \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, v \cdot -4, 1\right)\right)} \]
  8. Add Preprocessing

Alternative 6: 98.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right) \end{array} \]
(FPCore (v) :precision binary64 (acos (fma v (* v 4.0) -1.0)))
double code(double v) {
	return acos(fma(v, (v * 4.0), -1.0));
}
function code(v)
	return acos(fma(v, Float64(v * 4.0), -1.0))
end
code[v_] := N[ArcCos[N[(v * N[(v * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right)
\end{array}
Derivation
  1. Initial program 99.1%

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

    \[\leadsto \cos^{-1} \color{blue}{\left(4 \cdot {v}^{2} - 1\right)} \]
  4. Step-by-step derivation
    1. sub-negN/A

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

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

      \[\leadsto \cos^{-1} \left(\color{blue}{\left(4 \cdot v\right) \cdot v} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    4. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\color{blue}{v \cdot \left(4 \cdot v\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \cos^{-1} \left(v \cdot \left(4 \cdot v\right) + \color{blue}{-1}\right) \]
    6. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, 4 \cdot v, -1\right)\right)} \]
    7. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot 4}, -1\right)\right) \]
    8. *-lowering-*.f6498.7

      \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot 4}, -1\right)\right) \]
  5. Simplified98.7%

    \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right)} \]
  6. Add Preprocessing

Alternative 7: 98.2% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(5, v \cdot v, -1\right)\right) \end{array} \]
(FPCore (v) :precision binary64 (acos (fma 5.0 (* v v) -1.0)))
double code(double v) {
	return acos(fma(5.0, (v * v), -1.0));
}
function code(v)
	return acos(fma(5.0, Float64(v * v), -1.0))
end
code[v_] := N[ArcCos[N[(5.0 * N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\mathsf{fma}\left(5, v \cdot v, -1\right)\right)
\end{array}
Derivation
  1. Initial program 99.1%

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

    \[\leadsto \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\color{blue}{-1}}\right) \]
  4. Step-by-step derivation
    1. Simplified97.9%

      \[\leadsto \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\color{blue}{-1}}\right) \]
    2. Taylor expanded in v around 0

      \[\leadsto \cos^{-1} \color{blue}{\left(5 \cdot {v}^{2} - 1\right)} \]
    3. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(5 \cdot {v}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      2. *-commutativeN/A

        \[\leadsto \cos^{-1} \left(\color{blue}{{v}^{2} \cdot 5} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      3. unpow2N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{\left(v \cdot v\right)} \cdot 5 + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \cos^{-1} \left(\color{blue}{v \cdot \left(v \cdot 5\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \cos^{-1} \left(v \cdot \left(v \cdot 5\right) + \color{blue}{-1}\right) \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(v, v \cdot 5, -1\right)\right)} \]
      7. *-lowering-*.f6497.9

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(v, \color{blue}{v \cdot 5}, -1\right)\right) \]
    4. Simplified97.9%

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

      \[\leadsto \color{blue}{\cos^{-1} \left(5 \cdot {v}^{2} - 1\right)} \]
    6. Step-by-step derivation
      1. acos-lowering-acos.f64N/A

        \[\leadsto \color{blue}{\cos^{-1} \left(5 \cdot {v}^{2} - 1\right)} \]
      2. sub-negN/A

        \[\leadsto \cos^{-1} \color{blue}{\left(5 \cdot {v}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      3. metadata-evalN/A

        \[\leadsto \cos^{-1} \left(5 \cdot {v}^{2} + \color{blue}{-1}\right) \]
      4. accelerator-lowering-fma.f64N/A

        \[\leadsto \cos^{-1} \color{blue}{\left(\mathsf{fma}\left(5, {v}^{2}, -1\right)\right)} \]
      5. unpow2N/A

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(5, \color{blue}{v \cdot v}, -1\right)\right) \]
      6. *-lowering-*.f6497.9

        \[\leadsto \cos^{-1} \left(\mathsf{fma}\left(5, \color{blue}{v \cdot v}, -1\right)\right) \]
    7. Simplified97.9%

      \[\leadsto \color{blue}{\cos^{-1} \left(\mathsf{fma}\left(5, v \cdot v, -1\right)\right)} \]
    8. Add Preprocessing

    Alternative 8: 98.1% accurate, 1.3× speedup?

    \[\begin{array}{l} \\ \cos^{-1} -1 \end{array} \]
    (FPCore (v) :precision binary64 (acos -1.0))
    double code(double v) {
    	return acos(-1.0);
    }
    
    real(8) function code(v)
        real(8), intent (in) :: v
        code = acos((-1.0d0))
    end function
    
    public static double code(double v) {
    	return Math.acos(-1.0);
    }
    
    def code(v):
    	return math.acos(-1.0)
    
    function code(v)
    	return acos(-1.0)
    end
    
    function tmp = code(v)
    	tmp = acos(-1.0);
    end
    
    code[v_] := N[ArcCos[-1.0], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \cos^{-1} -1
    \end{array}
    
    Derivation
    1. Initial program 99.1%

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

      \[\leadsto \cos^{-1} \color{blue}{-1} \]
    4. Step-by-step derivation
      1. Simplified97.7%

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

      Reproduce

      ?
      herbie shell --seed 2024197 
      (FPCore (v)
        :name "Falkner and Boettcher, Appendix B, 1"
        :precision binary64
        (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))