Commit 4387b7c1 authored by Pascal Fradet's avatar Pascal Fradet

Clean PF version

parent 968de8c7
This diff is collapsed.
Require Import Arith NPeano List Omega.
Require Import event_model types.
Require Import Arith NPeano List Omega.
Require Import event_model types.
(* ########################################################### *)
(** * Evaluations *)
(* ########################################################### *)
Definition sigma1 (t : instant) : nb_occurrences :=
match t with
| 0 => 0
| 1 => 0
| 2 => 1
| 3 => 2
| 4 => 1
| 5 => 1
| 9 => 3
| n => 4
end.
Check delta.
(*
Example test_delta : @delta sigma1 AE 1 3 = 1.
unfold delta.
simpl.
unfold instant_of.
assert (H : instant_after sigma1 AE 3 0 = 3).
-
unfold instant_after.
elim sigma1.
induction sigma1.
unfold instant_after_func.
simpl.
induction.
Eval compute in (@next sigma1 AE 1).
(* ########################################################### *)
Definition sigma (t : instant) : nb_occurrences :=
match t with
| 0 => 0
| 1 => 0
| 2 => 1
| 3 => 2
| 4 => 0
| 5 => 0
| 6 => 3
| n => 1
end.
(*
Example test_delta : @delta sigma1 AE 1 3 = 1.
unfold delta.
simpl.
unfold instant_of.
assert (H : instant_after sigma1 AE 3 0 = 3).
-
unfold instant_after.
elim sigma1.
induction sigma1.
unfold instant_after_func.
simpl.
induction.
Eval compute in (@next sigma1 AE 1).
*)
\ No newline at end of file
Require Import NPeano Arith Omega.
Require Import trace types util.
Require Import NPeano Arith Omega Psatz.
Require Import Coq.Program.Wf Coq.Program.Tactics.
Require Import trace types util tactics.
Set Implicit Arguments.
(* ######################################################## *)
(* ** Definitions related to the event load function eta ** *)
(* ######################################################## *)
(** The event load function *)
Fixpoint eta (t : instant) (dt : duration) : nb_occurrences :=
match dt with
| 0 => 0
| S dt' => sigma t + eta (S t) dt'
end.
(* ############################################################## *)
(* ** Definitions related to the event distance function delta ** *)
(* ############################################################## *)
(** The event distance function *)
Definition delta (n : id_occurrence) (k : nb_occurrences) : duration :=
instant_of (n + k - 1) - instant_of n.
(* ######################################################## *)
(** The event load function *)
Fixpoint eta (t : instant) (dt : duration) : nb_occurrences :=
match dt with
| 0 => 0
| S dt' => sigma t + eta (S t) dt'
end.
(* ####################### *)
(* ** Properties of eta ** *)
(* ####################### *)
Property eta_additive:
forall dt1 dt2 t,
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2.
Proof.
intros dt1 dt2.
induction dt1.
intros. simpl. replace (t + 0) with t; easy.
intros.
simpl.
rewrite <- plus_assoc.
apply Nat.add_cancel_l.
replace (t + S dt1) with (S t + dt1).
apply (IHdt1 (S t)).
omega.
Qed.
(* ** Properties of eta ** *)
(* ####################### *)
Property eta_additive: forall dt1 dt2 t,
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2.
Proof.
induction dt1; intros.
- rewrite Nat.add_0_r; easy.
- cbn. rewrite IHdt1.
rewrite <- plus_Snm_nSm.
rewrite <- plus_assoc. easy.
Qed.
Corollary eta_S : forall t dt,
eta t (S dt) = eta t dt + sigma (t + dt).
Proof.
intros.
rewrite <- Nat.add_1_r.
rewrite eta_additive.
easy.
Qed.
Lemma eta_ge_sig : forall dt t x,
t <= x < t + dt -> sigma x <= eta t dt.
Proof.
induction dt; introv [I1 I2].
- omega.
- cbn. destruct (Nat.eq_dec x t).
+ subst. omega.
+ rewrite <- Nat.add_succ_comm in I2.
assert (X: sigma x <= eta (S t) dt).
apply IHdt. omega. omega.
Qed.
Property eta_nd : forall t, non_decreasing (eta t).
Proof.
unfold non_decreasing. intros t a b.
generalize b t.
induction a; introv G; cbn.
- omega.
- destruct b0; cbn. omega.
assert (X: a < b0) by omega.
apply IHa with (b:=b0) (t:= S t0) in X.
omega.
Qed.
Property etaZ : forall dt t, eta t dt = 0 -> (forall x, t <= x < t+dt -> sigma x = 0).
Proof.
induction dt; introv G [I1 I2].
- omega.
- cbn in G.
apply plus_is_O in G.
destruct G as [G1 G2].
assert (X:forall x : nat, S t <= x < S t + dt -> sigma x = 0)
by (apply IHdt; easy).
destruct (Nat.eq_dec x t) as [I|I].
+ subst. easy.
+ apply X. split; omega.
Qed.
Property eta_dtmax : forall t dt, 1 <= t -> eta t dt = 0 -> dt < dt_max.
Proof.
introv E G.
set (F:= dt_max_nz).
set (P:= fun x => t+dt <= instant_of x).
assert (X: forall x, P x \/ ~ P x).
intros. unfold P.
destruct (le_lt_dec (t+dt) (instant_of x)); omega.
set (Y := sig_imp_ge_inst_of (t+dt)). destruct Y as [km Y].
assert (Z: exists m, P m /\ forall p, p<m -> ~P p).
eapply exists_min. exact X. exact Y. clear X Y.
destruct Z as [k [X1 Y]]. unfold P in X1.
destruct k as[| k]. cbn in X1. omega.
assert (X2 : ~ t+dt <= instant_of k)
by ( apply Y; omega).
assert (X: instant_of k < t+dt) by omega. clear X2.
destruct (le_lt_dec dt_max dt); try easy.
destruct (le_lt_dec t (instant_of k)) as [W|W].
- assert (Z: forall x, t <= x < t+dt -> sigma x = 0) by (apply etaZ; easy).
assert (U: sigma (instant_of k) = 0 )
by (apply Z; split; easy).
destruct k. cbn in *. omega.
assert (V: 1 <= sigma (instant_of (S k)))
by (apply sig_inst_of_nz; omega).
omega.
- assert (Z : dt_max < instant_of (S k) - instant_of k).
omega.
assert (U: instant_of (S k) - instant_of k <= dt_max).
apply Duration_bound_between_events.
omega.
Qed.
Corollary eta_dtmax_nz : forall t dt, 1 <= t -> dt >= dt_max -> 1 <= eta t dt.
Proof.
introv I G.
destruct (Nat.eq_dec (eta t dt) 0) as [X|X].
- apply eta_dtmax with (dt:=dt) in X; try exact I.
omega.
- omega.
Qed.
Property eta_k_dtmax : forall k t, k <= eta t (S (dt_max * k)).
Proof.
induction k; intros.
- omega.
- rewrite Nat.mul_succ_r.
replace (S (dt_max * k + dt_max)) with (S (dt_max * k) + dt_max)
by omega.
rewrite eta_additive.
assert (X: k <= eta t (S (dt_max * k))) by apply IHk.
assert (Y: 1 <= eta (t + S (dt_max * k)) dt_max).
apply eta_dtmax_nz. rewrite Nat.add_succ_r.
apply Nat.lt_0_succ. easy.
omega.
Qed.
(* ############################################################## *)
(* ** Definitions related to the event distance function delta ** *)
(* ############################################################## *)
(** The event distance function *)
Definition delta (n : id_occurrence) (k : nb_occurrences) : duration :=
instant_of (n + k - 1) - instant_of n.
(* ######################### *)
(* ** Properties of delta ** *)
(* ######################### *)
(* ** Properties of delta ** *)
(* ######################### *)
Property delta_additive:
forall k1 k2 n,
delta n (k1 + k2) = delta n k1 + delta (n + k1) (k2 + 1).
Proof.
intros.
unfold delta.
rewrite plus_assoc.
replace (n + (k1 + 1) - 1) with (n + k1).
Focus 2. omega.
replace (instant_of (n + k1) - instant_of n + (instant_of (n + k1 + k2 - 1) - instant_of (n + k1))) with (instant_of (n + k1 + k2 - 1) - instant_of (n + k1) + instant_of (n + k1) - instant_of n).
Admitted.
Property delta_additive: forall k1 k2 n,
1 <= n -> 1 <= k1
-> delta n (k1 + k2) = delta n k1 + delta (n + k1 - 1) (k2 + 1).
Proof.
introv I1 I2.
induction k1; unfold delta.
- omega.
- unfold delta in IHk1.
rewrite plus_sub_S_1.
replace (n + (S k1 + k2) - 1) with (n+k1+k2) by omega.
replace (n + k1 + (k2+1) - 1) with (n+k1+k2) by omega.
assert (X: n <= n+k1) by omega.
apply inst_of_increasing in X.
assert (Y: n+k1 <= n+k1+k2) by omega.
apply inst_of_increasing in Y.
rewrite (le_sub_plus (instant_of (n + k1)) (instant_of n)
(instant_of (n + k1 + k2) - instant_of (n + k1))); try easy.
rewrite <- (le_plus_minus (instant_of (n + k1)) (instant_of (n + k1 + k2))); easy.
Qed.
(* #################################### *)
(* ** Relation between eta and delta ** *)
(* #################################### *)
(* ** Relation between eta and delta ** *)
(* #################################### *)
(* Relation between delta and eta *)
Property delta_to_eta :
forall n k,
k <= eta (instant_of n) (delta n k + 1).
Proof.
intros.
induction k.
omega.
replace (S k) with (k + 1).
replace (delta n (k + 1)) with (delta n k + delta (n + k) 2).
Focus 2.
symmetry.
apply delta_additive.
Focus 2. omega.
replace (delta n k + delta (n + k) 2 + 1) with (delta n k + 1 + delta (n + k) 2).
Focus 2. omega.
replace (eta (instant_of n) (delta n k + 1 + delta (n + k) 2))
with (eta (instant_of n) (delta n k + 1) + eta (instant_of n + (delta n k + 1)) (delta (n + k) 2)).
Focus 2. symmetry.
Admitted.
(** à finir et nettoyer
apply (eta_additive (delta n k + 1) (delta n k + 1)).
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2.
delta n (k1 + k2) = delta n k1 + delta (n + k1) (k2 + 1).
replace (eta (instant_of n) (delta n (k + 1) + delta (n + k) 1 + 1))
with (eta (instant_of n) (delta n (k + 1)) + eta (instant_of n + delta n (k + 1)) (delta (n + k) 1 + 1)).
Focus 2.
symmetry.
replace (delta n (k + 1) + delta (n + k) 1 + 1) with (delta n (k + 1) + (delta (n + k) 1 + 1)).
apply (eta_additive (delta n (k + 1)) (delta (n + k) 1 + 1) (instant_of n)).
omega.
Focus 2.
unfold delta.
replace (n + k + 1 - 1) with (n + k).
omega. omega.
Focus 2.
omega.
transitivity (eta (instant_of n) (delta n k + 1) + 1).
apply plus_le_compat_r.
apply IHk.
replace (delta n (k + 1)) with (delta n (k + 1) + delta (n + k) 1).
Focus 2.
symmetry.
apply delta_additive.
replace (delta (n + k) 1) with 0.
simpl.
replace (eta (instant_of n) (delta n (k + 1) + delta (n + k) 1))
with (eta (instant_of n) (delta n (k + 1)) + eta (instant_of n + delta n (k + 1)) (delta (n + k) 1).
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2.
unfold delta. simpl.
(* replace (delta n (S k) )
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2.
cut (deltainstant_of (n + k) - instant_of n + 1
*)
unfold eta.
Admitted.
(*
unfold delta in H.
assert (H0: instant_of(n + 1) >= instant_of(n)).
unfold instant_of.
induction n. simpl.
assert (H0: instant_of(n + k - 1) = instant_of(n)).
assert (H1: instant_of (n + k - 1) >= instant_of n).
- assert (H2: decidable (instant_of (n + k - 1) >= instant_of n))
by apply dec_ge.
destruct H2. omega.
assert (H3: instant_of (n + k - 1) < instant_of n). omega.
assert (H4: instant_of n - instant_of (n+k-1) > 0 ). omega.
contradiction.
*)
**)
(* Relation between delta and eta *)
Property delta_to_eta : forall k n,
1 <= n -> 1 <= k
-> k <= eta (instant_of n) (delta n k + 1).
Proof.
(* we use strong induction *)
intros k' n. apply (lt_wf_ind k'). intros k G I1 I2.
destruct k; try omega.
set (X:= exists_min (n + k) (fun z => instant_of z = instant_of (n + k))).
assert (Y:forall x, instant_of x = instant_of (n + k)
\/ instant_of x <> instant_of (n + k))
by (intros; destruct (Nat.eq_dec (instant_of x) (instant_of (n + k))); easy).
apply X in Y; try easy. clear X.
destruct Y as [nk [X Y]].
destruct (le_lt_dec nk n) as [Z | Z].
- apply inst_of_increasing in Z.
rewrite X in Z.
assert (W: instant_of n <= instant_of (n+k))
by (apply inst_of_increasing; omega).
destruct (lt_eq_lt_dec (instant_of n) (instant_of (n+k))) as [[U|U]|U]; try omega.
clear Z W.
destruct n; try omega.
apply sig_ge_inst_of in U.
rewrite Nat.add_1_r.
simpl. omega.
- destruct nk as [? | np]; try omega.
assert (U : instant_of np <> instant_of (n + k))
by (apply Y; omega).
destruct (le_lt_dec (S np) (n+k)) as [V|V].
+ replace (S k) with (S np - n + (n + k - np)) by omega.
rewrite delta_additive; try omega.
rewrite Nat.add_shuffle0.
replace (n + (S np - n) - 1) with np by omega.
rewrite eta_additive.
assert (R1: S np - n <= eta (instant_of n) (delta n (S np - n) + 1))
by (apply G; omega).
assert (R2: sigma (instant_of (S np)) > n + k - S np)
by (apply sig_ge_inst_of;
replace (S np + (n + k - S np)) with (n + k) by omega; easy).
replace (instant_of n + (delta n (S np - n) + 1))
with (instant_of np + 1).
Focus 2. unfold delta. replace (n + (S np - n) - 1) with np by omega.
assert (S: instant_of n <= instant_of np)
by (apply inst_of_increasing; omega).
omega.
assert (L1: instant_of np + 1 <= instant_of (S np)).
assert (W: instant_of np <= instant_of (S np))
by (apply inst_of_increasing; omega).
rewrite <- X in U.
apply neq_le_imp_lt in W; try easy.
omega.
assert (L2: instant_of (S np) < instant_of np + 1 + delta np (n + k - np + 1)).
unfold delta.
replace (np + (n + k - np + 1) - 1)
with (n + k) by omega.
replace (instant_of np + 1 + (instant_of (n + k) - instant_of np))
with (instant_of (n + k) + 1) by omega. omega.
assert (R3: sigma (instant_of (S np)) <= eta (instant_of np + 1) (delta np (n + k - np + 1))).
apply eta_ge_sig. easy.
assert (R4 : n + k - np <= sigma (instant_of (S np))) by omega.
omega.
+ assert (W1: instant_of np <= instant_of (S np))
by (apply inst_of_increasing; omega).
assert (W2: instant_of (n+k) <= instant_of np)
by (apply inst_of_increasing; omega).
rewrite X in W1.
destruct (lt_eq_lt_dec (instant_of np) (instant_of (n+k))) as [[?|?]|?]; try omega.
false.
Qed.
Require Import NPeano Arith Omega.
Require Import event_functions trace types util.
Require Import NPeano Arith Omega.
Require Import event_functions trace types util tactics.
(* #################################################### *)
(* ** Definitions related to the event load function ** *)
(* #################################################### *)
Definition max_eta_trace (f : duration -> nb_occurrences) : Prop :=
forall t dt, eta t dt <= f dt.
(** The event load maximum function *)
Definition eta_max (f : duration -> nb_occurrences) : Prop :=
max_eta_trace f /\ subadditive f.
(* #################################################### *)
Definition max_eta_trace (f : duration -> nb_occurrences) : Prop :=
forall t dt, eta t dt <= f dt.
(** The event load maximum function *)
Definition eta_max (f : duration -> nb_occurrences) : Prop :=
max_eta_trace f /\ subadditive f.
(* ######################################################## *)
(* ** Definitions related to the event distance function ** *)
(* ######################################################## *)
Definition pseudo_superadditive (f : nat -> nat) : Prop :=
forall (x y : nat), f (x + 1) + f (y + 1) <= f (x + (y + 1)).
Definition pseudo_superadditive (f : nat -> nat) : Prop :=
forall (x y : nat), f (x + 1) + f (y + 1) <= f (x + (y + 1)).
Definition min_delta_trace (f : nb_occurrences -> duration) : Prop :=
forall n k, f k <= delta n k.
(** The event distance minimum function *)
Definition delta_min (f : nb_occurrences -> duration) : Prop :=
min_delta_trace f /\ pseudo_superadditive f.
(* Relation between delta and eta_max *)
Property eta_max_by_delta :
forall n k (eta_plus : duration -> nb_occurrences),
max_eta_trace eta_plus
-> k <= eta_plus ((delta n k) + 1).
Proof.
intros.
unfold max_eta_trace in H.
transitivity (eta (instant_of n) (delta n k +1)).
apply delta_to_eta.
apply H.
Qed.
(* ######################################################## *)
Definition pseudo_superadditive (f : nat -> nat) : Prop :=
forall (x y : nat), f (x + 1) + f (y + 1) <= f (x + (y + 1)).
Definition min_delta_trace (f : nb_occurrences -> duration) : Prop :=
forall n k, 1 <= n -> f k <= delta n k.
(** The event distance minimum function *)
Definition delta_min (f : nb_occurrences -> duration) : Prop :=
min_delta_trace f /\ pseudo_superadditive f.
(* Relation between delta and eta_max *)
Property eta_max_by_delta :
forall n k (eta_plus : duration -> nb_occurrences),
1 <= n -> 1 <= k -> max_eta_trace eta_plus
-> k <= eta_plus ((delta n k) + 1).
Proof.
introv I1 I2 H.
transitivity (eta (instant_of n) (delta n k +1)).
eapply delta_to_eta; try easy.
apply H.
Qed.
\ No newline at end of file
(* ------------------------------------------------------- *)
(** #<hr> <center> <h1>#
Basic and simple tactics and notations
(mostly taken form Software Foundations' LibTactics.v
with a few complements)
#</h1>#
Basic tactics and notations
(mostly taken from Software Foundations' LibTactics.v
with a few complements)
#</h1>#
#</center> <hr># *)