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
929559dd
Commit
929559dd
authored
9 years ago
by
Viktor Kuncak
Browse files
Options
Downloads
Patches
Plain Diff
doc: more on tutorial
parent
543488bf
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
+41
-2
41 additions, 2 deletions
doc/tutorial.rst
with
41 additions
and
2 deletions
doc/tutorial.rst
+
41
−
2
View file @
929559dd
...
@@ -113,7 +113,7 @@ defined the reference implementation
...
@@ -113,7 +113,7 @@ defined the reference implementation
.. code-block:: scala
.. code-block:: scala
def rmax(x: BigInt, y: BigInt) = {
def rmax(x: BigInt, y: BigInt) = {
if (x <= y)
x
else
y
if (x <= y)
y
else
x
}
}
and then used as postcondition of `max` simply
and then used as postcondition of `max` simply
...
@@ -184,6 +184,45 @@ behavior of Leon.
...
@@ -184,6 +184,45 @@ behavior of Leon.
In the sequel we will mostly use `BigInt` types.
In the sequel we will mostly use `BigInt` types.
Let us now look at synthesis. Suppose we omit
the implementation of `max`, keeping the specification
in the ensuring clause but using only a placeholder
`???[BigInt]` indicating we are looking for an unknown implementation
of an integer type.
.. code-block:: scala
def max(x: BigInt, y: BigInt): BigInt = {
???[BigInt]
} ensuring(res => (res == x || res == y) && x <= res && y <= res)
Leon can then automatically generate an implementation that satisfies
this specification, such as
.. code-block:: scala
if (y <= x) {
x
} else {
y
}
This is remarkable because we have much more freedom in
writing specifications: we can explain the intention of the
computation using a conjunction of orthogonal properties,
and still obtain automatically an efficient implementation.
As a remark, an expression with missing parts in Leon is
an abbreviation for Leon's `choose` construct. Using `choose`
we can write the above example as
.. code-block:: scala
def max(x: BigInt, y: BigInt): BigInt = choose((res:BigInt) =>
(res == x || res == y) && x <= res && y <= res)
We explain `choose` in more detail through our subsequent examples.
Sorting Two Elements
Sorting Two Elements
--------------------
--------------------
...
@@ -193,7 +232,7 @@ write.
...
@@ -193,7 +232,7 @@ write.
.. code-block:: scala
.. code-block:: scala
import leon.lang.
_
import leon.lang.
Set
import leon.lang.synthesis._
import leon.lang.synthesis._
object Sort {
object Sort {
def sort2(x : BigInt, y : BigInt) = choose{(res: (BigInt,BigInt)) =>
def sort2(x : BigInt, y : BigInt) = choose{(res: (BigInt,BigInt)) =>
...
...
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