Average Error: 24.5 → 24.5
Time: 49.9s
Precision: 64
\[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right)\]
\[\left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1, \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)\right)}}{\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\]
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right)
\left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1, \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)\right)}}{\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r1538445 = R;
        double r1538446 = 2.0;
        double r1538447 = phi1;
        double r1538448 = phi2;
        double r1538449 = r1538447 - r1538448;
        double r1538450 = r1538449 / r1538446;
        double r1538451 = sin(r1538450);
        double r1538452 = pow(r1538451, r1538446);
        double r1538453 = cos(r1538447);
        double r1538454 = cos(r1538448);
        double r1538455 = r1538453 * r1538454;
        double r1538456 = lambda1;
        double r1538457 = lambda2;
        double r1538458 = r1538456 - r1538457;
        double r1538459 = r1538458 / r1538446;
        double r1538460 = sin(r1538459);
        double r1538461 = r1538455 * r1538460;
        double r1538462 = r1538461 * r1538460;
        double r1538463 = r1538452 + r1538462;
        double r1538464 = sqrt(r1538463);
        double r1538465 = 1.0;
        double r1538466 = r1538465 - r1538463;
        double r1538467 = sqrt(r1538466);
        double r1538468 = atan2(r1538464, r1538467);
        double r1538469 = r1538446 * r1538468;
        double r1538470 = r1538445 * r1538469;
        return r1538470;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r1538471 = R;
        double r1538472 = 2.0;
        double r1538473 = r1538471 * r1538472;
        double r1538474 = phi2;
        double r1538475 = cos(r1538474);
        double r1538476 = lambda1;
        double r1538477 = lambda2;
        double r1538478 = r1538476 - r1538477;
        double r1538479 = r1538478 / r1538472;
        double r1538480 = sin(r1538479);
        double r1538481 = r1538475 * r1538480;
        double r1538482 = phi1;
        double r1538483 = cos(r1538482);
        double r1538484 = r1538480 * r1538483;
        double r1538485 = r1538482 - r1538474;
        double r1538486 = r1538485 / r1538472;
        double r1538487 = sin(r1538486);
        double r1538488 = log1p(r1538487);
        double r1538489 = expm1(r1538488);
        double r1538490 = r1538487 * r1538489;
        double r1538491 = fma(r1538481, r1538484, r1538490);
        double r1538492 = sqrt(r1538491);
        double r1538493 = cos(r1538486);
        double r1538494 = expm1(r1538493);
        double r1538495 = log1p(r1538494);
        double r1538496 = r1538495 * r1538495;
        double r1538497 = r1538484 * r1538481;
        double r1538498 = r1538496 - r1538497;
        double r1538499 = sqrt(r1538498);
        double r1538500 = atan2(r1538492, r1538499);
        double r1538501 = r1538473 * r1538500;
        return r1538501;
}

Error

Bits error versus R

Bits error versus lambda1

Bits error versus lambda2

Bits error versus phi1

Bits error versus phi2

Derivation

  1. Initial program 24.5

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)}}{\sqrt{1 - \left({\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right) \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\right)\]
  2. Simplified24.5

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2, \cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\cos \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 - \phi_2}{2}\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2\right) \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}} \cdot \left(R \cdot 2\right)}\]
  3. Using strategy rm
  4. Applied expm1-log1p-u24.5

    \[\leadsto \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2, \cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)} \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\cos \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 - \phi_2}{2}\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2\right) \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}} \cdot \left(R \cdot 2\right)\]
  5. Using strategy rm
  6. Applied log1p-expm1-u24.5

    \[\leadsto \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2, \cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)} \cdot \cos \left(\frac{\phi_1 - \phi_2}{2}\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2\right) \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}} \cdot \left(R \cdot 2\right)\]
  7. Using strategy rm
  8. Applied log1p-expm1-u24.5

    \[\leadsto \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2, \cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) \cdot \sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)}}{\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)} - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_2\right) \cdot \left(\cos \phi_1 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}} \cdot \left(R \cdot 2\right)\]
  9. Final simplification24.5

    \[\leadsto \left(R \cdot 2\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1, \sin \left(\frac{\phi_1 - \phi_2}{2}\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right)\right)}}{\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\frac{\phi_1 - \phi_2}{2}\right)\right)\right) - \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \cos \phi_1\right) \cdot \left(\cos \phi_2 \cdot \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\right)}}\]

Reproduce

herbie shell --seed 2019152 +o rules:numerics
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Distance on a great circle"
  (* R (* 2 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2)) 2) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2))) (sin (/ (- lambda1 lambda2) 2))))) (sqrt (- 1 (+ (pow (sin (/ (- phi1 phi2) 2)) 2) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2))) (sin (/ (- lambda1 lambda2) 2))))))))))