代做CSSE3100/7100 Reasoning about Programs Assignment 1代做迭代

Assignment 1              CSSE3100/7100 Reasoning about Programs

Due:  4pm on 1 April, 2025

The aim of this assignment is to consolidate your understanding of the course's material on weakest precondition reasoning. It is worth 15% of your final mark for the course.

Submission instructions: Upload a single Dafny file (A1.dfy) to Gradescope with your solutions to Q1-Q3 formatted as per the formatting instructions below.

Q1 Prove the following justifying each line of your proof with a law from Appendix A of Programming from Specifications.

(A ==> B) && (!A ==> B)     =     B (2 marks)

Q2 The following program is the third suggested fix for the Zune bug (discussed in Week 1)   that appeared online in 2009. At the time, one commentator said "Trying to verify correctness by pure reason—as opposed to trial-and-error testing—looks almost hopeless." Use weakest   precondition reasoning to show that the code below is partially correct.

method CalculateYear(d: nat) returns (year: nat)

requires d > 0

ensures year == Year(d, 1980) {

year:= 1980;

var days := d;

while days > 365

invariant days >= 0 && Year(days, year) == Year(d, 1980)

{

if IsLeapYear(year) {

if days > 366 {

days := days - 366;

year := year+1;

} else {

days := days - 366;

}

} else {

days := days - 365;

year:= year + 1;

}


}

}

where

predicate IsLeapYear(y: nat) {

y%4 == 0 && (y%100 == 0 ==> y%400==0) }

and

Copyright Notice © This content is protected and may not be shared, uploaded or distributed. The School of EECS at the University of Queensland holds the copyright for this material. Students are not permitted to share these materials  on sites external to the University of Queensland.

ghost function Year(d: nat, y: nat):nat {

if d > DaysInYear(y) then Year(d - DaysInYear(y), y+1) else y }

ghost function DaysInYear(y: nat): nat{

if IsLeapYear(y) then 366 else 365

} (9 marks)

Q3 The original Zune bug was due to the program not terminating. Additionally prove that   the above program is totally correct using weakest precondition reasoning. You will need to decide on an appropriate termination metric to do this. (4 marks)

Formatting instructions

The proofs are to be completed in the template file A1.dfy provided on Blackboard. The template enables checking of the syntax of your predicates to avoid you making typos or misusing predicate operators. It also enables us to (partially) auto-grade your submission. For this latter reason, it is important that you carefully follow the instructions below.

The file includes three methods, one for each question above.

The method Q1 has inputs A and B corresponding to the predicates of Q1, and a single declaration of a local Boolean variable PS (for proof state). The proof should be written as a series of assignments to PS. For example, the proof of Exercise 1.5(c) (shown below on the  left) should be written as shown on the right below.

X && Y ==> Z PS := X && Y ==> Z;

!(X&&Y)||Z             (A.22) PS := !(X&&Y)||Z;                   // A.22

(!X||!Y)||Z                (A.18) PS := (!X||!Y)||Z;                      // A.18

!X || (!Y || Z)            (A.5) PS := !X || (!Y || Z);                  // A.5

X==>!Y||Z               (A.22) PS := X==>!Y||Z;                     // A.22

Note that justification in terms of laws from Programming from Specifications should be included as comments.

The method CalculateYear includes the code from Q2 with two additional local Boolean variables WP and WP_s. The proof should again be written as a series of assignments to WP and WP_s. WP (for weakest precondition) should be used for all predicates in the proof excepting those where a strengthening has occurred. WP_s should be used only when a strengthening has occurred, i.e., the predicate assigned to WP_s should be strictly stronger than the predicate below it. For example, the snippet of the final proof in Week 4's lecture  slides (shown on the left below) should be written as shown below on the right.


{s == n*(n – 1)/2 && n != 33}

(strengthen with n!=33)

{s == n*(n – 1)/2}              (arithmetic)

{s + n == n*(n – 1)/2 + n} s := s + n;

{s == n*(n – 1)/2 + n}

WP_s := s == n*(n – 1)/2 && n != 33; // strengthen with n!=33

WP := s == n*(n – 1)/2;   // arithmetic

WP := s + n == n*(n – 1)/2 + n; s := s + n;

WP := s == n*(n – 1)/2 + n;


Note that justification must be provided for all predicate simplifications. These need to be

sufficient for a peer, e.g., someone else doing this course, to understand the step. If you refer to a function in your justification, make sure you state the property of the function you are

using. For basic arithmetic, the justification can just be "arithmetic" (as above). The

justification can be on the same line as the predicate or, when this would make the overall   line too long, on the line following the predicate. If you use the rule proved in Q1, you may include "Q1" as justification.

You also need to justify why the result of your weakest precondition calculation means the method is partially correct. Add this justification as a comment immediately above the top- most line of your proof.

The method Q3 includes the code from Q2 with a ghost variable m to record the value of the termination metric (similar to the ghost variable d in the lecture slides) and two additional

Boolean variables WP and WP_s. The proof is to be written following the rules given above for the method CalculateYear. The proof should begin with just the predicate required for proving termination (d > D in the lecture slides) and introduce additional predicates by strengthening if required.

You need to justify why the result of your weakest precondition calculation means the   method terminates. Add this justification as a comment above the top-most line of your proof.

Marking

For each question, you will be awarded full marks for a correct proof (formatted as described  above) with each step (apart from application of wp rules) sufficiently justified. You will lose marks for incorrect proof steps or missing justification as detailed below.

Q1 You will lose 0.5 marks for each incorrect proof step (capped at 1 marks), and 0.5 marks for each case of insufficient or incorrect justification (capped at 1 marks).

Q2 You will lose 0.5 marks for each incorrect proof step (capped at 6.5 marks), and 0.5 marks for each case of insufficient or incorrect justification (capped at 2.5 marks).

Q3 You will lose 0.5 marks for each incorrect proof step (capped at 3 marks), and 0.5 marks for each case of insufficient or incorrect justification (capped at 1 marks).

For each question, additional marks (up to the total marks for the question) may be taken off for work regarded as having little or no academic merit.



热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图