Falkner and Boettcher, Appendix B, 1

?

Percentage Accurate: 99.2% → 98.8%
Time: 29.1s
Precision: binary64
Cost: 32704

?

\[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\left(4 \cdot {v}^{2} + 4 \cdot {v}^{4}\right) + -1\right)\right)\right) \]
(FPCore (v)
 :precision binary64
 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
(FPCore (v)
 :precision binary64
 (expm1 (log1p (acos (+ (+ (* 4.0 (pow v 2.0)) (* 4.0 (pow v 4.0))) -1.0)))))
double code(double v) {
	return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
double code(double v) {
	return expm1(log1p(acos((((4.0 * pow(v, 2.0)) + (4.0 * pow(v, 4.0))) + -1.0))));
}
public static double code(double v) {
	return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
public static double code(double v) {
	return Math.expm1(Math.log1p(Math.acos((((4.0 * Math.pow(v, 2.0)) + (4.0 * Math.pow(v, 4.0))) + -1.0))));
}
def code(v):
	return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
def code(v):
	return math.expm1(math.log1p(math.acos((((4.0 * math.pow(v, 2.0)) + (4.0 * math.pow(v, 4.0))) + -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 expm1(log1p(acos(Float64(Float64(Float64(4.0 * (v ^ 2.0)) + Float64(4.0 * (v ^ 4.0))) + -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[1 + N[ArcCos[N[(N[(N[(4.0 * N[Power[v, 2.0], $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[Power[v, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\left(4 \cdot {v}^{2} + 4 \cdot {v}^{4}\right) + -1\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 5 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

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 99.3%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. 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)} \]
    Step-by-step derivation

    [Start]99.3%

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

    expm1-log1p-u [=>]99.3%

    \[ \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)} \]

    sub-neg [=>]99.3%

    \[ \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) \]

    +-commutative [=>]99.3%

    \[ \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) \]

    *-commutative [=>]99.3%

    \[ \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) \]

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

    \[ \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) \]

    fma-def [=>]99.3%

    \[ \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) \]

    metadata-eval [=>]99.3%

    \[ \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) \]

    fma-neg [=>]99.3%

    \[ \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) \]

    metadata-eval [=>]99.3%

    \[ \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. Taylor expanded in v around 0 99.3%

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

    \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\left(4 \cdot {v}^{2} + 4 \cdot {v}^{4}\right) + -1\right)\right)\right) \]

Alternatives

Alternative 1
Accuracy98.8%
Cost32704
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\left(4 \cdot {v}^{2} + 4 \cdot {v}^{4}\right) + -1\right)\right)\right) \]
Alternative 2
Accuracy98.8%
Cost13440
\[\cos^{-1} \left(4 \cdot \left({v}^{4} + v \cdot v\right) + -1\right) \]
Alternative 3
Accuracy99.2%
Cost7232
\[\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right) \]
Alternative 4
Accuracy98.5%
Cost6848
\[\cos^{-1} \left(-1 + 4 \cdot \left(v \cdot v\right)\right) \]
Alternative 5
Accuracy97.8%
Cost6464
\[\cos^{-1} -1 \]

Reproduce?

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