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

better fricas and giac conversion for symbolic matrices #30815

Closed
fchapoton opened this issue Oct 23, 2020 · 11 comments
Closed

better fricas and giac conversion for symbolic matrices #30815

fchapoton opened this issue Oct 23, 2020 · 11 comments

Comments

@fchapoton
Copy link
Contributor

and a similar problem with giac.

Here it is

sage: fricas(sin(x)).sage()                                                     
sin(x)
sage: M = matrix(SR, 1, [sin(x)])                                               
sage: fricas(M)                                                                 
+sin +
+   x+
sage: fricas(M).sage()                                                          
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/sage/local/lib/python3.8/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6664)()
    571             try:
--> 572                 args = [SR.coerce(a) for a in args]
    573             except TypeError as err:

~/sage/local/lib/python3.8/site-packages/sage/structure/parent.pyx in sage.structure.parent.Parent.coerce (build/cythonized/sage/structure/parent.c:10692)()
   1113 
-> 1114     cpdef coerce(self, x):
   1115         """

~/sage/local/lib/python3.8/site-packages/sage/structure/parent.pyx in sage.structure.parent.Parent.coerce (build/cythonized/sage/structure/parent.c:10618)()
   1143                     _record_exception()
-> 1144             raise TypeError(_LazyString(_lazy_format, ("no canonical coercion from %s to %s", parent(x), self), {}))
   1145         else:

TypeError: no canonical coercion from <class 'sage.functions.trig.Function_sin'> to Symbolic Ring

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-63-0b5b80f0dcc8> in <module>
----> 1 fricas(M).sage()

~/sage/local/lib/python3.8/site-packages/sage/interfaces/interface.py in sage(self, *args, **kwds)
   1090             [0 0]
   1091         """
-> 1092         return self._sage_(*args, **kwds)
   1093 
   1094     def __repr__(self):

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in _sage_(self)
   1864         if head == "Matrix":
   1865             base_ring = self._get_sage_type(domain[1])
-> 1866             rows = self.listOfLists().sage()
   1867             return matrix(base_ring, rows)
   1868 

~/sage/local/lib/python3.8/site-packages/sage/interfaces/interface.py in sage(self, *args, **kwds)
   1090             [0 0]
   1091         """
-> 1092         return self._sage_(*args, **kwds)
   1093 
   1094     def __repr__(self):

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in _sage_(self)
   1856         if head == "List":
   1857             n = P.get_integer('#(%s)' % self._name)
-> 1858             return [self.elt(k).sage() for k in range(1, n + 1)]
   1859 
   1860         if head == "Vector" or head == "DirectProduct":

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in <listcomp>(.0)
   1856         if head == "List":
   1857             n = P.get_integer('#(%s)' % self._name)
-> 1858             return [self.elt(k).sage() for k in range(1, n + 1)]
   1859 
   1860         if head == "Vector" or head == "DirectProduct":

~/sage/local/lib/python3.8/site-packages/sage/interfaces/interface.py in sage(self, *args, **kwds)
   1090             [0 0]
   1091         """
-> 1092         return self._sage_(*args, **kwds)
   1093 
   1094     def __repr__(self):

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in _sage_(self)
   1856         if head == "List":
   1857             n = P.get_integer('#(%s)' % self._name)
-> 1858             return [self.elt(k).sage() for k in range(1, n + 1)]
   1859 
   1860         if head == "Vector" or head == "DirectProduct":

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in <listcomp>(.0)
   1856         if head == "List":
   1857             n = P.get_integer('#(%s)' % self._name)
-> 1858             return [self.elt(k).sage() for k in range(1, n + 1)]
   1859 
   1860         if head == "Vector" or head == "DirectProduct":

~/sage/local/lib/python3.8/site-packages/sage/interfaces/interface.py in sage(self, *args, **kwds)
   1090             [0 0]
   1091         """
-> 1092         return self._sage_(*args, **kwds)
   1093 
   1094     def __repr__(self):

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in _sage_(self)
   1943             # we treat Expression Integer and Expression Complex
   1944             # Integer just the same
-> 1945             return FriCASElement._sage_expression(P.get_InputForm(self._name))
   1946 
   1947         if head == 'DistributedMultivariatePolynomial':

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in _sage_expression(fricas_InputForm)
   1630         register_symbol(convert_rootOf, {'fricas': 'rootOf'})
   1631 
-> 1632         ex, _ = FriCASElement._parse_and_eval(fricas_InputForm)
   1633         # postprocessing of rootOf
   1634         from sage.rings.all import QQbar, PolynomialRing

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1234 
   1235         if s[a] == FriCASElement._LEFTBRACKET:
-> 1236             return FriCASElement._parse_list(s, start=a)
   1237         elif s[a] == FriCASElement._STRINGMARKER:
   1238             return FriCASElement._parse_string(s, start=a)

~/sage/local/lib/python3.8/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1279             args.append(e)
   1280             a += 1
-> 1281         return fun(*args), a
   1282 
   1283     @staticmethod

~/sage/local/lib/python3.8/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6826)()
    583                     if callable(method):
    584                         return method()
--> 585                 raise TypeError("cannot coerce arguments: %s" % (err))
    586 
    587         else: # coerce == False

TypeError: cannot coerce arguments: no canonical coercion from <class 'sage.functions.trig.Function_sin'> to Symbolic Ring

CC: @mantepse

Component: interfaces: optional

Keywords: FriCAS, giac

Author: Frédéric Chapoton

Branch/Commit: c1c5ef5

Reviewer: Martin Rubey

Issue created by migration from https://trac.sagemath.org/ticket/30815

@fchapoton
Copy link
Contributor Author

Changed keywords from none to FriCAS

@fchapoton
Copy link
Contributor Author

Commit: c1c5ef5

@fchapoton
Copy link
Contributor Author

Changed keywords from FriCAS to FriCAS, giac

@fchapoton

This comment has been minimized.

@fchapoton
Copy link
Contributor Author

Branch: u/chapoton/30815

@fchapoton
Copy link
Contributor Author

Author: Frédéric Chapoton

@fchapoton
Copy link
Contributor Author

New commits:

c1c5ef5trrac 30815 better conversion of symbolic matrices to giac and fricas

@fchapoton fchapoton changed the title bug in fricas interface for symbolic matrices better fricas and giac conversion for symbolic matrices Oct 23, 2020
@mantepse
Copy link
Contributor

comment:3

Thank you!

@mantepse
Copy link
Contributor

Reviewer: Martin Rubey

@fchapoton
Copy link
Contributor Author

comment:4

NOTE : conversion to maple also needs the same kind of fix. TODO once this ticket is merged.

@vbraun
Copy link
Member

vbraun commented Nov 7, 2020

Changed branch from u/chapoton/30815 to c1c5ef5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants