# First define the mapping by defining the strings T0 and T1: # 00 / 1101 A284116 This is the "Post Tag System" T0:="00"; T1:="1101"; # 00 / 1011 A291067 These three are from the Watanabe paper T0:="00"; T1:="1011"; # 00 / 1110 A291068 T0:="00"; T1:="1110"; # 00 / 0111 A291069 T0:="00"; T1:="0111"; with(StringTools): read(format): # the mapping: f1:=proc(w) local L, ws, w2; global T0,T1; ws:=convert(w, string); if ws="-1" then return("-1"); fi; if ws[1]="0" then w2:=Join([ws, T0], ""); else w2:=Join([ws, T1], ""); fi; L:=length(w2); if L <= 3 then return("-1"); fi; w2[4..L]; end; # Compute the trajectory of s1 as a set tr:=proc(s1) local ss,n,M,traj; global f1,T0,T1; ss:=convert(s1,string); M:=1000; traj:={}; for n from 1 to M do traj := traj union {ss}; ss:=f1(ss); od: #lprint(nops(traj),traj); nops(traj); end: # Compute max length of any trajectory for strings of length <= 7 # rec holds records for length n, best holds an example of an optimal string lprint("Results for the case T0, T1 =", T0, T1); S:=["0","1","00","10","000","100","0000","0001","1000","1001","00000","00010","10000","10010","000000","000100","100000","100100","0000000","0000001","0001000","0001001","1000000","1000001","1001000","1001001"]; rec:=Array(1..7,0); best:=Array(1..7,0); for i in S do L:=length(i); ll:=tr(i); if ll > rec[L] then rec[L]:=ll; best[L]:=i; fi; od: rec; best;