test-1-mock

pdf

School

Syracuse University *

*We aren’t endorsed by this school

Course

623

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

6

Uploaded by DoctorDanger12858

Report
CIS 623 Structured programming and formal methods Prof. Andrew C. Lee Spring, 2023 § Mock Midterm Time allowed : (No more than) 70 minutes. This is a closed book , closed notes and closed neighbors test. You are expected to work alone. Answer all the questions . Presentation counts . Partial credits will be given to carefully presented answers. Write legibly . Illegible answers will not be graded. When you are asked to write a haskell function, you must include the function’s type in your answer. Essential definitions (syntax, semantics and proof rules) of access control logic are provided separately. 1
Part I: Short Questions (30 point) Question 1 (Total 20 point. True/False question. Circle your choice. Explanations are not required) a. Let T and U be two relations on the set A = 1 , 2 , 3 , 4 where T = { (1 , 1) , (2 , 1) , (3 , 3) , (4 , 4) , (3 , 4) } and U = { (2 , 4) , (1 , 3) , (3 , 3) , (3 , 2) } . Then T U = U T . True/False In the following two questions, we refer to a Kripke’s model M where Alice , Bob are two principals, and the symbols p , q and r are propositional variables in the model M . b. M | = ( p q ) ( p q ) . True/False c. Alice | Bob is a well-formed Access control formula. True/False d. The (most general) type of the function pair x y = (x,y) is a -> b -> (a,b) True/False e. The list [ (x,y) | x <- [1,2], y <-[3,4]] and [ (y,x) | x <-[3,4], y <- [1,2]] represent the same list. True/False f. The type of the expression [ a , b ] is String . True/False g. Let φ be a ACL formula. We can always find a Kripke model Let M = ( W, I, J ) such that M | = φ True/False . h. Consider the following function h : > h :: [a] -> [a] > h (x:xs) = (h xs) ++ (h xs) > h [x] = [x,x] > h [] = [] Then evaluate h [1] will return [1,1] . True/False Consider the following Haskell function: > (#) :: Int -> Int -> Int > (#) x y = x + y + 1 i. The Haskell expression (# 1) 2
represents function of type Int -> Int True/False j. Evaluate the expression 1 # 2 will return 4 . True/False Question 2 (15 point) Write down your answer in the space provided. a. (9 point) Define the following library functions by recursion: > product :: [Int] -> Int > length :: [a] -> Int > reverse :: [a] -> [a] b. (6 point) Let h be the function which has the following type: > h :: Char -> Int -> Char -> Int State the types of Expression i , ii and iii in the space provided: Expression Type i . [(False, 0 ), (True, 1 )] ii . ([False,True], [ 0 , 1 ]) iii . h a 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Part II: Programming questions (30 point) Question 3 (15 point) (define functions for new data types) a. Write a function count which will, given a list of shapes (type Shape) as input, return (c,r) where c = the number of shapes in the list that are circles r = the number of shapes in the list that are rectangles > data Shape = Circle Float | Rect Float Float > deriving (Show) Question 4 (15 point) (define function using list comprehension) Use list comprehension to write a Boolean function detect of the following type: > detect :: Ord a => [a] -> Bool It detects if a list is already is sorted in ascending order. In your answer, you may use the library functions from Prelude such as head , tail , or , and , not , zip , take , drop etc. % 4
Part III: Formal methods (35 point) Question 5 (15 point) (inference proofs for ACL: access control logic) The following inference proof for the Conjunction rule where line 3 is missing: 1 . φ 1 (Assumption) 2 . φ 2 (Assumption) 3 . (Taut) 4 . φ 2 ( φ 1 φ 2 ) (1,3 Modus Ponens) 5 . φ 1 φ 2 (2,4 Modus Ponens) a . (10 point) Fill in the blanks in line 3 to complete the proof. State the tautology that are used to support that step. Verify that it is in fact a tautology by constructing its truth table. b . (5 point) Draw a proof tree for the inference proof completed in part a . 5
Question 6 (20 point) (Kripke’s structure) Let M 1 = ( W 1 , I 1 , J 1 ) be a Kripke structure defined as follows: W 1 = { w 0 , w 1 , w 2 } I 1 : PropVar P ( W 1 ) (the interpretation function) I 1 ( q ) = { w 0 , w 2 } , I 1 ( r ) = { w 1 } , I 1 ( s ) = { w 1 , w 2 } . J 1 : PName P ( W 1 × W 1 ) be defined as: J 1 ( Alice ) = { ( w 0 , w 0 ) , ( w 1 , w 1 ) , ( w 2 , w 2 ) } , J 1 ( Bob ) = { ( w 0 , w 0 ) , ( w 0 , w 1 ) , ( w 1 , w 2 ) , ( w 2 , w 1 ) } . a . (4 point) State what is meant by M | = φ , where φ is a well formed formula and M is a Kripke model for ACL. b . (12 point) For the given model M 1 , Compute E M 1 ( Bob controls ( r s ) ) , where E M 1 is the evaluation function for the Kripke’s model M 1 . c . (4 point) From your computations in part b , can we say M 1 | = Bob controls ( r s ) ? Give reason(s) to support your answer. 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help