intros; unfold distance in |- *; rewrite (Rsqr_neg (xt s2 - xt s1));
rewrite (Rsqr_neg (yt s2 - yt s1)); repeat rewrite Ropp_minus_distr...
Qed.
Definition alerting_distance (s1 s2 : State) : Prop :=
(distance s1 s2 <= AlertRange)%R.
Definition conflict_distance (s1 s2 : State) : Prop :=
(distance s1 s2 <= ConflictRange)%R.
Definition chkrange (range tpred : R) : Prop :=
(range <= AlertRange)%R /\ (tpred <= AlertTime)%R.
Definition chktrack (intruder evader : State) (tpred : R) : Prop :=
let tau := tau intruder evader 0 in
match Rle_dec tau 0 with
| left _ => chkrange (RR intruder evader 0) tpred
| right _ =>
match Rlt_dec AlertTime (tpred + tau) with
| left _ => (RR intruder evader AlertTime <= AlertRange)%R
| right _ => (RR intruder evader tau <= AlertRange)%R
end
end.
Definition arc_loop (intruder evader : State) (arcrad trkrate : R)
(idtrk iarc : nat) : Prop :=
match iarc with
| S p => False
| O =>
let tpred := (INR iarc * tstep)%R in
let xloc := (xt evader + v evaderSpeed * tpred)%R in
let yloc := yt evader in
let xtrk :=
match Rlt_le_dec 0 trkrate with
| left _ =>
(xt intruder +
arcrad *
(sind (heading intruder + trkrate * tpred) -
sind (heading intruder)))%R
| right _ =>
(xt intruder +
arcrad *
(sind (heading intruder) - sind (heading intruder) +
trkrate * tpred))%R
end in
let ytrk :=
match Rlt_le_dec 0 trkrate with
| left _ =>
(yt intruder +
arcrad *
(cosd (heading intruder) -
cosd (heading intruder + trkrate * tpred)))%R
| right _ =>
(yt intruder +
arcrad *
(cosd (heading intruder + trkrate * tpred) -
cosd (heading intruder)))%R
end in
match mod_ iarc idtrk with
| O =>
let tantrk := (heading intruder + tpred * trkrate)%R in
let int := mkState xtrk ytrk tantrk (bank intruder) in
let eva := mkState xloc yloc (heading evader) (bank evader) in
chktrack int eva tpred
| _ =>
let range := sqrt (Rsqr (xtrk - xloc) + Rsqr (ytrk - yloc)) in
chkrange range tpred
end
end.
Definition ails_alert (intruder evader : State) : Prop :=
let phi := bank intruder in
let trkrate := trkrate phi in
match Req_EM_var trkrate 0 with
| left _ => chktrack intruder evader 0
| right _ =>
let arcrad := (Rsqr (v intruderSpeed) / (g * tand (r phi)))%R in
let idtrk :=
match Rle_dec 3 trkrate with
| left _ => 1
| right _ =>
match Rle_dec (3 / 2) trkrate with
| left _ => 2
| right _ =>
match Rle_dec (3 / 4) trkrate with
| left _ => 4
| right _ => 8
end
end
end in
arc_loop intruder evader arcrad trkrate idtrk 0
end.

Lemma R_distance :
forall intruder evader : State,
RR intruder evader 0 = distance intruder evader.