From 0eb62047b052cb4fbf842525170dd916679e8b7e Mon Sep 17 00:00:00 2001 From: Son Ho Date: Mon, 18 Sep 2023 19:56:27 +0200 Subject: Simplify some lemmas and prove that the scalars and Vec are inhabited --- backends/lean/Base/IList/IList.lean | 16 +++++++--------- backends/lean/Base/Primitives/Scalar.lean | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'backends/lean') diff --git a/backends/lean/Base/IList/IList.lean b/backends/lean/Base/IList/IList.lean index a940da25..214a6582 100644 --- a/backends/lean/Base/IList/IList.lean +++ b/backends/lean/Base/IList/IList.lean @@ -375,12 +375,11 @@ theorem index_itake_append_end [Inhabited α] (i j : Int) (l0 l1 : List α) simp_all @[simp] -theorem index_ne +theorem index_update_ne {α : Type u} [Inhabited α] (l: List α) (i: ℤ) (j: ℤ) (x: α) : - 0 ≤ i → i < l.len → 0 ≤ j → j < l.len → j ≠ i → - (l.update i x).index j = l.index j + j ≠ i → (l.update i x).index j = l.index j := - λ _ _ _ _ _ => match l with + λ _ => match l with | [] => by simp at * | hd :: tl => if h: i = 0 then @@ -391,12 +390,11 @@ theorem index_ne by simp [*] else by - simp [*] - simp at * - apply index_ne <;> scalar_tac + simp_all + apply index_update_ne; scalar_tac @[simp] -theorem index_eq +theorem index_update_eq {α : Type u} [Inhabited α] (l: List α) (i: ℤ) (x: α) : 0 ≤ i → i < l.len → (l.update i x).index i = x @@ -411,7 +409,7 @@ theorem index_eq by simp [*] simp at * - apply index_eq <;> scalar_tac + apply index_update_eq <;> scalar_tac theorem update_map_eq {α : Type u} {β : Type v} (ls : List α) (i : Int) (x : α) (f : α → β) : (ls.update i x).map f = (ls.map f).update i (f x) := diff --git a/backends/lean/Base/Primitives/Scalar.lean b/backends/lean/Base/Primitives/Scalar.lean index 55227a9f..fecb0d1d 100644 --- a/backends/lean/Base/Primitives/Scalar.lean +++ b/backends/lean/Base/Primitives/Scalar.lean @@ -395,6 +395,9 @@ def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Re @[reducible] def U64 := Scalar .U64 @[reducible] def U128 := Scalar .U128 +instance (ty : ScalarTy) : Inhabited (Scalar ty) := by + constructor; cases ty <;> apply (Scalar.ofInt 0) + -- TODO: below: not sure this is the best way. -- Should we rather overload operations like +, -, etc.? -- Also, it is possible to automate the generation of those definitions -- cgit v1.2.3