Skip to content
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 an axiom for each function signature #4736

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pyk/src/pyk/k2lean4/k2lean4.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from .model import (
Alt,
AltsFieldVal,
Axiom,
Ctor,
ExplBinder,
ImplBinder,
Inductive,
Instance,
InstField,
Expand All @@ -33,7 +35,7 @@

from ..kore.internal import KoreDefn
from ..kore.syntax import SymbolDecl
from .model import Command, Declaration, FieldVal
from .model import Binder, Command, Declaration, FieldVal


_VALID_LEAN_IDENT: Final = re.compile(
Expand Down Expand Up @@ -207,6 +209,23 @@ def inj(subsort: str, supersort: str, x: str) -> Term:

return res

def func_module(self) -> Module:
commands = [self._transform_func(func) for func in self.defn.functions]
return Module(commands=commands)

def _transform_func(self, func: str) -> Axiom:
ident = self._symbol_ident(func)
decl = self.defn.symbols[func]
sort_params = [var.name for var in decl.symbol.vars]
param_sorts = [sort.name for sort in decl.param_sorts]
sort = decl.sort.name

binders: list[Binder] = []
if sort_params:
binders.append(ImplBinder(sort_params, Term('Type')))
binders.extend(ExplBinder((f'x{i}',), Term(sort)) for i, sort in enumerate(param_sorts))
return Axiom(ident, Signature(binders, Term(f'Option {sort}')))


def _param_sorts(decl: SymbolDecl) -> list[str]:
from ..utils import check_type
Expand Down
18 changes: 18 additions & 0 deletions pyk/src/pyk/k2lean4/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ class Declaration(Command, ABC):
modifiers: Modifiers | None


@final
@dataclass
class Axiom(Declaration):
ident: DeclId
signature: Signature
modifiers: Modifiers | None

def __init__(self, ident: str | DeclId, signature: Signature, modifiers: Modifiers | None = None):
ident = DeclId(ident) if isinstance(ident, str) else ident
object.__setattr__(self, 'ident', ident)
object.__setattr__(self, 'signature', signature)
object.__setattr__(self, 'modifiers', modifiers)

def __str__(self) -> str:
modifiers = f'{self.modifiers} ' if self.modifiers else ''
return f'{modifiers}axiom {self.ident} {self.signature}'


@final
@dataclass
class Abbrev(Declaration):
Expand Down
Loading