Average Error: 1.0 → 0.0
Time: 18.9s
Precision: 64
\[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\]
\[2 \cdot \log \left(\frac{1 - \mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right) \cdot \mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right)}{1 - \mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\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 \log \left(\frac{1 - \mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right) \cdot \mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right)}{1 - \mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right)}\right)
double f(double g, double h) {
        double r137110 = 2.0;
        double r137111 = atan2(1.0, 0.0);
        double r137112 = r137110 * r137111;
        double r137113 = 3.0;
        double r137114 = r137112 / r137113;
        double r137115 = g;
        double r137116 = -r137115;
        double r137117 = h;
        double r137118 = r137116 / r137117;
        double r137119 = acos(r137118);
        double r137120 = r137119 / r137113;
        double r137121 = r137114 + r137120;
        double r137122 = cos(r137121);
        double r137123 = r137110 * r137122;
        return r137123;
}

double f(double g, double h) {
        double r137124 = 2.0;
        double r137125 = 1.0;
        double r137126 = 3.0;
        double r137127 = r137124 / r137126;
        double r137128 = atan2(1.0, 0.0);
        double r137129 = g;
        double r137130 = -r137129;
        double r137131 = h;
        double r137132 = r137130 / r137131;
        double r137133 = acos(r137132);
        double r137134 = r137133 / r137126;
        double r137135 = fma(r137127, r137128, r137134);
        double r137136 = cos(r137135);
        double r137137 = expm1(r137136);
        double r137138 = r137137 * r137137;
        double r137139 = r137125 - r137138;
        double r137140 = r137125 - r137137;
        double r137141 = r137139 / r137140;
        double r137142 = log(r137141);
        double r137143 = r137124 * r137142;
        return r137143;
}

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. Using strategy rm
  4. Applied log1p-expm1-u1.0

    \[\leadsto 2 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right)\right)}\]
  5. Using strategy rm
  6. Applied log1p-udef1.0

    \[\leadsto 2 \cdot \color{blue}{\log \left(1 + \mathsf{expm1}\left(\cos \left(\mathsf{fma}\left(\frac{2}{3}, \pi, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\right)\right)}\]
  7. Using strategy rm
  8. Applied flip-+0.0

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

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

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

Reproduce

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