diff --git a/mathics/builtin/forms/output.py b/mathics/builtin/forms/output.py
index 081c7e1ba..cce8b09a4 100644
--- a/mathics/builtin/forms/output.py
+++ b/mathics/builtin/forms/output.py
@@ -1,11 +1,13 @@
# FIXME: split these forms up further.
-# MathML and TeXForm feel more closely related since they go with specific kinds of interpreters:
-# LaTeX and MathML
+# MathML and TeXForm feel more closely related since they go with
+# specific kinds of interpreters: LaTeX and MathML
-# SympyForm and PythonForm feel related since are our own hacky thing (and mostly broken for now)
+# SympyForm and PythonForm feel related since are our own hacky thing
+# (and mostly broken for now)
-# NumberForm, TableForm, and MatrixForm seem closely related since they seem to be relevant
-# for particular kinds of structures rather than applicable to all kinds of expressions.
+# NumberForm, TableForm, and MatrixForm seem closely related since
+# they seem to be relevant for particular kinds of structures rather
+# than applicable to all kinds of expressions.
"""
Forms which appear in '$OutputForms'.
@@ -50,7 +52,7 @@
SymbolSubscriptBox,
SymbolSuperscriptBox,
)
-from mathics.eval.makeboxes import format_element
+from mathics.eval.makeboxes import StringLParen, StringRParen, format_element
MULTI_NEWLINE_RE = re.compile(r"\n{2,}")
@@ -1058,12 +1060,14 @@ class MatrixForm(TableForm):
in_printforms = False
summary_text = "format as a matrix"
- def eval_makeboxes_matrix(self, table, f, evaluation, options):
+ def eval_makeboxes_matrix(self, table, form, evaluation, options):
"""MakeBoxes[%(name)s[table_, OptionsPattern[%(name)s]],
- f:StandardForm|TraditionalForm]"""
+ form:StandardForm|TraditionalForm]"""
- result = super(MatrixForm, self).eval_makeboxes(table, f, evaluation, options)
+ result = super(MatrixForm, self).eval_makeboxes(
+ table, form, evaluation, options
+ )
if result.get_head_name() == "System`GridBox":
- return RowBox(String("("), result, String(")"))
+ return RowBox(StringLParen, StringRParen)
return result
diff --git a/mathics/builtin/matrices/partmatrix.py b/mathics/builtin/matrices/partmatrix.py
index a4009520d..32bda9b6c 100644
--- a/mathics/builtin/matrices/partmatrix.py
+++ b/mathics/builtin/matrices/partmatrix.py
@@ -8,6 +8,7 @@
from mathics.builtin.base import Builtin
+from mathics.core.evaluation import Evaluation
from mathics.core.list import ListExpression
@@ -47,7 +48,7 @@ class Diagonal(Builtin):
summary_text = "gives a list with the diagonal elements of a given matrix"
- def apply(self, expr, diag, evaluation):
+ def eval(self, expr, diag, evaluation: Evaluation):
"Diagonal[expr_List, diag_Integer]"
result = []
@@ -63,7 +64,9 @@ def apply(self, expr, diag, evaluation):
class MatrixQ(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/MatrixQ.html
+
+ :WMA link:
+ https://reference.wolfram.com/language/ref/MatrixQ.html
- 'MatrixQ[$m$]'
diff --git a/mathics/builtin/messages.py b/mathics/builtin/messages.py
index f91a5b495..a2e4b1618 100644
--- a/mathics/builtin/messages.py
+++ b/mathics/builtin/messages.py
@@ -1,6 +1,5 @@
"""
-Message related functions.
-
+Message-related functions.
"""
@@ -10,7 +9,7 @@
from mathics.builtin.base import BinaryOperator, Builtin
from mathics.core.atoms import String
from mathics.core.attributes import A_HOLD_ALL, A_HOLD_FIRST, A_PROTECTED
-from mathics.core.evaluation import Message as EvaluationMessage
+from mathics.core.evaluation import Evaluation, Message as EvaluationMessage
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.symbols import Symbol, SymbolNull
@@ -19,7 +18,9 @@
class Message(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/Message.html
+
+ :WMA link:
+ https://reference.wolfram.com/language/ref/Message.html
- 'Message[$symbol$::$msg$, $expr1$, $expr2$, ...]'
@@ -43,7 +44,7 @@ class Message(Builtin):
}
summary_text = "display a message"
- def apply(self, symbol, tag, params, evaluation):
+ def eval(self, symbol: Symbol, tag: String, params, evaluation: Evaluation):
"Message[MessageName[symbol_Symbol, tag_String], params___]"
params = params.get_sequence()
@@ -62,11 +63,14 @@ def check_message(expr) -> bool:
class Check(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/Check.html
+
+ :WMA link:
+ https://reference.wolfram.com/language/ref/Check.html
- 'Check[$expr$, $failexpr$]'
-
- evaluates $expr$, and returns the result, unless messages were generated, in which case it evaluates and $failexpr$ will be returned.
+
- evaluates $expr$, and returns the result, unless messages were \
+ generated, in which case it evaluates and $failexpr$ will be returned.
- 'Check[$expr$, $failexpr$, {s1::t1,s2::t2,...}]'
- checks only for the specified messages.
@@ -141,11 +145,11 @@ class Check(Builtin):
}
summary_text = "discard the result if the evaluation produced messages"
- def apply_1_argument(self, expr, evaluation):
+ def eval(self, expr, evaluation: Evaluation):
"Check[expr_]"
return evaluation.message("Check", "argmu")
- def apply(self, expr, failexpr, params, evaluation):
+ def eval_with_fail(self, expr, failexpr, params, evaluation: Evaluation):
"Check[expr_, failexpr_, params___]"
# Todo: To implement the third form of this function , we need to implement the function $MessageGroups first
@@ -257,7 +261,7 @@ class Quiet(Builtin):
}
summary_text = "evaluate without showing messages"
- def apply(self, expr, moff, mon, evaluation):
+ def eval(self, expr, moff, mon, evaluation: Evaluation):
"Quiet[expr_, moff_, mon_]"
def get_msg_list(expr):
@@ -351,7 +355,7 @@ class Off(Builtin):
attributes = A_HOLD_ALL | A_PROTECTED
summary_text = "turn off a message for printing"
- def apply(self, expr, evaluation):
+ def eval(self, expr, evaluation: Evaluation):
"Off[expr___]"
seq = expr.get_sequence()
@@ -399,7 +403,7 @@ class On(Builtin):
attributes = A_HOLD_ALL | A_PROTECTED
summary_text = "turn on a message for printing"
- def apply(self, expr, evaluation):
+ def eval(self, expr, evaluation: Evaluation):
"On[expr___]"
seq = expr.get_sequence()
@@ -458,7 +462,7 @@ class MessageName(BinaryOperator):
),
}
- def apply(self, symbol, tag, evaluation):
+ def eval(self, symbol: Symbol, tag: String, evaluation: Evaluation):
"MessageName[symbol_Symbol, tag_String]"
pattern = Expression(SymbolMessageName, symbol, tag)
@@ -575,7 +579,9 @@ class Syntax(Builtin):
class General(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/General.html
+
+ :WMA link:
+ https://reference.wolfram.com/language/ref/General.html
- 'General'
diff --git a/mathics/builtin/numeric.py b/mathics/builtin/numeric.py
index c5bb41a02..917ed6a0b 100644
--- a/mathics/builtin/numeric.py
+++ b/mathics/builtin/numeric.py
@@ -1,9 +1,9 @@
# cython: language_level=3
# -*- coding: utf-8 -*-
-# Note: docstring is flowed in documentation. Line breaks in the docstring will appear in the
-# printed output, so be careful not to add them mid-sentence. Line breaks like \
-# this work though.
+# Note: docstring is flowed in documentation. Line breaks in the
+# docstring will appear in the printed output, so be careful not to
+# add them mid-sentence. Line breaks like \ this work though.
"""
Numerical Functions
@@ -89,7 +89,8 @@ def eval(self, expr, delta, evaluation: Evaluation):
class N(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/N.html
+ :WMA link:
+ https://reference.wolfram.com/language/ref/N.html
- 'N[$expr$, $prec$]'
@@ -213,7 +214,7 @@ class N(Builtin):
summary_text = "numerical evaluation to specified precision and accuracy"
- def apply_with_prec(self, expr, prec, evaluation, options=None):
+ def eval_with_prec(self, expr, prec, evaluation, options=None):
"N[expr_, prec_, OptionsPattern[%(name)s]]"
# If options are passed, set the preference in evaluation, and call again
@@ -236,7 +237,7 @@ def apply_with_prec(self, expr, prec, evaluation, options=None):
if preference:
preference_queue.append(preference)
try:
- result = self.apply_with_prec(expr, prec, evaluation)
+ result = self.eval_with_prec(expr, prec, evaluation)
except Exception:
result = None
preference_queue.pop()
@@ -244,7 +245,7 @@ def apply_with_prec(self, expr, prec, evaluation, options=None):
return eval_nvalues(expr, prec, evaluation)
- def apply_N(self, expr, evaluation):
+ def eval_N(self, expr, evaluation: Evaluation):
"""N[expr_]"""
# TODO: Specialize for atoms
return eval_nvalues(expr, SymbolMachinePrecision, evaluation)
diff --git a/mathics/builtin/optimization.py b/mathics/builtin/optimization.py
index cb2d6025d..46d8694f6 100644
--- a/mathics/builtin/optimization.py
+++ b/mathics/builtin/optimization.py
@@ -1,11 +1,16 @@
# -*- coding: utf-8 -*-
"""Mathematical Optimization
-Mathematical optimization is the selection of a best element, with regard to some criterion, from some set of available alternatives.
+Mathematical optimization is the selection of a best element, with regard to \
+some criterion, from some set of available alternatives.
-Optimization problems of sorts arise in all quantitative disciplines from computer science and engineering to operations research and economics, and the development of solution methods has been of interest in mathematics for centuries.
+Optimization problems of sorts arise in all quantitative disciplines from \
+computer science and engineering to operations research and economics, \
+and the development of solution methods has been of interest in mathematics \
+for centuries.
-We intend to provide local and global optimization techniques, both numeric and symbolic.
+We intend to provide local and global optimization techniques, both numeric \
+and symbolic.
"""
# This tells documentation how to sort this module
@@ -18,6 +23,7 @@
from mathics.core.attributes import A_CONSTANT, A_PROTECTED, A_READ_PROTECTED
from mathics.core.convert.python import from_python
from mathics.core.convert.sympy import from_sympy
+from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.symbols import Atom, Symbol
@@ -28,11 +34,14 @@
class Maximize(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/Maximize.html
+
+ :WMA link:
+ https://reference.wolfram.com/language/ref/Maximize.html
- 'Maximize[$f$, $x$]'
-
- compute the maximum of $f$ respect $x$ that change between $a$ and $b$
+
- compute the maximum of $f$ respect $x$ that change between \
+ $a$ and $b$.
>> Maximize[-2 x^2 - 3 x + 5, x]
@@ -48,7 +57,7 @@ class Maximize(Builtin):
attributes = A_PROTECTED | A_READ_PROTECTED
summary_text = "compute the maximum of a function"
- def apply(self, f, vars, evaluation):
+ def eval(self, f, vars, evaluation: Evaluation):
"Maximize[f_?NotListQ, vars_]"
dual_f = f.to_sympy() * (-1)
@@ -66,7 +75,7 @@ def apply(self, f, vars, evaluation):
return from_python(solutions)
- def apply_constraints(self, f, vars, evaluation):
+ def eval_constraints(self, f, vars, evaluation: Evaluation):
"Maximize[f_List, vars_]"
constraints = [function for function in f.elements]
@@ -86,11 +95,14 @@ def apply_constraints(self, f, vars, evaluation):
class Minimize(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/Minimize.html
+
+ :WMA link:
+ https://reference.wolfram.com/language/ref/Minimize.html
- 'Minimize[$f$, $x$]'
-
- compute the minimum of $f$ respect $x$ that change between $a$ and $b$
+
- compute the minimum of $f$ respect $x$ that change between \
+ $a$ and $b$.
>> Minimize[2 x^2 - 3 x + 5, x]
@@ -106,7 +118,7 @@ class Minimize(Builtin):
attributes = A_PROTECTED | A_READ_PROTECTED
summary_text = "compute the minimum of a function"
- def apply_onevariable(self, f, x, evaluation):
+ def eval_onevariable(self, f, x, evaluation: Evaluation):
"Minimize[f_?NotListQ, x_?NotListQ]"
sympy_x = x.to_sympy()
@@ -137,7 +149,7 @@ def apply_onevariable(self, f, x, evaluation):
)
)
- def apply_multiplevariable(self, f, vars, evaluation):
+ def eval_multiplevariable(self, f, vars, evaluation: Evaluation):
"Minimize[f_?NotListQ, vars_List]"
head_name = vars.get_head_name()
@@ -215,7 +227,7 @@ def apply_multiplevariable(self, f, vars, evaluation):
)
)
- def apply_constraints(self, f, vars, evaluation):
+ def eval_constraints(self, f, vars, evaluation: Evaluation):
"Minimize[f_List, vars_List]"
head_name = vars.get_head_name()
vars_or = vars
diff --git a/mathics/builtin/recurrence.py b/mathics/builtin/recurrence.py
index f93afec1b..0e62ef3f6 100644
--- a/mathics/builtin/recurrence.py
+++ b/mathics/builtin/recurrence.py
@@ -5,7 +5,8 @@
"""
# This tells documentation how to sort this module
-# Here we are also hiding "moments" since this erroneously appears at the top level.
+# Here we are also hiding "moments" since this erroneously appears at the
+# top level.
sort_order = "mathics.builtin.solving-recurrence-equations"
@@ -15,6 +16,7 @@
from mathics.core.atoms import IntegerM1
from mathics.core.attributes import A_CONSTANT
from mathics.core.convert.sympy import from_sympy, sympy_symbol_prefix
+from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.symbols import Atom, Symbol, SymbolPlus, SymbolTimes
@@ -23,7 +25,9 @@
class RSolve(Builtin):
"""
- :WMA link:https://reference.wolfram.com/language/ref/RSolve.html
+
+ :WMA link:
+ https://reference.wolfram.com/language/ref/RSolve.html
- 'RSolve[$eqn$, $a$[$n$], $n$]'
@@ -63,7 +67,7 @@ class RSolve(Builtin):
}
summary_text = "recurrence equations solver"
- def eval(self, eqns, a, n, evaluation):
+ def eval(self, eqns, a, n, evaluation: Evaluation):
"RSolve[eqns_, a_, n_]"
# TODO: Do this with rules?
diff --git a/mathics/core/rules.py b/mathics/core/rules.py
index 47e33a349..9fac71636 100644
--- a/mathics/core/rules.py
+++ b/mathics/core/rules.py
@@ -26,12 +26,15 @@ class BaseRule(KeyComparable):
"""
This is the base class from which all other Rules are derived from.
- Rules are part of the rewriting system of Mathics. See https://en.wikipedia.org/wiki/Rewriting
+ Rules are part of the rewriting system of Mathics. See
+ https://en.wikipedia.org/wiki/Rewriting
- This class is not complete in of itself and subclasses should adapt or fill in
- what is needed. In particular ``do_replace()`` needs to be implemented.
+ This class is not complete in of itself and subclasses should
+ adapt or fill in what is needed. In particular ``do_replace()``
+ needs to be implemented.
Important subclasses: BuiltinRule and Rule.
+
"""
def __init__(self, pattern, system=False) -> None: