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
e6dfce7d
Commit
e6dfce7d
authored
10 years ago
by
Regis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
formalize preconditions
parent
bbb45aa9
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/verification.rst
+45
-1
45 additions, 1 deletion
doc/verification.rst
with
45 additions
and
1 deletion
doc/verification.rst
+
45
−
1
View file @
e6dfce7d
...
@@ -44,7 +44,8 @@ important part in a contract is the postcondition. The postcondition specifies
...
@@ -44,7 +44,8 @@ important part in a contract is the postcondition. The postcondition specifies
the behaviour of the function. It takes into account the precondition and only
the behaviour of the function. It takes into account the precondition and only
asserts the property of the output when the input satisfies the precondition.
asserts the property of the output when the input satisfies the precondition.
Formally, we consider a function
Formally, we consider a function with a single parameter (one can generalize
the following for any number of parameters):
.. code-block:: scala
.. code-block:: scala
...
@@ -95,6 +96,49 @@ chapter on Leon's algorithms.
...
@@ -95,6 +96,49 @@ chapter on Leon's algorithms.
Preconditions
Preconditions
*************
*************
Preconditions are used as part of the contract of functions. They are a way to
restrict the input to only relevant inputs, without having to implement guards
and error handling in the functions themselves.
Preconditions are contracts that the call sites should respect, and thus are
not checked as part of verifying the function. Given the following definition:
.. code-block:: scala
def f(x: A): B = {
require(prec)
body
}
For each call site in the whole program (including in ``f`` itself):
.. code-block:: scala
...
f(e)
...
where the expression :math:`\mbox{e}(x)` is an expression of type ``A`` with
free variables among :math:`\{ x \}`. Let us define the path condition on :math:`x`
at that program point as :math:`\mbox{pc}(x)`. The path condition is a formula that
summarizes the facts known about :math:`x` at that call site. A typical example is
when the call site is inside an if expression:
.. code-block:: scala
if(x > 0)
f(x)
The path condition on :math:`x` would include the fact that :math:`x > 0`. This
path condition is then used as a precondition of proving the validity of the
call to :math:`\mbox{f}`. Formally, for each such call site, Leon will attempt
to prove the following theorem:
.. math::
\forall x. \mbox{pc}(x) \implies \mbox{prec}(\mbox{e}(x))
Loop invariants
Loop invariants
***************
***************
...
...
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