-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Improving precedence comparison. #1154
Conversation
* Improving handling for Infix, Prefix and Postfix format
mathics/builtin/layout.py
Outdated
@@ -16,7 +16,13 @@ | |||
from mathics.builtin.makeboxes import MakeBoxes | |||
from mathics.builtin.options import options_to_rules | |||
from mathics.core.atoms import Real, String | |||
from mathics.core.builtin import BinaryOperator, Builtin, Operator | |||
from mathics.core.builtin import ( | |||
BinaryOperator, |
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.
WIth the changes to use PostfixOperator and PrefixOperator (thank you very much), the "BinaryOperator" is no longer imported.
mathics/builtin/recurrence.py
Outdated
## PyPy: {{a -> (Function[{n}, 1 - C[1] + C[1] -1 ^ n])}} | ||
## CPython: {{a -> (Function[{n}, 1 + C[1] -1 ^ n - C[1]])} | ||
## PyPy: {{a -> Function[{n}, 1 - C[1] + C[1] -1 ^ n]}} | ||
## CPython: {{a -> Function[{n}, 1 + C[1] -1 ^ n - C[1]]} | ||
|
||
Geta "pure function" solution for a with two boundary conditions: |
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.
A small typo from previous: "Geta" -> "Get a"
attributes = A_SEQUENCE_HOLD | A_PROTECTED | ||
grouping = "Right" | ||
name = "Rule" |
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.
Thanks for alphabetizing.
@@ -527,7 +527,7 @@ def lhs(expr): | |||
return Expression(SymbolFormat, expr, Symbol(format)) | |||
|
|||
def rhs(expr): | |||
if expr.has_formf(SymbolInfix, None): | |||
if expr.has_form(SymbolInfix, None): |
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.
Good catch!
mathics/eval/makeboxes.py
Outdated
) -> Optional[int]: | ||
""" | ||
compare the precedence of the element regarding a precedence value. | ||
If both precedences are equivalent, return 0. If precedence of element |
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.
precedence is an integers or maybe fixed-point numbers. So here, "equivalent" is the same as "equals".
If both precedences are equivalent -> If the precedence is the same
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.
If the precedence of element -> If the precedence of the first element
@@ -279,8 +307,8 @@ def format_expr(expr): | |||
|
|||
formatted = format_expr(expr) if isinstance(expr, EvalMixin) else None | |||
if formatted is not None: | |||
do_format = element_formatters.get(type(formatted), do_format_element) | |||
result = do_format(formatted, evaluation, form) | |||
do_format_fn = element_formatters.get(type(formatted), do_format_element) |
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.
thanks
@@ -1151,22 +1151,29 @@ def __init__(self, *args, **kwargs): | |||
|
|||
# Prevent pattern matching symbols from gaining meaning here using | |||
# Verbatim | |||
name = f"Verbatim[{name}]" | |||
verbatim_name = f"Verbatim[{name}]" |
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.
thanks
LGTM - but please see comments. |
@rocky, good. Then let's merge and iterate. |
This PR includes some fixes and improvings for handling operator precedence. In particular, as in WMA, avoids wrapping in parenthesis the second element of
Rule[pat_, Function[...]]
.