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

More Unary and Binary operators from JSON #1257

Merged
merged 5 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 0 additions & 7 deletions mathics/builtin/assignments/assign_binaryop.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class AddTo(InfixOperator, InplaceInfixOperator):

attributes = A_HOLD_FIRST | A_PROTECTED
grouping = "Right"
operator = "+="

operator_symbol = SymbolPlus
return_before_value: bool = True
Expand Down Expand Up @@ -120,7 +119,6 @@ class Decrement(InplaceInfixOperator, InfixOperator, PostfixOperator):

attributes = A_HOLD_FIRST | A_PROTECTED | A_READ_PROTECTED
increment_symbol = IntegerM1
operator = "--"
operator_symbol = SymbolPlus

returns_updated_value = False
Expand Down Expand Up @@ -206,7 +204,6 @@ class Increment(InplaceInfixOperator, InfixOperator, PostfixOperator):

attributes = A_HOLD_FIRST | A_PROTECTED | A_READ_PROTECTED
increment_symbol = Integer1
operator = "++"
operator_symbol = SymbolPlus
returns_updated_value: bool = False
summary_text = (
Expand Down Expand Up @@ -244,7 +241,6 @@ class PreDecrement(InplaceInfixOperator, PrefixOperator):

attributes = A_HOLD_FIRST | A_PROTECTED | A_READ_PROTECTED
increment_symbol = IntegerM1
operator = "--"
operator_symbol = SymbolPlus
returns_updated_value: bool = True
summary_text = "decrease the value by one and assigns that returning the new value"
Expand Down Expand Up @@ -297,7 +293,6 @@ class PreIncrement(InplaceInfixOperator, PrefixOperator):
"""

attributes = A_HOLD_FIRST | A_PROTECTED | A_READ_PROTECTED
operator = "++"
operator_symbol = SymbolPlus
return_before_value: bool = False

Expand Down Expand Up @@ -326,7 +321,6 @@ class SubtractFrom(InfixOperator):

attributes = A_HOLD_FIRST | A_PROTECTED
grouping = "Right"
operator = "-="

rules = {
"x_ -= dx_": "x = x - dx",
Expand All @@ -353,7 +347,6 @@ class TimesBy(InfixOperator):
#> Clear[a]
"""

operator = "*="
attributes = A_HOLD_FIRST | A_PROTECTED
grouping = "Right"

Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/atomic/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ class Information(PrefixOperator):

attributes = A_HOLD_ALL | A_SEQUENCE_HOLD | A_PROTECTED | A_READ_PROTECTED
messages = {"notfound": "Expression `1` is not a symbol"}
operator = "??"
options = {
"LongForm": "True",
}
Expand Down
3 changes: 0 additions & 3 deletions mathics/builtin/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ class Get(PrefixOperator):
## >> << "VectorAnalysis`"
"""

operator = "<<"
options = {
"Trace": "False",
}
Expand Down Expand Up @@ -566,7 +565,6 @@ class Put(InfixOperator):
S> DeleteFile[filename]
"""

operator = ">>"
summary_text = "write an expression to a file"

def eval(self, exprs, filename, evaluation):
Expand Down Expand Up @@ -661,7 +659,6 @@ class PutAppend(InfixOperator):
>> DeleteFile["factorials"];
"""

operator = ">>>"
summary_text = "append an expression to a file"

def eval(self, exprs, filename, evaluation):
Expand Down
5 changes: 0 additions & 5 deletions mathics/builtin/functional/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class Function(PostfixOperator, SympyFunction):
to the function body.
"""

operator = "&"
attributes = A_HOLD_ALL | A_PROTECTED

messages = {
Expand Down Expand Up @@ -196,8 +195,6 @@ class Slot(SympyFunction, PrefixOperator):

attributes = A_N_HOLD_ALL | A_PROTECTED

operator = "#" # FIXME generate this automatically

rules = {
"Slot[]": "Slot[1]",
"MakeBoxes[Slot[n_Integer?NonNegative],"
Expand Down Expand Up @@ -237,8 +234,6 @@ class SlotSequence(PrefixOperator, Builtin):

attributes = A_N_HOLD_ALL | A_PROTECTED

operator = "##" # FIXME generate this automatically

rules = {
"SlotSequence[]": "SlotSequence[1]",
"MakeBoxes[SlotSequence[n_Integer?Positive],"
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/functional/apply_fns_to_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class Apply(InfixOperator):
summary_text = "apply a function to a list, at specified levels"
grouping = "Right"

operator = "@@" # FIXME generate this automatically

options = {
"Heads": "False",
}
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ class Postfix(PostfixOperator):
"""

grouping = "Left"
operator = "//"
operator_display = None
summary_text = "postfix form"

Expand Down Expand Up @@ -321,7 +320,6 @@ class Prefix(PrefixOperator):
"""

grouping = "Right"
operator = "@"
operator_display = None
summary_text = "prefix form"

Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/list/eol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,6 @@ class Span(InfixOperator):
= Span[1, 3]
"""

operator = ";;"
summary_text = "general specification for spans or blocks of elements"


Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ class MessageName(InfixOperator):
default_formats = False
formats: typing.Dict[str, Any] = {}
messages = {"messg": "Message cannot be set to `1`. It must be set to a string."}
operator = "::"
rules = {
"MakeBoxes[MessageName[symbol_Symbol, tag_String], "
"f:StandardForm|TraditionalForm|OutputForm]": (
Expand Down
4 changes: 0 additions & 4 deletions mathics/builtin/no_meaning/infix_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class DirectedEdge(InfixOperator):

attributes = A_NO_ATTRIBUTES
default_formats = False # Don't use any default format rules. Instead, see belo.

operator = "→"
summary_text = 'DirectedEdge infix operator "→"'


Expand Down Expand Up @@ -82,6 +80,4 @@ class UndirectedEdge(InfixOperator):

attributes = A_NO_ATTRIBUTES
default_formats = False # Don't use any default format rules. Instead, see belo.

operator = "↔"
summary_text = 'UndirectedEdge infix operator "↔"'
1 change: 0 additions & 1 deletion mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ class Derivative(PostfixOperator, SympyFunction):

attributes = A_N_HOLD_ALL
default_formats = False
operator = "'"
rules = {
"MakeBoxes[Derivative[n__Integer][f_], "
" form:StandardForm|TraditionalForm]": (
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/patterns/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ class Repeated(PostfixOperator, PatternObject):
)
}

operator = ".."
summary_text = "match to one or more occurrences of a pattern"

def init(
Expand Down Expand Up @@ -550,7 +549,6 @@ class RepeatedNull(Repeated):
= t
"""

operator = "..."
summary_text = "match to zero or more occurrences of a pattern"

def init(
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/patterns/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class Optional(InfixOperator, PatternObject):
"MakeBoxes[Verbatim[Optional][Verbatim[Pattern][symbol_Symbol, Verbatim[_]]], f:StandardForm|TraditionalForm|InputForm|OutputForm]": 'MakeBoxes[symbol, f] <> "_."',
"MakeBoxes[Verbatim[Optional][Verbatim[_]], f:StandardForm|TraditionalForm|InputForm|OutputForm]": '"_."',
}
operator = ":"
summary_text = "an optional argument with a default value"

def init(
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/patterns/restrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Condition(InfixOperator, PatternObject):
arg_counts = [2]
# Don't know why this has attribute HoldAll in Mathematica
attributes = A_HOLD_REST | A_PROTECTED
operator = "/;"
summary_text = "conditional definition"

def init(
Expand Down Expand Up @@ -106,7 +105,6 @@ class PatternTest(InfixOperator, PatternObject):
"""

arg_counts = [2]
operator = "?"
summary_text = "match to a pattern conditioned to a test result"

def init(
Expand Down
3 changes: 3 additions & 0 deletions mathics/builtin/patterns/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ class Rule_(InfixOperator):
grouping = "Right"
name = "Rule"
needs_verbatim = True

# FIXME: if we remove this we have problems.
# We should be able to get this from JSON.
operator = "->"
summary_text = "a replacement rule"

Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/procedural.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ class CompoundExpression(InfixOperator):
"""

attributes = A_HOLD_ALL | A_PROTECTED | A_READ_PROTECTED
operator = ";"

summary_text = "execute expressions in sequence"

Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/specialfns/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class Factorial(PostfixOperator, MPMathFunction):
attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED

mpmath_name = "factorial"
operator = "!"
summary_text = "factorial"


Expand Down Expand Up @@ -201,7 +200,6 @@ class Factorial2(PostfixOperator, MPMathFunction):
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED
operator = "!!"
mpmath_name = "fac2"
sympy_name = "factorial2"
messages = {
Expand Down
3 changes: 2 additions & 1 deletion mathics/builtin/testing_expressions/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ class Or(InfixOperator):
"""

attributes = A_FLAT | A_HOLD_ALL | A_ONE_IDENTITY | A_PROTECTED
operator = "||"
summary_text = "logic (inclusive) disjunction"

# rules = {
Expand Down Expand Up @@ -437,6 +436,8 @@ class Not(PrefixOperator):
= !b
"""

# FIXME: If we remove this we pick up unicode unconditionally
# which wew don't want to do.
operator = "!"

rules = {
Expand Down
12 changes: 12 additions & 0 deletions mathics/core/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,18 @@ class UnaryOperator(Operator):
def __init__(self, format_function, *args, **kwargs):
super().__init__(*args, **kwargs)
name = self.get_name(short=True)

# Pick up operator string from JSON table if
# it appears there.
if self.operator is None:
operator_string = self.get_operator()
if operator_string:
self.operator = operator_string
# else:
# if self.operator is None:
# breakpoint()
# print("FIX UP", self.operator, name)

self.precedence = self.get_precedence(name)
if self.needs_verbatim:
name = f"Verbatim[{name}"
Expand Down
Loading