Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions mathics/builtin/atomic/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class IntegerLength(Builtin):
def eval(self, n, b, evaluation):
"""IntegerLength[n_, b_]"""

n, b = n.get_int_value(), b.get_int_value()
n, b = n.int_value, b.int_value
if n is None or b is None:
evaluation.message("IntegerLength", "int")
return
Expand Down Expand Up @@ -399,7 +399,7 @@ def eval_rational_with_base(self, n, b, evaluation):
# expr = Expression(SymbolRealDigits, n)
py_n = abs(n.value)
py_b = b.value
if check_finite_decimal(n.denominator().get_int_value()) and not py_b % 2:
if check_finite_decimal(n.denominator().int_value) and not py_b % 2:
return self.eval_with_base(n, b, evaluation)
else:
exp = log_n_b(py_n, py_b)
Expand Down Expand Up @@ -441,7 +441,7 @@ def eval_with_base(self, n, b, evaluation, nr_elements=None, pos=None):
rational_no = (
True if isinstance(n, Rational) else False
) # it is used for checking whether the input n is a rational or not
py_b = b.get_int_value()
py_b = b.int_value
if isinstance(n, (Expression, Symbol, Rational)):
pos_len = abs(pos) + 1 if pos is not None and pos < 0 else 1
if nr_elements is not None:
Expand Down Expand Up @@ -558,12 +558,12 @@ def eval_with_base_and_length(self, n, b, length, evaluation, pos=None):
if pos is not None:
elements.append(from_python(pos))
expr = Expression(SymbolRealDigits, n, b, length, *elements)
if not (isinstance(length, Integer) and length.get_int_value() >= 0):
if not (isinstance(length, Integer) and length.int_value >= 0):
evaluation.message("RealDigits", "intnm", Integer3, expr)
return

return self.eval_with_base(
n, b, evaluation, nr_elements=length.get_int_value(), pos=pos
n, b, evaluation, nr_elements=length.int_value, pos=pos
)

def eval_with_base_length_and_precision(self, n, b, length, p, evaluation):
Expand All @@ -574,9 +574,7 @@ def eval_with_base_length_and_precision(self, n, b, length, p, evaluation):
)
return

return self.eval_with_base_and_length(
n, b, length, evaluation, pos=p.get_int_value()
)
return self.eval_with_base_and_length(n, b, length, evaluation, pos=p.int_value)


class MaxPrecision(Predefined):
Expand Down
10 changes: 5 additions & 5 deletions mathics/builtin/binary/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def eval(self, name, n, b, kind, evaluation):
expr = Expression(SymbolBinaryWrite, channel, b, kind)

# Check channel
stream = stream_manager.lookup_stream(n.get_int_value())
stream = stream_manager.lookup_stream(n.int_value)

if stream is None or stream.io.closed:
evaluation.message("General", "openx", name)
Expand Down Expand Up @@ -661,9 +661,9 @@ def eval(self, name, n, b, kind, evaluation):
if isinstance(x, Real):
x_py = x.to_python()
elif x.has_form(SymbolDirectedInfinity, 1):
if x.elements[0].get_int_value() == 1:
if x.elements[0].int_value == 1:
x_py = float("+inf")
elif x.elements[0].get_int_value() == -1:
elif x.elements[0].int_value == -1:
x_py = float("-inf")
else:
x_py = None
Expand All @@ -689,7 +689,7 @@ def eval(self, name, n, b, kind, evaluation):
x_py = None
elif t.startswith("Character"):
if isinstance(x, Integer):
x_list = [String(char) for char in str(x.get_int_value())]
x_list = [String(char) for char in str(x.int_value)]
pyb = list(chain(pyb[:i], x_list, pyb[i + 1 :]))
x = pyb[i]
assert isinstance(x, String)
Expand All @@ -711,7 +711,7 @@ def eval(self, name, n, b, kind, evaluation):
assert isinstance(x, String)
x_py = ord(x.value)
else:
x_py = x.get_int_value()
x_py = x.int_value

if x_py is None:
evaluation.message(SymbolBinaryWrite, "nocoerce", b)
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/box/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def init(self, graphics, style, item, options):
spline_degree = options.get("System`SplineDegree")
if not isinstance(spline_degree, Integer):
raise BoxExpressionError
self.spline_degree = spline_degree.get_int_value()
self.spline_degree = spline_degree.int_value


class CircleBox(ArcBox):
Expand Down Expand Up @@ -548,7 +548,7 @@ def parse_component(segments):
spline_degree = options.get("SplineDegree", Integer(3))
if not isinstance(spline_degree, Integer):
raise BoxExpressionError
k = spline_degree.get_int_value()
k = spline_degree.int_value
elif head == "System`BSplineCurve":
raise NotImplementedError # FIXME convert bspline to bezier here
# parts = segment.elements
Expand Down Expand Up @@ -864,7 +864,7 @@ def init(self, graphics, style, item):
x = pos.elements[0].round_to_float()
y = pos.elements[1].round_to_float()

n = item.elements[-1].get_int_value()
n = item.elements[-1].int_value

if any(t is None for t in (x, y, r)) or n < 0:
raise BoxExpressionError
Expand Down
18 changes: 4 additions & 14 deletions mathics/builtin/colors/color_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,23 +372,13 @@ def compute(c1, c2):
distance_function.elements[1].elements[1], Integer
):
if (
distance_function.elements[1].elements[0].get_int_value()
> 0
and distance_function.elements[1]
.elements[1]
.get_int_value()
> 0
distance_function.elements[1].elements[0].int_value > 0
and distance_function.elements[1].elements[1].int_value > 0
):
lightness = (
distance_function.elements[1]
.elements[0]
.get_int_value()
)
chroma = (
distance_function.elements[1]
.elements[1]
.get_int_value()
distance_function.elements[1].elements[0].int_value
)
chroma = distance_function.elements[1].elements[1].int_value

def compute(c1, c2):
return (
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/distance/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _cluster(self, p, k, mode, evaluation, options, expr):
if not isinstance(k, Integer):
evaluation.message(self.get_name(), "intpm", expr)
return
py_k = k.get_int_value()
py_k = k.int_value
if py_k < 1:
evaluation.message(self.get_name(), "intpm", expr)
return
Expand All @@ -131,7 +131,7 @@ def _cluster(self, p, k, mode, evaluation, options, expr):
if seed_string == "Automatic":
py_seed = 12345
elif isinstance(seed, Integer):
py_seed = seed.get_int_value()
py_seed = seed.int_value
else:
evaluation.message(
self.get_name(), "rseed", Expression(SymbolRule, "RandomSeed", seed)
Expand Down Expand Up @@ -447,7 +447,7 @@ def eval(
py_r = None

if isinstance(up_to, Integer):
py_n = up_to.get_int_value()
py_n = up_to.int_value
elif up_to.get_name() == "System`All":
py_n = None
else:
Expand Down
4 changes: 1 addition & 3 deletions mathics/builtin/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ def graphics(distributions):

def manual_bins(bspec, hspec):
if isinstance(bspec, Integer):
distributions = [
Distribution(data, bspec.get_int_value()) for data in matrix
]
distributions = [Distribution(data, bspec.int_value) for data in matrix]
return graphics(distributions)
elif bspec.get_head_name() == "System`List" and len(bspec.elements) == 1:
bin_width = bspec[0].to_mpmath()
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/exp_structure/head_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Operate(Builtin):
def eval(self, p, expr, n, evaluation: Evaluation):
"Operate[p_, expr_, Optional[n_, 1]]"

head_depth = n.get_int_value()
head_depth = n.int_value
if head_depth is None or head_depth < 0:
evaluation.message(
"Operate", "intnn", Expression(SymbolOperate, p, expr, n), 3
Expand Down
14 changes: 6 additions & 8 deletions mathics/builtin/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def eval(self, exprs, filename, evaluation: Evaluation):

def eval_input(self, exprs, name, n, evaluation: Evaluation):
"Put[exprs___, OutputStream[name_, n_]]"
stream = stream_manager.lookup_stream(n.get_int_value())
stream = stream_manager.lookup_stream(n.int_value)

if stream is None or stream.io.closed:
evaluation.message("Put", "openx", evaluation.current_expression)
Expand Down Expand Up @@ -799,7 +799,7 @@ def eval(self, exprs, filename, evaluation):

def eval_input(self, exprs, name, n, evaluation: Evaluation):
"PutAppend[exprs___, OutputStream[name_, n_]]"
stream = stream_manager.lookup_stream(n.get_int_value())
stream = stream_manager.lookup_stream(n.int_value)

if stream is None or stream.io.closed:
evaluation.message("Put", "openx", evaluation.current_expression)
Expand Down Expand Up @@ -1258,7 +1258,7 @@ class StreamPosition(Builtin):

def eval_input(self, name, n, evaluation):
"StreamPosition[InputStream[name_, n_]]"
stream = stream_manager.lookup_stream(n.get_int_value())
stream = stream_manager.lookup_stream(n.int_value)

if stream is None or stream.io is None or stream.io.closed:
evaluation.message("General", "openx", name)
Expand Down Expand Up @@ -1317,7 +1317,7 @@ class SetStreamPosition(Builtin):

def eval_input(self, name, n, m, evaluation):
"SetStreamPosition[InputStream[name_, n_], m_]"
stream = stream_manager.lookup_stream(n.get_int_value())
stream = stream_manager.lookup_stream(n.int_value)

if stream is None or stream.io is None or stream.io.closed:
evaluation.message("General", "openx", name)
Expand Down Expand Up @@ -1671,7 +1671,7 @@ def eval(self, channel, expr, evaluation):
strm = channel_to_stream(channel, "w")
if strm is None:
return
stream = stream_manager.lookup_stream(strm.elements[1].get_int_value())
stream = stream_manager.lookup_stream(strm.elements[1].int_value)

if stream is None or stream.io is None or stream.io.closed:
evaluation.message("General", "openx", channel)
Expand Down Expand Up @@ -1740,9 +1740,7 @@ def eval(self, channel, expr, evaluation: Evaluation):
stream_expr = channel_to_stream(channel, "w")
if stream_expr is None:
return
stream = stream_manager.lookup_stream(
stream_expr.elements[1].get_int_value()
)
stream = stream_manager.lookup_stream(stream_expr.elements[1].int_value)
else:
evaluation.message("WriteString", "strml", channel)
return
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/files_io/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def eval(self, filename, evaluation: Evaluation, options: dict):

def eval_n(self, filename, n, evaluation: Evaluation, options: dict):
"FileNameTake[filename_String, n_Integer, OptionsPattern[FileBaseName]]"
n_int = n.get_int_value()
n_int = n.int_value
parts = pathlib.Path(filename.to_python()[1:-1]).parts
if n_int >= 0:
subparts = parts[:n_int]
Expand Down
25 changes: 15 additions & 10 deletions mathics/builtin/forms/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@

from mathics.builtin.box.layout import RowBox, StyleBox, SuperscriptBox
from mathics.builtin.forms.base import FormBaseClass
from mathics.core.atoms import Integer, Real, String
from mathics.core.atoms import Integer, Real, String, get_int_value
from mathics.core.builtin import Builtin
from mathics.core.element import BaseElement
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.number import dps
from mathics.core.symbols import Atom, Symbol, SymbolFalse, SymbolNull, SymbolTrue
from mathics.core.systemsymbols import SymbolAutomatic, SymbolInfinity, SymbolMakeBoxes
from mathics.core.systemsymbols import (
SymbolAutomatic,
SymbolInfinity,
SymbolList,
SymbolMakeBoxes,
)
from mathics.eval.strings import eval_StringForm_MakeBoxes, eval_ToString
from mathics.format.box import (
StringLParen,
Expand Down Expand Up @@ -175,14 +180,14 @@ def check_DigitBlock(self, value, evaluation: Evaluation) -> Optional[List[int]]
at the left and right of the decimal separator. `None` otherwise.

"""
py_value = value.get_int_value()
py_value = get_int_value(value)
if value.sameQ(SymbolInfinity):
return [0, 0]
if py_value is not None and py_value > 0:
return [py_value, py_value]
if value.has_form("List", 2):
if value.has_form(SymbolList, 2):
nleft, nright = value.elements
py_left, py_right = nleft.get_int_value(), nright.get_int_value()
py_left, py_right = nleft.int_value, nright.int_value
if nleft.sameQ(SymbolInfinity):
nleft = 0
elif py_left is not None and py_left > 0:
Expand Down Expand Up @@ -327,7 +332,7 @@ def check_ExponentStep(
If the value is valid, the value of the option. `None` otherwise.

"""
result = value.get_int_value()
result = value.int_value
if result is None or result <= 0:
evaluation.message(self.get_name(), "estep", "ExponentStep", value)
return None
Expand Down Expand Up @@ -363,7 +368,7 @@ def check_SignPadding(
def _check_List2str(
self, value, msg, evaluation: Evaluation
) -> Optional[List[str]]:
if value.has_form("List", 2):
if value.has_form(SymbolList, 2):
result = [element.get_string_value() for element in value.elements]
if None not in result:
return result
Expand Down Expand Up @@ -522,7 +527,7 @@ class NumberForm(_NumberForm):
def default_ExponentFunction(value: Integer):
"""The default function used to format exponent."""

n = value.get_int_value()
n = value.int_value
if -5 <= n <= 5:
return SymbolNull

Expand Down Expand Up @@ -575,7 +580,7 @@ def eval_makeboxes(self, fexpr, form, evaluation):
py_f = py_n = None
if prec_parms is None:
if isinstance(target, Integer):
py_n = len(str(abs(target.get_int_value())))
py_n = len(str(abs(target.int_value)))
elif isinstance(target, Real):
if target.is_machine_precision():
py_n = 6
Expand All @@ -584,7 +589,7 @@ def eval_makeboxes(self, fexpr, form, evaluation):
elif isinstance(prec_parms, Integer):
if isinstance(target, (Integer, Real)):
py_n = prec_parms.value
elif prec_parms.has_form("List", 2):
elif prec_parms.has_form(SymbolList, 2):
if isinstance(target, (Integer, Real)):
n, f = prec_parms.elements
py_n = n.value
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/functional/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class Slot(SympyFunction, PrefixOperator):

def to_sympy(self, expr: Expression, **kwargs):
index: Integer = expr.elements[0]
return sympy.Symbol(f"{SYMPY_SLOT_PREFIX}{index.get_int_value()}")
return sympy.Symbol(f"{SYMPY_SLOT_PREFIX}{index.int_value}")


class SlotSequence(PrefixOperator, Builtin):
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/functional/apply_fns_to_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dataclasses import replace as dc_replace
from typing import Iterable

from mathics.core.atoms import Integer, Integer0, Integer1, Integer3
from mathics.core.atoms import Integer, Integer0, Integer1, Integer3, get_int_value
from mathics.core.builtin import Builtin, InfixOperator
from mathics.core.convert.expression import to_mathics_list
from mathics.core.evaluation import Evaluation
Expand Down Expand Up @@ -384,7 +384,7 @@ def eval_n(self, f, expr, n, evaluation):
full_expr = Expression(SymbolMapThread, f, expr)
else:
full_expr = Expression(SymbolMapThread, f, expr, n)
n = n.get_int_value()
n = get_int_value(n)

if n is None or n < 0:
evaluation.message("MapThread", "intnm", Integer3, full_expr)
Expand Down
Loading
Loading