def unparsed_input_form(self): """ Get the linear string representation of this object, if possible (often it isn't). EXAMPLES:: sage: a = axiom(x^2+1); a #optional - axiom 2 x + 1 sage: a.unparsed_input_form() #optional - axiom 'x*x+1' sage: a = fricas(x^2+1) #optional - fricas sage: a.unparsed_input_form() #optional - fricas 'x^2+1' """ P = self._check_valid() 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
def unparsed_input_form(self): """ Get the linear string representation of this object, if possible (often it isn't). EXAMPLES:: sage: a = axiom(x^2+1); a #optional - axiom 2 x + 1 sage: a.unparsed_input_form() #optional - axiom 'x*x+1' sage: a = fricas(x^2+1) #optional - fricas sage: a.unparsed_input_form() #optional - fricas 'x^2+1' """ P = self._check_valid() 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
def _latex_(self): r""" EXAMPLES:: sage: a = axiom(1/2) #optional - axiom sage: latex(a) #optional - axiom \frac{1}{2} sage: a = fricas(1/2) #optional - fricas sage: latex(a) #optional - fricas 1 \over 2 """ self._check_valid() P = self.parent() s = P._eval_line('outputAsTex(%s)'%self.name(), reformat=False) if not '$$' in s: raise RuntimeError, "Error texing axiom object." 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! return s
def _latex_(self): r""" EXAMPLES:: sage: a = axiom(1/2) #optional - axiom sage: latex(a) #optional - axiom \frac{1}{2} sage: a = fricas(1/2) #optional - fricas sage: latex(a) #optional - fricas 1 \over 2 """ self._check_valid() P = self.parent() s = P._eval_line('outputAsTex(%s)' % self.name(), reformat=False) if not '$$' in s: raise RuntimeError, "Error texing axiom object." 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! return s
def external_string(self): """ EXAMPLES: sage: R = macaulay2("QQ[symbol x, symbol y]") #optional sage: R.external_string() #optional 'QQ[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {2:1}, Position => Up}, DegreeRank => 1]' """ P = self._check_valid() code = 'toExternalString(%s)'%self.name() X = P.eval(code, strip=True) if 'stdio:' in X: if 'to external string' in X: return P.eval('%s'%self.name()) raise RuntimeError("Error evaluating Macaulay2 code.\nIN:%s\nOUT:%s"%(code, X)) s = multiple_replace({'\r':'', '\n':' '}, X) return s
def external_string(self): """ EXAMPLES: sage: R = macaulay2("QQ[symbol x, symbol y]") #optional sage: R.external_string() #optional 'QQ [x, y]' """ P = self._check_valid() code = 'toExternalString(%s)'%self.name() X = P.eval(code, strip=True) if 'stdio:' in X: if 'to external string' in X: return P.eval('%s'%self.name()) raise RuntimeError, "Error evaluating Macaulay2 code.\nIN:%s\nOUT:%s"%(code, X) s = multiple_replace({'\r':'', '\n':' '}, X) return s
def external_string(self): """ EXAMPLES: sage: R = macaulay2("QQ[symbol x, symbol y]") #optional sage: R.external_string() #optional 'QQ [x, y]' """ P = self._check_valid() code = 'toExternalString(%s)' % self.name() X = P.eval(code, strip=True) if 'stdio:' in X: if 'to external string' in X: return P.eval('%s' % self.name()) raise RuntimeError, "Error evaluating Macaulay2 code.\nIN:%s\nOUT:%s" % ( code, X) s = multiple_replace({'\r': '', '\n': ' '}, X) return s