Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'mathics_33581' into mathics_33581_33584
Browse files Browse the repository at this point in the history
  • Loading branch information
soehms committed Mar 28, 2022
2 parents 4302109 + e526292 commit d969e4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/sage/interfaces/kenzo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
# https://www.gnu.org/licenses/
# ****************************************************************************


from sage.structure.sage_object import SageObject
from sage.homology.homology_group import HomologyGroup
from sage.rings.integer_ring import ZZ
from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup
from sage.groups.abelian_gps.abelian_group import AbelianGroup
from sage.categories.commutative_additive_groups import CommutativeAdditiveGroups
from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup

from sage.matrix.constructor import matrix
from sage.homology.chain_complex import ChainComplex
Expand Down Expand Up @@ -1879,7 +1877,7 @@ def build_morphism(source_complex, target_complex, degree, algorithm, strategy,
"""
return KenzoChainComplexMorphism(
__build_mrph_aux__(source_complex._kenzo, target_complex._kenzo,
degree, algorithm, ":"+strategy, orgn))
degree, algorithm, ":" + strategy, orgn))


def morphism_dictmat(morphism):
Expand Down
48 changes: 20 additions & 28 deletions src/sage/interfaces/mathics.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,18 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
##############################################################################

import os
import re

from enum import Enum
from sage.misc.cachefunc import cached_method
from sage.interfaces.interface import Interface, InterfaceElement, InterfaceFunction, InterfaceFunctionElement
from sage.interfaces.tab_completion import ExtraTabCompletion
from sage.docs.instancedoc import instancedoc
from sage.structure.richcmp import rich_to_bool



def _mathics_sympysage_symbol(self):
r"""
Convert a Sympy symbol ``self`` to a correspondig element
Expand Down Expand Up @@ -515,7 +512,6 @@ def _start(self):
from sage.interfaces.sympy import sympy_init
sympy_init()
from sympy import Symbol
from sympy.core.relational import Relational
Symbol._sage_ = _mathics_sympysage_symbol

def _read_in_file_command(self, filename):
Expand All @@ -531,7 +527,7 @@ def _read_in_file_command(self, filename):
sage: os.system('rm %s' %fn) # optional - mathics
0
"""
return '<<"%s"'%filename
return '<<"%s"' % filename

def _install_hints(self):
"""
Expand All @@ -547,7 +543,6 @@ def _install_hints(self):
optional Sage package Mathics installed.
"""


def _eval(self, code):
"""
Evaluates a command inside the Mathics interpreter and returns the output
Expand Down Expand Up @@ -575,13 +570,12 @@ def eval(self, code, *args, **kwds):
sage: mathics.eval('1+1') # optional - mathics
'2'
"""
res= self._eval(code)
res = self._eval(code)
if res.result == 'Null':
if len(res.out) == 1:
return str(res.out[0])
return res.result


def set(self, var, value):
"""
Set the variable var to the given value.
Expand All @@ -592,8 +586,8 @@ def set(self, var, value):
sage: bool(mathics('u').sage() == 2*x+e) # optional - mathics
True
"""
cmd = '%s=%s;'%(var,value)
out = self.eval(cmd)
cmd = '%s=%s;' % (var, value)
_ = self.eval(cmd)

def get(self, var):
"""
Expand All @@ -616,7 +610,7 @@ def _function_call_string(self, function, args, kwds):
sage: mathics._function_call_string('Sin', ['x'], [])
'Sin[x]'
"""
return "%s[%s]"%(function, ",".join(args))
return "%s[%s]" % (function, ",".join(args))

def _left_list_delim(self):
r"""
Expand Down Expand Up @@ -654,10 +648,9 @@ def _right_func_delim(self):
"""
return "]"


###########################################
# #########################################
# System -- change directory, etc
###########################################
# #########################################
def chdir(self, dir):
"""
Change Mathics's current working directory.
Expand All @@ -668,7 +661,7 @@ def chdir(self, dir):
sage: mathics('Directory[]') # optional - mathics
/
"""
self.eval('SetDirectory["%s"]'%dir)
self.eval('SetDirectory["%s"]' % dir)

def _true_symbol(self):
r"""
Expand Down Expand Up @@ -806,9 +799,9 @@ def help(self, cmd, long=False):
<BLANKLINE>
"""
if long:
return self.eval('Information[%s]' %cmd)
return self.eval('Information[%s]' % cmd)
else:
return self.eval('? %s' %cmd)
return self.eval('? %s' % cmd)

def __getattr__(self, attrname):
r"""
Expand Down Expand Up @@ -889,7 +882,6 @@ def _tab_completion(self):
"""
return dir(self._mathics_result.last_eval)


def __getitem__(self, n):
r"""
EXAMPLES::
Expand All @@ -902,7 +894,7 @@ def __getitem__(self, n):
x
0.15
"""
return self.parent().new('%s[[%s]]'%(self._name, n))
return self.parent().new('%s[[%s]]' % (self._name, n))

def __getattr__(self, attrname):
r"""
Expand Down Expand Up @@ -936,7 +928,7 @@ def __float__(self, precision=16):
True
"""
P = self.parent()
return float(P._eval('N[%s,%s]'%(self.name(), precision)).last_eval.to_mpmath())
return float(P._eval('N[%s,%s]' % (self.name(), precision)).last_eval.to_mpmath())

def _reduce(self):
r"""
Expand Down Expand Up @@ -967,9 +959,9 @@ def _latex_(self):
sage: latex(Q) # optional - mathics
\frac{\text{Sin}\left[x \text{Cos}\left[y\right]\right]}{\sqrt{1-x^2}}
"""
z = str(self.parent()('TeXForm[%s]'%self.name()))
z = str(self.parent()('TeXForm[%s]' % self.name()))
i = z.find('=')
return z[i+1:]
return z[i + 1:]

def _repr_(self):
r"""
Expand Down Expand Up @@ -1135,7 +1127,7 @@ def save_image(self, filename, ImageSize=600):
if not self._is_graphics():
raise ValueError('mathics expression is not graphics')
filename = os.path.abspath(filename)
s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize)
s = 'Export["%s", %s, ImageSize->%s]' % (filename, self.name(), ImageSize)
P.eval(s)

def _rich_repr_(self, display_manager, **kwds):
Expand Down Expand Up @@ -1204,7 +1196,6 @@ def show(self, ImageSize=600):
dm = get_display_manager()
dm.display_immediately(self, ImageSize=ImageSize)


def _richcmp_(self, other, op):
r"""
EXAMPLES::
Expand All @@ -1220,11 +1211,11 @@ def _richcmp_(self, other, op):
False
"""
P = self.parent()
if str(P("%s < %s"%(self.name(), other.name()))) == P._true_symbol():
if str(P("%s < %s" % (self.name(), other.name()))) == P._true_symbol():
return rich_to_bool(op, -1)
elif str(P("%s > %s"%(self.name(), other.name()))) == P._true_symbol():
elif str(P("%s > %s" % (self.name(), other.name()))) == P._true_symbol():
return rich_to_bool(op, 1)
elif str(P("%s == %s"%(self.name(), other.name()))) == P._true_symbol():
elif str(P("%s == %s" % (self.name(), other.name()))) == P._true_symbol():
return rich_to_bool(op, 0)
return NotImplemented

Expand Down Expand Up @@ -1273,6 +1264,7 @@ def n(self, *args, **kwargs):
# An instance
mathics = Mathics()


def reduce_load(X):
"""
Used in unpickling a Mathics element.
Expand Down

0 comments on commit d969e4b

Please sign in to comment.