Chapter 1
A Short Tutorial on NCAlgebra

NCAlgebra is a Mathematica package which allows one to do noncommutative algebraic computations. We will begin by presenting some calculations done with our package which should give some idea of what may be accomplished with NCAlgebra. We suggest that the reader later do these computations for himself with our package when it has been properly installed since it will provide a tutorial as well as an illustration.

In our package ** denotes noncommutative multiply, 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 constantly uses are built-in. The multiplicative identity is denoted Id in the program. At the present time, Id is set to 1. A element A may have an inverse, which will be denoted by inv[A], of it may have a left or right inverse, denoted inv[A] and invR[A], respectively.

The following examples are independent of each other, however they may be executed in one continuous session. At present, single-letter lower case variables are noncommutative by default and all others are commutative by default.

A Mathematica 3.0 user inside a notebook can use our special Palette by opening the file NCPalette.nb (see Section ??).

1.1 Installing NCAlgebra

1.1.1 Downloading

You can download the lastest version of NCAlgebra from www.math.ucsd.edu/~ncalg.

1.1.2 Unpacking

We provide the files NCAlgebra.zip and a NCAlgebra.tgz, which contain the exact same files in different compact formats. PC and Mac people might prefer to download the NCAlgebra.zip file, while Unix people may like the NCAlgebra.tgz file better. Unpacking any of these files will create a directory ’NC’ which contains all the files necessary to run NCAlgebra.

If you downloaded the NCAlgebra.zip file:

If you downloaded the NCAlgebra.tgz file:

1.1.3 Installing

All that is needed for NCAlgebra to run is that its top directory, the ’NC’ directory, be on Mathematica’s search path. If you are on a unix flavored machine (Solaris, Linux, Mac OSX) then unpacking in your home directory (~) is all you need to do. You may want to try to run NCAlgebra as explained in the next section to see if that works.

If you want to put the files someplace else, all you need to do is to modify Mathematica’s search path. You can do this in one of two ways:

If you are experienced with Mathematica

Or

1.2 Running NCAlgebra

In Mathematica (notebook or text interface), type

<< NC‘

If this fails, your installation has problems (check out previous section). If your installation is succesful you will see a message like:

You are using the version of NCAlgebra which is found in:  
  /your_home_directory/NC.  
You can now use "<< NCAlgebra‘" to load NCAlgebra or "<< NCGB‘" to load NCGB.

Just type

<< NCAlgebra‘

to load NCAlgebra, or

<< NCGB‘

to load NCAlgebra and NCGB. Your screen will be filled with lots of information as NCAlgerba or NCGB loads.

1.3 A Short Tutorial

NCAlgebra is a Mathematica package which allows one to do noncommutative algebraic computations. We will begin by presenting some calculations done with our package which should give some idea of what may be accomplished with NCAlgebra. We suggest that the reader later do these computations for himself with our package when it has been properly installed since it will provide a tutorial as well as an illustration.

To begin start Mathematica and load NCAlgebra.m or NCGB.m as shown in Section 1.2

In[1] << NC‘  
In[2] << NCAlgebra‘

The following examples are independent of each other, however they may be executed in one continuous session. At present, single-letter lower case variables are noncommutative by default and all others are commutative by default. In our package ** denotes noncommutative multiply.

In[3]:= a ** b - b ** a  
Out[3]= a ** b - b ** a  
 
In[4]:= A ** B - B ** A  
Out[4]= 0  
 
In[5]:= A ** b - b ** a  
Out[5]= A b - b ** a  
 
In[6]:= CommuteEverything[a ** b - b ** a]  
Out[6]= 0  
 
In[7]:= SetNonCommutative[A, B]  
Out[7]= {False, False}  
 
In[8]:= A ** B - B ** A  
Out[8]= A ** B - B ** A  
 
In[9]:= SetNonCommutative[A];  
In[10]:= SetCommutative[B];  
In[11]:= A ** B - B ** A  
Out[11]= 0

SNC is an alias for SetNonCommutative. So, SNC can be typed rather than the longer SetNonCommutative.

In[12]:= SNC[A];  
In[13]:= A ** a - a ** A  
Out[13]= -a ** A + A ** a  
 
In[14]:= SetCommutative[v];  
In[15]:= v ** b  
Out[15]= b v

Here is how to use NCAlgebra to manipulate and simplify expressions. 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 constantly uses are built-in.

In[16]:= NCCollect[a ** x + b ** x, x]  
Out[16]= (a + b) ** x  
 
In[17]:= NCExpand[(a + b) ** x]  
Out[17]= a ** x + b ** x  
 
In[18]:= NCCollect[tp[x] ** a ** x + tp[x] ** b ** x + z, {x, tp[x]}]  
Out[18]= z + tp[x] ** (a + b) ** x

You can compute directional derivatives and gradients.

In[19]:= DirectionalD[x ** x, x, h]  
Out[19]= h ** x + x ** h  
 
In[20]:= DirectionalD[tp[x] ** x + tp[x] ** A ** x + m ** x, x, h]  
Out[20]= m ** h + tp[h] ** x + tp[x] ** h + tp[h] ** A ** x + tp[x] ** A ** h  
 
In[21]:= (* In the next line, A is noncommutative and x represents a column vector*)  
In[22]:= Grad[tp[x] ** x + tp[x] ** A ** x + m ** x, x]  
Grad::limited: Grad gives correct answers only for a limited class of functions!  
Out[22]= 2 x + A ** x + tp[A] ** x + tp[m]

WARNING: Grad is trustworthy only on certain quadratics.

Rules can be used to modify expressions:

In[23]:= Substitute[x ** a ** b, a ** b -> c]  
Out[23]= x ** c  
 
In[24]:= Substitute[ tp[b ** a] + b ** a, b ** a -> p]  
Out[24]= p + tp[a] ** tp[b]  
 
In[25]:= SubstituteSymmetric[tp[b] ** tp[a] + w + a ** b, a ** b->c]  
Out[25]= c + w + tp[c]

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

The multiplicative identity is denoted Id in the program. At the present time, Id is set to 1. A element A may have an inverse, which will be denoted by inv[A], of it may have a left or right inverse, denoted inv[A] and invR[A], respectively.

In[26]:= MatMult[{{a, b}, {c, d}}, {{d, 2}, {e, 3}}]  
Out[26]= {{a ** d + b ** e, 2 a + 3 b}, {c ** d + d ** e, 2 c + 3 d}}  
 
In[27]:= tp[a ** b]  
Out[27]= tp[b] ** tp[a]  
 
In[28]:= tp[5]  
Out[28]= 5  
 
In[29]:= tp[2 + 3 I]  
Out[29]= 2 + 3 I  
 
In[30]:= tp[a]  
Out[30]= tp[a]  
 
In[31]:= tp[a + b]  
Out[31]= tp[a] + tp[b]  
 
In[32]:= tp[6 x]  
Out[32]= 6 tp[x]  
 
In[33]:= tp[tp[a]]  
Out[33]= a  
 
In[34]:= aj[5]  
Out[34]= 5  
 
In[35]:= aj[2 + 3 I]  
Out[35]= 2 - 3 I  
 
In[36]:= aj[a]  
Out[36]= aj[a]  
 
In[37]:= aj[a + b]  
Out[37]= aj[a] + aj[b]  
 
In[38]:= aj[6 x]  
Out[38]= 6 aj[x]  
 
In[39]:= aj[aj[a]]  
Out[39]= a  
 
In[40]:= Id  
Out[40]= 1  
 
In[41]:= inv[a ** b]  
Out[41]= inv[b] ** inv[a]  
 
In[42]:= inv[a] ** a  
Out[42]= 1  
 
In[43]:= a ** inv[a]  
Out[43]= 1  
 
In[44]:= a ** b ** inv[b]  
Out[44]= a  
 
In[45]:= invL[a] ** a  
Out[45]= 1  
 
In[46]:= a ** invR[a]  
Out[46]= 1  
 
In[47]:= a ** invL[a]  
Out[47]= a ** invL[a]  
 
In[48]:= invR[a] ** a  
Out[48]= invR[a] ** a

More extensive simplification can be obtained with NCSimplifyRational:

In[49]:= 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[50]:= NCSimplifyRational[f1]  
Out[50]= 1  
 
In[51]:= f2 = inv[1 + 2 a] ** a;  
In[52]:= NCSimplifyRational[f2]  
         1   inv[1 + 2 a]  
Out[52]= - - ------------  
         2        2

NCSR is the alias for NCSimplifyRational.

In[53]:= f3 = a ** inv[1 - a];  
In[54]:= NCSR[f3]  
Out[54]= -1 + inv[1 - a]  
 
In[55]:= f4 = inv[1 - b ** a] ** inv[a];  
In[56]:= NCSR[f4]  
Out[56]= inv[a] + b ** inv[1 - a ** b]

There is also a very limited NCSolve. Please consider using NCGB for serious equation solving.

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

Note: NCSolve applies to some linear equations in only one unknown.

1.4 Where to Find More Examples

At this point looking at demos is very helpful. We recommend working thru the NCAlgebra demos which accompany this document. Some of them are pdf files and can be read (and can be found in the directory NC/DOCUMENTATION).

All demos can be found in the NC/DEMOS directory. The NCAlgebra website, http://math.ucsd.edu/~ncalg also contains some demos. As of August 2009, the following is a subset of the demos which are available:

DemoBRL.nb        DemoGBM.nb*       DmGBG1.nb         NCPalette.nb  
DemoGB1.nb        DemoSimplify.nb   DmGBG2.nb         PaletteSource.nb  
SingPert.nb

1.5 Pretty Output

Beautifying NCAlgebra

WARNING: The command SetOutput is now deprecated. Please use NCSetOutput instead.

In[104]:= NCSetOutput[ All -> True ];  
In[105]:= inv[ tp[k] ]  
             T -1  
Out[105]= (k)  
 
In[106]:= NCSetOutput[ All -> True ];  
In[107]:= rt[x - inv[y + aj[z]]] + tp[x]  
            T              * -1 1/2  
Out[107]=  x  + (x - (y + z )  )  
 
In[108]:= NCSetOutput[ All -> True, inv -> False ];  
In[109]:= inv[1 + tp[1-x]]  
 
                   T  
Out[109]= inv[2 - x ]

TEXOutput

WARNING: The TEX commands in this version of NCAlgebra have been updated to use the new package NCTeX. Please see Section ?? for more details.

 
In[110]:= mat = {{a + tp[b],aj[c]},{inv[d],e}}  
Out[110]= {{a + tp[b], aj[c]}, {inv[d], e}}  
 
In[111]:= NCTeX[mat]

The above command takes the Mathematica matrix mat, converts it to LATEX, outputs the string and surrounding LATEX to a file, LATEXs the file and displays the LATEXed pdf output to the screen. If you are in a notebook environment, the resulting pdf file is imported back to the notebook. Refer to Section ?? for more details. If you are in a text environment then it opens a pdf viewer with the following formula in its display.

(           )
  a + bT  c*
   d-1    e

The command

In[113]:= NCTeX[Sum[a[i],{i,1,50}], ImportPDF -> False, DisplayPDF -> True];

generates a window which contains the following formula in its display.

a(1)+a(2)+a(3)+a(4)+a(5)+a(6)+a(7)+a(8)+a(9)+a(10)+a(11)+a(12)+a(13)+a(14)+

a(15)+ a(16) + a(17)+ a(18) + a(19)+ a(20) + a(21)+ a(22) + a(23)+ a(24) + a(25)+ a(26)+

a(27)+ a(28) + a(29)+ a(30) + a(31)+ a(32) + a(33)+ a(34) + a(35)+ a(36) + a(37)+ a(38)+
a(39)+  a(40)+ a(41) + a(42)+  a(43)+ a(44) + a(45)+  a(46)+ a(47) + a(48)+  a(49)+ a(50)

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