ppoly.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
partial class POLY2
partial class POLY2 is
--Copyright (C) 1985 1996 Kouji KODAMA
--1998/1 LongInt version
-- 1996/10
-- LINUX version
-- Date: 1993- 7-11 0:32:39.
-- PC98 NS/L : i386/ 20MHz
-- rateCl=234;
-- Knot: C12
-- #resolution: PPoly, t= 375 , c= 36 , rs= 531441.0 , rv= 4025386.63
-- Knot: C13
-- #resolution: PPoly, t= 1141 , c= 39 , rs= 1594323.0 , rv= 15355783.15
-- Knot: T27
-- #resolution: PPoly, t= 241 , c= 27 , rs= 317811.0 , rv= 139074.38
-- Knot: T29
-- #resolution: PPoly, t= 654 , c= 29 , rs= 832040.0 , rv= 339907.60
-- Revision 1.2 93/06/22 20:56:36 KDM
-- vpoly changed for module tunnel
-- 1992/11
-- In Jones polynomial and Alexander polynomial,
-- when "number of crossings>33" computation was halted,
-- because it can be overflow.
--
-- Now, I change the condition as follows.
-- Alexander polynomial
-- "In resolution tree, /=smoothing in a pass >33"
-- Jones polynomial
-- "In resolution, (/=smoothing-/=component+1 in a pass)>33"
--
-- Note.
-- 33 means upper limit of coefficients of (1+t)^n are not overflow.
--
--1990/2 P(L,M),P(X,Y,Z), P-poly-Low
--1989/11 Jones polynomial.
--1989/8 Modula-2 version
--1985/12 P-poly., C-poly.
shared Alloc0:CARD;
shared Poly:ARRAY{ARRAY{INTI}}; -- [0..Alloc0][0..Alloc0]
shared TCodeRes:ARRAY{RTCODE}; --[0..Alloc0]
-- TYPE td=array[1..4] OF INT;
-- inout TdRes:array[0..PPOLYmaxC] OF td;
shared TdRes:ARRAY{ARRAY{INT}}; -- [0..Alloc0][0..4]
shared TraceDeg:ARRAY{INT}; -- [0..4]
shared TraceRes:ARRAY{RES_MARK}; -- [0..Alloc0]
shared ResFlg:ARRAY{BOOL}; -- [0..Alloc0]
shared CN,CP:ARRAY{POLYS_INTI}; -- [0..Alloc0][0..Alloc0]
shared TCodeTmp,TCodePtr:RTCODE;
shared endTc:VERTEXP;
shared i:CARD;
shared r0,r1,r2:INT;
shared o1,o2,o3:INT;
shared n,n1,n2:INT;
shared enp,stp:CARD;
shared tmp,tmpMax,tmpMp:CARD;
shared c0p,c0n,compo0,compo:INT;
shared resPtr,tPtr,tPtr1,tPtr2:CARD;
shared count:CARD; -- count resolution
-------------------init----------------------
private wait is
#OUT+"Hit return key."+#IN.get_str;
end;
closeRes is
Poly:=#; CP:=#; CN:=#;
TCodeRes:=#; TraceRes:=#; TdRes:=#; TraceDeg:=#; ResFlg:=#;
end;
test_time(TCode:TCODE, tstep, cvRes, cvTime:FLT):FLT is
rtcode:RTCODE:=#(TCode);
t:FLT:=RTCODE_TRIM::SCode(inout rtcode, tstep, cvRes, cvTime);
return t;
end;
initRes(TCode:TCODE, tstep, cvRes, cvTime:FLT):BOOL is
if TCode.has_band then return false; end;
c0:INT:=0.int; c0p:=0.int; c0n:=0.int; compo0:=0.int; b0:INT:=0.int;
TCode.numbers_count(inout c0,inout c0p,inout c0n,inout compo0,inout b0);
Alloc0:=(c0p+c0n+compo0).card;
POLYS_INTI::init;
Poly:=#(Alloc0+1);
loop i::=Poly.ind!;
Poly[i]:=#(Alloc0+1); Poly[i].to_val(0.inti);
end;
TCodeRes:=#(Alloc0+1); loop i::=TCodeRes.ind!; TCodeRes[i]:=#; end;
TraceRes:=#(Alloc0+1); loop i::=TraceRes.ind!; TraceRes[i]:=#; end;
TdRes:=#(Alloc0+1); loop i::=TdRes.ind!; TdRes[i]:=#(5); end;
TraceDeg:=#(5); TraceDeg.to_val(0.int);
ResFlg:=#(Alloc0+1); ResFlg.to_val(false);
compo:=compo0;
endTc:=#;
endTc.sep:=TCode[TCode.length].sep.clone;
endTc.companion:=0.int;
TCodeTmp:=#(TCode);
t::=RTCODE_TRIM::SCode(inout TCodeTmp, tstep, cvRes, cvTime);
TCodeRes[0]:=TCodeTmp;
TCodeRes[1]:=TCodeTmp.clone;
tmp:=0;
tPtr:=0; tmp:=0;
TraceRes[tmp].p:=tPtr;
TraceRes[tmp].m:=TCodeTmp.length;
TraceRes[tmp].c:=compo;
TdRes[tmp]:=TraceDeg.copy;
ResFlg[tmp]:=false;
tmp:=tmp+1;
TraceRes[tmp]:=TraceRes[tmp-1].clone;
TdRes[tmp]:=TraceDeg.copy; ResFlg[tmp]:=true;
resPtr:=tmp; TCodeTmp:=TCodeRes[tmp].clone;
tmpMax:=TCodeTmp.length;
return true;
end;
-- assert (tmpMax=TCodeTmp.length);
--------- resolution-------------
MakeRes201 is
n:=TCodeTmp[i].companion;
TCodePtr.k[n1.card]:=#;
if n<tPtr1.int then TCodePtr[n1.card].companion:= n;
elsif n<=tPtr2.int then TCodePtr[n1.card].companion:= n+r2;
elsif n<=enp.int then TCodePtr[n1.card].companion:= n-r1;
else TCodePtr[n1.card].companion:=n;
end;
TCodePtr[n1.card].sep:=TCodeTmp[i].sep;
end;
MakeRes2 is
resPtr:=resPtr+1;
TCodePtr:=#; TCodePtr.k:=#(TCodeTmp.k.size);
r1:=tPtr2.int-tPtr1.int+1; r2:=enp.int-tPtr2.int;
-- loop i:=0.upto!(tPtr1-1) ; n1:=i; MakeRes201; end;
loop i:=tPtr1.upto!(tPtr2) ; n1:=i.int+r2; MakeRes201; end;
loop i:=(tPtr2+1).upto!(enp) ; n1:=i.int-r1; MakeRes201; end;
loop i:=(enp+1).upto!(tmpMax-1); n1:=i.int; MakeRes201; end;
TCodePtr[tmpMax]:=endTc;
TCodePtr[(tPtr1.int+r2).card].sep:=VERTEXC::knot_s;
TCodePtr[(tPtr2.int+r2).card].sep:=VERTEXC::knot_e;
TCodePtr.TrimC(tPtr,(tPtr1.int+r2).card);
TCodeRes[resPtr]:=TCodePtr;
TraceRes[resPtr].p:=tPtr;
TraceRes[resPtr].m:=TCodePtr.length;
TraceRes[resPtr].c:=compo+1;
end;
MakeRes301 is
n:=TCodeTmp[i].companion;
TCodePtr.k[n1.card]:=#;
if n<tPtr1.int then TCodePtr[n1.card].companion:= n;
elsif n<stp.int then TCodePtr[n1.card].companion:= n+o1;
elsif n<tPtr2.int then TCodePtr[n1.card].companion:= n+o2;
elsif n<enp.int then TCodePtr[n1.card].companion:= n+o3;
else TCodePtr[n1.card].companion:= n-4;
end;
TCodePtr[n1.card].sep:=TCodeTmp[i].sep;
end;
MakeRes3 is
resPtr:=resPtr+1;
TCodePtr:=#; TCodePtr.k:=#(TCodeTmp.k.size-4);
r0:=stp.int-tPtr1.int-1; r1:=tPtr2.int-stp.int-1; r2:=enp.int-tPtr2.int-1;
o1:=r1+r2-1; o2:=r2-r0-2; o3:=-r0-r1-3;
-- loop i:=0.upto!(tPtr1-1) ; n1:=i; MakeRes301; end;
loop i:=(tPtr1+1).upto!(stp-1) ; n1:=i.int+o1; MakeRes301; end;
loop i:=(stp+1).upto!(tPtr2-1) ; n1:=i.int+o2; MakeRes301; end;
loop i:=(tPtr2+1).upto!(enp-1) ; n1:=i.int+o3; MakeRes301; end;
loop i:=(enp+1).upto!(tmpMax-1) ; n1:=i.int-4; MakeRes301; end;
TCodePtr[tmpMax-4]:=endTc;
TCodePtr.TrimL(tPtr,(tPtr2.int-1+o2).card);
TCodeRes[resPtr]:=TCodePtr;
TraceRes[resPtr].p:=tPtr;
TraceRes[resPtr].m:=TCodePtr.length;
TraceRes[resPtr].c:=compo-1;
end;
MakeRes is
tPtr1:=tPtr; tPtr2:=TCodeTmp[tPtr].companion.card; stp:=tmpMax;
loop enp:=stp-1; stp:=TCodeTmp[enp].companion.card; until!(stp<=tPtr2); end;
if stp<tPtr1 then MakeRes2; else MakeRes3; end;
TdRes[resPtr]:=TraceDeg.copy;
ResFlg[resPtr]:=false;
if VERTEXC::positive.in(TCodeTmp[tPtr].sep) then
TraceDeg[2]:=TraceDeg[2]+1;
TdRes[resPtr][4]:=TdRes[resPtr][4]+1;
else
TraceDeg[1]:=TraceDeg[1]+1;
TdRes[resPtr][3]:=TdRes[resPtr][3]+1;
end;
tPtr:=tPtr+1;
end;
MakeResLow is
tPtr1:=tPtr; tPtr2:=TCodeTmp[tPtr].companion.card; stp:=tmpMax;
loop enp:=stp-1; stp:=TCodeTmp[enp].companion.card; until!(stp<=tPtr2); end;
if stp<tPtr1 then MakeRes2;
TdRes[resPtr]:=TraceDeg.copy;
ResFlg[resPtr]:=false;
if VERTEXC::positive.in(TCodeTmp[tPtr].sep) then
TraceDeg[2]:=TraceDeg[2]+1;
TdRes[resPtr][4]:=TdRes[resPtr][4]+1;
else
TraceDeg[1]:=TraceDeg[1]+1;
TdRes[resPtr][3]:=TdRes[resPtr][3]+1;
end;
else -- MakeRes3;
if VERTEXC::positive.in(TCodeTmp[tPtr].sep) then
TraceDeg[2]:=TraceDeg[2]+1;
else TraceDeg[1]:=TraceDeg[1]+1;
end;
end;
tPtr:=tPtr+1;
end;
SetMp is
if tmpMp>tPtr then
flg:BOOL:=~VERTEXC::ks.in(TCodeTmp[tmpMp].sep);
chf:ARRAY{BOOL}:=#(TCodeTmp.size);
loop ci::=tmpMp.upto!(tmpMax-1) ; chf[ci]:=flg; end;
tmpMp:=tmpMp-1;
loop while!((tmpMp>=tPtr)and(tmpMp>0)) ;
if TCodeTmp[tmpMp].companion<(tmpMp.int+2) then
chf[tmpMp]:=true; tmpMp:=tmpMp-1;
else
tPtr1:=TCodeTmp[tmpMp].companion.card;
if chf[tPtr1] then
loop ci::=tmpMp.upto!(tPtr1); chf[ci]:=false; end;
tmpMp:=tmpMp-1;
elsif VERTEXC::over.in(TCodeTmp[tmpMp].sep) then
tmpMp:=tmpMp-1;
elsif VERTEXC::ks.in(TCodeTmp[tmpMp].sep) then
loop ci::=tmpMp.upto!(tPtr1); chf[ci]:=false; end;
tmpMp:=tmpMp-2;
else tmpMp:=tmpMp+1; return;
end;
end;
end;
end;
end;
SetMpC is
stp:=tmpMax;
loop enp:=stp-1; stp:=TCodeTmp[enp].companion.card;
until!(stp<=tPtr);
end;
tmpMp:=enp+1;
if tmpMp=tmpMax then tmpMp:=tmpMax-4; SetMp;
else
loop
tmpMp:=tmpMp-1;
until!( (tmpMp=0)or
(tmpMp<tPtr)or
((enp.int<TCodeTmp[tmpMp].companion)
and(VERTEXC::under.in(TCodeTmp[tmpMp].sep))));
end;
tmpMp:=tmpMp+1;
end;
end;
SetNotWell:BOOL is
loop
if (tPtr>=tmpMp) then return false;
elsif ((tPtr.int+2) < TCodeTmp[tPtr].companion)
and (VERTEXC::under.in(TCodeTmp[tPtr].sep)) then return true;
elsif VERTEXC::ks.in(TCodeTmp[tPtr].sep) then
TCodeTmp.TrimDelPC(tPtr);
tmpMax:=TCodeTmp.length.card;
tmpMp:=tmpMax-4;
SetMp;
assert (tmpMax=TCodeTmp.length);
end;
tPtr:=tPtr+1;
end;
end;
SetNotWellC:BOOL is
loop
if (tPtr>=tmpMp) then return false;
elsif ((tPtr.int+2) < TCodeTmp[tPtr].companion)
and (VERTEXC::under.in(TCodeTmp[tPtr].sep))
then return true;
end;
tPtr:=tPtr+1;
end;
end;
SetTCodeTmp is
loop while!(ResFlg[resPtr]) ; resPtr:=resPtr-1; end;
tmp:=resPtr;
TraceDeg:=TdRes[tmp]; ResFlg[tmp]:=true;
tPtr:=TraceRes[tmp].p;
tmpMax:=TraceRes[tmp].m;
compo:=TraceRes[tmp].c;
TCodeTmp:=TCodeRes[tmp]; -- .clone(tPtr);
--#OUT+"SetTCodeTmp 1: support="+TCodeTmp.support+"\n";
--if void(TCodeTmp[tPtr]) then
-- #OUT+"SetTCodeTmp: TCodeTmp\n"; TCodeTmp.printD(tPtr); wait;
--end;
assert (tmpMax=TCodeTmp.length);
end;
end; -- POLY2
class PPOLY
class PPOLY is
include POLY2;
const Def_xyz,Def_lm,Def_vz;
------------------- P.poly. -----------------
private SetPolyP is
degX::=(TraceDeg[1]-TraceDeg[2]-TraceDeg[4]+c0p).card;
degZ::=(TraceDeg[3]+TraceDeg[4]-compo+compo0).card;
-- polyT:=Poly[TraceDeg[3]+TraceDeg[4]-compo+compo0];
-- polyT Poly[degZ]
--if (degZ<0)or(degZ>Alloc0) then
-- out("Polynomial: error on degree-z.");
--end;
--if (degX<0)or(degX>Alloc0) then
-- out("Polynomial: error on degree-x.");
--end;
case compo
when 2.int then
if TraceDeg[3].is_odd then
Poly[degZ][degX+1]:=Poly[degZ][degX+1]-1.inti;
Poly[degZ][degX]:=Poly[degZ][degX]+1.inti;
else
Poly[degZ][degX+1]:=Poly[degZ][degX+1]+1.inti;
Poly[degZ][degX]:=Poly[degZ][degX]-1.inti;
end;
when 1.int then
if TraceDeg[3].is_odd then
Poly[degZ][degX]:=Poly[degZ][degX]-1.inti;
else
Poly[degZ][degX]:=Poly[degZ][degX]+1.inti;
end;
else
degC::=compo.card-1;
if TraceDeg[3].is_odd then
loop i::=0.upto!(degC); j::=degX.up!;
Poly[degZ][j]:=Poly[degZ][j]-CN[degC][i];
end;
else
loop i::=0.upto!(degC); j::=degX.up!;
Poly[degZ][j]:=Poly[degZ][j]+CN[degC][i];
end;
end;
end;
end;
Ppoly_time(TCode:TCODE,DefS:CARD) is
-- for speed test
-- rate: rateCl
-- res/s: rateCl*4.4
-- 1.201< 1.25 <1.5
-- 1.25, 2.18
-- 1.27, 2.0 : (worst time)=(expected time)
-- Worst case is (2,n) torus knot.
-- 1.27, 6.0 : (real time) < 3*(expected time)
-- 1.27202=sqrt((1+sqrt(5))/2)= sqrt of Fibonacci ratio.
if ~ initRes(TCode, 1.27 , 0.0, 10000.0 ) then
closeRes; return;
end;
count:=0; CN:=POLY_COEFF::AllocCN(Alloc0);
loop while!(resPtr.is_pos);
tmpMp:=tmpMax-4; SetMp;
loop while!(SetNotWell); MakeRes; end;
count:=count+1; -- count is needed for POLY_TIME::rateCl.
SetPolyP; SetTCodeTmp;
end;
-- POLY_TIME::SetR(count.flt,"PPoly");
closeRes;
end;
test_time(TCode:TCODE):FLT is
return test_time(TCode, 1.27 , 0.5, POLY_TIME::rateCl*0.96);
end;
PpolyP(TCode:TCODE,DefS:CARD):POLYM_INTI is
-- rate: rateCl
-- res/s: rateCl*4.4
-- 1.201< 1.25 <1.5
-- 1.25, 2.18
-- 1.27, 2.0 : (worst time)=(expected time)
-- Worst case is (2,n) torus knot.
-- 1.27, 6.0 : (real time) < 3*(expected time)
-- 1.27202=sqrt((1+sqrt(5))/2)= sqrt of Fibonacci ratio.
p:POLYM_INTI:=#;
if ~ initRes(TCode, 1.27 , 0.5, POLY_TIME::rateCl*0.96) then
closeRes; return p;
end;
count:=0; poly_count:POLY_COUNT:=#; time:TIME_MEASURE:=#;
CN:=POLY_COEFF::AllocCN(Alloc0);
loop while!(resPtr.is_pos);
tmpMp:=tmpMax-4; SetMp;
loop while!(SetNotWell); MakeRes; end;
count:=count+1; poly_count.count(compo);
SetPolyP; SetTCodeTmp;
end;
POLY_TIME::SetR(count.flt,"PPoly");
#OUT+"size of resolution:"+poly_count.str+"\n"; --WriteCount
p:=PTbl2Polym(DefS);
--PPrintLog(DefS,"P-polynomial:");
closeRes;
return p;
end;
Ppoly(tcode:TCODE,DefS:CARD,isTest:BOOL):POLYM_INTI is
time:TIME_MEASURE:=#;
poly:POLYM_INTI:=#;
if tcode.has_band then return poly; end;
t0,t1:FLT;
if false and tcode.number_crossing<20.int then t0:=1.0; t1:=t0+1.0;
else
time:=#;
t0:=PPOLY::test_time(tcode);
--#OUT+"elapsed time for test0:"+t0.str+"\n";
time:=#;
braid:BRAID:=#;
b::=BRAID_CNV::TCode2Braid(tcode, out braid);
if ~b then t1:=t0+t0+1.0;
elsif braid.index>9 then t1:=t0+t0+1.0;
else t1:=PPOLYB::test_time(braid);
end;
--#OUT+"elapsed time for test1:"+t1.str+"\n";
end;
-- test
if isTest then
poly0,poly1:POLYM_INTI;
time:=#;
poly0:=PPOLY::PpolyP(tcode,DefS);
t0:=time.elapsed.flt;
#OUT+"elapsed time for test0:"+t0.str+"\n";
time:=#;
poly1:=PPOLYB::Ppoly(tcode,DefS);
t1:=time.elapsed.flt;
#OUT+"elapsed time for test1:"+t1.str+"\n";
if poly0/=poly1 then
#OUT+"Ppoly test failed:\n";
#OUT+"ppoly1\n"; PPrintLog(poly0,DefS,"P-polynomial:");
#OUT+"ppoly2\n"; PPrintLog(poly1,DefS,"P-polynomial:");
end;
OUT::flush;
return poly1;
end;
--
time:=#;
POLY_TIME::out_expected_time(t0.min(t1));
if t0<t1 then poly:=PPOLY::PpolyP(tcode,DefS);
else poly:=PPOLYB::Ppoly(tcode,DefS);
end;
#OUT+"elapsed time="+time.elapsed.str+"sec.\n";
return poly;
end;
Ppoly(tcode:TCODE,DefS:CARD) is
if tcode.has_band then return; end;
poly::=Ppoly(tcode,DefS,false);
PPrintLog(poly,DefS,"P-polynomial:");
end;
PpolyTest(tcode:TCODE,DefS:CARD) is
if tcode.has_band then return; end;
poly::=Ppoly(tcode,DefS,true);
PPrintLog(poly,DefS,"P-polynomial:");
end;
shared z,z1,x,x1:INT;
shared ds,dx:INT; -- degree
shared chs,chx:STR;
shared ci:INTI;
private CoeXYZs is
ds:=z; chs:="(z/y)";
end;
private CoeXYZx is
ci:=Poly[z1.card][x1.card]; dx:=x; chx:="(x/y)";
end;
private CoeVZs is
ds:=z; chs:="z";
end;
private CoeVZx is
ci:=Poly[z1.card][x1.card]; dx:=-x-x-z; chx:="v";
end;
private CoeLMs is
ds:=z; chs:="m";
end;
private CoeLMx is
ci:=0.inti;
if x.is_odd then ci:=ci-Poly[z1.card][x1.card];
else ci:=ci+Poly[z1.card][x1.card];
end;
dx:=x+x+z; chx:="l";
end;
private wrTitle(title,s:STR) is
LOGOUT::Title(title,s);
end;
PPrintLogHead(DefS:CARD,title:STR) is
case DefS
when Def_xyz then -- x,y,z form.
wrTitle(title,"xP_{L+} -yP_{L-} = zP_{L0}");
when Def_lm then -- L-M form.
wrTitle(title,"lP_{L+} +(1/l)P_{L-} +mP_{L0} = 0");
when Def_vz then -- v-z form
wrTitle(title,"(1/v)P_{L+} -vP_{L-} = zP_{L0}");
else
wrTitle(title,"unknown poly.");
end;
end;
P_str(poly:POLYM_INTI, DefS:CARD):STR is
return P_str(poly, DefS, "text");
end;
P_str(poly:POLYM_INTI, DefS:CARD, format:STR):STR is
z:STR:="";
case DefS
when Def_xyz then z:="z"; -- x,y,z form.
when Def_lm then z:="m"; -- L-M form.
when Def_vz then z:="z"; -- v-z form
else return poly.str;
end;
timeC,timeV,power1,power2,ms,me,sign:STR;
POLY_WRITE::str_parts(format,out timeC,out timeV,out power1,out power2,out ms,out me);
res:STR:=""; nl_str:STR:="";
maxdeg:INT:=poly.maxdeg(z); mindeg:INT:=poly.mindeg(z);
count:INT:=0;
loop i:INT:=mindeg.stepto!(maxdeg,2.int);
polyd:POLYM_INTI:=poly.coeff("z", i);
polyz:POLYM_INTI:=#(1.inti,z,i);
if polyd.is_zero.not then count:=count+1;
flg1:BOOL:=(i.is_zero);
flg2:BOOL:=polyd.is_one;
flg3:BOOL:=(-polyd).is_one;
res:=res+nl_str;
if flg3 then res:=res+"-";
elsif nl_str/="" then res:=res+"+";
end;
nl_str:="\n";
if flg1.not then res:=res+polyz.str(format); end;
if flg1.not and (flg2 or flg3).not then res:=res+timeC; end;
if (flg2 or flg3) then
if flg1 then res:=res+"1"; end;
else
res:=res+"("+polyd.str(format)+")";
end;
end;
end;
if count.is_zero then res:=res+"0"; end;
res:=ms+res+me;
return res;
end;
PTbl2Polym(DefS:CARD):POLYM_INTI is
z,x:POLYM_INTI; -- xP_{L+} -P_{L-} = zP_{L0}
case DefS
when Def_xyz then -- x,y,z form. xP_{L+} -yP_{L-} = zP_{L0}
x:=#POLYM_INTI(1.inti,"x",1.int)*#POLYM_INTI(1.inti,"y",-1);
z:=#POLYM_INTI(1.inti,"z",1.int)*#POLYM_INTI(1.inti,"y",-1);
when Def_lm then -- L-M form. lP_{L+} +(1/l)P_{L-} +mP_{L0} = 0
x:=-#POLYM_INTI(1.inti,"l",2.int);
z:=#POLYM_INTI(1.inti,"m",1.int)*#POLYM_INTI(1.inti,"l",1.int);
when Def_vz then -- v-z form. (1/v)P_{L+} -vP_{L-} = zP_{L0}
x:=#POLYM_INTI(1.inti,"v",-2);
z:=#POLYM_INTI(1.inti,"z",1.int)*#POLYM_INTI(1.inti,"v",-1);
else -- default. v-z form. (1/v)P_{L+} -vP_{L-} = zP_{L0}
x:=#POLYM_INTI(1.inti,"v",-2);
z:=#POLYM_INTI(1.inti,"z",1.int)*#POLYM_INTI(1.inti,"v",-1);
end;
poly:POLYM_INTI:=#;
loop z_deg:INT:=(1.int-compo0).stepto!(c0p+c0n,2.int); z1::=z_deg+compo0-1;
loop x_deg::=(-c0p).upto!(c0n-z_deg);
if Poly[z1.card][(x_deg+c0p).card]/=0.inti then
poly:=poly+(z^z_deg)*(x^x_deg)*Poly[z1.card][(x_deg+c0p).card];
end;
end;
end;
return poly;
end;
PPrintLog(poly:POLYM_INTI,DefS:CARD,title:STR) is
PPrintLogHead(DefS,title);
VARNAME::setVarOrder(|"z","x","y","m","l","v"|);
MONOMIAL{INTI}::setTermOrder("lex");
#LOGOUT+P_str(poly.normalize,DefS)+"\n";
VARNAME::setVarOrder;
MONOMIAL{INTI}::setTermOrder;
end;
PPrintLog(DefS:CARD,title:STR) is
PPrintLogHead(DefS,title);
count:CARD;
step:INT;
flg,flg2:BOOL; -- not the first term, need +/-
flgSt:BOOL; -- need * .
CoeTps,CoeTpx:ROUT;
case DefS
when Def_xyz then -- x,y,z form.
CoeTps:=bind(CoeXYZs); CoeTpx:=bind(CoeXYZx);
when Def_lm then -- L-M form.
CoeTps:=bind(CoeLMs); CoeTpx:=bind(CoeLMx);
when Def_vz then -- v-z form
CoeTps:=bind(CoeVZs); CoeTpx:=bind(CoeVZx);
else
CoeTps:=bind(CoeLMs); CoeTpx:=bind(CoeLMx); DefS:=Def_lm;
end;
#OUT+"compo, cross(+/-): "+compo0.str+", "+c0p.str+"/"+c0n.str+"\n";
ci:=0.inti; flg:=false;
loop z:=(1.int-compo0).stepto!(c0p+c0n,2.int); z1:=z+compo0-1; count:=0;
loop x:=(-c0p).upto!(c0n-z);
if Poly[z1.card][(x+c0p).card].is_non_zero then count:=count+1; end;
end;
if count=1 then
loop x:=(-c0p).upto!(c0n-z);
x1:=x+c0p; CoeTps.call; CoeTpx.call;
if ci/=0.inti then
#LOGOUT+POLY_WRITE::wrCoeff(ci,inout flg,out flgSt);
#LOGOUT+POLY_WRITE::wrVar(chx,dx,false,inout flgSt);
#LOGOUT+POLY_WRITE::wrVar(chs,ds,true,inout flgSt);
end;
end;
#LOGOUT+"\n";
elsif count>1 then
ci:=1.inti; CoeTps.call;
#LOGOUT+POLY_WRITE::wrCoeff(ci,inout flg,out flgSt);
#LOGOUT+POLY_WRITE::wrVar(chs,ds,false,inout flgSt);
if flgSt then #LOGOUT+"*"; end;
#LOGOUT+"("; flg2:=false;
case DefS
when Def_xyz,Def_lm then x:=-c0p; step:=1;
when Def_vz then x:=c0n-z; step:=-1;
else ;
end;
loop while!(((c0p+x)*(c0n-z-x)).is_non_neg);
x1:=x+c0p; CoeTpx.call;
if ci.is_non_zero then
#LOGOUT+POLY_WRITE::wrCoeff(ci,inout flg2,out flgSt);
#LOGOUT+POLY_WRITE::wrVar(chx,dx,true,inout flgSt);
end;
x:=x+step;
end;
#LOGOUT+")\n";
end;
end;
#LOGOUT+"\n"; LOGOUT::flush;
end;
-------------------P poly -LOW ----------------------
private CnvP is
x1,z1:CARD;
ci:INTI:=0.inti;
loop z1:=Alloc0.downto!(2);
-- polyT:= Poly[z1-1];
loop x1:=0.upto!(Alloc0) ;
ci:=Poly[z1][x1]; Poly[z1][x1]:=0.inti;
if ci/=0.inti then
Poly[z1-1][x1+1]:=Poly[z1-1][x1+1]+ci;
Poly[z1-1][x1]:=Poly[z1-1][x1]-ci;
end;
end;
end;
polyT::=Poly[0]; -- exchange
Poly[0]:=Poly[1];
Poly[1]:=polyT;
end;
PpolyLow(TCode:TCODE,DefS:CARD) is
-- 1.120< ? <1.124
if ~ initRes(TCode,1.123, 4.0, POLY_TIME::rateCl*39.0) then
closeRes; return;
end;
count:=0;
time:TIME_MEASURE:=#;
loop while!(resPtr.is_pos) ;
count:=count+1;
tmpMp:=tmpMax-4;
loop while!(SetNotWell); MakeResLow; end;
degX:CARD:=(TraceDeg[1]-TraceDeg[2]-TraceDeg[4]+c0p).card;
if TraceDeg[3].is_odd then
Poly[compo.card][degX]:=
Poly[compo.card][degX]-1.inti;
else Poly[compo.card][degX]:=
Poly[compo.card][degX]+1.inti;
end;
SetTCodeTmp;
end;
--(*WriteWrap; WriteLn; *)
POLY_TIME::SetR(count.flt,"PpolyLow");
CnvP;
PPrintLog(DefS,"P-polynomial low:");
closeRes;
end;
end; -- class PPOLY
class VPOLY
class VPOLY is
include POLY2;
-- TYPE polyv=ARRAY[-4*PPOLYmaxC..4*PPOLYmaxC] OF LongInt;
--------------------Jones' poly.---------
VPrintLog(polyV:POLYS_INTI,shift:INT) is
flg,flgSt:BOOL;
t:INT;
LOGOUT::Title("Jones polynomial:",
"tV_{L+}-(1/t)V_{L-} = -(\sqrt{t}-1/\sqrt{t})V_{L0}");
flg:=false;
loop i::=polyV.arr.ind!; t:=i.int-shift;
if polyV[i].is_non_zero then
#LOGOUT+POLY_WRITE::wrCoeff(polyV[i],inout flg,out flgSt);
if t=0.int then
if ~ flgSt then #LOGOUT+"1"; end;
elsif t=2.int then
if flgSt then #LOGOUT+"*"; end;
#LOGOUT+"t";
else
if flgSt then #LOGOUT+"*"; end;
#LOGOUT+"t"+"^{";
if t.is_odd then
#LOGOUT+t.str+"/2";
else #LOGOUT+(t/2.int).str;
end;
#LOGOUT+"}";
end;
end;
end;
-- if ~ flg then LogOut.Write('0'); end;
#LOGOUT+"\n"; LOGOUT::flush;
end;
private SetPolyV2 is
degX:CARD:=(TraceDeg[1]-TraceDeg[2]-TraceDeg[4]+c0p).card;
degZ::=TraceDeg[3]+TraceDeg[4]-compo+1;
degC:CARD;
if degZ.is_non_neg then degC:=(compo-1).card; else degC:=(compo-1+degZ).card; end;
z::=(degZ+compo0-1).card;
-- polyT:= Poly[z];
if degC=2 then
if TraceDeg[3].is_odd then
Poly[z][degX+2]:=Poly[z][degX+2]-1.inti;
Poly[z][degX+1]:=Poly[z][degX+1]+2.inti;
Poly[z][degX]:=Poly[z][degX]-1.inti;
else
Poly[z][degX+2]:=Poly[z][degX+2]+1.inti;
Poly[z][degX+1]:=Poly[z][degX+1]-2.inti;
Poly[z][degX]:=Poly[z][degX]+1.inti;
end;
elsif degC=1 then
if TraceDeg[3].is_odd then
Poly[z][degX+1]:=Poly[z][degX+1]-1.inti;
Poly[z][degX]:=Poly[z][degX]+1.inti;
else
Poly[z][degX+1]:=Poly[z][degX+1]+1.inti;
Poly[z][degX]:=Poly[z][degX]-1.inti;
end;
elsif degC>1 then
if TraceDeg[3].is_odd then
loop i::=0.upto!(degC) ; j::=degX.up!;
Poly[z][j]:=Poly[z][j]-CN[degC][i];
end;
else
loop i::=0.upto!(degC) ; j::=degX.up!;
Poly[z][j]:=Poly[z][j]+CN[degC][i];
end;
end;
else
if TraceDeg[3].is_odd then Poly[z][degX]:=Poly[z][degX]-1.inti;
else Poly[z][degX]:=Poly[z][degX]+1.inti;
end;
end;
end;
private shift_normal(inout poly:POLYS_INTI, inout offset:INT) is
poly.normalize; m::=poly.low_deg;
if m.is_pos then poly:=poly.shift_deg(-m); offset:=offset-m; end;
end;
private cnvV2(out polyV:POLYS_INTI,out offset:INT) is
-- Use with SetPolyV2
polyV:=#; offset:=((Alloc0+1)*4).int;
z1:CARD;
ci:INTI;
pcn:POLYS_INTI;
loop z:INT:=(1.int-compo0).stepto!(c0p+c0n,2.int);
ci:=0.inti;
if z.is_non_neg then z1:=z.card; pcn:=CN[z1]; else z1:=(-z).card; pcn:=CP[z1]; end;
loop x::=(-c0p).upto!(c0n-z);
degZ::=4.int*x+z;
ci:=Poly[(z+compo0-1).card][(x+c0p).card];
if ci.is_non_zero then
if z1.is_odd then
loop i:=0.upto!(z1.card) ;
polyV[(degZ+offset).card]:=polyV[(degZ+offset).card]-ci*pcn[i];
degZ:=degZ+2;
end;
else
loop i:=0.upto!(z1.card);
polyV[(degZ+offset).card]:=polyV[(degZ+offset).card]+ci*pcn[i];
degZ:=degZ+2;
end;
end;
end;
ci:=0.inti;
end;
end;
shift_normal(inout polyV,inout offset);
end;
test_time(TCode:TCODE):FLT is
return test_time(TCode,1.27, 0.5,POLY_TIME::rateCl*0.96);
end;
VpolyP(TCode:TCODE, out polyV:POLYS_INTI, out offset:INT):BOOL is
-- t * V(Lp) - 1/t * V(Ln) + (t^1/2 - t^(-1/2)) * V(Ls) = 0 .
if ~initRes(TCode,1.27, 0.5,POLY_TIME::rateCl*0.96) then
closeRes; return false;
end;
time:TIME_MEASURE:=#;
CN:=POLY_COEFF::AllocCN(Alloc0); CP:=POLY_COEFF::AllocCP(Alloc0);
loop while!(resPtr.is_pos);
tmpMp:=tmpMax-4; SetMp;
loop while!( SetNotWell) ; MakeRes; end;
SetPolyV2; SetTCodeTmp;
end;
cnvV2(out polyV,out offset);
closeRes;
return true;
end;
Vpoly(tcode:TCODE, out poly:POLYS_INTI, out offset:INT) is
-- t * V(Lp) - 1/t * V(Ln) + (t^1/2 - t^(-1/2)) * V(Ls) = 0 .
poly:=#; offset:=0;
if tcode.has_band then return; end;
t0,t1:FLT;
if tcode.number_crossing<20.int then t0:=1.0; t1:=t0+1.0;
else
t0:=VPOLY::test_time(tcode);
braid:BRAID:=#;
b::=BRAID_CNV::TCode2Braid(tcode, out braid);
if ~b then t1:=t0+t0+1.0;
elsif braid.index>9 then t1:=t0+t0+1.0;
else t1:=VPOLYB::test_time(braid);
end;
end;
-- test
if false then
poly1,poly2:POLYS_INTI; ofs1,ofs2:INT;
if VPOLY::VpolyP(tcode,out poly1, out ofs1) then; end;
VPOLYB::Vpoly(tcode,out poly2, out ofs2);
shift_normal(inout poly1,inout ofs1);
shift_normal(inout poly2,inout ofs2);
if poly1/=poly2 then
#OUT+"poly1="+poly1.str+", poly2="+poly2.str+"\n";
end;
end;
--
POLY_TIME::out_expected_time(t0.min(t1));
time:TIME_MEASURE:=#;
if t0<t1 then
if VPOLY::VpolyP(tcode,out poly, out offset) then; end;
--VPOLY::VPrintLog(poly,offset);
else
VPOLYB::Vpoly(tcode,out poly, out offset);
VPOLY::VPrintLog(poly,offset);
end;
#OUT+time.elapsed.str+"sec.\n";
end;
Vpoly(tcode:TCODE) is
if tcode.has_band then return; end;
poly:POLYS_INTI; offset:INT;
Vpoly(tcode,out poly, out offset);
VPOLY::VPrintLog(poly,offset);
end;
VPara(TCode:TCODE, n:INT) is
-- V polynomial of n-parallel for knot.
PARALLEL_T::parallel(inout TCode, n);
Vpoly(TCode);
end;
end; -- class VPOLY
class CPOLY
class CPOLY is
include POLY2;
--------------------C.poly.----------------
test_time(TCode:TCODE):FLT is
return test_time(TCode,1.27, 0.5, POLY_TIME::rateCl*1.1);
end;
CpolyP(TCode:TCODE):POLYS_INTI is
if ~ initRes(TCode,1.27, 0.5, POLY_TIME::rateCl*1.1) then
closeRes; return #;
end;
count:=0;
time:TIME_MEASURE:=#;
PolyCon:ARRAY{INTI}:=#(Alloc0+1);
loop i::=PolyCon.ind!; PolyCon[i]:=0.inti; end;
loop while!(resPtr.is_pos);
count:=count+1;
SetMpC;
loop while!( SetNotWellC) ; MakeRes; end;
if compo=1 then
if TraceDeg[3].is_odd then
PolyCon[TraceDeg[3]+TraceDeg[4]]:=
PolyCon[TraceDeg[3]+TraceDeg[4]]-1.inti;
else
PolyCon[TraceDeg[3]+TraceDeg[4]]:=
PolyCon[TraceDeg[3]+TraceDeg[4]]+1.inti;
end;
end;
SetTCodeTmp;
end;
-- WriteWrap; WriteLn;
POLY_TIME::SetR(count.flt,"CPoly");
-- WriteCount;
cpoly:POLYS_INTI:=POLYS_INTI::gen_func(PolyCon); cpoly.normalize;
--ALEXMAT::printConway(cpoly);
closeRes;
return cpoly
end;
Cpoly(tcode:TCODE):POLYS_INTI is
poly:POLYS_INTI:=#;
if tcode.has_band then return poly; end;
t0,t1:FLT;
if tcode.number_crossing<20 then t0:=1.0; t1:=t0+1.0;
else
t0:=CPOLY::test_time(tcode);
braid:BRAID:=#;
b::=BRAID_CNV::TCode2Braid(tcode, out braid);
if ~b then t1:=t0+t0+1.0;
elsif braid.index>9 then t1:=t0+t0+1.0;
else t1:=CPOLYB::test_time(braid);
end;
end;
if false then -- test
poly1,poly2:POLYS_INTI;
poly1:=CPOLY::CpolyP(tcode);
poly2:=CPOLYB::Cpoly(tcode);
if poly1/=poly2 then
#OUT+"poly1="+poly1.str+", poly2="+poly2.str+"\n";
end;
end;
--
POLY_TIME::out_expected_time(t0.min(t1));
time:TIME_MEASURE:=#;
if t0<t1 then
poly:=CPOLY::CpolyP(tcode);
else
poly:=CPOLYB::Cpoly(tcode);
end;
#OUT+time.elapsed.str+"sec.\n";
return poly;
end;
Cpoly(tcode:TCODE) is
if tcode.has_band then return; end;
poly:POLYS_INTI:=Cpoly(tcode);
ALEXMAT::printConway(poly);
end;
end; -- class CPOLY
class APOLY
class APOLY is
test_time(TCode:TCODE):FLT is
return CPOLY::test_time(TCode);
end;
ApolyC(tcode:TCODE):POLYS_INTI is
apoly:POLYS_INTI:=#;
if tcode.has_band then return apoly; end;
cpoly:POLYS_INTI:=CPOLY::Cpoly(tcode);
--ALEXMAT::printConway(poly);
ALEXMAT::conway2apoly(cpoly,out apoly);
--ALEXMAT::printApoly(apoly);
return apoly;
end;
ApolyC(tcode:TCODE) is
if tcode.has_band then return; end;
apoly::=ApolyC(tcode);
ALEXMAT::printApoly(apoly);
end;
end; -- APOLY