@@ -11,9 +11,12 @@ inductive HList.{u} : List (Type u) -> Type (u + 1) where
1111 | nil : HList []
1212 | cons {α β}: α -> HList β -> HList (α :: β)
1313
14+ infixr :67 "; " => HList.cons
1415
16+ -- -- I want to try constructing a dependent HList
17+ -- inductive DHList.{u} : List (Type u) -> Type u where
18+ -- | cons {α β}: (x: α) -> HList x
1519
16- infixr :67 "; " => HList.cons
1720
1821universe u
1922variable {A B : Type u} {α α' β β' γ : List (Type u)} {a : HList α} {b : HList β} {g : HList γ}
@@ -42,6 +45,7 @@ def HList.cast (a : HList α) (h : α = β) : HList β := h ▸ a
4245-- This theorem lets me change between eq cast and heq easily
4346theorem HList.eq_cast_iff_heq {h : β = α} : a = b.cast h <-> a ≍ b := by
4447 -- grind only [<- cast_rfl, cases Or]
48+
4549 subst_vars; rw [heq_iff_eq]; rfl
4650
4751-- theorem HList.cast_heq : a.cast rfl ≍ a := by
@@ -125,9 +129,7 @@ theorem HList.sigma_ext {a b : Sigma HList}
125129 rw [<- eq_cast_iff_heq, h']
126130
127131@[simp]
128- theorem HList.nil_inst (a : HList []) : a = nil := by
129- -- grind only [cases HList]
130- cases a with | nil => rfl
132+ theorem HList.nil_inst (a : HList []) : a = nil := by cases a with | nil => rfl
131133
132134@[grind →]
133135theorem HList.append_right_cancel {a b : HList α} {c : HList β}
@@ -147,84 +149,72 @@ section Algebra
147149
148150instance HList.Sigma.instZero : Zero (Sigma HList) where zero := ⟨[], HList.nil⟩
149151
152+ def HList.Sigma.append (a b : Sigma HList) : Sigma HList :=
153+ ⟨a.fst ++ b.fst, a.snd ++ b.snd⟩
154+
155+ instance HList.Sigma.instAdd : Add (Sigma HList) where add := HList.Sigma.append
156+
150157@[simp, grind =]
151158theorem HList.Sigma.zero_fst : (0 : Sigma HList).fst = [] := rfl
152159
153160@[simp, grind =]
154161theorem HList.Sigma.zero_snd : (0 : Sigma HList).snd = HList.nil := rfl
155162
156- def HList.Sigma.append (a b : Sigma HList) : Sigma HList :=
157- ⟨a.fst ++ b.fst, a.snd ++ b.snd⟩
158-
159- instance HList.Sigma.instAdd : Add (Sigma HList) where add := HList.Sigma.append
160-
161163@[simp, grind =]
162164theorem HList.Sigma.add_fst (a b : Sigma HList) : (a + b).fst = a.fst ++ b.fst := rfl
163165
164166@[simp, grind =]
165167theorem HList.Sigma.add_snd (a b : Sigma HList) : (a + b).snd = a.snd ++ b.snd := rfl
166168
167- instance HList.Sigma.instAddZeroClass : AddZeroClass (Sigma HList) where
169+ instance HList.Sigma.instAddMonoid : AddMonoid (Sigma HList) where
168170 zero_add := by rintro a; rfl
169171 add_zero a := by ext1 <;> simp!
170172 -- ext1
171173 -- · rw [add_fst, zero_fst, List.append_nil]
172174 -- · rw [add_snd, zero_snd, append_nil]
173-
174- instance HList.Sigma.instAddSemigroup : AddSemigroup (Sigma HList) where
175- add_assoc a b c := by ext1 <;> simp!
175+ add_assoc a b c := by ext1 <;> simp! only [add_fst, add_snd, List.append_assoc, append_assoc]
176176 -- grind only [sigma_ext, = add_fst, = add_snd, = append_assoc, =_ List.append_assoc]
177177 -- ext1
178178 -- · simp! only [add_fst, List.append_assoc]
179179 -- · simp! only [add_fst, add_snd, append_assoc]
180-
181- instance HList.Sigma.instAddMonoid : AddMonoid (Sigma HList) where
182180 nsmul := nsmulRec
183181 nsmul_zero _ := rfl
184182 nsmul_succ _ _ := rfl
185183
186- @[simp, grind =]
187- theorem HList.Sigma.nsmul_fst {n} (a : Sigma HList) :
188- (n • a).fst = (List.replicate n a.fst).flatten := by
189- induction n with
190- | zero => rw [zero_nsmul, zero_fst, List.replicate_zero, List.flatten_nil]
191- | succ n hn =>
192- rw [succ_nsmul', add_fst, List.replicate_succ, List.flatten_cons, <- hn]
193-
194- -- -- TODO: Implement a `HList.repeat (n : Nat) (a : HList α) : HList (List.replicate n α).flatten`
195- -- @[ simp ]
196- -- theorem HList.Sigma.nsmul_snd {n} (a : Sigma HList) : (n • a).snd = a.snd
197-
198- instance HList.Sigma.instAddLeftCancelMonoid : AddLeftCancelMonoid (Sigma HList) where
184+ instance HList.Sigma.instAddCancelMonoid : AddCancelMonoid (Sigma HList) where
199185 add_left_cancel := by
200- -- intro a; rw [IsAddLeftRegular, Function.Injective]
201186 intro a b c h
202187 injection h with fst_eq snd_eq
203188 ext1
204189 · rw [List.append_cancel_left fst_eq]
205190 · apply append_left_cancel (a := a.snd)
206- rw [<- cast, append_cast, cast_cast, eq_cast_iff_heq]
207- exact snd_eq
208-
209- instance HList.Sigma.instAddRightCancelMonoid : AddRightCancelMonoid (Sigma HList) where
191+ rwa [← cast, append_cast, cast_cast, eq_cast_iff_heq]
210192 add_right_cancel := by
211- -- intro a; rw [IsAddRightRegular, Function.Injective]
212193 intro a b c h
213194 injection h with fst_eq snd_eq
214195 ext1
215196 · rw [List.append_cancel_right fst_eq]
216197 · apply append_right_cancel (c := a.snd)
217- rw [<- cast, cast_append, cast_cast, eq_cast_iff_heq]
218- exact snd_eq
198+ rwa [← cast, cast_append, cast_cast, eq_cast_iff_heq]
219199 -- grind? only [= IsAddRightRegular, = Function.Injective, -> sigma_ext,
220200 -- -> List.append_cancel_right, -> append_right_cancel, = cast_rfl, = add_fst, = add_snd]
221201
222- instance HList.Sigma.instAddCancelMonoid : AddCancelMonoid (Sigma HList) where
223-
224202instance HList.Sigma.instMulAction : MulAction Nat (Sigma HList) where
225203 one_smul b := by rw [one_nsmul]
226204 mul_smul x y b := by rw [mul_comm, mul_nsmul]
227205
206+ @[simp, grind =]
207+ theorem HList.Sigma.nsmul_fst {n} (a : Sigma HList) :
208+ (n • a).fst = (List.replicate n a.fst).flatten := by
209+ induction n with
210+ | zero => rw [zero_nsmul, zero_fst, List.replicate_zero, List.flatten_nil]
211+ | succ n hn =>
212+ rw [succ_nsmul', add_fst, List.replicate_succ, List.flatten_cons, <- hn]
213+
214+ -- -- TODO: Implement a `HList.repeat (n : Nat) (a : HList α) : HList (List.replicate n α).flatten`
215+ -- @[ simp ]
216+ -- theorem HList.Sigma.nsmul_snd {n} (a : Sigma HList) : (n • a).snd = a.snd
217+
228218-- -- I dont think i actually need this instance. It should be possible, but probably not useful.
229219-- instance HList.Sigma.instIsAddTorsionFree : IsAddTorsionFree (Sigma HList) where
230220-- nsmul_right_injective := by
0 commit comments