
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(+
(* (sin phi1) (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 23 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
(acos
(+
(* (sin phi1) (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * r
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))))) * R;
}
def code(R, lambda1, lambda2, phi1, phi2): return math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))) * R
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) * R) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))) * R; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right) \cdot R
\end{array}
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2))))
(*
(acos
(fma
(sin phi1)
(sin phi2)
(+
(* t_0 (* (cos lambda1) (cos lambda2)))
(* t_0 (expm1 (log1p (* (sin lambda1) (sin lambda2))))))))
R)))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi1) * cos(phi2);
return acos(fma(sin(phi1), sin(phi2), ((t_0 * (cos(lambda1) * cos(lambda2))) + (t_0 * expm1(log1p((sin(lambda1) * sin(lambda2)))))))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) return Float64(acos(fma(sin(phi1), sin(phi2), Float64(Float64(t_0 * Float64(cos(lambda1) * cos(lambda2))) + Float64(t_0 * expm1(log1p(Float64(sin(lambda1) * sin(lambda2)))))))) * R) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, N[(N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[(t$95$0 * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * N[(Exp[N[Log[1 + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * R), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
\cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, t_0 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) + t_0 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)\right) \cdot R
\end{array}
\end{array}
Initial program 75.2%
Simplified75.2%
associate-*r*75.2%
cos-diff94.4%
distribute-lft-in94.4%
Applied egg-rr94.4%
expm1-log1p-u94.4%
Applied egg-rr94.4%
Final simplification94.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2))))
(*
R
(acos
(fma
(sin phi1)
(sin phi2)
(+
(* t_0 (* (cos lambda1) (cos lambda2)))
(* t_0 (* (sin lambda1) (sin lambda2)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi1) * cos(phi2);
return R * acos(fma(sin(phi1), sin(phi2), ((t_0 * (cos(lambda1) * cos(lambda2))) + (t_0 * (sin(lambda1) * sin(lambda2))))));
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) return Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(Float64(t_0 * Float64(cos(lambda1) * cos(lambda2))) + Float64(t_0 * Float64(sin(lambda1) * sin(lambda2))))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[(t$95$0 * N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, t_0 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2\right) + t_0 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2\right)\right)\right)
\end{array}
\end{array}
Initial program 75.2%
Simplified75.2%
associate-*r*75.2%
cos-diff94.4%
distribute-lft-in94.4%
Applied egg-rr94.4%
Final simplification94.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(acos
(+
(* (sin phi1) (sin phi2))
(*
(* (cos phi1) (cos phi2))
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * ((Math.cos(lambda1) * Math.cos(lambda2)) + (Math.sin(lambda1) * Math.sin(lambda2))))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * ((math.cos(lambda1) * math.cos(lambda2)) + (math.sin(lambda1) * math.sin(lambda2))))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)
\end{array}
Initial program 75.2%
cos-diff61.9%
+-commutative61.9%
Applied egg-rr94.4%
Final simplification94.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(*
R
(acos
(fma
(sin phi1)
(sin phi2)
(* (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2)))))))))
(if (<= phi1 -2.1e+16)
t_0
(if (<= phi1 4.3e-48)
(*
R
(acos
(+
(*
(* (cos phi1) (cos phi2))
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2))))
(* phi1 (sin phi2)))))
(pow (sqrt t_0) 2.0)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = R * acos(fma(sin(phi1), sin(phi2), (cos(phi1) * (cos(phi2) * cos((lambda1 - lambda2))))));
double tmp;
if (phi1 <= -2.1e+16) {
tmp = t_0;
} else if (phi1 <= 4.3e-48) {
tmp = R * acos((((cos(phi1) * cos(phi2)) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))) + (phi1 * sin(phi2))));
} else {
tmp = pow(sqrt(t_0), 2.0);
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))))))) tmp = 0.0 if (phi1 <= -2.1e+16) tmp = t_0; elseif (phi1 <= 4.3e-48) tmp = Float64(R * acos(Float64(Float64(Float64(cos(phi1) * cos(phi2)) * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2)))) + Float64(phi1 * sin(phi2))))); else tmp = sqrt(t_0) ^ 2.0; end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -2.1e+16], t$95$0, If[LessEqual[phi1, 4.3e-48], N[(R * N[ArcCos[N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[Sqrt[t$95$0], $MachinePrecision], 2.0], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)\\
\mathbf{if}\;\phi_1 \leq -2.1 \cdot 10^{+16}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\phi_1 \leq 4.3 \cdot 10^{-48}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) + \phi_1 \cdot \sin \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\sqrt{t_0}\right)}^{2}\\
\end{array}
\end{array}
if phi1 < -2.1e16Initial program 82.9%
Simplified82.9%
if -2.1e16 < phi1 < 4.3e-48Initial program 70.2%
Taylor expanded in phi1 around 0 68.8%
cos-diff90.4%
+-commutative90.4%
Applied egg-rr90.4%
if 4.3e-48 < phi1 Initial program 80.6%
Simplified80.6%
associate-*r*80.6%
cos-diff96.7%
distribute-lft-in96.7%
Applied egg-rr96.7%
add-sqr-sqrt52.4%
pow252.5%
Applied egg-rr41.7%
Final simplification75.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))) (t_1 (* (cos phi1) (cos phi2))))
(if (<= phi1 -2.1e+16)
(* R (acos (fma (sin phi1) (sin phi2) (* (cos phi1) (* (cos phi2) t_0)))))
(if (<= phi1 3.4e-12)
(*
R
(acos
(+
(*
t_1
(+ (* (cos lambda1) (cos lambda2)) (* (sin lambda1) (sin lambda2))))
(* phi1 (sin phi2)))))
(* R (- (/ PI 2.0) (asin (fma (sin phi1) (sin phi2) (* t_1 t_0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double t_1 = cos(phi1) * cos(phi2);
double tmp;
if (phi1 <= -2.1e+16) {
tmp = R * acos(fma(sin(phi1), sin(phi2), (cos(phi1) * (cos(phi2) * t_0))));
} else if (phi1 <= 3.4e-12) {
tmp = R * acos(((t_1 * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2)))) + (phi1 * sin(phi2))));
} else {
tmp = R * ((((double) M_PI) / 2.0) - asin(fma(sin(phi1), sin(phi2), (t_1 * t_0))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) t_1 = Float64(cos(phi1) * cos(phi2)) tmp = 0.0 if (phi1 <= -2.1e+16) tmp = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi1) * Float64(cos(phi2) * t_0))))); elseif (phi1 <= 3.4e-12) tmp = Float64(R * acos(Float64(Float64(t_1 * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2)))) + Float64(phi1 * sin(phi2))))); else tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(fma(sin(phi1), sin(phi2), Float64(t_1 * t_0))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -2.1e+16], N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-12], N[(R * N[ArcCos[N[(N[(t$95$1 * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
\mathbf{if}\;\phi_1 \leq -2.1 \cdot 10^{+16}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right)\right)\right)\\
\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-12}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right) + \phi_1 \cdot \sin \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, t_1 \cdot t_0\right)\right)\right)\\
\end{array}
\end{array}
if phi1 < -2.1e16Initial program 82.9%
Simplified82.9%
if -2.1e16 < phi1 < 3.4000000000000001e-12Initial program 69.8%
Taylor expanded in phi1 around 0 68.5%
cos-diff90.0%
+-commutative90.0%
Applied egg-rr90.0%
if 3.4000000000000001e-12 < phi1 Initial program 82.0%
Simplified82.0%
associate-*r*82.0%
cos-diff97.9%
distribute-lft-in97.9%
Applied egg-rr97.9%
acos-asin97.9%
distribute-lft-out97.9%
cos-diff82.0%
associate-*l*82.0%
Applied egg-rr82.0%
associate-*r*82.0%
Simplified82.0%
Final simplification86.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2)))
(t_1 (cos (- lambda1 lambda2)))
(t_2 (* (sin phi1) (sin phi2))))
(if (<= phi2 -5.2e-7)
(* R (acos (+ t_2 (* t_0 (log1p (expm1 t_1))))))
(if (<= phi2 3.8e-7)
(*
R
(acos
(+
t_2
(*
(cos phi1)
(+
(* (cos lambda1) (cos lambda2))
(* (sin lambda1) (sin lambda2)))))))
(* R (acos (+ t_2 (* t_0 (log (exp t_1))))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi1) * cos(phi2);
double t_1 = cos((lambda1 - lambda2));
double t_2 = sin(phi1) * sin(phi2);
double tmp;
if (phi2 <= -5.2e-7) {
tmp = R * acos((t_2 + (t_0 * log1p(expm1(t_1)))));
} else if (phi2 <= 3.8e-7) {
tmp = R * acos((t_2 + (cos(phi1) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))))));
} else {
tmp = R * acos((t_2 + (t_0 * log(exp(t_1)))));
}
return tmp;
}
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos(phi1) * Math.cos(phi2);
double t_1 = Math.cos((lambda1 - lambda2));
double t_2 = Math.sin(phi1) * Math.sin(phi2);
double tmp;
if (phi2 <= -5.2e-7) {
tmp = R * Math.acos((t_2 + (t_0 * Math.log1p(Math.expm1(t_1)))));
} else if (phi2 <= 3.8e-7) {
tmp = R * Math.acos((t_2 + (Math.cos(phi1) * ((Math.cos(lambda1) * Math.cos(lambda2)) + (Math.sin(lambda1) * Math.sin(lambda2))))));
} else {
tmp = R * Math.acos((t_2 + (t_0 * Math.log(Math.exp(t_1)))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos(phi1) * math.cos(phi2) t_1 = math.cos((lambda1 - lambda2)) t_2 = math.sin(phi1) * math.sin(phi2) tmp = 0 if phi2 <= -5.2e-7: tmp = R * math.acos((t_2 + (t_0 * math.log1p(math.expm1(t_1))))) elif phi2 <= 3.8e-7: tmp = R * math.acos((t_2 + (math.cos(phi1) * ((math.cos(lambda1) * math.cos(lambda2)) + (math.sin(lambda1) * math.sin(lambda2)))))) else: tmp = R * math.acos((t_2 + (t_0 * math.log(math.exp(t_1))))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) t_1 = cos(Float64(lambda1 - lambda2)) t_2 = Float64(sin(phi1) * sin(phi2)) tmp = 0.0 if (phi2 <= -5.2e-7) tmp = Float64(R * acos(Float64(t_2 + Float64(t_0 * log1p(expm1(t_1)))))); elseif (phi2 <= 3.8e-7) tmp = Float64(R * acos(Float64(t_2 + Float64(cos(phi1) * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2))))))); else tmp = Float64(R * acos(Float64(t_2 + Float64(t_0 * log(exp(t_1)))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -5.2e-7], N[(R * N[ArcCos[N[(t$95$2 + N[(t$95$0 * N[Log[1 + N[(Exp[t$95$1] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 3.8e-7], N[(R * N[ArcCos[N[(t$95$2 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$2 + N[(t$95$0 * N[Log[N[Exp[t$95$1], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \cos \left(\lambda_1 - \lambda_2\right)\\
t_2 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\phi_2 \leq -5.2 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(t_1\right)\right)\right)\\
\mathbf{elif}\;\phi_2 \leq 3.8 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_2 + \cos \phi_1 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_2 + t_0 \cdot \log \left(e^{t_1}\right)\right)\\
\end{array}
\end{array}
if phi2 < -5.19999999999999998e-7Initial program 80.3%
log1p-expm1-u80.3%
Applied egg-rr80.3%
if -5.19999999999999998e-7 < phi2 < 3.80000000000000015e-7Initial program 70.4%
cos-diff90.4%
Applied egg-rr90.4%
cos-neg90.4%
*-commutative90.4%
fma-def90.4%
cos-neg90.4%
Simplified90.4%
Taylor expanded in phi2 around 0 90.3%
if 3.80000000000000015e-7 < phi2 Initial program 80.2%
add-log-exp80.2%
Applied egg-rr80.2%
Final simplification85.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi1 -3.2e-5)
(* R (acos (fma (sin phi1) (sin phi2) (* (cos phi1) (* (cos phi2) t_0)))))
(if (<= phi1 3.4e-12)
(*
R
(acos
(+
(* (sin phi1) (sin phi2))
(*
(cos phi2)
(+
(* (cos lambda1) (cos lambda2))
(* (sin lambda1) (sin lambda2)))))))
(*
R
(-
(/ PI 2.0)
(asin
(fma (sin phi1) (sin phi2) (* (* (cos phi1) (cos phi2)) t_0)))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi1 <= -3.2e-5) {
tmp = R * acos(fma(sin(phi1), sin(phi2), (cos(phi1) * (cos(phi2) * t_0))));
} else if (phi1 <= 3.4e-12) {
tmp = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi2) * ((cos(lambda1) * cos(lambda2)) + (sin(lambda1) * sin(lambda2))))));
} else {
tmp = R * ((((double) M_PI) / 2.0) - asin(fma(sin(phi1), sin(phi2), ((cos(phi1) * cos(phi2)) * t_0))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi1 <= -3.2e-5) tmp = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi1) * Float64(cos(phi2) * t_0))))); elseif (phi1 <= 3.4e-12) tmp = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi2) * Float64(Float64(cos(lambda1) * cos(lambda2)) + Float64(sin(lambda1) * sin(lambda2))))))); else tmp = Float64(R * Float64(Float64(pi / 2.0) - asin(fma(sin(phi1), sin(phi2), Float64(Float64(cos(phi1) * cos(phi2)) * t_0))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi1, -3.2e-5], N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi1, 3.4e-12], N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[(N[(N[Cos[lambda1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -3.2 \cdot 10^{-5}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot t_0\right)\right)\right)\\
\mathbf{elif}\;\phi_1 \leq 3.4 \cdot 10^{-12}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_2 \cdot \left(\cos \lambda_1 \cdot \cos \lambda_2 + \sin \lambda_1 \cdot \sin \lambda_2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\frac{\pi}{2} - \sin^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0\right)\right)\right)\\
\end{array}
\end{array}
if phi1 < -3.19999999999999986e-5Initial program 80.9%
Simplified80.9%
if -3.19999999999999986e-5 < phi1 < 3.4000000000000001e-12Initial program 70.1%
cos-diff91.3%
Applied egg-rr91.3%
cos-neg91.3%
*-commutative91.3%
fma-def91.3%
cos-neg91.3%
Simplified91.3%
Taylor expanded in phi1 around 0 91.0%
if 3.4000000000000001e-12 < phi1 Initial program 82.0%
Simplified82.0%
associate-*r*82.0%
cos-diff97.9%
distribute-lft-in97.9%
Applied egg-rr97.9%
acos-asin97.9%
distribute-lft-out97.9%
cos-diff82.0%
associate-*l*82.0%
Applied egg-rr82.0%
associate-*r*82.0%
Simplified82.0%
Final simplification86.8%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(acos
(fma
(sin phi1)
(sin phi2)
(* (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(fma(sin(phi1), sin(phi2), (cos(phi1) * (cos(phi2) * cos((lambda1 - lambda2))))));
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)\right)
\end{array}
Initial program 75.2%
Simplified75.2%
Final simplification75.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= lambda2 8.8e-10)
(*
R
(acos
(+
(* (sin phi1) (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos lambda1)))))
(*
R
(acos
(fma (sin phi1) (sin phi2) (* (cos phi2) (cos (- lambda2 lambda1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= 8.8e-10) {
tmp = R * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos(lambda1))));
} else {
tmp = R * acos(fma(sin(phi1), sin(phi2), (cos(phi2) * cos((lambda2 - lambda1)))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda2 <= 8.8e-10) tmp = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda1))))); else tmp = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi2) * cos(Float64(lambda2 - lambda1)))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 8.8e-10], N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 8.8 \cdot 10^{-10}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\
\end{array}
\end{array}
if lambda2 < 8.7999999999999996e-10Initial program 81.0%
Taylor expanded in lambda2 around 0 65.9%
if 8.7999999999999996e-10 < lambda2 Initial program 57.4%
Simplified57.3%
Taylor expanded in phi1 around 0 40.0%
sub-neg40.0%
remove-double-neg40.0%
mul-1-neg40.0%
distribute-neg-in40.0%
+-commutative40.0%
cos-neg40.0%
mul-1-neg40.0%
unsub-neg40.0%
Simplified40.0%
Final simplification59.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos phi2))) (t_1 (* (sin phi1) (sin phi2))))
(if (<= lambda1 -2.4e-7)
(* R (acos (+ t_1 (* t_0 (cos lambda1)))))
(* R (acos (+ t_1 (* t_0 (cos lambda2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos(phi1) * cos(phi2);
double t_1 = sin(phi1) * sin(phi2);
double tmp;
if (lambda1 <= -2.4e-7) {
tmp = R * acos((t_1 + (t_0 * cos(lambda1))));
} else {
tmp = R * acos((t_1 + (t_0 * cos(lambda2))));
}
return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos(phi1) * cos(phi2)
t_1 = sin(phi1) * sin(phi2)
if (lambda1 <= (-2.4d-7)) then
tmp = r * acos((t_1 + (t_0 * cos(lambda1))))
else
tmp = r * acos((t_1 + (t_0 * cos(lambda2))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos(phi1) * Math.cos(phi2);
double t_1 = Math.sin(phi1) * Math.sin(phi2);
double tmp;
if (lambda1 <= -2.4e-7) {
tmp = R * Math.acos((t_1 + (t_0 * Math.cos(lambda1))));
} else {
tmp = R * Math.acos((t_1 + (t_0 * Math.cos(lambda2))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos(phi1) * math.cos(phi2) t_1 = math.sin(phi1) * math.sin(phi2) tmp = 0 if lambda1 <= -2.4e-7: tmp = R * math.acos((t_1 + (t_0 * math.cos(lambda1)))) else: tmp = R * math.acos((t_1 + (t_0 * math.cos(lambda2)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(phi2)) t_1 = Float64(sin(phi1) * sin(phi2)) tmp = 0.0 if (lambda1 <= -2.4e-7) tmp = Float64(R * acos(Float64(t_1 + Float64(t_0 * cos(lambda1))))); else tmp = Float64(R * acos(Float64(t_1 + Float64(t_0 * cos(lambda2))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(phi1) * cos(phi2); t_1 = sin(phi1) * sin(phi2); tmp = 0.0; if (lambda1 <= -2.4e-7) tmp = R * acos((t_1 + (t_0 * cos(lambda1)))); else tmp = R * acos((t_1 + (t_0 * cos(lambda2)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -2.4e-7], N[(R * N[ArcCos[N[(t$95$1 + N[(t$95$0 * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$1 + N[(t$95$0 * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \phi_1 \cdot \cos \phi_2\\
t_1 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -2.4 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + t_0 \cdot \cos \lambda_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 + t_0 \cdot \cos \lambda_2\right)\\
\end{array}
\end{array}
if lambda1 < -2.39999999999999979e-7Initial program 55.7%
Taylor expanded in lambda2 around 0 55.7%
if -2.39999999999999979e-7 < lambda1 Initial program 83.1%
Taylor expanded in lambda1 around 0 70.4%
cos-neg24.1%
Simplified70.4%
Final simplification66.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(acos
(+
(* (sin phi1) (sin phi2))
(* (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos((lambda1 - lambda2))))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos((lambda1 - lambda2))))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos((lambda1 - lambda2))))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi1) * (math.cos(phi2) * math.cos((lambda1 - lambda2))))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi1) * Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos((lambda1 - lambda2)))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\right)
\end{array}
Initial program 75.2%
Taylor expanded in phi1 around 0 75.2%
Final simplification75.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= phi1 -1.1)
(*
R
(acos
(fma (sin phi1) (sin phi2) (* (cos phi1) (cos (- lambda2 lambda1))))))
(*
R
(acos
(+
(* phi1 (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -1.1) {
tmp = R * acos(fma(sin(phi1), sin(phi2), (cos(phi1) * cos((lambda2 - lambda1)))));
} else {
tmp = R * acos(((phi1 * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -1.1) tmp = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi1) * cos(Float64(lambda2 - lambda1)))))); else tmp = Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.1], N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.1:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot \cos \left(\lambda_2 - \lambda_1\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\
\end{array}
\end{array}
if phi1 < -1.1000000000000001Initial program 80.9%
Simplified80.9%
Taylor expanded in phi2 around 0 44.8%
sub-neg44.8%
remove-double-neg44.8%
mul-1-neg44.8%
distribute-neg-in44.8%
+-commutative44.8%
cos-neg44.8%
mul-1-neg44.8%
unsub-neg44.8%
Simplified44.8%
if -1.1000000000000001 < phi1 Initial program 74.0%
Taylor expanded in phi1 around 0 54.2%
Final simplification52.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda2 lambda1))))
(if (<= phi2 6.8e-46)
(* R (acos (fma (sin phi1) (sin phi2) (* (cos phi1) t_0))))
(* R (acos (fma (sin phi1) (sin phi2) (* (cos phi2) t_0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda2 - lambda1));
double tmp;
if (phi2 <= 6.8e-46) {
tmp = R * acos(fma(sin(phi1), sin(phi2), (cos(phi1) * t_0)));
} else {
tmp = R * acos(fma(sin(phi1), sin(phi2), (cos(phi2) * t_0)));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda2 - lambda1)) tmp = 0.0 if (phi2 <= 6.8e-46) tmp = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi1) * t_0)))); else tmp = Float64(R * acos(fma(sin(phi1), sin(phi2), Float64(cos(phi2) * t_0)))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 6.8e-46], N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision] + N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_2 - \lambda_1\right)\\
\mathbf{if}\;\phi_2 \leq 6.8 \cdot 10^{-46}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_1 \cdot t_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\sin \phi_1, \sin \phi_2, \cos \phi_2 \cdot t_0\right)\right)\\
\end{array}
\end{array}
if phi2 < 6.79999999999999992e-46Initial program 74.2%
Simplified74.2%
Taylor expanded in phi2 around 0 53.1%
sub-neg53.1%
remove-double-neg53.1%
mul-1-neg53.1%
distribute-neg-in53.1%
+-commutative53.1%
cos-neg53.1%
mul-1-neg53.1%
unsub-neg53.1%
Simplified53.1%
if 6.79999999999999992e-46 < phi2 Initial program 77.8%
Simplified77.9%
Taylor expanded in phi1 around 0 50.8%
sub-neg50.8%
remove-double-neg50.8%
mul-1-neg50.8%
distribute-neg-in50.8%
+-commutative50.8%
cos-neg50.8%
mul-1-neg50.8%
unsub-neg50.8%
Simplified50.8%
Final simplification52.5%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi2 5.0)
(* R (acos (+ (* (* (cos phi1) (cos phi2)) t_0) (* (sin phi1) phi2))))
(*
R
(acos
(+
(* phi1 (sin phi2))
(/ (+ (cos (- phi1 phi2)) (cos (+ phi1 phi2))) (/ 2.0 t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 5.0) {
tmp = R * acos((((cos(phi1) * cos(phi2)) * t_0) + (sin(phi1) * phi2)));
} else {
tmp = R * acos(((phi1 * sin(phi2)) + ((cos((phi1 - phi2)) + cos((phi1 + phi2))) / (2.0 / t_0))));
}
return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: tmp
t_0 = cos((lambda1 - lambda2))
if (phi2 <= 5.0d0) then
tmp = r * acos((((cos(phi1) * cos(phi2)) * t_0) + (sin(phi1) * phi2)))
else
tmp = r * acos(((phi1 * sin(phi2)) + ((cos((phi1 - phi2)) + cos((phi1 + phi2))) / (2.0d0 / t_0))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 5.0) {
tmp = R * Math.acos((((Math.cos(phi1) * Math.cos(phi2)) * t_0) + (Math.sin(phi1) * phi2)));
} else {
tmp = R * Math.acos(((phi1 * Math.sin(phi2)) + ((Math.cos((phi1 - phi2)) + Math.cos((phi1 + phi2))) / (2.0 / t_0))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if phi2 <= 5.0: tmp = R * math.acos((((math.cos(phi1) * math.cos(phi2)) * t_0) + (math.sin(phi1) * phi2))) else: tmp = R * math.acos(((phi1 * math.sin(phi2)) + ((math.cos((phi1 - phi2)) + math.cos((phi1 + phi2))) / (2.0 / t_0)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= 5.0) tmp = Float64(R * acos(Float64(Float64(Float64(cos(phi1) * cos(phi2)) * t_0) + Float64(sin(phi1) * phi2)))); else tmp = Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + Float64(Float64(cos(Float64(phi1 - phi2)) + cos(Float64(phi1 + phi2))) / Float64(2.0 / t_0))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos((lambda1 - lambda2)); tmp = 0.0; if (phi2 <= 5.0) tmp = R * acos((((cos(phi1) * cos(phi2)) * t_0) + (sin(phi1) * phi2))); else tmp = R * acos(((phi1 * sin(phi2)) + ((cos((phi1 - phi2)) + cos((phi1 + phi2))) / (2.0 / t_0)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 5.0], N[(R * N[ArcCos[N[(N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[N[(phi1 - phi2), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(phi1 + phi2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 5:\\
\;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot t_0 + \sin \phi_1 \cdot \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \frac{\cos \left(\phi_1 - \phi_2\right) + \cos \left(\phi_1 + \phi_2\right)}{\frac{2}{t_0}}\right)\\
\end{array}
\end{array}
if phi2 < 5Initial program 73.8%
Taylor expanded in phi2 around 0 54.8%
if 5 < phi2 Initial program 79.8%
Taylor expanded in phi1 around 0 45.7%
cos-mult45.7%
+-commutative45.7%
cos-diff61.9%
*-commutative61.9%
*-commutative61.9%
cos-diff45.7%
associate-/r/45.7%
cos-diff61.9%
*-commutative61.9%
*-commutative61.9%
cos-diff45.7%
Applied egg-rr45.7%
Final simplification52.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))
(if (<= phi1 -3.2e+84)
(* R (acos (+ t_0 (* (sin phi1) phi2))))
(* R (acos (+ (* phi1 (sin phi2)) t_0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2));
double tmp;
if (phi1 <= -3.2e+84) {
tmp = R * acos((t_0 + (sin(phi1) * phi2)));
} else {
tmp = R * acos(((phi1 * sin(phi2)) + t_0));
}
return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: tmp
t_0 = (cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))
if (phi1 <= (-3.2d+84)) then
tmp = r * acos((t_0 + (sin(phi1) * phi2)))
else
tmp = r * acos(((phi1 * sin(phi2)) + t_0))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = (Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2));
double tmp;
if (phi1 <= -3.2e+84) {
tmp = R * Math.acos((t_0 + (Math.sin(phi1) * phi2)));
} else {
tmp = R * Math.acos(((phi1 * Math.sin(phi2)) + t_0));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = (math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)) tmp = 0 if phi1 <= -3.2e+84: tmp = R * math.acos((t_0 + (math.sin(phi1) * phi2))) else: tmp = R * math.acos(((phi1 * math.sin(phi2)) + t_0)) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))) tmp = 0.0 if (phi1 <= -3.2e+84) tmp = Float64(R * acos(Float64(t_0 + Float64(sin(phi1) * phi2)))); else tmp = Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + t_0))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = (cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2)); tmp = 0.0; if (phi1 <= -3.2e+84) tmp = R * acos((t_0 + (sin(phi1) * phi2))); else tmp = R * acos(((phi1 * sin(phi2)) + t_0)); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -3.2e+84], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_1 \leq -3.2 \cdot 10^{+84}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \sin \phi_1 \cdot \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + t_0\right)\\
\end{array}
\end{array}
if phi1 < -3.2000000000000001e84Initial program 78.3%
Taylor expanded in phi2 around 0 37.8%
if -3.2000000000000001e84 < phi1 Initial program 74.8%
Taylor expanded in phi1 around 0 52.8%
Final simplification50.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(acos
(+
(* phi1 (sin phi2))
(* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((phi1 * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * acos(((phi1 * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * Math.acos(((phi1 * Math.sin(phi2)) + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2)))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((phi1 * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2)))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((phi1 * sin(phi2)) + ((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)
\end{array}
Initial program 75.2%
Taylor expanded in phi1 around 0 47.9%
Final simplification47.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi2 1.1e-74)
(* R (acos (+ (* phi1 phi2) (* (cos phi1) t_0))))
(* R (acos (+ (* (cos phi2) t_0) (* phi1 (sin phi2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 1.1e-74) {
tmp = R * acos(((phi1 * phi2) + (cos(phi1) * t_0)));
} else {
tmp = R * acos(((cos(phi2) * t_0) + (phi1 * sin(phi2))));
}
return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: tmp
t_0 = cos((lambda1 - lambda2))
if (phi2 <= 1.1d-74) then
tmp = r * acos(((phi1 * phi2) + (cos(phi1) * t_0)))
else
tmp = r * acos(((cos(phi2) * t_0) + (phi1 * sin(phi2))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = Math.cos((lambda1 - lambda2));
double tmp;
if (phi2 <= 1.1e-74) {
tmp = R * Math.acos(((phi1 * phi2) + (Math.cos(phi1) * t_0)));
} else {
tmp = R * Math.acos(((Math.cos(phi2) * t_0) + (phi1 * Math.sin(phi2))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.cos((lambda1 - lambda2)) tmp = 0 if phi2 <= 1.1e-74: tmp = R * math.acos(((phi1 * phi2) + (math.cos(phi1) * t_0))) else: tmp = R * math.acos(((math.cos(phi2) * t_0) + (phi1 * math.sin(phi2)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= 1.1e-74) tmp = Float64(R * acos(Float64(Float64(phi1 * phi2) + Float64(cos(phi1) * t_0)))); else tmp = Float64(R * acos(Float64(Float64(cos(phi2) * t_0) + Float64(phi1 * sin(phi2))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = cos((lambda1 - lambda2)); tmp = 0.0; if (phi2 <= 1.1e-74) tmp = R * acos(((phi1 * phi2) + (cos(phi1) * t_0))); else tmp = R * acos(((cos(phi2) * t_0) + (phi1 * sin(phi2)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, 1.1e-74], N[(R * N[ArcCos[N[(N[(phi1 * phi2), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] + N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 1.1 \cdot 10^{-74}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \phi_2 + \cos \phi_1 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_2 \cdot t_0 + \phi_1 \cdot \sin \phi_2\right)\\
\end{array}
\end{array}
if phi2 < 1.10000000000000005e-74Initial program 73.5%
Taylor expanded in phi1 around 0 48.6%
Taylor expanded in phi2 around 0 39.2%
Taylor expanded in phi2 around 0 38.2%
if 1.10000000000000005e-74 < phi2 Initial program 79.3%
Taylor expanded in phi1 around 0 46.2%
Taylor expanded in phi1 around 0 45.0%
Final simplification40.2%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* phi1 (sin phi2))))
(if (<= lambda2 7.5e-8)
(* R (acos (+ t_0 (* (cos phi1) (cos lambda1)))))
(* R (acos (+ t_0 (* (cos phi1) (cos lambda2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = phi1 * sin(phi2);
double tmp;
if (lambda2 <= 7.5e-8) {
tmp = R * acos((t_0 + (cos(phi1) * cos(lambda1))));
} else {
tmp = R * acos((t_0 + (cos(phi1) * cos(lambda2))));
}
return tmp;
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
real(8) :: t_0
real(8) :: tmp
t_0 = phi1 * sin(phi2)
if (lambda2 <= 7.5d-8) then
tmp = r * acos((t_0 + (cos(phi1) * cos(lambda1))))
else
tmp = r * acos((t_0 + (cos(phi1) * cos(lambda2))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = phi1 * Math.sin(phi2);
double tmp;
if (lambda2 <= 7.5e-8) {
tmp = R * Math.acos((t_0 + (Math.cos(phi1) * Math.cos(lambda1))));
} else {
tmp = R * Math.acos((t_0 + (Math.cos(phi1) * Math.cos(lambda2))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = phi1 * math.sin(phi2) tmp = 0 if lambda2 <= 7.5e-8: tmp = R * math.acos((t_0 + (math.cos(phi1) * math.cos(lambda1)))) else: tmp = R * math.acos((t_0 + (math.cos(phi1) * math.cos(lambda2)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(phi1 * sin(phi2)) tmp = 0.0 if (lambda2 <= 7.5e-8) tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * cos(lambda1))))); else tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * cos(lambda2))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = phi1 * sin(phi2); tmp = 0.0; if (lambda2 <= 7.5e-8) tmp = R * acos((t_0 + (cos(phi1) * cos(lambda1)))); else tmp = R * acos((t_0 + (cos(phi1) * cos(lambda2)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda2, 7.5e-8], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_2 \leq 7.5 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \lambda_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_1 \cdot \cos \lambda_2\right)\\
\end{array}
\end{array}
if lambda2 < 7.4999999999999997e-8Initial program 80.9%
Taylor expanded in phi1 around 0 51.1%
Taylor expanded in phi2 around 0 33.5%
Taylor expanded in lambda2 around 0 26.2%
if 7.4999999999999997e-8 < lambda2 Initial program 57.3%
Taylor expanded in phi1 around 0 37.7%
Taylor expanded in phi2 around 0 28.4%
Taylor expanded in lambda1 around 0 28.5%
cos-neg28.5%
Simplified28.5%
Final simplification26.8%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (acos (+ (* phi1 (sin phi2)) (* (cos phi1) (cos (- lambda1 lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((phi1 * sin(phi2)) + (cos(phi1) * cos((lambda1 - lambda2)))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * acos(((phi1 * sin(phi2)) + (cos(phi1) * cos((lambda1 - lambda2)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * Math.acos(((phi1 * Math.sin(phi2)) + (Math.cos(phi1) * Math.cos((lambda1 - lambda2)))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((phi1 * math.sin(phi2)) + (math.cos(phi1) * math.cos((lambda1 - lambda2)))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + Float64(cos(phi1) * cos(Float64(lambda1 - lambda2)))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((phi1 * sin(phi2)) + (cos(phi1) * cos((lambda1 - lambda2))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)
\end{array}
Initial program 75.2%
Taylor expanded in phi1 around 0 47.9%
Taylor expanded in phi2 around 0 32.3%
Final simplification32.3%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= phi1 -1.3e-7) (* R (acos (+ (* phi1 phi2) (* (cos phi1) (cos lambda1))))) (* R (acos (+ (cos (- lambda2 lambda1)) (* phi1 phi2))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -1.3e-7) {
tmp = R * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda1))));
} else {
tmp = R * acos((cos((lambda2 - lambda1)) + (phi1 * phi2)));
}
return tmp;
}
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) :: tmp
if (phi1 <= (-1.3d-7)) then
tmp = r * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda1))))
else
tmp = r * acos((cos((lambda2 - lambda1)) + (phi1 * phi2)))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (phi1 <= -1.3e-7) {
tmp = R * Math.acos(((phi1 * phi2) + (Math.cos(phi1) * Math.cos(lambda1))));
} else {
tmp = R * Math.acos((Math.cos((lambda2 - lambda1)) + (phi1 * phi2)));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if phi1 <= -1.3e-7: tmp = R * math.acos(((phi1 * phi2) + (math.cos(phi1) * math.cos(lambda1)))) else: tmp = R * math.acos((math.cos((lambda2 - lambda1)) + (phi1 * phi2))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (phi1 <= -1.3e-7) tmp = Float64(R * acos(Float64(Float64(phi1 * phi2) + Float64(cos(phi1) * cos(lambda1))))); else tmp = Float64(R * acos(Float64(cos(Float64(lambda2 - lambda1)) + Float64(phi1 * phi2)))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (phi1 <= -1.3e-7) tmp = R * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda1)))); else tmp = R * acos((cos((lambda2 - lambda1)) + (phi1 * phi2))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[phi1, -1.3e-7], N[(R * N[ArcCos[N[(N[(phi1 * phi2), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] + N[(phi1 * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\phi_1 \leq -1.3 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \phi_2 + \cos \phi_1 \cdot \cos \lambda_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \phi_1 \cdot \phi_2\right)\\
\end{array}
\end{array}
if phi1 < -1.29999999999999999e-7Initial program 80.0%
Taylor expanded in phi1 around 0 20.6%
Taylor expanded in phi2 around 0 20.6%
Taylor expanded in phi2 around 0 20.6%
Taylor expanded in lambda2 around 0 10.7%
if -1.29999999999999999e-7 < phi1 Initial program 74.1%
Taylor expanded in phi1 around 0 54.2%
Taylor expanded in phi2 around 0 35.0%
Taylor expanded in phi2 around 0 32.7%
Taylor expanded in phi1 around 0 27.0%
sub-neg27.0%
remove-double-neg27.0%
mul-1-neg27.0%
distribute-neg-in27.0%
+-commutative27.0%
cos-neg27.0%
mul-1-neg27.0%
sub-neg27.0%
Simplified27.0%
Final simplification23.9%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (if (<= lambda1 -5e-8) (* R (acos (+ (* phi1 phi2) (* (cos phi1) (cos lambda1))))) (* R (acos (+ (* phi1 phi2) (* (cos phi1) (cos lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda1 <= -5e-8) {
tmp = R * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda1))));
} else {
tmp = R * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda2))));
}
return tmp;
}
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) :: tmp
if (lambda1 <= (-5d-8)) then
tmp = r * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda1))))
else
tmp = r * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda2))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda1 <= -5e-8) {
tmp = R * Math.acos(((phi1 * phi2) + (Math.cos(phi1) * Math.cos(lambda1))));
} else {
tmp = R * Math.acos(((phi1 * phi2) + (Math.cos(phi1) * Math.cos(lambda2))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if lambda1 <= -5e-8: tmp = R * math.acos(((phi1 * phi2) + (math.cos(phi1) * math.cos(lambda1)))) else: tmp = R * math.acos(((phi1 * phi2) + (math.cos(phi1) * math.cos(lambda2)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda1 <= -5e-8) tmp = Float64(R * acos(Float64(Float64(phi1 * phi2) + Float64(cos(phi1) * cos(lambda1))))); else tmp = Float64(R * acos(Float64(Float64(phi1 * phi2) + Float64(cos(phi1) * cos(lambda2))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (lambda1 <= -5e-8) tmp = R * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda1)))); else tmp = R * acos(((phi1 * phi2) + (cos(phi1) * cos(lambda2)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda1, -5e-8], N[(R * N[ArcCos[N[(N[(phi1 * phi2), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[(phi1 * phi2), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_1 \leq -5 \cdot 10^{-8}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \phi_2 + \cos \phi_1 \cdot \cos \lambda_1\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \phi_2 + \cos \phi_1 \cdot \cos \lambda_2\right)\\
\end{array}
\end{array}
if lambda1 < -4.9999999999999998e-8Initial program 55.7%
Taylor expanded in phi1 around 0 42.2%
Taylor expanded in phi2 around 0 34.3%
Taylor expanded in phi2 around 0 31.4%
Taylor expanded in lambda2 around 0 31.6%
if -4.9999999999999998e-8 < lambda1 Initial program 83.1%
Taylor expanded in phi1 around 0 50.2%
Taylor expanded in phi2 around 0 31.4%
Taylor expanded in phi2 around 0 30.0%
Taylor expanded in lambda1 around 0 22.8%
cos-neg22.8%
Simplified22.8%
Final simplification25.3%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (acos (+ (* phi1 phi2) (* (cos phi1) (cos (- lambda1 lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((phi1 * phi2) + (cos(phi1) * cos((lambda1 - lambda2)))));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * acos(((phi1 * phi2) + (cos(phi1) * cos((lambda1 - lambda2)))))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * Math.acos(((phi1 * phi2) + (Math.cos(phi1) * Math.cos((lambda1 - lambda2)))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((phi1 * phi2) + (math.cos(phi1) * math.cos((lambda1 - lambda2)))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(Float64(phi1 * phi2) + Float64(cos(phi1) * cos(Float64(lambda1 - lambda2)))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((phi1 * phi2) + (cos(phi1) * cos((lambda1 - lambda2))))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(phi1 * phi2), $MachinePrecision] + N[(N[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\phi_1 \cdot \phi_2 + \cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)
\end{array}
Initial program 75.2%
Taylor expanded in phi1 around 0 47.9%
Taylor expanded in phi2 around 0 32.3%
Taylor expanded in phi2 around 0 30.4%
Final simplification30.4%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (acos (+ (cos (- lambda2 lambda1)) (* phi1 phi2)))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos((cos((lambda2 - lambda1)) + (phi1 * phi2)));
}
real(8) function code(r, lambda1, lambda2, phi1, phi2)
real(8), intent (in) :: r
real(8), intent (in) :: lambda1
real(8), intent (in) :: lambda2
real(8), intent (in) :: phi1
real(8), intent (in) :: phi2
code = r * acos((cos((lambda2 - lambda1)) + (phi1 * phi2)))
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * Math.acos((Math.cos((lambda2 - lambda1)) + (phi1 * phi2)));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos((math.cos((lambda2 - lambda1)) + (phi1 * phi2)))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(cos(Float64(lambda2 - lambda1)) + Float64(phi1 * phi2)))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos((cos((lambda2 - lambda1)) + (phi1 * phi2))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision] + N[(phi1 * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\cos \left(\lambda_2 - \lambda_1\right) + \phi_1 \cdot \phi_2\right)
\end{array}
Initial program 75.2%
Taylor expanded in phi1 around 0 47.9%
Taylor expanded in phi2 around 0 32.3%
Taylor expanded in phi2 around 0 30.4%
Taylor expanded in phi1 around 0 23.1%
sub-neg23.1%
remove-double-neg23.1%
mul-1-neg23.1%
distribute-neg-in23.1%
+-commutative23.1%
cos-neg23.1%
mul-1-neg23.1%
sub-neg23.1%
Simplified23.1%
Final simplification23.1%
herbie shell --seed 2023333
(FPCore (R lambda1 lambda2 phi1 phi2)
:name "Spherical law of cosines"
:precision binary64
(* (acos (+ (* (sin phi1) (sin phi2)) (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2))))) R))