
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0)
code = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0);
return R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0) return R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0)) return Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0); tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot t_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi1) (cos phi2)) t_0) t_0))))
(* R (* 2.0 (atan2 (sqrt t_1) (sqrt (- 1.0 t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0);
return R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0)
code = r * (2.0d0 * atan2(sqrt(t_1), sqrt((1.0d0 - t_1))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_1 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((Math.cos(phi1) * Math.cos(phi2)) * t_0) * t_0);
return R * (2.0 * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1))));
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (((math.cos(phi1) * math.cos(phi2)) * t_0) * t_0) return R * (2.0 * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))))
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) * t_0)) return Float64(R * Float64(2.0 * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(((lambda1 - lambda2) / 2.0)); t_1 = (sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (((cos(phi1) * cos(phi2)) * t_0) * t_0); tmp = R * (2.0 * atan2(sqrt(t_1), sqrt((1.0 - t_1)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right) \cdot t_0\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\right)
\end{array}
\end{array}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (* (cos phi1) (cos phi2)))
(t_3 (* t_2 (- (/ (cos (- lambda1 lambda2)) 2.0) 0.5))))
(if (<= phi1 -2.95e-5)
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (* phi1 0.5)) 2.0)
(* (cos phi1) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))
(sqrt (+ (- 1.0 t_0) t_3)))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_0 (* t_2 (* t_1 t_1))))
(sqrt (+ (pow (cos (* phi2 -0.5)) 2.0) t_3))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = cos(phi1) * cos(phi2);
double t_3 = t_2 * ((cos((lambda1 - lambda2)) / 2.0) - 0.5);
double tmp;
if (phi1 <= -2.95e-5) {
tmp = R * (2.0 * atan2(sqrt((pow(sin((phi1 * 0.5)), 2.0) + (cos(phi1) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))), sqrt(((1.0 - t_0) + t_3))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_0 + (t_2 * (t_1 * t_1)))), sqrt((pow(cos((phi2 * -0.5)), 2.0) + t_3))));
}
return tmp;
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
t_2 = cos(phi1) * cos(phi2)
t_3 = t_2 * ((cos((lambda1 - lambda2)) / 2.0d0) - 0.5d0)
if (phi1 <= (-2.95d-5)) then
tmp = r * (2.0d0 * atan2(sqrt(((sin((phi1 * 0.5d0)) ** 2.0d0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))), sqrt(((1.0d0 - t_0) + t_3))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_0 + (t_2 * (t_1 * t_1)))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) + t_3))))
end if
code = tmp
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_2 = Math.cos(phi1) * Math.cos(phi2);
double t_3 = t_2 * ((Math.cos((lambda1 - lambda2)) / 2.0) - 0.5);
double tmp;
if (phi1 <= -2.95e-5) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((phi1 * 0.5)), 2.0) + (Math.cos(phi1) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))), Math.sqrt(((1.0 - t_0) + t_3))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + (t_2 * (t_1 * t_1)))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) + t_3))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) t_2 = math.cos(phi1) * math.cos(phi2) t_3 = t_2 * ((math.cos((lambda1 - lambda2)) / 2.0) - 0.5) tmp = 0 if phi1 <= -2.95e-5: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((phi1 * 0.5)), 2.0) + (math.cos(phi1) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))), math.sqrt(((1.0 - t_0) + t_3)))) else: tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + (t_2 * (t_1 * t_1)))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) + t_3)))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = Float64(cos(phi1) * cos(phi2)) t_3 = Float64(t_2 * Float64(Float64(cos(Float64(lambda1 - lambda2)) / 2.0) - 0.5)) tmp = 0.0 if (phi1 <= -2.95e-5) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + Float64(cos(phi1) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))), sqrt(Float64(Float64(1.0 - t_0) + t_3))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + Float64(t_2 * Float64(t_1 * t_1)))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) + t_3))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
t_1 = sin(((lambda1 - lambda2) / 2.0));
t_2 = cos(phi1) * cos(phi2);
t_3 = t_2 * ((cos((lambda1 - lambda2)) / 2.0) - 0.5);
tmp = 0.0;
if (phi1 <= -2.95e-5)
tmp = R * (2.0 * atan2(sqrt(((sin((phi1 * 0.5)) ^ 2.0) + (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))), sqrt(((1.0 - t_0) + t_3))));
else
tmp = R * (2.0 * atan2(sqrt((t_0 + (t_2 * (t_1 * t_1)))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) + t_3))));
end
tmp_2 = tmp;
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -2.95e-5], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - t$95$0), $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + N[(t$95$2 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \cos \phi_1 \cdot \cos \phi_2\\
t_3 := t_2 \cdot \left(\frac{\cos \left(\lambda_1 - \lambda_2\right)}{2} - 0.5\right)\\
\mathbf{if}\;\phi_1 \leq -2.95 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}{\sqrt{\left(1 - t_0\right) + t_3}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + t_2 \cdot \left(t_1 \cdot t_1\right)}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} + t_3}}\right)\\
\end{array}
\end{array}
if phi1 < -2.9499999999999999e-5Initial program 48.2%
associate-*l*48.3%
Simplified48.3%
sin-mult48.3%
div-inv48.3%
metadata-eval48.3%
div-inv48.3%
metadata-eval48.3%
div-inv48.3%
metadata-eval48.3%
div-inv48.3%
metadata-eval48.3%
Applied egg-rr48.3%
div-sub48.3%
+-inverses48.3%
+-inverses48.3%
+-inverses48.3%
cos-048.3%
metadata-eval48.3%
distribute-lft-out48.3%
metadata-eval48.3%
*-rgt-identity48.3%
Simplified48.3%
Taylor expanded in phi2 around 0 50.3%
if -2.9499999999999999e-5 < phi1 Initial program 66.7%
associate-*l*66.7%
Simplified66.7%
sin-mult66.8%
div-inv66.8%
metadata-eval66.8%
div-inv66.8%
metadata-eval66.8%
div-inv66.8%
metadata-eval66.8%
div-inv66.8%
metadata-eval66.8%
Applied egg-rr66.8%
div-sub66.8%
+-inverses66.8%
+-inverses66.8%
+-inverses66.8%
cos-066.8%
metadata-eval66.8%
distribute-lft-out66.8%
metadata-eval66.8%
*-rgt-identity66.8%
Simplified66.8%
Taylor expanded in phi1 around 0 58.3%
unpow258.3%
1-sub-sin58.3%
unpow258.3%
Simplified58.3%
Final simplification56.4%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* (- phi1 phi2) 0.5)))
(t_1 (* (cos phi1) (cos phi2)))
(t_2 (sin (/ (- lambda1 lambda2) 2.0))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_1 (* t_2 t_2))))
(sqrt
(+
(/ (- 1.0 (pow t_0 4.0)) (+ 1.0 (pow t_0 2.0)))
(*
t_1
(-
(/
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2)))
2.0)
0.5)))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((phi1 - phi2) * 0.5));
double t_1 = cos(phi1) * cos(phi2);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_2 * t_2)))), sqrt((((1.0 - pow(t_0, 4.0)) / (1.0 + pow(t_0, 2.0))) + (t_1 * ((((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))) / 2.0) - 0.5))))));
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = sin(((phi1 - phi2) * 0.5d0))
t_1 = cos(phi1) * cos(phi2)
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_1 * (t_2 * t_2)))), sqrt((((1.0d0 - (t_0 ** 4.0d0)) / (1.0d0 + (t_0 ** 2.0d0))) + (t_1 * ((((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))) / 2.0d0) - 0.5d0))))))
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((phi1 - phi2) * 0.5));
double t_1 = Math.cos(phi1) * Math.cos(phi2);
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_2 * t_2)))), Math.sqrt((((1.0 - Math.pow(t_0, 4.0)) / (1.0 + Math.pow(t_0, 2.0))) + (t_1 * ((((Math.cos(lambda1) * Math.cos(lambda2)) + (Math.sin(lambda1) * Math.sin(lambda2))) / 2.0) - 0.5))))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((phi1 - phi2) * 0.5)) t_1 = math.cos(phi1) * math.cos(phi2) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_2 * t_2)))), math.sqrt((((1.0 - math.pow(t_0, 4.0)) / (1.0 + math.pow(t_0, 2.0))) + (t_1 * ((((math.cos(lambda1) * math.cos(lambda2)) + (math.sin(lambda1) * math.sin(lambda2))) / 2.0) - 0.5))))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(phi1 - phi2) * 0.5)) t_1 = Float64(cos(phi1) * cos(phi2)) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_1 * Float64(t_2 * t_2)))), sqrt(Float64(Float64(Float64(1.0 - (t_0 ^ 4.0)) / Float64(1.0 + (t_0 ^ 2.0))) + Float64(t_1 * Float64(Float64(Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2))) / 2.0) - 0.5))))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((phi1 - phi2) * 0.5));
t_1 = cos(phi1) * cos(phi2);
t_2 = sin(((lambda1 - lambda2) / 2.0));
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_1 * (t_2 * t_2)))), sqrt((((1.0 - (t_0 ^ 4.0)) / (1.0 + (t_0 ^ 2.0))) + (t_1 * ((((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))) / 2.0) - 0.5))))));
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[(1.0 - N[Power[t$95$0, 4.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(N[(N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \left(t_2 \cdot t_2\right)}}{\sqrt{\frac{1 - {t_0}^{4}}{1 + {t_0}^{2}} + t_1 \cdot \left(\frac{\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2}{2} - 0.5\right)}}\right)
\end{array}
\end{array}
Initial program 62.2%
associate-*l*62.2%
Simplified62.2%
sin-mult62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
Applied egg-rr62.2%
div-sub62.2%
+-inverses62.2%
+-inverses62.2%
+-inverses62.2%
cos-062.2%
metadata-eval62.2%
distribute-lft-out62.2%
metadata-eval62.2%
*-rgt-identity62.2%
Simplified62.2%
cos-diff62.7%
Applied egg-rr62.7%
flip--62.6%
metadata-eval62.6%
div-inv62.6%
metadata-eval62.6%
div-inv62.6%
metadata-eval62.6%
div-inv62.6%
metadata-eval62.6%
Applied egg-rr62.6%
pow-sqr62.7%
*-commutative62.7%
metadata-eval62.7%
*-commutative62.7%
Simplified62.7%
Final simplification62.7%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(*
R
(*
2.0
(atan2
(sqrt (+ t_2 (* t_0 (* t_1 t_1))))
(sqrt
(+
(- 1.0 t_2)
(*
t_0
(-
(/
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2)))
2.0)
0.5)))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi1) * cos(phi2);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * atan2(sqrt((t_2 + (t_0 * (t_1 * t_1)))), sqrt(((1.0 - t_2) + (t_0 * ((((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))) / 2.0) - 0.5))))));
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = cos(phi1) * cos(phi2)
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
t_2 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt((t_2 + (t_0 * (t_1 * t_1)))), sqrt(((1.0d0 - t_2) + (t_0 * ((((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))) / 2.0d0) - 0.5d0))))))
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos(phi1) * Math.cos(phi2);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt((t_2 + (t_0 * (t_1 * t_1)))), Math.sqrt(((1.0 - t_2) + (t_0 * ((((Math.cos(lambda1) * Math.cos(lambda2)) + (Math.sin(lambda1) * Math.sin(lambda2))) / 2.0) - 0.5))))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos(phi1) * math.cos(phi2) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) return R * (2.0 * math.atan2(math.sqrt((t_2 + (t_0 * (t_1 * t_1)))), math.sqrt(((1.0 - t_2) + (t_0 * ((((math.cos(lambda1) * math.cos(lambda2)) + (math.sin(lambda1) * math.sin(lambda2))) / 2.0) - 0.5))))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(t_0 * Float64(t_1 * t_1)))), sqrt(Float64(Float64(1.0 - t_2) + Float64(t_0 * Float64(Float64(Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2))) / 2.0) - 0.5))))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = cos(phi1) * cos(phi2);
t_1 = sin(((lambda1 - lambda2) / 2.0));
t_2 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
tmp = R * (2.0 * atan2(sqrt((t_2 + (t_0 * (t_1 * t_1)))), sqrt(((1.0 - t_2) + (t_0 * ((((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))) / 2.0) - 0.5))))));
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[(t$95$0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - t$95$2), $MachinePrecision] + N[(t$95$0 * N[(N[(N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2 + t_0 \cdot \left(t_1 \cdot t_1\right)}}{\sqrt{\left(1 - t_2\right) + t_0 \cdot \left(\frac{\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2}{2} - 0.5\right)}}\right)
\end{array}
\end{array}
Initial program 62.2%
associate-*l*62.2%
Simplified62.2%
sin-mult62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
Applied egg-rr62.2%
div-sub62.2%
+-inverses62.2%
+-inverses62.2%
+-inverses62.2%
cos-062.2%
metadata-eval62.2%
distribute-lft-out62.2%
metadata-eval62.2%
*-rgt-identity62.2%
Simplified62.2%
cos-diff62.7%
Applied egg-rr62.7%
Final simplification62.7%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(*
R
(*
2.0
(atan2
(sqrt (+ t_2 (* t_0 (* t_1 t_1))))
(sqrt
(+ (- 1.0 t_2) (* t_0 (- (/ (cos (- lambda1 lambda2)) 2.0) 0.5)))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi1) * cos(phi2);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * atan2(sqrt((t_2 + (t_0 * (t_1 * t_1)))), sqrt(((1.0 - t_2) + (t_0 * ((cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = cos(phi1) * cos(phi2)
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
t_2 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt((t_2 + (t_0 * (t_1 * t_1)))), sqrt(((1.0d0 - t_2) + (t_0 * ((cos((lambda1 - lambda2)) / 2.0d0) - 0.5d0))))))
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos(phi1) * Math.cos(phi2);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_2 = Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * Math.atan2(Math.sqrt((t_2 + (t_0 * (t_1 * t_1)))), Math.sqrt(((1.0 - t_2) + (t_0 * ((Math.cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos(phi1) * math.cos(phi2) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) return R * (2.0 * math.atan2(math.sqrt((t_2 + (t_0 * (t_1 * t_1)))), math.sqrt(((1.0 - t_2) + (t_0 * ((math.cos((lambda1 - lambda2)) / 2.0) - 0.5))))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + Float64(t_0 * Float64(t_1 * t_1)))), sqrt(Float64(Float64(1.0 - t_2) + Float64(t_0 * Float64(Float64(cos(Float64(lambda1 - lambda2)) / 2.0) - 0.5))))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = cos(phi1) * cos(phi2);
t_1 = sin(((lambda1 - lambda2) / 2.0));
t_2 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
tmp = R * (2.0 * atan2(sqrt((t_2 + (t_0 * (t_1 * t_1)))), sqrt(((1.0 - t_2) + (t_0 * ((cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[(t$95$0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - t$95$2), $MachinePrecision] + N[(t$95$0 * N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2 + t_0 \cdot \left(t_1 \cdot t_1\right)}}{\sqrt{\left(1 - t_2\right) + t_0 \cdot \left(\frac{\cos \left(\lambda_1 - \lambda_2\right)}{2} - 0.5\right)}}\right)
\end{array}
\end{array}
Initial program 62.2%
associate-*l*62.2%
Simplified62.2%
sin-mult62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
div-inv62.2%
metadata-eval62.2%
Applied egg-rr62.2%
div-sub62.2%
+-inverses62.2%
+-inverses62.2%
+-inverses62.2%
cos-062.2%
metadata-eval62.2%
distribute-lft-out62.2%
metadata-eval62.2%
*-rgt-identity62.2%
Simplified62.2%
Final simplification62.2%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(t_1 (* (cos phi1) (cos phi2))))
(if (<= phi1 -2.25e-5)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* phi1 0.5)) 2.0) (* (cos phi1) t_0)))
(sqrt
(+
(- 1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(* t_1 (- (/ (cos (- lambda1 lambda2)) 2.0) 0.5)))))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* (- phi1 phi2) 0.5)) 2.0) (* t_1 t_0)))
(sqrt (- (pow (cos (* phi2 -0.5)) 2.0) (* (cos phi2) t_0)))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = cos(phi1) * cos(phi2);
double tmp;
if (phi1 <= -2.25e-5) {
tmp = R * (2.0 * atan2(sqrt((pow(sin((phi1 * 0.5)), 2.0) + (cos(phi1) * t_0))), sqrt(((1.0 - pow(sin(((phi1 - phi2) / 2.0)), 2.0)) + (t_1 * ((cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
} else {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) * 0.5)), 2.0) + (t_1 * t_0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * t_0)))));
}
return tmp;
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0
t_1 = cos(phi1) * cos(phi2)
if (phi1 <= (-2.25d-5)) then
tmp = r * (2.0d0 * atan2(sqrt(((sin((phi1 * 0.5d0)) ** 2.0d0) + (cos(phi1) * t_0))), sqrt(((1.0d0 - (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0)) + (t_1 * ((cos((lambda1 - lambda2)) / 2.0d0) - 0.5d0))))))
else
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) * 0.5d0)) ** 2.0d0) + (t_1 * t_0))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - (cos(phi2) * t_0)))))
end if
code = tmp
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = Math.cos(phi1) * Math.cos(phi2);
double tmp;
if (phi1 <= -2.25e-5) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((phi1 * 0.5)), 2.0) + (Math.cos(phi1) * t_0))), Math.sqrt(((1.0 - Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0)) + (t_1 * ((Math.cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) * 0.5)), 2.0) + (t_1 * t_0))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) - (Math.cos(phi2) * t_0)))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0) t_1 = math.cos(phi1) * math.cos(phi2) tmp = 0 if phi1 <= -2.25e-5: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((phi1 * 0.5)), 2.0) + (math.cos(phi1) * t_0))), math.sqrt(((1.0 - math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)) + (t_1 * ((math.cos((lambda1 - lambda2)) / 2.0) - 0.5)))))) else: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) * 0.5)), 2.0) + (t_1 * t_0))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) - (math.cos(phi2) * t_0))))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 t_1 = Float64(cos(phi1) * cos(phi2)) tmp = 0.0 if (phi1 <= -2.25e-5) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + Float64(cos(phi1) * t_0))), sqrt(Float64(Float64(1.0 - (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) + Float64(t_1 * Float64(Float64(cos(Float64(lambda1 - lambda2)) / 2.0) - 0.5))))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) * 0.5)) ^ 2.0) + Float64(t_1 * t_0))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - Float64(cos(phi2) * t_0)))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) * 0.5)) ^ 2.0;
t_1 = cos(phi1) * cos(phi2);
tmp = 0.0;
if (phi1 <= -2.25e-5)
tmp = R * (2.0 * atan2(sqrt(((sin((phi1 * 0.5)) ^ 2.0) + (cos(phi1) * t_0))), sqrt(((1.0 - (sin(((phi1 - phi2) / 2.0)) ^ 2.0)) + (t_1 * ((cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
else
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) * 0.5)) ^ 2.0) + (t_1 * t_0))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - (cos(phi2) * t_0)))));
end
tmp_2 = tmp;
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -2.25e-5], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
\mathbf{if}\;\phi_1 \leq -2.25 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot t_0}}{\sqrt{\left(1 - {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right) + t_1 \cdot \left(\frac{\cos \left(\lambda_1 - \lambda_2\right)}{2} - 0.5\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2} + t_1 \cdot t_0}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - \cos \phi_2 \cdot t_0}}\right)\\
\end{array}
\end{array}
if phi1 < -2.25000000000000014e-5Initial program 48.2%
associate-*l*48.3%
Simplified48.3%
sin-mult48.3%
div-inv48.3%
metadata-eval48.3%
div-inv48.3%
metadata-eval48.3%
div-inv48.3%
metadata-eval48.3%
div-inv48.3%
metadata-eval48.3%
Applied egg-rr48.3%
div-sub48.3%
+-inverses48.3%
+-inverses48.3%
+-inverses48.3%
cos-048.3%
metadata-eval48.3%
distribute-lft-out48.3%
metadata-eval48.3%
*-rgt-identity48.3%
Simplified48.3%
Taylor expanded in phi2 around 0 50.3%
if -2.25000000000000014e-5 < phi1 Initial program 66.7%
associate-*l*66.7%
Simplified66.7%
Taylor expanded in phi1 around 0 58.4%
associate--r+58.4%
unpow258.4%
1-sub-sin58.4%
unpow258.4%
Simplified58.4%
add-log-exp53.8%
div-inv53.8%
metadata-eval53.8%
*-commutative53.8%
associate-*l*53.8%
pow253.8%
Applied egg-rr53.8%
add-log-exp58.4%
associate-*r*58.4%
*-commutative58.4%
Applied egg-rr58.4%
Final simplification56.4%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)))
(if (<= phi1 -8.6e-16)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* phi1 0.5)) 2.0) (* (cos phi1) t_0)))
(sqrt
(+
(- 1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(*
(* (cos phi1) (cos phi2))
(- (/ (cos (- lambda1 lambda2)) 2.0) 0.5)))))))
(*
R
(*
2.0
(atan2
(sqrt (fma t_0 (cos phi2) (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt (- (pow (cos (* phi2 -0.5)) 2.0) (* (cos phi2) t_0)))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double tmp;
if (phi1 <= -8.6e-16) {
tmp = R * (2.0 * atan2(sqrt((pow(sin((phi1 * 0.5)), 2.0) + (cos(phi1) * t_0))), sqrt(((1.0 - pow(sin(((phi1 - phi2) / 2.0)), 2.0)) + ((cos(phi1) * cos(phi2)) * ((cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
} else {
tmp = R * (2.0 * atan2(sqrt(fma(t_0, cos(phi2), pow(sin((phi2 * -0.5)), 2.0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * t_0)))));
}
return tmp;
}
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 tmp = 0.0 if (phi1 <= -8.6e-16) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + Float64(cos(phi1) * t_0))), sqrt(Float64(Float64(1.0 - (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(cos(Float64(lambda1 - lambda2)) / 2.0) - 0.5))))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(fma(t_0, cos(phi2), (sin(Float64(phi2 * -0.5)) ^ 2.0))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - Float64(cos(phi2) * t_0)))))); end return tmp end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[phi1, -8.6e-16], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 * N[Cos[phi2], $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
\mathbf{if}\;\phi_1 \leq -8.6 \cdot 10^{-16}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot t_0}}{\sqrt{\left(1 - {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right) + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\frac{\cos \left(\lambda_1 - \lambda_2\right)}{2} - 0.5\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t_0, \cos \phi_2, {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - \cos \phi_2 \cdot t_0}}\right)\\
\end{array}
\end{array}
if phi1 < -8.5999999999999997e-16Initial program 48.3%
associate-*l*48.3%
Simplified48.4%
sin-mult48.4%
div-inv48.4%
metadata-eval48.4%
div-inv48.4%
metadata-eval48.4%
div-inv48.4%
metadata-eval48.4%
div-inv48.4%
metadata-eval48.4%
Applied egg-rr48.4%
div-sub48.4%
+-inverses48.4%
+-inverses48.4%
+-inverses48.4%
cos-048.4%
metadata-eval48.4%
distribute-lft-out48.4%
metadata-eval48.4%
*-rgt-identity48.4%
Simplified48.4%
Taylor expanded in phi2 around 0 50.3%
if -8.5999999999999997e-16 < phi1 Initial program 66.9%
associate-*l*66.9%
Simplified66.9%
Taylor expanded in phi1 around 0 58.5%
associate--r+58.5%
unpow258.5%
1-sub-sin58.5%
unpow258.5%
Simplified58.5%
Taylor expanded in phi1 around 0 57.2%
+-commutative57.2%
*-commutative57.2%
fma-def57.2%
Simplified57.2%
Final simplification55.4%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(t_1 (* (cos phi2) t_0)))
(if (<= phi1 -2e-17)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (* phi1 0.5)) 2.0) (* (cos phi1) t_0)))
(sqrt
(+
(- 1.0 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(*
(* (cos phi1) (cos phi2))
(- (/ (cos (- lambda1 lambda2)) 2.0) 0.5)))))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_1 (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt (- (pow (cos (* phi2 -0.5)) 2.0) t_1))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = cos(phi2) * t_0;
double tmp;
if (phi1 <= -2e-17) {
tmp = R * (2.0 * atan2(sqrt((pow(sin((phi1 * 0.5)), 2.0) + (cos(phi1) * t_0))), sqrt(((1.0 - pow(sin(((phi1 - phi2) / 2.0)), 2.0)) + ((cos(phi1) * cos(phi2)) * ((cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_1 + pow(sin((phi2 * -0.5)), 2.0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - t_1))));
}
return tmp;
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0
t_1 = cos(phi2) * t_0
if (phi1 <= (-2d-17)) then
tmp = r * (2.0d0 * atan2(sqrt(((sin((phi1 * 0.5d0)) ** 2.0d0) + (cos(phi1) * t_0))), sqrt(((1.0d0 - (sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0)) + ((cos(phi1) * cos(phi2)) * ((cos((lambda1 - lambda2)) / 2.0d0) - 0.5d0))))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_1 + (sin((phi2 * (-0.5d0))) ** 2.0d0))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - t_1))))
end if
code = tmp
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = Math.cos(phi2) * t_0;
double tmp;
if (phi1 <= -2e-17) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin((phi1 * 0.5)), 2.0) + (Math.cos(phi1) * t_0))), Math.sqrt(((1.0 - Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0)) + ((Math.cos(phi1) * Math.cos(phi2)) * ((Math.cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_1 + Math.pow(Math.sin((phi2 * -0.5)), 2.0))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) - t_1))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0) t_1 = math.cos(phi2) * t_0 tmp = 0 if phi1 <= -2e-17: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin((phi1 * 0.5)), 2.0) + (math.cos(phi1) * t_0))), math.sqrt(((1.0 - math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0)) + ((math.cos(phi1) * math.cos(phi2)) * ((math.cos((lambda1 - lambda2)) / 2.0) - 0.5)))))) else: tmp = R * (2.0 * math.atan2(math.sqrt((t_1 + math.pow(math.sin((phi2 * -0.5)), 2.0))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) - t_1)))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 t_1 = Float64(cos(phi2) * t_0) tmp = 0.0 if (phi1 <= -2e-17) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(phi1 * 0.5)) ^ 2.0) + Float64(cos(phi1) * t_0))), sqrt(Float64(Float64(1.0 - (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0)) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(cos(Float64(lambda1 - lambda2)) / 2.0) - 0.5))))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_1 + (sin(Float64(phi2 * -0.5)) ^ 2.0))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - t_1))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) * 0.5)) ^ 2.0;
t_1 = cos(phi2) * t_0;
tmp = 0.0;
if (phi1 <= -2e-17)
tmp = R * (2.0 * atan2(sqrt(((sin((phi1 * 0.5)) ^ 2.0) + (cos(phi1) * t_0))), sqrt(((1.0 - (sin(((phi1 - phi2) / 2.0)) ^ 2.0)) + ((cos(phi1) * cos(phi2)) * ((cos((lambda1 - lambda2)) / 2.0) - 0.5))))));
else
tmp = R * (2.0 * atan2(sqrt((t_1 + (sin((phi2 * -0.5)) ^ 2.0))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - t_1))));
end
tmp_2 = tmp;
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[phi1, -2e-17], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$1 + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \cos \phi_2 \cdot t_0\\
\mathbf{if}\;\phi_1 \leq -2 \cdot 10^{-17}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\phi_1 \cdot 0.5\right)}^{2} + \cos \phi_1 \cdot t_0}}{\sqrt{\left(1 - {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right) + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\frac{\cos \left(\lambda_1 - \lambda_2\right)}{2} - 0.5\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_1 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - t_1}}\right)\\
\end{array}
\end{array}
if phi1 < -2.00000000000000014e-17Initial program 48.3%
associate-*l*48.3%
Simplified48.4%
sin-mult48.4%
div-inv48.4%
metadata-eval48.4%
div-inv48.4%
metadata-eval48.4%
div-inv48.4%
metadata-eval48.4%
div-inv48.4%
metadata-eval48.4%
Applied egg-rr48.4%
div-sub48.4%
+-inverses48.4%
+-inverses48.4%
+-inverses48.4%
cos-048.4%
metadata-eval48.4%
distribute-lft-out48.4%
metadata-eval48.4%
*-rgt-identity48.4%
Simplified48.4%
Taylor expanded in phi2 around 0 50.3%
if -2.00000000000000014e-17 < phi1 Initial program 66.9%
associate-*l*66.9%
Simplified66.9%
Taylor expanded in phi1 around 0 58.5%
associate--r+58.5%
unpow258.5%
1-sub-sin58.5%
unpow258.5%
Simplified58.5%
Taylor expanded in phi1 around 0 57.2%
*-commutative46.0%
Simplified57.2%
Final simplification55.4%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (* (cos phi2) t_0)))
(if (<= phi2 1.75e-34)
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (+ (sin (* phi1 0.5)) (* -0.5 (* phi2 (cos (* phi1 0.5))))) 2.0)
(* t_1 (* (* (cos phi1) (cos phi2)) t_1))))
(sqrt (- 1.0 t_0)))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_2 (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt (- (pow (cos (* phi2 -0.5)) 2.0) t_2))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = cos(phi2) * t_0;
double tmp;
if (phi2 <= 1.75e-34) {
tmp = R * (2.0 * atan2(sqrt((pow((sin((phi1 * 0.5)) + (-0.5 * (phi2 * cos((phi1 * 0.5))))), 2.0) + (t_1 * ((cos(phi1) * cos(phi2)) * t_1)))), sqrt((1.0 - t_0))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_2 + pow(sin((phi2 * -0.5)), 2.0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - t_2))));
}
return tmp;
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
t_2 = cos(phi2) * t_0
if (phi2 <= 1.75d-34) then
tmp = r * (2.0d0 * atan2(sqrt((((sin((phi1 * 0.5d0)) + ((-0.5d0) * (phi2 * cos((phi1 * 0.5d0))))) ** 2.0d0) + (t_1 * ((cos(phi1) * cos(phi2)) * t_1)))), sqrt((1.0d0 - t_0))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_2 + (sin((phi2 * (-0.5d0))) ** 2.0d0))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - t_2))))
end if
code = tmp
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_2 = Math.cos(phi2) * t_0;
double tmp;
if (phi2 <= 1.75e-34) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow((Math.sin((phi1 * 0.5)) + (-0.5 * (phi2 * Math.cos((phi1 * 0.5))))), 2.0) + (t_1 * ((Math.cos(phi1) * Math.cos(phi2)) * t_1)))), Math.sqrt((1.0 - t_0))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_2 + Math.pow(Math.sin((phi2 * -0.5)), 2.0))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) - t_2))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) t_2 = math.cos(phi2) * t_0 tmp = 0 if phi2 <= 1.75e-34: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow((math.sin((phi1 * 0.5)) + (-0.5 * (phi2 * math.cos((phi1 * 0.5))))), 2.0) + (t_1 * ((math.cos(phi1) * math.cos(phi2)) * t_1)))), math.sqrt((1.0 - t_0)))) else: tmp = R * (2.0 * math.atan2(math.sqrt((t_2 + math.pow(math.sin((phi2 * -0.5)), 2.0))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) - t_2)))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = Float64(cos(phi2) * t_0) tmp = 0.0 if (phi2 <= 1.75e-34) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((Float64(sin(Float64(phi1 * 0.5)) + Float64(-0.5 * Float64(phi2 * cos(Float64(phi1 * 0.5))))) ^ 2.0) + Float64(t_1 * Float64(Float64(cos(phi1) * cos(phi2)) * t_1)))), sqrt(Float64(1.0 - t_0))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + (sin(Float64(phi2 * -0.5)) ^ 2.0))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - t_2))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) * 0.5)) ^ 2.0;
t_1 = sin(((lambda1 - lambda2) / 2.0));
t_2 = cos(phi2) * t_0;
tmp = 0.0;
if (phi2 <= 1.75e-34)
tmp = R * (2.0 * atan2(sqrt((((sin((phi1 * 0.5)) + (-0.5 * (phi2 * cos((phi1 * 0.5))))) ^ 2.0) + (t_1 * ((cos(phi1) * cos(phi2)) * t_1)))), sqrt((1.0 - t_0))));
else
tmp = R * (2.0 * atan2(sqrt((t_2 + (sin((phi2 * -0.5)) ^ 2.0))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - t_2))));
end
tmp_2 = tmp;
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[phi2, 1.75e-34], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] + N[(-0.5 * N[(phi2 * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$2 + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - t$95$2), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \cos \phi_2 \cdot t_0\\
\mathbf{if}\;\phi_2 \leq 1.75 \cdot 10^{-34}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\phi_1 \cdot 0.5\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(\phi_1 \cdot 0.5\right)\right)\right)}^{2} + t_1 \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_1\right)}}{\sqrt{1 - t_0}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_2 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - t_2}}\right)\\
\end{array}
\end{array}
if phi2 < 1.75e-34Initial program 66.7%
Taylor expanded in phi2 around 0 58.9%
Taylor expanded in phi2 around 0 57.1%
Taylor expanded in phi1 around 0 39.2%
if 1.75e-34 < phi2 Initial program 52.7%
associate-*l*52.7%
Simplified52.7%
Taylor expanded in phi1 around 0 52.1%
associate--r+52.1%
unpow252.1%
1-sub-sin52.1%
unpow252.1%
Simplified52.1%
Taylor expanded in phi1 around 0 52.4%
*-commutative39.7%
Simplified52.4%
Final simplification43.5%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0))))
(if (<= phi2 7.6e-6)
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (+ (sin (* phi1 0.5)) (* -0.5 (* phi2 (cos (* phi1 0.5))))) 2.0)
(* t_1 (* (* (cos phi1) (cos phi2)) t_1))))
(sqrt (- 1.0 t_0)))))
(*
R
(*
2.0
(atan2
(sqrt (+ (* (cos phi2) t_0) (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt
(-
(pow (cos (* phi2 -0.5)) 2.0)
(* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0))))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if (phi2 <= 7.6e-6) {
tmp = R * (2.0 * atan2(sqrt((pow((sin((phi1 * 0.5)) + (-0.5 * (phi2 * cos((phi1 * 0.5))))), 2.0) + (t_1 * ((cos(phi1) * cos(phi2)) * t_1)))), sqrt((1.0 - t_0))));
} else {
tmp = R * (2.0 * atan2(sqrt(((cos(phi2) * t_0) + pow(sin((phi2 * -0.5)), 2.0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))))));
}
return tmp;
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
if (phi2 <= 7.6d-6) then
tmp = r * (2.0d0 * atan2(sqrt((((sin((phi1 * 0.5d0)) + ((-0.5d0) * (phi2 * cos((phi1 * 0.5d0))))) ** 2.0d0) + (t_1 * ((cos(phi1) * cos(phi2)) * t_1)))), sqrt((1.0d0 - t_0))))
else
tmp = r * (2.0d0 * atan2(sqrt(((cos(phi2) * t_0) + (sin((phi2 * (-0.5d0))) ** 2.0d0))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - (cos(phi2) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))))))
end if
code = tmp
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double tmp;
if (phi2 <= 7.6e-6) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow((Math.sin((phi1 * 0.5)) + (-0.5 * (phi2 * Math.cos((phi1 * 0.5))))), 2.0) + (t_1 * ((Math.cos(phi1) * Math.cos(phi2)) * t_1)))), Math.sqrt((1.0 - t_0))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt(((Math.cos(phi2) * t_0) + Math.pow(Math.sin((phi2 * -0.5)), 2.0))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) - (Math.cos(phi2) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) tmp = 0 if phi2 <= 7.6e-6: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow((math.sin((phi1 * 0.5)) + (-0.5 * (phi2 * math.cos((phi1 * 0.5))))), 2.0) + (t_1 * ((math.cos(phi1) * math.cos(phi2)) * t_1)))), math.sqrt((1.0 - t_0)))) else: tmp = R * (2.0 * math.atan2(math.sqrt(((math.cos(phi2) * t_0) + math.pow(math.sin((phi2 * -0.5)), 2.0))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) - (math.cos(phi2) * math.pow(math.sin((lambda2 * -0.5)), 2.0)))))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if (phi2 <= 7.6e-6) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((Float64(sin(Float64(phi1 * 0.5)) + Float64(-0.5 * Float64(phi2 * cos(Float64(phi1 * 0.5))))) ^ 2.0) + Float64(t_1 * Float64(Float64(cos(phi1) * cos(phi2)) * t_1)))), sqrt(Float64(1.0 - t_0))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(cos(phi2) * t_0) + (sin(Float64(phi2 * -0.5)) ^ 2.0))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) * 0.5)) ^ 2.0;
t_1 = sin(((lambda1 - lambda2) / 2.0));
tmp = 0.0;
if (phi2 <= 7.6e-6)
tmp = R * (2.0 * atan2(sqrt((((sin((phi1 * 0.5)) + (-0.5 * (phi2 * cos((phi1 * 0.5))))) ^ 2.0) + (t_1 * ((cos(phi1) * cos(phi2)) * t_1)))), sqrt((1.0 - t_0))));
else
tmp = R * (2.0 * atan2(sqrt(((cos(phi2) * t_0) + (sin((phi2 * -0.5)) ^ 2.0))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - (cos(phi2) * (sin((lambda2 * -0.5)) ^ 2.0))))));
end
tmp_2 = tmp;
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 7.6e-6], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] + N[(-0.5 * N[(phi2 * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_2 \leq 7.6 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\left(\sin \left(\phi_1 \cdot 0.5\right) + -0.5 \cdot \left(\phi_2 \cdot \cos \left(\phi_1 \cdot 0.5\right)\right)\right)}^{2} + t_1 \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_1\right)}}{\sqrt{1 - t_0}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_2 \cdot t_0 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - \cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}}}\right)\\
\end{array}
\end{array}
if phi2 < 7.6000000000000001e-6Initial program 66.5%
Taylor expanded in phi2 around 0 58.9%
Taylor expanded in phi2 around 0 57.4%
Taylor expanded in phi1 around 0 39.3%
if 7.6000000000000001e-6 < phi2 Initial program 52.5%
associate-*l*52.5%
Simplified52.5%
Taylor expanded in phi1 around 0 52.3%
associate--r+52.4%
unpow252.4%
1-sub-sin52.4%
unpow252.4%
Simplified52.4%
Taylor expanded in lambda1 around 0 40.2%
*-commutative40.2%
Simplified40.2%
Taylor expanded in phi1 around 0 40.4%
*-commutative40.4%
Simplified40.4%
Final simplification39.7%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (cos phi1) (cos phi2)) (* t_0 t_0))))
(sqrt (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0)))), sqrt((1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0)))), sqrt((1.0d0 - (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((Math.cos(phi1) * Math.cos(phi2)) * (t_0 * t_0)))), Math.sqrt((1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((math.cos(phi1) * math.cos(phi2)) * (t_0 * t_0)))), math.sqrt((1.0 - math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(t_0 * t_0)))), sqrt(Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0)))), sqrt((1.0 - (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))));
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(t_0 \cdot t_0\right)}}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right)
\end{array}
\end{array}
Initial program 62.2%
associate-*l*62.2%
Simplified62.2%
Taylor expanded in phi1 around 0 48.7%
associate--r+48.7%
unpow248.7%
1-sub-sin48.8%
unpow248.8%
Simplified48.8%
Taylor expanded in phi2 around 0 33.5%
Final simplification33.5%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (* phi2 (cos (* phi1 0.5)))))
(if (<= phi1 -1.65e+37)
(*
R
(*
2.0
(atan2
(+ (sin (* phi1 0.5)) (* -0.5 t_1))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* t_0 (* (* (cos phi1) (cos phi2)) t_0))))))))
(*
R
(*
2.0
(atan2
(* 0.5 t_1)
(sqrt
(-
1.0
(+
(pow (sin (* (- phi1 phi2) 0.5)) 2.0)
(*
(cos phi2)
(* (cos phi1) (pow (sin (* lambda1 0.5)) 2.0))))))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = phi2 * cos((phi1 * 0.5));
double tmp;
if (phi1 <= -1.65e+37) {
tmp = R * (2.0 * atan2((sin((phi1 * 0.5)) + (-0.5 * t_1)), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * ((cos(phi1) * cos(phi2)) * t_0)))))));
} else {
tmp = R * (2.0 * atan2((0.5 * t_1), sqrt((1.0 - (pow(sin(((phi1 - phi2) * 0.5)), 2.0) + (cos(phi2) * (cos(phi1) * pow(sin((lambda1 * 0.5)), 2.0))))))));
}
return tmp;
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = phi2 * cos((phi1 * 0.5d0))
if (phi1 <= (-1.65d+37)) then
tmp = r * (2.0d0 * atan2((sin((phi1 * 0.5d0)) + ((-0.5d0) * t_1)), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * ((cos(phi1) * cos(phi2)) * t_0)))))))
else
tmp = r * (2.0d0 * atan2((0.5d0 * t_1), sqrt((1.0d0 - ((sin(((phi1 - phi2) * 0.5d0)) ** 2.0d0) + (cos(phi2) * (cos(phi1) * (sin((lambda1 * 0.5d0)) ** 2.0d0))))))))
end if
code = tmp
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_1 = phi2 * Math.cos((phi1 * 0.5));
double tmp;
if (phi1 <= -1.65e+37) {
tmp = R * (2.0 * Math.atan2((Math.sin((phi1 * 0.5)) + (-0.5 * t_1)), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * ((Math.cos(phi1) * Math.cos(phi2)) * t_0)))))));
} else {
tmp = R * (2.0 * Math.atan2((0.5 * t_1), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) * 0.5)), 2.0) + (Math.cos(phi2) * (Math.cos(phi1) * Math.pow(Math.sin((lambda1 * 0.5)), 2.0))))))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = phi2 * math.cos((phi1 * 0.5)) tmp = 0 if phi1 <= -1.65e+37: tmp = R * (2.0 * math.atan2((math.sin((phi1 * 0.5)) + (-0.5 * t_1)), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * ((math.cos(phi1) * math.cos(phi2)) * t_0))))))) else: tmp = R * (2.0 * math.atan2((0.5 * t_1), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) * 0.5)), 2.0) + (math.cos(phi2) * (math.cos(phi1) * math.pow(math.sin((lambda1 * 0.5)), 2.0)))))))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(phi2 * cos(Float64(phi1 * 0.5))) tmp = 0.0 if (phi1 <= -1.65e+37) tmp = Float64(R * Float64(2.0 * atan(Float64(sin(Float64(phi1 * 0.5)) + Float64(-0.5 * t_1)), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(Float64(cos(phi1) * cos(phi2)) * t_0)))))))); else tmp = Float64(R * Float64(2.0 * atan(Float64(0.5 * t_1), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) * 0.5)) ^ 2.0) + Float64(cos(phi2) * Float64(cos(phi1) * (sin(Float64(lambda1 * 0.5)) ^ 2.0))))))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
t_1 = phi2 * cos((phi1 * 0.5));
tmp = 0.0;
if (phi1 <= -1.65e+37)
tmp = R * (2.0 * atan2((sin((phi1 * 0.5)) + (-0.5 * t_1)), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * ((cos(phi1) * cos(phi2)) * t_0)))))));
else
tmp = R * (2.0 * atan2((0.5 * t_1), sqrt((1.0 - ((sin(((phi1 - phi2) * 0.5)) ^ 2.0) + (cos(phi2) * (cos(phi1) * (sin((lambda1 * 0.5)) ^ 2.0))))))));
end
tmp_2 = tmp;
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(phi2 * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -1.65e+37], N[(R * N[(2.0 * N[ArcTan[N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] + N[(-0.5 * t$95$1), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[(0.5 * t$95$1), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \phi_2 \cdot \cos \left(\phi_1 \cdot 0.5\right)\\
\mathbf{if}\;\phi_1 \leq -1.65 \cdot 10^{+37}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sin \left(\phi_1 \cdot 0.5\right) + -0.5 \cdot t_1}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{0.5 \cdot t_1}{\sqrt{1 - \left({\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2} + \cos \phi_2 \cdot \left(\cos \phi_1 \cdot {\sin \left(\lambda_1 \cdot 0.5\right)}^{2}\right)\right)}}\right)\\
\end{array}
\end{array}
if phi1 < -1.65e37Initial program 46.6%
Taylor expanded in phi2 around 0 48.1%
Taylor expanded in phi2 around -inf 13.4%
if -1.65e37 < phi1 Initial program 66.4%
Taylor expanded in phi2 around 0 46.0%
Taylor expanded in phi2 around inf 11.7%
Taylor expanded in lambda2 around 0 11.7%
Final simplification12.1%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
(*
R
(*
2.0
(atan2
(- (* 0.5 (* phi2 (cos (* phi1 0.5)))) (sin (* phi1 0.5)))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* t_0 (* (* (cos phi1) (cos phi2)) t_0))))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * atan2(((0.5 * (phi2 * cos((phi1 * 0.5)))) - sin((phi1 * 0.5))), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * ((cos(phi1) * cos(phi2)) * t_0)))))));
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
code = r * (2.0d0 * atan2(((0.5d0 * (phi2 * cos((phi1 * 0.5d0)))) - sin((phi1 * 0.5d0))), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * ((cos(phi1) * cos(phi2)) * t_0)))))))
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.sin(((lambda1 - lambda2) / 2.0));
return R * (2.0 * Math.atan2(((0.5 * (phi2 * Math.cos((phi1 * 0.5)))) - Math.sin((phi1 * 0.5))), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * ((Math.cos(phi1) * Math.cos(phi2)) * t_0)))))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) return R * (2.0 * math.atan2(((0.5 * (phi2 * math.cos((phi1 * 0.5)))) - math.sin((phi1 * 0.5))), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * ((math.cos(phi1) * math.cos(phi2)) * t_0)))))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(R * Float64(2.0 * atan(Float64(Float64(0.5 * Float64(phi2 * cos(Float64(phi1 * 0.5)))) - sin(Float64(phi1 * 0.5))), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(Float64(cos(phi1) * cos(phi2)) * t_0)))))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
tmp = R * (2.0 * atan2(((0.5 * (phi2 * cos((phi1 * 0.5)))) - sin((phi1 * 0.5))), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * ((cos(phi1) * cos(phi2)) * t_0)))))));
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[(N[(0.5 * N[(phi2 * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$0 * N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{0.5 \cdot \left(\phi_2 \cdot \cos \left(\phi_1 \cdot 0.5\right)\right) - \sin \left(\phi_1 \cdot 0.5\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)\right)}}\right)
\end{array}
\end{array}
Initial program 62.2%
Taylor expanded in phi2 around 0 46.5%
Taylor expanded in phi2 around inf 13.3%
+-commutative13.3%
mul-1-neg13.3%
unsub-neg13.3%
*-commutative13.3%
Simplified13.3%
Final simplification13.3%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (* phi1 0.5))))
(*
R
(*
2.0
(atan2
(* 0.5 (* phi2 t_0))
(sqrt
(- (pow t_0 2.0) (* (cos phi1) (pow (sin (* lambda1 0.5)) 2.0)))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((phi1 * 0.5));
return R * (2.0 * atan2((0.5 * (phi2 * t_0)), sqrt((pow(t_0, 2.0) - (cos(phi1) * pow(sin((lambda1 * 0.5)), 2.0))))));
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
t_0 = cos((phi1 * 0.5d0))
code = r * (2.0d0 * atan2((0.5d0 * (phi2 * t_0)), sqrt(((t_0 ** 2.0d0) - (cos(phi1) * (sin((lambda1 * 0.5d0)) ** 2.0d0))))))
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos((phi1 * 0.5));
return R * (2.0 * Math.atan2((0.5 * (phi2 * t_0)), Math.sqrt((Math.pow(t_0, 2.0) - (Math.cos(phi1) * Math.pow(Math.sin((lambda1 * 0.5)), 2.0))))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((phi1 * 0.5)) return R * (2.0 * math.atan2((0.5 * (phi2 * t_0)), math.sqrt((math.pow(t_0, 2.0) - (math.cos(phi1) * math.pow(math.sin((lambda1 * 0.5)), 2.0))))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(phi1 * 0.5)) return Float64(R * Float64(2.0 * atan(Float64(0.5 * Float64(phi2 * t_0)), sqrt(Float64((t_0 ^ 2.0) - Float64(cos(phi1) * (sin(Float64(lambda1 * 0.5)) ^ 2.0))))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = cos((phi1 * 0.5));
tmp = R * (2.0 * atan2((0.5 * (phi2 * t_0)), sqrt(((t_0 ^ 2.0) - (cos(phi1) * (sin((lambda1 * 0.5)) ^ 2.0))))));
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[N[(0.5 * N[(phi2 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(N[Power[t$95$0, 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\phi_1 \cdot 0.5\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{0.5 \cdot \left(\phi_2 \cdot t_0\right)}{\sqrt{{t_0}^{2} - \cos \phi_1 \cdot {\sin \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)
\end{array}
\end{array}
Initial program 62.2%
Taylor expanded in phi2 around 0 46.5%
Taylor expanded in phi2 around inf 10.8%
Taylor expanded in phi2 around 0 11.0%
associate--r+11.0%
unpow211.0%
1-sub-sin11.0%
unpow211.0%
*-commutative11.0%
Simplified11.0%
Taylor expanded in lambda2 around 0 11.0%
*-commutative11.0%
Simplified11.0%
Final simplification11.0%
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(*
2.0
(atan2
(* 0.5 (* phi2 (cos (* phi1 0.5))))
(sqrt (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * atan2((0.5 * (phi2 * cos((phi1 * 0.5)))), sqrt((1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
}
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * (2.0d0 * atan2((0.5d0 * (phi2 * cos((phi1 * 0.5d0)))), sqrt((1.0d0 - (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))
end function
assert phi1 < phi2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * Math.atan2((0.5 * (phi2 * Math.cos((phi1 * 0.5)))), Math.sqrt((1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return R * (2.0 * math.atan2((0.5 * (phi2 * math.cos((phi1 * 0.5)))), math.sqrt((1.0 - math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * Float64(2.0 * atan(Float64(0.5 * Float64(phi2 * cos(Float64(phi1 * 0.5)))), sqrt(Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = R * (2.0 * atan2((0.5 * (phi2 * cos((phi1 * 0.5)))), sqrt((1.0 - (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))));
end
NOTE: phi1 and phi2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(2.0 * N[ArcTan[N[(0.5 * N[(phi2 * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{0.5 \cdot \left(\phi_2 \cdot \cos \left(\phi_1 \cdot 0.5\right)\right)}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right)
\end{array}
Initial program 62.2%
Taylor expanded in phi2 around 0 46.5%
Taylor expanded in phi2 around inf 10.8%
Taylor expanded in phi2 around 0 11.0%
associate--r+11.0%
unpow211.0%
1-sub-sin11.0%
unpow211.0%
*-commutative11.0%
Simplified11.0%
Taylor expanded in phi1 around 0 11.0%
Final simplification11.0%
herbie shell --seed 2023189
(FPCore (R lambda1 lambda2 phi1 phi2)
:name "Distance on a great circle"
:precision binary64
(* R (* 2.0 (atan2 (sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))) (sqrt (- 1.0 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* (* (cos phi1) (cos phi2)) (sin (/ (- lambda1 lambda2) 2.0))) (sin (/ (- lambda1 lambda2) 2.0))))))))))