Skip to content

Commit 916a8a7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into Dispatch2
2 parents f0e9cb4 + df81cb5 commit 916a8a7

File tree

25 files changed

+716
-447
lines changed

25 files changed

+716
-447
lines changed

CHANGES.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ CHANGES
55
2.1.1
66
-----
77

8-
New builtins
9-
++++++++++++
8+
New variables and builtins
9+
++++++++++++++++++++++++++
1010

1111
* ``Arg``
1212
* ``Dispatch``
1313
* ``FullSimplify``
1414
* ``LetterNumber`` #1298. The ``alphabet`` parameter supports only a minimal number of languages.
15+
* ``MemoryAvailable``
16+
* ``MemoryInUse``
1517
* ``Nand`` and ``Nor`` logical functions.
1618
* ``Series``, ``O`` and ``SeriesData``
1719
* ``StringReverse``
20+
* ``$SystemMemory``
1821
* Add all of the named colors, e.g. ``Brown`` or ``LighterMagenta``.
1922

2023

@@ -28,7 +31,7 @@ Enhancements
2831
* ``D`` and ``Derivative`` improvements.
2932
* ``FileNames`` returns a sorted list (#1250).
3033
* ``FindRoot`` now receives several optional parameters like ``Method`` and ``MaxIterations``.
31-
* ``FixedPoint`` now supports the ``SameTest`` option.
34+
* ``FixedPoint`` now supports the ``SameTest`` option.
3235
* ``Prime`` and ``PrimePi`` now accept a list parameter and have the ``NumericFunction`` attribute.
3336
* ``ReplaceRepeated`` and ``FixedPoint`` now supports the ``MaxIteration`` option (#1260).
3437
* ``Simplify`` performs a more sophisticated set of simplifications.
@@ -38,7 +41,7 @@ Enhancements
3841
* ``ToString`` accepts an optional *form* parameter.
3942
* ``ToExpression`` handles multi-line string input
4043
* The implementation of Streams was redone.
41-
44+
4245

4346

4447
Bug fixes
@@ -54,7 +57,7 @@ Internal changes
5457
----------------
5558

5659
* doctest accepts the option `-d` to show how long it takes to parse, evaluate and compare each individual test.
57-
60+
5861

5962
2.1.0
6063
-----

mathics/builtin/__init__.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,37 @@ def get_module_doc(module):
8585
return title, text
8686

8787
def import_builtins(module_names: List[str], submodule_name=None) -> None:
88-
for module_name in module_names:
89-
import_name = (
90-
f"mathics.builtin.{submodule_name}.{module_name}"
91-
if submodule_name
92-
else f"mathics.builtin.{module_name}"
93-
)
88+
"""
89+
Imports the list of Mathics Built-in modules so that inside
90+
Mathics we have these Builtin Functions, like Plus[], List[] are defined.
91+
92+
"""
93+
def import_module(module_name: str, import_name: str):
9494
try:
9595
module = importlib.import_module(import_name)
9696
except Exception as e:
9797
print(e)
9898
print(f" Not able to load {module_name}. Check your installation.")
9999
print(f" mathics.builtin loads from {__file__[:-11]}")
100-
continue
100+
return None
101101

102102
if __version__ != module.__version__:
103103
print(
104-
f"Version {module.__version__} in the module do not match with {__version__}"
104+
f"Version {module.__version__} in the module does not match top-level Mathics version {__version__}"
105105
)
106+
if module:
107+
modules.append(module)
106108

107-
modules.append(module)
109+
if submodule_name:
110+
import_module(submodule_name, f"mathics.builtin.{submodule_name}")
111+
112+
for module_name in module_names:
113+
import_name = (
114+
f"mathics.builtin.{submodule_name}.{module_name}"
115+
if submodule_name
116+
else f"mathics.builtin.{module_name}"
117+
)
118+
import_module(module_name, import_name)
108119

109120

110121
def is_builtin(var):
@@ -116,22 +127,25 @@ def is_builtin(var):
116127

117128

118129
# FIXME: redo using importlib since that is probably less fragile.
119-
exclude_files = set(("files", "codetables", "base", "importexport", "colors"))
130+
exclude_files = set(("codetables", "base"))
120131
module_names = [
121132
f for f in __py_files__ if re.match("^[a-z0-9]+$", f) if f not in exclude_files
122133
]
123134

124-
if ENABLE_FILES_MODULE:
125-
module_names += ["files", "importexport"]
126-
127135
modules = []
128136
import_builtins(module_names)
129137

130138
_builtins = []
131139
builtins_by_module = {}
132140

133-
for subdir in ("drawing", "numbers", "specialfns",):
141+
disable_file_module_names = [] if ENABLE_FILES_MODULE else ["files_io.files", "files_io.importexport"]
142+
143+
for subdir in ("drawing", "files_io", "numbers", "specialfns",):
134144
import_name = f"{__name__}.{subdir}"
145+
146+
if import_name in disable_file_module_names:
147+
continue
148+
135149
builtin_module = importlib.import_module(import_name)
136150
submodule_names = [
137151
modname

mathics/builtin/arithmetic.py

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,109 +1858,6 @@ class Factorial(PostfixOperator, _MPMathFunction):
18581858
precedence = 610
18591859
mpmath_name = "factorial"
18601860

1861-
1862-
class Gamma(_MPMathMultiFunction):
1863-
"""
1864-
<dl>
1865-
<dt>'Gamma[$z$]'
1866-
<dd>is the gamma function on the complex number $z$.
1867-
<dt>'Gamma[$z$, $x$]'
1868-
<dd>is the upper incomplete gamma function.
1869-
<dt>'Gamma[$z$, $x0$, $x1$]'
1870-
<dd>is equivalent to 'Gamma[$z$, $x0$] - Gamma[$z$, $x1$]'.
1871-
</dl>
1872-
1873-
'Gamma[$z$]' is equivalent to '($z$ - 1)!':
1874-
>> Simplify[Gamma[z] - (z - 1)!]
1875-
= 0
1876-
1877-
Exact arguments:
1878-
>> Gamma[8]
1879-
= 5040
1880-
>> Gamma[1/2]
1881-
= Sqrt[Pi]
1882-
>> Gamma[1, x]
1883-
= E ^ (-x)
1884-
>> Gamma[0, x]
1885-
= ExpIntegralE[1, x]
1886-
1887-
Numeric arguments:
1888-
>> Gamma[123.78]
1889-
= 4.21078*^204
1890-
>> Gamma[1. + I]
1891-
= 0.498016 - 0.15495 I
1892-
1893-
Both 'Gamma' and 'Factorial' functions are continuous:
1894-
>> Plot[{Gamma[x], x!}, {x, 0, 4}]
1895-
= -Graphics-
1896-
1897-
## Issue 203
1898-
#> N[Gamma[24/10], 100]
1899-
= 1.242169344504305404913070252268300492431517240992022966055507541481863694148882652446155342679460339
1900-
#> N[N[Gamma[24/10],100]/N[Gamma[14/10],100],100]
1901-
= 1.400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1902-
#> % // Precision
1903-
= 100.
1904-
1905-
#> Gamma[1.*^20]
1906-
: Overflow occurred in computation.
1907-
= Overflow[]
1908-
1909-
## Needs mpmath support for lowergamma
1910-
#> Gamma[1., 2.]
1911-
= Gamma[1., 2.]
1912-
"""
1913-
1914-
mpmath_names = {
1915-
1: "gamma",
1916-
}
1917-
sympy_names = {
1918-
1: "gamma",
1919-
2: "uppergamma",
1920-
}
1921-
1922-
rules = {
1923-
"Gamma[z_, x0_, x1_]": "Gamma[z, x0] - Gamma[z, x1]",
1924-
"Gamma[1 + z_]": "z!",
1925-
"Derivative[1][Gamma]": "(Gamma[#1]*PolyGamma[0, #1])&",
1926-
"Derivative[1, 0][Gamma]": "(Gamma[#1, #2]*Log[#2] + MeijerG[{{}, {1, 1}}, {{0, 0, #1}, {}}, #2])&",
1927-
"Derivative[0, 1][Gamma]": "(-(#2^(-1 + #1)/E^#2))&",
1928-
}
1929-
1930-
def get_sympy_names(self):
1931-
return ["gamma", "uppergamma", "lowergamma"]
1932-
1933-
def from_sympy(self, sympy_name, leaves):
1934-
if sympy_name == "lowergamma":
1935-
# lowergamma(z, x) -> Gamma[z, 0, x]
1936-
z, x = leaves
1937-
return Expression(self.get_name(), z, Integer0, x)
1938-
else:
1939-
return Expression(self.get_name(), *leaves)
1940-
1941-
1942-
class Pochhammer(SympyFunction):
1943-
"""
1944-
<dl>
1945-
<dt>'Pochhammer[$a$, $n$]'
1946-
<dd>is the Pochhammer symbol (a)_n.
1947-
</dl>
1948-
1949-
>> Pochhammer[4, 8]
1950-
= 6652800
1951-
"""
1952-
1953-
attributes = ("Listable", "NumericFunction", "Protected")
1954-
1955-
sympy_name = "RisingFactorial"
1956-
1957-
rules = {
1958-
"Pochhammer[a_, n_]": "Gamma[a + n] / Gamma[a]",
1959-
"Derivative[1,0][Pochhammer]": "(Pochhammer[#1, #2]*(-PolyGamma[0, #1] + PolyGamma[0, #1 + #2]))&",
1960-
"Derivative[0,1][Pochhammer]": "(Pochhammer[#1, #2]*PolyGamma[0, #1 + #2])&",
1961-
}
1962-
1963-
19641861
class HarmonicNumber(_MPMathFunction):
19651862
"""
19661863
<dl>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
"""
22
Graphics, Drawing, and Images
3+
4+
Functions like 'Plot' and 'ListPlot' can be used to draw graphs of functions and data.
5+
6+
Graphics is implemented as a collection of <i>graphics primitives</i>. Primatives are objects like 'Point', 'Line', and 'Polygon' and become elements of a <i>graphics object</i>.
7+
8+
A graphics object can have directives as well such as 'RGBColor', and 'Thickness'.
9+
10+
There are several kinds of graphics objects; each kind has a head which identifies its type.
11+
12+
>> ListPlot[ Table[Prime[n], {n, 20} ]]
13+
= -Graphics-
14+
>> Head[%]
15+
= Graphics
16+
>> Graphics3D[Sphere[]]
17+
= -Graphics3D-
18+
>> Head[%]
19+
= Graphics3D
20+
>>
21+
22+
323
"""
24+
25+
from mathics.version import __version__ # noqa used in loading to check consistency.

0 commit comments

Comments
 (0)