Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
javawlp
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
Model registry
Operate
Environments
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
impresshs
javawlp
Commits
90cba87c
Verified
Commit
90cba87c
authored
7 years ago
by
Ogilvie, D.H. (Duncan)
Browse files
Options
Downloads
Patches
Plain Diff
implemented some of the z3 backend
parent
ed94ff22
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/LogicIR/Backend/Z3.hs
+29
-7
29 additions, 7 deletions
src/LogicIR/Backend/Z3.hs
src/SimpleFormulaChecker.hs
+9
-2
9 additions, 2 deletions
src/SimpleFormulaChecker.hs
src/z3_tests/equivalence.py
+20
-1
20 additions, 1 deletion
src/z3_tests/equivalence.py
with
58 additions
and
10 deletions
src/LogicIR/Backend/Z3.hs
+
29
−
7
View file @
90cba87c
...
@@ -10,16 +10,38 @@ lExprToZ3Ast = foldLExpr lExprToZ3AstAlgebra
...
@@ -10,16 +10,38 @@ lExprToZ3Ast = foldLExpr lExprToZ3AstAlgebra
lExprToZ3AstAlgebra
::
LExprAlgebra
(
Z3
AST
)
lExprToZ3AstAlgebra
::
LExprAlgebra
(
Z3
AST
)
lExprToZ3AstAlgebra
=
(
flConst
,
flVar
,
flNot
,
flBinop
,
flComp
,
flQuant
,
flArray
,
flNil
,
fnConst
,
fnUnop
,
fnBinop
,
fnIf
,
fnLen
)
where
lExprToZ3AstAlgebra
=
(
flConst
,
flVar
,
flNot
,
flBinop
,
flComp
,
flQuant
,
flArray
,
flNil
,
fnConst
,
fnUnop
,
fnBinop
,
fnIf
,
fnLen
)
where
flConst
=
undefined
flConst
b
=
mkBool
b
flVar
=
undefined
flVar
(
Var
t
n
)
=
do
symbol
<-
mkStringSymbol
n
flNot
=
undefined
case
t
of
flBinop
=
undefined
TPrim
PInt
->
mkIntVar
symbol
flComp
=
undefined
TPrim
PBool
->
mkBoolVar
symbol
_
->
error
$
show
n
flNot
a
=
a
>>=
mkNot
flBinop
a'
o
b'
=
do
a
<-
a'
b
<-
b'
case
o
of
LAnd
->
mkAnd
[
a
,
b
]
LOr
->
mkOr
[
a
,
b
]
LImpl
->
mkImplies
a
b
LBicond
->
undefined
flComp
a'
o
b'
=
do
a
<-
a'
b
<-
b'
case
o
of
CEqual
->
mkEq
a
b
CNEqual
->
mkEq
a
b
>>=
mkNot
CLess
->
mkLt
a
b
CGreater
->
mkGt
a
b
CLeq
->
mkLe
a
b
CGeq
->
mkGe
a
b
flQuant
=
undefined
flQuant
=
undefined
flArray
=
undefined
flArray
=
undefined
flNil
=
undefined
flNil
=
undefined
fnConst
=
undefined
fnConst
n
=
mkInteger
(
fromIntegral
n
)
fnUnop
=
undefined
fnUnop
=
undefined
fnBinop
=
undefined
fnBinop
a'
o
b'
=
do
a
<-
a'
b
<-
b'
case
o
of
NAdd
->
mkAdd
[
a
,
b
]
_
->
undefined
fnIf
=
undefined
fnIf
=
undefined
fnLen
=
undefined
fnLen
=
undefined
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/SimpleFormulaChecker.hs
+
9
−
2
View file @
90cba87c
...
@@ -15,6 +15,8 @@ import LogicIR.Frontend.Java
...
@@ -15,6 +15,8 @@ import LogicIR.Frontend.Java
import
LogicIR.Backend.Z3
import
LogicIR.Backend.Z3
import
LogicIR.Backend.Pretty
import
LogicIR.Backend.Pretty
import
Control.Monad.Trans
(
liftIO
)
import
Debug.Trace
import
Debug.Trace
{-
{-
...
@@ -113,7 +115,12 @@ determineFormulaEq m1@(decls1, mbody1, env1) m2@(decls2, mbody2, env2) name = do
...
@@ -113,7 +115,12 @@ determineFormulaEq m1@(decls1, mbody1, env1) m2@(decls2, mbody2, env2) name = do
let
(
e1
,
e2
)
=
(
extractCond
m1
name
,
extractCond
m2
name
)
let
(
e1
,
e2
)
=
(
extractCond
m1
name
,
extractCond
m2
name
)
putStrLn
$
"e1:
\n
"
++
prettyPrint
e1
++
"
\n\n
e2:
\n
"
++
prettyPrint
e2
++
"
\n
"
putStrLn
$
"e1:
\n
"
++
prettyPrint
e1
++
"
\n\n
e2:
\n
"
++
prettyPrint
e2
++
"
\n
"
let
lexpr
=
javaExpToLExpr
e1
env1
decls1
let
lexpr
=
javaExpToLExpr
e1
env1
decls1
putStrLn
$
show
lexpr
++
"
\n\n
"
++
prettyLExpr
lexpr
putStrLn
$
"LogicIR.Expr:
\n
"
++
show
lexpr
++
"
\n\n
LogicIR.Pretty:
\n
"
++
prettyLExpr
lexpr
putStrLn
"
\n
Z3 AST:"
evalZ3
$
do
asd
<-
lExprToZ3Ast
lexpr
zprint
astToString
asd
return
asd
putStrLn
"
\n
Z3 Result:"
{--- get postconditions
{--- get postconditions
let (post1, post2) = (extractCond m1 "post", extractCond m2 "post")
let (post1, post2) = (extractCond m1 "post", extractCond m2 "post")
putStrLn $ "post1:\n" ++ prettyPrint post1 ++ "\npost2:\n" ++ prettyPrint post2 ++ "\n"-}
putStrLn $ "post1:\n" ++ prettyPrint post1 ++ "\npost2:\n" ++ prettyPrint post2 ++ "\n"-}
...
@@ -149,4 +156,4 @@ edslSrc = "javawlp_edsl/src/nl/uu/javawlp_edsl/Main.java"
...
@@ -149,4 +156,4 @@ edslSrc = "javawlp_edsl/src/nl/uu/javawlp_edsl/Main.java"
testEq
=
compareSpec
(
edslSrc
,
"swap_spec1"
)
(
edslSrc
,
"swap_spec1"
)
testEq
=
compareSpec
(
edslSrc
,
"swap_spec1"
)
(
edslSrc
,
"swap_spec1"
)
testNeq
=
compareSpec
(
edslSrc
,
"swap_spec1"
)
(
edslSrc
,
"swap_spec2"
)
testNeq
=
compareSpec
(
edslSrc
,
"swap_spec1"
)
(
edslSrc
,
"swap_spec2"
)
blub
=
compareSpec
(
edslSrc
,
"getMax_spec1"
)
(
edslSrc
,
"getMax_spec1"
)
blub
=
compareSpec
(
edslSrc
,
"simple1"
)
(
edslSrc
,
"simple1"
)
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/z3_tests/equivalence.py
+
20
−
1
View file @
90cba87c
...
@@ -55,6 +55,7 @@ def neq_forall2():
...
@@ -55,6 +55,7 @@ def neq_forall2():
solve
(
ast
)
solve
(
ast
)
def
neq_forall3
():
def
neq_forall3
():
return
print
"
3
"
print
"
3
"
x
=
Int
(
'
x
'
)
x
=
Int
(
'
x
'
)
ast1
=
ForAll
(
x
,
x
*
x
>=
x
,
patterns
=
[
x
])
ast1
=
ForAll
(
x
,
x
*
x
>=
x
,
patterns
=
[
x
])
...
@@ -66,6 +67,22 @@ def neq_forall3():
...
@@ -66,6 +67,22 @@ def neq_forall3():
# A <=> B means A => B and B => A, so if we prove (A & ~B), A => B doesn't hold so A != B
# A <=> B means A => B and B => A, so if we prove (A & ~B), A => B doesn't hold so A != B
# - joao
# - joao
def
python_is_super_hot
():
print
"
SUPER HOT
"
IntArray
=
ArraySort
(
IntSort
(),
IntSort
())
ArrayRef
=
Datatype
(
'
ArrayRef
'
)
ArrayRef
.
declare
(
'
NotNull
'
,
(
'
Value
'
,
IntArray
))
ArrayRef
.
declare
(
'
Null
'
)
ArrayRef
=
ArrayRef
.
create
()
print
ArrayRef
.
Null
print
ArrayRef
.
NotNull
nullArr
=
Array
(
'
null
'
,
IntSort
(),
IntSort
())
arr
=
Array
(
'
a
'
,
IntSort
(),
IntSort
())
solve
(
arr
==
nullArr
)
help_simplify
()
eq
()
eq
()
print
""
print
""
neq
()
neq
()
...
@@ -74,4 +91,6 @@ neq_forall()
...
@@ -74,4 +91,6 @@ neq_forall()
print
""
print
""
neq_forall2
()
neq_forall2
()
print
""
print
""
neq_forall3
()
neq_forall3
()
\ No newline at end of file
print
""
python_is_super_hot
()
\ No newline at end of file
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