Average Error: 36.9 → 0.1
Time: 52.7s
Precision: 64
\[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
\[\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \left(-\left(\lambda_1 - \lambda_2\right)\right), \phi_1 - \phi_2\right) \cdot R\]
R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}
\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \left(-\left(\lambda_1 - \lambda_2\right)\right), \phi_1 - \phi_2\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r1886644 = R;
        double r1886645 = lambda1;
        double r1886646 = lambda2;
        double r1886647 = r1886645 - r1886646;
        double r1886648 = phi1;
        double r1886649 = phi2;
        double r1886650 = r1886648 + r1886649;
        double r1886651 = 2.0;
        double r1886652 = r1886650 / r1886651;
        double r1886653 = cos(r1886652);
        double r1886654 = r1886647 * r1886653;
        double r1886655 = r1886654 * r1886654;
        double r1886656 = r1886648 - r1886649;
        double r1886657 = r1886656 * r1886656;
        double r1886658 = r1886655 + r1886657;
        double r1886659 = sqrt(r1886658);
        double r1886660 = r1886644 * r1886659;
        return r1886660;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r1886661 = lambda1;
        double r1886662 = lambda2;
        double r1886663 = r1886661 - r1886662;
        double r1886664 = 0.5;
        double r1886665 = phi2;
        double r1886666 = r1886664 * r1886665;
        double r1886667 = cos(r1886666);
        double r1886668 = phi1;
        double r1886669 = r1886664 * r1886668;
        double r1886670 = cos(r1886669);
        double r1886671 = r1886667 * r1886670;
        double r1886672 = r1886663 * r1886671;
        double r1886673 = sin(r1886666);
        double r1886674 = sin(r1886669);
        double r1886675 = r1886673 * r1886674;
        double r1886676 = -r1886663;
        double r1886677 = r1886675 * r1886676;
        double r1886678 = r1886672 + r1886677;
        double r1886679 = r1886668 - r1886665;
        double r1886680 = hypot(r1886678, r1886679);
        double r1886681 = R;
        double r1886682 = r1886680 * r1886681;
        return r1886682;
}

Error

Bits error versus R

Bits error versus lambda1

Bits error versus lambda2

Bits error versus phi1

Bits error versus phi2

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 36.9

    \[R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
  2. Simplified3.8

    \[\leadsto \color{blue}{\mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_2 + \phi_1}{2}\right), \phi_1 - \phi_2\right) \cdot R}\]
  3. Taylor expanded around -inf 3.8

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot \left(\phi_1 + \phi_2\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  4. Using strategy rm
  5. Applied distribute-lft-in3.8

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \color{blue}{\left(\frac{1}{2} \cdot \phi_1 + \frac{1}{2} \cdot \phi_2\right)}, \phi_1 - \phi_2\right) \cdot R\]
  6. Applied cos-sum0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) - \sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  7. Using strategy rm
  8. Applied sub-neg0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right) + \left(-\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  9. Applied distribute-lft-in0.1

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_1\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) + \left(\lambda_1 - \lambda_2\right) \cdot \left(-\sin \left(\frac{1}{2} \cdot \phi_1\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right)\right)}, \phi_1 - \phi_2\right) \cdot R\]
  10. Final simplification0.1

    \[\leadsto \mathsf{hypot}\left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\cos \left(\frac{1}{2} \cdot \phi_2\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_1\right)\right) + \left(\sin \left(\frac{1}{2} \cdot \phi_2\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_1\right)\right) \cdot \left(-\left(\lambda_1 - \lambda_2\right)\right), \phi_1 - \phi_2\right) \cdot R\]

Reproduce

herbie shell --seed 2019152 +o rules:numerics
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Equirectangular approximation to distance on a great circle"
  (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2)))) (* (- phi1 phi2) (- phi1 phi2))))))