The Most Basic Commands -- A short tutorial

tp[x] denotes the transpose of an element x, and aj[x] denotes the adjoint of an element x. Note that the properties of transposes and adjoints that everyone uses constantly are built-in. The multiplicative identity is denoted Id in the program. At the present time, Id is set to 1. An element A may have an inverse, which will be denoted by inv[A], or it may have a left or right inverse, denoted invL[A] and invR[A] respectively.

Each example is independent of the rest and assumes that you are executing it as the first command after you load in our packages. For this reason, every time we want to show a feature of a typical command, like the SetLinear command we explicitly invoke the SetLinear command (even though once one says SetLinear[f], f will remain linear for the rest of your Mathematica session until changed or redefined).

At present, single-letter lower case variables are non-commutative by default and all others are commutative by default.

When the lower case variables are non-commutative then we get the following:


In[1]:= a ** b - b ** a 
Out[1]= a ** b - b ** a

In[2]:= A ** B - B ** A 
Out[2]= 0

In[3]:= A ** b - b ** a
Out[3]= A b - b ** a

In[4]:= CommuteEverything[a ** b - b ** a] 
Out[4]= 0

In[5]:= SetNonCommutative[A, B]
Out[5]= {False, False}

In[6]:= A ** B - B ** A
Out[6]= A ** B - B ** A     

In[7]:= SetNonCommutative[A];SetCommutative[B]
Out[7]= {True} 

In[8]:= A ** B - B ** A
Out[8]= 0     

SNC is an alias for SetNonCommutative. So, SNC can be typed rather than the longer SetNonCommutative.
In[9]:= SNC[A];         
In[10]:= A ** a - a ** A  
Out[10]= A ** a - a ** A 

In[11]:= SetCommutative[v]; 
In[12]:= v ** b
Out[12]= v b

In[13]:= NCCollect[a ** x + b ** x, x]
Out[13]= (a + b) ** x

In[14]:= NCExpand[(a + b) ** x]
Out[14]= a ** x + b ** x

In[15]:= NCCollect[tp[x] ** a ** x + tp[x] ** b ** x + z, {x, tp[x]}]  
Out[15]= z + tp[x] ** (a+b) ** x 

In[16]:= DirectionalD[x ** x, x, h]
Out[16]= h ** x + x ** h

In[17]:= Grad[tp[x] ** x + tp[x]**A**x + m**x, x]
         (* Here A is noncommutative and x represents a column vector*)
Out[17]= 2 x + A ** x + tp[A] ** x + tp[m]

Warning: Grad is trustworthy only on certain quadratics.

IMPORTANT: The Mathematica substitute commands \. -> and \:> are not reliable in NCAlgebra, so you must use our substitute command.


In[18]:= Substitute[x ** a ** b, a ** b -> c]
Out[18]= x ** c

In[19]:= Substitute[ tp[b ** a] + b ** a, b ** a -> p]  
Out[19]= p + tp[a] ** tp[b] 

In[20]:= SubstituteSymmetric[tp[b] ** tp[a] + w + a ** b, a**b->c] 
Out[20]= c + w + tp[c] 

In[21]:= MatMult[{{a, b}, {c, d}}, {{d, 2}, {e, 3}}]  
Out[21]= {{a ** d + b ** e, 2 a + 3 b}, {c ** d + d ** e, 2 c + 3 d}}

In[22]:= tp[a ** b]
Out[22]= tp[b] ** tp[a]

In[23]:=tp[5]
Out[23]= 5

In[24]:= tp[2 + 3 I]
Out[24]= 2 + 3 I

In[25]:= tp[a]
Out[25]= tp[a]

In[26]:= tp[a + b]
Out[26]= tp[a] + tp[b]

In[27]:= tp[6 x]
Out[27]= 6 tp[x]

In[28]:= tp[tp[a]]
Out[28]= a

In[29]:= aj[5]
Out[29]= 5

In[30]:= aj[2 + 3 I]
Out[30]= 2 - 3 I

In[31]:= aj[a]  
Out[31]= aj[a]

In[32]:= aj[a + b] 
Out[32]= aj[a] + aj[b]

In[33]:= aj[6 x] 
Out[33]= 6 aj[x]

In[34]:= aj[aj[a]]  
Out[34]= a

In[35]:= Id 
Out[35]= 1

In[36]:= inv[a ** b]  
Out[36]= inv[b] ** inv[a]

In[37]:= inv[a] ** a
Out[37]= 1

In[38]:= a ** inv[a] 
Out[38]= 1

In[39]:= a ** b ** inv[b] 
Out[39]= a

In[40]:= invL[a] ** a
Out[40]= 1

In[41]:= a ** invR[a]
Out[41]= 1

In[42]:= a ** invL[a] 
Out[42]= a ** invL[a]

In[43]:= invR[a] ** a 
Out[43]= invR[a] ** a 

In[44]:= f1 = 1 + inv[d] ** c ** inv[S - a] ** b - inv[d] ** c ** 
    inv[S - a + b ** inv[d] ** c] ** b - inv[d] ** c ** 
    inv[S - a + b ** inv[d] ** c] ** b ** inv[d] ** c ** 
    inv[S - a] ** b;
In[45]:= NCSimplifyRational[f1]
Out[45]= 1

In[46]:= f2 = inv[1 + 2 a] ** a; 
In[47]:= NCSimplifyRational[f2]
Out[47]= [1 - inv(1 + 2 a)] / 2

NCSR is the alias for NCSimplifyRational.
In[48]:= f3 = a ** inv[1 - a]; 
In[49]:= NCSR[f3] 
Out[49]= inv[1 - a] - 1
 
In[50]:= f4 = inv[1 - b ** a] ** inv[a]; 
In[51]:= NCSR[f4]  
Out[51]= inv[a] ** inv[1 - a ** b]

In[52]:= NCSolve[a ** x == b, x] 
Out[52]= {x -> inv[a] ** b}    

Note: Linear equations in one unknown only.
In[53]:= SetIsometry[s]; 
In[54]:= IsometryQ[s] 
Out[54]= True

In[55]:= SetIsometry[s]; 
In[56]:= aj[s] ** s 
Out[56]= 1

Remember the line In[55] is redundant and unnecessary. Nevertheless, it is restated for the sake of clarity. Normally, In[55] would be left out, because s is still defined as in line In[53].
In[57]:= SetIsometry[s]; 
In[58]:= tp[s] ** s
Out[58]= 1

In[59]:= SetSelfAdjoint[t]; 
In[60]:= tp[t] 
Out[60]= t

In[61]:= SetSelfAdjoint[t]; 
In[62]:= aj[t] 
Out[62]= t

In[63]:= SetProjection[p]; 
In[64]:= p ** p 
Out[64]= p

In[65]:= SetCoIsometry[s]; 
In[66]:= s ** tp[s] 
Out[66]= 1  

In[67]:= SetCoIsometry[w]; 
In[68]:= w** aj[w] 
Out[68]= 1  

In[69]:= SetInv[x]; 
In[70]:= invL[x] 
Out[70]= inv[x]

In[71]:= SetInv[x]; 
In[72]:= invR[x]
Out[72]= inv[x]

In[73]:= SetLinear[f]; 
In[74]:= f[x + y]  
Out[74]= f[x] + f[y]

In[75]:= SetLinear[f]; 
In[76]:= f[(2 + 3 I) x ]  
Out[76]= (2 + 3 I) f[x]

In[77]:= SetConjugateLinear[q]; 
In[78]:= q[x + y]
Out[78]= q[x] + f[y]

In[79]:= SetConjugateLinear[g]; 
In[80]:= g[(2 + 3 I) x ]  
Out[80]= 2 g[x] - 3 I g[x]

In[81]:= SetBilinear[h]; 
In[82]:= h[x + y, w] 
Out[82]= h[x, w] + h[y, w]

In[83]:= SetBilinear[f]; 
In[84]:= f[w, x + y] 
Out[84]= f[w, x] + f[w, y]

In[85]:= SetBilinear[f]; 
In[86]:= f[(2 + 3 I) x, w ] 
Out[86]= (2 + 3 I) f[x, w]

In[87]:= SetBilinear[f]; 
In[88]:= f[w,(2 + 3 I) x] 
Out[88]= (2 + 3 I) f[w, x]

In[89]:= SetSesquilinear[f]; 
In[90]:= f[x + y, w]  
Out[90]= f[x, w] + f[y, w]

In[91]:= SetSesquilinear[f]; 
In[92]:= f[w, x + y]  
Out[92]= f[w, x] + f[w, y]

In[93]:= SetSesquilinear[f]; 
In[94]:= f[(2 + 3 I) x, w] 
Out[94]= (2 + 3 I) f[x, w]

In[95]:= SetSesquilinear[f]; 
In[96]:= f[w,(2 + 3 I) x] 
Out[96]= (2 - 3 I) f[w, x]

In[97]:= SetIdempotent[f]; 
In[98]:= f[f[w]]  
Out[98]= w

In[99]:= SetCommutingFunctions[f, g]; LeftQ[f, g] = True; 
In[100]:= g[f[x]] 
Out[100]= f[g[x]]

In[101]:= SetCommutingFunctions[f, g]; LeftQ[f, g] = True; 
In[102]:= f[g[x]] 
Out[102]= f[g[x]]

In[103]:= SetCommutingFunctions[f, g]; LeftQ[f, g] = False; 
In[104]:= g[f[x]] 
Out[104]= g[f[x]]

In[105]:= SetCommutingFunctions[f, g]; LeftQ[f, g] = False; 
In[106]:= f[g[x]] 
Out[106]= g[f[x]]

The above examples demonstrate the most commonly used features in NCAlgebra.

Home