Beispiel #1
0
    def eval(self, code, strip=True, **kwds):
        r"""
        Send the code x to the Giac interpreter.
        Remark: To enable multi-lines codes in the notebook magic mode: ``%giac``,
        the ``\n`` are removed before sending the code to giac.

        INPUT:

        - code -- str
        - strip -- Default is True and removes ``\n``

        EXAMPLES::

            sage: giac.eval("2+2;\n3")
            '4,3'
            sage: giac.eval("2+2;\n3",False)
            '4\n3'
            sage: s='g(x):={\nx+1;\nx+2;\n}'
            sage: giac(s)
            ...x+1...x+2...
            sage: giac.g(5)
            7
        """
        #we remove \n to enable multiline code in the notebook magic mode %giac
        if strip:
             code = code.replace("\n","").strip()
        ans = Expect.eval(self, code, strip=strip, **kwds).strip()
        return ans
Beispiel #2
0
    def eval(self, code, strip=True, **kwds):
        r"""
        Send the code x to the Giac interpreter.
        Remark: To enable multi-lines codes in the notebook magic mode: ``%giac``,
        the ``\n`` are removed before sending the code to giac.

        INPUT:

        - code -- str
        - strip -- Default is True and removes ``\n``

        EXAMPLES::

            sage: giac.eval("2+2;\n3") #optional - giac
            '4,3'
            sage: giac.eval("2+2;\n3",False) # optional - giac
            '4\n3'
            sage: s='g(x):={\nx+1;\nx+2;\n}'
            sage: giac(s)                    # optional - giac
            (x)->{
            x+1;
            x+2;
            }
            sage: giac.g(5)                   # optional - giac
            7
        """
        #we remove \n to enable multiline code in the notebook magic mode %giac
        if strip:
             code = code.replace("\n","").strip()
        ans = Expect.eval(self, code, strip=strip, **kwds).strip()
        return ans
Beispiel #3
0
    def eval(self, code, strip=True, **kwds):
        """
        Send the code x to the Giac interpreter.
        Remark: To enable multi-lines codes in the notebook magic mode: %giac,
        the \\n are removed before sending the code to giac.

        INPUT:
            code -- str
            strip -- Default is True and removes \n

        EXAMPLES:
            sage: giac.eval("2+2;\n3") #optional - giac
            '4,3'
            sage: giac.eval("2+2;\n3",False) # optional - giac
            '4\n3'
            sage: s='g(x):={\nx+1;\nx+2;\n}'
            sage: giac(s)                    # optional - giac
            (x)->{
            x+1;
            x+2;
            }
            sage: giac.g(5)                   # optional - giac
            7
        """
        #we remove \n to enable multiline code in the notebook magic mode %giac
        if strip:
             code = code.replace("\n","").strip()
        ans = Expect.eval(self, code, strip=strip, **kwds).strip()
        return ans
 def eval(self, code, strip=True, **kwds):
     #        print "Evaluating %s"%code
     code = code.replace("\n", " ")
     result = Expect.eval(self, code, strip=strip, **kwds)
     if result.find("Exception") != -1:
         raise ValueError, "An Exception occured: %s" % result
     else:
         return result
Beispiel #5
0
    def eval(self, code, strip=True, **kwds):
#        print "Evaluating %s"%code
        code = code.replace("\n", " ")
        result = Expect.eval(self,code,strip=strip,**kwds)
        if result.find("Exception") != -1:
            raise ValueError, "An Exception occured: %s"%result
        else:
            return result
Beispiel #6
0
    def set(self, var, value):
        """
        Set the variable var to the given value.

        EXAMPLES::

            sage: macaulay2.set("a", "2")  # optional - macaulay2
            sage: macaulay2.get("a")       # optional - macaulay2
            2
        """
        cmd = '%s=%s;'%(var,value)
        ans = Expect.eval(self, cmd)
        if ans.find("stdio:") != -1:
            raise RuntimeError("Error evaluating Macaulay2 code.\nIN:%s\nOUT:%s"%(cmd, ans))
Beispiel #7
0
    def set(self, var, value):
        """
        Set the variable var to the given value.

        EXAMPLES::

            sage: macaulay2.set("a", "2")  # optional - macaulay2
            sage: macaulay2.get("a")       # optional - macaulay2
            2
        """
        cmd = '%s=%s;'%(var,value)
        ans = Expect.eval(self, cmd)
        if ans.find("stdio:") != -1:
            raise RuntimeError("Error evaluating Macaulay2 code.\nIN:%s\nOUT:%s"%(cmd, ans))
Beispiel #8
0
    def eval(self, code, strip=True, **kwds):
        """
        Send the code x to the Macaulay2 interpreter and return the output
        as a string suitable for input back into Macaulay2, if possible.

        INPUT:

        - code -- str
        - strip -- ignored

        EXAMPLES::

            sage: macaulay2.eval("2+2") # optional - macaulay2
            4
        """
        code = code.strip()
        # TODO: in some cases change toExternalString to toString??
        ans = Expect.eval(self, code, strip=strip, **kwds).strip('\n')
        if strip:
            ans = remove_output_labels(ans)
        return AsciiArtString(ans)
Beispiel #9
0
    def eval(self, code, strip=True, **kwds):
        """
        Send the code x to the Macaulay2 interpreter and return the output
        as a string suitable for input back into Macaulay2, if possible.

        INPUT:

        - code -- str
        - strip -- ignored

        EXAMPLES::

            sage: macaulay2.eval("2+2") # optional - macaulay2
            4
        """
        code = code.strip()
        # TODO: in some cases change toExternalString to toString??
        ans = Expect.eval(self, code, strip=strip, **kwds).strip('\n')
        if strip:
            ans = remove_output_labels(ans)
        return AsciiArtString(ans)
Beispiel #10
0
 def eval(self, code, strip=True, **kwds):
     s = Expect.eval(self, code, **kwds)
     if strip:
         return AsciiArtString(clean_output(s))
     else:
         return AsciiArtString(s)
Beispiel #11
0
 def eval(self, code, strip=True, **kwds):
     s = Expect.eval(self, code, **kwds)
     if strip:
         return AsciiArtString(clean_output(s))
     else:
         return AsciiArtString(s)