编程理论 - 证明不变量
我已经定义了这个伪代码,用于使用松弛特里树识别字符串,其中函数 Next[u,x] 给出具有来自 u 的 u 边的节点集(基本上是这样的节点集(u,x,v)是 T 中的一条边)。
基本上
U := {1};
while s ≠ λ and U ≠ Ø do
U:= U in u Union Next [u, head(s)];
s:= tail(s)
od;
if U ≠ Ø then
if Final[u] for some u in U then
Accept
else reject
fi
else
reject
fi
我已经为循环定义了一个后置条件,并给出了一个循环不变式(我想我已经涵盖了这些元素,但如果您认为这将有助于解释它,那就去吧)。
因此,我需要给出一个简短的论点,说明为什么不变量是不变的(即,当循环条件成立时,循环体如何保留它)。
然后我需要扩展这个伪代码,以便它可以移动到一个新节点而不需要提前输入:(
我想我会通过添加另一个数组(比如 Null)来做到这一点,其中 Null[u] 是它可以移动到的状态集 。
还应该进行更改,以便在查看输入之前的每次迭代都可以从 U 中的状态到达所有状态,而无需提前输入
感谢您的所有帮助,我发现这两个步骤非常困难,但认为我的第一部分的伪代码很好
I have defined this pseudo-code for recognising strings using a relaxed-trie where the function Next[u,x] gives the set of nodes with u-edges from u ( basically the set of nodes such that (u,x,v) is an edge in T).
Here it is:
U := {1};
while s ≠ λ and U ≠ Ø do
U:= U in u Union Next [u, head(s)];
s:= tail(s)
od;
if U ≠ Ø then
if Final[u] for some u in U then
Accept
else reject
fi
else
reject
fi
Basically I have defined a postcondition for the loop, and given a loop invariant ( I think I have these elements covered, but if you think it will help to explain it go for it).
So I need to give a short argument stating why the invariant is invariant, (ie how it is preserved by the loop body, when the loop condition holds).
I then need to extend this pseudocode such that it can move to a new node without advancing the input :
(I think I would do this by adding another array (say Null) where Null[u] is the set of states it can move to from u without advancing the input)
It should also be changed such that each iteration before looking at the input all states can be reached from a state in U without advancing the input.
Thanks for all your help, am finding these two steps quite difficult, but think my psuedo-code for the first part is fine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论