Skip to content

Commit

Permalink
keep the constraints unchanged after creating a new cterm
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevengre committed Dec 11, 2024
1 parent e2a9c6f commit fc28d3f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pyk/src/pyk/cterm/cterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CTerm:
config: KInner # TODO Optional?
constraints: tuple[KInner, ...]

def __init__(self, config: KInner, constraints: Iterable[KInner] = ()) -> None:
def __init__(self, config: KInner, constraints: Iterable[KInner] = (), sort_constraints: bool = True) -> None:
"""Instantiate a given `CTerm`, performing basic sanity checks on the `config` and `constraints`."""
if is_top(config, weak=True):
config = mlTop()
Expand All @@ -55,7 +55,7 @@ def __init__(self, config: KInner, constraints: Iterable[KInner] = ()) -> None:
constraints = ()
else:
self._check_config(config)
constraints = self._normalize_constraints(constraints)
constraints = self._normalize_constraints(constraints, sort_constraints)
object.__setattr__(self, 'config', config)
object.__setattr__(self, 'constraints', constraints)

Expand Down Expand Up @@ -94,8 +94,12 @@ def _check_config(config: KInner) -> None:
raise ValueError(f'Expected cell label, found: {config}')

@staticmethod
def _normalize_constraints(constraints: Iterable[KInner]) -> tuple[KInner, ...]:
constraints = sorted(normalize_constraints(constraints), key=CTerm._constraint_sort_key)
def _normalize_constraints(constraints: Iterable[KInner], sort_constraints: bool = True) -> tuple[KInner, ...]:
if sort_constraints:
constraints = normalize_constraints(constraints)
# constraints = sorted(normalize_constraints(constraints), key=CTerm._constraint_sort_key)
else:
constraints = normalize_constraints(constraints)
return tuple(constraints)

@property
Expand Down Expand Up @@ -349,7 +353,7 @@ def apply(self, cterm: CTerm) -> CTerm:
"""Apply this `CSubst` to the given `CTerm` (instantiating the free variables, and adding the constraints)."""
config = self.subst(cterm.config)
constraints = [self.subst(constraint) for constraint in cterm.constraints] + list(self.constraints)
return CTerm(config, constraints)
return CTerm(config, constraints, sort_constraints=False)

def __call__(self, cterm: CTerm) -> CTerm:
"""Overload for `CSubst.apply`."""
Expand Down

0 comments on commit fc28d3f

Please sign in to comment.