Status: New
Owner: asmeurer
Labels: Type-Defect Priority-Medium
New issue 1577 by asmeurer: match doesn't put every wild as a key
http://code.google.com/p/sympy/issues/detail?id=1577
In [2]: a = Wild('a', exclude=[f(x)])
In [3]: b = Wild('b', exclude=[f(x)])
In [4]: c = Wild('c', exclude=[f(x)])
In [5]: n = Wild('n', exclude=[f(x)])
In [6]: s = a*diff(f(x),x) + b*f(x) + c*f(x)**n
In [7]: eq = f(x).diff(x)
In [8]: r = eq.match(s)
In [9]: r
Out[9]: {a: 1, b: 0, c: 0}
In [10]: r[n]
<raises KeyError>
I need for r[n] to return something. 0 was what I was expecting, but even
something like NaN or None would be
fine. I realize that, mathematically speaking, with r[c] == 0, r[n] can be
anything. But if r[c] is 0 and I want to test
r[n], then I have to either except a KeyError (bad idea. I my match
expression is flawed somehow, it would mask it),
or else every time I have something like this, I have to check first if
r[c] == 0 before I test r[n]. That might be trivial
in this case, but I can easily imagine a match expression that is not much
more complex than this one where doing
that would make a simple if statement more than a line long. Consider
something like a*x**n*y**m*z**p, where a,
n, m, and p are all Wilds. Or you could even end up having two or more
Wilds multiplying each other, because they
have different "excludes". You would have to check if every single Wild is
zero in the match dictionary in such a way
that it doesn't raise a KeyError if the wild is not in the dictionary.
By the way, the above is the match for the Bernoulli ODE from dsolve(), and
the solution method is only valid if r[n]
!= 1.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en
-~----------~----~----~----~------~----~------~--~---