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

Commit

Permalink
move dictionary with constants to module level
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Jul 2, 2021
1 parent 577e476 commit 52099de
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/sage/interfaces/fricas.py
Expand Up @@ -205,10 +205,18 @@
from sage.docs.instancedoc import instancedoc
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.infinity import infinity
from sage.misc.lazy_import import lazy_import
lazy_import('sage.libs.pynac.pynac', ['symbol_table'])
lazy_import('sage.calculus.var', ['var', 'function'])
lazy_import('sage.symbolic.constants', ['I', 'e', 'pi'])

FRICAS_CONSTANTS = {'%i': I,
'%e': e,
'%pi': pi,
'infinity': infinity,
'plusInfinity': infinity,
'minusInfinity': -infinity}

FRICAS_SINGLE_LINE_START = 3 # where output starts when it fits next to the line number
FRICAS_MULTI_LINE_START = 2 # and when it doesn't
Expand Down Expand Up @@ -253,7 +261,6 @@
FRICAS_FIRST_PROMPT = r"\(1\) -> "
FRICAS_LINENUMBER_OFF_PROMPT = r"\(NIL\) -> "


class FriCAS(ExtraTabCompletion, Expect):
"""
Interface to a FriCAS interpreter.
Expand Down Expand Up @@ -1281,7 +1288,8 @@ def _parse_list(s, start=0):

@staticmethod
def _parse_other(s, start=0, make_fun=False):
"""Parse the initial part of a string, assuming that it is an
"""
Parse the initial part of a string, assuming that it is an
atom, but not a string.
Symbols and numbers must not contain ``FriCASElement._WHITESPACE`` and
Expand Down Expand Up @@ -1333,22 +1341,14 @@ def _parse_other(s, start=0, make_fun=False):
except KeyError:
e = function(e)
else:
from sage.symbolic.constants import e as sage_e, pi, I
from sage.rings.infinity import infinity
constants = {'%i': I,
'%e': sage_e,
'%pi': pi,
'infinity': infinity,
'plusInfinity': infinity,
'minusInfinity': -infinity}
try:
e = ZZ(e)
except TypeError:
try:
e = float(e)
except ValueError:
try:
e = constants[e]
e = FRICAS_CONSTANTS[e]
except KeyError:
e = var(e.replace("%", "_"))
return e, a - 1
Expand Down Expand Up @@ -1621,7 +1621,6 @@ def _sage_expression(fricas_InputForm):
from sage.functions.other import abs
from sage.functions.gamma import gamma
from sage.misc.functional import symbolic_sum, symbolic_prod
from sage.symbolic.constants import I, pi
register_symbol(pi, {'fricas': 'pi'}) # pi is also a function in fricas
register_symbol(cos, {'fricas': 'cos'})
register_symbol(sin, {'fricas': 'sin'})
Expand Down

0 comments on commit 52099de

Please sign in to comment.