我需要函数后置条件的证明
这是一项作业,但我无法通过编写正式证明来理解整个事情。任何人都可以破解这个并为该 fnc 的后置条件编写正式的证明:
string REPLACE_BY (string s,char c,char d)
后置条件 返回的值是由 s 通过替换每个出现的字符串形成的字符串 c乘以d(否则保持s不变)。
this is a homework but I just cannot get my head around this whole business with writing formal prooves. Could anyone crack this and write formal proof for postcondition of this fnc:
string REPLACE_BY (string s,char c,char d)
postcondition The returned value is the string formed from s by replacing every occurrence
of c by d (and otherwise leaving s unchanged).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了证明函数的正确性(即,如果输入符合给定的前置条件,则符合后置条件),您需要函数的实现。
我将首先向您提供工作所需的假设,但将证明留给您,因为这是家庭作业。
假设是:
该方法定义如下:
前提条件是
s != null /\ s.size() < Integer.MAX_VALUE
old(s)
用于引用进入函数之前s
的值散文中给出的后置条件的正式规范是
(
\-/
是逻辑 for-all 运算符,\/
是“或”,/\
是“与”)有了这个,您应该能够基于 构建证明霍尔逻辑。
In order to proove the correctness of the function (i.e. compliance to a post-condition if the input conforms to a given pre-condition), you need the function's implementation.
I will get you started by giving you the assumptions under which you will need to work, but leave the proof up to you since it's homework.
The assumptions are:
that the method is defined as such:
that the precondition is
s != null /\ s.size() < Integer.MAX_VALUE
old(s)
is used to refer to the value ofs
before entering the functionthat the formal specification of your postcondition given in prose is
(
\-/
is the logical for-all operator,\/
is 'or' and/\
is 'and')With this, you should be able to build a proof based on Hoare logic.