Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
9c076b11
Commit
9c076b11
authored
14 years ago
by
Philippe Suter
Browse files
Options
Downloads
Patches
Plain Diff
has no effect
parent
7ba98f5b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/purescala/Z3Solver.scala
+31
-27
31 additions, 27 deletions
src/purescala/Z3Solver.scala
with
31 additions
and
27 deletions
src/purescala/Z3Solver.scala
+
31
−
27
View file @
9c076b11
...
@@ -14,6 +14,9 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
...
@@ -14,6 +14,9 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
// this is fixed
// this is fixed
private
val
z3cfg
=
new
Z3Config
()
private
val
z3cfg
=
new
Z3Config
()
z3cfg
.
setParamValue
(
"MODEL"
,
"true"
)
z3cfg
.
setParamValue
(
"MODEL"
,
"true"
)
z3cfg
.
setParamValue
(
"SOFT_TIMEOUT"
,
"5000"
)
// this one doesn't work apparently
z3cfg
.
setParamValue
(
"TYPE_CHECK"
,
"true"
)
z3cfg
.
setParamValue
(
"WELL_SORTED_CHECK"
,
"true"
)
Z3Global
.
toggleWarningMessages
(
true
)
Z3Global
.
toggleWarningMessages
(
true
)
// we restart Z3 for each new program
// we restart Z3 for each new program
...
@@ -151,6 +154,7 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
...
@@ -151,6 +154,7 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
val
fOfT
:
Expr
=
FunctionInvocation
(
funDef
,
List
(
CaseClass
(
ccd
,
subids
.
map
(
Variable
(
_
)))))
val
fOfT
:
Expr
=
FunctionInvocation
(
funDef
,
List
(
CaseClass
(
ccd
,
subids
.
map
(
Variable
(
_
)))))
val
toConvert
=
Equals
(
fOfT
,
rhs
)
val
toConvert
=
Equals
(
fOfT
,
rhs
)
//println(toConvert)
val
initialMap
:
Map
[
String
,
Z3AST
]
=
Map
((
subids
.
map
(
_
.
uniqueName
)
zip
boundVars
)
:_
*
)
+
(
pid
.
uniqueName
->
matcher
)
+
(
funDef
.
args
(
0
).
id
.
uniqueName
->
matcher
)
val
initialMap
:
Map
[
String
,
Z3AST
]
=
Map
((
subids
.
map
(
_
.
uniqueName
)
zip
boundVars
)
:_
*
)
+
(
pid
.
uniqueName
->
matcher
)
+
(
funDef
.
args
(
0
).
id
.
uniqueName
->
matcher
)
toZ3Formula
(
z3
,
toConvert
,
initialMap
)
match
{
toZ3Formula
(
z3
,
toConvert
,
initialMap
)
match
{
case
Some
(
axiomTree
)
=>
{
case
Some
(
axiomTree
)
=>
{
...
@@ -159,7 +163,7 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
...
@@ -159,7 +163,7 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
}
else
{
}
else
{
z3
.
mkForAll
(
0
,
List
(
pattern
),
nameTypePairs
,
axiomTree
)
z3
.
mkForAll
(
0
,
List
(
pattern
),
nameTypePairs
,
axiomTree
)
}
}
//
z3.printAST(toAssert)
//z3.printAST(toAssert)
z3
.
assertCnstr
(
toAssert
)
z3
.
assertCnstr
(
toAssert
)
}
}
case
None
=>
{
case
None
=>
{
...
@@ -169,32 +173,32 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
...
@@ -169,32 +173,32 @@ class Z3Solver(reporter: Reporter) extends Solver(reporter) {
}
}
})
})
case
_
=>
{
case
_
=>
{
// Newly introduced variables should in fact
//
//
Newly introduced variables should in fact
// probably also be universally quantified.
//
//
probably also be universally quantified.
val
argSorts
:
Seq
[
Z3Sort
]
=
funDef
.
args
.
map
(
vd
=>
typeToSort
(
vd
.
getType
))
//
val argSorts: Seq[Z3Sort] = funDef.args.map(vd => typeToSort(vd.getType))
val
boundVars
=
argSorts
.
zipWithIndex
.
map
(
p
=>
z3
.
mkBound
(
p
.
_2
,
p
.
_1
))
//
val boundVars = argSorts.zipWithIndex.map(p => z3.mkBound(p._2, p._1))
val
pattern
:
Z3Pattern
=
z3
.
mkPattern
(
functionDefToDef
(
funDef
)(
boundVars
:
_
*
))
//
val pattern: Z3Pattern = z3.mkPattern(functionDefToDef(funDef)(boundVars: _*))
val
nameTypePairs
=
argSorts
.
map
(
s
=>
(
z3
.
mkIntSymbol
(
nextIntForSymbol
()),
s
))
//
val nameTypePairs = argSorts.map(s => (z3.mkIntSymbol(nextIntForSymbol()), s))
val
fOfX
:
Expr
=
FunctionInvocation
(
funDef
,
funDef
.
args
.
map
(
_
.
toVariable
))
//
val fOfX: Expr = FunctionInvocation(funDef, funDef.args.map(_.toVariable))
val
toConvert
:
Expr
=
if
(
funDef
.
hasPrecondition
)
{
//
val toConvert: Expr = if(funDef.hasPrecondition) {
Implies
(
funDef
.
precondition
.
get
,
Equals
(
fOfX
,
funDef
.
body
.
get
))
//
Implies(funDef.precondition.get, Equals(fOfX, funDef.body.get))
}
else
{
//
} else {
Equals
(
fOfX
,
funDef
.
body
.
get
)
//
Equals(fOfX, funDef.body.get)
}
//
}
val
finalToConvert
=
Analysis
.
rewriteSimplePatternMatching
(
toConvert
)
//
val finalToConvert = Analysis.rewriteSimplePatternMatching(toConvert)
val
initialMap
:
Map
[
String
,
Z3AST
]
=
Map
((
funDef
.
args
.
map
(
_
.
id
.
uniqueName
)
zip
boundVars
)
:_
*
)
//
val initialMap: Map[String,Z3AST] = Map((funDef.args.map(_.id.uniqueName) zip boundVars):_*)
toZ3Formula
(
z3
,
finalToConvert
,
initialMap
)
match
{
//
toZ3Formula(z3, finalToConvert, initialMap) match {
case
Some
(
axiomTree
)
=>
{
//
case Some(axiomTree) => {
val
quantifiedAxiom
=
z3
.
mkForAll
(
0
,
List
(
pattern
),
nameTypePairs
,
axiomTree
)
//
val quantifiedAxiom = z3.mkForAll(0, List(pattern), nameTypePairs, axiomTree)
//z3.printAST(quantifiedAxiom)
//
//z3.printAST(quantifiedAxiom)
z3
.
assertCnstr
(
quantifiedAxiom
)
//
z3.assertCnstr(quantifiedAxiom)
}
//
}
case
None
=>
{
//
case None => {
reporter
.
warning
(
"Could not generate forall axiom for "
+
funDef
.
id
.
name
)
//
reporter.warning("Could not generate forall axiom for " + funDef.id.name)
reporter
.
warning
(
toConvert
)
//
reporter.warning(toConvert)
reporter
.
warning
(
finalToConvert
)
//
reporter.warning(finalToConvert)
}
//
}
}
//
}
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment