Saturday, November 24, 2012

A good reading from WikiBooks


Artical from: http://en.wikibooks.org/wiki/Logic_for_Computer_Scientists/Introduction
Please try not to repost this article somewhere else! thanks --gcseed
In order to define datatypes and to derive efficient implementations for it, the concept of abstract datatype definitions is central. The idea is to define the abstract properties of a datatype, instead of giving special realisations. A very trivial example is the definition of a stack: Let \Sigma be an alphabet. In order to define a stack S over \Sigma we assume clear to be a nullary function and we define the following properties of stacks:
\begin{matrix}
 clear \in S \\

 \forall  s \in S \;  \forall x \in \Sigma \;(push(s,x)\in S)\\ 

 \forall s \in S  \; (s \neq clear \Rightarrow pop(s) \in S)\\

 \forall s \in S  \; (s \neq clear \Rightarrow top(s) \in\Sigma)\\

 \forall s \in S \; (empty(s) \in \{true, false\})\\
\end{matrix}
Hence, we have the functions clear, push and pop, which yield stacks and the predicate empty, furthermore we need the following properties with respect to the push-operation.
\begin{matrix}
\forall s \in S  \; \forall x \in \Sigma   \; (push(s,x)  \neq  clear) \\    

\forall s \in S  \; \forall x,y \in \Sigma \; (push(s,x) = push(s,y) \Rightarrow  x=y)\\

\forall s,t\in S  \; \forall x \in \Sigma  \; (push(s,x) = push(t,x)& \Rightarrow  s=t)\\
\end{matrix}

And we have to give properties with respect of the combinations of functions:
\begin{matrix}
\forall s \in S  \; \forall x \in \Sigma &( top(push(s,x)) = x \land 
pop(push(s,x)) = s)\\

\forall s \in S  \; \forall x \in \Sigma & ( empty(push(s,x))= false)\\

&  empty(clear) = true\\
\end{matrix}
The above formulae state what properties we expect stacks to have. Obviously it contains no hints how to implement such a data type. And indeed this specification is aiming to solve other problems, e.g.
  • Is the specification correct? I.e. is there a set S together with the given operations, such that the axioms above hold?
  • Is the specification complete. I.e. do the axioms imply all the properties we intuitively assume a stack to have? Are there sets S which do not meet our expectations?
The reader may have already noticed, that the axioms are nothing else than formulas in predicate logic, i.e. all logic where variables like x or s together with so called quantifiers \forall and \exists are used. The above two questions, namely correctness and completeness, are very central topics for the design of formal systems in logic. The proof of these properties often is difficult and costly, but on the other hand it is one of the clear advantages of logical systems, that these properties can be proved formally. In the main part of this course we will deal with these questions explicitly.

No comments:

Post a Comment