% !TeX root = ./forallxyyc.tex
% Chapter on modal logic. Original author: Rob Trueman, York
% University, http://www.rtrueman.com/

\part{Modal logic}
\label{ch.ML}
\addtocontents{toc}{\protect\mbox{}\protect\hrulefill\par}

%\usepackage{gensymb}
%\input{fitch1.sty}

\chapter{Introducing modal logic}
\label{Intro}

Modal logic (ML) is the logic of \emph{modalities}, ways in which a statement can be true. \emph{Necessity} and \emph{possibility} are two such modalities: a statement can be true, but it can also be necessarily true (true no matter how the world might have been). For instance, logical truths are not just true because of some accidental feature of the world, but true come what may. A possible statement may not actually be true, but it might have been true. We use $\ebox$ to express necessity, and $\ediamond$ to express possibility. So you can read $\ebox \metav{A}$ as \emph{It is necessarily the case that} $\metav{A}$, and $\ediamond \metav{A}$ as \emph{It is possibly the case that} $\metav{A}$.

There are lots of different kinds of necessity. It is \emph{humanly impossible} for me to run at 100mph. Given the sorts of creatures that we are, no human can do that. But still, it isn't \emph{physically impossible} for me to run that fast. We haven't got the technology to do it yet, but it is surely physically possible to swap my biological legs for robotic ones which could run at 100mph. By contrast, it is physically impossible for me to run faster than the speed of light. The laws of physics forbid any object from accelerating up to that speed. But even that isn't \emph{logically} impossible. It isn't a contradiction to imagine that the laws of physics might have been different, and that they might have allowed objects to move faster than light.

Which kind of modality does ML deal with? \emph{All of them!} ML is a very flexible tool. We start with a basic set of rules that govern $\ebox$ and $\ediamond$, and then add more rules to fit whatever kind of modality we are interested in. In fact, ML is so flexible that we do not even have to think of $\ebox$ and $\ediamond$ as expressing \emph{necessity} and \emph{possibility}. We might instead read $\ebox$ as expressing \emph{provability}, so that $\ebox\metav{A}$ means \emph{It is provable that} $\metav{A}$, and $\ediamond\metav{A}$ means \emph{It is not refutable that} $\metav{A}$. Similarly, we can interpret $\ebox$ to mean $S$ \emph{knows that $\metav{A}$} or $S$ \emph{believes that $\metav{A}$}. Or we might read $\ebox$ as expressing \emph{moral obligation}, so that $\ebox \metav{A}$ means \emph{It is morally obligatory that} $\metav{A}$, and $\ediamond \metav{A}$ means \emph{It is morally permissible that} $\metav{A}$. All we would need to do is cook up the right rules for these different readings of $\ebox$ and $\ediamond$.

A modal formula is one that includes modal operators such as $\ebox$ and $\ediamond$. Depending on the interpretation we assign to $\ebox$ and $\ediamond$, different modal formulas will be provable or valid. For instance, $\ebox \metav{A} \eif \metav{A}$ might say that ``if $\metav{A}$ is necessary, it is true,'' if $\ebox$ is interpreted as necessity. It might express ``if $\metav{A}$ is known, then it is true,'' if $\ebox$ expresses known truth. Under both these interpretations, $\ebox\metav{A} \eif \metav{A}$ is valid: All necessary propositions are true come what may, so are true in the actual world. And if a proposition is known to be true, it must be true (one can't know something that's false). However, when $\ebox$ is interpreted as ``it is believed that'' or ``it ought to be the case that,'' $\ebox\metav{A} \eif \metav{A}$ is not valid: We can believe false propositions. Not every proposition that ought to be true is in fact true, e.g., ``Every murderer will be brought to justice.'' This \emph{ought} to be true, but it isn't.

We will consider different kinds of systems of ML. They differ in the rules of proof allowed, and in the semantics we use to define our logical notions. The different systems we'll consider are called \mlK, \mlT, \mlSfour, and \mlSfive. \mlK{} is the basic system; everything that is valid or provable in \mlK{} is also provable in the others. But there are some things that \mlK{} does not prove, such as the formula $\ebox A \eif A$ for sentence letter~$A$. So \mlK{} is not an appropriate modal logic for necessity and possibility (where $\ebox\metav{A} \eif \metav{A}$ should be provable). This is provable in the system \mlT, so \mlT{} is more appropriate when dealing with necessity and possibiliity, but less apropriate when dealing with belief or obligation, since then $\ebox\metav{A} \eif \metav{A}$ should \emph{not} (always) be provable. The perhaps best system of ML for necessity and possibility, and in any case the most widely accepted, is the strongest of the systems we consider, \mlSfive.

\section{The Language of ML}
\label{TFLtoML}

In order to do modal logic, we have to do two things. First, we want to learn how to prove things in ML. Second, we want to see how to construct interpretations for ML. But before we can do either of these things, we need to explain how to construct sentences in ML.

The language of ML is an extension of TFL. We could have started with FOL, which would have given us Quantified Modal Logic (QML). QML is much more powerful than ML, but it is also much, much more complicated. So we are going to keep things simple, and start with TFL.

Just like TFL, ML starts with an infinite stock of \emph{atoms}. These are written as capital letters, with or without numerical subscripts: $A$, $B$, \dots  $A_1$, $B_1$, \dots  We then take all of the rules about how to make sentences from TFL, and add two more for $\ebox$ and $\ediamond$:
\begin{itemize}
	\item[(1)]Every atom of ML is a sentence of ML.
	\item[(2)]If $\metav{A}$ is a sentence of ML, then $\enot\metav{A}$ is a sentence of ML.
	\item[(3)]If $\metav{A}$ and $\metav{B}$ are sentences of ML, then $(\metav{A}\eand\metav{B})$ is a sentence of ML.
	\item[(4)]If $\metav{A}$ and $\metav{B}$ are sentences of ML, then $(\metav{A}\eor\metav{B})$ is a sentence of ML.
	\item[(5)]If $\metav{A}$ and $\metav{B}$ are sentences of ML, then $(\metav{A}\eif\metav{B})$ is a sentence of ML.
	\item[(6)]If $\metav{A}$ and $\metav{B}$ are sentences of ML, then $(\metav{A}\eiff\metav{B})$ is a sentence of ML.
	\item[(7)]If $\metav{A}$ is a sentence of ML, then $\ebox\metav{A}$ is a sentence of ML.
	\item[(8)]If $\metav{A}$ is a sentence of ML, then $\ediamond\metav{A}$ is a sentence of ML.
	\item[(9)]Nothing else is a sentence of ML.
\end{itemize}
Here are some examples of ML sentences:
\begin{itemize}
	\item[]$A,\;P\eor Q,\;\ebox A,\;C\eor \ebox D,\;\ebox\ebox (A\eif R),\;\ebox\ediamond (S\eand (Z\eiff (\ebox W \eor \ediamond Q)))$
\end{itemize}

\chapter{Natural deduction for ML}
\label{Proof}

Now that we know how to make sentences in ML, we can look at how to \emph{prove} things in ML. We will use $\proves$ to express provability.  So $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n \proves \metav{C}$ means that $\metav{C}$ can be proven from $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n$. However, we will be looking at a number of different systems of ML, and so it will be useful to add a subscript to indicate which system we are working with. So for example, if we want to say that we can prove $\metav{C}$ from $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n$ \emph{in system}~\mlK, we will write: $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n \proves_\mlK \metav{C}$.

\section{System \mlK}
\label{K}

We start with a particularly simple system called \mlK, in honour of the philosopher and logician Saul Kripke. \mlK{} includes all of the natural deduction rules from TFL, including the derived rules as well as the basic ones. \mlK{} then adds a special kind of subproof, plus two new basic rules for \ebox.

The special kind of subproof looks like an ordinary subproof, except it has a~\ebox in its assumption line instead of a formula. We call them \emph{strict subproofs}---they allow as to reason and prove things about alternate possibilities. What we can prove inside a strict subproof holds in any alternate possibility, in particular, in alternate possibilities where the assumptions in force in our proof may not hold. In a strict subproofs, all assumptions are disregarded, and we are not allowed to appeal to any lines outside the strict subproof (except as allowed by the modal rules given below).

The \ebox I rule allows us to derive a formula $\ebox \metav{A}$ if we can derive $\metav{A}$ inside a strict subproof.  It is our fundamental method of introducing \ebox{} into proofs. The basic idea is simple enough: if $\metav{A}$ is a theorem, then $\ebox \metav{A}$ should be a theorem too. (Remember that to call $\metav{A}$ a theorem is to say that we can prove $\metav{A}$ without relying on any undischarged assumptions.)

Suppose we wanted to prove $\ebox(A\eif A)$. The first thing we need to do is prove that $A\eif A$ is a theorem. You already know how to do that using TFL. You simply present a proof of $A\eif A$ which doesn't start with any premises, like this:
\[
	\begin{nd}
		\open
		\hypo{1}{A}
		\have{2}{A}\by{R}{1}
		\close
		\have{3}{A\eif A}\ci{1-2}
	\end{nd}
\]
But to apply \ebox I, we need to have proven the formula inside a strict subproof.  Since our proof of $A \eif A$ makes use of no assumptions at all, this is possible.
\[\begin{nd}
		\open
		\hypo{1}{\ebox}
		\open
		\hypo{2}{A}
		\have{3}{A}\by{R}{2}
		\close
		\have{4}{A\eif A}\ci{2-3}
		\close
		\have{5}{\ebox(A\eif A)}\boxi{1-4}
	\end{nd}\]

\factoidbox{
	\[\begin{nd}
			\open
			\hypo[m]{m}{\ebox}
			\have[n]{n}{\metav{A}}
			\close
			\have[\,]{o}{\ebox\metav{A}}\boxi{m-n}
		\end{nd}\]
	No line above line $m$ may be cited by any rule within the strict subproof begun at line $m$ unless the rule explicitly allows it.
}
It is essential to emphasise that in strict subproof you cannot use any rule which appeals to anything you proved outside of the strict subproof. There are exceptions, e.g., the \ebox E rule below. These rules will explicitly state that they can be used inside strict subproofs and cite lines outside the strict subproof. This restriction is essential, otherwise we would get terrible results. For example, we could provide the following proof to vindicate $A\therefore \ebox A$:
\[\begin{nd}
		\hypo{1}{A}
		\open
		\hypo{2}{\ebox}
		\have{3}{A}\by{incorrect use of R}{1}
		\close
		\have{4}{\ebox A}\boxi{2-3}
	\end{nd}
\]
This is not a legitimate proof, because at line 3 we appealed to line 1, even though line 1 comes before the beginning of the strict subproof at line 2.

We said above that a strict subproof allows us to reason about arbitrary alternate possible situations. What can be proved in a strict subproof holds in all alternate possible situtations, and so is necessary. This is the idea behind the \ebox I rule. On the other hand, if we've assumed that something is necessary, we have therewith assumed that it is true in all alternate possbile situations.  Hence, we have the rule \ebox E:

\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\ebox\metav{A}}
			\open
			\hypo[\ ]{o}{\ebox}
			\have[n]{n}{\metav{A}}\boxe{m}
			\close
		\end{nd}\]
		\ebox E can only be applied if line $m$ (containing $\ebox A$) lies \emph{outside} of the strict subproof in which line $n$ falls, and this strict subproof is not itself part of a strict subproof not containing~$m$.
		}
\ebox E allows you to assert $\metav{A}$ inside a strict subproof if you have $\ebox \metav{A}$ outside the strict subproof. The restriction means that you can only do this in the first strict subproof, you cannot apply the \ebox E rule inside a nested strict subproof. So the following is not allowed:
\[\begin{nd}
	\have{1}{\ebox\metav{A}}
	\open
	\hypo{2}{\ebox}
	\open
	\hypo{3}{\ebox}
	\have{4}{\metav{A}}\by{incorrect use of \ebox E}{1}
\close\close
\end{nd}\]
The incorrect use of \ebox E on line~$4$ violates the condition, because although line~$1$ lies outside the strict subproof in which line~$4$ falls, the strict subproof containing line~$4$ lies inside the strict subproof beginning on line~$2$ which does not contain line~$1$.

Let's begin with an example.
\[
	\begin{nd}
		\hypo{1}{\ebox A}
		\hypo{2}{\ebox B}
		\open
		\hypo{3}{\ebox}
		\have{4}{A}\boxe{1}
		\have{5}{B}\boxe{2}
		\have{6}{A \eand B}\ai{4,5}
		\close
		\have{6}{\ebox(A \land B)}\boxi{3-6}
	\end{nd}
\]
We can also mix regular subproofs and strict subproofs:
\[\begin{nd}
		\hypo{1}{\ebox (A \eif B)}
		\open
		\hypo{2}{\ebox A}
		\open
		\hypo{3}{\ebox}
		\have{4}{A}\boxe{2}
		\have{5}{A \eif B}\boxe{1}
		\have{6}{B}\ce{4,5}
		\close
		\have{7}{\ebox B}
		\close
		\have{8}{\ebox A \eif \ebox B} \ci{2-7}
	\end{nd}\]
This is called the \emph{Distribution Rule}, because it tells us that $\ebox$ `distributes' over $\eif$.

The rules \ebox I and \ebox E look simple enough, and indeed \mlK{} is a very simple system! But \mlK{} is more powerful than you might have thought. You can prove a fair few things in it.

\section{Possibility}
\label{possibility}

In the last subsection, we looked at all of the basic rules for \mlK. But you might have noticed that all of these rules were about necessity, $\ebox$, and none of them were about possibility, $\ediamond$. That's because we can \emph{define} possibility in terms of necessity:
\factoidbox{
$\ediamond\metav{A}=_{df} \enot \ebox\enot \metav{A}$
}
In other words, to say that $\metav{A}$ is \emph{possibly true}, is to say that $\metav{A}$ is \emph{not necessarily false}. As a result, it isn't really essential to add a $\ediamond$, a special symbol for possibility, into system \mlK. Still, the system will be \emph{much} easier to use if we do, and so we will add the following definitional rules:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\enot\ebox\enot \metav{A}}
			\have[\, ]{n}{\ediamond \metav{A}}\diadf{m}
		\end{nd}
	\]
	\[\begin{nd}
			\have[m]{m}{\ediamond \metav{A}}
			\have[\, ]{n}{\enot\ebox\enot \metav{A}}\diadf{m}
		\end{nd}\]
}
Importantly, you should not think of these rules as any real addition to \mlK: they just record the way that $\ediamond$ is defined in terms of $\ebox$.

If we wanted, we could leave our rules for \mlK{} here. But it will be helpful to add some \emph{Modal Conversion} rules, which give us some more ways of flipping between $\ebox$ and $\ediamond$:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\enot\ebox \metav{A}}
			\have[\, ]{n}{\ediamond \enot\metav{A}}\mc{m}
		\end{nd}
	\]
	\[\begin{nd}
			\have[m]{m}{\ediamond \enot \metav{A}}
			\have[\, ]{n}{\enot\ebox \metav{A}}\mc{m}
		\end{nd}\]
	\[\begin{nd}
			\have[m]{m}{\enot\ediamond \metav{A}}
			\have[\, ]{n}{\ebox \enot\metav{A}}\mc{m}
		\end{nd}\]
	\[\begin{nd}
			\have[m]{m}{\ebox\enot \metav{A}}
			\have[\, ]{n}{\enot\ediamond\metav{A}}\mc{m}
		\end{nd}\]
}
These Modal Conversion Rules are also no addition to the power of \mlK, because they can be derived from the basic rules, along with the definition of $\ediamond$.

In system \mlK, using Def\ediamond{} (or the modal conversion rules), one can prove $\ediamond A \eiff \enot\ebox\enot A$. When laying out system \mlK, we started with $\ebox$ as our primitive modal symbol, and then defined $\ediamond$ in terms of it. But if we had preferred, we could have started with $\ediamond$ as our primitive, and then defined $\ebox$ as follows: $\ebox\metav{A} =_{df} \enot \ediamond \enot \metav{A}$. There is, then, no sense in which necessity is somehow more \emph{fundamental} than possibility. Necessity and possibility are exactly as fundamental as each other.

\section{System \mlT}
\label{T}

So far we have focussed on \mlK, which is a very simple modal system. \mlK{} is so weak that it will not even let you prove $\metav{A}$ from $\ebox\metav{A}$. But if we are thinking of $\ebox$ as expressing \emph{necessity}, then we will want to be able to make this inference: if $\metav{A}$ is \emph{necessarily true}, then it must surely be \emph{true}!

This leads us to a new system,  \mlT, which we get by adding the following rule to \mlK:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\ebox \metav{A}}
			\have[n]{n}{\metav{A}}\rt{m}
		\end{nd}\]
	The line $n$ on which rule R\mlT{} is applied must \emph{not} lie in a strict subproof that begins after line~$m$.
}

The restriction on rule \mlT{} is in a way the opposite of the restriction on \ebox E: you can \emph{only} use \ebox E in a nested strict subproof, but you cannot use \mlT{} in a nested strict subproof.

We can prove things in \mlT{} which we could not prove in \mlK, e.g., $\ebox A \eif A$.

\section{System \mlSfour}
\label{S4}

\mlT{} allows you to strip away the necessity boxes: from $\ebox \metav{A}$, you may infer $\metav{A}$. But what if we wanted to add extra boxes? That is, what if we wanted to go from $\ebox\metav{A}$ to $\ebox\ebox\metav{A}$? Well, that would be no problem, if we had proved $\ebox\metav{A}$ by applying \ebox I to a strict subproof of $\metav{A}$ which itself does not use \ebox E. In that case, $\metav{A}$ is a tautology, and by nesting the strict subproof inside another strict subproof and applying \ebox I again, we can prove $\ebox\ebox \metav{A}$. For example, we could prove $\ebox\ebox (P\eif P)$ like this:
\[
	\begin{nd}
		\open
		\hypo{1}{\ebox}
		\open
		\hypo{2}{\ebox}
		\open
		\hypo{3}{P}
		\have{4}{P}\by{R}{3}
		\close
		\have{5}{P\eif P}\ci{3-4}
		\close
		\have{6}{\ebox(P\eif P)}\boxi{2-5}
		\close
		\have{7}{\ebox\ebox(P\eif P)}\boxi{1-6}
	\end{nd}
\]
But what if we didn't prove $\ebox\metav{A}$ in this restricted way, but used \ebox E inside the strict subproof of $\metav{A}$. If we put that strict subproof inside another strict subproof, the requirement of rule \ebox E to not cite a line containing $\ebox\metav{A}$ which lies in another strict subproof that has not yet concluded, is violated.  Or what if $\ebox\metav{A}$ were just an assumption we started our proof with? Could we infer $\ebox\ebox\metav{A}$ then? Not in  \mlT, we couldn't. And this might well strike you as a limitation of  \mlT, at least if we are reading $\ebox$ as expressing \emph{necessity}. It seems intuitive that if $\metav{A}$ is necessarily true, then it couldn't have \emph{failed} to be necessarily true.

This leads us to another new system, \mlSfour, which we get by adding the following rule to~\mlT:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\ebox\metav{A}}
			\open
			\hypo[\ ]{k}{\ebox}
			\have[n]{n}{\ebox\metav{A}}\rfour{m}
			\close
		\end{nd}
	\]
	Note that R$\mathbf{4}$ can only be applied if line $m$ (containing $\ebox A$) lies outside of the strict subproof in which line $n$ falls, and this strict subproof is not itself part of a strict subproof not containing $n$.
}

Rule R$\mathbf{4}$ looks just like {\ebox}E, except that instead of yielding $\metav{A}$ from $\ebox\metav{A}$ it yields $\ebox\metav{A}$ inside a strict subproof. The restriction is the same, however: R$\mathbf{4}$ allows us to ``import'' $\ebox \metav{A}$ into a strict subproof, but not into a strict subproof itself nested inside a strict subproof. However, if that is necessary, an additional application of R$\mathbf{4}$ would have the same result.

Now we can prove even more results. For instance:
\[\begin{nd}
	\open
	\hypo{1}{\ebox A}
	\open
	\hypo{2}{\ebox}
	\have{3}{\ebox A}\rfour{1}
	\close
	\have{4}{\ebox\ebox A}\boxi{2-3}
	\close
	\have{5}{\ebox A \eif \ebox\ebox A}\ci{1-6}
\end{nd}\]
Similarly, we can prove $\ediamond\ediamond A \eif \ediamond A$. This shows us that as well as letting us \emph{add} extra \emph{boxes}, \mlSfour{} lets us \emph{delete} extra \emph{diamonds}: from $\ediamond\ediamond \metav{A}$, you can always infer $\ediamond\metav{A}$.

\section{System \mlSfive}
\label{S5}

In \mlSfour, we can always add a box in front of another box. But \mlSfour{} does not automatically let us add a box in front of a \emph{diamond}. That is, \mlSfour{} does not generally permit the inference from $\ediamond\metav{A}$ to $\ebox\ediamond\metav{A}$. But again, that might strike you as a shortcoming, at least if you are reading $\ebox$ and $\ediamond$ as expressing \emph{necessity} and \emph{possibility}. It seems intuitive that if $\metav{A}$ is possibly true, then it couldn't have \emph{failed} to be possibly true.

This leads us to our final modal system, \mlSfive, which we get by adding the following rule to \mlSfour:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\enot \ebox\metav{A}}
			\open
			\hypo[\ ]{k}{\ebox}
			\have[n]{n}{\enot\ebox\metav{A}}\rfive{m}
			\close
	\end{nd}\]
	Rule R$\mathbf{5}$ can only be applied if line $m$ (containing $\enot \ebox\metav{A}$) lies outside of the strict subproof in which line $n$ falls, and this strict subproof is not itself part of a strict subproof not containing line~$m$.
}

This rule allows us to show, for instance, that $\ediamond\ebox A\proves_\mlSfive  \ebox A$:
\[\begin{nd}
	\hypo{1}{\ediamond\ebox A}
	\have{2}{\enot\ebox\enot\ebox A}\by{Def\ediamond}{1}
	\open
	\hypo{3}{\enot \ebox A}
	\open
	\hypo{4}{\ebox}
	\have{5}{\enot\ebox A}\rfive{3}
	\close
	\have{6}{\ebox\enot\ebox A}\boxi{4-5}
	\have{7}{\ered}\ne{2,6}
	\close
	\have{8}{\ebox A}\by{IP}{3-7}
\end{nd}\]

So, as well as adding boxes in front of diamonds, we can also delete diamonds in front of boxes.

We got \mlSfive{} just by adding the rule R$\mathbf{5}$ rule to \mlSfour. In fact, we could have added rule R$\mathbf{5}$ to \mlT{} alone, and leave out rule R$\mathbf{4}$). Everything we can prove by rule R$\mathbf{4}$ can also be proved using R\mlT{} together with R$\mathbf{5}$. For instance, here is a proof that shows $\ebox A \proves_\mlSfive  \ebox\ebox A$ without using R$\mathbf{4}$:
\[\begin{nd}
	\hypo{1}{\ebox A}
	\open
	\hypo{2}{\ebox\enot\ebox A}
	\have{3}{\enot\ebox A}\rt{2}
	\have{4}{\ered}\ne{1,3}
	\close
	\have{5}{\enot\ebox\enot\ebox A}\ni{2-4}
	\open
	\hypo{6}{\ebox}
	\open
	\hypo{7}{\enot\ebox A}
	\open
	\hypo{8}{\ebox}
	\have{9}{\enot\ebox A}\rfive{7}
	\close
	\have{10}{\ebox \enot\ebox A}\boxi{8-9}
	\have{11}{\enot\ebox\enot\ebox A}\rfive{5}
	\have{12}{\ered}\ne{10,11}
	\close
	\have{13}{\ebox A}\ip{7-12}
	\close
	\have{14}{\ebox\ebox A}\boxi{6-13}
\end{nd}\]
\mlSfive{} is \emph{strictly stronger} than \mlSfour: there are things which can be proved in \mlSfive, but not in \mlSfour{} (e.g., $\ediamond\ebox A \eif \ebox A$).

The important point about \mlSfive{} can be put like this: if you have a long string of boxes and diamonds, in any combination whatsoever, you can delete all but the last of them. So for example, $\ediamond\ebox\ediamond\ediamond\ebox\ebox\ediamond\ebox A$ can be simplified down to just $\ebox A$.

\practiceproblems

\problempart
Provide proofs for the following:
\begin{earg}
	\item $\ebox (A\eand B)\proves_\mlK\ebox A \eand \ebox B$
	\item $\ebox A\eand\ebox B\proves_\mlK\ebox( A \eand  B)$
	\item $\ebox A\eor\ebox B\proves_\mlK\ebox( A \eor  B)$
	\item $\ebox (A \eiff B)\proves_\mlK \ebox A \eiff \ebox B$
\end{earg}

\problempart
Provide proofs for the following (without using Modal Conversion!):
\begin{earg}
	\item $\enot\ebox A\proves_\mlK \ediamond \enot A$
	\item $\ediamond\enot A\proves_\mlK\enot \ebox A$
	\item $\enot\ediamond A\proves_\mlK\ebox\enot A$
	\item $\ebox\enot A\proves_\mlK\enot\ediamond A$
\end{earg}

\problempart
Provide proofs of the following (and now feel free to use Modal Conversion!):
\begin{earg}
	\item $\ebox(A\eif B), \ediamond A \proves_\mlK \ediamond B$
	\item $\ebox A \proves_\mlK \enot\ediamond\enot A$
	\item $\enot\ediamond\enot A \proves_\mlK \ebox A$
\end{earg}

\problempart
Provide proofs for the following:
\begin{earg}
	\item $P\proves_\mlT\ediamond P$
	\item $\proves_\mlT (A\eand B)\eor(\enot \ebox A\eor\enot\ebox B)$
\end{earg}

\problempart
Provide proofs for the following:
\begin{earg}
	\item $\ebox(\ebox A\eif B), \ebox (\ebox B\eif C), \ebox A \proves_\mlSfour \ebox\ebox C$
	\item $\ebox A \proves_\mlSfour \ebox(\ebox A \eor B)$
	\item $\ediamond \ediamond A \proves_\mlSfour \ediamond A$
\end{earg}

\problempart
Provide proofs in \mlSfive{} for the following:
\begin{earg}
	\item $\enot\ebox\enot A, \ediamond B\proves_\mlSfive \ebox(\ediamond A \eand \ediamond B)$
	\item $A \proves_\mlSfive  \ebox\ediamond A$
	\item $\ediamond\ediamond A\proves_\mlSfive  \ediamond A$
\end{earg}

\chapter{Semantics for ML}
\label{Semantics}

So far, we have focussed on laying out various systems of Natural Deduction for ML. Now we will look at the \emph{semantics} for ML. A semantics for a language is a method for assigning truth-values to the sentences in that language. So a semantics for ML is a method for assigning truth-values to the sentences of ML.

\section{Interpretations of ML}

The big idea behind the semantics for ML is this. In ML, sentences are not just true or false, full stop. A sentence is true or false \emph{at a given possible world}, and a single sentence may well be true at some worlds and false at others. We then say that $\ebox \metav{A}$ is true iff $\metav{A}$ is true at \emph{every} world, and $\ediamond\metav{A}$ is true iff $\metav{A}$ is true at \emph{some} world.

That's the big idea, but we need to refine it and make it more precise. To do this, we need to introduce the idea of an \emph{interpretation} of ML. The first thing you need to include in an interpretation is a collection of \emph{possible worlds}. Now, at this point you might well want to ask: What exactly is a possible world? The intuitive idea is that a possible world is another way that this world could have been. But what exactly does that mean? This is an excellent philosophical question, and we will look at it in a lot of detail later. But we do not need to worry too much about it right now. As far as the formal logic goes, possible worlds can be anything you like. All that matters is that you supply each interpretation with a non-empty collection of things labelled \define{possible worlds}.

Once you have chosen your collection of possible worlds, you need to find some way of determining which sentences of ML are true at which possible worlds. To do that, we need to introduce the notion of a \emph{valuation function}. Those of you who have studied some maths will already be familiar with the general idea of a function. But for those of you who haven't, a function is a mathematical entity which maps arguments to values. That might sound a little bit abstract, but some familiar examples will help. Take the function $x+1$. This is a function which takes in a number as argument, and then spits out the next number as value. So if you feed in the number $1$ as an argument, the function $x+1$ will spit out the number $2$ as a value; if you feed in $2$, it will spit out $3$; if you feed in $3$, it will spit out $4$ \dots  Or here is another example: the function $x+y$. This time, you have to feed two arguments into this function if you want it to return a value: if you feed in $2$ and $3$ as your arguments, it spits out $5$; if you feed in $1003$ and $2005$, it spits out $3008$; and so on.

A valuation function for ML takes in a sentence and a world as its arguments, and then returns a truth-value as its value. So if $\nu$ is a valuation function and $w$ is a possible world, $\nu_w(\metav{A})$ is whatever truth-value $\nu$ maps $\metav{A}$ and $w$ to: if $\nu_w(\metav{A})=F$, then $\metav{A}$ is false at world $w$ on valuation $\nu$; if $\nu_w(\metav{A})=T$, then $\metav{A}$ is true at world $w$ on valuation $\nu$.

These valuation functions are allowed to map any \emph{atomic} sentence to any truth-value at any world. But there are rules about which truth-values more complex sentences get assigned at a world. Here are the rules for the connectives from TFL:
\begin{itemize}
	\item[(1)]$\nu_w(\enot\metav{A})=T$ iff: $\nu_w(\metav{A})=F$
	\item[(2)]$\nu_w(\metav{A}\eand\metav{B})=T$ iff: $\nu_w(\metav{A})=T$ and $\nu_w(\metav{B})=T$
	\item[(3)]$\nu_w(\metav{A}\eor\metav{B})=T$ iff: $\nu_w(\metav{A})=T$ or $\nu_w(\metav{B})=T$, or both
	\item[(4)]$\nu_w(\metav{A}\eif\metav{B})=T$ iff: $\nu_w(\metav{A})=F$ or $\nu_w(\metav{B})=T$, or both
	\item[(5)]$\nu_w(\metav{A}\eiff\metav{B})=T$ iff: $\nu_w(\metav{A})=T$ and $\nu_w(\metav{B})=T$, or $\nu_w(\metav{A})=F$ and $\nu_w(\metav{B})=F$
\end{itemize}
So far, these rules should all look very familiar. Essentially, they all work exactly like the truth-tables for TFL. The only difference is that these truth-table rules have to be applied over and over again, to one world at a time.

But what are the rules for the new modal operators, $\ebox$ and $\ediamond$? The most obvious idea would be to give rules like these:
\begin{itemize}
	\item[]$\nu_w(\ebox \metav{A})=T$ iff $\forall w' (\nu_{w'}(\metav{A})=T)$
	\item[]$\nu_w(\ediamond \metav{A})=T$ iff $\exists w' (\nu_{w'}(\metav{A})=T)$
\end{itemize}
This is just the fancy formal way of writing out the idea that $\ebox\metav{A}$ is true at $w$ just in case $\metav{A}$ is true at \emph{every} world, and $\ediamond\metav{A}$ is true at $w$ just in case $\metav{A}$ is true at \emph{some} world.

However, while these rules are nice and simple, they turn out not to be quite as useful as we would like. As we mentioned, ML is meant to be a very flexible tool. It is meant to be a general framework for dealing with lots of different kinds of necessity. As a result, we want our semantic rules for $\ebox$ and $\ediamond$ to be a bit less rigid. We can do this by introducing another new idea: \emph{accessibility relations}.

An accessibility relation, $R$, is a relation between possible worlds. Roughly, to say that $Rw_1w_2$ (in English: world $w_1$ \emph{accesses} world $w_2$) is to say that $w_2$ is possible \emph{relative to} $w_1$. In other words, by introducing accessibility relations, we open up the idea that a given world might be possible relative to some worlds but not others. This turns out to be a \emph{very} fruitful idea when studying modal systems. We can now give the following semantic rules for $\ebox$ and $\ediamond$:
\begin{itemize}
	\item[(6)]$\nu_{w_1}(\ebox \metav{A})=T$ iff $\forall w_2 (Rw_1w_2\eif \nu_{w_2}(\metav{A})=T)$
	\item[(7)]$\nu_{w_1}(\ediamond \metav{A})=T$ iff $\exists w_2 (Rw_1w_2\eand \nu_{w_2}(\metav{A})=T)$
\end{itemize}
Or in plain English: $\ebox\metav{A}$ is true in world $w_1$ iff $\metav{A}$ is true in every world that is possible relative to $w_1$; and $\ediamond\metav{A}$ is true in world $w_1$ iff $\metav{A}$ is true in some world that is possible relative to $w_1$.

So, there we have it. An interpretation for ML consists of three things: a collection of possible worlds, $W$; an accessibility relation, $R$; and a valuation function, $\nu$. The collection of `possible worlds' can really be a collection of anything you like. It really doesn't matter, so long as $W$ isn't empty. (For many purposes, it is helpful just to take a collection of numbers to be your collection of worlds.) And for now, at least, $R$ can be any relation between the worlds in $W$ that you like. It could be a relation which every world in $W$ bears to every world in $W$, or one which no world bears to any world, or anything in between. And lastly, $\nu$ can map any atomic sentence of ML to any truth-value at any world. All that matters is that it follows the rules (1)--(7) when it comes to the more complex sentences.

Let's look at an example. It is often helpful to present interpretations of ML as diagrams, like this:
\begin{center}
	\begin{tikzpicture}
		\node (atom1) at (0,1) {1};
		\node (atom2) at (3,1) {2};
		\node (atom3) at (-0.25,0) {$A$};
		\node (atom4) at (3,0) {$\enot A$};
		\node (atom5) at (-0.25,-0.7) {$\enot B$};
		\node (atom6) at (3,-0.7) {$B$};
		\draw[->, thick] (atom1)+(-0.15,0.15) arc (-330:-30:.3);
		%\draw[->, thick] (atom2)+(0.15,-0.15) arc (-150:150:.3);
		\draw[<-, thick] (atom1) -- (atom2);
		\draw (-0.8,-1.2) rectangle (0.4,0.5);
		\draw (2.4,-1.2) rectangle (3.6,0.5);
	\end{tikzpicture}
\end{center}
Here is how to read the interpretation off from this diagram. It contains just two worlds, 1 and 2. The arrows between the worlds indicate the accessibility relation. So 1 and 2 both access 1, but neither 1 nor 2 accesses 2. The boxes at each world let us know which atomic sentences are true at each world: $A$ is true at 1 but false at 2; $B$ is false at 1 but true at 2. You may only write an atomic sentence or the negation of an atomic sentence into one of these boxes. We can figure out what truth-values the more complex sentences get at each world from that. For example, on this interpretation all of the following sentences are true at $w_1$:
\begin{itemize}
	\item[]$A\eand\enot B$, $B\eif A$, $\ediamond A$, $\ebox\enot B$
\end{itemize}
If you don't like thinking diagrammatically, then you can also present an interpretation like this:
\begin{itemize}
	\item[$W$:]$1,2$
	\item[$R$:]$\langle 1,1\rangle, \langle 2,1\rangle$
	\item[]$\nu_{1}(A)=T, \nu_{2}(B)=F, \nu_{2}(A)=F, \nu_{2}(B)=T$
\end{itemize}
You will get the chance to cook up some interpretations of your own shortly, when we start looking at \emph{counter-interpretations}.

\section{A Semantics for System \mlK}
\label{SemanticsK}

We can now extend all of the semantic concepts of TFL to cover ML:
\factoidbox{
	\begin{itemize}
		\item  $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\therefore\metav{C}$ is \define{modally valid} iff there is no world in any interpretation at which $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n$ are all true and $\metav{C}$ is false.

		\item $\metav{A}$ is a \define{modal truth} iff $\metav{A}$ is true at every world in every interpretation.

		\item $\metav{A}$ is a \define{modal contradiction} iff $\metav{A}$ is false at every world in every interpretation.

		\item $\metav{A}$ is \define{modally satisfiable} iff $\metav{A}$ is true at some world in some interpretation.
	\end{itemize}
}
(From now on we will drop the explicit `modal' qualifications, since they can be taken as read.)

We can also extend our use of $\entails$. However, we need to add subscripts again, just as we did with $\proves$. So, when we want to say that $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\therefore\metav{C}$ is valid, we will write: $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlK\metav{C}$.

Let's get more of a feel for this semantics by presenting some counter-interpretations. Consider the following (false) claim:
\begin{itemize}
	\item[]
	      \begin{itemize}
		      \item[]$\enot A\entails_\mlK \enot \ediamond A$
	      \end{itemize}
\end{itemize}
In order to present a counter-interpretation to this claim, we need to cook up an interpretation which makes $\enot A$ true at some world $w$, and $\enot\ediamond A$ false at $w$. Here is one such interpretation, presented diagrammatically:
\begin{center}
	\begin{tikzpicture}
		\node (atom1) at (0,1) {1};
		\node (atom2) at (3,1) {2};
		\node (atom3) at (-0.25,0) {$\enot A$};
		\node (atom4) at (3,0) {$A$};
		\draw[->, thick] (atom1) -- (atom2);
		\draw (-0.8,-0.6) rectangle (0.4,0.5);
		\draw (2.4,-0.6) rectangle (3.6,0.5);
	\end{tikzpicture}
\end{center}
It is easy to see that this will work as a counter-interpretation for our claim. First, $\enot A$ is true at world $1$. And second, $\enot\ediamond A$ is false at $1$: $A$ is true at $2$, and $2$ is accessible from $1$. So there is some world in this interpretation where $\enot A$ is true and $\enot\ediamond A$ is false, so it is not the case that $\enot A\entails_\mlK\enot\ediamond A$.

Why did we choose the subscript \mlK? Well, it turns out that there is an important relationship between system \mlK{} and the definition of validity we have just given. In particular, we have the following two results:
\begin{itemize}
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlK\metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlK\metav{C}$
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlK\metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlK\metav{C}$
\end{itemize}
The first result is known as a \emph{soundness} result, since it tells us that the rules of \mlK{} are good, sound rules: if you can vindicate an argument by giving a proof for it using system \mlK, then that argument really is valid. The second result is known as a \emph{completeness} result, since it tells us that the rules of \mlK{} are broad enough to capture all of the valid arguments: if an argument is valid, then it will be possible to offer a proof in \mlK{} which vindicates it.

Now, it is one thing to state these results, quite another to prove them. However, we will not try to prove them here. But the idea behind the proof of soundness will perhaps make clearer how strict subproofs work.

In a strict subproof, we are not allowed to make use of any information from outside the strict subproof, except what we import into the strict subproof using \ebox E. If we've assumed or proved $\ebox \metav{A}$, by \ebox E, we can used $\metav{A}$ inside a strict subproof. And in \mlK, that is the only way to import a formula into a strict subproof. So everything that can be proved inside a strict subproof must follow from formulas $\metav{A}$ where outside the strict subproof we have $\ebox \metav{A}$. Let's imagine that we are reasoning about what's true in a possible world in some interpretation. If we know that $\ebox\metav{A}$ is true in that possible world, we know that $\metav{A}$ is true in all accessible worlds. So, everything proved inside a strict subproof is true in all accessible possible worlds. That is why \ebox I is a sound rule.

\section{A Semantics for System \mlT}
\label{SemanticsT}

A few moments ago, we said that system \mlK{} is sound and complete. Where does that leave the other modal systems we looked at, namely  \mlT, \mlSfour{} and \mlSfive? Well, they are all \emph{unsound}, relative to the definition of validity we gave above. For example, all of these systems allow us to infer $A$ from $\ebox A$, even though $\ebox A\nentails_\mlK A$.

Does that mean that these systems are a waste of time? Not at all! These systems are only unsound \emph{relative to the definition of validity we gave above}. (Or to use symbols, they are unsound relative to $\entails_\mlK$.) So when we are dealing with these stronger modal systems, we just need to modify our definition of validity to fit. This is where accessibility relations come in really handy.

When we introduced the idea of an accessibility relation, we said that it could be any relation between worlds that you like: you could have it relating every world to every world, no world to any world, or anything in between. That is how we were thinking of accessibility relations in our definition of $\entails_\mlK$. But if we wanted, we could start putting some restrictions on the accessibility relation. In particular, we might insist that it has to be \emph{reflexive}:
\begin{itemize}
	\item $\forall wRww$
\end{itemize}
In English: every world accesses itself. Or in terms of relative possibility: every world is possible relative to itself. If we imposed this restriction, we could introduce a new consequence relation, $\entails_\mlT$, as follows:
\factoidbox{
	$\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlT \metav{C}$ iff there is no world in any interpretation \emph{which has a reflexive accessibility relation}, at which $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n$ are all true and $\metav{C}$ is false
}
We have attached the \mlT{} subscript to $\entails$ because it turns out that system \mlT{} is sound and complete relative to this new definition of validity:
\begin{itemize}
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlT\metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlT\metav{C}$
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlT\metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlT\metav{C}$
\end{itemize}
As before, we will not try to prove these soundness and completeness results. However, it is relatively easy to see how insisting that the accessibility relation must be reflexive will vindicate the R\mlT{} rule:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\ebox \metav{A}}
			\have[\, ]{n}{\metav{A}}\rt{m}
		\end{nd}\]
}
To see this, just imagine trying to cook up a counter-interpretation to this claim:
\[
	\ebox \metav{A}\entails_\mlT \metav{A}
\]
We would need to construct a world, $w$, at which $\ebox \metav{A}$ was true, but $\metav{A}$ was false. Now, if $\ebox \metav{A}$ is true at $w$, then $\metav{A}$ must be true at every world $w$ accesses. But since the accessibility relation is reflexive, $w$ accesses $w$. So $\metav{A}$ must be true at $w$. But now $\metav{A}$ must be true \emph{and} false at $w$. Contradiction!

\section{A Semantics for \mlSfour}
\label{SemanticsS4}

How else might we tweak our definition of validity? Well, we might also stipulate that the accessibility relation has to be \emph{transitive}:
\begin{itemize}
	\item $\forall w_1\forall w_2\forall w_3 ((Rw_1w_2 \eand Rw_2w_3)\eif Rw_1w_3)$
\end{itemize}
In English: if $w_1$ accesses $w_2$, and $w_2$ accesses $w_3$, then $w_1$ accesses $w_3$. Or in terms of relative possibility: if $w_3$ is possible relative to $w_2$, and $w_2$ is possible relative to $w_1$, then $w_3$ is possible relative to $w_1$. If we added this restriction on our accessibility relation, we could introduce a new consequence relation, $\entails_\mlSfour$, as follows:
\factoidbox{
	$\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlSfour \metav{C}$ iff there is no world in any interpretation \emph{which has a reflexive and transitive accessibility relation}, at which $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n$ are all true and $\metav{C}$ is false
}
We have attached the \mlSfour{} subscript to $\entails$ because it turns out that system \mlSfour{} is sound and complete relative to this new definition of validity:
\begin{itemize}
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlSfour\metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlSfour\metav{C}$
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlSfour\metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlSfour\metav{C}$
\end{itemize}
As before, we will not try to prove these soundness and completeness results. However, it is relatively easy to see how insisting that the accessibility relation must be transitive will vindicate the \mlSfour{} rule:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\ebox\metav{A}}
			\open
			\hypo[\ ]{k}{\ebox}
			\have[\ ]{n}{\ebox\metav{A}}\rfour{m}
		\end{nd}\]
}
The idea behind strict subproofs, remember, is that they are ways to prove things that must be true in all accessible worlds. So the R$\mathbf{4}$ rule means that whenever $\ebox \metav{A}$ is true, $\ebox \metav{A}$ must also be true in every accessible world. In other words, we must have $\ebox\metav{A} \entails_\mlSfour \ebox\ebox\metav{A}$.

To see this, just imagine trying to cook up a counter-interpretation to this claim:
\begin{itemize}
	\item[]$\ebox\metav{A} \entails_\mlSfour \ebox \ebox \metav{A}$
\end{itemize}
We would need to construct a world, $w_1$, at which $\ebox\metav{A}$ was true, but $\ebox \ebox \metav{A}$ was false. Now, if $\ebox \ebox \metav{A}$ is false at $w_1$, then $w_1$ must access some world, $w_2$, at which $\ebox\metav{A}$ is false. Equally, if $\ebox \metav{A}$ is false at $w_2$, then $w_2$ must access some world, $w_3$, at which $\metav{A}$ is false. We just said that $w_1$ accesses $w_2$, and $w_2$ accesses $w_3$. So since we are now insisting that the accessibility relation be transitive, $w_1$ must access $w_3$. And as $\ebox\metav{A}$ is true at $w_1$, and $w_3$ is accessible from $w_1$, it follows that $\metav{A}$ must be true at $w_3$. So $\metav{A}$ is true \emph{and} false at $w_3$. Contradiction!

\section{A Semantics for \mlSfive}
\label{SemanticsS5}

Let's put one more restriction on the accessibility relation. This time, let's insist that it must also be \emph{symmetric}:
\begin{itemize}
	\item $\forall w_1\forall w_2(Rw_1w_2 \eif Rw_2w_1)$
\end{itemize}
In English: if $w_1$ accesses $w_2$, then $w_2$ accesses $w_1$. Or in terms of relative possibility: if $w_2$ is possible relative to $w_1$, then $w_1$ is possible relative to $w_2$. Logicians call a relation that is reflexive, symmetric, and transitive an \emph{equivalence} relation. We can now define a new consequence relation, $\entails_\mlSfive $, as follows:
\factoidbox{
	$\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlSfive  \metav{C}$ iff there is no world in any interpretation \emph{whose accessibility relation is an equivalence relation}, at which $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n$ are all true and $\metav{C}$ is false
}
We have attached the \mlSfive{} subscript to $\entails$ because it turns out that system \mlSfive{} is sound and complete relative to this new definition of validity:
\begin{itemize}
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlSfive \metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlSfive \metav{C}$
	\item If $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlSfive \metav{C}$, then $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\proves_\mlSfive \metav{C}$
\end{itemize}
As before, we will not try to prove these soundness and completeness results here. However, it is relatively easy to see how insisting that the accessibility relation must be an equivalence relation will vindicate the R$\mathbf{5}$ rule:
\factoidbox{
	\[\begin{nd}
			\have[m]{m}{\enot\ebox \metav{A}}
			\open
			\hypo[\ ]{k}{\ebox}
			\have[\, ]{n}{\enot\ebox\metav{A}}\rfive{m}
		\end{nd}\]
}
The rule says that if $\metav{A}$ is not necessary, i.e., false in some accessible world, it is also not necessary in any accessible prossible world, i.e., we have $\enot\ebox \metav{A} \proves_\mlSfive  \ebox\enot\ebox \metav{A}$.

To see this, just imagine trying to cook up a counter-interpretation to this claim:
\[
	\enot\ebox\metav{A} \entails_\mlSfive  \ebox \enot\ebox \metav{A}
\]
We would need to construct a world, $w_1$, at which $\enot\ebox\metav{A}$ was true, but $\ebox \enot\ebox \metav{A}$ was false.
Now, if $\enot\ebox\metav{A}$ is true at $w_1$, then $w_1$ must access some world, $w_2$, at which $\metav{A}$ is false. Equally, if $\ebox \enot\ebox \metav{A}$ is false at $w_1$, then $w_1$ must access some world, $w_3$, at which $\enot\ebox \metav{A}$ is false. Since we are now insisting that the accessibility relation is an equivalence relation, and hence symmetric, we can infer that $w_3$ accesses $w_1$. Thus, $w_3$ accesses $w_1$, and $w_1$ accesses $w_2$. Again, since we are now insisting that the accessibility relation is an equivalence relation, and hence transitive, we can infer that $w_3$ accesses $w_2$. But earlier we said that $\enot\ebox \metav{A}$ is false at $w_3$, which implies that $\metav{A}$ is true at every world which $w_3$ accesses. So $\metav{A}$ is true \emph{and} false at $w_2$. Contradiction!

In the definition of $\entails_\mlSfive $, we stipulated that the accessibility relation must be an equivalence relation. But it turns out that there is another way of getting a notion of validity fit for \mlSfive. Rather than stipulating that the accessibility relation be an equivalence relation, we can instead stipulate that it be a \emph{universal} relation:
\begin{itemize}
	\item $\forall w_1\forall w_2Rw_1w_2$
\end{itemize}
In English: every world accesses every world. Or in terms of relative possibility: every world is possible relative to every world. Using this restriction on the accessibility relation, we could have defined $\entails_\mlSfive $ like this:
\factoidbox{
	$\metav{A}_1,\metav{A}_2, \dots \metav{A}_n\entails_\mlSfive  \metav{C}$ iff there is no world in any interpretation \emph{which has a universal accessibility relation}, at which $\metav{A}_1,\metav{A}_2, \dots \metav{A}_n$ are all true and $\metav{C}$ is false.
}
If we defined $\entails_\mlSfive $ like this, we would still get the same soundness and completeness results for \mlSfive. What does this tell us? Well, it means that if we are dealing with a notion of necessity according to which \emph{every} world is possible relative to \emph{every} world, then we should use \mlSfive. What is more, most philosophers assume that the notions of necessity that they are most concerned with, like \emph{logical necessity} and \emph{metaphysical necessity}, are of exactly this kind. So \mlSfive{} is the modal system that most philosophers use most of the time.

\practiceproblems

\problempart
Present counter-interpretations to the following false claims:
\begin{earg}
	\item $\enot P \entails_\mlK \enot\ediamond P$
	\item $\ebox(P \eor Q)\entails_\mlK \ebox P \eor \ebox Q$
	\item $\entails_\mlK \enot \ebox (A\eand \enot A)$
	\item $\ebox A\entails_\mlK A$
\end{earg}

\problempart
Present counter-interpretations to the following false claims:
\begin{earg}
	\item $\ediamond A\entails_\mlSfour \ebox\ediamond A$
	\item $\ediamond A, \ebox (\ediamond A \eif B)\entails_\mlSfour\ebox B$
\end{earg}

\problempart
Present counter-interpretations to the following false claims:
\begin{earg}
	\item $\ebox (M\eif O),\ediamond M\entails_\mlT O$
	\item $\ebox A\entails_\mlT \ebox \ebox A$
\end{earg}

\section*{Further reading}

Modal logic is a large subfield of logic. We have only scratched the surface. If you want to learn more about modal logic, here are some textbooks you might consult.

\begin{itemize}
	\item Hughes, G. E., \& Cresswell, M. J. (1996). \emph{A New Introduction to Modal Logic}, Oxford: Routledge.
	\item Priest, G. (2008). \emph{An Introduction to Non-Classical Logic}, 2nd ed., Cambridge: Cambridge University Press.
	\item Garson, J. W. (2013). \emph{Modal Logic for Philosophers}, 2nd ed., Cambridge: Cambridge University Press.
\end{itemize}

None of these authors formulate their modal proof systems in quite the way we did, but the closest formulation is given by Garson.


\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{dirtree}
\usepackage[margin=1in]{geometry}
\usepackage[UKenglish]{babel}
\usepackage[fixlanguage]{babelbib}
\usepackage[square,sort,nonamebreak,comma]{natbib}  % citação bibliográfica alpha (alpha-ime.bst)
\usepackage{listings}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{hyperref}

\title{iModel: Icosahedral grid tools for geosphysical fluid dynamics modelling}
\author{Pedro S. Peixoto (pedrosp@ime.usp.br)}

\begin{document}
\maketitle

The software is a pack of tools to work with icosahedral and Voronoi geodesic grid based geophysical fluid models. It contains
\begin{itemize}
 \item Grid generator and grid tools, including grid optimization
 \item Interpolation and vector reconstruction pack
  \item A Multigrid solver
 \item A transport model
 \item A shallow water model
\end{itemize}

This code is mainly for research and educational purposes. It is in constant change and has not been tested for all its configurations possibilities.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY. See the GNU General Public License for more details.

For references check my website: \url{www.ime.usp.br/~pedrosp}. Do not hesitate to contact me in case of problems or doubts. Please contact me if you wish to have pre-calculated optimized grids, since they are very large, they are not shipped with the code.

\section{Requirements}

The software is very much self contained and does not rely on extra third party software other than the compiler. It is built for \textbf{linux platforms}, but may be run on Windows via Cygwin.

It was designed to run with very basic Fortran 90 coding, therefore tends to runs on any version of \textbf{GNU gfortran} compilers or \textbf{Intel ifort} compilers. Intel compiler will chosen as default if installed.

The outputs of the program are either text files or maps with binary data files. The maps are outputted to be read and graphed using \textbf{Generic Mapping Tool} Version 4.x.x, and several scripts for this purpose are provided. It is also possible to use \textbf{Generic Mapping Tool} Version 5.x.x, with the scripts with *gmt5.sh in gmt/ folder. GMT 5.x.x can be installed by ``apt-get'' in Ubuntu and Debian systems very easily.

Some output data can be easily analysed in Matlab, but since they are outputted as text files, any other software may be used.

The code is not very optimized, but uses openmp shared memory parallelism in many places.

\section{Code structure}

Main files of program

\dirtree{%
.1 imodel/ \hspace{1cm}  \begin{minipage}[t]{10cm}
                  Makefile \\
		  readme{.}txt\\
                \end{minipage}.
.2 bin/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          This directory holds executable files (binary files)\\
          \end{minipage}.
.2 data/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Directory where output from imodel is written\\
          \end{minipage}.
.2 doc/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Directory for documentation\\
          \end{minipage}.
.2 gmt/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Generic Mapping Tool (GMT) scripts\\
          \end{minipage}.
.3 {.}sh \hspace{1cm}  \begin{minipage}[t]{10cm}
          GMT bash scripts\\
	  the main one being plot{.}sh for plotting grids, scalar and vector fields\\
	  anin{.}sh may be used to create animations\\
	  \end{minipage}.
.3 {.cpt} \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Color pallets \\
          \end{minipage}.
.2 graphs/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Output directory for GMT maps (eps and pdf)\\
          \end{minipage}.
.2 grid/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Directory for all grid files\\
	  iModel will automatic save and load the grids from this directory\\
	  GMT will read grid files from this directory to draw figures of grids\\
          \end{minipage}.
.3 {.}dat \hspace{1cm}  \begin{minipage}[t]{10cm}
          Fortran binary files with saved grid information to be loaded\\
	  \end{minipage}.
.3 {.gmt} \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Text grid files for GMT to read and graph\\
          \end{minipage}.
.2 matlab/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Directory for matlab scripts\\
          \end{minipage}.
.2 par/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Directory for input parameter files
          \end{minipage}.
.3 mesh{.}par \hspace{1cm}  \begin{minipage}[t]{10cm}
          Parameters for grid to be used (generate or load)\\
	  \end{minipage}.
.3 simul{.}par \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Parameters for several simulations of differential operator and interpolation testing\\
          \end{minipage}.
.3 multigrid{.}par \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Parameters for Multigrid solver\\
          \end{minipage}.
.3 trans{.}par \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Parameters for Semi-Lagrangian Transport model\\
          \end{minipage}.
.3 swm{.}par \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Parameters for Shallow Water Model\\
          \end{minipage}.
.2 ref/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Directory for reference solutions\\
	  Currently has ENDGame source files\\
	  Reference solutions will be read from this directory\\
	  Edit eg-swm-ref-{.}f90 and run Makefile to create the reference data \\
	  See EG-refsoln-doc{.}pdf for details
          \end{minipage}.
.2 sh/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Bash scripts to run several instances of the program with different parameter configurations
          \end{minipage}.
.2 src/ \hspace{1cm}  \begin{minipage}[t]{10cm}
          Fortran 90 source files and extra bash scripts\\
          \end{minipage}.
.3 imodel{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
          Main driver for program\\
	  Use par/mesh{.}par to select which program component you want to run\\
	  \end{minipage}.
.3 constants{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
          Refers to all constants used in the program\\
	  \end{minipage}.
.3 datastruct*{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
          Refers to all datastructure used for the grids\\
	  datastruct{.}f90 is general and datastructmult{.}f90 is for the multigrid solver \\
	  \end{minipage}.
.3 stripackm{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Robert Renka Algorithm 772 for Parameters for Delaunay Triangulation and Voronoi Diagram on the Surface of a Sphere\\
          \end{minipage}.
.3 smeshpack{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
          Main program for grid generation \\
	  Has many tools to load and work with geodesic grids\\
	  Configure it using par/mesh{.}par
	  \end{minipage}.
.3 interpack{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
          Pack with scalar and vector interpolation routines \\
	  \end{minipage}.
.3 diffoperpack{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
          Pack with some discrete differential operators\\
	  \end{minipage}.
.3 simulpack{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
          Main program for simulations with interpolations and basic discrete differential operator analysis\\
	  Parameters set with par/simul{.}par\\
	  \end{minipage}.
.3 multigrid{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Multigrid solver\\
          \end{minipage}.
.3 transport{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Semi-Lagrangian transport model\\
          \end{minipage}.
.3 swm{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Shallow Water Model\\
	    Relies on data structure dataswm{.}f90
	    \end{minipage}.
.4 dataswm{.}f90 \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Shallow Water Model data structure\\
          \end{minipage}.
.3 *{.}sh \hspace{1cm}  \begin{minipage}[t]{10cm}
	    Scripts for: \\
	    Code archive to tar.bz2 (tarfiles)\\
	    Code backup (backup)\\
	    Verify compiler (compiler) \\
	    Create program directory structure (dirs) \\
	    Create binary link for imodel (link) \\
          \end{minipage}.
}

\section{Usage and Pre-setup programs}

Type ``make'' to compile all source code. Use the parameter files in ``par/*.par'' to setup what you wish to run. Run with ``./imodel'' from the main folder.

Programs already setup. Select in par/mesh.par:\\
\begin{verse}
!  case(1) !Test geodesic to regular grid conversion tool\\
!  case(2) !Test grid point search methods\\
!  case(3) !Mesh quality and distortion tests\\
!  case(4) !Divergence Tests\\
!  case(5) !Laplacian Tests\\
!  case(6) !Test scalar interpolations\\
!  case(7) !Test vector interpolation\\
!  case(8) !Test vector reconstruction\\
!  case(9) !Passive advection simulation\\
!  case(10)!Transport flow simulation\\
!  case(11)!Multigrid tests\\
!  case(12)!Tg reconstruction test\\
!  case(13)!Rotational discretization test\\
!  case(14)!Horizontal Discret Shallow water model diagnostics\\
!  case(15)!Shallow water model test cases\\
\end{verse}

\section{Grid generator}

The grid generator creates spherical triangular grids with its dual Voronoi grid and all the necessary relationship between nodes, edges, triangles and Voronoi cells (see datastruct.f90 for details). All the grid specifications need to be setup um par/mesh.par.

Kinds of grids generated:\\
\begin{verse}
!   icos (icosahedral) \\
!   octg (octahedral) \\
!   read (read from file - give filename where indicated) \\
!   rand (random points - be careful, you can get ugly meshes...) \\
\end{verse}

When using `icos' or `octg', you need to specify the number of nodes wanted as well. It does not need to be exact, as the code will adjust the next icosahedral or octahedral grid with the proper number of nodes.

You may read grid nodes from a text file. This may be with lat/lon  coordinates (which should have extension .gmt) or x/y/z coordinates (which should have extension .xyz) of the points. For x/y/z coordinates, you must first add the number of nodes that will be read. For lat/long, this is not necessary. The order of the points may matter, as we do not want to have the first 3 points aligned. A file with the connection from one node to its neighbour indexes may also be read with extension .ngb (the mesh generator will check if the ngb file exists, if so, use it). These files must be in the grid/ folder in runtime.

The position of the mesh with respect to geographic coordinates may be chosen from:\\
!Mesh Positions \\
\begin{verse}
!  eqs (equator symmetric)\\
!  pol (north pole point)\\
!  ran (all random points)\\
!  ref (local mesh refinement - needs scvt optimization)\\
\end{verse}

Once the grid is generated, you may use all the pre computed data stored in the datastruct of type `mesh'. You may chose to save the generated grid to later load it directly from the binary files.

A regular latitude-longitude grid table containing for each latitude-longitude box the index of the grid nodes it intersects is also generated. This allows a very quick search within the grid, since the regular grid resolution is calculated to be very fine and have on average almost only 1 grid cell intersection. This is useful in Semi-Lagrangian methods, or other procedures that require interpolations of arbitrary points.

\subsection{Grid optimizations}

The grid generator has the following grid optimizers coded:\\
!Optimization of mesh \\
\begin{verse}
!  nopt (no optimization) \\
!  sprg (spring dynamics - ok until level 8) \\
!  scvt (centroidal voronoi) \\
!  salt (aligned tesselation - not debuged ...) \\
!  hr95 (Heikes and Randall 1995 optimization using Miura's alg - not debuged...) \\
\end{verse}

The `salt' optimization tries to align a grid with respect to the index given in \cite{Peixoto2013}, but is not successful. The HR95 grid optimizer is not producing the expected results. It uses and algorithm proposed by  \cite{Miura2005}, that does not seem to converge properly.

There is an option to generate locally refined grids with SCVT tessellations, as in \cite{Ringler2013}. The density function needs to be set in src/smeshpack.f90 function dens\_f. Also, option regarding the way the grid is constructed, recursively (hierarchically)or not.\\

!Hierarchical grid construction: \\
!  0-No; \\
!  1-Yes; \\
!  2 - Optimizes only the new points in hierarchy; \\
!  3 - Do not optimize nodes that belong to primary icosahedral edges\\

\subsection{Testing}
The main testing programs can be selected in the par/mesh.par file as one of the bellow.\\
!  case(1) !Test geodesic to regular grid conversion tool\\
!  case(2) !Test grid point search methods\\
!  case(3) !Mesh quality and distortion tests\\

\subsection{Grid visualization and examples}

To view the grid generated, go to the gmt/ folder and use the `plot.sh' script (for GMT4) or `plot{\textunderscore}gmt5.sh' (for GMT5). You need to provide as command line input the name of the grid you want to be plotted. This is done by passing the name of the file that contain the `*nodes.gmt' in the grd/ folder. The script will guide you through its options, for either plotting just the triangular grid, Voronoi grid and other options. Outputs will be placed in graphs/ folder. Edit plot.sh to fulfill your needs.

\subsubsection{Example 1 - icosahedral grid level 2}
To generate the grid set in par/mesh.par the following parameters (leave the rest as default):
No. of vertices: 42 \\
Kind of mesh: icos \\
Optimization: nopt \\
Run any program of grid testing, e.g. cases 1,2,3, or actually any other test case should generate the grid.
\begin{lstlisting}[language=bash]
$ ./imodel
\end{lstlisting}
Once the grid is generated, run:
\begin{lstlisting}[language=bash]
$ cd gmt
$ ./plot.sh ../grid/icos_pol_nopt_2_nodes.gmt
Options : 1-> 1-> 6
Output in graphs/icos_pol_nopt_2.pdf
\end{lstlisting}

\includegraphics[scale=0.5]{icos_pol_nopt_2}

\subsubsection{Example 2 - Locally refined grid}

Follow the same example as above, but set grid parameters in par/mesh.par to:
No. of vertices: 600 \\
Kind of mesh: icos \\
Position: ref \\
Optimization: scvt \\
It will start from icosahedral grids and use SCVT algorithms to get locally refined ones based on a density function given in src/smeshpack.f90 function dens\_f. The generation can take some minutes.

\begin{lstlisting}[language=bash]
$ cd gmt
$ ./plot.sh ../grid/icos_ref_scvt_h1_3_nodes.gmt
Options : 1-> 1-> 5
Output in graphs/icos_ref_scvt_h1_3.pdf
\end{lstlisting}

\includegraphics[scale=0.5]{icos_ref_scvt_h1_3}

\subsection{Important}

Some grid generations with optimizations can take hours and even days (months in case of very fine grids). The grid points are saved in .xyz of .gmt for future use in this or other codes. All the grid structures and pre calculated features are store as well, and this can be loaded at runtime setting the load option in par/mesh.par. Setting the read option in par/mesh.par read only the node points in cartesian or lat-long coordinates, but regenerates all other data structures and pre computable mesh properties. Please contact me if you wish to have pre-calculated optimized grids, since they are very large, they are not shipped with the code.

\section{Interpolations}

The main module for interpolations on spherical geodesic grids is src/interpack.f90. It contains several kinds of methods and possibilities. These maybe set via par/simul.par, and several testing programs exist to analyse the methods.

\subsection{Variable location}

The variables may be located in the grid in the following different ways:\\
  ! List of Stags for interpolation - (if no vector - considers scalars on vector positions)\\
  ! HA  - Scalars and vectors on triangle vertices, hexagon centers\\
  ! HC  - Scalars on triangle vertices, hexagon centers and vectors hexagon edge midpoints\\
  ! TA  - Scalars and vectors on triangle circumcenter, hexagon vertices\\
  ! TC  - Scalars on triangle vertices, hexagon centers and vectors triangle edge midpoints\\
  ! HCT - Voronoi staggered grid but with vectors on intersection of hx edge and tr edge.\\

Note: Not all methods are implemented for all positionings.

\subsection{Scalar interpolations}

Implemented scalar interpolation methods:\\
    !*** (For values given on triangle vertices - Stag=HA) ***\\
    ! none     = Just get triangle\\
    ! neartrv  = Nearest node  (default)\\
    ! lintrv   = Linear TR - values on tr vertices - default\\
    ! linhxb   = Linear TR - values on Voronoi cell centroids\\
    ! lsqhx    = Quadratic Least Squares \\
    ! hermtrv  = Cubic (R.Renka C1 Hermite)\\
    ! rbftr    = RadialBasisFunction TR (3pts)\\
    ! rbfetr   = RadialBasisFunction ETR(11,12pts)\\
    ! rbfhx    = RadialBasisFunction HX (6,7pts)\\
    ! natlap   = Natural Coordinate with Laplace\\
    ! natsib   = Natural Coordinate with Sibson\\
    ! natfar   = Natural Coordinate with Farin\\
    ! lmshep   = Local Modified Shepard Method\\
    ! qdshep   = Quadratic Shepard Method\\
    !*** (For values given on triangle circumcenters - Stag=TA) ***\\
    ! none     = Just get triangle\\
    ! neartrc  = Nearest triangle\\
    ! wach     = Wachspress interpolation - default\\
    !*** (For values given on triangle edge midpoints - Stag=TC) ***
    ! none     = Just get triangle\\
    ! p1nc     = P1 Non corforming element - default\\
    !*** (For values given on voronoi edge midpoints - Stag=HC) ***
    ! none     = Just get triangle \\
    ! wach     = Modified Wachspress interpolation (linear) - default \\
    ! lmshep   = Local Modified Shepard Method\\
    ! p1nc     = P1 Non corforming element - may do extrapolation\\
    !*** (For values given on Voronoi centroids) ***\\
    ! neartrv  = Nearest node  (default)\\
    !*** (For values given on triangle centroids) ***\\
    ! neartrc  = Nearest triangle  (default)\\

    Use "none" to set no interpolation. Used only to calculate basic computational cost. Some of these scalar interpolations, such as `lintrv' and `wach', may be used to do vector interpolation when the full vector is given pointwise.

\subsection{Vector reconstructions}

See \cite{Peixoto2014} for the vector reconstruction problem definition and methods. The methods implemented are as follows.

    !Kind of reconstruction\\
    !  none   = Just find the nearest node\\
    !  rbf    = Radial Basis Function\\
    !     rbfhx  - rbf for 6 point Voronoi cell\\
    !     rbftr  - rbf for 3 point triangle\\
    !     rbf*pc- rbf* with constant polynomial\\
    !  per    = Perot (2000) recosntruction\\
    !     perhx  - Perot for Hexagons\\
    !     pertr  - Perot for Triangles\\
    !     perpj  - Perot for Hexagons projecting to tang plane\\
    !     pered  - Perot vector for edges (tangent recon)\\
    !  lsq    = Least Square Fit\\
    !     lsqhxe - 12 point hexagon stencil\\
    !     lsqtrc - 9 point triangle based stencil\\
    !  rt0    = Raviart Thomas 0th order element reconstruction\\
    !  dtred  = Dual triangle tangent reconstruction\\
    !  wht    = Whitney Edge element reconstruction\\
    !  kls    = Klausen reconstruction with Wachspress coords\\
    !  trsk   = TRISK tangent vector reconstruction\\

\subsection{Testing}
The main testing programs can be found in src/simulpack.f90, and the test can be selected in the par/mesh.par file as one of the bellow.\\
!  case(6) !Test scalar interpolations\\
!  case(7) !Test vector interpolation\\
!  case(8) !Test vector reconstruction\\
!  case(12)!Tg reconstruction test\\

There are several scalar and vector function options that can be selected, see par/simul.par.

Once a test has been run, the results are stored in data/ folder with either numerical text files (for errors and diagnostics) or .dat files, for field plots. To plot a field, you can use the plot.sh GMT script.

Example setting staggering to HA in par/simul.par and keeping the rest default - shows the exact scalar function to be interpolated:
\begin{lstlisting}[language=bash]
$ cd gmt
$ ./plot.sh ../data/sinterp_f5_HA_lintrv_exact_icos_pol_nopt_5.dat
Options : 2-> 2-> 0-> 6
Output in ../graphs/sinterp_f5_HA_lintrv_exact_icos_pol_nopt_5.pdf
\end{lstlisting}
\includegraphics[scale=0.5]{sinterp_f5_HA_lintrv_exact_icos_pol_nopt_5}

\section{Differential operators}

The analysis of the differential operator done in \cite{Peixoto2013} were mainly using the code in simulpack.f90 and diffoperpack.f90. You can chose the variable location as with the interpolation methods.

\subsection{Testing}
The main testing programs can be selected in the par/mesh.par file as one of the bellow.\\
!  case(4) !Divergence Tests\\
!  case(5) !Laplacian Tests\\

Use the same plotting routines as used in interpolation routines. Example setting staggering to HC in par/simul.par and keeping the rest default - shows the error in the divergence calculation:

\begin{lstlisting}[language=bash]
$ cd gmt
$ ./plot.sh ../data/divtest_f5_HC_error_icos_pol_nopt_5.dat
Options : 2-> 1-> 0-> 2
Output in ../graphs/divtest_f5_HC_error_icos_pol_nopt_5.pdf
\end{lstlisting}
\includegraphics[scale=0.5]{divtest_f5_HC_error_icos_pol_nopt_5}

\section{Multigrid solver}

This part of the code was developed by Marline I. Silva in Sept 2014. It reads the parameter from par/multigrid.par and runs several tests for the multigrid solver. Select the following test case in par/mesh.par to run this program:\\
!  case(11)!Multigrid tests

This part of the code has not been thoroughly debug, and some tiding up may be necessary.

\section{Transport model}

The transport model is a Semi-Lagrangian as described in \cite{Peixoto2013b} and \cite{Peixoto2014}. You can run several test cases editing par/trans.par and selecting in par/mesh.par the following cases:\\
!  case(9) !Passive advection simulation\\
!  case(10)!Transport flow simulation\\

There is GMT script to create animations in gmt/anim.sh - please refer to it on usage.

\section{Shallow Water Model}

The shallow water model is a finite volume method with some methods implemented. The main module is swm.f90. First it has the TRSK method of \cite{Thuburn2009} and \cite{Ringler2010}, but also the modified scheme proposed in \cite{Peixoto2015}. Edit par/swm.par to configure the shallow water model.

!Test Cases implemented\\
2 : Steady State Will92\\
5 : Flow over mountain Will92\\
6 : Rossby-Haurwitz Will92 \\
11 : Linearized equations - for mode calculation - fsphere\\
12 : Linearized equations - for mode calculation - f variable\\
21 : Galewski et al Barotropically unstable jet with perturbation\\
22 : Galewski et al Barotropically unstable jet without perturbation\\
32 : Hollingsworth instability with tc2\\
33 : Hollingsworth instability with constant h and non rotating frame  \\
42 : Rotated Steady state localised test on f-sphere\\
51 : Flow over mountain Will92 smooth mountain (Gaussian)\\

Some test cases rely on reference solutions to calculate errors. These solutions, if wanted, need to be pre-computed from the reference folder (ref/) with the ENDGame shallow water model - there is special documentation file in that folder to help.

To set up the new modified scheme proposed in \cite{Peixoto2015}, set in swm.par the following parameters:
\begin{verse}
!Scalar/vector location (HC or HTC) \\
HC \\
!Cell vec reconstruction method (Kenergy) / Gassmann parameter (if gass set) \\
perhx 0.75 \\
!Coriolis vec reconstruction method \\
pered \\
!Scalar interpolations \\
bary \\
!Gradient discrete method \\
trsk \\
\end{verse}
You also should set the HR95 grids to be read in par/mesh.par - the grid generator is not able to generate these with the same properties as in \cite{Heikes1995a}, so the .xyz grid nodes must be provided.

For TRSK, use
\begin{verse}
!Scalar/vector location (HC or HTC) \\
HTC \\
!Cell vec reconstruction method (Kenergy) / Gassmann parameter (if gass set) \\
trsk 0.75 \\
!Coriolis vec reconstruction method \\
trsk \\
!Scalar interpolations \\
trsk \\
!Gradient discrete method \\
trsk \\
\end{verse}

You can get the preprint of \cite{Peixoto2015} in \url{www.ime.usp.br/~pedrosp}, but I do apologize that some of the notation is different in the paper and code. Please contact me if you wish to have pre-calculated HR95 optimized grids.

\bibliographystyle{plainnat}% citação bibliográfica alpha
\bibliography{bibliography}  % associado ao arquivo: 'bibliografia.bib'

\end{document}