Library prosa.util.bigcat

Lemmas Awaiting the Next MathComp Release

In this section, we introduce a few lemmas about the concatenation operation performed over arbitrary sequences.
Section BigCatSeqLemmas.

Consider any two types X and Y supporting equality comparisons...
  Variable X Y : eqType.

...and a function f that, given an index X, yields a sequence of Y.
  Variable f : X → seq Y.

First, we show that the concatenation comprises all the elements of each sequence; i.e. any element contained in one of the sequences will also be an element of the result of the concatenation. TODO: MathComp's mem_bigcatP covers this lemma and is expected in the next MathComp release (PR 1660: https://github.com/math-comp/math-comp/pull/1660).
  Lemma mem_bigcat :
    ∀ x y s,
      x \in s →
      y \in f x →
      y \in \cat_(x <- s) f x.

Conversely, we prove that any element belonging to a concatenation of sequences must come from one of the sequences. TODO: MathComp's mem_bigcatP covers this lemma and is expected in the next MathComp release (PR 1660: https://github.com/math-comp/math-comp/pull/1660).
  Lemma mem_bigcat_exists :
    ∀ {P} s y,
      y \in \cat_(x <- s | P x) f x →
      ∃ x, x \in s ∧ y \in f x.

In this section, we show how we can preserve uniqueness of the elements (i.e. the absence of a duplicate) over a concatenation of sequences.
  Section BigCatDistinctElements.

Consider a list xs, ...
    Context {xs : seq X}.

... a filter predicate P, ...
    Context {P : pred X}.

... assume that there are no duplicates in each of the possible sequences to concatenate...
    Hypothesis H_uniq_f : ∀ x, P x → uniq (f x).

...and that there are no elements in common between the sequences.
    Hypothesis H_no_elements_in_common :
      ∀ x y z,
        x \in f y → x \in f z → y = z.

We prove that the concatenation will yield a sequence with unique elements. TODO: MathComp's bigcat_uniq covers this lemma and is expected in the next MathComp release (PR 1660: https://github.com/math-comp/math-comp/pull/1660).
    Lemma bigcat_uniq :
        uniq xs →
        uniq (\cat_(x <- xs | P x) (f x)).

  End BigCatDistinctElements.

End BigCatSeqLemmas.

In this section, we introduce lemmas about the concatenation operation performed over arbitrary sequences.
Section BigCatNatLemmas.

Consider any type T supporting equality comparisons...
  Variable T : eqType.

...and a function f that, given an index, yields a sequence.
  Variable f : nat → seq T.

First, we show that the concatenation comprises all the elements of each sequence; i.e., any element contained in one of the sequences will also be an element of the result of the concatenation. TODO: MathComp's mem_bigcatP covers this lemma and is expected in the next MathComp release (PR 1660: https://github.com/math-comp/math-comp/pull/1660).
  Lemma mem_bigcat_nat :
    ∀ x m n j,
      m ≤ j < n →
      x \in f j →
      x \in \cat_(m ≤ i < n) (f i).

Conversely, we prove that any element belonging to a concatenation of sequences must come from one of the sequences. TODO: MathComp's mem_bigcatP covers this lemma and is expected in the next MathComp release (PR 1660: https://github.com/math-comp/math-comp/pull/1660).
  Lemma mem_bigcat_nat_exists :
    ∀ x m n,
      x \in \cat_(m ≤ i < n) (f i) →
      ∃ i,
        x \in f i ∧ m ≤ i < n.

We also restate lemma mem_bigcat_nat in terms of ordinals. TODO: MathComp's mem_bigcatP covers this lemma and is expected in the next MathComp release (PR 1660: https://github.com/math-comp/math-comp/pull/1660).
  Lemma mem_bigcat_ord :
    ∀ (x : T) (n : nat) (j : 'I_n) (f : 'I_n → seq T),
      j < n →
      x \in (f j) →
      x \in \cat_(i < n) (f i).

In this section, we show how we can preserve uniqueness of the elements (i.e. the absence of a duplicate) over a concatenation of sequences.
Assume that there are no duplicates in each of the possible sequences to concatenate...
    Hypothesis H_uniq_seq : ∀ i, uniq (f i).

...and that there are no elements in common between the sequences.
    Hypothesis H_no_elements_in_common :
      ∀ x i1 i2, x \in f i1 → x \in f i2 → i1 = i2.

We prove that the concatenation will yield a sequence with unique elements. TODO: MathComp's bigcat_uniq covers this lemma and is expected in the next MathComp release (PR 1660: https://github.com/math-comp/math-comp/pull/1660).
    Lemma bigcat_nat_uniq :
      ∀ n1 n2,
        uniq (\cat_(n1 ≤ i < n2) (f i)).

  End BigCatNatDistinctElements.

End BigCatNatLemmas.

Recovering a Component of a Concatenation

In this section, we show how to recover one sequence from a concatenation by filtering for the elements that originate from it.
Consider any two types X and Y supporting equality comparisons...
  Variable X Y : eqType.

...and a function f that, given an index X, yields a sequence of Y.
  Variable f : X → seq Y.

Consider a function g...
  Variable g : Y → X.

... and assume that g can cancel f starting from an element of the sequence f x.
  Hypothesis H_g_cancels_f : ∀ x y, y \in f x → g y = x.

Assume we are given an element y which is contained in a duplicate-free sequence xs. Then, f is applied to each element of xs, but only the elements for which g yields y are kept. In this scenario, concatenating the resulting sequences will always lead to f y.
  Lemma bigcat_seq_uniqK :
    ∀ y xs,
      y \in xs →
      uniq xs →
      \cat_(x <- xs) [seq x' <- f x | g x' == y] = f y.

End BigCatReconstruction.