This repository was archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Deduplicate productions #505
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f31eae5
Deduplicate productions
virgil-serbanuta ddd977c
Merge f31eae567ce0b05f32cb1233f299f6f692615d2c into be262783d22ac29ab…
virgil-serbanuta 635df4c
Set Version: 0.1.340
rv-auditor 7412737
Fix review comments
virgil-serbanuta e822ed3
Merge branch 'master' into fix-deduplicate-productions
virgil-serbanuta 39c89c6
Merge e822ed3530627b7c4e2def364878784f23da7cd1 into 606bd702c6077fd7b…
virgil-serbanuta a16e92b
Set Version: 0.1.341
rv-auditor 719126d
Add test
virgil-serbanuta 9a3555e
Fix review comments
virgil-serbanuta 541ae86
Merge branch 'master' into fix-deduplicate-productions
virgil-serbanuta c823246
Merge 541ae86abb72b35e2ef8995250779e9c1bb3b79d into b596b753413203160…
virgil-serbanuta e323c29
Set Version: 0.1.343
rv-auditor 2b8a459
Fix review comments
virgil-serbanuta d6f5762
Update src/pyk/kast/kast.py
virgil-serbanuta 9ee428d
Merge branch 'master' into fix-deduplicate-productions
virgil-serbanuta 0b24257
Merge 9ee428d28ebdf6b9b78080eb853f2b482a1f97fc into e0cb46765b33f27a8…
virgil-serbanuta 9e12943
Set Version: 0.1.345
rv-auditor c836e9d
Fix review comments.
virgil-serbanuta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.1.342 | ||
| 0.1.343 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
|
||
| [tool.poetry] | ||
| name = "pyk" | ||
| version = "0.1.342" | ||
| version = "0.1.343" | ||
| description = "" | ||
| authors = [ | ||
| "Runtime Verification, Inc. <[email protected]>", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| module MULTIPLE-DEFINITIONS | ||
| imports A | ||
| imports B | ||
| imports BOOL | ||
|
|
||
| syntax KItem ::= a(KItem) [symbol, label(a)] | ||
| | "b" [symbol, label(b)] | ||
| | "c" [symbol, label(c)] | ||
| rule a(X) => b requires isInt(X) | ||
| rule a(X) => b requires notBool isInt(X) | ||
| rule b => c | ||
| endmodule | ||
|
|
||
| module A | ||
| syntax Int | ||
| endmodule | ||
|
|
||
| module B | ||
| syntax Int | ||
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import pytest | ||
|
|
||
| from pyk.cterm import CTerm | ||
| from pyk.kast.inner import KApply, KSequence, KVariable | ||
| from pyk.prelude.ml import mlTop | ||
| from pyk.testing import KCFGExploreTest | ||
|
|
||
| from ..utils import K_FILES | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Iterable | ||
|
|
||
| from pyk.kcfg import KCFGExplore | ||
|
|
||
|
|
||
| EXECUTE_TEST_DATA: Iterable[tuple[str]] = (('branch',),) | ||
|
|
||
|
|
||
| class TestMultipleDefinitionsProof(KCFGExploreTest): | ||
| KOMPILE_MAIN_FILE = K_FILES / 'multiple-definitions.k' | ||
|
|
||
| @staticmethod | ||
| def config() -> CTerm: | ||
| return CTerm( | ||
| KApply( | ||
| '<generatedTop>', | ||
| KApply('<k>', KSequence(KApply('a', [KVariable('X')]))), | ||
| KVariable('GENERATED_COUNTER_CELL'), | ||
| ), | ||
| (mlTop(),), | ||
| ) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| 'test_id', | ||
| EXECUTE_TEST_DATA, | ||
| ids=[test_id for test_id, *_ in EXECUTE_TEST_DATA], | ||
| ) | ||
| def test_execute( | ||
| self, | ||
| kcfg_explore: KCFGExplore, | ||
| test_id: str, | ||
| ) -> None: | ||
| split_depth, split_post_term, split_next_terms, _logs = kcfg_explore.cterm_execute(self.config(), depth=1) | ||
|
|
||
| split_k = kcfg_explore.kprint.pretty_print(split_post_term.cell('K_CELL')) | ||
| split_next_k = [kcfg_explore.kprint.pretty_print(split_post_term.cell('K_CELL')) for term in split_next_terms] | ||
|
|
||
| assert split_depth == 0 | ||
| assert len(split_next_terms) == 2 | ||
| assert 'a ( X:KItem )' == split_k | ||
| assert [ | ||
| 'a ( X:KItem )', | ||
| 'a ( X:KItem )', | ||
| ] == split_next_k | ||
|
|
||
| step_1_depth, step_1_post_term, step_1_next_terms, _logs = kcfg_explore.cterm_execute( | ||
| split_next_terms[0], depth=1 | ||
| ) | ||
| step_1_k = kcfg_explore.kprint.pretty_print(step_1_post_term.cell('K_CELL')) | ||
| assert 'c' == step_1_k | ||
|
|
||
| step_2_depth, step_2_post_term, step_2_next_terms, _logs = kcfg_explore.cterm_execute( | ||
| split_next_terms[1], depth=1 | ||
| ) | ||
| step_2_k = kcfg_explore.kprint.pretty_print(step_1_post_term.cell('K_CELL')) | ||
| assert 'c' == step_2_k |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
len(_prods)is the number of keys incounter.counteris aMapping[KProduction, int]where the key is the representative of the equivalence class (i.e. the production without the source attribute), and the value is the number of productions that fall into the equivalence class (i.e. those that equal the representative when dropping the source attribute).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.
Yes, I think that's correct. I'm not sure why you explained this, you probably wanted to point out something that I'm still missing.
All I'm saying here is that if I have 'n' production, which I group in 'm' equivalence classes, and I keep one production form each class, this means that I dropped all the other productions, i.e. I dropped n-m productions.
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.
I see, thanks for the clarification.
For me, the following order seems more logical though:
By the way, using this
n-mtrick, theCounteris unnecessary for both orderings: you can just use asetinstead (converting to list is not necessary).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.
I changed it to a set.
To me, this code looks like a series of filters (remove 'unparseAvoid', remove equivalent productions), and other filters may be added in the future. To me, it makes sense to log each filter's activity, then move to the next step (and, for the last filter, the next step is to check how many productions are left and return)