Average Error: 1.0 → 1.0
Time: 12.6s
Precision: 64
\[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\]
\[2 \cdot \mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right)\right)\right)\right)\right)\]
2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
2 \cdot \mathsf{log1p}\left(\left(\mathsf{expm1}\left(\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right)\right)\right)\right)\right)
double f(double g, double h) {
        double r4002578 = 2.0;
        double r4002579 = atan2(1.0, 0.0);
        double r4002580 = r4002578 * r4002579;
        double r4002581 = 3.0;
        double r4002582 = r4002580 / r4002581;
        double r4002583 = g;
        double r4002584 = -r4002583;
        double r4002585 = h;
        double r4002586 = r4002584 / r4002585;
        double r4002587 = acos(r4002586);
        double r4002588 = r4002587 / r4002581;
        double r4002589 = r4002582 + r4002588;
        double r4002590 = cos(r4002589);
        double r4002591 = r4002578 * r4002590;
        return r4002591;
}

double f(double g, double h) {
        double r4002592 = 2.0;
        double r4002593 = 0.6666666666666666;
        double r4002594 = atan2(1.0, 0.0);
        double r4002595 = g;
        double r4002596 = -r4002595;
        double r4002597 = h;
        double r4002598 = r4002596 / r4002597;
        double r4002599 = acos(r4002598);
        double r4002600 = 3.0;
        double r4002601 = r4002599 / r4002600;
        double r4002602 = fma(r4002593, r4002594, r4002601);
        double r4002603 = cos(r4002602);
        double r4002604 = expm1(r4002603);
        double r4002605 = log1p(r4002604);
        double r4002606 = r4002592 * r4002605;
        return r4002606;
}

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}{\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right) \cdot 2}\]
  3. Using strategy rm
  4. Applied log1p-expm1-u1.0

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

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

Reproduce

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