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

Comparison of AST for constraints #76

Open
jmhorcas opened this issue Feb 23, 2022 · 5 comments
Open

Comparison of AST for constraints #76

jmhorcas opened this issue Feb 23, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@jmhorcas
Copy link

jmhorcas commented Feb 23, 2022

Actually, the comparison of AST needs revision. This is important to identify redundancies (e.g., duplicate constraints with different ASTs), as well as to use 'hash' function over the AST.

A first try: to compare two AST, and therefore two constraints, first we need to pass the AST to CNF (already done), remove duplicate clauses, and sort the clauses by lenght and then by variables strings:

clauses = ast.get_clauses()
sorted_clauses = list(map(sorted, clauses))
sorted_clauses.sort(key=len)

Maybe there is another more correct way.

@jmhorcas jmhorcas added the enhancement New feature or request label Feb 23, 2022
@jmhorcas jmhorcas self-assigned this Feb 23, 2022
@jagalindo jagalindo added this to the Sprint 3 (Post opening) milestone Mar 8, 2022
@jagalindo
Copy link
Member

any examples of uses for this? Operations between two models?

@jmhorcas
Copy link
Author

jmhorcas commented Mar 9, 2022

Consider the simplest example:
someone defines the following constraint: A => B
other stakeholder defines the following constraint: not A v B

This is a redundancy which cannot be detected without the funcionality of comparing AST.
The aforementioned solution will solve this example, but maybe not others more complicated.

@jagalindo
Copy link
Member

Yes, I understand the semantics of the functionality. But there are two main things to consider, i) as an operation clearly I see the use case, for example, you have a model and want to simplify it by removing redundant relationships (see http://ceur-ws.org/Vol-1128/paper16.pdf) ii) to have AST simplification, this is where I don't see the use case. It is true that it can simplify the analysis and, even make it faster in some cases, but a complete redundancy check would probably require a sat,bdd or the alike solver. Then, what's the usage scenario of having this functionality in the core?

@jmhorcas
Copy link
Author

jmhorcas commented Mar 9, 2022

Ah ok, I see your doubt. This functionality is not the redundancies checking (that's is a possible usage), this functionality is the comparison through the __eq__ (equals) method in the AST class. That is, wether two AST are the same "semantically" or not. Not sure if the implementation of the equals should be "semantically" or "syntactically". I think this depend if you consider the AST as an AST conceptually or as a lists of clauses.

@jmhorcas
Copy link
Author

jmhorcas commented Mar 9, 2022

OK, after discussing this issue with @jagalindo, I checked that in the current code and there is not any version of __eq__ method provided. Therefore, we can provide one "syntactically" in a future release or leave it without __eq__ method and close this issue.

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

No branches or pull requests

2 participants