diff options
author | Ryan Lahfa | 2024-04-30 14:36:40 +0200 |
---|---|---|
committer | Ryan Lahfa | 2024-04-30 14:36:40 +0200 |
commit | b6a820cc3ed1d5d4d875cddf7982aaa84ff01d44 (patch) | |
tree | 9abbd4494d5d3da04b68c033568cd8bd80dc6cf4 /backends | |
parent | fead40d1fb6e9f7bed705e8d3048133cf59c3bb8 (diff) |
feat(backend/lean): Raw Lean literals can be parsed into scalars automatically
We can use coercion to go to integers, build a scalar out of an int via
unification and let the user clear up bounds or let Lean decide them.
Signed-off-by: Ryan Lahfa <ryan.lahfa@inria.fr>
Diffstat (limited to 'backends')
-rw-r--r-- | backends/lean/Base/Primitives/Scalar.lean | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/backends/lean/Base/Primitives/Scalar.lean b/backends/lean/Base/Primitives/Scalar.lean index 2bee8a2f..dccbcdf2 100644 --- a/backends/lean/Base/Primitives/Scalar.lean +++ b/backends/lean/Base/Primitives/Scalar.lean @@ -332,6 +332,11 @@ instance [Decide (Scalar.cMin ty ≤ v ∧ v ≤ Scalar.cMax ty)] : InBounds ty @[simp] abbrev Scalar.check_bounds (ty : ScalarTy) (x : Int) : Bool := (Scalar.cMin ty ≤ x || Scalar.min ty ≤ x) ∧ (x ≤ Scalar.cMax ty || x ≤ Scalar.max ty) +-- TODO(raitobezarius): the inbounds constraint is a bit ugly as we can pretty trivially +-- discharge the lhs on ≥ 0. +instance {ty: ScalarTy} [InBounds ty (Int.ofNat n)]: OfNat (Scalar ty) (n: ℕ) where + ofNat := Scalar.ofInt n + theorem Scalar.check_bounds_imp_in_bounds {ty : ScalarTy} {x : Int} (h: Scalar.check_bounds ty x) : Scalar.in_bounds ty x := by |