word.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
-- This code is "GPL"ed. 


class WORD

class WORD is -- group word attr w:ARRAY{INT}; create:SAME is res::=new; res.w:=#; return res; end; create(s:STR):SAME is -- convert STR to WORD. -- format: "2 -1 3 -2 -3 2 1" -- ^^^^^^^^^^^^^^^^word g:INT; s1:STR; res:SAME:=#; sc:STR_CURSOR:=#(s); loop if sc.is_done then return res; end; s1:=STRINGSK::splitStr(inout sc); g:=#(s1); if (1<=g.abs) then res.append(g); elsif (g=0) then ; end; end; return res; end; aget(i:INT):INT is return w[i]; end; aset(i:INT, g:INT) is w[i]:=g; end; clone:SAME is res:SAME:=#; res.w:=w.copy; return res; end; size:INT is return w.size; end; length:INT is return w.size; end; check:BOOL is if void(self) then return false; elsif void(w) then return false; end; return true; end; maxGen:INT is -- m= max index of generator m::=0; loop s::=w.elt!; m:=m.max(s.abs); end; return m; end; reverse:SAME is -- reverse order of elements b:SAME:=#; b.w:=w.reverse; return b; end; inverse:SAME is -- inverse as group res:SAME:=reverse; neg:ROUT{INT}:INT:=bind(_.negate); res.w.map(neg); return res; end; append(b:SAME) is w:=w.append(b.w); end; append(b:SAME):SAME is res:SAME:=clone; res.append(b); return res; end; append(s:INT) is 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:=#; if 0<pos then res.w:=w.subarr(0,pos); end; res.w:=res.w.append(b.w); if pos<w.size then res.w:=res.w.append(w.subarr(pos,w.size-pos)); end; return res; end; insert(pos:INT, s:INT):SAME is res:SAME:=#; if 0<pos then res.w:=w.subarr(0,pos); end; res.w:=res.w.resize(pos+1); res.w[pos]:=s; if pos<w.size then res.w:=res.w.append(w.subarr(pos,w.size-pos)); end; return res; end; insert(pos:INT, s:INT) is res::=insert(pos,s); w:=res.w; end; delete(pos:INT) is if pos<(w.size-1) then loop i::=pos.upto!(w.size-2); w[i]:=w[i+1]; end; end; if pos<w.size then w:=w.resize(w.size-1); end; end; delete(pos:INT):SAME is res:SAME:=clone; res.delete(pos); return res; end; times(s:INT):SAME is return append(s); end; times(b:SAME):SAME is return append(b); end; div(b:SAME):SAME is return times(b.inverse); end; div(s:INT):SAME is return times(-s); end; cancel:SAME is res:SAME:=clone; loop i::=(size-2).downto!(0); if (i<(res.w.size-1)) and(res.w[i]=-res.w[i+1]) then res.delete(i+1); res.delete(i); elsif res.w[i]=0 then res.delete(i); end; end; return res; end; ---------------- str and print out ----------------- printD is -- print for debug/check #OUT+"word "+str+"\n"; end; printWordLog is #LOGOUT+" "+wstr("x_{","}")+"\n"; end; str:STR is -- convert WORD to STR as a sequence of number -- "\n" can be included. -- format: "1 2 3 -2 -1 -2 " s::=""; loop i::=w.ind!; s:=s+w[i].str+" "; if (i+1).mod(16)=0 then s:=s+"\n"; end; end; return s; end; wstr:STR is -- convert WORD to STR in TeX like format -- as "x_{1} x_{2} x_{1}^{-1} x_{2}^{-1} " return wstr("x_{","}"); end; wstr(s1,s2:STR):STR is -- convert WORD to STR -- s1(s2 resp.) is pre(post resp.) str for generator name "g". s::=""; loop i::=w.elt!; if i/=0 then s:=s+gstr(i,0,s1,s2)+" "; end; end; return s; end; gstr(g:INT,b:INT, s1,s2:STR):STR is -- b: base for coverings -- s1(s2 resp.) is pre(post resp.) str for generator name "g". s::=s1+g.abs.str; if b>0 then s:=s+"."+b.str; end; s:=s+s2; if g<0 then s:=s+"^{-1}"; end; return s; end; gstr(g:INT, b:INT):STR is -- b: base for coverings return gstr(g,b,"x_{", "}"); end; end; -- class WORD