From f7e781d50b43f245511850162e21887c49fc3d0a Mon Sep 17 00:00:00 2001 From: Stanislav Date: Fri, 16 Oct 2026 01:25:32 +0400 Subject: [PATCH 1/3] EvenQ, OddQ, PrimeQ: use get_int_value() so non-atoms give False Since #1934 only atoms have an int_value property, so EvenQ[f[1]] and patterns such as _?EvenQ raised AttributeError on any expression. Co-Authored-By: Claude Opus 5.5 --- .../builtin/testing_expressions/numerical_properties.py | 8 ++++---- test/builtin/test_testing_expressions.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mathics/builtin/testing_expressions/numerical_properties.py b/mathics/builtin/testing_expressions/numerical_properties.py index 6b6612ee5c..4d9a59ca2d 100644 --- a/mathics/builtin/testing_expressions/numerical_properties.py +++ b/mathics/builtin/testing_expressions/numerical_properties.py @@ -12,7 +12,7 @@ from mathics.core.convert.python import from_bool, from_python from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression -from mathics.core.number import is_machine_precision, is_numeric +from mathics.core.number import get_int_value, is_machine_precision, is_numeric from mathics.core.symbols import BooleanType, SymbolFalse, SymbolTrue from mathics.core.systemsymbols import SymbolExpandAll, SymbolSimplify from mathics.eval.arithmetic import test_zero_arithmetic_expr @@ -99,7 +99,7 @@ class EvenQ(Test): summary_text = "test whether elements are even numbers" def test(self, n) -> bool: - value = n.int_value + value = get_int_value(n) return value is not None and value % 2 == 0 @@ -408,7 +408,7 @@ class OddQ(Test): summary_text = "test whether elements are odd numbers" def test(self, n) -> bool: - value = n.int_value + value = get_int_value(n) return value is not None and value % 2 != 0 @@ -557,7 +557,7 @@ class PrimeQ(SympyFunction): def eval(self, n, evaluation: Evaluation) -> BooleanType: "PrimeQ[n_]" - n = n.int_value + n = get_int_value(n) if n is None: return SymbolFalse diff --git a/test/builtin/test_testing_expressions.py b/test/builtin/test_testing_expressions.py index 4dd16437f6..e48e6b2e53 100644 --- a/test/builtin/test_testing_expressions.py +++ b/test/builtin/test_testing_expressions.py @@ -134,6 +134,12 @@ def test_equality_inequality(str_expr, msgs, str_expected, fail_msg): ("Positive[Sin[{11, 14}]]", None, "{False, True}", None), ("PrimeQ[1]", None, "False", None), ("PrimeQ[2 ^ 255 - 1]", None, "False", None), + # Non-atomic arguments + ("EvenQ[f[2]]", None, "False", None), + ("OddQ[f[1]]", None, "False", None), + ("PrimeQ[f[2]]", None, "False", None), + ("MatchQ[f[2], _?EvenQ]", None, "False", None), + ("Cases[{2, f[2], 3}, _?OddQ]", None, "{3}", None), ], ) def test_numerical_properties(str_expr, msgs, str_expected, fail_msg): From a31c8abb3adf5588ce42dfe4c61aa547f9f2cfdf Mon Sep 17 00:00:00 2001 From: "R. Bernstein" Date: Fri, 16 Oct 2026 09:34:23 -0400 Subject: [PATCH 2/3] Apply batched suggestions from code review Add assert failure messages in new tests. Co-authored-by: R. Bernstein --- test/builtin/test_testing_expressions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/builtin/test_testing_expressions.py b/test/builtin/test_testing_expressions.py index e48e6b2e53..eba7c14e25 100644 --- a/test/builtin/test_testing_expressions.py +++ b/test/builtin/test_testing_expressions.py @@ -135,9 +135,9 @@ def test_equality_inequality(str_expr, msgs, str_expected, fail_msg): ("PrimeQ[1]", None, "False", None), ("PrimeQ[2 ^ 255 - 1]", None, "False", None), # Non-atomic arguments - ("EvenQ[f[2]]", None, "False", None), - ("OddQ[f[1]]", None, "False", None), - ("PrimeQ[f[2]]", None, "False", None), + ("EvenQ[f[2]]", None, "False", "Non-atomic EvenQ check"), + ("OddQ[f[1]]", None, "False", "Non-atomic OddQ check") + ("PrimeQ[f[2]]", None, "False", "Non-atomic PrimeQ check"), ("MatchQ[f[2], _?EvenQ]", None, "False", None), ("Cases[{2, f[2], 3}, _?OddQ]", None, "{3}", None), ], From 9c84303caef7b893fe5e1d74b41a4fca35ea4264 Mon Sep 17 00:00:00 2001 From: "R. Bernstein" Date: Fri, 16 Oct 2026 09:51:52 -0400 Subject: [PATCH 3/3] Apply batched suggestions from code review Co-authored-by: R. Bernstein --- test/builtin/test_testing_expressions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/builtin/test_testing_expressions.py b/test/builtin/test_testing_expressions.py index eba7c14e25..7c25af60fb 100644 --- a/test/builtin/test_testing_expressions.py +++ b/test/builtin/test_testing_expressions.py @@ -135,9 +135,9 @@ def test_equality_inequality(str_expr, msgs, str_expected, fail_msg): ("PrimeQ[1]", None, "False", None), ("PrimeQ[2 ^ 255 - 1]", None, "False", None), # Non-atomic arguments - ("EvenQ[f[2]]", None, "False", "Non-atomic EvenQ check"), - ("OddQ[f[1]]", None, "False", "Non-atomic OddQ check") - ("PrimeQ[f[2]]", None, "False", "Non-atomic PrimeQ check"), + ("EvenQ[f[2]]", None, "False", "Non-atomic EvenQ check"), + ("OddQ[f[1]]", None, "False", "Non-atomic OddQ check"), + ("PrimeQ[f[2]]", None, "False", "Non-atomic PrimeQ check"), ("MatchQ[f[2], _?EvenQ]", None, "False", None), ("Cases[{2, f[2], 3}, _?OddQ]", None, "{3}", None), ],