Skip to content

Commit 6ec6557

Browse files
authored
Added proof that KFinite types with decidable equality are Bishop finite (UniMath#2047)
1 parent 5941f44 commit 6ec6557

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

UniMath/Combinatorics/FiniteSets.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,12 @@ Delimit Scope finset with finset.
618618
Notation "'∑' x .. y , P" := (FiniteSetSum (λ x,.. (FiniteSetSum (λ y, P))..))
619619
(at level 200, x binder, y binder, right associativity) : finset.
620620
(* type this in emacs in agda-input method with \sum *)
621+
622+
(* A surjection from stn 0 is an equivalence *)
623+
Lemma surj_from_stn0_to_neg {X : UU} (f : ⟦ 0 ⟧ → X ) : (issurjective f) → nelstruct 0 X.
624+
Proof.
625+
intros surj. apply tpair with (pr1 := f). intros x.
626+
apply fromempty, (squash_to_prop (surj x) (isapropempty)).
627+
intros [contra eq]; clear surj.
628+
apply negstn0, contra.
629+
Qed.

UniMath/Combinatorics/KFiniteTypes.v

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Require Import UniMath.Foundations.Propositions.
2424
Require Import UniMath.MoreFoundations.PartA.
2525
Require Import UniMath.MoreFoundations.Notations.
26+
Require Import UniMath.MoreFoundations.DecidablePropositions.
2627
Require Import UniMath.Combinatorics.FiniteSets.
2728
Require Import UniMath.Combinatorics.StandardFiniteSets.
2829

@@ -241,3 +242,90 @@ Section kfinite_definition.
241242
:= hinhfun kfinstruct_finstruct.
242243

243244
End kfinite_definition.
245+
246+
Section iskfinite_isdeceq_isfinite.
247+
(**
248+
This section provides the necessary construction to prove that
249+
every K-Finite type with decidable equality is Bishop-finite.
250+
251+
Proof outline:
252+
Let X be a K-Finite type. Then there exists n : nat with a surjection
253+
from stn n to X.
254+
255+
The proof goes by induction on n, with the type X being generalized.
256+
In the base case, we have a surjection from an uninhabited type to X.
257+
Thus, X must also have no elements and therefore, X is equivalent with
258+
stn 0.
259+
260+
In the inductive step, we assume that for any type X for which there
261+
exists a surjection from stn n to X and has decidable equality is
262+
Bishop finite. We have to show that if there exists a surjection f
263+
from stn (S n) to X and X has decidable equality, then X is Bishop
264+
finite.
265+
Let g : stn n -> X such that g (x) := f x. If X has decidable equality,
266+
then it is decidable whether f (n) is included in the image of g.
267+
268+
We will thus proceed by case analysis on whether f n is included in the image of g.
269+
If f n is included in the image of g, then g must be a surjection as well. By the inductive
270+
hypothesis X is Bishop finite. If f n is not included in the image of g, we will denote
271+
y := f n. We now consider the type X / y (pair X (\x -> x != y)) which is inhabited by
272+
terms different than y. First, we note that X / y has decidable equality. Secondly, we note
273+
that X / y + unit is equivalent to X. Lastly, we note that by restricting the codomain of g
274+
to X / y, we obtain a surjection g1 : stn n -> X / y. By the inductive hypothesis, the type
275+
X / y is Bishop finite, and thus equivalent to stn m for some m : nat.
276+
To conclude, we have the following chain of equivalences
277+
X ≃ X / y + 1 ≃ stn m + 1 ≃ stn (S m). Thus, X is Bishop finite.
278+
279+
*)
280+
281+
Lemma issurjective_stnfun_singleton_complement {X : UU} {n : nat} (f : stn (S n) → X)
282+
(nfib : ¬ hfiber (fun_stnsn_to_stnn f) (f lastelement)) : issurjective f →
283+
issurjective (stnfun_singleton_complement f nfib).
284+
Proof.
285+
intros surjf y.
286+
destruct y as [x neq].
287+
use squash_to_prop.
288+
- exact (hfiber f x).
289+
- exact (surjf x).
290+
- apply propproperty.
291+
- intros [[m lth] q]; clear surjf. apply hinhpr.
292+
induction (natlehchoice _ _ (natlthsntoleh _ _ lth)).
293+
+ apply (tpair _ (m ,, a)).
294+
unfold stnfun_singleton_complement, fun_stnsn_to_stnn, make_stn.
295+
apply subtypePath_prop; cbn.
296+
induction q. apply maponpaths, stn_eq, idpath.
297+
+ assert (H : (m ,, lth = lastelement)) by apply stn_eq, b.
298+
apply fromempty. induction neq. induction H. apply pathsinv0, q.
299+
Qed.
300+
301+
Lemma kfinstruct_dec_finstruct {X : UU} : isdeceq X → kfinstruct X → finstruct X.
302+
Proof.
303+
intros deceqX [n [f surj]].
304+
generalize dependent X.
305+
induction n; intros.
306+
- apply tpair with (pr1 := 0).
307+
apply surj_from_stn0_to_neg with (f := f). assumption.
308+
- set (g := fun_stnsn_to_stnn f).
309+
set (y := f lastelement).
310+
induction (isdeceq_isdecsurj g y deceqX).
311+
+ apply IHn with (f := g); try apply surj_fun_stnsn_to_stnn; assumption.
312+
+ set (g' := stnfun_singleton_complement f b).
313+
set (surjg' := (issurjective_stnfun_singleton_complement f b surj)).
314+
specialize IHn with (f := g').
315+
apply IHn in surjg';
316+
[ | apply isdeceq_subtype; try assumption; intros x; apply isapropneg ].
317+
destruct surjg' as [s1 s2].
318+
apply tpair with (pr1 := (S s1)); unfold nelstruct.
319+
eapply weqcomp.
320+
* apply invweq, weqdnicoprod, lastelement.
321+
* eapply weqcomp.
322+
{ eapply weqcoprodf1, s2. }
323+
apply weq_singleton_complement_unit; assumption.
324+
Qed.
325+
326+
Lemma iskfinite_dec_to_isfinite {X : UU} : isdeceq X → iskfinite X → isfinite X.
327+
Proof.
328+
intros deceqX. apply hinhfun, kfinstruct_dec_finstruct, deceqX.
329+
Qed.
330+
331+
End iskfinite_isdeceq_isfinite.

UniMath/Combinatorics/StandardFiniteSets.v

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,3 +2025,55 @@ Lemma stn_ord_bij {n : nat} (f : ⟦ n ⟧ ≃ ⟦ n ⟧) :
20252025
Proof.
20262026
apply (stn_ord_inj (weqtoincl f)).
20272027
Defined.
2028+
2029+
(* Functions with domain in Standard finite sets. *)
2030+
Definition fun_stnsn_to_stnn {X : UU} {n : nat} (f : stn (S n) → X) : stn n → X := f ∘ dni_lastelement.
2031+
2032+
Definition stnfun_singleton_complement {X : UU} {n : nat} (f : stn (S n) → X) :
2033+
¬ hfiber (fun_stnsn_to_stnn f) (f lastelement) → stn n →
2034+
(singleton_complement (f lastelement)).
2035+
Proof.
2036+
intros X0 X1.
2037+
exists (fun_stnsn_to_stnn f X1).
2038+
intros contra. apply X0.
2039+
eexists. apply contra.
2040+
Defined.
2041+
2042+
Lemma isdeceq_isdecsurj {X : UU} {n : nat} (f : ⟦ n ⟧ → X ) (y : X) :
2043+
isdeceq X → decidable (hfiber f y).
2044+
Proof.
2045+
generalize dependent X.
2046+
induction n; intros X f x deceqX.
2047+
- right. intros contra. eapply weqstn0toempty, pr1, contra.
2048+
- set (g := fun_stnsn_to_stnn f). specialize IHn with (f := g) (y := x).
2049+
set (H := IHn deceqX).
2050+
induction H.
2051+
+ left. induction a as [p eq]. induction p as [m lth].
2052+
apply tpair with (pr1 := (m ,, (natlthtolths _ _ lth))), eq.
2053+
+ induction (deceqX (f (lastelement)) x); [left | right].
2054+
* apply (tpair _ lastelement). assumption.
2055+
* intros H. induction H as [p eq]. induction p as [m lth].
2056+
induction (natlehchoice _ _ (natlthsntoleh _ _ lth)).
2057+
-- apply b. apply tpair with (pr1 := (m ,, a)).
2058+
induction eq. unfold g, fun_stnsn_to_stnn, make_stn. unfold funcomp.
2059+
apply maponpaths, stn_eq, idpath.
2060+
-- apply b0. unfold lastelement. induction b1, eq.
2061+
apply maponpaths, stn_eq, idpath.
2062+
Qed.
2063+
2064+
Lemma surj_fun_stnsn_to_stnn {X : UU} {n : nat} (f : ⟦ S n ⟧ → X) : isdeceq X → issurjective f →
2065+
hfiber (fun_stnsn_to_stnn f) (f lastelement) → issurjective (fun_stnsn_to_stnn f).
2066+
Proof.
2067+
intros deceqX surj x. induction x as [x eq].
2068+
intros y'.
2069+
induction (deceqX (f lastelement) y').
2070+
- induction a. apply hinhpr, tpair with (pr1 := x), eq.
2071+
- apply (squash_to_prop (surj y')); try apply propproperty.
2072+
intros m. induction m as [m eq']; induction m as [m lth]. apply hinhpr.
2073+
induction (natlehchoice _ _ (natlthsntoleh _ _ lth)).
2074+
+ apply tpair with (pr1 := m ,, a).
2075+
unfold fun_stnsn_to_stnn, make_stn, funcomp.
2076+
induction eq'. apply maponpaths, stn_eq, idpath.
2077+
+ induction eq', b0. apply fromempty, b.
2078+
apply maponpaths, stn_eq, idpath.
2079+
Qed.

UniMath/MoreFoundations/DecidablePropositions.v

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,39 @@ Definition natneq_DecidableProposition : DecidableRelation nat :=
456456

457457
End DecidablePropositions.
458458

459+
Section DecidableEquality.
460+
461+
Lemma isdeceq_subtype {X : UU} (P : hsubtype X) :
462+
isdeceq X → isdeceq P.
463+
Proof.
464+
intros deceqX predP. apply isdeceq_total2.
465+
+ apply deceqX.
466+
+ intros x. apply isdeceqifisaprop, propproperty.
467+
Qed.
468+
469+
Definition singleton_complement {X : UU} (y : X) : hsubtype X := λ x, make_hProp (x != y) (isapropneg (x = y)).
470+
471+
Lemma weq_singleton_complement_unit {X : UU} (y : X) : isdeceq X → carrier (singleton_complement y) ⨿ unit ≃ X.
472+
Proof.
473+
intros deceqx.
474+
use weq_iso.
475+
- intros [[x neq] | tt]; [apply x | apply y].
476+
- intros x. induction (deceqx x y); [right; apply tt | left].
477+
apply tpair with (pr1 := x), b.
478+
- intros [[x neq] | tt].
479+
+ induction (deceqx x y).
480+
* apply fromempty. induction neq. assumption.
481+
* cbn. apply maponpaths, subtypePath_prop, idpath.
482+
+ induction (deceqx y y).
483+
* induction tt. apply idpath.
484+
* apply fromempty, b, idpath.
485+
- intros x; cbn beta.
486+
induction (deceqx x y); cbn beta;
487+
try induction a; apply idpath.
488+
Qed.
489+
490+
End DecidableEquality.
491+
459492
Declare Scope decidable_nat.
460493
Notation " x < y " := (natlth_DecidableProposition x y) (at level 70, no associativity) :
461494
decidable_nat.

0 commit comments

Comments
 (0)