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
c6ad8d6b
Commit
c6ad8d6b
authored
10 years ago
by
Viktor Kuncak
Browse files
Options
Downloads
Patches
Plain Diff
doc: tutorial on sorting
parent
1db7bc27
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/tutorial.rst
+28
-6
28 additions, 6 deletions
doc/tutorial.rst
with
28 additions
and
6 deletions
doc/tutorial.rst
+
28
−
6
View file @
c6ad8d6b
...
...
@@ -11,8 +11,8 @@ types, how to **verify** certain properties of an insertion
sort. We finish showing how to use Leon to **synthesize**
provably correct operations from specifications.
A Preview of Synthesis
^^^^^^^^^^^^^^^^^^^^^^
A Preview of
Specification and
Synthesis
^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^
As a preview, let us start by **specifying** a function that
sorts **two** mathematical integers. Here is what we need
...
...
@@ -57,10 +57,14 @@ Finally, the `choose` construct takes a variable name (here,
`=>` a property that this value should satisfy. This
construct allows us to say that we are interested in
computing a result `res` tuple storing the same set as
`{x,y}` but with `x <= y`.
After typing this code at e.g. http://leon.epfl.ch, we can
select to synthesize a function corresponding to `choose`.
`{x,y}` but with the first component less then or equal the
second one. If we view the input as a list of two elements
and the returned tuple as the resulting list of two
elements, we should have performed a very special case of
sorting. Note that the result is uniquely specified.
After invoking Leon on this code (using e.g. http://leon.epfl.ch), we can
choose to synthesize a function corresponding to `choose`.
The system then synthesizes a computation that satisfies
the specification, such as, for, example:
...
...
@@ -71,6 +75,24 @@ the specification, such as, for, example:
else y
}
Depending on the particular run, Leon may also produce a solution such as
.. code-block:: scala
def sort2(x : BigInt, y : BigInt): (BigInt, BigInt) = {
if (x < y) {
(x, y)
} else if (x == y) {
(x, x)
} else {
(y, x)
}
}
This code performs some unnecessary case analysis, but still
satisfies our specification. In this case, the specification
is unambiguous, so all programs that one can synthesize
compute the same results for all inputs.
Defining lists
^^^^^^^^^^^^^^
...
...
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