Destination given bearing on a great circle

Percentage Accurate: 99.8% → 99.8%
Time: 6.0s
Alternatives: 10
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \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)} \end{array} \]
(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))))))))))
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))))))));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - (Math.sin(phi1) * Math.sin(Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - (math.sin(phi1) * math.sin(math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))))
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 tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
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]
\begin{array}{l}

\\
\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)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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)} \end{array} \]
(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))))))))))
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))))))));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - (Math.sin(phi1) * Math.sin(Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - (math.sin(phi1) * math.sin(math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))))
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 tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
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]
\begin{array}{l}

\\
\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)}
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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)} \end{array} \]
(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))))))))))
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))))))));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return lambda1 + Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - (Math.sin(phi1) * Math.sin(Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return lambda1 + math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - (math.sin(phi1) * math.sin(math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))))
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 tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = lambda1 + atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
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]
\begin{array}{l}

\\
\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)}
\end{array}
Derivation
  1. Initial program 99.7%

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

Alternative 2: 31.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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)} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (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 atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - (Math.sin(phi1) * Math.sin(Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - (math.sin(phi1) * math.sin(math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))))
function code(lambda1, phi1, phi2, delta, theta)
	return 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 tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - (sin(phi1) * sin(asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))));
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := 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]
\begin{array}{l}

\\
\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)}
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around 0

    \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}} \]
  4. Applied rewrites27.7%

    \[\leadsto \color{blue}{\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)}} \]
  5. Add Preprocessing

Alternative 3: 10.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1\\ \mathbf{if}\;delta \leq -7 \cdot 10^{-54}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{\cos delta - \sin^{-1} \left(\cos \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1}_* \frac{t\_1}{\cos \phi_1}\\ \end{array} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (let* ((t_1 (* (* (sin theta) (sin delta)) (cos phi1))))
   (if (<= delta -7e-54)
     (atan2
      t_1
      (-
       (cos delta)
       (asin
        (+
         (* (cos phi1) (cos delta))
         (* (* (cos phi1) (sin delta)) (cos theta))))))
     (atan2 t_1 (cos phi1)))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = (sin(theta) * sin(delta)) * cos(phi1);
	double tmp;
	if (delta <= -7e-54) {
		tmp = atan2(t_1, (cos(delta) - asin(((cos(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))));
	} else {
		tmp = atan2(t_1, cos(phi1));
	}
	return tmp;
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (sin(theta) * sin(delta)) * cos(phi1)
    if (delta <= (-7d-54)) then
        tmp = atan2(t_1, (cos(delta) - asin(((cos(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))
    else
        tmp = atan2(t_1, cos(phi1))
    end if
    code = tmp
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	double t_1 = (Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1);
	double tmp;
	if (delta <= -7e-54) {
		tmp = Math.atan2(t_1, (Math.cos(delta) - Math.asin(((Math.cos(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))));
	} else {
		tmp = Math.atan2(t_1, Math.cos(phi1));
	}
	return tmp;
}
def code(lambda1, phi1, phi2, delta, theta):
	t_1 = (math.sin(theta) * math.sin(delta)) * math.cos(phi1)
	tmp = 0
	if delta <= -7e-54:
		tmp = math.atan2(t_1, (math.cos(delta) - math.asin(((math.cos(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))
	else:
		tmp = math.atan2(t_1, math.cos(phi1))
	return tmp
function code(lambda1, phi1, phi2, delta, theta)
	t_1 = Float64(Float64(sin(theta) * sin(delta)) * cos(phi1))
	tmp = 0.0
	if (delta <= -7e-54)
		tmp = atan(t_1, Float64(cos(delta) - asin(Float64(Float64(cos(phi1) * cos(delta)) + Float64(Float64(cos(phi1) * sin(delta)) * cos(theta))))));
	else
		tmp = atan(t_1, cos(phi1));
	end
	return tmp
end
function tmp_2 = code(lambda1, phi1, phi2, delta, theta)
	t_1 = (sin(theta) * sin(delta)) * cos(phi1);
	tmp = 0.0;
	if (delta <= -7e-54)
		tmp = atan2(t_1, (cos(delta) - asin(((cos(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))));
	else
		tmp = atan2(t_1, cos(phi1));
	end
	tmp_2 = tmp;
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := Block[{t$95$1 = N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[delta, -7e-54], N[ArcTan[t$95$1 / N[(N[Cos[delta], $MachinePrecision] - N[ArcSin[N[(N[(N[Cos[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], N[ArcTan[t$95$1 / N[Cos[phi1], $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1\\
\mathbf{if}\;delta \leq -7 \cdot 10^{-54}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_1}{\cos delta - \sin^{-1} \left(\cos \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}\\

\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_1}{\cos \phi_1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if delta < -6.99999999999999964e-54

    1. Initial program 99.7%

      \[\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. Add Preprocessing
    3. Taylor expanded in lambda1 around 0

      \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}} \]
    4. Applied rewrites42.5%

      \[\leadsto \color{blue}{\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)}} \]
    5. Taylor expanded in phi1 around 0

      \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \phi_1 \cdot \color{blue}{\left(\cos theta \cdot \sin delta\right)}} \]
    6. Applied rewrites19.8%

      \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    7. Taylor expanded in phi1 around 0

      \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin^{-1} \left(\left(\phi_1 \cdot \left(1 + \frac{-1}{6} \cdot {\phi_1}^{2}\right)\right) \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
    8. Applied rewrites17.4%

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

    if -6.99999999999999964e-54 < delta

    1. Initial program 99.7%

      \[\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. Add Preprocessing
    3. Taylor expanded in lambda1 around 0

      \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}} \]
    4. Applied rewrites22.7%

      \[\leadsto \color{blue}{\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)}} \]
    5. Taylor expanded in phi1 around 0

      \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta + \color{blue}{\phi_1 \cdot \left(\phi_1 \cdot \left(-1 \cdot \left(\phi_1 \cdot \left(\frac{-1}{2} \cdot \left(\cos theta \cdot \sin delta\right) + \frac{-1}{6} \cdot \left(\cos theta \cdot \sin delta\right)\right)\right) - \cos delta\right) - \cos theta \cdot \sin delta\right)}} \]
    6. Applied rewrites10.6%

      \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos \phi_1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 14.2% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (atan2
  (* (* (sin theta) (sin delta)) (cos phi1))
  (-
   (cos delta)
   (asin
    (+
     (* (sin phi1) (cos delta))
     (* (* (cos phi1) (sin delta)) (cos theta)))))))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), (Math.cos(delta) - Math.asin(((Math.sin(phi1) * Math.cos(delta)) + ((Math.cos(phi1) * Math.sin(delta)) * Math.cos(theta))))));
}
def code(lambda1, phi1, phi2, delta, theta):
	return math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), (math.cos(delta) - math.asin(((math.sin(phi1) * math.cos(delta)) + ((math.cos(phi1) * math.sin(delta)) * math.cos(theta))))))
function code(lambda1, phi1, phi2, delta, theta)
	return atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), Float64(cos(delta) - asin(Float64(Float64(sin(phi1) * cos(delta)) + Float64(Float64(cos(phi1) * sin(delta)) * cos(theta))))))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = atan2(((sin(theta) * sin(delta)) * cos(phi1)), (cos(delta) - asin(((sin(phi1) * cos(delta)) + ((cos(phi1) * sin(delta)) * cos(theta))))));
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[delta], $MachinePrecision] - 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]
\begin{array}{l}

\\
\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)}
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around 0

    \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}} \]
  4. Applied rewrites27.7%

    \[\leadsto \color{blue}{\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)}} \]
  5. Taylor expanded in phi1 around 0

    \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \phi_1 \cdot \color{blue}{\left(\cos theta \cdot \sin delta\right)}} \]
  6. Applied rewrites13.7%

    \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta - \sin^{-1} \left(\sin \phi_1 \cdot \cos delta + \left(\cos \phi_1 \cdot \sin delta\right) \cdot \cos theta\right)} \]
  7. Add Preprocessing

Alternative 5: 11.1% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos \phi_1} \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (atan2 (* (* (sin theta) (sin delta)) (cos phi1)) (cos phi1)))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(phi1));
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(phi1))
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return Math.atan2(((Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1)), Math.cos(phi1));
}
def code(lambda1, phi1, phi2, delta, theta):
	return math.atan2(((math.sin(theta) * math.sin(delta)) * math.cos(phi1)), math.cos(phi1))
function code(lambda1, phi1, phi2, delta, theta)
	return atan(Float64(Float64(sin(theta) * sin(delta)) * cos(phi1)), cos(phi1))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = atan2(((sin(theta) * sin(delta)) * cos(phi1)), cos(phi1));
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[ArcTan[N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] / N[Cos[phi1], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos \phi_1}
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around 0

    \[\leadsto \color{blue}{\lambda_1 + \tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}} \]
  4. Applied rewrites27.7%

    \[\leadsto \color{blue}{\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)}} \]
  5. Taylor expanded in phi1 around 0

    \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos delta + \color{blue}{\phi_1 \cdot \left(\phi_1 \cdot \left(-1 \cdot \left(\phi_1 \cdot \left(\frac{-1}{2} \cdot \left(\cos theta \cdot \sin delta\right) + \frac{-1}{6} \cdot \left(\cos theta \cdot \sin delta\right)\right)\right) - \cos delta\right) - \cos theta \cdot \sin delta\right)}} \]
  6. Applied rewrites10.4%

    \[\leadsto \tan^{-1}_* \frac{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1}{\cos \phi_1} \]
  7. Add Preprocessing

Alternative 6: 10.0% accurate, 4.3× speedup?

\[\begin{array}{l} \\ \left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1 \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (* (* (sin theta) (sin delta)) (cos phi1)))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return (sin(theta) * sin(delta)) * cos(phi1);
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = (sin(theta) * sin(delta)) * cos(phi1)
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return (Math.sin(theta) * Math.sin(delta)) * Math.cos(phi1);
}
def code(lambda1, phi1, phi2, delta, theta):
	return (math.sin(theta) * math.sin(delta)) * math.cos(phi1)
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(Float64(sin(theta) * sin(delta)) * cos(phi1))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = (sin(theta) * sin(delta)) * cos(phi1);
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around inf

    \[\leadsto \color{blue}{\lambda_1} \]
  4. Applied rewrites9.5%

    \[\leadsto \color{blue}{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1} \]
  5. Add Preprocessing

Alternative 7: 9.0% accurate, 6.5× speedup?

\[\begin{array}{l} \\ \sin theta \cdot \sin delta \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta)
 :precision binary64
 (* (sin theta) (sin delta)))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return sin(theta) * sin(delta);
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = sin(theta) * sin(delta)
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return Math.sin(theta) * Math.sin(delta);
}
def code(lambda1, phi1, phi2, delta, theta):
	return math.sin(theta) * math.sin(delta)
function code(lambda1, phi1, phi2, delta, theta)
	return Float64(sin(theta) * sin(delta))
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = sin(theta) * sin(delta);
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[(N[Sin[theta], $MachinePrecision] * N[Sin[delta], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin theta \cdot \sin delta
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around inf

    \[\leadsto \color{blue}{\lambda_1 \cdot \left(1 + \frac{\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}}{\lambda_1}\right)} \]
  4. Applied rewrites8.2%

    \[\leadsto \color{blue}{\sin theta \cdot \sin delta} \]
  5. Add Preprocessing

Alternative 8: 5.3% accurate, 13.3× speedup?

\[\begin{array}{l} \\ \sin delta \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta) :precision binary64 (sin delta))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return sin(delta);
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = sin(delta)
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return Math.sin(delta);
}
def code(lambda1, phi1, phi2, delta, theta):
	return math.sin(delta)
function code(lambda1, phi1, phi2, delta, theta)
	return sin(delta)
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = sin(delta);
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[Sin[delta], $MachinePrecision]
\begin{array}{l}

\\
\sin delta
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around inf

    \[\leadsto \color{blue}{\lambda_1 \cdot \left(1 + \frac{\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}}{\lambda_1}\right)} \]
  4. Applied rewrites8.2%

    \[\leadsto \color{blue}{\sin theta \cdot \sin delta} \]
  5. Taylor expanded in lambda1 around inf

    \[\leadsto \color{blue}{\lambda_1 \cdot \left(1 + \frac{\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}}{\lambda_1}\right)} \]
  6. Applied rewrites5.0%

    \[\leadsto \color{blue}{\sin delta} \]
  7. Add Preprocessing

Alternative 9: 4.7% accurate, 13.3× speedup?

\[\begin{array}{l} \\ \cos \phi_1 \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta) :precision binary64 (cos phi1))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return cos(phi1);
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = cos(phi1)
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return Math.cos(phi1);
}
def code(lambda1, phi1, phi2, delta, theta):
	return math.cos(phi1)
function code(lambda1, phi1, phi2, delta, theta)
	return cos(phi1)
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = cos(phi1);
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[Cos[phi1], $MachinePrecision]
\begin{array}{l}

\\
\cos \phi_1
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around -inf

    \[\leadsto \color{blue}{-1 \cdot \left(\lambda_1 \cdot \left(-1 \cdot \frac{\tan^{-1}_* \frac{\cos \phi_1 \cdot \left(\sin delta \cdot \sin theta\right)}{\cos delta - \sin \phi_1 \cdot \left(\cos delta \cdot \sin \phi_1 + \cos \phi_1 \cdot \left(\cos theta \cdot \sin delta\right)\right)}}{\lambda_1} - 1\right)\right)} \]
  4. Applied rewrites4.0%

    \[\leadsto \color{blue}{\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)} \]
  5. Taylor expanded in phi1 around 0

    \[\leadsto \cos delta + \color{blue}{\phi_1 \cdot \left(\phi_1 \cdot \left(-1 \cdot \left(\phi_1 \cdot \left(\frac{-1}{2} \cdot \left(\cos theta \cdot \sin delta\right) + \frac{-1}{6} \cdot \left(\cos theta \cdot \sin delta\right)\right)\right) - \cos delta\right) - \cos theta \cdot \sin delta\right)} \]
  6. Applied rewrites4.6%

    \[\leadsto \cos \phi_1 \]
  7. Add Preprocessing

Alternative 10: 4.7% accurate, 13.3× speedup?

\[\begin{array}{l} \\ \cos delta \end{array} \]
(FPCore (lambda1 phi1 phi2 delta theta) :precision binary64 (cos delta))
double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return cos(delta);
}
real(8) function code(lambda1, phi1, phi2, delta, theta)
    real(8), intent (in) :: lambda1
    real(8), intent (in) :: phi1
    real(8), intent (in) :: phi2
    real(8), intent (in) :: delta
    real(8), intent (in) :: theta
    code = cos(delta)
end function
public static double code(double lambda1, double phi1, double phi2, double delta, double theta) {
	return Math.cos(delta);
}
def code(lambda1, phi1, phi2, delta, theta):
	return math.cos(delta)
function code(lambda1, phi1, phi2, delta, theta)
	return cos(delta)
end
function tmp = code(lambda1, phi1, phi2, delta, theta)
	tmp = cos(delta);
end
code[lambda1_, phi1_, phi2_, delta_, theta_] := N[Cos[delta], $MachinePrecision]
\begin{array}{l}

\\
\cos delta
\end{array}
Derivation
  1. Initial program 99.7%

    \[\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. Add Preprocessing
  3. Taylor expanded in lambda1 around inf

    \[\leadsto \color{blue}{\lambda_1} \]
  4. Applied rewrites9.5%

    \[\leadsto \color{blue}{\left(\sin theta \cdot \sin delta\right) \cdot \cos \phi_1} \]
  5. Taylor expanded in phi1 around 0

    \[\leadsto \sin delta \cdot \sin theta + \color{blue}{{\phi_1}^{2} \cdot \left(\frac{-1}{2} \cdot \left(\sin delta \cdot \sin theta\right) + {\phi_1}^{2} \cdot \left(\frac{-1}{720} \cdot \left({\phi_1}^{2} \cdot \left(\sin delta \cdot \sin theta\right)\right) + \frac{1}{24} \cdot \left(\sin delta \cdot \sin theta\right)\right)\right)} \]
  6. Applied rewrites4.2%

    \[\leadsto \cos delta \]
  7. Add Preprocessing

Reproduce

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