Average Error: 37.7 → 30.8
Time: 7.2m
Precision: 64
Internal Precision: 1408
\[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}\;\phi_2 \le 2.8760683199294135 \cdot 10^{+153}:\\ \;\;\;\;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 \log \left(e^{\cos \left(\frac{\phi_1 + \phi_2}{2}\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}\]

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 2 regimes
  2. if phi2 < 2.8760683199294135e+153

    1. Initial program 34.7

      \[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. Using strategy rm
    3. Applied add-log-exp34.7

      \[\leadsto 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 \color{blue}{\log \left(e^{\cos \left(\frac{\phi_1 + \phi_2}{2}\right)}\right)}\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]

    if 2.8760683199294135e+153 < phi2

    1. Initial program 61.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. Taylor expanded around 0 0.0

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

Runtime

Time bar (total: 7.2m)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(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))))))