ebook img

Programming for Mathematicians PDF

434 Pages·2000·4.408 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming for Mathematicians

Raymond Seroul Programming foMra thematicians Translfartoetmdh Fer ench by Donal O'Shea Wit4h0 F igures Springer RaymonSde roul UniversLiotueiP sa steur U.F.dRe.M athematiqeutde 'sI nformatique 7,r ueR eneD escartes 6708S4t rasbo,uF rrgance e-maisle:r [email protected] Translator: DonaOl' Shea DepartmeonfMt a thematics MountH olyokCeo llege ClapLpa boratory SoutHha dleMyA, 0 1075-1U4S6A1 , e-maidlo:s [email protected] Titolfte hF er ench original edition: math-Iinnffoor.m paotumiraq tuhee mat© IinctieernEsPd.ai rt1ii9so9,n5 s., LibraorfyC ongreCsast aloging-in-PuDbaltiaacp aptliifoeondr DieD eutscBhieb lio-thCeIkP-Einheitsaufnahme Seroul, RParyomgornamdm:if nogrm athematicIiR aanysm onSde rouTlr.a nsf!r.o m theF rencbhy D onaOl' She-aB.erliHne;i delbeNregwY; o rkB;a rceloHnoan;g K ong; LondonM;i lanP;a riSsi;n gapoTroek;y oS:p ring2e0r,0 0 (UniversiItSeBxN3t )- 540-66422-X MathemSautbijCcelsca ts sifica0t4i-o0n4 ,(6189-9011) : ISBN3 -540-6642S2p-rXi nger-VBeerrllaign HeidelYboerrkg New ©Springer-VBeerrllaign Heidelberg 2000 PrintiendG ermany Preafce Wea raesd wravseist otnti ehns gh lodueorfg si saW.ne ts eteih ntgahst ardee eoperfurr ht enr,o btyt ehp enteitoorafno uorw nvi soirbo yn ouorw n h,be uibtge hctatuhseey suusap npldoe rnutsdt e hihreg ih.t Berndad reC hartrecse ntury) (Xl/1h Ib ecaimneetr esitnce odm peurst cieinntc he1e 89 0'asft tewre nyteryaso f prcaticmiantgh eimcwasht etnh fier msitoc cormpeurtasp peedaA.rt t htiism e, thee wrasm uchhy pe ahbooweu atsp yr oagmrmiwnag.s S uppoesd,lo yne coullaedr init n e igdhyats! Ie xamdi ntaehvelab ailleti erea taubnredc aqmueeid tiisulslnieodTh.be ooks thorugwhh iIcl hae fewde rneoh tinbgud tsi matlr meeatnotfss y anxt atnhdo se cotnaniinpgr ogrdaimndso e tx plhaoiwtn h epsoreg rawmeserc eraetdT.h ere werseee vrmaolr aemb tiiobuoso kvsey,rf omra,lw hischho wheodw coonuel d deduacnae gl otrhibme ngniiwnigta hni vnaarniotfs omleo oIpd .in do fitn d these vbeyor cooknscv iinntghi:era p oparhcs eemedf omtrao,lto o hoe a,v y antdo cou otf ffr ormel ayi.Bt upte hrapIs waso ltdHo?oo w eevrd,i scussions witmhyc ollaeguceosvn nicemdet hparteo sfsipornoaagmlmr erdson owto rk in this way. Thewraeas r itIf:w oludh avteol eaavw eo drw lhiIck hn ewwe ltlofi nd myw aym,o sotf the htoiuamgt eu iwidineatu ,n viesrew ith alnavdwa sl ues 1 thwaetr feo irgetno amnetd h Ian te edteoud nd erasntd. Aftaenra pepnrticoefss ehviaeplyr erasI,b egtaont eapcrho gmrianmtgo studientn htiesr dty heiaorrfm athecms(a wthiiwcech a tlhlLe i ce)nI.wc aes veryp rssieutdro fi ndt hamta nwye rfear nkhloys ttiocl oem pusticeern ce. Aftteakrli ntgot heImr ,aei lzetdh tahtie hro slytiw itasar etaictoont hwea y that htahdbe eyet nag uhth:o w coanne rnlt ehaseu btloefat liaeunsag ge orc ondaur cfietne da nlaysoifts h pee orrfmanocfae na lgorwihtehonmn e 2 canneovtew nr iatp er ogrsaemvaellr iensi nl engMtygh o?a ble catmoee n tice thset udbeyns thsoi wntgh etmh tath ey vceoyruq ludi cwkrliyit neeetr sting progrkanmosnw goi nlvyey r ftecewh niqfuroecmso mpeurst cience. 1A nyi dniivdual hawbshe oe enxl ieodr w hoh arsda iclaycl hagnedp reosfsiwoinl l knowwh ta amt alkaibnogu t. I 2T heryme indemde osfo moef t huen happpyrc aticoefts h "en emwa thetmiacs" whicphr etetnodt eeda rcihn sgt ructtous rteusd ewnhtohs ad not myasette rtehde ir multiicpalttialobens . Them odemma thteimcaiisca onn demtnope rdo g.rB aumhto w doonees lerna top roagmr?T his aisd sifi fcualslt er ainnhgo wt od op ro!oA fnsd, in botcha stehsee,i r sn om ethod. Litbtyll eti ltmey,i edabse cacmlere eaarn d bmayc okugnradsa m athe­ matibceigatanon h elTphi.sb o oikst hferi uotf t haaptep nrticaenstdhh iapt syhnestiIsit.ts h beo ok Iwt ohuahtla dv leie kdt oh avhea wdh eInb eg.aI nits meant for thaonis tner uowcdhtoti opow rnao angmtrm iwnight ournteo uncing thierma themabtaicockuaglnra dn d wwhaont toh ramnoiouistnleaygt rteh is newd isciipnolt tihneei ro ftw haoyu ght. Howe,v emara thteimcaciaarnnpa idcloyvn etrt haebi ilttyoc eratper oofs tot haer otfp rogmrianmigf ftolhloew itnwgco ondiatrifeoul nllsfie ld: he sohrhe a asc laeri deoafw haatc ompeurit sw,ht ai cta n adnowd,h at • icta nndoot. he orl ersanhtseot hidnyakn mcilaly. • Mathemartseiuclcatalsbn e r oguhldyi veidid not twcoa lsses: starteiscuC lratemsrf:'o smr ul"at,he ee xrixss tu cthh Patx( ")t,h dee fin­ • itiooftn hg eer atceosmtm odni ovri satnhBdee zout tI=h eauo+ rbvee,mt c. dynamriseclu tGsa:u sspiiavno tainen xgip,cl ciotsn turctioofn e alne ­ • menxti nas eEts astyfiinpgr opePr,Etu cyl iadn'Bdsl n akihnispag'lostr hims thcaotm peut htGeC Da ntdh neu bmerusv, i nB ezuott'hsee omre,t .c A trdaiitonmaalt hteimcatiihannks tsa tliysc;ya sltedmyaanmtiitccha iln king isan ewd isicniweph losdee velohpamcseo niitnd cewdih tt hoaftc omputer scieCnocvneet.ri fnrgo m sttoda ytniacm tihcianlik sni onetga sy s(oamned winlelv meark teh ter saiinot)n. Expieernscheo wthsaw tri tiang go opdr ogriaesmv emno rdeifi fcutlhta n writianp gr oboefc atuhseej ceotbtsh aotn ceo nesriasdr leki et ibnayr osf westo :at phesiyld bee twoene'ens g efi.rnP srogmrianmigos f tseynn onymous wiht "foolianorgu ndw"h icmha keistd iassttuelaf ndof tena lzypianfrgo r mathteimcaiaacnusst toomo etdh er dsst.a ndar Weu saev eyrs tridpopwepndor garmmilnnagg ugea( asseingttnsem,sa tnsd looapnstd)h e res tarndpd raogmrianmtgce hniques: reycclianngrd we riticnogd e • desncdeianngla ysainssd u cscseirvfieene ment • thues oefs equetnoac lelsoo nwte o t ransafd oyrnma mpiorcballie mno t • as taptriolcbe mmo erf mailrti oma athteimcasi.a n Ip lcae eeqmupahla osnti hsae e sthseitdAie mc.a thteimncaa ilawaeyxs­ peirencpreoosuf nsdas tfitaicoonns tudayb ienuagtu iltf heyoo rrp rooTfhi.s isw hyh eo r sphrcaet imcaetsh eimcaIswt .a nttoc onnvcimea thteimcaians that they will efeexlpgiesunr pioeannn ycazeli antnghd e t issuenaptgam ne algiotrhemv,ea nv eyrs impolnee . Theu soef c ompeurctser atneeswo ri,ns omiesn tanrcseeusst,ca itoelsd porbleimnms a theimc(asht omwu cshp ascheo uolndre se erivnem emyo r fotrh dei ovriss ag oifv ienengt enr? a)n d ceorms pcuite(nicenesv tigating algtohrmipsor,v ipnorgg ra)m.Tsh isb oobke awrist nteots hsii tsne crtai:o n tot hpel eeat shuee rrisp roignmr ianmmga tmhaetiacnstd ot hpel eraeos fu reoansiwnhge onn per oagmrs. Sicnef omre p rogmrianmdgo ensom te adne niynmgy fi rlsotv tehr,ei gorous sidtea kpersi oorvietarm y o rdeea tidl setuodfya p roagmrminlgna guage. Whenepvosesri bItl aek,te h oep ptonuriy ttop ersemnatht emattihcamsty studenntoskt n od.Fwo o trh riaess ,oo nnfien dmsa nmya themarsteuiclatls anpdr ooifnts h bioso k. Mosotfa llt,h bioso iksa m ieda tu ndgerruaadtweihsts ommea thematical bacokugnrIdwt.i alllbs eoo fi nertetsott h owsihets ommea htemattirncaiainlg whow ihs( onre e)t dob egipnr oagmrmnig. Fohrsi tcoarrlies aonPsa,s ictashl le ag nuaugsee Bdu.tti h bso oiaksb soyl utel noat troenat thPieas selc aanlg uCoavngeseri.ot noam oerm odelma unagge isis ntantsao:nn eneoe ued hoanvalesy s igntmeesantntslds o ,o ps. Acknoewdlmgeents A bookl ieia ksni cegb.Te hrea uthiosr otnhlepy a rtth aetm egresO.u to f sightth oawsrheeoi s npeidar nd hwehelodp oitnhw eayrs A.m ong lttatheirs groaurpte h feol lowiwnhgo mIw ouelsdp iealclyl iet kot hank. The IaRtES rMtsa boguw rhiacllohw emde a ccetsots hc eo luomfnt sh e • rveielOw'u evtrt,h eraelblyo mwei nrgtfieo n mey i deas. Altlh ceo elalguaensfdr e indwsh oh avfeol lwoedt hceo urisnpeo rsg ram­ • mintgh aIht a ve ttahuogwshiehtt w,h omIh avdei scedum sasttaebrosu t whiIcc ha rdee e,pa lnytdh owsheo hgaivveme ena dvicaeb otuhtbi oso k. Thset undtmesaj roiingnm a theimcaastSt r tsabogu,or nw hoImt eesdat nd • rfiened mieyda fso orv etrey ne aWrist.h outf eetdhbeaitcrhkb i oso k would nevhearv e tshelegei hnot f day. FinlayIl,w oullkdie t o tthhatenrk sa alntoDro,n aOl' Sehao,f M ount • HoylokCeol elgfeo hri esxe cllweonrtk . Raymond Seroul UnviesreiL toiuPsa st,e ur UFRd eM atheqmuaeetstid I'nofrmtaique 7r uRee nDee stceas6r,7 08S4ta rsbgoC uErDE(XrF nace) seoru@lm at.hus-tasrbgr .f Contents 1.P rogrammiPnrgo ver.bs . . . . . . . . . . 1.1A.bo vaeln lot, ir c!k s. . . . . . . . . . 12..D on octh ewgiunmgw hicllebi imnsgts a ir 2 13..N ame wthhiayctoh su i tldlo' nktn ow. . 2 14..T omorrotwh,ni gwsi blelb etttehre ;a dfatybe ert,st lteilr 2 15..N eveexre caunot red beerf oirteg viiesn 3 16..D oucmetnotd taoay v otieda trosm orrow 3 17..D estcsea'Dr iscsoeou ntr hMee thod 3 2.R evieowf A rithmetic 5 21..E ucleiadDni viiosn 5 2.2N.um ertaiSoyns tems 6 2.3P.rm ieN umber.s . 7 2.13T..h en umbeorfp irmessm altlheaarng ivreenan lum be.r 8 2.4T.h eG resatt eComDmiovonir s 9 2.14T..h eB ezoTuhte orem 10 2.4G.au2s.s L'esm ma. . . . 10 2.5C.o nugenrce.s . . . . . . . 11 2.6T.h eC hinReesmea iTnhdeeorr em 12 2.7T.h eE ulpehrFi u ncti.o n. . . 14 2.8T.h eT heeomrso fF ermaantEd u ler 15 2.9W.il osn'Tsh eor.e m . . . . . . . 16 21.0 .Q uaadtrRiecs id.u es. . . . . . 17 21..1 PrmieN umbaenrSd u mo fT woS qursae 18 21..2T heM obeiuFsu nct.i on 19 21..3T heF ibcoicnN aumbers 21 21..4R eaosnibnygI nduction 22 21..5S olutoifto hnEesx ceriess 25 3.A n AlgorithDmeiscc riptLiaonng uage 29 31..I ednteirfis. . . . . . 30 3.2A.ri thmEextpeirscs i.o ns 31 3.12N..u mebrs. 31 3.2O.p2e.ir aotns 31 3.2A.rr3a.y s 32 32..F4u.n ctcialolsann pda erntheses 32 3.3B.oo leane sEsxip.or ns 32 34.. Satetmenatnstd h eira xS ynt 33 34.1.A.s siegnntms 34 3.4C.o2n.d itionals 34 3.4F.o3lr.oo ps. 35 34..W4h.i llooep .s 35 34...R5 epelaootp s 35 34..S6e.q ueonfcs etesam tents 36 3.4B.l7co.ko sfs a ttmeents 36 34..C8o.m lpesxt maetents 37 34..L9a.y oount paangcdeo tnrols ytonaf.x 38 34.1.0 .To w hadto etshe ele bs elong? 40 3..41S1e.mo ilcosnosm:ce ls asiecrarlo rs 40 3.5T.h eS emanotfSi atcetsm ents 42 3.15A..s siegnntms 42 3.5C.o2n.d ist ional 42 3.5F.i3rt.sr stal tnaio.n s 43 3..54T.h eb outorsphedorodne r 45 3.5T.h5ef. ol ro op 47 3..56T.h ew hile loop 48 3.5T.h7er.p e ealto op 50 3.5E.m8b.e dldoeodp s 51 3.6W.h icLho otpoC hoose? 51 3.16C..h oionsag flooorp 52 36..C2h.o ionsagw hilloeo p 52 3.6C.h3o.io nsagr peealotop 52 36..I4sn.p cetienntgar ncaensed x its 52 3.6L.o5o.pw sih t caicdents 54 36..G6a.u sseilainnma ition 55 3.6H.o7wt. o g arbd ata 56 4.H ow toC reataen Algorithm 59 41..T heT raocfea nA lgoirthm 59 4.2F.i rMsett h:Ro edclyicKnngo wCno de 60 4.12P..o tsagset amps 60 4.2H.o2w.t o d etmeirnweh etahp eors tiasrgae eil azble 61 4.2C.al3c.ut iltnahgte he rshovladl ue 62 4.3S.e coMnedt h:Uo dsiSnegq uences 64 4.13C..re atoifoa ns ipmlaegl otrhim. 66 4.3T.h2ee. x poinaeslne tries 67 43..D3e.c oomspitiinoop tnrm ief atcors 69 4..34T.h e ldeiavosrift snu ction 71 43..C5a.dr ilniyato fa ni nertsteicon 71 4.3T.h6eC. O RDIAClg otrhim. . . . 74 4.4T.h diM reth:o dDefWerirteid.n g . . . 78 4.14C..al culatwtboi inrzgra fenu ctions 80 4.4S.ot2r.a ogfet hfier Ns tp rinmumeb ers 81 4.34.L.a srcteo mmetnidoans 84 4.5H.o w Ptorov aen A lgotrhim 85 4.15C..ra she.s . . . . . 85 4.5I.n2fi.enl iotop.s . . . 85 4..53C.al culathtGeiC nDgo ft won umebrs 86 4..54A. m orceo pmlitecedax amp.l e . . 86 4..55T.h ev aildyio tfa r seuflutirn hsed abl yo op 87 4.6S.o lutoifto hnEesx ceriess . . . . 88 5.A lgorithamnsd C lassiCcoanls tructions 91 51..E xcnhgaitnhgCe o nteonfTt wsoV aarbiles 91 5.2D.iv esreS um.s . . . . . . . . 9.2 5.12A.. v eyri mpotracnotn vention 92 52..D2o.u bsluem s. . . . 93 52..S3u.m wsih te xceptions 94 5.3S.e rcahifnogarM aximu.m 95 54.. SolvaiT nriga ngrC urlaamSeyres mt 96 5.5R.ap iCdal ctuilooafnP ower.s . . 97 56..C alctuilooafn Ftihbeo nNaumcbceir s 98 5.7T.h eN otioofan S atck. . . . 99 5.8L.ni eaTrra verosfaaF lni ieS tet 101 59..T heLe xcioagphriOcr de.r . . 120 59.1.W.o rdosffi xeldeg nth 120 59..W2o.r dosfv aarbilleeg nth 140 51.0 .S oluttioto hnEexs ce riess 150 6.T heP ascaLla nguage. . . . 190 61..S taogre tohUfes uOabjlc ets 190 6.2I.ne tgeArri thmienPt aiscc al 101 6.12S..ot raogfei netgeirnPs a scal 101 6.3A.rr ayisnP ascal 131 6.4D.e lcraaitoonfa nA rray 141 6.5P.r oudcSte tasnT dy pes 151 6.15P..or duocfet q usaelt s 151 6.5P.r2ou.dc otfu neqsueatls 161 6.5C.o3m.p otsyiptees 161 6.6. TheC oRnosltea notfs 171 6.7L.ti te.r . . . . . . 191 6.8P.r eodceusr. . . . . 191 6.18T..h ed eacrltaipvaero tfa p reodceu r 102 6.8P.r2eo.cd euc rlals 121 6.8C.o3m.mn uciatoifoap n r eodceuw ritthhe exe trior 122 6.9V.is ilbyiio tf Vtaharebi lienasP orceed ur 142 61. 0C.o ntEefxeftc t.s . . . . . . 152 61.0 1.F.un ctio. ns. . . . . . . 1.72 . 61.. 02P.or ceedo urfr nuction? 182 61.1P.r eocdeusrW:h at Ptrhoeg rSaeme mTosD o 192 61..11U.si tnhge mo.d el 133 61..2S olutoifto hnEesx ceriess 143 7.H ow toW ritae Program. . . 153 71..I nrvseea no fdO er4rM atirx 153 71..T1h.ep rolbem 163 71..2T.h eeotrisctauld y 163 71.3..Wr ititnhpger ogram 183 71 4...T hefun ctdieo.tn . 104 71.5..Ho wt ot ypaep rogram 134 7.2C.ha rcatsetrPiiocl ynoomfai M aalt rix 144 7. 21.T.h ep rogrLaevmer rier 174 7.3H.o wt oW rtiea P rogr.a m . 125 7.4A. P oorWlrtyit Peornc eed ur 165 8.T heI nteger.s . . . . . . . . 195 81..T he lEieudacAnl ogirth.m . 195 81..C1o.m pleoxfti htEeyuc leiadanl gorithm 106 8.2T.h eB lnakinAslghoitrphi m. 161 8.3P.e rfNeucmteb rs. . . . . 136 8.4T.h eLo weDsitvo irFs unction 156 8.5T.h eM oeibuFsu nct.i o.n . 176 8.6T.h eSe ivoef E rasttohenes 196 8.16F..o mrultaioofnt hael gorithm 171 8.6T.r2a.n sifnotgrh mael giotrhtmoa p rogram 127 8.7T.h eF unctpiio(nx. ). . . . ... . . . 157 8.17L..e gneder'fso rumla. . . . .. . . 157 8.7I.m2ep.ml entaotfL ieognnede r'fsom rula 187 8.7M.e3i.s' sfseo mlrula 197 8.8E.g yptFircaatni ons 181 8.18T..h ep rogram 138 8.8N.um2e.cr airlse ults 168 8.9O.p eartioonnL sa rIgtnee gers 178 8.19A..d dit.i on. 178 8.9S.ub2ta.rtc io.n 188 8.9M.u3l.ti icpaltion 198 8.9D.e4ac.rlt aions 109 8o59oToheprogr0a m 0 0 0 0 0 0 0 109 10 0 81000D isviioinnB aseb 0 0 0 0 0 0 0 01 490 0 0 810O oloDe sicprtoifot hnde i sviioanl gorithm 149 80010J20u sctaitfioifot nhd ei vioiansl giotrhm 169 81000E3f0ef cteisvmteai toefsi netgepra rts 179 8100.04 A gdoioivdoia nsl giotrh0m 0 200 81001 SumosfF ibonNaucmcebir s0 0 0 0 200 81020O dd mPersai sa S umo fT woS qursae 203 81003 SumosfF ouSrqu are0s 0 0 0 0 0 0 207 81004 HighCloymo pseiN tumber0s 0 0 0 208 81004.1S eevrparlo tpieoerfsh igcholmyp eon sumibters 210 810402P0rc atiicneavslt igoafht iigochnol myp eoi sneitgters2 12 81005 PermtuitoaJnosh:n 'ssAo'lgn oirthm 213 81005.1T hep rogJraomh nson 215 81006T heC ouinGtso od 218 810061S0y antctitcr ees 219 9.T heC ompleNxu mbers0 0 225 90 .1 The GauIsnestgiearns 225 910.1E.ulc ieaddni ivsion 226 910.2I0rre duicbl0e s0 0 226 9103.0T hep rogram 231 902B0a soefsN umertaioinn Gtauhes sIitnaeng ers 234 9012T00h em odulboe tmaa p 0 0 0 0 0 0 02 34 902H0o2w0t ofi nadn e xact osfyr pseertseemtn itva0e s 235 902N0u3m0e riaotsny stienbm a se 0b et0a 0 0 236 90.24A0n a lgorfioterhx emps rsiionbn a sbee ta 237 903M0a chFionru mla0s 0 0 0 0 0 0 0 02 400 90013U.n iqueonfea Ms asc hifnomr ul0a 242 903P0r2o0oo fPf r poosi9t30i10o n0 0 0 243 903T0h3eT0 o dcdo ndiitsnie ocsnea sry 244 90.34T0h eTo dcdo ndiitssi ufiofcni ent 244 903K0e5rn'0a sgl ori0t hm0 0 0 0 0 0 245 903H0o6w0t og erti odft hAerc tanfgunecntti on 249 903E0x7a0m ples 251 10P.o lynomia0ls 0 0 253 1001D0efi niiotn0s 0 253 1002D0e gereo fa P olynomial 254 1003H0o w Stotor aeP olynolm ia 254 1.04T0h Ceo nvenwteiA odnosp t 256 1.05E.uc leiadDni sviion 259 1006E0v aluoaftP ioloynn olmsHi:oa me'rMse thod 261 100 7T ra0n slaatnCido omnp iotsi0o n 0 0 0 0 0 02 62

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.