forked from UniMath/UniMath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auxiliary.v
656 lines (557 loc) · 17.8 KB
/
Auxiliary.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
(** * Matrices
Miscellaneous background lemmas for [GaussianElimination.Elimination]
Primary Author: Daniel @Skantz (November 2022)
*)
Require Import UniMath.Foundations.All.
Require Import UniMath.MoreFoundations.All.
Require Import UniMath.Combinatorics.Maybe.
Require Import UniMath.Combinatorics.StandardFiniteSets.
Require Import UniMath.Algebra.Domains_and_Fields.
Require Import UniMath.Algebra.RigsAndRings.
(** Results of this file are required for the [Elimination] subpackage but aren’t specifically part of the topic; probably could/should be upstreamed within [UniMath] *)
(** * Logic *)
Section Logic.
(* not obvious how to deduce this from existing [isapropisdecprop] *)
Lemma isaprop_dec_with_negProp {P : hProp} (Q : negProp P) : isaprop (P ⨿ Q).
Proof.
apply isapropcoprod.
- apply propproperty.
- apply propproperty.
- intros p q; revert p. apply (negProp_to_neg q).
Defined.
End Logic.
(** * Naturals *)
(** Lemmas for standard functions on natural numbers *)
Section Nat.
Lemma natminus1lthn
(n : nat) : n > 0 -> n - 1 < n.
Proof.
intros n_gt_0.
apply natminuslthn.
- assumption.
- reflexivity.
Defined.
(* Next two lemmas are from PAdics.lemmas, restated here for accessibility.
They are only used in this file, in the dualelement section. *)
Lemma minussn1' ( n : nat ) : ( S n ) - 1 = n.
Proof.
destruct n; apply idpath.
Defined.
Local Lemma pathssminus' ( n m : nat ) ( p : natlth m ( S n ) ) :
S ( n - m ) = ( S n ) - m.
Proof.
revert m p; induction n.
intros m p; destruct m. {auto. }
apply fromempty.
apply nopathstruetofalse. apply pathsinv0. assumption.
- intros m p. destruct m.
+ auto.
+ apply IHn. apply p.
Defined.
(* End duplicated proofs. *)
Lemma eq_of_le_le {a b : nat} (le_a_b : a ≤ b) (le_b_a : b ≤ a)
: a = b.
Proof.
destruct (natlehchoice _ _ le_a_b) as [lt_a_b | e_a_b].
2: { assumption. }
apply fromempty. eapply natlthtonegnatgeh; eassumption.
Qed.
Lemma prev_nat
(n : nat) (p : n > 0): ∑ m, S m = n.
Proof.
destruct n as [| n]. { contradiction (negnatlthn0 _ p). }
exists n; reflexivity.
Defined.
Lemma from_natneq_eq
{X : UU} (m n : nat) : (m = n) -> (m ≠ n) -> X.
Proof.
intros m_eq_n m_neq_n.
apply fromempty.
destruct m_eq_n.
eapply isirrefl_natneq.
exact (m_neq_n).
Defined.
Lemma isaprop_nat_eq_or_neq {m n : nat} : isaprop ((m = n) ⨿ (m ≠ n)).
Proof.
refine (@isaprop_dec_with_negProp (_,,_) (natneq _ _)).
apply isasetnat.
Defined.
Lemma nat_eq_or_neq_refl (i : nat)
: nat_eq_or_neq i i = inl (idpath i).
Proof.
apply isaprop_nat_eq_or_neq.
Defined.
Lemma nat_eq_or_neq_left {i j: nat} (p : i = j)
: nat_eq_or_neq i j = inl p.
Proof.
apply isaprop_nat_eq_or_neq.
Defined.
Lemma nat_eq_or_neq_right {i j: nat} (p : i ≠ j)
: nat_eq_or_neq i j = inr p.
Proof.
apply isaprop_nat_eq_or_neq.
Defined.
Lemma min_le_l:
∏ a b : (nat), min a b ≤ a.
Proof.
intros; unfold min; revert a.
induction b as [| b IH]; destruct a ; try reflexivity.
apply IH.
Defined.
Lemma min_le_r:
∏ a b : (nat), min a b ≤ b.
Proof.
intros; unfold min; revert a.
induction b as [| b IH]; destruct a ; try reflexivity.
apply IH.
Defined.
Lemma min_le_iff :
∏ a b c : nat, (a ≤ min b c) <-> (a ≤ b ∧ a ≤ c).
Proof.
intros a b c; split.
- intros le_a_mbc; split; eapply (istransnatleh le_a_mbc).
+ apply min_le_l.
+ apply min_le_r.
- revert a c; induction b as [ | b' IH ]; intros a c [le_a_b le_a_c].
{ intros; exact le_a_b. } (* case b = 0 *)
destruct c as [ | c' ].
{ exact le_a_c. } (* case c = 0 *)
destruct a as [ | a' ].
{ apply natleh0n. } (* case a = 0 *)
(* when all successors, done by the reductions
[ min (S b') (S c') ~~> S (min b' c') ]
[ S x ≤ S y ~~> x ≤ y ] *)
apply IH.
split; assumption.
Qed.
(** All further properties of [min] should be derivable from [min_le_iff]:
the inductive definition of [min] should never need unfolding again
(though of course it can be, if that makes a proof nicer). *)
Lemma min_of_le {a b : nat} (le_a_b : a ≤ b) : min a b = a.
Proof.
apply eq_of_le_le.
- apply min_le_l.
- apply min_le_iff. split; try assumption. apply isreflnatleh.
Qed.
Lemma min_comm (a b : nat) : min a b = min b a.
Proof.
apply eq_of_le_le;
apply min_le_iff; split; auto using min_le_l, min_le_r.
Qed.
Lemma min_eq_a_or_eq_b :
∏ a b : (nat), coprod (min a b = a) (min a b = b).
Proof.
intros a b. destruct (natleorle a b) as [le_a_b | le_b_a].
- apply inl. apply min_of_le; assumption.
- apply inr. rewrite min_comm. apply min_of_le; assumption.
Qed.
End Nat.
(** * Standard finite sets *)
(** lemmas for working with [Stn], the standard finite sets *)
Section Stn.
Lemma minabstn_to_astn
{ a b : nat } : ⟦ min a b ⟧%stn -> ⟦ a ⟧%stn.
Proof.
apply stnmtostnn, min_le_l.
Defined.
Lemma minabstn_to_bstn
{ a b : nat } : ⟦ min a b ⟧%stn -> ⟦ b ⟧%stn.
Proof.
apply stnmtostnn, min_le_r.
Defined.
Lemma stn_inhabited_implies_succ
{n:nat} (i : ⟦ n ⟧%stn)
: ∑ m, n = S m.
Proof.
destruct n as [| m].
- destruct i as [i le_i_0].
destruct (negnatlthn0 _ le_i_0).
- exists m. apply idpath.
Defined.
Lemma isaprop_stn_eq_or_neq {n} (i j : ⟦n⟧%stn)
: isaprop ((i = j) ⨿ (i ≠ j)).
Proof.
refine (@isaprop_dec_with_negProp (_,,_) (stnneq _ _)).
apply isasetstn.
Defined.
Lemma stn_eq_or_neq_refl {n} {i : ⟦ n ⟧%stn}
: stn_eq_or_neq i i = inl (idpath i).
Proof.
apply isaprop_stn_eq_or_neq.
Defined.
Lemma stn_eq_or_neq_left {n} {i j: (⟦ n ⟧)%stn}
: forall p : i = j, stn_eq_or_neq i j = inl p.
Proof.
intros; apply isaprop_stn_eq_or_neq.
Defined.
Lemma stn_eq_or_neq_right {n} {i j : (⟦ n ⟧)%stn}
: forall (p : i ≠ j), stn_eq_or_neq i j = inr p.
Proof.
intros; apply isaprop_stn_eq_or_neq.
Defined.
Lemma stn_implies_ngt0
{ n : nat} (i : ⟦ n ⟧%stn) : n > 0.
Proof.
eapply natgthgehtrans. { exact (stnlt i). }
apply natgehn0.
Defined.
Lemma stn_implies_nneq0
{ n : nat } (i : ⟦ n ⟧%stn) : n ≠ 0.
Proof.
apply natgthtoneq, stn_implies_ngt0, i.
Defined.
Lemma snlehm_to_nltm
(m n : nat) : (S n ≤ m) -> n < m.
Proof.
intros le_sn_m; exact le_sn_m.
Defined.
Lemma stn_eq {k : nat} (i j : stn k) (eq : pr1 i = pr1 j)
: i = j.
Proof.
now apply subtypePath_prop.
Defined.
Lemma stn_eq_2 {k : nat} (i: stn k) (j : nat) (eq : pr1 i = j) (P : j < k)
: i = (j,, P).
Proof.
intros; apply stn_eq, eq.
Defined.
(* perhaps generalise to a version for any [isincl], and use [isinclstntonat]? *)
Lemma stn_eq_nat_eq
{ n : nat } (i j : ⟦ n ⟧%stn) : i = j <-> (pr1 i = pr1 j).
Proof.
split.
- apply maponpaths.
- apply subtypePath_prop.
Defined.
Lemma stn_neq_nat_neq
{ n : nat } (i j : ⟦ n ⟧%stn) : i ≠ j <-> (pr1 i ≠ pr1 j).
Proof.
split; apply idfun.
Defined.
Lemma issymm_stnneq {n : nat} {i j : stn n} (neq : i ≠ j)
: (j ≠ i).
Proof.
apply issymm_natneq; assumption.
Defined.
Lemma prev_stn
{n : nat} (i : ⟦ n ⟧%stn) (p : i > 0) : ∑ j : ⟦ n ⟧%stn, S j = i.
Proof.
destruct (prev_nat i p) as [j Sj_i].
use tpair.
- exists j.
refine (istransnatlth _ _ _ (natgthsnn j) _ ).
rewrite Sj_i.
apply (pr2 i).
- exact Sj_i.
Defined.
(** General symmetry for decidable equality is tricky to state+prove (requires Hedberg’s theorem); but for non-dependent case-splits, it’s cleaner. *)
(** Should also be generalisable using [negProp], ideally *)
Lemma stn_eq_or_neq_symm_nondep {n} {x y : ⟦n⟧%stn}
(de_xy : (x = y) ⨿ (x ≠ y)%stn) (de_yx : (y = x) ⨿ (y ≠ x)%stn)
{Z} (z1 z2 : Z)
: coprod_rect (fun _ => Z) (fun _ => z1) (fun _ => z2) de_xy
= coprod_rect (fun _ => Z) (fun _ => z1) (fun _ => z2) de_yx.
Proof.
destruct de_xy as [e_xy | ne_xy];
destruct de_yx as [e_yx | ne_yx];
simpl;
(** consistent cases: *)
try reflexivity;
(** inconsistent cases: *)
eapply fromempty, nat_neq_to_nopath; try eassumption;
apply pathsinv0, maponpaths; assumption.
Defined.
End Stn.
(** Lemmas on the “dual” function on the standard finite sets, reversing the order *)
(** Note: the definition of [dualelement] upstream has an unnecessary case split.
We provide an alternative to simplify proofs in this section, that could potentially be upstreamed. *)
Section Dual.
Definition dualelement' {n : nat} (i : ⟦ n ⟧%stn) : ⟦ n ⟧%stn.
Proof.
refine (make_stn n (n - 1 - i) _).
apply StandardFiniteSets.dualelement_lt. (* Make non-local upstream? *)
now apply stn_implies_ngt0.
Defined.
Definition dualelement_defs_eq {n : nat} (i : ⟦ n ⟧%stn)
: dualelement i = dualelement' i.
Proof.
unfold dualelement', dualelement.
apply subtypePath_prop; simpl.
destruct (natchoice0 _) as [eq0 | gt]; reflexivity.
Defined.
Lemma dualelement_2x
{n : nat} (i : ⟦ n ⟧%stn) : dualelement (dualelement i) = i.
Proof.
do 2 rewrite dualelement_defs_eq; unfold dualelement'.
unfold make_stn.
apply subtypePath_prop; simpl.
rewrite minusminusmmn; try reflexivity.
apply natgthtogehm1, (pr2 i).
Defined.
Lemma dualelement_eq
{n : nat} (i j : ⟦ n ⟧%stn)
: dualelement i = j
-> i = dualelement j.
Proof.
do 2 rewrite dualelement_defs_eq; unfold dualelement'.
intros H; apply subtypePath_prop; revert H; simpl.
intros eq; rewrite <- eq; simpl.
rewrite minusminusmmn; try reflexivity.
apply natlthsntoleh.
apply natgthtogehm1, (pr2 i).
Defined.
Lemma dualelement_lt_comp
{n : nat} (i j : ⟦ n ⟧%stn)
: i < j -> (dualelement i) > (dualelement j).
Proof.
intros lt.
do 2 rewrite dualelement_defs_eq; unfold dualelement'.
apply minusgth0inv; simpl.
rewrite natminusminusassoc, natpluscomm,
<- natminusminusassoc, minusminusmmn.
2: {apply (natgthtogehm1 _ _ (pr2 j)). }
apply (minusgth0 _ _ lt).
Defined.
Lemma dualelement_lt_comp'
{n : nat} (i j : ⟦ n ⟧%stn)
: (dualelement i) < (dualelement j)
-> j < i.
Proof.
intros lt.
pose (H := @dualelement_lt_comp _ (dualelement i) (dualelement j) lt).
now do 2 rewrite dualelement_2x in H.
Defined.
Lemma dualelement_le_comp
{n : nat} (i j : ⟦ n ⟧%stn)
: i ≤ j -> (dualelement j) ≤ (dualelement i).
Proof.
intros le.
destruct (natlehchoice i j) as [lt | eq]; try assumption.
{ apply natlthtoleh. apply (dualelement_lt_comp _ _ lt). }
rewrite (stn_eq _ _ eq).
apply isreflnatgeh.
Defined.
Lemma dualelement_le_comp'
{n : nat} (i j : ⟦ n ⟧%stn)
: (dualelement i) ≤ (dualelement j)
-> j ≤ i.
Proof.
intros le.
pose (H := @dualelement_le_comp _ (dualelement i) (dualelement j) le).
now do 2 rewrite dualelement_2x in H.
Defined.
Lemma dualelement_lt_trans_2
{m n k q: nat} (p1 : n < k ) (p2 : n < q) (p3 : k < q)
(lt_dual : m < dualelement (n,, p1))
: (m < (dualelement (n,, p2))).
Proof.
rewrite dualelement_defs_eq; unfold dualelement'.
refine (istransnatlth _ _ _ _ _). {exact lt_dual. }
rewrite dualelement_defs_eq.
simpl; do 2 rewrite natminusminus.
apply natlthandminusl; try assumption.
refine (natlehlthtrans _ _ _ _ _); try assumption.
2: { exact p3. }
rewrite natpluscomm.
apply natlthtolehp1.
exact p1; assumption.
Defined.
Lemma dualelement_sn_eq
{m n k q: nat} (lt : S n < S k)
: pr1 (dualelement (n,, lt)) = (pr1 (dualelement (S n,, lt))).
Proof.
do 2 rewrite dualelement_defs_eq; unfold dualelement'; simpl.
now rewrite natminuseqn, natminusminus.
Defined.
Lemma dualelement_sn_le
{m n k q: nat} (lt : S n < S k)
: pr1 (dualelement (n,, lt)) <= (pr1 (dualelement (S n,, lt))).
Proof.
rewrite (@dualelement_sn_eq n n k k lt).
apply isreflnatleh.
Defined.
Lemma dualelement_sn_le_2
{m n k q: nat} (lt : S n < S k)
: pr1 (dualelement (n,, lt)) >= (pr1 (dualelement (S n,, lt))).
Proof.
rewrite (@dualelement_sn_eq n n k k lt).
apply isreflnatleh.
Defined.
Lemma dualelement_sn_stn_nge_0
{n : nat} (i : stn n)
: forall lt : (0 < S n), i >= (dualelement (0,, lt)) -> empty.
Proof.
intros lt gt.
rewrite dualelement_defs_eq in gt; unfold dualelement' in gt.
simpl in gt.
do 2 rewrite natminuseqn in gt.
contradiction (natgthtonegnatleh _ _ (pr2 i)).
Defined.
Lemma dualelement_sn_stn_ge_n
{n : nat} (i : stn n) : i >= (dualelement (n,, natgthsnn n)).
Proof.
rewrite dualelement_defs_eq.
simpl.
rewrite (@natminuseqn _), minuseq0'.
apply idpath.
Defined.
Lemma dualelement_lt_to_le_s
{n k : nat}
(i : stn n)
(p : k < n)
(leh: dualelement (k,, p) < i)
: dualelement (k,, istransnatlth _ _ (S n) (natgthsnn k) p) <= i.
Proof.
rewrite dualelement_defs_eq; rewrite dualelement_defs_eq in leh;
unfold dualelement' in leh |- *; simpl in leh |- *.
rewrite natminuseqn.
apply natgthtogehsn in leh.
rewrite pathssminus' in leh.
2: { rewrite pathssminus'.
- now rewrite minussn1'.
- now apply (stn_implies_ngt0 i). }
assert (e : n = S (n - 1)).
{ change (S (n - 1)) with (1 + (n - 1)). rewrite natpluscomm.
apply pathsinv0, minusplusnmm, (natlthtolehp1 _ _ (stn_implies_ngt0 i)). }
now destruct (!e).
Defined.
Lemma dualvalue_eq
{X : UU} {n : nat}
(v : ⟦ n ⟧%stn -> X) (i : ⟦ n ⟧%stn)
: (v i) = (λ i' : ⟦ n ⟧%stn, v (dualelement i')) (dualelement i).
Proof.
simpl; now rewrite dualelement_2x.
Defined.
End Dual.
(** * Rings, fields *)
(** Lemmas on general rings and fields, and in particular their decidable equality *)
Section Rings_and_Fields.
#[reversible] Coercion multlinvpair_of_multinvpair {R : rig} (x : R)
: @multinvpair R x -> @multlinvpair R x.
Proof.
intros [y [xy yx]]. esplit; eauto.
Defined.
#[reversible] Coercion multrinvpair_of_multinvpair {R : rig} (x : R)
: @multinvpair R x -> @multrinvpair R x.
Proof.
intros [y [xy yx]]. esplit; eauto.
Defined.
Lemma ringplusminus
{R: ring} (a b : R) : (a + b - b)%ring = a.
Proof.
rewrite ringassoc1.
rewrite ringrinvax1.
apply (rigrunax1 R).
Defined.
Lemma ringminusdistr' { X : commring } ( a b c : X ) :
(a * (b - c))%ring = (a * b - a * c)%ring.
Proof.
intros. rewrite ringldistr. rewrite ringrmultminus. apply idpath.
Defined.
Lemma fldchoice0 {X : fld} (e : X) : coprod (e = 0%ring) (e != 0%ring).
Proof.
destruct (fldchoice e) as [ x_inv | x_0 ].
- right.
apply isnonzerofromrinvel. { apply nonzeroax. }
exact x_inv.
- left; assumption.
Defined.
Lemma fldchoice0_left {X : fld} (e : X) (eq : (e = 0)%ring):
(fldchoice0 e) = inl eq.
Proof.
apply isapropdec, setproperty.
Defined.
Lemma fldchoice0_right {X : fld} (e : X) (neq : (e != 0)%ring):
(fldchoice0 e) = inr neq.
Proof.
apply isapropdec, setproperty.
Defined.
Lemma fldmultinvlax {X: fld} (e : X) (ne : e != 0%ring) :
(fldmultinv e ne * e)%ring = 1%ring.
Proof.
exact (pr1 (pr2 (fldmultinvpair _ e ne))).
Defined.
Lemma fldmultinvrax {X: fld} (e : X) (ne : e != 0%ring) :
(e * fldmultinv e ne)%ring = 1%ring.
Proof.
exact (pr2 (pr2 (fldmultinvpair _ e ne))).
Defined.
Definition fldmultinv' {X : fld} (e : X) : X.
Proof.
destruct (fldchoice0 e) as [eq0 | neq].
- exact 0%ring.
- exact (fldmultinv e neq).
Defined.
Lemma fldmultinvlax' {X: fld} (e : X) (ne : e != 0%ring) :
(fldmultinv' e * e)%ring = 1%ring.
Proof.
unfold fldmultinv'.
destruct (fldchoice0 _).
- contradiction.
- apply fldmultinvlax.
Defined.
Lemma fldmultinvrax' {X: fld} (e : X) (ne : e != 0%ring) :
(e * fldmultinv' e)%ring = 1%ring.
Proof.
unfold fldmultinv'.
destruct (fldchoice0 _).
- contradiction.
- apply fldmultinvrax.
Defined.
End Rings_and_Fields.
(** * Rationals. Commented out to respect import dependency ordering. Could be downstreamed or removed. *)
(* Section Rationals.
Lemma hqone_neq_hqzero : 1%hq != 0%hq.
Proof.
intro contr.
assert (contr_hz : intpart 1%hq != intpart 0%hq).
{ unfold intpart. apply hzone_neg_hzzero. }
apply contr_hz.
apply maponpaths, contr.
Defined.
(* A more obvious approach might be to use the injectivity of the map from the integers:
[apply hzone_neg_hzzero; refine (invmaponpathsincl _ isinclhztohq 1%hz 0%hz contr).]
However, this turns out very slow, apparently because recognising [hztohq 1%hz = 1%hq] is slow (and similarly for 0). Seems surprising that this is slower than computing [intpart 1%hq = 1%hz]!
*)
Lemma hqplusminus
(a b : hq) : (a + b - b)%hq = a.
Proof.
apply (@ringplusminus hq).
Defined.
End Rationals. *)
(** * Maybe *)
(** Lemmas on the general “maybe” construction *)
Section Maybe.
Lemma isdeceqmaybe
{X : UU} (dec : isdeceq X) : isdeceq (maybe X).
Proof.
apply isdeceqcoprod.
- exact dec.
- exact isdecequnit.
Defined.
Definition maybe_choice
{X : UU} (e : maybe X)
: coprod (e != nothing) (e = nothing).
Proof.
destruct e as [? | u].
- apply ii1. apply negpathsii1ii2.
- apply ii2. now induction u.
Defined.
Definition maybe_choice'
{X : UU} (e : maybe X)
: coprod (∑ x:X, e = just x) (e = nothing).
Proof.
destruct e as [x | u].
- apply ii1. exists x; reflexivity.
- apply ii2. now induction u.
Defined.
Definition from_maybe
{X : UU} (m : maybe X) (p : m != nothing) : X.
Proof.
unfold nothing in p.
destruct m as [x | u].
- exact x.
- contradiction p.
now induction u.
Defined.
End Maybe.