Average Error: 38.6 → 28.7
Time: 38.0s
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}\;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)} = -\infty \lor \neg \left(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)} \le 2.124445660313305561909369816980475178885 \cdot 10^{281}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\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)}\\ \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}\;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)} = -\infty \lor \neg \left(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)} \le 2.124445660313305561909369816980475178885 \cdot 10^{281}\right):\\
\;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\

\mathbf{else}:\\
\;\;\;\;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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\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)}\\

\end{array}
double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r97295 = R;
        double r97296 = lambda1;
        double r97297 = lambda2;
        double r97298 = r97296 - r97297;
        double r97299 = phi1;
        double r97300 = phi2;
        double r97301 = r97299 + r97300;
        double r97302 = 2.0;
        double r97303 = r97301 / r97302;
        double r97304 = cos(r97303);
        double r97305 = r97298 * r97304;
        double r97306 = r97305 * r97305;
        double r97307 = r97299 - r97300;
        double r97308 = r97307 * r97307;
        double r97309 = r97306 + r97308;
        double r97310 = sqrt(r97309);
        double r97311 = r97295 * r97310;
        return r97311;
}

double f(double R, double lambda1, double lambda2, double phi1, double phi2) {
        double r97312 = R;
        double r97313 = lambda1;
        double r97314 = lambda2;
        double r97315 = r97313 - r97314;
        double r97316 = phi1;
        double r97317 = phi2;
        double r97318 = r97316 + r97317;
        double r97319 = 2.0;
        double r97320 = r97318 / r97319;
        double r97321 = cos(r97320);
        double r97322 = r97315 * r97321;
        double r97323 = r97322 * r97322;
        double r97324 = r97316 - r97317;
        double r97325 = r97324 * r97324;
        double r97326 = r97323 + r97325;
        double r97327 = sqrt(r97326);
        double r97328 = r97312 * r97327;
        double r97329 = -inf.0;
        bool r97330 = r97328 <= r97329;
        double r97331 = 2.1244456603133056e+281;
        bool r97332 = r97328 <= r97331;
        double r97333 = !r97332;
        bool r97334 = r97330 || r97333;
        double r97335 = r97317 - r97316;
        double r97336 = r97312 * r97335;
        double r97337 = 2.0;
        double r97338 = pow(r97314, r97337);
        double r97339 = 0.5;
        double r97340 = r97339 * r97317;
        double r97341 = cos(r97340);
        double r97342 = r97339 * r97316;
        double r97343 = cos(r97342);
        double r97344 = r97341 * r97343;
        double r97345 = sin(r97340);
        double r97346 = sin(r97342);
        double r97347 = r97345 * r97346;
        double r97348 = r97344 - r97347;
        double r97349 = pow(r97348, r97337);
        double r97350 = r97338 * r97349;
        double r97351 = r97317 * r97339;
        double r97352 = sin(r97351);
        double r97353 = r97316 * r97339;
        double r97354 = sin(r97353);
        double r97355 = r97352 * r97354;
        double r97356 = r97344 - r97355;
        double r97357 = pow(r97356, r97337);
        double r97358 = pow(r97313, r97337);
        double r97359 = r97357 * r97358;
        double r97360 = r97350 + r97359;
        double r97361 = r97317 + r97316;
        double r97362 = r97339 * r97361;
        double r97363 = cos(r97362);
        double r97364 = pow(r97363, r97337);
        double r97365 = r97364 * r97313;
        double r97366 = r97314 * r97365;
        double r97367 = r97337 * r97366;
        double r97368 = r97360 - r97367;
        double r97369 = r97368 + r97325;
        double r97370 = sqrt(r97369);
        double r97371 = r97312 * r97370;
        double r97372 = r97334 ? r97336 : r97371;
        return r97372;
}

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 (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))) < -inf.0 or 2.1244456603133056e+281 < (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2)))))

    1. Initial program 63.1

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

      \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)}\]

    if -inf.0 < (* R (sqrt (+ (* (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0))) (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2.0)))) (* (- phi1 phi2) (- phi1 phi2))))) < 2.1244456603133056e+281

    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 \color{blue}{\left(0.5 \cdot \phi_2 + 0.5 \cdot \phi_1\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)}\]
    5. Applied cos-sum1.3

      \[\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(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)}\]
    6. Using strategy rm
    7. Applied distribute-lft-in1.3

      \[\leadsto 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 \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)}\]
    8. Applied cos-sum0.7

      \[\leadsto 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} + {\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)}\]
    9. Simplified0.7

      \[\leadsto 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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;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)} = -\infty \lor \neg \left(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)} \le 2.124445660313305561909369816980475178885 \cdot 10^{281}\right):\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \mathbf{else}:\\ \;\;\;\;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(0.5 \cdot \phi_2\right) \cdot \cos \left(0.5 \cdot \phi_1\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)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019208 
(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))))))