Falkner and Boettcher, Appendix B, 1

Percentage Accurate: 99.1% → 99.1%
Time: 15.5s
Alternatives: 6
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 6 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.1% 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.1% accurate, 1.0× speedup?

\[\begin{array}{l} v_m = \left|v\right| \\ \cos^{-1} \left(\frac{\mathsf{fma}\left(v\_m, v\_m \cdot -5, 1\right)}{\mathsf{fma}\left(v\_m + -1, v\_m, v\_m + -1\right)}\right) \end{array} \]
v_m = (fabs.f64 v)
(FPCore (v_m)
 :precision binary64
 (acos (/ (fma v_m (* v_m -5.0) 1.0) (fma (+ v_m -1.0) v_m (+ v_m -1.0)))))
v_m = fabs(v);
double code(double v_m) {
	return acos((fma(v_m, (v_m * -5.0), 1.0) / fma((v_m + -1.0), v_m, (v_m + -1.0))));
}
v_m = abs(v)
function code(v_m)
	return acos(Float64(fma(v_m, Float64(v_m * -5.0), 1.0) / fma(Float64(v_m + -1.0), v_m, Float64(v_m + -1.0))))
end
v_m = N[Abs[v], $MachinePrecision]
code[v$95$m_] := N[ArcCos[N[(N[(v$95$m * N[(v$95$m * -5.0), $MachinePrecision] + 1.0), $MachinePrecision] / N[(N[(v$95$m + -1.0), $MachinePrecision] * v$95$m + N[(v$95$m + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|

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

    \[\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. lift-*.f64N/A

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

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

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)} \]
    7. lift-acos.f6499.2

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

    \[\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. Step-by-step derivation
    1. difference-of-sqr--1N/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v + -1, v, v + \color{blue}{-1}\right)}\right) \]
    13. lower-+.f6498.4

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

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

Alternative 2: 99.1% accurate, 1.0× speedup?

\[\begin{array}{l} v_m = \left|v\right| \\ \cos^{-1} \left(\frac{\mathsf{fma}\left(v\_m, v\_m \cdot -5, 1\right)}{\mathsf{fma}\left(v\_m, v\_m, -1\right)}\right) \end{array} \]
v_m = (fabs.f64 v)
(FPCore (v_m)
 :precision binary64
 (acos (/ (fma v_m (* v_m -5.0) 1.0) (fma v_m v_m -1.0))))
v_m = fabs(v);
double code(double v_m) {
	return acos((fma(v_m, (v_m * -5.0), 1.0) / fma(v_m, v_m, -1.0)));
}
v_m = abs(v)
function code(v_m)
	return acos(Float64(fma(v_m, Float64(v_m * -5.0), 1.0) / fma(v_m, v_m, -1.0)))
end
v_m = N[Abs[v], $MachinePrecision]
code[v$95$m_] := N[ArcCos[N[(N[(v$95$m * N[(v$95$m * -5.0), $MachinePrecision] + 1.0), $MachinePrecision] / N[(v$95$m * v$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|

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

    \[\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. lift-*.f64N/A

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

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

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

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

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

      \[\leadsto \cos^{-1} \color{blue}{\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)} \]
    7. lift-acos.f6499.2

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

    \[\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. Add Preprocessing

Alternative 3: 98.8% accurate, 1.1× speedup?

\[\begin{array}{l} v_m = \left|v\right| \\ \cos^{-1} \left(\mathsf{fma}\left(v\_m, v\_m \cdot \mathsf{fma}\left(v\_m, v\_m \cdot 4, 4\right), -1\right)\right) \end{array} \]
v_m = (fabs.f64 v)
(FPCore (v_m)
 :precision binary64
 (acos (fma v_m (* v_m (fma v_m (* v_m 4.0) 4.0)) -1.0)))
v_m = fabs(v);
double code(double v_m) {
	return acos(fma(v_m, (v_m * fma(v_m, (v_m * 4.0), 4.0)), -1.0));
}
v_m = abs(v)
function code(v_m)
	return acos(fma(v_m, Float64(v_m * fma(v_m, Float64(v_m * 4.0), 4.0)), -1.0))
end
v_m = N[Abs[v], $MachinePrecision]
code[v$95$m_] := N[ArcCos[N[(v$95$m * N[(v$95$m * N[(v$95$m * N[(v$95$m * 4.0), $MachinePrecision] + 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|

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

    \[\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. lower-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. lower-*.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. unpow2N/A

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

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

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

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

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

Alternative 4: 98.6% accurate, 1.1× speedup?

\[\begin{array}{l} v_m = \left|v\right| \\ \mathsf{fma}\left(\pi, 0.5, -\sin^{-1} \left(\mathsf{fma}\left(v\_m, v\_m \cdot 4, -1\right)\right)\right) \end{array} \]
v_m = (fabs.f64 v)
(FPCore (v_m)
 :precision binary64
 (fma PI 0.5 (- (asin (fma v_m (* v_m 4.0) -1.0)))))
v_m = fabs(v);
double code(double v_m) {
	return fma(((double) M_PI), 0.5, -asin(fma(v_m, (v_m * 4.0), -1.0)));
}
v_m = abs(v)
function code(v_m)
	return fma(pi, 0.5, Float64(-asin(fma(v_m, Float64(v_m * 4.0), -1.0))))
end
v_m = N[Abs[v], $MachinePrecision]
code[v$95$m_] := N[(Pi * 0.5 + (-N[ArcSin[N[(v$95$m * N[(v$95$m * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|

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

    \[\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{PI}\left(\right)}{2} + \left(\mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right)\right)\right)} \]
    5. div-invN/A

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \color{blue}{\frac{1}{2}}, \mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right)\right)\right) \]
    9. lower-neg.f64N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{PI}\left(\right), \frac{1}{2}, \color{blue}{\mathsf{neg}\left(\sin^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right)\right)}\right) \]
    10. lower-asin.f6498.4

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

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

Alternative 5: 98.6% accurate, 1.2× speedup?

\[\begin{array}{l} v_m = \left|v\right| \\ \cos^{-1} \left(\mathsf{fma}\left(v\_m, v\_m \cdot 4, -1\right)\right) \end{array} \]
v_m = (fabs.f64 v)
(FPCore (v_m) :precision binary64 (acos (fma v_m (* v_m 4.0) -1.0)))
v_m = fabs(v);
double code(double v_m) {
	return acos(fma(v_m, (v_m * 4.0), -1.0));
}
v_m = abs(v)
function code(v_m)
	return acos(fma(v_m, Float64(v_m * 4.0), -1.0))
end
v_m = N[Abs[v], $MachinePrecision]
code[v$95$m_] := N[ArcCos[N[(v$95$m * N[(v$95$m * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|

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

    \[\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. *-commutativeN/A

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

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

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

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

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

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

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

Alternative 6: 97.9% accurate, 1.3× speedup?

\[\begin{array}{l} v_m = \left|v\right| \\ \cos^{-1} -1 \end{array} \]
v_m = (fabs.f64 v)
(FPCore (v_m) :precision binary64 (acos -1.0))
v_m = fabs(v);
double code(double v_m) {
	return acos(-1.0);
}
v_m = abs(v)
real(8) function code(v_m)
    real(8), intent (in) :: v_m
    code = acos((-1.0d0))
end function
v_m = Math.abs(v);
public static double code(double v_m) {
	return Math.acos(-1.0);
}
v_m = math.fabs(v)
def code(v_m):
	return math.acos(-1.0)
v_m = abs(v)
function code(v_m)
	return acos(-1.0)
end
v_m = abs(v);
function tmp = code(v_m)
	tmp = acos(-1.0);
end
v_m = N[Abs[v], $MachinePrecision]
code[v$95$m_] := N[ArcCos[-1.0], $MachinePrecision]
\begin{array}{l}
v_m = \left|v\right|

\\
\cos^{-1} -1
\end{array}
Derivation
  1. Initial program 99.2%

    \[\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.9%

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

    Reproduce

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