Commit 83918615 authored by Sergey Bozhko's avatar Sergey Bozhko Committed by Sergey Bozhko

Update util files

parent e1e81f86
Require Export rt.util.tactics.
Require Export rt.util.notation.
Require Export rt.util.bigcat.
Require Export rt.util.pick.
Require Export rt.util.bigord.
Require Export rt.util.counting.
Require Export rt.util.div_mod.
......@@ -16,4 +17,4 @@ Require Export rt.util.sum.
Require Export rt.util.minmax.
Require Export rt.util.seqset.
Require Export rt.util.step_function.
Require Export rt.util.pick.
\ No newline at end of file
Require Export rt.util.epsilon.
......@@ -109,6 +109,52 @@ Section UniqList.
End UniqList.
(* Additional lemmas about rem for lists. *)
Section RemList.
(* We prove that if x lies in xs excluding y, then x also lies in xs. *)
Lemma rem_in:
forall (T: eqType) (x y: T) (xs: seq T),
x \in rem y xs -> x \in xs.
Proof.
clear; intros.
induction xs; simpl in H.
{ by rewrite in_nil in H. }
{ rewrite in_cons; apply/orP.
destruct (a == y) eqn:EQ.
{ by move: EQ => /eqP EQ; subst a; right. }
{ move: H; rewrite in_cons; move => /orP [/eqP H | H].
- by subst a; left.
- by right; apply IHxs.
}
}
Qed.
(* We prove that if we remove an element x for which P x from
a filter, then the size of the filter decreases by 1. *)
Lemma filter_size_rem:
forall (T: eqType) (x:T) (xs: seq T) (P: T -> bool),
(x \in xs) ->
P x ->
size [seq y <- xs | P y] = size [seq y <- rem x xs | P y] + 1.
Proof.
clear; intros.
induction xs; first by inversion H.
move: H; rewrite in_cons; move => /orP [/eqP H | H]; subst.
{ by simpl; rewrite H0 -[X in X = _]addn1 eq_refl. }
{ specialize (IHxs H); simpl in *.
case EQab: (a == x); simpl.
{ move: EQab => /eqP EQab; subst.
by rewrite H0 addn1. }
{ case Pa: (P a); simpl.
- by rewrite IHxs !addn1.
- by rewrite IHxs.
}
}
Qed.
End RemList.
(* Additional lemmas about list zip. *)
Section Zip.
......@@ -697,4 +743,89 @@ Section Order.
rel x2 x1 ->
x1 = x2.
End Order.
\ No newline at end of file
End Order.
(* In this section we prove some additional lemmas about sequences. *)
Section AdditionalLemmas.
(* We define a local function max over lists using foldl and maxn. *)
Let max := foldl maxn 0.
(* We prove that max {x, xs} is equal to max {x, max xs}. *)
Lemma seq_max_cons: forall x xs, max (x :: xs) = maxn x (max xs).
Proof.
have L: forall s x xs, foldl maxn s (x::xs) = maxn x (foldl maxn s xs).
{ clear; intros.
generalize dependent s; generalize dependent x.
induction xs.
{ by intros; rewrite maxnC. }
{ intros; simpl in *.
by rewrite maxnC IHxs [maxn s a]maxnC IHxs maxnA [maxn s x]maxnC.
}
}
by intros; unfold max; apply L.
Qed.
(* We prove that for any two sequences xs and ys the fact that xs is a subsequence
of ys implies that the size of xs is at most the size of ys. *)
Lemma subseq_leq_size:
forall {T: eqType} (xs ys: seq T),
uniq xs ->
(forall x, x \in xs -> x \in ys) ->
size xs <= size ys.
Proof.
clear; intros ? ? ? UNIQ SUB.
have Lem:
forall a ys,
(a \in ys) ->
exists ysl ysr, ys = ysl ++ [::a] ++ ysr.
{ clear; intros ? ? ? SUB.
induction ys; first by done.
move: SUB; rewrite in_cons; move => /orP [/eqP EQ|IN].
- by subst; exists [::], ys.
- feed IHys; first by done.
clear IN; move: IHys => [ysl [ysr EQ]].
by subst; exists(a0::ysl), ysr.
}
have EXm: exists m, size ys <= m.
{ by exists (size ys). }
move: EXm => [m SIZEm].
move: SIZEm UNIQ SUB; move: xs ys.
induction m.
{ intros.
move: SIZEm; rewrite leqn0 size_eq0; move => /eqP SIZEm; subst ys.
destruct xs; first by done.
specialize (SUB s).
feed SUB; first by rewrite in_cons; apply/orP; left.
by done.
}
{ intros.
destruct xs as [ | x xs]; first by done.
specialize (@Lem _ x ys).
feed Lem.
{ by apply SUB; rewrite in_cons; apply/orP; left. }
move: Lem => [ysl [ysr EQ]]; subst ys.
rewrite !size_cat; simpl; rewrite -addnC add1n addSn ltnS -size_cat.
eapply IHm.
- move: SIZEm; rewrite !size_cat; simpl; move => SIZE.
by rewrite add1n addnS ltnS addnC in SIZE.
- by move: UNIQ; rewrite cons_uniq; move => /andP [_ UNIQ].
- intros a IN.
destruct (a == x) eqn: EQ.
{ exfalso.
move: EQ UNIQ; rewrite cons_uniq; move => /eqP EQ /andP [NIN UNIQ].
by subst; move: NIN => /negP NIN; apply: NIN.
}
{ specialize (SUB a).
feed SUB.
{ by rewrite in_cons; apply/orP; right. }
clear IN; move: SUB; rewrite !mem_cat; move => /orP [IN| /orP [IN|IN]].
- by apply/orP; right.
- exfalso.
by move: IN; rewrite in_cons; move => /orP [IN|IN]; [rewrite IN in EQ | ].
- by apply/orP; left.
}
}
Qed.
End AdditionalLemmas.
\ No newline at end of file
......@@ -514,14 +514,55 @@ End MinMaxSeq.
(* Additional lemmas about max. *)
Section ExtraLemmas.
Lemma leq_big_max I r (P : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i) ->
\max_(i <- r | P i) E1 i <= \max_(i <- r | P i) E2 i.
Lemma leq_bigmax_cond_seq (T : eqType) (P : pred T) (r : seq T) F i0 :
i0 \in r -> P i0 -> F i0 <= \max_(i <- r | P i) F i.
Proof.
intros IN0 Pi0; by rewrite (big_rem i0) //= Pi0 leq_maxl.
Qed.
Lemma bigmax_sup_seq:
forall (T: eqType) (i: T) r (P: pred T) m F,
i \in r -> P i -> m <= F i -> m <= \max_(i <- r| P i) F i.
Proof.
intros.
induction r.
- by rewrite in_nil in H.
move: H; rewrite in_cons; move => /orP [/eqP EQA | IN].
{
clear IHr; subst a.
rewrite (big_rem i) //=; last by rewrite in_cons; apply/orP; left.
apply leq_trans with (F i); first by done.
by rewrite H0 leq_maxl.
}
{
apply leq_trans with (\max_(i0 <- r | P i0) F i0); first by apply IHr.
rewrite [in X in _ <= X](big_rem a) //=; last by rewrite in_cons; apply/orP; left.
have Ob: a == a; first by done.
by rewrite Ob leq_maxr.
}
Qed.
Lemma bigmax_leq_seqP (T : eqType) (P : pred T) (r : seq T) F m :
reflect (forall i, i \in r -> P i -> F i <= m)
(\max_(i <- r | P i) F i <= m).
Proof.
apply: (iffP idP) => leFm => [i IINR Pi|];
first by apply: leq_trans leFm; apply leq_bigmax_cond_seq.
rewrite big_seq_cond; elim/big_ind: _ => // m1 m2.
by intros; rewrite geq_max; apply/andP; split.
by move: m2 => /andP [M1IN Pm1]; apply: leFm.
Qed.
Lemma leq_big_max (T : eqType) (P : pred T) (r : seq T) F1 F2 :
(forall i, i \in r -> P i -> F1 i <= F2 i) ->
\max_(i <- r | P i) F1 i <= \max_(i <- r | P i) F2 i.
Proof.
move => leE12; elim/big_ind2 : _ => // m1 m2 n1 n2.
intros LE1 LE2; rewrite leq_max; unfold maxn.
by destruct (m2 < n2) eqn:LT; [by apply/orP; right | by apply/orP; left].
intros; apply /bigmax_leq_seqP; intros.
specialize (H i); feed_n 2 H; try(done).
rewrite (big_rem i) //=; rewrite H1.
by apply leq_trans with (F2 i); [ | rewrite leq_maxl].
Qed.
Lemma bigmax_ord_ltn_identity n :
......
......@@ -22,7 +22,7 @@ Section NatLemmas.
n1 >= n2 ->
(m1 + n1) - (m2 + n2) = m1 - m2 + (n1 - n2).
Proof. by ins; ssromega. Qed.
Lemma subh3 :
forall m n p,
m + p <= n ->
......@@ -33,6 +33,21 @@ Section NatLemmas.
by rewrite subh1 // -addnBA // subnn addn0.
Qed.
(* subh3: forall m n p : nat, m + p <= n -> p <= n -> m <= n - p *)
(* unnecessary condition -- ^^^^^^^^^ *)
(* TODO: del subh3 *)
Lemma subh3_ext:
forall m n p,
m + p <= n ->
m <= n - p.
Proof.
clear.
intros.
apply subh3; first by done.
apply leq_trans with (m+p); last by done.
by rewrite leq_addl.
Qed.
Lemma subh4:
forall m n p,
m <= n ->
......
......@@ -85,5 +85,50 @@ Section StepFunction.
End ExistsIntermediateValue.
End Lemmas.
(* In this section, we prove an analogue of the intermediate
value theorem, but for predicates of natural numbers. *)
Section ExistsIntermediateValuePredicates.
(* Let P be any predicate on natural numbers. *)
Variable P: nat -> bool.
(* Consider a time interval [t1,t2] such that ... *)
Variables t1 t2: nat.
Hypothesis H_t1_le_t2: t1 <= t2.
(* ... P doesn't hold for t1 ... *)
Hypothesis H_not_P_at_t1: ~~ P t1.
(* ... but holds for t2. *)
Hypothesis H_P_at_t2: P t2.
(* Then we prove that within time interval [t1,t2] there exists time
instant t such that t is the first time instant when P holds. *)
Lemma exists_first_intermediate_point:
exists t, (t1 < t <= t2) /\ (forall x, t1 <= x < t -> ~~ P x) /\ P t.
Proof.
have EX: exists x, P x && (t1 < x <= t2).
{ exists t2.
apply/andP; split; first by done.
apply/andP; split; last by done.
move: H_t1_le_t2; rewrite leq_eqVlt; move => /orP [/eqP EQ | NEQ1]; last by done.
by exfalso; subst t2; move: H_not_P_at_t1 => /negP NPt1.
}
have MIN := ex_minnP EX.
move: MIN => [x /andP [Px /andP [LT1 LT2]] MIN]; clear EX.
exists x; repeat split; [ apply/andP; split | | ]; try done.
move => y /andP [NEQ1 NEQ2]; apply/negPn; intros Py.
feed (MIN y).
{ apply/andP; split; first by done.
apply/andP; split.
- move: NEQ1. rewrite leq_eqVlt; move => /orP [/eqP EQ | NEQ1]; last by done.
by exfalso; subst y; move: H_not_P_at_t1 => /negP NPt1.
- by apply ltnW, leq_trans with x.
}
by move: NEQ2; rewrite ltnNge; move => /negP NEQ2.
Qed.
End ExistsIntermediateValuePredicates.
End StepFunction.
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment