Average Error: 24.3 → 13.5
Time: 1.1min
Precision: binary64
\[[phi1, phi2]=\mathsf{sort}([phi1, phi2])\]
\[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\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({\sin \left(\frac{\phi_1 - \phi_2}{2}\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) \]
\[\begin{array}{l} t_0 := \sin \left(\phi_2 \cdot 0.5\right)\\ t_1 := \sin \left(0.5 \cdot \phi_1\right)\\ t_2 := \cos \left(\phi_2 \cdot 0.5\right)\\ t_3 := {t_1}^{2} \cdot {t_2}^{2}\\ t_4 := \cos \left(0.5 \cdot \phi_1\right)\\ t_5 := 2 \cdot \left(t_4 \cdot \left(t_1 \cdot \left(t_2 \cdot t_0\right)\right)\right)\\ t_6 := {t_4}^{2} \cdot {t_0}^{2}\\ 2 \cdot \left(R \cdot \tan^{-1}_* \frac{\sqrt{\left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + \left(t_3 + t_6\right)\right) - t_5}}{\sqrt{\left(t_5 + 1\right) - \left(t_3 + \left(t_6 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot {\left(\sin \left(0.5 \cdot \lambda_1\right) \cdot \cos \left(\lambda_2 \cdot -0.5\right) + \cos \left(0.5 \cdot \lambda_1\right) \cdot \sin \left(\lambda_2 \cdot -0.5\right)\right)}^{2}\right)\right)\right)}}\right) \end{array} \]
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\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({\sin \left(\frac{\phi_1 - \phi_2}{2}\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)
\begin{array}{l}
t_0 := \sin \left(\phi_2 \cdot 0.5\right)\\
t_1 := \sin \left(0.5 \cdot \phi_1\right)\\
t_2 := \cos \left(\phi_2 \cdot 0.5\right)\\
t_3 := {t_1}^{2} \cdot {t_2}^{2}\\
t_4 := \cos \left(0.5 \cdot \phi_1\right)\\
t_5 := 2 \cdot \left(t_4 \cdot \left(t_1 \cdot \left(t_2 \cdot t_0\right)\right)\right)\\
t_6 := {t_4}^{2} \cdot {t_0}^{2}\\
2 \cdot \left(R \cdot \tan^{-1}_* \frac{\sqrt{\left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + \left(t_3 + t_6\right)\right) - t_5}}{\sqrt{\left(t_5 + 1\right) - \left(t_3 + \left(t_6 + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot {\left(\sin \left(0.5 \cdot \lambda_1\right) \cdot \cos \left(\lambda_2 \cdot -0.5\right) + \cos \left(0.5 \cdot \lambda_1\right) \cdot \sin \left(\lambda_2 \cdot -0.5\right)\right)}^{2}\right)\right)\right)}}\right)
\end{array}
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (*
  R
  (*
   2.0
   (atan2
    (sqrt
     (+
      (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
      (*
       (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0)))
       (sin (/ (- lambda1 lambda2) 2.0)))))
    (sqrt
     (-
      1.0
      (+
       (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
       (*
        (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0)))
        (sin (/ (- lambda1 lambda2) 2.0))))))))))
(FPCore (R lambda1 lambda2 phi1 phi2)
 :precision binary64
 (let* ((t_0 (sin (* phi2 0.5)))
        (t_1 (sin (* 0.5 phi1)))
        (t_2 (cos (* phi2 0.5)))
        (t_3 (* (pow t_1 2.0) (pow t_2 2.0)))
        (t_4 (cos (* 0.5 phi1)))
        (t_5 (* 2.0 (* t_4 (* t_1 (* t_2 t_0)))))
        (t_6 (* (pow t_4 2.0) (pow t_0 2.0))))
   (*
    2.0
    (*
     R
     (atan2
      (sqrt
       (-
        (+
         (*
          (cos phi2)
          (* (pow (sin (* 0.5 (- lambda1 lambda2))) 2.0) (cos phi1)))
         (+ t_3 t_6))
        t_5))
      (sqrt
       (-
        (+ t_5 1.0)
        (+
         t_3
         (+
          t_6
          (*
           (cos phi2)
           (*
            (cos phi1)
            (pow
             (+
              (* (sin (* 0.5 lambda1)) (cos (* lambda2 -0.5)))
              (* (cos (* 0.5 lambda1)) (sin (* lambda2 -0.5))))
             2.0))))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	return R * (2.0 * atan2(sqrt(pow(sin((phi1 - phi2) / 2.0), 2.0) + (((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)) * sin((lambda1 - lambda2) / 2.0))), sqrt(1.0 - (pow(sin((phi1 - phi2) / 2.0), 2.0) + (((cos(phi1) * cos(phi2)) * sin((lambda1 - lambda2) / 2.0)) * sin((lambda1 - lambda2) / 2.0))))));
}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double t_0 = sin(phi2 * 0.5);
	double t_1 = sin(0.5 * phi1);
	double t_2 = cos(phi2 * 0.5);
	double t_3 = pow(t_1, 2.0) * pow(t_2, 2.0);
	double t_4 = cos(0.5 * phi1);
	double t_5 = 2.0 * (t_4 * (t_1 * (t_2 * t_0)));
	double t_6 = pow(t_4, 2.0) * pow(t_0, 2.0);
	return 2.0 * (R * atan2(sqrt(((cos(phi2) * (pow(sin(0.5 * (lambda1 - lambda2)), 2.0) * cos(phi1))) + (t_3 + t_6)) - t_5), sqrt((t_5 + 1.0) - (t_3 + (t_6 + (cos(phi2) * (cos(phi1) * pow(((sin(0.5 * lambda1) * cos(lambda2 * -0.5)) + (cos(0.5 * lambda1) * sin(lambda2 * -0.5))), 2.0))))))));
}

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 24.3

    \[R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\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({\sin \left(\frac{\phi_1 - \phi_2}{2}\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. Applied div-sub_binary6424.3

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\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({\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\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) \]
  3. Applied sin-diff_binary6423.6

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\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({\color{blue}{\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\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) \]
  4. Applied div-sub_binary6423.6

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \color{blue}{\left(\frac{\phi_1}{2} - \frac{\phi_2}{2}\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}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\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) \]
  5. Applied sin-diff_binary6413.8

    \[\leadsto R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\color{blue}{\left(\sin \left(\frac{\phi_1}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\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}{2}\right) \cdot \cos \left(\frac{\phi_2}{2}\right) - \cos \left(\frac{\phi_1}{2}\right) \cdot \sin \left(\frac{\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) \]
  6. Taylor expanded in R around 0 13.8

    \[\leadsto \color{blue}{2 \cdot \left(R \cdot \tan^{-1}_* \frac{\sqrt{\left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right) - 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}}{\sqrt{\left(1 + 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)\right) - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + \left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right)}}\right)} \]
  7. Applied sub-neg_binary6413.8

    \[\leadsto 2 \cdot \left(R \cdot \tan^{-1}_* \frac{\sqrt{\left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right) - 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}}{\sqrt{\left(1 + 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)\right) - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + \left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \color{blue}{\left(\lambda_1 + \left(-\lambda_2\right)\right)}\right)}^{2} \cdot \cos \phi_1\right) + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right)}}\right) \]
  8. Applied distribute-rgt-in_binary6413.8

    \[\leadsto 2 \cdot \left(R \cdot \tan^{-1}_* \frac{\sqrt{\left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right) - 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}}{\sqrt{\left(1 + 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)\right) - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + \left(\cos \phi_2 \cdot \left({\sin \color{blue}{\left(\lambda_1 \cdot 0.5 + \left(-\lambda_2\right) \cdot 0.5\right)}}^{2} \cdot \cos \phi_1\right) + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right)}}\right) \]
  9. Applied sin-sum_binary6413.5

    \[\leadsto 2 \cdot \left(R \cdot \tan^{-1}_* \frac{\sqrt{\left(\cos \phi_2 \cdot \left({\sin \left(0.5 \cdot \left(\lambda_1 - \lambda_2\right)\right)}^{2} \cdot \cos \phi_1\right) + \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right) - 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)}}{\sqrt{\left(1 + 2 \cdot \left(\cos \left(0.5 \cdot \phi_1\right) \cdot \left(\sin \left(0.5 \cdot \phi_1\right) \cdot \left(\cos \left(0.5 \cdot \phi_2\right) \cdot \sin \left(0.5 \cdot \phi_2\right)\right)\right)\right)\right) - \left({\sin \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\cos \left(0.5 \cdot \phi_2\right)}^{2} + \left(\cos \phi_2 \cdot \left({\color{blue}{\left(\sin \left(\lambda_1 \cdot 0.5\right) \cdot \cos \left(\left(-\lambda_2\right) \cdot 0.5\right) + \cos \left(\lambda_1 \cdot 0.5\right) \cdot \sin \left(\left(-\lambda_2\right) \cdot 0.5\right)\right)}}^{2} \cdot \cos \phi_1\right) + {\cos \left(0.5 \cdot \phi_1\right)}^{2} \cdot {\sin \left(0.5 \cdot \phi_2\right)}^{2}\right)\right)}}\right) \]
  10. Final simplification13.5

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

Reproduce

herbie shell --seed 2022019 
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Distance on a great circle"
  :precision binary64
  (* R (* 2.0 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))) (sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))))))))