
(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 20 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
(*
(acos
(+
(* (sin phi1) (sin phi2))
(*
(* (cos phi1) (cos phi2))
(fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2))))))
R))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)))))) * R;
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(Float64(cos(phi1) * cos(phi2)) * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(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[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $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 \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right)\right) \cdot R
\end{array}
Initial program 79.9%
cos-diff97.7%
Applied egg-rr97.7%
cos-neg97.7%
*-commutative97.7%
fma-def97.7%
cos-neg97.7%
Simplified97.7%
Final simplification97.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (sin phi1) (sin phi2)))
(t_1 (* (cos phi1) (cos phi2)))
(t_2 (cos (- lambda1 lambda2))))
(if (<= phi2 -0.056)
(* R (acos (+ (log (+ 1.0 (expm1 t_0))) (* t_1 t_2))))
(if (<= phi2 0.44)
(*
R
(acos
(+
(*
t_1
(fma (cos lambda2) (cos lambda1) (* (sin lambda1) (sin lambda2))))
(* (sin phi1) phi2))))
(* R (- (* PI 0.5) (asin (fma (cos phi1) (* (cos phi2) t_2) t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(phi1) * sin(phi2);
double t_1 = cos(phi1) * cos(phi2);
double t_2 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= -0.056) {
tmp = R * acos((log((1.0 + expm1(t_0))) + (t_1 * t_2)));
} else if (phi2 <= 0.44) {
tmp = R * acos(((t_1 * fma(cos(lambda2), cos(lambda1), (sin(lambda1) * sin(lambda2)))) + (sin(phi1) * phi2)));
} else {
tmp = R * ((((double) M_PI) * 0.5) - asin(fma(cos(phi1), (cos(phi2) * t_2), t_0)));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi1) * sin(phi2)) t_1 = Float64(cos(phi1) * cos(phi2)) t_2 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= -0.056) tmp = Float64(R * acos(Float64(log(Float64(1.0 + expm1(t_0))) + Float64(t_1 * t_2)))); elseif (phi2 <= 0.44) tmp = Float64(R * acos(Float64(Float64(t_1 * fma(cos(lambda2), cos(lambda1), Float64(sin(lambda1) * sin(lambda2)))) + Float64(sin(phi1) * phi2)))); else tmp = Float64(R * Float64(Float64(pi * 0.5) - asin(fma(cos(phi1), Float64(cos(phi2) * t_2), t_0)))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -0.056], N[(R * N[ArcCos[N[(N[Log[N[(1.0 + N[(Exp[t$95$0] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(t$95$1 * t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 0.44], N[(R * N[ArcCos[N[(N[(t$95$1 * N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision] + N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$2), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
t_2 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -0.056:\\
\;\;\;\;R \cdot \cos^{-1} \left(\log \left(1 + \mathsf{expm1}\left(t_0\right)\right) + t_1 \cdot t_2\right)\\
\mathbf{elif}\;\phi_2 \leq 0.44:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot \mathsf{fma}\left(\cos \lambda_2, \cos \lambda_1, \sin \lambda_1 \cdot \sin \lambda_2\right) + \sin \phi_1 \cdot \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\pi \cdot 0.5 - \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_2, t_0\right)\right)\right)\\
\end{array}
\end{array}
if phi2 < -0.0560000000000000012Initial program 85.9%
log1p-expm1-u85.9%
log1p-udef85.7%
Applied egg-rr85.7%
if -0.0560000000000000012 < phi2 < 0.440000000000000002Initial program 72.1%
cos-diff96.0%
Applied egg-rr96.0%
cos-neg96.0%
*-commutative96.0%
fma-def96.0%
cos-neg96.0%
Simplified96.0%
Taylor expanded in phi2 around 0 96.0%
if 0.440000000000000002 < phi2 Initial program 86.2%
acos-asin86.3%
sub-neg86.3%
div-inv86.3%
metadata-eval86.3%
+-commutative86.3%
*-commutative86.3%
fma-def86.3%
Applied egg-rr86.3%
sub-neg86.3%
fma-udef86.3%
*-commutative86.3%
associate-*r*86.2%
fma-def86.3%
Simplified86.3%
Final simplification90.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(acos
(+
(* (sin phi1) (sin phi2))
(*
(* (cos phi1) (cos phi2))
(+ (* (sin lambda1) (sin lambda2)) (* (cos lambda2) (cos lambda1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda2) * cos(lambda1))))));
}
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)) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda2) * cos(lambda1))))))
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.sin(lambda1) * Math.sin(lambda2)) + (Math.cos(lambda2) * Math.cos(lambda1))))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((math.sin(phi1) * math.sin(phi2)) + ((math.cos(phi1) * math.cos(phi2)) * ((math.sin(lambda1) * math.sin(lambda2)) + (math.cos(lambda2) * math.cos(lambda1))))))
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(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda2) * cos(lambda1))))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((sin(phi1) * sin(phi2)) + ((cos(phi1) * cos(phi2)) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda2) * cos(lambda1)))))); 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[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $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(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)
\end{array}
Initial program 79.9%
cos-diff97.7%
+-commutative97.7%
Applied egg-rr97.7%
Final simplification97.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (sin phi1) (sin phi2)))
(t_1 (* (cos phi1) (cos phi2)))
(t_2 (cos (- lambda1 lambda2))))
(if (<= phi2 -0.000225)
(* R (acos (+ (log (+ 1.0 (expm1 t_0))) (* t_1 t_2))))
(if (<= phi2 0.75)
(*
R
(acos
(+
(*
t_1
(+ (* (sin lambda1) (sin lambda2)) (* (cos lambda2) (cos lambda1))))
(* (sin phi1) phi2))))
(* R (- (* PI 0.5) (asin (fma (cos phi1) (* (cos phi2) t_2) t_0))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(phi1) * sin(phi2);
double t_1 = cos(phi1) * cos(phi2);
double t_2 = cos((lambda1 - lambda2));
double tmp;
if (phi2 <= -0.000225) {
tmp = R * acos((log((1.0 + expm1(t_0))) + (t_1 * t_2)));
} else if (phi2 <= 0.75) {
tmp = R * acos(((t_1 * ((sin(lambda1) * sin(lambda2)) + (cos(lambda2) * cos(lambda1)))) + (sin(phi1) * phi2)));
} else {
tmp = R * ((((double) M_PI) * 0.5) - asin(fma(cos(phi1), (cos(phi2) * t_2), t_0)));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi1) * sin(phi2)) t_1 = Float64(cos(phi1) * cos(phi2)) t_2 = cos(Float64(lambda1 - lambda2)) tmp = 0.0 if (phi2 <= -0.000225) tmp = Float64(R * acos(Float64(log(Float64(1.0 + expm1(t_0))) + Float64(t_1 * t_2)))); elseif (phi2 <= 0.75) tmp = Float64(R * acos(Float64(Float64(t_1 * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda2) * cos(lambda1)))) + Float64(sin(phi1) * phi2)))); else tmp = Float64(R * Float64(Float64(pi * 0.5) - asin(fma(cos(phi1), Float64(cos(phi2) * t_2), t_0)))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[phi2, -0.000225], N[(R * N[ArcCos[N[(N[Log[N[(1.0 + N[(Exp[t$95$0] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(t$95$1 * t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 0.75], N[(R * N[ArcCos[N[(N[(t$95$1 * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$2), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
t_1 := \cos \phi_1 \cdot \cos \phi_2\\
t_2 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -0.000225:\\
\;\;\;\;R \cdot \cos^{-1} \left(\log \left(1 + \mathsf{expm1}\left(t_0\right)\right) + t_1 \cdot t_2\right)\\
\mathbf{elif}\;\phi_2 \leq 0.75:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right) + \sin \phi_1 \cdot \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\pi \cdot 0.5 - \sin^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_2, t_0\right)\right)\right)\\
\end{array}
\end{array}
if phi2 < -2.2499999999999999e-4Initial program 85.8%
log1p-expm1-u85.8%
log1p-udef85.7%
Applied egg-rr85.7%
if -2.2499999999999999e-4 < phi2 < 0.75Initial program 72.0%
cos-diff96.1%
+-commutative96.1%
Applied egg-rr96.1%
Taylor expanded in phi2 around 0 96.1%
if 0.75 < phi2 Initial program 86.2%
acos-asin86.3%
sub-neg86.3%
div-inv86.3%
metadata-eval86.3%
+-commutative86.3%
*-commutative86.3%
fma-def86.3%
Applied egg-rr86.3%
sub-neg86.3%
fma-udef86.3%
*-commutative86.3%
associate-*r*86.2%
fma-def86.3%
Simplified86.3%
Final simplification90.3%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (sin phi1) (sin phi2)))
(t_1 (fma (cos phi1) (* (cos phi2) (cos (- lambda1 lambda2))) t_0)))
(if (<= phi2 -1.95e-7)
(* R (acos t_1))
(if (<= phi2 3.2e-7)
(*
R
(acos
(+
t_0
(*
(cos phi1)
(+
(* (sin lambda1) (sin lambda2))
(* (cos lambda2) (cos lambda1)))))))
(* R (- (* PI 0.5) (asin t_1)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(phi1) * sin(phi2);
double t_1 = fma(cos(phi1), (cos(phi2) * cos((lambda1 - lambda2))), t_0);
double tmp;
if (phi2 <= -1.95e-7) {
tmp = R * acos(t_1);
} else if (phi2 <= 3.2e-7) {
tmp = R * acos((t_0 + (cos(phi1) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda2) * cos(lambda1))))));
} else {
tmp = R * ((((double) M_PI) * 0.5) - asin(t_1));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi1) * sin(phi2)) t_1 = fma(cos(phi1), Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))), t_0) tmp = 0.0 if (phi2 <= -1.95e-7) tmp = Float64(R * acos(t_1)); elseif (phi2 <= 3.2e-7) tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda2) * cos(lambda1))))))); else tmp = Float64(R * Float64(Float64(pi * 0.5) - asin(t_1))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[phi2, -1.95e-7], N[(R * N[ArcCos[t$95$1], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 3.2e-7], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
t_1 := \mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), t_0\right)\\
\mathbf{if}\;\phi_2 \leq -1.95 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} t_1\\
\mathbf{elif}\;\phi_2 \leq 3.2 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\pi \cdot 0.5 - \sin^{-1} t_1\right)\\
\end{array}
\end{array}
if phi2 < -1.95000000000000012e-7Initial program 85.8%
Taylor expanded in phi1 around 0 85.8%
fma-def85.9%
Simplified85.9%
if -1.95000000000000012e-7 < phi2 < 3.2000000000000001e-7Initial program 72.2%
Taylor expanded in phi2 around 0 72.2%
cos-diff96.0%
+-commutative96.0%
Applied egg-rr96.0%
if 3.2000000000000001e-7 < phi2 Initial program 85.5%
acos-asin85.6%
sub-neg85.6%
div-inv85.6%
metadata-eval85.6%
+-commutative85.6%
*-commutative85.6%
fma-def85.6%
Applied egg-rr85.6%
sub-neg85.6%
fma-udef85.6%
*-commutative85.6%
associate-*r*85.5%
fma-def85.6%
Simplified85.6%
Final simplification90.1%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0
(fma
(cos phi1)
(* (cos phi2) (cos (- lambda1 lambda2)))
(* (sin phi1) (sin phi2)))))
(if (<= phi2 -3e-179)
(* R (acos t_0))
(if (<= phi2 4.4e-170)
(*
R
(acos
(+
(*
(cos phi1)
(+ (* (sin lambda1) (sin lambda2)) (* (cos lambda2) (cos lambda1))))
(* phi1 (sin phi2)))))
(* R (- (* PI 0.5) (asin t_0)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = fma(cos(phi1), (cos(phi2) * cos((lambda1 - lambda2))), (sin(phi1) * sin(phi2)));
double tmp;
if (phi2 <= -3e-179) {
tmp = R * acos(t_0);
} else if (phi2 <= 4.4e-170) {
tmp = R * acos(((cos(phi1) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda2) * cos(lambda1)))) + (phi1 * sin(phi2))));
} else {
tmp = R * ((((double) M_PI) * 0.5) - asin(t_0));
}
return tmp;
}
function code(R, lambda1, lambda2, phi1, phi2) t_0 = fma(cos(phi1), Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))), Float64(sin(phi1) * sin(phi2))) tmp = 0.0 if (phi2 <= -3e-179) tmp = Float64(R * acos(t_0)); elseif (phi2 <= 4.4e-170) tmp = Float64(R * acos(Float64(Float64(cos(phi1) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda2) * cos(lambda1)))) + Float64(phi1 * sin(phi2))))); else tmp = Float64(R * Float64(Float64(pi * 0.5) - asin(t_0))); end return tmp end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, -3e-179], N[(R * N[ArcCos[t$95$0], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 4.4e-170], N[(R * N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\\
\mathbf{if}\;\phi_2 \leq -3 \cdot 10^{-179}:\\
\;\;\;\;R \cdot \cos^{-1} t_0\\
\mathbf{elif}\;\phi_2 \leq 4.4 \cdot 10^{-170}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right) + \phi_1 \cdot \sin \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \left(\pi \cdot 0.5 - \sin^{-1} t_0\right)\\
\end{array}
\end{array}
if phi2 < -3.00000000000000006e-179Initial program 82.7%
Taylor expanded in phi1 around 0 82.7%
fma-def82.7%
Simplified82.7%
if -3.00000000000000006e-179 < phi2 < 4.40000000000000029e-170Initial program 70.0%
Taylor expanded in phi2 around 0 70.0%
Taylor expanded in phi1 around 0 66.0%
cos-diff96.6%
+-commutative96.6%
Applied egg-rr91.0%
if 4.40000000000000029e-170 < phi2 Initial program 82.5%
acos-asin82.6%
sub-neg82.6%
div-inv82.6%
metadata-eval82.6%
+-commutative82.6%
*-commutative82.6%
fma-def82.6%
Applied egg-rr82.6%
sub-neg82.6%
fma-udef82.6%
*-commutative82.6%
associate-*r*82.5%
fma-def82.6%
Simplified82.6%
Final simplification84.4%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (cos (- lambda1 lambda2))))
(if (<= phi2 -6.5e-175)
(* R (acos (fma (cos phi1) (* (cos phi2) t_0) (* (sin phi1) (sin phi2)))))
(if (<= phi2 7e-177)
(*
R
(acos
(+
(*
(cos phi1)
(+ (* (sin lambda1) (sin lambda2)) (* (cos lambda2) (cos lambda1))))
(* phi1 (sin phi2)))))
(*
R
(acos
(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 (phi2 <= -6.5e-175) {
tmp = R * acos(fma(cos(phi1), (cos(phi2) * t_0), (sin(phi1) * sin(phi2))));
} else if (phi2 <= 7e-177) {
tmp = R * acos(((cos(phi1) * ((sin(lambda1) * sin(lambda2)) + (cos(lambda2) * cos(lambda1)))) + (phi1 * sin(phi2))));
} else {
tmp = R * acos(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 (phi2 <= -6.5e-175) tmp = Float64(R * acos(fma(cos(phi1), Float64(cos(phi2) * t_0), Float64(sin(phi1) * sin(phi2))))); elseif (phi2 <= 7e-177) tmp = Float64(R * acos(Float64(Float64(cos(phi1) * Float64(Float64(sin(lambda1) * sin(lambda2)) + Float64(cos(lambda2) * cos(lambda1)))) + Float64(phi1 * sin(phi2))))); else tmp = Float64(R * acos(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[phi2, -6.5e-175], N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * t$95$0), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[phi2, 7e-177], N[(R * N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[(N[(N[Sin[lambda1], $MachinePrecision] * N[Sin[lambda2], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[lambda2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[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]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq -6.5 \cdot 10^{-175}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot t_0, \sin \phi_1 \cdot \sin \phi_2\right)\right)\\
\mathbf{elif}\;\phi_2 \leq 7 \cdot 10^{-177}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \phi_1 \cdot \left(\sin \lambda_1 \cdot \sin \lambda_2 + \cos \lambda_2 \cdot \cos \lambda_1\right) + \phi_1 \cdot \sin \phi_2\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-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)\\
\end{array}
\end{array}
if phi2 < -6.5000000000000005e-175Initial program 83.2%
Taylor expanded in phi1 around 0 83.2%
fma-def83.3%
Simplified83.3%
if -6.5000000000000005e-175 < phi2 < 7.0000000000000003e-177Initial program 68.2%
Taylor expanded in phi2 around 0 68.2%
Taylor expanded in phi1 around 0 64.1%
cos-diff96.7%
+-commutative96.7%
Applied egg-rr90.9%
if 7.0000000000000003e-177 < phi2 Initial program 82.8%
Simplified82.8%
Final simplification84.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(*
R
(acos
(fma
(cos phi1)
(* (cos phi2) (cos (- lambda1 lambda2)))
(* (sin phi1) (sin phi2))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(fma(cos(phi1), (cos(phi2) * cos((lambda1 - lambda2))), (sin(phi1) * sin(phi2))));
}
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(fma(cos(phi1), Float64(cos(phi2) * cos(Float64(lambda1 - lambda2))), Float64(sin(phi1) * sin(phi2))))) end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\mathsf{fma}\left(\cos \phi_1, \cos \phi_2 \cdot \cos \left(\lambda_1 - \lambda_2\right), \sin \phi_1 \cdot \sin \phi_2\right)\right)
\end{array}
Initial program 79.9%
Taylor expanded in phi1 around 0 79.9%
fma-def80.0%
Simplified80.0%
Final simplification80.0%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(if (<= lambda2 5.9e-7)
(*
R
(acos
(+
(* (sin phi1) (sin phi2))
(* (cos phi1) (* (cos phi2) (cos lambda1))))))
(* R (acos (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2)))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= 5.9e-7) {
tmp = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
} else {
tmp = R * acos(((cos(phi1) * cos(phi2)) * cos((lambda1 - 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 (lambda2 <= 5.9d-7) then
tmp = r * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos(lambda1)))))
else
tmp = r * acos(((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2))))
end if
code = tmp
end function
public static double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double tmp;
if (lambda2 <= 5.9e-7) {
tmp = R * Math.acos(((Math.sin(phi1) * Math.sin(phi2)) + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos(lambda1)))));
} else {
tmp = R * Math.acos(((Math.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): tmp = 0 if lambda2 <= 5.9e-7: tmp = R * math.acos(((math.sin(phi1) * math.sin(phi2)) + (math.cos(phi1) * (math.cos(phi2) * math.cos(lambda1))))) else: tmp = R * math.acos(((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0 if (lambda2 <= 5.9e-7) tmp = Float64(R * acos(Float64(Float64(sin(phi1) * sin(phi2)) + Float64(cos(phi1) * Float64(cos(phi2) * cos(lambda1)))))); else tmp = Float64(R * acos(Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) tmp = 0.0; if (lambda2 <= 5.9e-7) tmp = R * acos(((sin(phi1) * sin(phi2)) + (cos(phi1) * (cos(phi2) * cos(lambda1))))); else tmp = R * acos(((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := If[LessEqual[lambda2, 5.9e-7], 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[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\lambda_2 \leq 5.9 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \sin \phi_2 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)\\
\end{array}
\end{array}
if lambda2 < 5.89999999999999963e-7Initial program 86.3%
cos-diff97.1%
+-commutative97.1%
Applied egg-rr97.1%
Taylor expanded in lambda2 around 0 70.3%
associate-*r*70.3%
*-commutative70.3%
associate-*l*70.3%
Simplified70.3%
if 5.89999999999999963e-7 < lambda2 Initial program 61.5%
add-cube-cbrt61.3%
pow361.3%
Applied egg-rr61.3%
rem-cube-cbrt61.5%
*-commutative61.5%
sin-mult48.3%
Applied egg-rr48.3%
Taylor expanded in phi2 around 0 48.3%
cos-neg48.3%
+-inverses48.3%
Simplified48.3%
Final simplification64.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (sin phi1) (sin phi2))))
(if (<= lambda1 -6.3e-7)
(* R (acos (+ t_0 (* (cos phi1) (* (cos phi2) (cos lambda1))))))
(* R (acos (+ t_0 (* (* (cos phi1) (cos phi2)) (cos lambda2))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = sin(phi1) * sin(phi2);
double tmp;
if (lambda1 <= -6.3e-7) {
tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))));
} else {
tmp = R * acos((t_0 + ((cos(phi1) * cos(phi2)) * 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 = sin(phi1) * sin(phi2)
if (lambda1 <= (-6.3d-7)) then
tmp = r * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1)))))
else
tmp = r * acos((t_0 + ((cos(phi1) * cos(phi2)) * 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.sin(phi1) * Math.sin(phi2);
double tmp;
if (lambda1 <= -6.3e-7) {
tmp = R * Math.acos((t_0 + (Math.cos(phi1) * (Math.cos(phi2) * Math.cos(lambda1)))));
} else {
tmp = R * Math.acos((t_0 + ((Math.cos(phi1) * Math.cos(phi2)) * Math.cos(lambda2))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = math.sin(phi1) * math.sin(phi2) tmp = 0 if lambda1 <= -6.3e-7: tmp = R * math.acos((t_0 + (math.cos(phi1) * (math.cos(phi2) * math.cos(lambda1))))) else: tmp = R * math.acos((t_0 + ((math.cos(phi1) * math.cos(phi2)) * math.cos(lambda2)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(sin(phi1) * sin(phi2)) tmp = 0.0 if (lambda1 <= -6.3e-7) tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * Float64(cos(phi2) * cos(lambda1)))))); else tmp = Float64(R * acos(Float64(t_0 + Float64(Float64(cos(phi1) * cos(phi2)) * cos(lambda2))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = sin(phi1) * sin(phi2); tmp = 0.0; if (lambda1 <= -6.3e-7) tmp = R * acos((t_0 + (cos(phi1) * (cos(phi2) * cos(lambda1))))); else tmp = R * acos((t_0 + ((cos(phi1) * cos(phi2)) * cos(lambda2)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(N[Sin[phi1], $MachinePrecision] * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -6.3e-7], N[(R * N[ArcCos[N[(t$95$0 + N[(N[Cos[phi1], $MachinePrecision] * N[(N[Cos[phi2], $MachinePrecision] * N[Cos[lambda1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(t$95$0 + N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[lambda2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -6.3 \cdot 10^{-7}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \cos \phi_1 \cdot \left(\cos \phi_2 \cdot \cos \lambda_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(t_0 + \left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \lambda_2\right)\\
\end{array}
\end{array}
if lambda1 < -6.30000000000000003e-7Initial program 67.5%
cos-diff98.3%
+-commutative98.3%
Applied egg-rr98.3%
Taylor expanded in lambda2 around 0 67.1%
associate-*r*67.1%
*-commutative67.1%
associate-*l*67.2%
Simplified67.2%
if -6.30000000000000003e-7 < lambda1 Initial program 83.3%
Taylor expanded in lambda1 around 0 70.0%
cos-neg70.0%
Simplified70.0%
Final simplification69.4%
(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 79.9%
Taylor expanded in phi1 around inf 79.9%
Final simplification79.9%
(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(Float64(cos(phi1) * 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[(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(\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)
\end{array}
Initial program 79.9%
Final simplification79.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* (cos phi1) (cos (- lambda1 lambda2)))))
(if (<= phi2 0.5)
(* R (acos (+ (* (sin phi1) phi2) t_0)))
(* 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((lambda1 - lambda2));
double tmp;
if (phi2 <= 0.5) {
tmp = R * acos(((sin(phi1) * phi2) + t_0));
} 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((lambda1 - lambda2))
if (phi2 <= 0.5d0) then
tmp = r * acos(((sin(phi1) * phi2) + t_0))
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((lambda1 - lambda2));
double tmp;
if (phi2 <= 0.5) {
tmp = R * Math.acos(((Math.sin(phi1) * phi2) + t_0));
} 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((lambda1 - lambda2)) tmp = 0 if phi2 <= 0.5: tmp = R * math.acos(((math.sin(phi1) * phi2) + t_0)) else: tmp = R * math.acos(((phi1 * math.sin(phi2)) + t_0)) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(cos(phi1) * cos(Float64(lambda1 - lambda2))) tmp = 0.0 if (phi2 <= 0.5) tmp = Float64(R * acos(Float64(Float64(sin(phi1) * phi2) + t_0))); 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((lambda1 - lambda2)); tmp = 0.0; if (phi2 <= 0.5) tmp = R * acos(((sin(phi1) * phi2) + t_0)); 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[Cos[phi1], $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi2, 0.5], N[(R * N[ArcCos[N[(N[(N[Sin[phi1], $MachinePrecision] * phi2), $MachinePrecision] + t$95$0), $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 := \cos \phi_1 \cdot \cos \left(\lambda_1 - \lambda_2\right)\\
\mathbf{if}\;\phi_2 \leq 0.5:\\
\;\;\;\;R \cdot \cos^{-1} \left(\sin \phi_1 \cdot \phi_2 + t_0\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + t_0\right)\\
\end{array}
\end{array}
if phi2 < 0.5Initial program 77.6%
Taylor expanded in phi2 around 0 50.0%
Taylor expanded in phi2 around 0 44.2%
if 0.5 < phi2 Initial program 86.2%
Taylor expanded in phi2 around 0 16.0%
Taylor expanded in phi1 around 0 9.8%
Final simplification34.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* phi1 (sin phi2))))
(if (<= phi1 -2.2e-8)
(* R (acos (+ t_0 (* (cos phi1) (cos lambda1)))))
(* R (acos (+ t_0 (cos (- lambda2 lambda1))))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = phi1 * sin(phi2);
double tmp;
if (phi1 <= -2.2e-8) {
tmp = R * acos((t_0 + (cos(phi1) * cos(lambda1))));
} else {
tmp = R * acos((t_0 + cos((lambda2 - lambda1))));
}
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 (phi1 <= (-2.2d-8)) then
tmp = r * acos((t_0 + (cos(phi1) * cos(lambda1))))
else
tmp = r * acos((t_0 + cos((lambda2 - lambda1))))
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 (phi1 <= -2.2e-8) {
tmp = R * Math.acos((t_0 + (Math.cos(phi1) * Math.cos(lambda1))));
} else {
tmp = R * Math.acos((t_0 + Math.cos((lambda2 - lambda1))));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = phi1 * math.sin(phi2) tmp = 0 if phi1 <= -2.2e-8: tmp = R * math.acos((t_0 + (math.cos(phi1) * math.cos(lambda1)))) else: tmp = R * math.acos((t_0 + math.cos((lambda2 - lambda1)))) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(phi1 * sin(phi2)) tmp = 0.0 if (phi1 <= -2.2e-8) tmp = Float64(R * acos(Float64(t_0 + Float64(cos(phi1) * cos(lambda1))))); else tmp = Float64(R * acos(Float64(t_0 + cos(Float64(lambda2 - lambda1))))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = phi1 * sin(phi2); tmp = 0.0; if (phi1 <= -2.2e-8) tmp = R * acos((t_0 + (cos(phi1) * cos(lambda1)))); else tmp = R * acos((t_0 + cos((lambda2 - lambda1)))); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[phi1, -2.2e-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[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\phi_1 \leq -2.2 \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 \left(\lambda_2 - \lambda_1\right)\right)\\
\end{array}
\end{array}
if phi1 < -2.1999999999999998e-8Initial program 82.5%
Taylor expanded in phi2 around 0 52.8%
Taylor expanded in phi1 around 0 28.5%
Taylor expanded in lambda2 around 0 19.9%
*-commutative19.9%
Simplified19.9%
if -2.1999999999999998e-8 < phi1 Initial program 79.2%
Taylor expanded in phi2 around 0 37.3%
Taylor expanded in phi1 around 0 27.0%
Taylor expanded in phi1 around 0 23.5%
sub-neg23.5%
remove-double-neg23.5%
mul-1-neg23.5%
distribute-neg-in23.5%
+-commutative23.5%
cos-neg23.5%
mul-1-neg23.5%
unsub-neg23.5%
Simplified23.5%
Final simplification22.7%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* phi1 (sin phi2))))
(if (<= lambda1 -1.8e-6)
(* 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 (lambda1 <= -1.8e-6) {
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 (lambda1 <= (-1.8d-6)) 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 (lambda1 <= -1.8e-6) {
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 lambda1 <= -1.8e-6: 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 (lambda1 <= -1.8e-6) 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 (lambda1 <= -1.8e-6) 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[lambda1, -1.8e-6], 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_1 \leq -1.8 \cdot 10^{-6}:\\
\;\;\;\;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 lambda1 < -1.79999999999999992e-6Initial program 67.5%
Taylor expanded in phi2 around 0 40.1%
Taylor expanded in phi1 around 0 26.9%
Taylor expanded in lambda2 around 0 26.3%
*-commutative26.3%
Simplified26.3%
if -1.79999999999999992e-6 < lambda1 Initial program 83.3%
Taylor expanded in phi2 around 0 41.0%
Taylor expanded in phi1 around 0 27.5%
Taylor expanded in lambda1 around 0 22.6%
cos-neg22.6%
Simplified22.6%
Final simplification23.4%
(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 79.9%
Taylor expanded in phi2 around 0 40.8%
Taylor expanded in phi1 around 0 27.3%
Final simplification27.3%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (acos (* (* (cos phi1) (cos phi2)) (cos (- lambda1 lambda2))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((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(((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.cos(phi1) * Math.cos(phi2)) * Math.cos((lambda1 - lambda2))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((math.cos(phi1) * math.cos(phi2)) * math.cos((lambda1 - lambda2))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(Float64(cos(phi1) * cos(phi2)) * cos(Float64(lambda1 - lambda2))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((cos(phi1) * cos(phi2)) * cos((lambda1 - lambda2)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(N[Cos[phi1], $MachinePrecision] * N[Cos[phi2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(lambda1 - lambda2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\left(\cos \phi_1 \cdot \cos \phi_2\right) \cdot \cos \left(\lambda_1 - \lambda_2\right)\right)
\end{array}
Initial program 79.9%
add-cube-cbrt79.7%
pow379.7%
Applied egg-rr79.7%
rem-cube-cbrt79.9%
*-commutative79.9%
sin-mult62.7%
Applied egg-rr62.7%
Taylor expanded in phi2 around 0 62.9%
cos-neg62.9%
+-inverses62.9%
Simplified62.9%
Final simplification62.9%
(FPCore (R lambda1 lambda2 phi1 phi2)
:precision binary64
(let* ((t_0 (* phi1 (sin phi2))))
(if (<= lambda1 -2e-6)
(* R (acos (+ (cos lambda1) t_0)))
(* R (acos (+ (cos lambda2) t_0))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
double t_0 = phi1 * sin(phi2);
double tmp;
if (lambda1 <= -2e-6) {
tmp = R * acos((cos(lambda1) + t_0));
} else {
tmp = R * acos((cos(lambda2) + 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 = phi1 * sin(phi2)
if (lambda1 <= (-2d-6)) then
tmp = r * acos((cos(lambda1) + t_0))
else
tmp = r * acos((cos(lambda2) + 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 = phi1 * Math.sin(phi2);
double tmp;
if (lambda1 <= -2e-6) {
tmp = R * Math.acos((Math.cos(lambda1) + t_0));
} else {
tmp = R * Math.acos((Math.cos(lambda2) + t_0));
}
return tmp;
}
def code(R, lambda1, lambda2, phi1, phi2): t_0 = phi1 * math.sin(phi2) tmp = 0 if lambda1 <= -2e-6: tmp = R * math.acos((math.cos(lambda1) + t_0)) else: tmp = R * math.acos((math.cos(lambda2) + t_0)) return tmp
function code(R, lambda1, lambda2, phi1, phi2) t_0 = Float64(phi1 * sin(phi2)) tmp = 0.0 if (lambda1 <= -2e-6) tmp = Float64(R * acos(Float64(cos(lambda1) + t_0))); else tmp = Float64(R * acos(Float64(cos(lambda2) + t_0))); end return tmp end
function tmp_2 = code(R, lambda1, lambda2, phi1, phi2) t_0 = phi1 * sin(phi2); tmp = 0.0; if (lambda1 <= -2e-6) tmp = R * acos((cos(lambda1) + t_0)); else tmp = R * acos((cos(lambda2) + t_0)); end tmp_2 = tmp; end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := Block[{t$95$0 = N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[lambda1, -2e-6], N[(R * N[ArcCos[N[(N[Cos[lambda1], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(R * N[ArcCos[N[(N[Cos[lambda2], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \phi_1 \cdot \sin \phi_2\\
\mathbf{if}\;\lambda_1 \leq -2 \cdot 10^{-6}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \lambda_1 + t_0\right)\\
\mathbf{else}:\\
\;\;\;\;R \cdot \cos^{-1} \left(\cos \lambda_2 + t_0\right)\\
\end{array}
\end{array}
if lambda1 < -1.99999999999999991e-6Initial program 67.5%
Taylor expanded in phi2 around 0 40.1%
Taylor expanded in phi1 around 0 26.9%
Taylor expanded in phi1 around 0 21.4%
sub-neg21.4%
remove-double-neg21.4%
mul-1-neg21.4%
distribute-neg-in21.4%
+-commutative21.4%
cos-neg21.4%
mul-1-neg21.4%
unsub-neg21.4%
Simplified21.4%
Taylor expanded in lambda2 around 0 20.8%
cos-neg20.8%
Simplified20.8%
if -1.99999999999999991e-6 < lambda1 Initial program 83.3%
Taylor expanded in phi2 around 0 41.0%
Taylor expanded in phi1 around 0 27.5%
Taylor expanded in phi1 around 0 19.6%
sub-neg19.6%
remove-double-neg19.6%
mul-1-neg19.6%
distribute-neg-in19.6%
+-commutative19.6%
cos-neg19.6%
mul-1-neg19.6%
unsub-neg19.6%
Simplified19.6%
Taylor expanded in lambda1 around 0 15.5%
Final simplification16.7%
(FPCore (R lambda1 lambda2 phi1 phi2) :precision binary64 (* R (acos (+ (* phi1 (sin phi2)) (cos (- lambda2 lambda1))))))
double code(double R, double lambda1, double lambda2, double phi1, double phi2) {
return R * acos(((phi1 * sin(phi2)) + cos((lambda2 - lambda1))));
}
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((lambda2 - lambda1))))
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((lambda2 - lambda1))));
}
def code(R, lambda1, lambda2, phi1, phi2): return R * math.acos(((phi1 * math.sin(phi2)) + math.cos((lambda2 - lambda1))))
function code(R, lambda1, lambda2, phi1, phi2) return Float64(R * acos(Float64(Float64(phi1 * sin(phi2)) + cos(Float64(lambda2 - lambda1))))) end
function tmp = code(R, lambda1, lambda2, phi1, phi2) tmp = R * acos(((phi1 * sin(phi2)) + cos((lambda2 - lambda1)))); end
code[R_, lambda1_, lambda2_, phi1_, phi2_] := N[(R * N[ArcCos[N[(N[(phi1 * N[Sin[phi2], $MachinePrecision]), $MachinePrecision] + N[Cos[N[(lambda2 - lambda1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
R \cdot \cos^{-1} \left(\phi_1 \cdot \sin \phi_2 + \cos \left(\lambda_2 - \lambda_1\right)\right)
\end{array}
Initial program 79.9%
Taylor expanded in phi2 around 0 40.8%
Taylor expanded in phi1 around 0 27.3%
Taylor expanded in phi1 around 0 20.0%
sub-neg20.0%
remove-double-neg20.0%
mul-1-neg20.0%
distribute-neg-in20.0%
+-commutative20.0%
cos-neg20.0%
mul-1-neg20.0%
unsub-neg20.0%
Simplified20.0%
Final simplification20.0%
(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 79.9%
Taylor expanded in phi2 around 0 40.8%
Taylor expanded in phi1 around 0 27.3%
Taylor expanded in phi1 around 0 20.0%
sub-neg20.0%
remove-double-neg20.0%
mul-1-neg20.0%
distribute-neg-in20.0%
+-commutative20.0%
cos-neg20.0%
mul-1-neg20.0%
unsub-neg20.0%
Simplified20.0%
Taylor expanded in phi2 around 0 17.5%
Final simplification17.5%
herbie shell --seed 2023318
(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))