
(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 27 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}
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (* (cos phi2) (cos phi1))))
(*
(*
(atan2
(sqrt
(+
(* (* t_1 t_0) t_0)
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(sqrt
(fma
(fma
-0.5
(fma (sin lambda2) (sin lambda1) (* (cos lambda1) (cos lambda2)))
0.5)
(* (- (cos phi1)) (cos phi2))
(fma (+ (* (sin phi2) (sin phi1)) t_1) 0.5 0.5))))
2.0)
R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = cos(phi2) * cos(phi1);
return (atan2(sqrt((((t_1 * t_0) * t_0) + pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0))), sqrt(fma(fma(-0.5, fma(sin(lambda2), sin(lambda1), (cos(lambda1) * cos(lambda2))), 0.5), (-cos(phi1) * cos(phi2)), fma(((sin(phi2) * sin(phi1)) + t_1), 0.5, 0.5)))) * 2.0) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = Float64(cos(phi2) * cos(phi1)) return Float64(Float64(atan(sqrt(Float64(Float64(Float64(t_1 * t_0) * t_0) + (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0))), sqrt(fma(fma(-0.5, fma(sin(lambda2), sin(lambda1), Float64(cos(lambda1) * cos(lambda2))), 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(Float64(Float64(sin(phi2) * sin(phi1)) + t_1), 0.5, 0.5)))) * 2.0) * R) 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[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(t$95$1 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * N[(N[Sin[lambda2], $MachinePrecision] * N[Sin[lambda1], $MachinePrecision] + N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \cos \phi_2 \cdot \cos \phi_1\\
\left(\tan^{-1}_* \frac{\sqrt{\left(t\_1 \cdot t\_0\right) \cdot t\_0 + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, \mathsf{fma}\left(\sin \lambda_2, \sin \lambda_1, \cos \lambda_1 \cdot \cos \lambda_2\right), 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\sin \phi_2 \cdot \sin \phi_1 + t\_1, 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R
\end{array}
\end{array}
Initial program 66.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6467.6
Applied rewrites67.6%
Applied rewrites67.8%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.4
Applied rewrites79.4%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-sin.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6479.9
Applied rewrites79.9%
Final simplification79.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (cos (- lambda1 lambda2)))
(t_3 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_4 (+ t_3 (* (* t_0 t_1) t_1)))
(t_5 (sqrt (- 1.0 t_4))))
(if (<= (atan2 (sqrt t_4) t_5) 0.09)
(*
(*
(atan2
(sqrt
(-
t_3
(*
(*
(-
(* (sin (* lambda2 0.5)) (cos (* lambda1 0.5)))
(* (cos (* lambda2 0.5)) (sin (* lambda1 0.5))))
t_0)
t_1)))
t_5)
2.0)
R)
(*
(*
(atan2
(sqrt
(+
(* (fma t_2 -0.5 0.5) t_0)
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(sqrt
(fma
(fma -0.5 t_2 0.5)
(* (- (cos phi1)) (cos phi2))
(fma (+ (* (sin phi2) (sin phi1)) t_0) 0.5 0.5))))
2.0)
R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = cos((lambda1 - lambda2));
double t_3 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_4 = t_3 + ((t_0 * t_1) * t_1);
double t_5 = sqrt((1.0 - t_4));
double tmp;
if (atan2(sqrt(t_4), t_5) <= 0.09) {
tmp = (atan2(sqrt((t_3 - ((((sin((lambda2 * 0.5)) * cos((lambda1 * 0.5))) - (cos((lambda2 * 0.5)) * sin((lambda1 * 0.5)))) * t_0) * t_1))), t_5) * 2.0) * R;
} else {
tmp = (atan2(sqrt(((fma(t_2, -0.5, 0.5) * t_0) + pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0))), sqrt(fma(fma(-0.5, t_2, 0.5), (-cos(phi1) * cos(phi2)), fma(((sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = cos(Float64(lambda1 - lambda2)) t_3 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_4 = Float64(t_3 + Float64(Float64(t_0 * t_1) * t_1)) t_5 = sqrt(Float64(1.0 - t_4)) tmp = 0.0 if (atan(sqrt(t_4), t_5) <= 0.09) tmp = Float64(Float64(atan(sqrt(Float64(t_3 - Float64(Float64(Float64(Float64(sin(Float64(lambda2 * 0.5)) * cos(Float64(lambda1 * 0.5))) - Float64(cos(Float64(lambda2 * 0.5)) * sin(Float64(lambda1 * 0.5)))) * t_0) * t_1))), t_5) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(Float64(Float64(fma(t_2, -0.5, 0.5) * t_0) + (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0))), sqrt(fma(fma(-0.5, t_2, 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(Float64(Float64(sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 + N[(N[(t$95$0 * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[N[(1.0 - t$95$4), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[ArcTan[N[Sqrt[t$95$4], $MachinePrecision] / t$95$5], $MachinePrecision], 0.09], N[(N[(N[ArcTan[N[Sqrt[N[(t$95$3 - N[(N[(N[(N[(N[Sin[N[(lambda2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(lambda2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$5], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(t$95$2 * -0.5 + 0.5), $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * t$95$2 + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_3 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_4 := t\_3 + \left(t\_0 \cdot t\_1\right) \cdot t\_1\\
t_5 := \sqrt{1 - t\_4}\\
\mathbf{if}\;\tan^{-1}_* \frac{\sqrt{t\_4}}{t\_5} \leq 0.09:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{t\_3 - \left(\left(\sin \left(\lambda_2 \cdot 0.5\right) \cdot \cos \left(\lambda_1 \cdot 0.5\right) - \cos \left(\lambda_2 \cdot 0.5\right) \cdot \sin \left(\lambda_1 \cdot 0.5\right)\right) \cdot t\_0\right) \cdot t\_1}}{t\_5} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_2, -0.5, 0.5\right) \cdot t\_0 + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, t\_2, 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\sin \phi_2 \cdot \sin \phi_1 + t\_0, 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) < 0.089999999999999997Initial program 92.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6492.8
Applied rewrites92.8%
if 0.089999999999999997 < (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) Initial program 64.4%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6465.4
Applied rewrites65.4%
Applied rewrites65.5%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.2
Applied rewrites78.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
pow2N/A
lower-pow.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.2
Applied rewrites78.2%
Final simplification79.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (pow (sin (/ (- phi1 phi2) 2.0)) 2.0))
(t_3 (+ t_2 (* (* t_0 t_1) t_1)))
(t_4 (sqrt t_3))
(t_5 (cos (- lambda1 lambda2))))
(if (<= (atan2 t_4 (sqrt (- 1.0 t_3))) 0.09)
(*
(*
(atan2
t_4
(sqrt
(-
1.0
(-
t_2
(*
(*
(-
(* (sin (* lambda2 0.5)) (cos (* lambda1 0.5)))
(* (cos (* lambda2 0.5)) (sin (* lambda1 0.5))))
t_0)
t_1)))))
2.0)
R)
(*
(*
(atan2
(sqrt
(+
(* (fma t_5 -0.5 0.5) t_0)
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(sqrt
(fma
(fma -0.5 t_5 0.5)
(* (- (cos phi1)) (cos phi2))
(fma (+ (* (sin phi2) (sin phi1)) t_0) 0.5 0.5))))
2.0)
R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0);
double t_3 = t_2 + ((t_0 * t_1) * t_1);
double t_4 = sqrt(t_3);
double t_5 = cos((lambda1 - lambda2));
double tmp;
if (atan2(t_4, sqrt((1.0 - t_3))) <= 0.09) {
tmp = (atan2(t_4, sqrt((1.0 - (t_2 - ((((sin((lambda2 * 0.5)) * cos((lambda1 * 0.5))) - (cos((lambda2 * 0.5)) * sin((lambda1 * 0.5)))) * t_0) * t_1))))) * 2.0) * R;
} else {
tmp = (atan2(sqrt(((fma(t_5, -0.5, 0.5) * t_0) + pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0))), sqrt(fma(fma(-0.5, t_5, 0.5), (-cos(phi1) * cos(phi2)), fma(((sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0 t_3 = Float64(t_2 + Float64(Float64(t_0 * t_1) * t_1)) t_4 = sqrt(t_3) t_5 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (atan(t_4, sqrt(Float64(1.0 - t_3))) <= 0.09) tmp = Float64(Float64(atan(t_4, sqrt(Float64(1.0 - Float64(t_2 - Float64(Float64(Float64(Float64(sin(Float64(lambda2 * 0.5)) * cos(Float64(lambda1 * 0.5))) - Float64(cos(Float64(lambda2 * 0.5)) * sin(Float64(lambda1 * 0.5)))) * t_0) * t_1))))) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(Float64(Float64(fma(t_5, -0.5, 0.5) * t_0) + (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0))), sqrt(fma(fma(-0.5, t_5, 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(Float64(Float64(sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 + N[(N[(t$95$0 * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[t$95$3], $MachinePrecision]}, Block[{t$95$5 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[ArcTan[t$95$4 / N[Sqrt[N[(1.0 - t$95$3), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 0.09], N[(N[(N[ArcTan[t$95$4 / N[Sqrt[N[(1.0 - N[(t$95$2 - N[(N[(N[(N[(N[Sin[N[(lambda2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[N[(lambda2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(lambda1 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(t$95$5 * -0.5 + 0.5), $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * t$95$5 + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2}\\
t_3 := t\_2 + \left(t\_0 \cdot t\_1\right) \cdot t\_1\\
t_4 := \sqrt{t\_3}\\
t_5 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\tan^{-1}_* \frac{t\_4}{\sqrt{1 - t\_3}} \leq 0.09:\\
\;\;\;\;\left(\tan^{-1}_* \frac{t\_4}{\sqrt{1 - \left(t\_2 - \left(\left(\sin \left(\lambda_2 \cdot 0.5\right) \cdot \cos \left(\lambda_1 \cdot 0.5\right) - \cos \left(\lambda_2 \cdot 0.5\right) \cdot \sin \left(\lambda_1 \cdot 0.5\right)\right) \cdot t\_0\right) \cdot t\_1\right)}} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_5, -0.5, 0.5\right) \cdot t\_0 + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, t\_5, 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\sin \phi_2 \cdot \sin \phi_1 + t\_0, 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) < 0.089999999999999997Initial program 92.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6492.7
Applied rewrites92.7%
if 0.089999999999999997 < (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) Initial program 64.4%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6465.4
Applied rewrites65.4%
Applied rewrites65.5%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.2
Applied rewrites78.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
pow2N/A
lower-pow.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.2
Applied rewrites78.2%
Final simplification79.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* t_0 t_1) t_1)))
(t_3
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0))
(t_4 (sqrt (- 1.0 t_2)))
(t_5 (cos (- lambda1 lambda2))))
(if (<= (atan2 (sqrt t_2) t_4) 0.09)
(*
(*
(atan2
(sqrt
(+ (* (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0) (cos phi2)) t_3))
t_4)
2.0)
R)
(*
(*
(atan2
(sqrt (+ (* (fma t_5 -0.5 0.5) t_0) t_3))
(sqrt
(fma
(fma -0.5 t_5 0.5)
(* (- (cos phi1)) (cos phi2))
(fma (+ (* (sin phi2) (sin phi1)) t_0) 0.5 0.5))))
2.0)
R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((t_0 * t_1) * t_1);
double t_3 = pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0);
double t_4 = sqrt((1.0 - t_2));
double t_5 = cos((lambda1 - lambda2));
double tmp;
if (atan2(sqrt(t_2), t_4) <= 0.09) {
tmp = (atan2(sqrt(((pow(sin(((lambda1 - lambda2) * 0.5)), 2.0) * cos(phi2)) + t_3)), t_4) * 2.0) * R;
} else {
tmp = (atan2(sqrt(((fma(t_5, -0.5, 0.5) * t_0) + t_3)), sqrt(fma(fma(-0.5, t_5, 0.5), (-cos(phi1) * cos(phi2)), fma(((sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(t_0 * t_1) * t_1)) t_3 = Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0 t_4 = sqrt(Float64(1.0 - t_2)) t_5 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (atan(sqrt(t_2), t_4) <= 0.09) tmp = Float64(Float64(atan(sqrt(Float64(Float64((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0) * cos(phi2)) + t_3)), t_4) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(Float64(Float64(fma(t_5, -0.5, 0.5) * t_0) + t_3)), sqrt(fma(fma(-0.5, t_5, 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(Float64(Float64(sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(t$95$0 * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(1.0 - t$95$2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[ArcTan[N[Sqrt[t$95$2], $MachinePrecision] / t$95$4], $MachinePrecision], 0.09], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision] / t$95$4], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(t$95$5 * -0.5 + 0.5), $MachinePrecision] * t$95$0), $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * t$95$5 + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(t\_0 \cdot t\_1\right) \cdot t\_1\\
t_3 := {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}\\
t_4 := \sqrt{1 - t\_2}\\
t_5 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\tan^{-1}_* \frac{\sqrt{t\_2}}{t\_4} \leq 0.09:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{{\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} \cdot \cos \phi_2 + t\_3}}{t\_4} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_5, -0.5, 0.5\right) \cdot t\_0 + t\_3}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, t\_5, 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\sin \phi_2 \cdot \sin \phi_1 + t\_0, 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) < 0.089999999999999997Initial program 92.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6492.7
Applied rewrites92.7%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f6492.7
Applied rewrites92.7%
if 0.089999999999999997 < (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) Initial program 64.4%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6465.4
Applied rewrites65.4%
Applied rewrites65.5%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.2
Applied rewrites78.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
pow2N/A
lower-pow.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.2
Applied rewrites78.2%
Final simplification79.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (sin (/ (- lambda1 lambda2) 2.0)))
(t_2 (cos (- lambda1 lambda2)))
(t_3 (+ (pow (sin (/ (- phi1 phi2) 2.0)) 2.0) (* (* t_0 t_1) t_1)))
(t_4 (sqrt (- 1.0 t_3)))
(t_5
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(if (<= (atan2 (sqrt t_3) t_4) 0.09)
(*
(*
(atan2
(sqrt
(+ (* (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0) (cos phi2)) t_5))
t_4)
2.0)
R)
(*
(*
(atan2
(sqrt (+ (* (* (fma t_2 -0.5 0.5) (cos phi2)) (cos phi1)) t_5))
(sqrt
(fma
(fma -0.5 t_2 0.5)
(* (- (cos phi1)) (cos phi2))
(fma (+ (* (sin phi2) (sin phi1)) t_0) 0.5 0.5))))
2.0)
R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = sin(((lambda1 - lambda2) / 2.0));
double t_2 = cos((lambda1 - lambda2));
double t_3 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + ((t_0 * t_1) * t_1);
double t_4 = sqrt((1.0 - t_3));
double t_5 = pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0);
double tmp;
if (atan2(sqrt(t_3), t_4) <= 0.09) {
tmp = (atan2(sqrt(((pow(sin(((lambda1 - lambda2) * 0.5)), 2.0) * cos(phi2)) + t_5)), t_4) * 2.0) * R;
} else {
tmp = (atan2(sqrt((((fma(t_2, -0.5, 0.5) * cos(phi2)) * cos(phi1)) + t_5)), sqrt(fma(fma(-0.5, t_2, 0.5), (-cos(phi1) * cos(phi2)), fma(((sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_2 = cos(Float64(lambda1 - lambda2)) t_3 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(t_0 * t_1) * t_1)) t_4 = sqrt(Float64(1.0 - t_3)) t_5 = Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0 tmp = 0.0 if (atan(sqrt(t_3), t_4) <= 0.09) tmp = Float64(Float64(atan(sqrt(Float64(Float64((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0) * cos(phi2)) + t_5)), t_4) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(Float64(Float64(Float64(fma(t_2, -0.5, 0.5) * cos(phi2)) * cos(phi1)) + t_5)), sqrt(fma(fma(-0.5, t_2, 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(Float64(Float64(sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(t$95$0 * t$95$1), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(1.0 - t$95$3), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[N[ArcTan[N[Sqrt[t$95$3], $MachinePrecision] / t$95$4], $MachinePrecision], 0.09], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + t$95$5), $MachinePrecision]], $MachinePrecision] / t$95$4], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(N[(t$95$2 * -0.5 + 0.5), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + t$95$5), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * t$95$2 + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_2 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_3 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(t\_0 \cdot t\_1\right) \cdot t\_1\\
t_4 := \sqrt{1 - t\_3}\\
t_5 := {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}\\
\mathbf{if}\;\tan^{-1}_* \frac{\sqrt{t\_3}}{t\_4} \leq 0.09:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{{\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} \cdot \cos \phi_2 + t\_5}}{t\_4} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\left(\mathsf{fma}\left(t\_2, -0.5, 0.5\right) \cdot \cos \phi_2\right) \cdot \cos \phi_1 + t\_5}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, t\_2, 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\sin \phi_2 \cdot \sin \phi_1 + t\_0, 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) < 0.089999999999999997Initial program 92.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6492.7
Applied rewrites92.7%
Taylor expanded in phi1 around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f6492.7
Applied rewrites92.7%
if 0.089999999999999997 < (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) Initial program 64.4%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6465.4
Applied rewrites65.4%
Applied rewrites65.5%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.2
Applied rewrites78.2%
Applied rewrites78.1%
Final simplification79.3%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- phi2 phi1)))
(t_1 (fma -0.5 (cos (- lambda1 lambda2)) 0.5))
(t_2 (sin (/ (- lambda1 lambda2) 2.0)))
(t_3
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi2) (cos phi1)) t_2) t_2)))
(t_4 (sqrt t_3)))
(if (<= (atan2 t_4 (sqrt (- 1.0 t_3))) 2e-16)
(*
(*
(atan2 t_4 (sqrt (- 1.0 (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0))))
2.0)
R)
(*
(*
(atan2
(sqrt
(fma (* (+ (cos (+ phi2 phi1)) t_0) t_1) 0.5 (- 0.5 (* t_0 0.5))))
(sqrt
(fma
t_1
(* (- (cos phi1)) (cos phi2))
(fma (cos (- phi1 phi2)) 0.5 0.5))))
2.0)
R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((phi2 - phi1));
double t_1 = fma(-0.5, cos((lambda1 - lambda2)), 0.5);
double t_2 = sin(((lambda1 - lambda2) / 2.0));
double t_3 = pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi2) * cos(phi1)) * t_2) * t_2);
double t_4 = sqrt(t_3);
double tmp;
if (atan2(t_4, sqrt((1.0 - t_3))) <= 2e-16) {
tmp = (atan2(t_4, sqrt((1.0 - pow(sin(((lambda1 - lambda2) * 0.5)), 2.0)))) * 2.0) * R;
} else {
tmp = (atan2(sqrt(fma(((cos((phi2 + phi1)) + t_0) * t_1), 0.5, (0.5 - (t_0 * 0.5)))), sqrt(fma(t_1, (-cos(phi1) * cos(phi2)), fma(cos((phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(phi2 - phi1)) t_1 = fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5) t_2 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_3 = Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_2) * t_2)) t_4 = sqrt(t_3) tmp = 0.0 if (atan(t_4, sqrt(Float64(1.0 - t_3))) <= 2e-16) tmp = Float64(Float64(atan(t_4, sqrt(Float64(1.0 - (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0)))) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(fma(Float64(Float64(cos(Float64(phi2 + phi1)) + t_0) * t_1), 0.5, Float64(0.5 - Float64(t_0 * 0.5)))), sqrt(fma(t_1, Float64(Float64(-cos(phi1)) * cos(phi2)), fma(cos(Float64(phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[t$95$3], $MachinePrecision]}, If[LessEqual[N[ArcTan[t$95$4 / N[Sqrt[N[(1.0 - t$95$3), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2e-16], N[(N[(N[ArcTan[t$95$4 / N[Sqrt[N[(1.0 - N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision] + t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision] * 0.5 + N[(0.5 - N[(t$95$0 * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(t$95$1 * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\phi_2 - \phi_1\right)\\
t_1 := \mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right)\\
t_2 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_3 := {\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t\_2\right) \cdot t\_2\\
t_4 := \sqrt{t\_3}\\
\mathbf{if}\;\tan^{-1}_* \frac{t\_4}{\sqrt{1 - t\_3}} \leq 2 \cdot 10^{-16}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{t\_4}{\sqrt{1 - {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}}} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \left(\phi_2 + \phi_1\right) + t\_0\right) \cdot t\_1, 0.5, 0.5 - t\_0 \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(t\_1, \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right), 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) < 2e-16Initial program 93.0%
Taylor expanded in phi2 around 0
+-commutativeN/A
associate--l+N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites93.0%
Taylor expanded in phi1 around 0
Applied rewrites93.0%
if 2e-16 < (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) Initial program 65.2%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6466.2
Applied rewrites66.2%
Applied rewrites66.3%
Applied rewrites65.7%
Final simplification67.2%
(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 phi2) (cos phi1)) t_0) t_0)))
(t_2 (cos (- phi2 phi1)))
(t_3 (fma -0.5 (cos (- lambda1 lambda2)) 0.5)))
(if (<= (atan2 (sqrt t_1) (sqrt (- 1.0 t_1))) 0.02)
(*
(*
(atan2
(sqrt
(fma
(pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)
(cos phi1)
(pow (sin (* 0.5 phi1)) 2.0)))
(sqrt
(fma
(cos phi1)
(- 0.5 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
0.5)))
2.0)
R)
(*
(*
(atan2
(sqrt
(fma (* (+ (cos (+ phi2 phi1)) t_2) t_3) 0.5 (- 0.5 (* t_2 0.5))))
(sqrt
(fma
t_3
(* (- (cos phi1)) (cos phi2))
(fma (cos (- phi1 phi2)) 0.5 0.5))))
2.0)
R))))
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(phi2) * cos(phi1)) * t_0) * t_0);
double t_2 = cos((phi2 - phi1));
double t_3 = fma(-0.5, cos((lambda1 - lambda2)), 0.5);
double tmp;
if (atan2(sqrt(t_1), sqrt((1.0 - t_1))) <= 0.02) {
tmp = (atan2(sqrt(fma(pow(sin(((lambda1 - lambda2) * 0.5)), 2.0), cos(phi1), pow(sin((0.5 * phi1)), 2.0))), sqrt(fma(cos(phi1), (0.5 - fma(cos((lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * 2.0) * R;
} else {
tmp = (atan2(sqrt(fma(((cos((phi2 + phi1)) + t_2) * t_3), 0.5, (0.5 - (t_2 * 0.5)))), sqrt(fma(t_3, (-cos(phi1) * cos(phi2)), fma(cos((phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R;
}
return tmp;
}
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(phi2) * cos(phi1)) * t_0) * t_0)) t_2 = cos(Float64(phi2 - phi1)) t_3 = fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5) tmp = 0.0 if (atan(sqrt(t_1), sqrt(Float64(1.0 - t_1))) <= 0.02) tmp = Float64(Float64(atan(sqrt(fma((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0), cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(fma(cos(phi1), Float64(0.5 - fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(fma(Float64(Float64(cos(Float64(phi2 + phi1)) + t_2) * t_3), 0.5, Float64(0.5 - Float64(t_2 * 0.5)))), sqrt(fma(t_3, Float64(Float64(-cos(phi1)) * cos(phi2)), fma(cos(Float64(phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R); end return tmp 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[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]}, If[LessEqual[N[ArcTan[N[Sqrt[t$95$1], $MachinePrecision] / N[Sqrt[N[(1.0 - t$95$1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 0.02], N[(N[(N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(0.5 - N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision] + t$95$2), $MachinePrecision] * t$95$3), $MachinePrecision] * 0.5 + N[(0.5 - N[(t$95$2 * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(t$95$3 * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $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_2 \cdot \cos \phi_1\right) \cdot t\_0\right) \cdot t\_0\\
t_2 := \cos \left(\phi_2 - \phi_1\right)\\
t_3 := \mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right)\\
\mathbf{if}\;\tan^{-1}_* \frac{\sqrt{t\_1}}{\sqrt{1 - t\_1}} \leq 0.02:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{\mathsf{fma}\left(\cos \phi_1, 0.5 - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right), 0.5\right)}} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\left(\cos \left(\phi_2 + \phi_1\right) + t\_2\right) \cdot t\_3, 0.5, 0.5 - t\_2 \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(t\_3, \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right), 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) < 0.0200000000000000004Initial program 93.9%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6493.9
Applied rewrites93.9%
Applied rewrites93.9%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f6488.5
Applied rewrites88.5%
Taylor expanded in phi2 around 0
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
cancel-sign-sub-invN/A
sub-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-fma.f64N/A
Applied rewrites88.5%
if 0.0200000000000000004 < (atan2.f64 (sqrt.f64 (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))) (sqrt.f64 (-.f64 #s(literal 1 binary64) (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))))))) Initial program 64.9%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6465.9
Applied rewrites65.9%
Applied rewrites66.0%
Applied rewrites65.5%
Final simplification66.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
(*
(*
(atan2
(sqrt
(+
(* (* (* (cos phi2) (cos phi1)) t_0) t_0)
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(sqrt
(fma
(fma -0.5 (cos (- lambda1 lambda2)) 0.5)
(* (- (cos phi1)) (cos phi2))
(fma (fma (cos phi2) (cos phi1) (* (sin phi2) (sin phi1))) 0.5 0.5))))
2.0)
R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
return (atan2(sqrt(((((cos(phi2) * cos(phi1)) * t_0) * t_0) + pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0))), sqrt(fma(fma(-0.5, cos((lambda1 - lambda2)), 0.5), (-cos(phi1) * cos(phi2)), fma(fma(cos(phi2), cos(phi1), (sin(phi2) * sin(phi1))), 0.5, 0.5)))) * 2.0) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(Float64(atan(sqrt(Float64(Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_0) * t_0) + (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0))), sqrt(fma(fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(fma(cos(phi2), cos(phi1), Float64(sin(phi2) * sin(phi1))), 0.5, 0.5)))) * 2.0) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\left(\tan^{-1}_* \frac{\sqrt{\left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t\_0\right) \cdot t\_0 + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\mathsf{fma}\left(\cos \phi_2, \cos \phi_1, \sin \phi_2 \cdot \sin \phi_1\right), 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R
\end{array}
\end{array}
Initial program 66.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6467.6
Applied rewrites67.6%
Applied rewrites67.8%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.4
Applied rewrites79.4%
Final simplification79.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (* (- lambda1 lambda2) 0.5))))
(*
(*
(atan2
(sqrt
(+
(* (* (* t_0 (cos phi2)) t_0) (cos phi1))
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(sqrt
(fma
(fma -0.5 (cos (- lambda1 lambda2)) 0.5)
(* (- (cos phi1)) (cos phi2))
(fma
(+ (* (sin phi2) (sin phi1)) (* (cos phi2) (cos phi1)))
0.5
0.5))))
2.0)
R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) * 0.5));
return (atan2(sqrt(((((t_0 * cos(phi2)) * t_0) * cos(phi1)) + pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0))), sqrt(fma(fma(-0.5, cos((lambda1 - lambda2)), 0.5), (-cos(phi1) * cos(phi2)), fma(((sin(phi2) * sin(phi1)) + (cos(phi2) * cos(phi1))), 0.5, 0.5)))) * 2.0) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) * 0.5)) return Float64(Float64(atan(sqrt(Float64(Float64(Float64(Float64(t_0 * cos(phi2)) * t_0) * cos(phi1)) + (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0))), sqrt(fma(fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(Float64(Float64(sin(phi2) * sin(phi1)) + Float64(cos(phi2) * cos(phi1))), 0.5, 0.5)))) * 2.0) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(N[(t$95$0 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)\\
\left(\tan^{-1}_* \frac{\sqrt{\left(\left(t\_0 \cdot \cos \phi_2\right) \cdot t\_0\right) \cdot \cos \phi_1 + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\sin \phi_2 \cdot \sin \phi_1 + \cos \phi_2 \cdot \cos \phi_1, 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R
\end{array}
\end{array}
Initial program 66.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6467.6
Applied rewrites67.6%
Applied rewrites67.8%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.4
Applied rewrites79.4%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6479.4
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f6479.4
lift-/.f64N/A
div-invN/A
metadata-evalN/A
Applied rewrites79.4%
Final simplification79.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (fma -0.5 (cos (- lambda1 lambda2)) 0.5))
(t_2
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0))
(t_3 (sin (/ (- lambda1 lambda2) 2.0))))
(if (<= phi1 -1e-8)
(*
(*
(atan2
(sqrt
(+ (* (pow (sin (* (- lambda1 lambda2) 0.5)) 2.0) (cos phi1)) t_2))
(sqrt
(fma
t_1
(* (- (cos phi1)) (cos phi2))
(fma (+ (* (sin phi2) (sin phi1)) t_0) 0.5 0.5))))
2.0)
R)
(*
(*
(atan2
(sqrt (+ (* (* t_0 t_3) t_3) t_2))
(sqrt
(/
(-
(+ (cos (- phi1 phi2)) 1.0)
(* (+ (cos (+ phi2 phi1)) (cos (- phi2 phi1))) t_1))
2.0)))
2.0)
R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = fma(-0.5, cos((lambda1 - lambda2)), 0.5);
double t_2 = pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0);
double t_3 = sin(((lambda1 - lambda2) / 2.0));
double tmp;
if (phi1 <= -1e-8) {
tmp = (atan2(sqrt(((pow(sin(((lambda1 - lambda2) * 0.5)), 2.0) * cos(phi1)) + t_2)), sqrt(fma(t_1, (-cos(phi1) * cos(phi2)), fma(((sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R;
} else {
tmp = (atan2(sqrt((((t_0 * t_3) * t_3) + t_2)), sqrt((((cos((phi1 - phi2)) + 1.0) - ((cos((phi2 + phi1)) + cos((phi2 - phi1))) * t_1)) / 2.0))) * 2.0) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5) t_2 = Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0 t_3 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) tmp = 0.0 if (phi1 <= -1e-8) tmp = Float64(Float64(atan(sqrt(Float64(Float64((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0) * cos(phi1)) + t_2)), sqrt(fma(t_1, Float64(Float64(-cos(phi1)) * cos(phi2)), fma(Float64(Float64(sin(phi2) * sin(phi1)) + t_0), 0.5, 0.5)))) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(Float64(Float64(Float64(t_0 * t_3) * t_3) + t_2)), sqrt(Float64(Float64(Float64(cos(Float64(phi1 - phi2)) + 1.0) - Float64(Float64(cos(Float64(phi2 + phi1)) + cos(Float64(phi2 - phi1))) * t_1)) / 2.0))) * 2.0) * R); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -1e-8], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(t$95$1 * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Sin[phi2], $MachinePrecision] * N[Sin[phi1], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(t$95$0 * t$95$3), $MachinePrecision] * t$95$3), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[(N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right)\\
t_2 := {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}\\
t_3 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\mathbf{if}\;\phi_1 \leq -1 \cdot 10^{-8}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{{\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2} \cdot \cos \phi_1 + t\_2}}{\sqrt{\mathsf{fma}\left(t\_1, \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\sin \phi_2 \cdot \sin \phi_1 + t\_0, 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\left(t\_0 \cdot t\_3\right) \cdot t\_3 + t\_2}}{\sqrt{\frac{\left(\cos \left(\phi_1 - \phi_2\right) + 1\right) - \left(\cos \left(\phi_2 + \phi_1\right) + \cos \left(\phi_2 - \phi_1\right)\right) \cdot t\_1}{2}}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if phi1 < -1e-8Initial program 52.6%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6454.2
Applied rewrites54.2%
Applied rewrites54.3%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.7
Applied rewrites79.7%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f6465.0
Applied rewrites65.0%
if -1e-8 < phi1 Initial program 71.4%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6472.1
Applied rewrites72.1%
Applied rewrites72.3%
Final simplification70.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0)))
(t_1 (fma -0.5 (cos (- lambda1 lambda2)) 0.5)))
(if (<=
(+
(pow (sin (/ (- phi1 phi2) 2.0)) 2.0)
(* (* (* (cos phi2) (cos phi1)) t_0) t_0))
0.0002)
(*
(*
(atan2
(sqrt
(fma
(pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)
(cos phi1)
(pow (sin (* 0.5 phi1)) 2.0)))
(sqrt
(fma
(cos phi1)
(- 0.5 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
0.5)))
2.0)
R)
(*
(*
(atan2
(sqrt
(fma
(* t_1 (cos phi1))
(cos phi2)
(- 0.5 (* (cos (- phi2 phi1)) 0.5))))
(sqrt
(fma
t_1
(* (- (cos phi1)) (cos phi2))
(fma (cos (- phi1 phi2)) 0.5 0.5))))
2.0)
R))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
double t_1 = fma(-0.5, cos((lambda1 - lambda2)), 0.5);
double tmp;
if ((pow(sin(((phi1 - phi2) / 2.0)), 2.0) + (((cos(phi2) * cos(phi1)) * t_0) * t_0)) <= 0.0002) {
tmp = (atan2(sqrt(fma(pow(sin(((lambda1 - lambda2) * 0.5)), 2.0), cos(phi1), pow(sin((0.5 * phi1)), 2.0))), sqrt(fma(cos(phi1), (0.5 - fma(cos((lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * 2.0) * R;
} else {
tmp = (atan2(sqrt(fma((t_1 * cos(phi1)), cos(phi2), (0.5 - (cos((phi2 - phi1)) * 0.5)))), sqrt(fma(t_1, (-cos(phi1) * cos(phi2)), fma(cos((phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) t_1 = fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5) tmp = 0.0 if (Float64((sin(Float64(Float64(phi1 - phi2) / 2.0)) ^ 2.0) + Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_0) * t_0)) <= 0.0002) tmp = Float64(Float64(atan(sqrt(fma((sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0), cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(fma(cos(phi1), Float64(0.5 - fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * 2.0) * R); else tmp = Float64(Float64(atan(sqrt(fma(Float64(t_1 * cos(phi1)), cos(phi2), Float64(0.5 - Float64(cos(Float64(phi2 - phi1)) * 0.5)))), sqrt(fma(t_1, Float64(Float64(-cos(phi1)) * cos(phi2)), fma(cos(Float64(phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R); end return tmp 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[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]}, If[LessEqual[N[(N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 0.0002], N[(N[(N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(0.5 - N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[(N[ArcTan[N[Sqrt[N[(N[(t$95$1 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Cos[phi2], $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(t$95$1 * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
t_1 := \mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right)\\
\mathbf{if}\;{\sin \left(\frac{\phi_1 - \phi_2}{2}\right)}^{2} + \left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t\_0\right) \cdot t\_0 \leq 0.0002:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{\mathsf{fma}\left(\cos \phi_1, 0.5 - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right), 0.5\right)}} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1 \cdot \cos \phi_1, \cos \phi_2, 0.5 - \cos \left(\phi_2 - \phi_1\right) \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(t\_1, \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right), 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R\\
\end{array}
\end{array}
if (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))))) < 2.0000000000000001e-4Initial program 68.3%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6474.3
Applied rewrites74.3%
Applied rewrites74.3%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f6470.0
Applied rewrites70.0%
Taylor expanded in phi2 around 0
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
cancel-sign-sub-invN/A
sub-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-fma.f64N/A
Applied rewrites69.6%
if 2.0000000000000001e-4 < (+.f64 (pow.f64 (sin.f64 (/.f64 (-.f64 phi1 phi2) #s(literal 2 binary64))) #s(literal 2 binary64)) (*.f64 (*.f64 (*.f64 (cos.f64 phi1) (cos.f64 phi2)) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64)))) (sin.f64 (/.f64 (-.f64 lambda1 lambda2) #s(literal 2 binary64))))) Initial program 66.6%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6467.0
Applied rewrites67.0%
Applied rewrites67.1%
Applied rewrites66.6%
Final simplification66.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
(*
(*
(atan2
(sqrt
(+
(* (* (* (cos phi2) (cos phi1)) t_0) t_0)
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(sqrt
(/
(-
(+ (cos (- phi1 phi2)) 1.0)
(*
(+ (cos (+ phi2 phi1)) (cos (- phi2 phi1)))
(fma -0.5 (cos (- lambda1 lambda2)) 0.5)))
2.0)))
2.0)
R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
return (atan2(sqrt(((((cos(phi2) * cos(phi1)) * t_0) * t_0) + pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0))), sqrt((((cos((phi1 - phi2)) + 1.0) - ((cos((phi2 + phi1)) + cos((phi2 - phi1))) * fma(-0.5, cos((lambda1 - lambda2)), 0.5))) / 2.0))) * 2.0) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(Float64(atan(sqrt(Float64(Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_0) * t_0) + (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0))), sqrt(Float64(Float64(Float64(cos(Float64(phi1 - phi2)) + 1.0) - Float64(Float64(cos(Float64(phi2 + phi1)) + cos(Float64(phi2 - phi1))) * fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5))) / 2.0))) * 2.0) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[(N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\left(\tan^{-1}_* \frac{\sqrt{\left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t\_0\right) \cdot t\_0 + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}}}{\sqrt{\frac{\left(\cos \left(\phi_1 - \phi_2\right) + 1\right) - \left(\cos \left(\phi_2 + \phi_1\right) + \cos \left(\phi_2 - \phi_1\right)\right) \cdot \mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right)}{2}}} \cdot 2\right) \cdot R
\end{array}
\end{array}
Initial program 66.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6467.6
Applied rewrites67.6%
Applied rewrites68.1%
Final simplification68.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (sin (/ (- lambda1 lambda2) 2.0))))
(*
(*
(atan2
(sqrt
(+
(* (* (* (cos phi2) (cos phi1)) t_0) t_0)
(pow
(-
(* (cos (* phi2 0.5)) (sin (* 0.5 phi1)))
(* (sin (* phi2 0.5)) (cos (* 0.5 phi1))))
2.0)))
(sqrt
(fma
(fma -0.5 (cos (- lambda1 lambda2)) 0.5)
(* (- (cos phi1)) (cos phi2))
(fma (cos (- phi1 phi2)) 0.5 0.5))))
2.0)
R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(((lambda1 - lambda2) / 2.0));
return (atan2(sqrt(((((cos(phi2) * cos(phi1)) * t_0) * t_0) + pow(((cos((phi2 * 0.5)) * sin((0.5 * phi1))) - (sin((phi2 * 0.5)) * cos((0.5 * phi1)))), 2.0))), sqrt(fma(fma(-0.5, cos((lambda1 - lambda2)), 0.5), (-cos(phi1) * cos(phi2)), fma(cos((phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(Float64(Float64(lambda1 - lambda2) / 2.0)) return Float64(Float64(atan(sqrt(Float64(Float64(Float64(Float64(cos(phi2) * cos(phi1)) * t_0) * t_0) + (Float64(Float64(cos(Float64(phi2 * 0.5)) * sin(Float64(0.5 * phi1))) - Float64(sin(Float64(phi2 * 0.5)) * cos(Float64(0.5 * phi1)))) ^ 2.0))), sqrt(fma(fma(-0.5, cos(Float64(lambda1 - lambda2)), 0.5), Float64(Float64(-cos(phi1)) * cos(phi2)), fma(cos(Float64(phi1 - phi2)), 0.5, 0.5)))) * 2.0) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[ArcTan[N[Sqrt[N[(N[(N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] + N[Power[N[(N[(N[Cos[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[N[(phi2 * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(-0.5 * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] + 0.5), $MachinePrecision] * N[((-N[Cos[phi1], $MachinePrecision]) * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\frac{\lambda_1 - \lambda_2}{2}\right)\\
\left(\tan^{-1}_* \frac{\sqrt{\left(\left(\cos \phi_2 \cdot \cos \phi_1\right) \cdot t\_0\right) \cdot t\_0 + {\left(\cos \left(\phi_2 \cdot 0.5\right) \cdot \sin \left(0.5 \cdot \phi_1\right) - \sin \left(\phi_2 \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \phi_1\right)\right)}^{2}}}{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, \cos \left(\lambda_1 - \lambda_2\right), 0.5\right), \left(-\cos \phi_1\right) \cdot \cos \phi_2, \mathsf{fma}\left(\cos \left(\phi_1 - \phi_2\right), 0.5, 0.5\right)\right)}} \cdot 2\right) \cdot R
\end{array}
\end{array}
Initial program 66.7%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6467.6
Applied rewrites67.6%
Applied rewrites67.8%
Final simplification67.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- phi2 phi1))))
(*
(* 2.0 R)
(atan2
(sqrt
(fma
(* (cos phi2) (cos phi1))
(pow (sin (* (- lambda1 lambda2) 0.5)) 2.0)
(pow (sin (* (- phi1 phi2) 0.5)) 2.0)))
(*
(sqrt 0.5)
(sqrt
(-
(+ t_0 1.0)
(*
(fma (cos (- lambda2 lambda1)) -0.5 0.5)
(+ (cos (+ phi2 phi1)) t_0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((phi2 - phi1));
return (2.0 * R) * atan2(sqrt(fma((cos(phi2) * cos(phi1)), pow(sin(((lambda1 - lambda2) * 0.5)), 2.0), pow(sin(((phi1 - phi2) * 0.5)), 2.0))), (sqrt(0.5) * sqrt(((t_0 + 1.0) - (fma(cos((lambda2 - lambda1)), -0.5, 0.5) * (cos((phi2 + phi1)) + t_0))))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(phi2 - phi1)) return Float64(Float64(2.0 * R) * atan(sqrt(fma(Float64(cos(phi2) * cos(phi1)), (sin(Float64(Float64(lambda1 - lambda2) * 0.5)) ^ 2.0), (sin(Float64(Float64(phi1 - phi2) * 0.5)) ^ 2.0))), Float64(sqrt(0.5) * sqrt(Float64(Float64(t_0 + 1.0) - Float64(fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5) * Float64(cos(Float64(phi2 + phi1)) + t_0))))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(phi2 - phi1), $MachinePrecision]], $MachinePrecision]}, N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] * N[Power[N[Sin[N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[Sqrt[0.5], $MachinePrecision] * N[Sqrt[N[(N[(t$95$0 + 1.0), $MachinePrecision] - N[(N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * N[(N[Cos[N[(phi2 + phi1), $MachinePrecision]], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\phi_2 - \phi_1\right)\\
\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\cos \phi_2 \cdot \cos \phi_1, {\sin \left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right)}^{2}, {\sin \left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right)}^{2}\right)}}{\sqrt{0.5} \cdot \sqrt{\left(t\_0 + 1\right) - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right) \cdot \left(\cos \left(\phi_2 + \phi_1\right) + t\_0\right)}}
\end{array}
\end{array}
Initial program 66.7%
Taylor expanded in phi2 around 0
lower-sin.f64N/A
*-commutativeN/A
lower-*.f6443.2
Applied rewrites43.2%
Applied rewrites43.6%
Taylor expanded in lambda1 around 0
Applied rewrites67.1%
Final simplification67.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (- lambda1 lambda2) 0.5))
(t_1 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
(t_2
(sqrt
(fma
(- 0.5 (* (cos (* t_0 2.0)) 0.5))
(* (cos phi2) (cos phi1))
(- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))))
(if (<= phi2 -950000.0)
(*
(* 2.0 R)
(atan2
t_2
(sqrt
(-
0.5
(* (- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5) (cos phi2))))))
(if (<= phi2 1.4e-7)
(*
(*
(atan2
(sqrt
(fma (pow (sin t_0) 2.0) (cos phi1) (pow (sin (* 0.5 phi1)) 2.0)))
(sqrt (fma (cos phi1) (- 0.5 t_1) 0.5)))
2.0)
R)
(*
(atan2 t_2 (sqrt (- (fma (cos phi2) 0.5 0.5) (* t_1 (cos phi2)))))
(* 2.0 R))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * 0.5;
double t_1 = fma(cos((lambda2 - lambda1)), -0.5, 0.5);
double t_2 = sqrt(fma((0.5 - (cos((t_0 * 2.0)) * 0.5)), (cos(phi2) * cos(phi1)), (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5))));
double tmp;
if (phi2 <= -950000.0) {
tmp = (2.0 * R) * atan2(t_2, sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi2)))));
} else if (phi2 <= 1.4e-7) {
tmp = (atan2(sqrt(fma(pow(sin(t_0), 2.0), cos(phi1), pow(sin((0.5 * phi1)), 2.0))), sqrt(fma(cos(phi1), (0.5 - t_1), 0.5))) * 2.0) * R;
} else {
tmp = atan2(t_2, sqrt((fma(cos(phi2), 0.5, 0.5) - (t_1 * cos(phi2))))) * (2.0 * R);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda1 - lambda2) * 0.5) t_1 = fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5) t_2 = sqrt(fma(Float64(0.5 - Float64(cos(Float64(t_0 * 2.0)) * 0.5)), Float64(cos(phi2) * cos(phi1)), Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))) tmp = 0.0 if (phi2 <= -950000.0) tmp = Float64(Float64(2.0 * R) * atan(t_2, sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi2)))))); elseif (phi2 <= 1.4e-7) tmp = Float64(Float64(atan(sqrt(fma((sin(t_0) ^ 2.0), cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(fma(cos(phi1), Float64(0.5 - t_1), 0.5))) * 2.0) * R); else tmp = Float64(atan(t_2, sqrt(Float64(fma(cos(phi2), 0.5, 0.5) - Float64(t_1 * cos(phi2))))) * Float64(2.0 * R)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(t$95$0 * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -950000.0], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[t$95$2 / N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 1.4e-7], N[(N[(N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(0.5 - t$95$1), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], N[(N[ArcTan[t$95$2 / N[Sqrt[N[(N[(N[Cos[phi2], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision] - N[(t$95$1 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot 0.5\\
t_1 := \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right)\\
t_2 := \sqrt{\mathsf{fma}\left(0.5 - \cos \left(t\_0 \cdot 2\right) \cdot 0.5, \cos \phi_2 \cdot \cos \phi_1, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}\\
\mathbf{if}\;\phi_2 \leq -950000:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{t\_2}{\sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_2}}\\
\mathbf{elif}\;\phi_2 \leq 1.4 \cdot 10^{-7}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin t\_0}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{\mathsf{fma}\left(\cos \phi_1, 0.5 - t\_1, 0.5\right)}} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_2}{\sqrt{\mathsf{fma}\left(\cos \phi_2, 0.5, 0.5\right) - t\_1 \cdot \cos \phi_2}} \cdot \left(2 \cdot R\right)\\
\end{array}
\end{array}
if phi2 < -9.5e5Initial program 55.3%
Applied rewrites55.6%
Taylor expanded in phi1 around 0
associate--l+N/A
lower-+.f64N/A
cos-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6456.4
Applied rewrites56.4%
if -9.5e5 < phi2 < 1.4000000000000001e-7Initial program 76.8%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6476.9
Applied rewrites76.9%
Applied rewrites77.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in phi2 around 0
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
cancel-sign-sub-invN/A
sub-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-fma.f64N/A
Applied rewrites76.2%
if 1.4000000000000001e-7 < phi2 Initial program 59.0%
Applied rewrites58.8%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6422.1
Applied rewrites22.1%
Taylor expanded in phi1 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
+-commutativeN/A
cos-negN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites59.8%
Final simplification66.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (- lambda1 lambda2) 0.5))
(t_1
(*
(* 2.0 R)
(atan2
(sqrt
(fma
(- 0.5 (* (cos (* t_0 2.0)) 0.5))
(* (cos phi2) (cos phi1))
(- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))
(sqrt
(-
0.5
(*
(- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5)
(cos phi2))))))))
(if (<= phi2 -950000.0)
t_1
(if (<= phi2 1.4e-7)
(*
(*
(atan2
(sqrt
(fma (pow (sin t_0) 2.0) (cos phi1) (pow (sin (* 0.5 phi1)) 2.0)))
(sqrt
(fma
(cos phi1)
(- 0.5 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
0.5)))
2.0)
R)
t_1))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (lambda1 - lambda2) * 0.5;
double t_1 = (2.0 * R) * atan2(sqrt(fma((0.5 - (cos((t_0 * 2.0)) * 0.5)), (cos(phi2) * cos(phi1)), (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi2)))));
double tmp;
if (phi2 <= -950000.0) {
tmp = t_1;
} else if (phi2 <= 1.4e-7) {
tmp = (atan2(sqrt(fma(pow(sin(t_0), 2.0), cos(phi1), pow(sin((0.5 * phi1)), 2.0))), sqrt(fma(cos(phi1), (0.5 - fma(cos((lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * 2.0) * R;
} else {
tmp = t_1;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(lambda1 - lambda2) * 0.5) t_1 = Float64(Float64(2.0 * R) * atan(sqrt(fma(Float64(0.5 - Float64(cos(Float64(t_0 * 2.0)) * 0.5)), Float64(cos(phi2) * cos(phi1)), Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi2)))))) tmp = 0.0 if (phi2 <= -950000.0) tmp = t_1; elseif (phi2 <= 1.4e-7) tmp = Float64(Float64(atan(sqrt(fma((sin(t_0) ^ 2.0), cos(phi1), (sin(Float64(0.5 * phi1)) ^ 2.0))), sqrt(fma(cos(phi1), Float64(0.5 - fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * 2.0) * R); else tmp = t_1; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(t$95$0 * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -950000.0], t$95$1, If[LessEqual[phi2, 1.4e-7], N[(N[(N[ArcTan[N[Sqrt[N[(N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + N[Power[N[Sin[N[(0.5 * phi1), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[phi1], $MachinePrecision] * N[(0.5 - N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * R), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\lambda_1 - \lambda_2\right) \cdot 0.5\\
t_1 := \left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(0.5 - \cos \left(t\_0 \cdot 2\right) \cdot 0.5, \cos \phi_2 \cdot \cos \phi_1, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}}{\sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_2}}\\
\mathbf{if}\;\phi_2 \leq -950000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;\phi_2 \leq 1.4 \cdot 10^{-7}:\\
\;\;\;\;\left(\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left({\sin t\_0}^{2}, \cos \phi_1, {\sin \left(0.5 \cdot \phi_1\right)}^{2}\right)}}{\sqrt{\mathsf{fma}\left(\cos \phi_1, 0.5 - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right), 0.5\right)}} \cdot 2\right) \cdot R\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if phi2 < -9.5e5 or 1.4000000000000001e-7 < phi2 Initial program 57.3%
Applied rewrites57.3%
Taylor expanded in phi1 around 0
associate--l+N/A
lower-+.f64N/A
cos-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6458.2
Applied rewrites58.2%
if -9.5e5 < phi2 < 1.4000000000000001e-7Initial program 76.8%
lift-sin.f64N/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sin-diffN/A
lower--.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lower-sin.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6476.9
Applied rewrites76.9%
Applied rewrites77.0%
Taylor expanded in phi2 around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-cos.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in phi2 around 0
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
cancel-sign-sub-invN/A
sub-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-fma.f64N/A
Applied rewrites76.2%
Final simplification66.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5)))
(t_2 (cos (- lambda1 lambda2)))
(t_3 (- (- 0.5 (* t_2 0.5)) 0.5))
(t_4
(*
(atan2
(sqrt (fma (fma -0.5 t_2 0.5) t_0 t_1))
(sqrt (- 0.5 (* t_3 (cos phi1)))))
(* 2.0 R))))
(if (<= phi1 -820000000.0)
t_4
(if (<= phi1 5.4e+39)
(*
(* 2.0 R)
(atan2
(sqrt
(fma
(- 0.5 (* (cos (* (* (- lambda1 lambda2) 0.5) 2.0)) 0.5))
t_0
t_1))
(sqrt (- 0.5 (* t_3 (cos phi2))))))
t_4))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = 0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5);
double t_2 = cos((lambda1 - lambda2));
double t_3 = (0.5 - (t_2 * 0.5)) - 0.5;
double t_4 = atan2(sqrt(fma(fma(-0.5, t_2, 0.5), t_0, t_1)), sqrt((0.5 - (t_3 * cos(phi1))))) * (2.0 * R);
double tmp;
if (phi1 <= -820000000.0) {
tmp = t_4;
} else if (phi1 <= 5.4e+39) {
tmp = (2.0 * R) * atan2(sqrt(fma((0.5 - (cos((((lambda1 - lambda2) * 0.5) * 2.0)) * 0.5)), t_0, t_1)), sqrt((0.5 - (t_3 * cos(phi2)))));
} else {
tmp = t_4;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)) t_2 = cos(Float64(lambda1 - lambda2)) t_3 = Float64(Float64(0.5 - Float64(t_2 * 0.5)) - 0.5) t_4 = Float64(atan(sqrt(fma(fma(-0.5, t_2, 0.5), t_0, t_1)), sqrt(Float64(0.5 - Float64(t_3 * cos(phi1))))) * Float64(2.0 * R)) tmp = 0.0 if (phi1 <= -820000000.0) tmp = t_4; elseif (phi1 <= 5.4e+39) tmp = Float64(Float64(2.0 * R) * atan(sqrt(fma(Float64(0.5 - Float64(cos(Float64(Float64(Float64(lambda1 - lambda2) * 0.5) * 2.0)) * 0.5)), t_0, t_1)), sqrt(Float64(0.5 - Float64(t_3 * cos(phi2)))))); else tmp = t_4; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(0.5 - N[(t$95$2 * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]}, Block[{t$95$4 = N[(N[ArcTan[N[Sqrt[N[(N[(-0.5 * t$95$2 + 0.5), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(t$95$3 * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -820000000.0], t$95$4, If[LessEqual[phi1, 5.4e+39], N[(N[(2.0 * R), $MachinePrecision] * N[ArcTan[N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(N[(N[(lambda1 - lambda2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(t$95$3 * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$4]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\\
t_2 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_3 := \left(0.5 - t\_2 \cdot 0.5\right) - 0.5\\
t_4 := \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, t\_2, 0.5\right), t\_0, t\_1\right)}}{\sqrt{0.5 - t\_3 \cdot \cos \phi_1}} \cdot \left(2 \cdot R\right)\\
\mathbf{if}\;\phi_1 \leq -820000000:\\
\;\;\;\;t\_4\\
\mathbf{elif}\;\phi_1 \leq 5.4 \cdot 10^{+39}:\\
\;\;\;\;\left(2 \cdot R\right) \cdot \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(0.5 - \cos \left(\left(\left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5, t\_0, t\_1\right)}}{\sqrt{0.5 - t\_3 \cdot \cos \phi_2}}\\
\mathbf{else}:\\
\;\;\;\;t\_4\\
\end{array}
\end{array}
if phi1 < -8.2e8 or 5.40000000000000007e39 < phi1 Initial program 54.2%
Applied rewrites54.0%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6455.0
Applied rewrites55.0%
lift--.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lift-cos.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
lift-fma.f6455.0
Applied rewrites55.0%
if -8.2e8 < phi1 < 5.40000000000000007e39Initial program 76.0%
Applied rewrites68.2%
Taylor expanded in phi1 around 0
associate--l+N/A
lower-+.f64N/A
cos-negN/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6468.3
Applied rewrites68.3%
Final simplification62.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5)))
(t_2
(*
(atan2
(sqrt (fma (fma (cos lambda1) -0.5 0.5) t_0 t_1))
(sqrt
(fma
(cos phi2)
(- 0.5 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
0.5)))
(* 2.0 R)))
(t_3 (cos (- lambda1 lambda2))))
(if (<= phi2 -950000.0)
t_2
(if (<= phi2 0.00105)
(*
(atan2
(sqrt (fma (fma -0.5 t_3 0.5) t_0 t_1))
(sqrt (- 0.5 (* (- (- 0.5 (* t_3 0.5)) 0.5) (cos phi1)))))
(* 2.0 R))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = 0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5);
double t_2 = atan2(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), t_0, t_1)), sqrt(fma(cos(phi2), (0.5 - fma(cos((lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * (2.0 * R);
double t_3 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= -950000.0) {
tmp = t_2;
} else if (phi2 <= 0.00105) {
tmp = atan2(sqrt(fma(fma(-0.5, t_3, 0.5), t_0, t_1)), sqrt((0.5 - (((0.5 - (t_3 * 0.5)) - 0.5) * cos(phi1))))) * (2.0 * R);
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)) t_2 = Float64(atan(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), t_0, t_1)), sqrt(fma(cos(phi2), Float64(0.5 - fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * Float64(2.0 * R)) t_3 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= -950000.0) tmp = t_2; elseif (phi2 <= 0.00105) tmp = Float64(atan(sqrt(fma(fma(-0.5, t_3, 0.5), t_0, t_1)), sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(t_3 * 0.5)) - 0.5) * cos(phi1))))) * Float64(2.0 * R)); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[ArcTan[N[Sqrt[N[(N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * N[(0.5 - N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -950000.0], t$95$2, If[LessEqual[phi2, 0.00105], N[(N[ArcTan[N[Sqrt[N[(N[(-0.5 * t$95$3 + 0.5), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(t$95$3 * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\\
t_2 := \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right), t\_0, t\_1\right)}}{\sqrt{\mathsf{fma}\left(\cos \phi_2, 0.5 - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right), 0.5\right)}} \cdot \left(2 \cdot R\right)\\
t_3 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -950000:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_2 \leq 0.00105:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(-0.5, t\_3, 0.5\right), t\_0, t\_1\right)}}{\sqrt{0.5 - \left(\left(0.5 - t\_3 \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_1}} \cdot \left(2 \cdot R\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi2 < -9.5e5 or 0.00104999999999999994 < phi2 Initial program 57.3%
Applied rewrites57.3%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6420.8
Applied rewrites20.8%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6420.8
Applied rewrites20.8%
Taylor expanded in phi1 around 0
sub-negN/A
cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
associate-+r+N/A
+-commutativeN/A
+-commutativeN/A
Applied rewrites43.0%
if -9.5e5 < phi2 < 0.00104999999999999994Initial program 76.8%
Applied rewrites67.3%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6467.4
Applied rewrites67.4%
lift--.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lift-cos.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
lift-fma.f6467.4
Applied rewrites67.4%
Final simplification54.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5)))
(t_2
(sqrt
(-
0.5
(* (- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5) (cos phi1)))))
(t_3 (sqrt (fma (fma (cos lambda1) -0.5 0.5) t_0 t_1))))
(if (<= phi1 -4.35e-35)
(*
(atan2 (sqrt (fma (fma (cos lambda2) -0.5 0.5) t_0 t_1)) t_2)
(* 2.0 R))
(if (<= phi1 4.8e-8)
(*
(atan2
t_3
(sqrt
(fma
(cos phi2)
(- 0.5 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
0.5)))
(* 2.0 R))
(* (atan2 t_3 t_2) (* 2.0 R))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = 0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5);
double t_2 = sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))));
double t_3 = sqrt(fma(fma(cos(lambda1), -0.5, 0.5), t_0, t_1));
double tmp;
if (phi1 <= -4.35e-35) {
tmp = atan2(sqrt(fma(fma(cos(lambda2), -0.5, 0.5), t_0, t_1)), t_2) * (2.0 * R);
} else if (phi1 <= 4.8e-8) {
tmp = atan2(t_3, sqrt(fma(cos(phi2), (0.5 - fma(cos((lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * (2.0 * R);
} else {
tmp = atan2(t_3, t_2) * (2.0 * R);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)) t_2 = sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1)))) t_3 = sqrt(fma(fma(cos(lambda1), -0.5, 0.5), t_0, t_1)) tmp = 0.0 if (phi1 <= -4.35e-35) tmp = Float64(atan(sqrt(fma(fma(cos(lambda2), -0.5, 0.5), t_0, t_1)), t_2) * Float64(2.0 * R)); elseif (phi1 <= 4.8e-8) tmp = Float64(atan(t_3, sqrt(fma(cos(phi2), Float64(0.5 - fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * Float64(2.0 * R)); else tmp = Float64(atan(t_3, t_2) * Float64(2.0 * R)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -4.35e-35], N[(N[ArcTan[N[Sqrt[N[(N[(N[Cos[lambda2], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision] / t$95$2], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 4.8e-8], N[(N[ArcTan[t$95$3 / N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * N[(0.5 - N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], N[(N[ArcTan[t$95$3 / t$95$2], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\\
t_2 := \sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_1}\\
t_3 := \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right), t\_0, t\_1\right)}\\
\mathbf{if}\;\phi_1 \leq -4.35 \cdot 10^{-35}:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_2, -0.5, 0.5\right), t\_0, t\_1\right)}}{t\_2} \cdot \left(2 \cdot R\right)\\
\mathbf{elif}\;\phi_1 \leq 4.8 \cdot 10^{-8}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_3}{\sqrt{\mathsf{fma}\left(\cos \phi_2, 0.5 - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right), 0.5\right)}} \cdot \left(2 \cdot R\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_3}{t\_2} \cdot \left(2 \cdot R\right)\\
\end{array}
\end{array}
if phi1 < -4.34999999999999976e-35Initial program 55.5%
Applied rewrites53.9%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6452.6
Applied rewrites52.6%
Taylor expanded in lambda1 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
cos-negN/A
lower-cos.f6445.9
Applied rewrites45.9%
if -4.34999999999999976e-35 < phi1 < 4.79999999999999997e-8Initial program 79.6%
Applied rewrites71.6%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6435.3
Applied rewrites35.3%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6427.1
Applied rewrites27.1%
Taylor expanded in phi1 around 0
sub-negN/A
cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
associate-+r+N/A
+-commutativeN/A
+-commutativeN/A
Applied rewrites48.6%
if 4.79999999999999997e-8 < phi1 Initial program 50.3%
Applied rewrites50.1%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6450.8
Applied rewrites50.8%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6442.1
Applied rewrites42.1%
Final simplification46.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1
(sqrt
(-
0.5
(* (- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5) (cos phi1)))))
(t_2 (fma (cos lambda1) -0.5 0.5))
(t_3
(sqrt
(fma t_2 t_0 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))))
(if (<= phi1 -820000000.0)
(* (atan2 (sqrt (fma t_2 t_0 (- 0.5 (* (cos phi1) 0.5)))) t_1) (* 2.0 R))
(if (<= phi1 4.8e-8)
(*
(atan2
t_3
(sqrt
(fma
(cos phi2)
(- 0.5 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
0.5)))
(* 2.0 R))
(* (atan2 t_3 t_1) (* 2.0 R))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))));
double t_2 = fma(cos(lambda1), -0.5, 0.5);
double t_3 = sqrt(fma(t_2, t_0, (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5))));
double tmp;
if (phi1 <= -820000000.0) {
tmp = atan2(sqrt(fma(t_2, t_0, (0.5 - (cos(phi1) * 0.5)))), t_1) * (2.0 * R);
} else if (phi1 <= 4.8e-8) {
tmp = atan2(t_3, sqrt(fma(cos(phi2), (0.5 - fma(cos((lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * (2.0 * R);
} else {
tmp = atan2(t_3, t_1) * (2.0 * R);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1)))) t_2 = fma(cos(lambda1), -0.5, 0.5) t_3 = sqrt(fma(t_2, t_0, Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))) tmp = 0.0 if (phi1 <= -820000000.0) tmp = Float64(atan(sqrt(fma(t_2, t_0, Float64(0.5 - Float64(cos(phi1) * 0.5)))), t_1) * Float64(2.0 * R)); elseif (phi1 <= 4.8e-8) tmp = Float64(atan(t_3, sqrt(fma(cos(phi2), Float64(0.5 - fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * Float64(2.0 * R)); else tmp = Float64(atan(t_3, t_1) * Float64(2.0 * R)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(t$95$2 * t$95$0 + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -820000000.0], N[(N[ArcTan[N[Sqrt[N[(t$95$2 * t$95$0 + N[(0.5 - N[(N[Cos[phi1], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$1], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 4.8e-8], N[(N[ArcTan[t$95$3 / N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * N[(0.5 - N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], N[(N[ArcTan[t$95$3 / t$95$1], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_1}\\
t_2 := \mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right)\\
t_3 := \sqrt{\mathsf{fma}\left(t\_2, t\_0, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}\\
\mathbf{if}\;\phi_1 \leq -820000000:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_2, t\_0, 0.5 - \cos \phi_1 \cdot 0.5\right)}}{t\_1} \cdot \left(2 \cdot R\right)\\
\mathbf{elif}\;\phi_1 \leq 4.8 \cdot 10^{-8}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_3}{\sqrt{\mathsf{fma}\left(\cos \phi_2, 0.5 - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right), 0.5\right)}} \cdot \left(2 \cdot R\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{t\_3}{t\_1} \cdot \left(2 \cdot R\right)\\
\end{array}
\end{array}
if phi1 < -8.2e8Initial program 53.9%
Applied rewrites53.7%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6454.9
Applied rewrites54.9%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6442.5
Applied rewrites42.5%
Taylor expanded in phi2 around 0
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6442.7
Applied rewrites42.7%
if -8.2e8 < phi1 < 4.79999999999999997e-8Initial program 78.8%
Applied rewrites70.5%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6435.4
Applied rewrites35.4%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6426.3
Applied rewrites26.3%
Taylor expanded in phi1 around 0
sub-negN/A
cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
associate-+r+N/A
+-commutativeN/A
+-commutativeN/A
Applied rewrites47.3%
if 4.79999999999999997e-8 < phi1 Initial program 50.3%
Applied rewrites50.1%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6450.8
Applied rewrites50.8%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6442.1
Applied rewrites42.1%
Final simplification45.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (fma (cos lambda1) -0.5 0.5))
(t_2
(*
(atan2
(sqrt
(fma t_1 t_0 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))
(sqrt
(fma
(cos phi2)
(- 0.5 (fma (cos (- lambda2 lambda1)) -0.5 0.5))
0.5)))
(* 2.0 R))))
(if (<= phi2 -950000.0)
t_2
(if (<= phi2 1.4e-7)
(*
(atan2
(sqrt (fma t_1 t_0 (- 0.5 (* (cos phi1) 0.5))))
(sqrt
(-
0.5
(* (- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5) (cos phi1)))))
(* 2.0 R))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = fma(cos(lambda1), -0.5, 0.5);
double t_2 = atan2(sqrt(fma(t_1, t_0, (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos(phi2), (0.5 - fma(cos((lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * (2.0 * R);
double tmp;
if (phi2 <= -950000.0) {
tmp = t_2;
} else if (phi2 <= 1.4e-7) {
tmp = atan2(sqrt(fma(t_1, t_0, (0.5 - (cos(phi1) * 0.5)))), sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))))) * (2.0 * R);
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = fma(cos(lambda1), -0.5, 0.5) t_2 = Float64(atan(sqrt(fma(t_1, t_0, Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos(phi2), Float64(0.5 - fma(cos(Float64(lambda2 - lambda1)), -0.5, 0.5)), 0.5))) * Float64(2.0 * R)) tmp = 0.0 if (phi2 <= -950000.0) tmp = t_2; elseif (phi2 <= 1.4e-7) tmp = Float64(atan(sqrt(fma(t_1, t_0, Float64(0.5 - Float64(cos(phi1) * 0.5)))), sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))))) * Float64(2.0 * R)); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]}, Block[{t$95$2 = N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[phi2], $MachinePrecision] * N[(0.5 - N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -950000.0], t$95$2, If[LessEqual[phi2, 1.4e-7], N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[(0.5 - N[(N[Cos[phi1], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right)\\
t_2 := \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(\cos \phi_2, 0.5 - \mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), -0.5, 0.5\right), 0.5\right)}} \cdot \left(2 \cdot R\right)\\
\mathbf{if}\;\phi_2 \leq -950000:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_2 \leq 1.4 \cdot 10^{-7}:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, 0.5 - \cos \phi_1 \cdot 0.5\right)}}{\sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_1}} \cdot \left(2 \cdot R\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi2 < -9.5e5 or 1.4000000000000001e-7 < phi2 Initial program 57.3%
Applied rewrites57.3%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6420.8
Applied rewrites20.8%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6420.8
Applied rewrites20.8%
Taylor expanded in phi1 around 0
sub-negN/A
cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
associate-+r+N/A
+-commutativeN/A
+-commutativeN/A
Applied rewrites43.0%
if -9.5e5 < phi2 < 1.4000000000000001e-7Initial program 76.8%
Applied rewrites67.3%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6467.4
Applied rewrites67.4%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6447.2
Applied rewrites47.2%
Taylor expanded in phi2 around 0
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6447.2
Applied rewrites47.2%
Final simplification45.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (fma (cos lambda1) -0.5 0.5))
(t_2
(sqrt
(-
0.5
(* (- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5) (cos phi1))))))
(if (<= phi2 -1.65e-7)
(*
(atan2
(sqrt (fma t_1 t_0 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))
(sqrt (fma (cos (- lambda2 lambda1)) 0.5 0.5)))
(* 2.0 R))
(if (<= phi2 0.125)
(*
(atan2 (sqrt (fma t_1 t_0 (- 0.5 (* (cos phi1) 0.5)))) t_2)
(* 2.0 R))
(*
(atan2 (sqrt (fma t_1 t_0 (- 0.5 (* (cos phi2) 0.5)))) t_2)
(* 2.0 R))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = fma(cos(lambda1), -0.5, 0.5);
double t_2 = sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))));
double tmp;
if (phi2 <= -1.65e-7) {
tmp = atan2(sqrt(fma(t_1, t_0, (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos((lambda2 - lambda1)), 0.5, 0.5))) * (2.0 * R);
} else if (phi2 <= 0.125) {
tmp = atan2(sqrt(fma(t_1, t_0, (0.5 - (cos(phi1) * 0.5)))), t_2) * (2.0 * R);
} else {
tmp = atan2(sqrt(fma(t_1, t_0, (0.5 - (cos(phi2) * 0.5)))), t_2) * (2.0 * R);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = fma(cos(lambda1), -0.5, 0.5) t_2 = sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1)))) tmp = 0.0 if (phi2 <= -1.65e-7) tmp = Float64(atan(sqrt(fma(t_1, t_0, Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos(Float64(lambda2 - lambda1)), 0.5, 0.5))) * Float64(2.0 * R)); elseif (phi2 <= 0.125) tmp = Float64(atan(sqrt(fma(t_1, t_0, Float64(0.5 - Float64(cos(phi1) * 0.5)))), t_2) * Float64(2.0 * R)); else tmp = Float64(atan(sqrt(fma(t_1, t_0, Float64(0.5 - Float64(cos(phi2) * 0.5)))), t_2) * Float64(2.0 * R)); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -1.65e-7], N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 0.125], N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[(0.5 - N[(N[Cos[phi1], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$2], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[(0.5 - N[(N[Cos[phi2], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$2], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right)\\
t_2 := \sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_1}\\
\mathbf{if}\;\phi_2 \leq -1.65 \cdot 10^{-7}:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), 0.5, 0.5\right)}} \cdot \left(2 \cdot R\right)\\
\mathbf{elif}\;\phi_2 \leq 0.125:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, 0.5 - \cos \phi_1 \cdot 0.5\right)}}{t\_2} \cdot \left(2 \cdot R\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, 0.5 - \cos \phi_2 \cdot 0.5\right)}}{t\_2} \cdot \left(2 \cdot R\right)\\
\end{array}
\end{array}
if phi2 < -1.6500000000000001e-7Initial program 54.8%
Applied rewrites55.0%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6419.3
Applied rewrites19.3%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6419.9
Applied rewrites19.9%
Taylor expanded in phi1 around 0
Applied rewrites20.1%
if -1.6500000000000001e-7 < phi2 < 0.125Initial program 77.3%
Applied rewrites67.7%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6467.7
Applied rewrites67.7%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6447.4
Applied rewrites47.4%
Taylor expanded in phi2 around 0
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6447.4
Applied rewrites47.4%
if 0.125 < phi2 Initial program 59.0%
Applied rewrites58.8%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6422.1
Applied rewrites22.1%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6421.7
Applied rewrites21.7%
Taylor expanded in phi1 around 0
lower--.f64N/A
cos-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6421.9
Applied rewrites21.9%
Final simplification33.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (fma (cos lambda1) -0.5 0.5))
(t_2
(*
(atan2
(sqrt
(fma t_1 t_0 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))
(sqrt (fma (cos (- lambda2 lambda1)) 0.5 0.5)))
(* 2.0 R))))
(if (<= phi2 -1.65e-7)
t_2
(if (<= phi2 1.4e-7)
(*
(atan2
(sqrt (fma t_1 t_0 (- 0.5 (* (cos phi1) 0.5))))
(sqrt
(-
0.5
(* (- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5) (cos phi1)))))
(* 2.0 R))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = fma(cos(lambda1), -0.5, 0.5);
double t_2 = atan2(sqrt(fma(t_1, t_0, (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos((lambda2 - lambda1)), 0.5, 0.5))) * (2.0 * R);
double tmp;
if (phi2 <= -1.65e-7) {
tmp = t_2;
} else if (phi2 <= 1.4e-7) {
tmp = atan2(sqrt(fma(t_1, t_0, (0.5 - (cos(phi1) * 0.5)))), sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))))) * (2.0 * R);
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = fma(cos(lambda1), -0.5, 0.5) t_2 = Float64(atan(sqrt(fma(t_1, t_0, Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos(Float64(lambda2 - lambda1)), 0.5, 0.5))) * Float64(2.0 * R)) tmp = 0.0 if (phi2 <= -1.65e-7) tmp = t_2; elseif (phi2 <= 1.4e-7) tmp = Float64(atan(sqrt(fma(t_1, t_0, Float64(0.5 - Float64(cos(phi1) * 0.5)))), sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))))) * Float64(2.0 * R)); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]}, Block[{t$95$2 = N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -1.65e-7], t$95$2, If[LessEqual[phi2, 1.4e-7], N[(N[ArcTan[N[Sqrt[N[(t$95$1 * t$95$0 + N[(0.5 - N[(N[Cos[phi1], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := \mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right)\\
t_2 := \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), 0.5, 0.5\right)}} \cdot \left(2 \cdot R\right)\\
\mathbf{if}\;\phi_2 \leq -1.65 \cdot 10^{-7}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\phi_2 \leq 1.4 \cdot 10^{-7}:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(t\_1, t\_0, 0.5 - \cos \phi_1 \cdot 0.5\right)}}{\sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_1}} \cdot \left(2 \cdot R\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if phi2 < -1.6500000000000001e-7 or 1.4000000000000001e-7 < phi2 Initial program 57.0%
Applied rewrites57.0%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6420.8
Applied rewrites20.8%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6420.8
Applied rewrites20.8%
Taylor expanded in phi1 around 0
Applied rewrites20.9%
if -1.6500000000000001e-7 < phi2 < 1.4000000000000001e-7Initial program 77.3%
Applied rewrites67.7%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6467.7
Applied rewrites67.7%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6447.4
Applied rewrites47.4%
Taylor expanded in phi2 around 0
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6447.4
Applied rewrites47.4%
Final simplification33.6%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(atan2
(sqrt
(fma
(fma (cos lambda1) -0.5 0.5)
(* (cos phi2) (cos phi1))
(- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))
(sqrt (+ (* (* (cos lambda1) 0.5) (cos phi1)) 0.5)))
(* 2.0 R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return atan2(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), (cos(phi2) * cos(phi1)), (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt((((cos(lambda1) * 0.5) * cos(phi1)) + 0.5))) * (2.0 * R);
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(atan(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), Float64(cos(phi2) * cos(phi1)), Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(Float64(Float64(Float64(cos(lambda1) * 0.5) * cos(phi1)) + 0.5))) * Float64(2.0 * R)) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcTan[N[Sqrt[N[(N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[(N[Cos[lambda1], $MachinePrecision] * 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right), \cos \phi_2 \cdot \cos \phi_1, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}}{\sqrt{\left(\cos \lambda_1 \cdot 0.5\right) \cdot \cos \phi_1 + 0.5}} \cdot \left(2 \cdot R\right)
\end{array}
Initial program 66.7%
Applied rewrites62.1%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6443.3
Applied rewrites43.3%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6433.6
Applied rewrites33.6%
Taylor expanded in lambda2 around 0
Applied rewrites33.4%
Final simplification33.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(atan2
(sqrt
(fma
(fma (cos lambda1) -0.5 0.5)
(* (cos phi2) (cos phi1))
(- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))
(sqrt (fma (* (cos lambda1) 0.5) (cos phi1) 0.5)))
(* 2.0 R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return atan2(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), (cos(phi2) * cos(phi1)), (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma((cos(lambda1) * 0.5), cos(phi1), 0.5))) * (2.0 * R);
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(atan(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), Float64(cos(phi2) * cos(phi1)), Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(Float64(cos(lambda1) * 0.5), cos(phi1), 0.5))) * Float64(2.0 * R)) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcTan[N[Sqrt[N[(N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(N[Cos[lambda1], $MachinePrecision] * 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right), \cos \phi_2 \cdot \cos \phi_1, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(\cos \lambda_1 \cdot 0.5, \cos \phi_1, 0.5\right)}} \cdot \left(2 \cdot R\right)
\end{array}
Initial program 66.7%
Applied rewrites62.1%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6443.3
Applied rewrites43.3%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6433.6
Applied rewrites33.6%
Taylor expanded in lambda2 around 0
Applied rewrites33.4%
Final simplification33.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi2) (cos phi1)))
(t_1 (- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5)))
(t_2
(*
(atan2
(sqrt (fma (fma (cos lambda1) -0.5 0.5) t_0 t_1))
(sqrt (fma (cos (- lambda2 lambda1)) 0.5 0.5)))
(* 2.0 R))))
(if (<= lambda1 -7.8e-16)
t_2
(if (<= lambda1 0.06)
(*
(atan2
(sqrt (fma (* 0.25 (* lambda1 lambda1)) t_0 t_1))
(sqrt
(-
0.5
(* (- (- 0.5 (* (cos (- lambda1 lambda2)) 0.5)) 0.5) (cos phi1)))))
(* 2.0 R))
t_2))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi2) * cos(phi1);
double t_1 = 0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5);
double t_2 = atan2(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), t_0, t_1)), sqrt(fma(cos((lambda2 - lambda1)), 0.5, 0.5))) * (2.0 * R);
double tmp;
if (lambda1 <= -7.8e-16) {
tmp = t_2;
} else if (lambda1 <= 0.06) {
tmp = atan2(sqrt(fma((0.25 * (lambda1 * lambda1)), t_0, t_1)), sqrt((0.5 - (((0.5 - (cos((lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))))) * (2.0 * R);
} else {
tmp = t_2;
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi2) * cos(phi1)) t_1 = Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)) t_2 = Float64(atan(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), t_0, t_1)), sqrt(fma(cos(Float64(lambda2 - lambda1)), 0.5, 0.5))) * Float64(2.0 * R)) tmp = 0.0 if (lambda1 <= -7.8e-16) tmp = t_2; elseif (lambda1 <= 0.06) tmp = Float64(atan(sqrt(fma(Float64(0.25 * Float64(lambda1 * lambda1)), t_0, t_1)), sqrt(Float64(0.5 - Float64(Float64(Float64(0.5 - Float64(cos(Float64(lambda1 - lambda2)) * 0.5)) - 0.5) * cos(phi1))))) * Float64(2.0 * R)); else tmp = t_2; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[ArcTan[N[Sqrt[N[(N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -7.8e-16], t$95$2, If[LessEqual[lambda1, 0.06], N[(N[ArcTan[N[Sqrt[N[(N[(0.25 * N[(lambda1 * lambda1), $MachinePrecision]), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[(N[(0.5 - N[(N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_2 \cdot \cos \phi_1\\
t_1 := 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\\
t_2 := \tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right), t\_0, t\_1\right)}}{\sqrt{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), 0.5, 0.5\right)}} \cdot \left(2 \cdot R\right)\\
\mathbf{if}\;\lambda_1 \leq -7.8 \cdot 10^{-16}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\lambda_1 \leq 0.06:\\
\;\;\;\;\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(0.25 \cdot \left(\lambda_1 \cdot \lambda_1\right), t\_0, t\_1\right)}}{\sqrt{0.5 - \left(\left(0.5 - \cos \left(\lambda_1 - \lambda_2\right) \cdot 0.5\right) - 0.5\right) \cdot \cos \phi_1}} \cdot \left(2 \cdot R\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if lambda1 < -7.79999999999999954e-16 or 0.059999999999999998 < lambda1 Initial program 48.6%
Applied rewrites48.6%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6438.9
Applied rewrites38.9%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6438.5
Applied rewrites38.5%
Taylor expanded in phi1 around 0
Applied rewrites30.0%
if -7.79999999999999954e-16 < lambda1 < 0.059999999999999998Initial program 82.9%
Applied rewrites74.2%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6447.3
Applied rewrites47.3%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6429.2
Applied rewrites29.2%
Taylor expanded in lambda1 around 0
Applied rewrites31.7%
Final simplification30.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(atan2
(sqrt
(fma
(fma (cos lambda1) -0.5 0.5)
(* (cos phi2) (cos phi1))
(- 0.5 (* (cos (* (* (- phi1 phi2) 0.5) 2.0)) 0.5))))
(sqrt (fma (cos (- lambda2 lambda1)) 0.5 0.5)))
(* 2.0 R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return atan2(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), (cos(phi2) * cos(phi1)), (0.5 - (cos((((phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos((lambda2 - lambda1)), 0.5, 0.5))) * (2.0 * R);
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(atan(sqrt(fma(fma(cos(lambda1), -0.5, 0.5), Float64(cos(phi2) * cos(phi1)), Float64(0.5 - Float64(cos(Float64(Float64(Float64(phi1 - phi2) * 0.5) * 2.0)) * 0.5)))), sqrt(fma(cos(Float64(lambda2 - lambda1)), 0.5, 0.5))) * Float64(2.0 * R)) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcTan[N[Sqrt[N[(N[(N[Cos[lambda1], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[phi1], $MachinePrecision]), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(N[(N[(phi1 - phi2), $MachinePrecision] * 0.5), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(2.0 * R), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\cos \lambda_1, -0.5, 0.5\right), \cos \phi_2 \cdot \cos \phi_1, 0.5 - \cos \left(\left(\left(\phi_1 - \phi_2\right) \cdot 0.5\right) \cdot 2\right) \cdot 0.5\right)}}{\sqrt{\mathsf{fma}\left(\cos \left(\lambda_2 - \lambda_1\right), 0.5, 0.5\right)}} \cdot \left(2 \cdot R\right)
\end{array}
Initial program 66.7%
Applied rewrites62.1%
Taylor expanded in phi2 around 0
associate--l+N/A
lower-+.f64N/A
*-commutativeN/A
distribute-lft-out--N/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower--.f6443.3
Applied rewrites43.3%
Taylor expanded in lambda2 around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f6433.6
Applied rewrites33.6%
Taylor expanded in phi1 around 0
Applied rewrites23.9%
Final simplification23.9%
herbie shell --seed 2024240
(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))))))))))