Average Error: 1.0 → 1.0
Time: 8.1s
Precision: 64
\[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(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\]
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(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)
double f(double g, double h) {
        double r84244 = 2.0;
        double r84245 = atan2(1.0, 0.0);
        double r84246 = r84244 * r84245;
        double r84247 = 3.0;
        double r84248 = r84246 / r84247;
        double r84249 = g;
        double r84250 = -r84249;
        double r84251 = h;
        double r84252 = r84250 / r84251;
        double r84253 = acos(r84252);
        double r84254 = r84253 / r84247;
        double r84255 = r84248 + r84254;
        double r84256 = cos(r84255);
        double r84257 = r84244 * r84256;
        return r84257;
}

double f(double g, double h) {
        double r84258 = 2.0;
        double r84259 = 3.0;
        double r84260 = r84258 / r84259;
        double r84261 = atan2(1.0, 0.0);
        double r84262 = g;
        double r84263 = -r84262;
        double r84264 = h;
        double r84265 = r84263 / r84264;
        double r84266 = acos(r84265);
        double r84267 = r84266 / r84259;
        double r84268 = fma(r84260, r84261, r84267);
        double r84269 = cos(r84268);
        double r84270 = r84258 * r84269;
        return r84270;
}

Error

Bits error versus g

Bits error versus h

Derivation

  1. Initial program 1.0

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

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

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

Reproduce

herbie shell --seed 2019208 +o rules:numerics
(FPCore (g h)
  :name "2-ancestry mixing, negative discriminant"
  :precision binary64
  (* 2 (cos (+ (/ (* 2 PI) 3) (/ (acos (/ (- g) h)) 3)))))