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

Allow including lemmas dynamically into APRProver #4681

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

ehildenb
Copy link
Member

@ehildenb ehildenb commented Nov 12, 2024

In order to include lemmas dynamically in the Kontrol prover, we need an option for passing the extra module into the APRProver so that it can be fed into the booster's add-module endpoint. This also requires being able to translate functional rules to Kore in pyk using krule_to_kore. This PR:

  • Adds the extra_module parameter to the APRProver initialization, which allows passing a new module with lemmas into the prover at initialization time. It will pass this module on to the add-module endpoint and make sure it's used on all future requests.
  • Adds the symbolic and smt-lemma attributes to the list of attributes recognized by pyk.
  • Renames KProve.get_claims_modules to KProve.parse_modules, and renames some of its parameters.
  • Adds support to specifying the sort to use in bool_to_ml_pred for converting boolean predicates to matching logic ones.
  • Makes adjustments to _krule_to_kore to make it support translating some functional/simplification rules to Kore which were not supported before (and adds tests):
    • Factors out _krule_att_to_kore method for converting attributes of KRule to kore.
    • Adds a pass to process the rule attributes a bit in krule_to_kore (eg. handle owise => priority(200) and simplification vs priority).
    • Sort the attributes before sending to Kore (for reliable ordering of the Kore output).
    • Refactors the production of Kore axiom to differentiate between semantic and functional rules, and to convert functional rules as matching-logic implies axioms.

@ehildenb ehildenb self-assigned this Nov 13, 2024
@ehildenb ehildenb marked this pull request as ready for review November 13, 2024 07:25
@@ -198,45 +218,105 @@ def _inject(definition: KDefinition, term: KInner, sort: KSort) -> KInner:

# 'krule' should have sorts on variables
def krule_to_kore(definition: KDefinition, krule: KRule) -> Axiom:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -102,15 +102,15 @@ def fun(term: KInner) -> KInner:
return fun


def bool_to_ml_pred(kast: KInner) -> KInner:
def bool_to_ml_pred(kast: KInner, sort: str | KSort = GENERATED_TOP_CELL) -> KInner:
def _bool_constraint_to_ml(_kast: KInner) -> KInner:
if _kast == TRUE:
return mlTop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return mlTop()
return mlTop(sort=sort)

@cached_property
def function_labels(self) -> tuple[str, ...]:
"""Returns the label names of all the `KProduction` which are function symbols for all modules in this definition."""
return tuple(func.klabel.name for func in self.functions if func.klabel is not None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a function symbol without a klabel, consider asserting instead.


axiom_vars: tuple[SortVar, ...] = ()
kore_axiom: Pattern
if not is_functional:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting two helpers: one for the functional case, one for a normal rewrite.

@@ -249,6 +329,25 @@ def kflatmodule_to_kore(definition: KDefinition, kflatmodule: KFlatModule) -> Mo
return Module(name=kflatmodule.name, sentences=(imports + kore_axioms))


def _krule_att_to_kore(att_entry: AttEntry, kast_rule_vars: dict[str, list[KVariable]]) -> App:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's similar logic in _module_to_kore, maybe it's possible to extract that into it's own module and reuse it here.

@@ -255,19 +255,19 @@ def prove_claim(
depth=depth,
)

def get_claim_modules(
def parse_modules(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the module parser exposed by kprove general enough to parse an arbitrary module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants