Skip to content

Commit

Permalink
Merge branch 'master' into combinatorica-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera authored May 8, 2022
2 parents 02a71a0 + e772d09 commit 8e38bd4
Show file tree
Hide file tree
Showing 39 changed files with 671 additions and 401 deletions.
4 changes: 2 additions & 2 deletions mathics/algorithm/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def rec(cur, rest):
raise PartDepthError
try:
if pos > 0:
part = cur._elements[pos - 1]
part = cur.elements[pos - 1]
elif pos == 0:
part = cur.get_head()
else:
part = cur._elements[pos]
part = cur.elements[pos]
except IndexError:
raise PartRangeError
return rec(part, rest[1:])
Expand Down
2 changes: 1 addition & 1 deletion mathics/algorithm/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def series_times_series(series1, series2):
data[pos] = Expression(SymbolTimes, c1, c2)
elif data[pos].get_head() is SymbolPlus:
data[pos] = Expression(
SymbolPlus, Expression(SymbolTimes, c1, c2), *(data[pos]._elements)
SymbolPlus, Expression(SymbolTimes, c1, c2), *(data[pos].elements)
)
else:
data[pos] = Expression(
Expand Down
8 changes: 4 additions & 4 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ class DirectedInfinity(SympyFunction):
}

def to_sympy(self, expr, **kwargs):
if len(expr._elements) == 1:
if len(expr.elements) == 1:
dir = expr.leaves[0].get_int_value()
if dir == 1:
return sympy.oo
elif dir == -1:
return -sympy.oo
else:
return sympy.Mul((expr._elements[0].to_sympy()), sympy.zoo)
return sympy.Mul((expr.elements[0].to_sympy()), sympy.zoo)
else:
return sympy.zoo

Expand Down Expand Up @@ -1283,7 +1283,7 @@ def apply_assuming(self, assumptions, expr, evaluation):
elif isinstance(assumptions, Symbol) or not assumptions.has_form("List", None):
cond = [assumptions]
else:
cond = assumptions._elements
cond = assumptions.elements
cond = tuple(cond) + get_assumptions_list(evaluation)
list_cond = Expression("List", *cond)
# TODO: reduce the list of predicates
Expand Down Expand Up @@ -1339,7 +1339,7 @@ def apply_generic(self, expr, cond, evaluation):
# cond as a predicate, using assumptions.
# Let's delegate this to the And (and Or) symbols...
if not isinstance(cond, Atom) and cond._head is SymbolList:
cond = Expression("System`And", *(cond._elements))
cond = Expression("System`And", *(cond.elements))
else:
cond = Expression("System`And", cond)
if cond is None:
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/assignments/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def unroll_patterns(lhs, rhs, evaluation):
if isinstance(lhs, Atom):
return lhs, rhs
name = lhs.get_head_name()
lhs_elements = lhs._elements
lhs_elements = lhs.elements
if name == "System`Pattern":
lhs = lhs_elements[1]
rulerepl = (lhs_elements[0], repl_pattern_by_symbol(lhs))
Expand All @@ -186,7 +186,7 @@ def unroll_conditions(lhs):
lhs = lhs_elements[0]
if isinstance(lhs, Atom):
break
name, lhs_elements = lhs.get_head_name(), lhs._elements
name, lhs_elements = lhs.get_head_name(), lhs.elements
if len(condition) == 0:
return lhs, None
if len(condition) > 1:
Expand Down
9 changes: 9 additions & 0 deletions mathics/builtin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,15 @@ def is_literal(self) -> bool:
"""
return True

@property
def elements(self):
return self._elements

@elements.setter
def elements(self, value):
self._elements = value
return self._elements

def tex_block(self, tex, only_subsup=False):
if len(tex) == 1:
return tex
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/box/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class CompiledCodeBox(BoxConstruct):

def boxes_to_text(self, elements=None, **options):
if elements is None:
elements = self._elements
elements = self.elements
return elements[0].value

def boxes_to_mathml(self, elements=None, **options):
if elements is None:
elements = self._elements
elements = self.elements
return elements[0].value

def boxes_to_tex(self, elements=None, **options):
if elements is None:
elements = self._elements
elements = self.elements
return elements[0].value
49 changes: 33 additions & 16 deletions mathics/builtin/box/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

from mathics.builtin.colors.color_directives import _ColorObject, ColorError, RGBColor
from mathics.builtin.drawing.graphics_internals import _GraphicsElement, GLOBALS
from mathics.builtin.drawing.graphics_internals import _GraphicsElementBox, GLOBALS

from mathics.builtin.graphics import (
Arrowheads,
Expand Down Expand Up @@ -48,12 +48,12 @@


# Note: has to come before _ArcBox
class _RoundBox(_GraphicsElement):
class _RoundBox(_GraphicsElementBox):
face_element = None

def init(self, graphics, style, item):
super(_RoundBox, self).init(graphics, item, style)
if len(item._elements) not in (1, 2):
if len(item.elements) not in (1, 2):
raise BoxConstructError
self.edge_color, self.face_color = style.get_style(
_ColorObject, face_element=self.face_element
Expand Down Expand Up @@ -363,8 +363,8 @@ class CircleBox(_ArcBox):
</dl>
"""

summary_text = "internal box representation for 'Circle' elements"
face_element = False
summary_text = "internal box representation for 'Circle' elements"


class DiskBox(_ArcBox):
Expand All @@ -375,8 +375,8 @@ class DiskBox(_ArcBox):
</dl>
"""

summary_text = "internal box representation for 'Disk' elements"
face_element = True
summary_text = "internal box representation for 'Disk' elements"


class GraphicsBox(BoxConstruct):
Expand All @@ -390,19 +390,27 @@ class GraphicsBox(BoxConstruct):
Graphics.
"""

options = Graphics.options

attributes = hold_all | protected | read_protected
options = Graphics.options

def __new__(cls, *elements, **kwargs):
instance = super().__new__(cls, *elements, **kwargs)
instance.evaluation = kwargs.get("evaluation", None)
instance._elements = elements
instance.elements = elements
return instance

def to_expression(self):
return self

@property
def elements(self):
return self._elements

@elements.setter
def elements(self, value):
self._elements = value
return self._elements

def get_elements(self):
return self._elements

Expand Down Expand Up @@ -942,7 +950,7 @@ def add_element(element):
add_element(LineBox(elements, axes_style[1], lines=ticks))"""


class FilledCurveBox(_GraphicsElement):
class FilledCurveBox(_GraphicsElementBox):
"""
<dl>
<dt>'FilledCurveBox[...]'
Expand Down Expand Up @@ -1020,7 +1028,7 @@ def extent(self):
return result


class InsetBox(_GraphicsElement):
class InsetBox(_GraphicsElementBox):
def init(
self,
graphics,
Expand Down Expand Up @@ -1088,11 +1096,19 @@ def init(self, graphics, style, item=None, lines=None):

class PointBox(_Polyline):
"""
Boxing methods for a list of Point.
object attributes:
edge_color: _ColorObject
point_radius: radius of each point
<dl>
<dt>'PointBox'[{$x$, $y$}]
<dd> a box construction representing a point in a Graphic.
<dt>'PointBox'[{$x$, $y$, $z$}]
<dd> represents a point in a Graphic3D.
<dt>'PointBox'[{$p_1$, $p_2$,...}]
<dd> represents a set of points.
</dl>
## Boxing methods for a list of Point.
##
## object attributes:
## edge_color: _ColorObject
## point_radius: radius of each point
"""

def init(self, graphics, style, item=None):
Expand All @@ -1113,6 +1129,7 @@ def init(self, graphics, style, item=None):

if item is not None:
if len(item.elements) != 1:
print("item:", item)
raise BoxConstructError
points = item.elements[0]
if points.has_form("List", None) and len(points.elements) != 0:
Expand Down Expand Up @@ -1188,7 +1205,7 @@ def process_option(self, name, value):
raise BoxConstructError


class RectangleBox(_GraphicsElement):
class RectangleBox(_GraphicsElementBox):
def init(self, graphics, style, item):
super(RectangleBox, self).init(graphics, item, style)
if len(item.elements) not in (1, 2):
Expand Down
12 changes: 6 additions & 6 deletions mathics/builtin/box/graphics3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)

from mathics.builtin.colors.color_directives import _ColorObject, RGBColor
from mathics.builtin.drawing.graphics_internals import GLOBALS3D, _GraphicsElement
from mathics.builtin.drawing.graphics_internals import GLOBALS3D, _GraphicsElementBox
from mathics.builtin.drawing.graphics3d import (
Coords3D,
Graphics3DElements,
Expand Down Expand Up @@ -712,7 +712,7 @@ def _apply_boxscaling(self, boxscale):
coords.scale(boxscale)


class Cone3DBox(_GraphicsElement):
class Cone3DBox(_GraphicsElementBox):
# """
# Internal Python class used when Boxing a 'Cone' object.
# """
Expand Down Expand Up @@ -758,7 +758,7 @@ def _apply_boxscaling(self, boxscale):
pass


class Cuboid3DBox(_GraphicsElement):
class Cuboid3DBox(_GraphicsElementBox):
# """
# Internal Python class used when Boxing a 'Cuboid' object.
# """
Expand Down Expand Up @@ -788,7 +788,7 @@ def _apply_boxscaling(self, boxscale):
pass


class Cylinder3DBox(_GraphicsElement):
class Cylinder3DBox(_GraphicsElementBox):
# """
# Internal Python class used when Boxing a 'Cylinder' object.
# """
Expand Down Expand Up @@ -905,7 +905,7 @@ def _apply_boxscaling(self, boxscale):
coords.scale(boxscale)


class Sphere3DBox(_GraphicsElement):
class Sphere3DBox(_GraphicsElementBox):
# summary_text = "box representation for a sphere"

def init(self, graphics, style, item):
Expand Down Expand Up @@ -948,7 +948,7 @@ def _apply_boxscaling(self, boxscale):
pass


class Tube3DBox(_GraphicsElement):
class Tube3DBox(_GraphicsElementBox):
# summary_text = "box representation for a tube"

def init(self, graphics, style, item):
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/box/uniform_polyhedra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from mathics.builtin.base import BoxConstructError
from mathics.builtin.colors.color_directives import _ColorObject
from mathics.builtin.drawing.graphics_internals import GLOBALS3D, _GraphicsElement
from mathics.builtin.drawing.graphics_internals import GLOBALS3D, _GraphicsElementBox

import numbers
from mathics.core.symbols import Symbol


class UniformPolyhedron3DBox(_GraphicsElement):
class UniformPolyhedron3DBox(_GraphicsElementBox):
"""
<dl>
<dt>'UniformPolyedron3DBox[]'
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/colors/color_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Builtin,
BoxConstructError,
)
from mathics.builtin.drawing.graphics_internals import _GraphicsElement, get_class
from mathics.builtin.drawing.graphics_internals import _GraphicsDirective, get_class
from mathics.core.element import ImmutableValueMixin
from mathics.core.expression import Expression
from mathics.core.atoms import (
Expand Down Expand Up @@ -124,7 +124,7 @@ def _euclidean_distance(a, b):
return sqrt(sum((x1 - x2) * (x1 - x2) for x1, x2 in zip(a, b)))


class _ColorObject(_GraphicsElement, ImmutableValueMixin):
class _ColorObject(_GraphicsDirective, ImmutableValueMixin):
formats = {
# we are adding ImageSizeMultipliers in the rule below, because we do _not_ want color boxes to
# diminish in size when they appear in lists or rows. we only want the display of colors this
Expand Down
Loading

0 comments on commit 8e38bd4

Please sign in to comment.