print(`Version of Nov. 22, 1996`): lprint(``): print(`This is DIKDUK, a Maple package that empirically finds`): print(`the grammar of combinatorial objects, suitably encoded as words.`): print(`DIKDUK means grammar in Hebrew`): lprint(``): print(` The most current version is available on WWW at:`): print(` http://www.math.temple.edu/~zeilberg .`): lprint(``): print(`For general help, and a list of the available functions,`): print(` type "ezra();". For specific help type "ezra(procedure_name)" `): lprint(``): ezra:=proc() if args=NULL then print(` DIKDUK, `): print(`a Maple package that empirically finds`): print(`the grammar of combinatorial objects, suitably encoded as words.`): print(`DIKDUK means grammar in Hebrew`): lprint(``): print(`For help with a specific procedure, type "ezra(procedure_name);"`): lprint(``): print(`Contains procedures: `): print(` Dikduk, Safa, gf, gf1 , reduc, Reduc `): print(` Grammar , SafaAd, CORPUSES `): fi: if nops([args])=1 and op(1,[args])=`SafaAd` then print(`SafaAd(dikduk,r,OREKH), given an r-Markovian grammar, in terms`): print(`of a list of 6 entries:`): print(`[Milimktsarot,rTuplemat,rTuplesof,rTuple,A,AlefBet],`): print(`returns all the words of length <=OREKH, where OREKH>=r`): fi: if nops([args])=1 and op(1,[args])=`Grammar` then print(`Grammar(safa,r,OREKH) tests whether a language, safa, is r-Markovian`): print(`by checking whether the r-Markovian grammar, guessed by`): print(`the subset of length =r`): print(`followed by all prefixes of length OREKH`): fi: if nops([args])=1 and op(1,[args])=`CORPUSES` then print(`CORPUSES(RaLa,N,GVUL): Given a procedure name, RaLa, `): print(`where RaLa() generates a`): print(`random element of a given langauge`): print(`generates three corpues of that`): print(`language, the first with N words, the second with 2N `): print(`words and the third with 3N words, for safety we want N`): print(` to be at least 10`): print(`GVUL is a limit to the tries to guarantee that the program`): print(`terminates`): print(`If it fails, it returns 0`): fi: end: #Dikduk(safa,r): Given a set of words of all lengths, #safa, and the Markovian-memory parameter r #returns a 6-component list: #The first is the set if all words of length=r then AlefBet:=AlefBet union convert(mila,set): rTuplemat:=rTuplemat union {[op(1..r,mila)]}: rTuplesof:=rTuplesof union {[op(nops(mila)-r+1..nops(mila),mila)]}: for j from 1 to nops(mila)-r+1 do rTuple:=rTuple union {[op(j..j+r-1,mila)]}: od: fi: od: for i from 1 to nops(rTuple) do A[op(op(i,rTuple))]:={}: od: for i from 1 to nops(safa) do mila:=op(i,safa): if nops(mila)>r then for j from 1 to nops(mila)-r do A[op(j..j+r-1,mila)]:= A[op(j..j+r-1,mila)] union {op(j+r,mila)}: od: fi: od: [Milimktsarot,rTuplemat,rTuplesof,rTuple,A,AlefBet]: end: #SafaAd(dikduk,r,OREKH), given an r-Markovian grammar, in terms #of a list of 6 entries: #[Milimktsarot,rTuplemat,rTuplesof,rTuple,A,AlefBet], #returns all the words of length <=OREKH, where OREKH>=r SafaAd:=proc(dikduk,r,OREKH) local lu,i: lu:=dikduk[1]: for i from r to OREKH do lu:=lu union Safa(dikduk,r,i)[1]: od: lu: end: #Safa(dikduk,r,OREKH), given an r-Markovian grammar, in terms #of a list of 6 entries: #[Milimktsarot,rTuplemat,rTuplesof,rTuple,A,AlefBet], #returns all the words of length OREKH, where OREKH>=r #followed by all prefixes of length OREKH Safa:=proc(dikduk,r,OREKH) local rTuplemat,rTuplesof,A,gu,gu1,gu2,mila,Mutar,i,j: option remember: if OREKH=OREKH`): fi: rTuplemat:=op(2,dikduk): rTuplesof:=op(3,dikduk): A:=op(5,dikduk): if r=OREKH then RETURN(rTuplemat intersect rTuplesof,rTuplemat): fi: gu:=Safa(dikduk,r,OREKH-1)[2]: gu1:={}: gu2:={}: for i from 1 to nops(gu) do mila:=op(i,gu): Mutar:=A[op(nops(mila)-r+1..nops(mila),mila)]: for j from 1 to nops(Mutar) do gu2:=gu2 union {[op(mila),op(j,Mutar)]}: if member( [op(nops(mila)-r+2..nops(mila),mila),op(j,Mutar)],rTuplesof) then gu1:=gu1 union {[op(mila),op(j,Mutar)]}: fi: od: od: gu1,gu2: end: #gf(dik,r,wt): Given an r-Markovian grammar dik, and a wt table wt, #indicating the wt of each of the letters, finds the weight #enumerator(i.e. generating function) of the whole language gf:=proc(dik,r,wt) local ktsarot,mu,mish,eq,var,i,KULAM,INI,FIN,A,B,lu,eq1,mutarim,mila,ot1,j: mish:=proc(mila,wt) local i,gu: gu:=1: for i from 1 to nops(mila) do gu:=gu*wt[op(i,mila)]: od: gu: end: ktsarot:=dik[1]: INI:=dik[2]: FIN:=dik[3]: KULAM:=dik[4]: A:=dik[5]: mu:=0: for i from 1 to nops(ktsarot) do mila:=op(i,ktsarot): if nops(mila)r`): fi: sa1:={}: sa2:={}: for i from 1 to nops(safa) do mila:=op(i,safa): if nops(mila)sa2 then print(`Could not guess a grammar, try to raise r or generate longer words`): RETURN(0): fi: di: end: savim:=proc(dik1,dik2) local i: for i from 1 to 4 do if dik1[i]<>dik2[i] then RETURN(0): fi: od: if dik1[6]<>dik2[6] then RETURN(0): fi: if op(op(op(dik1[5])))<>op(op(op(dik1[5]))) then RETURN(0): fi: 1: end: #CORPUSES(RaLa,N,GVUL): Given a procedure name, RaLa, #where RaLa() generates a #random element of a given langauge #generates three corpues of that #language, the first with N words, the second with 2N words and the third #with 3N words, for safety we want N to be at least 10 #GVUL is a limit to the tries to guarantee that the program #terminates #If it fails, it returns 0 CORPUSES:=proc(RaLa,N,GVUL) local i,sa1,sa2,sa3,mila: if not type(N,integer) or N<10 then ERROR(`N must be an integer>=10`): fi: sa:={}: for i from 1 to GVUL while nops(sa)