braid.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-- This code is "GPL"ed.
--
-- Braid group. from module BRAID.msi
-- 1998.7.2 K.Kodama
-- FROM StringsK IMPORT ReadLineF,splitStr,Str2Int,Int2Str,EolCh;
class BRAID
class BRAID is
-- const BRAIDmaxSLen:INT:=400; -- for knotXW
include WORD create->word_create, clone->word_clone, str->word_str,
printD->word_printD, check->word_check,
reverse->word_reverse, inverse->word_inverse,
append->word_append,insert->word_insert;
attr index:INT;
create:SAME is
res::=new; res.index:=0; res.w:=#; return res;
end;
create(i:INT):SAME is
res::=new; res.index:=i; res.w:=#; return res;
end;
create(s:STR):SAME is
-- convert STR to BRAID.
-- format: " 4 : 2 -1 3 -2 -3 2 1 endcode"
-- index^ ^^^^^^^^^^^^^^^^braid word
res:SAME:=#;
sc:STR_CURSOR:=#(s);
res.index:=sc.get_int;
if res.index<0 then res:=#; return res; end;
str:STR:=STRINGSK::splitStr(inout sc);
if str/=":" then res:=#; return res; end;
s:=sc.get_rest_str;
i::=s.search("endcode");
if i=-1 then res:=#; return res; end;
s:=s.left(i);
res.w:=word_create(s).w;
loop i:=res.w.ind!;
if res[i].abs>=res.index then res:=#; return res; end;
end;
return res;
end;
clone:SAME is
res:SAME:=word_clone; res.index:=index; return res;
end;
str:STR is
-- convert BRAID to STR
s:STR:=index.str+" : "+word_str+" endcode ";
return s;
end;
printD is
-- print for debug/check
#OUT+"braid "+str+"\n";
end;
check:BOOL is
if ~word_check then return false;
elsif index<0 then return false;
end;
loop e::=w.elt!; if e.abs>=index then return false; end; end;
return true;
end;
trackString(s:INT):INT is
aw:INT;
loop i::=0.upto!(w.size-1);
aw:=w[i].abs;
if aw=s then s:=s+1; elsif (aw+1)=s then s:=s-1; else ; end;
end;
return s;
end;
is_PureBraid:BOOL is
loop i::=1.upto!(index-1);
if i/=trackString(i) then return false; end;
end;
return true;
end;
maxIndexInWord:INT is
-- m= max index of generator +1. i.e. word \in B_m
return maxGen+1;
end;
reverse:SAME is
-- reverse order of elements
b:SAME:=word_reverse; b.index:=index; return b;
end;
inverse:SAME is
-- inverse as group
res:SAME:=word_inverse; res.index:=index; return res;
end;
append(b:SAME) is
index:=index.max(b.index); w:=w.append(b.w);
end;
append(b:SAME):SAME is
res:SAME:=clone; res.append(b); return res;
end;
append(s:INT) is
index:=index.max(s.abs+1);
--w:=w.resize(w.size+1); w[w.size-1]:=s;
w:=w.append(|s|);
end;
append(s:INT):SAME is
res:SAME:=clone; res.append(s); return res;
end;
insert(pos:INT,b:SAME):SAME is
res:SAME:=word_insert(pos,b); res.index:=index.max(b.index);
return res;
end;
insert(pos:INT, s:INT):SAME is
res:SAME:=word_insert(pos,s); res.index:=index.max(s.abs+1);
return res;
end;
insert(pos:INT, s:INT) is
res::=insert(pos,s);
index:=res.index;
w:=res.w;
end;
end; -- class BRAID