NCSOStoolsdemo - Basics of toolbox for symbolic computation with polynomials in noncommuting variables
%**************************************************************************
% Toolbox for symbolic computation with polynomials in noncommuting *
% variables *
%**************************************************************************
% -------------------------------------------------------------------------
% First we construct some symbolic noncommuting variables.
% -------------------------------------------------------------------------
>> NCvars x y z
% -------------------------------------------------------------------------
% Now we can define some polynomials in noncommuting variables.
% -------------------------------------------------------------------------
>> f = x^2 + 5*x*y - y*z + 3*x*y*z;
>> g = 2*y*z - z^2;
% -------------------------------------------------------------------------
% All basic arithmetic operations are defined in standard way.
% -------------------------------------------------------------------------
>> f + g, f - g, f*g, -f, g^2, g'
ans = x^2+5*x*y+3*x*y*z+y*z-z^2
ans = x^2+5*x*y+3*x*y*z-3*y*z+z^2
ans = 2*x^2*y*z-x^2*z^2+10*x*y^2*z+6*x*y*z*y*z-5*x*y*z^2-3*x*y*z^3-2*y*z*y*z+y*z^3
ans = -x^2-5*x*y-3*x*y*z+y*z
ans = 4*y*z*y*z-2*y*z^3-2*z^2*y*z+z^4
ans = 2*z*y-z^2
% -------------------------------------------------------------------------
% We can also define matrices of such polynomials.
% -------------------------------------------------------------------------
>> A = [2*x*y, x]
A = 2*x*y x
>> B = [x*y + x, y; y^2, x - y]
B = x+x*y y
y^2 x-y
% -------------------------------------------------------------------------
% All basic operations on such matrices are defined.
% -------------------------------------------------------------------------
>> A*B, B*B, B.*B, A', trace(B), diag(B), triu(B), [A; sum(B)]
ans = 2*x*y*x+2*x*y*x*y+x*y^2 x^2-x*y+2*x*y^2
ans = x^2+x^2*y+x*y*x+x*y*x*y+y^3 x*y+x*y^2+y*x-y^2
x*y^2+y^2*x+y^2*x*y-y^3 x^2-x*y-y*x+y^2+y^3
ans = x^2+x^2*y+x*y*x+x*y*x*y y^2
y^4 x^2-x*y-y*x+y^2
ans = 2*y*x
x
ans = 2*x+x*y-y
ans = x+x*y
x-y
ans = x+x*y y
0 x-y
ans = 2*x*y x
x+x*y+y^2 x
% -------------------------------------------------------------------------
% We can also do symbolic (in)equality test.
% -------------------------------------------------------------------------
>> B
B = x+x*y y
y^2 x-y
>> B + diag(diag(B)) == tril(B) + triu(B)
ans = 1 1
1 1
>> B ~= B'
ans = 1 0
1 0
% -------------------------------------------------------------------------
% We can evaluates a polynomial with substitutions and write monomials
% shortly using exponents or in expanded form without using exponents
% regardless of the parameter NC_using_exponents set in NCparam.m.
% -------------------------------------------------------------------------
>> f
f = x^2+5*x*y+3*x*y*z-y*z
>> NCeval(f,{{x,x+y},{y,x-y},{z,0}})
ans = 6*x^2-4*x*y+6*y*x-4*y^2
>> NCexpand(ans)
ans = 6*x*x-4*x*y+6*y*x-4*y*y
>> NCsimplify(ans)
ans = 6*x^2-4*x*y+6*y*x-4*y^2