Falkner and Boettcher, Appendix B, 1

?

Percentage Accurate: 99.1% → 99.1%
Time: 15.5s
Precision: binary64
Cost: 32832

?

\[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
\[e^{\log \left(-1 + \left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)} \]
(FPCore (v)
 :precision binary64
 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
(FPCore (v)
 :precision binary64
 (exp (log (+ -1.0 (+ 1.0 (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))))))
double code(double v) {
	return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
double code(double v) {
	return exp(log((-1.0 + (1.0 + acos((fma((v * v), -5.0, 1.0) / fma(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 code(v)
	return exp(log(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[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[v_] := N[Exp[N[Log[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]], $MachinePrecision]], $MachinePrecision]
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
e^{\log \left(-1 + \left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)}

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.

Herbie found 7 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Derivation?

  1. Initial program 98.7%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Applied egg-rr98.7%

    \[\leadsto \color{blue}{e^{\log \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}} \]
    Step-by-step derivation

    [Start]98.7%

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

    add-exp-log [=>]98.7%

    \[ \color{blue}{e^{\log \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)}} \]

    sub-neg [=>]98.7%

    \[ e^{\log \cos^{-1} \left(\frac{\color{blue}{1 + \left(-5 \cdot \left(v \cdot v\right)\right)}}{v \cdot v - 1}\right)} \]

    +-commutative [=>]98.7%

    \[ e^{\log \cos^{-1} \left(\frac{\color{blue}{\left(-5 \cdot \left(v \cdot v\right)\right) + 1}}{v \cdot v - 1}\right)} \]

    *-commutative [=>]98.7%

    \[ e^{\log \cos^{-1} \left(\frac{\left(-\color{blue}{\left(v \cdot v\right) \cdot 5}\right) + 1}{v \cdot v - 1}\right)} \]

    distribute-rgt-neg-in [=>]98.7%

    \[ e^{\log \cos^{-1} \left(\frac{\color{blue}{\left(v \cdot v\right) \cdot \left(-5\right)} + 1}{v \cdot v - 1}\right)} \]

    fma-def [=>]98.7%

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

    metadata-eval [=>]98.7%

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

    fma-neg [=>]98.7%

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

    metadata-eval [=>]98.7%

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

    \[\leadsto e^{\log \color{blue}{\left(\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\right)}} \]
    Step-by-step derivation

    [Start]98.7%

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

    expm1-log1p-u [=>]98.7%

    \[ e^{\log \color{blue}{\left(\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)}} \]

    expm1-udef [=>]98.7%

    \[ e^{\log \color{blue}{\left(e^{\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\right)}} \]

    log1p-udef [=>]98.7%

    \[ e^{\log \left(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\right)} \]

    add-exp-log [<=]98.7%

    \[ e^{\log \left(\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\right)} \]
  4. Final simplification98.7%

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

Alternatives

Alternative 1
Accuracy99.1%
Cost32832
\[e^{\log \left(-1 + \left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)} \]
Alternative 2
Accuracy99.1%
Cost32576
\[e^{\log \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)} \]
Alternative 3
Accuracy99.1%
Cost26304
\[\pi - \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{-\mathsf{fma}\left(v, v, -1\right)}\right) \]
Alternative 4
Accuracy99.1%
Cost20032
\[-1 + \left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right) \]
Alternative 5
Accuracy99.1%
Cost7232
\[\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right) \]
Alternative 6
Accuracy97.9%
Cost6976
\[\cos^{-1} \left(\left(1 + v\right) \cdot \frac{-1}{1 + v}\right) \]
Alternative 7
Accuracy97.9%
Cost6464
\[\cos^{-1} -1 \]

Reproduce?

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