在不锈钢中使用forall构建体

时间:2017-03-04 12:35:48

标签: scala

我试图在Stainless中证明,如果两个列表具有相同的内容,并且一个列表以x为界,则另一个列表也以x为界。为此,我被告知使用构造:

forall(x => list.content.contains(x) ==> p(x))

引理将以(详细的方式)写成:

def lowerBoundLemma(l1: List[BigInt],l2: List[BigInt],x:BigInt) : Boolean = {
    require(l1.content == l2.content && forall(y => l1.content.contains(y) ==> y <= x))
    forall(z => l2.content.contains(z) ==> z <= x) because{
      forall(z => l2.content.contains(z) ==> z <= x) ==| l1.content == l2.content |
      forall(z => l1.content.contains(z) ==> z <= x) ==| trivial                  |
      forall(y => l1.content.contains(z) ==> y <= x)
    }
  }.holds

问题是我收到以下错误:

exercise.scala:12:48: error: missing parameter type
require(l1.content == l2.content && forall(y => l1.content.contains(y) ==> y <= x))

一旦我将类型添加到y,我就会收到此错误(指向包含括号的左括号):

exercise.scala:12:81: error: ')' expected but '(' found.
require(l1.content == l2.content && forall(y : BigInt => l1.content.contains(y) ==> y <= x))

知道为什么会这样吗?

我还尝试了语法l.forall(_ <= x),但在与类型的because==|等结构组合时出错:因为它不是布尔值的成员。

1 个答案:

答案 0 :(得分:2)

您面临的问题来自Scala编译器前端到不锈钢。在Scala中,闭包的语法(具有指定的参数类型)是(x: Type) => body(注意额外的括号!)

如果您想使用because==|,则必须在源文件的开头添加import stainless.proof._