Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Jul 20, 2023
2 parents 74e5823 + 87316dc commit b3119c5
Show file tree
Hide file tree
Showing 33 changed files with 607 additions and 308 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/consistency-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/isort-and-black-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install click, black and isort
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install OS dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install OS dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install OS dependencies
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
.settings
.vscode
/.cache
/.gdbinit
/.python-version
/Mathics3.egg-info
/Mathics.egg-info
/Mathics3.egg-info
ChangeLog
Documents/
Homepage/
Expand All @@ -33,9 +34,9 @@ mathics/doc/tex/logo-heptatom.pdf
mathics/doc/tex/logo-text-nodrop.pdf
mathics/doc/tex/mathics-*.asy
mathics/doc/tex/mathics-*.dvi
mathics/doc/tex/mathics-*.dvi
mathics/doc/tex/mathics-*.eps
mathics/doc/tex/mathics-*.pdf
mathics/doc/tex/mathics-*.dvi
mathics/doc/tex/mathics-*.tex
mathics/doc/tex/mathics.aux
mathics/doc/tex/mathics.dvi
Expand Down
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ New Builtins


* `Elements`

* `RealAbs` and `RealSign`

Compatibility
-------------
Expand All @@ -24,7 +24,7 @@ Internals
* ``eval_abs`` and ``eval_sign`` extracted from ``Abs`` and ``Sign`` and added to ``mathics.eval.arithmetic``.
* Maximum number of digits allowed in a string set to 7000 and can be adjusted using environment variable
``MATHICS_MAX_STR_DIGITS`` on Python versions that don't adjust automatically (like pyston).

* Real number comparisons implemented is based now in the internal implementation of `RealSign`.

Bugs
----
Expand Down
2 changes: 2 additions & 0 deletions SYMBOLS_MANIFEST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,10 @@ System`Read
System`ReadList
System`ReadProtected
System`Real
System`RealAbs
System`RealDigits
System`RealNumberQ
System`RealSign
System`Reals
System`Reap
System`Record
Expand Down
9 changes: 8 additions & 1 deletion admin-tools/build_and_check_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

import sys

from mathics.builtin import Builtin, modules, name_is_builtin_symbol
from mathics.builtin.base import Builtin
from mathics.core.load_builtin import (
import_and_load_builtins,
modules,
name_is_builtin_symbol,
)

import_and_load_builtins()


def generate_available_builtins_names():
Expand Down
2 changes: 2 additions & 0 deletions examples/symbolic_logic/gries_schneider/test_gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from mathics.core.definitions import Definitions
from mathics.core.evaluation import Evaluation
from mathics.core.load_builtin import import_and_load_builtins
from mathics.core.parser import MathicsSingleLineFeeder, parse

import_and_load_builtins()
definitions = Definitions(add_builtin=True)

for i in range(0, 4):
Expand Down
35 changes: 0 additions & 35 deletions mathics/builtin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,3 @@
builtin class such as the Builtin's Attributes, its Information text,
among other things.
"""

import os
import os.path as osp

from mathics.core.load_builtin import (
add_builtins_from_builtin_modules,
get_module_names,
import_builtin_subdirectories,
import_builtins,
initialize_display_operators_set,
)
from mathics.settings import ENABLE_FILES_MODULE

# Get import modules in this directory of Python modules that contain
# Mathics3 Builtin class definitions.

builtin_path = osp.dirname(__file__)
exclude_files = {"codetables", "base"}
module_names = get_module_names(builtin_path, exclude_files)
modules = []
import_builtins(module_names, modules)

# Get import modules in subdirectories of this directory of Python
# modules that contain Mathics3 Builtin class definitions.

# The files_io module handles local file access, reading and writing..
# In some sandboxed settings, such as running Mathics from as a remote
# server, we disallow local file access.
disable_file_module_names = set() if ENABLE_FILES_MODULE else {"files_io"}

subdirectories = next(os.walk(builtin_path))[1]
import_builtin_subdirectories(subdirectories, disable_file_module_names, modules)

add_builtins_from_builtin_modules(modules)
initialize_display_operators_set()
82 changes: 81 additions & 1 deletion mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@
SymbolTable,
SymbolUndefined,
)
from mathics.eval.arithmetic import eval_Abs, eval_mpmath_function, eval_Sign
from mathics.eval.arithmetic import (
eval_Abs,
eval_mpmath_function,
eval_negate_number,
eval_RealSign,
eval_Sign,
)
from mathics.eval.nevaluator import eval_N
from mathics.eval.numerify import numerify

Expand Down Expand Up @@ -1207,6 +1213,44 @@ class Real_(Builtin):
name = "Real"


class RealAbs(Builtin):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/RealAbs.html</url>
<dl>
<dt>'RealAbs[$x$]'
<dd>returns the absolute value of a real number $x$.
</dl>
'RealAbs' is also known as modulus. It is evaluated if $x$ can be compared \
with $0$.
>> RealAbs[-3.]
= 3.
'RealAbs[$z$]' is left unevaluated for complex $z$:
>> RealAbs[2. + 3. I]
= RealAbs[2. + 3. I]
>> D[RealAbs[x ^ 2], x]
= 2 x ^ 3 / RealAbs[x ^ 2]
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED
rules = {
"D[RealAbs[x_],x_]": "x/RealAbs[x]",
"Integrate[RealAbs[x_],x_]": "1/2 x RealAbs[x]",
"Integrate[RealAbs[u_],{u_,a_,b_}]": "1/2 b RealAbs[b]-1/2 a RealAbs[a]",
}
summary_text = "real absolute value"

def eval(self, x: BaseElement, evaluation: Evaluation):
"""RealAbs[x_]"""
real_sign = eval_RealSign(x)
if real_sign is IntegerM1:
return eval_negate_number(x)
if real_sign is None:
return
return x


class RealNumberQ(Test):
"""
## Not found in WMA
Expand Down Expand Up @@ -1237,6 +1281,42 @@ def test(self, expr) -> bool:
return isinstance(expr, (Integer, Rational, Real))


class RealSign(Builtin):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/RealAbs.html</url>
<dl>
<dt>'RealSign[$x$]'
<dd>returns $-1$, $0$ or $1$ depending on whether $x$ is negative,
zero or positive.
</dl>
'RealSign' is also known as $sgn$ or $signum$ function.
>> RealSign[-3.]
= -1
'RealSign[$z$]' is left unevaluated for complex $z$:
>> RealSign[2. + 3. I]
= RealSign[2. + 3. I]
>> D[RealSign[x^2],x]
= 2 x Piecewise[{{0, x ^ 2 != 0}}, Indeterminate]
>> Integrate[RealSign[u],{u,0,x}]
= RealAbs[x]
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED
rules = {
"D[RealSign[x_],x_]": "Piecewise[{{0, x!=0}}, Indeterminate]",
"Integrate[RealSign[x_],x_]": "RealAbs[x]",
"Integrate[RealSign[u_],{u_, a_, b_}]": "RealAbs[b]-RealSign[a]",
}
summary_text = "real sign"

def eval(self, x: Number, evaluation: Evaluation) -> Optional[Integer]:
"""RealSign[x_]"""
return eval_RealSign(x)


class Sign(SympyFunction):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/Sign.html</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mathics.builtin.base import Builtin

# This tells documentation how to sort this module
sort_order = "mathics.builtin.drawing-options-and-option-values"
sort_order = "mathics.builtin.graphing-and-drawing.drawing-options-and-option-values"


class Automatic(Builtin):
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/drawing/graphics3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class Graphics3D(Graphics):
<dt>'Graphics3D[$primitives$, $options$]'
<dd>represents a three-dimensional graphic.
See also the <url>:Drawing Option and Option Values:
/doc/reference-of-built-in-symbols/drawing-options-and-option-values
See <url>:Drawing Option and Option Values:
/doc/reference-of-built-in-symbols/graphics-and-drawing/drawing-options-and-option-values
</url> for a list of Plot options.
</dl>
Expand Down
20 changes: 4 additions & 16 deletions mathics/builtin/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ class BarChart(_Chart):
<dt>'BarChart[{$b1$, $b2$ ...}]'
<dd>makes a bar chart with lengths $b1$, $b2$, ....
</dl>
Drawing options include -
Charting:
<ul>
Expand Down Expand Up @@ -2563,24 +2564,11 @@ class Plot3D(_Plot3D):
<dd>creates a three-dimensional plot of $f$ with $x$ ranging from $xmin$ to \
$xmax$ and $y$ ranging from $ymin$ to $ymax$.
See <url>:Drawing Option and Option Values:
/doc/reference-of-built-in-symbols/graphics-and-drawing/drawing-options-and-option-values
</url> for a list of Plot options.
</dl>
Plot3D has the same options as <url>:Graphics3D:
/doc/reference-of-built-in-symbols/graphics-and-drawing/three-dimensional-graphics/graphics3d</url>,\
in particular:
<ul>
<li><url>
:Mesh:
/doc/reference-of-built-in-symbols/drawing-options-and-option-values/mesh</url>
<li><url>
:PlotPoints:
/doc/reference-of-built-in-symbols/drawing-options-and-option-values/plotpoints</url>
<li><url>
:MaxRecursion:
/doc/reference-of-built-in-symbols/drawing-options-and-option-values/maxrecursion</url>
</ul>
>> Plot3D[x ^ 2 + 1 / y, {x, -1, 1}, {y, 1, 4}]
= -Graphics3D-
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class All(Predefined):
/doc/reference-of-built-in-symbols/graphics-and-drawing/plotting-data/plot</url>, \
setting the <url>
:Mesh:
/doc/reference-of-built-in-symbols/drawing-options-and-option-values/mesh</url> \
/doc/reference-of-built-in-symbols/graphics-and-drawing/drawing-options-and-option-values/mesh</url> \
option to 'All' will show the specific plot points:
>> Plot[x^2, {x, -1, 1}, MaxRecursion->5, Mesh->All]
Expand Down Expand Up @@ -180,7 +180,7 @@ class None_(Predefined):
Plot3D shows the mesh grid between computed points by default. This the <url>
:Mesh:
/doc/reference-of-built-in-symbols/drawing-options-and-option-values/mesh</url> option.
/doc/reference-of-built-in-symbols/graphics-and-drawing/drawing-options-and-option-values/mesh</url> \
However, you hide the mesh by setting the 'Mesh' option value to 'None':
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class Inner(Builtin):
messages = {
"incom": (
"Length `1` of dimension `2` in `3` is incommensurate with "
"length `4` of dimension 1 in `5."
"length `4` of dimension 1 in `5`."
),
}

Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/testing_expressions/equality_inequality.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def numerify_args(items, evaluation) -> list:
for item in items:
if not isinstance(item, Number):
# TODO: use $MaxExtraPrecision insterad of hard-coded 50
item = eval_N(item, evaluation, SymbolMaxPrecision)
item = eval_N(item, evaluation, SymbolMaxExtraPrecision)
n_items.append(item)
items = n_items
else:
Expand Down
12 changes: 6 additions & 6 deletions mathics/core/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
from mathics.core.convert.expression import to_mathics_list
from mathics.core.element import fully_qualified_symbol_name
from mathics.core.expression import Expression
from mathics.core.load_builtin import definition_contribute
from mathics.core.load_builtin import definition_contribute, mathics3_builtins_modules
from mathics.core.symbols import Atom, Symbol, strip_context
from mathics.core.systemsymbols import SymbolGet
from mathics.settings import ROOT_DIR

type_compiled_pattern = type(re.compile("a.a"))

Expand Down Expand Up @@ -138,12 +139,12 @@ def __init__(
self.timing_trace_evaluation = False

if add_builtin:
from mathics.builtin import modules
from mathics.settings import ROOT_DIR

loaded = False
if builtin_filename is not None:
builtin_dates = [get_file_time(module.__file__) for module in modules]
builtin_dates = [
get_file_time(module.__file__)
for module in mathics3_builtins_modules
]
builtin_time = max(builtin_dates)
if get_file_time(builtin_filename) > builtin_time:
builtin_file = open(builtin_filename, "rb")
Expand Down Expand Up @@ -770,7 +771,6 @@ def __init__(
builtin=None,
is_numeric=False,
) -> None:

super(Definition, self).__init__()
self.name = name

Expand Down
Loading

0 comments on commit b3119c5

Please sign in to comment.