WeBWorK Main Forum

Non-commutative expressions with negative exponents

Non-commutative expressions with negative exponents

by Darwyn Cook -
Number of replies: 2
I would like to write a problem whose answer is A^(-1)B, but the variables are non-commutative, ie BA^(-1) is incorrect. Matrices don't allow negative exponents as far as i can tell, so i am wondering what the easiest way to do this would be.

In reply to Darwyn Cook

Re: Non-commutative expressions with negative exponents

by Davide Cervone -
Actually, you can use negative powers for matrices, but that was added in a relatively recent version of pg, so you might need to update to get it. So you could do
    Context("Matrix");
    Context()->constants->add(
      A => Matrix([[1,2],[3,4]]),
      B => Matrix([[-1,e],[pi,sqrt(2)]]),
    );
    Context()->flags->set(
      formatStudentAnswer=>'parsed'
    );

    $BAinv = Formula("B A^(-1)");

    BEGIN_TEXT
    \( B A^{-1} \) = \{$BAinv->ans_rule\}
    END_TEXT

    ANS($BAinv->cmp);
to check for B A^(-1) as opposed to A^(-1) B.

Hope that helps.

Davide