solve traceback

72 views
Skip to first unread message

G B

unread,
Mar 31, 2015, 10:44:52 PM3/31/15
to sy...@googlegroups.com
Hi--

I'm trying to solve a system of 2 equations.  They are the result of substituting initial conditions into the solution returned from dsolve are of the form f(0)=expr, where f is a Function, and 0 is zero.

I'm calling it with solve([InitCond1,InitCond2],(C1,C2))

What is interesting is that it fails the first time, but succeeds when I call it a second time and then succeeds every time after.  I haven't verified the that the solution is accurate.

The traceback follows:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in getit(self)
    216         try:
--> 217             return self._assumptions[fact]
    218         except KeyError:

KeyError: 'zero'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in getit(self)
    216         try:
--> 217             return self._assumptions[fact]
    218         except KeyError:

KeyError: 'zero'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in getit(self)
    216         try:
--> 217             return self._assumptions[fact]
    218         except KeyError:

KeyError: 'real'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-30-b2993472ce67> in <module>()
----> 1 initConds=solve([InitCond1,InitCond2],(C1,C2))
      2 initConds

//anaconda/lib/python3.4/site-packages/sympy/solvers/solvers.py in solve(f, *symbols, **flags)
    909         solution = _solve(f[0], *symbols, **flags)
    910     else:
--> 911         solution = _solve_system(f, symbols, **flags)
    912 
    913     #

//anaconda/lib/python3.4/site-packages/sympy/solvers/solvers.py in _solve_system(exprs, symbols, **flags)
   1446         i, d = _invert(g, *symbols)
   1447         g = d - i
-> 1448         g = g.as_numer_denom()[0]
   1449         if manual:
   1450             failed.append(g)

//anaconda/lib/python3.4/site-packages/sympy/core/add.py in as_numer_denom(self)
    433         denoms, numers = [list(i) for i in zip(*iter(nd.items()))]
    434         n, d = self.func(*[Mul(*(denoms[:i] + [numers[i]] + denoms[i + 1:]))
--> 435                    for i in range(len(numers))]), Mul(*denoms)
    436 
    437         return _keep_coeff(ncon, n), _keep_coeff(dcon, d)

//anaconda/lib/python3.4/site-packages/sympy/core/add.py in <listcomp>(.0)
    433         denoms, numers = [list(i) for i in zip(*iter(nd.items()))]
    434         n, d = self.func(*[Mul(*(denoms[:i] + [numers[i]] + denoms[i + 1:]))
--> 435                    for i in range(len(numers))]), Mul(*denoms)
    436 
    437         return _keep_coeff(ncon, n), _keep_coeff(dcon, d)

//anaconda/lib/python3.4/site-packages/sympy/core/operations.py in __new__(cls, *args, **options)
     39             return args[0]
     40 
---> 41         c_part, nc_part, order_symbols = cls.flatten(args)
     42         is_commutative = not nc_part
     43         obj = cls._from_args(c_part + nc_part, is_commutative)

//anaconda/lib/python3.4/site-packages/sympy/core/mul.py in flatten(cls, seq)
    181                 a, b = b, a
    182             assert not a is S.One
--> 183             if not a.is_zero and a.is_Rational:
    184                 r, b = b.as_coeff_Mul()
    185                 if b.is_Add:

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in getit(self)
    219             if self._assumptions is self.default_assumptions:
    220                 self._assumptions = self.default_assumptions.copy()
--> 221             return _ask(fact, self)
    222 
    223     getit.func_name = as_property(fact)

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in _ask(fact, obj)
    262         pass
    263     else:
--> 264         a = evaluate(obj)
    265         if a is not None:
    266             assumptions.deduce_all_facts(((fact, a),))

//anaconda/lib/python3.4/site-packages/sympy/core/mul.py in _eval_is_zero(self)
    989         zero = infinite = False
    990         for a in self.args:
--> 991             z = a.is_zero
    992             if z:
    993                 if infinite:

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in getit(self)
    219             if self._assumptions is self.default_assumptions:
    220                 self._assumptions = self.default_assumptions.copy()
--> 221             return _ask(fact, self)
    222 
    223     getit.func_name = as_property(fact)

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in _ask(fact, obj)
    274             continue
    275         if pk in handler_map:
--> 276             _ask(pk, obj)
    277 
    278             # we might have found the value of fact

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in _ask(fact, obj)
    262         pass
    263     else:
--> 264         a = evaluate(obj)
    265         if a is not None:
    266             assumptions.deduce_all_facts(((fact, a),))

//anaconda/lib/python3.4/site-packages/sympy/core/expr.py in _eval_is_positive(self)
    662     def _eval_is_positive(self):
    663         if self.is_number:
--> 664             if self.is_real is False:
    665                 return False
    666             try:

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in getit(self)
    219             if self._assumptions is self.default_assumptions:
    220                 self._assumptions = self.default_assumptions.copy()
--> 221             return _ask(fact, self)
    222 
    223     getit.func_name = as_property(fact)

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in _ask(fact, obj)
    274             continue
    275         if pk in handler_map:
--> 276             _ask(pk, obj)
    277 
    278             # we might have found the value of fact

//anaconda/lib/python3.4/site-packages/sympy/core/assumptions.py in _ask(fact, obj)
    262         pass
    263     else:
--> 264         a = evaluate(obj)
    265         if a is not None:
    266             assumptions.deduce_all_facts(((fact, a),))

//anaconda/lib/python3.4/site-packages/sympy/core/expr.py in _eval_is_negative(self)
    692             try:
    693                 # check to see that we can get a value
--> 694                 n2 = self._eval_evalf(2)
    695                 if n2 is None:
    696                     raise AttributeError

//anaconda/lib/python3.4/site-packages/sympy/core/function.py in _eval_evalf(self, prec)
    484 
    485         with mpmath.workprec(prec):
--> 486             v = func(*args)
    487 
    488         return Expr._from_mpmath(v, prec)

TypeError: 'mpc' object is not callable

G B

unread,
Apr 2, 2015, 5:37:40 PM4/2/15
to sy...@googlegroups.com
It looks like the root cause of this is that the Function doesn't have all the assumptions set.  I don't fully understand how assumptions are wired in, and I know the assumptions system is in flux, but it looks like None is a flag for "exists but not set".  Would it be better to have FactKB inherit from defaultdict, rather than dict, so that all unset assumptions return None?  That could prevent these types of exceptions...


If I do: 

Qinit=symbols('Qinit')
InitCond1.subs(Q(0),Qinit)

then solve succeeds.  


Looking at Q(0)._assumptions:
{'commutative': True, 'complex': True}

And Qinit._assumptions:
{'algebraic': None,
 'antihermitian': None,
 'commutative': True,
 'complex': None,
 'even': None,
 'finite': None,
 'hermitian': None,
 'imaginary': None,
 'infinite': None,
 'integer': None,
 'irrational': None,
 'negative': None,
 'nonnegative': None,
 'nonpositive': None,
 'odd': None,
 'polar': None,
 'positive': None,
 'rational': None,
 'real': None,
 'zero': None}
...

Sudhanshu Mishra

unread,
Apr 2, 2015, 5:47:27 PM4/2/15
to sy...@googlegroups.com
Hi,

This seems interesting and might be a bug. Could you please create an issue here with your equations and traceback.

Sudhanshu Mishra

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/3003cfc4-3c43-4cd1-917f-592cff17c7a3%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

G B

unread,
Apr 3, 2015, 6:34:35 PM4/3/15
to sy...@googlegroups.com
Ok, I'll see if I can put together a simple test case.
Reply all
Reply to author
Forward
0 new messages