Library prosa.util.list
From mathcomp Require Import ssreflect ssrbool eqtype ssrnat seq fintype bigop.
Require Export mathcomp.boot.path mathcomp.zify.zify.
Require Import prosa.util.tactics.
Require Export prosa.util.supremum.
Require Export mathcomp.boot.path mathcomp.zify.zify.
Require Import prosa.util.tactics.
Require Export prosa.util.supremum.
The last element is bounded by the maximum.
If every element in a set ys is greater than the corresponding element
in another set xs then the maxima of ys is also greater than the
maxima of xs.
Lemma bigmax_leq_nth :
∀ xs ys,
(∀ n, nth 0 xs n ≤ nth 0 ys n) →
(\max_(x <- xs) x) ≤ \max_(y <- ys) y.
∀ xs ys,
(∀ n, nth 0 xs n ≤ nth 0 ys n) →
(\max_(x <- xs) x) ≤ \max_(y <- ys) y.
Misc. Additional Lemmas about Sequences
Lemma filter_in_pred0 :
∀ {X : eqType} (xs : seq X) (P : pred X),
(∀ x, x \in xs → ~~ P x) →
filter P xs = [::].
∀ {X : eqType} (xs : seq X) (P : pred X),
(∀ x, x \in xs → ~~ P x) →
filter P xs = [::].
We show that in a unique sequence of size greater than one
there exist two unique elements.
Lemma exists_two :
∀ {X : eqType} (xs : seq X),
size xs > 1 →
uniq xs →
∃ a b, a ≠ b ∧ a \in xs ∧ b \in xs.
∀ {X : eqType} (xs : seq X),
size xs > 1 →
uniq xs →
∃ a b, a ≠ b ∧ a \in xs ∧ b \in xs.
If head 0 xs ≤ x < last 0 xs, then some neighboring elements
bracket x. The sequence xs need not be sorted.
Lemma belonging_to_segment_of_seq_is_total :
∀ (xs : seq nat) (x : nat),
head 0 xs ≤ x < last 0 xs →
∃ n,
n.+1 < size xs
∧ nth 0 xs n ≤ x < nth 0 xs n.+1.
∀ (xs : seq nat) (x : nat),
head 0 xs ≤ x < last 0 xs →
∃ n,
n.+1 < size xs
∧ nth 0 xs n ≤ x < nth 0 xs n.+1.
Additional Lemmas about sorted
Lemma sorted_split :
∀ {X : eqType} (xs : seq X) P f t,
sorted (fun x y ⇒ f x ≤ f y) xs →
[seq x <- xs | P x] = [seq x <- xs | P x & f x ≤ t] ++ [seq x <- xs | P x & f x > t].
∀ {X : eqType} (xs : seq X) P f t,
sorted (fun x y ⇒ f x ≤ f y) xs →
[seq x <- xs | P x] = [seq x <- xs | P x & f x ≤ t] ++ [seq x <- xs | P x & f x > t].
Additional Lemmas about last
Lemma filter_last_mem :
∀ {X : eqType} (xs : seq X) (d : X) (P : pred X),
has P xs →
last d (filter P xs) \in xs.
∀ {X : eqType} (xs : seq X) (d : X) (P : pred X),
has P xs →
last d (filter P xs) \in xs.
Range of Indices
In the following, we establish some lemmas about index_iota and range
for lists.
Splitting index_iota t1 t2 at t yields two concatenated iotas.
Lemma index_iota_cat :
∀ t t1 t2,
t1 ≤ t ≤ t2 →
index_iota t1 t2 = index_iota t1 t ++ index_iota t t2.
∀ t t1 t2,
t1 ≤ t ≤ t2 →
index_iota t1 t2 = index_iota t1 t ++ index_iota t t2.
Filtering an interval by a sequence whose minimum is x yields x
followed by the interval filtered by the values other than x.
Lemma index_iota_filter_step :
∀ x xs a b,
a ≤ x < b →
(∀ y, y \in xs → x ≤ y) →
[seq ρ <- index_iota a b | ρ \in x :: xs]
= x :: [seq ρ <- index_iota a b | ρ \in filter (predC1 x) xs].
∀ x xs a b,
a ≤ x < b →
(∀ y, y \in xs → x ≤ y) →
[seq ρ <- index_iota a b | ρ \in x :: xs]
= x :: [seq ρ <- index_iota a b | ρ \in filter (predC1 x) xs].
Additional Lemmas about count
Lemma count_predUI' :
∀ (P1 P2 : pred nat) (xs : seq nat),
count (predU P1 P2) xs = count P1 xs + count P2 xs - count (predI P1 P2) xs.
∀ (P1 P2 : pred nat) (xs : seq nat),
count (predU P1 P2) xs = count P1 xs + count P2 xs - count (predI P1 P2) xs.
Shifting Sequences of Natural Numbers
Definition shift_points_pos (xs : seq nat) (s : nat) : seq nat :=
map (addn s) xs.
Definition shift_points_neg (xs : seq nat) (s : nat) : seq nat :=
let nonsmall := filter (fun x ⇒ x ≥ s) xs in
map (fun x ⇒ x - s) nonsmall.
map (addn s) xs.
Definition shift_points_neg (xs : seq nat) (s : nat) : seq nat :=
let nonsmall := filter (fun x ⇒ x ≥ s) xs in
map (fun x ⇒ x - s) nonsmall.
Upstream Replacements and Dependent Results
Lemma last_filter {T : Type} (d : T) (xs : seq T) (P : pred T) :
P (last d xs) → last d [seq x <- xs | P x] = last d xs.
P (last d xs) → last d [seq x <- xs | P x] = last d xs.
TODO: MathComp's sub_in_count covers this lemma (merged PR 1649).
Replace it after adopting the next MathComp release containing that result:
https://github.com/math-comp/math-comp/pull/1649.
If f implies g for all elements in xs, then the number of
elements in xs satisfying f is less than or equal to the
number of elements satisfying g.
Lemma sub_count_seq :
∀ {X : eqType} (f g : pred X) (xs : seq X),
{in xs, ∀ x, f x → g x} →
count f xs ≤ count g xs.
∀ {X : eqType} (f g : pred X) (xs : seq X),
{in xs, ∀ x, f x → g x} →
count f xs ≤ count g xs.
TODO: MathComp's eq_bigmax_seq subsumes this lemma (merged PR 1652).
Replace it after adopting the next MathComp release containing that result:
https://github.com/math-comp/math-comp/pull/1652.
The maximum of a nonempty sequence belongs to the sequence.
This local corollary is kept alongside bigmax_mem because its proof
uses that lemma. Adapt the proof when replacing bigmax_mem with
MathComp's eq_bigmax_seq.
A nonempty sequence whose elements all equal k has maximum k.