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

Precedence for Directed and Undirected Edge #103

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mathics_scanner/data/operators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ DifferentialD:
# comments:

DirectedEdge:
precedence: 128
precedence: 295
WolframLanguageData:
WolframLanguageData-corrected: 49
UnicodeCharacters.tr: 395
Expand Down Expand Up @@ -7057,7 +7057,7 @@ UnderscriptBox:
# comments:

UndirectedEdge:
precedence: 120 # FIXME: is probably 295. Check and adjust after code and mathics-core are merge
precedence: 295
WolframLanguageData:
WolframLanguageData-corrected: 49
UnicodeCharacters.tr: 395
Expand Down
5 changes: 2 additions & 3 deletions test/test_mathics_precedence.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,8 @@
"TildeEqual",
"TildeFullEqual",
"TildeTilde",
# In Mathics, the precedence of these operators is quite low.
# "DirectedEdge", # Mathics 128 , WMA 295
# "UndirectedEdge", # Mathics 120, WMA 295
"DirectedEdge",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precedence order of these symbols is tested here. Of course, other tests can be added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is extremely opaque. (BTW the one for TestConstrained is also that way.)

I was hoping for something operational or something a user might experience, rather than checking that the value in this table is less than another value.

Setting operator precedence determines whether we have parenthesis or not. So in a chain of direct/directed operators, we should see in full form the grouping change, and when there are other operators around them, then either parenthesis or the way calls are nested change.

I seem to recall that there were tests around that worked that way. This is testing the effect of the precedence values on the way parsing happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is extremely opaque. (BTW the one for TestConstrained is also that way.)

OK, but this is what we can check without bitting our tails: we cannot deduce what the precedence order is for a given pair of operators: we need to look at a reference. The parser or the formatter of Mathics-core could show the right behavior without looking at the tables. And even if they do, checking that their behavior is consistent with the information in the table is not a warranty that this information is right, because it was produced from it: What we are checking is the parser and the formatter, not the accuracy of the information.

What I think it makes more sense is to check if the precedence order in WMA is consistent with its own behavior, and handle the inconsistencies by slightly adjust the values that we store. This is why I wrote this kind of operational test in a WL module. Then, if someone has doubts about one precedence value in the table, can go to wolframscript and check it out. Of course, we can also use it over mathics-core.

Maybe it worth to put this in a comment on the pytest module, but it would go in another PR.

Copy link
Member

@rocky rocky Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial commentary for this PR shows WMA code that was run demonstrating why the precedence needs to be changed.

I want the tests to reflect that by doing the same thing. In general, if one observes that something is wrong because when I run something I get this, then fixing that should run the demonstration to show this is now addressed.

In the future, developers are more likely to encounter the pytest code rather than some PR commentary. The PR commentary is not checked in a simple-minded and easy-to-understand way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but the comments have the only purpose to converge to some criteria about what value must be assigned. Once these criteria can be clearly written, the comments can go out. I started to do that in #105, over this.

Copy link
Member

@rocky rocky Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#105 is fine (with one small removal of slight vagueness).

This PR changes the operator precedence numerical value of DirectedEdge and UndirectedEdge. I am asking that a test be written to demonstrate why the operator precedence change in value is needed and to check that the operational effect we want to achieve persists in the future.

"UndirectedEdge",
"SquareUnion",
"UnionPlus",
"Span",
Expand Down
Loading