UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Eksamen i INF 3230 Formell modellering og analyse av kommuniserende systemer Eksamensdag: 4. juni 2010 Tid for eksamen: 9.00 12.00 Oppgavesettet er på 8 sider. Vedlegg: Tillatte hjelpemidler: Ingen vedlegg Alle trykte og skrevne Kontroller at oppgavesettet er komplett før du begynner å besvare spørsmålene. Oppgavene og deloppgavene kan til en stor grad løses uavhengig av hverandre. Om det er en deloppgave du ikke har løst, så kan du anta at du har løst den og kan prøve å gå videre i settet. Legg vekt på å finne enkle og elegante løsninger! Poengtallene angitt i parentes for hver oppgave er veiledende. Alle svar skal begrunnes godt! Alle hjelpefunksjoner, sorter, etc., du trenger må selvfølgelig defineres fullt ut. English! This exam is given in English after the Norwegian part, from page 5 onwards. (Fortsettes på side 2.)
Eksamen i INF 3230, 4. juni 2010 Side 2 Oppgave 1 Terminering og konfluens (32 poeng) Vi skal i denne oppgaven se på spesifikasjonen E = {x (y + z) = (x y) + (x z), (x + y) + z = x + (y + z)} 1. Kan den leksikografiske stiordningen (lpo) bevise at E terminerer? Bevis (eller begrunn godt) ditt svar. 2. Kan multisett stiordningen (mpo) bevise at E terminerer? Bevis (eller begrunn godt) ditt svar. 3. Finnes det en forenklingsordning som kan brukes til å vise at E terminerer? Bevis (eller begrunn godt) ditt svar. 4. Er E konfluent? Bevis (eller begrunn godt) ditt svar. Oppgave 2 Definere den leksikografiske stiordningen (lpo) i Maude (72 poeng) I denne oppgaven skal vi rett og slett definere den leksikografiske stiordningen (lpo) i Maude, slik at vi kan bruke Maude til å sjekke om en gitt mengde ligninger kan vises terminerende ved hjelp av lpo med en gitt presedens. 1 Først må vi definere en datatype for å representere termer og ligninger som Maude-termer. Funksjonssymboler (både konstanter og ikke-konstanter) og variabelsymboler representeres av elementer av sort FuncVarSymbol: sort FuncVarSymbol. ops a ack b c d e f g h i j k l m n o p q r s t u v w 0 + * - v w x x1 x2 x3 x4 y y1 y2 y3 y4 z z1 z2 z3 z4 : -> FuncVarSymbol [ctor]. En term representeres av en term av sort Term, som enten kun er en konstant eller en variabel, eller er et funksjonssymbol (av sort FuncVarSymbol) brukt på en liste av termer, slik at termen f(a, g(b)) representeres av termen f[a, g[b]]: sorts Term TermList. subsort FuncVarSymbol < Term. subsort Term < TermList. op _,_ : TermList TermList -> TermList [ctor assoc]. op _[_] : FuncVarSymbol TermList -> Term [ctor]. 1 Det er ikke tid til å definere lpo uten en angitt presedens i løpet av en 3-timers eksamen. (Fortsettes på side 3.)
Eksamen i INF 3230, 4. juni 2010 Side 3 En ligning t = t representeres av en Maude term eq t = t., hvor t er vår representasjon av t og t er vår representasjon av t : sorts Equation EquationSet. subsort Equation < EquationSet. op none : -> EquationSet [ctor]. op : EquationSet EquationSet -> EquationSet [ctor assoc comm id: none]. op eq_=_. : Term Term -> Equation [ctor]. Den gamle gode ligningsmengden i modulen NAT-ADD kan derfor representeres ved følgende Maude term av sort EquationSet: eq +[0, x] = x. eq +[s[x], y] = s[+[x, y]]. En annen ligningsmengde kan representeres av følgende term av sort EquationSet: eq f[a, b, a] = f[a, b, b]. eq f[b, b, f[a, b, a]] = f[a, b, a]. Vi trenger også å representere presedenser. Vi velger å representere en presedens som en liste på formen f >> g >> h >> a, der f selvfølgelig er større enn g, som i sin tur er større enn h, osv. Du kan anta at et symbol ikke forekommer mer enn én gang i en slik liste. Merk at ikke alle funksjons/variabel-symboler trenger å være med i en slik liste (et symbol som ikke er med i listen er selvfølgelig ikke sammenlignbart i presedensen med noe annet symbol), men de symbolene som er med i listen er totalt ordnet: sort Precedence. subsort FuncVarSymbol < Precedence. op emptyprecedence : -> Precedence [ctor]. op _>>_ : Precedence Precedence -> Precedence [ctor assoc id: emptyprecedence]. 2a Sjekke funksjonssymboler i en presedens (12 poeng) Definér en funksjon op _>>_in_ : FuncVarSymbol FuncVarSymbol Precedence -> Bool. slik at f >> g in P er true hvis og bare hvis både f og g forekommer i listen P og f er større enn g i presedensen representert av listen P. For eksempel skal f >> g in h >> a >> f >> b >> g >> c returnere true, mens både g >> f in h >> a >> f >> b >> g >> c og f >> g in h >> f >> a skal returnere false. (Fortsettes på side 4.)
Eksamen i INF 3230, 4. juni 2010 Side 4 2b Definere lpo i Maude (60 poeng) I denne deloppgaven skal du rett og slett definere i Maude en funksjon op lpoterm : EquationSet Precedence -> Bool. som tar en ligningsmengde og en presedens som argumenter, og som sjekker om lpo med den gitte presedensen kan vise terminering av den gitte ligningsmengden. For eksempel skal kommandoene red lpoterm(eq +[0, x] = x. eq +[s[x], y] = s[+[x, y]]., + >> s >> 0). og red lpoterm(eq f[a, b, a] = f[a, b, b]. eq f[b, b, f[a, b, a]] = f[a, b, a]., f >> a >> b). begge skal returnere true, mens red lpoterm(eq f[a, b, a] = f[a, b, b]. eq f[b, b, f[a, b, a]] = f[a, b, a]., f >> b >> a). skal returnere false. Lykke til! Peter C. Ölveczky (Fortsettes på side 5.)
Eksamen i INF 3230, 4. juni 2010 Side 5 The Exam in English The exercises can, to a certain degree, be solved independently of each other. If you have not solved an exercise, you may assume that you have solved it and can continue with the other exercises. Emphasize simplicity and elegance in your solutions. All answers should be explained/justified. All auxiliary functions, sorts, etc., that you need must obviously be fully defined. Exercise 1 Termination and Confluence (32 points) In this exercise we consider the specification E = {x (y + z) = (x y) + (x z), (x + y) + z = x + (y + z)} 1. Can the lexicographic path ordering (lpo) prove that E is terminating? Prove/justify your answer. 2. Can the multiset path ordering (mpo) prove that E is terminating? Prove/justify your answer. 3. Does there exist a simplification ordering that can be used to prove that E is terminating? Prove/justify your answer. 4. Is E confluent? Prove/justify your answer. (The exam continues on the next page.) (Fortsettes på side 6.)
Eksamen i INF 3230, 4. juni 2010 Side 6 Exercise 2 Defining the Lexicographic Path Ordering in Maude (72 points) In this exercise we define the lexicographic path ordering (lpo) in Maude, so that we can use Maude to check whether a set of equations can be shown to be terminating using lpo w.r.t. a given precedence. We must first define a data type for representing sets of equations as Maude terms. We first define a way of representing terms as Maude terms of a sort Term. First, function symbols (both constants and non-constants) and variables are elements of the sort FuncVarSymbol: sort FuncVarSymbol. ops a ack b c d e f g h i j k l m n o p q r s t u v w 0 + * - v w x x1 x2 x3 x4 y y1 y2 y3 y4 z z1 z2 z3 z4 : -> FuncVarSymbol [ctor]. A term in an equational specification is represented by a Maude term of sort Term, which is either a constant or a variable, or a function symbol (of sort FuncVarSymbol) followed by (or applied to ) a list of terms, so that, e.g., the term f(a, g(b)) is represented by the Maude term f[a, g[b]] of sort Term: sorts Term TermList. subsort FuncVarSymbol < Term. subsort Term < TermList. op _,_ : TermList TermList -> TermList [ctor assoc]. op _[_] : FuncVarSymbol TermList -> Term [ctor]. An equation t = t is represented by the Maude term eq t = t. of sort Equation, where t is our representation of t and t is our representation of t : sorts Equation EquationSet. subsort Equation < EquationSet. op none : -> EquationSet [ctor]. op : EquationSet EquationSet -> EquationSet [ctor assoc comm id: none]. op eq_=_. : Term Term -> Equation [ctor]. The good old set of equations in the module NAT-ADD can now be represented by the following Maude term of sort EquationSet: eq +[0, x] = x. eq +[s[x], y] = s[+[x, y]]. Another set of equations can be represented by the following Maude term of sort EquationSet: (Fortsettes på side 7.)
Eksamen i INF 3230, 4. juni 2010 Side 7 eq f[a, b, a] = f[a, b, b]. eq f[b, b, f[a, b, a]] = f[a, b, a]. We also need to represent precedences. I choose to represent a precedence as a list of the form f >> g >> h >> a, where f is greater than g, which is greater than h, and so on. You may assume that each symbol appears at most once in the list. Notice that not all the symbols in a specification need to appear in the list (a symbol not appearing in the list is incomparable in the precedence to any other symbol), but the symbols that are in the list are totally ordered: sort Precedence. subsort FuncVarSymbol < Precedence. op emptyprecedence : -> Precedence [ctor]. op _>>_ : Precedence Precedence -> Precedence [ctor assoc id: emptyprecedence]. Exercise 2a Checking Function Symbols in a Precedence (12 points) Define a function op _>>_in_ : FuncVarSymbol FuncVarSymbol Precedence -> Bool. such that f >> g in P is true if and only if both f and g appear (explicitly) in the list P and f is greater than g in the precedence represented by the list P. For example, f >> g in h >> a >> f >> b >> g >> c should equal true, while both g >> f in h >> a >> f >> b >> g >> c and f >> g in h >> f >> a should equal false. Exercise 2b Define lpo in Maude (60 points) In this exercise you should define in Maude a function op lpoterm : EquationSet Precedence -> Bool. that takes as arguments a set of equations and a precedence, and that returns true if and only if the set of equations can be proved to terminate using lpo with the given precedence. For example, the commands red lpoterm(eq +[0, x] = x. eq +[s[x], y] = s[+[x, y]]., + >> s >> 0). and (Fortsettes på side 8.)
Eksamen i INF 3230, 4. juni 2010 Side 8 red lpoterm(eq f[a, b, a] = f[a, b, b]. eq f[b, b, f[a, b, a]] = f[a, b, a]., f >> a >> b). should both return true, whereas red lpoterm(eq f[a, b, a] = f[a, b, b]. eq f[b, b, f[a, b, a]] = f[a, b, a]., f >> b >> a). should return false. Good luck! Peter C. Ölveczky