2017-01-02 13:08:36 +01:00
|
|
|
Require Export HoTT.
|
2017-05-18 17:43:19 +02:00
|
|
|
Require Import HitTactics.
|
2017-05-22 21:06:13 +02:00
|
|
|
|
2017-01-02 13:08:36 +01:00
|
|
|
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'.
|
|
|
|
|
2017-05-22 21:06:13 +02:00
|
|
|
Instance: HitRecursion Mod2 := {
|
|
|
|
indTy := _; recTy := _;
|
|
|
|
H_inductor := Mod2_ind;
|
|
|
|
H_recursor := Mod2_rec }.
|
2017-01-02 13:08:36 +01:00
|
|
|
|
2017-05-18 17:43:19 +02:00
|
|
|
End modulo.
|
2017-01-02 13:08:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
Theorem modulo2 : forall n : Mod2, n = succ(succ n).
|
|
|
|
Proof.
|
2017-05-18 17:43:19 +02:00
|
|
|
intro n.
|
2017-05-22 21:06:13 +02:00
|
|
|
hinduction n.
|
2017-05-18 17:43:19 +02:00
|
|
|
- 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.
|
2017-01-02 13:08:36 +01:00
|
|
|
|
2017-05-18 17:43:19 +02:00
|
|
|
Definition negate : Mod2 -> Mod2.
|
|
|
|
Proof.
|
2017-05-22 21:06:13 +02:00
|
|
|
hrecursion.
|
2017-05-18 17:43:19 +02:00
|
|
|
- apply Z.
|
|
|
|
- intros. apply (succ H).
|
2017-05-20 14:05:46 +02:00
|
|
|
- simpl. apply mod.
|
2017-01-02 13:08:36 +01:00
|
|
|
Defined.
|
|
|
|
|
|
|
|
Definition plus : Mod2 -> Mod2 -> Mod2.
|
|
|
|
Proof.
|
2017-05-20 14:05:46 +02:00
|
|
|
intros n m.
|
|
|
|
hrecursion m.
|
|
|
|
- exact n.
|
|
|
|
- apply succ.
|
|
|
|
- apply modulo2.
|
2017-01-02 13:08:36 +01:00
|
|
|
Defined.
|
|
|
|
|
|
|
|
Definition Bool_to_Mod2 : Bool -> Mod2.
|
|
|
|
Proof.
|
|
|
|
intro b.
|
|
|
|
destruct b.
|
2017-05-20 14:05:46 +02:00
|
|
|
+ apply (succ Z).
|
|
|
|
+ apply Z.
|
2017-01-02 13:08:36 +01:00
|
|
|
Defined.
|
|
|
|
|
|
|
|
Definition Mod2_to_Bool : Mod2 -> Bool.
|
|
|
|
Proof.
|
2017-05-20 14:05:46 +02:00
|
|
|
intro x.
|
|
|
|
hrecursion x.
|
|
|
|
- exact false.
|
|
|
|
- exact negb.
|
|
|
|
- simpl. reflexivity.
|
2017-01-02 13:08:36 +01:00
|
|
|
Defined.
|
|
|
|
|
|
|
|
Theorem eq1 : forall n : Bool, Mod2_to_Bool (Bool_to_Mod2 n) = n.
|
|
|
|
Proof.
|
|
|
|
intro b.
|
2017-05-20 14:05:46 +02:00
|
|
|
destruct b; compute; reflexivity.
|
2017-01-02 13:08:36 +01:00
|
|
|
Qed.
|
|
|
|
|
|
|
|
Theorem Bool_to_Mod2_negb : forall x : Bool,
|
|
|
|
succ (Bool_to_Mod2 x) = Bool_to_Mod2 (negb x).
|
|
|
|
Proof.
|
|
|
|
intros.
|
2017-05-20 14:05:46 +02:00
|
|
|
destruct x; compute.
|
|
|
|
+ apply mod^.
|
|
|
|
+ apply reflexivity.
|
2017-01-02 13:08:36 +01:00
|
|
|
Defined.
|
|
|
|
|
|
|
|
Theorem eq2 : forall n : Mod2, Bool_to_Mod2 (Mod2_to_Bool n) = n.
|
|
|
|
Proof.
|
2017-05-20 14:05:46 +02:00
|
|
|
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.
|
2017-05-22 21:06:13 +02:00
|
|
|
+ apply (Mod2_rec_beta_mod Bool false negb 1).
|
2017-01-02 13:08:36 +01:00
|
|
|
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).
|
2017-01-02 13:15:17 +01:00
|
|
|
Qed.
|