Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
why3
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
95
Issues
95
List
Boards
Labels
Milestones
Merge Requests
10
Merge Requests
10
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Why3
why3
Commits
d4ccd8f2
Commit
d4ccd8f2
authored
Jun 18, 2011
by
Andrei Paskevich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update doc/api.tex
parent
05fe04e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
23 deletions
+30
-23
doc/api.tex
doc/api.tex
+30
-23
No files found.
doc/api.tex
View file @
d4ccd8f2
...
...
@@ -23,19 +23,24 @@ a piece of OCaml code for building the formula $true \lor false$.
open Why
(* a ground propositional goal: true or false *)
let fmla
_
true : Term.
fmla = Term.f
_
true
let fmla
_
false : Term.
fmla = Term.f
_
false
let fmla1 : Term.
fmla = Term.f
_
or fmla
_
true fmla
_
false
let fmla
_
true : Term.
term = Term.t
_
true
let fmla
_
false : Term.
term = Term.t
_
false
let fmla1 : Term.
term = Term.t
_
or fmla
_
true fmla
_
false
\end{verbatim}
As one can guess, the type
\texttt
{
fmla
}
is the type of formulas in
the library.
The library uses the common type
\texttt
{
term
}
both for terms
(i.e.~expressions that produce a value of some particular type)
and formulas (i.e.~boolean-valued expressions).
% To distinguish terms from formulas, one can look at the
% \texttt{t_ty} field of the \texttt{term} record: in formulas,
% this field has the value \texttt{None}, and in terms,
% \texttt{Some t}, where \texttt{t} is of type \texttt{Ty.ty}.
Such a formula can be printed using the module
\texttt
{
Pretty
}
providing pretty-printers.
\begin{verbatim}
(* printing
the formula
*)
(* printing
it
*)
open Format
let () = printf "@[formula 1 is:@
%a@]@." Pretty.print_
fmla
fmla1
let () = printf "@[formula 1 is:@
%a@]@." Pretty.print_
term
fmla1
\end{verbatim}
Assuming the lines above are written in a file
\texttt
{
f.ml
}
, it can
...
...
@@ -58,14 +63,16 @@ let prop_var_A : Term.lsymbol =
let prop
_
var
_
B : Term.lsymbol =
Term.create
_
psymbol (Ident.id
_
fresh "B") []
\end{verbatim}
The type
\texttt
{
lsymbol
}
is the type of logic symbols. Then the atoms
$
A
$
and
$
B
$
must be built by the general function for applying a predicate symbol to a list of terms. Here we just need the empty list of arguments.
The type
\texttt
{
lsymbol
}
is the type of function and predicate symbols (which
we call logic symbols for brevity). Then the atoms
$
A
$
and
$
B
$
must be built
by the general function for applying a predicate symbol to a list of terms.
Here we just need the empty list of arguments.
\begin{verbatim}
let atom
_
A : Term.
fmla = Term.f
_
app prop
_
var
_
A []
let atom
_
B : Term.
fmla = Term.f
_
app prop
_
var
_
B []
let fmla2 : Term.
fmla
=
Term.
f
_
implies (Term.f
_
and atom
_
A atom
_
B) atom
_
A
let () = printf "@[formula 2 is:@
%a@]@." Pretty.print_
fmla
fmla2
let atom
_
A : Term.
term = Term.ps
_
app prop
_
var
_
A []
let atom
_
B : Term.
term = Term.ps
_
app prop
_
var
_
B []
let fmla2 : Term.
term
=
Term.
t
_
implies (Term.t
_
and atom
_
A atom
_
B) atom
_
A
let () = printf "@[formula 2 is:@
%a@]@." Pretty.print_
term
fmla2
\end{verbatim}
As expected, the output is as follows.
...
...
@@ -175,7 +182,7 @@ loaded first.
\begin{verbatim}
(* builds the environment from the [loadpath] *)
let env : Env.env =
Lexer.create
_
env
(Whyconf.loadpath main)
Env.create
_
env
_
of
_
loadpath
(Whyconf.loadpath main)
(* loading the Alt-Ergo driver *)
let alt
_
ergo
_
driver : Driver.driver =
Driver.load
_
driver env alt
_
ergo.Whyconf.driver
...
...
@@ -262,7 +269,7 @@ let plus_symbol : Term.lsymbol =
Theory.ns
_
find
_
ls int
_
theory.Theory.th
_
export ["infix +"]
let two
_
plus
_
two : Term.term =
Term.t
_
app
_
infer plus
_
symbol [two;two]
let fmla3 : Term.
fmla = Term.f
_
equ two
_
plus
_
two four
let fmla3 : Term.
term = Term.t
_
equ two
_
plus
_
two four
\end{verbatim}
An important point to notice as that when building the application of
$
+
$
to the arguments, it is checked that the types are correct. Indeed
...
...
@@ -270,7 +277,7 @@ the constructor \texttt{t\_app\_infer} infers the type of the resulting
term. One could also provide the expected type as follows.
\begin{verbatim}
let two
_
plus
_
two : Term.term =
Term.
t
_
app plus
_
symbol [two;two] Ty.ty
_
int
Term.
fs
_
app plus
_
symbol [two;two] Ty.ty
_
int
\end{verbatim}
When building a task with this formula, we need to declare that we use
...
...
@@ -303,20 +310,20 @@ The formula $x*x \geq 0$ is obtained as in the previous example.
\begin{verbatim}
let x : Term.term = Term.t
_
var var
_
x
let x
_
times
_
x : Term.term = Term.t
_
app
_
infer mult
_
symbol [x;x]
let fmla4
_
aux : Term.
fmla = Term.f
_
app ge
_
symbol [x
_
times
_
x;zero]
let fmla4
_
aux : Term.
term = Term.ps
_
app ge
_
symbol [x
_
times
_
x;zero]
\end{verbatim}
To quantify on
$
x
$
, one can first build an intermediate
value of type
\texttt
{
fmla
\_
quant
}
, representing a closure
value of type
\texttt
{
term
\_
quant
}
, representing a closure
under a quantifier:
\begin{verbatim}
let fmla4
_
quant : Term.
fmla
_
quant = Term.f
_
close
_
quant [var
_
x] [] fmla4
_
aux
let fmla4 : Term.
fmla = Term.f
_
forall fmla4
_
quant
let fmla4
_
quant : Term.
term
_
quant = Term.t
_
close
_
quant [var
_
x] [] fmla4
_
aux
let fmla4 : Term.
term = Term.t
_
forall fmla4
_
quant
\end{verbatim}
The second argument of
\texttt
{
f
\_
close
\_
quant
}
is a list of triggers.
The second argument of
\texttt
{
t
\_
close
\_
quant
}
is a list of triggers.
A simpler method would be to use an appropriate function:
\begin{verbatim}
let fmla4bis : Term.
fmla = Term.f
_
forall
_
close [var
_
x] [] fmla4
_
aux
let fmla4bis : Term.
term = Term.t
_
forall
_
close [var
_
x] [] fmla4
_
aux
\end{verbatim}
\section
{
Building Theories
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment