@Mario: Thank you very much for the reply. I will have to go for this option If I am unable to fix `match()`
@Aaron: Sure. Regards, Thilina On Mon, Sep 16, 2013 at 3:43 AM, Aaron Meurer <asmeu...@gmail.com> wrote: > It's annoying to do this all the time, though. With dsolve and > classify_ode, I ended up writing a bunch of custom matchers, but it's > much less robust than using Wild() and match() when they work. > > Even for things that really do have to be algorithmically matched > (e.g., the homogeneous_order hint in the ODE module), it would be > better if it were done by passing a callable to Wild, rather than > writing a custom matcher with some mix of Wilds and Python code. > > Thilina, regardless of what you do, can you make sure you open an > issue for this bug (unless you fix it, then open a pull request). > > Aaron Meurer > > On Sun, Sep 15, 2013 at 3:17 PM, mario <mario.pern...@gmail.com> wrote: > > It is easy to write a custom match; in the following example there is a > > match for a quartic > > form; it is easy to write additional conditions, like restriction to 3 > > variables, integer coefficients, > > etc. > > > >>>> def match4(t): > > ... "match a quartic form" > > ... a = [] > > ... for xx in t.args: > > ... f = Factors(xx).factors > > ... c = 1 > > ... d = {} > > ... tot_deg = 0 > > ... for k, v in f.items(): > > ... if k.is_number: > > ... c = c*k**v > > ... else: > > ... d[k] = v > > ... if not v.is_integer or v < 0: > > ... return None > > ... tot_deg += v > > ... if tot_deg != 4: > > ... return None > > ... a.append((c, d)) > > ... return a > > ... > >>>> t = x**2*y**2 - 2*x**2*y*z + x**2*z**2 - 2*x*y**2*z - 2*x*y*z**2 + > >>>> y**2*z**2 > >>>> match4(t) > > [(1, {z: 2, y: 2}), (-2, {x: 1, z: 2, y: 1}), (1, {x: 2, z: 2}), (-2, > {x: 1, > > z: 1, y: 2}), (-2, {x: 2, z: 1, y: 1}), (1, {x: 2, y: 2})] > > > > > > > > On Sunday, September 15, 2013 8:13:29 PM UTC+2, Thilina Rathnayake wrote: > >> > >> Hi All, > >> > >> Addressing issue 4004, the equation after expanding can be written as > >> below, > >> > >>> In [1]: t = (x*y + y*z + x*z)**2 - 4*x*y*z*(x + y + z) > >>> In [2]: expand(t) > >>> Out[2]: > >>> 2 2 2 2 2 2 2 2 2 > >>> x ⋅y - 2⋅x ⋅y⋅z + x ⋅z - 2⋅x⋅y ⋅z - 2⋅x⋅y⋅z + y ⋅z > >> > >> > >> This is of the form `X**2 + Y**2 + Z**2 - 2*X*Y - 2*Y*Z - 2*X*Z` with X > = > >> x*y, Y = y*z and > >> Z = z*x. Latter can be solved by the Diophantine module for X, Y, Z and > we > >> can recover > >> solutions for x, y and z. > >> > >> I tried to automate this process with Wild's and `match()` but couldn't > >> do it. Given > >> an expression, I tried to determine if it is in the form `ap**2 + bq**2 > + > >> cr**2 + d*p*q + e*q*r + f*r*p` > >> where a, b, c, d, e, f are Wilds trying to match Integers(used > exclude=[x, > >> y, z] while > >> creating these) and p, q, r trying to match the variables. > >> > >> In[3]: _.match(a*p**2 + b*q**2 + c*r**2 + d*p*q + e*q*r + f*r*q) > >> > >> Above kept running forever. Is there a way to efficiently pattern match > an > >> expression > >> so that we can decide whether it belongs to a particular form or not? > >> > >> Regards, > >> Thilina. > >> > > -- > > 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+unsubscr...@googlegroups.com. > > To post to this group, send email to sympy@googlegroups.com. > > Visit this group at http://groups.google.com/group/sympy. > > For more options, visit https://groups.google.com/groups/opt_out. > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > Visit this group at http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.