1 / 12

F21RS Exam 2012 Questions 1 and 2

F21RS Exam 2012 Questions 1 and 2 . Andrew Ireland. Question 1. Question 1 – a solution. Q1.

sylvia
Download Presentation

F21RS Exam 2012 Questions 1 and 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. F21RS Exam 2012Questions 1 and 2 Andrew Ireland

  2. Question 1

  3. Question 1 – a solution • Q1. • a) Software standards provide guidance as to what methodologies and techniques should be used when developing software for high integrity systems. For example, language subsets are typically used in order to reduce the chances of introducing errors during coding and increase the opportunities for automated static analysis, e.g. MISRA-C and SPARK eliminate pointer based programs, while SPARK also enforces that functions must be pure, i.e. no side-effects. • [ 3 marks ] – 1 mark for “how” and 2 marks for example. • b) The derives annotation specifies the relationship between imported and exported variables associated with a subprogram, where imported/exported variables are either parameters or global variables. The globals annotation is used to indicate the use of global variables within a subprogram. Both derives and globals clauses must include mode information, i.e. in (imported) and out (exported) + an example. • [ 7 marks ] – 4 marks for explanation + 3 marks for example.

  4. Question 1 – a solution • Q1. • c) Answer should include reference to the following relations: • L(u, e) is true if the initial value of variable u may be used in computing the value of expression e. • M(e, v) is true if e may be used in computing the final value of variable v. • R(u, v) is true if the initial value of u may be used in computing the final value of variable v. [ 3 marks ] • And for X:=Y+Z; Z:=Z+2; X:=Z+Y (where e1 = Y+Z, e2 = Z+2, e3 = Z+Y) we get: • L = {(Y,e1), (Z,e1), (Z, e2), (Z, e3), (Y, e3)} • M = {(e2, Z), (e2, X), (e3, X) } • R = {(Y, X), (Z, Z), (Z, X), (Y, Y)} • [ 6 marks ] • Flow analysis shows that the value of e1 is ineffective, i.e. it contributes to the final value of none of the variables, also shows that the initial value of X contributes to the final value of none of the variables. [ 1 mark ] • [ part (c) total 10 marks ]

  5. Question 2

  6. Question2 (a) – a solution pre-loop VC: (M + div(N, 2) = div(n, 2) & N >= 0 & even(N)) -> (M + div(N, 2) = div(n, 2) & N >= 0 & even(N) (2 marks) loop VC: (M + div(N, 2) = div(n, 2) & N >= 0 & even(N) & N >= 2)-> ((M+1) + div(N-2, 2) = div(n, 2) & N-2 >= 0 & even(N-2)) (3 marks) post-loop VC: (M + div(N, 2) = div(n, 2) & N >= 0 & even(N) & not(N >= 2)) -> (M = div(n, 2)) (3 marks) [ 8 marks for VCs] {M + div(N, 2) = div(n, 2) & N >= 0 & even(N)} while (N >= 2) loop {M + div(N, 2) = div(n, 2) & N >= 0 & even(N)} M:=M+1; N:=N-2; end loop {M = div(n, 2)}

  7. Question 2

  8. Question2 (b) – a solution Pre-loop proof: Given: M + div(N, 2) = div(n, 2) & N >= 0 & even(N) Goal: M + div(N, 2) = div(n, 2) & N >= 0 & even(N) By tautology True [ 1 mark ]

  9. Question2 (b) – a solution loop-proof given: M + div(N, 2) = div(n, 2) & N >= 0 & even(N) & N >= 2 goal: (M+1) + div(N-2, 2) = div(n, 2) & N-2 >= 0 & even(N-2) by (5) M + (1 + div(N-2, 2)) = div(n, 2) & N-2 >= 0 & even(N-2) By (9) M + (1 + (div(N, 2)-1)) = div(n, 2) & N-2 >= 0 & even(N-2) by (10) M + div(N, 2) = div(n, 2) & N-2 >= 0 & even(N-2) By (6) …

  10. Question2 (b) – a solution loop-proof given: M + div(N, 2) = div(n, 2) & N >= 0 & even(N) & N >= 2 …. M + div(N, 2) = div(n, 2) & N-2 >= 0 & even(N-2) By (6) M + div(N, 2) = div(n, 2) & N >= 2 & even(N-2) By (4) M + div(N, 2) = div(n, 2) & N >= 2 & even(N) By givens M + div(N, 2) = div(n, 2) & N >= 2 & even(N) True [ 6 marks ]

  11. Question2 (b) – a solution post-loop proof given: M + div(N, 2) = div(n, 2) & N >= 0 & even(N) & not(N >= 2) goal: M = div(n, 2) by (12) using givens N >= 0, even(N), not(N >= 2) given: M + div(N, 2) = div(n, 2) & N >= 0 & even(N) & not(N >= 2) & (N = 0) goal: M = div(n, 2) by given (N = 0), substitute 0 for N in div(N, 2) given: M + div(0, 2) = div(n, 2) & N >= 0 & even(N) & not(N >= 2) & (N < 2) & (N = 0) goal: M = div(n, 2) by (7) …

  12. Question2 (b) – a solution post-loop proof given: M + div(0, 2) = div(n, 2) & N >= 0 & even(N) & not(N >= 2) & (N < 2) & (N = 0) goal: M = div(n, 2) by (7) given: M + 0 = div(n, 2) & N >= 0 & even(N) & not(N >= 2) & (N < 2) & (N = 0) goal: M = div(n, 2) by (1) given: M = div(n, 2) & N >= 0 & even(N) & not(N >= 2) & (N < 2) & (N = 0) goal: M = div(n, 2) by given M = div(n, 2) true [ 5 marks ]

More Related