
(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 22 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: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* (- lambda1 lambda2) 0.5)))
(t_1
(pow
(fma
(sin (* phi1 0.5))
(cos (* phi2 0.5))
(* (sin (* phi2 0.5)) (- (cos (* phi1 0.5)))))
2.0)))
(*
(atan2
(sqrt
(fma
(sin (/ (- lambda1 lambda2) 2.0))
(* (cos phi1) (* (cos phi2) (log1p (expm1 t_0))))
t_1))
(sqrt (- 1.0 (+ (* (* (cos phi1) (cos phi2)) (pow t_0 2.0)) t_1))))
(* 2.0 R))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) * 0.5));
double t_1 = pow(fma(sin((phi1 * 0.5)), cos((phi2 * 0.5)), (sin((phi2 * 0.5)) * -cos((phi1 * 0.5)))), 2.0);
return atan2(sqrt(fma(sin(((lambda1 - lambda2) / 2.0)), (cos(phi1) * (cos(phi2) * log1p(expm1(t_0)))), t_1)), sqrt((1.0 - (((cos(phi1) * cos(phi2)) * pow(t_0, 2.0)) + t_1)))) * (2.0 * R);
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) t_1 = fma(sin(Float64(phi1 * 0.5)), cos(Float64(phi2 * 0.5)), Float64(sin(Float64(phi2 * 0.5)) * Float64(-cos(Float64(phi1 * 0.5))))) ^ 2.0 return Float64(atan(sqrt(fma(sin(Float64(Float64(lambda1 - lambda2) / 2.0)), Float64(cos(phi1) * Float64(cos(phi2) * log1p(expm1(t_0)))), t_1)), sqrt(Float64(1.0 - Float64(Float64(Float64(cos(phi1) * cos(phi2)) * (t_0 ^ 2.0)) + t_1)))) * Float64(2.0 * R)) end
NOTE: lambda1 and lambda2 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] * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * (-N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, N[(N[ArcTan[N[Sqrt[N[(N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Log[1 + N[(Exp[t$95$0] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
t_1 := {\left(\mathsf{fma}\left(\sin \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\cos \left(\phi_1 \cdot 0.5\right)\right)\right)\right)}^{2}\\
\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right), \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(t_0\right)\right)\right), t_1\right)}}{\sqrt{1 - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot {t_0}^{2} + t_1\right)}} \cdot \left(2 \cdot R\right)
\end{array}
\end{array}
Initial program 63.1%
Simplified63.1%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr64.2%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified64.2%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr79.6%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified79.7%
sub-neg79.7%
fma-udef79.7%
Applied egg-rr79.7%
add-sqr-sqrt38.0%
sqrt-prod53.5%
log1p-expm1-u53.5%
sqrt-prod38.1%
add-sqr-sqrt79.7%
div-inv79.7%
metadata-eval79.7%
Applied egg-rr79.7%
Final simplification79.7%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(pow
(fma
(sin (* phi1 0.5))
(cos (* phi2 0.5))
(* (sin (* phi2 0.5)) (- (cos (* phi1 0.5)))))
2.0))
(t_1 (sin (/ (- lambda1 lambda2) 2.0))))
(*
(* 2.0 R)
(atan2
(sqrt (fma t_1 (* (cos phi1) (* t_1 (cos phi2))) t_0))
(sqrt
(-
1.0
(+
(*
(* (cos phi1) (cos phi2))
(pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
t_0)))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(fma(sin((phi1 * 0.5)), cos((phi2 * 0.5)), (sin((phi2 * 0.5)) * -cos((phi1 * 0.5)))), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
return (2.0 * R) * atan2(sqrt(fma(t_1, (cos(phi1) * (t_1 * cos(phi2))), t_0)), sqrt((1.0 - (((cos(phi1) * cos(phi2)) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)) + t_0))));
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = fma(sin(Float64(phi1 * 0.5)), cos(Float64(phi2 * 0.5)), Float64(sin(Float64(phi2 * 0.5)) * Float64(-cos(Float64(phi1 * 0.5))))) ^ 2.0 t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(Float64(2.0 * R) * atan(sqrt(fma(t_1, Float64(cos(phi1) * Float64(t_1 * cos(phi2))), t_0)), sqrt(Float64(1.0 - Float64(Float64(Float64(cos(phi1) * cos(phi2)) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)) + t_0))))) end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * (-N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$1 * N[(N[Cos[phi1], $MachinePrecision] * N[(t$95$1 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := {\left(\mathsf{fma}\left(\sin \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\cos \left(\phi_1 \cdot 0.5\right)\right)\right)\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t_1, \cos \phi_1 \cdot \left(t_1 \cdot \cos \phi_2\right), t_0\right)}}{\sqrt{1 - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} + t_0\right)}}
\end{array}
\end{array}
Initial program 63.1%
Simplified63.1%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr64.2%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified64.2%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr79.6%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified79.7%
sub-neg79.7%
fma-udef79.7%
Applied egg-rr79.7%
Final simplification79.7%
NOTE: lambda1 and lambda2 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 (sin (* phi2 0.5)))
(t_2 (cos (* phi1 0.5)))
(t_3 (* (cos phi1) (* t_0 (cos phi2))))
(t_4 (sin (* phi1 0.5)))
(t_5 (cos (* phi2 0.5)))
(t_6 (pow (fma t_4 t_5 (* t_1 (- t_2))) 2.0)))
(if (<= lambda1 -7e-79)
(*
(* 2.0 R)
(atan2
(sqrt (fma t_0 t_3 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(sqrt
(log
(exp
(-
1.0
(+
(*
(* (cos phi1) (cos phi2))
(pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
t_6)))))))
(*
(* 2.0 R)
(atan2
(sqrt
(+
(pow (- (* t_4 t_5) (* t_1 t_2)) 2.0)
(* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))))
(sqrt (- 1.0 (fma t_0 t_3 t_6))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = sin((phi2 * 0.5));
double t_2 = cos((phi1 * 0.5));
double t_3 = cos(phi1) * (t_0 * cos(phi2));
double t_4 = sin((phi1 * 0.5));
double t_5 = cos((phi2 * 0.5));
double t_6 = pow(fma(t_4, t_5, (t_1 * -t_2)), 2.0);
double tmp;
if (lambda1 <= -7e-79) {
tmp = (2.0 * R) * atan2(sqrt(fma(t_0, t_3, pow(sin(((phi1 - phi2) / 2.0)), 2.0))), sqrt(log(exp((1.0 - (((cos(phi1) * cos(phi2)) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)) + t_6))))));
} else {
tmp = (2.0 * R) * atan2(sqrt((pow(((t_4 * t_5) - (t_1 * t_2)), 2.0) + (cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))))), sqrt((1.0 - fma(t_0, t_3, t_6))));
}
return tmp;
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(phi2 * 0.5)) t_2 = cos(Float64(phi1 * 0.5)) t_3 = Float64(cos(phi1) * Float64(t_0 * cos(phi2))) t_4 = sin(Float64(phi1 * 0.5)) t_5 = cos(Float64(phi2 * 0.5)) t_6 = fma(t_4, t_5, Float64(t_1 * Float64(-t_2))) ^ 2.0 tmp = 0.0 if (lambda1 <= -7e-79) tmp = Float64(Float64(2.0 * R) * atan(sqrt(fma(t_0, t_3, (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), sqrt(log(exp(Float64(1.0 - Float64(Float64(Float64(cos(phi1) * cos(phi2)) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)) + t_6))))))); else tmp = Float64(Float64(2.0 * R) * atan(sqrt(Float64((Float64(Float64(t_4 * t_5) - Float64(t_1 * t_2)) ^ 2.0) + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))), sqrt(Float64(1.0 - fma(t_0, t_3, t_6))))); end return tmp end
NOTE: lambda1 and lambda2 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[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Cos[phi1], $MachinePrecision] * N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$6 = N[Power[N[(t$95$4 * t$95$5 + N[(t$95$1 * (-t$95$2)), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[lambda1, -7e-79], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$0 * t$95$3 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Log[N[Exp[N[(1.0 - N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + t$95$6), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(N[Power[N[(N[(t$95$4 * t$95$5), $MachinePrecision] - N[(t$95$1 * t$95$2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * t$95$3 + t$95$6), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \sin \left(\phi_2 \cdot 0.5\right)\\
t_2 := \cos \left(\phi_1 \cdot 0.5\right)\\
t_3 := \cos \phi_1 \cdot \left(t_0 \cdot \cos \phi_2\right)\\
t_4 := \sin \left(\phi_1 \cdot 0.5\right)\\
t_5 := \cos \left(\phi_2 \cdot 0.5\right)\\
t_6 := {\left(\mathsf{fma}\left(t_4, t_5, t_1 \cdot \left(-t_2\right)\right)\right)}^{2}\\
\mathbf{if}\;\lambda_1 \leq -7 \cdot 10^{-79}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t_0, t_3, {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{\log \left(e^{1 - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} + t_6\right)}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{{\left(t_4 \cdot t_5 - t_1 \cdot t_2\right)}^{2} + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(t_0, t_3, t_6\right)}}\\
\end{array}
\end{array}
if lambda1 < -7.00000000000000059e-79Initial program 55.4%
Simplified55.3%
div-sub55.3%
sin-diff55.9%
div-inv55.9%
metadata-eval55.9%
div-inv55.9%
metadata-eval55.9%
div-inv55.9%
metadata-eval55.9%
div-inv55.9%
metadata-eval55.9%
Applied egg-rr55.9%
fma-neg55.9%
*-commutative55.9%
*-commutative55.9%
*-commutative55.9%
*-commutative55.9%
distribute-rgt-neg-in55.9%
*-commutative55.9%
Simplified55.9%
add-log-exp55.9%
fma-udef55.9%
Applied egg-rr55.9%
if -7.00000000000000059e-79 < lambda1 Initial program 67.6%
Simplified67.6%
div-sub67.6%
sin-diff69.0%
div-inv69.0%
metadata-eval69.0%
div-inv69.0%
metadata-eval69.0%
div-inv69.0%
metadata-eval69.0%
div-inv69.0%
metadata-eval69.0%
Applied egg-rr69.0%
fma-neg69.0%
*-commutative69.0%
*-commutative69.0%
*-commutative69.0%
*-commutative69.0%
distribute-rgt-neg-in69.0%
*-commutative69.0%
Simplified69.0%
div-sub67.6%
sin-diff69.0%
div-inv69.0%
metadata-eval69.0%
div-inv69.0%
metadata-eval69.0%
div-inv69.0%
metadata-eval69.0%
div-inv69.0%
metadata-eval69.0%
Applied egg-rr88.3%
fma-neg69.0%
*-commutative69.0%
*-commutative69.0%
*-commutative69.0%
*-commutative69.0%
distribute-rgt-neg-in69.0%
*-commutative69.0%
Simplified88.3%
Taylor expanded in lambda1 around 0 72.8%
Final simplification66.6%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* phi1 0.5)))
(t_1 (cos (* phi2 0.5)))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3 (sin (* phi2 0.5)))
(t_4 (cos (* phi1 0.5)))
(t_5 (pow (- (* t_0 t_1) (* t_3 t_4)) 2.0))
(t_6
(sqrt
(-
1.0
(fma
t_2
(* (cos phi1) (* t_2 (cos phi2)))
(pow (fma t_0 t_1 (* t_3 (- t_4))) 2.0))))))
(if (<= lambda1 -1.25e-10)
(*
(* 2.0 R)
(atan2
(sqrt
(+ t_5 (* (cos phi1) (* (cos phi2) (pow (sin (* lambda1 0.5)) 2.0)))))
t_6))
(*
(* 2.0 R)
(atan2
(sqrt
(+ t_5 (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))))
t_6)))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin((phi1 * 0.5));
double t_1 = cos((phi2 * 0.5));
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = sin((phi2 * 0.5));
double t_4 = cos((phi1 * 0.5));
double t_5 = pow(((t_0 * t_1) - (t_3 * t_4)), 2.0);
double t_6 = sqrt((1.0 - fma(t_2, (cos(phi1) * (t_2 * cos(phi2))), pow(fma(t_0, t_1, (t_3 * -t_4)), 2.0))));
double tmp;
if (lambda1 <= -1.25e-10) {
tmp = (2.0 * R) * atan2(sqrt((t_5 + (cos(phi1) * (cos(phi2) * pow(sin((lambda1 * 0.5)), 2.0))))), t_6);
} else {
tmp = (2.0 * R) * atan2(sqrt((t_5 + (cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))))), t_6);
}
return tmp;
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(phi1 * 0.5)) t_1 = cos(Float64(phi2 * 0.5)) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = sin(Float64(phi2 * 0.5)) t_4 = cos(Float64(phi1 * 0.5)) t_5 = Float64(Float64(t_0 * t_1) - Float64(t_3 * t_4)) ^ 2.0 t_6 = sqrt(Float64(1.0 - fma(t_2, Float64(cos(phi1) * Float64(t_2 * cos(phi2))), (fma(t_0, t_1, Float64(t_3 * Float64(-t_4))) ^ 2.0)))) tmp = 0.0 if (lambda1 <= -1.25e-10) tmp = Float64(Float64(2.0 * R) * atan(sqrt(Float64(t_5 + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda1 * 0.5)) ^ 2.0))))), t_6)); else tmp = Float64(Float64(2.0 * R) * atan(sqrt(Float64(t_5 + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))), t_6)); end return tmp end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Power[N[(N[(t$95$0 * t$95$1), $MachinePrecision] - N[(t$95$3 * t$95$4), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$6 = N[Sqrt[N[(1.0 - N[(t$95$2 * N[(N[Cos[phi1], $MachinePrecision] * N[(t$95$2 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(t$95$0 * t$95$1 + N[(t$95$3 * (-t$95$4)), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[lambda1, -1.25e-10], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$5 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$6], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$5 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$6], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\phi_1 \cdot 0.5\right)\\
t_1 := \cos \left(\phi_2 \cdot 0.5\right)\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := \sin \left(\phi_2 \cdot 0.5\right)\\
t_4 := \cos \left(\phi_1 \cdot 0.5\right)\\
t_5 := {\left(t_0 \cdot t_1 - t_3 \cdot t_4\right)}^{2}\\
t_6 := \sqrt{1 - \mathsf{fma}\left(t_2, \cos \phi_1 \cdot \left(t_2 \cdot \cos \phi_2\right), {\left(\mathsf{fma}\left(t_0, t_1, t_3 \cdot \left(-t_4\right)\right)\right)}^{2}\right)}\\
\mathbf{if}\;\lambda_1 \leq -1.25 \cdot 10^{-10}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_5 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_1 \cdot 0.5\right)}^{2}\right)}}{t_6}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_5 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{t_6}\\
\end{array}
\end{array}
if lambda1 < -1.25000000000000008e-10Initial program 49.6%
Simplified49.6%
div-sub49.6%
sin-diff50.2%
div-inv50.2%
metadata-eval50.2%
div-inv50.2%
metadata-eval50.2%
div-inv50.2%
metadata-eval50.2%
div-inv50.2%
metadata-eval50.2%
Applied egg-rr50.2%
fma-neg50.2%
*-commutative50.2%
*-commutative50.2%
*-commutative50.2%
*-commutative50.2%
distribute-rgt-neg-in50.2%
*-commutative50.2%
Simplified50.2%
div-sub49.6%
sin-diff50.2%
div-inv50.2%
metadata-eval50.2%
div-inv50.2%
metadata-eval50.2%
div-inv50.2%
metadata-eval50.2%
div-inv50.2%
metadata-eval50.2%
Applied egg-rr57.7%
fma-neg50.2%
*-commutative50.2%
*-commutative50.2%
*-commutative50.2%
*-commutative50.2%
distribute-rgt-neg-in50.2%
*-commutative50.2%
Simplified57.8%
Taylor expanded in lambda2 around 0 57.1%
if -1.25000000000000008e-10 < lambda1 Initial program 69.0%
Simplified69.1%
div-sub69.1%
sin-diff70.3%
div-inv70.3%
metadata-eval70.3%
div-inv70.3%
metadata-eval70.3%
div-inv70.3%
metadata-eval70.3%
div-inv70.3%
metadata-eval70.3%
Applied egg-rr70.3%
fma-neg70.3%
*-commutative70.3%
*-commutative70.3%
*-commutative70.3%
*-commutative70.3%
distribute-rgt-neg-in70.3%
*-commutative70.3%
Simplified70.3%
div-sub69.1%
sin-diff70.3%
div-inv70.3%
metadata-eval70.3%
div-inv70.3%
metadata-eval70.3%
div-inv70.3%
metadata-eval70.3%
div-inv70.3%
metadata-eval70.3%
Applied egg-rr89.2%
fma-neg70.3%
*-commutative70.3%
*-commutative70.3%
*-commutative70.3%
*-commutative70.3%
distribute-rgt-neg-in70.3%
*-commutative70.3%
Simplified89.3%
Taylor expanded in lambda1 around 0 74.6%
Final simplification69.3%
NOTE: lambda1 and lambda2 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 (sin (* phi2 0.5)))
(t_2 (cos (* phi1 0.5)))
(t_3 (sin (* phi1 0.5)))
(t_4 (cos (* phi2 0.5)))
(t_5 (pow (- (* t_3 t_4) (* t_1 t_2)) 2.0))
(t_6
(fma
t_0
(* (cos phi1) (* t_0 (cos phi2)))
(pow (fma t_3 t_4 (* t_1 (- t_2))) 2.0))))
(if (<= lambda2 3.5e-6)
(*
(* 2.0 R)
(atan2
(sqrt t_6)
(sqrt
(-
1.0
(+
t_5
(* (cos phi1) (* (cos phi2) (pow (sin (* lambda1 0.5)) 2.0))))))))
(*
(* 2.0 R)
(atan2
(sqrt
(+ t_5 (* (cos phi1) (* (cos phi2) (pow (sin (* lambda2 -0.5)) 2.0)))))
(sqrt (- 1.0 t_6)))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = sin((phi2 * 0.5));
double t_2 = cos((phi1 * 0.5));
double t_3 = sin((phi1 * 0.5));
double t_4 = cos((phi2 * 0.5));
double t_5 = pow(((t_3 * t_4) - (t_1 * t_2)), 2.0);
double t_6 = fma(t_0, (cos(phi1) * (t_0 * cos(phi2))), pow(fma(t_3, t_4, (t_1 * -t_2)), 2.0));
double tmp;
if (lambda2 <= 3.5e-6) {
tmp = (2.0 * R) * atan2(sqrt(t_6), sqrt((1.0 - (t_5 + (cos(phi1) * (cos(phi2) * pow(sin((lambda1 * 0.5)), 2.0)))))));
} else {
tmp = (2.0 * R) * atan2(sqrt((t_5 + (cos(phi1) * (cos(phi2) * pow(sin((lambda2 * -0.5)), 2.0))))), sqrt((1.0 - t_6)));
}
return tmp;
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = sin(Float64(phi2 * 0.5)) t_2 = cos(Float64(phi1 * 0.5)) t_3 = sin(Float64(phi1 * 0.5)) t_4 = cos(Float64(phi2 * 0.5)) t_5 = Float64(Float64(t_3 * t_4) - Float64(t_1 * t_2)) ^ 2.0 t_6 = fma(t_0, Float64(cos(phi1) * Float64(t_0 * cos(phi2))), (fma(t_3, t_4, Float64(t_1 * Float64(-t_2))) ^ 2.0)) tmp = 0.0 if (lambda2 <= 3.5e-6) tmp = Float64(Float64(2.0 * R) * atan(sqrt(t_6), sqrt(Float64(1.0 - Float64(t_5 + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda1 * 0.5)) ^ 2.0)))))))); else tmp = Float64(Float64(2.0 * R) * atan(sqrt(Float64(t_5 + Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(lambda2 * -0.5)) ^ 2.0))))), sqrt(Float64(1.0 - t_6)))); end return tmp end
NOTE: lambda1 and lambda2 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[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Power[N[(N[(t$95$3 * t$95$4), $MachinePrecision] - N[(t$95$1 * t$95$2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$6 = N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(t$95$3 * t$95$4 + N[(t$95$1 * (-t$95$2)), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, 3.5e-6], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[t$95$6], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$5 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$5 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$6), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \sin \left(\phi_2 \cdot 0.5\right)\\
t_2 := \cos \left(\phi_1 \cdot 0.5\right)\\
t_3 := \sin \left(\phi_1 \cdot 0.5\right)\\
t_4 := \cos \left(\phi_2 \cdot 0.5\right)\\
t_5 := {\left(t_3 \cdot t_4 - t_1 \cdot t_2\right)}^{2}\\
t_6 := \mathsf{fma}\left(t_0, \cos \phi_1 \cdot \left(t_0 \cdot \cos \phi_2\right), {\left(\mathsf{fma}\left(t_3, t_4, t_1 \cdot \left(-t_2\right)\right)\right)}^{2}\right)\\
\mathbf{if}\;\lambda_2 \leq 3.5 \cdot 10^{-6}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_6}}{\sqrt{1 - \left(t_5 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_1 \cdot 0.5\right)}^{2}\right)\right)}}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_5 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\lambda_2 \cdot -0.5\right)}^{2}\right)}}{\sqrt{1 - t_6}}\\
\end{array}
\end{array}
if lambda2 < 3.49999999999999995e-6Initial program 66.8%
Simplified66.8%
div-sub66.8%
sin-diff67.8%
div-inv67.8%
metadata-eval67.8%
div-inv67.8%
metadata-eval67.8%
div-inv67.8%
metadata-eval67.8%
div-inv67.8%
metadata-eval67.8%
Applied egg-rr67.8%
fma-neg67.8%
*-commutative67.8%
*-commutative67.8%
*-commutative67.8%
*-commutative67.8%
distribute-rgt-neg-in67.8%
*-commutative67.8%
Simplified67.8%
div-sub66.8%
sin-diff67.8%
div-inv67.8%
metadata-eval67.8%
div-inv67.8%
metadata-eval67.8%
div-inv67.8%
metadata-eval67.8%
div-inv67.8%
metadata-eval67.8%
Applied egg-rr85.0%
fma-neg67.8%
*-commutative67.8%
*-commutative67.8%
*-commutative67.8%
*-commutative67.8%
distribute-rgt-neg-in67.8%
*-commutative67.8%
Simplified85.0%
Taylor expanded in lambda2 around 0 70.6%
if 3.49999999999999995e-6 < lambda2 Initial program 52.7%
Simplified52.7%
div-sub52.7%
sin-diff53.9%
div-inv53.9%
metadata-eval53.9%
div-inv53.9%
metadata-eval53.9%
div-inv53.9%
metadata-eval53.9%
div-inv53.9%
metadata-eval53.9%
Applied egg-rr53.9%
fma-neg53.9%
*-commutative53.9%
*-commutative53.9%
*-commutative53.9%
*-commutative53.9%
distribute-rgt-neg-in53.9%
*-commutative53.9%
Simplified53.9%
div-sub52.7%
sin-diff53.9%
div-inv53.9%
metadata-eval53.9%
div-inv53.9%
metadata-eval53.9%
div-inv53.9%
metadata-eval53.9%
div-inv53.9%
metadata-eval53.9%
Applied egg-rr64.4%
fma-neg53.9%
*-commutative53.9%
*-commutative53.9%
*-commutative53.9%
*-commutative53.9%
distribute-rgt-neg-in53.9%
*-commutative53.9%
Simplified64.4%
Taylor expanded in lambda1 around 0 64.2%
Final simplification68.9%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (* phi1 0.5)))
(t_1 (sin (* phi1 0.5)))
(t_2 (sin (* phi2 0.5)))
(t_3 (sin (/ (- lambda1 lambda2) 2.0)))
(t_4 (cos (* phi2 0.5))))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
t_3
(* (cos phi1) (* t_3 (cos phi2)))
(pow (fma t_1 t_4 (* t_2 (- t_0))) 2.0)))
(sqrt
(-
1.0
(+
(*
(cos phi1)
(* (cos phi2) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)))
(pow (- (* t_1 t_4) (* t_2 t_0)) 2.0))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((phi1 * 0.5));
double t_1 = sin((phi1 * 0.5));
double t_2 = sin((phi2 * 0.5));
double t_3 = sin(((lambda1 - lambda2) / 2.0));
double t_4 = cos((phi2 * 0.5));
return (2.0 * R) * atan2(sqrt(fma(t_3, (cos(phi1) * (t_3 * cos(phi2))), pow(fma(t_1, t_4, (t_2 * -t_0)), 2.0))), sqrt((1.0 - ((cos(phi1) * (cos(phi2) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0))) + pow(((t_1 * t_4) - (t_2 * t_0)), 2.0)))));
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(phi1 * 0.5)) t_1 = sin(Float64(phi1 * 0.5)) t_2 = sin(Float64(phi2 * 0.5)) t_3 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_4 = cos(Float64(phi2 * 0.5)) return Float64(Float64(2.0 * R) * atan(sqrt(fma(t_3, Float64(cos(phi1) * Float64(t_3 * cos(phi2))), (fma(t_1, t_4, Float64(t_2 * Float64(-t_0))) ^ 2.0))), sqrt(Float64(1.0 - Float64(Float64(cos(phi1) * Float64(cos(phi2) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0))) + (Float64(Float64(t_1 * t_4) - Float64(t_2 * t_0)) ^ 2.0)))))) end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$3 * N[(N[Cos[phi1], $MachinePrecision] * N[(t$95$3 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(t$95$1 * t$95$4 + N[(t$95$2 * (-t$95$0)), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(t$95$1 * t$95$4), $MachinePrecision] - N[(t$95$2 * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \cos \left(\phi_1 \cdot 0.5\right)\\
t_1 := \sin \left(\phi_1 \cdot 0.5\right)\\
t_2 := \sin \left(\phi_2 \cdot 0.5\right)\\
t_3 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_4 := \cos \left(\phi_2 \cdot 0.5\right)\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t_3, \cos \phi_1 \cdot \left(t_3 \cdot \cos \phi_2\right), {\left(\mathsf{fma}\left(t_1, t_4, t_2 \cdot \left(-t_0\right)\right)\right)}^{2}\right)}}{\sqrt{1 - \left(\cos \phi_1 \cdot \left(\cos \phi_2 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\right) + {\left(t_1 \cdot t_4 - t_2 \cdot t_0\right)}^{2}\right)}}
\end{array}
\end{array}
Initial program 63.1%
Simplified63.1%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr64.2%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified64.2%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr79.6%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified79.7%
Taylor expanded in lambda1 around inf 79.7%
Final simplification79.7%
NOTE: lambda1 and lambda2 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))))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
t_0
(* (cos phi1) (* t_0 (cos phi2)))
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(sqrt
(log
(exp
(-
1.0
(+
(*
(* (cos phi1) (cos phi2))
(pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(pow
(fma
(sin (* phi1 0.5))
(cos (* phi2 0.5))
(* (sin (* phi2 0.5)) (- (cos (* phi1 0.5)))))
2.0))))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
return (2.0 * R) * atan2(sqrt(fma(t_0, (cos(phi1) * (t_0 * cos(phi2))), pow(sin(((phi1 - phi2) / 2.0)), 2.0))), sqrt(log(exp((1.0 - (((cos(phi1) * cos(phi2)) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)) + pow(fma(sin((phi1 * 0.5)), cos((phi2 * 0.5)), (sin((phi2 * 0.5)) * -cos((phi1 * 0.5)))), 2.0)))))));
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(Float64(2.0 * R) * atan(sqrt(fma(t_0, Float64(cos(phi1) * Float64(t_0 * cos(phi2))), (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), sqrt(log(exp(Float64(1.0 - Float64(Float64(Float64(cos(phi1) * cos(phi2)) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)) + (fma(sin(Float64(phi1 * 0.5)), cos(Float64(phi2 * 0.5)), Float64(sin(Float64(phi2 * 0.5)) * Float64(-cos(Float64(phi1 * 0.5))))) ^ 2.0)))))))) end
NOTE: lambda1 and lambda2 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[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Log[N[Exp[N[(1.0 - N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * (-N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t_0, \cos \phi_1 \cdot \left(t_0 \cdot \cos \phi_2\right), {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{\log \left(e^{1 - \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} + {\left(\mathsf{fma}\left(\sin \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\cos \left(\phi_1 \cdot 0.5\right)\right)\right)\right)}^{2}\right)}\right)}}
\end{array}
\end{array}
Initial program 63.1%
Simplified63.1%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr64.2%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified64.2%
add-log-exp64.2%
fma-udef64.2%
Applied egg-rr64.2%
Final simplification64.2%
NOTE: lambda1 and lambda2 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) (* t_0 (cos phi2)))))
(*
(* 2.0 R)
(atan2
(sqrt (fma t_0 t_1 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0)))
(sqrt
(-
1.0
(fma
t_0
t_1
(pow
(fma
(sin (* phi1 0.5))
(cos (* phi2 0.5))
(* (sin (* phi2 0.5)) (- (cos (* phi1 0.5)))))
2.0))))))))assert(lambda1 < lambda2);
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) * (t_0 * cos(phi2));
return (2.0 * R) * atan2(sqrt(fma(t_0, t_1, pow(sin(((phi1 - phi2) / 2.0)), 2.0))), sqrt((1.0 - fma(t_0, t_1, pow(fma(sin((phi1 * 0.5)), cos((phi2 * 0.5)), (sin((phi2 * 0.5)) * -cos((phi1 * 0.5)))), 2.0)))));
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(cos(phi1) * Float64(t_0 * cos(phi2))) return Float64(Float64(2.0 * R) * atan(sqrt(fma(t_0, t_1, (sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0))), sqrt(Float64(1.0 - fma(t_0, t_1, (fma(sin(Float64(phi1 * 0.5)), cos(Float64(phi2 * 0.5)), Float64(sin(Float64(phi2 * 0.5)) * Float64(-cos(Float64(phi1 * 0.5))))) ^ 2.0)))))) end
NOTE: lambda1 and lambda2 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[Cos[phi1], $MachinePrecision] * N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(t$95$0 * t$95$1 + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(t$95$0 * t$95$1 + N[Power[N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * (-N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_1 \cdot \left(t_0 \cdot \cos \phi_2\right)\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t_0, t_1, {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\right)}}{\sqrt{1 - \mathsf{fma}\left(t_0, t_1, {\left(\mathsf{fma}\left(\sin \left(\phi_1 \cdot 0.5\right), \cos \left(\phi_2 \cdot 0.5\right), \sin \left(\phi_2 \cdot 0.5\right) \cdot \left(-\cos \left(\phi_1 \cdot 0.5\right)\right)\right)\right)}^{2}\right)}}
\end{array}
\end{array}
Initial program 63.1%
Simplified63.1%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr64.2%
fma-neg64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
*-commutative64.2%
distribute-rgt-neg-in64.2%
*-commutative64.2%
Simplified64.2%
Final simplification64.2%
NOTE: lambda1 and lambda2 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 (* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) t_1))
(sqrt
(-
1.0
(+
(pow
(-
(* (sin (* phi1 0.5)) (cos (* phi2 0.5)))
(* (sin (* phi2 0.5)) (cos (* phi1 0.5))))
2.0)
t_1))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + t_1)), sqrt((1.0 - (pow(((sin((phi1 * 0.5)) * cos((phi2 * 0.5))) - (sin((phi2 * 0.5)) * cos((phi1 * 0.5)))), 2.0) + t_1)))));
}
NOTE: lambda1 and lambda2 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
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)))
code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + t_1)), sqrt((1.0d0 - ((((sin((phi1 * 0.5d0)) * cos((phi2 * 0.5d0))) - (sin((phi2 * 0.5d0)) * cos((phi1 * 0.5d0)))) ** 2.0d0) + t_1)))))
end function
assert lambda1 < lambda2;
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 = t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)));
return 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((phi1 * 0.5)) * Math.cos((phi2 * 0.5))) - (Math.sin((phi2 * 0.5)) * Math.cos((phi1 * 0.5)))), 2.0) + t_1)))));
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2))) return 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((phi1 * 0.5)) * math.cos((phi2 * 0.5))) - (math.sin((phi2 * 0.5)) * math.cos((phi1 * 0.5)))), 2.0) + t_1)))))
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt(Float64(1.0 - Float64((Float64(Float64(sin(Float64(phi1 * 0.5)) * cos(Float64(phi2 * 0.5))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(phi1 * 0.5)))) ^ 2.0) + t_1)))))) end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
t_1 = t_0 * (t_0 * (cos(phi1) * cos(phi2)));
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + t_1)), sqrt((1.0 - ((((sin((phi1 * 0.5)) * cos((phi2 * 0.5))) - (sin((phi2 * 0.5)) * cos((phi1 * 0.5)))) ^ 2.0) + t_1)))));
end
NOTE: lambda1 and lambda2 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[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $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] + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1}}{\sqrt{1 - \left({\left(\sin \left(\phi_1 \cdot 0.5\right) \cdot \cos \left(\phi_2 \cdot 0.5\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(\phi_1 \cdot 0.5\right)\right)}^{2} + t_1\right)}}\right)
\end{array}
\end{array}
Initial program 63.1%
div-sub63.1%
sin-diff64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
div-inv64.2%
metadata-eval64.2%
Applied egg-rr64.2%
Final simplification64.2%
NOTE: lambda1 and lambda2 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))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (* t_0 t_1))))
(sqrt
(pow
(pow
(-
1.0
(fma
t_1
(- 0.5 (* 0.5 (cos (- lambda1 lambda2))))
(pow (sin (* 0.5 (- phi1 phi2))) 2.0)))
3.0)
0.3333333333333333)))))))assert(lambda1 < lambda2);
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);
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * t_1)))), sqrt(pow(pow((1.0 - fma(t_1, (0.5 - (0.5 * cos((lambda1 - lambda2)))), pow(sin((0.5 * (phi1 - phi2))), 2.0))), 3.0), 0.3333333333333333))));
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(cos(phi1) * cos(phi2)) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * t_1)))), sqrt(((Float64(1.0 - fma(t_1, Float64(0.5 - Float64(0.5 * cos(Float64(lambda1 - lambda2)))), (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))) ^ 3.0) ^ 0.3333333333333333))))) end
NOTE: lambda1 and lambda2 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[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $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$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[N[Power[N[(1.0 - N[(t$95$1 * N[(0.5 - N[(0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot t_1\right)}}{\sqrt{{\left({\left(1 - \mathsf{fma}\left(t_1, 0.5 - 0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)\right)}^{3}\right)}^{0.3333333333333333}}}\right)
\end{array}
\end{array}
Initial program 63.1%
add-cbrt-cube63.1%
pow1/363.1%
Applied egg-rr63.2%
Final simplification63.2%
NOTE: lambda1 and lambda2 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))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (* t_0 t_1))))
(sqrt
(exp
(log1p
(-
(fma
t_1
(- 0.5 (* 0.5 (cos (- lambda1 lambda2))))
(pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))))))assert(lambda1 < lambda2);
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);
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * t_1)))), sqrt(exp(log1p(-fma(t_1, (0.5 - (0.5 * cos((lambda1 - lambda2)))), pow(sin((0.5 * (phi1 - phi2))), 2.0)))))));
}
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(cos(phi1) * cos(phi2)) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * t_1)))), sqrt(exp(log1p(Float64(-fma(t_1, Float64(0.5 - Float64(0.5 * cos(Float64(lambda1 - lambda2)))), (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0))))))))) end
NOTE: lambda1 and lambda2 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[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $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$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Exp[N[Log[1 + (-N[(t$95$1 * N[(0.5 - N[(0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot t_1\right)}}{\sqrt{e^{\mathsf{log1p}\left(-\mathsf{fma}\left(t_1, 0.5 - 0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right), {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right)\right)}}}\right)
\end{array}
\end{array}
Initial program 63.1%
add-exp-log63.1%
sub-neg63.1%
log1p-def63.1%
Applied egg-rr63.2%
Final simplification63.2%
NOTE: lambda1 and lambda2 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))))
(*
R
(*
2.0
(atan2
(sqrt (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* t_0 (* t_0 t_1))))
(sqrt
(+
(- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0))
(* t_1 (- (* 0.5 (cos (- lambda1 lambda2))) 0.5)))))))))assert(lambda1 < lambda2);
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);
return R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * t_1)))), sqrt(((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)) + (t_1 * ((0.5 * cos((lambda1 - lambda2))) - 0.5))))));
}
NOTE: lambda1 and lambda2 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
t_0 = sin(((lambda1 - lambda2) / 2.0d0))
t_1 = cos(phi1) * cos(phi2)
code = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_0 * (t_0 * t_1)))), sqrt(((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)) + (t_1 * ((0.5d0 * cos((lambda1 - lambda2))) - 0.5d0))))))
end function
assert lambda1 < lambda2;
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);
return R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * t_1)))), Math.sqrt(((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)) + (t_1 * ((0.5 * Math.cos((lambda1 - lambda2))) - 0.5))))));
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) t_1 = math.cos(phi1) * math.cos(phi2) return R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_0 * (t_0 * t_1)))), math.sqrt(((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0)) + (t_1 * ((0.5 * math.cos((lambda1 - lambda2))) - 0.5))))))
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(cos(phi1) * cos(phi2)) return Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_0 * Float64(t_0 * t_1)))), sqrt(Float64(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)) + Float64(t_1 * Float64(Float64(0.5 * cos(Float64(lambda1 - lambda2))) - 0.5))))))) end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
t_1 = cos(phi1) * cos(phi2);
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_0 * (t_0 * t_1)))), sqrt(((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)) + (t_1 * ((0.5 * cos((lambda1 - lambda2))) - 0.5))))));
end
NOTE: lambda1 and lambda2 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[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $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$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(N[(0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_0 \cdot \left(t_0 \cdot t_1\right)}}{\sqrt{\left(1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}\right) + t_1 \cdot \left(0.5 \cdot \cos \left(\lambda_1 - \lambda_2\right) - 0.5\right)}}\right)
\end{array}
\end{array}
Initial program 63.1%
associate--r+63.1%
sub-neg63.1%
div-inv63.1%
metadata-eval63.1%
associate-*l*63.1%
Applied egg-rr63.2%
Final simplification63.2%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(t_1 (+ (* (cos phi1) t_0) (pow (sin (* phi1 0.5)) 2.0)))
(t_2 (sin (/ (- lambda1 lambda2) 2.0))))
(if (or (<= phi1 -4.5e-5) (not (<= phi1 7.5e-11)))
(* (* 2.0 R) (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))
(*
R
(*
2.0
(atan2
(sqrt (+ (* (cos phi2) t_0) (pow (sin (* phi2 -0.5)) 2.0)))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* t_2 (* t_2 (* (cos phi1) (cos phi2)))))))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = (cos(phi1) * t_0) + pow(sin((phi1 * 0.5)), 2.0);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi1 <= -4.5e-5) || !(phi1 <= 7.5e-11)) {
tmp = (2.0 * R) * atan2(sqrt(t_1), sqrt((1.0 - t_1)));
} else {
tmp = R * (2.0 * atan2(sqrt(((cos(phi2) * t_0) + pow(sin((phi2 * -0.5)), 2.0))), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_2 * (t_2 * (cos(phi1) * cos(phi2)))))))));
}
return tmp;
}
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0
t_1 = (cos(phi1) * t_0) + (sin((phi1 * 0.5d0)) ** 2.0d0)
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
if ((phi1 <= (-4.5d-5)) .or. (.not. (phi1 <= 7.5d-11))) then
tmp = (2.0d0 * r) * atan2(sqrt(t_1), sqrt((1.0d0 - t_1)))
else
tmp = r * (2.0d0 * atan2(sqrt(((cos(phi2) * t_0) + (sin((phi2 * (-0.5d0))) ** 2.0d0))), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_2 * (t_2 * (cos(phi1) * cos(phi2)))))))))
end if
code = tmp
end function
assert lambda1 < lambda2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = (Math.cos(phi1) * t_0) + Math.pow(Math.sin((phi1 * 0.5)), 2.0);
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi1 <= -4.5e-5) || !(phi1 <= 7.5e-11)) {
tmp = (2.0 * R) * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1)));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt(((Math.cos(phi2) * t_0) + Math.pow(Math.sin((phi2 * -0.5)), 2.0))), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_2 * (t_2 * (Math.cos(phi1) * Math.cos(phi2)))))))));
}
return tmp;
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0) t_1 = (math.cos(phi1) * t_0) + math.pow(math.sin((phi1 * 0.5)), 2.0) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) tmp = 0 if (phi1 <= -4.5e-5) or not (phi1 <= 7.5e-11): tmp = (2.0 * R) * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))) else: tmp = R * (2.0 * math.atan2(math.sqrt(((math.cos(phi2) * t_0) + math.pow(math.sin((phi2 * -0.5)), 2.0))), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_2 * (t_2 * (math.cos(phi1) * math.cos(phi2))))))))) return tmp
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 t_1 = Float64(Float64(cos(phi1) * t_0) + (sin(Float64(phi1 * 0.5)) ^ 2.0)) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if ((phi1 <= -4.5e-5) || !(phi1 <= 7.5e-11)) tmp = Float64(Float64(2.0 * R) * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1)))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64(Float64(cos(phi2) * t_0) + (sin(Float64(phi2 * -0.5)) ^ 2.0))), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_2 * Float64(t_2 * Float64(cos(phi1) * cos(phi2)))))))))); end return tmp end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) * 0.5)) ^ 2.0;
t_1 = (cos(phi1) * t_0) + (sin((phi1 * 0.5)) ^ 2.0);
t_2 = sin(((lambda1 - lambda2) / 2.0));
tmp = 0.0;
if ((phi1 <= -4.5e-5) || ~((phi1 <= 7.5e-11)))
tmp = (2.0 * R) * atan2(sqrt(t_1), sqrt((1.0 - t_1)));
else
tmp = R * (2.0 * atan2(sqrt(((cos(phi2) * t_0) + (sin((phi2 * -0.5)) ^ 2.0))), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_2 * (t_2 * (cos(phi1) * cos(phi2)))))))));
end
tmp_2 = tmp;
end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[phi1, -4.5e-5], N[Not[LessEqual[phi1, 7.5e-11]], $MachinePrecision]], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$2 * N[(t$95$2 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \cos \phi_1 \cdot t_0 + {\sin \left(\phi_1 \cdot 0.5\right)}^{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_1 \leq -4.5 \cdot 10^{-5} \lor \neg \left(\phi_1 \leq 7.5 \cdot 10^{-11}\right):\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{\cos \phi_2 \cdot t_0 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}}}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_2 \cdot \left(t_2 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)}}\right)\\
\end{array}
\end{array}
if phi1 < -4.50000000000000028e-5 or 7.5e-11 < phi1 Initial program 49.8%
Simplified49.7%
div-sub49.7%
sin-diff51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
Applied egg-rr51.9%
fma-neg51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
distribute-rgt-neg-in51.9%
*-commutative51.9%
Simplified51.9%
div-sub49.7%
sin-diff51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
Applied egg-rr82.3%
fma-neg51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
distribute-rgt-neg-in51.9%
*-commutative51.9%
Simplified82.4%
Taylor expanded in phi2 around 0 52.8%
Taylor expanded in phi2 around 0 52.2%
if -4.50000000000000028e-5 < phi1 < 7.5e-11Initial program 76.5%
Taylor expanded in phi1 around 0 76.5%
associate-+r+76.5%
associate-*r*76.5%
distribute-rgt1-in76.5%
unpow276.5%
*-commutative76.5%
*-commutative76.5%
associate-*l*76.5%
*-commutative76.5%
Simplified76.5%
Taylor expanded in phi1 around 0 75.8%
Final simplification64.0%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(t_1 (+ (* (cos phi1) t_0) (pow (sin (* phi1 0.5)) 2.0)))
(t_2 (sin (/ (- lambda1 lambda2) 2.0))))
(if (or (<= phi1 -8.6e-5) (not (<= phi1 1.7e-10)))
(* (* 2.0 R) (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* t_2 (* t_2 (* (cos phi1) (cos phi2))))))
(sqrt
(- 1.0 (+ (* (cos phi2) t_0) (pow (sin (* phi2 -0.5)) 2.0))))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = pow(sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = (cos(phi1) * t_0) + pow(sin((phi1 * 0.5)), 2.0);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi1 <= -8.6e-5) || !(phi1 <= 1.7e-10)) {
tmp = (2.0 * R) * atan2(sqrt(t_1), sqrt((1.0 - t_1)));
} else {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_2 * (t_2 * (cos(phi1) * cos(phi2)))))), sqrt((1.0 - ((cos(phi2) * t_0) + pow(sin((phi2 * -0.5)), 2.0))))));
}
return tmp;
}
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0
t_1 = (cos(phi1) * t_0) + (sin((phi1 * 0.5d0)) ** 2.0d0)
t_2 = sin(((lambda1 - lambda2) / 2.0d0))
if ((phi1 <= (-8.6d-5)) .or. (.not. (phi1 <= 1.7d-10))) then
tmp = (2.0d0 * r) * atan2(sqrt(t_1), sqrt((1.0d0 - t_1)))
else
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_2 * (t_2 * (cos(phi1) * cos(phi2)))))), sqrt((1.0d0 - ((cos(phi2) * t_0) + (sin((phi2 * (-0.5d0))) ** 2.0d0))))))
end if
code = tmp
end function
assert lambda1 < lambda2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0);
double t_1 = (Math.cos(phi1) * t_0) + Math.pow(Math.sin((phi1 * 0.5)), 2.0);
double t_2 = Math.sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi1 <= -8.6e-5) || !(phi1 <= 1.7e-10)) {
tmp = (2.0 * R) * Math.atan2(Math.sqrt(t_1), Math.sqrt((1.0 - t_1)));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_2 * (t_2 * (Math.cos(phi1) * Math.cos(phi2)))))), Math.sqrt((1.0 - ((Math.cos(phi2) * t_0) + Math.pow(Math.sin((phi2 * -0.5)), 2.0))))));
}
return tmp;
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0) t_1 = (math.cos(phi1) * t_0) + math.pow(math.sin((phi1 * 0.5)), 2.0) t_2 = math.sin(((lambda1 - lambda2) / 2.0)) tmp = 0 if (phi1 <= -8.6e-5) or not (phi1 <= 1.7e-10): tmp = (2.0 * R) * math.atan2(math.sqrt(t_1), math.sqrt((1.0 - t_1))) else: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_2 * (t_2 * (math.cos(phi1) * math.cos(phi2)))))), math.sqrt((1.0 - ((math.cos(phi2) * t_0) + math.pow(math.sin((phi2 * -0.5)), 2.0)))))) return tmp
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0 t_1 = Float64(Float64(cos(phi1) * t_0) + (sin(Float64(phi1 * 0.5)) ^ 2.0)) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if ((phi1 <= -8.6e-5) || !(phi1 <= 1.7e-10)) tmp = Float64(Float64(2.0 * R) * atan(sqrt(t_1), sqrt(Float64(1.0 - t_1)))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_2 * Float64(t_2 * Float64(cos(phi1) * cos(phi2)))))), sqrt(Float64(1.0 - Float64(Float64(cos(phi2) * t_0) + (sin(Float64(phi2 * -0.5)) ^ 2.0))))))); end return tmp end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) * 0.5)) ^ 2.0;
t_1 = (cos(phi1) * t_0) + (sin((phi1 * 0.5)) ^ 2.0);
t_2 = sin(((lambda1 - lambda2) / 2.0));
tmp = 0.0;
if ((phi1 <= -8.6e-5) || ~((phi1 <= 1.7e-10)))
tmp = (2.0 * R) * atan2(sqrt(t_1), sqrt((1.0 - t_1)));
else
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_2 * (t_2 * (cos(phi1) * cos(phi2)))))), sqrt((1.0 - ((cos(phi2) * t_0) + (sin((phi2 * -0.5)) ^ 2.0))))));
end
tmp_2 = tmp;
end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[phi1, -8.6e-5], N[Not[LessEqual[phi1, 1.7e-10]], $MachinePrecision]], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $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$2 * N[(t$95$2 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}\\
t_1 := \cos \phi_1 \cdot t_0 + {\sin \left(\phi_1 \cdot 0.5\right)}^{2}\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_1 \leq -8.6 \cdot 10^{-5} \lor \neg \left(\phi_1 \leq 1.7 \cdot 10^{-10}\right):\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_1}}{\sqrt{1 - t_1}}\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_2 \cdot \left(t_2 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{1 - \left(\cos \phi_2 \cdot t_0 + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}}\right)\\
\end{array}
\end{array}
if phi1 < -8.6000000000000003e-5 or 1.70000000000000007e-10 < phi1 Initial program 49.8%
Simplified49.7%
div-sub49.7%
sin-diff51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
Applied egg-rr51.9%
fma-neg51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
distribute-rgt-neg-in51.9%
*-commutative51.9%
Simplified51.9%
div-sub49.7%
sin-diff51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
div-inv51.9%
metadata-eval51.9%
Applied egg-rr82.3%
fma-neg51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
*-commutative51.9%
distribute-rgt-neg-in51.9%
*-commutative51.9%
Simplified82.4%
Taylor expanded in phi2 around 0 52.8%
Taylor expanded in phi2 around 0 52.2%
if -8.6000000000000003e-5 < phi1 < 1.70000000000000007e-10Initial program 76.5%
Taylor expanded in phi1 around 0 76.5%
Final simplification64.4%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(+
(* (cos phi1) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(pow (sin (* phi1 0.5)) 2.0)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0))))
(if (or (<= phi2 -740.0) (not (<= phi2 1.4e+27)))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* t_1 (* t_1 (* (cos phi1) (cos phi2))))))
(sqrt
(-
(pow (cos (* phi2 0.5)) 2.0)
(* (cos phi2) (pow (sin (* lambda1 0.5)) 2.0)))))))
(* (* 2.0 R) (atan2 (sqrt t_0) (sqrt (- 1.0 t_0)))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (cos(phi1) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)) + pow(sin((phi1 * 0.5)), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi2 <= -740.0) || !(phi2 <= 1.4e+27)) {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2)))))), sqrt((pow(cos((phi2 * 0.5)), 2.0) - (cos(phi2) * pow(sin((lambda1 * 0.5)), 2.0))))));
} else {
tmp = (2.0 * R) * atan2(sqrt(t_0), sqrt((1.0 - t_0)));
}
return tmp;
}
NOTE: lambda1 and lambda2 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 = (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)) + (sin((phi1 * 0.5d0)) ** 2.0d0)
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
if ((phi2 <= (-740.0d0)) .or. (.not. (phi2 <= 1.4d+27))) then
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2)))))), sqrt(((cos((phi2 * 0.5d0)) ** 2.0d0) - (cos(phi2) * (sin((lambda1 * 0.5d0)) ** 2.0d0))))))
else
tmp = (2.0d0 * r) * atan2(sqrt(t_0), sqrt((1.0d0 - t_0)))
end if
code = tmp
end function
assert lambda1 < lambda2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (Math.cos(phi1) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)) + Math.pow(Math.sin((phi1 * 0.5)), 2.0);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((phi2 <= -740.0) || !(phi2 <= 1.4e+27)) {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (Math.cos(phi1) * Math.cos(phi2)))))), Math.sqrt((Math.pow(Math.cos((phi2 * 0.5)), 2.0) - (Math.cos(phi2) * Math.pow(Math.sin((lambda1 * 0.5)), 2.0))))));
} else {
tmp = (2.0 * R) * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0)));
}
return tmp;
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = (math.cos(phi1) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)) + math.pow(math.sin((phi1 * 0.5)), 2.0) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) tmp = 0 if (phi2 <= -740.0) or not (phi2 <= 1.4e+27): tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (math.cos(phi1) * math.cos(phi2)))))), math.sqrt((math.pow(math.cos((phi2 * 0.5)), 2.0) - (math.cos(phi2) * math.pow(math.sin((lambda1 * 0.5)), 2.0)))))) else: tmp = (2.0 * R) * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0))) return tmp
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(cos(phi1) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)) + (sin(Float64(phi1 * 0.5)) ^ 2.0)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if ((phi2 <= -740.0) || !(phi2 <= 1.4e+27)) tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_1 * Float64(t_1 * Float64(cos(phi1) * cos(phi2)))))), sqrt(Float64((cos(Float64(phi2 * 0.5)) ^ 2.0) - Float64(cos(phi2) * (sin(Float64(lambda1 * 0.5)) ^ 2.0))))))); else tmp = Float64(Float64(2.0 * R) * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0)))); end return tmp end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)) + (sin((phi1 * 0.5)) ^ 2.0);
t_1 = sin(((lambda1 - lambda2) / 2.0));
tmp = 0.0;
if ((phi2 <= -740.0) || ~((phi2 <= 1.4e+27)))
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2)))))), sqrt(((cos((phi2 * 0.5)) ^ 2.0) - (cos(phi2) * (sin((lambda1 * 0.5)) ^ 2.0))))));
else
tmp = (2.0 * R) * atan2(sqrt(t_0), sqrt((1.0 - t_0)));
end
tmp_2 = tmp;
end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[phi2, -740.0], N[Not[LessEqual[phi2, 1.4e+27]], $MachinePrecision]], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[(t$95$1 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $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] * N[Power[N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} + {\sin \left(\phi_1 \cdot 0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_2 \leq -740 \lor \neg \left(\phi_2 \leq 1.4 \cdot 10^{+27}\right):\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{{\cos \left(\phi_2 \cdot 0.5\right)}^{2} - \cos \phi_2 \cdot {\sin \left(\lambda_1 \cdot 0.5\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_0}}{\sqrt{1 - t_0}}\\
\end{array}
\end{array}
if phi2 < -740 or 1.4e27 < phi2 Initial program 45.8%
Taylor expanded in lambda2 around 0 36.0%
Taylor expanded in phi1 around 0 35.4%
Taylor expanded in lambda2 around 0 35.9%
Taylor expanded in phi1 around 0 36.7%
+-commutative36.7%
associate--r+36.7%
Simplified36.8%
if -740 < phi2 < 1.4e27Initial program 77.7%
Simplified77.7%
div-sub77.7%
sin-diff77.7%
div-inv77.7%
metadata-eval77.7%
div-inv77.7%
metadata-eval77.7%
div-inv77.7%
metadata-eval77.7%
div-inv77.7%
metadata-eval77.7%
Applied egg-rr77.7%
fma-neg77.7%
*-commutative77.7%
*-commutative77.7%
*-commutative77.7%
*-commutative77.7%
distribute-rgt-neg-in77.7%
*-commutative77.7%
Simplified77.7%
div-sub77.7%
sin-diff77.7%
div-inv77.7%
metadata-eval77.7%
div-inv77.7%
metadata-eval77.7%
div-inv77.7%
metadata-eval77.7%
div-inv77.7%
metadata-eval77.7%
Applied egg-rr80.1%
fma-neg77.7%
*-commutative77.7%
*-commutative77.7%
*-commutative77.7%
*-commutative77.7%
distribute-rgt-neg-in77.7%
*-commutative77.7%
Simplified80.1%
Taylor expanded in phi2 around 0 76.2%
Taylor expanded in phi2 around 0 76.1%
Final simplification58.1%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(+
(* (cos phi1) (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))
(pow (sin (* phi1 0.5)) 2.0)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0))))
(if (<= (- lambda1 lambda2) -1.0)
(* (* 2.0 R) (atan2 (sqrt t_0) (sqrt (- 1.0 t_0))))
(*
R
(*
2.0
(atan2
(sqrt
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* t_1 (* t_1 (* (cos phi1) (cos phi2))))))
(sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (cos(phi1) * pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)) + pow(sin((phi1 * 0.5)), 2.0);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((lambda1 - lambda2) <= -1.0) {
tmp = (2.0 * R) * atan2(sqrt(t_0), sqrt((1.0 - t_0)));
} else {
tmp = R * (2.0 * atan2(sqrt((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2)))))), sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
}
return tmp;
}
NOTE: lambda1 and lambda2 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 = (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)) + (sin((phi1 * 0.5d0)) ** 2.0d0)
t_1 = sin(((lambda1 - lambda2) / 2.0d0))
if ((lambda1 - lambda2) <= (-1.0d0)) then
tmp = (2.0d0 * r) * atan2(sqrt(t_0), sqrt((1.0d0 - t_0)))
else
tmp = r * (2.0d0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2)))))), sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
end if
code = tmp
end function
assert lambda1 < lambda2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (Math.cos(phi1) * Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)) + Math.pow(Math.sin((phi1 * 0.5)), 2.0);
double t_1 = Math.sin(((lambda1 - lambda2) / 2.0));
double tmp;
if ((lambda1 - lambda2) <= -1.0) {
tmp = (2.0 * R) * Math.atan2(Math.sqrt(t_0), Math.sqrt((1.0 - t_0)));
} else {
tmp = R * (2.0 * Math.atan2(Math.sqrt((Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (Math.cos(phi1) * Math.cos(phi2)))))), Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
}
return tmp;
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = (math.cos(phi1) * math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0)) + math.pow(math.sin((phi1 * 0.5)), 2.0) t_1 = math.sin(((lambda1 - lambda2) / 2.0)) tmp = 0 if (lambda1 - lambda2) <= -1.0: tmp = (2.0 * R) * math.atan2(math.sqrt(t_0), math.sqrt((1.0 - t_0))) else: tmp = R * (2.0 * math.atan2(math.sqrt((math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (t_1 * (t_1 * (math.cos(phi1) * math.cos(phi2)))))), math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0))))) return tmp
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(cos(phi1) * (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)) + (sin(Float64(phi1 * 0.5)) ^ 2.0)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -1.0) tmp = Float64(Float64(2.0 * R) * atan(sqrt(t_0), sqrt(Float64(1.0 - t_0)))); else tmp = Float64(R * Float64(2.0 * atan(sqrt(Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(t_1 * Float64(t_1 * Float64(cos(phi1) * cos(phi2)))))), sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)))))); end return tmp end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2)
t_0 = (cos(phi1) * (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)) + (sin((phi1 * 0.5)) ^ 2.0);
t_1 = sin(((lambda1 - lambda2) / 2.0));
tmp = 0.0;
if ((lambda1 - lambda2) <= -1.0)
tmp = (2.0 * R) * atan2(sqrt(t_0), sqrt((1.0 - t_0)));
else
tmp = R * (2.0 * atan2(sqrt(((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (t_1 * (t_1 * (cos(phi1) * cos(phi2)))))), sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
end
tmp_2 = tmp;
end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Cos[phi1], $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(phi1 * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1.0], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(t$95$1 * N[(t$95$1 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} + {\sin \left(\phi_1 \cdot 0.5\right)}^{2}\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -1:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{t_0}}{\sqrt{1 - t_0}}\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{\sqrt{{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + t_1 \cdot \left(t_1 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -1Initial program 60.9%
Simplified60.8%
div-sub60.8%
sin-diff61.8%
div-inv61.8%
metadata-eval61.8%
div-inv61.8%
metadata-eval61.8%
div-inv61.8%
metadata-eval61.8%
div-inv61.8%
metadata-eval61.8%
Applied egg-rr61.8%
fma-neg61.8%
*-commutative61.8%
*-commutative61.8%
*-commutative61.8%
*-commutative61.8%
distribute-rgt-neg-in61.8%
*-commutative61.8%
Simplified61.8%
div-sub60.8%
sin-diff61.8%
div-inv61.8%
metadata-eval61.8%
div-inv61.8%
metadata-eval61.8%
div-inv61.8%
metadata-eval61.8%
div-inv61.8%
metadata-eval61.8%
Applied egg-rr72.9%
fma-neg61.8%
*-commutative61.8%
*-commutative61.8%
*-commutative61.8%
*-commutative61.8%
distribute-rgt-neg-in61.8%
*-commutative61.8%
Simplified72.9%
Taylor expanded in phi2 around 0 52.0%
Taylor expanded in phi2 around 0 51.4%
if -1 < (-.f64 lambda1 lambda2) Initial program 64.7%
Taylor expanded in lambda2 around 0 52.4%
Taylor expanded in lambda1 around 0 42.3%
Final simplification46.0%
NOTE: lambda1 and lambda2 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)
(* t_0 (* t_0 (* (cos phi1) (cos phi2))))))))
(if (<= (- lambda1 lambda2) -1.0)
(*
R
(*
2.0
(atan2 t_1 (sqrt (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))
(* R (* 2.0 (atan2 t_1 (sqrt (pow (cos (* phi2 -0.5)) 2.0))))))))assert(lambda1 < lambda2);
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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
double tmp;
if ((lambda1 - lambda2) <= -1.0) {
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
} else {
tmp = R * (2.0 * atan2(t_1, sqrt(pow(cos((phi2 * -0.5)), 2.0))));
}
return tmp;
}
NOTE: lambda1 and lambda2 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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))))
if ((lambda1 - lambda2) <= (-1.0d0)) then
tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))
else
tmp = r * (2.0d0 * atan2(t_1, sqrt((cos((phi2 * (-0.5d0))) ** 2.0d0))))
end if
code = tmp
end function
assert lambda1 < lambda2;
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) + (t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2))))));
double tmp;
if ((lambda1 - lambda2) <= -1.0) {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
} else {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt(Math.pow(Math.cos((phi2 * -0.5)), 2.0))));
}
return tmp;
}
[lambda1, lambda2] = sort([lambda1, lambda2]) 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) + (t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))))) tmp = 0 if (lambda1 - lambda2) <= -1.0: tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0))))) else: tmp = R * (2.0 * math.atan2(t_1, math.sqrt(math.pow(math.cos((phi2 * -0.5)), 2.0)))) return tmp
lambda1, lambda2 = sort([lambda1, lambda2]) 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(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))))) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -1.0) tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))))); else tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt((cos(Float64(phi2 * -0.5)) ^ 2.0))))); end return tmp end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
tmp = 0.0;
if ((lambda1 - lambda2) <= -1.0)
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))));
else
tmp = R * (2.0 * atan2(t_1, sqrt((cos((phi2 * -0.5)) ^ 2.0))));
end
tmp_2 = tmp;
end
NOTE: lambda1 and lambda2 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[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1.0], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\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} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -1:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2}}}\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -1Initial program 60.9%
Taylor expanded in phi2 around 0 51.1%
Taylor expanded in phi1 around 0 36.2%
if -1 < (-.f64 lambda1 lambda2) Initial program 64.7%
Taylor expanded in lambda2 around 0 52.4%
Taylor expanded in phi1 around 0 40.2%
Taylor expanded in lambda1 around 0 34.3%
unpow234.3%
1-sub-sin34.4%
unpow234.4%
*-commutative34.4%
Simplified34.4%
Final simplification35.1%
NOTE: lambda1 and lambda2 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)
(* t_0 (* t_0 (* (cos phi1) (cos phi2))))))))
(if (<= (- lambda1 lambda2) -1.0)
(*
R
(*
2.0
(atan2 t_1 (sqrt (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))))
(*
R
(*
2.0
(atan2 t_1 (sqrt (- 1.0 (pow (sin (* 0.5 (- phi1 phi2))) 2.0)))))))))assert(lambda1 < lambda2);
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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
double tmp;
if ((lambda1 - lambda2) <= -1.0) {
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
} else {
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - pow(sin((0.5 * (phi1 - phi2))), 2.0)))));
}
return tmp;
}
NOTE: lambda1 and lambda2 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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))))
if ((lambda1 - lambda2) <= (-1.0d0)) then
tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin(((lambda1 - lambda2) * 0.5d0)) ** 2.0d0)))))
else
tmp = r * (2.0d0 * atan2(t_1, sqrt((1.0d0 - (sin((0.5d0 * (phi1 - phi2))) ** 2.0d0)))))
end if
code = tmp
end function
assert lambda1 < lambda2;
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) + (t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2))))));
double tmp;
if ((lambda1 - lambda2) <= -1.0) {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin(((lambda1 - lambda2) * 0.5)), 2.0)))));
} else {
tmp = R * (2.0 * Math.atan2(t_1, Math.sqrt((1.0 - Math.pow(Math.sin((0.5 * (phi1 - phi2))), 2.0)))));
}
return tmp;
}
[lambda1, lambda2] = sort([lambda1, lambda2]) 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) + (t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))))) tmp = 0 if (lambda1 - lambda2) <= -1.0: tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin(((lambda1 - lambda2) * 0.5)), 2.0))))) else: tmp = R * (2.0 * math.atan2(t_1, math.sqrt((1.0 - math.pow(math.sin((0.5 * (phi1 - phi2))), 2.0))))) return tmp
lambda1, lambda2 = sort([lambda1, lambda2]) 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(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))))) tmp = 0.0 if (Float64(lambda1 - lambda2) <= -1.0) tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))))); else tmp = Float64(R * Float64(2.0 * atan(t_1, sqrt(Float64(1.0 - (sin(Float64(0.5 * Float64(phi1 - phi2))) ^ 2.0)))))); end return tmp end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2))))));
tmp = 0.0;
if ((lambda1 - lambda2) <= -1.0)
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin(((lambda1 - lambda2) * 0.5)) ^ 2.0)))));
else
tmp = R * (2.0 * atan2(t_1, sqrt((1.0 - (sin((0.5 * (phi1 - phi2))) ^ 2.0)))));
end
tmp_2 = tmp;
end
NOTE: lambda1 and lambda2 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[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(lambda1 - lambda2), $MachinePrecision], -1.0], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(R * N[(2.0 * N[ArcTan[t$95$1 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(0.5 * N[(phi1 - phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\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} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}\\
\mathbf{if}\;\lambda_1 - \lambda_2 \leq -1:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(2 \cdot \tan^{-1}_* \frac{t_1}{\sqrt{1 - {\sin \left(0.5 \cdot \left(\phi_1 - \phi_2\right)\right)}^{2}}}\right)\\
\end{array}
\end{array}
if (-.f64 lambda1 lambda2) < -1Initial program 60.9%
Taylor expanded in phi2 around 0 51.1%
Taylor expanded in phi1 around 0 36.2%
if -1 < (-.f64 lambda1 lambda2) Initial program 64.7%
Taylor expanded in lambda2 around 0 52.4%
Taylor expanded in lambda1 around 0 42.3%
Final simplification39.8%
NOTE: lambda1 and lambda2 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)
(* t_0 (* t_0 (* (cos phi1) (cos phi2))))))
(sqrt (pow (cos (* phi2 -0.5)) 2.0)))))))assert(lambda1 < lambda2);
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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt(pow(cos((phi2 * -0.5)), 2.0))));
}
NOTE: lambda1 and lambda2 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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt((cos((phi2 * (-0.5d0))) ** 2.0d0))))
end function
assert lambda1 < lambda2;
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) + (t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)))))), Math.sqrt(Math.pow(Math.cos((phi2 * -0.5)), 2.0))));
}
[lambda1, lambda2] = sort([lambda1, lambda2]) 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) + (t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))))), math.sqrt(math.pow(math.cos((phi2 * -0.5)), 2.0))))
lambda1, lambda2 = sort([lambda1, lambda2]) 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(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))))), sqrt((cos(Float64(phi2 * -0.5)) ^ 2.0))))) end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
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) + (t_0 * (t_0 * (cos(phi1) * cos(phi2)))))), sqrt((cos((phi2 * -0.5)) ^ 2.0))));
end
NOTE: lambda1 and lambda2 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[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[N[Cos[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\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} + t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)}}{\sqrt{{\cos \left(\phi_2 \cdot -0.5\right)}^{2}}}\right)
\end{array}
\end{array}
Initial program 63.1%
Taylor expanded in lambda2 around 0 47.5%
Taylor expanded in phi1 around 0 36.8%
Taylor expanded in lambda1 around 0 28.8%
unpow228.8%
1-sub-sin28.9%
unpow228.9%
*-commutative28.9%
Simplified28.9%
Final simplification28.9%
NOTE: lambda1 and lambda2 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
(* phi2 (* (* phi1 phi1) -0.0625))
(sqrt
(-
1.0
(+
(* t_0 (* t_0 (* (cos phi1) (cos phi2))))
(pow (sin (* phi2 -0.5)) 2.0)))))))))assert(lambda1 < lambda2);
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((phi2 * ((phi1 * phi1) * -0.0625)), sqrt((1.0 - ((t_0 * (t_0 * (cos(phi1) * cos(phi2)))) + pow(sin((phi2 * -0.5)), 2.0))))));
}
NOTE: lambda1 and lambda2 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((phi2 * ((phi1 * phi1) * (-0.0625d0))), sqrt((1.0d0 - ((t_0 * (t_0 * (cos(phi1) * cos(phi2)))) + (sin((phi2 * (-0.5d0))) ** 2.0d0))))))
end function
assert lambda1 < lambda2;
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((phi2 * ((phi1 * phi1) * -0.0625)), Math.sqrt((1.0 - ((t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)))) + Math.pow(Math.sin((phi2 * -0.5)), 2.0))))));
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) return R * (2.0 * math.atan2((phi2 * ((phi1 * phi1) * -0.0625)), math.sqrt((1.0 - ((t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))) + math.pow(math.sin((phi2 * -0.5)), 2.0))))))
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(R * Float64(2.0 * atan(Float64(phi2 * Float64(Float64(phi1 * phi1) * -0.0625)), sqrt(Float64(1.0 - Float64(Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))) + (sin(Float64(phi2 * -0.5)) ^ 2.0))))))) end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
tmp = R * (2.0 * atan2((phi2 * ((phi1 * phi1) * -0.0625)), sqrt((1.0 - ((t_0 * (t_0 * (cos(phi1) * cos(phi2)))) + (sin((phi2 * -0.5)) ^ 2.0))))));
end
NOTE: lambda1 and lambda2 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[(phi2 * N[(N[(phi1 * phi1), $MachinePrecision] * -0.0625), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(phi2 * -0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\phi_2 \cdot \left(\left(\phi_1 \cdot \phi_1\right) \cdot -0.0625\right)}{\sqrt{1 - \left(t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right) + {\sin \left(\phi_2 \cdot -0.5\right)}^{2}\right)}}\right)
\end{array}
\end{array}
Initial program 63.1%
Taylor expanded in phi1 around 0 47.7%
associate-+r+47.7%
associate-*r*47.7%
distribute-rgt1-in47.7%
unpow247.7%
*-commutative47.7%
*-commutative47.7%
associate-*l*47.7%
*-commutative47.7%
Simplified47.7%
Taylor expanded in phi1 around inf 6.8%
associate-*r*6.8%
unpow26.8%
*-commutative6.8%
Simplified6.8%
Taylor expanded in phi2 around 0 7.2%
*-commutative7.2%
*-commutative7.2%
associate-*l*7.2%
unpow27.2%
Simplified7.2%
Taylor expanded in phi1 around 0 7.2%
Final simplification7.2%
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function.
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(*
2.0
(atan2
(* phi2 (* (* phi1 phi1) -0.0625))
(sqrt
(-
1.0
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(*
(sin (* lambda2 -0.5))
(* (sin (/ (- lambda1 lambda2) 2.0)) (* (cos phi1) (cos phi2)))))))))))assert(lambda1 < lambda2);
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * atan2((phi2 * ((phi1 * phi1) * -0.0625)), sqrt((1.0 - (pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (sin((lambda2 * -0.5)) * (sin(((lambda1 - lambda2) / 2.0)) * (cos(phi1) * cos(phi2)))))))));
}
NOTE: lambda1 and lambda2 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((phi2 * ((phi1 * phi1) * (-0.0625d0))), sqrt((1.0d0 - ((sin(((phi1 - phi2) / 2.0d0)) ** 2.0d0) + (sin((lambda2 * (-0.5d0))) * (sin(((lambda1 - lambda2) / 2.0d0)) * (cos(phi1) * cos(phi2)))))))))
end function
assert lambda1 < lambda2;
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * (2.0 * Math.atan2((phi2 * ((phi1 * phi1) * -0.0625)), Math.sqrt((1.0 - (Math.pow(Math.sin(((phi1 - phi2) / 2.0)), 2.0) + (Math.sin((lambda2 * -0.5)) * (Math.sin(((lambda1 - lambda2) / 2.0)) * (Math.cos(phi1) * Math.cos(phi2)))))))));
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): return R * (2.0 * math.atan2((phi2 * ((phi1 * phi1) * -0.0625)), math.sqrt((1.0 - (math.pow(math.sin(((phi1 - phi2) / 2.0)), 2.0) + (math.sin((lambda2 * -0.5)) * (math.sin(((lambda1 - lambda2) / 2.0)) * (math.cos(phi1) * math.cos(phi2)))))))))
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * Float64(2.0 * atan(Float64(phi2 * Float64(Float64(phi1 * phi1) * -0.0625)), sqrt(Float64(1.0 - Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(sin(Float64(lambda2 * -0.5)) * Float64(sin(Float64(Float64(lambda1 - lambda2) / 2.0)) * Float64(cos(phi1) * cos(phi2)))))))))) end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
tmp = R * (2.0 * atan2((phi2 * ((phi1 * phi1) * -0.0625)), sqrt((1.0 - ((sin(((phi1 - phi2) / 2.0)) ^ 2.0) + (sin((lambda2 * -0.5)) * (sin(((lambda1 - lambda2) / 2.0)) * (cos(phi1) * cos(phi2)))))))));
end
NOTE: lambda1 and lambda2 should be sorted in increasing order before calling this function. code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[(2.0 * N[ArcTan[N[(phi2 * N[(N[(phi1 * phi1), $MachinePrecision] * -0.0625), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[Sin[N[(lambda2 * -0.5), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\phi_2 \cdot \left(\left(\phi_1 \cdot \phi_1\right) \cdot -0.0625\right)}{\sqrt{1 - \left({\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \sin \left(\lambda_2 \cdot -0.5\right) \cdot \left(\sin \left(\frac{\lambda_1 - \lambda_2}{2}\right) \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right)\right)}}\right)
\end{array}
Initial program 63.1%
Taylor expanded in phi1 around 0 47.7%
associate-+r+47.7%
associate-*r*47.7%
distribute-rgt1-in47.7%
unpow247.7%
*-commutative47.7%
*-commutative47.7%
associate-*l*47.7%
*-commutative47.7%
Simplified47.7%
Taylor expanded in phi1 around inf 6.8%
associate-*r*6.8%
unpow26.8%
*-commutative6.8%
Simplified6.8%
Taylor expanded in phi2 around 0 7.2%
*-commutative7.2%
*-commutative7.2%
associate-*l*7.2%
unpow27.2%
Simplified7.2%
Taylor expanded in lambda1 around 0 7.2%
Final simplification7.2%
NOTE: lambda1 and lambda2 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
(* phi2 (* (* phi1 phi1) -0.0625))
(sqrt
(-
1.0
(+
(* t_0 (* t_0 (* (cos phi1) (cos phi2))))
(- 0.5 (/ (cos (- phi1 phi2)) 2.0))))))))))assert(lambda1 < lambda2);
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((phi2 * ((phi1 * phi1) * -0.0625)), sqrt((1.0 - ((t_0 * (t_0 * (cos(phi1) * cos(phi2)))) + (0.5 - (cos((phi1 - phi2)) / 2.0)))))));
}
NOTE: lambda1 and lambda2 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((phi2 * ((phi1 * phi1) * (-0.0625d0))), sqrt((1.0d0 - ((t_0 * (t_0 * (cos(phi1) * cos(phi2)))) + (0.5d0 - (cos((phi1 - phi2)) / 2.0d0)))))))
end function
assert lambda1 < lambda2;
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((phi2 * ((phi1 * phi1) * -0.0625)), Math.sqrt((1.0 - ((t_0 * (t_0 * (Math.cos(phi1) * Math.cos(phi2)))) + (0.5 - (Math.cos((phi1 - phi2)) / 2.0)))))));
}
[lambda1, lambda2] = sort([lambda1, lambda2]) def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(((lambda1 - lambda2) / 2.0)) return R * (2.0 * math.atan2((phi2 * ((phi1 * phi1) * -0.0625)), math.sqrt((1.0 - ((t_0 * (t_0 * (math.cos(phi1) * math.cos(phi2)))) + (0.5 - (math.cos((phi1 - phi2)) / 2.0)))))))
lambda1, lambda2 = sort([lambda1, lambda2]) function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(R * Float64(2.0 * atan(Float64(phi2 * Float64(Float64(phi1 * phi1) * -0.0625)), sqrt(Float64(1.0 - Float64(Float64(t_0 * Float64(t_0 * Float64(cos(phi1) * cos(phi2)))) + Float64(0.5 - Float64(cos(Float64(phi1 - phi2)) / 2.0)))))))) end
lambda1, lambda2 = num2cell(sort([lambda1, lambda2])){:}
function tmp = code(R, lambda1, lambda2, phi1, phi2)
t_0 = sin(((lambda1 - lambda2) / 2.0));
tmp = R * (2.0 * atan2((phi2 * ((phi1 * phi1) * -0.0625)), sqrt((1.0 - ((t_0 * (t_0 * (cos(phi1) * cos(phi2)))) + (0.5 - (cos((phi1 - phi2)) / 2.0)))))));
end
NOTE: lambda1 and lambda2 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[(phi2 * N[(N[(phi1 * phi1), $MachinePrecision] * -0.0625), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(N[(t$95$0 * N[(t$95$0 * N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[lambda1, lambda2] = \mathsf{sort}([lambda1, lambda2])\\
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
R \cdot \left(2 \cdot \tan^{-1}_* \frac{\phi_2 \cdot \left(\left(\phi_1 \cdot \phi_1\right) \cdot -0.0625\right)}{\sqrt{1 - \left(t_0 \cdot \left(t_0 \cdot \left(\cos \phi_1 \cdot \cos \phi_2\right)\right) + \left(0.5 - \frac{\cos \left(\phi_1 - \phi_2\right)}{2}\right)\right)}}\right)
\end{array}
\end{array}
Initial program 63.1%
Taylor expanded in phi1 around 0 47.7%
associate-+r+47.7%
associate-*r*47.7%
distribute-rgt1-in47.7%
unpow247.7%
*-commutative47.7%
*-commutative47.7%
associate-*l*47.7%
*-commutative47.7%
Simplified47.7%
Taylor expanded in phi1 around inf 6.8%
associate-*r*6.8%
unpow26.8%
*-commutative6.8%
Simplified6.8%
Taylor expanded in phi2 around 0 7.2%
*-commutative7.2%
*-commutative7.2%
associate-*l*7.2%
unpow27.2%
Simplified7.2%
unpow27.2%
sin-mult7.2%
div-inv7.2%
metadata-eval7.2%
div-inv7.2%
metadata-eval7.2%
div-inv7.2%
metadata-eval7.2%
div-inv7.2%
metadata-eval7.2%
Applied egg-rr7.2%
div-sub7.2%
+-inverses7.2%
cos-07.2%
metadata-eval7.2%
distribute-lft-out7.2%
metadata-eval7.2%
*-rgt-identity7.2%
Simplified7.2%
Final simplification7.2%
herbie shell --seed 2023264
(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))))))))))