This report presents two versions of the specification. First an implicit
version ($SOCCER-IMPL$) is given then an explicit version ($SOCCER-EXPL$), which may be executed with the toolbox, is presented.
\begin{vdm_al} module SOCCER_IMPL
exportsall
definitions
\end{vdm_al}
\section{Constants, typesandstatevariables}
Two constants are introduced to denote the maximum numbers of substitutions for
goalkeepers ($gk-subs-max$) and field players ($fp-subs-max$). An alternate
model could consider these constants asvariables that must be defined before
the match begins.
A type $player$ is introduced as a renaming for natural numbers. It may as well be further constrained to a range of numbers (e.g.\ natural numbers less
than 17).
\begin{vdm_al} types player = nat1
\end{vdm_al}
The stateof the referee's book may be abstracted to five variables:
\begin{itemize}
\item the setof players on the field
\item the setof potential substitutes
\item the player who is the goal keeper (he is usually a member of the players
on the field, but this isnot mandatory if the team is able to play without
goalkeeper!)
\item the number of goalkeeper substitutions already performed
\item the number of field player substitutions already performed
\end{itemize}
\begin{vdm_al} state R_Book of
on_field_players : setof player
potential_substitutes : setof player
goalkeeper : player
nb_gk_subs : nat
nb_fp_subs : nat
inv mk_R_Book(ofp,ps,gk, ngk, nfp) ==
leq_eleven_players(ofp) and
within_allowed_limits(ngk,nfp) and
gk notinset ps and
ofp inter ps = {}
init r == r =
mk_R_Book({1,2,3,4,5,6,7,8,9,10,11},
{12,13,14,15,16},1,0,0) end
\end{vdm_al}
The state invariant states that there are at most eleven players of the team on
the field, and that the numbers of performed substitutions are less than or equal to the maxima allowed.
It also states that the goalkeeper isnot within the substitutes. In fact, most of the time $gk \in ofp$, except when he has been excluded from the field
($RED-CARD$). It is thus wrong tostateas an invariant that the goalkeeper is
member of $on-field-players$. Finally, the invariant states that a player is
either playing oris a substitute.
The initial state states the initial valuesof the variablesas a series of equalities (not very useful for the IFAD tools, but
allowed by the standard). The initial values are the usual ones in soccer
matches.
%\newpage
\section{Functions}
Two boolean functions are needed for the specification of the invariant.
\begin{vdm_al} functions
\end{vdm_al}
$leq-eleven-players$ states that there are at most eleven players in the set
passed as argument.
\begin{vdm_al}
leq_eleven_players : setof player +> bool
leq_eleven_players(f) == (card f) <= 11
;
\end{vdm_al}
$within-allowed-limits$ states that its arguments are less than or equal to
the two constants $gk-subs-max$ and $fp-subs-max$ respectively.
\begin{itemize}
\item the referee gives a red cardto one of the players
\item the goalkeeper is changed to another field player
\item the substitution of a player by another player
\end{itemize}
\begin{vdm_al} operations
\end{vdm_al}
The $RED-CARD$ operation takes the excluded player as argument.
The player may be any of the team players, so the pre-condition states that he isin one of both sets $on-field-players$ and $potential-substitutes$. The
post-condition states that he no longer appears in any of these sets and that
everything else remains unchanged.
\begin{vdm_al}
RED_CARD (p : player) extwr on_field_players : setof player wr potential_substitutes : setof player pre p inset on_field_players or p inset potential_substitutes post on_field_players = on_field_players~ \ {p} and potential_substitutes = potential_substitutes~ \ {p}
;
\end{vdm_al}
The second operation $CHANGE-GOALKEEPER$ expresses that one of the field
players takes the role of goal keeper. The pre-condition states that the player is on the field (not really mandatory, but often useful) and the post-condition
that he is the goal keeper.
\begin{vdm_al}
CHANGE_GOALKEEPER (p : player) extwr goalkeeper : player rd on_field_players : setof player pre p inset on_field_players post goalkeeper = p
;
\end{vdm_al}
The last operation expresses the substitution of a player by another. Depending
on the status of goalkeeper of the player who quits the field, the relevant
variable ($nb-gk-subs$ or $nb-fp-subs$) is updated. The pre-condition states
that the player is on the field, that the substitute is a valid substitute, and
that the maximum number of substitutions has notyet been reached. The
post-condition states that the substitute is on the field and that $pl$ no
longer participates in the match. It also states that $subs$ is the new
goalkeeper if $pl$ was goalkeeper. Finally, it updates the substitution
counters.
\begin{vdm_al}
SUBSTITUTION (pl : player, subs: player) extwr on_field_players : setof player wr potential_substitutes : setof player wr goalkeeper : player wr nb_gk_subs : nat wr nb_fp_subs : nat pre pl inset on_field_players and subs inset potential_substitutes and (pl = goalkeeper => within_allowed_limits(nb_gk_subs+1,nb_fp_subs)) and (pl <> goalkeeper => within_allowed_limits(nb_gk_subs,nb_fp_subs+1)) post on_field_players = on_field_players~ union {subs} \ {pl} and potential_substitutes = potential_substitutes~ \ {subs} and (pl = goalkeeper~ =>
((goalkeeper = subs) and (nb_gk_subs = nb_gk_subs~ +1 ) and (nb_fp_subs = nb_fp_subs~))) and (pl <> goalkeeper~ =>
((goalkeeper = goalkeeper~) and (nb_gk_subs = nb_gk_subs~) and (nb_fp_subs = nb_fp_subs~ +1)))
;
\end{vdm_al}
\subsection*{Alternate specification}
An alternate way tostate this specification isto express two distinct operationsfor the goalkeeper and the field player substitutions andthento
combine the results into a single explicit operation.
\begin{vdm_al}
SUBSTITUTION_GK (pl : player, subs: player) extwr on_field_players : setof player wr potential_substitutes : setof player wr goalkeeper : player wr nb_gk_subs : nat rd nb_fp_subs : nat pre pl inset on_field_players and subs inset potential_substitutes and pl = goalkeeper and within_allowed_limits(nb_gk_subs+1,nb_fp_subs) post on_field_players = on_field_players~ union {subs} \ {pl} and potential_substitutes = potential_substitutes~ \ {subs} and goalkeeper = subs and nb_gk_subs = nb_gk_subs~ +1
;
SUBSTITUTION_FP (pl : player, subs: player) extwr on_field_players : setof player wr potential_substitutes : setof player rd goalkeeper : player rd nb_gk_subs : nat wr nb_fp_subs : nat pre pl inset on_field_players and subs inset potential_substitutes and pl <> goalkeeper and within_allowed_limits(nb_gk_subs,nb_fp_subs+1) post on_field_players = on_field_players~ union {subs} \ {pl} and potential_substitutes = potential_substitutes~ \ {subs} and nb_fp_subs = nb_fp_subs~ +1
;
SUBSTITUTION_EXPL : player * player ==> ()
SUBSTITUTION_EXPL (pl , subs)
== if pl = goalkeeper then SUBSTITUTION_GK(pl,subs) else SUBSTITUTION_FP(pl,subs) pre (pl = goalkeeper =>
pre_SUBSTITUTION_GK(pl,subs,
mk_R_Book(on_field_players,potential_substitutes,
goalkeeper,nb_gk_subs, nb_fp_subs))) and (pl <> goalkeeper =>
pre_SUBSTITUTION_FP(pl,subs,
mk_R_Book(on_field_players,potential_substitutes,
goalkeeper,nb_gk_subs,nb_fp_subs))) end SOCCER_IMPL
\end{vdm_al}
%
% Note: this results in the following errorin tc def
%vdm> tc SOCCER_IMPL def
%Typechecking module SOCCER_IMPL ...
%ERRORS: 2 WARNINGS: 0
%Error : Function isnot applied with parameters of the correct type
%act : ( player * player * compose R_Book of ( setof player | {} ) ( setof player | {} ) player natnatend )
%exp : ( player * player * inv_(compose R_Book of ( setof player | {} ) ( setof player | {} ) player natnatend) )
%At line: 298 column: 51
%
% The explanation for this erroris that the third argument isnot a simple
% composite but is associated to an invariant. The systemisnot able to
% check that this invariant is fulfilled.
\section{Italy vs Norway}
We are now able to analyse the Italy-Norway game. Actually, the following
sequence ofoperationsis invalid:
So Baggio has exited the match as being the goalkeeper.
%\footnote{I don't claim
%that this formalisation of the soccer rules is the right one; but I hope it
%provides an entertaining example.}
\subsection*{Animation of the specification}
The specification of the soccer referee's book is sufficiently precise to
reason about the valid and invalid sequences ofoperationsandto decide that
Baggio had toexit the match in the role of the goalkeeper. Still, one might
find it interesting to simulate these sequences ofoperationsby ``executing''
the specification. The IFAD toolbox
\cite{elmstrom94} allows to execute VDM specifications expressed in an explicit
style. This style sets several restrictions on the way the initial stateis specifiedand also requires the operationstobe expressed in terms of
imperative statements rather than pre- and post-conditions.
The soccer referee's book may be easily translated into an explicit style.
It turns out that the post-conditions ofoperations are conjunctions of
equalities. These can be implemented by sequences of assignments. Appendix
\ref{VDMexplcode} presents an explicit version of the specification. This
explicit version may be executed with the toolbox as shown in appendix
\ref{VDMexe}. The dynamic evaluation of pre-condition helps to detect the
wrong sequences ofoperations.
The soccer referee's book specification was originally developped with the
KIDS/VDM environment
\cite{ledru92b,ledru94b}.
This environment is based on the program synthesis capabilities of the KIDS system \cite{smith90b}. It allows the semi-automatic translation of
VDM specifications into the REFINE language.
Appendix \ref{REFINEcode} shows the REFINE code generated from the implicit
specification. This synthesis process is semi-automatic, i.e.\ it is a
combination of automatic generation and user interaction. Nevertheless, every
synthesis step is performed under the control of the tool which guarantees the
correspondence between the implicit VDM specification and the resulting code.
The execution of this code is given in appendix \ref{REFINEexe}. It is very
similar to the execution performed with the toolbox, except that pre- and
post-condition are not checked at execution time.
\subsection*{Acknowledgments}
Thanks to Marie-Laure Potet and Peter Gorm Larsen for their comments on a first
version of this document.
\bibitem[ELL94]{elmstrom94}
R.~Elmstrom, P.~G. Larsen, and P.~B. Lassen.
\newblock The {IFAD VDM-SL} toolbox : a practical approach to formal
specifications.
\newblock {\em ACM SIGPLAN Notices}, 29(9), 1994.
\bibitem[Led94]{ledru94b}
Y.~Ledru.
\newblock Proof-based development of specifications with {KIDS/VDM}.
\newblock In M.~Naftalin, Tim Denvir, and Miquel Bertran, editors, {\em FME'94:
Industrial Benefit of Formal Methods}, volume 873 of {\em Lecture Notes in
Computer Science}, pages 214--232. Springer-Verlag, 1994.
\bibitem[LL92]{ledru92b}
Y.~Ledru and M.-H. Li\'{e}geois.
\newblock {Prototyping VDM specifications with KIDS}.
\newblock In {\em Proceedings of the 7th Knowledge-Based Software Engineering
Conference}. IEEE Computer Society Press, 1992.
\bibitem[Smi90]{smith90b}
D.R. Smith.
\newblock {KIDS: a semi-automatic program development system}.
\newblock {\em IEEE Transactions on Software Engineering --- Special Issue on
Formal Methods,}, 16(9), 1990.
\end{thebibliography}
\newpage
\appendix
\section{Explicit definition}\label{VDMexplcode}
This appendix provides an explicit specification to the Referee's Book specification.
\begin{vdm_al} state R_Book of
on_field_players : setof player
potential_substitutes : setof player
goalkeeper : player
nb_gk_subs : nat
nb_fp_subs : nat inv mk_R_Book(ofp,ps,gk, ngk, nfp) ==
leq_eleven_players(ofp) and
within_allowed_limits(ngk,nfp) and
gk notinset ps and
ofp inter ps = {}
init r == r = mk_R_Book({1,2,3,4,5,6,7,8,9,10,11}, {12,13,14,15,16}, 1, 0, 0) end
\end{vdm_al}
\begin{vdm_al}
RED_CARD : player ==> ()
RED_CARD (p) ==
(
on_field_players := on_field_players \ {p};
potential_substitutes := potential_substitutes \ {p}
) pre p inset on_field_players or p inset potential_substitutes post on_field_players = on_field_players~ \ {p} and potential_substitutes = potential_substitutes~ \ {p}
;
\end{vdm_al}
\begin{vdm_al}
CHANGE_GOALKEEPER : player ==> ()
CHANGE_GOALKEEPER (p) ==
(
goalkeeper := p
) pre p inset on_field_players post goalkeeper = p
;
\end{vdm_al}
\begin{vdm_al}
SUBSTITUTION : player * player ==> ()
SUBSTITUTION (pl, subs) ==
( on_field_players := on_field_players union {subs} \ {pl};
potential_substitutes := potential_substitutes \ {subs}; if pl = goalkeeper then (goalkeeper := subs;
nb_gk_subs := nb_gk_subs +1) else nb_fp_subs := nb_fp_subs +1
) pre pl inset on_field_players and subs inset potential_substitutes and (pl = goalkeeper => within_allowed_limits(nb_gk_subs+1,nb_fp_subs)) and (pl <> goalkeeper => within_allowed_limits(nb_gk_subs,nb_fp_subs+1)) post on_field_players = on_field_players~ union {subs} \ {pl} and potential_substitutes = potential_substitutes~ \ {subs} and (pl = goalkeeper~ =>
((goalkeeper = subs) and (nb_gk_subs = nb_gk_subs~ +1 ) and (nb_fp_subs = nb_fp_subs~))) and (pl <> goalkeeper~ =>
((goalkeeper = goalkeeper~) and (nb_gk_subs = nb_gk_subs~) and (nb_fp_subs = nb_fp_subs~ +1)))
;
\end{vdm_al}
\begin{vdm_al}
SUBSTITUTION_GK : player * player ==> ()
SUBSTITUTION_GK (pl , subs) ==
(
on_field_players := on_field_players union {subs} \ {pl};
potential_substitutes := potential_substitutes \ {subs};
goalkeeper := subs;
nb_gk_subs := nb_gk_subs +1
) pre pl inset on_field_players and subs inset potential_substitutes and pl = goalkeeper and within_allowed_limits(nb_gk_subs+1,nb_fp_subs) post on_field_players = on_field_players~ union {subs} \ {pl} and potential_substitutes = potential_substitutes~ \ {subs} and goalkeeper = subs and nb_gk_subs = nb_gk_subs~ +1
;
SUBSTITUTION_FP : player *player ==> ()
SUBSTITUTION_FP (pl , subs) ==
(
on_field_players := on_field_players union {subs} \ {pl};
potential_substitutes := potential_substitutes \ {subs};
nb_fp_subs := nb_fp_subs +1
) pre pl inset on_field_players and subs inset potential_substitutes and pl <> goalkeeper and within_allowed_limits(nb_gk_subs,nb_fp_subs+1) post on_field_players = on_field_players~ union {subs} \ {pl} and potential_substitutes = potential_substitutes~ \ {subs} and nb_fp_subs = nb_fp_subs~ +1
;
SUBSTITUTION_EXPL : player * player ==> ()
SUBSTITUTION_EXPL (pl , subs) == if pl = goalkeeper then SUBSTITUTION_GK(pl,subs) else SUBSTITUTION_FP(pl,subs) pre (pl = goalkeeper =>
pre_SUBSTITUTION_GK(pl,subs,
mk_R_Book(on_field_players,potential_substitutes,
goalkeeper,nb_gk_subs, nb_fp_subs))) and (pl <> goalkeeper =>
pre_SUBSTITUTION_FP(pl,subs,
mk_R_Book(on_field_players,potential_substitutes,
goalkeeper,nb_gk_subs,nb_fp_subs)))
end SOCCER_EXPL
\end{vdm_al}
\section{Execution of the explicit specification}\label{VDMexe}
This can be experimented with the VDM debugger of the IFAD toolbox.
{\small \begin{verbatim}
First execution : leads to an incorrect state.
\section{REFINE code synthesized with KIDS/VDM}\label{REFINEcode}
The following REFINE\footnote{REFINE is a trademark of Reasoning Systems.}
code has been synthesized semi-automaticaly with the KIDS/VDM systemfrom the
implicit specification $SOCCER-IMPL$.
\vspace{0.5cm}
% The following macros are taken from the KIDS preamble file
\def\NEWLINE{\hspace*{1em}\newline}
\def\ASSIGN{$\leftarrow$}
\def\NLSET{\{}\def\BLSET{{\large\tt\char'173}}
\def\NRSET{\/$\}$}\def\BRSET{{\large\tt\char'175}}
\def\SETDIFF{$\backslash$}
\def\UNION{$\cup$}
\def\MATHDE{\it{\gdef\useridentifier{\it}\gdef\LSET{\NLSET}\gdef\RSET{\NRSET}\gdef\LMAP{\NLMAP}\gdef\RMAP{\NRMAP}}}
\section{Execution of the REFINE code}\label{REFINEexe}
Here comes a trace of the execution of the REFINE code. It is very similar to
the execution of the explicit VDM specification. The only difference is that
this execution does not evaluate the pre- and post-conditions, so no erroris
reported. One way to detect these problems isto synthesize code for the pre- and post-conditions, orfor the invariant and evaluate these on the state
before and after each operation.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.