Skip to content

Commit b3f4cc8

Browse files
committed
Correct math.inf. Add test
1 parent 6d440ae commit b3f4cc8

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

mathics/builtin/arithmetic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,8 @@ class I(Predefined):
13401340
= 10
13411341
"""
13421342

1343+
python_equivalent = 1j
1344+
13431345
def evaluate(self, evaluation):
13441346
return Complex(Integer(0), Integer(1))
13451347

mathics/builtin/inout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,7 @@ class PythonForm(Builtin):
19471947
</dl>
19481948
19491949
>> PythonForm[Infinity]
1950-
= inf
1950+
= math.inf
19511951
>> PythonForm[Pi]
19521952
= sympy.pi
19531953
>> E // PythonForm

mathics/core/expression.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,8 @@ def __new__(cls, value):
26352635
self = super(StringFromPython, cls).__new__(cls, value)
26362636
if isinstance(value, sympy.NumberSymbol):
26372637
self.value = "sympy." + str(value)
2638+
elif value == math.inf:
2639+
self.value = "math.inf"
26382640
return self
26392641

26402642

test/test_to_python.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
from .helper import session, check_evaluation
3+
4+
import math
5+
import sympy
6+
import sys
7+
from mathics.core.parser import parse, SingleLineFeeder
8+
from mathics.core.definitions import Definitions
9+
from mathics.core.evaluation import Evaluation
10+
import pytest
11+
12+
13+
def test_to_infinity():
14+
for str_expr, str_expected, message in (
15+
(
16+
"PythonForm[Infinity]",
17+
'"math.inf"',
18+
"Infinity",
19+
),
20+
(
21+
"PythonForm[{1, 2, 3, 4}]",
22+
'"[1, 2, 3, 4]"',
23+
"Simple List of integers",
24+
),
25+
(
26+
"Pi // PythonForm",
27+
'"sympy.pi"',
28+
"Pi",
29+
),
30+
31+
):
32+
check_evaluation(str_expr, str_expected, message)

0 commit comments

Comments
 (0)