Module FormalML.utils.ClassicUtils
Lemma find_first_none n : find_first n = None -> forall k, (k <= n)%nat -> ~ P k.
induction n; simpl.
- match_destr; intros.
apply Nat.le_0_r in H0.
congruence.
- match_option.
match_destr.
intros.
apply Nat.le_succ_r in H0.
destruct H0.
+ auto.
+ congruence.
Qed.
Lemma find_first_some_first n k : find_first n = Some k -> forall i, (i < k)%nat -> ~ P i.
induction n; simpl.
- match_destr; intros.
invcs H.
now apply Nat.nlt_0_r in H0.
- match_option.
+ intros; apply IHn; congruence.
+ match_destr; intros.
invcs H.
apply (find_first_none n); trivial.
now apply Nat.lt_succ_r.
Qed.
End find.
Definition classic_min_of_sumbool (P: nat -> Prop) :
{ n : nat | P n /\ forall k, (k < n)%nat -> ~ P k} + {forall n, ~ P n}.
Proof.
Definition classic_min_of (P: nat -> Prop) : option nat
:= match classic_min_of_sumbool P with
| inleft n => Some (proj1_sig n)
| inright _ => None
end.
Lemma classic_min_of_some P k : classic_min_of P = Some k -> P k.
Proof.
unfold classic_min_of.
match_destr.
destruct s as [?[??]].
now intros HH;
invcs HH.
Qed.
Lemma classic_min_of_some_first P k : classic_min_of P = Some k -> forall j, (j < k)%nat -> ~ P j.
Proof.
unfold classic_min_of.
match_destr.
destruct s as [?[??]].
now intros HH;
invcs HH.
Qed.
Lemma classic_min_of_none P : classic_min_of P = None -> forall k, ~ P k.
Proof.
Global Instance classic_min_of_proper :
Proper (pointwise_relation _ iff ==> eq) classic_min_of.
Proof.
intros ???.
unfold classic_min_of.
repeat match_destr.
-
destruct s as [?[??]].
destruct s0 as [?[??]];
simpl.
f_equal.
apply antisymmetry.
+
apply Compare_dec.not_lt;
intros HH.
apply H in y0.
specialize (
n _ HH);
tauto.
+
apply Compare_dec.not_lt;
intros HH.
apply H in x1.
specialize (
n0 _ HH);
tauto.
-
destruct s as [?[??]].
elim (
n x0).
now apply H.
-
destruct s as [?[??]].
elim (
n x0).
now apply H.
Qed.