leanfran 0.6.0__py3-none-any.whl
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.
- leanfran/__init__.py +6 -0
- leanfran/check.py +292 -0
- leanfran/cli.py +73 -0
- leanfran/embed.py +131 -0
- leanfran/io.py +15 -0
- leanfran/io_externs.py +1192 -0
- leanfran/lean/LeanPythonLib/Py.lean +52 -0
- leanfran/marshal.py +729 -0
- leanfran/models.py +297 -0
- leanfran/runtime.py +1400 -0
- leanfran/sync.py +265 -0
- leanfran/translate.py +469 -0
- leanfran/types.py +33 -0
- leanfran/verify.py +147 -0
- leanfran-0.6.0.dist-info/METADATA +388 -0
- leanfran-0.6.0.dist-info/RECORD +19 -0
- leanfran-0.6.0.dist-info/WHEEL +4 -0
- leanfran-0.6.0.dist-info/entry_points.txt +2 -0
- leanfran-0.6.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/-! The meaning of the Python operations the translated functions use (`leanfran check`).
|
|
2
|
+
|
|
3
|
+
Failing operations (indexing, `//`, `%`, `assert`, `raise`) return `Py.M α = Except Py.Exc α`.
|
|
4
|
+
Python's `int` is `Int`; `//` and `%` round towards negative infinity (`Int.fdiv`, `Int.fmod`). -/
|
|
5
|
+
|
|
6
|
+
namespace Py
|
|
7
|
+
|
|
8
|
+
/-- The exceptions of the translated functions. -/
|
|
9
|
+
inductive Exc where
|
|
10
|
+
| indexError
|
|
11
|
+
| zeroDivisionError
|
|
12
|
+
| assertionError
|
|
13
|
+
| valueError (msg : String)
|
|
14
|
+
deriving Repr, DecidableEq
|
|
15
|
+
|
|
16
|
+
abbrev M := Except Exc
|
|
17
|
+
|
|
18
|
+
/-- `xs[i]`, with Python's negative indices. -/
|
|
19
|
+
def getItem (xs : List α) (i : Int) : M α :=
|
|
20
|
+
let j := if i < 0 then i + xs.length else i
|
|
21
|
+
if 0 ≤ j then
|
|
22
|
+
match xs[j.toNat]? with
|
|
23
|
+
| some v => pure v
|
|
24
|
+
| none => throw .indexError
|
|
25
|
+
else throw .indexError
|
|
26
|
+
|
|
27
|
+
/-- `a // b`. -/
|
|
28
|
+
def floordiv (a b : Int) : M Int := if b = 0 then throw .zeroDivisionError else pure (Int.fdiv a b)
|
|
29
|
+
|
|
30
|
+
/-- `a % b`. -/
|
|
31
|
+
def mod (a b : Int) : M Int := if b = 0 then throw .zeroDivisionError else pure (Int.fmod a b)
|
|
32
|
+
|
|
33
|
+
/-- `range(a, b)`. -/
|
|
34
|
+
def range (a b : Int) : List Int := (List.range (b - a).toNat).map fun (k : Nat) => a + (k : Int)
|
|
35
|
+
|
|
36
|
+
def abs (a : Int) : Int := if a < 0 then -a else a
|
|
37
|
+
|
|
38
|
+
def len (xs : List α) : Int := xs.length
|
|
39
|
+
|
|
40
|
+
def strLen (s : String) : Int := s.length
|
|
41
|
+
|
|
42
|
+
def sum (xs : List Int) : Int := xs.foldl (· + ·) 0
|
|
43
|
+
|
|
44
|
+
def assert (c : Bool) : M Unit := if c then pure () else throw .assertionError
|
|
45
|
+
|
|
46
|
+
@[simp] theorem range_mem (a b i : Int) : i ∈ range a b ↔ a ≤ i ∧ i < b := by
|
|
47
|
+
simp only [range, List.mem_map, List.mem_range]
|
|
48
|
+
constructor
|
|
49
|
+
· rintro ⟨k, hk, rfl⟩; omega
|
|
50
|
+
· intro h; exact ⟨(i - a).toNat, by omega, by omega⟩
|
|
51
|
+
|
|
52
|
+
end Py
|