keep the constraints unchanged after creating a new cterm#4709
keep the constraints unchanged after creating a new cterm#4709
Conversation
| 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) |
There was a problem hiding this comment.
@PetarMax Here is the fastest way to solve the disordered problem for CSubst.
k/pyk/src/pyk/kcfg/minimize.py
Lines 76 to 110 in c8d0bee
Take the above function as an example. line 101 should create a cterm with ordered constraints that the new constraints locates at the end of all the constraints.
Lines 348 to 352 in c8d0bee
But even the line 351 gives a correct order for the CTerm, the line 352 will re-sort the constraints after calling __init__.
Lines 755 to 760 in c8d0bee
What makes this situation harder to tackle is that the = in line 759 will call __init__ by default, which makes the sort_constraints flag useless.
There was a problem hiding this comment.
I think there's a copy-paste error here: even if sort_constraints=True, the constraints won't be sorted.
There was a problem hiding this comment.
@tothtamas28 Yes, it's an issue that I don't know how to solve it. Because the following code will call CTerm.__init__ by default and make the previous order-keeping efforts useless. Do you have any suggestions for it? And why should we sort the constraints, btw?
Line 758 in c8d0bee
There was a problem hiding this comment.
I'm not familiar with the context of this change. But my point is, instead of
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)you could have
def _normalize_constraints(constraints: Iterable[KInner]) -> tuple[KInner, ...]:
constraints = normalize_constraints(constraints)There was a problem hiding this comment.
Thank you! I want to refactor the function this way. But I'm not sure if there is any other applications / functions relying on the sorted function. Do you think it's safe to just remove the sorted?
There was a problem hiding this comment.
One thing I can think of where the constraints being sorted is useful is for equality checking between CTerm-s. I'm not sure if it's a common use case in the prover though.
Just to make sure, please check the history of this piece of code. Then we'll have a better idea of why constraints are sorted in the first place.
No description provided.