Another approach to this is to make Matrix-values constants
a and
b rather than Real-valued variables. For example:
Context("Numeric");
Context()->constants->add(
a => Matrix([1,2],[3,4]),
b => Matrix([pi,e],[0,sqrt(2)]),
);
Then when you make formulas with
a and
b, they will really be matrix formulas (though because the context is Numeric rather than Matrix, students can't enter matrices directly), and there will be a difference between
a*b
and
b*a
.
There is still a possibility that two different expressions in a and b that have the same value (since they are specific matrices, not variables), but I think it would be hard to come up with an example.
Note that there are a lot of operations you can't perform on a and b, like division, square roots, trig functions, etc., so you might want to remove those from the context.
Davide