Example #1
0
    def __init__(self):
        """
        Create an instance of the Maxima interpreter.
        See ``MaximaLib`` for full documentation.

        TESTS::

            sage: from sage.interfaces.maxima_lib import MaximaLib, maxima_lib
            sage: MaximaLib == loads(dumps(MaximaLib))
            True
            sage: maxima_lib == loads(dumps(maxima_lib))
            True

        We make sure labels are turned off (see :trac:`6816`)::

            sage: 'nolabels : true' in maxima_lib._MaximaLib__init_code
            True
        """
        global maxima_lib_instances
        if maxima_lib_instances > 0:
            raise RuntimeError("Maxima interface in library mode can only be instantiated once")
        maxima_lib_instances += 1

        global init_code
        self.__init_code = init_code

        MaximaAbstract.__init__(self,"maxima_lib")
        self.__seq = 0
Example #2
0
    def _coerce_from_special_method(self, x):
        r"""
        Coerce ``x`` into self trying to call a special underscore method.

        INPUT:

        - ``x`` - object to coerce into self

        OUTPUT: Maxima element equivalent to ``x``

        EXAMPLES::

            sage: from sage.interfaces.maxima_lib import maxima_lib
            sage: xmax = maxima_lib._coerce_from_special_method(x)
            sage: type(xmax)
            <class 'sage.interfaces.maxima_lib.MaximaLibElement'>
        """
        if isinstance(x, EclObject):
            return MaximaLibElement(self,self._create(x))
        else:
            return MaximaAbstract._coerce_from_special_method(self,x)
Example #3
0
    def __init__(self, script_subdirectory=None, logfile=None, server=None,
                 init_code = None):
        """
        Create an instance of the Maxima interpreter.

        TESTS::

            sage: Maxima == loads(dumps(Maxima))
            True
            sage: maxima == loads(dumps(maxima))
            True

        Unpickling a Maxima Pexpect interface gives the default interface::

            sage: m = Maxima()
            sage: maxima == loads(dumps(m))
            True

        We make sure labels are turned off (see trac 6816)::

            sage: 'nolabels : true' in maxima._Expect__init_code
            True
        """
        # TODO: Input and output prompts in maxima can be changed by
        # setting inchar and outchar..
        eval_using_file_cutoff = 256
        self.__eval_using_file_cutoff = eval_using_file_cutoff
        STARTUP = os.path.join(SAGE_LOCAL,'bin','sage-maxima.lisp')

        # We set maxima's configuration directory to $DOT_SAGE/maxima
        # This avoids that sage's maxima inadvertently loads
        # ~/.maxima/maxima-init.mac
        # If you absolutely want maxima instances that are started by
        # this interface to preload commands, put them in
        # $DOT_SAGE/maxima/maxima-init.mac
        # (we use the "--userdir" option in maxima for this)
        SAGE_MAXIMA_DIR = os.path.join(DOT_SAGE,"maxima")

        if not os.path.exists(STARTUP):
            raise RuntimeError, 'You must get the file local/bin/sage-maxima.lisp'

        #self.__init_code = init_code
        if init_code is None:
            # display2d -- no ascii art output
            # keepfloat -- don't automatically convert floats to rationals
            init_code = ['display2d : false', 'keepfloat : true']

        # Turn off the prompt labels, since computing them *very
        # dramatically* slows down the maxima interpret after a while.
        # See the function makelabel in suprv1.lisp.
        # Many thanks to [email protected] and also
        # Robert Dodier for figuring this out!
        # See trac # 6818.
        init_code.append('nolabels : true')

        MaximaAbstract.__init__(self,"maxima")
        Expect.__init__(self,
                        name = 'maxima',
                        prompt = '\(\%i[0-9]+\)',
                        command = 'maxima --userdir="%s" -p "%s"'%(SAGE_MAXIMA_DIR,STARTUP),
                        maxread = 10000,
                        script_subdirectory = script_subdirectory,
                        restart_on_ctrlc = False,
                        verbose_start = False,
                        init_code = init_code,
                        logfile = logfile,
                        eval_using_file_cutoff=eval_using_file_cutoff)
        self._display_prompt = '<sage-display>'  # must match what is in the file local/bin/sage-maxima.lisp!!
        self._output_prompt_re = re.compile('\(\%o[0-9]+\)')
        self._ask = ['zero or nonzero?', 'an integer?', 'positive, negative, or zero?',
                     'positive or negative?', 'positive or zero?']
        self._prompt_wait = [self._prompt] + [re.compile(x) for x in self._ask] + \
                            ['Break [0-9]+'] #note that you might need to change _expect_expr if you
                                             #change this
        self._error_re = re.compile('(Principal Value|debugmode|incorrect syntax|Maxima encountered a Lisp error)')
        self._display2d = False
Example #4
0
    def __init__(self, script_subdirectory=None, logfile=None, server=None,
                 init_code=None):
        """
        Create an instance of the Maxima interpreter.

        TESTS::

            sage: Maxima == loads(dumps(Maxima))
            True
            sage: maxima == loads(dumps(maxima))
            True

        Unpickling a Maxima Pexpect interface gives the default interface::

            sage: m = Maxima()
            sage: maxima == loads(dumps(m))
            True

        We make sure labels are turned off (see :trac:`6816`)::

            sage: 'nolabels : true' in maxima._Expect__init_code
            True
        """
        # TODO: Input and output prompts in maxima can be changed by
        # setting inchar and outchar..
        eval_using_file_cutoff = 256
        self.__eval_using_file_cutoff = eval_using_file_cutoff
        STARTUP = os.path.join(SAGE_LOCAL,'bin','sage-maxima.lisp')

        # We set maxima's configuration directory to $DOT_SAGE/maxima
        # This avoids that sage's maxima inadvertently loads
        # ~/.maxima/maxima-init.mac
        # If you absolutely want maxima instances that are started by
        # this interface to preload commands, put them in
        # $DOT_SAGE/maxima/maxima-init.mac
        # (we use the "--userdir" option in maxima for this)
        SAGE_MAXIMA_DIR = os.path.join(DOT_SAGE,"maxima")

        if not os.path.exists(STARTUP):
            raise RuntimeError('You must get the file local/bin/sage-maxima.lisp')

        #self.__init_code = init_code
        if init_code is None:
            # display2d -- no ascii art output
            # keepfloat -- don't automatically convert floats to rationals
            init_code = ['display2d : false', 'keepfloat : true']

        # Turn off the prompt labels, since computing them *very
        # dramatically* slows down the maxima interpret after a while.
        # See the function makelabel in suprv1.lisp.
        # Many thanks to [email protected] and also
        # Robert Dodier for figuring this out!
        # See trac # 6818.
        init_code.append('nolabels : true')

        MaximaAbstract.__init__(self,"maxima")
        Expect.__init__(self,
                        name = 'maxima',
                        prompt = '\(\%i[0-9]+\) ',
                        command = 'maxima --userdir="%s" -p "%s"'%(SAGE_MAXIMA_DIR,STARTUP),
                        maxread = 10000,
                        script_subdirectory = script_subdirectory,
                        restart_on_ctrlc = False,
                        verbose_start = False,
                        init_code = init_code,
                        logfile = logfile,
                        eval_using_file_cutoff=eval_using_file_cutoff)
        # Must match what is in the file local/bin/sage-maxima.lisp
        self._display_prompt = '<sage-display>'
        # See #15440 for the importance of the trailing space
        self._output_prompt_re = re.compile('\(\%o[0-9]+\) ')
        self._ask = ['zero or nonzero\\?', 'an integer\\?',
                     'positive, negative or zero\\?', 'positive or negative\\?',
                     'positive or zero\\?', 'equal to .*\\?']
        self._prompt_wait = [self._prompt] + [re.compile(x) for x in self._ask] + \
                            ['Break [0-9]+'] #note that you might need to change _expect_expr if you
                                             #change this
        self._error_re = re.compile('(Principal Value|debugmode|incorrect syntax|Maxima encountered a Lisp error)')
        self._display2d = False