-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate function definitions #4753
base: develop
Are you sure you want to change the base?
Conversation
a02ad0a
to
e77b76f
Compare
Known limitationsRestricting an argument to a subsort on the LHSThis fails to capture the case where a subsort of the subsort is injected directly. def _f4c2469 : SortK → Option SortBool
| SortK.kseq (SortKItem.inj_SortKResult KResult) SortK.dotk => some true
| _ => none Solution: unroll the pattern for each subsort (that has no further subsorts): def _f4c2469 : SortK → Option SortBool
| SortK.kseq (SortKItem.inj_SortBool KResult) SortK.dotk
| SortK.kseq (SortKItem.inj_SortInt KResult) SortK.dotk => some true
| _ => none Collection patterns on the LHSCollection "constructors" are mapped as functions, thus cannot be used in patterns. def _2ede380 : SortList → Option SortInt
| _List_ _Gen0 (ListItem (SortKItem.inj_SortInt I)) => do
let _Val0 <- «_+Int_» I 1
return _Val0
| _ => none Solution: add a de-structuring function for each supported pattern to the correspoinding hook implementation, then: def _2ede380 (x0 : SortList) : Option SortInt :=
match list_pat_init_last x0
| some (_Gen0 (SortKItem.inj_SortInt I)) => do
let _Val0 <- «_+Int_» I 1
return _Val0
| _ => none |
e77b76f
to
23c375b
Compare
def «_+Int_» (x0 : SortInt) (x1 : SortInt) : Option SortInt := some (x0 + x1) | ||
def «_-Int_» (x0 : SortInt) (x1 : SortInt) : Option SortInt := some (x0 - x1) | ||
def «_*Int_» (x0 : SortInt) (x1 : SortInt) : Option SortInt := some (x0 * x1) | ||
def «_<=Int_» (x0 : SortInt) (x1 : SortInt) : Option SortBool := some (x0 <= x1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't other functions be added? Such as «_modInt_»
? We could also add hooked functions such as _List_
. They would be noncomputable
rather than the current axiom
s, and we have the above hooks to link to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could very well be a follow up PR tho!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these few functions are just to demonstrate how to define functions that have no associated function rules:
- Add function definition to
Preulde
. - Add KORE symbol name to
_PRELUDE_FUNCS
ink2lean4.py
.
I'm getting the following error when trying to build the
This is for the following mutual block, but the larger one is also showing a similar error: mutual
def _432555e : SortWordStack → SortInt → Option SortInt
| SortWordStack.«_:__EVM-TYPES_WordStack_Int_WordStack» _Gen0 WS, SIZE => do
let _Val0 <- «_+Int_» SIZE 1
let _Val1 <- sizeWordStackAux WS _Val0
return _Val1
| _, _ => none
def sizeWordStackAux (x0 : SortWordStack) (x1 : SortInt) : Option SortInt := [_432555e, _75897fa].findSome? (· x0 x1)
end Somehow Lean is failing to see that the block is decreasing on the |
The |
Regarding the termination proof issue. I did a few experiments, and I think it might actually be a bug in Lean. In particular, as defined, Lean is unable to show that in If however the definition is modified to def sizeWordStackAux (x0 : SortWordStack) (x1 : SortInt) : Option SortInt := (_432555e x0 x1) <|> (75897fa x0 x1) the goal is as expected, and in fact no manual proof is necessary. I'll look into this a bit more, push a hotfix for the generator, and open an issue on Lean if necessary. |
Closes #4727
Generate a function definition for each (interpreted) function symbol and each function rule.
The definition for a function symbols applies its rule functions in an order respecting priorities:
A function rule evaluates to
none
ifand to
some
otherwise:Function definitions depending on an uninterpreted function are marked
noncomputable
.