quadratic equation pattern matching

Issue #101 closed
Former user created an issue

How can I check if an IExpr is a quadratic equation with the pattern matching?

Comments (2)

  1. Axel Kramer repo owner

    If you're logged in the online interface with your google account,

    symjaweb.appspot.com

    you can define these rules:

    $QuadraticQ(u_,x_Symbol) := 
      $PolyQ(u,x,2);
    $PolyQ(u_,x_Symbol,n_Integer) :=
      If(ListQ(u), Catch(Scan(Function(If(Not($PolyQ(#,x,n)),Throw(False))),u); True),
      PolynomialQ(u,x) && Exponent(u,x)==n && Coefficient(u,x,n)=!=0)
    
    >>> $QuadraticQ(4*x^2+3*x,x)
    True
    
    >>> $QuadraticQ(3*x,x)
    False
    

    If you would like to use the library in single user mode in a Java program, you can define:

    Config.SERVER_MODE = true;
    

    at the start of the program and can use QuadraticQ and PolyQ directly as identifiers without the leading '$' character.

  2. Log in to comment