diff --git a/.github/workflows/consistency-checks.yml b/.github/workflows/consistency-checks.yml index 8bc300226..03dada2f0 100644 --- a/.github/workflows/consistency-checks.yml +++ b/.github/workflows/consistency-checks.yml @@ -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 diff --git a/.github/workflows/isort-and-black-checks.yml b/.github/workflows/isort-and-black-checks.yml index ab890f67d..37cde2a21 100644 --- a/.github/workflows/isort-and-black-checks.yml +++ b/.github/workflows/isort-and-black-checks.yml @@ -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 diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 01fa611f1..09d594949 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -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 diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 840c1a618..e32d9b54b 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -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 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index be286d35b..d2a6bc21e 100755 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -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 diff --git a/.gitignore b/.gitignore index ccd7736f5..2d93eb961 100644 --- a/.gitignore +++ b/.gitignore @@ -14,9 +14,10 @@ .settings .vscode /.cache +/.gdbinit /.python-version -/Mathics3.egg-info /Mathics.egg-info +/Mathics3.egg-info ChangeLog Documents/ Homepage/ @@ -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 diff --git a/CHANGES.rst b/CHANGES.rst index 76238a823..6bfe2990d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,7 +9,7 @@ New Builtins * `Elements` - +* `RealAbs` and `RealSign` Compatibility ------------- @@ -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 ---- diff --git a/SYMBOLS_MANIFEST.txt b/SYMBOLS_MANIFEST.txt index 1bf18d1ea..d3ecf4204 100644 --- a/SYMBOLS_MANIFEST.txt +++ b/SYMBOLS_MANIFEST.txt @@ -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 diff --git a/admin-tools/build_and_check_manifest.py b/admin-tools/build_and_check_manifest.py index 9057a0f34..0feb64af9 100755 --- a/admin-tools/build_and_check_manifest.py +++ b/admin-tools/build_and_check_manifest.py @@ -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(): diff --git a/examples/symbolic_logic/gries_schneider/test_gs.py b/examples/symbolic_logic/gries_schneider/test_gs.py index 7212ec8ee..19cd96d03 100644 --- a/examples/symbolic_logic/gries_schneider/test_gs.py +++ b/examples/symbolic_logic/gries_schneider/test_gs.py @@ -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): diff --git a/mathics/builtin/__init__.py b/mathics/builtin/__init__.py index 946d024ba..efb232604 100755 --- a/mathics/builtin/__init__.py +++ b/mathics/builtin/__init__.py @@ -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() diff --git a/mathics/builtin/arithmetic.py b/mathics/builtin/arithmetic.py index d54f8f7bd..51980d633 100644 --- a/mathics/builtin/arithmetic.py +++ b/mathics/builtin/arithmetic.py @@ -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 @@ -1207,6 +1213,44 @@ class Real_(Builtin): name = "Real" +class RealAbs(Builtin): + """ + :WMA link:https://reference.wolfram.com/language/ref/RealAbs.html + +
+
'RealAbs[$x$]' +
returns the absolute value of a real number $x$. +
+ '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 @@ -1237,6 +1281,42 @@ def test(self, expr) -> bool: return isinstance(expr, (Integer, Rational, Real)) +class RealSign(Builtin): + """ + :WMA link:https://reference.wolfram.com/language/ref/RealAbs.html + +
+
'RealSign[$x$]' +
returns $-1$, $0$ or $1$ depending on whether $x$ is negative, + zero or positive. +
+ '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): """ :WMA link:https://reference.wolfram.com/language/ref/Sign.html diff --git a/mathics/builtin/optiondoc.py b/mathics/builtin/drawing/drawing_options.py similarity index 99% rename from mathics/builtin/optiondoc.py rename to mathics/builtin/drawing/drawing_options.py index a4d3592f1..5b88f680c 100644 --- a/mathics/builtin/optiondoc.py +++ b/mathics/builtin/drawing/drawing_options.py @@ -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): diff --git a/mathics/builtin/drawing/graphics3d.py b/mathics/builtin/drawing/graphics3d.py index 5244b6dda..f50ac9bae 100644 --- a/mathics/builtin/drawing/graphics3d.py +++ b/mathics/builtin/drawing/graphics3d.py @@ -69,8 +69,8 @@ class Graphics3D(Graphics):
'Graphics3D[$primitives$, $options$]'
represents a three-dimensional graphic. - See also the :Drawing Option and Option Values: - /doc/reference-of-built-in-symbols/drawing-options-and-option-values + See :Drawing Option and Option Values: + /doc/reference-of-built-in-symbols/graphics-and-drawing/drawing-options-and-option-values for a list of Plot options. diff --git a/mathics/builtin/drawing/plot.py b/mathics/builtin/drawing/plot.py index d641cfa06..87789651c 100644 --- a/mathics/builtin/drawing/plot.py +++ b/mathics/builtin/drawing/plot.py @@ -1100,6 +1100,7 @@ class BarChart(_Chart):
'BarChart[{$b1$, $b2$ ...}]'
makes a bar chart with lengths $b1$, $b2$, .... + Drawing options include - Charting: