diff --git a/mathics/builtin/inference.py b/mathics/builtin/inference.py index 84eddd41c..c2b34ec89 100644 --- a/mathics/builtin/inference.py +++ b/mathics/builtin/inference.py @@ -13,7 +13,7 @@ from mathics.core.parser import parse_builtin_rule from mathics.core.symbols import Symbol -from mathics.core.systemsymbols import SymbolAnd, SymbolNot, SymbolOr +from mathics.core.systemsymbols import SymbolAnd, SymbolEqual, SymbolNot, SymbolOr # TODO: Extend these rules? @@ -331,7 +331,7 @@ def get_assumption_rules_dispatch(evaluation): SymbolFalse, ) ) - for head in ("Equal", "Equivalent"): + for head in (SymbolEqual, Symbol("Equivalent")): assumption_rules.append( Rule( Expression(head, pat.elements[0], pat.elements[1]), diff --git a/mathics/builtin/list/associations.py b/mathics/builtin/list/associations.py index 33ce8b63a..1f7beb682 100644 --- a/mathics/builtin/list/associations.py +++ b/mathics/builtin/list/associations.py @@ -12,20 +12,18 @@ Test, ) from mathics.builtin.box.inout import RowBox - from mathics.builtin.lists import list_boxes - -from mathics.core.expression import Expression from mathics.core.atoms import Integer -from mathics.core.list import ListExpression, to_mathics_list +from mathics.core.attributes import hold_all_complete, protected +from mathics.core.expression import Expression +from mathics.core.list import to_mathics_list from mathics.core.symbols import Symbol, SymbolTrue from mathics.core.systemsymbols import ( SymbolAssociation, SymbolMakeBoxes, + SymbolMissing, ) -from mathics.core.attributes import hold_all_complete, protected - class Association(Builtin): """ @@ -157,7 +155,7 @@ def find_key(exprs, rules_dictionary: dict = {}): return ( result[key] if result - else Expression("Missing", Symbol("KeyAbsent"), key) + else Expression(SymbolMissing, Symbol("KeyAbsent"), key) ) except TypeError: return None @@ -273,7 +271,7 @@ def get_keys(expr): expr.has_form("Association", None) and AssociationQ(expr).evaluate(evaluation) is SymbolTrue ): - return ListExpression(*[get_keys(element) for element in expr.elements]) + return to_mathics_list(*expr.elements, elements_conversion_fn=get_keys) else: evaluation.message("Keys", "invrl", expr) raise TypeError diff --git a/mathics/builtin/list/constructing.py b/mathics/builtin/list/constructing.py index 274f6955e..ff3cd60f4 100644 --- a/mathics/builtin/list/constructing.py +++ b/mathics/builtin/list/constructing.py @@ -10,26 +10,23 @@ from mathics.builtin.base import Builtin, Pattern - -from mathics.core.element import ElementsProperties - from mathics.builtin.lists import ( _IterationFunction, get_tuples, ) - +from mathics.core.atoms import Integer, Symbol +from mathics.core.attributes import hold_first, listable, protected from mathics.core.convert import from_sympy - +from mathics.core.element import ElementsProperties from mathics.core.expression import ( Expression, to_expression, structure, ) -from mathics.core.atoms import Integer from mathics.core.list import ListExpression from mathics.core.symbols import Atom -from mathics.core.attributes import hold_first, listable, protected +SymbolNormal = Symbol("Normal") class Array(Builtin): @@ -155,7 +152,7 @@ def apply_general(self, expr, evaluation): return return Expression( expr.get_head(), - *[Expression("Normal", element) for element in expr.elements], + *[Expression(SymbolNormal, element) for element in expr.elements], ) @@ -447,9 +444,9 @@ class Table(_IterationFunction): summary_text = "make a table of values of an expression" - def get_result(self, items): + def get_result(self, elements) -> ListExpression: return ListExpression( - *items, + *elements, elements_properties=ElementsProperties(elements_fully_evaluated=True), ) diff --git a/mathics/builtin/list/eol.py b/mathics/builtin/list/eol.py index dbcf4be1e..20b405d62 100644 --- a/mathics/builtin/list/eol.py +++ b/mathics/builtin/list/eol.py @@ -31,27 +31,35 @@ from mathics.builtin.base import MessageException from mathics.builtin.box.inout import RowBox -from mathics.core.expression import Expression from mathics.core.atoms import Integer, Integer0, Integer1 +from mathics.core.attributes import ( + hold_first, + hold_rest, + n_hold_rest, + protected, + read_protected, +) +from mathics.core.expression import Expression from mathics.core.list import ListExpression, to_mathics_list +from mathics.core.rules import Rule from mathics.core.symbols import Atom, Symbol, SymbolNull, SymbolTrue from mathics.core.systemsymbols import ( SymbolAppend, + SymbolByteArray, SymbolFailed, + SymbolInfinity, SymbolMakeBoxes, + SymbolMissing, SymbolSequence, SymbolSet, ) -from mathics.core.rules import Rule - -from mathics.core.attributes import ( - hold_first, - hold_rest, - n_hold_rest, - protected, - read_protected, -) +SymbolAppendTo = Symbol("AppendTo") +SymbolDeleteCases = Symbol("DeleteCases") +SymbolDrop = Symbol("Drop") +SymbolPrepend = Symbol("Prepend") +SymbolPrependTo = Symbol("PrependTo") +SymbolTake = Symbol("Take") class Append(Builtin): @@ -96,8 +104,8 @@ def apply(self, expr, item, evaluation): class AppendTo(Builtin): """
-
'AppendTo[$s$, $item$]' -
append $item$ to value of $s$ and sets $s$ to the result. +
'AppendTo[$s$, $elem$]' +
append $elem$ to value of $s$ and sets $s$ to the result.
>> s = {}; @@ -129,19 +137,21 @@ class AppendTo(Builtin): "rvalue": "`1` is not a variable with a value, so its value cannot be changed.", } - def apply(self, s, item, evaluation): - "AppendTo[s_, item_]" + def apply(self, s, element, evaluation): + "AppendTo[s_, element_]" resolved_s = s.evaluate(evaluation) if s == resolved_s: return evaluation.message("AppendTo", "rvalue", s) if not isinstance(resolved_s, Atom): result = Expression( - SymbolSet, s, Expression(SymbolAppend, resolved_s, item) + SymbolSet, s, Expression(SymbolAppend, resolved_s, element) ) return result.evaluate(evaluation) - return evaluation.message("AppendTo", "normal", Expression("AppendTo", s, item)) + return evaluation.message( + "AppendTo", "normal", Expression(SymbolAppendTo, s, element) + ) class Cases(Builtin): @@ -317,7 +327,7 @@ def apply_ls_n(self, items, pattern, levelspec, n, evaluation): levelspec = python_levelspec(levelspec) - if n is Symbol("Infinity"): + if n is SymbolInfinity: n = -1 elif n.get_head_name() == "System`Integer": n = n.get_int_value() @@ -325,13 +335,13 @@ def apply_ls_n(self, items, pattern, levelspec, n, evaluation): evaluation.message( "DeleteCases", "innf", - Expression("DeleteCases", items, pattern, levelspec, n), + Expression(SymbolDeleteCases, items, pattern, levelspec, n), ) else: evaluation.message( "DeleteCases", "innf", - Expression("DeleteCases", items, pattern, levelspec, n), + Expression(SymbolDeleteCases, items, pattern, levelspec, n), ) return SymbolNull @@ -401,11 +411,11 @@ class Drop(Builtin): = Drop[{1, 2, 3, 4, 5, 6}, {-5, -2, -2}] """ - summary_text = "remove a number of elements from a list" messages = { "normal": "Nonatomic expression expected at position `1` in `2`.", "drop": "Cannot drop positions `1` through `2` in `3`.", } + summary_text = "remove a number of elements from a list" def apply(self, items, seqs, evaluation): "Drop[items_, seqs___]" @@ -414,7 +424,7 @@ def apply(self, items, seqs, evaluation): if isinstance(items, Atom): return evaluation.message( - "Drop", "normal", 1, Expression("Drop", items, *seqs) + "Drop", "normal", 1, Expression(SymbolDrop, items, *seqs) ) try: @@ -633,7 +643,7 @@ def check_pattern(input_list, pat, result, beginLevel): if is_found: return to_mathics_list(*result) else: - return Expression("Missing", "NotFound") if default is None else default + return Expression(SymbolMissing, "NotFound") if default is None else default def apply_default(self, expr, pattern, default, evaluation): "FirstPosition[expr_, pattern_, default_]" @@ -957,7 +967,7 @@ def apply(self, list, i, evaluation): if idx.get_head_name() == "System`Integer": idx = idx.get_int_value() if idx == 0: - return Symbol("System`ByteArray") + return SymbolByteArray data = list.elements[0].value lendata = len(data) if idx < 0: @@ -1130,11 +1140,13 @@ def apply(self, s, item, evaluation): return evaluation.message("PrependTo", "rvalue", s) if not isinstance(resolved_s, Atom): - result = Expression("Set", s, Expression("Prepend", resolved_s, item)) + result = Expression( + SymbolSet, s, Expression(SymbolPrepend, resolved_s, item) + ) return result.evaluate(evaluation) return evaluation.message( - "PrependTo", "normal", Expression("PrependTo", s, item) + "PrependTo", "normal", Expression(SymbolPrependTo, s, item) ) @@ -1302,8 +1314,8 @@ def apply(self, items, expr, evaluation): evaluation.message("Select", "normal") return - def cond(leaf): - test = Expression(expr, leaf) + def cond(element): + test = Expression(expr, element) return test.evaluate(evaluation) is SymbolTrue return items.filter(items.head, cond, evaluation) @@ -1421,7 +1433,7 @@ def apply(self, items, seqs, evaluation): if isinstance(items, Atom): return evaluation.message( - "Take", "normal", 1, Expression("Take", items, *seqs) + "Take", "normal", 1, Expression(SymbolTake, items, *seqs) ) try: diff --git a/mathics/builtin/numbers/algebra.py b/mathics/builtin/numbers/algebra.py index 4ce9758bb..6f2a8f0a5 100644 --- a/mathics/builtin/numbers/algebra.py +++ b/mathics/builtin/numbers/algebra.py @@ -1596,7 +1596,9 @@ def apply_with_assumptions(self, expr, assum, evaluation, options={}): SymbolList ) # Now, reevaluate the expression with all the assumptions. - simplify_expr = Expression(self.get_name(), expr, *options_to_rules(options)) + simplify_expr = Expression( + Symbol(self.get_name()), expr, *options_to_rules(options) + ) return dynamic_scoping( lambda ev: simplify_expr.evaluate(ev), {"System`$Assumptions": assumptions}, diff --git a/mathics/builtin/numbers/diffeqns.py b/mathics/builtin/numbers/diffeqns.py index 2085a92c1..806212b5c 100644 --- a/mathics/builtin/numbers/diffeqns.py +++ b/mathics/builtin/numbers/diffeqns.py @@ -6,10 +6,11 @@ import sympy from mathics.builtin.base import Builtin -from mathics.core.expression import Expression from mathics.core.convert import from_sympy +from mathics.core.expression import Expression +from mathics.core.list import ListExpression from mathics.core.symbols import Atom, Symbol -from mathics.core.systemsymbols import SymbolFunction +from mathics.core.systemsymbols import SymbolFunction, SymbolRule class DSolve(Builtin): @@ -134,7 +135,7 @@ def apply(self, eqn, y, x, evaluation): func = y except AttributeError: func = Expression(y, *syms) - function_form = Expression("List", *syms) + function_form = ListExpression(*syms) if isinstance(func, Atom): evaluation.message("DSolve", "dsfun", y) @@ -180,21 +181,18 @@ def apply(self, eqn, y, x, evaluation): sym_result = [sym_result] if function_form is None: - return Expression( - "List", + return ListExpression( *[ - Expression("List", Expression("Rule", *from_sympy(soln).leaves)) + ListExpression(Expression(SymbolRule, *from_sympy(soln).elements)) for soln in sym_result ] ) else: - return Expression( - "List", + return ListExpression( *[ - Expression( - "List", + ListExpression( Expression( - "Rule", + SymbolRule, y, Expression( SymbolFunction, @@ -214,9 +212,8 @@ def apply(self, eqn, y, x, evaluation): class C(Builtin): """
-
'C'[$n$] -
represents the $n$th constant in a solution to a - differential equation. +
'C'[$n$] +
represents the $n$th constant in a solution to a differential equation.
""" diff --git a/mathics/builtin/numbers/exptrig.py b/mathics/builtin/numbers/exptrig.py index edf4bdfe5..0cdf51455 100644 --- a/mathics/builtin/numbers/exptrig.py +++ b/mathics/builtin/numbers/exptrig.py @@ -15,20 +15,28 @@ from contextlib import contextmanager from itertools import chain +from mathics.builtin.arithmetic import _MPMathFunction from mathics.builtin.base import Builtin -from mathics.core.expression import Expression from mathics.core.atoms import ( - Real, Integer, Integer0, + IntegerM1, + Real, from_python, ) -from mathics.core.symbols import Symbol -from mathics.core.systemsymbols import SymbolCos, SymbolSin - -from mathics.builtin.arithmetic import _MPMathFunction - from mathics.core.attributes import listable, numeric_function, protected +from mathics.core.expression import Expression +from mathics.core.list import ListExpression +from mathics.core.symbols import Symbol, SymbolPower +from mathics.core.systemsymbols import SymbolCos, SymbolE, SymbolSin + +SymbolArcCos = Symbol("ArcCos") +SymbolArcCosh = Symbol("ArcCosh") +SymbolArcSin = Symbol("ArcSin") +SymbolArcSinh = Symbol("ArcSinh") +SymbolArcTan = Symbol("ArcTan") +SymbolCosh = Symbol("Cosh") +SymbolSinh = Symbol("Sinh") class Fold(object): @@ -205,14 +213,14 @@ class AnglePath(Builtin): @staticmethod def _compute(x0, y0, phi0, steps, evaluation): if not steps: - return Expression("List") + return ListExpression() if steps[0].get_head_name() == "System`List": def parse(step): if step.get_head_name() != "System`List": raise _IllegalStepSpecification - arguments = step.leaves + arguments = step.elements if len(arguments) != 2: raise _IllegalStepSpecification return arguments @@ -226,12 +234,12 @@ def parse(step): try: fold = AnglePathFold(parse) - leaves = [ - Expression("List", x, y) for x, y, _ in fold.fold((x0, y0, phi0), steps) + elements = [ + ListExpression(x, y) for x, y, _ in fold.fold((x0, y0, phi0), steps) ] - return Expression("List", *leaves) + return ListExpression(*elements) except _IllegalStepSpecification: - evaluation.message("AnglePath", "steps", Expression("List", *steps)) + evaluation.message("AnglePath", "steps", ListExpression(*steps)) def apply(self, steps, evaluation): "AnglePath[{steps___}]" @@ -255,7 +263,7 @@ def apply_xy_phi0(self, x, y, phi0, steps, evaluation): def apply_xy_dx(self, x, y, dx, dy, steps, evaluation): "AnglePath[{{x_, y_}, {dx_, dy_}}, {steps___}]" - phi0 = Expression("ArcTan", dx, dy) + phi0 = Expression(SymbolArcTan, dx, dy) return AnglePath._compute(x, y, phi0, steps.get_sequence(), evaluation) @@ -482,17 +490,17 @@ class ArcCsc(_MPMathFunction): } def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "ArcSin", Expression("Power", expr.leaves[0], Integer(-1)) + SymbolArcSin, Expression(SymbolPower, expr.elements[0], Integer(-1)) ).to_sympy() class ArcCsch(_MPMathFunction): """
-
'ArcCsch[$z$]' -
returns the inverse hyperbolic cosecant of $z$. +
'ArcCsch[$z$]' +
returns the inverse hyperbolic cosecant of $z$.
>> ArcCsch[0] @@ -501,8 +509,6 @@ class ArcCsch(_MPMathFunction): = 0.881374 """ - summary_text = "inverse hyperbolic cosecant function" - sympy_name = "" mpmath_name = "acsch" rules = { @@ -511,18 +517,21 @@ class ArcCsch(_MPMathFunction): "Derivative[1][ArcCsch]": "-1 / (Sqrt[1+1/#^2] * #^2) &", } + summary_text = "inverse hyperbolic cosecant function" + sympy_name = "" + def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "ArcSinh", Expression("Power", expr.leaves[0], Integer(-1)) + SymbolArcSinh, Expression(SymbolPower, expr.elements[0], IntegerM1) ).to_sympy() class ArcSec(_MPMathFunction): """
-
'ArcSec[$z$]' -
returns the inverse secant of $z$. +
'ArcSec[$z$]' +
returns the inverse secant of $z$.
>> ArcSec[1] @@ -531,8 +540,6 @@ class ArcSec(_MPMathFunction): = Pi """ - summary_text = "inverse secant function" - sympy_name = "" mpmath_name = "asec" rules = { @@ -541,18 +548,21 @@ class ArcSec(_MPMathFunction): "ArcSec[1]": "0", } + summary_text = "inverse secant function" + sympy_name = "" + def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "ArcCos", Expression("Power", expr.leaves[0], Integer(-1)) + SymbolArcCos, Expression(SymbolPower, expr.elements[0], IntegerM1) ).to_sympy() class ArcSech(_MPMathFunction): """
-
'ArcSech[$z$]' -
returns the inverse hyperbolic secant of $z$. +
'ArcSech[$z$]' +
returns the inverse hyperbolic secant of $z$.
>> ArcSech[0] @@ -563,8 +573,6 @@ class ArcSech(_MPMathFunction): = 1.31696 """ - summary_text = "inverse hyperbolic secant function" - sympy_name = "" mpmath_name = "asech" rules = { @@ -573,10 +581,13 @@ class ArcSech(_MPMathFunction): "Derivative[1][ArcSech]": "-1 / (# * Sqrt[(1-#)/(1+#)] (1+#)) &", } + summary_text = "inverse hyperbolic secant function" + sympy_name = "" + def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "ArcCosh", Expression("Power", expr.leaves[0], Integer(-1)) + SymbolArcCosh, Expression(SymbolPower, expr.elements[0], IntegerM1) ).to_sympy() @@ -593,8 +604,6 @@ class ArcSin(_MPMathFunction): = Pi / 2 """ - summary_text = "inverse sine function" - sympy_name = "asin" mpmath_name = "asin" rules = { @@ -603,12 +612,15 @@ class ArcSin(_MPMathFunction): "ArcSin[1]": "Pi / 2", } + summary_text = "inverse sine function" + sympy_name = "asin" + class ArcSinh(_MPMathFunction): """
-
'ArcSinh[$z$]' -
returns the inverse hyperbolic sine of $z$. +
'ArcSinh[$z$]' +
returns the inverse hyperbolic sine of $z$.
>> ArcSinh[0] @@ -661,8 +673,6 @@ class ArcTan(_MPMathFunction): = -Pi / 2 """ - summary_text = "inverse tangent function" - sympy_name = "atan" mpmath_name = "atan" rules = { @@ -673,6 +683,9 @@ class ArcTan(_MPMathFunction): ArcTan[y/x], If[y >= 0, ArcTan[y/x] + Pi, ArcTan[y/x] - Pi]]]""", } + summary_text = "inverse tangent function" + sympy_name = "atan" + class ArcTanh(_MPMathFunction): """ @@ -693,8 +706,6 @@ class ArcTanh(_MPMathFunction): = ArcTanh[2 + I] """ - summary_text = "inverse hyperbolic tangent function" - sympy_name = "atanh" mpmath_name = "atanh" numpy_name = "arctanh" @@ -702,6 +713,9 @@ class ArcTanh(_MPMathFunction): "Derivative[1][ArcTanh]": "1/(1-#^2)&", } + summary_text = "inverse hyperbolic tangent function" + sympy_name = "atanh" + class Cos(_MPMathFunction): """ @@ -717,7 +731,6 @@ class Cos(_MPMathFunction): = -1.83697×10^-16 """ - summary_text = "cosine function" mpmath_name = "cos" rules = { @@ -728,31 +741,34 @@ class Cos(_MPMathFunction): "Derivative[1][Cos]": "-Sin[#]&", } + summary_text = "cosine function" + class Cosh(_MPMathFunction): """
-
'Cosh[$z$]' -
returns the hyperbolic cosine of $z$. +
'Cosh[$z$]' +
returns the hyperbolic cosine of $z$.
>> Cosh[0] = 1 """ - summary_text = "hyperbolic cosine function" mpmath_name = "cosh" rules = { "Derivative[1][Cosh]": "Sinh[#]&", } + summary_text = "hyperbolic cosine function" + class Cot(_MPMathFunction): """
-
'Cot[$z$]' -
returns the cotangent of $z$. +
'Cot[$z$]' +
returns the cotangent of $z$.
>> Cot[0] @@ -761,7 +777,6 @@ class Cot(_MPMathFunction): = 0.642093 """ - summary_text = "cotangent function" mpmath_name = "cot" rules = { @@ -769,19 +784,20 @@ class Cot(_MPMathFunction): "Cot[0]": "ComplexInfinity", } + summary_text = "cotangent function" + class Coth(_MPMathFunction): """
-
'Coth[$z$]' -
returns the hyperbolic cotangent of $z$. +
'Coth[$z$]' +
returns the hyperbolic cotangent of $z$.
>> Coth[0] = ComplexInfinity """ - summary_text = "hyperbolic cotangent function" mpmath_name = "coth" rules = { @@ -790,12 +806,14 @@ class Coth(_MPMathFunction): "Derivative[1][Coth]": "-Csch[#1]^2&", } + summary_text = "hyperbolic cotangent function" + class Csc(_MPMathFunction): """
-
'Csc[$z$]' -
returns the cosecant of $z$. +
'Csc[$z$]' +
returns the cosecant of $z$.
>> Csc[0] @@ -806,7 +824,6 @@ class Csc(_MPMathFunction): = 1.1884 """ - summary_text = "cosecant function" mpmath_name = "csc" rules = { @@ -814,10 +831,12 @@ class Csc(_MPMathFunction): "Csc[0]": "ComplexInfinity", } + summary_text = "cosecant function" + def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "Power", Expression(SymbolSin, expr.leaves[0]), Integer(-1) + SymbolPower, Expression(SymbolSin, expr.elements[0]), Integer(-1) ).to_sympy() @@ -832,8 +851,6 @@ class Csch(_MPMathFunction): = ComplexInfinity """ - summary_text = "hyperbolic cosecant function" - sympy_name = "" mpmath_name = "csch" rules = { @@ -842,18 +859,21 @@ class Csch(_MPMathFunction): "Derivative[1][Csch]": "-Coth[#1] Csch[#1]&", } + summary_text = "hyperbolic cosecant function" + sympy_name = "" + def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "Power", Expression("Sinh", expr.leaves[0]), Integer(-1) + SymbolPower, Expression(SymbolSinh, expr.elements[0]), IntegerM1 ).to_sympy() class Exp(_MPMathFunction): """
-
'Exp[$z$]' -
returns the exponential function of $z$. +
'Exp[$z$]' +
returns the exponential function of $z$.
>> Exp[1] @@ -870,14 +890,14 @@ class Exp(_MPMathFunction): = Overflow[] """ - summary_text = "exponential function" rules = { "Exp[x_]": "E ^ x", "Derivative[1][Exp]": "Exp", } + summary_text = "exponential function" - def from_sympy(self, sympy_name, leaves): - return Expression("Power", Symbol("E"), leaves[0]) + def from_sympy(self, sympy_name, elements): + return Expression(SymbolPower, SymbolE, elements[0]) class Haversine(_MPMathFunction): @@ -966,10 +986,10 @@ class Log(_MPMathFunction): "Log[x_?InexactNumberQ]": "Log[E, x]", } - def prepare_sympy(self, leaves): - if len(leaves) == 2: - leaves = [leaves[1], leaves[0]] - return leaves + def prepare_sympy(self, elements): + if len(elements) == 2: + elements = [elements[1], elements[0]] + return elements def get_mpmath_function(self, args): return lambda base, x: mpmath.log(x, base) @@ -1071,43 +1091,43 @@ class Sec(_MPMathFunction): } def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "Power", Expression(SymbolCos, expr.leaves[0]), Integer(-1) + SymbolPower, Expression(SymbolCos, expr.elements[0]), Integer(-1) ).to_sympy() class Sech(_MPMathFunction): """
-
'Sech[$z$]' -
returns the hyperbolic secant of $z$. +
'Sech[$z$]' +
returns the hyperbolic secant of $z$.
>> Sech[0] = 1 """ - summary_text = "hyperbolic secant function" - sympy_name = "" mpmath_name = "sech" rules = { "Derivative[1][Sech]": "-Sech[#1] Tanh[#1]&", } + summary_text = "hyperbolic secant function" + sympy_name = "" def to_sympy(self, expr, **kwargs): - if len(expr.leaves) == 1: + if len(expr.elements) == 1: return Expression( - "Power", Expression("Cosh", expr.leaves[0]), Integer(-1) + SymbolPower, Expression(SymbolCosh, expr.elements[0]), IntegerM1 ).to_sympy() class Sin(_MPMathFunction): """
-
'Sin[$z$]' -
returns the sine of $z$. +
'Sin[$z$]' +
returns the sine of $z$.
>> Sin[0] @@ -1141,8 +1161,8 @@ class Sin(_MPMathFunction): class Sinh(_MPMathFunction): """
-
'Sinh[$z$]' -
returns the hyperbolic sine of $z$. +
'Sinh[$z$]' +
returns the hyperbolic sine of $z$.
>> Sinh[0] @@ -1160,8 +1180,8 @@ class Sinh(_MPMathFunction): class Tan(_MPMathFunction): """
-
'Tan[$z$]' -
returns the tangent of $z$. +
'Tan[$z$]' +
returns the tangent of $z$.
>> Tan[0] @@ -1186,8 +1206,8 @@ class Tan(_MPMathFunction): class Tanh(_MPMathFunction): """
-
'Tanh[$z$]' -
returns the hyperbolic tangent of $z$. +
'Tanh[$z$]' +
returns the hyperbolic tangent of $z$.
>> Tanh[0] diff --git a/mathics/core/systemsymbols.py b/mathics/core/systemsymbols.py index 6f3547be7..9d68adfe3 100644 --- a/mathics/core/systemsymbols.py +++ b/mathics/core/systemsymbols.py @@ -79,6 +79,7 @@ SymbolMean = Symbol("Mean") SymbolMessageName = Symbol("MessageName") SymbolMinus = Symbol("Minus") +SymbolMissing = Symbol("Missing") SymbolMap = Symbol("Map") SymbolMatchQ = Symbol("MatchQ") SymbolMatrixPower = Symbol("MatrixPower")