
(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 18 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 (cos (* phi2 -0.5)))
(t_1 (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (* (* (cos phi1) (cos phi2)) (* t_2 t_2))))
(if (<= phi2 3.2e-5)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_3))
(sqrt (- (pow (cos (* phi1 0.5)) 2.0) (* (cos phi1) t_1))))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_3 (pow (+ (* 0.5 (* phi1 t_0)) (sin (* phi2 -0.5))) 2.0)))
(sqrt (- (pow t_0 2.0) (* (cos phi2) t_1)))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((phi2 * -0.5));
double t_1 = pow(sin((-0.5 * (lambda2 - lambda1))), 2.0);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = (cos(phi1) * cos(phi2)) * (t_2 * t_2);
double tmp;
if (phi2 <= 3.2e-5) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_3)), sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * t_1)))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_3 + pow(((0.5 * (phi1 * t_0)) + sin((phi2 * -0.5))), 2.0))), sqrt((pow(t_0, 2.0) - (cos(phi2) * 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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = cos((phi2 * (-0.5d0)))
t_1 = sin(((-0.5d0) * (lambda2 - lambda1))) ** 2.0d0
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
t_3 = (cos(phi1) * cos(phi2)) * (t_2 * t_2)
if (phi2 <= 3.2d-5) then
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_3)), sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * t_1)))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_3 + (((0.5d0 * (phi1 * t_0)) + sin((phi2 * (-0.5d0)))) ** 2.0d0))), sqrt(((t_0 ** 2.0d0) - (cos(phi2) * 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.cos((phi2 * -0.5));
double t_1 = Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0);
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_3 = (Math.cos(phi1) * Math.cos(phi2)) * (t_2 * t_2);
double tmp;
if (phi2 <= 3.2e-5) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_3)), Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * t_1)))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_3 + Math.pow(((0.5 * (phi1 * t_0)) + Math.sin((phi2 * -0.5))), 2.0))), Math.sqrt((Math.pow(t_0, 2.0) - (Math.cos(phi2) * t_1)))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((phi2 * -0.5)) t_1 = math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) t_3 = (math.cos(phi1) * math.cos(phi2)) * (t_2 * t_2) tmp = 0 if phi2 <= 3.2e-5: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_3)), math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * t_1))))) else: tmp = R * (2.0 * math.atan2(math.sqrt((t_3 + math.pow(((0.5 * (phi1 * t_0)) + math.sin((phi2 * -0.5))), 2.0))), math.sqrt((math.pow(t_0, 2.0) - (math.cos(phi2) * t_1))))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(phi2 * -0.5)) t_1 = sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0 t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = Float64(Float64(cos(phi1) * cos(phi2)) * Float64(t_2 * t_2)) tmp = 0.0 if (phi2 <= 3.2e-5) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_3)), sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * t_1)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_3 + (Float64(Float64(0.5 * Float64(phi1 * t_0)) + sin(Float64(phi2 * -0.5))) ^ 2.0))), sqrt(Float64((t_0 ^ 2.0) - Float64(cos(phi2) * t_1)))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = cos((phi2 * -0.5));
t_1 = sin((-0.5 * (lambda2 - lambda1))) ^ 2.0;
t_2 = sin(((lambda1 - lambda2) / 2.0));
t_3 = (cos(phi1) * cos(phi2)) * (t_2 * t_2);
tmp = 0.0;
if (phi2 <= 3.2e-5)
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_3)), sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * t_1)))));
else
tmp = R * (2.0 * atan2(sqrt((t_3 + (((0.5 * (phi1 * t_0)) + sin((phi2 * -0.5))) ^ 2.0))), sqrt(((t_0 ^ 2.0) - (cos(phi2) * 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[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 3.2e-5], 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] + t$95$3), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$3 + N[Power[N[(N[(0.5 * N[(phi1 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[t$95$0, 2.0], $MachinePrecision] - N[(N[Cos[phi2], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\phi_2 \cdot -0.5\right)\\
t_1 := {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(t_2 \cdot t_2\right)\\
\mathbf{if}\;\phi_2 \leq 3.2 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_3}}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot t_1}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_3 + {\left(0.5 \cdot \left(\phi_1 \cdot t_0\right) + \sin \left(\phi_2 \cdot -0.5\right)\right)}^{2}}}{\sqrt{{t_0}^{2} - \cos \phi_2 \cdot t_1}}\right)\\
\end{array}
\end{array}
if phi2 < 3.19999999999999986e-5Initial program 67.2%
associate-*l*67.2%
Simplified67.2%
Taylor expanded in phi2 around 0 58.8%
associate--r+58.8%
unpow258.8%
1-sub-sin58.8%
unpow258.8%
*-commutative58.8%
unpow258.8%
associate-*r*58.8%
Simplified58.8%
if 3.19999999999999986e-5 < phi2 Initial program 46.1%
associate-*l*46.1%
Simplified46.2%
Taylor expanded in phi1 around 0 47.0%
associate--r+47.0%
unpow247.0%
1-sub-sin47.0%
unpow247.0%
sub-neg47.0%
mul-1-neg47.0%
+-commutative47.0%
distribute-lft-in47.0%
associate-*r*47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-*r*47.0%
distribute-lft-in47.0%
+-commutative47.0%
+-commutative47.0%
mul-1-neg47.0%
sub-neg47.0%
Simplified47.0%
Taylor expanded in phi1 around 0 47.7%
Final simplification56.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 (* (cos phi1) (cos phi2)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (* t_1 t_1))))
(sqrt
(expm1
(log1p
(-
1.0
(fma
t_0
(pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)
(pow (sin (* (- phi1 phi2) 0.5)) 2.0)))))))))))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));
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_1 * t_1)))), sqrt(expm1(log1p((1.0 - fma(t_0, pow(sin(((lambda1 - lambda2) * 0.5)), 2.0), pow(sin(((phi1 - phi2) * 0.5)), 2.0))))))));
}
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)) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_1 * t_1)))), sqrt(expm1(log1p(Float64(1.0 - fma(t_0, (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0), (sin(Float64(Float64(phi1 - phi2) * 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[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = 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$0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(Exp[N[Log[1 + N[(1.0 - N[(t$95$0 * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $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)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_1 \cdot t_1\right)}}{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(1 - \mathsf{fma}\left(t_0, {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)\right)\right)}}\right)
\end{array}
\end{array}
Initial program 61.9%
associate-*l*61.9%
Simplified61.9%
expm1-log1p-u61.9%
associate--l-61.9%
+-commutative61.9%
fma-udef62.0%
pow262.0%
div-inv62.0%
metadata-eval62.0%
Applied egg-rr62.0%
Final simplification62.0%
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 (* (* (cos phi1) (cos phi2)) (* t_0 t_0)))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(* R (* 2.0 (atan2 (sqrt (+ t_2 t_1)) (sqrt (- (- 1.0 t_2) t_1)))))))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 = (cos(phi1) * cos(phi2)) * (t_0 * t_0);
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
return R * (2.0 * atan2(sqrt((t_2 + t_1)), sqrt(((1.0 - t_2) - t_1))));
}
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(((lambda1 - lambda2) / 2.0d0))
t_1 = (cos(phi1) * cos(phi2)) * (t_0 * t_0)
t_2 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
code = r * (2.0d0 * atan2(sqrt((t_2 + t_1)), sqrt(((1.0d0 - t_2) - t_1))))
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 = (Math.cos(phi1) * Math.cos(phi2)) * (t_0 * t_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_1)), Math.sqrt(((1.0 - t_2) - t_1))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = (math.cos(phi1) * math.cos(phi2)) * (t_0 * t_0) t_2 = math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) return R * (2.0 * math.atan2(math.sqrt((t_2 + t_1)), math.sqrt(((1.0 - t_2) - t_1))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(Float64(cos(phi1) * cos(phi2)) * Float64(t_0 * t_0)) t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 return Float64(R * Float64(2.0 * atan(sqrt(Float64(t_2 + t_1)), sqrt(Float64(Float64(1.0 - t_2) - t_1))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
t_1 = (cos(phi1) * cos(phi2)) * (t_0 * t_0);
t_2 = sin(((phi1 - phi2) / 2.0)) ^ 2.0;
tmp = R * (2.0 * atan2(sqrt((t_2 + t_1)), sqrt(((1.0 - t_2) - t_1))));
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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * t$95$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 + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - t$95$2), $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(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(t_0 \cdot t_0\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_1}}{\sqrt{\left(1 - t_2\right) - t_1}}\right)
\end{array}
\end{array}
Initial program 61.9%
associate-*l*61.9%
Simplified61.9%
Final simplification61.9%
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 (* (cos phi1) (cos phi2)))
(t_2 (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0))
(t_3 (sin (/ (- lambda1 lambda2) 2.0))))
(if (<= phi1 -1.55e-6)
(*
R
(*
2.0
(atan2
(sqrt (+ t_0 (* (* t_1 t_3) (sin (* lambda2 -0.5)))))
(sqrt (- (pow (cos (* phi1 0.5)) 2.0) (* (cos phi1) t_2))))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_0 (* t_1 (* t_3 t_3))))
(sqrt (- (pow (cos (* phi2 -0.5)) 2.0) (* (cos phi2) t_2)))))))))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 = cos(phi1) * cos(phi2);
double t_2 = pow(sin((-0.5 * (lambda2 - lambda1))), 2.0);
double t_3 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if (phi1 <= -1.55e-6) {
tmp = R * (2.0 * atan2(sqrt((t_0 + ((t_1 * t_3) * sin((lambda2 * -0.5))))), sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * t_2)))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_0 + (t_1 * (t_3 * t_3)))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * 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) :: t_3
real(8) :: tmp
t_0 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
t_1 = cos(phi1) * cos(phi2)
t_2 = sin(((-0.5d0) * (lambda2 - lambda1))) ** 2.0d0
t_3 = sin(((lambda1 - lambda2) / 2.0d0))
if (phi1 <= (-1.55d-6)) then
tmp = r * (2.0d0 * atan2(sqrt((t_0 + ((t_1 * t_3) * sin((lambda2 * (-0.5d0)))))), sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * t_2)))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_0 + (t_1 * (t_3 * t_3)))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - (cos(phi2) * 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(((phi1 - phi2) / 2.0)), 2.0);
double t_1 = Math.cos(phi1) * Math.cos(phi2);
double t_2 = Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0);
double t_3 = Math.sin(((lambda1 - lambda2) / 2.0));
double tmp;
if (phi1 <= -1.55e-6) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + ((t_1 * t_3) * Math.sin((lambda2 * -0.5))))), Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * t_2)))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + (t_1 * (t_3 * t_3)))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) - (Math.cos(phi2) * t_2)))));
}
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.cos(phi1) * math.cos(phi2) t_2 = math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0) t_3 = math.sin(((lambda1 - lambda2) / 2.0)) tmp = 0 if phi1 <= -1.55e-6: tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + ((t_1 * t_3) * math.sin((lambda2 * -0.5))))), math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * t_2))))) else: tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + (t_1 * (t_3 * t_3)))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) - (math.cos(phi2) * t_2))))) 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 = Float64(cos(phi1) * cos(phi2)) t_2 = sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0 t_3 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if (phi1 <= -1.55e-6) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + Float64(Float64(t_1 * t_3) * sin(Float64(lambda2 * -0.5))))), sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * t_2)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + Float64(t_1 * Float64(t_3 * t_3)))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - Float64(cos(phi2) * t_2)))))); 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 = cos(phi1) * cos(phi2);
t_2 = sin((-0.5 * (lambda2 - lambda1))) ^ 2.0;
t_3 = sin(((lambda1 - lambda2) / 2.0));
tmp = 0.0;
if (phi1 <= -1.55e-6)
tmp = R * (2.0 * atan2(sqrt((t_0 + ((t_1 * t_3) * sin((lambda2 * -0.5))))), sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * t_2)))));
else
tmp = R * (2.0 * atan2(sqrt((t_0 + (t_1 * (t_3 * t_3)))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - (cos(phi2) * 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[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -1.55e-6], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + N[(N[(t$95$1 * t$95$3), $MachinePrecision] * N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + N[(t$95$1 * N[(t$95$3 * t$95$3), $MachinePrecision]), $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$2), $MachinePrecision]), $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 := \cos \phi_1 \cdot \cos \phi_2\\
t_2 := {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}\\
t_3 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_1 \leq -1.55 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + \left(t_1 \cdot t_3\right) \cdot \sin \left(\lambda_2 \cdot -0.5\right)}}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot t_2}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + t_1 \cdot \left(t_3 \cdot t_3\right)}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - \cos \phi_2 \cdot t_2}}\right)\\
\end{array}
\end{array}
if phi1 < -1.55e-6Initial program 50.1%
Taylor expanded in lambda1 around 0 39.7%
Taylor expanded in phi2 around 0 40.7%
associate--r+18.7%
unpow218.7%
1-sub-sin18.8%
unpow218.8%
*-commutative18.8%
*-commutative18.8%
unpow218.8%
associate-*l*18.8%
Simplified40.7%
if -1.55e-6 < phi1 Initial program 66.4%
associate-*l*66.4%
Simplified66.5%
Taylor expanded in phi1 around 0 55.6%
associate--r+55.7%
unpow255.7%
1-sub-sin55.7%
unpow255.7%
sub-neg55.7%
mul-1-neg55.7%
+-commutative55.7%
distribute-lft-in55.7%
associate-*r*55.7%
metadata-eval55.7%
metadata-eval55.7%
associate-*r*55.7%
distribute-lft-in55.7%
+-commutative55.7%
+-commutative55.7%
mul-1-neg55.7%
sub-neg55.7%
Simplified55.7%
Final simplification51.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 (* -0.5 (- lambda2 lambda1))) 2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (* (* (cos phi1) (cos phi2)) (* t_1 t_1))))
(if (<= phi2 0.000165)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_2))
(sqrt (- (pow (cos (* phi1 0.5)) 2.0) (* (cos phi1) t_0))))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_2 (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((-0.5 * (lambda2 - lambda1))), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = (cos(phi1) * cos(phi2)) * (t_1 * t_1);
double tmp;
if (phi2 <= 0.000165) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_2)), sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * 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) - (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) :: t_2
real(8) :: tmp
t_0 = sin(((-0.5d0) * (lambda2 - lambda1))) ** 2.0d0
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
t_2 = (cos(phi1) * cos(phi2)) * (t_1 * t_1)
if (phi2 <= 0.000165d0) then
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_2)), sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * t_0)))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_2 + (sin((phi2 * (-0.5d0))) ** 2.0d0))), 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((-0.5 * (lambda2 - lambda1))), 2.0);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_2 = (Math.cos(phi1) * Math.cos(phi2)) * (t_1 * t_1);
double tmp;
if (phi2 <= 0.000165) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_2)), Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * 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) - (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((-0.5 * (lambda2 - lambda1))), 2.0) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) t_2 = (math.cos(phi1) * math.cos(phi2)) * (t_1 * t_1) tmp = 0 if phi2 <= 0.000165: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_2)), math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * 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) - (math.cos(phi2) * t_0))))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = Float64(Float64(cos(phi1) * cos(phi2)) * Float64(t_1 * t_1)) tmp = 0.0 if (phi2 <= 0.000165) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_2)), sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * 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) - 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((-0.5 * (lambda2 - lambda1))) ^ 2.0;
t_1 = sin(((lambda1 - lambda2) / 2.0));
t_2 = (cos(phi1) * cos(phi2)) * (t_1 * t_1);
tmp = 0.0;
if (phi2 <= 0.000165)
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_2)), sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * t_0)))));
else
tmp = R * (2.0 * atan2(sqrt((t_2 + (sin((phi2 * -0.5)) ^ 2.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[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $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[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 0.000165], 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] + t$95$2), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $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] - 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(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(t_1 \cdot t_1\right)\\
\mathbf{if}\;\phi_2 \leq 0.000165:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_2}}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot 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} - \cos \phi_2 \cdot t_0}}\right)\\
\end{array}
\end{array}
if phi2 < 1.65e-4Initial program 67.2%
associate-*l*67.2%
Simplified67.2%
Taylor expanded in phi2 around 0 58.8%
associate--r+58.8%
unpow258.8%
1-sub-sin58.8%
unpow258.8%
*-commutative58.8%
unpow258.8%
associate-*r*58.8%
Simplified58.8%
if 1.65e-4 < phi2 Initial program 46.1%
associate-*l*46.1%
Simplified46.2%
Taylor expanded in phi1 around 0 47.0%
associate--r+47.0%
unpow247.0%
1-sub-sin47.0%
unpow247.0%
sub-neg47.0%
mul-1-neg47.0%
+-commutative47.0%
distribute-lft-in47.0%
associate-*r*47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-*r*47.0%
distribute-lft-in47.0%
+-commutative47.0%
+-commutative47.0%
mul-1-neg47.0%
sub-neg47.0%
Simplified47.0%
Taylor expanded in phi1 around 0 46.9%
Final simplification55.9%
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 (* (* (cos phi1) (cos phi2)) (* t_0 t_0))))
(if (<= phi1 -7.8e-13)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
(sqrt (- 1.0 (pow (sin (* -0.5 (- phi2 phi1))) 2.0))))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_1 (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt
(-
(pow (cos (* phi2 -0.5)) 2.0)
(* (cos phi2) (pow (sin (* -0.5 (- lambda2 lambda1))) 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 = (cos(phi1) * cos(phi2)) * (t_0 * t_0);
double tmp;
if (phi1 <= -7.8e-13) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), sqrt((1.0 - pow(sin((-0.5 * (phi2 - phi1))), 2.0)))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_1 + pow(sin((phi2 * -0.5)), 2.0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * pow(sin((-0.5 * (lambda2 - lambda1))), 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 = (cos(phi1) * cos(phi2)) * (t_0 * t_0)
if (phi1 <= (-7.8d-13)) then
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt((1.0d0 - (sin(((-0.5d0) * (phi2 - phi1))) ** 2.0d0)))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_1 + (sin((phi2 * (-0.5d0))) ** 2.0d0))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - (cos(phi2) * (sin(((-0.5d0) * (lambda2 - lambda1))) ** 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 = (Math.cos(phi1) * Math.cos(phi2)) * (t_0 * t_0);
double tmp;
if (phi1 <= -7.8e-13) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), Math.sqrt((1.0 - Math.pow(Math.sin((-0.5 * (phi2 - phi1))), 2.0)))));
} 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) - (Math.cos(phi2) * Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 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 = (math.cos(phi1) * math.cos(phi2)) * (t_0 * t_0) tmp = 0 if phi1 <= -7.8e-13: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), math.sqrt((1.0 - math.pow(math.sin((-0.5 * (phi2 - phi1))), 2.0))))) 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) - (math.cos(phi2) * math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 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(Float64(cos(phi1) * cos(phi2)) * Float64(t_0 * t_0)) tmp = 0.0 if (phi1 <= -7.8e-13) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64(1.0 - (sin(Float64(-0.5 * Float64(phi2 - phi1))) ^ 2.0)))))); 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) - Float64(cos(phi2) * (sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 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 = (cos(phi1) * cos(phi2)) * (t_0 * t_0);
tmp = 0.0;
if (phi1 <= -7.8e-13)
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt((1.0 - (sin((-0.5 * (phi2 - phi1))) ^ 2.0)))));
else
tmp = R * (2.0 * atan2(sqrt((t_1 + (sin((phi2 * -0.5)) ^ 2.0))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - (cos(phi2) * (sin((-0.5 * (lambda2 - lambda1))) ^ 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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -7.8e-13], 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] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(-0.5 * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $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] - N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $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(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(t_0 \cdot t_0\right)\\
\mathbf{if}\;\phi_1 \leq -7.8 \cdot 10^{-13}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}}}\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} - \cos \phi_2 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right)\\
\end{array}
\end{array}
if phi1 < -7.80000000000000009e-13Initial program 50.8%
associate-*l*50.8%
Simplified50.9%
Taylor expanded in lambda1 around 0 40.8%
+-commutative40.8%
*-commutative40.8%
fma-def40.8%
*-commutative40.8%
Simplified40.8%
Taylor expanded in lambda2 around 0 31.4%
if -7.80000000000000009e-13 < phi1 Initial program 66.2%
associate-*l*66.2%
Simplified66.3%
Taylor expanded in phi1 around 0 55.4%
associate--r+55.4%
unpow255.4%
1-sub-sin55.4%
unpow255.4%
sub-neg55.4%
mul-1-neg55.4%
+-commutative55.4%
distribute-lft-in55.4%
associate-*r*55.4%
metadata-eval55.4%
metadata-eval55.4%
associate-*r*55.4%
distribute-lft-in55.4%
+-commutative55.4%
+-commutative55.4%
mul-1-neg55.4%
sub-neg55.4%
Simplified55.4%
Taylor expanded in phi1 around 0 52.5%
Final simplification46.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 (* (* (cos phi1) (cos phi2)) (* t_0 t_0))))
(if (<= phi1 -8.2e-13)
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
(sqrt
(-
(pow (cos (* phi1 0.5)) 2.0)
(* (cos phi1) (pow (sin (* lambda2 -0.5)) 2.0)))))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_1 (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt
(-
(pow (cos (* phi2 -0.5)) 2.0)
(* (cos phi2) (pow (sin (* -0.5 (- lambda2 lambda1))) 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 = (cos(phi1) * cos(phi2)) * (t_0 * t_0);
double tmp;
if (phi1 <= -8.2e-13) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * pow(sin((lambda2 * -0.5)), 2.0))))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_1 + pow(sin((phi2 * -0.5)), 2.0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * pow(sin((-0.5 * (lambda2 - lambda1))), 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 = (cos(phi1) * cos(phi2)) * (t_0 * t_0)
if (phi1 <= (-8.2d-13)) then
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * (sin((lambda2 * (-0.5d0))) ** 2.0d0))))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_1 + (sin((phi2 * (-0.5d0))) ** 2.0d0))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - (cos(phi2) * (sin(((-0.5d0) * (lambda2 - lambda1))) ** 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 = (Math.cos(phi1) * Math.cos(phi2)) * (t_0 * t_0);
double tmp;
if (phi1 <= -8.2e-13) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0))))));
} 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) - (Math.cos(phi2) * Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 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 = (math.cos(phi1) * math.cos(phi2)) * (t_0 * t_0) tmp = 0 if phi1 <= -8.2e-13: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * math.pow(math.sin((lambda2 * -0.5)), 2.0)))))) 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) - (math.cos(phi2) * math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 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(Float64(cos(phi1) * cos(phi2)) * Float64(t_0 * t_0)) tmp = 0.0 if (phi1 <= -8.2e-13) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))))); 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) - Float64(cos(phi2) * (sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 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 = (cos(phi1) * cos(phi2)) * (t_0 * t_0);
tmp = 0.0;
if (phi1 <= -8.2e-13)
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * (sin((lambda2 * -0.5)) ^ 2.0))))));
else
tmp = R * (2.0 * atan2(sqrt((t_1 + (sin((phi2 * -0.5)) ^ 2.0))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - (cos(phi2) * (sin((-0.5 * (lambda2 - lambda1))) ^ 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[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -8.2e-13], 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] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $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] - N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $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(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(t_0 \cdot t_0\right)\\
\mathbf{if}\;\phi_1 \leq -8.2 \cdot 10^{-13}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}}}\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} - \cos \phi_2 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right)\\
\end{array}
\end{array}
if phi1 < -8.2000000000000004e-13Initial program 50.8%
associate-*l*50.8%
Simplified50.9%
Taylor expanded in lambda1 around 0 40.8%
+-commutative40.8%
*-commutative40.8%
fma-def40.8%
*-commutative40.8%
Simplified40.8%
Taylor expanded in phi2 around 0 41.2%
+-commutative41.2%
associate--r+41.2%
unpow241.2%
1-sub-sin41.3%
unpow241.3%
Simplified41.3%
if -8.2000000000000004e-13 < phi1 Initial program 66.2%
associate-*l*66.2%
Simplified66.3%
Taylor expanded in phi1 around 0 55.4%
associate--r+55.4%
unpow255.4%
1-sub-sin55.4%
unpow255.4%
sub-neg55.4%
mul-1-neg55.4%
+-commutative55.4%
distribute-lft-in55.4%
associate-*r*55.4%
metadata-eval55.4%
metadata-eval55.4%
associate-*r*55.4%
distribute-lft-in55.4%
+-commutative55.4%
+-commutative55.4%
mul-1-neg55.4%
sub-neg55.4%
Simplified55.4%
Taylor expanded in phi1 around 0 52.5%
Final simplification49.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) (cos phi2)))
(t_1 (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0))
(t_2 (sin (/ (- lambda1 lambda2) 2.0))))
(if (<= phi1 -8.2e-13)
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* t_0 t_2) (sin (* lambda2 -0.5)))))
(sqrt (- (pow (cos (* phi1 0.5)) 2.0) (* (cos phi1) t_1))))))
(*
R
(*
2.0
(atan2
(sqrt (+ (* t_0 (* t_2 t_2)) (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt (- (pow (cos (* phi2 -0.5)) 2.0) (* (cos phi2) t_1)))))))))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 = pow(sin((-0.5 * (lambda2 - lambda1))), 2.0);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if (phi1 <= -8.2e-13) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((t_0 * t_2) * sin((lambda2 * -0.5))))), sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * t_1)))));
} else {
tmp = R * (2.0 * atan2(sqrt(((t_0 * (t_2 * t_2)) + pow(sin((phi2 * -0.5)), 2.0))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * 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) :: t_2
real(8) :: tmp
t_0 = cos(phi1) * cos(phi2)
t_1 = sin(((-0.5d0) * (lambda2 - lambda1))) ** 2.0d0
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
if (phi1 <= (-8.2d-13)) then
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + ((t_0 * t_2) * sin((lambda2 * (-0.5d0)))))), sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * t_1)))))
else
tmp = r * (2.0d0 * atan2(sqrt(((t_0 * (t_2 * t_2)) + (sin((phi2 * (-0.5d0))) ** 2.0d0))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - (cos(phi2) * 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.cos(phi1) * Math.cos(phi2);
double t_1 = Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0);
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
double tmp;
if (phi1 <= -8.2e-13) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((t_0 * t_2) * Math.sin((lambda2 * -0.5))))), Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * t_1)))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt(((t_0 * (t_2 * t_2)) + Math.pow(Math.sin((phi2 * -0.5)), 2.0))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) - (Math.cos(phi2) * t_1)))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos(phi1) * math.cos(phi2) t_1 = math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) tmp = 0 if phi1 <= -8.2e-13: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((t_0 * t_2) * math.sin((lambda2 * -0.5))))), math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * t_1))))) else: tmp = R * (2.0 * math.atan2(math.sqrt(((t_0 * (t_2 * t_2)) + math.pow(math.sin((phi2 * -0.5)), 2.0))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) - (math.cos(phi2) * t_1))))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) t_1 = sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0 t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if (phi1 <= -8.2e-13) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(t_0 * t_2) * sin(Float64(lambda2 * -0.5))))), sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * t_1)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(t_0 * Float64(t_2 * t_2)) + (sin(Float64(phi2 * -0.5)) ^ 2.0))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - Float64(cos(phi2) * t_1)))))); end return tmp end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = cos(phi1) * cos(phi2);
t_1 = sin((-0.5 * (lambda2 - lambda1))) ^ 2.0;
t_2 = sin(((lambda1 - lambda2) / 2.0));
tmp = 0.0;
if (phi1 <= -8.2e-13)
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + ((t_0 * t_2) * sin((lambda2 * -0.5))))), sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * t_1)))));
else
tmp = R * (2.0 * atan2(sqrt(((t_0 * (t_2 * t_2)) + (sin((phi2 * -0.5)) ^ 2.0))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - (cos(phi2) * 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[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -8.2e-13], 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[(t$95$0 * t$95$2), $MachinePrecision] * N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(t$95$0 * N[(t$95$2 * t$95$2), $MachinePrecision]), $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$1), $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(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_1 \leq -8.2 \cdot 10^{-13}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(t_0 \cdot t_2\right) \cdot \sin \left(\lambda_2 \cdot -0.5\right)}}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot t_1}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 \cdot \left(t_2 \cdot t_2\right) + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - \cos \phi_2 \cdot t_1}}\right)\\
\end{array}
\end{array}
if phi1 < -8.2000000000000004e-13Initial program 50.8%
Taylor expanded in lambda1 around 0 40.6%
Taylor expanded in phi2 around 0 41.5%
associate--r+18.5%
unpow218.5%
1-sub-sin18.6%
unpow218.6%
*-commutative18.6%
*-commutative18.6%
unpow218.6%
associate-*l*18.6%
Simplified41.5%
if -8.2000000000000004e-13 < phi1 Initial program 66.2%
associate-*l*66.2%
Simplified66.3%
Taylor expanded in phi1 around 0 55.4%
associate--r+55.4%
unpow255.4%
1-sub-sin55.4%
unpow255.4%
sub-neg55.4%
mul-1-neg55.4%
+-commutative55.4%
distribute-lft-in55.4%
associate-*r*55.4%
metadata-eval55.4%
metadata-eval55.4%
associate-*r*55.4%
distribute-lft-in55.4%
+-commutative55.4%
+-commutative55.4%
mul-1-neg55.4%
sub-neg55.4%
Simplified55.4%
Taylor expanded in phi1 around 0 52.5%
Final simplification49.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 (/ (- phi1 phi2) 2.0)) 2.0))
(t_1 (* (cos phi1) (cos phi2)))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (sin (* lambda2 -0.5))))
(if (<= lambda2 3.9e-21)
(*
R
(*
2.0
(atan2
(sqrt (+ t_0 (* t_1 (* t_2 t_2))))
(sqrt (- 1.0 (pow (sin (* -0.5 (- phi2 phi1))) 2.0))))))
(*
R
(*
2.0
(atan2
(sqrt (+ t_0 (* (* t_1 t_2) t_3)))
(sqrt
(- (pow (cos (* phi2 -0.5)) 2.0) (* (cos phi2) (pow t_3 2.0))))))))))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 = cos(phi1) * cos(phi2);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = sin((lambda2 * -0.5));
double tmp;
if (lambda2 <= 3.9e-21) {
tmp = R * (2.0 * atan2(sqrt((t_0 + (t_1 * (t_2 * t_2)))), sqrt((1.0 - pow(sin((-0.5 * (phi2 - phi1))), 2.0)))));
} else {
tmp = R * (2.0 * atan2(sqrt((t_0 + ((t_1 * t_2) * t_3))), sqrt((pow(cos((phi2 * -0.5)), 2.0) - (cos(phi2) * pow(t_3, 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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0
t_1 = cos(phi1) * cos(phi2)
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
t_3 = sin((lambda2 * (-0.5d0)))
if (lambda2 <= 3.9d-21) then
tmp = r * (2.0d0 * atan2(sqrt((t_0 + (t_1 * (t_2 * t_2)))), sqrt((1.0d0 - (sin(((-0.5d0) * (phi2 - phi1))) ** 2.0d0)))))
else
tmp = r * (2.0d0 * atan2(sqrt((t_0 + ((t_1 * t_2) * t_3))), sqrt(((cos((phi2 * (-0.5d0))) ** 2.0d0) - (cos(phi2) * (t_3 ** 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(((phi1 - phi2) / 2.0)), 2.0);
double t_1 = Math.cos(phi1) * Math.cos(phi2);
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
double t_3 = Math.sin((lambda2 * -0.5));
double tmp;
if (lambda2 <= 3.9e-21) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + (t_1 * (t_2 * t_2)))), Math.sqrt((1.0 - Math.pow(Math.sin((-0.5 * (phi2 - phi1))), 2.0)))));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((t_0 + ((t_1 * t_2) * t_3))), Math.sqrt((Math.pow(Math.cos((phi2 * -0.5)), 2.0) - (Math.cos(phi2) * Math.pow(t_3, 2.0))))));
}
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.cos(phi1) * math.cos(phi2) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) t_3 = math.sin((lambda2 * -0.5)) tmp = 0 if lambda2 <= 3.9e-21: tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + (t_1 * (t_2 * t_2)))), math.sqrt((1.0 - math.pow(math.sin((-0.5 * (phi2 - phi1))), 2.0))))) else: tmp = R * (2.0 * math.atan2(math.sqrt((t_0 + ((t_1 * t_2) * t_3))), math.sqrt((math.pow(math.cos((phi2 * -0.5)), 2.0) - (math.cos(phi2) * math.pow(t_3, 2.0)))))) 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 = Float64(cos(phi1) * cos(phi2)) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = sin(Float64(lambda2 * -0.5)) tmp = 0.0 if (lambda2 <= 3.9e-21) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + Float64(t_1 * Float64(t_2 * t_2)))), sqrt(Float64(1.0 - (sin(Float64(-0.5 * Float64(phi2 - phi1))) ^ 2.0)))))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(t_0 + Float64(Float64(t_1 * t_2) * t_3))), sqrt(Float64((cos(Float64(phi2 * -0.5)) ^ 2.0) - Float64(cos(phi2) * (t_3 ^ 2.0))))))); 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 = cos(phi1) * cos(phi2);
t_2 = sin(((lambda1 - lambda2) / 2.0));
t_3 = sin((lambda2 * -0.5));
tmp = 0.0;
if (lambda2 <= 3.9e-21)
tmp = R * (2.0 * atan2(sqrt((t_0 + (t_1 * (t_2 * t_2)))), sqrt((1.0 - (sin((-0.5 * (phi2 - phi1))) ^ 2.0)))));
else
tmp = R * (2.0 * atan2(sqrt((t_0 + ((t_1 * t_2) * t_3))), sqrt(((cos((phi2 * -0.5)) ^ 2.0) - (cos(phi2) * (t_3 ^ 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[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $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]}, Block[{t$95$3 = N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda2, 3.9e-21], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + N[(t$95$1 * N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(-0.5 * N[(phi2 - phi1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(t$95$0 + N[(N[(t$95$1 * t$95$2), $MachinePrecision] * t$95$3), $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[t$95$3, 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(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := \sin \left(\lambda_2 \cdot -0.5\right)\\
\mathbf{if}\;\lambda_2 \leq 3.9 \cdot 10^{-21}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + t_1 \cdot \left(t_2 \cdot t_2\right)}}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{t_0 + \left(t_1 \cdot t_2\right) \cdot t_3}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2} - \cos \phi_2 \cdot {t_3}^{2}}}\right)\\
\end{array}
\end{array}
if lambda2 < 3.9000000000000001e-21Initial program 66.9%
associate-*l*66.9%
Simplified67.0%
Taylor expanded in lambda1 around 0 51.3%
+-commutative51.3%
*-commutative51.3%
fma-def51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in lambda2 around 0 40.4%
if 3.9000000000000001e-21 < lambda2 Initial program 48.8%
Taylor expanded in lambda1 around 0 47.2%
Taylor expanded in phi1 around 0 37.0%
Taylor expanded in lambda1 around 0 37.0%
associate--r+37.0%
unpow237.0%
1-sub-sin37.0%
unpow237.0%
*-commutative37.0%
Simplified37.0%
Final simplification39.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
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (cos phi1) (cos phi2)) (* t_0 t_0))))))
(if (<= (- lambda1 lambda2) -200000.0)
(*
R
(*
2.0
(atan2
t_1
(sqrt
(expm1
(log1p (- 1.0 (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0))))))))
(*
R
(*
2.0
(atan2 t_1 (sqrt (- 1.0 (pow (sin (* -0.5 (- phi2 phi1))) 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 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0))));
double tmp;
if ((lambda1 - lambda2) <= -200000.0) {
tmp = R * (2.0 * atan2(t_1, sqrt(expm1(log1p((1.0 - pow(sin((-0.5 * (lambda2 - lambda1))), 2.0)))))));
} else {
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin((-0.5 * (phi2 - phi1))), 2.0)))));
}
return tmp;
}
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 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((Math.cos(phi1) * Math.cos(phi2)) * (t_0 * t_0))));
double tmp;
if ((lambda1 - lambda2) <= -200000.0) {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt(Math.expm1(Math.log1p((1.0 - Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0)))))));
} else {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin((-0.5 * (phi2 - phi1))), 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 = math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((math.cos(phi1) * math.cos(phi2)) * (t_0 * t_0)))) tmp = 0 if (lambda1 - lambda2) <= -200000.0: tmp = R * (2.0 * math.atan2(t_1, math.sqrt(math.expm1(math.log1p((1.0 - math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0))))))) else: tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin((-0.5 * (phi2 - phi1))), 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 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(t_0 * t_0)))) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -200000.0) tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(expm1(log1p(Float64(1.0 - (sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0)))))))); else tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(-0.5 * Float64(phi2 - phi1))) ^ 2.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[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = 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]}, If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -200000.0], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(Exp[N[Log[1 + N[(1.0 - N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(-0.5 * N[(phi2 - phi1), $MachinePrecision]), $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)\\
t_1 := \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)}\\
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -200000:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}\right)\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}}}\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -2e5Initial program 53.2%
associate-*l*53.3%
Simplified53.3%
Taylor expanded in phi1 around 0 36.4%
associate--r+36.4%
unpow236.4%
1-sub-sin36.4%
unpow236.4%
sub-neg36.4%
mul-1-neg36.4%
+-commutative36.4%
distribute-lft-in36.4%
associate-*r*36.4%
metadata-eval36.4%
metadata-eval36.4%
associate-*r*36.4%
distribute-lft-in36.4%
+-commutative36.4%
+-commutative36.4%
mul-1-neg36.4%
sub-neg36.4%
Simplified36.4%
Taylor expanded in phi2 around 0 27.3%
expm1-log1p-u27.3%
Applied egg-rr27.3%
if -2e5 < (-.f64 lambda1 lambda2) Initial program 67.8%
associate-*l*67.8%
Simplified67.9%
Taylor expanded in lambda1 around 0 60.1%
+-commutative60.1%
*-commutative60.1%
fma-def60.1%
*-commutative60.1%
Simplified60.1%
Taylor expanded in lambda2 around 0 46.2%
Final simplification38.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
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (cos phi1) (cos phi2)) (* t_0 t_0))))))
(if (<= (- lambda1 lambda2) -200000.0)
(*
R
(*
2.0
(atan2
t_1
(sqrt (- 1.0 (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0))))))
(*
R
(*
2.0
(atan2 t_1 (sqrt (- 1.0 (pow (sin (* -0.5 (- phi2 phi1))) 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 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0))));
double tmp;
if ((lambda1 - lambda2) <= -200000.0) {
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin((-0.5 * (lambda2 - lambda1))), 2.0)))));
} else {
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin((-0.5 * (phi2 - phi1))), 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 = sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0))))
if ((lambda1 - lambda2) <= (-200000.0d0)) then
tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin(((-0.5d0) * (lambda2 - lambda1))) ** 2.0d0)))))
else
tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin(((-0.5d0) * (phi2 - phi1))) ** 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 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((Math.cos(phi1) * Math.cos(phi2)) * (t_0 * t_0))));
double tmp;
if ((lambda1 - lambda2) <= -200000.0) {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0)))));
} else {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin((-0.5 * (phi2 - phi1))), 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 = math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((math.cos(phi1) * math.cos(phi2)) * (t_0 * t_0)))) tmp = 0 if (lambda1 - lambda2) <= -200000.0: tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0))))) else: tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin((-0.5 * (phi2 - phi1))), 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 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(t_0 * t_0)))) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -200000.0) tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0)))))); else tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(-0.5 * Float64(phi2 - phi1))) ^ 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 = sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0))));
tmp = 0.0;
if ((lambda1 - lambda2) <= -200000.0)
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin((-0.5 * (lambda2 - lambda1))) ^ 2.0)))));
else
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin((-0.5 * (phi2 - phi1))) ^ 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[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]}, If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -200000.0], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(-0.5 * N[(phi2 - phi1), $MachinePrecision]), $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)\\
t_1 := \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)}\\
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -200000:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(-0.5 \cdot \left(\phi_2 - \phi_1\right)\right)}^{2}}}\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -2e5Initial program 53.2%
associate-*l*53.3%
Simplified53.3%
Taylor expanded in phi1 around 0 36.4%
associate--r+36.4%
unpow236.4%
1-sub-sin36.4%
unpow236.4%
sub-neg36.4%
mul-1-neg36.4%
+-commutative36.4%
distribute-lft-in36.4%
associate-*r*36.4%
metadata-eval36.4%
metadata-eval36.4%
associate-*r*36.4%
distribute-lft-in36.4%
+-commutative36.4%
+-commutative36.4%
mul-1-neg36.4%
sub-neg36.4%
Simplified36.4%
Taylor expanded in phi2 around 0 27.3%
if -2e5 < (-.f64 lambda1 lambda2) Initial program 67.8%
associate-*l*67.8%
Simplified67.9%
Taylor expanded in lambda1 around 0 60.1%
+-commutative60.1%
*-commutative60.1%
fma-def60.1%
*-commutative60.1%
Simplified60.1%
Taylor expanded in lambda2 around 0 46.2%
Final simplification38.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))))
(*
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 (* -0.5 (- lambda2 lambda1))) 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((-0.5 * (lambda2 - lambda1))), 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(((-0.5d0) * (lambda2 - lambda1))) ** 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((-0.5 * (lambda2 - lambda1))), 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((-0.5 * (lambda2 - lambda1))), 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(-0.5 * Float64(lambda2 - lambda1))) ^ 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((-0.5 * (lambda2 - lambda1))) ^ 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[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $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(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right)
\end{array}
\end{array}
Initial program 61.9%
associate-*l*61.9%
Simplified61.9%
Taylor expanded in phi1 around 0 46.2%
associate--r+46.2%
unpow246.2%
1-sub-sin46.2%
unpow246.2%
sub-neg46.2%
mul-1-neg46.2%
+-commutative46.2%
distribute-lft-in46.2%
associate-*r*46.2%
metadata-eval46.2%
metadata-eval46.2%
associate-*r*46.2%
distribute-lft-in46.2%
+-commutative46.2%
+-commutative46.2%
mul-1-neg46.2%
sub-neg46.2%
Simplified46.2%
Taylor expanded in phi2 around 0 32.5%
Final simplification32.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
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (cos phi1) (cos phi2)) (* t_0 t_0))))))
(if (<= lambda1 -3600.0)
(* R (* 2.0 (atan2 t_1 (sqrt (pow (cos (* lambda1 0.5)) 2.0)))))
(* R (* 2.0 (atan2 t_1 (sqrt (pow (cos (* 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));
double t_1 = sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0))));
double tmp;
if (lambda1 <= -3600.0) {
tmp = R * (2.0 * atan2(t_1, sqrt(pow(cos((lambda1 * 0.5)), 2.0))));
} else {
tmp = R * (2.0 * atan2(t_1, sqrt(pow(cos((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) / 2.0d0))
t_1 = sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0))))
if (lambda1 <= (-3600.0d0)) then
tmp = r * (2.0d0 * atan2(t_1, sqrt((cos((lambda1 * 0.5d0)) ** 2.0d0))))
else
tmp = r * (2.0d0 * atan2(t_1, sqrt((cos((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.sin(((lambda1 - lambda2) / 2.0));
double t_1 = Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((Math.cos(phi1) * Math.cos(phi2)) * (t_0 * t_0))));
double tmp;
if (lambda1 <= -3600.0) {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt(Math.pow(Math.cos((lambda1 * 0.5)), 2.0))));
} else {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt(Math.pow(Math.cos((lambda2 * -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 = math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + ((math.cos(phi1) * math.cos(phi2)) * (t_0 * t_0)))) tmp = 0 if lambda1 <= -3600.0: tmp = R * (2.0 * math.atan2(t_1, math.sqrt(math.pow(math.cos((lambda1 * 0.5)), 2.0)))) else: tmp = R * (2.0 * math.atan2(t_1, math.sqrt(math.pow(math.cos((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) / 2.0)) t_1 = sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(t_0 * t_0)))) tmp = 0.0 if (lambda1 <= -3600.0) tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt((cos(Float64(lambda1 * 0.5)) ^ 2.0))))); else tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt((cos(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) / 2.0));
t_1 = sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + ((cos(phi1) * cos(phi2)) * (t_0 * t_0))));
tmp = 0.0;
if (lambda1 <= -3600.0)
tmp = R * (2.0 * atan2(t_1, sqrt((cos((lambda1 * 0.5)) ^ 2.0))));
else
tmp = R * (2.0 * atan2(t_1, sqrt((cos((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[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = 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]}, If[LessEqual[lambda1, -3600.0], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[Power[N[Cos[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[Power[N[Cos[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $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 := \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)}\\
\mathbf{if}\;\lambda_1 \leq -3600:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{{\cos \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{{\cos \left(\lambda_2 \cdot -0.5\right)}^{2}}}\right)\\
\end{array}
\end{array}
if lambda1 < -3600Initial program 45.3%
associate-*l*45.3%
Simplified45.4%
Taylor expanded in phi1 around 0 30.3%
associate--r+30.3%
unpow230.3%
1-sub-sin30.3%
unpow230.3%
sub-neg30.3%
mul-1-neg30.3%
+-commutative30.3%
distribute-lft-in30.3%
associate-*r*30.3%
metadata-eval30.3%
metadata-eval30.3%
associate-*r*30.3%
distribute-lft-in30.3%
+-commutative30.3%
+-commutative30.3%
mul-1-neg30.3%
sub-neg30.3%
Simplified30.3%
Taylor expanded in phi2 around 0 23.1%
Taylor expanded in lambda2 around 0 23.1%
unpow223.1%
1-sub-sin23.1%
unpow223.1%
*-commutative23.1%
Simplified23.1%
if -3600 < lambda1 Initial program 69.0%
associate-*l*69.1%
Simplified69.1%
Taylor expanded in phi1 around 0 53.0%
associate--r+53.1%
unpow253.1%
1-sub-sin53.1%
unpow253.1%
sub-neg53.1%
mul-1-neg53.1%
+-commutative53.1%
distribute-lft-in53.1%
associate-*r*53.1%
metadata-eval53.1%
metadata-eval53.1%
associate-*r*53.1%
distribute-lft-in53.1%
+-commutative53.1%
+-commutative53.1%
mul-1-neg53.1%
sub-neg53.1%
Simplified53.1%
Taylor expanded in phi2 around 0 36.6%
Taylor expanded in lambda1 around 0 34.1%
unpow234.1%
1-sub-sin34.2%
unpow234.2%
Simplified34.2%
Final simplification30.8%
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 (pow (cos (* 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(pow(cos((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((cos((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(Math.pow(Math.cos((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(math.pow(math.cos((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((cos(Float64(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((cos((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[Power[N[Cos[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $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{{\cos \left(\lambda_2 \cdot -0.5\right)}^{2}}}\right)
\end{array}
\end{array}
Initial program 61.9%
associate-*l*61.9%
Simplified61.9%
Taylor expanded in phi1 around 0 46.2%
associate--r+46.2%
unpow246.2%
1-sub-sin46.2%
unpow246.2%
sub-neg46.2%
mul-1-neg46.2%
+-commutative46.2%
distribute-lft-in46.2%
associate-*r*46.2%
metadata-eval46.2%
metadata-eval46.2%
associate-*r*46.2%
distribute-lft-in46.2%
+-commutative46.2%
+-commutative46.2%
mul-1-neg46.2%
sub-neg46.2%
Simplified46.2%
Taylor expanded in phi2 around 0 32.5%
Taylor expanded in lambda1 around 0 29.9%
unpow229.9%
1-sub-sin29.9%
unpow229.9%
Simplified29.9%
Final simplification29.9%
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))))
(*
R
(*
2.0
(atan2
t_0
(sqrt
(-
1.0
(+
(pow t_0 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(((phi1 - phi2) * 0.5));
return R * (2.0 * atan2(t_0, sqrt((1.0 - (pow(t_0, 2.0) + (cos(phi2) * (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 = sin(((phi1 - phi2) * 0.5d0))
code = r * (2.0d0 * atan2(t_0, sqrt((1.0d0 - ((t_0 ** 2.0d0) + (cos(phi2) * (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.sin(((phi1 - phi2) * 0.5));
return R * (2.0 * Math.atan2(t_0, Math.sqrt((1.0 - (Math.pow(t_0, 2.0) + (Math.cos(phi2) * (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.sin(((phi1 - phi2) * 0.5)) return R * (2.0 * math.atan2(t_0, math.sqrt((1.0 - (math.pow(t_0, 2.0) + (math.cos(phi2) * (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 = sin(Float64(Float64(phi1 - phi2) * 0.5)) return Float64(R * Float64(2.0 * atan(t_0, sqrt(Float64(1.0 - Float64((t_0 ^ 2.0) + Float64(cos(phi2) * 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 = sin(((phi1 - phi2) * 0.5));
tmp = R * (2.0 * atan2(t_0, sqrt((1.0 - ((t_0 ^ 2.0) + (cos(phi2) * (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[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[t$95$0 / N[Sqrt[N[(1.0 - N[(N[Power[t$95$0, 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(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_0}{\sqrt{1 - \left({t_0}^{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}
Initial program 61.9%
Taylor expanded in lambda1 around 0 48.1%
Taylor expanded in lambda2 around 0 16.3%
Taylor expanded in lambda2 around 0 16.2%
Final simplification16.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 (sin (* (- phi1 phi2) 0.5))))
(*
R
(*
2.0
(atan2
t_0
(sqrt
(-
1.0
(+
(pow t_0 2.0)
(* (* (cos phi1) (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 = sin(((phi1 - phi2) * 0.5));
return R * (2.0 * atan2(t_0, sqrt((1.0 - (pow(t_0, 2.0) + ((cos(phi1) * cos(phi2)) * pow(sin((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(((phi1 - phi2) * 0.5d0))
code = r * (2.0d0 * atan2(t_0, sqrt((1.0d0 - ((t_0 ** 2.0d0) + ((cos(phi1) * cos(phi2)) * (sin((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(((phi1 - phi2) * 0.5));
return R * (2.0 * Math.atan2(t_0, Math.sqrt((1.0 - (Math.pow(t_0, 2.0) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.pow(Math.sin((lambda2 * -0.5)), 2.0)))))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((phi1 - phi2) * 0.5)) return R * (2.0 * math.atan2(t_0, math.sqrt((1.0 - (math.pow(t_0, 2.0) + ((math.cos(phi1) * math.cos(phi2)) * math.pow(math.sin((lambda2 * -0.5)), 2.0)))))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(phi1 - phi2) * 0.5)) return Float64(R * Float64(2.0 * atan(t_0, sqrt(Float64(1.0 - Float64((t_0 ^ 2.0) + Float64(Float64(cos(phi1) * cos(phi2)) * (sin(Float64(lambda2 * -0.5)) ^ 2.0)))))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((phi1 - phi2) * 0.5));
tmp = R * (2.0 * atan2(t_0, sqrt((1.0 - ((t_0 ^ 2.0) + ((cos(phi1) * cos(phi2)) * (sin((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[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(R * N[(2.0 * N[ArcTan[t$95$0 / N[Sqrt[N[(1.0 - N[(N[Power[t$95$0, 2.0], $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.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(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_0}{\sqrt{1 - \left({t_0}^{2} + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}\right)
\end{array}
\end{array}
Initial program 61.9%
Taylor expanded in lambda1 around 0 48.1%
Taylor expanded in lambda2 around 0 16.3%
Taylor expanded in lambda1 around 0 16.3%
Final simplification16.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 (sin (* (- phi1 phi2) 0.5))))
(if (<= phi1 -3.5e+15)
(*
R
(*
2.0
(atan2
t_0
(sqrt
(-
(pow (cos (* phi1 0.5)) 2.0)
(* (cos phi1) (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0)))))))
(*
R
(*
2.0
(atan2
t_0
(sqrt
(-
1.0
(+
(pow (sin (* phi2 -0.5)) 2.0)
(* (cos phi2) (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(((phi1 - phi2) * 0.5));
double tmp;
if (phi1 <= -3.5e+15) {
tmp = R * (2.0 * atan2(t_0, sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * pow(sin((-0.5 * (lambda2 - lambda1))), 2.0))))));
} else {
tmp = R * (2.0 * atan2(t_0, sqrt((1.0 - (pow(sin((phi2 * -0.5)), 2.0) + (cos(phi2) * pow(sin(((lambda1 - 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) :: tmp
t_0 = sin(((phi1 - phi2) * 0.5d0))
if (phi1 <= (-3.5d+15)) then
tmp = r * (2.0d0 * atan2(t_0, sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * (sin(((-0.5d0) * (lambda2 - lambda1))) ** 2.0d0))))))
else
tmp = r * (2.0d0 * atan2(t_0, sqrt((1.0d0 - ((sin((phi2 * (-0.5d0))) ** 2.0d0) + (cos(phi2) * (sin(((lambda1 - 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.sin(((phi1 - phi2) * 0.5));
double tmp;
if (phi1 <= -3.5e+15) {
tmp = R * (2.0 * Math.atan2(t_0, Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0))))));
} else {
tmp = R * (2.0 * Math.atan2(t_0, Math.sqrt((1.0 - (Math.pow(Math.sin((phi2 * -0.5)), 2.0) + (Math.cos(phi2) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))))));
}
return tmp;
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((phi1 - phi2) * 0.5)) tmp = 0 if phi1 <= -3.5e+15: tmp = R * (2.0 * math.atan2(t_0, math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0)))))) else: tmp = R * (2.0 * math.atan2(t_0, math.sqrt((1.0 - (math.pow(math.sin((phi2 * -0.5)), 2.0) + (math.cos(phi2) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0))))))) return tmp
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(phi1 - phi2) * 0.5)) tmp = 0.0 if (phi1 <= -3.5e+15) tmp = Float64(R * Float64(2.0 * atan(t_0, sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * (sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0))))))); else tmp = Float64(R * Float64(2.0 * atan(t_0, sqrt(Float64(1.0 - Float64((sin(Float64(phi2 * -0.5)) ^ 2.0) + Float64(cos(phi2) * (sin(Float64(Float64(lambda1 - 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(((phi1 - phi2) * 0.5));
tmp = 0.0;
if (phi1 <= -3.5e+15)
tmp = R * (2.0 * atan2(t_0, sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * (sin((-0.5 * (lambda2 - lambda1))) ^ 2.0))))));
else
tmp = R * (2.0 * atan2(t_0, sqrt((1.0 - ((sin((phi2 * -0.5)) ^ 2.0) + (cos(phi2) * (sin(((lambda1 - 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[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -3.5e+15], N[(R * N[(2.0 * N[ArcTan[t$95$0 / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$0 / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.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(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)\\
\mathbf{if}\;\phi_1 \leq -3.5 \cdot 10^{+15}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_0}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_0}{\sqrt{1 - \left({\sin \left(\phi_2 \cdot -0.5\right)}^{2} + \cos \phi_2 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right)}}\right)\\
\end{array}
\end{array}
if phi1 < -3.5e15Initial program 50.5%
Taylor expanded in lambda1 around 0 39.2%
Taylor expanded in lambda2 around 0 19.7%
Taylor expanded in phi2 around 0 20.1%
associate--r+20.1%
unpow220.1%
1-sub-sin20.2%
unpow220.2%
*-commutative20.2%
*-commutative20.2%
unpow220.2%
associate-*l*20.2%
Simplified20.2%
if -3.5e15 < phi1 Initial program 65.8%
Taylor expanded in lambda1 around 0 51.2%
Taylor expanded in lambda2 around 0 15.2%
Taylor expanded in phi1 around 0 13.4%
Final simplification15.1%
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
(sin (* (- phi1 phi2) 0.5))
(sqrt
(-
(pow (cos (* phi1 0.5)) 2.0)
(* (cos phi1) (pow (sin (* -0.5 (- lambda2 lambda1))) 2.0))))))))assert(phi1 < phi2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * atan2(sin(((phi1 - phi2) * 0.5)), sqrt((pow(cos((phi1 * 0.5)), 2.0) - (cos(phi1) * pow(sin((-0.5 * (lambda2 - lambda1))), 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(sin(((phi1 - phi2) * 0.5d0)), sqrt(((cos((phi1 * 0.5d0)) ** 2.0d0) - (cos(phi1) * (sin(((-0.5d0) * (lambda2 - lambda1))) ** 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(Math.sin(((phi1 - phi2) * 0.5)), Math.sqrt((Math.pow(Math.cos((phi1 * 0.5)), 2.0) - (Math.cos(phi1) * Math.pow(Math.sin((-0.5 * (lambda2 - lambda1))), 2.0))))));
}
[phi1, phi2] = sort([phi1, phi2]) def code(R, lambda1, lambda2, phi1, phi2): return R * (2.0 * math.atan2(math.sin(((phi1 - phi2) * 0.5)), math.sqrt((math.pow(math.cos((phi1 * 0.5)), 2.0) - (math.cos(phi1) * math.pow(math.sin((-0.5 * (lambda2 - lambda1))), 2.0))))))
phi1, phi2 = sort([phi1, phi2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * Float64(2.0 * atan(sin(Float64(Float64(phi1 - phi2) * 0.5)), sqrt(Float64((cos(Float64(phi1 * 0.5)) ^ 2.0) - Float64(cos(phi1) * (sin(Float64(-0.5 * Float64(lambda2 - lambda1))) ^ 2.0))))))) end
phi1, phi2 = num2cell(sort([phi1, phi2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = R * (2.0 * atan2(sin(((phi1 - phi2) * 0.5)), sqrt(((cos((phi1 * 0.5)) ^ 2.0) - (cos(phi1) * (sin((-0.5 * (lambda2 - lambda1))) ^ 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[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(-0.5 * N[(lambda2 - lambda1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[phi1, phi2] = \mathsf{sort}([phi1, phi2])\\
\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}{\sqrt{{\cos \left(\phi_1 \cdot 0.5\right)}^{2} - \cos \phi_1 \cdot {\sin \left(-0.5 \cdot \left(\lambda_2 - \lambda_1\right)\right)}^{2}}}\right)
\end{array}
Initial program 61.9%
Taylor expanded in lambda1 around 0 48.1%
Taylor expanded in lambda2 around 0 16.3%
Taylor expanded in phi2 around 0 14.0%
associate--r+14.0%
unpow214.0%
1-sub-sin14.0%
unpow214.0%
*-commutative14.0%
*-commutative14.0%
unpow214.0%
associate-*l*14.0%
Simplified14.0%
Final simplification14.0%
herbie shell --seed 2023172
(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))))))))))