


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Note: Answers to the exercises listed below should be handed to the instructor in hardcopy and in typewritten form (latex formatting preferred) by the deadline mentioned above. You should also email to ([email protected]) the Maude code for the exercises requiring that. Make sure that you use the latest version of the lecture notes for exercises belonging to a particular lecture.
fmod CARD is sorts Natural MSet. subsort Natural < MSet. op 0 : -> Natural [ctor]. op s : Natural -> Natural [ctor]. op + : Natural Natural -> Natural. op __ : MSet MSet -> MSet [ctor assoc comm]. op card : MSet -> Natural. vars N M : Natural. vars U V : MSet. eq N + 0 = N. eq N + s(M) = s(N + M). eq card(N U) = s(card(U)). endfm
Do the following:
((card(U:MSet V:MSet)) = (card(U:MSet) + card(V:MSet)))
Note the fact that both the above equation as a whole, as well as the left side and right side of the equation, are enclosed in parentheses. This is to help the, somewhat primitive, parser of the ITP, which may not be able to parse a goal unless the equation in the goal has enough parentheses.
fmod TREE is protecting QID. sorts Natural Tree. subsort Qid < Tree. op 0 : -> Natural [ctor]. op s : Natural -> Natural [ctor]. op + : Natural Natural -> Natural [assoc comm]. op # : Tree Tree -> Tree [ctor]. ops leaves inner : Tree -> Natural. var I : Qid. vars N M : Natural. vars T T’ : Tree. eq N + 0 = N. eq N + s(M) = s(N + M). *** add equations for leaves and inner here endfm
Once you have defined and tested your definitions for leaves and inner do the following, including screenshots for each tool used in your hardcopy of the homework:
int-val(S:WrappedState[’N])) = (true) & (int-val(S:WrappedState[’N])) = (N:Int)) .)
fmod DIV2-JAVAX is including JAVAX. op div2 : -> BlockStatements. op div2-init : -> BlockStatements. eq div2 = ’Y = #i(0) ; while (#i(1) < ’X) { ’X = ’X - #i(2) ; ’Y = ’Y + #i(1) ; }. eq div2-init = (int ’X ; int ’Y ;). endfm
and here is the goal you should prove, now with the invariant left unspecified; so you have to first come up wiht it, and then prove the goal.
select ITP-TOOL. loop init-itp.
(javax-inv DIV2-JAVAX : --- specification constants (N:Int) --- precondition (((S:WrappedState[’X]) = (int(N:Int))) & ((N:Int >= 0) = (true))) --- program div2-init div --- postcondition ((((2 * int-val(S:WrappedState[’Y]))