Procedures for sample worksheet IV 



This worksheet contains programs for worksheet IV. Most of these procedures are the same or are similar to those found in the previous worksheets.
There are a few major differences. The first is that the valid color vectors are know calculated with a c program that has been dynamically linked to Maple.
 

This will speed up the process significantly. The second difference is that procedures are included that will calculate invariants in a systematic way. Procedures will automatically generate file names and save all data for the case that  the user is calculating. This worksheet includes procedures for the cases presented in the three previous worksheets.
The procedures included in this worksheet are:

validColorVectors:=define_external(
                     'validcolorvectorsint',
                     'quandle'::ARRAY(datatype=integer[2]),
                     'quandlesize'::integer[4],
                     'knot'::ARRAY(datatype=integer[2]),
                     'braidindex'::integer[4],
                     'nopsknot'::integer[4],
                     'validCvecs'::ARRAY(datatype=integer[2]),
                     RETURN::integer[4],
                     LIB="ValCol8_1_05.so"):
 

cvrtarray:=proc(brind,nopknt,L,numVC);
Invar2_3UntwistedDLL:=proc(Quandle,p,Knot);
CalcUntwistinvars:=proc(filePATH,p ,qord,qnum,numberofknots,{cpath:=false},{solpath=false});
fpQuan:=proc(tfile,Quandle,qsize);
Invar2UntwistedDLL:=proc(Quandle,p,Knot);
Calc2Untwistinvars:=proc(filePATH,p,qord,qnum,numberofknots,{cpath=false},{solpath:=false});
 

Invar3UntwistedDLL:=proc(Quandle,p,Knot); 

Calc3Untwistinvars:=proc(filePATH,p,qord,qnum,numberofknots,{cpath=false},{solpath:=false});
Invar2_3MochizukiDLL:=proc(Xpolym,Apolym,p,m1,m2,a3,n1,b2,Knot);
CalcMochinvars:=proc(filePATH,p ,polym,m1,m2,a3,n,b,numberofknots,{cpath:=false},{solpath:=false});
Invar2MochizukiDLL:=proc(Xpolym,Apolym,p,n1,b2,Knot);
 

Calc2Mochinvars:=proc(filePATH,p ,polym,n,b,numberofknots,{cpath:=false},{solpath:=false}); 

Invar3MochizukiDLL:=proc(Xpolym,Apolym,p,m1,m2,a3,Knot); 

Calc3Mochinvars:=proc(filePATH,p ,polym,m1,m2,a3,numberofknots,{cpath:=false},{solpath:=false});
ismult:=proc(charstar);
CalcDihinvars:=proc(filePATH,p,numberofKnots,{cpath:=false},{solpath:=false});
co2TwistedSol:=proc(Quandle,polym,p);
Invar2TwistedDLL(Quandle,knot,polym,p);
Calc2twistinvars(filePATH,p,polym,qord,qnum,numberofknots,{cpath:=false},{solpath:=false});
tinverse(polym,p);

quandlesize:=proc(Quandle);
makeinv:=proc(Quandle);
co2Solution:=proc(Quandle,m::posint);
mirrorKnot:=proc(L);
barKnot:=proc(L);
connSumKnots:=proc(Knots_list);
co3Solution:=proc(Quandle,m::posint);
Mochizuki3coc:=proc(Xpolym,Apolym,p,m1,m2,a3);
cocycle3check:=proc(cocy,Xpolym,Apolym,p);
Xi:=proc(n);
Mochizuki2coc:=proc(Xpolym,Apolym,p,m1,a2);
cocycle2check:=proc(cocy,Xpolym,Apolym,p);
MochizukiDihedral3coc:=proc(p);

 

Last updated 8/22/05 

 

This procedure is perhaps the most powerful of the new procedures. A c program libcolor8_1_05.c was created and compiled as a shared object file (or a dynamic link library) in Linux. This program will generate all possible initial color vectors and then color a given braid. Only the valid color vectors are saved. These color vectors are then stored in an array validCvecs that is passed to the c program from this Maple procedure. The parameters used in the define_external ar enow explained. The fist element ''validcolorvectorsint' is the name of the function that was used in the c program. 'quandle' is the Cayley table for the quandle that is used. Arrays must be modified slightly before passing them to the c program. Assume you have a quandle, Quandle:=Q3 := array(0 .. 2, 0 .. 2,[(2, 1)=0,(0, 0)=0,(2, 2)=2,(0, 1)=2,(0, 2)=1,(1, 0)=2,(1, 1)=1,(1, 2)=0,(2, 0)=1]); stored as in the previous worksheets. Now the quandle should be modified to QuandleC by the following statement, QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order): This will change the datatype to a 2 byte integer and store it in C_order. This will allow the c program to use it. All arrays passed to this function must be modified in this way. The second term 'quandlesize' is an integer representing the order of the quandle. 'knot' is an array that is the braid word for the knot. It must be modified as the quandle array was before passing it. Next the braid index and the number of crossings, 'braidindex' and 'nopsknot' respectively, are integers. Finally, an empty array validCvecs' is created and passed to the function. This is really just a pointer that will be used to store that valid color vectors. This array can be initialized by the followingstatement, VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
This array is declared with a bound to it. Statically declaring the array makes things easier, but may create problems under special cases. For example, it requires the braid index * nops(Knot)+1 many cells of the array to store the valid color vectors for one valid coloring of the braid. So if the # valid colorings is greater than 10000000/(braidindex*nops(Knot)+1) then a segmentation fault will be created with the c program and then passed to the Maple program. There are some possible modification that can be made without rewriting the c program to dynamically declare memory. One such solution would be to allocate more menory for the validCvecs array. The above example alloted 10000000 cells at 2 bytes each. This requires 20 MB of space. So if you computer has enough memory you could simply declare a larger array. There are other solutions to this problem. If this turn out to be a frequently encountered problem, we will rework this. I have ideas already, but I feel this is a good alpha version. The function will return an integer representing the number of valid colorings for the braid. This is a 4 byte integer and should not exceed 2^31 -1. The shared object file "ValCol8_1_05.so" should be stored in the same directory as the worksheet calling it to avoid altering the PATH given to the LIB statement below.
 

> restart;
 

> validColorVectors:=define_external(
                     'validcolorvectorsint',
                     'quandle'::ARRAY(datatype=integer[2]),
                     'quandlesize'::integer[4],
                     'knot'::ARRAY(datatype=integer[2]),
                     'braidindex'::integer[4],
                     'nopsknot'::integer[4],
                     'validCvecs'::ARRAY(datatype=integer[2]),
                     RETURN::integer[4],
                     LIB="/media/sda1/WorksheetIV/ValCol8_1_05.so"):
 
 

This next procedure is used to change the one dimensional array containing the valid color vectors that was created with the Maple procedure validColorVectors() to a three dimensional array. The first index will range from 1 to the number of valid coloring. The second and third indices are the crossing and strand, respectively. There may be an automatic conversion (dimension) for this, but it was faster and safer for me to create a procedure for it. The first and second parameters are the braid index and the number of crossings for the braid. The third parameter, L, is the name of the array that the valid color vectors were stored in from validColorVectors() procedure. The final parameter, numVC, is the value returned by the above procedure. It represents the number of valid colorings of the braid.   

> cvrtarray:=proc(brind,nopknt,L,numVC)
local i,j,k,tempClr,counttmp;
tempClr[0]:=numVC;
for i from 1 to numVC do
  for j from 1 to nopknt+1 do
    tempClr[i][j]:=array(1..brind);
od:od:

#tempClr:=array(0..numVC,1..nopknt+1,1..brind);
#counttmp:=brind*(nopknt+1)+2;
counttmp:=1;
for i from  1 to numVC do
 for j from 1 to nopknt+1 do
    for k from 1 to brind do
      tempClr[i][j][k]:=L[counttmp];
      counttmp:=counttmp+1;
    od:
  od:
od:
eval(tempClr):
end:

 

This procedure is similar to those discussed in the worksheet "cocysample.mws" The "untwisted case." This procedure will take a quandle, a prime modulus, and a knot in braid form. The quandle is stored as it was in "cocysample.mws" (ie. A two dimensional zero indexed array). This program will evaluate the 2-cocycle and 3-cocycle values for the untwisted case by solving an overdetermined system of equations generated from the cocycle conditions. It will use the c program to generate all valid colorings of the braid and then will calculate the colorings of the regions while evaluating the state sum for the two and three cocycle cases.  This procedure will return in the following order:
1) the value of the untwisted 2-cocycle invariant,
2) the value of the untwisted 3-cocycle invariant,
 

3) the valid coloring of the braid,
4) the solutions to the 2-cocycle condition,
5) the solutions to the 3-cocycle condition, and
6) the number of valid coloring of the braid.
 

> Invar2_3UntwistedDLL:=proc(Quandle,p,Knot)
local SST2coc,SST3coc,SST2contri,SST3contri,jj3,jj5,jj6,jj8,s,num,Color,brind,
     indx,ColDiffMatch0,ColorDiff0,Ginv,quandleorder,        
     co2Solutions,co3Solutions,Facecolors,facecolors,
     precolorface,nowcolor,colcoloring,VALIDCOLORS,
     QuandleC,KnotC,x,y,i,valid2coc,valid3coc,numVcolors;
SST2coc:=0;
SST3coc:=0;
VALIDCOLORS:=[];
#valid2coc:=false;
#valid3coc:=false;

#print("Program start");

co3Solutions:=[];
co2Solutions:=[];

quandleorder:=quandlesize(Quandle);



co3Solutions:=co3Solution(Quandle,p);
co2Solutions:=co2Solution(Quandle,p);

brind:=max(op(map(x->abs(x),Knot)))+1;


#################
numVcolors:=0;

##################

#print("brind is",brind);
QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order):
#print("finish QuandleC");
KnotC:=Array(0..(nops(Knot)-1),Knot,datatype=integer[2],order=C_order):
#print("finish Knotc");
VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
#print("finish VALIDCOLORS");
numVcolors:=validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

#print("numVcolors is ",numVcolors);
#validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

Color[0]:=numVcolors;
#Color[0]:=VALIDCOLORS[0];
#print("finish colors"):
#for x from 1 to VALIDCOLORS[0] do
for x from 1 to numVcolors do
 for y from 1 to nops(Knot)+1 do
   Color[x][y]:=array(1..brind,[]):
 od:
od:


for jj3 from 1 to (nops(Knot)+1) do                # Color vectors.
    
    Facecolors[jj3]:=array(0..brind-1):
od;

Color:=cvrtarray(brind,nops(Knot),VALIDCOLORS,numVcolors);
#Color[0]:=VALIDCOLORS[0];

#print("The number of valid colorings ",Color[0]);
#print("about to enter sst loop");
#  for i from 1 to VALIDCOLORS[0] do

for i from 1 to numVcolors do     
for facecolors from 0 to  (quandleorder-1) do
       SST2contri:=0;                                # State-sum contributions.
       SST3contri:=0;     
        for precolorface from 1 to (nops(Knot)+1) do  
        
           Facecolors[precolorface][0]:=facecolors:

       od;
       for nowcolor from 1 to nops(Knot) do
      
           for colcoloring from 0 to (abs(Knot[nowcolor])-1) do  
               Facecolors[nowcolor][colcoloring+1]:=Quandle[Facecolors[nowcolor][colcoloring],
                                                    Color[i][nowcolor][colcoloring+1]]:
     
           od:

       od:
       for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST3contri:= SST3contri + co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s][abs(Knot[s])], Color[i][s][abs(Knot[s])+1] ] :

           else
               SST3contri:=SST3contri -co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s+1][abs(Knot[s])], Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:                          # Closing the state-sum term, for s.
                                   
    SST3coc:=SST3coc + u^(map(z->z mod p,SST3contri));
    od:     
                          #closes facecolors  

    for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST2contri:= SST2contri + co2Solutions[Color[i][s][abs(Knot[s])], Color[i][s][abs(Knot[s])+1] ] :

           else
               SST2contri:=SST2contri -co2Solutions[Color[i][s+1][abs(Knot[s])],Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:
    SST2coc:=SST2coc + u^(map(z->z mod p,SST2contri));                                              
od:                                     # Closing indx loop (one color here at a time, for indx).
return(SST2coc,SST3coc,Color,co2Solutions,co3Solutions,numVcolors);
end:
 

The procedure CalcUntwistinvars() will run the procedure, Invar2_3UntwistedDLL:=proc(Quandle,p,Knot), over the 2977 knots stored in the file knotsLivingston.txt. It will automatically generate filenames and write the data to the appropriate file. All of the values that the 2-cocycle and 3-cocycle invariants take are written to the files,  Z_puntwistedQqord_qnum_2cocinv.inv or Z_puntwistedQqord_qnum_3cocinv.inv. For example, 

the values for the untwisted 2 cocycle invariants with coefficient group Z_3 and colored with the quandle Q6_25 would be stored in the file Z_3untwistedQ6_25_2cocinv.inv. This file is saved in the directory specified by the string filePATH that is specified by the user. The solutions to the cocycle conditions for a quandle Qqord_qnum over Z_p are stored in the file cociSolnsZ_puntwistedQqord_qnum where i=2 or 3 representing 2-cocycle or 3-cocycle. The valid colorings of a given braid with knot number Kx_y with the quandle Qqord_qnum are stored in the file, ColorsQqord_qnumKx_y.clr.  numberofknots is how far through the table table you wish to calculate. For example, numberofknots=83 will calculate through 9 crossings. 

> CalcUntwistinvars:=proc(filePATH,p ,qord,qnum,numberofknots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpfilename2,tmpfilename3,tmpf1,tmpf2,tmpf3,INVARS,
     Quandle,quandleorder,tmpfilename4,tmpfilename5,tmpf4,tmpf5,brind,
     tmpColorstr,x,y,z,tmpco2str,tmpco3str,bstrand,crossvec,colnum,JJ,writesolpath,cpath,solpath;


  cpath:=args[6];
  solpath:=args[7];

Quandle:=cat(Q,qord,_,qnum);
quandleorder:=quandlesize(Quandle);
 HH:=ssystem(date):HH[2];

tmpfilename1:=cat(filePATH,"Z_",p,"untwistedQ",qord,"_",qnum,"_2cocinv.inv");
tmpfilename2:=cat(filePATH,"Z_",p,"untwistedQ",qord,"_",qnum,"_3cocinv.inv");

#if cpath<>false then
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);
#fi;
if solpath<> false then
tmpfilename4:=cat(solpath,"coc2SolnsZ_",p,"untwistedQ",qord,"_",qnum,".sol");
tmpfilename5:=cat(solpath,"coc3SolnsZ_",p,"untwistedQ",qord,"_",qnum,".sol");
tmpf4:=fopen(tmpfilename4,WRITE);
tmpf5:=fopen(tmpfilename5,WRITE);
printf("%s\n",tmpfilename4);
printf("%s\n",tmpfilename5);
fprintf(tmpf4,"#Untwisted Quandle 2-cocycle solutions for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);
fprintf(tmpf5,"#Untwisted Quandle 3-cocyclesolutions for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);
 fprintf(tmpf4,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fprintf(tmpf5,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fpQuan(tmpf4,Quandle,quandleorder);
fpQuan(tmpf5,Quandle,quandleorder);

fprintf(tmpf4,"#Generated %s\n",HH[2]);
fprintf(tmpf5,"#Generated %s\n",HH[2]);
writesolpath:=true;
fi;



tmpf1:=fopen(tmpfilename1,WRITE);
tmpf2:=fopen(tmpfilename2,WRITE);
# tmpf3:=fopen(tmpfilename3,WRITE);

printf("%s\n",tmpfilename1);
printf("%s\n",tmpfilename2);
#printf("%s\n",tmpfilename3);



fprintf(tmpf1,"#Untwisted Quandle 2-cocycle invariants for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);
fprintf(tmpf2,"#Untwisted Quandle 3-cocycle invariants for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);

fprintf(tmpf1,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fprintf(tmpf2,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fpQuan(tmpf1,Quandle,quandleorder);
fpQuan(tmpf2,Quandle,quandleorder);

# fprintf(tmpf3,"The valid color vectors for the braids colored with the quandle Q%d_%d\n\n",qord,qnum);
#fprintf(tmpf3,"The cayley table for the quandle Q%d_%d\n",qord,qnum);
#fpQuan(tmpf3,Quandle,quandleorder);






fprintf(tmpf1,"#Generated %s\n",HH[2]);
fprintf(tmpf2,"#Generated %s\n",HH[2]);
#fprintf(tmpf3,"#Generated %s\n",HH[2]);


for i from 0 to numberofknots do
#print("Before loop");

JJ:=ssystem(date):


INVARS:=Invar2_3UntwistedDLL(Quandle,p,Knot[i,2]):
fprintf(tmpf1,"%s\t%s\t \n%s\n\n",convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[1],string));
fprintf(tmpf2,"%s\t%s\t \n%s\n\n",convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[2],string));

if cpath<> false then

tmpfilename3:=cat(cpath,"ColorsQ",qord,"_",qnum);
tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");
tmpf3:=fopen(tmpfilename3,WRITE);
#printf("%s\n",tmpfilename3);

fprintf(tmpf3,"#The valid color vectors for the braids colored with the quandle Q%d_%d \n#for the knot %s with braid %s\n\n",qord,qnum,convert(Knot[i,1],string),convert(Knot[i,2],string));
fprintf(tmpf3,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fpQuan(tmpf3,Quandle,quandleorder);
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
tmpColorstr:=cat(Col,convert(Knot[i,1],string),_,Q,qord,_,qnum);
fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVARS[6]);
brind:=max(op(map(x->abs(x),Knot[i,2])))+1;
for colnum from 1 to INVARS[6] do
  for crossvec from 1 to nops(Knot[i,2])+1 do
    for bstrand from 1 to brind do
      fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVARS[3][colnum][crossvec][bstrand]);
od:od:od:
JJ:=ssystem(date):
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
 fprintf(tmpf3,"\n\n\n");
fclose(tmpf3);
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);
fi;

if writesolpath<>false then
tmpco2str:=cat(co2SolUntwist,Q,qord,_,qnum,Z_,p);
tmpco3str:=cat(co3SolUntwist,Q,qord,_,qnum,Z_,p);

for x from 0 to quandleorder-1 do
   for y from 0 to quandleorder-1 do
     for z from 0 to quandleorder-1 do
        fprintf(tmpf5,"%s[%d,%d,%d]:=%s;\n",tmpco3str,x,y,z,convert(INVARS[5][x,y,z],string));
     od;
   fprintf(tmpf4,"%s[%d,%d]:=%s;\n",tmpco2str,x,y,convert(INVARS[4][x,y],string));
od:od:
fprintf(tmpf4,"\n\n\n");
fprintf(tmpf5,"\n\n\n");

fclose(tmpf4);
fclose(tmpf5);
writesolpath:=false;

fi;


od:
print("finished all knots");



HH:=ssystem(date):HH[2];
fprintf(tmpf1,"#Generated %s\n",HH[2]);
fprintf(tmpf2,"#Generated %s\n",HH[2]);

fclose(tmpf1);
fclose(tmpf2);
# fclose(tmpf3);


end:
 

The procedure fpQuan() is used in the  procedure, CalcUntwistinvars(),  to print the quandle to the file. tfile is the name of the file. Quandle is the quandle, and qsize is the order of the quandle. 

> fpQuan:=proc(tfile,Quandle,qsize)
local i,j;
fprintf(tfile,"\n#  ");
for i from 0 to qsize-1 do
  for j from 0 to qsize-1 do
    fprintf(tfile,"%5d  ",Quandle[i,j]);
  od:
  fprintf(tfile,"\n#  ");
od:
fprintf(tfile,"\n\n");
end:
 

This procedure is similar to Invar2_3UntwistedDLL(), but it just does the 2-cocycle case. The valid color vectors of the braid are calculated with the c program.
The parameters input are the same.
The output is ordered as follows:
1) the value of the untwisted 2-cocycle invariant,
2) the valid coloring of the braid,
3) the solutions to the 2-cocycle condition, and
4) the number of valid coloring of the braid.
 

> Invar2UntwistedDLL:=proc(Quandle,p,Knot)
local SST2coc,SST2contri,jj3,jj5,jj6,jj8,s,num,Color,brind,
     indx,ColDiffMatch0,ColorDiff0,Ginv,quandleorder,        
     co2Solutions,VALIDCOLORS,
     QuandleC,KnotC,x,y,i,valid2coc,numVcolors;
SST2coc:=0;
VALIDCOLORS:=[];


#print("Program start");


co2Solutions:=[];
quandleorder:=quandlesize(Quandle);


if nargs<4 then
 co2Solutions:=co2Solution(Quandle,p);
else
 co2Solutions:=args[4];
fi;




brind:=max(op(map(x->abs(x),Knot)))+1;


#################
numVcolors:=0;

##################

#print("brind is",brind);
QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order):
#print("finish QuandleC");
KnotC:=Array(0..(nops(Knot)-1),Knot,datatype=integer[2],order=C_order):
#print("finish Knotc");
VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
#print("finish VALIDCOLORS");
numVcolors:=validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

#print("numVcolors is ",numVcolors);
#validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

Color[0]:=numVcolors;
#Color[0]:=VALIDCOLORS[0];
#print("finish colors"):
#for x from 1 to VALIDCOLORS[0] do
for x from 1 to numVcolors do
 for y from 1 to nops(Knot)+1 do
   Color[x][y]:=array(1..brind,[]):
 od:
od:



Color:=cvrtarray(brind,nops(Knot),VALIDCOLORS,numVcolors);
#Color[0]:=VALIDCOLORS[0];

#print("The number of valid colorings ",Color[0]);
#print("about to enter sst loop");
#  for i from 1 to VALIDCOLORS[0] do

for i from 1 to numVcolors do      
       SST2contri:=0;                                # State-sum contributions.
           
    for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST2contri:= SST2contri + co2Solutions[Color[i][s][abs(Knot[s])], Color[i][s][abs(Knot[s])+1] ] :

           else
               SST2contri:=SST2contri -co2Solutions[Color[i][s+1][abs(Knot[s])],Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:
    SST2coc:=SST2coc + u^(map(z->z mod p,SST2contri));                                              
od:                                     # Closing indx loop (one color here at a time, for indx).
return(SST2coc,Color,co2Solutions,numVcolors);
end:
 

> Calc2Untwistinvars:=proc(filePATH,p ,qord,qnum,numberofknots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpfilename2,tmpfilename3,tmpf1,tmpf2,tmpf3,INVARS,
     Quandle,quandleorder,tmpfilename4,tmpfilename5,tmpf4,tmpf5,brind,
     tmpColorstr,x,y,z,tmpco2str,tmpco3str,bstrand,crossvec,colnum,JJ,writesolpath,cpath,solpath;


 cpath:=args[6];
 solpath:=args[7];


Quandle:=cat(Q,qord,_,qnum);
quandleorder:=quandlesize(Quandle);
 HH:=ssystem(date):HH[2];

tmpfilename1:=cat(filePATH,"Z_",p,"untwistedQ",qord,"_",qnum,"_2cocinv.inv");


#if cpath<>false then
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);
#fi;
if solpath<> false then
tmpfilename4:=cat(solpath,"coc2SolnsZ_",p,"untwistedQ",qord,"_",qnum,".sol");

tmpf4:=fopen(tmpfilename4,WRITE);

printf("%s\n",tmpfilename4);

fprintf(tmpf4,"#Untwisted Quandle 2-cocycle solutions for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);

 fprintf(tmpf4,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);

fpQuan(tmpf4,Quandle,quandleorder);


fprintf(tmpf4,"#Generated %s\n",HH[2]);

writesolpath:=true;
fi;



tmpf1:=fopen(tmpfilename1,WRITE);

# tmpf3:=fopen(tmpfilename3,WRITE);

printf("%s\n",tmpfilename1);

#printf("%s\n",tmpfilename3);



fprintf(tmpf1,"#Untwisted Quandle 2-cocycle invariants for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);

fprintf(tmpf1,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);

fpQuan(tmpf1,Quandle,quandleorder);


# fprintf(tmpf3,"The valid color vectors for the braids colored with the quandle Q%d_%d\n\n",qord,qnum);
#fprintf(tmpf3,"The cayley table for the quandle Q%d_%d\n",qord,qnum);
#fpQuan(tmpf3,Quandle,quandleorder);






fprintf(tmpf1,"#Generated %s\n",HH[2]);

#fprintf(tmpf3,"#Generated %s\n",HH[2]);


for i from 0 to numberofknots do

JJ:=ssystem(date):


INVARS:=Invar2UntwistedDLL(Quandle,p,Knot[i,2]):
fprintf(tmpf1,"%s\t%s\t \n%s\n\n",convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[1],string));

if cpath<> false then
tmpfilename3:=cat(cpath,"ColorsQ",qord,"_",qnum);
tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");

tmpf3:=fopen(tmpfilename3,WRITE);
#printf("%s\n",tmpfilename3);

fprintf(tmpf3,"#The valid color vectors for the braids colored with the quandle Q%d_%d \n#for the knot %s with braid %s\n\n",qord,qnum,convert(Knot[i,1],string),convert(Knot[i,2],string));
fprintf(tmpf3,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fpQuan(tmpf3,Quandle,quandleorder);
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
tmpColorstr:=cat(Col,convert(Knot[i,1],string),_,Q,qord,_,qnum);
fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVARS[4]);
brind:=max(op(map(x->abs(x),Knot[i,2])))+1;
for colnum from 1 to INVARS[4] do
  for crossvec from 1 to nops(Knot[i,2])+1 do
    for bstrand from 1 to brind do
      fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVARS[2][colnum][crossvec][bstrand]);
od:od:od:
JJ:=ssystem(date):
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
 fprintf(tmpf3,"\n\n\n");
fclose(tmpf3);
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);
fi;

if writesolpath<>false then
tmpco2str:=cat(co2SolUntwist,Q,qord,_,qnum,Z_,p);

for x from 0 to quandleorder-1 do
   for y from 0 to quandleorder-1 do
       fprintf(tmpf4,"%s[%d,%d]:=%s;\n",tmpco2str,x,y,convert(INVARS[3][x,y],string));
od:od:
fprintf(tmpf4,"\n\n\n");


fclose(tmpf4);

writesolpath:=false;

fi;


od:
print("finished all knots");



HH:=ssystem(date):HH[2];
fprintf(tmpf1,"#Generated %s\n",HH[2]);

fclose(tmpf1);

# fclose(tmpf3);


end:
 

This procedure is similar to Invar2_3UntwistedDLL(), but it just does the 3-cocycle case. The valid color vectors are calculated with the c program.
The parameters input are the same.
The output is ordered as follows:
1) the value of the untwisted 3-cocycle invariant,
2) the valid coloring of the braid (excluding the regions),
3) the solutions to the 3-cocycle condition, and
4) the number of valid coloring of the braid (excluding regions).
 

> Invar3UntwistedDLL:=proc(Quandle,p,Knot)
local SST3coc,SST3contri,jj3,jj5,jj6,jj8,s,num,Color,brind,
     indx,ColDiffMatch0,ColorDiff0,Ginv,quandleorder,        
     co3Solutions,Facecolors,facecolors,
     precolorface,nowcolor,colcoloring,VALIDCOLORS,
     QuandleC,KnotC,x,y,i,valid2coc,valid3coc,numVcolors;
SST3coc:=0;
VALIDCOLORS:=[];
#valid2coc:=false;
#valid3coc:=false;

#print("Program start");



co3Solutions:=[];
quandleorder:=quandlesize(Quandle);


if nargs<4 then
 co3Solutions:=co3Solution(Quandle,p);
else
 co3Solutions:=args[4];
fi;



brind:=max(op(map(x->abs(x),Knot)))+1;


#################
numVcolors:=0;

##################

#print("brind is",brind);
QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order):
#print("finish QuandleC");
KnotC:=Array(0..(nops(Knot)-1),Knot,datatype=integer[2],order=C_order):
#print("finish Knotc");
VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
#print("finish VALIDCOLORS");
numVcolors:=validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

#print("numVcolors is ",numVcolors);
#validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

Color[0]:=numVcolors;
#Color[0]:=VALIDCOLORS[0];
#print("finish colors"):
#for x from 1 to VALIDCOLORS[0] do
for x from 1 to numVcolors do
 for y from 1 to nops(Knot)+1 do
   Color[x][y]:=array(1..brind,[]):
 od:
od:


for jj3 from 1 to (nops(Knot)+1) do                # Color vectors.
    
    Facecolors[jj3]:=array(0..brind-1):
od;

Color:=cvrtarray(brind,nops(Knot),VALIDCOLORS,numVcolors);
#Color[0]:=VALIDCOLORS[0];

#print("The number of valid colorings ",Color[0]);
#print("about to enter sst loop");
#  for i from 1 to VALIDCOLORS[0] do

for i from 1 to numVcolors do    
 for facecolors from 0 to  (quandleorder-1) do
                                       # State-sum contributions.
       SST3contri:=0;     
        for precolorface from 1 to (nops(Knot)+1) do  
        
           Facecolors[precolorface][0]:=facecolors:

       od;
       for nowcolor from 1 to nops(Knot) do
      
           for colcoloring from 0 to (abs(Knot[nowcolor])-1) do  
               Facecolors[nowcolor][colcoloring+1]:=Quandle[Facecolors[nowcolor][colcoloring],
                                                    Color[i][nowcolor][colcoloring+1]]:
     
           od:

       od:
       for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST3contri:= SST3contri + co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s][abs(Knot[s])], Color[i][s][abs(Knot[s])+1] ] :

           else
               SST3contri:=SST3contri -co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s+1][abs(Knot[s])], Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:                          # Closing the state-sum term, for s.
                                   
    SST3coc:=SST3coc + u^(map(z->z mod p,SST3contri));
    od:     
                          #closes facecolors  

                                                 
od:                                     # Closing indx loop (one color here at a time, for indx).
return(SST3coc,Color,co3Solutions,numVcolors);
end:
 

> Calc3Untwistinvars:=proc(filePATH,p ,qord,qnum,numberofknots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpfilename2,tmpfilename3,tmpf1,tmpf2,tmpf3,INVARS,
     Quandle,quandleorder,tmpfilename4,tmpfilename5,tmpf4,tmpf5,brind,
     tmpColorstr,x,y,z,tmpco2str,tmpco3str,bstrand,crossvec,colnum,JJ,writesolpath,cpath,solpath;


  cpath:=args[6];
  solpath:=args[7];


Quandle:=cat(Q,qord,_,qnum);
quandleorder:=quandlesize(Quandle);
 HH:=ssystem(date):HH[2];


tmpfilename2:=cat(filePATH,"Z_",p,"untwistedQ",qord,"_",qnum,"_3cocinv.inv");

#if cpath<>false then
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);
#fi;
if solpath<> false then

tmpfilename5:=cat(solpath,"coc3SolnsZ_",p,"untwistedQ",qord,"_",qnum,".sol");

tmpf5:=fopen(tmpfilename5,WRITE);

printf("%s\n",tmpfilename5);

fprintf(tmpf5,"#Untwisted Quandle 3-cocyclesolutions for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);

fprintf(tmpf5,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);

fpQuan(tmpf5,Quandle,quandleorder);


fprintf(tmpf5,"#Generated %s\n",HH[2]);
writesolpath:=true;
fi;




tmpf2:=fopen(tmpfilename2,WRITE);
# tmpf3:=fopen(tmpfilename3,WRITE);


printf("%s\n",tmpfilename2);
#printf("%s\n",tmpfilename3);




fprintf(tmpf2,"#Untwisted Quandle 3-cocycle invariants for the Quandle Q%d_%d and \n#coefficient group Z_%d\n\n",qord,qnum,p);


fprintf(tmpf2,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);

fpQuan(tmpf2,Quandle,quandleorder);

# fprintf(tmpf3,"The valid color vectors for the braids colored with the quandle Q%d_%d\n\n",qord,qnum);
#fprintf(tmpf3,"The cayley table for the quandle Q%d_%d\n",qord,qnum);
#fpQuan(tmpf3,Quandle,quandleorder);







fprintf(tmpf2,"#Generated %s\n",HH[2]);
#fprintf(tmpf3,"#Generated %s\n",HH[2]);


for i from 0 to numberofknots do
#print("Before loop");

JJ:=ssystem(date):


INVARS:=Invar3UntwistedDLL(Quandle,p,Knot[i,2]):

fprintf(tmpf2,"%s\t%s\t \n%s\n\n",convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[1],string));

if cpath<> false then
tmpfilename3:=cat(cpath,"ColorsQ",qord,"_",qnum);
tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");

tmpf3:=fopen(tmpfilename3,WRITE);
#printf("%s\n",tmpfilename3);

fprintf(tmpf3,"#The valid color vectors for the braids colored with the quandle Q%d_%d \n#for the knot %s with braid %s\n\n",qord,qnum,convert(Knot[i,1],string),convert(Knot[i,2],string));
fprintf(tmpf3,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fpQuan(tmpf3,Quandle,quandleorder);
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
tmpColorstr:=cat(Col,convert(Knot[i,1],string),_,Q,qord,_,qnum);
fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVARS[4]);
brind:=max(op(map(x->abs(x),Knot[i,2])))+1;
for colnum from 1 to INVARS[4] do
  for crossvec from 1 to nops(Knot[i,2])+1 do
    for bstrand from 1 to brind do
      fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVARS[2][colnum][crossvec][bstrand]);
od:od:od:
JJ:=ssystem(date):
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
 fprintf(tmpf3,"\n\n\n");
fclose(tmpf3);
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);
fi;

if writesolpath<>false then

tmpco3str:=cat(co3SolUntwist,Q,qord,_,qnum,Z_,p);

for x from 0 to quandleorder-1 do
   for y from 0 to quandleorder-1 do
     for z from 0 to quandleorder-1 do
        fprintf(tmpf5,"%s[%d,%d,%d]:=%s;\n",tmpco3str,x,y,z,convert(INVARS[3][x,y,z],string));
     od;
   
od:od:

fprintf(tmpf5,"\n\n\n");


fclose(tmpf5);
writesolpath:=false;

fi;


od:
print("finished all knots");



HH:=ssystem(date):HH[2];

fprintf(tmpf2,"#Generated %s\n",HH[2]);


fclose(tmpf2);
# fclose(tmpf3);


end:
 

This procedure is similar to the one discussed in the worksheet "cocysampleIII.mws," the "Mochizuki Polynomial Cases." This procedure will take two polynomials, in t, Xpolym and Apolym, and a prime modulus. The Alexander quandle Z_p[t,t^-1]/(Xpolym) is used to color the braids. The Alexander quandle Z_p[t,t^-1]/(Apolym) is used for the coefficient group. This program will evaluate the 2-cocycle and 3-cocycle values from the Mochizuki polynomial formula. The 2-cocycle formula is f(x,y)=x-y)^p^(n1) * y^(b2) where n1 and b2 correspond to the arguments passed to the procedure. The 3-cocycle formula is, f(x,y,z)=(x-y)^p^(m1) * (y-z)^p^(m2) * z^(a3) where m1, m2, and a3 correspond to arguments passed to the procedure. It will use the c program to generate all valid colorings of the braid and then will calculate the colorings of the regions while evaluating the state sum for the two and three cocycle cases. The final parameter is the braid word of a knot.
This procedure will return in the following order:
1) the value of the Mochizuki polynomial 2-cocycle invariant,
2) the value of the Mochizuki polynomial 3-cocycle invariant,
 

3) the valid coloring of the braid,
4) the values of the Mochizuki polynomial 2-cocycle formula,
5) the values of the Mochizuki polynomial 3-cocycle formula, and
6) the number of valid coloring of the braid.
 

 

> Invar2_3MochizukiDLL:=proc(Xpolym,Apolym,p,m1,m2,a3,n1,b2,Knot)
#Procedure to calculate the state sum term for a knot
#Input: (1) Xpolym is the polynomial from the Alexander quandle that will
#           be used to color the knot.
#       (2) Apolym is the polynomial from the alexander quandle that
#           is used for the coefficients.
#       (3) prime, p, for the quandles.
#       (4) From Mochizuki theorem a1=p^m1
#       (5) From Mochizuki theorem a2=p^m2
#       (6) From Mochizuki theorem a3=p^m3 or a3=0. So a3 must be a power of p
#            or zero.
#       (7) A knot given in braid form (ex [1,1,1]).
#Output: The state sum of the knot.
#Example Input: Invar3Mochizuki(t^2-t+1,t^2-t+1,5,0,1,0,[1,1,1]);
#Example Output:  625+3750*u^(t+3)+3750*u^(4*t+2)+3750*u^(3*t+4)+3750*u^(1+2*t)

local SST2coc,SST3coc,SST2contri,SST3contri,jj3,jj5,jj6,jj8,s,num,Color,brind,
     indx,ColDiffMatch0,ColorDiff0,Ginv,quandleorder,        
     co2Solutions,co3Solutions,Facecolors,facecolors,
     precolorface,nowcolor,colcoloring,Quandle,VALIDCOLORS,
     QuandleC,KnotC,x,y,i,valid2coc,valid3coc,numVcolors;
SST2coc:=0;
SST3coc:=0;
VALIDCOLORS:=[];
valid2coc:=false;
valid3coc:=false;

#print("Program start");


#The following will create the Cayley table for the Alexander Quandle where the elements come
#from the set {0..n-1}
Quandle:=AlexQuandle(Xpolym,p);

co3Solutions:=[];
co2Solutions:=[];
quandleorder:=quandlesize(Quandle);

#print("Generated the quandle");
# The following statement will use Mochizuki formula to get the values for each term of the
#cocycle. The indices of the array come from {0..n-1} and represent elements of the Alexander
#quandle X. The values of these elements lie in A=Z_p[t^(+-1)/(Apolym) and are in polynomial #form.


co3Solutions:=Mochizuki3coc(Xpolym,Apolym,p,m1,m2,a3);
co2Solutions:=Mochizuki2coc(Xpolym,Apolym,p,n1,b2);
#print("finished cocycles");
if type(co2Solutions,table) and type(co3Solutions,table) then
 valid2coc:=cocycle2check(co2Solutions,Xpolym,Apolym,p);
 valid3coc:=cocycle3check(co3Solutions,Xpolym,Apolym,p);
fi;

#print("The value of co3check is ",cocycle3check(coSolutions,Xpolym,Apolym,p));

if valid2coc and valid3coc then
brind:=max(op(map(x->abs(x),Knot)))+1;


#################
numVcolors:=0;

##################

#print("brind is",brind);
QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order):
#print("finish QuandleC");
KnotC:=Array(0..(nops(Knot)-1),Knot,datatype=integer[2],order=C_order):
#print("finish Knotc");
VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
#print("finish VALIDCOLORS");
numVcolors:=validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

#print("numVcolors is ",numVcolors);
#validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

Color[0]:=numVcolors;
#Color[0]:=VALIDCOLORS[0];
#print("finish colors"):
#for x from 1 to VALIDCOLORS[0] do
for x from 1 to numVcolors do
 for y from 1 to nops(Knot)+1 do
   Color[x][y]:=array(1..brind,[]):
 od:
od:


for jj3 from 1 to (nops(Knot)+1) do                # Color vectors.
    
    Facecolors[jj3]:=array(0..brind-1):
od;

Color:=cvrtarray(brind,nops(Knot),VALIDCOLORS,numVcolors);
#Color[0]:=VALIDCOLORS[0];

#print("The number of valid colorings ",Color[0]);
#print("about to enter sst loop");
#  for i from 1 to VALIDCOLORS[0] do

for i from 1 to numVcolors do      for facecolors from 0 to  (quandleorder-1) do
       SST2contri:=0;                                # State-sum contributions.
       SST3contri:=0;     
        for precolorface from 1 to (nops(Knot)+1) do  
        
           Facecolors[precolorface][0]:=facecolors:

       od;
       for nowcolor from 1 to nops(Knot) do
      
           for colcoloring from 0 to (abs(Knot[nowcolor])-1) do  
               Facecolors[nowcolor][colcoloring+1]:=Quandle[Facecolors[nowcolor][colcoloring],
                                                    Color[i][nowcolor][colcoloring+1]]:
     
           od:

       od:
       for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST3contri:= SST3contri + co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s][abs(Knot[s])], Color[i][s][abs(Knot[s])+1] ] :

           else
               SST3contri:=SST3contri -co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s+1][abs(Knot[s])], Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:                          # Closing the state-sum term, for s.
    
                                    
    SST3coc:=SST3coc + u^(Rem(SST3contri,Apolym,t) mod p);
    od:     
                          #closes facecolors  

    for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST2contri:= SST2contri + co2Solutions[Color[i][s][abs(Knot[s])],                              Color[i][s][abs(Knot[s])+1] ] :

           else
               SST2contri:=SST2contri -co2Solutions[Color[i][s+1][abs(Knot[s])],                                                         Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:
    SST2coc:=SST2coc + u^(Rem(SST2contri,Apolym,t) mod p);                                              
od:                                     # Closing indx loop (one color here at a time, for indx).
return(SST2coc,SST3coc,Color,co2Solutions,co3Solutions,numVcolors);
else
print("Invalid cocycles");
return;
fi;
end:
 

The procedure CalcMochinvars() will run the procedure, Invar2_3MochizukiDLL:=proc(Quandle,p,Knot), over the 2977 knots stored in the file knotsLivingston.txt. It will automatically generate filenames and write the data to the appropriate file. All of the values that the 2-cocycle and 3-cocycle invariants take are written to the files, Z_pmod(polym)2cocinvn_b.inv or Z_2mod(polym)3cocinvm1_m2_a3.inv. For example, 

the values for the Mochizuki 2 cocycle invariants with Mochizuki 2-cocycle formula f(x,y)=(x-y)^2^(1) * y^0 and Alexander quandle
Z_2 [t,t^-1]/(t^6+t^3+1) would be stored  in the file Z_2mod(t^6+t^3+1)2cocinv1_0.inv. This file is saved in the directory specified by the string PATH that is specified by the user. The values the Mochizuki formula give are stored in the file coc2SolnsZ_pmod(polym)_n_b.sol or coc3SolnsZ_pmod(polym)_m1_m2_a3.sol. The valid colorings of a given braid with knot number Kx_y are stored in the file, ColorsZ_pmod(polym)Kx_y.clr. numberofknots is how far through the table table you wish to calculate. For example, numberofknots=83 will calculate through 9 crossings.
 

> CalcMochinvars:=proc(filePATH,p ,polym,m1,m2,a3,n,b,numberofknots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpfilename2,tmpfilename3,tmpf1,tmpf2,
     tmpf3,INVARS,quandleorder,tmpfilename4,tmpfilename5,tmpf4,tmpf5,brind,
     tmpColorstr,x,y,z,tmpco2str,tmpco3str,bstrand,crossvec,colnum,JJ,writesolpath,cpath,solpath;


  cpath:=args[10];
  solpath:=args[11];



HH:=ssystem(date):HH[2];


tmpfilename1:=cat(filePATH,"Z_",p,"mod(",convert(polym,string),")2cocinv",n,"_",b,".inv");
tmpfilename2:=cat(filePATH,"Z_",p,"mod(",convert(polym,string),")3cocinv",m1,"_",m2,"_",a3,".inv");

tmpfilename1:=StringTools[Remove](ismult,tmpfilename1);
tmpfilename2:=StringTools[Remove](ismult,tmpfilename2);



#if cpath<> false then
#    tmpfilename3:=cat(cpath,Colors,Z_,p,m,o,d,"(",convert(polym,string),")");
#    tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);
#fi;

if solpath<> false then
   tmpfilename4:=cat(solpath,"coc2SolnsZ_",p,"mod(",convert(polym,string),")_",n,"_",b,".sol");
   tmpfilename5:=cat(solpath,"coc3SolnsZ_",p,"mod(",convert(polym,string),")_",m1,"_",m2,"_",a3,".sol");
   tmpfilename4:=StringTools[Remove](ismult,tmpfilename4);
   tmpfilename5:=StringTools[Remove](ismult,tmpfilename5);
   tmpf4:=fopen(tmpfilename4,WRITE);
   tmpf5:=fopen(tmpfilename5,WRITE);
   printf("%s\n",tmpfilename4);
   printf("%s\n",tmpfilename5);
   fprintf(tmpf4,"#Mochizuki 2-cocycle solutions for the Alexander Quandle %s\n",
             cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
   fprintf(tmpf5,"#Mochizuki 3-cocycle solutions for the Alexander Quandle %s\n",
             cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
   fprintf(tmpf4,"#2-cocycle formula f(x,y)=(x-y)^%d^%d *y^%d \n",p,n,b);
   fprintf(tmpf5,"#3-cocycle formula f(x,y,z)=(x-y)^%d^%d *(y-z)^%d^%d *z^%d\n",p,m1,p,m2,a3);
   fprintf(tmpf4,"#Generated %s\n",HH[2]);
   fprintf(tmpf5,"#Generated %s\n",HH[2]);
   writesolpath:=true;
fi;
tmpf1:=fopen(tmpfilename1,WRITE);
tmpf2:=fopen(tmpfilename2,WRITE);
# tmpf3:=fopen(tmpfilename3,WRITE);




printf("%s\n",tmpfilename1);
printf("%s\n",tmpfilename2);
#printf("%s\n",tmpfilename3);




fprintf(tmpf1,"#Mochizuki 2-cocycle invariants for Alexander Quandles\n");
fprintf(tmpf2,"#Mochizuki 3-cocycle invariants for Alexander Quandles\n");
fprintf(tmpf1,"#2-cocycle formula f(x,y)=(x-y)^%d^%d *y^%d \n",p,n,b);
fprintf(tmpf2,"#3-cocycle formula f(x,y,z)=(x-y)^%d^%d *(y-z)^%d^%d *z^%d\n",p,m1,p,m2,a3);

fprintf(tmpf1,"#Alexander Quandle %s\n",
              cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
fprintf(tmpf2,"#Alexander Quandle %s\n",
              cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));

#fprintf(tmpf3,"The valid color vectors for the braids colored with the following quandle\n");
#fprintf(tmpf3,"Alexander Quandle %s\n",cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));



fprintf(tmpf1,"#Generated %s\n",HH[2]);
fprintf(tmpf2,"#Generated %s\n",HH[2]);
#fprintf(tmpf3,"#Generated %s\n",HH[2]);



for i from 0 to numberofknots do

if Gcd(Knot[i,3],polym) mod p <>1 then
JJ:=ssystem(date):
    
INVARS:=Invar2_3MochizukiDLL(polym,polym,p,m1,m2,a3,n,b,Knot[i,2]):
fprintf(tmpf1,"%s\t%s\t \n%s\n\n",
       convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[1],string));
fprintf(tmpf2,"%s\t%s\t \n%s\n\n",
       convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[2],string));

if cpath<> false then
    tmpfilename3:=cat(cpath,"ColorsZ_",p,"mod(",convert(polym,string),")");
    tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);
    tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");

    tmpf3:=fopen(tmpfilename3,WRITE);

    fprintf(tmpf3,"#The valid color vectors for the braids colored with the Alexander quandle %s\n",
               cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
    tmpColorstr:=cat(Col,convert(Knot[i,1],string),cat(Z_,p,"mod","(",convert(polym,string),")"));
    fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVARS[6]);
    brind:=max(op(map(x->abs(x),Knot[i,2])))+1;

    for colnum from 1 to INVARS[6] do
        for crossvec from 1 to nops(Knot[i,2])+1 do
            for bstrand from 1 to brind do
                fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVARS[3][colnum][crossvec][bstrand]);
    od:od:od:
    
    JJ:=ssystem(date):
    fprintf(tmpf3,"#Generated %s\n",JJ[2]);
    fprintf(tmpf3,"\n\n\n");
  
    fclose(tmpf3);
# tmpfilename3:=cat(cpath,Colors,Z_,p,m,o,d,"(",convert(polym,string),")");
#   tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);
fi;   #  closes if cpath write color file

if writesolpath<> false then

   tmpco2str:=cat(co2Z_,p,m,o,d,"(",convert(polym,string),")",2,cocSol,n,_,b);
   tmpco3str:=cat(co3Z_,p,m,o,d,"(",convert(polym,string),")",3,cocSol,m1,_,m2,_,a3);
   quandleorder:=quandlesize(AlexQuandle(polym,p));
   for x from 0 to quandleorder-1 do
      for y from 0 to quandleorder-1 do
         for z from 0 to quandleorder-1 do
             fprintf(tmpf5,"%s[%d,%d,%d]:=%s;\n",tmpco3str,x,y,z,convert(INVARS[5][x,y,z],string));
         od;
         fprintf(tmpf4,"%s[%d,%d]:=%s;\n",tmpco2str,x,y,convert(INVARS[4][x,y],string));
   od:od:
   JJ:=ssystem(date):JJ[2];
   fprintf(tmpf4,"#Generated %s\n",JJ[2]);
   fprintf(tmpf5,"#Generated %s\n",JJ[2]);
   fprintf(tmpf4,"\n\n\n");
   fprintf(tmpf5,"\n\n\n");
   fclose(tmpf4);
   fclose(tmpf5);
   writesolpath:=false;
fi;#closes solpath write



fi;  #closes if gcd Alexander polynomial test




od:
print("finished all knots");







HH:=ssystem(date):HH[2];

fprintf(tmpf1,"#Generated %s\n",HH[2]);
fprintf(tmpf2,"#Generated %s\n",HH[2]);


fclose(tmpf1);
fclose(tmpf2);
#fclose(tmpf3);


end:
 

> Invar2MochizukiDLL:=proc(Xpolym,Apolym,p,n1,b2,Knot)
#Procedure to calculate the state sum term for a knot
#Input: (1) Xpolym is the polynomial from the Alexander quandle that will
#           be used to color the knot.
#       (2) Apolym is the polynomial from the alexander quandle that
#           is used for the coefficients.
#       (3) prime, p, for the quandles.
#       (4) n1 is the first exponent from the Mochizuki 3 cocycle formula f(x,y)=(x-y)^(p^(n1)) * y^b2
#       (5) b2 is the second exponent from the Mochizuki 3 cocycle formula f(x,y)=(x-y)^(p^(n1)) * y^b2
#       (6) A knot given in braid form (ex [1,1,1]).
#Output: The state sum of the knot.
#Example Input:
#Example Output:  

local SST2coc,SST3coc,SST2contri,SST3contri,jj3,jj5,jj6,jj8,s,num,Color,brind,
     indx,ColDiffMatch0,ColorDiff0,Ginv,quandleorder,        
     co2Solutions,co3Solutions,Facecolors,facecolors,
     precolorface,nowcolor,colcoloring,Quandle,VALIDCOLORS,
     QuandleC,KnotC,x,y,i,valid2coc,valid3coc,numVcolors;
SST2coc:=0;

VALIDCOLORS:=[];
valid2coc:=false;

co2Solutions:=[];
#print("Program start");


#The following will create the Cayley table for the Alexander Quandle where the elements come
#from the set {0..n-1}
Quandle:=AlexQuandle(Xpolym,p);

quandleorder:=quandlesize(Quandle);

#print("Generated the quandle");
# The following statement will use Mochizuki formula to get the values for each term of the
#cocycle. The indices of the array come from {0..n-1} and represent elements of the Alexander
#quandle X. The values of these elements lie in A=Z_p[t^(+-1)/(Apolym) and are in polynomial #form.



co2Solutions:=Mochizuki2coc(Xpolym,Apolym,p,n1,b2);
#print("finished cocycles");
if type(co2Solutions,table)  then
 valid2coc:=cocycle2check(co2Solutions,Xpolym,Apolym,p);
fi;

#print("The value of co3check is ",cocycle3check(coSolutions,Xpolym,Apolym,p));

if valid2coc then
brind:=max(op(map(x->abs(x),Knot)))+1;


#################
numVcolors:=0;

##################

#print("brind is",brind);
QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order):
#print("finish QuandleC");
KnotC:=Array(0..(nops(Knot)-1),Knot,datatype=integer[2],order=C_order):
#print("finish Knotc");
VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
#print("finish VALIDCOLORS");
numVcolors:=validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

#print("numVcolors is ",numVcolors);
#validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

Color[0]:=numVcolors;
#Color[0]:=VALIDCOLORS[0];
#print("finish colors"):
#for x from 1 to VALIDCOLORS[0] do
for x from 1 to numVcolors do
 for y from 1 to nops(Knot)+1 do
   Color[x][y]:=array(1..brind,[]):
 od:
od:




Color:=cvrtarray(brind,nops(Knot),VALIDCOLORS,numVcolors);
#Color[0]:=VALIDCOLORS[0];

#print("The number of valid colorings ",Color[0]);
#print("about to enter sst loop");
#  for i from 1 to VALIDCOLORS[0] do

for i from 1 to numVcolors do      
   
       SST2contri:=0;                                # State-sum contributions
    for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST2contri:= SST2contri + co2Solutions[Color[i][s][abs(Knot[s])],Color[i][s][abs(Knot[s])+1] ] :

           else
               SST2contri:=SST2contri -co2Solutions[Color[i][s+1][abs(Knot[s])],Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:
    SST2coc:=SST2coc + u^(Rem(SST2contri,Apolym,t) mod p);                                              
od:                                     # Closing indx loop (one color here at a time, for indx).
return(SST2coc,Color,co2Solutions,numVcolors);
else
print("Invalid cocycles");
return false;
fi;
end:
 

> Calc2Mochinvars:=proc(filePATH,p ,polym,n,b,numberofknots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpfilename2,tmpfilename3,tmpf1,tmpf2,
     tmpf3,INVARS,quandleorder,tmpfilename4,tmpfilename5,tmpf4,tmpf5,brind,
     tmpColorstr,x,y,z,tmpco2str,tmpco3str,bstrand,crossvec,colnum,JJ,writesolpath,cpath,solpath;


  cpath:=args[7];
  solpath:=args[8];


HH:=ssystem(date):HH[2];


tmpfilename1:=cat(filePATH,"Z_",p,"mod(",convert(polym,string),")2cocinv",n,"_",b,".inv");

tmpfilename1:=StringTools[Remove](ismult,tmpfilename1);



#if cpath<> false then
#    tmpfilename3:=cat(cpath,Colors,Z_,p,m,o,d,"(",convert(polym,string),")");
#    tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);
#fi;

if solpath<> false then
   tmpfilename4:=cat(solpath,"coc2SolnsZ_",p,"mod(",convert(polym,string),")_",n,"_",b,".sol");
   
   tmpfilename4:=StringTools[Remove](ismult,tmpfilename4);
  
   tmpf4:=fopen(tmpfilename4,WRITE);
   
   printf("%s\n",tmpfilename4);
   
   fprintf(tmpf4,"#Mochizuki 2-cocycle solutions for the Alexander Quandle %s\n",
             cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
   
   fprintf(tmpf4,"#2-cocycle formula f(x,y)=(x-y)^%d^%d *y^%d \n",p,n,b);
   
   fprintf(tmpf4,"#Generated %s\n",HH[2]);
  
   writesolpath:=true;
fi;
tmpf1:=fopen(tmpfilename1,WRITE);





printf("%s\n",tmpfilename1);





fprintf(tmpf1,"#Mochizuki 2-cocycle invariants for Alexander Quandles\n");

fprintf(tmpf1,"#2-cocycle formula f(x,y)=(x-y)^%d^%d *y^%d \n",p,n,b);


fprintf(tmpf1,"#Alexander Quandle %s\n",
              cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));


#fprintf(tmpf3,"The valid color vectors for the braids colored with the following quandle\n");
#fprintf(tmpf3,"Alexander Quandle %s\n",cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));



fprintf(tmpf1,"#Generated %s\n",HH[2]);



for i from 0 to numberofknots do

if Gcd(Knot[i,3],polym) mod p <>1 then
JJ:=ssystem(date):
    
INVARS:=Invar2MochizukiDLL(polym,polym,p,n,b,Knot[i,2]):
fprintf(tmpf1,"%s\t%s\t \n%s\n\n",
       convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[1],string));

if cpath<> false then
    tmpfilename3:=cat(cpath,"ColorsZ_",p,"mod(",convert(polym,string),")");
    tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);
    tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");

    tmpf3:=fopen(tmpfilename3,WRITE);

    fprintf(tmpf3,"#The valid color vectors for the braids colored with the Alexander quandle %s\n",
               cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
    tmpColorstr:=cat(Col,convert(Knot[i,1],string),cat(Z_,p,"mod","(",convert(polym,string),")"));
    fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVARS[4]);
    brind:=max(op(map(x->abs(x),Knot[i,2])))+1;

    for colnum from 1 to INVARS[4] do
        for crossvec from 1 to nops(Knot[i,2])+1 do
            for bstrand from 1 to brind do
                fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVARS[2][colnum][crossvec][bstrand]);
    od:od:od:
    
    JJ:=ssystem(date):
    fprintf(tmpf3,"#Generated %s\n",JJ[2]);
    fprintf(tmpf3,"\n\n\n");
  
    fclose(tmpf3);
#tmpfilename3:=cat(cpath,Colors,Z_,p,m,o,d,"(",convert(polym,string),")");
#    tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);

fi;   #  closes if cpath write color file

if writesolpath<> false then

   tmpco2str:=cat(co2Z_,p,m,o,d,"(",convert(polym,string),")",2,cocSol,n,_,b);
  
   quandleorder:=quandlesize(AlexQuandle(polym,p));
   for x from 0 to quandleorder-1 do
      for y from 0 to quandleorder-1 do
         
         fprintf(tmpf4,"%s[%d,%d]:=%s;\n",tmpco2str,x,y,convert(INVARS[3][x,y],string));
   od:od:
   JJ:=ssystem(date):JJ[2];
   fprintf(tmpf4,"#Generated %s\n",JJ[2]);
   
   fprintf(tmpf4,"\n\n\n");
   
   fclose(tmpf4);
   
   writesolpath:=false;
fi;#closes solpath write



fi;  #closes if gcd Alexander polynomial test




od:
print("finished all knots");







HH:=ssystem(date):HH[2];

fprintf(tmpf1,"#Generated %s\n",HH[2]);



fclose(tmpf1);



end:
 

> Invar3MochizukiDLL:=proc(Xpolym,Apolym,p,m1,m2,a3,Knot)
#Procedure to calculate the state sum term for a knot
#Input: (1) Xpolym is the polynomial from the Alexander quandle that will
#           be used to color the knot.
#       (2) Apolym is the polynomial from the alexander quandle that
#           is used for the coefficients.
#       (3) prime, p, for the quandles.
#       (4) From Mochizuki theorem a1=p^m1,f(x,y,z)=(x-y)^(p^(m1)) * (y-z)^(p^(m2)) * z^(a3)
#       (5) From Mochizuki theorem a2=p^m2
#       (6) From Mochizuki theorem a3=p^m3 or a3=0. So a3 must be a power of p
#            or zero.
#       (7) A knot given in braid form (ex [1,1,1]).
#Output: The state sum of the knot.
#Example Input: Invar3Mochizuki(t^2-t+1,t^2-t+1,5,0,1,0,[1,1,1]);
#Example Output:  625+3750*u^(t+3)+3750*u^(4*t+2)+3750*u^(3*t+4)+3750*u^(1+2*t)

local SST2coc,SST3coc,SST2contri,SST3contri,jj3,jj5,jj6,jj8,s,num,Color,brind,
     indx,ColDiffMatch0,ColorDiff0,Ginv,quandleorder,        
     co2Solutions,co3Solutions,Facecolors,facecolors,
     precolorface,nowcolor,colcoloring,Quandle,VALIDCOLORS,
     QuandleC,KnotC,x,y,i,valid2coc,valid3coc,numVcolors;

SST3coc:=0;
VALIDCOLORS:=[];

valid3coc:=false;

co3Solutions:=[];
#print("Program start");


#The following will create the Cayley table for the Alexander Quandle where the elements come
#from the set {0..n-1}
Quandle:=AlexQuandle(Xpolym,p);

quandleorder:=quandlesize(Quandle);

#print("Generated the quandle");
# The following statement will use Mochizuki formula to get the values for each term of the
#cocycle. The indices of the array come from {0..n-1} and represent elements of the Alexander
#quandle X. The values of these elements lie in A=Z_p[t^(+-1)/(Apolym) and are in polynomial #form.


co3Solutions:=Mochizuki3coc(Xpolym,Apolym,p,m1,m2,a3);

#print("finished cocycles");
if type(co3Solutions,table) then
 
 valid3coc:=cocycle3check(co3Solutions,Xpolym,Apolym,p);
fi;

#print("The value of co3check is ",cocycle3check(coSolutions,Xpolym,Apolym,p));

if valid3coc then
brind:=max(op(map(x->abs(x),Knot)))+1;


#################
numVcolors:=0;

##################

#print("brind is",brind);
QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order):
#print("finish QuandleC");
KnotC:=Array(0..(nops(Knot)-1),Knot,datatype=integer[2],order=C_order):
#print("finish Knotc");
VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
#print("finish VALIDCOLORS");
numVcolors:=validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

#print("numVcolors is ",numVcolors);
#validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

Color[0]:=numVcolors;
#Color[0]:=VALIDCOLORS[0];
#print("finish colors"):
#for x from 1 to VALIDCOLORS[0] do
for x from 1 to numVcolors do
 for y from 1 to nops(Knot)+1 do
   Color[x][y]:=array(1..brind,[]):
 od:
od:


for jj3 from 1 to (nops(Knot)+1) do                # Color vectors.
    
    Facecolors[jj3]:=array(0..brind-1):
od;

Color:=cvrtarray(brind,nops(Knot),VALIDCOLORS,numVcolors);
#Color[0]:=VALIDCOLORS[0];

#print("The number of valid colorings ",Color[0]);
#print("about to enter sst loop");
#  for i from 1 to VALIDCOLORS[0] do

for i from 1 to numVcolors do     
for facecolors from 0 to  (quandleorder-1) do
                                      # State-sum contributions.
       SST3contri:=0;     
        for precolorface from 1 to (nops(Knot)+1) do  
        
           Facecolors[precolorface][0]:=facecolors:

       od;
       for nowcolor from 1 to nops(Knot) do
      
           for colcoloring from 0 to (abs(Knot[nowcolor])-1) do  
               Facecolors[nowcolor][colcoloring+1]:=Quandle[Facecolors[nowcolor][colcoloring],
                                                    Color[i][nowcolor][colcoloring+1]]:
     
           od:

       od:
       for s from 1 to nops(Knot) do
           if  Knot[s] > 0 then
               SST3contri:= SST3contri + co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s][abs(Knot[s])], Color[i][s][abs(Knot[s])+1] ] :

           else
               SST3contri:=SST3contri -co3Solutions[Facecolors[s][abs(Knot[s])-1],
                           Color[i][s+1][abs(Knot[s])], Color[i][s+1][abs(Knot[s])+1] ] :


           fi:
       od:                          # Closing the state-sum term, for s.
    
                                    
    SST3coc:=SST3coc + u^(Rem(SST3contri,Apolym,t) mod p);
    od:     
                          #closes facecolors  

                                              
od:                                     # Closing indx loop (one color here at a time, for indx).
return(SST3coc,Color,co3Solutions,numVcolors);
else
print("Invalid cocycles");
return false;
fi;
end:
 

> Calc3Mochinvars:=proc(filePATH,p ,polym,m1,m2,a3,numberofknots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpfilename2,tmpfilename3,tmpf1,tmpf2,
     tmpf3,INVARS,quandleorder,tmpfilename4,tmpfilename5,tmpf4,tmpf5,brind,
     tmpColorstr,x,y,z,tmpco2str,tmpco3str,bstrand,crossvec,colnum,JJ,writesolpath,cpath,solpath;


  cpath:=args[8];
  solpath:=args[9];


HH:=ssystem(date):HH[2];



tmpfilename2:=cat(filePATH,"Z_",p,"mod(",convert(polym,string),")3cocinv",m1,"_",m2,"_",a3,".inv");


tmpfilename2:=StringTools[Remove](ismult,tmpfilename2);



#if cpath<> false then
#    tmpfilename3:=cat(cpath,Colors,Z_,p,m,o,d,"(",convert(polym,string),")");
#    tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);
#fi;

if solpath<> false then
   
   tmpfilename5:=cat(solpath,"coc3SolnsZ_",p,"mod(",convert(polym,string),")_",m1,"_",m2,"_",a3,".sol");
   
   tmpfilename5:=StringTools[Remove](ismult,tmpfilename5);
   
   tmpf5:=fopen(tmpfilename5,WRITE);
  
   printf("%s\n",tmpfilename5);
   
   fprintf(tmpf5,"#Mochizuki 3-cocycle solutions for the Alexander Quandle %s\n",
             cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
   
   fprintf(tmpf5,"#3-cocycle formula f(x,y,z)=(x-y)^%d^%d *(y-z)^%d^%d *z^%d\n",p,m1,p,m2,a3);
   
   fprintf(tmpf5,"#Generated %s\n",HH[2]);
   writesolpath:=true;
fi;

tmpf2:=fopen(tmpfilename2,WRITE);
# tmpf3:=fopen(tmpfilename3,WRITE);





printf("%s\n",tmpfilename2);
#printf("%s\n",tmpfilename3);





fprintf(tmpf2,"#Mochizuki 3-cocycle invariants for Alexander Quandles\n");

fprintf(tmpf2,"#3-cocycle formula f(x,y,z)=(x-y)^%d^%d *(y-z)^%d^%d *z^%d\n",p,m1,p,m2,a3);


fprintf(tmpf2,"#Alexander Quandle %s\n",
              cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));

#fprintf(tmpf3,"The valid color vectors for the braids colored with the following quandle\n");
#fprintf(tmpf3,"Alexander Quandle %s\n",cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));




fprintf(tmpf2,"#Generated %s\n",HH[2]);
#fprintf(tmpf3,"#Generated %s\n",HH[2]);



for i from 0 to numberofknots do

if Gcd(Knot[i,3],polym) mod p <>1 then
JJ:=ssystem(date);
INVARS:=Invar3MochizukiDLL(polym,polym,p,m1,m2,a3,Knot[i,2]):

fprintf(tmpf2,"%s\t%s\t \n%s\n\n",
       convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[1],string));

if cpath<> false then
    tmpfilename3:=cat(cpath,"ColorsZ_",p,"mod(",convert(polym,string),")");
    tmpfilename3:=StringTools[Remove](ismult,tmpfilename3);
    tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");

    tmpf3:=fopen(tmpfilename3,WRITE);

    fprintf(tmpf3,"#The valid color vectors for the braids colored with the Alexander quandle %s\n",
               cat(Z_,p,"[t^1,t^-1]","/","(",convert(polym,string),")"));
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
    tmpColorstr:=cat(Col,convert(Knot[i,1],string),cat(Z_,p,"mod","(",convert(polym,string),")"));
    fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVARS[4]);
    brind:=max(op(map(x->abs(x),Knot[i,2])))+1;

    for colnum from 1 to INVARS[4] do
        for crossvec from 1 to nops(Knot[i,2])+1 do
            for bstrand from 1 to brind do
                fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVARS[2][colnum][crossvec][bstrand]);
    od:od:od:
    
    JJ:=ssystem(date):
    fprintf(tmpf3,"#Generated %s\n",JJ[2]);
    fprintf(tmpf3,"\n\n\n");
  
    fclose(tmpf3);


fi;   #  closes if cpath write color file

if writesolpath<> false then

   
   tmpco3str:=cat(co3Z_,p,m,o,d,"(",convert(polym,string),")",3,cocSol,m1,_,m2,_,a3);
   quandleorder:=quandlesize(AlexQuandle(polym,p));
   for x from 0 to quandleorder-1 do
      for y from 0 to quandleorder-1 do
         for z from 0 to quandleorder-1 do
             fprintf(tmpf5,"%s[%d,%d,%d]:=%s;\n",tmpco3str,x,y,z,convert(INVARS[3][x,y,z],string));
         od;
         
   od:od:
   JJ:=ssystem(date):JJ[2];
   
   fprintf(tmpf5,"#Generated %s\n",JJ[2]);
  
   fprintf(tmpf5,"\n\n\n");
   
   fclose(tmpf5);
   writesolpath:=false;
fi;#closes solpath write



fi;  #closes if gcd Alexander polynomial test




od:
print("finished all knots");







HH:=ssystem(date):HH[2];


fprintf(tmpf2,"#Generated %s\n",HH[2]);


fclose(tmpf2);



end:
 

ismult() is used in the procedure CalcMochinvars() to remove the character '*' from the filename that is generated. 

> ismult:=proc(charstar)
if charstar="*" then
 return true;
else
return false;
fi;
end:
 

 

>
 

> CalcDihinvars:=proc(filePATH,p,numberofKnots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpf1,Mcocycles,INVAR,polym,tmpfilename2,tmpfilename3,tmpf3,tmpf2,x,y,z,tmpColorstr,
     brind,colnum,crossvec,bstrand,quandleorder,tmpco3str,JJ,writesolpath,cpath,solpath;


  cpath:=args[4];
  solpath:=args[5];

Mcocycles:=[];

polym:=t+1;
Mcocycles:=MochizukiDihedral3coc(p);
HH:=ssystem(date):HH[2];

tmpfilename1:=cat(filePATH,"MochDih_R_",p,"3coc_inZ_",p,".inv");




#if cpath<> false then
#
#   tmpfilename3:=cat(cpath,ColorsDih,_,R,_,p);
#fi;

if solpath<> false then
  tmpfilename2:=cat(solpath,"MochDih3cocSOL_inZ_",p,".sol");
  tmpf2:=fopen(tmpfilename2,WRITE);
  fprintf(tmpf2,"#Mochizuki 3-cocycle solutions for the Dihedral Quandle R_%d \n",p);
  fprintf(tmpf2,"#3-cocycle formula in Z_%d is f(x,y,z)=(x-y)[(2z^%d -j^%d)-(2z-y)^%d]/%d mod %d\n",p,p,p,p,p,p);
  printf("%s\n",tmpfilename2);
  writesolpath:=true;
fi;
printf("%s\n",tmpfilename1);

tmpf1:=fopen(tmpfilename1,WRITE);



fprintf(tmpf1,"#Mochizuki 3-cocycle invariants for the Dihedral Quandle R_%d \n",p);

fprintf(tmpf1,"#3-cocycle formula in Z_%d is f(x,y,z)=(x-y)[(2z^%d -j^%d)-(2z-y)^%d]/%d mod %d\n",p,p,p,p,p,p);




fprintf(tmpf1,"#Generated %s\n",HH[2]);


#print("before knot loop");
for i from 0 to  numberofKnots do
JJ:=ssystem(date):JJ[2];


    INVAR:=Invar3UntwistedDLL(AlexQuandle(polym,p),p,Knot[i,2],Mcocycles);
    fprintf(tmpf1,"%s\t%s\t\n%s\n\n",convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVAR[1],string));
    
    if cpath<>false then

        tmpfilename3:=cat(cpath,"ColorDih_R_",p);
        tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");

tmpf3:=fopen(tmpfilename3,WRITE);
    

        fprintf(tmpf3,"#The valid color vectors for the braids colored with the quandle R_%d\n",p);
        #print("opened clr file");
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
        tmpColorstr:=cat(Col,convert(Knot[i,1],string),R,_,p);
        fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVAR[4]);
        brind:=max(op(map(x->abs(x),Knot[i,2])))+1;
        #print("just wrote the number of colors",INVAR[4]);
        for colnum from 1 to INVAR[4] do
            for crossvec from 1 to nops(Knot[i,2])+1 do
                for bstrand from 1 to brind do
                    fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVAR[2][colnum][crossvec][bstrand]);
        od:od:od:
       
       JJ:=ssystem(date);
       fprintf(tmpf3,"#Generated %s\n",JJ[2]);
       fprintf(tmpf3,"\n\n\n");
      fclose(tmpf3);
#tmpfilename3:=cat(cpath,ColorsDih,_,R,_,p);

   fi;  #end if cpath write


   if writesolpath<> false then
      tmpco3str:=cat(co3MochDihZ_,p,Sol);
      quandleorder:=p;
      for x from 0 to quandleorder-1 do
          for y from 0 to quandleorder-1 do
             for z from 0 to quandleorder-1 do
                fprintf(tmpf2,"%s[%d,%d,%d]:=%s;\n",tmpco3str,x,y,z,convert(INVAR[3][x,y,z],string));
             od;
          od;
       od;

      fprintf(tmpf2,"\n\n\n");
      JJ:=ssystem(date);
      fprintf(tmpf2,"#Generated %s\n",JJ[2]);
      fclose(tmpf2);
      writesolpath:=false;
    fi;


od:
print("finished all knots");





HH:=ssystem(date):HH[2];

fprintf(tmpf1,"#Generated %s\n",HH[2]);

fclose(tmpf1);


end:
 

>
 

The twisted solution procedure 

 

> co2TwistedSol:=proc(Quandle,polym,m::posint)
local x,y,z,i,EQ,f,F,vars,A,quanod,E,Sol,Sol_list,j,
     temp, deg,Cof,testsol,ttemp,TempPoly,TempEq,
     TempList,k,LL,GG,b,ss;
option remember;
Cof:=[];
if type(polym,polynom) then  
  deg:=degree(polym,t);
else
  printf("%s\n",ERROR);
  return;
fi;
Cof:=coeffs(polym);
if gcd(Cof[1],m)<>1 and gcd(Cof[nops(Cof)],m)<>1 then
 printf("%s","ERROR: Not a finite ring.");
 return;
else
 continue;
fi;
quanod:=quandlesize(Quandle);

f:=array(0..quanod-1,0..quanod-1,0..(deg-1));
EQ:=[];
for i from 0 to quanod-1 do
 for j from 0 to quanod-1 do
    F[i,j]:=sum(f[i,j,k]*t^k, k=0..deg-1);
od:od:


for x from 0 to (quanod-1) do
  for y from 0 to (quanod-1) do
     for z from 0 to (quanod-1) do
        TempEq[x,y,z]:=t*F[x,y]+F[Quandle[x,y], z]-t*F[x,z]
                       -F[Quandle[x,z],Quandle[y,z]]+(t-1)*F[y,z]:
                              # The equation for each (x,y,z).
        TempPoly:=Rem(TempEq[x,y,z],polym,t) mod m;

                              # Mod ``polym'' and mod m, so that the equation is formulated in
                              # Z_m[t,t^(-1)]/(polym) .
                              # The number m is a prime (it's not clear if this works for non-prime).

        TempList:=PolynomialTools[CoefficientList](TempPoly,t);
                              # For each (x,y,z), this is the list of coefficients of t^k.

        for i from 1 to nops(TempList) do
            E[x,y,z,i-1]:=TempList[i];
            EQ:=[op(EQ),E[x,y,z,i-1]=0];
        od;

     od:
  od:
od:
#7/1/04
#will add Reid. type I move to the list of equations
for i from 0 to (quanod-1) do
 for j from 0 to (deg-1) do
   EQ:=[op(EQ), f[i,i,j]=0];
 od;
od;
     
vars:=[seq(seq(seq(f[i,j,k],i=0..quanod-1),j=0..quanod-1),k=0..deg-1)];
A:=linalg[genmatrix](EQ,vars);
b:=vector(linalg[rowdim](A),0);
Sol:=Linsolve(A,b,'r',ss) mod m;

 # At this point the solution is in a vector form, in the order of
 # (f[0,0,0],f[1,0,0],...]).
 # From here the free variables are renamed so that the subscripts starts with 1
 # and put the solutions back into polynomial form.

Sol_list:=convert(Sol,list);
LL:=indets(Sol_list);
LL:=convert(LL,list);

x:='x'; # Unassign x. (But ``unassign(x)'' didn't seem to work.)
temp:=1; # The first subscript for the new set of free variables x_1, x_2, ....   
GG:=[];

for i from 1 to nops(LL) do
 ttemp:=op(LL[i]); # ttemp is the original subscript of the free variables in ss.
 GG:=[op(GG),ss[ttemp]=x[temp]*t^(iquo(ttemp,quanod^2))];
    # The first block matrix (whose size is quanod^2 where quanod is the order of X)
    # is for f[i,j,0], and so on, so iquo(ttemp,quanod^2) is the degree of the free variable.
 temp:=temp+1;
od;

Sol_list:=subs(GG,Sol_list); # Puts new free variables x in polynomial forms back into Sol_list.
temp:=1;
for k from 0 to deg-1 do
 for j from 0 to quanod-1 do
   for i from 0 to quanod-1 do
     f[i,j,k]:=collect(Sol_list[temp],t): # Puts the solutions back into f in polynomial form.
     temp:=temp+1:
od:od:od:


testsol:=map(`mod`,evalm(A &* Sol - b),m);
testsol:=convert(testsol,set);


if testsol={0} then
  return(f);
else
  printf("%s","ERROR: co2TwistedSol solutions are not valid");
  return;
fi;
end:
 

The procedure to calculate the value of the 2-cocycle twisted invariant. 

> Invar2TwistedDLL:=proc(Quandle,Knot,polym,m::posint)
local i,j,k,x,y,z,quandleorder,F,f,tinv,brind,
     SSTcontri,SST,jj3,jj5,jj6,jj8,s,num,
     Color,ColDiffMatch0,ColorDiff0,Ginv,
     indx,ttemp,deg,SST2,numVcolors,QuandleC,KnotC,VALIDCOLORS;
SST2:=0;
#SST:=[];

f:=[];
quandleorder:=quandlesize(Quandle);
tinv:=tinverse(polym,m);   
Ginv:=makeinv(Quandle);
brind:=max(op(map(x->abs(x),Knot)))+1;
deg:=degree(polym,t);
    #For the optional 5th argument. The user sends the twisted cocycle solution as input.
if nargs<5 then
 f:=co2TwistedSol(Quandle,polym,m);
else
 f:=args[5];
fi;

for i from 0 to quandleorder-1 do
 for j from 0 to quandleorder-1 do
    F[i,j]:=sum(f[i,j,k], k=0..deg-1);
#Removed the *t^k from the def of F[i,j] since the t terms are
#introduced in the solutions by the procedure co2TwistedSol()

od:od:
#########################################
###############9_30_05
numVcolors:=0;


QuandleC:=Array(op(Quandle),datatype=integer[2],order=C_order):
#print("finish QuandleC");

KnotC:=Array(0..(nops(Knot)-1),Knot,datatype=integer[2],order=C_order):
#print("finish Knotc");

VALIDCOLORS:=Array(0..10000000,datatype=integer[2],order=C_order):
#print("finish VALIDCOLORS");

numVcolors:=validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

#print("numVcolors is ",numVcolors);
#validColorVectors(QuandleC,quandleorder,KnotC,brind,nops(Knot),VALIDCOLORS):

Color[0]:=numVcolors;
#Color[0]:=VALIDCOLORS[0];
############debug
#print("finish colors"):

for x from 1 to numVcolors do
 for y from 1 to nops(Knot)+1 do
   Color[x][y]:=array(1..brind,[]):
 od:
od:


#print("There were ",numVcolors," valid colorings");

Color:=cvrtarray(brind,nops(Knot),VALIDCOLORS,numVcolors);

#######################################

#ADD
for i from 1 to numVcolors do
SSTcontri:=0;
    for s from 1 to nops(Knot) do
      if  Knot[s] > 0 then
       
          ttemp:=tinv^abs((-abs(Knot[s])+1))*F[Color[i][s][abs(Knot[s])], Color[i][s][abs(Knot[s])+1] ];

          SSTcontri:=SSTcontri + Rem(ttemp,polym,t) mod m:

     else       

          ttemp:=tinv^(abs(-abs(Knot[s])+1))*F[Color[i][s+1][abs(Knot[s])], Color[i][s+1][abs(Knot[s])+1] ];     
          SSTcontri:=SSTcontri+Rem(-ttemp,polym,t) mod m:
      fi:
    od:                                         # Closing the state-sum term, for s.
    
    #SST:=[op(SST),Rem(SSTcontri,polym,t) mod m];
    SST2:=SST2+u^(Rem(SSTcontri,polym,t) mod m);
od;  #end i loop through valid colorings
   #      print("SST2 is",SST2);                                
return(SST2,Color,F,numVcolors);
end:
 

> Calc2twistinvars:=proc(filePATH,p,polym,qord,qnum,numberofknots)
#,{cpath:=false},{solpath:=false})
local i,HH,tmpfilename1,tmpfilename2,tmpfilename3,tmpf1,tmpf2,tmpf3,INVARS,
     Quandle,quandleorder,tmpfilename4,tmpfilename5,tmpf4,tmpf5,brind,
     tmpColorstr,x,y,z,tmpco2str,tmpco3str,bstrand,crossvec,colnum,JJ,writesolpath,cpath,solpath;




  cpath:=args[7];
  solpath:=args[8];

Quandle:=cat(Q,qord,_,qnum);
quandleorder:=quandlesize(Quandle);
 HH:=ssystem(date):HH[2];

tmpfilename1:=cat(filePATH,"Z_",p,"mod",convert(polym,string),"twistedQ",qord,"_",qnum,"_2cocinv.inv");


#if cpath<>false then
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);
#fi;
if solpath<> false then
tmpfilename4:=cat(solpath,"coc2SolnsZ_",p,"twistedQ",qord,"_",qnum,".sol");

tmpf4:=fopen(tmpfilename4,WRITE);

printf("%s\n",tmpfilename4);

fprintf(tmpf4,"#Twisted Quandle 2-cocycle solutions for the Quandle Q%d_%d and \n#coefficient group Z_%d[t,t^(-1)]/(%s)\n\n",qord,qnum,p,convert(polym,string));

 fprintf(tmpf4,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);

fpQuan(tmpf4,Quandle,quandleorder);


fprintf(tmpf4,"#Generated %s\n",HH[2]);

writesolpath:=true;
fi;



tmpf1:=fopen(tmpfilename1,WRITE);

# tmpf3:=fopen(tmpfilename3,WRITE);

printf("%s\n",tmpfilename1);

#printf("%s\n",tmpfilename3);



fprintf(tmpf1,"#Twisted Quandle 2-cocycle invariants for the Quandle Q%d_%d and \n#coefficient group Z_%d[t,t^(-1)]/(%s)\n\n",qord,qnum,p,convert(polym,string));

fprintf(tmpf1,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);

fpQuan(tmpf1,Quandle,quandleorder);


# fprintf(tmpf3,"The valid color vectors for the braids colored with the quandle Q%d_%d\n\n",qord,qnum);
#fprintf(tmpf3,"The cayley table for the quandle Q%d_%d\n",qord,qnum);
#fpQuan(tmpf3,Quandle,quandleorder);






fprintf(tmpf1,"#Generated %s\n",HH[2]);

#fprintf(tmpf3,"#Generated %s\n",HH[2]);


for i from 0 to numberofknots do

JJ:=ssystem(date):


INVARS:=Invar2TwistedDLL(Quandle,Knot[i,2],polym,p):
fprintf(tmpf1,"%s\t%s\t \n%s\n\n",convert(Knot[i,1],string),convert(Knot[i,2],string),convert(INVARS[1],string));

if cpath<> false then

tmpfilename3:=cat(cpath,"ColorsQ",qord,"_",qnum);

tmpfilename3:=cat(tmpfilename3,"K",Knot[i,1],".clr");
tmpf3:=fopen(tmpfilename3,WRITE);
#printf("%s\n",tmpfilename3);

fprintf(tmpf3,"#The valid color vectors for the braids colored with the quandle Q%d_%d \n#for the knot %s with braid %s\n\n",qord,qnum,convert(Knot[i,1],string),convert(Knot[i,2],string));
fprintf(tmpf3,"#The cayley table for the quandle Q%d_%d\n",qord,qnum);
fpQuan(tmpf3,Quandle,quandleorder);
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
tmpColorstr:=cat(Col,convert(Knot[i,1],string),_,Q,qord,_,qnum);
fprintf(tmpf3,"%s[0]:=%d;\n",tmpColorstr,INVARS[4]);
brind:=max(op(map(x->abs(x),Knot[i,2])))+1;
for colnum from 1 to INVARS[4] do
  for crossvec from 1 to nops(Knot[i,2])+1 do
    for bstrand from 1 to brind do
      fprintf(tmpf3,"%s[%d][%d][%d]:=%d;\n",tmpColorstr,colnum,crossvec,
                                           bstrand,INVARS[2][colnum][crossvec][bstrand]);
od:od:od:
JJ:=ssystem(date):
fprintf(tmpf3,"#Generated %s\n",JJ[2]);
 fprintf(tmpf3,"\n\n\n");
fclose(tmpf3);
#tmpfilename3:=cat(cpath,Colors,Q,qord,_,qnum);

fi;

if writesolpath<>false then
tmpco2str:=cat(co2SolUntwist,Q,qord,_,qnum,Z_,p);

for x from 0 to quandleorder-1 do
   for y from 0 to quandleorder-1 do
       fprintf(tmpf4,"%s[%d,%d]:=%s;\n",tmpco2str,x,y,convert(INVARS[3][x,y],string));
od:od:
fprintf(tmpf4,"\n\n\n");


fclose(tmpf4);

writesolpath:=false;

fi;


od:
print("finished all knots");



HH:=ssystem(date):HH[2];
fprintf(tmpf1,"#Generated %s\n",HH[2]);

fclose(tmpf1);

# fclose(tmpf3);


end:
 

Local procedure for ClacTwistDLL procedure 

> tinverse:=proc(polym,m)
local i,temp,L,deg,tinv,Cof,lowdeg,coffinv,tmppgcd;
option remember;
if type(polym,polynom) then  
  deg:=degree(polym,t);
else
  printf("%s\n",ERROR);
  return;
fi;
Cof:=PolynomialTools[CoefficientList](polym,t);
temp:=1;
   while Cof[temp]=0 do
     temp:=temp+1;
   od;
if gcd(Cof[temp],m)=1 and gcd(Cof[nops(Cof)],m)=1 then
 continue;
else
 printf("%s","ERROR, Not a finite ring.");
 return;
fi;
lowdeg:=0; # lowdeg is the lowest degree of polym.
while Cof[lowdeg+1]=0 do
lowdeg:=lowdeg+1;
od;
tinv:=0;
for i from (lowdeg+2) to nops(Cof) do
 tinv:=tinv-Cof[i]*t^(i-(lowdeg+2));
od;
# For example, if t^2+2*t+3=polym, then first do 3=-2*t-t^2 and
# compute 3*t^(-1)=-2-t. Then the next step cancels 3.   

tmppgcd:=igcdex(Cof[lowdeg+1],m,'s','r');
# This is 1 iff the coeff of the lowest dgree is invertible (and it should be).

if tmppgcd<>1 then
  printf("%s %d %s %d","ERROR: Inverse dne for ",Cof[lowdeg+1],"mod",m);
else
  coffinv:=s mod m; # This is he inverse of the coeff of the lowest dgree.
fi;
tinv:=tinv*coffinv;
tinv:=Rem(tinv,polym,t) mod m;
return(tinv);
end:
 

>
 

The following procedures are included from the other packages. These were not modified. 

> quandlesize:=proc(Quandle)
#Procedure to determine how many elements are in the quandle
#Input: A zero indexed two dimensional array representing the
#       the multiplication table for the quandle.
#Output: A positive integer. Representing the number of elements in the set.
local T;
option remember; #create table to avoid multiple function calls
T:=convert(Quandle,matrix);
if linalg[rowdim](T)<>linalg[coldim](T) then
  prinf("%s %s %s\n",ERROR, quandle, dimensions);
else return(linalg[rowdim](T));
fi;
end:
 

> makeinv:=proc(Quandle)
#Procedure that will create a zero indexed two dimensional array
#representing the multiplication table for the second property of a quandle.
# ie. There exists a unique c such that a=c*b. Will be used to calculate the
#     colors for a negative crossing.
#Input: A zero indexed 2-dim array representing the multiplication
#       table for the quandle.
#Output:A zero indexed 2-dim array.
local i,j,temp,L,quandleorder;
option remember;
quandleorder:=quandlesize(Quandle);
L:=array(0..quandleorder-1,0..quandleorder-1,[]):
for i from 0 to quandleorder-1 do
 for j from 0 to quandleorder-1 do
   temp:=Quandle[i,j];
   L[j,temp]:=i;
 od;
od;
return(L);
end:
 

> co2Solution:=proc(Quandle,m::posint)
#Procedure to calculate the solutions to the 2-cocycle conditions
#Input: (1) a Quandle.
#       (2) the modulus.
#Output: Solutions
local x,y,z,i,EQ,f,vars,A,quanod,E,Sol,Sol_list,j,temp,
     testsol;
option remember;
print(co2solproccall);
quanod:=quandlesize(Quandle);
f:=array(0..(quanod-1),0..(quanod-1));
EQ:=[];                             #defining the 2-cocycle condition
for x from 0 to (quanod-1) do
  for y from 0 to (quanod-1) do
     for z from 0 to (quanod-1) do
       E[x,y,z]:= f[x,y]+f[Quandle[x,y], z]-f[x,z]-f[Quandle[x,z],Quandle[y,z]]:
       EQ:=[op(EQ),E[x,y,z]=0]:
od: od: od:
for i from 0 to (quanod-1) do
EQ:=[op(EQ),f[i,i]=0]:
od:
vars:=[seq(seq(f[i,j],j=0..(quanod-1)),i=0..(quanod-1))];             
A:=linalg[genmatrix](EQ,vars,b):
Sol:=Linsolve(A,b,'r',t) mod m:
Sol_list:=convert(Sol,list):
temp:=1;
     #create the array of solutions
for i from 0 to (quanod-1) do
 for j from 0 to (quanod-1) do
          f[i,j]:=Sol_list[temp]:
          temp:=temp+1;
od:od:

testsol:=[];
for i from 1 to nops(EQ) do
 testsol:=[op(testsol),map(x->x mod m,eval(EQ[i]))];
od;
testsol:=convert(testsol,set);
#test to see if the solutions satisfy the equations
if testsol={0=0} then return(f);
else printf("%s %s %s\n",co2Solution,solutions, invalid);
fi;


end:
 

> mirrorKnot:=proc(L)
local i,S,braidIndex;
braidIndex:=max(op(map(x->abs(x),L)))+1;
S:=[];
for i from 1 to nops(L) do
  if L[i]<0 then
    S:=[op(S),braidIndex+L[i]];
  else
    S:=[op(S),(-1)*(braidIndex-L[i])];
  fi;
od;
return(S);
end:
 

> barKnot:=proc(L)
local i,S;
S:=[];
for i from 1 to nops(L) do
  S:=[L[i],op(S)];
od;
return(S);
end:
 

> connSumKnots:=proc(Knots_list)
#Procedure to form the braid word of a connected sum of knots.
#Input: A list.
#       [1] A list of lists. The elements of the list are lists
#           representing the braid words of the knots
#            in the order that they are to be connected.
#           ex. [[1,1,1],[1,1,1],[1,-2,1,-2]]
#Output: A list, [L].
#       [L] The new braid word.
# ex. of a function call
# ConnSumKnots([[1,1,1],[1,1,1],[1,-2,1,-2]]);

local newIndex, i,k, j, NewKnot,Braid_Index_list;
NewKnot:=[];
Braid_Index_list:[];
newIndex:=0;
for k from 1 to nops(Knots_list) do
 Braid_Index_list[k]:=max(op(map(x->abs(x),Knots_list[k])))+1;
od;
for i from 1 to nops(Knots_list) do
  for j from 1 to nops(Knots_list[i]) do
     if Knots_list[i][j]<0 then      
        NewKnot:=[op(NewKnot),Knots_list[i][j]-newIndex];
     else
        NewKnot:=[op(NewKnot),Knots_list[i][j]+newIndex];
     fi;
  od;
  newIndex:=newIndex+Braid_Index_list[i];
  if i<> nops(Knots_list) then
     NewKnot:=[op(NewKnot),newIndex];
  fi;
od;
return(NewKnot);
end:
 

> co3Solution:=proc(Quandle,m::posint)
#Procedure to calculate the solutions to the 3-cocycle conditions
#Input: (1) a Quandle.
#       (2) the modulus.
#Output: Solutions
local x,y,z,i,w,k,EQ,h,vars,A,quanod,E,Sol,Sol_list,j,temp,
testsol;
option remember;
print(co3solproccall);
quanod:=quandlesize(Quandle);
h:=array(0..(quanod-1),0..(quanod-1),0..(quanod-1));
EQ:=[];                             #defining the 3-cocycle condition
for x from 0 to (quanod-1) do
  for y from 0 to (quanod-1) do
     for z from 0 to (quanod-1) do
       for w from 0 to (quanod-1) do
       E[x,y,z,w]:=  h[x,z,w] - h[x,y,w]  + h[x,y,z]  
- h[Quandle[x,y],z,w] + h[Quandle[x,z],Quandle[y,z],w]- h[Quandle[x,w],Quandle[y,w],Quandle[z,w]]:
EQ:=[op(EQ),E[x,y,z,w]=0]:
od: od: od:od:
for i from 0 to (quanod-1) do
 for j from 0 to (quanod-1) do
   EQ:=[op(EQ),h[i,j,j]=0]:
od:od:
vars:=[seq(seq(seq(h[i,j,k],k=0..(quanod-1)),j=0..(quanod-1)),i=0..(quanod-1))];             
A:=linalg[genmatrix](EQ,vars,b):
Sol:=Linsolve(A,b,'r',t) mod m:
Sol_list:=convert(Sol,list):
temp:=1;
for i from 0 to (quanod-1) do
 for j from 0 to (quanod-1) do
   for k from 0 to (quanod-1) do
          h[i,j,k]:=Sol_list[temp]:
          temp:=temp+1;
od:od:od:
testsol:=[];
for i from 1 to nops(EQ) do
 testsol:=[op(testsol),map(x->x mod m,eval(EQ[i]))];
od;
testsol:=convert(testsol,set);

if testsol={0=0} then return(h);
else printf("%s %s %s\n",co3Solution,solutions, invalid);
fi;
end:
 

> Mochizuki3coc:=proc(Xpolym,Apolym,p,m1,m2,a3)
#Input: (1) The polynomial in t from the Alexander quandle
#           that will be used to color the braid( Z_p[t^-1,t]/(Xpolym)).
#       (2) The polynomial in t from the Alexander quandle
#           that is used for the coefficients (Z_p[t^-1,t]/(Apolym)).
#       (3) The prime modulus from the above Alexander quandles.
#       (4) m1 is the exponent from Mochizuki's formula for the first term
#           f(x1,x2,x3)=(x1-x2)^(p^m1)(x2-x3)^(p^m2)x3^a3.
#       (5) m2 is the exponent from the second term in Mochizuki formula above.
#       (6) a3 is the third term in the formula. a3 must either be zero or a power
#           of p such that Apolym divides 1-t^(p^m1+p^m2+a3).
#Output: A table that has the values for the 3-cocycles.
#Example Input: Mochizuki3coc(t^2-t+1,t^2-t+1,2,1,1,0);



local i,j,k,f, qsize, Quandle,Xelements,temp, tempcheck;
option remember;

Xelements:=[];
Xelements:=rres(Xpolym,p):


#print("Mochizuki called");
#print(Xelements);
qsize:=nops(Xelements);

# In the following statement Xpolym is used. This is the polynomial
# from the Alexander quandle that is used to color the braid.
# The paper by Kheira says that we should use the polynomial from the Alexander quandle
# that is used for the coefficients in the Divides test

tempcheck:=Divide(1-t^(p^m1+p^m2+a3),Apolym) mod p;
#print("tempcheck is ",1-t^(p^m1+p^m2+a3),Xpolym,tempcheck);
if a3=0 or tempcheck then
 continue;
else
 print("Mochizuki conditions not satisfied");
 return false;
fi;
f:=array(0..qsize-1,0..qsize-1,0..qsize-1);
for i from 1 to qsize do
 for j from 1 to qsize do
  for k from 1 to qsize do
temp:=(Xelements[i]-Xelements[j])^(p^m1)*(Xelements[j]-Xelements[k])^(p^m2)*Xelements[k]^a3;

# a[3] is zero or p^m3
#This procedure does not currently check to see if a[3] is prime power.
#DEBUG
#print("temp ploy is ",temp);   
#END DEBUG
f[i-1,j-1,k-1]:=Rem(temp,Apolym,t) mod p;
#DEBUG
#print("temp ploy reduced in A is ",f[i-1,j-1,k-1]);
#END DEBUG
od:od:
od:

return(f);
end:  
 

> cocycle3check:=proc(cocy,Xpolym,Apolym,p)
#Input: (1) A table that contains the values for the 3-cocycles that is generated
#           from the procedure Mochizuki3coc().
#       (2) The polynomial in t from the Alexander quandle
#           that will be used to color the braid( Z_p[t^-1,t]/(Xpolym)).
#       (3) The polynomial in t from the Alexander quandle
#           that is used for the coefficients (Z_p[t^-1,t]/(Apolym)).
#       (4) The prime modulus from the above Alexander quandles.
#Output: A true or false value. This procedure will plug the values from the table cocy
#        into the 3-cocycle condition to make sure it is a valid 3-cocycle.
#        Note: This only tests the Reidmeister type II and III moves.
#Example Input: cocycle3check(Mochizuki3coc(t^2-t+1,t^2-t+1,2,1,1,0),t^2-t+1,t^2-t+1,2);

local i, j, k,x,y,z,w,temp,rrespol,quanod,Quandle;

option remember;
rrespol:=rres(Xpolym,p);
#print(rrespol);
Quandle:=AlexQuandle(Xpolym,p);

quanod:=nops(rrespol);
#print(convert(Quandle,matrix));
#print(quanod);
for i from 0 to (quanod-1) do
for j from 0 to (quanod-1) do
 if cocy[i,j,j]<>0 then
   print("f[",i,j,j,"]=",cocy[i,j,j]);
   return false;
 fi;
od;od;

# print("finished rII");
for x from 0 to (quanod-1) do
  for y from 0 to (quanod-1) do
     for z from 0 to (quanod-1) do
       for w from 0 to (quanod-1) do
       temp:= cocy[x,z,w] - cocy[x,y,w]  + cocy[x,y,z]  
- cocy[Quandle[x,y],z,w] + cocy[Quandle[x,z],Quandle[y,z],w]- cocy[Quandle[x,w],Quandle[y,w],Quandle[z,w]];


#print(temp);
       if Rem(temp,Apolym,t) mod p<>0 then
          print("temp from ReidIII is ",temp,"xyzw is",x,y,z,w);
          return false;
       fi;
od;od;od;od;

return true;
end:
 

> Xi:=proc(n)
#input: (1)A positive integer n.
#output: A polynomial in t. Sum((-t)^i,i = 0 .. n-1).
#        Xi(0):=0 by definition.
#Example input: Xi(3);
#Example output: t^2-t+1

if n=0 then
 return 0;
else
return(sum((-t)^i,i=0..n-1));
fi;
end:
 

> Mochizuki2coc:=proc(Xpolym,Apolym,p,m1,a2)
#Input: (1) The polynomial in t from the Alexander quandle
#           that will be used to color the braid( Z_p[t^-1,t]/(Xpolym)).
#       (2) The polynomial in t from the Alexander quandle
#           that is used for the coefficients (Z_p[t^-1,t]/(Apolym)).
#       (3) The prime modulus from the above Alexander quandles.
#       (4) m1 is the exponent from Mochizuki's formula for the first term
#           f(x1,x2,x3)=(x1-x2)^(p^m1)x2^a2.
#       (5) a2 is the second term in the formula. a2 must either be zero or a power
#           of p such that Apolym divides 1-t^(p^m1+a2).
#Output: A table that has the values for the 2-cocycles.
#Example Input: Mochizuki3coc(t^2-t+1,t^2-t+1,2,1,0);


local i,j,f, qsize, Quandle,Xelements,temp,tempcheck;
option remember;
Xelements:=[];
Xelements:=rres(Xpolym,p):
qsize:=nops(Xelements);

tempcheck:=Divide(1-t^(p^m1+a2),Xpolym) mod p;
#print("tempcheck is ",1-t^(p^m1+a2),Xpolym,tempcheck);
if a2=0 or tempcheck then
 continue;
else
 print("Mochizuki conditions not satisfied");
 return false;
fi;
#print(Xelements);


f:=array(0..qsize-1,0..qsize-1);
for i from 1 to qsize do
 for j from 1 to qsize do

temp:=(Xelements[i]-Xelements[j])^(p^m1)*Xelements[j]^a2;
#print(temp);   
f[i-1,j-1]:=Rem(temp,Apolym,t) mod p;
od:od:
return(f);
end:   
 

> cocycle2check:=proc(cocy,Xpolym,Apolym,p)
#Input: (1) A table that contains the values for the 2-cocycles that is generated
#           from the procedure Mochizuki2coc().
#       (2) The polynomial in t from the Alexander quandle
#           that will be used to color the braid( Z_p[t^-1,t]/(Xpolym)).
#       (3) The polynomial in t from the Alexander quandle
#           that is used for the coefficients (Z_p[t^-1,t]/(Apolym)).
#       (4) The prime modulus from the above Alexander quandles.
#Output: A true or false value. This procedure will plug the values from the table cocy
#        into the 2-cocycle condition to make sure it is a valid 2-cocycle.
#        Note: This only tests the Reidmeister type II and III moves.
#Example Input: cocycle2check(Mochizuki2coc(t^2-t+1,t^2-t+1,2,1,1,0),t^2-t+1,t^2-t+1,2);


local i, j, k,x,y,z,w,temp,rrespol,quanod,Quandle;

option remember;
rrespol:=rres(Xpolym,p);
#print(rrespol);
Quandle:=AlexQuandle(Xpolym,p);

quanod:=nops(rrespol);
#print(convert(Quandle,matrix));
#print(quanod);
for i from 0 to (quanod-1) do
  if cocy[i,i]<>0 then
   print("f[",i,i,"]=",cocy[i,i]);
   return false;
 fi;
od;

# print("finished rII");

# E[x,y,z]:= f[x,y]+f[Quandle[x,y], z]-f[x,z]-f[Quandle[x,z],Quandle[y,z]]:
for x from 0 to (quanod-1) do
  for y from 0 to (quanod-1) do
     for z from 0 to (quanod-1) do
       temp:= cocy[x,y]+cocy[Quandle[x,y], z]-cocy[x,z]-cocy[Quandle[x,z],Quandle[y,z]];


#print(temp);
       if Rem(temp,Apolym,t) mod p<>0 then
          print("temp from ReidIII is ",temp,"xyz is",x,y,z);
          return false;
       fi;
od;od;od;

return true;
end:
 

> MochizukiDihedral3coc:=proc(p)
local i,j,k,f, qsize, Quandle,Xelements,temp, tempcheck;
option remember;

f:=array(0..(p-1),0..(p-1),0..(p-1));
for i from 0 to (p-1) do
 for j from 0 to (p-1) do
  for k from 0 to (p-1) do
f[i,j,k]:=((i-j)*((2*k^p-j^p)-(2*k-j)^p)/p) mod p;

od:od:
od:

return(f);
end:   
 

> #save validColorVectors,cvrtarray,Invar2_3UntwistedDLL,CalcUntwistinvars, fpQuan, #Invar2UntwistedDLL,Calc2Untwistinvars,Invar3UntwistedDLL, #Calc3Untwistinvars,Invar2_3MochizukiDLL,CalcMochinvars,Invar2MochizukiDLL,Calc2Mochinvars, #Invar3MochizukiDLL, Calc3Mochinvars, ismult, #CalcDihinvars,co2TwistedSol,Invar2TwistedDLL,Calc2twistinvars,tinverse, quandlesize, makeinv, #co2Solution, mirrorKnot, barKnot, connSumKnots, co3Solution, Mochizuki3coc, cocycle3check, Xi, #Mochizuki2coc, cocycle2check, MochizukiDihedral3coc, "/media/sda1/WorksheetIVtnfr/quancocDLLpkgmaple8.m";