2-ancestry mixing, negative discriminant

?

Percentage Accurate: 98.5% → 98.5%
Time: 5.0s
Precision: binary64
Cost: 26176

?

\[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
\[2 \cdot \cos \left(\mathsf{fma}\left(\pi, 0.6666666666666666, \frac{\cos^{-1} \left(-\frac{g}{h}\right)}{3}\right)\right) \]
(FPCore (g h)
 :precision binary64
 (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
(FPCore (g h)
 :precision binary64
 (* 2.0 (cos (fma PI 0.6666666666666666 (/ (acos (- (/ g h))) 3.0)))))
double code(double g, double h) {
	return 2.0 * cos((((2.0 * ((double) M_PI)) / 3.0) + (acos((-g / h)) / 3.0)));
}
double code(double g, double h) {
	return 2.0 * cos(fma(((double) M_PI), 0.6666666666666666, (acos(-(g / h)) / 3.0)));
}
function code(g, h)
	return Float64(2.0 * cos(Float64(Float64(Float64(2.0 * pi) / 3.0) + Float64(acos(Float64(Float64(-g) / h)) / 3.0))))
end
function code(g, h)
	return Float64(2.0 * cos(fma(pi, 0.6666666666666666, Float64(acos(Float64(-Float64(g / h))) / 3.0))))
end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[(N[(2.0 * Pi), $MachinePrecision] / 3.0), $MachinePrecision] + N[(N[ArcCos[N[((-g) / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[g_, h_] := N[(2.0 * N[Cos[N[(Pi * 0.6666666666666666 + N[(N[ArcCos[(-N[(g / h), $MachinePrecision])], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
2 \cdot \cos \left(\mathsf{fma}\left(\pi, 0.6666666666666666, \frac{\cos^{-1} \left(-\frac{g}{h}\right)}{3}\right)\right)

Local Percentage Accuracy?

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 3 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Derivation?

  1. Initial program 98.5%

    \[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
  2. Simplified98.5%

    \[\leadsto \color{blue}{2 \cdot \cos \left(\mathsf{fma}\left(\pi, 0.6666666666666666, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)} \]
    Step-by-step derivation

    [Start]98.5

    \[ 2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]

    associate-/l* [=>]98.5

    \[ 2 \cdot \cos \left(\color{blue}{\frac{2}{\frac{3}{\pi}}} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]

    associate-/r/ [=>]98.5

    \[ 2 \cdot \cos \left(\color{blue}{\frac{2}{3} \cdot \pi} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]

    *-commutative [=>]98.5

    \[ 2 \cdot \cos \left(\color{blue}{\pi \cdot \frac{2}{3}} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]

    fma-def [=>]98.5

    \[ 2 \cdot \cos \color{blue}{\left(\mathsf{fma}\left(\pi, \frac{2}{3}, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)} \]

    metadata-eval [=>]98.5

    \[ 2 \cdot \cos \left(\mathsf{fma}\left(\pi, \color{blue}{0.6666666666666666}, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right) \]
  3. Final simplification98.5%

    \[\leadsto 2 \cdot \cos \left(\mathsf{fma}\left(\pi, 0.6666666666666666, \frac{\cos^{-1} \left(-\frac{g}{h}\right)}{3}\right)\right) \]

Alternatives

Alternative 1
Accuracy98.5%
Cost19904
\[2 \cdot \cos \left(\frac{\cos^{-1} \left(-\frac{g}{h}\right)}{3} + \pi \cdot 0.6666666666666666\right) \]
Alternative 2
Accuracy96.5%
Cost19840
\[2 \cdot \cos \left(\cos^{-1} \left(\frac{g}{h}\right) \cdot 0.3333333333333333 + \pi \cdot 0.6666666666666666\right) \]

Reproduce?

herbie shell --seed 2023162 
(FPCore (g h)
  :name "2-ancestry mixing, negative discriminant"
  :precision binary64
  (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))