leanfran 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +667 -2
- package/dist/arbitrary-B7Frjn9q.js +131 -0
- package/dist/block-CU7YIXdj.js +37 -0
- package/dist/check-DROT5twE.js +2931 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +134 -0
- package/dist/embed-BlX4FUDH.js +200 -0
- package/dist/index-DPF21ftq.d.ts +210 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +1 -0
- package/dist/io-CmMW8KGX.d.ts +66 -0
- package/dist/marshal-DhKsxhRw.js +2012 -0
- package/dist/node-B3DpEsaq.js +46 -0
- package/dist/object-G1zwZFrv.d.ts +93 -0
- package/dist/runtime/node.d.ts +2 -0
- package/dist/runtime/node.js +1 -0
- package/dist/runtime.d.ts +433 -0
- package/dist/runtime.js +1020 -0
- package/dist/schema-CvTyc8wa.js +308 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +4 -0
- package/dist/verify.d.ts +27 -0
- package/dist/verify.js +215 -0
- package/package.json +69 -4
- package/src/lean/LeanTsLib/Ts.lean +78 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
namespace Ts
|
|
2
|
+
|
|
3
|
+
inductive Exc where
|
|
4
|
+
| error (name : String) (message : String)
|
|
5
|
+
| undefinedValue
|
|
6
|
+
| zeroDivision
|
|
7
|
+
deriving Repr, DecidableEq
|
|
8
|
+
|
|
9
|
+
abbrev M := Except Exc
|
|
10
|
+
|
|
11
|
+
def index (xs : List α) (i : Int) : Option α :=
|
|
12
|
+
if i < 0 then none else xs[i.toNat]?
|
|
13
|
+
|
|
14
|
+
def get (xs : List α) (i : Int) : M α :=
|
|
15
|
+
match index xs i with
|
|
16
|
+
| some v => pure v
|
|
17
|
+
| none => throw .undefinedValue
|
|
18
|
+
|
|
19
|
+
def unwrap (o : Option α) : M α :=
|
|
20
|
+
match o with
|
|
21
|
+
| some v => pure v
|
|
22
|
+
| none => throw .undefinedValue
|
|
23
|
+
|
|
24
|
+
def floorDiv (a b : Int) : M Int := if b = 0 then throw .zeroDivision else pure (Int.fdiv a b)
|
|
25
|
+
|
|
26
|
+
def truncDiv (a b : Int) : M Int := if b = 0 then throw .zeroDivision else pure (Int.tdiv a b)
|
|
27
|
+
|
|
28
|
+
def rem (a b : Int) : M Int := if b = 0 then throw .zeroDivision else pure (Int.tmod a b)
|
|
29
|
+
|
|
30
|
+
def range (a b : Int) : List Int := (List.range (b - a).toNat).map fun (k : Nat) => a + (k : Int)
|
|
31
|
+
|
|
32
|
+
def abs (a : Int) : Int := if a < 0 then -a else a
|
|
33
|
+
|
|
34
|
+
def length (xs : List α) : Int := xs.length
|
|
35
|
+
|
|
36
|
+
def strLength (s : String) : Int :=
|
|
37
|
+
(s.toList.map fun c => if c.toNat ≥ 0x10000 then (2 : Int) else 1).sum
|
|
38
|
+
|
|
39
|
+
def startsWith (s t : String) : Bool := t.toList.isPrefixOf s.toList
|
|
40
|
+
|
|
41
|
+
def endsWith (s t : String) : Bool := t.toList.isSuffixOf s.toList
|
|
42
|
+
|
|
43
|
+
def includes (s t : String) : Bool :=
|
|
44
|
+
(List.range (s.length + 1)).any fun i => t.toList.isPrefixOf (s.toList.drop i)
|
|
45
|
+
|
|
46
|
+
class Str (α : Type) where
|
|
47
|
+
str : α → String
|
|
48
|
+
|
|
49
|
+
instance : Str Int := ⟨fun n => toString n⟩
|
|
50
|
+
instance : Str String := ⟨id⟩
|
|
51
|
+
instance : Str Bool := ⟨fun b => if b then "true" else "false"⟩
|
|
52
|
+
|
|
53
|
+
def str [Str α] (a : α) : String := Str.str a
|
|
54
|
+
|
|
55
|
+
@[simp] theorem str_string (s : String) : str s = s := rfl
|
|
56
|
+
|
|
57
|
+
@[simp] theorem length_eq (xs : List α) : length xs = (xs.length : Int) := rfl
|
|
58
|
+
|
|
59
|
+
@[simp] theorem range_mem (a b i : Int) : i ∈ range a b ↔ a ≤ i ∧ i < b := by
|
|
60
|
+
simp only [range, List.mem_map, List.mem_range]
|
|
61
|
+
constructor
|
|
62
|
+
· rintro ⟨k, hk, rfl⟩; omega
|
|
63
|
+
· intro h; exact ⟨(i - a).toNat, by omega, by omega⟩
|
|
64
|
+
|
|
65
|
+
theorem range_succ (a b : Int) (h : a ≤ b) : range a (b + 1) = range a b ++ [b] := by
|
|
66
|
+
simp only [range]
|
|
67
|
+
have h1 : (b + 1 - a).toNat = (b - a).toNat + 1 := by omega
|
|
68
|
+
rw [h1, List.range_succ, List.map_append]
|
|
69
|
+
simp only [List.map_cons, List.map_nil, List.append_cancel_left_eq, List.cons.injEq, and_true]
|
|
70
|
+
omega
|
|
71
|
+
|
|
72
|
+
@[simp] theorem index_nil (i : Int) : index ([] : List α) i = none := by
|
|
73
|
+
unfold index; split <;> simp
|
|
74
|
+
|
|
75
|
+
theorem abs_nonneg (a : Int) : 0 ≤ abs a := by
|
|
76
|
+
unfold abs; split <;> omega
|
|
77
|
+
|
|
78
|
+
end Ts
|