Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pep8 for axiom and sympy interfaces #36745

Merged
merged 2 commits into from
Dec 10, 2023
Merged
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
75 changes: 37 additions & 38 deletions src/sage/interfaces/axiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ def _commands(self):
i = s.find(start)
end = "To get more information about"
j = s.find(end)
s = s[i+len(start):j].split()
return s
return s[i + len(start):j].split()

def _tab_completion(self, verbose=True, use_disk_cache=True):
"""
Expand Down Expand Up @@ -357,15 +356,15 @@ def _tab_completion(self, verbose=True, use_disk_cache=True):
print("To force rebuild later, delete %s." % self._COMMANDS_CACHE)
v = self._commands()

#Process we now need process the commands to strip out things which
#are not valid Python identifiers.
# Process we now need process the commands to strip out things which
# are not valid Python identifiers.
valid = re.compile('[^a-zA-Z0-9_]+')
names = [x for x in v if valid.search(x) is None]

#Change everything that ends with ? to _q and
#everything that ends with ! to _e
names += [x[:-1]+"_q" for x in v if x.endswith("?")]
names += [x[:-1]+"_e" for x in v if x.endswith("!")]
# Change everything that ends with ? to _q and
# everything that ends with ! to _e
names += [x[:-1] + "_q" for x in v if x.endswith("?")]
names += [x[:-1] + "_e" for x in v if x.endswith("!")]

self.__tab_completion = names
if len(v) > 200:
Expand Down Expand Up @@ -430,7 +429,7 @@ def _eval_line(self, line, reformat=True, allow_use_file=False,
if self._expect is None:
self._start()
if allow_use_file and self.__eval_using_file_cutoff and \
len(line) > self.__eval_using_file_cutoff:
len(line) > self.__eval_using_file_cutoff:
return self._eval_line_using_file(line)
try:
E = self._expect
Expand Down Expand Up @@ -465,7 +464,7 @@ def _eval_line(self, line, reformat=True, allow_use_file=False,
line = line.rstrip()
if line[:4] == ' (':
i = line.find('(')
i += line[i:].find(')')+1
i += line[i:].find(')') + 1
if line[i:] == "":
i = 0
outs = outs[1:]
Expand Down Expand Up @@ -598,14 +597,13 @@ def _richcmp_(self, other, op):
sage: f = axiom('sin(x)'); g = axiom('cos(x)') #optional - axiom
sage: f == g #optional - axiom
False

"""
P = self.parent()
if 'true' in P.eval("(%s = %s) :: Boolean" % (self.name(),other.name())):
if 'true' in P.eval("(%s = %s) :: Boolean" % (self.name(), other.name())):
return rich_to_bool(op, 0)
elif 'true' in P.eval("(%s < %s) :: Boolean" % (self.name(), other.name())):
return rich_to_bool(op, -1)
elif 'true' in P.eval("(%s > %s) :: Boolean" % (self.name(),other.name())):
elif 'true' in P.eval("(%s > %s) :: Boolean" % (self.name(), other.name())):
return rich_to_bool(op, 1)

return NotImplemented
Expand Down Expand Up @@ -637,7 +635,7 @@ def __len__(self):
P = self._check_valid()
s = P.eval('# %s ' % self.name())
i = s.rfind('Type')
return int(s[:i-1])
return int(s[:i - 1])

def __getitem__(self, n):
r"""
Expand Down Expand Up @@ -709,12 +707,12 @@ def _latex_(self):
i = s.find('$$')
j = s.rfind('$$')
s = s[i + 2:j]
s = multiple_replace({'\r':'', '\n':' ',
' \\sp ':'^',
'\\arcsin ':'\\sin^{-1} ',
'\\arccos ':'\\cos^{-1} ',
'\\arctan ':'\\tan^{-1} '},
re.sub(r'\\leqno\(.*?\)','',s)) # no eq number!
s = multiple_replace({'\r': '', '\n': ' ',
' \\sp ': '^',
'\\arcsin ': '\\sin^{-1} ',
'\\arccos ': '\\cos^{-1} ',
'\\arctan ': '\\tan^{-1} '},
re.sub(r'\\leqno\(.*?\)', '', s)) # no eq number!
return s

def as_type(self, type):
Expand Down Expand Up @@ -753,16 +751,13 @@ def unparsed_input_form(self):
s = P.eval('unparse(%s::InputForm)' % self._name)
if 'translation error' in s or 'Cannot convert' in s:
raise NotImplementedError
s = multiple_replace({'\r\n':'', # fix stupid Fortran-ish
'DSIN(':'sin(',
'DCOS(':'cos(',
'DTAN(':'tan(',
'DSINH(':'sinh('}, s)
r = re.search(r'"(.*)"',s)
if r:
return r.groups(0)[0]
else:
return s
s = multiple_replace({'\r\n': '', # fix stupid Fortran-ish
'DSIN(': 'sin(',
'DCOS(': 'cos(',
'DTAN(': 'tan(',
'DSINH(': 'sinh('}, s)
r = re.search(r'"(.*)"', s)
return r.groups(0)[0] if r else s

def _sage_(self):
"""
Expand Down Expand Up @@ -835,8 +830,8 @@ def _sage_(self):
from sage.rings.integer_ring import ZZ
prec = max(self.mantissa().length()._sage_(), 53)
R = RealField(prec)
x,e,b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',')
return R(ZZ(x)*ZZ(b)**ZZ(e))
x, e, b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',')
return R(ZZ(x) * ZZ(b)**ZZ(e))
elif type == "DoubleFloat":
from sage.rings.real_double import RDF
return RDF(repr(self))
Expand All @@ -850,16 +845,18 @@ def _sage_(self):
R = PolynomialRing(base_ring, vars)
return R(self.unparsed_input_form())
elif type.startswith('Fraction'):
return self.numer().sage()/self.denom().sage()
return self.numer().sage() / self.denom().sage()

#If all else fails, try using the unparsed input form
# If all else fails, try using the unparsed input form
try:
import sage.misc.sage_eval
vars = sage.symbolic.ring.var(str(self.variables())[1:-1])
if isinstance(vars,tuple):
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(), locals={str(x):x for x in vars})
if isinstance(vars, tuple):
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
locals={str(x): x for x in vars})
else:
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(), locals={str(vars):vars})
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
locals={str(vars): vars})
except Exception:
raise NotImplementedError

Expand Down Expand Up @@ -961,9 +958,10 @@ def is_AxiomElement(x):
return isinstance(x, AxiomElement)


#Instances
# Instances
axiom = Axiom(name='axiom')


def reduce_load_Axiom():
"""
Returns the Axiom interface object defined in
Expand All @@ -977,6 +975,7 @@ def reduce_load_Axiom():
"""
return axiom


def axiom_console():
"""
Spawn a new Axiom command-line session.
Expand Down
Loading
Loading