Average Error: 0.2 → 0.1
Time: 31.4s
Precision: binary64
Cost: 84288
\[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
\[\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos delta, \sin \phi_1, \cos theta \cdot \left(\sin delta \cdot \cos \phi_1\right)\right), -\sin \phi_1, \cos delta\right)} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (* (sin theta) (sin delta)) (cos phi1))
   (-
    (cos delta)
    (*
     (sin phi1)
     (sin
      (asin
       (+
        (* (sin phi1) (cos delta))
        (* (* (cos phi1) (sin delta)) (cos theta))))))))))
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (+
  lambda1
  (atan2
   (* (sin delta) (* (cos phi1) (sin theta)))
   (fma
    (fma (cos delta) (sin phi1) (* (cos theta) (* (sin delta) (cos phi1))))
    (- (sin phi1))
    (cos delta)))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
}
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + atan2((sin(delta) * (cos(phi1) * sin(theta))), fma(fma(cos(delta), sin(phi1), (cos(theta) * (sin(delta) * cos(phi1)))), -sin(phi1), cos(delta)));
}
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(lambda1 + atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), Float64(cos(delta) - Float64(sin(phi1) * sin(asin(Float64(Float64(sin(phi1) * cos(delta)) + Float64(Float64(cos(phi1) * sin(delta)) * cos(theta)))))))))
end
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(lambda1 + atan(Float64(sin(delta) * Float64(cos(phi1) * sin(theta))), fma(fma(cos(delta), sin(phi1), Float64(cos(theta) * Float64(sin(delta) * cos(phi1)))), Float64(-sin(phi1)), cos(delta))))
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(lambda1 + N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - N[(N[Sin[phi1], $MachinePrecision] * N[Sin[N[ArcSin[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Cos[delta], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(lambda1 + N[ArcTan[N[(N[Sin[delta], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Sin[theta], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[delta], $MachinePrecision] * N[Sin[phi1], $MachinePrecision] + N[(N[Cos[theta], $MachinePrecision] * N[(N[Sin[delta], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Sin[phi1], $MachinePrecision]) + N[Cos[delta], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}
\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos delta, \sin \phi_1, \cos theta \cdot \left(\sin delta \cdot \cos \phi_1\right)\right), -\sin \phi_1, \cos delta\right)}

Error

Derivation

  1. Initial program 0.2

    \[\lambda_1 + \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
  2. Simplified0.2

    \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \sin \sin^{-1} \left(\mathsf{fma}\left(\sin delta, \cos \phi_1 \cdot \cos theta, \cos delta \cdot \sin \phi_1\right)\right)}} \]
    Proof
    (+.f64 lambda1 (atan2.f64 (*.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (sin.f64 theta))) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (fma.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (cos.f64 theta)) (*.f64 (cos.f64 delta) (sin.f64 phi1))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (sin.f64 delta) (Rewrite<= *-commutative_binary64 (*.f64 (sin.f64 theta) (cos.f64 phi1)))) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (fma.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (cos.f64 theta)) (*.f64 (cos.f64 delta) (sin.f64 phi1))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (sin.f64 delta) (sin.f64 theta)) (cos.f64 phi1))) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (fma.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (cos.f64 theta)) (*.f64 (cos.f64 delta) (sin.f64 phi1))))))))): 3 points increase in error, 1 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (sin.f64 theta) (sin.f64 delta))) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (fma.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (cos.f64 theta)) (*.f64 (cos.f64 delta) (sin.f64 phi1))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (sin.f64 phi1)))) (sin.f64 (asin.f64 (fma.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (cos.f64 theta)) (*.f64 (cos.f64 delta) (sin.f64 phi1))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (neg.f64 (neg.f64 (sin.f64 phi1))) (sin.f64 (asin.f64 (fma.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (cos.f64 theta)) (Rewrite<= *-commutative_binary64 (*.f64 (sin.f64 phi1) (cos.f64 delta)))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (neg.f64 (neg.f64 (sin.f64 phi1))) (sin.f64 (asin.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (sin.f64 delta) (*.f64 (cos.f64 phi1) (cos.f64 theta))) (*.f64 (sin.f64 phi1) (cos.f64 delta)))))))))): 1 points increase in error, 1 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (neg.f64 (neg.f64 (sin.f64 phi1))) (sin.f64 (asin.f64 (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (sin.f64 delta) (cos.f64 phi1)) (cos.f64 theta))) (*.f64 (sin.f64 phi1) (cos.f64 delta))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (neg.f64 (neg.f64 (sin.f64 phi1))) (sin.f64 (asin.f64 (+.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 (cos.f64 phi1) (sin.f64 delta))) (cos.f64 theta)) (*.f64 (sin.f64 phi1) (cos.f64 delta))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (-.f64 (cos.f64 delta) (*.f64 (neg.f64 (neg.f64 (sin.f64 phi1))) (sin.f64 (asin.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta)))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (Rewrite=> cancel-sign-sub_binary64 (+.f64 (cos.f64 delta) (*.f64 (neg.f64 (sin.f64 phi1)) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta)))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 lambda1 (atan2.f64 (*.f64 (*.f64 (sin.f64 theta) (sin.f64 delta)) (cos.f64 phi1)) (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (cos.f64 delta) (*.f64 (sin.f64 phi1) (sin.f64 (asin.f64 (+.f64 (*.f64 (sin.f64 phi1) (cos.f64 delta)) (*.f64 (*.f64 (cos.f64 phi1) (sin.f64 delta)) (cos.f64 theta)))))))))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.1

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\cos delta, \sin \phi_1, \left(\sin delta \cdot \cos theta\right) \cdot \cos \phi_1\right), -\sin \phi_1, \cos delta\right)}} \]
  4. Applied egg-rr0.1

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos delta, \sin \phi_1, \color{blue}{{\left(\cos theta \cdot \left(\sin delta \cdot \cos \phi_1\right)\right)}^{1}}\right), -\sin \phi_1, \cos delta\right)} \]
  5. Final simplification0.1

    \[\leadsto \lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos delta, \sin \phi_1, \cos theta \cdot \left(\sin delta \cdot \cos \phi_1\right)\right), -\sin \phi_1, \cos delta\right)} \]

Alternatives

Alternative 1
Error0.1
Cost84288
\[\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\cos delta, \sin \phi_1, \cos \phi_1 \cdot \left(\sin delta \cdot \cos theta\right)\right), -\sin \phi_1, \cos delta\right)} \]
Alternative 2
Error0.2
Cost77952
\[\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \mathsf{fma}\left(\cos delta, \sin \phi_1, \cos \phi_1 \cdot \left(\sin delta \cdot \cos theta\right)\right)} \]
Alternative 3
Error0.2
Cost71680
\[\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \sin delta \cdot \left(\cos \phi_1 \cdot \cos theta\right)\right)} \]
Alternative 4
Error3.5
Cost65152
\[\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\sin delta \cdot \cos \phi_1 + \cos delta \cdot \sin \phi_1\right)} \]
Alternative 5
Error4.9
Cost45504
\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - {\sin \phi_1}^{2}} \]
Alternative 6
Error5.1
Cost39240
\[\begin{array}{l} t_1 := \cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)\\ t_2 := \lambda_1 + \tan^{-1}_* \frac{t_1}{\cos delta}\\ \mathbf{if}\;delta \leq -0.06143553106674193:\\ \;\;\;\;t_2\\ \mathbf{elif}\;delta \leq 2.1289870397713247 \cdot 10^{-15}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{t_1}{{\cos \phi_1}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error7.2
Cost32512
\[\lambda_1 + \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta} \]
Alternative 8
Error8.0
Cost26376
\[\begin{array}{l} t_1 := \lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \sin theta}{\cos delta}\\ \mathbf{if}\;theta \leq -56801.11291929814:\\ \;\;\;\;t_1\\ \mathbf{elif}\;theta \leq 1.3283140189769552 \cdot 10^{-92}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \left(\cos \phi_1 \cdot theta\right)}{\cos delta}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error8.6
Cost25984
\[\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot \sin theta}{\cos delta} \]
Alternative 10
Error15.0
Cost19848
\[\begin{array}{l} t_1 := \lambda_1 + \tan^{-1}_* \frac{delta \cdot \sin theta}{\cos delta}\\ \mathbf{if}\;theta \leq -1.4379630000168665 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;theta \leq -2.2646992340602262 \cdot 10^{-209}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{\sin delta \cdot theta}{\cos delta}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error16.2
Cost19584
\[\lambda_1 + \tan^{-1}_* \frac{delta \cdot \sin theta}{\cos delta} \]
Alternative 12
Error19.6
Cost13448
\[\begin{array}{l} \mathbf{if}\;\phi_1 \leq 2.286756765024666 \cdot 10^{-69}:\\ \;\;\;\;\lambda_1\\ \mathbf{elif}\;\phi_1 \leq 1.2753795301530433 \cdot 10^{+230}:\\ \;\;\;\;\lambda_1 + \tan^{-1}_* \frac{delta \cdot theta}{\cos delta}\\ \mathbf{else}:\\ \;\;\;\;\lambda_1\\ \end{array} \]
Alternative 13
Error19.0
Cost64
\[\lambda_1 \]

Error

Reproduce

herbie shell --seed 2022294 
(FPCore (lambda1 phi1 phi2 delta theta)
  :name "Destination given bearing on a great circle"
  :precision binary64
  (+ lambda1 (atan2 (* (* (sin theta) (sin delta)) (cos phi1)) (- (cos delta) (* (sin phi1) (sin (asin (+ (* (sin phi1) (cos delta)) (* (* (cos phi1) (sin delta)) (cos theta))))))))))