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/Primitives/Scalar.lean | 3 +++ 1 file changed, 3 insertions(+) (limited to 'backends/lean/Base/Primitives') 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 From 92887b89e35607e99bae2f19e4c5b2f162683d02 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Mon, 18 Sep 2023 19:59:19 +0200 Subject: Prove that Vec is inhabited --- backends/lean/Base/Primitives/Vec.lean | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'backends/lean/Base/Primitives') diff --git a/backends/lean/Base/Primitives/Vec.lean b/backends/lean/Base/Primitives/Vec.lean index c4c4d9f2..2d48a641 100644 --- a/backends/lean/Base/Primitives/Vec.lean +++ b/backends/lean/Base/Primitives/Vec.lean @@ -35,6 +35,10 @@ example {a: Type u} (v : Vec a) : v.length ≤ Scalar.max ScalarTy.Usize := by def Vec.new (α : Type u): Vec α := ⟨ [], by apply Scalar.cMax_suffices .Usize; simp ⟩ +instance (α : Type u) : Inhabited (Vec α) := by + constructor + apply Vec.new + -- TODO: very annoying that the α is an explicit parameter def Vec.len (α : Type u) (v : Vec α) : Usize := Usize.ofIntCore v.val.len (by scalar_tac) (by scalar_tac) -- cgit v1.2.3