Average Error: 38.9 → 32.8
Time: 6.9s
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}\;\phi_2 \le -3.3249148060297065 \cdot 10^{146}:\\ \;\;\;\;R \cdot \left(-\left(\phi_2 + \left(\frac{\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)}{\phi_1} + \frac{\phi_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)}{{\phi_1}^{2}}\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \le -1.18009183834190891 \cdot 10^{-83}:\\ \;\;\;\;R \cdot \sqrt{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \mathbf{elif}\;\phi_2 \le -3.4664449046846123 \cdot 10^{-180}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{elif}\;\phi_2 \le 4.2118397995985516 \cdot 10^{84}:\\ \;\;\;\;R \cdot \sqrt{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\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}\;\phi_2 \le -3.3249148060297065 \cdot 10^{146}:\\
\;\;\;\;R \cdot \left(-\left(\phi_2 + \left(\frac{\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)}{\phi_1} + \frac{\phi_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)}{{\phi_1}^{2}}\right)\right)\right)\\

\mathbf{elif}\;\phi_2 \le -1.18009183834190891 \cdot 10^{-83}:\\
\;\;\;\;R \cdot \sqrt{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\

\mathbf{elif}\;\phi_2 \le -3.4664449046846123 \cdot 10^{-180}:\\
\;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\

\mathbf{elif}\;\phi_2 \le 4.2118397995985516 \cdot 10^{84}:\\
\;\;\;\;R \cdot \sqrt{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\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 (R * sqrt(((((lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0))) * ((lambda1 - lambda2) * cos(((phi1 + phi2) / 2.0)))) + ((phi1 - phi2) * (phi1 - phi2)))));
}
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
	double VAR;
	if ((phi2 <= -3.3249148060297065e+146)) {
		VAR = (R * -(phi2 + (((lambda2 * (pow(cos((0.5 * (phi2 + phi1))), 2.0) * lambda1)) / phi1) + ((phi2 * (lambda2 * (pow(cos((0.5 * (phi2 + phi1))), 2.0) * lambda1))) / pow(phi1, 2.0)))));
	} else {
		double VAR_1;
		if ((phi2 <= -1.1800918383419089e-83)) {
			VAR_1 = (R * sqrt((((cos(((phi1 + phi2) / 2.0)) * cos(((phi1 + phi2) / 2.0))) * ((lambda1 - lambda2) * (lambda1 - lambda2))) + ((phi1 - phi2) * (phi1 - phi2)))));
		} else {
			double VAR_2;
			if ((phi2 <= -3.4664449046846123e-180)) {
				VAR_2 = (R * (lambda2 - lambda1));
			} else {
				double VAR_3;
				if ((phi2 <= 4.211839799598552e+84)) {
					VAR_3 = (R * sqrt((((cos(((phi1 + phi2) / 2.0)) * cos(((phi1 + phi2) / 2.0))) * ((lambda1 - lambda2) * (lambda1 - lambda2))) + ((phi1 - phi2) * (phi1 - phi2)))));
				} else {
					VAR_3 = (R * (phi2 - phi1));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	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 4 regimes
  2. if phi2 < -3.3249148060297065e+146

    1. Initial program 62.6

      \[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 *-commutative62.6

      \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    4. Applied *-commutative62.6

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    5. Applied swap-sqr62.6

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    6. Taylor expanded around inf 44.4

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

    if -3.3249148060297065e+146 < phi2 < -1.1800918383419089e-83 or -3.4664449046846123e-180 < phi2 < 4.211839799598552e+84

    1. Initial program 31.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. Using strategy rm
    3. Applied *-commutative31.9

      \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    4. Applied *-commutative31.9

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    5. Applied swap-sqr31.9

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

    if -1.1800918383419089e-83 < phi2 < -3.4664449046846123e-180

    1. Initial program 31.4

      \[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 *-commutative31.4

      \[\leadsto R \cdot \sqrt{\left(\left(\lambda_1 - \lambda_2\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    4. Applied *-commutative31.4

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} \cdot \left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    5. Applied swap-sqr31.5

      \[\leadsto R \cdot \sqrt{\color{blue}{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right)} + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\]
    6. Taylor expanded around 0 47.4

      \[\leadsto R \cdot \color{blue}{\left(\lambda_2 - \lambda_1\right)}\]

    if 4.211839799598552e+84 < phi2

    1. Initial program 53.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 21.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\phi_2 \le -3.3249148060297065 \cdot 10^{146}:\\ \;\;\;\;R \cdot \left(-\left(\phi_2 + \left(\frac{\lambda_2 \cdot \left({\left(\cos \left(0.5 \cdot \left(\phi_2 + \phi_1\right)\right)\right)}^{2} \cdot \lambda_1\right)}{\phi_1} + \frac{\phi_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)}{{\phi_1}^{2}}\right)\right)\right)\\ \mathbf{elif}\;\phi_2 \le -1.18009183834190891 \cdot 10^{-83}:\\ \;\;\;\;R \cdot \sqrt{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\right)\right) + \left(\phi_1 - \phi_2\right) \cdot \left(\phi_1 - \phi_2\right)}\\ \mathbf{elif}\;\phi_2 \le -3.4664449046846123 \cdot 10^{-180}:\\ \;\;\;\;R \cdot \left(\lambda_2 - \lambda_1\right)\\ \mathbf{elif}\;\phi_2 \le 4.2118397995985516 \cdot 10^{84}:\\ \;\;\;\;R \cdot \sqrt{\left(\cos \left(\frac{\phi_1 + \phi_2}{2}\right) \cdot \cos \left(\frac{\phi_1 + \phi_2}{2}\right)\right) \cdot \left(\left(\lambda_1 - \lambda_2\right) \cdot \left(\lambda_1 - \lambda_2\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 2020071 
(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))))))