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
f9e2fb53
Commit
f9e2fb53
authored
10 years ago
by
Viktor Kuncak
Browse files
Options
Downloads
Patches
Plain Diff
doc: more in tutorial
parent
270dad44
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
doc/tutorial.rst
+20
-2
20 additions, 2 deletions
doc/tutorial.rst
with
20 additions
and
2 deletions
doc/tutorial.rst
+
20
−
2
View file @
f9e2fb53
...
@@ -432,7 +432,23 @@ As the starting point, we define size of a list.
...
@@ -432,7 +432,23 @@ As the starting point, we define size of a list.
case Cons(x, rest) => 1 + size(rest)
case Cons(x, rest) => 1 + size(rest)
})
})
We can add a specification that the size is non-negative.
The definition uses *pattern matching* to define size of the
list in the case it is empty (where it is zero) and when it
is non-empty, or, if its non-empty, then it has a head `x`
and the rest of the list `rest`, so the size is one plus the
size of the rest. Thus `size` is a recursive function. A
strength of Leon is that it allows using such recursive
functions in specifications.
It makes little sense to try to write a complete
specification of `size`, given that its recursive definition
is already a pretty clear description of its
meaning. However, it is useful to add a consequence of this
definition, namely that the size is non-negative. The reason
is that Leon most of the time reasons by unfolding `size`,
and the property of size being non-negative is not revealed
by such unfolding. Once specified, the non-negativity is
easily proven and Leon will make use of it.
.. code-block:: scala
.. code-block:: scala
...
@@ -479,7 +495,9 @@ which is a building block for an insertion sort.
...
@@ -479,7 +495,9 @@ which is a building block for an insertion sort.
Leon verifies that the returned list is indeed sorted. Note
Leon verifies that the returned list is indeed sorted. Note
how we are again using a recursively defined function to
how we are again using a recursively defined function to
specify another function.
specify another function. We can introduce a bug into the
definition above and examine the counterexamples that Leon
finds.
Being Sorted is Not Enough
Being Sorted is Not Enough
--------------------------
--------------------------
...
...
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