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}
On Tuesday, March 31, 2015 at 7:44:52 PM UTC-7, G B wrote:
>
> 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)
>
> ...
--
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 [email protected].
To post to this group, send email to [email protected].
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.