Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a minimizing solver for smaller counter-examples #176

Open
wants to merge 2 commits into
base: scala-2.13
Choose a base branch
from

Conversation

SolalPirelli
Copy link

This is part of the Formal Verification course project from @mbovel and me, the idea is to add a "minimizing" solver that makes "smaller" counter-examples, such as ints/BVs closer to 0 and ADT constructors with fewer parameters.

Two examples from our project presentation:

def f(n: Int): Unit = {
  assert(n * n > 10)
}

With default Stainless this results in a counter-example of -1743011841, with our smt-z3-min solver it results in 0 instead (and the overflow counter-example is also far closer to 0).

sealed abstract class Thing {
  def size: Int = this match {
    case Big(a, b, c) => a + b + c
    case Small() => 0
    case Medium(a) => a
  }
}
case class Big(a: Int, b: Int, c: Int) extends Thing
case class Small() extends Thing
case class Medium(a: Int) extends Thing

def g(t: Thing): Unit = {
  assert(t.size > 10)
}

With default Stainless the output isn't stable, it will somewhat randomly be one of the three ADT constructors, with our smt-z3-min it's always Small() (and the overflow counter-examples are also minimized).

WDYT? In particular, should there be other kinds of minimization? What tests should there be, and is there an easier way to write such tests than the rather verbose one we added (the TIP format maybe)?

@CLAassistant
Copy link

CLAassistant commented Jan 10, 2022

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants