1 | initial version |
You can define a function as shown in the comments.
Alternatively you can substitute into a noncommutative polynomial, e.g.:
R.<x,y,z> = FreeAlgebra(QQ, 3)
f = (x*y - y*x)*z # not zero
A = Matrix(QQ, [[0,1],[0,0]])
B = Matrix(QQ, [[1,1],[1,1]])
C = Matrix(QQ, [[0,-1],[-1,0]])
f.subs({x: A, y: B, z: C})