This website houses notes from my studies at the University of Liverpool. If you see any errors or issues, please do open an issue on this site's GitHub.
Recursive Types We have seen types which contain other types. In a recursive custom type, some constructors contain the type itself. data IntList = Empty | Cons Int IntList deriving(Show) Some examples using this type: Empty -- [] Cons 1 (Empty) -- [1] Cons 1 (Cons 2 Empty) -- [1,2]...
All the relations we have been looking at so far have been binary relations however this can be generalised for greater numbered relations. $n$-ary Relations The Cartesian product $A_1\times A_2\times \ldots \times A_n$ of sets $A_1,A_2,\ldots,A_n$ is defined by: \[\begin{aligned} A_1\times A_2\times \ldots \times A_n=&\\ \{(a_1,\ldots,a_n)\ \vert\ a_1\in A_1,\ldots,a_n\in A_n\}&...
Partial Orders A binary relation $R$ on set $A$ which is reflexive, transitive and antisymmetric is called a partial order. Partial orders are important in situations where we wish to characterise precedence. Examples The relation $\leq$ on the set of $\Bbb{R}$ of real numbers. The relation $\subseteq$ on $\text{Pow}(A)$. “Is...
ER by View Integration You should consider each user perspective separately. Requirements are given for many users groups or applications independently. an ER schema is designed for each user group and application (typically by different developers.) Individual views are merged into a global conceptual schema. Individual views can be reconstructed...
Equivalence Relations A binary relation $R$ on a set $A$ is called an equivalence relation if it is reflective, transitive and symmetric. This is the same as $x=y$ in that $x$ has the same property as $y$. Example 1 The relation $R$ on the non-zero integers given by $xRy$ if...
Maybe data Maybe a = Just a | Nothing > :t Just "hello" Maybe [Char] > :t Just False Maybe Bool > :t Nothing Maybe a From here you can see that when you call the Just constructor you force the type variable a to be a particular type and...
Parameterised Custom Types Type Variables in Custom Types We can use type variables in custom types: data Point a = Point a a Here we say we are making a new type where the constructor point is made of type a. > :t Point (1::Int) (2::Int) Point Int We can...
Marginalisation Given an joint distribution $\mathbf{P}(F_1,\ldots,F_k)$, one can compute the marginal probabilities of the random variables $F_i$ by summing out the remaining variables. For example: \[\begin{aligned} P(\text{Cavity}=1)&=0.108+0.012+0.072+0.008\\ &=0.2 \end{aligned}\] is the sum of the entries in the first row of: $\text{Toothache}=1$ $\text{Toothache}=1$ $\text{Toothache}=0$ $\text{Toothache}=0$ $\text{Catch}=1$ $\text{Catch}=0$ $\text{Catch}=1$ $\text{Catch}=0$...
Examples of Probabilistic Models To model a domain using probability theory, one first introduces the relevant random variable. We have seen two basic examples: The weather domain could be modelled using the single random variable $\text{Weather}$ with values: \[(\text{sunny},\text{rain},\text{cloudy},\text{snow})\] The dentist domain could be modelled using the random variables $\text{Toothache,...
Transitive Closure Given a binary relation $R$ on a set $A$ the transitive closure $R^*$ of $R$ is the (uniquely determined) relation on $A$ with the following properties: $R^*$ is transitive. $R\subseteq R^*$. All links you find in $R$ you should also find in $R^*$. If $S$ is a transitive...