关于dafny证明seq中引理的问题<int>
Question about dafny to prove the Lemma in seq<int>
我刚开始跟dafny学习。现在我有谓词:
predicate allEqual(s:seq<int>)
//{forall i,j::0<=i<|s| && 0<=j<|s| ==> s[i]==s[j] }
//{forall i,j::0<=i<=j<|s| ==> s[i]==s[j] }
//{forall i::0<i<|s| ==> s[i-1]==s[i]}
{forall i::0<=i<|s|-1 ==> s[i]==s[i+1]}
然后我需要证明引理:
lemma equivalenceContiguous(s:seq<int>)
ensures (allEqual(s) <==> forall i::0<=i<|s|-1 ==> s[i]==s[i+1])
我怎样才能证明这一点?据我所知,我需要写 "assert" 什么的?
这个证明特别简单,因为您要证明 allEqual
就是它被定义的样子。只需在引理中添加一个空体:
lemma equivalenceContiguous(s: seq<int>)
ensures allEqual(s) <==> forall i :: 0 <= i < |s| - 1 ==> s[i] == s[i+1]
{
}
我刚开始跟dafny学习。现在我有谓词:
predicate allEqual(s:seq<int>)
//{forall i,j::0<=i<|s| && 0<=j<|s| ==> s[i]==s[j] }
//{forall i,j::0<=i<=j<|s| ==> s[i]==s[j] }
//{forall i::0<i<|s| ==> s[i-1]==s[i]}
{forall i::0<=i<|s|-1 ==> s[i]==s[i+1]}
然后我需要证明引理:
lemma equivalenceContiguous(s:seq<int>)
ensures (allEqual(s) <==> forall i::0<=i<|s|-1 ==> s[i]==s[i+1])
我怎样才能证明这一点?据我所知,我需要写 "assert" 什么的?
这个证明特别简单,因为您要证明 allEqual
就是它被定义的样子。只需在引理中添加一个空体:
lemma equivalenceContiguous(s: seq<int>)
ensures allEqual(s) <==> forall i :: 0 <= i < |s| - 1 ==> s[i] == s[i+1]
{
}