Pattern Matching documentation + Expression identification

Issue #149 closed
Former user created an issue

Is there any documentation about how to use the pattern matching?

I get from the user pre defined expression, and trying to check if it is linear / polynomial equation:

a+2b+5=4c - Linear equation a^2 + b^7 = f^3 - polynomial

Can the pattern matching help me do it?

Thanks

Comments (2)

  1. Axel Kramer repo owner

    This should match a linear expression a+b*x:

    a_. + b_. * x_
    

    This should match a quadratic expression with nonzero linear term:

    a_. + b_. * x_ + c_. * x_^2
    

    I started a patterns and rules description document.

    For your use case the CoefficientList or the PolynomialQ function will probably better suitable?

    >> CoefficientList(a+b*x, x)
    {a,b}
    
    >> CoefficientList(a+b*x+c*x^2, x)
    {a,b,c}
    
    >> CoefficientList(a+c*x^2, x)
    {a,0,c}
    
  2. Log in to comment