-
Notifications
You must be signed in to change notification settings - Fork 150
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
Merge CTerm #4621
Merge CTerm #4621
Changes from all commits
9ff6473
b493ab8
2f1ac1e
6aa49cd
0484b4a
c73308b
a7896a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -102,6 +102,11 @@ def is_bottom(self) -> bool: | |||||
"""Check if a given `CTerm` is trivially empty.""" | ||||||
return is_bottom(self.config, weak=True) or any(is_bottom(cterm, weak=True) for cterm in self.constraints) | ||||||
|
||||||
@property | ||||||
def constraint(self) -> KInner: | ||||||
"""Return the set of constraints as a single flattened constraint using `mlAnd`.""" | ||||||
return mlAnd(self.constraints) | ||||||
|
||||||
@staticmethod | ||||||
def _constraint_sort_key(term: KInner) -> tuple[int, str]: | ||||||
term_str = str(term) | ||||||
|
@@ -253,6 +258,46 @@ def remove_useless_constraints(self, keep_vars: Iterable[str] = ()) -> CTerm: | |||||
return CTerm(self.config, new_constraints) | ||||||
|
||||||
|
||||||
def merge_cterms(t1: CTerm, t2: CTerm) -> CTerm | None: | ||||||
"""Return a `CTerm` which is the merge of the two input `CTerm` instances. | ||||||
|
||||||
Args: | ||||||
t1: First `CTerm` to merge. | ||||||
t2: Second `CTerm` to merge. | ||||||
|
||||||
Returns: | ||||||
A `CTerm` which is the merge of the two input `CTerm` instances. | ||||||
""" | ||||||
# check all cells in t1 and t1, if they are the same, keep them, otherwise, create a new free variable for them | ||||||
t1_config, t1_subst = split_config_from(t1.config) | ||||||
t2_config, t2_subst = split_config_from(t2.config) | ||||||
|
||||||
if t1_config != t2_config: | ||||||
# cannot merge two configurations with different structure | ||||||
return None | ||||||
|
||||||
new_subst = Subst({}) | ||||||
new_t1_subst = Subst({}) | ||||||
new_t2_subst = Subst({}) | ||||||
|
||||||
for cell in t1_subst: | ||||||
if t1_subst[cell] == t2_subst[cell]: | ||||||
# keep the cell if it is the same | ||||||
new_subst = new_subst * Subst({cell: t1_subst[cell]}) | ||||||
else: | ||||||
# create a new free variable for the cell | ||||||
new_t1_subst = new_t1_subst * Subst({cell: t1_subst[cell]}) | ||||||
new_t2_subst = new_t2_subst * Subst({cell: t2_subst[cell]}) | ||||||
new_config = new_subst(t1_config) | ||||||
|
||||||
new_constraints: list[KInner] = [] | ||||||
for new_subst, t in [(new_t1_subst, t1), (new_t2_subst, t2)]: | ||||||
if new_subst: | ||||||
new_constraints.append(mlImplies(new_subst.ml_pred, t.constraint)) | ||||||
|
||||||
return CTerm(new_config, new_constraints) | ||||||
Comment on lines
+261
to
+298
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a less powerful version of
You'll have that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are some tests of antiunification: k/pyk/src/tests/integration/proof/test_imp.py Line 1296 in 42e0354
k/pyk/src/tests/integration/proof/test_imp.py Line 1247 in 42e0354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I looked at the code and tests of |
||||||
|
||||||
|
||||||
def anti_unify(state1: KInner, state2: KInner, kdef: KDefinition | None = None) -> tuple[KInner, Subst, Subst]: | ||||||
"""Return a generalized state over the two input states. | ||||||
|
||||||
|
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.
Main implementation of
merge_cterms
.None
if the configuration structures are different.CELL_NAME == SUBST /\ ... -> source.constraint /\ ...