summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorSon HO2023-12-05 17:46:17 +0100
committerGitHub2023-12-05 17:46:17 +0100
commit9eb117dc9e94d1b04d24c87d278d014f456b2d89 (patch)
tree2663915767c3558203990ed14f8d5604b7fd21d1 /backends
parent4795e5f823bc89504855d8eb946b111d9314f4d5 (diff)
parent726db4911add81a853aafcec3936b457aaeff5b4 (diff)
Merge pull request #38 from AeneasVerif/son_fixes2
Simplify and add some lemmas
Diffstat (limited to 'backends')
-rw-r--r--backends/lean/Base/IList/IList.lean16
-rw-r--r--backends/lean/Base/Primitives/Scalar.lean3
-rw-r--r--backends/lean/Base/Primitives/Vec.lean4
3 files changed, 14 insertions, 9 deletions
diff --git a/backends/lean/Base/IList/IList.lean b/backends/lean/Base/IList/IList.lean
index f71f2de2..e90d1e0d 100644
--- a/backends/lean/Base/IList/IList.lean
+++ b/backends/lean/Base/IList/IList.lean
@@ -412,12 +412,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
@@ -428,12 +427,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
@@ -448,7 +446,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 cdd6d6f9..f74fecd4 100644
--- a/backends/lean/Base/Primitives/Scalar.lean
+++ b/backends/lean/Base/Primitives/Scalar.lean
@@ -427,6 +427,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: reducible?
@[reducible] def core_isize_min : Isize := Scalar.ofInt Isize.min (by simp [Scalar.min, Scalar.max]; apply (Scalar.min_le_max .Isize))
@[reducible] def core_isize_max : Isize := Scalar.ofInt Isize.max (by simp [Scalar.min, Scalar.max]; apply (Scalar.min_le_max .Isize))
diff --git a/backends/lean/Base/Primitives/Vec.lean b/backends/lean/Base/Primitives/Vec.lean
index e600a151..2c3fce91 100644
--- a/backends/lean/Base/Primitives/Vec.lean
+++ b/backends/lean/Base/Primitives/Vec.lean
@@ -37,6 +37,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)