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
0b075615
Commit
0b075615
authored
9 years ago
by
ravi
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring Conqueue
parent
4c89c7b6
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
testcases/lazy-datastructures/conc/Conqueue.scala
+19
-19
19 additions, 19 deletions
testcases/lazy-datastructures/conc/Conqueue.scala
with
19 additions
and
19 deletions
testcases/lazy-datastructures/conc/Conqueue.scala
+
19
−
19
View file @
0b075615
...
...
@@ -51,13 +51,13 @@ object Conqueue {
/**
* Checks whether there is a zero before an unevaluated closure
*/
def
zeroPrece
e
dsLazy
[
T
](
q
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
def
zeroPreced
e
sLazy
[
T
](
q
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
if
(
q
.
isEvaluated
)
{
q
*
match
{
case
Spine
(
Empty
(),
_
,
rear
)
=>
true
// here we have seen a zero
case
Spine
(
h
,
_
,
rear
)
=>
zeroPrece
e
dsLazy
(
rear
)
//here we have not seen a zero
zeroPreced
e
sLazy
(
rear
)
//here we have not seen a zero
case
Tip
(
_
)
=>
true
}
}
else
false
...
...
@@ -66,12 +66,12 @@ object Conqueue {
/**
* Checks whether there is a zero before a given suffix
*/
def
zeroPrece
e
dsSuf
[
T
](
q
:
$
[
ConQ
[
T
]],
suf
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
def
zeroPreced
e
sSuf
[
T
](
q
:
$
[
ConQ
[
T
]],
suf
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
if
(
q
!=
suf
)
{
q
*
match
{
case
Spine
(
Empty
(),
_
,
rear
)
=>
true
case
Spine
(
_
,
_
,
rear
)
=>
zeroPrece
e
dsSuf
(
rear
,
suf
)
zeroPreced
e
sSuf
(
rear
,
suf
)
case
Tip
(
_
)
=>
false
}
}
else
false
...
...
@@ -124,7 +124,7 @@ object Conqueue {
q
.
isEvaluated
&&
{
schs
match
{
case
Cons
(
head
,
tail
)
=>
zeroPrece
e
dsSuf
(
q
,
head
)
// zeroPrece
e
dsSuf holds initially
zeroPreced
e
sSuf
(
q
,
head
)
// zeroPreced
e
sSuf holds initially
case
Nil
()
=>
true
}
}
&&
...
...
@@ -150,7 +150,7 @@ object Conqueue {
}
def
pushLeft
[
T
](
ys
:
Single
[
T
],
xs
:
$
[
ConQ
[
T
]])
:
ConQ
[
T
]
=
{
require
(
zeroPrece
e
dsLazy
(
xs
))
require
(
zeroPreced
e
sLazy
(
xs
))
xs
.
value
match
{
case
Tip
(
CC
(
_
,
_
))
=>
Spine
(
ys
,
False
(),
xs
)
...
...
@@ -168,13 +168,13 @@ object Conqueue {
// this procedure does not change state
@invstate
def
pushLeftLazy
[
T
](
ys
:
Conc
[
T
],
xs
:
$
[
ConQ
[
T
]])
:
ConQ
[
T
]
=
{
require
(!
ys
.
isEmpty
&&
zeroPrece
e
dsLazy
(
xs
)
&&
require
(!
ys
.
isEmpty
&&
zeroPreced
e
sLazy
(
xs
)
&&
(
xs
*
match
{
case
Spine
(
h
,
_
,
_
)
=>
h
!=
Empty
[
T
]()
case
_
=>
false
}))
xs
.
value
match
{
case
Spine
(
head
,
_
,
rear
)
=>
// here, rear is guaranteed to be evaluated by 'zeroPrece
e
dsLazy' invariant
case
Spine
(
head
,
_
,
rear
)
=>
// here, rear is guaranteed to be evaluated by 'zeroPreced
e
sLazy' invariant
val
carry
=
CC
(
head
,
ys
)
//here, head and ys are of the same level
rear
.
value
match
{
case
s
@
Spine
(
Empty
(),
_
,
srear
)
=>
...
...
@@ -215,7 +215,7 @@ object Conqueue {
*/
@invstate
def
pushLeftLazyLemma
[
T
](
ys
:
Conc
[
T
],
xs
:
$
[
ConQ
[
T
]],
suf
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
require
(!
ys
.
isEmpty
&&
zeroPrece
e
dsSuf
(
xs
,
suf
)
&&
require
(!
ys
.
isEmpty
&&
zeroPreced
e
sSuf
(
xs
,
suf
)
&&
(
xs
*
match
{
case
Spine
(
h
,
_
,
_
)
=>
h
!=
Empty
[
T
]()
case
_
=>
false
...
...
@@ -237,7 +237,7 @@ object Conqueue {
case
_
=>
true
}
})
&&
// instantiate the lemma that implies zeroPrece
e
dsLazy
// instantiate the lemma that implies zeroPreced
e
sLazy
(
if
(
zeroPredSufConcreteUntilLemma
(
xs
,
suf
))
{
// property
(
pushLeftLazy
(
ys
,
xs
)
match
{
...
...
@@ -249,7 +249,7 @@ object Conqueue {
def
pushLeftWrapper
[
T
](
ys
:
Single
[
T
],
w
:
Queue
[
T
])
=
{
require
(
w
.
valid
&&
// instantiate the lemma that implies zeroPrece
e
dsLazy
// instantiate the lemma that implies zeroPreced
e
sLazy
(
w
.
schedule
match
{
case
Cons
(
h
,
_
)
=>
zeroPredSufConcreteUntilLemma
(
w
.
queue
,
h
)
...
...
@@ -320,7 +320,7 @@ object Conqueue {
})
case
_
=>
true
})
&&
// instantiations for zeroPrece
e
dsSuf property
// instantiations for zeroPreced
e
sSuf property
(
scheds
match
{
case
Cons
(
head
,
rest
)
=>
(
concreteUntilIsSuffix
(
q
,
head
)
withState
in
)
&&
...
...
@@ -328,7 +328,7 @@ object Conqueue {
case
Cons
(
rhead
,
rtail
)
=>
concreteUntilIsSuffix
(
pushUntilCarry
(
head
),
rhead
)
&&
suffixZeroLemma
(
q
,
head
,
rhead
)
&&
zeroPrece
e
dsSuf
(
q
,
rhead
)
zeroPreced
e
sSuf
(
q
,
rhead
)
case
_
=>
true
})
...
...
@@ -450,20 +450,20 @@ object Conqueue {
(
concreteUntil
(
q
,
suf1
)
&&
concreteUntil
(
suf1
,
suf2
))
==>
concreteUntil
(
q
,
suf2
)
}
holds
// properties that relate `concUntil`, `concrete`, `zeroPrece
e
dsSuf` with `zeroPrece
e
dsLazy`
// - these are used in preconditions to derive the `zeroPrece
e
dsLazy` property
// properties that relate `concUntil`, `concrete`, `zeroPreced
e
sSuf` with `zeroPreced
e
sLazy`
// - these are used in preconditions to derive the `zeroPreced
e
sLazy` property
@traceInduct
def
zeroPredSufConcreteUntilLemma
[
T
](
q
:
$
[
ConQ
[
T
]],
suf
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
(
zeroPrece
e
dsSuf
(
q
,
suf
)
&&
concreteUntil
(
q
,
suf
))
==>
zeroPrece
e
dsLazy
(
q
)
(
zeroPreced
e
sSuf
(
q
,
suf
)
&&
concreteUntil
(
q
,
suf
))
==>
zeroPreced
e
sLazy
(
q
)
}
holds
@traceInduct
def
concreteZeroPredLemma
[
T
](
q
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
isConcrete
(
q
)
==>
zeroPrece
e
dsLazy
(
q
)
isConcrete
(
q
)
==>
zeroPreced
e
sLazy
(
q
)
}
holds
// properties relating `suffix` an `zeroPrece
e
dsSuf`
// properties relating `suffix` an `zeroPreced
e
sSuf`
def
suffixZeroLemma
[
T
](
q
:
$
[
ConQ
[
T
]],
suf
:
$
[
ConQ
[
T
]],
suf2
:
$
[
ConQ
[
T
]])
:
Boolean
=
{
require
(
suf
*
match
{
...
...
@@ -481,7 +481,7 @@ object Conqueue {
true
}
}
else
true
)
&&
zeroPrece
e
dsSuf
(
q
,
suf2
)
// property
zeroPreced
e
sSuf
(
q
,
suf2
)
// property
}.
holds
/**
...
...
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