Average Error: 38.5 → 28.3
Time: 13.8s
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)}\]
\[\begin{array}{l} \mathbf{if}\;\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) \le 7.02312313660020193 \cdot 10^{304}:\\ \;\;\;\;R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}^{2} + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array}\]
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)}
\begin{array}{l}
\mathbf{if}\;\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) \le 7.02312313660020193 \cdot 10^{304}:\\
\;\;\;\;R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}^{2} + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\

\mathbf{else}:\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

\end{array}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return ((double) (R * ((double) sqrt(((double) (((double) (((double) (((double) (lambda1 - lambda2)) * ((double) cos(((double) (((double) (phi1 + phi2)) / 2.0)))))) * ((double) (((double) (lambda1 - lambda2)) * ((double) cos(((double) (((double) (phi1 + phi2)) / 2.0)))))))) + ((double) (((double) (phi1 - phi2)) * ((double) (phi1 - phi2))))))))));
}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double VAR;
	if ((((double) (((double) (((double) (((double) (lambda1 - lambda2)) * ((double) cos(((double) (((double) (phi1 + phi2)) / 2.0)))))) * ((double) (((double) (lambda1 - lambda2)) * ((double) cos(((double) (((double) (phi1 + phi2)) / 2.0)))))))) + ((double) (((double) (phi1 - phi2)) * ((double) (phi1 - phi2)))))) <= 7.023123136600202e+304)) {
		VAR = ((double) (R * ((double) sqrt(((double) (((double) (((double) (((double) (((double) pow(lambda2, 2.0)) * ((double) pow(((double) (((double) (((double) cos(((double) (0.5 * phi2)))) * ((double) cos(((double) (0.5 * phi1)))))) - ((double) (((double) sin(((double) (0.5 * phi2)))) * ((double) sin(((double) (0.5 * phi1)))))))), 2.0)))) + ((double) (((double) pow(((double) (((double) (((double) cos(((double) (phi2 * 0.5)))) * ((double) cos(((double) (phi1 * 0.5)))))) - ((double) (((double) sin(((double) (phi2 * 0.5)))) * ((double) sin(((double) (phi1 * 0.5)))))))), 2.0)) * ((double) pow(lambda1, 2.0)))))) - ((double) (2.0 * ((double) (lambda2 * ((double) (((double) pow(((double) cos(((double) (0.5 * ((double) (phi2 + phi1)))))), 2.0)) * lambda1)))))))) + ((double) (((double) (phi1 - phi2)) * ((double) (phi1 - phi2))))))))));
	} else {
		VAR = ((double) (R * ((double) (phi2 - phi1))));
	}
	return VAR;
}

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. Split input into 2 regimes
  2. if (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))) < 7.023123136600202e+304

    1. Initial program 1.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. Taylor expanded around inf 1.9

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} + {\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right)} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    3. Using strategy rm
    4. Applied distribute-lft-in1.9

      \[\leadsto R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} + {\left(\cos \color{blue}{\left(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\right)}\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    5. Applied cos-sum1.3

      \[\leadsto R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} + {\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    6. Simplified1.3

      \[\leadsto R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} + {\left(\color{blue}{\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)} - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    7. Simplified1.3

      \[\leadsto R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \color{blue}{\sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)}\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    8. Using strategy rm
    9. Applied distribute-lft-in1.3

      \[\leadsto R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \color{blue}{\left(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\right)}\right)}^{2} + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    10. Applied cos-sum0.7

      \[\leadsto R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\color{blue}{\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}}^{2} + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]

    if 7.023123136600202e+304 < (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2)))

    1. Initial program 63.5

      \[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. Taylor expanded around 0 47.1

      \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\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) \le 7.02312313660020193 \cdot 10^{304}:\\ \;\;\;\;R \cdot \sqrt{\left(\left({\lambda_2}^{2} \cdot {\left(\cos \left(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\right) - \sin \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_1\right)\right)}^{2} + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(\phi_1 \cdot 0.5\right)\right)}^{2} \cdot {\lambda_1}^{2}\right) - 2 \cdot \left(\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array}\]

Reproduce

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