I am using SageMath on Ubuntu running on a Windows Subsystem for Lynux (WSL), and trying to reproduce the following code, which calls for the package friCAS as a dependency. As you can see in the reproduced error, SageMath does recognize friCAS:
x = var('x')
y = function('y')(x)
de = x^3*diff(y,x,3) - 3*x^2*diff(y,x,2) + 6*x*diff(y,x) -6*y == 0
h = desolve(de,y,ics=[1,7,17,32],algorithm="fricas")
show(expand(h))
This produces an output without glitches when run on SageMath Cell Server.
I have installed friCAS in two different ways:
sudo apt install fricas
And including it (appending it) in a long list of packages in sagemanifolds.obspm.fr/install_ubuntu dot html
I can run friCAS and start the program from the Ubuntu cmd line.
Why am I getting the error below when running this identical code on a Jupyter Notebook?
The error is:
x = var('x')
y = function('y')(x)
de = x^3*diff(y,x,3) - 3*x^2*diff(y,x,2) + 6*x*diff(y,x) -6*y == 0
h = desolve(de,y,ics=[1,7,17,32],algorithm="fricas")
show(expand(h))
x = var('x')
y = function('y')(x)
de = x^3*diff(y,x,3) - 3*x^2*diff(y,x,2) + 6*x*diff(y,x) -6*y == 0
h = desolve(de,y,ics=[1,7,17,32],algorithm="fricas")
show(expand(h))
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/expect.py in __init__(self, parent, value, is_name, name)
1469 try:
-> 1470 self._name = parent._create(value, name=name)
1471 # Convert ValueError and RuntimeError to TypeError for
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in _create(self, value, name)
512 name = self._next_var_name() if name is None else name
--> 513 self.set(name, value)
514 return name
/usr/lib/python3/dist-packages/sage/interfaces/fricas.py in set(self, var, value)
674 output = self.eval(cmd, reformat=False)
--> 675 self._check_errors(value, output)
676
/usr/lib/python3/dist-packages/sage/interfaces/fricas.py in _check_errors(self, line, output)
569 output = output.replace(old, new)
--> 570 raise RuntimeError("An error occurred when FriCAS evaluated '%s':\n%s" % (line, output))
571
RuntimeError: An error occurred when FriCAS evaluated 'x':
Function declaration sageprint : InputForm -> String has been added to
workspace.
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/tmp/ipykernel_206935/3617173396.py in <module>
2 y = function('y')(x)
3 de = x**Integer(3)*diff(y,x,Integer(3)) - Integer(3)*x**Integer(2)*diff(y,x,Integer(2)) + Integer(6)*x*diff(y,x) -Integer(6)*y == Integer(0)
----> 4 h = desolve(de,y,ics=[Integer(1),Integer(7),Integer(17),Integer(32)],algorithm="fricas")
5 show(expand(h))
/usr/lib/python3/dist-packages/sage/calculus/desolvers.py in desolve(de, dvar, ics, ivar, show_method, contrib_ode, algorithm)
565
566 if algorithm == "fricas":
--> 567 return fricas_desolve(de, dvar, ics, ivar)
568 elif algorithm != "maxima":
569 raise ValueError("unknown algorithm %s" % algorithm)
/usr/lib/python3/dist-packages/sage/calculus/desolvers.py in fricas_desolve(de, dvar, ics, ivar)
113 y = fricas(de).solve(dvar.operator(), ivar).sage()
114 else:
--> 115 eq = fricas.equation(ivar, ics[0])
116 y = fricas(de).solve(dvar.operator(), eq, ics[1:]).sage()
117
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __call__(self, *args, **kwds)
665
666 def __call__(self, *args, **kwds):
--> 667 return self._parent.function_call(self._name, list(args), kwds)
668
669 def _instancedoc_(self):
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in function_call(self, function, args, kwds)
606 [0.5,5.5511151231257...e-15,21,0]
607 """
--> 608 args, kwds = self._convert_args_kwds(args, kwds)
609 self._check_valid_function_name(function)
610 s = self._function_call_string(function,
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in _convert_args_kwds(self, args, kwds)
567 for i, arg in enumerate(args):
568 if not isinstance(arg, InterfaceElement) or arg.parent() is not self:
--> 569 args[i] = self(arg)
570 for key, value in kwds.items():
571 if not isinstance(value, InterfaceElement) or value.parent() is not self:
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __call__(self, x, name)
300 # user-assigned name might change its value, so we return a
301 # new element.
--> 302 result = self._coerce_from_special_method(x)
303 return result if name is None else result.name(new_name=name)
304 except TypeError:
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in _coerce_from_special_method(self, x)
328 s = '_gp_'
329 try:
--> 330 return (x.__getattribute__(s))(self)
331 except AttributeError:
332 return self(x._interface_init_())
/usr/lib/python3/dist-packages/sage/structure/sage_object.pyx in sage.structure.sage_object.SageObject._fricas_ (build/cythonized/sage/structure/sage_object.c:7704)()
769 import sage.interfaces.fricas
770 G = sage.interfaces.fricas.fricas
--> 771 return self._interface_(G)
772
773 def _fricas_init_(self):
/usr/lib/python3/dist-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._interface_ (build/cythonized/sage/symbolic/expression.cpp:35189)()
1202 if is_a_constant(self._gobj):
1203 return self.pyobject()._interface_(I)
-> 1204 return super(Expression, self)._interface_(I)
1205
1206 def _maxima_(self, session=None):
/usr/lib/python3/dist-packages/sage/structure/sage_object.pyx in sage.structure.sage_object.SageObject._interface_ (build/cythonized/sage/structure/sage_object.c:5852)()
692 except Exception:
693 raise NotImplementedError("coercion of object %s to %s not implemented:\n%s\n%s" % (repr(self), I))
--> 694 X = I(s)
695 if c:
696 try:
/usr/lib/python3/dist-packages/sage/interfaces/interface.py in __call__(self, x, name)
293
294 if isinstance(x, str):
--> 295 return cls(self, x, name=name)
296 try:
297 # Special methods do not and should not have an option to
/usr/lib/python3/dist-packages/sage/interfaces/expect.py in __init__(self, parent, value, is_name, name)
1473 except (RuntimeError, ValueError) as x:
1474 self._session_number = -1
-> 1475 raise TypeError(*x.args)
1476 except BaseException:
1477 self._session_number = -1
TypeError: An error occurred when FriCAS evaluated 'x':
Function declaration sageprint : InputForm -> String has been added to
workspace.