Library prosa.classic.util.pick
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq fintype.
Auxiliary Functions
Definition default0 {n} (x: option 'I_n) : nat := if x is Some y then y else 0.
Definition arg_pred_nat n (P: pred 'I_n) ord :=
[pred i | P i & [∀ j: 'I_n, P j ==> ord i j]].
Definition pred_min_nat n (P: pred 'I_n) := arg_pred_nat n P leq.
Definition pred_max_nat n (P: pred 'I_n) := arg_pred_nat n P (fun x y ⇒ geq x y).
Definition to_pred_ord n (P: pred nat) := (fun x:'I_n ⇒ P (nat_of_ord x)).
Defining Pick functions
Definition pick_any n (P: pred nat) := default0 (pick (to_pred_ord n P)).
Definition pick_min n (P: pred nat) := default0 (pick (pred_min_nat n (to_pred_ord n P))).
Definition pick_max n (P: pred nat) := default0 (pick (pred_max_nat n (to_pred_ord n P))).
Improved notation
Notation "[ 'pick-any' x <= N | P ]" :=
(pick_any N.+1 (fun x : nat ⇒ P%B))
(at level 0, x ident, only parsing) : form_scope.
Notation "[ 'pick-any' x < N | P ]" :=
(pick_any N (fun x : nat ⇒ P%B))
(at level 0, x ident, only parsing) : form_scope.
Notation "[ 'pick-min' x <= N | P ]" :=
(pick_min N.+1 (fun x : nat ⇒ P%B))
(at level 0, x ident, only parsing) : form_scope.
Notation "[ 'pick-min' x < N | P ]" :=
(pick_min N (fun x : nat ⇒ P%B))
(at level 0, x ident, only parsing) : form_scope.
Notation "[ 'pick-max' x <= N | P ]" :=
(pick_max N.+1 (fun x : nat ⇒ P%B))
(at level 0, x ident, only parsing) : form_scope.
Notation "[ 'pick-max' x < N | P ]" :=
(pick_max N (fun x : nat ⇒ P%B))
(at level 0, x ident, only parsing) : form_scope.
Lemmas about pick_any
Section PickAny.
Variable n: nat.
Variable p: pred nat.
Variable P: nat → Prop.
Hypothesis EX: ∃ x, x < n ∧ p x.
Hypothesis HOLDS: ∀ x, p x → P x.
Lemma pick_any_holds: P (pick_any n p).
End PickAny.
Lemmas about pick_min
Section PickMin.
Variable n: nat.
Variable p: pred nat.
Variable P: nat → Prop.
Hypothesis EX: ∃ x, x < n ∧ p x.
Section Bound.
Lemma pick_min_ltn: pick_min n p < n.
End Bound.
Section Minimum.
Hypothesis MIN:
∀ x,
x < n →
p x →
(∀ y, y < n → p y → x ≤ y) →
P x.
Lemma pick_min_holds: P (pick_min n p).
End Minimum.
End PickMin.
Variable n: nat.
Variable p: pred nat.
Variable P: nat → Prop.
Hypothesis EX: ∃ x, x < n ∧ p x.
Section Bound.
Lemma pick_min_ltn: pick_min n p < n.
End Bound.
Section Minimum.
Hypothesis MIN:
∀ x,
x < n →
p x →
(∀ y, y < n → p y → x ≤ y) →
P x.
Lemma pick_min_holds: P (pick_min n p).
End Minimum.
End PickMin.
Lemmas about pick_max
Section PickMax.
Variable n: nat.
Variable p: pred nat.
Variable P: nat → Prop.
Hypothesis EX: ∃ x, x < n ∧ p x.
Section Bound.
Lemma pick_max_ltn: pick_max n p < n.
End Bound.
Section Maximum.
Hypothesis MAX:
∀ x,
x < n →
p x →
(∀ y, y < n → p y → x ≥ y) →
P x.
Lemma pick_max_holds: P (pick_max n p).
End Maximum.
End PickMax.
Section Predicate.
Variable n: nat.
Variable p: pred nat.
Hypothesis EX: ∃ x, x < n ∧ p x.
Lemma pick_any_pred: p (pick_any n p).
Lemma pick_min_pred: p (pick_min n p).
Lemma pick_max_pred: p (pick_max n p).
End Predicate.
Section PickMinCompare.
Variable n: nat.
Variable p1 p2: pred nat.
Hypothesis EX1 : ∃ x, x < n ∧ p1 x.
Hypothesis EX2 : ∃ x, x < n ∧ p2 x.
Hypothesis OUT:
∀ x y, x < n → y < n → p1 x → p2 y → ~~ p1 y → x ≤ y.
Lemma pick_min_compare: pick_min n p1 ≤ pick_min n p2.
End PickMinCompare.
Variable n: nat.
Variable p: pred nat.
Variable P: nat → Prop.
Hypothesis EX: ∃ x, x < n ∧ p x.
Section Bound.
Lemma pick_max_ltn: pick_max n p < n.
End Bound.
Section Maximum.
Hypothesis MAX:
∀ x,
x < n →
p x →
(∀ y, y < n → p y → x ≥ y) →
P x.
Lemma pick_max_holds: P (pick_max n p).
End Maximum.
End PickMax.
Section Predicate.
Variable n: nat.
Variable p: pred nat.
Hypothesis EX: ∃ x, x < n ∧ p x.
Lemma pick_any_pred: p (pick_any n p).
Lemma pick_min_pred: p (pick_min n p).
Lemma pick_max_pred: p (pick_max n p).
End Predicate.
Section PickMinCompare.
Variable n: nat.
Variable p1 p2: pred nat.
Hypothesis EX1 : ∃ x, x < n ∧ p1 x.
Hypothesis EX2 : ∃ x, x < n ∧ p2 x.
Hypothesis OUT:
∀ x y, x < n → y < n → p1 x → p2 y → ~~ p1 y → x ≤ y.
Lemma pick_min_compare: pick_min n p1 ≤ pick_min n p2.
End PickMinCompare.