; TeX output 1996.03.06:1224y?JZDtGGcmr17A7tdemonstrationofthe߆TG cmtt12programenqvironment!N9ȹ)XQ cmr12MartinWVardCenrtreforSoftwareMaintenanceiUnivrersityofDurham7ÍiMarcrh6,1996.J>(Nff cmbx12ContentsN9>)"V cmbx101MExampleTwith*M cmbxsl10 rstffs4#set.byand rstffs4#set*%.1>2MProQceduresTandF unctionsV3>3MATRev9erseEngineeringExample5%Bˍ>1VLExampleffwith-Mff cmbxsl10 rstYffЎ)setBand rstYffЎ)set='i.5S>K`y cmr10The.settingUUprogramsandalgorithms.qWithintheprogramenvironment:ƝJ81.WNewlinesUUaresigni cant;2J82.WEach:lineisinmathmoGde,@/soforexamplespacesintheinput learenotWsigni cant;J83.WTheUUcommand\\withinalinecausesanextralinebreakintheoutput;J84.WTheUUindentationofeachlineiscalculatedautomatically;J85.WT*ocauseextraindentation,Qusethecommands\tabtosetanewtab,andW\untabUUtoremoveUUit(seetheexamplesbGelow);J86.WV*erticalbarsareusedtodelimitlongvqariablenameswithunderscoresW(andUUotherunusualcharacters).ƝMtesting?|inverbatim>testing?|inverbatim1*y?MHereisasmallprogram:f/p0J cmsl10 rstffset+:=bu cmex10 zJ b> cmmi10x8 !", cmsy10jx^ٓRcmr72S+8y1C>0b Itshowshowto >typGesetmathematicsaspartofaprogram.SinceeachlineistypGesetinmaths>moGde,allspacingisdoneautomatically*.8Thesetbracketsexpandautomatically,>forexampleinthisprogram(whichalsodemonstratesthe\taband\untab>commands):>t:=^ $x8j<$ȵxȟwfe (֍:y&/=z?^AԲ;l>t:=t8nu;>z7:=a8+b+c+dZ+8e+fLo+gZ+8h+i+j;>if>feSH x=0UUthenUUfeN/y":=0UU UUfec㑍MY*ou8canusevqariableffnamesJtintextormathmoGde:ٌvqariableffnameD2M`=:2.>NamesUUcanhaveUUoGddffcharacters:!@#$%^&*:;fflikeffthis!.N8MNotethat\(and\)arerede nedtotypGesetaprograminaminipage.?J(This>isNusefulinrunningtext,Portokeepashortprogramallononepage).oThereis>somenotationforsequences:rhx1|s;x2;:::;x 0ercmmi7nq~iKJ9andforuniversalandexistential>quanti ers:qǸ8x:9y[:y">xUU(yes,Iusetheseinmyprograms!)MI}oftențusebGoldletterstorepresentprogramfragments,lformulasetc.˙soI>haveBsetupcommandsS /β,RVhaveoneargument(asubscript,egS!1 a,S {2 ,S {23a)orasequenceof\prime"charac->ters:S ip O!cmsy70 7,S p00000òetc.*If~youwantbGothasubscriptandoneormoreprimes,thenyou>must݌usemathsmoGde,egSp A0p A2Considerthedi erencebetween݌typing``\S2''>whichgives\Sc2 "and``$\S2''$''whichgives\Spc00pc2 ".^OutsidemathsmoGde,(%\S>assumesUUanyprimesafterasubscriptareeitherclosingquotesorapGostrophes.MHere.varetwo.vprogramexampleswithdi erentindentationstyles.dNotethat>allUUindentationiscalculatedautomaticallyineitherstyle:>if>feSH TP 1H thenH feNaKifaKfeSkTs2kthenkfeNʖifʖfeS>T;3>then>feNSm4elsefeESn3ʖ ʖfecp/elsep/feEʗS.#2aK aKfecLJLelseLJLfeEaLShH؟1> >fecDc;>if>feSH TP 1WmthenWmfeNqifqfeS{T2}then}feNn ifn feSxTxş3JthenJfeN%0S߈4Ê1elseÊ1feE%1S߈3Z Zfec!else!feEn!Sѭ2u ufec\else\feEqSx1e efecO;2,y?MNotethatthenfeNQandelsefeEpshouldbGeatthe0': cmti10startofaline(asintheexam- >plesabGove),-2notattheend.wThisissothatyoucanlinethemupinshortiffeS>statements,UUforexample:h>if>feSH x=1UUthenUUfeN/afflongffproGcedureffnameSW(arg1;arg2a2;::: UO)g elseg feE}G anotherfflongffproGcedureffname(arg1;arg2a2;::: UO)UU UUfec>IfUUthetestislong,thenyouprobablywantanextralinebreak:>if>feSH afflongffbGooleanfffunctionffname?z(arg1;arg2a2;::: UO)H thenH feNaKafflongffproGcedureffname(arg1;arg2a2;::: UO)LJLelseLJLfeEaLanotherfflongffproGcedureffnamee!(arg1;arg2a2;::: UO)UU UUfec>Comparethiswiththefollowing(whichhaslinebreaksinthe\wrong"places):>if>feSH afflongffbGooleanfffunctionffname?z(arg1;arg2a2;::: UO)UUthenUUfeN1lafflongffproGcedureffname](arg1;arg2a2;::: UO)elsefeE1lanotherfflongffproGcedureffnameӲ(arg1;arg2a2;::: UO)UU UUfecMJustutoshowthat|stillworksnormallytoindicatetheplacingofvertical>lines)UUinthepreambleofatabular(orarray)environment:эML͉fffdͤ ff͟fdStatemen9t ffE Conditions͟ ffff͟ ff.؟fdS4dc1?0 ffE BM@1W ff ͟ ff.؟fdS4dc2?0 ffE BM@2W ffff.f>2VLPros3ceduresffandFfunctions5S>T*urning5onlinenumbGering5here.MAlsousingthealgoritmenviroment5tonumber>theUUalgorithmswithinthesections.>AlgorithmT2.1hM1t}\cmti71WAUUfastexpGonentiationfunction:M2WbQeginWfeOuNforuNfe i:=1UUtoUUfe 8㊲10UUstepUUfeU1UUdoUUfe #M3print(exptbc(2;i));M4newlineQ&()UUoQdUUfe uQM5WwhereWfeێM6WfunctWfet5Nexpt(x;n)mM7a' fbafe<n:efaz7:=1;M8efawhileefafeZXn6=0UUdoUUfe #M9XwhileXfeZOeven8(n)UUdoUUfe #I610On:=n=2;qx:=x8xUUoQdUUfe uQʦ;I611Xn:=n81;qz7:=zwxUUoQdUUfe uQʦ;I612efazp'n:p' fb.I613WendWfe l3Xy?>FirstUUlineisline1,lastisline13.qLine10iswhatmakesthisfunctionfast!荍>AlgorithmT2.2&M1WAUUfastexpGonentiationprocedure: M2WbQeginWfeOuNforuNfe i:=1UUtoUUfe 8㊲10UUstepUUfeU1UUdoUUfe #M3expt](2;i);M4newlineQ&()UUoQdUUfe uQ#ThisUUtextwillbGeset ushtotherightmarginM5WwhereWfeێM6WproQcWfeN2pexpt(x;n)mM7az7:=1;M8adoafe #pxifpxfeSzn=0UUthenUUfeN/exit/fe3 3fec9ꚲ;M9pxdopxfe #iffeSioGddĺ(n)UUthenUUfeN/exit/fe3 3fec9ꚲ;I610commen9tfe- β:qThisUUisacommentstatement4eM;I611n:=n=2;qx:=x8xUUoQdUUfe uQʦ;I612pxfn>0g;I613pxn:=n81;qz7:=zwxUUoQdUUfe uQʦ;I614aprintvf(zp).I615WendWfe l>AnUUactionsystemequivqalenttoawhilefeZ!LloGop:w1=uactions=ufe# A:w2=uAm8if8feSCB&then&feN@SGB;qcallqfe*Aw3-else-feE_-call_-fe˗Z q  qfec o.w4=uendactions=ufe5cm1whilefeZNotertheuseof\(and\)toenclosethetworprogrambGoxes.T*urningo line>numbGersUUhere.N8>DijkstraUUconditionalsandloGops:&>if>feSH x=1UU!y":=y+81> u> tH x=2UU!y":=y[ٟ^2>:::-> u> tH x=nUU!y":=>n X tմi=1㉵yi fec2؍>do>fe #Mx߲2jxq^,x>0UU!x:=x=2Cx޸uCxtMx:2jxUU!x:=jx8+3jUUoQdUUfe uQD^>LoGopsUUwithmultipleexitfeWs:>do>fe #MxdoMxߟfe #\if\feSffBo*1vdthenvdfeNexitfe. .fec;\ScUJ1gѽ;\if\feSffBo*2vdthenvdfeNexitfeȲ(2)UU UUfec 6oQd 6fe uQ;MxifMxߟfeSWB_1gthengfeN^(exit^(fe> >fecnoQdnfe uQD^>IUUhopGeyougettheidea!4'^y?>3VLAffReverseEngineeringExample5S>Here'sUUtheoriginalprogram:N8>AlgorithmT3.1>v\rar>feQhm:=0;p:=0;lastE:=\?"i; HactionsHfe# n`Mprog{:HprogbpRhline亲:=\?";m:=0;i:=1i;RcallRfefllinhere.HlN͸Ri:=i8+1;RifRfeS\ (i=(n8+1))UUthenUUfeN/call/fe1balldoneT Tfec[!;Rm:=1;RifRfeS\ itemo|t[i]6=last\ then\ feNuMwrite(line);qlineVz:=\?";qm:=0;uMcalluMfeQinhere= =fecKɲ;RcallRfefllmore|.Hinherei]Rp:=numbGer$([i];qlineVz:=item8[i];Rlined伲:=lineҲ++#.\?"5E++B]p;RcallRfefllmore|.Hmored]RifRfeS\ (m=1)UUthenUUfeN/p:=numbGer$([i];line:=lineҲ++#.\,?":HB++GpUU UUfec ;RlastdC:=item8[i];RcallRfeflll2`.HalldonemLRwritehk(line);qcallqfe*Z.>7endactions>7fe5c?end?fe lMAndUUhere'sthetransformedandcorrectedversion:>AlgorithmT3.2>hline亲:=\?";i:=1i;>while>feZ[i6=n8+1UUdoUUfe #[linen:=item8[i]++t\?""#++/xnumbGerQE[i];[i:=i8+1;[while[feZy_i6=n8+1q^,item"[i]=item8[i81]UUdoUUfe #y_lineD:=lineҲ++#.\,?":HB++GnumbGerij[i]);y_i:=i8+1UUoQdUUfe uQʦ;[writer`(line)UUoQdUUfe uQMTheseaarethesameprogramsinasans-serifstyle,usingthecommand>\sfvariables:564y?>2kAH cmssbx10varOhm:=0;p:=0;3m#R cmss10lastO:=\?"i; Hactionskeprog:Hprog`7Rhline*:=\?";m:=0;i:=1i;Rcalld[inhere}y.HlN͸Ri:=i8+1;Rif[@(i=(n8+1))UUthen call-alldoneNQ T.E;Rm:=1;Rif[@itemm[i]6=last[@thenr]write'(linec);qlinef:=\?";qm:=0;r]callinhere) Ý;Rcalld[moreyz.Hinhereg#Rp:=numbGer"[i];qlinef:=item*[i];Rlinec*:=line++!G\?"3N1++@p;Rcalld[moreyz.HmorebRif[@(m=1)UUthen p:=numbGer"[i];.lineY|:=line++!G\,?"8.++E㊵pUU 1ɲ;Rlastcj:=item*[i];Rcalld[l2`.HalldonekxRwritef̲(linec);qcallZ.>7endactions:JendN8>hline*:=\?";i:=1i;>whileXvi6=n8+1UUdoXvlinei:=item*[i]++t\?""#++/xnumbGerO1Ͳ[i];Xvi:=i8+1;Xvwhiles8i6=n8+1q^,item![i]=item*[i81]UUdos8linec:=line++!G\,?"8.++EnumbGerep[i]);s8i:=i8+1UUoN9d;XvwritemN@(linec)UUoN9d6A9;yh 3m#R cmss102kAH cmssbx101t}\cmti70': cmti10/p0J cmsl10. cmmi10 0ercmmi7K`y cmr10ٓRcmr7u cmex10H