Skip to content

Commit 6a5720b

Browse files
committed
Proven closure property for lists.
1 parent 2adba78 commit 6a5720b

File tree

2 files changed

+108
-35
lines changed

2 files changed

+108
-35
lines changed

code/Enumerability/EnumerableTypes.v

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Require Import init.imports.
22
Require Import Enumerability.EnumerablePredicates.
33
Require Import Decidability.DecidablePredicates.
4+
Require Import util.NaturalEmbedding.
45
Require Import Inductive.Option.
56
Require Import Inductive.Predicates.
67
Require Import util.NaturalEmbedding.
@@ -322,6 +323,57 @@ Section ListEnumerability.
322323
- apply propproperty.
323324
Qed.
324325

326+
Local Infix "++" := concatenate.
327+
328+
Definition listfun (X : UU) (L : nat → list X) : (nat → (list (list X))).
329+
Proof.
330+
intros n; induction n.
331+
- exact (cons nil nil).
332+
- exact (IHn ++ (map (λ (x : (X×(list X))), (cons (pr1 x) (pr2 x))) (list_prod (cumul L n) IHn))).
333+
Defined.
334+
335+
Lemma iscumulativelistfun (X : UU) (L : nat → list X) : (iscumulative (listfun X L)).
336+
Proof.
337+
intros ?; simpl.
338+
use (tpair _ (map (λ x : X × list X, cons (pr1 x) (pr2 x)) (list_prod (cumul L n) (listfun X L n)))); apply idpath.
339+
Defined.
340+
341+
Lemma listlistenumerator (X : UU) (L : nat → list X) : (islistenumerator X L) → (islistenumerator (list X) (listfun X L)).
342+
Proof.
343+
intros lstenm.
344+
use list_ind; cbn beta.
345+
- apply hinhpr. use (tpair _ 0). right; apply idpath.
346+
- intros.
347+
use (squash_to_prop X0 (propproperty _)); intros [n inn1]; clear X0.
348+
use (squash_to_prop (lstenm x) (propproperty _)); intros [m inn2]; clear lstenm.
349+
apply hinhpr; use tpair; cbn beta.
350+
+ induction (natlthorgeh n m). exact (S m). exact (S n).
351+
+ induction (natlthorgeh n m); simpl.
352+
* induction m. apply fromempty. apply (negnatlthn0 n a).
353+
set (q := (isincumulleh _ _ (iscumulativelistfun _ _) n (S m) (natlthtoleh _ _ a) inn1)).
354+
simpl. apply isin_concatenate2. apply (is_inmap (λ (x : X × (list X)), (cons (pr1 x) (pr2 x))) _ (x,, xs)), inn_list_prod1. apply isin_concatenate2. exact inn2.
355+
exact q.
356+
* induction n. set (q := (nat0gehtois0 m b)). induction (pathsinv0 q). clear q.
357+
apply isin_concatenate2. apply (is_inmap (λ (x : X × (list X)), (cons (pr1 x) (pr2 x))) _ (x,, xs)). apply inn_list_prod1. exact inn2. exact inn1.
358+
apply isin_concatenate2. apply (is_inmap (λ (x : X × (list X)), (cons (pr1 x) (pr2 x))) _ (x,, xs)). apply inn_list_prod1.
359+
assert (inn3 : is_in x (cumul L m)) by apply (isinlisincumull _ _ _ inn2).
360+
apply (isincumulleh _ _ (iscumulativecumul _) m (S n) b inn3).
361+
apply inn1.
362+
Defined.
363+
364+
Lemma islistenumerablelist {X : UU} (isenum : islistenumerable X) : (islistenumerable (list X)).
365+
Proof.
366+
use squash_to_prop.
367+
- exact (listenumerator X).
368+
- exact isenum.
369+
- apply propproperty.
370+
- clear isenum; intros [L isenum]. apply hinhpr.
371+
exact ((listfun X L),, (listlistenumerator X L isenum)).
372+
Qed.
325373

374+
Lemma isenumerablelist {X : UU} (isenum : isenumerable X) : (isenumerable (list X)).
375+
Proof.
376+
apply weqisenumerableislistenumerable, islistenumerablelist, weqisenumerableislistenumerable. exact isenum.
377+
Qed.
326378

327379
End ListEnumerability.

code/Inductive/ListProperties.v

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -272,30 +272,7 @@ Section Append.
272272
Example testappendnilright: (append l2 nil) = l2. Proof. apply idpath. Qed.
273273

274274
End AppendTests.
275-
276-
(* Local Notation "l1 ++ l2" := (append l1 l2) (at level 60, left associativity).
277-
Lemma appendnil1 {X : UU} (l1 : list X) : (l1 ++ nil) = l1.
278-
Proof.
279-
revert l1.
280-
use list_ind; cbn beta; intros.
281-
- apply idpath.
282-
- exact (maponpaths (cons x) X0).
283-
Qed.
284-
285-
Lemma appendnil1inv {X : UU} (l1 : list X) : l1 = (l1 ++ nil).
286-
Proof.
287-
apply pathsinv0, appendnil1.
288-
Qed.
289275

290-
Lemma appendnil2 {X : UU} (l1 : list X) : (nil ++ l1) = l1.
291-
Proof. apply idpath. Qed.
292-
293-
Lemma appendnil2inv {X : UU} (l2 : list X) : l2 = (nil ++ l2).
294-
Proof. apply idpath. Qed.
295-
296-
Lemma appendtrans {X : UU} (l1 l2 l3 : list X) : (l1 ++ l2) ++ l3 = l1 ++ l2 ++ l3.
297-
Proof. *)
298-
299276
Local Infix "++" := concatenate.
300277

301278
Lemma isin_concatenate1 {X : UU} (l1 l2 : list X) (x : X) : (is_in x l1) → (is_in x (l1 ++ l2)).
@@ -328,12 +305,51 @@ Section Append.
328305
Defined.
329306
End Append.
330307

308+
Section ListProduct.
309+
Local Infix "++" := concatenate.
310+
Definition list_prod {X Y : UU} (l1 : list X) (l2 : list Y) : (list (X × Y)).
311+
Proof.
312+
revert l1.
313+
use list_ind; cbn beta.
314+
- exact nil.
315+
- intros; exact ((map (λ (y : Y), (x,, y)) l2) ++ X0).
316+
Defined.
317+
318+
Lemma inn_list_prod1 {X Y : UU} (l1 : list X) (l2 : list Y) (x : X) (y : Y) : (is_in x l1) → (is_in y l2) → (is_in (x,, y) (list_prod l1 l2)).
319+
Proof.
320+
revert l1.
321+
use list_ind; cbn beta.
322+
- exact fromempty.
323+
- intros x0 xs IHl inn1 inn2.
324+
destruct inn1 as [l | r].
325+
+ apply isin_concatenate2. exact (IHl l inn2).
326+
+ apply isin_concatenate1. rewrite <- r. clear IHl r x0.
327+
revert l2 inn2. use list_ind; cbn beta.
328+
* exact (fromempty).
329+
* intros y0 ys IHl [l | r]; rewrite -> (mapStep).
330+
-- left. exact (IHl l).
331+
-- right. rewrite -> r. apply idpath.
332+
Defined.
333+
End ListProduct.
334+
335+
Section Map.
336+
337+
Lemma is_inmap {X Y : UU} (f : X → Y) (l : list X) (x : X) : (is_in x l) → (is_in (f x) (map f l)).
338+
Proof.
339+
revert l. use list_ind; cbn beta.
340+
- exact fromempty.
341+
- intros x0 xs IHl [l | r].
342+
+ left. exact (IHl l).
343+
+ right. apply maponpaths. exact r.
344+
Defined.
345+
End Map.
346+
331347
Section CumulativeFunctions.
332348

333349
Local Infix "++" := concatenate.
334-
Definition iscumulative {X : UU} (L : nat → list X) := ∏ (n : nat), (l : list X), (L (S n) = ((L n) ++ l)).
350+
Definition iscumulative {X : UU} (L : nat → list X) := ∏ (n : nat), (l : list X), (L (S n) = ((L n) ++ l)).
335351

336-
Lemma cumulativenleqm {X : UU} (L : nat → list X) (iscum : (iscumulative L)) (m n : nat) : n ≤ m → (l : list X), L m = (L n) ++ l.
352+
Lemma cumulativenleqm {X : UU} (L : nat → list X) (iscum : (iscumulative L)) (m n : nat) : n ≤ m → (l : list X), L m = (L n) ++ l.
337353
Proof.
338354
intros nleqm.
339355
assert (eq : ∑ (k : nat), n + k = m).
@@ -342,11 +358,11 @@ Section CumulativeFunctions.
342358
+ cbn beta. rewrite -> (natpluscomm n (m - n)). apply (minusplusnmm _ _ nleqm).
343359
- destruct eq as [k eq].
344360
induction eq; induction k.
345-
+ rewrite (natpluscomm n 0). apply hinhpr. use (tpair _ nil). simpl. rewrite -> (concatenate_nil (L n)). apply idpath.
346-
+ rewrite (natplusnsm n k); use (squash_to_prop (iscum (n + k)) (propproperty _)); intros [l eq]; clear iscum.
347-
use (squash_to_prop (IHk (natlehnplusnm _ _)) (propproperty _)); intros [l0 neq]; clear IHk; apply hinhpr.
361+
+ rewrite (natpluscomm n 0). use (tpair _ nil). simpl. rewrite -> (concatenate_nil (L n)). apply idpath.
362+
+ rewrite (natplusnsm n k); destruct (iscum (n + k)) as [l eq]; clear iscum.
363+
destruct (IHk (natlehnplusnm _ _)) as [l0 neq]; clear IHk.
348364
use (tpair _ (l0 ++ l)). simpl. rewrite -> eq, neq. apply assoc_concatenate.
349-
Qed.
365+
Qed.
350366

351367
Definition cumul {X : UU} : (nat → list X) → (nat → list X).
352368
Proof.
@@ -359,10 +375,8 @@ Section CumulativeFunctions.
359375
Lemma iscumulativecumul {X : UU} (L : nat → list X) : (iscumulative (cumul L)).
360376
Proof.
361377
intros n; induction n.
362-
- apply hinhpr.
363-
use (tpair _ (L 1) (idpath _)).
364-
- use (squash_to_prop IHn (propproperty _)); intros IH; clear IHn; apply hinhpr.
365-
use (tpair _ (L (S (S n))) (idpath _)).
378+
- use (tpair _ (L 1) (idpath _)).
379+
- use (tpair _ (L (S (S n))) (idpath _)).
366380
Defined.
367381

368382
Lemma isinlisincumull {X : UU} (L : nat → list X) (x : X) (n : nat) : (is_in x (L n)) → (is_in x (cumul L n)).
@@ -371,7 +385,14 @@ Section CumulativeFunctions.
371385
induction n.
372386
- exact inn.
373387
- simpl. apply isin_concatenate2. exact inn.
374-
Defined.
388+
Defined.
389+
390+
Lemma isincumulleh {X : UU} (L : nat → list X) (x : X) (iscum : iscumulative L) (n m: nat) : (n ≤ m) → (is_in x (L n)) → (is_in x (L m)).
391+
Proof.
392+
intros leq inn.
393+
set (q := cumulativenleqm L iscum m n leq); destruct q as [l eq]; rewrite -> eq.
394+
apply isin_concatenate1. exact inn.
395+
Defined.
375396

376397
Lemma iscumulex {X : UU} (L : nat → list X) (x : X) : (∃ (n : nat), (is_in x (L n))) <-> (∃ (n : nat), (is_in x (cumul L n))).
377398
Proof.
@@ -383,7 +404,7 @@ Section CumulativeFunctions.
383404
+ induction (isin_concatenate_choice (cumul L n) (L (S n)) x inn).
384405
* exact (IHn a).
385406
* exact ((S n),, b).
386-
Defined.
407+
Defined.
387408

388409
End CumulativeFunctions.
389410

0 commit comments

Comments
 (0)