* Update to version 7.0.0. * Disable whole swathe of failing tests (gh#Mathics3/mathics-core#1346). * Add python-Mathics-sympy1_13.patch -- Add compatibility for tests against sympy >= 1.13 (upstream commits). * Switch to pyproject_* macros for build. * Require numpy < 2 as numpy2 is not supported yet. * BuildArch: noarch as there are no arch dependent binaries in package. * Enable Python 3.11, 3.12. * Disable Python 3.13. * Drop old compatibility macro redefinition. OBS-URL: https://build.opensuse.org/request/show/1242224 OBS-URL: https://build.opensuse.org/package/show/science/python-Mathics?expand=0&rev=42
225 lines
8.9 KiB
Diff
225 lines
8.9 KiB
Diff
From ef8a0ceeb213e5dd26a0dba8ec50b66c44c69c56 Mon Sep 17 00:00:00 2001
|
|
From: Juan Mauricio Matera <matera@fisica.unlp.edu.ar>
|
|
Date: Tue, 20 Aug 2024 09:18:51 -0300
|
|
Subject: [PATCH] fix tests for sympy conversions (#1073)
|
|
|
|
This PR just fixes the pytest, and marks some issues in the conversion
|
|
of Lambda functions.
|
|
|
|
---------
|
|
|
|
Co-authored-by: rocky <rb@dustyfeet.com>
|
|
---
|
|
mathics/core/symbols.py | 4 +-
|
|
test/core/test_sympy_python_convert.py | 71 +++++++++++++++++---------
|
|
2 files changed, 49 insertions(+), 26 deletions(-)
|
|
|
|
Index: Mathics3-7.0.0/mathics/core/symbols.py
|
|
===================================================================
|
|
--- Mathics3-7.0.0.orig/mathics/core/symbols.py
|
|
+++ Mathics3-7.0.0/mathics/core/symbols.py
|
|
@@ -14,8 +14,8 @@ from mathics.core.element import (
|
|
# I put this constants here instead of inside `mathics.core.convert.sympy`
|
|
# to avoid a circular reference. Maybe they should be in its own module.
|
|
|
|
-sympy_symbol_prefix = "_Mathics_User_"
|
|
-sympy_slot_prefix = "_Mathics_Slot_"
|
|
+sympy_symbol_prefix = "_mu_"
|
|
+sympy_slot_prefix = "_ms_"
|
|
|
|
|
|
# FIXME: This is repeated below
|
|
Index: Mathics3-7.0.0/test/core/test_sympy_python_convert.py
|
|
===================================================================
|
|
--- Mathics3-7.0.0.orig/test/core/test_sympy_python_convert.py
|
|
+++ Mathics3-7.0.0/test/core/test_sympy_python_convert.py
|
|
@@ -20,32 +20,39 @@ from mathics.core.convert.python import
|
|
from mathics.core.convert.sympy import from_sympy
|
|
from mathics.core.expression import Expression
|
|
from mathics.core.list import ListExpression
|
|
-from mathics.core.symbols import Symbol, SymbolPlus
|
|
+from mathics.core.symbols import (
|
|
+ Symbol,
|
|
+ SymbolPlus,
|
|
+ sympy_slot_prefix,
|
|
+ sympy_symbol_prefix,
|
|
+)
|
|
from mathics.core.systemsymbols import (
|
|
SymbolD,
|
|
SymbolDerivative,
|
|
+ SymbolFunction,
|
|
SymbolGamma,
|
|
SymbolIntegrate,
|
|
SymbolSin,
|
|
+ SymbolSlot,
|
|
)
|
|
|
|
|
|
class SympyConvert(unittest.TestCase):
|
|
def compare_to_sympy(self, mathics_expr, sympy_expr, **kwargs):
|
|
- mathics_expr.to_sympy(**kwargs) == sympy_expr
|
|
+ assert mathics_expr.to_sympy(**kwargs) == sympy_expr
|
|
|
|
def compare_to_mathics(self, mathics_expr, sympy_expr, **kwargs):
|
|
- mathics_expr == from_sympy(sympy_expr, **kwargs)
|
|
+ assert mathics_expr == from_sympy(sympy_expr, **kwargs)
|
|
|
|
def compare(self, mathics_expr, sympy_expr, **kwargs):
|
|
self.compare_to_sympy(mathics_expr, sympy_expr, **kwargs)
|
|
self.compare_to_mathics(mathics_expr, sympy_expr)
|
|
|
|
def testSymbol(self):
|
|
- self.compare(Symbol("Global`x"), sympy.Symbol("_Mathics_User_Global`x"))
|
|
+ self.compare(Symbol("Global`x"), sympy.Symbol(f"{sympy_symbol_prefix}Global`x"))
|
|
self.compare(
|
|
Symbol("_Mathics_User_x"),
|
|
- sympy.Symbol("_Mathics_User_System`_Mathics_User_x"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}System`_Mathics_User_x"),
|
|
)
|
|
|
|
def testReal(self):
|
|
@@ -81,15 +88,15 @@ class SympyConvert(unittest.TestCase):
|
|
def testAdd(self):
|
|
self.compare(
|
|
Expression(SymbolPlus, Integer1, Symbol("Global`x")),
|
|
- sympy.Add(sympy.Integer(1), sympy.Symbol("_Mathics_User_Global`x")),
|
|
+ sympy.Add(sympy.Integer(1), sympy.Symbol(f"{sympy_symbol_prefix}Global`x")),
|
|
)
|
|
|
|
def testIntegrate(self):
|
|
self.compare(
|
|
Expression(SymbolIntegrate, Symbol("Global`x"), Symbol("Global`y")),
|
|
sympy.Integral(
|
|
- sympy.Symbol("_Mathics_User_Global`x"),
|
|
- sympy.Symbol("_Mathics_User_Global`y"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`x"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`y"),
|
|
),
|
|
)
|
|
|
|
@@ -97,8 +104,8 @@ class SympyConvert(unittest.TestCase):
|
|
self.compare(
|
|
Expression(SymbolD, Symbol("Global`x"), Symbol("Global`y")),
|
|
sympy.Derivative(
|
|
- sympy.Symbol("_Mathics_User_Global`x"),
|
|
- sympy.Symbol("_Mathics_User_Global`y"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`x"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`y"),
|
|
),
|
|
)
|
|
|
|
@@ -111,11 +118,13 @@ class SympyConvert(unittest.TestCase):
|
|
)
|
|
expr = Expression(head, Symbol("Global`x"), Symbol("Global`y"))
|
|
|
|
- sfxy = sympy.Function(str("_Mathics_User_Global`f"))(
|
|
- sympy.Symbol("_Mathics_User_Global`x"),
|
|
- sympy.Symbol("_Mathics_User_Global`y"),
|
|
+ sfxy = sympy.Function(str(f"{sympy_symbol_prefix}Global`f"))(
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`x"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`y"),
|
|
+ )
|
|
+ sym_expr = sympy.Derivative(
|
|
+ sfxy, sympy.Symbol(f"{sympy_symbol_prefix}Global`x")
|
|
)
|
|
- sym_expr = sympy.Derivative(sfxy, sympy.Symbol("_Mathics_User_Global`x"))
|
|
|
|
self.compare_to_sympy(expr, sym_expr, **kwargs)
|
|
# compare_to_mathics fails because Derivative becomes D (which then evaluates to Derivative)
|
|
@@ -124,28 +133,28 @@ class SympyConvert(unittest.TestCase):
|
|
kwargs = {"converted_functions": set(["Global`f"])}
|
|
|
|
marg1 = Expression(Symbol("Global`f"), Symbol("Global`x"))
|
|
- sarg1 = sympy.Function(str("_Mathics_User_Global`f"))(
|
|
- sympy.Symbol("_Mathics_User_Global`x")
|
|
+ sarg1 = sympy.Function(str(f"{sympy_symbol_prefix}Global`f"))(
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`x")
|
|
)
|
|
self.compare(marg1, sarg1, **kwargs)
|
|
|
|
marg2 = Expression(Symbol("Global`f"), Symbol("Global`x"), Symbol("Global`y"))
|
|
- sarg2 = sympy.Function(str("_Mathics_User_Global`f"))(
|
|
- sympy.Symbol("_Mathics_User_Global`x"),
|
|
- sympy.Symbol("_Mathics_User_Global`y"),
|
|
+ sarg2 = sympy.Function(str(f"{sympy_symbol_prefix}Global`f"))(
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`x"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`y"),
|
|
)
|
|
self.compare(marg2, sarg2, **kwargs)
|
|
|
|
self.compare(
|
|
Expression(SymbolD, marg2, Symbol("Global`x")),
|
|
- sympy.Derivative(sarg2, sympy.Symbol("_Mathics_User_Global`x")),
|
|
+ sympy.Derivative(sarg2, sympy.Symbol(f"{sympy_symbol_prefix}Global`x")),
|
|
**kwargs,
|
|
)
|
|
|
|
def testExpression(self):
|
|
self.compare(
|
|
Expression(SymbolSin, Symbol("Global`x")),
|
|
- sympy.sin(sympy.Symbol("_Mathics_User_Global`x")),
|
|
+ sympy.sin(sympy.Symbol(f"{sympy_symbol_prefix}Global`x")),
|
|
)
|
|
|
|
def testConstant(self):
|
|
@@ -155,14 +164,28 @@ class SympyConvert(unittest.TestCase):
|
|
def testGamma(self):
|
|
self.compare(
|
|
Expression(SymbolGamma, Symbol("Global`z")),
|
|
- sympy.gamma(sympy.Symbol("_Mathics_User_Global`z")),
|
|
+ sympy.gamma(sympy.Symbol(f"{sympy_symbol_prefix}Global`z")),
|
|
)
|
|
self.compare(
|
|
Expression(SymbolGamma, Symbol("Global`z"), Symbol("Global`x")),
|
|
sympy.uppergamma(
|
|
- sympy.Symbol("_Mathics_User_Global`z"),
|
|
- sympy.Symbol("_Mathics_User_Global`x"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`z"),
|
|
+ sympy.Symbol(f"{sympy_symbol_prefix}Global`x"),
|
|
+ ),
|
|
+ )
|
|
+
|
|
+ def testSlots(self):
|
|
+ """check the conversion of slots in anonymous functions."""
|
|
+ sympy_symbol = sympy.Symbol("x")
|
|
+ sympy_lambda_expr = sympy.Lambda(sympy_symbol, sympy_symbol + 1)
|
|
+ # compare_to_sympy does not pass because Slot[1] are translated as
|
|
+ # functions
|
|
+ self.compare_to_mathics(
|
|
+ Expression(
|
|
+ SymbolFunction,
|
|
+ Expression(SymbolPlus, Integer1, Expression(SymbolSlot, Integer1)),
|
|
),
|
|
+ sympy_lambda_expr,
|
|
)
|
|
|
|
|
|
Index: Mathics3-7.0.0/mathics/builtin/testing_expressions/numerical_properties.py
|
|
===================================================================
|
|
--- Mathics3-7.0.0.orig/mathics/builtin/testing_expressions/numerical_properties.py
|
|
+++ Mathics3-7.0.0/mathics/builtin/testing_expressions/numerical_properties.py
|
|
@@ -42,8 +42,8 @@ class CoprimeQ(Builtin):
|
|
## CoprimeQ also works for complex numbers
|
|
## >> CoprimeQ[1+2I, 1-I]
|
|
## = True
|
|
-
|
|
- ## This test case is commenteted out because the result produced by sympy is wrong:
|
|
+
|
|
+ ## This test case is commented out because the result produced by sympy is wrong:
|
|
## In this case, both numbers can be factorized as 2 (2 + I) and 3 (2 + I):
|
|
## >> CoprimeQ[4+2I, 6+3I]
|
|
## = False
|
|
Index: Mathics3-7.0.0/pyproject.toml
|
|
===================================================================
|
|
--- Mathics3-7.0.0.orig/pyproject.toml
|
|
+++ Mathics3-7.0.0/pyproject.toml
|
|
@@ -23,7 +23,7 @@ dependencies = [
|
|
"python-dateutil",
|
|
"requests",
|
|
"setuptools",
|
|
- "sympy>=1.11,<1.13",
|
|
+ "sympy>=1.11,<1.14",
|
|
]
|
|
license = {text = "GPL"}
|
|
name = "Mathics3"
|