-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTypes.v
164 lines (131 loc) · 4.66 KB
/
Types.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
(** Types *)
(* This won't work with equality due to inversion.
Inductive coefficient :=
| Gi
| Gneg.
Inductive GType :=
| I
| X
| Z
| scale : coefficient -> GType -> GType
| mul : GType -> GType -> GType
| tensor : GType -> GType -> GType
| cap : GType -> GType -> GType
| arrow : GType -> GType -> GType.
*)
Parameter GType : Type.
Parameter I : GType.
Parameter X : GType.
Parameter Z : GType.
Parameter i : GType -> GType.
Parameter neg : GType -> GType.
Parameter mul : GType -> GType -> GType.
Parameter tensor : GType -> GType -> GType.
Parameter cap : GType -> GType -> GType.
Parameter arrow : GType -> GType -> GType.
Notation "- T" := (neg T).
Infix "*" := mul (at level 40, left associativity).
Infix "⊗" := tensor (at level 51, right associativity).
Infix "→" := arrow (at level 60, no associativity).
Infix "∩" := cap (at level 60, no associativity).
Notation Y := (i (X * Z)).
(* Singleton Types *)
(* Could probably safely make this inductive. Can't do inversion on GTypes anyhow. *)
Parameter Singleton : GType -> Prop.
Axiom SI: Singleton I.
Axiom SX : Singleton X.
Axiom SZ : Singleton Z.
Axiom S_neg : forall A, Singleton A -> Singleton (neg A).
Axiom S_i : forall A, Singleton A -> Singleton (i A).
Axiom S_mul : forall A B, Singleton A -> Singleton B -> Singleton (A * B).
Hint Resolve SI SX SZ S_neg S_i S_mul : sing_db.
Lemma SY : Singleton Y.
Proof. auto with sing_db. Qed.
(* Multiplication laws *)
Axiom mul_assoc : forall A B C, A * (B * C) = A * B * C.
Axiom mul_I_l : forall A, I * A = A.
Axiom mul_I_r : forall A, A * I = A.
Axiom Xsqr : X * X = I.
Axiom Zsqr : Z * Z = I.
Axiom ZmulX : Z * X = - (X * Z).
Axiom neg_inv : forall A, - - A = A.
Axiom neg_dist_l : forall A B, -A * B = - (A * B).
Axiom neg_dist_r : forall A B, A * -B = - (A * B).
Axiom i_sqr : forall A, i (i A) = -A.
Axiom i_dist_l : forall A B, i A * B = i (A * B).
Axiom i_dist_r : forall A B, A * i B = i (A * B).
Axiom i_neg_comm : forall A, i (-A) = -i A.
Hint Rewrite mul_I_l mul_I_r Xsqr Zsqr ZmulX neg_inv neg_dist_l neg_dist_r i_sqr i_dist_l i_dist_r i_neg_comm : mul_db.
(** ** Tensor Laws *)
Axiom tensor_assoc : forall A B C, A ⊗ (B ⊗ C) = (A ⊗ B) ⊗ C.
Axiom neg_tensor_dist_l : forall A B, -A ⊗ B = - (A ⊗ B).
Axiom neg_tensor_dist_r : forall A B, A ⊗ -B = - (A ⊗ B).
Axiom i_tensor_dist_l : forall A B, i A ⊗ B = i (A ⊗ B).
Axiom i_tensor_dist_r : forall A B, A ⊗ i B = i (A ⊗ B).
(** ** Multiplication & Tensor Laws *)
(* Appropriate restriction is that size A = size C and size B = size D,
but axiomatization doesn't allow for that calculation. *)
(* This should be generalizable to the other, assuming we're multiplying
valid types. *)
Axiom mul_tensor_dist : forall A B C D,
Singleton A ->
Singleton C ->
(A ⊗ B) * (C ⊗ D) = (A * C) ⊗ (B * D).
Lemma decompose_tensor : forall A B,
Singleton A ->
Singleton B ->
A ⊗ B = (A ⊗ I) * (I ⊗ B).
Proof.
intros.
rewrite mul_tensor_dist; auto with sing_db.
rewrite mul_I_l, mul_I_r.
easy.
Qed.
Lemma decompose_tensor_mult_l : forall A B,
Singleton A ->
Singleton B ->
(A * B) ⊗ I = (A ⊗ I) * (B ⊗ I).
Proof.
intros.
rewrite mul_tensor_dist; auto with sing_db.
rewrite mul_I_l.
easy.
Qed.
Lemma decompose_tensor_mult_r : forall A B,
I ⊗ (A * B) = (I ⊗ A) * (I ⊗ B).
Proof.
intros.
rewrite mul_tensor_dist; auto with sing_db.
rewrite mul_I_l.
easy.
Qed.
Hint Rewrite neg_tensor_dist_l neg_tensor_dist_r i_tensor_dist_l i_tensor_dist_r : tensor_db.
(** ** Intersection Laws *)
Axiom cap_idem : forall A, A ∩ A = A.
Axiom cap_comm : forall A B, A ∩ B = B ∩ A.
Axiom cap_assoc : forall A B C, A ∩ (B ∩ C) = (A ∩ B) ∩ C.
Axiom cap_I_l : forall A,
Singleton A ->
I ∩ A = A.
Lemma cap_I_r : forall A,
Singleton A ->
A ∩ I = A.
Proof. intros; rewrite cap_comm, cap_I_l; easy. Qed.
(* Note: I haven't proven that this works or terminates.
An anticommutative monoidal solver would be ideal here. *)
Ltac normalize_mul :=
repeat match goal with
| |- context[(?A ⊗ ?B) ⊗ ?C] => rewrite <- (tensor_assoc A B C)
end;
repeat (rewrite mul_tensor_dist by auto with sing_db);
repeat rewrite mul_assoc;
repeat (
try rewrite <- (mul_assoc X Z _);
autorewrite with mul_db tensor_db;
try rewrite mul_assoc ).
Lemma Ysqr : Y * Y = I. Proof. normalize_mul. reflexivity. Qed.
Lemma XmulZ : X * Z = - Z * X. Proof. normalize_mul. reflexivity. Qed.
Lemma XmulY : X * Y = i Z. Proof. normalize_mul. reflexivity. Qed.
Lemma YmulX : Y * X = -i Z. Proof. normalize_mul. reflexivity. Qed.
Lemma ZmulY : Z * Y = -i X. Proof. normalize_mul. reflexivity. Qed.
Lemma YmulZ : Y * Z = i X. Proof. normalize_mul. reflexivity. Qed.