On Thu, 1 Jul 2010 13:40:03 -0700 (PDT)
jeral <jeral2...@gmail.com> wrote:

> Hi, All.
> 
> Is there any way in sage to match not only given expression against
> pattern, but equivalent expressions too?
> Say, i want to match expression with pattern pat = c*x^p*y^q*z^r,
> 
> (2*x^2*y^3*z^4).match(pat)
> 
> works fine, but
> (x*y).match(pat)
> returns None, while x*y is special case of c*x^p*y^q*z^r.
> Maybe there is a way to match such expressions other, than to write
> additional patterns by hand?

No, we don't support this style of pattern matching.

Here is an alternative method to detect power products:

def is_power_product(ex):
    """
    EXAMPLES::

        sage: var('x,y,z')
        (x, y, z)
        sage: is_power_product(x)
        True
        sage: is_power_product(x*y^2)
        True
        sage: is_power_product(2*x*y^2)
        True
        sage: is_power_product(2*pi*x*y^2)
        True
        sage: is_power_product(sin(x))
        False
        sage: is_power_product(x+y)
        False
    """
    def test_power(t):
        op = t.operator()
        return op is None or op is operator.pow
    op = ex.operator()
    return op is None or op is operator.pow or \
            (op is operator.mul and all(test_power(t) for t in
            ex.operands()))


Cheers,
Burcin

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to