-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMod2.v
152 lines (132 loc) · 2.87 KB
/
Mod2.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
Require Export HoTT.
Require Import HitTactics.
Module Export modulo.
Private Inductive Mod2 : Type0 :=
| Z : Mod2
| succ : Mod2 -> Mod2.
Axiom mod : Z = succ(succ Z).
Fixpoint Mod2_ind
(P : Mod2 -> Type)
(a : P Z)
(s : forall (n : Mod2), P n -> P (succ n))
(mod' : mod # a = s (succ Z) (s Z a))
(x : Mod2)
{struct x}
: P x
:=
(match x return _ -> P x with
| Z => fun _ => a
| succ n => fun _ => s n ((Mod2_ind P a s mod') n)
end) mod'.
Axiom Mod2_ind_beta_mod : forall
(P : Mod2 -> Type)
(a : P Z)
(s : forall (n : Mod2), P n -> P (succ n))
(mod' : mod # a = s (succ Z) (s Z a))
, apD (Mod2_ind P a s mod') mod = mod'.
Fixpoint Mod2_rec
(P : Type)
(a : P)
(s : P -> P)
(mod' : a = s (s a))
(x : Mod2)
{struct x}
: P
:=
(match x return _ -> P with
| Z => fun _ => a
| succ n => fun _ => s ((Mod2_rec P a s mod') n)
end) mod'.
Axiom Mod2_rec_beta_mod : forall
(P : Type)
(a : P)
(s : P -> P)
(mod' : a = s (s a))
, ap (Mod2_rec P a s mod') mod = mod'.
Instance: HitRecursion Mod2 := {
indTy := _; recTy := _;
H_inductor := Mod2_ind;
H_recursor := Mod2_rec }.
End modulo.
Theorem modulo2 : forall n : Mod2, n = succ(succ n).
Proof.
intro n.
hinduction n.
- apply mod.
- intros n p.
apply (ap succ p).
- simpl.
etransitivity.
eapply (@transport_paths_FlFr _ _ idmap (fun n => succ (succ n))).
hott_simpl.
apply ap_compose.
Defined.
Definition negate : Mod2 -> Mod2.
Proof.
hrecursion.
- apply Z.
- intros. apply (succ H).
- simpl. apply mod.
Defined.
Definition plus : Mod2 -> Mod2 -> Mod2.
Proof.
intros n m.
hrecursion m.
- exact n.
- apply succ.
- apply modulo2.
Defined.
Definition Bool_to_Mod2 : Bool -> Mod2.
Proof.
intro b.
destruct b.
+ apply (succ Z).
+ apply Z.
Defined.
Definition Mod2_to_Bool : Mod2 -> Bool.
Proof.
intro x.
hrecursion x.
- exact false.
- exact negb.
- simpl. reflexivity.
Defined.
Theorem eq1 : forall n : Bool, Mod2_to_Bool (Bool_to_Mod2 n) = n.
Proof.
intro b.
destruct b; compute; reflexivity.
Qed.
Theorem Bool_to_Mod2_negb : forall x : Bool,
succ (Bool_to_Mod2 x) = Bool_to_Mod2 (negb x).
Proof.
intros.
destruct x; compute.
+ apply mod^.
+ apply reflexivity.
Defined.
Theorem eq2 : forall n : Mod2, Bool_to_Mod2 (Mod2_to_Bool n) = n.
Proof.
intro n.
hinduction n.
- reflexivity.
- intros n IHn.
symmetry. etransitivity. apply (ap succ IHn^).
etransitivity. apply Bool_to_Mod2_negb.
hott_simpl.
- rewrite @HoTT.Types.Paths.transport_paths_FlFr.
hott_simpl.
rewrite ap_compose.
enough (ap Mod2_to_Bool mod = idpath).
+ rewrite X. hott_simpl.
+ apply (Mod2_rec_beta_mod Bool false negb 1).
Defined.
Theorem adj :
forall x : Mod2, eq1 (Mod2_to_Bool x) = ap Mod2_to_Bool (eq2 x).
Proof.
intro x.
apply hset_bool.
Defined.
Definition isomorphism : IsEquiv Mod2_to_Bool.
Proof.
apply (BuildIsEquiv Mod2 Bool Mod2_to_Bool Bool_to_Mod2 eq1 eq2 adj).
Qed.