Skip to content

Commit 75c1cbf

Browse files
committed
merge
2 parents 44e7698 + df81cb5 commit 75c1cbf

File tree

25 files changed

+714
-447
lines changed

25 files changed

+714
-447
lines changed

CHANGES.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ CHANGES
55
2.1.1
66
-----
77

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

1111
* ``Arg``
1212
* ``CoefficientArrays`` and ``Collect`` (#1174, #1194)
1313
* ``Dispatch``
1414
* ``FullSimplify``
1515
* ``LetterNumber`` #1298. The ``alphabet`` parameter supports only a minimal number of languages.
16+
* ``MemoryAvailable``
17+
* ``MemoryInUse``
1618
* ``Nand`` and ``Nor`` logical functions.
1719
* ``Series``, ``O`` and ``SeriesData``
1820
* ``StringReverse``
21+
* ``$SystemMemory``
1922
* Add all of the named colors, e.g. ``Brown`` or ``LighterMagenta``.
2023

2124

@@ -40,7 +43,7 @@ Enhancements
4043
* ``Table`` [*expr*, *n*] is supported.
4144
* ``ToString`` accepts an optional *form* parameter.
4245
* ``ToExpression`` handles multi-line string input.
43-
* The implementation of Streams was redone.
46+
* The implementation of Streams was redone.
4447

4548

4649
Bug fixes

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
@@ -1859,109 +1859,6 @@ class Factorial(PostfixOperator, _MPMathFunction):
18591859
precedence = 610
18601860
mpmath_name = "factorial"
18611861

1862-
1863-
class Gamma(_MPMathMultiFunction):
1864-
"""
1865-
<dl>
1866-
<dt>'Gamma[$z$]'
1867-
<dd>is the gamma function on the complex number $z$.
1868-
<dt>'Gamma[$z$, $x$]'
1869-
<dd>is the upper incomplete gamma function.
1870-
<dt>'Gamma[$z$, $x0$, $x1$]'
1871-
<dd>is equivalent to 'Gamma[$z$, $x0$] - Gamma[$z$, $x1$]'.
1872-
</dl>
1873-
1874-
'Gamma[$z$]' is equivalent to '($z$ - 1)!':
1875-
>> Simplify[Gamma[z] - (z - 1)!]
1876-
= 0
1877-
1878-
Exact arguments:
1879-
>> Gamma[8]
1880-
= 5040
1881-
>> Gamma[1/2]
1882-
= Sqrt[Pi]
1883-
>> Gamma[1, x]
1884-
= E ^ (-x)
1885-
>> Gamma[0, x]
1886-
= ExpIntegralE[1, x]
1887-
1888-
Numeric arguments:
1889-
>> Gamma[123.78]
1890-
= 4.21078*^204
1891-
>> Gamma[1. + I]
1892-
= 0.498016 - 0.15495 I
1893-
1894-
Both 'Gamma' and 'Factorial' functions are continuous:
1895-
>> Plot[{Gamma[x], x!}, {x, 0, 4}]
1896-
= -Graphics-
1897-
1898-
## Issue 203
1899-
#> N[Gamma[24/10], 100]
1900-
= 1.242169344504305404913070252268300492431517240992022966055507541481863694148882652446155342679460339
1901-
#> N[N[Gamma[24/10],100]/N[Gamma[14/10],100],100]
1902-
= 1.400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1903-
#> % // Precision
1904-
= 100.
1905-
1906-
#> Gamma[1.*^20]
1907-
: Overflow occurred in computation.
1908-
= Overflow[]
1909-
1910-
## Needs mpmath support for lowergamma
1911-
#> Gamma[1., 2.]
1912-
= Gamma[1., 2.]
1913-
"""
1914-
1915-
mpmath_names = {
1916-
1: "gamma",
1917-
}
1918-
sympy_names = {
1919-
1: "gamma",
1920-
2: "uppergamma",
1921-
}
1922-
1923-
rules = {
1924-
"Gamma[z_, x0_, x1_]": "Gamma[z, x0] - Gamma[z, x1]",
1925-
"Gamma[1 + z_]": "z!",
1926-
"Derivative[1][Gamma]": "(Gamma[#1]*PolyGamma[0, #1])&",
1927-
"Derivative[1, 0][Gamma]": "(Gamma[#1, #2]*Log[#2] + MeijerG[{{}, {1, 1}}, {{0, 0, #1}, {}}, #2])&",
1928-
"Derivative[0, 1][Gamma]": "(-(#2^(-1 + #1)/E^#2))&",
1929-
}
1930-
1931-
def get_sympy_names(self):
1932-
return ["gamma", "uppergamma", "lowergamma"]
1933-
1934-
def from_sympy(self, sympy_name, leaves):
1935-
if sympy_name == "lowergamma":
1936-
# lowergamma(z, x) -> Gamma[z, 0, x]
1937-
z, x = leaves
1938-
return Expression(self.get_name(), z, Integer0, x)
1939-
else:
1940-
return Expression(self.get_name(), *leaves)
1941-
1942-
1943-
class Pochhammer(SympyFunction):
1944-
"""
1945-
<dl>
1946-
<dt>'Pochhammer[$a$, $n$]'
1947-
<dd>is the Pochhammer symbol (a)_n.
1948-
</dl>
1949-
1950-
>> Pochhammer[4, 8]
1951-
= 6652800
1952-
"""
1953-
1954-
attributes = ("Listable", "NumericFunction", "Protected")
1955-
1956-
sympy_name = "RisingFactorial"
1957-
1958-
rules = {
1959-
"Pochhammer[a_, n_]": "Gamma[a + n] / Gamma[a]",
1960-
"Derivative[1,0][Pochhammer]": "(Pochhammer[#1, #2]*(-PolyGamma[0, #1] + PolyGamma[0, #1 + #2]))&",
1961-
"Derivative[0,1][Pochhammer]": "(Pochhammer[#1, #2]*PolyGamma[0, #1 + #2])&",
1962-
}
1963-
1964-
19651862
class HarmonicNumber(_MPMathFunction):
19661863
"""
19671864
<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.

mathics/builtin/evaluation.py

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -317,145 +317,6 @@ class Sequence(Builtin):
317317
"""
318318

319319

320-
class Line(Builtin):
321-
"""
322-
<dl>
323-
<dt>'$Line'
324-
<dd>holds the current input line number.
325-
</dl>
326-
>> $Line
327-
= 1
328-
>> $Line
329-
= 2
330-
>> $Line = 12;
331-
>> 2 * 5
332-
= 10
333-
>> Out[13]
334-
= 10
335-
>> $Line = -1;
336-
: Non-negative integer expected.
337-
"""
338-
339-
name = "$Line"
340-
341-
342-
class HistoryLength(Builtin):
343-
"""
344-
<dl>
345-
<dt>'$HistoryLength'
346-
<dd>specifies the maximum number of 'In' and 'Out' entries.
347-
</dl>
348-
>> $HistoryLength
349-
= 100
350-
>> $HistoryLength = 1;
351-
>> 42
352-
= 42
353-
>> %
354-
= 42
355-
>> %%
356-
= %3
357-
>> $HistoryLength = 0;
358-
>> 42
359-
= 42
360-
>> %
361-
= %7
362-
"""
363-
364-
name = "$HistoryLength"
365-
366-
rules = {
367-
"$HistoryLength": "100",
368-
}
369-
370-
371-
class In(Builtin):
372-
"""
373-
<dl>
374-
<dt>'In[$k$]'
375-
<dd>gives the $k$th line of input.
376-
</dl>
377-
>> x = 1
378-
= 1
379-
>> x = x + 1
380-
= 2
381-
>> Do[In[2], {3}]
382-
>> x
383-
= 5
384-
>> In[-1]
385-
= 5
386-
>> Definition[In]
387-
= Attributes[In] = {Listable, Protected}
388-
.
389-
. In[6] = Definition[In]
390-
.
391-
. In[5] = In[-1]
392-
.
393-
. In[4] = x
394-
.
395-
. In[3] = Do[In[2], {3}]
396-
.
397-
. In[2] = x = x + 1
398-
.
399-
. In[1] = x = 1
400-
"""
401-
402-
attributes = ("Listable", "Protected")
403-
404-
rules = {
405-
"In[k_Integer?Negative]": "In[$Line + k]",
406-
}
407-
408-
409-
class Out(Builtin):
410-
"""
411-
<dl>
412-
<dt>'Out[$k$]'
413-
<dt>'%$k$'
414-
<dd>gives the result of the $k$th input line.
415-
<dt>'%', '%%', etc.
416-
<dd>gives the result of the previous input line, of the line before the previous input line, etc.
417-
</dl>
418-
419-
>> 42
420-
= 42
421-
>> %
422-
= 42
423-
>> 43;
424-
>> %
425-
= 43
426-
>> 44
427-
= 44
428-
>> %1
429-
= 42
430-
>> %%
431-
= 44
432-
>> Hold[Out[-1]]
433-
= Hold[%]
434-
>> Hold[%4]
435-
= Hold[%4]
436-
>> Out[0]
437-
= Out[0]
438-
439-
#> 10
440-
= 10
441-
#> Out[-1] + 1
442-
= 11
443-
#> Out[] + 1
444-
= 12
445-
"""
446-
447-
attributes = ("Listable", "Protected")
448-
449-
rules = {
450-
"Out[k_Integer?Negative]": "Out[$Line + k]",
451-
"Out[]": "Out[$Line - 1]",
452-
"MakeBoxes[Out[k_Integer?((-10 <= # < 0)&)],"
453-
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'StringJoin[ConstantArray["%%", -k]]',
454-
"MakeBoxes[Out[k_Integer?Positive],"
455-
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'"%%" <> ToString[k]',
456-
}
457-
458-
459320
class Quit(Builtin):
460321
"""
461322
<dl>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
Input/Output, Files, and Filesystem
3+
"""
4+
5+
from mathics.version import __version__ # noqa used in loading to check consistency.

0 commit comments

Comments
 (0)