Falkner and Boettcher, Appendix B, 1

Percentage Accurate: 99.2% → 99.2%
Time: 18.7s
Alternatives: 4
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 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: 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} \\ \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)\right) + -1 \end{array} \]
(FPCore (v)
 :precision binary64
 (+
  (+ 1.0 (expm1 (log1p (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))))
  -1.0))
double code(double v) {
	return (1.0 + expm1(log1p(acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0)))))) + -1.0;
}
function code(v)
	return Float64(Float64(1.0 + expm1(log1p(acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0)))))) + -1.0)
end
code[v_] := N[(N[(1.0 + N[(Exp[N[Log[1 + N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}

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

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u99.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)\right)\right)} \]
    2. sub-neg99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{1 + \left(-5 \cdot \left(v \cdot v\right)\right)}}{v \cdot v - 1}\right)\right)\right) \]
    3. +-commutative99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(-5 \cdot \left(v \cdot v\right)\right) + 1}}{v \cdot v - 1}\right)\right)\right) \]
    4. *-commutative99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\left(-\color{blue}{\left(v \cdot v\right) \cdot 5}\right) + 1}{v \cdot v - 1}\right)\right)\right) \]
    5. distribute-rgt-neg-in99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(v \cdot v\right) \cdot \left(-5\right)} + 1}{v \cdot v - 1}\right)\right)\right) \]
    6. fma-def99.3%

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, \color{blue}{-5}, 1\right)}{v \cdot v - 1}\right)\right)\right) \]
    8. fma-neg99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\color{blue}{\mathsf{fma}\left(v, v, -1\right)}}\right)\right)\right) \]
    9. metadata-eval99.3%

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

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)} \]
  4. Step-by-step derivation
    1. add-sqr-sqrt99.3%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)} \cdot \sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}}\right) \]
    2. pow299.3%

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

    \[\leadsto \mathsf{expm1}\left(\color{blue}{{\left(\sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}\right)}^{2}}\right) \]
  6. Step-by-step derivation
    1. expm1-udef99.3%

      \[\leadsto \color{blue}{e^{{\left(\sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}\right)}^{2}} - 1} \]
    2. unpow299.3%

      \[\leadsto e^{\color{blue}{\sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)} \cdot \sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}}} - 1 \]
    3. add-sqr-sqrt99.3%

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

      \[\leadsto e^{\color{blue}{\log \left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}} - 1 \]
    5. add-exp-log99.3%

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

    \[\leadsto \color{blue}{\left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right) - 1} \]
  8. Step-by-step derivation
    1. expm1-log1p-u99.3%

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

    \[\leadsto \left(1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)}\right) - 1 \]
  10. Final simplification99.3%

    \[\leadsto \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)\right) + -1 \]

Alternative 2: 99.2% accurate, 0.2× speedup?

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

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

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u99.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)\right)\right)} \]
    2. sub-neg99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{1 + \left(-5 \cdot \left(v \cdot v\right)\right)}}{v \cdot v - 1}\right)\right)\right) \]
    3. +-commutative99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(-5 \cdot \left(v \cdot v\right)\right) + 1}}{v \cdot v - 1}\right)\right)\right) \]
    4. *-commutative99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\left(-\color{blue}{\left(v \cdot v\right) \cdot 5}\right) + 1}{v \cdot v - 1}\right)\right)\right) \]
    5. distribute-rgt-neg-in99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(v \cdot v\right) \cdot \left(-5\right)} + 1}{v \cdot v - 1}\right)\right)\right) \]
    6. fma-def99.3%

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, \color{blue}{-5}, 1\right)}{v \cdot v - 1}\right)\right)\right) \]
    8. fma-neg99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\color{blue}{\mathsf{fma}\left(v, v, -1\right)}}\right)\right)\right) \]
    9. metadata-eval99.3%

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

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)} \]
  4. Final simplification99.3%

    \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right) \]

Alternative 3: 99.2% accurate, 0.4× speedup?

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

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

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u99.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)\right)\right)} \]
    2. sub-neg99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{1 + \left(-5 \cdot \left(v \cdot v\right)\right)}}{v \cdot v - 1}\right)\right)\right) \]
    3. +-commutative99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(-5 \cdot \left(v \cdot v\right)\right) + 1}}{v \cdot v - 1}\right)\right)\right) \]
    4. *-commutative99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\left(-\color{blue}{\left(v \cdot v\right) \cdot 5}\right) + 1}{v \cdot v - 1}\right)\right)\right) \]
    5. distribute-rgt-neg-in99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(v \cdot v\right) \cdot \left(-5\right)} + 1}{v \cdot v - 1}\right)\right)\right) \]
    6. fma-def99.3%

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, \color{blue}{-5}, 1\right)}{v \cdot v - 1}\right)\right)\right) \]
    8. fma-neg99.3%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\color{blue}{\mathsf{fma}\left(v, v, -1\right)}}\right)\right)\right) \]
    9. metadata-eval99.3%

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

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)} \]
  4. Step-by-step derivation
    1. add-sqr-sqrt99.3%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)} \cdot \sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}}\right) \]
    2. pow299.3%

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

    \[\leadsto \mathsf{expm1}\left(\color{blue}{{\left(\sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}\right)}^{2}}\right) \]
  6. Step-by-step derivation
    1. unpow299.3%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)} \cdot \sqrt{\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)}}\right) \]
    2. add-sqr-sqrt99.3%

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

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

      \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
    5. div-inv99.3%

      \[\leadsto \color{blue}{\pi \cdot \frac{1}{2}} - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \]
    6. metadata-eval99.3%

      \[\leadsto \pi \cdot \color{blue}{0.5} - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \]
    7. flip--1.2%

      \[\leadsto \color{blue}{\frac{\left(\pi \cdot 0.5\right) \cdot \left(\pi \cdot 0.5\right) - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \cdot \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}{\pi \cdot 0.5 + \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}} \]
    8. swap-sqr1.2%

      \[\leadsto \frac{\color{blue}{\left(\pi \cdot \pi\right) \cdot \left(0.5 \cdot 0.5\right)} - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \cdot \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}{\pi \cdot 0.5 + \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
    9. unpow21.2%

      \[\leadsto \frac{\color{blue}{{\pi}^{2}} \cdot \left(0.5 \cdot 0.5\right) - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \cdot \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}{\pi \cdot 0.5 + \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
    10. metadata-eval1.2%

      \[\leadsto \frac{{\pi}^{2} \cdot \color{blue}{0.25} - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \cdot \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}{\pi \cdot 0.5 + \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
    11. *-commutative1.2%

      \[\leadsto \frac{\color{blue}{0.25 \cdot {\pi}^{2}} - \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \cdot \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}{\pi \cdot 0.5 + \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
    12. unpow21.2%

      \[\leadsto \frac{0.25 \cdot {\pi}^{2} - \color{blue}{{\sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}^{2}}}{\pi \cdot 0.5 + \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
  7. Applied egg-rr99.3%

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

    \[\leadsto \frac{1}{\frac{1}{\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}} \]

Alternative 4: 99.2% accurate, 1.0× speedup?

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

\\
\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right)
\end{array}
Derivation
  1. Initial program 99.3%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Final simplification99.3%

    \[\leadsto \cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right) \]

Reproduce

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