Average Error: 36.1 → 24.8
Time: 1.3m
Precision: 64
Internal precision: 128
\[R \cdot \sqrt{{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}^2 + {\left(\phi_1 - \phi_2\right)}^2}\]
\[\begin{array}{l} \mathbf{if}\;\phi_2 \le -4.105018222076383 \cdot 10^{+161}:\\ \;\;\;\;R \cdot \left(\left(\frac{1}{2} \cdot \frac{{\left(\cos \left(\frac{1}{2} \cdot \left(\frac{1}{\phi_1} + \frac{1}{\phi_2}\right)\right)\right)}^2 \cdot \phi_2}{{\lambda_1}^2 \cdot {\phi_1}^2} + \phi_1\right) - \phi_2\right)\\ \mathbf{if}\;\phi_2 \le 8.289315905944159 \cdot 10^{+107}:\\ \;\;\;\;R \cdot \sqrt{{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}^2 + {\left(\phi_1 - \phi_2\right)}^2}\\ \mathbf{else}:\\ \;\;\;\;R \cdot \left(\phi_2 - \phi_1\right)\\ \end{array}\]

Error

Bits error versus R

Bits error versus lambda1

Bits error versus lambda2

Bits error versus phi1

Bits error versus phi2

Derivation

  1. Split input into 3 regimes.
  2. if phi2 < -4.105018222076383e+161

    1. Initial program 61.7

      \[R \cdot \sqrt{{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}^2 + {\left(\phi_1 - \phi_2\right)}^2}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt 61.7

      \[\leadsto R \cdot \sqrt{\color{blue}{{\left(\sqrt[3]{{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}^2}\right)}^3} + {\left(\phi_1 - \phi_2\right)}^2}\]
    4. Using strategy rm
    5. Applied square-prod 61.7

      \[\leadsto R \cdot \sqrt{{\left(\sqrt[3]{\color{blue}{{\left(\lambda_1 - \lambda_2\right)}^2 \cdot {\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}^2}}\right)}^3 + {\left(\phi_1 - \phi_2\right)}^2}\]
    6. Applied cbrt-prod 61.7

      \[\leadsto R \cdot \sqrt{{\color{blue}{\left(\sqrt[3]{{\left(\lambda_1 - \lambda_2\right)}^2} \cdot \sqrt[3]{{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}^2}\right)}}^3 + {\left(\phi_1 - \phi_2\right)}^2}\]
    7. Applied taylor 16.0

      \[\leadsto R \cdot \left(\left(\frac{1}{2} \cdot \frac{{\left(\cos \left(\frac{1}{2} \cdot \left(\frac{1}{\phi_1} + \frac{1}{\phi_2}\right)\right)\right)}^2 \cdot \phi_2}{{\lambda_1}^2 \cdot {\phi_1}^2} + \phi_1\right) - \phi_2\right)\]
    8. Taylor expanded around inf 16.0

      \[\leadsto R \cdot \color{blue}{\left(\left(\frac{1}{2} \cdot \frac{{\left(\cos \left(\frac{1}{2} \cdot \left(\frac{1}{\phi_1} + \frac{1}{\phi_2}\right)\right)\right)}^2 \cdot \phi_2}{{\lambda_1}^2 \cdot {\phi_1}^2} + \phi_1\right) - \phi_2\right)}\]

    if -4.105018222076383e+161 < phi2 < 8.289315905944159e+107

    1. Initial program 30.3

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

    if 8.289315905944159e+107 < phi2

    1. Initial program 54.7

      \[R \cdot \sqrt{{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right)}^2 + {\left(\phi_1 - \phi_2\right)}^2}\]
    2. Applied taylor 0.0

      \[\leadsto R \cdot \left(\phi_2 - \phi_1\right)\]
    3. Taylor expanded around 0 0.0

      \[\leadsto R \cdot \color{blue}{\left(\phi_2 - \phi_1\right)}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 1.3m) Debug log

Please include this information when filing a bug report:

herbie --seed '#(4053867336 2222219051 4144786416 1091445303 1899459079 1921968717)'
(FPCore (R lambda1 lambda2 phi1 phi2)
  :name "Equirectangular approximation to distance on a great circle"
  (* R (sqrt (+ (sqr (* (- lambda1 lambda2) (cos (/ (+ phi1 phi2) 2)))) (sqr (- phi1 phi2))))))