summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorSon Ho2024-04-12 16:47:40 +0200
committerSon Ho2024-04-12 16:47:40 +0200
commit0a258c03bc49b4d3d89b3ce0f73b1c57e38f4eeb (patch)
tree19541337b81ba7d6901949dc6d2e932fe6395d64 /backends
parent03a175b423c9ccff2160300c4d349978f9b1aeb9 (diff)
Start adding integer functions to the Lean library
Diffstat (limited to 'backends')
-rw-r--r--backends/lean/Base/Primitives.lean2
-rw-r--r--backends/lean/Base/Primitives/Core.lean (renamed from backends/lean/Base/Primitives/CoreOps.lean)12
-rw-r--r--backends/lean/Base/Primitives/Scalar.lean255
3 files changed, 266 insertions, 3 deletions
diff --git a/backends/lean/Base/Primitives.lean b/backends/lean/Base/Primitives.lean
index 7196d2ec..ad8f2501 100644
--- a/backends/lean/Base/Primitives.lean
+++ b/backends/lean/Base/Primitives.lean
@@ -4,4 +4,4 @@ import Base.Primitives.Scalar
import Base.Primitives.ArraySlice
import Base.Primitives.Vec
import Base.Primitives.Alloc
-import Base.Primitives.CoreOps
+import Base.Primitives.Core
diff --git a/backends/lean/Base/Primitives/CoreOps.lean b/backends/lean/Base/Primitives/Core.lean
index 1736bfa6..f67da7d7 100644
--- a/backends/lean/Base/Primitives/CoreOps.lean
+++ b/backends/lean/Base/Primitives/Core.lean
@@ -4,7 +4,13 @@ import Base.Primitives.Base
open Primitives
open Result
-namespace core.ops
+namespace core
+
+/- Trait declaration: [core::convert::From] -/
+structure convert.From (Self T : Type) where
+ from_ : T → Result Self
+
+namespace ops -- core.ops
namespace index -- core.ops.index
@@ -32,4 +38,6 @@ structure DerefMut (Self : Type) where
end deref -- core.ops.deref
-end core.ops
+end ops -- core.ops
+
+end core
diff --git a/backends/lean/Base/Primitives/Scalar.lean b/backends/lean/Base/Primitives/Scalar.lean
index 8de2b3f2..0ba538b7 100644
--- a/backends/lean/Base/Primitives/Scalar.lean
+++ b/backends/lean/Base/Primitives/Scalar.lean
@@ -2,6 +2,7 @@ import Lean
import Lean.Meta.Tactic.Simp
import Mathlib.Tactic.Linarith
import Base.Primitives.Base
+import Base.Primitives.Core
import Base.Diverge.Base
import Base.Progress.Base
import Base.Arith.Int
@@ -1393,4 +1394,258 @@ instance (ty : ScalarTy) : DecidableEq (Scalar ty) :=
@[simp] theorem Scalar.neq_to_neq_val {ty} : ∀ {i j : Scalar ty}, (¬ i = j) ↔ ¬ i.val = j.val := by
simp [eq_equiv]
+-- Conversions
+def core.convert.num.FromUsizeBool.from (b : Bool) : Usize :=
+ if b then 1#usize else 0#usize
+
+def core.convert.num.FromU8Bool.from (b : Bool) : U8 :=
+ if b then 1#u8 else 0#u8
+
+def core.convert.num.FromU16Bool.from (b : Bool) : U16 :=
+ if b then 1#u16 else 0#u16
+
+def core.convert.num.FromU32Bool.from (b : Bool) : U32 :=
+ if b then 1#u32 else 0#u32
+
+def core.convert.num.FromU64Bool.from (b : Bool) : U64 :=
+ if b then 1#u64 else 0#u64
+
+def core.convert.num.FromU128Bool.from (b : Bool) : U128 :=
+ if b then 1#u128 else 0#u128
+
+def core.convert.num.FromIsizeBool.from (b : Bool) : Isize :=
+ if b then 1#isize else 0#isize
+
+def core.convert.num.FromI8Bool.from (b : Bool) : I8 :=
+ if b then 1#i8 else 0#i8
+
+def core.convert.num.FromI16Bool.from (b : Bool) : I16 :=
+ if b then 1#i16 else 0#i16
+
+def core.convert.num.FromI32Bool.from (b : Bool) : I32 :=
+ if b then 1#i32 else 0#i32
+
+def core.convert.num.FromI64Bool.from (b : Bool) : I64 :=
+ if b then 1#i64 else 0#i64
+
+def core.convert.num.FromI128Bool.from (b : Bool) : I128 :=
+ if b then 1#i128 else 0#i128
+
+def core.convert.num.FromUsizeU8.from (x : U8) : Usize := sorry
+def core.convert.num.FromUsizeU16.from (x : U16) : Usize := sorry
+def core.convert.num.FromUsizeU32.from (x : U32) : Usize := sorry
+def core.convert.num.FromUsizeUsize.from (x : Usize) : Usize := sorry
+
+def core.convert.num.FromU8U8.from (x : U8) : U8 := sorry
+
+def core.convert.num.FromU16U8.from (x : U8) : U16 := sorry
+def core.convert.num.FromU16U16.from (x : U16) : U16 := sorry
+
+def core.convert.num.FromU32U8.from (x : U8) : U32 := sorry
+def core.convert.num.FromU32U16.from (x : U16) : U32 := sorry
+def core.convert.num.FromU32U32.from (x : U32) : U32 := sorry
+
+def core.convert.num.FromU64U8.from (x : U8) : U64 := sorry
+def core.convert.num.FromU64U16.from (x : U16) : U64 := sorry
+def core.convert.num.FromU64U32.from (x : U32) : U64 := sorry
+def core.convert.num.FromU64U64.from (x : U64) : U64 := sorry
+
+def core.convert.num.FromU128U8.from (x : U8) : U128 := sorry
+def core.convert.num.FromU128U16.from (x : U16) : U128 := sorry
+def core.convert.num.FromU128U32.from (x : U32) : U128 := sorry
+def core.convert.num.FromU128U64.from (x : U64) : U128 := sorry
+def core.convert.num.FromU128U128.from (x : U128) : U128 := sorry
+
+def core.convert.num.FromIsizeI8.from (x : I8) : Isize := sorry
+def core.convert.num.FromIsizeI16.from (x : I16) : Isize := sorry
+def core.convert.num.FromIsizeI32.from (x : I32) : Isize := sorry
+def core.convert.num.FromIsizeIsize.from (x : Isize) : Isize := sorry
+
+def core.convert.num.FromI8I8.from (x : I8) : I8 := sorry
+
+def core.convert.num.FromI16I8.from (x : I8) : I16 := sorry
+def core.convert.num.FromI16I16.from (x : I16) : I16 := sorry
+
+def core.convert.num.FromI32I8.from (x : I8) : I32 := sorry
+def core.convert.num.FromI32I16.from (x : I16) : I32 := sorry
+def core.convert.num.FromI32I32.from (x : I32) : I32 := sorry
+
+def core.convert.num.FromI64I8.from (x : I8) : I64 := sorry
+def core.convert.num.FromI64I16.from (x : I16) : I64 := sorry
+def core.convert.num.FromI64I32.from (x : I32) : I64 := sorry
+def core.convert.num.FromI64I64.from (x : I64) : I64 := sorry
+
+def core.convert.num.FromI128I8.from (x : I8) : I128 := sorry
+def core.convert.num.FromI128I16.from (x : I16) : I128 := sorry
+def core.convert.num.FromI128I32.from (x : I32) : I128 := sorry
+def core.convert.num.FromI128I64.from (x : I64) : I128 := sorry
+def core.convert.num.FromI128I128.from (x : I128) : I128 := sorry
+
+def core.convert.FromUsizeU8 : core.convert.From Usize U8 := {
+ from_ := fun x => ok (core.convert.num.FromUsizeU8.from x)
+}
+
+def core.convert.FromUsizeU16 : core.convert.From Usize U16 := {
+ from_ := fun x => ok (core.convert.num.FromUsizeU16.from x)
+}
+
+def core.convert.FromUsizeU32 : core.convert.From Usize U32 := {
+ from_ := fun x => ok (core.convert.num.FromUsizeU32.from x)
+}
+
+def core.convert.FromUsizeUsize : core.convert.From Usize Usize := {
+ from_ := fun x => ok (core.convert.num.FromUsizeUsize.from x)
+}
+
+def core.convert.FromU8U8 : core.convert.From U8 U8 := {
+ from_ := fun x => ok (core.convert.num.FromU8U8.from x)
+}
+
+def core.convert.FromU16U8 : core.convert.From U16 U8 := {
+ from_ := fun x => ok (core.convert.num.FromU16U8.from x)
+}
+
+def core.convert.FromU16U16 : core.convert.From U16 U16 := {
+ from_ := fun x => ok (core.convert.num.FromU16U16.from x)
+}
+
+def core.convert.FromU32U8 : core.convert.From U32 U8 := {
+ from_ := fun x => ok (core.convert.num.FromU32U8.from x)
+}
+
+def core.convert.FromU32U16 : core.convert.From U32 U16 := {
+ from_ := fun x => ok (core.convert.num.FromU32U16.from x)
+}
+
+def core.convert.FromU32U32 : core.convert.From U32 U32 := {
+ from_ := fun x => ok (core.convert.num.FromU32U32.from x)
+}
+
+def core.convert.FromU64U8 : core.convert.From U64 U8 := {
+ from_ := fun x => ok (core.convert.num.FromU64U8.from x)
+}
+
+def core.convert.FromU64U16 : core.convert.From U64 U16 := {
+ from_ := fun x => ok (core.convert.num.FromU64U16.from x)
+}
+
+def core.convert.FromU64U32 : core.convert.From U64 U32 := {
+ from_ := fun x => ok (core.convert.num.FromU64U32.from x)
+}
+
+def core.convert.FromU64U64 : core.convert.From U64 U64 := {
+ from_ := fun x => ok (core.convert.num.FromU64U64.from x)
+}
+
+def core.convert.FromU128U8 : core.convert.From U128 U8 := {
+ from_ := fun x => ok (core.convert.num.FromU128U8.from x)
+}
+
+def core.convert.FromU128U16 : core.convert.From U128 U16 := {
+ from_ := fun x => ok (core.convert.num.FromU128U16.from x)
+}
+
+def core.convert.FromU128U32 : core.convert.From U128 U32 := {
+ from_ := fun x => ok (core.convert.num.FromU128U32.from x)
+}
+
+def core.convert.FromU128U64 : core.convert.From U128 U64 := {
+ from_ := fun x => ok (core.convert.num.FromU128U64.from x)
+}
+
+def core.convert.FromU128U128 : core.convert.From U128 U128 := {
+ from_ := fun x => ok (core.convert.num.FromU128U128.from x)
+}
+
+def core.convert.FromIsizeI8 : core.convert.From Isize I8 := {
+ from_ := fun x => ok (core.convert.num.FromIsizeI8.from x)
+}
+
+def core.convert.FromIsizeI16 : core.convert.From Isize I16 := {
+ from_ := fun x => ok (core.convert.num.FromIsizeI16.from x)
+}
+
+def core.convert.FromIsizeI32 : core.convert.From Isize I32 := {
+ from_ := fun x => ok (core.convert.num.FromIsizeI32.from x)
+}
+
+def core.convert.FromIsizeIsize : core.convert.From Isize Isize := {
+ from_ := fun x => ok (core.convert.num.FromIsizeIsize.from x)
+}
+
+def core.convert.FromI8I8 : core.convert.From I8 I8 := {
+ from_ := fun x => ok (core.convert.num.FromI8I8.from x)
+}
+
+def core.convert.FromI16I8 : core.convert.From I16 I8 := {
+ from_ := fun x => ok (core.convert.num.FromI16I8.from x)
+}
+
+def core.convert.FromI16I16 : core.convert.From I16 I16 := {
+ from_ := fun x => ok (core.convert.num.FromI16I16.from x)
+}
+
+def core.convert.FromI32I8 : core.convert.From I32 I8 := {
+ from_ := fun x => ok (core.convert.num.FromI32I8.from x)
+}
+
+def core.convert.FromI32I16 : core.convert.From I32 I16 := {
+ from_ := fun x => ok (core.convert.num.FromI32I16.from x)
+}
+
+def core.convert.FromI32I32 : core.convert.From I32 I32 := {
+ from_ := fun x => ok (core.convert.num.FromI32I32.from x)
+}
+
+def core.convert.FromI64I8 : core.convert.From I64 I8 := {
+ from_ := fun x => ok (core.convert.num.FromI64I8.from x)
+}
+
+def core.convert.FromI64I16 : core.convert.From I64 I16 := {
+ from_ := fun x => ok (core.convert.num.FromI64I16.from x)
+}
+
+def core.convert.FromI64I32 : core.convert.From I64 I32 := {
+ from_ := fun x => ok (core.convert.num.FromI64I32.from x)
+}
+
+def core.convert.FromI64I64 : core.convert.From I64 I64 := {
+ from_ := fun x => ok (core.convert.num.FromI64I64.from x)
+}
+
+def core.convert.FromI128I8 : core.convert.From I128 I8 := {
+ from_ := fun x => ok (core.convert.num.FromI128I8.from x)
+}
+
+def core.convert.FromI128I16 : core.convert.From I128 I16 := {
+ from_ := fun x => ok (core.convert.num.FromI128I16.from x)
+}
+
+def core.convert.FromI128I32 : core.convert.From I128 I32 := {
+ from_ := fun x => ok (core.convert.num.FromI128I32.from x)
+}
+
+def core.convert.FromI128I64 : core.convert.From I128 I64 := {
+ from_ := fun x => ok (core.convert.num.FromI128I64.from x)
+}
+
+def core.convert.FromI128I128 : core.convert.From I128 I128 := {
+ from_ := fun x => ok (core.convert.num.FromI128I128.from x)
+}
+
+-- Leading zeros
+def core.num.Usize.leading_zeros (x : Usize) : U32 := sorry
+def core.num.U8.leading_zeros (x : U8) : U32 := sorry
+def core.num.U16.leading_zeros (x : U16) : U32 := sorry
+def core.num.U32.leading_zeros (x : U32) : U32 := sorry
+def core.num.U64.leading_zeros (x : U64) : U32 := sorry
+def core.num.U128.leading_zeros (x : U128) : U32 := sorry
+
+def core.num.Isize.leading_zeros (x : Isize) : U32 := sorry
+def core.num.I8.leading_zeros (x : I8) : U32 := sorry
+def core.num.I16.leading_zeros (x : I16) : U32 := sorry
+def core.num.I32.leading_zeros (x : I32) : U32 := sorry
+def core.num.I64.leading_zeros (x : I64) : U32 := sorry
+def core.num.I128.leading_zeros (x : I128) : U32 := sorry
+
end Primitives