Skip to content
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
9 changes: 9 additions & 0 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ def eval_wrong_domain(
evaluation.message("Element", "bset", domain)
return None

def eval_algebraic(self, elem: BaseElement, evaluation: Evaluation):
"""Element[elem_, Algebraics]"""
if elem.to_sympy().is_algebraic:
return SymbolTrue
return SymbolFalse

def eval_Element_alternatives(
self, elems: BaseElement, domain: BaseElement, evaluation: Evaluation
) -> Expression | None | Symbol:
Expand Down Expand Up @@ -574,6 +580,9 @@ def to_sympy(self, expr, **kwargs):
sympy_domain = sympy.Rationals
case domain if domain is SymbolReals:
sympy_domain = sympy.Reals
# Not implemented in sympy...
# case domain if domain is SymbolAlgebraics:
# sympy_domain = sympy.S.Algebraics
case _:
raise RuntimeError("Unknown domain {domain}")
return sympy.Contains(arg.to_sympy(), sympy_domain)
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/assignments/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ class SubValues(Builtin):
>> f[1][x_] := x
>> f[2][x_] := x ^ 2
>> SubValues[f]
= {HoldPattern[f[2][x_]] ⧴ x ^ 2, HoldPattern[f[1][x_]] ⧴ x}
= {HoldPattern[f[1][x_]] ⧴ x, HoldPattern[f[2][x_]] ⧴ x ^ 2}
>> Definition[f]
= f[2][x_] = x^2
= f[1][x_] = x
.
. f[1][x_] = x
. f[2][x_] = x^2
"""

attributes = A_HOLD_ALL | A_PROTECTED
Expand Down
4 changes: 3 additions & 1 deletion mathics/builtin/import_export/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ def import_setup(self, source, evaluation) -> tuple:

def eval(self, source, evaluation, options={}):
"Import[source_, OptionsPattern[]]"
return self.eval_element_list(source, ListExpression(), evaluation, options)
return self.eval_with_element_list(
source, ListExpression(), evaluation, options
)

def eval_elements_query(self, source, evaluation, options={}):
"""Import[source_String, "Elements", OptionsPattern[]]"""
Expand Down
1 change: 1 addition & 0 deletions mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
SymbolList,
SymbolLog,
SymbolNIntegrate,
SymbolRoot,
SymbolRule,
SymbolSequence,
SymbolSeries,
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/testing_expressions/equality_inequality.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ class SameQ(_ComparisonOperator):

summary_text = "literal symbolic identity"

def eval_list(self, elements, evaluation: Evaluation):
def eval(self, elements, evaluation: Evaluation):
"%(name)s[elements___]"
elements_sequence = elements.get_sequence()
if len(elements_sequence) <= 1:
Expand Down Expand Up @@ -972,7 +972,7 @@ class UnsameQ(_ComparisonOperator):

summary_text = "not literal symbolic identity"

def eval_list(self, elements, evaluation: Evaluation):
def eval(self, elements, evaluation: Evaluation):
"%(name)s[elements___]"
elements_sequence = elements.get_sequence()
if len(elements_sequence) <= 1:
Expand Down
2 changes: 2 additions & 0 deletions mathics/core/keycomparable.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def __ne__(self, other) -> bool:

# The numeric magic code for an expression
BASIC_EXPRESSION_PATTERN_SORT_KEY = MAGIC_ATOM_SORT_KEY + PATTERN_SORT_KEY_IS_EXPRESSION
# TODO: Mark that it is an expression but literal.
BASIC_LITERAL_EXPRESSION_PATTERN_SORT_KEY = MAGIC_ATOM_SORT_KEY

# Blanks
BLANK_WITH_PATTERN_PATTERN_SORT_KEY = (
Expand Down
3 changes: 3 additions & 0 deletions mathics/core/pattern/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from mathics.core.keycomparable import (
BASIC_ATOM_PATTERN_SORT_KEY,
BASIC_EXPRESSION_PATTERN_SORT_KEY,
BASIC_LITERAL_EXPRESSION_PATTERN_SORT_KEY,
END_OF_LIST_PATTERN_SORT_KEY,
)
from mathics.core.symbols import Atom, Symbol
Expand Down Expand Up @@ -478,6 +479,8 @@ def __init__(
]

def _build_pattern_sort_key(self) -> tuple:
if self.isliteral:
return (BASIC_LITERAL_EXPRESSION_PATTERN_SORT_KEY, self.expr.element_order)
return (
BASIC_EXPRESSION_PATTERN_SORT_KEY,
self.head.pattern_precedence,
Expand Down
4 changes: 4 additions & 0 deletions mathics/core/pattern/orderless.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ def __init__(
super().__init__(expression, attributes, evaluation)
self.attributes = attributes
self.sort()
if not (A_ONE_IDENTITY + A_FLAT) & attributes:
self.isliteral = self.head.isliteral and all(
element.isliteral for element in self.elements
)

def _yield_sequence_wrappings(self, items: Tuple, yield_func: Callable):
"""Orderless case: one Sequence[...] wrapping per permutation."""
Expand Down
Loading