-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathlogic.lean
1097 lines (803 loc) · 38 KB
/
logic.lean
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn
-/
prelude
import init.core
universes u v w
@[simp] lemma opt_param_eq (α : Sort u) (default : α) : opt_param α default = α :=
rfl
@[inline] def id {α : Sort u} (a : α) : α := a
def flip {α : Sort u} {β : Sort v} {φ : Sort w} (f : α → β → φ) : β → α → φ :=
λ b a, f a b
/- implication -/
def implies (a b : Prop) := a → b
/-- Implication `→` is transitive. If `P → Q` and `Q → R` then `P → R`. -/
@[trans] lemma implies.trans {p q r : Prop} (h₁ : implies p q) (h₂ : implies q r) : implies p r :=
assume hp, h₂ (h₁ hp)
lemma trivial : true := ⟨⟩
/-- We can't have `a` and `¬a`, that would be absurd!-/
@[inline] def absurd {a : Prop} {b : Sort v} (h₁ : a) (h₂ : ¬a) : b :=
false.rec b (h₂ h₁)
lemma not.intro {a : Prop} (h : a → false) : ¬ a :=
h
/-- Modus tollens. If an implication is true, then so is its contrapositive. -/
lemma mt {a b : Prop} (h₁ : a → b) (h₂ : ¬b) : ¬a := assume ha : a, h₂ (h₁ ha)
/- not -/
lemma not_false : ¬false := id
def non_contradictory (a : Prop) : Prop := ¬¬a
lemma non_contradictory_intro {a : Prop} (ha : a) : ¬¬a :=
assume hna : ¬a, absurd ha hna
/- false -/
@[inline] def false.elim {C : Sort u} (h : false) : C :=
false.rec C h
/- eq -/
-- proof irrelevance is built in
lemma proof_irrel {a : Prop} (h₁ h₂ : a) : h₁ = h₂ := rfl
@[simp] lemma id.def {α : Sort u} (a : α) : id a = a := rfl
@[inline] def eq.mp {α β : Sort u} : (α = β) → α → β :=
eq.rec_on
@[inline] def eq.mpr {α β : Sort u} : (α = β) → β → α :=
λ h₁ h₂, eq.rec_on (eq.symm h₁) h₂
@[elab_as_eliminator]
lemma eq.substr {α : Sort u} {p : α → Prop} {a b : α} (h₁ : b = a) : p a → p b :=
eq.subst (eq.symm h₁)
lemma congr {α : Sort u} {β : Sort v} {f₁ f₂ : α → β} {a₁ a₂ : α} (h₁ : f₁ = f₂) (h₂ : a₁ = a₂) : f₁ a₁ = f₂ a₂ :=
eq.subst h₁ (eq.subst h₂ rfl)
lemma congr_fun {α : Sort u} {β : α → Sort v} {f g : Π x, β x} (h : f = g) (a : α) : f a = g a :=
eq.subst h (eq.refl (f a))
lemma congr_arg {α : Sort u} {β : Sort v} {a₁ a₂ : α} (f : α → β) : a₁ = a₂ → f a₁ = f a₂ :=
congr rfl
lemma trans_rel_left {α : Sort u} {a b c : α} (r : α → α → Prop) (h₁ : r a b) (h₂ : b = c) : r a c :=
h₂ ▸ h₁
lemma trans_rel_right {α : Sort u} {a b c : α} (r : α → α → Prop) (h₁ : a = b) (h₂ : r b c) : r a c :=
h₁.symm ▸ h₂
lemma of_eq_true {p : Prop} (h : p = true) : p :=
h.symm ▸ trivial
lemma not_of_eq_false {p : Prop} (h : p = false) : ¬p :=
assume hp, h ▸ hp
@[inline] def cast {α β : Sort u} (h : α = β) (a : α) : β :=
eq.rec a h
lemma cast_proof_irrel {α β : Sort u} (h₁ h₂ : α = β) (a : α) : cast h₁ a = cast h₂ a := rfl
lemma cast_eq {α : Sort u} (h : α = α) (a : α) : cast h a = a := rfl
/- ne -/
@[reducible] def ne {α : Sort u} (a b : α) := ¬(a = b)
infix ` ≠ `:50 := ne
@[simp] lemma ne.def {α : Sort u} (a b : α) : a ≠ b = ¬ (a = b) := rfl
namespace ne
variable {α : Sort u}
variables {a b : α}
lemma intro (h : a = b → false) : a ≠ b := h
lemma elim (h : a ≠ b) : a = b → false := h
lemma irrefl (h : a ≠ a) : false := h rfl
lemma symm (h : a ≠ b) : b ≠ a :=
assume (h₁ : b = a), h (h₁.symm)
end ne
lemma false_of_ne {α : Sort u} {a : α} : a ≠ a → false := ne.irrefl
section
variables {p : Prop}
lemma ne_false_of_self : p → p ≠ false :=
assume (hp : p) (heq : p = false), heq ▸ hp
lemma ne_true_of_not : ¬p → p ≠ true :=
assume (hnp : ¬p) (heq : p = true), (heq ▸ hnp) trivial
lemma true_ne_false : ¬true = false :=
ne_false_of_self trivial
end
attribute [refl] heq.refl
section
variables {α β φ : Sort u} {a a' : α} {b b' : β} {c : φ}
def heq.elim {α : Sort u} {a : α} {p : α → Sort v} {b : α} (h₁ : a == b) : p a → p b :=
eq.rec_on (eq_of_heq h₁)
lemma heq.subst {p : ∀ T : Sort u, T → Prop} : a == b → p α a → p β b :=
heq.rec_on
@[symm] lemma heq.symm (h : a == b) : b == a :=
heq.rec_on h (heq.refl a)
lemma heq_of_eq (h : a = a') : a == a' :=
eq.subst h (heq.refl a)
@[trans] lemma heq.trans (h₁ : a == b) (h₂ : b == c) : a == c :=
heq.subst h₂ h₁
@[trans] lemma heq_of_heq_of_eq (h₁ : a == b) (h₂ : b = b') : a == b' :=
heq.trans h₁ (heq_of_eq h₂)
@[trans] lemma heq_of_eq_of_heq (h₁ : a = a') (h₂ : a' == b) : a == b :=
heq.trans (heq_of_eq h₁) h₂
lemma type_eq_of_heq (h : a == b) : α = β :=
heq.rec_on h (eq.refl α)
end
lemma eq_rec_heq {α : Sort u} {φ : α → Sort v} : ∀ {a a' : α} (h : a = a') (p : φ a), (eq.rec_on h p : φ a') == p
| a _ rfl p := heq.refl p
lemma heq_of_eq_rec_left {α : Sort u} {φ : α → Sort v} : ∀ {a a' : α} {p₁ : φ a} {p₂ : φ a'} (e : a = a') (h₂ : (eq.rec_on e p₁ : φ a') = p₂), p₁ == p₂
| a _ p₁ p₂ rfl h := eq.rec_on h (heq.refl p₁)
lemma heq_of_eq_rec_right {α : Sort u} {φ : α → Sort v} : ∀ {a a' : α} {p₁ : φ a} {p₂ : φ a'} (e : a' = a) (h₂ : p₁ = eq.rec_on e p₂), p₁ == p₂
| a _ p₁ p₂ rfl h :=
have p₁ = p₂, from h,
this ▸ heq.refl p₁
lemma of_heq_true {a : Prop} (h : a == true) : a :=
of_eq_true (eq_of_heq h)
lemma eq_rec_compose : ∀ {α β φ : Sort u} (p₁ : β = φ) (p₂ : α = β) (a : α), (eq.rec_on p₁ (eq.rec_on p₂ a : β) : φ) = eq.rec_on (eq.trans p₂ p₁) a
| α _ _ rfl rfl a := rfl
lemma cast_heq : ∀ {α β : Sort u} (h : α = β) (a : α), cast h a == a
| α _ rfl a := heq.refl a
/- and -/
infixr ` /\ `:35 := and
infixr ` ∧ `:35 := and
variables {a b c d : Prop}
lemma and.elim (h₁ : a ∧ b) (h₂ : a → b → c) : c :=
and.rec h₂ h₁
lemma and.swap : a ∧ b → b ∧ a :=
assume ⟨ha, hb⟩, ⟨hb, ha⟩
lemma and.symm : a ∧ b → b ∧ a := and.swap
/- or -/
infixr ` \/ `:30 := or
infixr ` ∨ `:30 := or
namespace or
lemma elim (h₁ : a ∨ b) (h₂ : a → c) (h₃ : b → c) : c :=
or.rec h₂ h₃ h₁
end or
lemma non_contradictory_em (a : Prop) : ¬¬(a ∨ ¬a) :=
assume not_em : ¬(a ∨ ¬a),
have neg_a : ¬a, from
assume pos_a : a, absurd (or.inl pos_a) not_em,
absurd (or.inr neg_a) not_em
lemma or.swap : a ∨ b → b ∨ a := or.rec or.inr or.inl
lemma or.symm : a ∨ b → b ∨ a := or.swap
/- xor -/
def xor (a b : Prop) := (a ∧ ¬ b) ∨ (b ∧ ¬ a)
/- iff -/
/-- `iff P Q`, with notation `P ↔ Q`, is the proposition asserting that `P` and `Q` are equivalent,
that is, have the same truth value. -/
structure iff (a b : Prop) : Prop :=
intro :: (mp : a → b) (mpr : b → a)
infix ` <-> `:20 := iff
infix ` ↔ `:20 := iff
lemma iff.elim : ((a → b) → (b → a) → c) → (a ↔ b) → c := iff.rec
attribute [recursor 5] iff.elim
lemma iff.elim_left : (a ↔ b) → a → b := iff.mp
lemma iff.elim_right : (a ↔ b) → b → a := iff.mpr
lemma iff_iff_implies_and_implies (a b : Prop) : (a ↔ b) ↔ (a → b) ∧ (b → a) :=
iff.intro (λ h, and.intro h.mp h.mpr) (λ h, iff.intro h.left h.right)
@[refl]
lemma iff.refl (a : Prop) : a ↔ a :=
iff.intro (assume h, h) (assume h, h)
lemma iff.rfl {a : Prop} : a ↔ a :=
iff.refl a
@[trans]
lemma iff.trans (h₁ : a ↔ b) (h₂ : b ↔ c) : a ↔ c :=
iff.intro
(assume ha, iff.mp h₂ (iff.mp h₁ ha))
(assume hc, iff.mpr h₁ (iff.mpr h₂ hc))
@[symm]
lemma iff.symm (h : a ↔ b) : b ↔ a :=
iff.intro (iff.elim_right h) (iff.elim_left h)
lemma iff.comm : (a ↔ b) ↔ (b ↔ a) :=
iff.intro iff.symm iff.symm
lemma eq.to_iff {a b : Prop} (h : a = b) : a ↔ b :=
eq.rec_on h iff.rfl
lemma neq_of_not_iff {a b : Prop} : ¬(a ↔ b) → a ≠ b :=
λ h₁ h₂,
have a ↔ b, from eq.subst h₂ (iff.refl a),
absurd this h₁
lemma not_iff_not_of_iff (h₁ : a ↔ b) : ¬a ↔ ¬b :=
iff.intro
(assume (hna : ¬ a) (hb : b), hna (iff.elim_right h₁ hb))
(assume (hnb : ¬ b) (ha : a), hnb (iff.elim_left h₁ ha))
lemma of_iff_true (h : a ↔ true) : a :=
iff.mp (iff.symm h) trivial
lemma not_of_iff_false : (a ↔ false) → ¬a := iff.mp
lemma iff_true_intro (h : a) : a ↔ true :=
iff.intro
(λ hl, trivial)
(λ hr, h)
lemma iff_false_intro (h : ¬a) : a ↔ false :=
iff.intro h (false.rec a)
lemma not_non_contradictory_iff_absurd (a : Prop) : ¬¬¬a ↔ ¬a :=
iff.intro
(λ (hl : ¬¬¬a) (ha : a), hl (non_contradictory_intro ha))
absurd
lemma imp_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a → b) ↔ (c → d) :=
iff.intro
(λ hab hc, iff.mp h₂ (hab (iff.mpr h₁ hc)))
(λ hcd ha, iff.mpr h₂ (hcd (iff.mp h₁ ha)))
lemma imp_congr_ctx (h₁ : a ↔ c) (h₂ : c → (b ↔ d)) : (a → b) ↔ (c → d) :=
iff.intro
(λ hab hc, have ha : a, from iff.mpr h₁ hc,
have hb : b, from hab ha,
iff.mp (h₂ hc) hb)
(λ hcd ha, have hc : c, from iff.mp h₁ ha,
have hd : d, from hcd hc,
iff.mpr (h₂ hc) hd)
lemma imp_congr_right (h : a → (b ↔ c)) : (a → b) ↔ (a → c) :=
iff.intro
(assume hab ha, iff.elim_left (h ha) (hab ha))
(assume hab ha, iff.elim_right (h ha) (hab ha))
lemma not_not_intro (ha : a) : ¬¬a :=
assume hna : ¬a, hna ha
lemma not_of_not_not_not (h : ¬¬¬a) : ¬a :=
λ ha, absurd (not_not_intro ha) h
@[simp] lemma not_true : (¬ true) ↔ false :=
iff_false_intro (not_not_intro trivial)
@[simp] lemma not_false_iff : (¬ false) ↔ true :=
iff_true_intro not_false
@[congr] lemma not_congr (h : a ↔ b) : ¬a ↔ ¬b :=
iff.intro (λ h₁ h₂, h₁ (iff.mpr h h₂)) (λ h₁ h₂, h₁ (iff.mp h h₂))
lemma ne_self_iff_false {α : Sort u} (a : α) : (not (a = a)) ↔ false :=
iff.intro false_of_ne false.elim
@[simp] lemma eq_self_iff_true {α : Sort u} (a : α) : (a = a) ↔ true :=
iff_true_intro rfl
lemma heq_self_iff_true {α : Sort u} (a : α) : (a == a) ↔ true :=
iff_true_intro (heq.refl a)
@[simp] lemma iff_not_self (a : Prop) : (a ↔ ¬a) ↔ false :=
iff_false_intro (λ h,
have h' : ¬a, from (λ ha, (iff.mp h ha) ha),
h' (iff.mpr h h'))
@[simp] lemma not_iff_self (a : Prop) : (¬a ↔ a) ↔ false :=
iff_false_intro (λ h,
have h' : ¬a, from (λ ha, (iff.mpr h ha) ha),
h' (iff.mp h h'))
lemma true_iff_false : (true ↔ false) ↔ false :=
iff_false_intro (λ h, iff.mp h trivial)
lemma false_iff_true : (false ↔ true) ↔ false :=
iff_false_intro (λ h, iff.mpr h trivial)
lemma false_of_true_iff_false : (true ↔ false) → false :=
assume h, iff.mp h trivial
lemma false_of_true_eq_false : (true = false) → false :=
assume h, h ▸ trivial
lemma true_eq_false_of_false : false → (true = false) :=
false.elim
lemma eq_comm {α : Sort u} {a b : α} : a = b ↔ b = a :=
⟨eq.symm, eq.symm⟩
/- and simp rules -/
lemma and.imp (hac : a → c) (hbd : b → d) : a ∧ b → c ∧ d :=
assume ⟨ha, hb⟩, ⟨hac ha, hbd hb⟩
lemma and_implies (hac : a → c) (hbd : b → d) : a ∧ b → c ∧ d := and.imp hac hbd
@[congr] lemma and_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a ∧ b) ↔ (c ∧ d) :=
iff.intro (and.imp (iff.mp h₁) (iff.mp h₂)) (and.imp (iff.mpr h₁) (iff.mpr h₂))
lemma and_congr_right (h : a → (b ↔ c)) : (a ∧ b) ↔ (a ∧ c) :=
iff.intro
(assume ⟨ha, hb⟩, ⟨ha, iff.elim_left (h ha) hb⟩)
(assume ⟨ha, hc⟩, ⟨ha, iff.elim_right (h ha) hc⟩)
lemma and.comm : a ∧ b ↔ b ∧ a :=
iff.intro and.swap and.swap
lemma and_comm (a b : Prop) : a ∧ b ↔ b ∧ a := and.comm
lemma and.assoc : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) :=
iff.intro
(assume ⟨⟨ha, hb⟩, hc⟩, ⟨ha, ⟨hb, hc⟩⟩)
(assume ⟨ha, ⟨hb, hc⟩⟩, ⟨⟨ha, hb⟩, hc⟩)
lemma and_assoc (a b : Prop) : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) := and.assoc
lemma and.left_comm : a ∧ (b ∧ c) ↔ b ∧ (a ∧ c) :=
iff.trans (iff.symm and.assoc) (iff.trans (and_congr and.comm (iff.refl c)) and.assoc)
lemma and_iff_left {a b : Prop} (hb : b) : (a ∧ b) ↔ a :=
iff.intro and.left (λ ha, ⟨ha, hb⟩)
lemma and_iff_right {a b : Prop} (ha : a) : (a ∧ b) ↔ b :=
iff.intro and.right (and.intro ha)
@[simp] lemma and_true (a : Prop) : a ∧ true ↔ a :=
and_iff_left trivial
@[simp] lemma true_and (a : Prop) : true ∧ a ↔ a :=
and_iff_right trivial
@[simp] lemma and_false (a : Prop) : a ∧ false ↔ false :=
iff_false_intro and.right
@[simp] lemma false_and (a : Prop) : false ∧ a ↔ false :=
iff_false_intro and.left
@[simp] lemma not_and_self (a : Prop) : (¬a ∧ a) ↔ false :=
iff_false_intro (λ h, and.elim h (λ h₁ h₂, absurd h₂ h₁))
@[simp] lemma and_not_self (a : Prop) : (a ∧ ¬a) ↔ false :=
iff_false_intro (assume ⟨h₁, h₂⟩, absurd h₁ h₂)
@[simp] lemma and_self (a : Prop) : a ∧ a ↔ a :=
iff.intro and.left (assume h, ⟨h, h⟩)
/- or simp rules -/
lemma or.imp (h₂ : a → c) (h₃ : b → d) : a ∨ b → c ∨ d :=
or.rec (λ h, or.inl (h₂ h)) (λ h, or.inr (h₃ h))
lemma or.imp_left (h : a → b) : a ∨ c → b ∨ c :=
or.imp h id
lemma or.imp_right (h : a → b) : c ∨ a → c ∨ b :=
or.imp id h
@[congr] lemma or_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a ∨ b) ↔ (c ∨ d) :=
iff.intro (or.imp (iff.mp h₁) (iff.mp h₂)) (or.imp (iff.mpr h₁) (iff.mpr h₂))
lemma or.comm : a ∨ b ↔ b ∨ a := iff.intro or.swap or.swap
lemma or_comm (a b : Prop) : a ∨ b ↔ b ∨ a := or.comm
lemma or.assoc : (a ∨ b) ∨ c ↔ a ∨ (b ∨ c) :=
iff.intro
(or.rec (or.imp_right or.inl) (λ h, or.inr (or.inr h)))
(or.rec (λ h, or.inl (or.inl h)) (or.imp_left or.inr))
lemma or_assoc (a b : Prop) : (a ∨ b) ∨ c ↔ a ∨ (b ∨ c) :=
or.assoc
lemma or.left_comm : a ∨ (b ∨ c) ↔ b ∨ (a ∨ c) :=
iff.trans (iff.symm or.assoc) (iff.trans (or_congr or.comm (iff.refl c)) or.assoc)
theorem or_iff_right_of_imp (ha : a → b) : (a ∨ b) ↔ b :=
iff.intro (or.rec ha id) or.inr
theorem or_iff_left_of_imp (hb : b → a) : (a ∨ b) ↔ a :=
iff.intro (or.rec id hb) or.inl
@[simp] lemma or_true (a : Prop) : a ∨ true ↔ true :=
iff_true_intro (or.inr trivial)
@[simp] lemma true_or (a : Prop) : true ∨ a ↔ true :=
iff_true_intro (or.inl trivial)
@[simp] lemma or_false (a : Prop) : a ∨ false ↔ a :=
iff.intro (or.rec id false.elim) or.inl
@[simp] lemma false_or (a : Prop) : false ∨ a ↔ a :=
iff.trans or.comm (or_false a)
@[simp] lemma or_self (a : Prop) : a ∨ a ↔ a :=
iff.intro (or.rec id id) or.inl
lemma not_or {a b : Prop} : ¬ a → ¬ b → ¬ (a ∨ b)
| hna hnb (or.inl ha) := absurd ha hna
| hna hnb (or.inr hb) := absurd hb hnb
/- or resolution rulse -/
lemma or.resolve_left {a b : Prop} (h : a ∨ b) (na : ¬ a) : b :=
or.elim h (λ ha, absurd ha na) id
lemma or.neg_resolve_left {a b : Prop} (h : ¬ a ∨ b) (ha : a) : b :=
or.elim h (λ na, absurd ha na) id
lemma or.resolve_right {a b : Prop} (h : a ∨ b) (nb : ¬ b) : a :=
or.elim h id (λ hb, absurd hb nb)
lemma or.neg_resolve_right {a b : Prop} (h : a ∨ ¬ b) (hb : b) : a :=
or.elim h id (λ nb, absurd hb nb)
/- iff simp rules -/
@[simp] lemma iff_true (a : Prop) : (a ↔ true) ↔ a :=
iff.intro (assume h, iff.mpr h trivial) iff_true_intro
@[simp] lemma true_iff (a : Prop) : (true ↔ a) ↔ a :=
iff.trans iff.comm (iff_true a)
@[simp] lemma iff_false (a : Prop) : (a ↔ false) ↔ ¬ a :=
iff.intro iff.mp iff_false_intro
@[simp] lemma false_iff (a : Prop) : (false ↔ a) ↔ ¬ a :=
iff.trans iff.comm (iff_false a)
@[simp] lemma iff_self (a : Prop) : (a ↔ a) ↔ true :=
iff_true_intro iff.rfl
@[congr] lemma iff_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a ↔ b) ↔ (c ↔ d) :=
(iff_iff_implies_and_implies a b).trans
((and_congr (imp_congr h₁ h₂) (imp_congr h₂ h₁)).trans
(iff_iff_implies_and_implies c d).symm)
/- implies simp rule -/
@[simp] lemma implies_true_iff (α : Sort u) : (α → true) ↔ true :=
iff.intro (λ h, trivial) (λ ha h, trivial)
lemma false_implies_iff (a : Prop) : (false → a) ↔ true :=
iff.intro (λ h, trivial) (λ ha h, false.elim h)
theorem true_implies_iff (α : Prop) : (true → α) ↔ α :=
iff.intro (λ h, h trivial) (λ h h', h)
/--
The existential quantifier.
To prove a goal of the form `⊢ ∃ x, p x`, you can provide a witness `y` with the tactic `existsi y`.
If you are working in a project that depends on mathlib, then we recommend the `use` tactic
instead.
You'll then be left with the goal `⊢ p y`.
To extract a witness `x` and proof `hx : p x` from a hypothesis `h : ∃ x, p x`,
use the tactic `cases h with x hx`. See also the mathlib tactics `obtain` and `rcases`.
-/
inductive Exists {α : Sort u} (p : α → Prop) : Prop
| intro (w : α) (h : p w) : Exists
attribute [intro] Exists.intro
notation `exists` binders `, ` r:(scoped P, Exists P) := r
notation `∃` binders `, ` r:(scoped P, Exists P) := r
/- This is a `def`, so that it can be used as pattern in the equation compiler. -/
@[pattern] def exists.intro {α : Sort u} {p : α → Prop} (w : α) (h : p w) : ∃ x, p x := ⟨w, h⟩
lemma exists.elim {α : Sort u} {p : α → Prop} {b : Prop}
(h₁ : ∃ x, p x) (h₂ : ∀ (a : α), p a → b) : b :=
Exists.rec h₂ h₁
/- exists unique -/
def exists_unique {α : Sort u} (p : α → Prop) :=
∃ x, p x ∧ ∀ y, p y → y = x
notation `∃!` binders `, ` r:(scoped P, exists_unique P) := r
@[intro]
lemma exists_unique.intro {α : Sort u} {p : α → Prop} (w : α) (h₁ : p w) (h₂ : ∀ y, p y → y = w) :
∃! x, p x :=
exists.intro w ⟨h₁, h₂⟩
attribute [recursor 4]
lemma exists_unique.elim {α : Sort u} {p : α → Prop} {b : Prop}
(h₂ : ∃! x, p x) (h₁ : ∀ x, p x → (∀ y, p y → y = x) → b) : b :=
exists.elim h₂ (λ w hw, h₁ w (and.left hw) (and.right hw))
lemma exists_unique_of_exists_of_unique {α : Sort u} {p : α → Prop}
(hex : ∃ x, p x) (hunique : ∀ y₁ y₂, p y₁ → p y₂ → y₁ = y₂) : ∃! x, p x :=
exists.elim hex (λ x px, exists_unique.intro x px (assume y, assume : p y, hunique y x this px))
lemma exists_of_exists_unique {α : Sort u} {p : α → Prop} (h : ∃! x, p x) : ∃ x, p x :=
exists.elim h (λ x hx, ⟨x, and.left hx⟩)
lemma unique_of_exists_unique {α : Sort u} {p : α → Prop}
(h : ∃! x, p x) {y₁ y₂ : α} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ :=
exists_unique.elim h
(assume x, assume : p x,
assume unique : ∀ y, p y → y = x,
show y₁ = y₂, from eq.trans (unique _ py₁) (eq.symm (unique _ py₂)))
/- exists, forall, exists unique congruences -/
@[congr] lemma forall_congr {α : Sort u} {p q : α → Prop} (h : ∀ a, (p a ↔ q a)) : (∀ a, p a) ↔ ∀ a, q a :=
iff.intro (λ p a, iff.mp (h a) (p a)) (λ q a, iff.mpr (h a) (q a))
lemma exists_imp_exists {α : Sort u} {p q : α → Prop} (h : ∀ a, (p a → q a)) (p : ∃ a, p a) : ∃ a, q a :=
exists.elim p (λ a hp, ⟨a, h a hp⟩)
@[congr] lemma exists_congr {α : Sort u} {p q : α → Prop} (h : ∀ a, (p a ↔ q a)) : (Exists p) ↔ ∃ a, q a :=
iff.intro
(exists_imp_exists (λ a, iff.mp (h a)))
(exists_imp_exists (λ a, iff.mpr (h a)))
@[congr] lemma exists_unique_congr {α : Sort u} {p₁ p₂ : α → Prop} (h : ∀ x, p₁ x ↔ p₂ x) : (exists_unique p₁) ↔ (∃! x, p₂ x) := --
exists_congr (λ x, and_congr (h x) (forall_congr (λ y, imp_congr (h y) iff.rfl)))
lemma forall_not_of_not_exists {α : Sort u} {p : α → Prop} : ¬(∃ x, p x) → (∀ x, ¬p x) :=
λ hne x hp, hne ⟨x, hp⟩
/- decidable -/
def decidable.to_bool (p : Prop) [h : decidable p] : bool :=
decidable.cases_on h (λ h₁, bool.ff) (λ h₂, bool.tt)
export decidable (is_true is_false to_bool)
@[simp] lemma to_bool_true_eq_tt (h : decidable true) : @to_bool true h = tt :=
decidable.cases_on h (λ h, false.elim (iff.mp not_true h)) (λ _, rfl)
@[simp] lemma to_bool_false_eq_ff (h : decidable false) : @to_bool false h = ff :=
decidable.cases_on h (λ h, rfl) (λ h, false.elim h)
instance decidable.true : decidable true :=
is_true trivial
instance decidable.false : decidable false :=
is_false not_false
-- We use "dependent" if-then-else to be able to communicate the if-then-else condition
-- to the branches
@[inline] def dite {α : Sort u} (c : Prop) [h : decidable c] : (c → α) → (¬ c → α) → α :=
λ t e, decidable.rec_on h e t
/- if-then-else -/
@[inline] def ite {α : Sort u} (c : Prop) [h : decidable c] (t e : α) : α :=
decidable.rec_on h (λ hnc, e) (λ hc, t)
namespace decidable
variables {p q : Prop}
def rec_on_true [h : decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : p) (h₄ : h₁ h₃)
: decidable.rec_on h h₂ h₁ :=
decidable.rec_on h (λ h, false.rec _ (h h₃)) (λ h, h₄)
def rec_on_false [h : decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : ¬p) (h₄ : h₂ h₃)
: decidable.rec_on h h₂ h₁ :=
decidable.rec_on h (λ h, h₄) (λ h, false.rec _ (h₃ h))
def by_cases {q : Sort u} [φ : decidable p] : (p → q) → (¬p → q) → q := dite _
/-- Law of Excluded Middle. -/
lemma em (p : Prop) [decidable p] : p ∨ ¬p := by_cases or.inl or.inr
lemma by_contradiction [decidable p] (h : ¬p → false) : p :=
if h₁ : p then h₁ else false.rec _ (h h₁)
lemma of_not_not [decidable p] : ¬ ¬ p → p :=
λ hnn, by_contradiction (λ hn, absurd hn hnn)
lemma not_not_iff (p) [decidable p] : (¬ ¬ p) ↔ p :=
iff.intro of_not_not not_not_intro
lemma not_and_iff_or_not (p q : Prop) [d₁ : decidable p] [d₂ : decidable q] : ¬ (p ∧ q) ↔ ¬ p ∨ ¬ q :=
iff.intro
(λ h, match d₁ with
| is_true h₁ :=
match d₂ with
| is_true h₂ := absurd (and.intro h₁ h₂) h
| is_false h₂ := or.inr h₂
end
| is_false h₁ := or.inl h₁
end)
(λ h ⟨hp, hq⟩, or.elim h (λ h, h hp) (λ h, h hq))
lemma not_or_iff_and_not (p q) [d₁ : decidable p] [d₂ : decidable q] : ¬ (p ∨ q) ↔ ¬ p ∧ ¬ q :=
iff.intro
(λ h, match d₁ with
| is_true h₁ := false.elim $ h (or.inl h₁)
| is_false h₁ :=
match d₂ with
| is_true h₂ := false.elim $ h (or.inr h₂)
| is_false h₂ := ⟨h₁, h₂⟩
end
end)
(λ ⟨np, nq⟩ h, or.elim h np nq)
end decidable
section
variables {p q : Prop}
def decidable_of_decidable_of_iff (hp : decidable p) (h : p ↔ q) : decidable q :=
if hp : p then is_true (iff.mp h hp)
else is_false (iff.mp (not_iff_not_of_iff h) hp)
def decidable_of_decidable_of_eq (hp : decidable p) (h : p = q) : decidable q :=
decidable_of_decidable_of_iff hp h.to_iff
protected def or.by_cases [decidable p] [decidable q] {α : Sort u}
(h : p ∨ q) (h₁ : p → α) (h₂ : q → α) : α :=
if hp : p then h₁ hp else
if hq : q then h₂ hq else
false.rec _ (or.elim h hp hq)
end
section
variables {p q : Prop}
instance [decidable p] [decidable q] : decidable (p ∧ q) :=
if hp : p then
if hq : q then is_true ⟨hp, hq⟩
else is_false (assume h : p ∧ q, hq (and.right h))
else is_false (assume h : p ∧ q, hp (and.left h))
instance [decidable p] [decidable q] : decidable (p ∨ q) :=
if hp : p then is_true (or.inl hp) else
if hq : q then is_true (or.inr hq) else
is_false (or.rec hp hq)
instance [decidable p] : decidable (¬p) :=
if hp : p then is_false (absurd hp) else is_true hp
instance implies.decidable [decidable p] [decidable q] : decidable (p → q) :=
if hp : p then
if hq : q then is_true (assume h, hq)
else is_false (assume h : p → q, absurd (h hp) hq)
else is_true (assume h, absurd h hp)
instance [decidable p] [decidable q] : decidable (p ↔ q) :=
if hp : p then
if hq : q then is_true ⟨λ_, hq, λ_, hp⟩
else is_false $ λh, hq (h.1 hp)
else
if hq : q then is_false $ λh, hp (h.2 hq)
else is_true $ ⟨λh, absurd h hp, λh, absurd h hq⟩
instance [decidable p] [decidable q] : decidable (xor p q) :=
if hp : p then
if hq : q then is_false (or.rec (λ ⟨_, h⟩, h hq : ¬(p ∧ ¬ q)) (λ ⟨_, h⟩, h hp : ¬(q ∧ ¬ p)))
else is_true $ or.inl ⟨hp, hq⟩
else
if hq : q then is_true $ or.inr ⟨hq, hp⟩
else is_false (or.rec (λ ⟨h, _⟩, hp h : ¬(p ∧ ¬ q)) (λ ⟨h, _⟩, hq h : ¬(q ∧ ¬ p)))
instance exists_prop_decidable {p} (P : p → Prop)
[Dp : decidable p] [DP : ∀ h, decidable (P h)] : decidable (∃ h, P h) :=
if h : p then decidable_of_decidable_of_iff (DP h)
⟨λ h2, ⟨h, h2⟩, λ⟨h', h2⟩, h2⟩ else is_false (mt (λ⟨h, _⟩, h) h)
instance forall_prop_decidable {p} (P : p → Prop)
[Dp : decidable p] [DP : ∀ h, decidable (P h)] : decidable (∀ h, P h) :=
if h : p then decidable_of_decidable_of_iff (DP h)
⟨λ h2 _, h2, λal, al h⟩ else is_true (λ h2, absurd h2 h)
end
instance {α : Sort u} [decidable_eq α] (a b : α) : decidable (a ≠ b) :=
implies.decidable
lemma bool.ff_ne_tt : ff = tt → false
.
def is_dec_eq {α : Sort u} (p : α → α → bool) : Prop := ∀ ⦃x y : α⦄, p x y = tt → x = y
def is_dec_refl {α : Sort u} (p : α → α → bool) : Prop := ∀ x, p x x = tt
open decidable
instance : decidable_eq bool
| ff ff := is_true rfl
| ff tt := is_false bool.ff_ne_tt
| tt ff := is_false (ne.symm bool.ff_ne_tt)
| tt tt := is_true rfl
def decidable_eq_of_bool_pred {α : Sort u} {p : α → α → bool} (h₁ : is_dec_eq p) (h₂ : is_dec_refl p) : decidable_eq α :=
assume x y : α,
if hp : p x y = tt then is_true (h₁ hp)
else is_false (assume hxy : x = y, absurd (h₂ y) (@eq.rec_on _ _ (λ z, ¬p z y = tt) _ hxy hp))
lemma decidable_eq_inl_refl {α : Sort u} [h : decidable_eq α] (a : α) : h a a = is_true (eq.refl a) :=
match (h a a) with
| (is_true e) := rfl
| (is_false n) := absurd rfl n
end
lemma decidable_eq_inr_neg {α : Sort u} [h : decidable_eq α] {a b : α} : Π n : a ≠ b, h a b = is_false n :=
assume n,
match (h a b) with
| (is_true e) := absurd e n
| (is_false n₁) := proof_irrel n n₁ ▸ eq.refl (is_false n)
end
/- inhabited -/
class inhabited (α : Sort u) :=
(default : α)
export inhabited (default)
@[inline, irreducible] def arbitrary (α : Sort u) [inhabited α] : α :=
default
instance prop.inhabited : inhabited Prop :=
⟨true⟩
instance pi.inhabited (α : Sort u) {β : α → Sort v} [Π x, inhabited (β x)] : inhabited (Π x, β x) :=
⟨λ a, default⟩
instance : inhabited bool := ⟨ff⟩
instance : inhabited true := ⟨trivial⟩
class inductive nonempty (α : Sort u) : Prop
| intro (val : α) : nonempty
protected lemma nonempty.elim {α : Sort u} {p : Prop} (h₁ : nonempty α) (h₂ : α → p) : p :=
nonempty.rec h₂ h₁
@[priority 100]
instance nonempty_of_inhabited {α : Sort u} [inhabited α] : nonempty α :=
⟨default⟩
lemma nonempty_of_exists {α : Sort u} {p : α → Prop} : (∃ x, p x) → nonempty α
| ⟨w, h⟩ := ⟨w⟩
/- subsingleton -/
class inductive subsingleton (α : Sort u) : Prop
| intro (h : ∀ a b : α, a = b) : subsingleton
protected lemma subsingleton.elim {α : Sort u} [h : subsingleton α] : ∀ (a b : α), a = b :=
subsingleton.rec (λ p, p) h
protected lemma subsingleton.helim {α β : Sort u} [h : subsingleton α] (h : α = β) :
∀ (a : α) (b : β), a == b :=
eq.rec_on h (λ a b : α, heq_of_eq (subsingleton.elim a b))
instance subsingleton_prop (p : Prop) : subsingleton p :=
⟨λ a b, proof_irrel a b⟩
instance (p : Prop) : subsingleton (decidable p) :=
subsingleton.intro (λ d₁,
match d₁ with
| (is_true t₁) := (λ d₂,
match d₂ with
| (is_true t₂) := eq.rec_on (proof_irrel t₁ t₂) rfl
| (is_false f₂) := absurd t₁ f₂
end)
| (is_false f₁) := (λ d₂,
match d₂ with
| (is_true t₂) := absurd t₂ f₁
| (is_false f₂) := eq.rec_on (proof_irrel f₁ f₂) rfl
end)
end)
protected lemma rec_subsingleton {p : Prop} [h : decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u}
[h₃ : Π (h : p), subsingleton (h₁ h)] [h₄ : Π (h : ¬p), subsingleton (h₂ h)]
: subsingleton (decidable.rec_on h h₂ h₁) :=
match h with
| (is_true h) := h₃ h
| (is_false h) := h₄ h
end
lemma if_pos {c : Prop} [h : decidable c] (hc : c) {α : Sort u} {t e : α} : (ite c t e) = t :=
match h with
| (is_true hc) := rfl
| (is_false hnc) := absurd hc hnc
end
lemma if_neg {c : Prop} [h : decidable c] (hnc : ¬c) {α : Sort u} {t e : α} : (ite c t e) = e :=
match h with
| (is_true hc) := absurd hc hnc
| (is_false hnc) := rfl
end
@[simp]
lemma if_t_t (c : Prop) [h : decidable c] {α : Sort u} (t : α) : (ite c t t) = t :=
match h with
| (is_true hc) := rfl
| (is_false hnc) := rfl
end
lemma implies_of_if_pos {c t e : Prop} [decidable c] (h : ite c t e) : c → t :=
assume hc, eq.rec_on (if_pos hc : ite c t e = t) h
lemma implies_of_if_neg {c t e : Prop} [decidable c] (h : ite c t e) : ¬c → e :=
assume hnc, eq.rec_on (if_neg hnc : ite c t e = e) h
lemma if_ctx_congr {α : Sort u} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]
{x y u v : α}
(h_c : b ↔ c) (h_t : c → x = u) (h_e : ¬c → y = v) :
ite b x y = ite c u v :=
match dec_b, dec_c with
| (is_false h₁), (is_false h₂) := h_e h₂
| (is_true h₁), (is_true h₂) := h_t h₂
| (is_false h₁), (is_true h₂) := absurd h₂ (iff.mp (not_iff_not_of_iff h_c) h₁)
| (is_true h₁), (is_false h₂) := absurd h₁ (iff.mpr (not_iff_not_of_iff h_c) h₂)
end
lemma if_congr {α : Sort u} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]
{x y u v : α}
(h_c : b ↔ c) (h_t : x = u) (h_e : y = v) :
ite b x y = ite c u v :=
@if_ctx_congr α b c dec_b dec_c x y u v h_c (λ h, h_t) (λ h, h_e)
@[simp]
lemma if_true {α : Sort u} {h : decidable true} (t e : α) : (@ite α true h t e) = t :=
if_pos trivial
@[simp]
lemma if_false {α : Sort u} {h : decidable false} (t e : α) : (@ite α false h t e) = e :=
if_neg not_false
lemma if_ctx_congr_prop {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c]
(h_c : b ↔ c) (h_t : c → (x ↔ u)) (h_e : ¬c → (y ↔ v)) :
ite b x y ↔ ite c u v :=
match dec_b, dec_c with
| (is_false h₁), (is_false h₂) := h_e h₂
| (is_true h₁), (is_true h₂) := h_t h₂
| (is_false h₁), (is_true h₂) := absurd h₂ (iff.mp (not_iff_not_of_iff h_c) h₁)
| (is_true h₁), (is_false h₂) := absurd h₁ (iff.mpr (not_iff_not_of_iff h_c) h₂)
end
@[congr]
lemma if_congr_prop {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c]
(h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) :
ite b x y ↔ ite c u v :=
if_ctx_congr_prop h_c (λ h, h_t) (λ h, h_e)
lemma if_ctx_simp_congr_prop {b c x y u v : Prop} [dec_b : decidable b]
(h_c : b ↔ c) (h_t : c → (x ↔ u)) (h_e : ¬c → (y ↔ v)) :
ite b x y ↔ (@ite Prop c (decidable_of_decidable_of_iff dec_b h_c) u v) :=
@if_ctx_congr_prop b c x y u v dec_b (decidable_of_decidable_of_iff dec_b h_c) h_c h_t h_e
@[congr]
lemma if_simp_congr_prop {b c x y u v : Prop} [dec_b : decidable b]
(h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) :
ite b x y ↔ (@ite Prop c (decidable_of_decidable_of_iff dec_b h_c) u v) :=
@if_ctx_simp_congr_prop b c x y u v dec_b h_c (λ h, h_t) (λ h, h_e)
@[simp] lemma dif_pos {c : Prop} [h : decidable c] (hc : c) {α : Sort u} {t : c → α} {e : ¬ c → α} : dite c t e = t hc :=
match h with
| (is_true hc) := rfl
| (is_false hnc) := absurd hc hnc
end
@[simp] lemma dif_neg {c : Prop} [h : decidable c] (hnc : ¬c) {α : Sort u} {t : c → α} {e : ¬ c → α} : dite c t e = e hnc :=
match h with
| (is_true hc) := absurd hc hnc
| (is_false hnc) := rfl
end
@[congr]
lemma dif_ctx_congr {α : Sort u} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c]
{x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α}
(h_c : b ↔ c)
(h_t : ∀ (h : c), x (iff.mpr h_c h) = u h)
(h_e : ∀ (h : ¬c), y (iff.mpr (not_iff_not_of_iff h_c) h) = v h) :
(@dite α b dec_b x y) = (@dite α c dec_c u v) :=
match dec_b, dec_c with
| (is_false h₁), (is_false h₂) := h_e h₂
| (is_true h₁), (is_true h₂) := h_t h₂
| (is_false h₁), (is_true h₂) := absurd h₂ (iff.mp (not_iff_not_of_iff h_c) h₁)
| (is_true h₁), (is_false h₂) := absurd h₁ (iff.mpr (not_iff_not_of_iff h_c) h₂)
end
lemma dif_ctx_simp_congr {α : Sort u} {b c : Prop} [dec_b : decidable b]
{x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α}
(h_c : b ↔ c)
(h_t : ∀ (h : c), x (iff.mpr h_c h) = u h)
(h_e : ∀ (h : ¬c), y (iff.mpr (not_iff_not_of_iff h_c) h) = v h) :
(@dite α b dec_b x y) = (@dite α c (decidable_of_decidable_of_iff dec_b h_c) u v) :=
@dif_ctx_congr α b c dec_b (decidable_of_decidable_of_iff dec_b h_c) x u y v h_c h_t h_e
-- Remark: dite and ite are "defally equal" when we ignore the proofs.
lemma dif_eq_if (c : Prop) [h : decidable c] {α : Sort u} (t : α) (e : α) : dite c (λ h, t) (λ h, e) = ite c t e :=
match h with
| (is_true hc) := rfl
| (is_false hnc) := rfl
end
instance {c t e : Prop} [d_c : decidable c] [d_t : decidable t] [d_e : decidable e] : decidable (if c then t else e) :=
match d_c with
| (is_true hc) := d_t
| (is_false hc) := d_e
end
instance {c : Prop} {t : c → Prop} {e : ¬c → Prop} [d_c : decidable c] [d_t : ∀ h, decidable (t h)] [d_e : ∀ h, decidable (e h)] : decidable (if h : c then t h else e h) :=
match d_c with
| (is_true hc) := d_t hc
| (is_false hc) := d_e hc
end
def as_true (c : Prop) [decidable c] : Prop :=
if c then true else false
def as_false (c : Prop) [decidable c] : Prop :=
if c then false else true
lemma of_as_true {c : Prop} [h₁ : decidable c] (h₂ : as_true c) : c :=
match h₁, h₂ with
| (is_true h_c), h₂ := h_c
| (is_false h_c), h₂ := false.elim h₂
end
/-- Universe lifting operation -/
structure {r s} ulift (α : Type s) : Type (max s r) :=
up :: (down : α)
namespace ulift
/- Bijection between α and ulift.{v} α -/
lemma up_down {α : Type u} : ∀ (b : ulift.{v} α), up (down b) = b
| (up a) := rfl
lemma down_up {α : Type u} (a : α) : down (up.{v} a) = a := rfl
end ulift
/-- Universe lifting operation from Sort to Type -/
structure plift (α : Sort u) : Type u :=
up :: (down : α)