Page 1

Resolutionofgoalswith the functional andlogic

programminglanguage LPG?

impactofabstract interpretation

DidierBert?R achid Echahed and KamelA di

IMA G?LSR? CNRS?BP??? ????? Grenoble cedex ??F rance

e?mail?fb ert? echahedg?imag?fr

h ttp???thot?imag?fr?Les?Group es?scop?

? Introduction

lpg??? ??b elongs to theclass of languages designedfor softw aresp eci?cation?

rapidprototyping andhigh?lev elprogramming?It allo wsone tode?ne abstract

datat ypes?functionsand predicateswithin oneuni?edframew ork? Hornclause

logic with equality? An implementation oflpg forSUN??SunOS?????isav ail?

ableby URLftp???ftp?imag?fr?p ub?SC OP?LPG? Thelpg calculus? designed

to solve goals?a laProlog? ismainly basedon narro wing techniques? These tech?

niques yieldsemi?decidable algorithms?Recently?we have sho wn in????? how

abstract interpretationmayhelptoimprove theoperational semanticsof lpg?

likelanguages?Inthisdemonstration?we intendtopresentthespeci?cation and

programming styles of lpg asw ell asthe capabilities of the?solv er? augmen ted

withabstr acttermrewritesystems?

?Examplesof LPG sp eci?cations

Inlpg? speci?cationsarebuilt upby compositionof reusable modules?Thereare

three kindsofsp eci?cation modules?namely pr operties? typ esand enrichments?

All the mo dulesare comp osed ofa signaturepartand anaxiomatization part?

The signaturepartisaman y?sorted?rst?ordersignature???S????? where

S isa seta sorts?? isa set ofop eratorsymb ols and? isa setof predicate

symb ols? Theaxiomatization ofop eratorsisac hievedby conditionalequations

whereas the predicatesde?nitions arepro videdby Horn clauses? where thebo dies

ofthe clausesmay includeclassical literals?equations?t ??t?? and?ordisequa?

tions?t???t??? Theaxiomatization is structured intwo lay ers? thealgebraic

axiomatizationof theop erators? like inalgebraicsp eci?cation languages? without

any referenceto predicatesym b ols?andasecond lay erforthe axiomatization

of predicates which can mixall kindsof logicalatoms?Thetyp emodulesare

intendedtode?ne newdatat ypes?The constructorsofdatatypes areexplicitly

given?In Figure?? wede?nethedatat ypeofnaturalswithsomeoperators?Fig?

ure?? whichde?nes thedatatypeof binarytrees?showsanexampleofageneric

typemodule? Theenrichmentmodulesde?nenewop eratorsand?ornewpredi?

catesoverpreviouslyde?neddatatypes? Anenric hmentmaybegenericornot?

InFigure??wegiv ean exampleofagenericenrichmentthatde?nes anequality

Page 2

type Naturals

sorts

nat

constructors

??? nat

succ? nat? nat

operators

max? ?nat?nat?? nat

g?nat? nat

variables

x?y? nat

equations

??max ??? x? ???x

?? max?succ?x?? ????? succ?x?

?? max?succ?x??succ?y?? ??? succ?max?x?y??

??g ???????

??g ?succ?x????? g?x?

end Naturals

Fig? ??Datat ype of naturaln umb erswith some operators?

type BinTreesrequires Formal Sort ?elem?

sorts tree

constructors

empty?? tree?elem?

node? ?tree?elem?? elem?tree?elem??? tree?elem?

operators

height? tree?elem?? nat

predicates

balanced?not

balanced?tree?elem?

variables

i? elem

a?b? tree?elem?

equations

?? height?empty?????

??height?node?a?i?b????? succ?max?height?a?? height?b???

clauses

?? balanced ?empty?

?? balanced ?node?a?i?b?????height?a? ??height?b?? balanced?a??balanced?b?

?? not

balanced?node?a?i?b?????height?a???? height?b?

?? notbalanced ?node?a?i?b????? notbalanced?a?

?? not balanced ?node?a?i?b????? notbalanced?b?

endBin

Trees

Fig? ??Datat ype ofbinarytrees?

op erator???tree?elem??tree ?el em ??? boolov erbinarytrees? Thedef?

inition of thisop eratorrequiresanother equality operatorov erthe formal sort

elem? Thesp eci?cationof thisformal operator isin troducedby thestatement

requires Equality?elem operatorseq??

The prop ertymo dules aredesigned tosp ecify?rst?ordertheories? Such mod?

ules aremainly usedforspeci?cation purp oses? They areused tocharacterize

preciselytheformal parametersof generic modules? Figures? and? givetwo ex?

amplesofprop ertymodules? Formal Sort speci?esthe classofsets andEquality

characterizesalgebras thatconsist ofa set andaboolean op erator which satis?es

theaxioms of ?equivalence?? Moredetails ab outlpg maybe foundin ??? ???

? TheLPG solv er

Inlpg system?one mayeithernormalizetermsusing anabstract machine as

inclassicalfunctionallanguages or solvegoals?alaProlog?Agoalissyntacti?

cally written as?A

?

?????A

m

?????A

n

??whereev eryA

i

iseitheranequation?

adisequation oranyotherliteral?Theop erationalsemantics oflpg??? ?? ??

Page 3

property FormalSort

sortst

end Formal

Sort

Fig? ?? Property ofany datat ype?

property Equality

sortst

operators

?? ?t?t?? bool

variables

x?y?z?t

equations

??x?x ?? true

??x?y ??y?x

?? ?x?y andy? z?? ?x? z? ??true

satisfies Formal

Sort ?t?

end Equality

enrichmentEqTree

requires Equality ?elemoperators eq?

operators

???tree?elem??tree?elem??? bool

variables

i? j? elem

a? b? c?d?tree?elem?

equations

??empty? empty ??? true

??empty? node?a? i? b? ??? false

?? node?a?i?b?? node?c?j? d????

eq?i?j?anda?c andb?d

models

Eq

tree? Equality?tree?elem?operators ??

end Eq Tree

Fig??? Genericde?nition ofequality ofbinarytrees requiring theprop erty ofany data

t ype with?equalit y? operator?

maybede?nedinformally as anextension of the SLD?resolutionwhere syn?

tacticuni?cationhasb eenreplacedby seman tic uni?cation?augmen tedwith

two algorithms forsolving equations anddisequations?The lasttwo algorithms

are based onnarro wing?The current implementation alwa ys selectstheleft?

most atom for SLD?resolution and usesleftmost?innermost narrowing strategy?

Thesearc hingtree maybe constructedfollowingthe depth??rstorbreadth??rst

strategiesaccording to user?sindications? In Figure??we givea sample session?

The readerfamiliarwith narro wing?based algorithms mightbesurprised tosee

thatour solv erdev elopsa ?nitesearch spacefor each of theconsideredgoals?

Actually? mostnarrowing?basedalgorithms will lo opwhen solvingthesegoals?

Our currentimplemen tation oflpg solv erusesa newprocedurethatco operates

withtheclassicalnarrowing?basedalgorithms? This newprocedure?based on

abstraction techniques? tries tov erifytheunsatis?abilityorthe validity ofthe

consideredgoals?For each termt? itpro vides anapproximationA?t?ofthe set of

possiblenormalformsof thegroundinstancesoft?Then?theequationt??t

?

is

not satis?ableifA?t? andA?t

?

?aredisjoint?Suchapproximationsarecomputed

usingabstractrewritingsystems????InFigure??wegive anabstractrewriting

systemwhich isobtained automaticallyfrom theconcrete sp eci?cations ofthe

operators height andggiv en in Figures? and?? In such abstract rewriting

systems? the top operator???s? isaconstant thatstands for allp ossiblevalues

of sorts?

References

?? D?Bert andR?Ec hahed?Designand implementationofageneric?logic andfunc?

tionalprogramminglanguage? In Pro c? ofESOP????LNCS ???? pp????????

Springer?Verlag??????

Page 4

f?g variablesa?tree?nat? i?j?natend

f?g max ?g?i??g?j??????

Nosolution?

f?g max?g?i??g?j?? ????

forallj? nat

for alli? nat

moresolutions?y

No moresolution?

f?g height?a???? ?? true?balanced?a??

a ??empty

moresolutions?y

forallx

?? nat

a ??node?empty?x

??empty?

more solutions?y

forallx

?? nat

forallx ???nat

forallx

??? nat

a ??node?node?empty?x

???empty??

x ??

node?empty?x

???empty??

more solutions?y

No moresolution?

f?g height?a? ??? ??true? notbalanced?a??

forallx

?? nat

for allx ??? nat

a ??node?empty?x

??node?empty?x???empty??

moresolutions?y

forallx

?? nat

for allx ??? nat

a ??node?node?empty?x ???empty??x??empty?

moresolutions?y

No moresolution?

f?g height?a? ??g?i??

foralli? nat

a ??empty

moresolutions?y

Nomoresolution?

f?g end

Fig??? Sample session oflpgsolv er?

??height?empty???

?? height?node?empty???nat?empty????

??height?node?node????tree?nat?tree?????nat?empty??? succ?succ???nat??

?? height?node???tree???nat?node????tree?nat?tree????? succ?succ???nat??

??height?node?node????tree?nat?tree?????nat?node????tree?nat?tree ????? succ?succ???nat??

?? g?succ??????

?? g?????

?? g?succ?succ???nat?????

Fig? ?? Sampleabstract termrewritingsystem?

??D? Bert? R?Ec hahed?and B? M??stv old? Abstractrewriting? InPr ocee dings of the

?rdInternationalWorkshop onStaticAnalysis? WSA????n umb er??? inLecture

NotesinComputer Science?pp???????? Springer?Verlag? ?????

??D?Bert?R? Ec hahed?and J??C?Reynaud?Reference man ual of theLPG speci?ca?

tion language and environmen t? ftp???ftp?imag?fr?pub?SCOP?LPG??????

?? D? Bert andR? Ec hahed?Abstraction ofconditional termrewritingsystems?In

J? Lloyd?editor?Pro c? oftheInternationalSymposium onLogicPro gramming?

ILPS???? pp ????????Portland?Oregon?????? MITPress?

??D?BertandR? Ec hahed?On the operationalseman tics of thealgebraic and logic

languageLPG?InRec entTr endsin DataT yp es Spe ci?c ation?LNCS????? pp

???????? Springer?Verlag? ?????

??R? Echahed? Surl?int? egration deslangages alg? ebriqueset logiques?PhD thesis?

INPG?Grenoble??????