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
08cdd673
Commit
08cdd673
authored
10 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
Move passes to purescala
parent
e29b1ba2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/purescala.rst
+61
-0
61 additions, 0 deletions
doc/purescala.rst
doc/repair.rst
+3
-37
3 additions, 37 deletions
doc/repair.rst
with
64 additions
and
37 deletions
doc/purescala.rst
+
61
−
0
View file @
08cdd673
...
@@ -297,3 +297,64 @@ Map
...
@@ -297,3 +297,64 @@ Map
m contains index
m contains index
m.updated(index, value)
m.updated(index, value)
Symbolic Input-Output examples
------------------------------
Sometimes, a complete formal specification is hard to write,
especially when it comes to simple, elementary functions. In such cases,
it may be easier to provide a set of IO-examples. On the other hand,
IO-examples can never cover all the possible executions of a function,
and are thus weaker than a formal specification.
Leon provides a powerful compromise between these two extremes.
It introduces *symbolic IO-examples*, expressed through a specialized ``passes``
construct, which resembles pattern-matching:
.. code-block:: scala
sealed abstract class List {
def size: Int = (this match {
case Nil() => 0
case Cons(h, t) => 1 + t.size
}) ensuring { res => (this, res) passes {
case Nil() => 0
case Cons(_, Nil()) => 1
case Cons(_, Cons(_, Nil())) => 2
}}
}
case class Cons[T](h: T, t: List[T]) extends List[T]
case class Nil[T]() extends List[T]
In the above example, the programmer has chosen to partially specify ``size``
through a list of IO-examples, describing what the function should do
for lists of size 0, 1 or 2.
Notice that the examples are symbolic, in that the elements of the lists are
left unconstrained.
The semantics of ``passes`` is the following.
Let ``a: A`` be a tuple of method parameters and/or ``this``, ``b: B``,
and for each i ``pi: A`` and ``ei: B``. Then
.. code-block:: scala
(a, b) passes {
case p1 => e1
case p2 => e2
...
case pN => eN
}
is equivalent to
.. code-block:: scala
a match {
case p1 => b == e1
case p2 => b == e2
...
case pN => b == eN
case _ => true
}
This diff is collapsed.
Click to expand it.
doc/repair.rst
+
3
−
37
View file @
08cdd673
...
@@ -129,15 +129,8 @@ present it as an untrusted solution.
...
@@ -129,15 +129,8 @@ present it as an untrusted solution.
Repairing with IO-examples
Repairing with IO-examples
--------------------------
--------------------------
Sometimes, a complete formal specification is hard to express,
In the :ref:`Pure Scala <purescala>` section, we have presented the ``passes`` construct.
especially when it comes to simple, elementary functions. In such cases,
This construct is especially useful when it comes to repair. Look at the following example:
it may be easier to provide a set of IO-examples. However, IO-examples can never
cover all the possible executions of the function and are thus weaker than a formal
specification.
Leon provides a powerful compromise between these two extremes.
It introduces *symbolic IO-examples*, expressed through a specialized ``passes``
construct, which resembles pattern-matching:
.. code-block:: scala
.. code-block:: scala
...
@@ -163,34 +156,8 @@ In the above example, the programmer has chosen to specify drop through a
...
@@ -163,34 +156,8 @@ In the above example, the programmer has chosen to specify drop through a
list of IO-examples, describing what the function should do in the cases where
list of IO-examples, describing what the function should do in the cases where
the elements to drop are more than the size of the list,
the elements to drop are more than the size of the list,
or 0, 1 or 2 elements are to be dropped by a list with enough elements.
or 0, 1 or 2 elements are to be dropped by a list with enough elements.
Notice that the examples are symbolic, in that the elements of the lists are
left as arbitrary values.
The semantics of ``passes: ( (A, B) => Boolean)`` are the following:
.. code-block:: scala
(a, b) passes {
case p1 => e1
case p2 => e2
...
case pN => eN
}
where ``a: A`` is a tuple of method parameters and/or ``this``, ``b: B``,
Leon manages to repair this program: ::
and for each i ``pi: A`` and ``ei: B``, is equivalent to
.. code-block:: scala
a match {
case p1 => b == e1
case p2 => b == e2
...
case pN => b == eN
case _ => true
}
Leon will manage to repair this program: ::
...
...
[ Info ] Found trusted solution!
[ Info ] Found trusted solution!
...
@@ -207,4 +174,3 @@ Leon will manage to repair this program: ::
...
@@ -207,4 +174,3 @@ Leon will manage to repair this program: ::
[ Info ] }
[ Info ] }
...
...
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