您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > Proof for Functional Programming
ProofforFunctionalProgrammingToappearin:ParallelFunctionalProgrammingSimonThompsonDraft2{August19981IntroductionInthischapterweexaminewaysinwhichfunctionalprogramscanbeprovedcorrect.Foranumberofreasonsthisiseasierforfunctionalthanforimpera-tiveprograms.Inthesimplestcasesfunctionalprogramsareequations,sothelanguagedocumentsitself,asitwere.Beyondthisweoftenhaveahigher-levelexpressionofproperties,bymeansofequationsbetweenfunctionsratherthanvalues.Wecanalsoexpresspropertieswhichcannotsimplybediscussedforimperativeprograms,usingnotationsforlistsandotheralgebraicdatatypes,forinstance.Apartfromthegeneralobservationthatproofscarryoverdirectlytoim-plicitlyparallelfunctionalsystems,whatistheparticularrelevanceofprooftoparallelfunctionalprogramming?Twoparticularpointsareemphasisedinthischapter. Lazyevaluationgivesin niteandpartialdatastructures,whichcanbeviewedasdescribingthedata owingarounddeterministicnetworksofprocessesCross-referencetoLoogen’sSection3.3.1here.Sec-tion8.3givesaproofthataprocessnetworkproducesthelistoffactorials;thebisimulationmethodusedhereformsalinkwithveri cationtechniquesforprocessalgebras,whichgiveadeclarativetreatmentofparallelismandnon-determinismandwhicharesurveyedinSection8.4. Thereisanimportantthreadinthedevelopmentoffunctionalprogram-ming,goingbackatleasttoBackus’FP[2],whicharguesthatitisbesttoeschewexplicitrecursionandtoprogramusinga xedsetofhigher-order,polymorphiccombinators,whicharerelatedtoprogrammingskeletonscross-referencetoskeletons.Thepropertiesofthesecombinatorscanbeseenaslogicallawsinanalgebraofprogramming[4].Theselawscanalsobeseentohaveintensionalcontent,withatransformationfromleft-toright-handsiderepresentingachangeinthecostofanoperation,orintheparallelismimplicittherecross-referencetocostmodelling.ThistopicisexaminedfurtherinSection9.3.1Theequationalmodel,exploredinSection2,givesthespiritoffunctionalprogramveri cation,butitneedstobemodi edandstrengthenedinvariouswaysinordertoapplytoafullfunctionallanguage.Thepatternofthechapterwillbetogiveasuccessionofre nementsofthelogicasfurtherfeaturesareaddedtothelanguage.Thesewelookatnow.Thede ningformsoflanguagesaremorecomplexthansimpleequations.Section3looksatconditionalde nitions(using‘guards’),patternmatchingandlocalde nitions(inletandwhereclauses)eachofwhichaddscomplications,notleastwhenthefeaturesinteract.Reasoningcannotbecompletelyequational.Weneedtobeabletoreasonbycases,andingeneraltobeabletoprovepropertiesoffunctionsde nedbyrecursion;structuralinductionisthemechanism,anditisdiscussedinSection4andillustratedbyacorrectnessproofforaminiaturecompilerinSection5.Withgeneralrecursion,examinedinSection6andwhichisafeatureofalllanguagesinthecurrentmainstream,comesthepossibilityofnon-terminationofevaluation.Inalazylanguagegeneralrecursionhasthemoreprofounde ectofintroducingin niteandpartiallistsandotherdatastructures.Inbothlazyandstrictlanguagesthispossibilitymeansinturnthatinin-terpretingthemeaningofprogramsweareforcedtointroduceextravaluesateachtype.Thisplainlya ectsthewayinwhichthelogicisexpressed,anditsrelationtofamiliarpropertiesof,say,theintegers.ThebackgroundtothisisexploredinSection7.Section8givesanoverviewofthetwoprincipalapproachestogivingmean-ingstoprograms{denotationalsemanticsandoperationalsemantics{andtheirimplicationsforprogramveri cation.Aproofofcorrectnessforafunctionde nedbygeneralrecursionexempli esthedenotationalapproach,whilstop-erationalsemanticsunderpinsaproofthatalazyprocessnetworkgeneratesthelistoffactorials.Thislastproofformsalinkwiththeprocessalgebraapproachtoparallelism,whichisalsodiscussedinthissection.Becauseofthecomplicationswhichnon-terminationbrings,therehasbeenrecentinterestinterminatinglanguagesandtheseareintroducedinSection9.OfparticularrelevancehereisthetransformationalapproachofBackus,Birdandothers.Afully- edgedlanguagewillallowuserstointeractwiththeenvironmentinvariousways,butatitssimplestbyreadinginputandwritingoutput.Thisissupportedinavarietyofways,includingtheside-e ectingfunctionsofStandardMLandthemonadsofHaskell1.4.SMLalsoallowsmutablereferencesandexceptions.Inthischapterwecoveronlythepurepartsoflanguages,butreferreadersto[6]foraperspicaciousdiscussionofprogramveri cationforvariousformsofinput/outputincludingmonadicIO.RecentworkonmodellingSML-stylereferencescanbefoundin[15].Thischapterdoesnottrytoaddressalltheworkonveri cationofparallelimperativeprograms:Sections8.9and8.10oftheexhaustivesurvey[5]morethandojusticetothistopic,andputitinthecontextofimperativeprogramver-i cationingeneral.Ontheotherhand,linkswithprocessalgebraareexaminedinSection8.4.22Thebasisoffunctionalprogramming:equa-tionsInthissectionweexaminethebasisoffunctionalprogrammingandshowhowthede nitionsofasimplefunctionalprogramcanbeinterpretedaslogicalequations.Anexaminationofhowthisapproachcanbemodi edandextendedtoworkingeneralformsthemainpartofthechapter.Afunctionalprogramconsistsofacollectionofde nitionsoffunctionsandothervalues.AnexampleprogramusingthenotationoftheHaskelllanguage[14]istest::Integertest=42id::a-aidx=xplusOne::Inte
本文标题:Proof for Functional Programming
链接地址:https://www.777doc.com/doc-4382707 .html