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
f5feca73
Commit
f5feca73
authored
9 years ago
by
Samuel Gruetter
Browse files
Options
Downloads
Patches
Plain Diff
add termination evidence to ParBalance testcase
parent
66c9ec79
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/test/resources/regression/verification/purescala/valid/ParBalance.scala
+20
-4
20 additions, 4 deletions
.../regression/verification/purescala/valid/ParBalance.scala
with
20 additions
and
4 deletions
src/test/resources/regression/verification/purescala/valid/ParBalance.scala
+
20
−
4
View file @
f5feca73
...
...
@@ -146,12 +146,21 @@ object ParBalance {
case
Nil
()
=>
Nil
()
}
def
size
(
list
:
List
)
:
BigInt
=
(
list
match
{
case
Nil
()
=>
0
case
Cons
(
h
,
t
)
=>
1
+
size
(
t
)
})
ensuring
(
_
>=
0
)
def
addLast
(
list
:
List
,
x
:
BigInt
)
:
List
=
{
list
match
{
case
Cons
(
head
,
tail
)
=>
Cons
(
head
,
addLast
(
tail
,
x
))
case
Nil
()
=>
Cons
(
x
,
Nil
())
}
}
ensuring
{
res
=>
lastOption
(
res
)
==
Some
(
x
)
&&
init
(
res
)
==
list
}
}
ensuring
{
res
=>
lastOption
(
res
)
==
Some
(
x
)
&&
init
(
res
)
==
list
&&
size
(
list
)
+
1
==
size
(
res
)
}
def
reverse
(
list
:
List
)
:
List
=
{
list
match
{
...
...
@@ -160,7 +169,8 @@ object ParBalance {
}
}
ensuring
{
res
=>
lastOption
(
res
)
==
headOption
(
list
)
&&
lastOption
(
list
)
==
headOption
(
res
)
lastOption
(
list
)
==
headOption
(
res
)
&&
size
(
res
)
==
size
(
list
)
}
def
reverse_tail_equivalence
(
list
:
List
)
:
Boolean
=
{
...
...
@@ -181,10 +191,16 @@ object ParBalance {
})
}.
holds
def
reverse_reverse_equivalence
(
list
:
List
)
:
Boolean
=
{
// In order to prove that this function terminates, we cannot just say
// "it always calls itself with a sub-list of `list`", because `t2` is
// the tail of `reverse(list)`, not the tail of `list` directly.
// So we add another argument `s`, whose only purpose is to be
// always decreasing, so that the termination checker can prove termination.
def
reverse_reverse_equivalence
(
s
:
BigInt
,
list
:
List
)
:
Boolean
=
{
require
(
size
(
list
)
==
s
)
reverse
(
reverse
(
list
))
==
list
&&
((
list
,
reverse
(
list
))
match
{
case
(
Cons
(
h1
,
t1
),
Cons
(
h2
,
t2
))
=>
reverse_reverse_equivalence
(
t1
)
&&
reverse_reverse_equivalence
(
t2
)
reverse_reverse_equivalence
(
size
(
t1
),
t1
)
&&
reverse_reverse_equivalence
(
size
(
t2
),
t2
)
case
_
=>
true
})
}.
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