set_tcode_alg.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 

class SET_TCODE_ALG

class SET_TCODE_ALG is -- 1989/8 Kouji Kodama -- make TCODE for Theta curve. -------------------set relator fron TCode---------------- shared stp,gen,compo,i:INT; shared cod:VERTEXC; shared TCode:TCODE; shared Knot:KNOT; SetTCode(knot:KNOT,out tcode:TCODE):BOOL is Knot:=knot.clone; TCode:=#; if (setupK and SetTCode0 and SetTCodeC and tgIdent_end and tgIdent_band and tgIdent_trivial and delG and DelBandUCross ) then tcode:=TCode; TCode:=#; Knot:=#; return tcode.check(true); else tcode:=TCode; TCode:=#; Knot:=#; return false; end; end; SetTCode_Theta(knot:KNOT,out tcode:TCODE):BOOL is TCode:=#; Knot:=knot.clone; if (setupK_Theta and SetTCode0 and SetTCodeC and SetTCodeC_Theta_vert --and tgIdent_end and tgIdent_band and tgIdent_trivial and delG and DelBandUCross ) then tcode:=TCode; TCode:=#; Knot:=#; return tcode.check(true); else tcode:=TCode; TCode:=#; Knot:=#; return false; end; end; ------------------------set TCode from knot data ---------------------- setupK:BOOL is -- change Knot near ts/te. if void(Knot) or void(Knot.k) then return false; end; if ~Knot.is_proper then return false; end; if Knot.CrossSet then ; end; loop i::=0.upto!(Knot.length-1); cod:=Knot[i].sep; if VERTEXC::ts.in(cod) then Knot[i].x:=Knot[i+1].x; Knot[i].y:=Knot[i+1].y; elsif VERTEXC::te.in(cod) then Knot[i].x:=Knot[i-1].x; Knot[i].y:=Knot[i-1].y; end; end; return true; end; setupK_Theta:BOOL is -- separate theta graph to 3-strings if void(Knot) or void(Knot.k) then return false; end; if ~Knot.is_proper then return false; end; if Knot.CrossSet then ; end; if ~Knot.is_theta then return false; end; s1::=Knot.bandStart; s2::=Knot.endOfString(s1,1); b1::=Knot.cmpOf(s1); b2::=Knot.cmpOf(s2); Knot[b1].sep:=VERTEXC::normal; Knot[b2].sep:=VERTEXC::normal; k00::=0; k01::=Knot.endOfString(k00,1); kn:KNOT:=#; i:INT:=k00;kn.append(Knot[i].clone); i:=b1; loop kn.append(Knot[i].clone); if i=b2 then break!; elsif i=k01-1 then i:=k00+2; else i:=i+1; end; end; i:=k01;kn.append(Knot[i].clone); i:=k00;kn.append(Knot[i].clone); i:=b2; loop kn.append(Knot[i].clone); if i=b1 then break!; elsif i=k01-1 then i:=k00+2; else i:=i+1; end; end; i:=k01;kn.append(Knot[i].clone); i:=k00;kn.append(Knot[i].clone); i:=s1+1; loop kn.append(Knot[i].clone); if i=s2-1 then break!; else i:=i+1; end; end; i:=k01;kn.append(Knot[i].clone); Knot:=kn; return true; end; SetTCode0:BOOL is tp:INT; tp:=-1; compo:=0; gen:=0; stp:=0; i:=0; loop i:=0.upto!(Knot.length-1); cod:=Knot[i].sep; if (VERTEXC::normal /= cod) then tp:=tp+1; TCode.CodeIn(tp); TCode[tp].sep:=cod; TCode[tp].linkPtr:=i; TCode[tp].companion:=0; if VERTEXC::ks.in(cod) then stp:=tp; compo:=compo+1; gen:=gen+1; elsif VERTEXC::ke.in(cod) then TCode[tp].companion:=stp; TCode[stp].companion:=tp; elsif VERTEXC::ts.in(cod) then compo:=compo+1; gen:=gen+1; end; TCode[tp].gen:=gen; TCode[tp].compo:=compo; if VERTEXC::under.in(cod) then gen:=gen+1; end; end; end; return true; end; SetTCodeCrossSgn(i1,i2,j1,j2:INT):BOOL is -- set sign at the crossing d,dx1,dx2,dy1,dy2:INT; dx1:=Knot[j1+1].x-Knot[j1].x; dy1:=Knot[j1+1].y-Knot[j1].y; dx2:=Knot[j2+1].x-Knot[j2].x; dy2:=Knot[j2+1].y-Knot[j2].y; d:=-(dx1*dy2-dy1*dx2); if (d>0) then TCode[i1].sep:=TCode[i1].sep+VERTEXC::positive; TCode[i2].sep:=TCode[i2].sep+VERTEXC::positive; else TCode[i1].sep:=TCode[i1].sep+VERTEXC::negative; TCode[i2].sep:=TCode[i2].sep+VERTEXC::negative; end; return true; end; SetTCodeBandSgn(i1,i2,j1,j2:INT):BOOL is -- set sign at the band-end d:INT:=Knot.band_attach_sgn(j1); if (d>0) then TCode[i1].sep:=TCode[i1].sep+VERTEXC::positive; TCode[i2].sep:=TCode[i2].sep+VERTEXC::positive; else TCode[i1].sep:=TCode[i1].sep+VERTEXC::negative; TCode[i2].sep:=TCode[i2].sep+VERTEXC::negative; end; return true; end; SetTCodeCmp(i1,inout i2, inout j1, inout j2:INT):BOOL is j1:=TCode[i1].linkPtr; i2:=0; loop i2:=i2+1; j2:=TCode[i2].linkPtr; if (TCode.size-1)<=i2 then break!; elsif ((i1/=i2) and Knot.Match2(j1,j2)) then break!; end; end; TCode[i1].companion:=i2; TCode[i2].companion:=i1; return true; end; SetTCodeC:BOOL is -- set companion and sign at crossings and bands i1,i2,j1,j2:INT; loop i1:=0.upto!(TCode.size-1); if VERTEXC::under.in(TCode[i1].sep) then if ~(SetTCodeCmp(i1,inout i2, inout j1, inout j2) and SetTCodeCrossSgn(i1,i2,j1,j2)) then return false; end; elsif VERTEXC::band.in(TCode[i1].sep) then if ~(SetTCodeCmp(i1,inout i2, inout j1, inout j2) and SetTCodeBandSgn(i1,i2,j1,j2)) then return false; end; end; end; return true; end; SetTCodeC_Theta_vert:BOOL is -- sign of vertex rotation t10::=TCode.compoStart(1); t11::=TCode.endOfString(t10,1); k10::=Knot.compoStart(1); k11::=Knot.endOfString(k10,1); k20::=Knot.compoStart(2); k21::=Knot.endOfString(k20,1); k30::=Knot.compoStart(3); k31::=Knot.endOfString(k30,1); rot,v1x,v2x,v3x,v1y,v2y,v3y:INT; v1x:=Knot[k10+1].x-Knot[k10].x; v1y:=Knot[k10+1].y-Knot[k10].y; v2x:=Knot[k20+1].x-Knot[k20].x; v2y:=Knot[k20+1].y-Knot[k20].y; v3x:=Knot[k30+1].x-Knot[k30].x; v3y:=Knot[k30+1].y-Knot[k30].y; rot:=VEC_ALG::rotation(v1x,v1y,v2x,v2y,v3x,v3y); if rot>0 then Knot[k10].sep:=Knot[k10].sep+VERTEXC::positive; else Knot[k10].sep:=Knot[k10].sep+VERTEXC::negative; end; if rot>0 then TCode[t10].sep:=TCode[t10].sep+VERTEXC::positive; else TCode[t10].sep:=TCode[t10].sep+VERTEXC::negative; end; v1x:=Knot[k11-1].x-Knot[k11].x; v1y:=Knot[k11-1].y-Knot[k11].y; v2x:=Knot[k21-1].x-Knot[k21].x; v2y:=Knot[k21-1].y-Knot[k21].y; v3x:=Knot[k31-1].x-Knot[k31].x; v3y:=Knot[k31-1].y-Knot[k31].y; rot:=VEC_ALG::rotation(v1x,v1y,v2x,v2y,v3x,v3y); if rot>0 then Knot[k11].sep:=Knot[k11].sep+VERTEXC::positive; else Knot[k11].sep:=Knot[k11].sep+VERTEXC::negative; end; if rot>0 then TCode[t11].sep:=TCode[t11].sep+VERTEXC::positive; else TCode[t11].sep:=TCode[t11].sep+VERTEXC::negative; end; return true; end; tgIdent1(inout g1,inout g2:INT) is if g1>g2 then g3::=g1; g1:=g2; g2:=g3; end; loop j::=0.upto!(TCode.length); if TCode[j].gen=g2 then TCode[j].gen:=g1; end; end; end; tgIdent_end:BOOL is -- Gen trimming. -- "identify gen at the beginning and ending of knot code\n". -- Don't use for Theta curve i,j,i1,i2,j1,j2,g1,g2,g3:INT; i:=0; loop if (VERTEXC::endc.in(TCode[i].sep) or VERTEXC::ts.in(TCode[i].sep) ) then break!; end; g1:=TCode[i].gen; i:=TCode[i].companion; g2:=TCode[i].gen; tgIdent1(inout g1,inout g2); i:=i+1; end; return true; end; tgIdent_band:BOOL is -- Gen trimming. -- adjust generator number on band i,j,i1,i2,j1,j2,g1,g2,g3:INT; if TCode.has_band then -- #OUT+"tgIdent: band\n"; -- Saddle-bands induce identification of generators. j1:=TCode.bandStart; loop while!(VERTEXC::ts.in(TCode[j1].sep)); j2:=TCode.endOfString(j1,1); i1:=TCode[j1].companion; -- start i2:=TCode[j2].companion; -- end -- #OUT+"Identify gemerator at the start of band.\n"; g1:=TCode[i1].gen; g2:=TCode[j1].gen; tgIdent1(inout g1,inout g2); -- If band is orientable, -- then identify generator at the end of band. if (VERTEXC::positive.in(TCode[i1].sep) = VERTEXC::positive.in(TCode[i2].sep)) then g1:=TCode[i2].gen; g2:=TCode[j2].gen; tgIdent1(inout g1,inout g2); end; j1:=j2+1; end; -- Saddle-bands induce identification of components. loop i:=0.upto!(TCode.length) ; if VERTEXC::band.in(TCode[i].sep) then g1:=TCode[i].compo; g2:=TCode[TCode[i].companion].compo; if g1>g2 then g3:=g1; g1:=g2; g2:=g3; end; loop j:=0.upto!(TCode.length); if TCode[j].compo=g2 then TCode[j].compo:=g1; end; end; end; end; -- #OUT+"identify gen. at crossings under bands\n"; tst::=TCode.bandStart; loop i:=0.upto!(TCode.length); if (VERTEXC::under.in(TCode[i].sep) and (tst<TCode[i].companion)) then g1:=TCode[i].gen; g2:=TCode[i+1].gen; tgIdent1(inout g1,inout g2); end; end; end; -- on Bands return true; end; tgIdent_trivial:BOOL is -- Gen trimming. -- identify generators along trivial relation: a b a~ a~ or a a a~ b~ i,j,i1,i2,j1,j2,g1,g2,g3:INT; i:=0; loop while!(i<TCode.length) ; if VERTEXC::under.in(TCode[i].sep) then g1:=TCode[i].gen; g2:=TCode[i+1].gen; g3:=TCode[TCode[i].companion].gen; if ((g1=g3) /= (g2=g3)) then tgIdent1(inout g1,inout g2); i:=0; end; end; i:=i+1; end; -- #OUT+"tgIdent:\n"; TCode.printD; return true; end; delG:BOOL is -- adjust generator number i,g,l,gm,lm:INT; flgG::=#ARRAY{BOOL}(TCode.size); flgG.to_val(true); gm:=0; loop i:=0.upto!(TCode.length-1); flgG[TCode[i].gen]:=false; gm:=gm.max(TCode[i].gen); end; g:=gm; loop while!(g>=1); if flgG[g] then gm:=gm-1; loop i:=0.upto!(TCode.length) ; if TCode[i].gen>g then TCode[i].gen:=TCode[i].gen-1; end; end; end; g:=g-1; end; TCode[TCode.length].gen:=gm; flgG:=#(TCode.size); flgG.to_val(true); lm:=0; loop i:=0.upto!(TCode.length-1) ; flgG[TCode[i].compo]:=false; lm:=lm.max(TCode[i].compo); end; l:=lm; loop while!(l>=1); if flgG[l] then lm:=lm-1; loop i:=0.upto!(TCode.length); if TCode[i].compo>l then TCode[i].compo:=TCode[i].compo-1; end; end; end; l:=l-1; end; TCode[TCode.length].compo:=lm; return true; end; DelBandUCross:BOOL is -- delete crossings under band i,i1,j:INT; if ~TCode.has_band then return true; end; tst::=TCode.bandStart; i:=0; loop while!(i<TCode.length); if (VERTEXC::under.in(TCode[i].sep) and (tst < TCode[i].companion)) then j:=TCode[i].companion; if j<i then i1:=i; i:=j; j:=i1; end; TCode.CodeDel(j); loop i1:=0.upto!(TCode.length) ; if j<TCode[i1].companion then TCode[i1].companion:=TCode[i1].companion-1; end; end; if i<tst then tst:=tst-1; end; TCode.CodeDel(i); loop i1:=0.upto!(TCode.length) ; if i<TCode[i1].companion then TCode[i1].companion:=TCode[i1].companion-1; end; end; else i:=i+1; end; end; return true; end; end;