Skip to content

Commit 562d323

Browse files
authored
Klean: implement ^%Int and rename generated abs to kabs (#4836)
This PR implements the `^%Int` function and renames the generated `abs` function to `kabs` to not collide with Mathlib's `abs` function.
1 parent 6e23f34 commit 562d323

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

  • pyk/src/pyk/klean

pyk/src/pyk/klean/k2lean4.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"Lbl'UndsStar'Int'Unds'", # *Int
6868
"Lbl'UndsSlsh'Int'Unds'", # /Int
6969
"Lbl'Unds'modInt'Unds'", # modInt
70+
"Lbl'UndsXor-Perc'Int'UndsUnds'", # ^%Int
7071
"LblmaxInt'LParUndsCommUndsRParUnds'INT-COMMON'Unds'Int'Unds'Int'Unds'Int", # maxInt
7172
"Lbl'Tild'Int'Unds'", # ~Int
7273
"Lbl'Unds-LT-Eqls'Int'Unds'", # <=Int
@@ -87,6 +88,7 @@
8788

8889
_SYMBOL_OVERRIDES: Final = {
8990
'Lblite': 'kite',
91+
'Lblabs': 'kabs',
9092
}
9193

9294

pyk/src/pyk/klean/template/{{ cookiecutter.package_name }}/{{ cookiecutter.library_name }}/Prelude.lean

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,13 @@ def «_-Int_» (x0 x1 : SortInt) : Option SortInt := some (x0 - x1)
241241
def «_*Int_» (x0 x1 : SortInt) : Option SortInt := some (x0 * x1)
242242
def «_/Int_» (x0 x1 : SortInt) : Option SortInt :=
243243
ite (x1 == 0) none (Int.tdiv x0 x1)
244-
def _modInt_ (x0 : SortInt) (x1 : SortInt) : Option SortInt :=
244+
def _modInt_ (x0 x1 : SortInt) : Option SortInt :=
245245
ite (x1 == 0) none (Int.emod x0 x1)
246+
def «_^%Int__» (x0 x1 x2 : SortInt) : Option SortInt :=
247+
if x2 == 0 then none else
248+
match x1 with -- TODO: Revisit this implementation
249+
| .ofNat n => some (Int.emod (Int.pow x0 n) x2)
250+
| _ => none
246251
def «maxInt(_,_)_INT-COMMON_Int_Int_Int» (x0 x1 : SortInt) :=
247252
some (ite (x0 < x1) x1 x0)
248253
def «log2Int(_)_INT-COMMON_Int_Int» (x0 : SortInt) : Option SortInt :=

0 commit comments

Comments
 (0)