]> matita.cs.unibo.it Git - helm.git/blob - helm/mathql/doc/mathql_introduction_basic.tex
ocaml 3.09 transition
[helm.git] / helm / mathql / doc / mathql_introduction_basic.tex
1 \subsection{The basic library} \label{Basic}
2
3 The present paper leaves us too little space to present a complete
4 description of {\MathQL}.4 basic library, so we only give a glance to the
5 features it provides.
6
7 For the user convenience {\MathQL}.4 includes a syntax extension for all the
8 basic library functions, in order to hide the actual function invocation.
9
10 Here are some of the provided constructions:
11
12 \begin{itemize}
13
14 \item 
15 \textbf{Aliases for commonly used constant {\av} sets.}
16 \EM{empty}, \EM{false}, \EM{true}. 
17
18 \item 
19 \textbf{Conditional operator.} 
20 \TT{if} \EM{av-set} \TT{then} \EM{av-set} \TT{else} \EM{av-set}.
21 Tests the first {\av} set for inhabitance and evaluates one of the other {\av}
22 sets accordingly.
23
24 \item 
25 \textbf{Standard \emph{select} clause.} 
26 \TT{select @}\EM{variable} \TT{from} \EM{av-set-1} \TT{where} \EM{av-set-2}.
27 It is:
28 \TT{for @}\EM{variable} \TT{in} \EM{av-set-1} \TT{sup}
29 \TT{if} \EM{av-set-2} \TT{then @}\EM{variable} \TT{else empty}.
30
31 \item
32 \textbf{Set refinement}. The operator
33 \TT{keep} \EM{optional-flag} \EM{name-list} \TT{in} \EM{av-set}
34 removes from its argument every attribute whose name is included (or is not,
35 according to the \EM{flag}) in the given \EM{name-list}.
36 If the \EM{flag} is not present, the \EM{name-list} specifies the attributes
37 to keep, whereas if the \EM{flag} is \TT{allbut}, the \EM{name-list} specifies
38 the attributes to remove.
39 Removing unwanted information from an {\av} set is useful in two cases: it
40 lowers the complexity of intermediate query results increasing the performance
41 of subsequent operations and it cleans the final query results making them
42 easier to manage for the application that submits the query.%
43 \footnote
44 {Interpreting {\av} sets as relational database tables, this functionality
45 allows to select the columns a table is made of, as with the {\SQL} 
46 \emph{select} operator.}
47
48 \item
49 \textbf{projections.} 
50 The operator 
51 \TT{proj} \EM{name} \TT{of} \EM{av-set} makes the set-theoretic union of the
52 contents that the specified attribute has in each group of the given {\av} set.
53 Each element of this union then becomes the head string of an {\av} without
54 attributes and the set of these is returned.%
55 \footnote
56 {This is the content of a labelled column of the given \EM{av-set} viewed as a
57 table.} 
58 See \figref{Proj}.
59
60 \begin{figure}
61 \begin{footnotesize} \begin{verbatim}
62 proj /"name" of ["1" attr {\"name" = {"a", "b"}}, {\"name" = {"b", "c"}} 
63 gives "a"; "b"; "b"
64 \end{verbatim} \end{footnotesize}
65 \vspace{-1pc}
66 \caption{A simple projection} \label{Proj}
67 \end{figure}
68
69 The construction \TT{keep} \EM{av-set} is also provided to remove all the
70 attributes in the given \EM{av-set} ({\ie} the list of the attributes to keep
71 is empty).%
72 \footnote
73 {This is the content of the first column of the \EM{av-set} viewed as a table.}
74
75 \item
76 \textbf{Core operations on {\av} sets.}
77 \EM{av-set} \EM{core-operator} \EM{av-set}
78 returns an {\av} set composing the two operands according to the specified
79 \EM{core-operator} (see \subsecref{AVSets}) which can be \TT{union}
80 (set-theoretic union), \TT{intersect} (set-theoretic intersection) or
81 \TT{diff} (difference). 
82 \TT{union} and \TT{intersect} are also provided in their $n$-ary form
83 ($ n \ge 1 $ for \TT{intersect}) and the $n$-ary union has the syntax
84 extension: 
85 \verb+{+ \EM{av-set} \TT{,} $\cdots$ \TT{,} \EM{av-set} \verb+}+.
86
87 \item 
88 \textbf{Logical operations on {\av} sets.}
89 \EM{and}, \EM{or}, \EM{xor}, \EM{not}.
90 They are inspired by the C-style Boolean operators defined for the
91 integer numbers. In particular:
92
93 \TT{not} \EM{av-set}:
94 returns \emph{false} if the \EM{av-set} is inhabited, or \emph{true} otherwise.
95
96 \EM{av-set-1} \TT{and} \EM{av-set-2}:
97 gives \EM{av-set-2} if \EM{av-set-1} is inhabited, or \emph{false} otherwise.
98
99 \EM{av-set-1} \TT{or} \EM{av-set-2}:
100 returns \EM{av-set-1} if it is inhabited, or \EM{av-set-2} otherwise.
101
102 \EM{av-set-1} \TT{xor} \EM{av-set-2}:
103 gives \emph{false} if both av-sets are inhabited or empty, or the inhabited
104 \EM{av-set} otherwise.
105
106 \TT{and} and \TT{or} are also available in their $n$-ary form.
107
108 \item 
109 \textbf{Comparisons between {\av} sets.}
110 \EM{av-set} \EM{test-operator} \EM{av-set}.
111 Following the repetition rules of {\av} sets presented in \subsecref{AVSets},
112 these operators work just on the head strings of their arguments and
113 discard the attributes. All of them return \emph{false} or \emph{true}
114 according to the outcome of the respective test. 
115 The \emph{test-operator} includes: \TT{sub} (set-theoretic subset relation),
116 \TT{eq} (set-theoretic quality), \TT{meet} (inhabitance of the set-theoretic
117 intersection), \TT{le} (numeric less-or-equal-than), \TT{lt} (numeric
118 less-than).%
119 \footnote{\TT{le} and \TT{lt} return \emph{false} if their operands are invalid
120 numbers.}
121
122 Note that the set-theoretic ``meet'' operator 
123 ({\ie} $ V \meet W \equiv (\lex v \in V)\ v \in W $)
124 is the natural companion of the corresponding ``sub'' operator 
125 ({\ie} $ V \sub W \equiv (\lall v \in V)\ v \in W $) being its logical dual
126 and is already being used successfully in the context of a constructive
127 ({\ie} intuitionistic and predicative) approach to point-free topology
128 (see \cite{Sam00} for details).
129
130 \item 
131 \textbf{Cardinality of an {\av} set.}
132 This information is retrieved by the operator \TT{count} \EM{av-set} that
133 returns an {\av} set representing a natural number.
134
135 \end{itemize}
136