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 Arith NPeano List Omega.
Require Import event_model types. Require Import event_model types.
(* ########################################################### *) (* ########################################################### *)
(** * Evaluations *) (** * Evaluations *)
(* ########################################################### *) (* ########################################################### *)
Definition sigma1 (t : instant) : nb_occurrences := Definition sigma (t : instant) : nb_occurrences :=
match t with match t with
| 0 => 0 | 0 => 0
| 1 => 0 | 1 => 0
| 2 => 1 | 2 => 1
| 3 => 2 | 3 => 2
| 4 => 1 | 4 => 0
| 5 => 1 | 5 => 0
| 9 => 3 | 6 => 3
| n => 4 | n => 1
end. end.
Check delta.
(*
(* Example test_delta : @delta sigma1 AE 1 3 = 1.
Example test_delta : @delta sigma1 AE 1 3 = 1. unfold delta.
unfold delta. simpl.
simpl. unfold instant_of.
unfold instant_of. assert (H : instant_after sigma1 AE 3 0 = 3).
assert (H : instant_after sigma1 AE 3 0 = 3). -
- unfold instant_after.
unfold instant_after. elim sigma1.
elim sigma1. induction sigma1.
induction sigma1. unfold instant_after_func.
unfold instant_after_func. simpl.
simpl. induction.
induction. Eval compute in (@next sigma1 AE 1).
Eval compute in (@next sigma1 AE 1).
*) *)
\ No newline at end of file
Require Import NPeano Arith Omega. Require Import NPeano Arith Omega Psatz.
Require Import Coq.Program.Wf Coq.Program.Tactics.
Require Import trace types util.
Require Import trace types util tactics.
Set Implicit Arguments.
(* ######################################################## *) (* ######################################################## *)
(* ** Definitions related to the event load function eta ** *) (* ** Definitions related to the event load function eta ** *)
(* ######################################################## *) (* ######################################################## *)
(** The event load function *) (** The event load function *)
Fixpoint eta (t : instant) (dt : duration) : nb_occurrences := Fixpoint eta (t : instant) (dt : duration) : nb_occurrences :=
match dt with match dt with
| 0 => 0 | 0 => 0
| S dt' => sigma t + eta (S t) dt' | S dt' => sigma t + eta (S t) dt'
end. 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 ** *) (* ** Properties of eta ** *)
(* ####################### *) (* ####################### *)
Property eta_additive: Property eta_additive: forall dt1 dt2 t,
forall dt1 dt2 t, eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2.
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2. Proof.
Proof. induction dt1; intros.
intros dt1 dt2. - rewrite Nat.add_0_r; easy.
induction dt1. - cbn. rewrite IHdt1.
intros. simpl. replace (t + 0) with t; easy. rewrite <- plus_Snm_nSm.
intros. rewrite <- plus_assoc. easy.
simpl. Qed.
rewrite <- plus_assoc.
apply Nat.add_cancel_l. Corollary eta_S : forall t dt,
replace (t + S dt1) with (S t + dt1). eta t (S dt) = eta t dt + sigma (t + dt).
apply (IHdt1 (S t)). Proof.
omega. intros.
Qed. 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,
1 <= n -> 1 <= k1
Property delta_additive: -> delta n (k1 + k2) = delta n k1 + delta (n + k1 - 1) (k2 + 1).
forall k1 k2 n, Proof.
delta n (k1 + k2) = delta n k1 + delta (n + k1) (k2 + 1). introv I1 I2.
Proof. induction k1; unfold delta.
intros. - omega.
unfold delta. - unfold delta in IHk1.
rewrite plus_assoc. rewrite plus_sub_S_1.
replace (n + (k1 + 1) - 1) with (n + k1). replace (n + (S k1 + k2) - 1) with (n+k1+k2) by omega.
Focus 2. omega. replace (n + k1 + (k2+1) - 1) with (n+k1+k2) by 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). assert (X: n <= n+k1) by omega.
Admitted. 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 k n,
(* Relation between delta and eta *) 1 <= n -> 1 <= k
Property delta_to_eta : -> k <= eta (instant_of n) (delta n k + 1).
forall n k, Proof.
k <= eta (instant_of n) (delta n k + 1). (* we use strong induction *)
Proof. intros k' n. apply (lt_wf_ind k'). intros k G I1 I2.
intros. destruct k; try omega.
induction k. set (X:= exists_min (n + k) (fun z => instant_of z = instant_of (n + k))).
omega. assert (Y:forall x, instant_of x = instant_of (n + k)
replace (S k) with (k + 1). \/ instant_of x <> instant_of (n + k))
replace (delta n (k + 1)) with (delta n k + delta (n + k) 2). by (intros; destruct (Nat.eq_dec (instant_of x) (instant_of (n + k))); easy).
Focus 2. apply X in Y; try easy. clear X.
symmetry. destruct Y as [nk [X Y]].
apply delta_additive. destruct (le_lt_dec nk n) as [Z | Z].
Focus 2. omega.
replace (delta n k + delta (n + k) 2 + 1) with (delta n k + 1 + delta (n + k) 2). - apply inst_of_increasing in Z.
Focus 2. omega. rewrite X in Z.
replace (eta (instant_of n) (delta n k + 1 + delta (n + k) 2)) assert (W: instant_of n <= instant_of (n+k))
with (eta (instant_of n) (delta n k + 1) + eta (instant_of n + (delta n k + 1)) (delta (n + k) 2)). by (apply inst_of_increasing; omega).
Focus 2. symmetry. destruct (lt_eq_lt_dec (instant_of n) (instant_of (n+k))) as [[U|U]|U]; try omega.
Admitted. clear Z W.
destruct n; try omega.
(** à finir et nettoyer apply sig_ge_inst_of in U.
rewrite Nat.add_1_r.
apply (eta_additive (delta n k + 1) (delta n k + 1)). simpl. omega.
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2. - destruct nk as [? | np]; try omega.
delta n (k1 + k2) = delta n k1 + delta (n + k1) (k2 + 1). assert (U : instant_of np <> instant_of (n + k))
by (apply Y; omega).
replace (eta (instant_of n) (delta n (k + 1) + delta (n + k) 1 + 1)) destruct (le_lt_dec (S np) (n+k)) as [V|V].
with (eta (instant_of n) (delta n (k + 1)) + eta (instant_of n + delta n (k + 1)) (delta (n + k) 1 + 1)). + replace (S k) with (S np - n + (n + k - np)) by omega.
Focus 2. rewrite delta_additive; try omega.
symmetry. rewrite Nat.add_shuffle0.
replace (delta n (k + 1) + delta (n + k) 1 + 1) with (delta n (k + 1) + (delta (n + k) 1 + 1)). replace (n + (S np - n) - 1) with np by omega.
apply (eta_additive (delta n (k + 1)) (delta (n + k) 1 + 1) (instant_of n)). rewrite eta_additive.
omega. assert (R1: S np - n <= eta (instant_of n) (delta n (S np - n) + 1))
Focus 2. by (apply G; omega).
unfold delta. assert (R2: sigma (instant_of (S np)) > n + k - S np)
replace (n + k + 1 - 1) with (n + k). by (apply sig_ge_inst_of;
omega. omega. replace (S np + (n + k - S np)) with (n + k) by omega; easy).
Focus 2. replace (instant_of n + (delta n (S np - n) + 1))
omega. with (instant_of np + 1).
transitivity (eta (instant_of n) (delta n k + 1) + 1). Focus 2. unfold delta. replace (n + (S np - n) - 1) with np by omega.
apply plus_le_compat_r. assert (S: instant_of n <= instant_of np)
apply IHk. by (apply inst_of_increasing; omega).
omega.
replace (delta n (k + 1)) with (delta n (k + 1) + delta (n + k) 1). assert (L1: instant_of np + 1 <= instant_of (S np)).
Focus 2. assert (W: instant_of np <= instant_of (S np))
symmetry. by (apply inst_of_increasing; omega).
apply delta_additive. rewrite <- X in U.
replace (delta (n + k) 1) with 0. apply neq_le_imp_lt in W; try easy.
simpl. omega.
replace (eta (instant_of n) (delta n (k + 1) + delta (n + k) 1)) assert (L2: instant_of (S np) < instant_of np + 1 + delta np (n + k - np + 1)).
with (eta (instant_of n) (delta n (k + 1)) + eta (instant_of n + delta n (k + 1)) (delta (n + k) 1). unfold delta.
replace (np + (n + k - np + 1) - 1)
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2. with (n + k) by omega.
replace (instant_of np + 1 + (instant_of (n + k) - instant_of np))
unfold delta. simpl. with (instant_of (n + k) + 1) by omega. omega.
(* replace (delta n (S k) ) assert (R3: sigma (instant_of (S np)) <= eta (instant_of np + 1) (delta np (n + k - np + 1))).
apply eta_ge_sig. easy.
eta t (dt1 + dt2) = eta t dt1 + eta (t + dt1) dt2. assert (R4 : n + k - np <= sigma (instant_of (S np))) by omega.
omega.
+ assert (W1: instant_of np <= instant_of (S np))
cut (deltainstant_of (n + k) - instant_of n + 1 by (apply inst_of_increasing; omega).
*) assert (W2: instant_of (n+k) <= instant_of np)
by (apply inst_of_increasing; omega).
unfold eta. rewrite X in W1.
Admitted. destruct (lt_eq_lt_dec (instant_of np) (instant_of (n+k))) as [[?|?]|?]; try omega.
(* false.
unfold delta in H. Qed.
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.
*)
**)
Require Import NPeano Arith Omega. Require Import NPeano Arith Omega.
Require Import event_functions trace types util. Require Import event_functions trace types util tactics.
(* #################################################### *) (* #################################################### *)
(* ** Definitions related to the event load function ** *) (* ** Definitions related to the event load function ** *)
(* #################################################### *) (* #################################################### *)
Definition max_eta_trace (f : duration -> nb_occurrences) : Prop := Definition max_eta_trace (f : duration -> nb_occurrences) : Prop :=
forall t dt, eta t dt <= f dt. forall t dt, eta t dt <= f dt.
(** The event load maximum function *) (** The event load maximum function *)
Definition eta_max (f : duration -> nb_occurrences) : Prop := Definition eta_max (f : duration -> nb_occurrences) : Prop :=
max_eta_trace f /\ subadditive f. max_eta_trace f /\ subadditive f.
(* ######################################################## *) (* ######################################################## *)
(* ** Definitions related to the event distance function ** *) (* ** Definitions related to the event distance function ** *)
(* ######################################################## *) (* ######################################################## *)
Definition pseudo_superadditive (f : nat -> nat) : Prop := Definition pseudo_superadditive (f : nat -> nat) : Prop :=
forall (x y : nat), f (x + 1) + f (y + 1) <= f (x + (y + 1)). 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 :=
Definition min_delta_trace (f : nb_occurrences -> duration) : Prop := forall n k, 1 <= n -> f k <= delta n k.
forall n k, f k <= delta n k.
(** The event distance minimum function *)
(** The event distance minimum function *) Definition delta_min (f : nb_occurrences -> duration) : Prop :=
Definition delta_min (f : nb_occurrences -> duration) : Prop := min_delta_trace f /\ pseudo_superadditive f.
min_delta_trace f /\ pseudo_superadditive f.
(* Relation between delta and eta_max *)
(* Relation between delta and eta_max *) Property eta_max_by_delta :
Property eta_max_by_delta : forall n k (eta_plus : duration -> nb_occurrences),
forall n k (eta_plus : duration -> nb_occurrences), 1 <= n -> 1 <= k -> max_eta_trace eta_plus
max_eta_trace eta_plus -> k <= eta_plus ((delta n k) + 1).
-> k <= eta_plus ((delta n k) + 1). Proof.
Proof. introv I1 I2 H.
intros. transitivity (eta (instant_of n) (delta n k +1)).
unfold max_eta_trace in H. eapply delta_to_eta; try easy.
transitivity (eta (instant_of n) (delta n k +1)). apply H.
apply delta_to_eta. Qed.
apply H. \ No newline at end of file
Qed.
(* ------------------------------------------------------- *) (* ------------------------------------------------------- *)
(** #<hr> <center> <h1># (** #<hr> <center> <h1>#
Basic and simple tactics and notations Basic tactics and notations
(mostly taken form Software Foundations' LibTactics.v (mostly taken from Software Foundations' LibTactics.v
with a few complements) with a few complements)
#</h1># #</h1>#
#</center> <hr># *) #</center> <hr># *)
(* Pascal Fradet - 2014_2015 *) (* Pascal Fradet - 2014_2015 *)
(* ------------------------------------------------------- *) (* ------------------------------------------------------- *)
...@@ -614,7 +614,7 @@ Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1) ...@@ -614,7 +614,7 @@ Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
(* and the following small shortcuts *) (* and the following small shortcuts *)
(* ####################################################### *) (* ####################################################### *)
Ltac easy := solve [simpl; intros; auto]. Ltac easy := solve [cbn; intros; auto].
(* Ltac easy := solve [simpl; intros; info_auto]. *) (* Ltac easy := solve [simpl; intros; info_auto]. *)
Ltac dupl_base h1 h2 := generalize h1; intro h2. Ltac dupl_base h1 h2 := generalize h1; intro h2.
......
Require Import NPeano Arith Omega. Require Import Arith Omega Psatz.
Require Import Coq.Program.Wf Coq.Logic.ConstructiveEpsilon Coq.Logic.Decidable. Require Import Coq.Program.Wf Coq.Logic.ConstructiveEpsilon Coq.Logic.Decidable.
Require Import types util tactics.