regexp.abstract.utils

Require Import regexp.prelude.
Some helper lemmas
Section Cxt.
  Context {St0 St1 : finType}.
  Definition State : finType := (St0 + St1)%type.

  Lemma imset_inl (st : St0)(S : {set St0}) : ((inl st : State) \in inl @: S) = (st \in S).
  Proof using Type.
    by rewrite (mem_imset _ _ inl_inj).
  Qed.

  Lemma imset_inr (st : St1)(S : {set St1}) : ((inr st : State) \in inr @: S) = (st \in S).
  Proof.
    by rewrite (mem_imset _ _ inr_inj).
  Qed.

  Lemma imset_inl_inr (st : St0)(S : {set St1}) : (inl st : State) \in inr @: S = false.
    apply/imsetPh. case: hx h1 h2; inversion h2.
  Qed.

  Lemma imset_inr_inl (st : St1)(S : {set St0}) : inr st \in inl @: S = false.
  Proof using Type.
    apply/imsetPh; case: hx h1 h2; inversion h2.
  Qed.

End Cxt.

Lemma set_unit : [set: unit] = [set tt].
  rewrite -setPi; case i; rewrite in_set1 in_setT //=.
Qed.

Lemma snocE {A} (xs : seq A) : xs = [::] ( ys y, xs = ys ++ [::y]) .
  elim: xs ⇒ [|z zs IH].
  - by left.
  - case: IHhyp; right.
    + [::]; z; by rewrite hyp.
    + case: hypys [y] h.
       (z :: ys); y; by rewrite h.
Qed.

Definition inhabited {A : finType}(U : {set A}) : bool := [ z, z \in U].

Definition inhabitedP {A : finType}(U : {set A}) : reflect ( z , z \in U) (inhabited U) := existsP.

Lemma lemb : b : bool, b b = false.
  by case; intuition.
Qed.

Lemma inhabitedIP {A : finType}(U V : {set A}) : reflect ( z, z \in U z \in V) (inhabited (U :&: V)).
  apply/(iffP idP).
  - by case /inhabitedPz /setIP h; z.
  - by casez h; apply /inhabitedP; z; apply /setIP.
Qed.