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

Clean PF version

parent 968de8c7
Require Import NPeano Arith Omega.
Require Import event_models event_functions trace types util.
Require Import event_models event_functions trace types util tactics.
(* ########################## *)
(* ** Conversion functions ** *)
(* ########################## *)
Definition conversion_delta_eta (f: nb_occurrences -> duration)
: duration -> nb_occurrences :=
: duration -> nb_occurrences :=
fun (dt : duration) => max_nb_occ_in_dt f dt.
Definition conversion_eta_delta (g: duration -> nb_occurrences)
: nb_occurrences -> duration :=
fun (k: nb_occurrences) => min_dt_with_k g k.
(* ############################################ *)
(* ** Properties of the conversion functions ** *)
(* ############################################ *)
Property relation_eta_plus_delta_min_min :
forall (g: duration -> nb_occurrences) k,
g (conversion_eta_delta g k) + 1 <= k .
Property g_min_dt_lt : forall (g : duration -> nb_occurrences) (dt d: duration) (k : nb_occurrences),
g 0 = 0 -> 1 <= k
-> min_dt_with_k' dt g k = d -> g d + 1 <= k.
Proof.
intros eta_plus k.
Admitted.
induction dt; introv G H M.
- cbn in *. subst. omega.
- dupl G G1. cbn in M.
destruct k; cbn in *.
+ apply IHdt; easy.
+ destruct (le_lt_dec (g dt) k) as [I|I].
* replace (g dt <=? k) with true in M
by (symmetry; apply leb_correct; easy).
subst. omega.
* replace (g dt <=? k) with false in M
by (symmetry; apply leb_correct_conv; easy).
apply IHdt; easy.
Qed.
Property g_min_dt_le : forall (g : duration -> nb_occurrences) (dt d: duration) (k : nb_occurrences),
g 0 = 0 -> k <= g dt
-> min_dt_with_k' dt g k = d -> k <= g (d + 1).
Proof.
induction dt; introv H G M.
- cbn in *. subst. omega.
- dupl G G1. cbn in M.
destruct k; cbn in *.
+ apply IHdt; try easy. omega.
+ destruct (le_lt_dec (g dt) k) as [I|I].
* replace (g dt <=? k) with true in M
by (symmetry; apply leb_correct; easy).
subst. replace (d+1) with (S d) by omega. exact G.
* replace (g dt <=? k) with false in M
by (symmetry; apply leb_correct_conv; easy).
apply IHdt. easy. omega. easy.
Qed.
Property relation_eta_plus_delta_min_maj :
forall (g: duration -> nb_occurrences) k,
k <= g (conversion_eta_delta g k + 1).
Property relation_eta_plus_delta_min_min : forall (g: duration -> nb_occurrences) k,
g 0 = 0 -> 1 <= k
-> g (conversion_eta_delta g k) + 1 <= k .
Proof.
intros eta_plus k.
Admitted.
intros.
unfold conversion_eta_delta.
unfold min_dt_with_k.
apply g_min_dt_lt with (dt:=(S (dt_max * k))); easy.
Qed.
Property relation_eta_plus_delta_min_maj : forall (g: duration -> nb_occurrences) k,
g 0 = 0 -> k <= g (S (dt_max * k))
-> k <= g (conversion_eta_delta g k + 1).
Proof.
intros.
unfold conversion_eta_delta.
unfold min_dt_with_k.
apply g_min_dt_le with (dt:=(S (dt_max * k))); easy.
Qed.
(* Properties needed on eta functions ... *)
Definition wf_nf nf := nf 0 = 0 /\ non_decreasing nf /\ forall k, k <= nf (S (dt_max * k)).
(* eta_delta_min respect the min_delta_trace property *)
(* These three properties hold for eta t *)
Property eta_wf_nf : forall t, eta t 0 = 0 /\ non_decreasing (eta t) /\ forall k, k <= eta t (S (dt_max * k)).
Proof.
intros. split.
easy. split.
apply eta_nd.
intros; apply eta_k_dtmax.
Qed.
(* eta_delta_min respects the min_delta_trace property *)
Property conversion_eta_delta_min_delta_trace :
forall (eta_plus: duration -> nb_occurrences),
max_eta_trace eta_plus
-> non_decreasing eta_plus
-> wf_nf eta_plus
-> min_delta_trace (conversion_eta_delta eta_plus).
Proof.
intros eta_plus H_max_eta_trace H_non_decreasing_eta_plus.
intros eta_plus H_max_eta_trace [etaZero [etaIncr etaBound]].
unfold min_delta_trace.
intros n k.
assert (eta_plus (conversion_eta_delta eta_plus k) + 1 <= eta_plus (delta n k + 1)).
transitivity k.
apply (relation_eta_plus_delta_min_min eta_plus k).
apply eta_max_by_delta. easy.
apply plus_le_reg_r with (p := 1).
intros n k In.
destruct k. cbn. rewrite Nat.mul_0_r. cbn. omega.
assert (eta_plus (conversion_eta_delta eta_plus (S k)) + 1 <= eta_plus (delta n (S k) + 1)).
transitivity (S k).
apply (relation_eta_plus_delta_min_min eta_plus (S k)); try omega; try easy.
apply eta_max_by_delta; try omega; try easy.
apply plus_le_reg_r with (c := 1).
apply non_decreasing_lemma with (f := eta_plus). easy. easy.
Qed.
(* eta_delta_min respect is pseudo_superadditivity *)
(* eta_delta_min is pseudo_superadditive *)
Property conversion_eta_delta_min_superadditive:
forall (eta_plus: duration -> nb_occurrences),
subadditive eta_plus
subadditive eta_plus -> wf_nf eta_plus
-> pseudo_superadditive (conversion_eta_delta eta_plus).
Proof.
intros eta_plus H_eta_subadditive.
intros eta_plus H_eta_subadditive [etaZero [etaIncr etaBound]].
unfold pseudo_superadditive.
intros a b.
assert (eta_plus (conversion_eta_delta eta_plus (a + 1) + conversion_eta_delta eta_plus (b + 1)) + 1 <=
......@@ -72,19 +129,15 @@ apply H_eta_subadditive.
transitivity (a + b + 1).
apply plus_le_compat_r.
apply plus_le_compat with (n := eta_plus (conversion_eta_delta eta_plus (a + 1))) (m := a) (p := (eta_plus (conversion_eta_delta eta_plus (b + 1)))) (q := b).
apply plus_le_reg_r with (p := 1).
apply (relation_eta_plus_delta_min_min eta_plus (a + 1)).
apply plus_le_reg_r with (p := 1).
apply (relation_eta_plus_delta_min_min eta_plus (b + 1)).
apply plus_le_reg_r with (c := 1).
apply (relation_eta_plus_delta_min_min eta_plus (a + 1)); try omega; try easy.
apply plus_le_reg_r with (c := 1).
apply (relation_eta_plus_delta_min_min eta_plus (b + 1)); try omega; try easy.
replace (a + (b + 1)) with (a + b + 1).
apply (relation_eta_plus_delta_min_maj eta_plus (a + b + 1)).
ring_simplify; reflexivity.
apply (relation_eta_plus_delta_min_maj eta_plus (a + b + 1)); try omega; try easy.
omega.
assert (conversion_eta_delta eta_plus (a + 1) + conversion_eta_delta eta_plus (b + 1) + 1 <= conversion_eta_delta eta_plus (a + (b + 1)) + 1).
apply non_decreasing_lemma with (f:= eta_plus).
apply subadditive_implies_non_decreasing.
easy.
easy.
apply plus_le_reg_r with (p:=1).
apply non_decreasing_lemma with (f:= eta_plus); easy.
omega.
Qed.
......@@ -92,14 +145,14 @@ Qed.
(* eta_delta_min is an delta_min *)
Property conversion_eta_plus_delta_min:
forall (eta_plus: duration -> nb_occurrences),
eta_max eta_plus
eta_max eta_plus -> wf_nf eta_plus
-> delta_min (conversion_eta_delta eta_plus).
Proof.
intros.
introv [H1 H2].
unfold delta_min.
split.
+ unfold eta_max in H. apply conversion_eta_delta_min_delta_trace. easy. apply subadditive_implies_non_decreasing. easy.
+ apply conversion_eta_delta_min_superadditive. unfold eta_max in H. easy.
+ apply conversion_eta_delta_min_delta_trace; easy.
+ apply conversion_eta_delta_min_superadditive; easy.
Qed.
......
......@@ -6,19 +6,18 @@ Require Import event_model types.
(** * Evaluations *)
(* ########################################################### *)
Definition sigma1 (t : instant) : nb_occurrences :=
Definition sigma (t : instant) : nb_occurrences :=
match t with
| 0 => 0
| 1 => 0
| 2 => 1
| 3 => 2
| 4 => 1
| 5 => 1
| 9 => 3
| n => 4
| 4 => 0
| 5 => 0
| 6 => 3
| n => 1
end.
Check delta.
(*
Example test_delta : @delta sigma1 AE 1 3 = 1.
......
Require Import NPeano Arith Omega.
Require Import NPeano Arith Omega Psatz.
Require Import Coq.Program.Wf Coq.Program.Tactics.
Require Import trace types util tactics.
Set Implicit Arguments.
Require Import trace types util.
(* ######################################################## *)
(* ** Definitions related to the event load function eta ** *)
......@@ -13,142 +17,229 @@ Fixpoint eta (t : instant) (dt : duration) : nb_occurrences :=
| 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.
(* ####################### *)
(* ** Properties of eta ** *)
(* ####################### *)
Property eta_additive:
forall dt1 dt2 t,
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.
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.
(* ######################### *)
(* ** Properties of delta ** *)
(* ######################### *)
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 delta_additive:
forall k1 k2 n,
delta n (k1 + k2) = delta n k1 + delta (n + k1) (k2 + 1).
Property eta_nd : forall t, non_decreasing (eta t).
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.
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.
(* #################################### *)
(* ** Relation between eta and delta ** *)
(* #################################### *)
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.
(* Relation between delta and eta *)
Property delta_to_eta :
forall n k,
k <= eta (instant_of n) (delta n k + 1).
Corollary eta_dtmax_nz : forall t dt, 1 <= t -> dt >= dt_max -> 1 <= eta t dt.
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) )
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.
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2.
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 ** *)
(* ############################################################## *)
cut (deltainstant_of (n + k) - instant_of n + 1
*)
(** The event distance function *)
Definition delta (n : id_occurrence) (k : nb_occurrences) : duration :=
instant_of (n + k - 1) - instant_of n.
unfold eta.
Admitted.
(*
unfold delta in H.
assert (H0: instant_of(n + 1) >= instant_of(n)).
unfold instant_of.
induction n. simpl.
(* ######################### *)
(* ** Properties of delta ** *)
(* ######################### *)
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.
*)
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 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 +<