Bug in ODE solving?
I am trying to solve this equation system
F’(x) = Sin(x)*F(x)+G(x) G’(x) = F(x)
For some reason, putting this in sagemath:
var('xx','real')
assume(xx>0)
assume(sin(xx)>0)
f,g=[function(i)(xx) for i in 'fg']
eq= [g+sin(xx)*f==diff(f),diff(g)-f==0]
desolve_system(eq,[f,g],ivar=xx)
It yield an error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last) <ipython-input-1-71dd73b24497> in <module>() 4 f,g=[function(i)(xx) for i in 'fg'] 5 eq= [g+sin(xx)*f==diff(f),diff(g)-f==Integer(0)] ----> 6 desolve_system(eq,[f,g],ivar=xx)
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/calculus/desolvers.pyc in desolve_system(des, vars, ics, ivar) 838 soln = list(soln) 839 for i, sol in enumerate(soln): --> 840 soln[i] = sol.sage() 841 if ics is not None: 842 ivar_ic = ics[0]
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in sage(self, args, *kwds) 1049 [0 0] 1050 """ -> 1051 return self._sage_(args, *kwds) 1052 1053 def __repr__(self):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/interfaces/maxima_abstract.pyc in _sage_(self) 1236 import sage.calculus.calculus as calculus 1237 return calculus.symbolic_expression_from_maxima_string(self.name(), -> 1238 maxima=self.parent()) 1239 1240 def _symbolic_(self, R):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in symbolic_expression_from_maxima_string(x, equals_sub, maxima) 2153 global _augmented_syms 2154 _augmented_syms = syms -> 2155 return SRM_parser.parse_sequence(s) 2156 finally: 2157 _augmented_syms = {}
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:5409)() 537 return expr 538 --> 539 cpdef parse_sequence(self, s): 540 """ 541 Parse a (possibly nested) set of lists and tuples.
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:5276)() 553 """ 554 cdef Tokenizer tokens = Tokenizer(s) --> 555 all = self.p_sequence(tokens) 556 if tokens.next() != EOS: 557 self.parse_error(tokens)
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_sequence (build/cythonized/sage/misc/parser.c:6213)() 626 return all 627 else: --> 628 obj = self.p_eqn(tokens) 629 PyList_Append(all, obj) 630 token = tokens.next()
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_eqn (build/cythonized/sage/misc/parser.c:7123)() 719 cdef int op = tokens.next() 720 if op == '=': --> 721 return lhs == self.p_expr(tokens) 722 elif op == NOT_EQ: 723 return lhs != self.p_expr(tokens)
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:7489)() 756 # Note: this is left-recursive, so we can't just recurse 757 cdef int op --> 758 operand1 = self.p_term(tokens) 759 op = tokens.next() 760 while op == '+' or op == '-':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:7769)() 790 # Note: this is left-recursive, so we can't just recurse 791 cdef int op --> 792 operand1 = self.p_factor(tokens) 793 op = tokens.next() 794 if op == NAME and self.implicit_multiplication:
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_factor (build/cythonized/sage/misc/parser.c:8224)() 833 else: 834 tokens.backtrack() --> 835 return self.p_power(tokens) 836 837 # power ::= (atom | atom!) ^ factor | atom | atom!
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_power (build/cythonized/sage/misc/parser.c:8387)() 861 862 """ --> 863 operand1 = self.p_atom(tokens) 864 cdef int token = tokens.next() 865 if token == '^':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_atom (build/cythonized/sage/misc/parser.c:9056)() 916 if token == '(': 917 func = self.callable_constructor(name) --> 918 args, kwds = self.p_args(tokens) 919 token = tokens.next() 920 if token != ')':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_args (build/cythonized/sage/misc/parser.c:9611)() 953 cdef int token = ',' 954 while token == ',': --> 955 arg = self.p_arg(tokens) 956 if isinstance(arg, tuple): 957 name, value = arg
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_arg (build/cythonized/sage/misc/parser.c:10044)() 1003 else: 1004 tokens.backtrack() -> 1005 return self.p_expr(tokens) 1006 1007 cdef parse_error(self, Tokenizer tokens, msg="Malformed expression"):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:7489)() 756 # Note: this is left-recursive, so we can't just recurse 757 cdef int op --> 758 operand1 = self.p_term(tokens) 759 op = tokens.next() 760 while op == '+' or op == '-':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:7769)() 790 # Note: this is left-recursive, so we can't just recurse 791 cdef int op --> 792 operand1 = self.p_factor(tokens) 793 op = tokens.next() 794 if op == NAME and self.implicit_multiplication:
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_factor (build/cythonized/sage/misc/parser.c:8224)() 833 else: 834 tokens.backtrack() --> 835 return self.p_power(tokens) 836 837 # power ::= (atom | atom!) ^ factor | atom | atom!
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_power (build/cythonized/sage/misc/parser.c:8387)() 861 862 """ --> 863 operand1 = self.p_atom(tokens) 864 cdef int token = tokens.next() 865 if token == '^':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_atom (build/cythonized/sage/misc/parser.c:9280)() 925 return self.variable_constructor(name) 926 elif token == '(': --> 927 expr = self.p_expr(tokens) 928 token = tokens.next() 929 if token != ')':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:7489)() 756 # Note: this is left-recursive, so we can't just recurse 757 cdef int op --> 758 operand1 = self.p_term(tokens) 759 op = tokens.next() 760 while op == '+' or op == '-':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:7769)() 790 # Note: this is left-recursive, so we can't just recurse 791 cdef int op --> 792 operand1 = self.p_factor(tokens) 793 op = tokens.next() 794 if op == NAME and self.implicit_multiplication:
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_factor (build/cythonized/sage/misc/parser.c:8224)() 833 else: 834 tokens.backtrack() --> 835 return self.p_power(tokens) 836 837 # power ::= (atom | atom!) ^ factor | atom | atom!
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_power (build/cythonized/sage/misc/parser.c:8387)() 861 862 """ --> 863 operand1 = self.p_atom(tokens) 864 cdef int token = tokens.next() 865 if token == '^':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_atom (build/cythonized/sage/misc/parser.c:9280)() 925 return self.variable_constructor(name) 926 elif token == '(': --> 927 expr = self.p_expr(tokens) 928 token = tokens.next() 929 if token != ')':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:7489)() 756 # Note: this is left-recursive, so we can't just recurse 757 cdef int op --> 758 operand1 = self.p_term(tokens) 759 op = tokens.next() 760 while op == '+' or op == '-':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:7854)() 796 tokens.backtrack() 797 while op == '' or op == '/': --> 798 operand2 = self.p_factor(tokens) 799 if op == '': 800 operand1 = operand1 * operand2
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_factor (build/cythonized/sage/misc/parser.c:8224)() 833 else: 834 tokens.backtrack() --> 835 return self.p_power(tokens) 836 837 # power ::= (atom | atom!) ^ factor | atom | atom!
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_power (build/cythonized/sage/misc/parser.c:8387)() 861 862 """ --> 863 operand1 = self.p_atom(tokens) 864 cdef int token = tokens.next() 865 if token == '^':
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_atom (build/cythonized/sage/misc/parser.c:9171)() 920 if token != ')': 921 self.parse_error(tokens, "Bad function call") --> 922 return func(args, *kwds) 923 else: 924 tokens.backtrack()
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in dummy_laplace(args) 1871 laplace(f(t), t, s) 1872 """ -> 1873 return _laplace(args[0], var(repr(args[1])), var(repr(args[2]))) 1874 1875 def dummy_inverse_laplace(args):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/symbolic/ring.pyx in sage.symbolic.ring.var (build/cythonized/sage/symbolic/ring.cpp:14039)() 1297 ValueError: The name "3" is not a valid Python identifier. 1298 """ -> 1299 return SR.var(name, **kwds) 1300 1301 def is_SymbolicVariable(x):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/symbolic/ring.pyx in sage.symbolic.ring.SymbolicRing.var (build/cythonized/sage/symbolic/ring.cpp:10242)() 840 for s in names_list: 841 if not isidentifier(s): --> 842 raise ValueError('The name "'+s+'" is not a valid Python identifier.') 843 844 formatted_latex_name = None
ValueError: The name "+" is not a valid Python identifier.
It seems Sage has trouble parsing the output from Maxima. Can you/someone try solving the same system in Maxima (with
desolve
I presume) and adding the output?This is the bug reported in https://trac.sagemath.org/ticket/23445. Unfortunately, it has not been fixed yet...
@Chernoxyl
To display blocks of code or error messages, skip a line above and below, and do one of the following (all give the same result):
For instance, typing
produces:
Please edit your question to do that.