Skip to content

Commit

Permalink
Merge branch 'master' into lint-portion-ListPlot-point-checking
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky authored Dec 29, 2024
2 parents 84ddcb2 + 2aecdb3 commit abd025b
Show file tree
Hide file tree
Showing 46 changed files with 1,868 additions and 1,085 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ jobs:
git submodule update
remake -x develop
cd mathics/packages/Combinatorica-repo
# If Combinatorica repo changes, we may need the below altered
# with a branch name, (not HEAD) for testing.
# git pull origin HEAD
pip install -e .[dev]
remake -x check
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ repos:
hooks:
- id: check-merge-conflict
- id: debug-statements
stages: [commit]
stages: [pre-commit]
- id: end-of-file-fixer
stages: [commit]
stages: [pre-commit]
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
stages: [commit]
stages: [pre-commit]
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
language_version: python3
stages: [commit]
stages: [pre-commit]
2 changes: 1 addition & 1 deletion mathics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

version_info[package] = package_version

version_string = """Mathics {mathics}
version_string = """Mathics3 {mathics}
on {python}
using SymPy {sympy}, mpmath {mpmath}, numpy {numpy}""".format(
**version_info
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/arithfns/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
SymbolPattern,
SymbolSequence,
)
from mathics.eval.arithmetic import eval_Plus, eval_Times
from mathics.eval.arithfns.basic import eval_Plus, eval_Times
from mathics.eval.nevaluator import eval_N
from mathics.eval.numerify import numerify

Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
SymbolTable,
SymbolUndefined,
)
from mathics.eval.arithmetic import eval_Sign
from mathics.eval.inference import get_assumptions_list
from mathics.eval.nevaluator import eval_N
from mathics.eval.numeric import eval_Sign

# This tells documentation how to sort this module
sort_order = "mathics.builtin.mathematical-functions"
Expand Down
78 changes: 4 additions & 74 deletions mathics/builtin/atomic/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@

from mathics.core.atoms import Integer, Integer0, Integer1, String
from mathics.core.attributes import A_LISTABLE, A_PROTECTED
from mathics.core.builtin import Builtin, Predefined, PrefixOperator, Test
from mathics.core.builtin import Builtin, Predefined, PrefixOperator
from mathics.core.convert.expression import to_mathics_list
from mathics.core.convert.python import from_bool
from mathics.core.convert.regex import to_regex
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.parser import MathicsFileLineFeeder, parse
from mathics.core.symbols import Symbol, SymbolTrue
from mathics.core.systemsymbols import (
SymbolFailed,
SymbolInputForm,
SymbolNone,
SymbolOutputForm,
SymbolToExpression,
)
from mathics.eval.strings import eval_ToString
from mathics.eval.strings import eval_StringContainsQ, eval_ToString
from mathics.settings import SYSTEM_CHARACTER_ENCODING

SymbolToExpression = Symbol("ToExpression")

# covers all of the variations. Here we just give some minimal basics

# Data taken from:
Expand Down Expand Up @@ -130,48 +126,6 @@ def push(i, iter, form):
push(i, iter, form)


def _pattern_search(name, string, patt, evaluation, options, matched):
# Get the pattern list and check validity for each
if patt.has_form("List", None):
patts = patt.elements
else:
patts = [patt]
re_patts = []
for p in patts:
py_p = to_regex(p, show_message=evaluation.message)
if py_p is None:
evaluation.message("StringExpression", "invld", p, patt)
return
re_patts.append(py_p)

flags = re.MULTILINE
if options["System`IgnoreCase"] is SymbolTrue:
flags = flags | re.IGNORECASE

def _search(patts, str, flags, matched):
if any(re.search(p, str, flags=flags) for p in patts):
return from_bool(matched)
return from_bool(not matched)

# Check string validity and perform regex searchhing
if string.has_form("List", None):
py_s = [s.get_string_value() for s in string.elements]
if any(s is None for s in py_s):
evaluation.message(
name, "strse", Integer1, Expression(Symbol(name), string, patt)
)
return
return to_mathics_list(*[_search(re_patts, s, flags, matched) for s in py_s])
else:
py_s = string.get_string_value()
if py_s is None:
evaluation.message(
name, "strse", Integer1, Expression(Symbol(name), string, patt)
)
return
return _search(re_patts, py_s, flags, matched)


def anchor_pattern(patt):
"""
anchors a regex in order to force matching against an entire string.
Expand Down Expand Up @@ -691,35 +645,11 @@ class StringContainsQ(Builtin):

def eval(self, string, patt, evaluation: Evaluation, options: dict):
"StringContainsQ[string_, patt_, OptionsPattern[%(name)s]]"
return _pattern_search(
return eval_StringContainsQ(
self.__class__.__name__, string, patt, evaluation, options, True
)


class StringQ(Test):
"""
<url>
:WMA link:
https://reference.wolfram.com/language/ref/StringQ.html</url>
<dl>
<dt>'StringQ[$expr$]'
<dd>returns 'True' if $expr$ is a 'String', or 'False' otherwise.
</dl>
>> StringQ["abc"]
= True
>> StringQ[1.5]
= False
>> Select[{"12", 1, 3, 5, "yz", x, y}, StringQ]
= {12, yz}
"""

summary_text = "test whether an expression is a string"

def test(self, expr) -> bool:
return isinstance(expr, String)


class StringRepeat(Builtin):
"""
<url>
Expand Down
8 changes: 8 additions & 0 deletions mathics/builtin/drawing/drawing_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ class Mesh(Builtin):
specifies the mesh to be drawn. The default is 'Mesh->None'.
</dl>
Options include:
<ul>
<li>None: No mesh is drawn
<li>All: mesh divisions between elements
<li>Full: mesh divisions between regular datapoints
</ul>
>> Plot[Sin[Cos[x^2]],{x,-4,4},Mesh->All]
= -Graphics-
Expand Down
28 changes: 21 additions & 7 deletions mathics/builtin/functional/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@
Function Application
"""

# This tells documentation how to sort this module
sort_order = "mathics.builtin.function-application"


from itertools import chain

import sympy

from mathics.core.atoms import Integer, Integer1
from mathics.core.attributes import A_HOLD_ALL, A_N_HOLD_ALL, A_PROTECTED
from mathics.core.builtin import Builtin, PostfixOperator, SympyFunction
from mathics.core.builtin import Builtin, PostfixOperator, PrefixOperator, SympyFunction
from mathics.core.convert.sympy import SymbolFunction
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.symbols import Symbol, sympy_slot_prefix
from mathics.core.systemsymbols import SymbolSlot

# This tells documentation how to sort this module
sort_order = "mathics.builtin.function-application"


class Function(PostfixOperator, SympyFunction):
"""
<url>:WMA link:
https://reference.wolfram.com/language/ref/Function.html</url>
<dl>
<dt>'Function[$body$]'
<dt>'$body$ &'
Expand Down Expand Up @@ -164,8 +166,11 @@ def to_sympy(self, expr: Expression, **kwargs):
raise NotImplementedError


class Slot(SympyFunction):
class Slot(SympyFunction, PrefixOperator):
"""
<url>:WMA link:
https://reference.wolfram.com/language/ref/Slot.html</url>
<dl>
<dt>'#$n$'
<dd>represents the $n$th argument to a pure function.
Expand All @@ -190,6 +195,9 @@ class Slot(SympyFunction):
"""

attributes = A_N_HOLD_ALL | A_PROTECTED

operator = "#" # FIXME generate this automatically

rules = {
"Slot[]": "Slot[1]",
"MakeBoxes[Slot[n_Integer?NonNegative],"
Expand All @@ -204,8 +212,12 @@ def to_sympy(self, expr: Expression, **kwargs):
return sympy.Symbol(f"{sympy_slot_prefix}{index.get_int_value()}")


class SlotSequence(Builtin):
class SlotSequence(PrefixOperator, Builtin):
"""
<url>:WMA link:
https://reference.wolfram.com/language/ref/SlotSequence.html</url>
<dl>
<dt>'##'
<dd>is the sequence of arguments supplied to a pure function.
Expand All @@ -225,6 +237,8 @@ class SlotSequence(Builtin):

attributes = A_N_HOLD_ALL | A_PROTECTED

operator = "##" # FIXME generate this automatically

rules = {
"SlotSequence[]": "SlotSequence[1]",
"MakeBoxes[SlotSequence[n_Integer?Positive],"
Expand Down
Loading

0 comments on commit abd025b

Please sign in to comment.