首页 > 其他分享 >CSSE3100 合理性解析

CSSE3100 合理性解析

时间:2023-04-29 09:22:22浏览次数:40  
标签:even CSSE3100 Question number up array 解析 your 合理性


ssignment 2 CSSE3100/7100 Reasoning about Programs
Due: 4pm on 28 April, 2023
The aim of this assignment is to consolidate your understanding of the course's material on
arrays, program derivation and recursion. It is worth 20% of your final mark for the course.
Instructions: Upload a plain text file with your solution to Question 1(b) and a Dafny
file with your solutions to Questions 1(a) and 2 (and Question 3, if applicable) to
Gradescope by the due date and time.
1. Imagine you need to make multiple queries regarding the number of even numbers in
various parts of a large integer array, a. For example, a first query might ask for the number
of even numbers from position 336 up to, and including, position 500 of a, and the second
may ask for the number of even numbers from 336 up to, and including, 479. If you search
through the relevant part of a on each query, you may end up duplicating work previously
carried out (in the example the range of positions from 336 to 479 would be searched twice).
An alternative is to search through the entire array just once, storing in a second integer array
of the same length, b, the number of even numbers up to each point in array a, i.e., b[i] will
hold the number of even numbers occurring in the elements a[0] ... a[i] (note that an even
number in a[i] is included in this count). The number of even numbers from positions i up to,
and including, position j of a would then be b[j] - b[i-1] when i > 0, and b[j] otherwise.
(a) Given the function Count below, specify and derive a method PreCompute which given
two integer arrays a and b of the same length, assigns values to b as described above. The
method must call a second method ComputeCount which uses recursion (and not a loop) to
write values to the array b. Provide a termination metric that allows Dafny to verify this
method and hence verify your method PreCompute.
Note that Count is declared as ghost which means it cannot be used in code. It can only be
used in specifications and invariants. You are not allowed to define and use any other
functions in your solution. (6 marks)
ghost function Count(hi: nat, s:seq): int
requires 0 <= hi <= |s|
decreases hi
{
if hi == 0 then 0
else if s[hi-1]%2 == 0 then 1 + Count(hi-1, s) else Count(hi-1, s)
}

(b) Provide a weakest precondition proof that PreCompute is partially correct. (4 marks)
2. For further efficiency, specify and derive a program Evens which given an integer array a,
returns a 2-dimensional integer array c such that c[i, j] directly provides the number of even
numbers from position i up to, and including, position j of a. Note that this will be 0
whenever j < i.
Your program should call PreCompute to get the values in array b and then use one or more
loops (no recursion this time) to write the values to the array c. Again, you are not allowed to
define and use any other functions in your solution.
Check your program using the Dafny verifier. There is no need to provide a proof.
(10 marks)

3. (CSSE7100 students only) Using your specification of PreCompute from Question 1,
derive a program PreComputeL using one or more loops (no method calls or recursion) to
write values to b. Again, you are not allowed to define and use any other functions in your
solution.
Check your program using the Dafny verifier. There is no need to provide a proof.
(3 marks)

Hints: Be careful regarding end points: Count provides the number of even numbers from
position 0 up to, but not including, position hi, whereas b[i] is the number of even numbers
from position 0 up to, and including, position i.
Don't forget about aliasing, and that a <= b < c is a <= b && b < c!

Marking
For Questions 1(a) and 2 (and Question 3 if applicable), you will get marks for
correctness of specifications
completeness of specifications
key lines of code
correctness and completeness of loop invariants
Note that you will get part marks even if your code doesn't verify in Dafny.
For Question 1(b), you will get marks for
the application of the appropriate weakest precondition rules for each line of code,
stating why the entire method is correct, and
correct and, where necessary, justified predicate transformations.
You must justify all predicate transformations which are not due to either simple arithmetic
or commutativity of && or ||. Justification must be either
a law from Appendix A of Programming from Specification (Questions 1),
a brief explanation for any non-obvious arithmetic step (Question 1), or
"strengthening" when you have strengthened a predicate (Question 1). Strengthening
steps must be obvious, e.g., adding one or more conjuncts, or restricting the range of
values of one or more variable.
For CSSE7100 students, the final mark is M - (3 - m) where M is the mark for Questions 1
and 2 (out of 20) and m is the mark for Question 3 (out of 3).

School Policy on Student Misconduct
This assignment is to be completed individually. You are required to read and understand the
School Statement on Misconduct, available on the School's website at:
http://www.itee.uq.edu.au/itee-student-misconduct-including-plagiarism

 WX:codehelp

标签:even,CSSE3100,Question,number,up,array,解析,your,合理性
From: https://www.cnblogs.com/mondayw/p/17363573.html

相关文章

  • 超大文件上传和断点续传的实例解析
    ASP.NET上传文件用FileUpLoad就可以,但是对文件夹的操作却不能用FileUpLoad来实现。下面这个示例便是使用ASP.NET来实现上传文件夹并对文件夹进行压缩以及解压。ASP.NET页面设计:TextBox和Button按钮。TextBox中需要自己受到输入文件夹的路径(包含文件夹),通过Button实现选择文件夹......
  • 记录一次git patch解析的问题
    因为工作需要对gitpatch内容进行解析,解析成文件及对应修改行、删除行的数据结构。gitpatch大概内容:点击查看代码commitmessage1commitmessage2diff--gita/file1.txtb/file1.txtindex1234567..abcdefg100644---a/file1.txt+++b/file1.txt@@-1,3+1,5@@l......
  • 解析后端接口的文件流
    下面使用的是若依框架中的axios请求api:通用importrequestfrom'@/utils/request'exportfunctionguideCome(data){returnrequest({url:'/sys/client/export',method:'post',responseType:&#......
  • vue3 ts 项目文件夹解析
    vue3ts项目文件夹解析layouts文件夹通常用于存放应用程序中的布局组件或布局相关的文件。布局组件是用于包装应用程序中的页面内容的组件,通常包含头部导航、侧边栏、页脚、页面标题等等。布局组件可以在不同的页面中共享,并且可以为应用程序带来一致的外观和体验。core存放......
  • 编程用JAVA解析XML的方式
    用SAX方式解析XML,XML文件如下:<?xmlversion="1.0"encoding="gb2312"?><person><name>王小明</name><college>信息学院</college><telephone>6258113</telephone><notes>男,1955年生,博士,95年调入海南大学......
  • 高保真智能录音机解决方案技术特色解析
    需求分析 随着数字化进程的不断推进,录音机的需求也在逐渐发生变化。用户对录音机的需求逐渐朝着,微型化,便携化,智能化的方向靠拢。鉴于此,团队根据市场的变化,及时推出了一系列高保真的数字录音机方案,方便系统集成厂商集成和运用,满足个性化的产品需求。 特色梳理 有趣的灵魂......
  • golang1.6版本json包解析嵌套指针的问题小记
    指针的指针问题本地跑的好好的,测试环境跑的好好,预发布环境(准线上环境),跪了。起因就是:1a:=&struct{s:""}2json.Unmarshal([]byte{},&a)3fmt.Println(a.s)//报错行第一行代码进行&取地址,获得指针变量。第二行代码,进行json解析的时候,传入了&a, 指针的指针,a到了jso......
  • 解析方法调用
    解析方法调用的语法,支持常量(双引号包含)、变量、函数(嵌套调用)作为入参。自动机:java实现://方法执行publicStringexcuteMethod(Stringexpression,JSONObjectformData)throwsException{if(null==expression)return"";while(e......
  • 局域网实现文件上传下载功能实例解析
    ​IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头。 一. 两个必要响应头Accept-Ranges、ETag        客户端每次提交下载请求时,服务端都要添加这两个响应头,以保证客户端和服务端将此下载识别为可以断点续传......
  • 进程前驱图控制原理解析
    题目:进程P1、P2、P3、P4和P5的前趋图如图所示。 若用PV操作控制进程P1~P5并发执行的过程,则需要设置5个信号量S1、S2、S3、S4和S5,进程间同步所使用的信号量标注在图1-4中的边上,且信号量S1~S5的初值都等于零,初始状态下进程P1开始执行。图1-5中a、b和c处应分别填写(2);d和e处应......