Average Error: 37.0 → 0.1
Time: 2.0m
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(\left(\sin \left(\phi_1 \cdot \frac{1}{2}\right) \cdot \left(\lambda_2 - \lambda_1\right)\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right) - \left(\cos \left(\phi_1 \cdot \frac{1}{2}\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\right), \left(\phi_1 - \phi_2\right)\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(\left(\sin \left(\phi_1 \cdot \frac{1}{2}\right) \cdot \left(\lambda_2 - \lambda_1\right)\right) \cdot \sin \left(\frac{1}{2} \cdot \phi_2\right) - \left(\cos \left(\phi_1 \cdot \frac{1}{2}\right) \cdot \cos \left(\frac{1}{2} \cdot \phi_2\right)\right) \cdot \left(\lambda_2 - \lambda_1\right)\right), \left(\phi_1 - \phi_2\right)\right) \cdot R
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r10798640 = R;
        double r10798641 = lambda1;
        double r10798642 = lambda2;
        double r10798643 = r10798641 - r10798642;
        double r10798644 = phi1;
        double r10798645 = phi2;
        double r10798646 = r10798644 + r10798645;
        double r10798647 = 2.0;
        double r10798648 = r10798646 / r10798647;
        double r10798649 = cos(r10798648);
        double r10798650 = r10798643 * r10798649;
        double r10798651 = r10798650 * r10798650;
        double r10798652 = r10798644 - r10798645;
        double r10798653 = r10798652 * r10798652;
        double r10798654 = r10798651 + r10798653;
        double r10798655 = sqrt(r10798654);
        double r10798656 = r10798640 * r10798655;
        return r10798656;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r10798657 = phi1;
        double r10798658 = 0.5;
        double r10798659 = r10798657 * r10798658;
        double r10798660 = sin(r10798659);
        double r10798661 = lambda2;
        double r10798662 = lambda1;
        double r10798663 = r10798661 - r10798662;
        double r10798664 = r10798660 * r10798663;
        double r10798665 = phi2;
        double r10798666 = r10798658 * r10798665;
        double r10798667 = sin(r10798666);
        double r10798668 = r10798664 * r10798667;
        double r10798669 = cos(r10798659);
        double r10798670 = cos(r10798666);
        double r10798671 = r10798669 * r10798670;
        double r10798672 = r10798671 * r10798663;
        double r10798673 = r10798668 - r10798672;
        double r10798674 = r10798657 - r10798665;
        double r10798675 = hypot(r10798673, r10798674);
        double r10798676 = R;
        double r10798677 = r10798675 * r10798676;
        return r10798677;
}

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 37.0

    \[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.7

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

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

    \[\leadsto \mathsf{hypot}\left(\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)}\right), \left(\phi_1 - \phi_2\right)\right) \cdot R\]
  6. Applied cos-sum0.1

    \[\leadsto \mathsf{hypot}\left(\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)}\right), \left(\phi_1 - \phi_2\right)\right) \cdot R\]
  7. Taylor expanded around -inf 0.1

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

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

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

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

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

Reproduce

herbie shell --seed 2019124 +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))))))