Skip to content

Commit e646493

Browse files
committed
Merge remote-tracking branch 'upstream/master' into newcellstotexfixes2
2 parents 5a9782f + 7fb2fa1 commit e646493

43 files changed

Lines changed: 4183 additions & 1909 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/windows.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 -e .
29+
- name: Install Mathics
30+
run: |
31+
python setup.py install
32+
- name: Test Mathics
33+
run: |
34+
pip install pytest
35+
py.test test
36+
python mathics/test.py

CHANGES.rst

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

4+
2.1.0
5+
-----
6+
7+
New builtins
8+
++++++++++++
9+
10+
* ``ArcTanh``
11+
* ``ByteArray``
12+
* ``CreateFile``
13+
* ``CreateTemporary``
14+
* ``FileNames``
15+
* ``NIntegrate``
16+
* ``PartitionsP``
17+
* ``$Notebooks``
18+
19+
Enhancements
20+
++++++++++++
21+
22+
* the Mathics version is checked for builtin modules at load time. A message is given when a builtin doesn't load.
23+
* Automatic detection for the best strategy to numeric evaluation of constants.
24+
* ``FileNameJoin`` - implement ``OperatingSystem`` option
25+
* Mathics functions are accepted by ``Compile[]``. The return value or type will be
26+
``Compile[] and CompiledFunction[]`` every expression can have a compiled form,
27+
as a Python function.
28+
* ``Equal[]`` now compares complex against other numbers properly.
29+
30+
31+
Bug fixes
32+
+++++++++
33+
34+
* TeXForm for integrals are now properly formatted.
35+
36+
37+
Pymathics Modules
38+
+++++++++++++++++
39+
40+
* Pymathics modules now can run initialization code when are loaded.
41+
* The ``builtins`` list is not hardliked to the library anymore. This simplifies
42+
the loading and reloading of pymathics modules.
43+
* Decoupling of BoxConstructors from the library. Now are defined at the
44+
level of the definition objects. This is useful for customizing the
45+
Graphics output if it is available.
46+
47+
48+
Miscellanea
49+
+++++++++++
50+
51+
* A pass was made to improve Microsoft Windows compatability and testing
52+
Windows under MSYS.
53+
* Include numpy version in version string. Show in CLI
54+
* Small CLI tweaks ``--colors=None`` added to match mathicsscript.
55+
456
2.0.0
557
-----
658

@@ -79,7 +131,7 @@ Numerous bugs were fixed while working on Combinatorica V0.9 and CellsToTeX.
79131
Document updates
80132
++++++++++++++++
81133

82-
- Start a readthedocs `Developer Guide <https://mathics-development-guide.readthedocs.io/en/latest/>`_
134+
- Start a readthedocs `Developer Guide <https://mathics-development-guide.reandthedocs.io/en/latest/>`_
83135

84136
Enhancements and bug fixes:
85137
+++++++++++++++++++++++++++

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mathicsserver: a Django-based Web interface
2828
Installing and Running
2929
----------------------
3030

31-
See the `readthe docs guide <https://mathics-development-guide.readthedocs.io/en/latest/>`_ for instructions on `installing <https://mathics-development-guide.readthedocs.io/en/latest/installing.html>`_ and `running <https://mathics-development-guide.readthedocs.io/en/latest/running.html>`_.
31+
See the `read the docs guide <https://mathics-development-guide.readthedocs.io/en/latest/>`_ for instructions on `installing <https://mathics-development-guide.readthedocs.io/en/latest/installing.html>`_ and `running <https://mathics-development-guide.readthedocs.io/en/latest/running.html>`_.
3232

3333
Contributing
3434
------------

mathics/Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

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/autoload/settings.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
Settings`$PreferredBackendMethod::usage = "Set this do whether to use mpmath, numpy or Sympy for numeric and symbolic constants and methods when there is s choice";
1111
Settings`$PreferredBackendMethod = "sympy"
1212
Unprotect[Settings`$PreferredBackendMethod]
13+
14+
(* Some packages like Feyncalc, test for whether a they are being used
15+
inside a notbook. *)
16+
System`$Notebooks::usage = "Set True if the Mathics is being used with a notebook‐based front end.";
17+
System`$Notebooks = False;
18+
Unprotect[System`Notebooks];

mathics/builtin/arithmetic.py

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from mathics.version import __version__ # noqa used in loading to check consistency.
1111
import sympy
1212
import mpmath
13+
from functools import lru_cache
1314

1415
from mathics.builtin.base import (
1516
Builtin,
@@ -34,12 +35,29 @@
3435
SymbolNull,
3536
SymbolTrue,
3637
from_python,
38+
from_mpmath,
3739
)
3840
from mathics.core.numbers import min_prec, dps, SpecialValueError
3941

4042
from mathics.builtin.lists import _IterationFunction
4143
from mathics.core.convert import from_sympy, SympyExpression
4244

45+
@lru_cache(maxsize=1024)
46+
def call_mpmath(mpmath_function, mpmath_args):
47+
try:
48+
return mpmath_function(*mpmath_args)
49+
except ValueError as exc:
50+
text = str(exc)
51+
if text == "gamma function pole":
52+
return Symbol("ComplexInfinity")
53+
else:
54+
raise
55+
except ZeroDivisionError:
56+
return
57+
except SpecialValueError as exc:
58+
return Symbol(exc.name)
59+
60+
4361
class _MPMathFunction(SympyFunction):
4462

4563
attributes = ("Listable", "NumericFunction")
@@ -48,6 +66,7 @@ class _MPMathFunction(SympyFunction):
4866

4967
nargs = 1
5068

69+
@lru_cache(maxsize=1024)
5170
def get_mpmath_function(self, args):
5271
if self.mpmath_name is None or len(args) != self.nargs:
5372
return None
@@ -57,7 +76,7 @@ def apply(self, z, evaluation):
5776
"%(name)s[z__]"
5877

5978
args = z.numerify(evaluation).get_sequence()
60-
mpmath_function = self.get_mpmath_function(args)
79+
mpmath_function = self.get_mpmath_function(tuple(args))
6180
result = None
6281

6382
# if no arguments are inexact attempt to use sympy
@@ -82,7 +101,7 @@ def apply(self, z, evaluation):
82101
if None in float_args:
83102
return
84103

85-
result = self.call_mpmath(mpmath_function, float_args)
104+
result = call_mpmath(mpmath_function, tuple(float_args))
86105
if isinstance(result, (mpmath.mpc, mpmath.mpf)):
87106
if mpmath.isinf(result) and isinstance(result, mpmath.mpc):
88107
result = Symbol("ComplexInfinity")
@@ -93,7 +112,7 @@ def apply(self, z, evaluation):
93112
elif mpmath.isnan(result):
94113
result = Symbol("Indeterminate")
95114
else:
96-
result = Number.from_mpmath(result)
115+
result = from_mpmath(result)
97116
else:
98117
prec = min_prec(*args)
99118
d = dps(prec)
@@ -104,9 +123,9 @@ def apply(self, z, evaluation):
104123
mpmath_args = [x.to_mpmath() for x in args]
105124
if None in mpmath_args:
106125
return
107-
result = self.call_mpmath(mpmath_function, mpmath_args)
126+
result = call_mpmath(mpmath_function, tuple(mpmath_args))
108127
if isinstance(result, (mpmath.mpc, mpmath.mpf)):
109-
result = Number.from_mpmath(result, d)
128+
result = from_mpmath(result, d)
110129
return result
111130

112131
def call_mpmath(self, mpmath_function, mpmath_args):
@@ -338,12 +357,12 @@ def append_last():
338357
if is_machine_precision:
339358
numbers = [item.to_mpmath() for item in numbers]
340359
number = mpmath.fsum(numbers)
341-
number = Number.from_mpmath(number)
360+
number = from_mpmath(number)
342361
else:
343362
with mpmath.workprec(prec):
344363
numbers = [item.to_mpmath() for item in numbers]
345364
number = mpmath.fsum(numbers)
346-
number = Number.from_mpmath(number, dps(prec))
365+
number = from_mpmath(number, dps(prec))
347366
else:
348367
number = from_sympy(sum(item.to_sympy() for item in numbers))
349368
else:
@@ -670,12 +689,12 @@ def apply(self, items, evaluation):
670689
if is_machine_precision:
671690
numbers = [item.to_mpmath() for item in numbers]
672691
number = mpmath.fprod(numbers)
673-
number = Number.from_mpmath(number)
692+
number = from_mpmath(number)
674693
else:
675694
with mpmath.workprec(prec):
676695
numbers = [item.to_mpmath() for item in numbers]
677696
number = mpmath.fprod(numbers)
678-
number = Number.from_mpmath(number, dps(prec))
697+
number = from_mpmath(number, dps(prec))
679698
else:
680699
number = sympy.Mul(*[item.to_sympy() for item in numbers])
681700
number = from_sympy(number)
@@ -1095,6 +1114,7 @@ class Re(SympyFunction):
10951114
"""
10961115

10971116
attributes = ("Listable", "NumericFunction")
1117+
sympy_name = "re"
10981118

10991119
def apply_complex(self, number, evaluation):
11001120
"Re[number_Complex]"
@@ -1209,7 +1229,7 @@ class Abs(_MPMathFunction):
12091229
mpmath_name = "fabs" # mpmath actually uses python abs(x) / x.__abs__()
12101230

12111231

1212-
class Sign(Builtin):
1232+
class Sign(SympyFunction):
12131233
"""
12141234
<dl>
12151235
<dt>'Sign[$x$]'
@@ -1237,8 +1257,7 @@ class Sign(Builtin):
12371257
= Sign[20]
12381258
"""
12391259

1240-
# Sympy and mpmath do not give the desired form of complex number
1241-
# sympy_name = 'sign'
1260+
sympy_name = "sign"
12421261
# mpmath_name = 'sign'
12431262

12441263
attributes = ("Listable", "NumericFunction")
@@ -1248,14 +1267,15 @@ class Sign(Builtin):
12481267
}
12491268

12501269
def apply(self, x, evaluation):
1251-
"Sign[x_]"
1270+
"%(name)s[x_]"
1271+
# Sympy and mpmath do not give the desired form of complex number
12521272
if isinstance(x, Complex):
12531273
return Expression("Times", x, Expression("Power", Expression("Abs", x), -1))
12541274

12551275
sympy_x = x.to_sympy()
12561276
if sympy_x is None:
12571277
return None
1258-
return from_sympy(sympy.sign(sympy_x))
1278+
return super().apply(x)
12591279

12601280
def apply_error(self, x, seqs, evaluation):
12611281
"Sign[x_, seqs__]"
@@ -1591,7 +1611,7 @@ class Rational_(Builtin):
15911611
name = "Rational"
15921612

15931613
def apply(self, n, m, evaluation):
1594-
"Rational[n_Integer, m_Integer]"
1614+
"%(name)s[n_Integer, m_Integer]"
15951615

15961616
if m.to_sympy() == 1:
15971617
return Integer(n.to_sympy())
@@ -1658,7 +1678,7 @@ class Complex_(Builtin):
16581678
name = "Complex"
16591679

16601680
def apply(self, r, i, evaluation):
1661-
"Complex[r_?NumberQ, i_?NumberQ]"
1681+
"%(name)s[r_?NumberQ, i_?NumberQ]"
16621682

16631683
if isinstance(r, Complex) or isinstance(i, Complex):
16641684
sym_form = r.to_sympy() + sympy.I * i.to_sympy()
@@ -2063,7 +2083,7 @@ class Piecewise(SympyFunction):
20632083
attributes = ("HoldAll",)
20642084

20652085
def apply(self, items, evaluation):
2066-
"Piecewise[items__]"
2086+
"%(name)s[items__]"
20672087
result = self.to_sympy(Expression("Piecewise", *items.get_sequence()))
20682088
if result is None:
20692089
return
@@ -2129,7 +2149,7 @@ class Boole(Builtin):
21292149
attributes = ("Listable",)
21302150

21312151
def apply(self, expr, evaluation):
2132-
"Boole[expr_]"
2152+
"%(name)s[expr_]"
21332153
if isinstance(expr, Symbol):
21342154
if expr == SymbolTrue:
21352155
return Integer(1)

0 commit comments

Comments
 (0)