> On Jun 19, 6:42 pm, "Aaron S. Meurer" <[email protected]> wrote:
>> I have been working on getting separable equations in dsolve, and I
>> noticed this:
>>>>> c = Wild('c', exclude=[y])
>>>>> d = Wild('d', exclude=[x])
>>>>> (x).match(c*d)
>> {c: x, d: 1}
>>>>> (log(x)).match(c*d)
>> {c: log(x), d: 1}
>>>>> (x*log(x)).match(c*d)
>> <Returns None>
>>
>> I would like for the last one to return {c:x*log(x), d:1}.
Although you could get what you want by using the .as_independent()
method, I agree that the expected behavior is missing.
> I have also noticed this with the same Wild variables:
>
>>>> print (exp(x)*exp(y)).match(c*d)
> {d_: exp(y), c_: exp(x)}
>>>> print (exp(x)*exp(y)*y).match(c*d)
> {d_: y*exp(y), c_: exp(x)}
>>>> print (x*exp(x)*exp(y)*y).match(c*d)
> None
>
Ahh...but the common base (E) gathers in the x and y so that x*exp(x)
*exp(y)*y really exists as something else:
###
>>> x*exp(x)*exp(y)*y
x*y*exp(x + y)
###
So after finding the "x" the rest of the expression does not match a
non-x pattern so the matching fails. It seems to me, however, that
match should split up a function as long as no assumptions would be
violated. In the case of exp(x+y) are there any assumptions that would
be violated by breaking this up as exp(x)*exp(y)? (In the case of sqrt
(x*y) we could only break it up into sqrt(x)*sqrt(y) if x and y are
not both negative.)
But if you do that, then you should probably handle all of the
following:
powers as products:
a**(x+y) = a**x*a**y
function as product:
exp(x+y) = exp(x)*exp(y)
sqrt(x*y) = sqrt(x)*sqrt(y) if not(x<0 and y<0) else -sqrt(x)*sqrt(y)
log(x,y) = log(x)*log(y)**-1
sums as product:
[sin (x+y) + sin (x-y)]/2 = sinx cosy
[sin (x+y) - sin (x-y)]/2 = cosx siny
[cos (x+y) + cos (x-y)]/2 = cosx cosy
-[cos (x+y) - cos (x-y)]/2 = sinx siny
sums as constants:
(sinx)**2 + (cosx)**2 = 1
(secx)**2 - (tanx)**2 = 1
(cscx)**2 - (cotx)**2 = 1
function as sum
log(x*y) = log(x) + log(y)
products as sums
2 sin((x+y)/2) cos((x-y)/2) = sinx + siny
2 sin((x-y)/2) cos((x+y)/2) = sinx - siny
2 cos((x+y)/2) cos((x-y)/2) = cosx + cosy
-2 sin((x+y)/2) sin((x-y)/2) = cosx - cosy
Am I missing anything? Is this the way to go with pattern matching?
/c
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" 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?hl=en
-~----------~----~----~----~------~----~------~--~---