Skip to content

Commit 53575b3

Browse files
committed
merge
2 parents 3b7f03e + e8a5440 commit 53575b3

25 files changed

Lines changed: 2721 additions & 1140 deletions

.github/workflows/windows.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Mathics (Windows)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
strategy:
13+
matrix:
14+
os: [windows]
15+
python-version: [3.7, 3.8]
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
python -m pip install wheel
26+
choco install llvm
27+
set LLVM_DIR="C:\Program Files\LLVM"
28+
pip install llvmlite
29+
pip install numpy
30+
pip install sympy
31+
pip install pillow
32+
pip install scikit-image
33+
pip install requests
34+
pip install wordcloud
35+
pip install PyYAML
36+
pip install palettable
37+
pip install mpmath
38+
pip install mathics_scanner
39+
- name: Install Mathics
40+
run: |
41+
python setup.py install
42+
- name: Test Mathics
43+
run: |
44+
pip install pytest
45+
py.test test
46+
python mathics/test.py

CHANGES.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CHANGES
22
=======
33

4+
<<<<<<< HEAD
45

56
2.0.1
67
-----
@@ -34,6 +35,35 @@ Pymathics Modules
3435

3536

3637

38+
=======
39+
2.1.0
40+
-----
41+
42+
New builtins
43+
++++++++++++++
44+
45+
* ``ByteArray``
46+
* ``FileNames``
47+
* ``CreateFile``
48+
* ``CreateTemporary``
49+
50+
51+
Enhancements
52+
++++++++++++
53+
54+
* ``FileNameJoin`` - implement ``OperatingSystem`` option
55+
* Mathics functions are accepted by ``Compile[]``. The return value or type will be
56+
``CompiledFunction``
57+
* ``EqualQ[]`` now compares complex against other numbers properly.
58+
59+
Miscellanea
60+
+++++++++++
61+
62+
* A pass was made to improve Microsoft Windows compatability and testing
63+
Windows under MSYS.
64+
* Include numpy version in version string. Show in CLI
65+
* Small CLI tweaks ``--colors=None`` added to match mathicsscript.
66+
>>>>>>> upstream/master
3767

3868
2.0.0
3969
-----
@@ -113,7 +143,7 @@ Numerous bugs were fixed while working on Combinatorica V0.9 and CellsToTeX.
113143
Document updates
114144
++++++++++++++++
115145

116-
- Start a readthedocs `Developer Guide <https://mathics-development-guide.readthedocs.io/en/latest/>`_
146+
- Start a readthedocs `Developer Guide <https://mathics-development-guide.reandthedocs.io/en/latest/>`_
117147

118148
Enhancements and bug fixes:
119149
+++++++++++++++++++++++++++

mathics/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import platform
66
import sympy
77
import mpmath
8+
import numpy
89

910
from mathics.version import __version__
1011
from mathics.core.expression import (
@@ -27,6 +28,7 @@
2728
"mathics": __version__,
2829
"sympy": sympy.__version__,
2930
"mpmath": mpmath.__version__,
31+
"numpy": numpy.__version__,
3032
"python": platform.python_implementation() + " " + sys.version.split("\n")[0],
3133
}
3234

@@ -40,7 +42,7 @@
4042

4143
version_string = """Mathics {mathics}
4244
on {python}
43-
using SymPy {sympy}, mpmath {mpmath}""".format(
45+
using SymPy {sympy}, mpmath {mpmath}, numpy {numpy}""".format(
4446
**version_info
4547
)
4648

mathics/autoload/formats/Base64/Export.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
strm = OpenWrite[filename];
1212
If[strm === $Failed, Return[$Failed]];
1313
data = B64Encode[expr];
14-
WriteString[strm, data];
14+
WriteString[strm, data];
1515
Close[strm];
1616
]
1717

@@ -21,7 +21,7 @@
2121
FunctionChannels -> {"FileNames"},
2222
Options -> {"CharacterEncoding", "ByteOrderMark"},
2323
DefaultElement -> "Plaintext",
24-
BinaryFormat -> True
24+
BinaryFormat -> False
2525
]
2626

2727

mathics/autoload/formats/CSV/Export.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
FunctionChannels -> {"Streams"},
2323
Options -> {"ByteOrderMark"},
2424
DefaultElement -> "Plaintext",
25-
BinaryFormat -> True,
25+
BinaryFormat -> False,
2626
Options -> {
2727
"CharacterEncoding",
2828
"FieldSeparators"

mathics/builtin/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
MachineReal,
2222
PrecisionReal,
2323
String,
24+
ByteArrayAtom,
2425
Symbol,
2526
ensure_context,
2627
strip_context,

mathics/builtin/comparison.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# -*- coding: utf-8 -*-
33

44

5+
from mathics.version import __version__ # noqa used in loading to check consistency.
6+
57
import itertools
68
from typing import Optional, Union
79

810
import sympy
9-
from mathics.version import __version__ # noqa used in loading to check consistency.
1011

1112
from mathics.builtin.base import (
1213
BinaryOperator,
@@ -21,6 +22,7 @@
2122
Expression,
2223
Integer,
2324
Number,
25+
Real,
2426
String,
2527
Symbol,
2628
SymbolFalse,
@@ -32,6 +34,9 @@ def cmp(a, b) -> int:
3234
"Returns 0 if a == b, -1 if a < b and 1 if a > b"
3335
return (a > b) - (a < b)
3436

37+
def is_number(sympy_value) -> bool:
38+
return hasattr(sympy_value, "is_number") or isinstance(sympy_value, sympy.Float)
39+
3540
class SameQ(BinaryOperator):
3641
"""
3742
<dl>
@@ -231,17 +236,30 @@ def do_compare(self, l1, l2) -> Union[bool, None]:
231236
return result
232237
return True
233238

239+
# Use Mathics' built-in comparisons for Real and Integer. These use
240+
# WL's interpretation of Equal[] which allows for slop in Reals
241+
# in the least significant digit of precision, while for Integers, comparison
242+
# has to be exact.
243+
244+
if ((isinstance(l1, Real) and isinstance(l2, Real)) or
245+
(isinstance(l1, Integer) and isinstance(l2, Integer))):
246+
return l1 == l2
247+
248+
# For everything else, use sympy.
249+
234250
l1_sympy = l1.to_sympy(evaluate=True, prec=COMPARE_PREC)
235251
l2_sympy = l2.to_sympy(evaluate=True, prec=COMPARE_PREC)
236252

237253
if l1_sympy is None or l2_sympy is None:
238254
return None
239255

240-
if not hasattr(l1_sympy, "is_number"):
256+
257+
if not is_number(l1_sympy):
241258
l1_sympy = mp_convert_constant(l1_sympy, prec=COMPARE_PREC)
242-
if not hasattr(l2_sympy, "is_number"):
259+
if not is_number(l2_sympy):
243260
l2_sympy = mp_convert_constant(l2_sympy, prec=COMPARE_PREC)
244261

262+
245263
if l1_sympy.is_number and l2_sympy.is_number:
246264
# assert min_prec(l1, l2) is None
247265
prec = COMPARE_PREC # TODO: Use $MaxExtraPrecision
@@ -254,8 +272,12 @@ def do_compare(self, l1, l2) -> Union[bool, None]:
254272
def apply(self, items, evaluation):
255273
"%(name)s[items___]"
256274
items_sequence = items.get_sequence()
257-
if len(items_sequence) <= 1:
275+
n = len(items_sequence)
276+
if n <= 1:
258277
return SymbolTrue
278+
is_exact_vals = [Expression("ExactNumberQ", arg).evaluate(evaluation) for arg in items_sequence]
279+
if all(val == SymbolTrue for val in is_exact_vals):
280+
return self.apply_other(items, evaluation)
259281
args = self.numerify_args(items, evaluation)
260282
wanted = operators[self.get_name()]
261283
for x, y in itertools.combinations(args, 2):
@@ -274,7 +296,7 @@ def apply(self, items, evaluation):
274296
return SymbolTrue
275297

276298
def apply_other(self, args, evaluation):
277-
"%(name)s[args___?(!RealNumberQ[#]&)]"
299+
"%(name)s[args___?(!ExactNumberQ[#]&)]"
278300
args = args.get_sequence()
279301
for x, y in itertools.combinations(args, 2):
280302
c = self.do_compare(x, y)
@@ -285,6 +307,7 @@ def apply_other(self, args, evaluation):
285307
return SymbolTrue
286308

287309

310+
288311
class _ComparisonOperator(_InequalityOperator):
289312
"Compares arguments in a chain e.g. a < b < c compares a < b and b < c."
290313

@@ -355,7 +378,6 @@ def apply(self, items, evaluation):
355378
]
356379
return Expression("And", *groups)
357380

358-
359381
def do_cmp(x1, x2) -> Optional[int]:
360382

361383
# don't attempt to compare complex numbers
@@ -369,8 +391,10 @@ def do_cmp(x1, x2) -> Optional[int]:
369391
s1 = x1.to_sympy()
370392
s2 = x2.to_sympy()
371393

372-
# use internal comparisons only for Reals
373-
# and use sympy for everything else
394+
# Use internal comparisons only for Real which is uses
395+
# WL's interpretation of equal (which allows for slop
396+
# in the least significant digit of precision), and use
397+
# use sympy for everything else
374398
if s1.is_Float and s2.is_Float:
375399
if x1 == x2:
376400
return 0
@@ -450,8 +474,9 @@ class Equal(_EqualityOperator, SympyComparison):
450474
## TODO Needs power precision tracking
451475
## >> 0.1 ^ 10000 == 0.1 ^ 10000 + 0.1 ^ 10012
452476
## = False
453-
## >> 0.1 ^ 10000 == 0.1 ^ 10000 + 0.1 ^ 10013
454-
## = True
477+
478+
#> 0.1 ^ 10000 == 0.1 ^ 10000 + 0.1 ^ 10013
479+
= True
455480
456481
#> 0.1111111111111111 == 0.1111111111111126
457482
= True

mathics/builtin/compilation.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from mathics.version import __version__ # noqa used in loading to check consistency.
44
from mathics.builtin.base import Builtin, BoxConstruct
5+
from mathics.core.evaluation import Evaluation
56
from mathics.core.expression import (
67
Atom,
78
Expression,
@@ -16,7 +17,7 @@
1617

1718

1819
class Compile(Builtin):
19-
'''
20+
"""
2021
<dl>
2122
<dt>'Compile[{x1, x2, ...}, expr_]'
2223
<dd>Compiles $expr$ assuming each $xi$ is a $Real$ number.
@@ -64,7 +65,7 @@ class Compile(Builtin):
6465
functions
6566
>> Compile[{{a, _Integer}, {b, _Integer}}, While[b != 0, {a, b} = {b, Mod[a, b]}]; a] (* GCD of a, b *)
6667
= CompiledFunction[{a, b}, a, -PythonizedCode-]
67-
'''
68+
"""
6869

6970
requires = ("llvmlite",)
7071

@@ -126,23 +127,25 @@ def apply(self, vars, expr, evaluation):
126127
cfunc = _compile(expr, args)
127128
except CompileError:
128129
cfunc = None
129-
# llvm compilation failed. Try to pythonize it
130+
130131
if cfunc is None:
131132
try:
133+
132134
def _pythonized_mathics_expr(*x):
133135
inner_evaluation = Evaluation(definitions=evaluation.definitions)
134-
vars = dict(list(zip(names, x[:len(names)])))
136+
vars = dict(list(zip(names, x[: len(names)])))
135137
pyexpr = expr.replace_vars(vars)
136138
pyexpr = Expression("N", pyexpr).evaluate(inner_evaluation)
137139
res = pyexpr.to_python(n_evaluation=inner_evaluation)
138140
return res
139-
#TODO: check if we can use numba to compile this...
141+
142+
# TODO: check if we can use numba to compile this...
140143
cfunc = _pythonized_mathics_expr
141144
except Exception as e:
142145
cfunc = None
143-
# Pythonization failed. Show an error.
146+
144147
if cfunc is None:
145-
evaluation.message('Compile', 'comperr', expr)
148+
evaluation.message("Compile", "comperr", expr)
146149
args = Expression("List", *names)
147150
return Expression("Function", args, expr)
148151

mathics/builtin/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Degree(MPMathConstant, NumpyConstant, SympyConstant):
248248
u"""
249249
<dl>
250250
<dt>'Degree'
251-
<dd>is the number of radians in one degree. It hsas a numerical value of \u03c0 / 180.
251+
<dd>is the number of radians in one degree. It has a numerical value of \u03c0 / 180.
252252
</dl>
253253
>> Cos[60 Degree]
254254
= 1 / 2

0 commit comments

Comments
 (0)