\documentclass{beamer}
\usepackage{appendixnumberbeamer}

\mode<presentation>{\usetheme[subsectionpage=progressbar,block=fill,numbering=none]{metropolis}}

\usepackage[sfdefault]{FiraSans} %% option 'sfdefault' activates Fira Sans as the default text font
\usepackage[english]{babel}
% \usepackage[utf8]{inputenc}

\usepackage{graphicx} % Allows including images
\usepackage{caption}
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage{multicol}

% Math packages
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{mathpartir}
\usepackage{stmaryrd}
\usepackage{centernot}
\usepackage[normalem]{ulem}

%% Coding
\usepackage[outputdir=build]{minted}

% Coloured boxes
\usepackage{tcolorbox}
\colorlet{alert}{mLightBrown}
\colorlet{mLightBrownTransparent}{white!70!mLightBrown}
\newtcolorbox{alertbox}
{standard jigsaw, opacityback=0,colframe=alert}
\newtcolorbox{tbox}
{standard jigsaw, opacityback=0,opacityframe=0}

%% Quotes with author
\usepackage{xparse}

\let\oldquote\quote
\let\endoldquote\endquote

\RenewDocumentEnvironment{quote}{o}
  {\oldquote}
  {\IfValueT{#1}{\par\nobreak
   \hfill--- #1}\endoldquote\addvspace{\smallskipamount}}

\newcommand{\dotcup}{\mathbin{\mathaccent\cdot\cup}}
\newcommand{\fromto}[2]{\{#1,\dotsc,#2\}}
\newcommand{\denot}[1]{\llbracket#1\rrbracket}
\newcommand{\listt}[1]{\mathsf{List}~#1}
\newcommand{\map}{\mathsf{map}}
\newcommand{\haskell}[1]{\mintinline{haskell}{#1}}
\newcommand{\vint}[1]{\mathcal{V}\denot{#1}}
\newcommand{\tint}[1]{\mathcal{E}\denot{#1}}
\newcommand{\wt}[1]{\mathsf{wt}_{#1}}
\newcommand{\rels}{\mathcal{R}}
\newcommand{\values}{Val}
\newcommand{\bool}{\mathsf{Bool}}
\newcommand{\nat}{\mathsf{Nat}}
\newcommand{\zero}{\mathsf{0}}
\newcommand{\suc}{\mathsf{succ}}
\newcommand{\pair}{\mathsf{pair}}
\newcommand{\true}{\mathsf{true}}
\newcommand{\false}{\mathsf{false}}
\newcommand{\nil}{\mathsf{nil}}
\newcommand{\cons}{\mathsf{cons}}
\newcommand{\length}{\mathsf{length}}
\newcommand{\eq}{\mathsf{eq}}
\newcommand{\cmp}{\mathsf{cmp}}
\newcommand{\nf}[1]{#1{\downarrow}}
\newcommand{\eqnf}{=^*}

\title{Theorems for Free!} % the title on the title page
\subtitle{by Philip Wadler}

\author{Kevin Kappelmann} % Your name
\institute[TU Munich]{Technical University of Munich}
\date{May 27, 2021} % Date, can be changed to a custom date

\begin{document}

\maketitle

%------------------------------------------------
\section{Type Systems and Polymorphism}
% \begin{frame}[fragile]{Haskell Has Types}

% \begin{minted}{haskell}
% appTwice :: (Int -> Int) -> Int -> Int
% appTwice f x = f (f x)
% \end{minted}

% \pause
% \centering What is the result of\dotso

% \begin{uncoverenv}<3>
% \begin{onlyenv}<1-3>
% \begin{minted}{haskell}
% appTwice (*2) 1 = ?
% \end{minted}
% \end{onlyenv}
% \end{uncoverenv}

% \begin{onlyenv}<4>
% \begin{minted}{haskell}
% appTwice (*2) 1 = 4
% \end{minted}
% \end{onlyenv}

% \begin{onlyenv}<5>
% \begin{minted}{haskell}
% appTwice (*2) 1 = 4
% appTwice (*2) "bogus" = ?
% \end{minted}
% \end{onlyenv}

% \begin{onlyenv}<6>
% \begin{minted}{haskell}
% appTwice (*2) 1 = 4
% appTwice (*2) "bogus" = ...
% \end{minted}
% \begin{alertbox}
% \begin{minted}[escapeinside=??]{bash}
% • Couldn?'?t match expected type ‘Int’ with
  % actual type ‘[Char]’
% • In the second argument of ‘appTwice’,
  % namely ‘"bogus"’
  % In the expression: appTwice (*2) "bogus"...
% \end{minted}
% \end{alertbox}
% \end{onlyenv}
% \end{frame}

% \begin{frame}
% \centering
% \Huge Thank you, type system!
% \end{frame}

% \begin{frame}{What is a Type System?}

% {\Large Type systems are mechanisms that guarantee the absence of certain programming errors.}

% \pause
% \vspace{3\baselineskip}
% \centering{\alert{\large \dotso is there a catch?}}
% \end{frame}

\begin{frame}[fragile]{Sigh, Just Apply It Twice!}
\begin{minted}{haskell}
appTwice :: (Int -> Int) -> Int -> Int
appTwice f x = f (f x)
\end{minted}

\centering What is the result of\dotso

\begin{onlyenv}<1-2>
\begin{uncoverenv}<2>
\begin{minted}{haskell}
appTwice (*2) 1 = ?
\end{minted}
\end{uncoverenv}
\end{onlyenv}

\begin{onlyenv}<3>
\begin{minted}{haskell}
appTwice (*2) 1 = 4
\end{minted}
\end{onlyenv}

\begin{onlyenv}<4>
\begin{minted}{haskell}
appTwice (*2) 1 = 2
appTwice (*2) "bogus" = ?
\end{minted}
\end{onlyenv}

\begin{onlyenv}<5>
\begin{minted}{haskell}
appTwice (*2) 1 = 2
appTwice (*2) "bogus" = ...
\end{minted}
\end{onlyenv}

\begin{onlyenv}<1-5>
\begin{uncoverenv}<5>
\begin{alertbox}
\begin{minted}[escapeinside=??]{bash}
• Couldn?'?t match expected type ‘Int’ with
  actual type ‘[Char]’
• In the second argument of ‘appTwice’,
  namely ‘"bogus"’
  In the expression: appTwice (*2) "bogus"...
\end{minted}
\end{alertbox}
\end{uncoverenv}
\end{onlyenv}

\begin{onlyenv}<6>
\begin{minted}{haskell}
appTwice (*2) 1 = 2
appTwice (++"l") "haske" = ?
\end{minted}
\end{onlyenv}

\begin{onlyenv}<7>
\begin{minted}{haskell}
appTwice (*2) 1 = 2
appTwice (++"l") "haske" = ...
\end{minted}
\end{onlyenv}

\begin{onlyenv}<6->
\begin{uncoverenv}<7->
\begin{alertbox}
\begin{minted}[escapeinside=??]{bash}
• Couldn?'?t match type ‘[Char]’ with ‘Int’
  Expected type: Int -> Int
  Actual type: [Char] -> [Char]
• In the first argument of ‘appTwice’,
  namely ‘(++"l")’
  In the expression: appTwice (++"l") "haske"...
\end{minted}
\end{alertbox}
\end{uncoverenv}
\end{onlyenv}

\end{frame}

% \begin{frame}[fragile]{Do Not Repeat Yourself}
% Well then, let us fix this problem:

% \begin{onlyenv}<1-3>
% \begin{uncoverenv}<2-3>
% \begin{minted}{haskell}
% appTwiceInt :: (Int -> Int) -> Int -> Int}
% appTwiceInt f x = f (f x)

% appTwiceString :: (String -> String) -> String -> String
% appTwiceString f x = f (f x)
% \end{minted}
% \end{uncoverenv}
% \end{onlyenv}

% \begin{onlyenv}<4>
% \begin{minted}[highlightlines={2,5},highlightcolor=mLightBrownTransparent]{haskell}
% appTwiceInt :: (Int -> Int) -> Int -> Int}
% appTwiceInt f x = f (f x)

% appTwiceString :: (String -> String) -> String -> String
% appTwiceString f x = f (f x)
% \end{minted}
% \end{onlyenv}
% \only<1-3>{\uncover<3>{And we are happy again:}}
% \only<4>{And we are \sout{happy} \alert{unhappy} again:}

% \begin{uncoverenv}<3->
% \begin{minted}{haskell}
% appTwiceInt (*2) 1 = 4
% appTwiceSting (++"l") "haske" = "haskell"
% \end{minted}
% \end{uncoverenv}
% \end{frame}

% \begin{frame}{The \emph{Abstraction Principle}}
% \begin{quote}[Benjamin Pierce]
% Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts.
% \end{quote}
% \end{frame}

\begin{frame}[fragile]{Polymorphism to the Rescue!}
Haskell knows \emph{parametric polymorphism}: we
can abstract over types by using type variables.

\pause

\begin{minted}{haskell}
appTwice :: (a -> a) -> a -> a
appTwice f x = f (f x)
\end{minted}

\pause
And we are happy:

\begin{minted}{haskell}
appTwice (*2) 1 = 4
appTwice (++"l") "haske" = "haskell"
\end{minted}

\pause
\centering {\large End of the story? \pause \alert{Of course not!}}

\end{frame}

\begin{frame}
\centering {\Huge Polymorphism comes with another twist!}
\end{frame}

\begin{frame}[fragile]{Black Magic}
I show you a term's type but not its definition.
You tell me the possible results:
\footnote{Let us forget about \mintinline{haskell}{undefined} for a moment.}

% \begin{uncoverenv}<2>
% \begin{onlyenv}<1-2>
% \begin{minted}{haskell}
% f :: a -> b -> a
% -- def. of f hidden

% f 42 "hi" = ?
% f "hi" 42 = ?
% \end{minted}
% \end{onlyenv}
% \end{uncoverenv}

% \begin{onlyenv}<3>
% \begin{minted}{haskell}
% f :: a -> b -> a
% -- def. of f hidden

% f 42 "hi" = 42
% f "hi" 42 = "hi"
% \end{minted}
% \end{onlyenv}

% \begin{onlyenv}<4>
% \begin{minted}{haskell}
% f :: a -> b -> a
% f x y = x

% f 42 "hi" = 42
% f "hi" 42 = "hi"
% \end{minted}
% \end{onlyenv}

\begin{uncoverenv}<2>
\begin{onlyenv}<1-2>
\begin{minted}{haskell}
g :: (a -> a) -> a -> a
-- def. of g hidden

g (*2) 1 =? 1
g (*2) 1 =? 2
g (*2) 1 =? 3
g (*2) 1 =? 16
g (*2) 1 =? 42
\end{minted}
\end{onlyenv}
\end{uncoverenv}

\begin{onlyenv}<3-4>
\begin{minted}[highlightlines={4,5,7},highlightcolor=mLightBrownTransparent]{haskell}
g :: (a -> a) -> a -> a
-- def. of g hidden

g (*2) 1 =? 1
g (*2) 1 =? 2
g (*2) 1 /= 3
g (*2) 1 =? 16
g (*2) 1 /= 42
\end{minted}
\end{onlyenv}

\begin{onlyenv}<5>
\begin{minted}[highlightlines={7},highlightcolor=mLightBrownTransparent]{haskell}
g :: (a -> a) -> a -> a
-- def. of g hidden

g (*2) 1 /= 1
g (*2) 1 /= 2
g (*2) 1 /= 3
g (*2) 1 = 16
g (*2) 1 /= 42
\end{minted}
\end{onlyenv}

\begin{onlyenv}<6>
\begin{minted}[highlightlines={7},highlightcolor=mLightBrownTransparent]{haskell}
g :: (a -> a) -> a -> a
g f x = f (f (f (f x)))

g (*2) 1 /= 1
g (*2) 1 /= 2
g (*2) 1 /= 3
g (*2) 1 = 16
g (*2) 1 /= 42
\end{minted}
\end{onlyenv}

\uncover<4-6>{
What if I told you that \mintinline{haskell}{g (++"I") "" = "IIII"}?
}
\end{frame}

\begin{frame}
\Large Polymorphic functions are defined once and for all for any type and as such must work uniformly on values of any type.

\pause

\Large From the type of a polymorphic function,
we can derive a theorem that it satisfies.
\end{frame}

\begin{frame}
\centering \huge Polymorphic types provide us \emph{theorems for free}.
\end{frame}

\section{Technical Development}

\begin{frame}{System F}

The polymorphic lambda calculus aka System F:

\pause
Types:
\begin{equation*}
\tau \Coloneqq  \alpha \mid \tau \to \tau \mid \forall \alpha.\ \tau
\end{equation*}

\pause
Terms:
\begin{equation*}
t \Coloneqq x \mid \lambda x : \tau.\ t \mid t\, t \mid \Lambda \alpha.\ t \mid  t\,[\tau]
\end{equation*}

\pause
Values:
\begin{equation*}
v \Coloneqq x\mid \lambda x : \tau.\ t \mid \Lambda \alpha.\ t
\end{equation*}

\pause
Here is our \mintinline{haskell}{appTwice} function:
\begin{align*}
&\Lambda \alpha.\,\lambda f : \alpha\to\alpha.\,\lambda x : \alpha.\, f\ (f\, x) : \forall \alpha.\, (\alpha\to\alpha)\to\alpha\to\alpha
\end{align*}

\pause

We can call it like this: \mintinline{haskell}{appTwice [Int] (+1) 0}
\end{frame}

\begin{frame}[fragile]{Types as Relations}
\only<1>{It is natural to interpret a type $\tau$ as a set $\denot{\tau}$ containing all values of type $\tau$, e.g. $\denot{\mintinline{haskell}{Bool}}=\{\mintinline{haskell}{True,False}\}$ in Haskell.}
\only<2>{\sout{It is natural to interpret a type $\tau$ as a set $\denot{\tau}$ containing all values of type $\tau$, e.g. $\denot{\mintinline{haskell}{Bool}}=\{\mintinline{haskell}{True,False}\}$ in Haskell.}}

% \pause

% The key idea to derive free theorems is to instead interpret a \emph{type as a relation} that
% \begin{enumerate}[<+->]
% \item relates terms of the given type and
% \item whose membership is preserved under eliminating forms.
% \end{enumerate}

\vspace{\baselineskip}

\uncover<2>{\centering \Large New slogan: \alert{types relate terms and related terms lead to related results.}}
\end{frame}

\begin{frame}{Types as Relations: Examples}
\begin{columns}
	\column{\dimexpr\paperwidth-10pt}
\begin{itemize}[<+->]
  \item Base types are interpreted as their identity relation,
    e.g.\
    $\denot{\haskell{Bool}}=\{(\haskell{True,True}),(\haskell{False,False})\}$.
  \item Two pairs are related if their components are related, i.e.
\vspace{-0.5\baselineskip}
\begin{equation*}
	\bigl((t_1,t_2),(t_1',t_2')\bigr)\in\denot{(\tau_1,\tau_2)} \iff (t_1,t_1')\in\denot{\tau_1}\land (t_2,t_2')\in\denot{\tau_2}.
\end{equation*}
  \item Two lists are related if they have the same length and their elements are related, i.e.
\vspace{-0.5\baselineskip}
\begin{align*}
&\bigl([t_1,\dotsc,t_n],[t_1',\dotsc,t_{n'}']\bigr)\in \denot{\listt{\tau}}\\
\iff&n = n' \land \forall i\in\fromto{1}{n}.\ (t_i,t_i')\in \denot{\tau}.
\end{align*}
  \item Two functions are related if they map related arguments to related results, i.e.
\vspace{-0.5\baselineskip}
\begin{equation*}
	(f,f')\in \denot{\tau_1 \to \tau_2} \iff \forall (t,t')\in \denot{\tau_1}.~\bigl(f\, t, f'\, t'\bigr)\in\denot{\tau_2}.
\end{equation*}
\end{itemize}
\end{columns}
\end{frame}

\begin{frame}{Recipe for Logical Relations}
A \emph{logical relation} $R\denot{\tau}$ is an inductive family of relations indexed by types.

\pause
If we want to prove a property $P$ for the terms of our language,
we construct $R\denot{\tau}$ in a way such that:
\begin{enumerate}[<+->]
  \item If $R\denot{\tau}\bigl(t_1,\dotsc,t_n\bigr)$ then
  \begin{enumerate}
    \item $\vdash t_i : \tau$ for $1\leq i \leq n$ (we write $\wt{\tau}(t_1,\dotsc,t_n)$)
    \item $P\bigl(t_1,\dotsc,t_n\bigr)$
  \end{enumerate}
  \item The conditions of the relation are preserved by eliminating forms.
\end{enumerate}

\end{frame}

\begin{frame}{Our Logical Relation}
We split our logical relation into two parts:
\begin{enumerate}
\item $\vint{\tau}$ on values
\item $\tint{\tau}$ on general terms
\end{enumerate}

\pause
\begin{align*}
  \tint{\tau}\coloneqq\bigl\{(t_1,t_2)\mid
  \wt{\tau}(t_1,t_2)\land (\nf{t_1},\nf{t_2})\in\vint{\tau}\bigr\}
\end{align*}

\end{frame}

\begin{frame}{Relating Functions}

If we had a $\haskell{Bool}$ base type, we would first define:
\begin{equation*}
  \vint{\haskell{Bool}}\coloneqq\{(\haskell{True,True}),(\haskell{False,False})\}
\end{equation*}

\pause
And then continue with function types:
\begin{align*}
  \vint{\tau_1\to\tau_2}\coloneqq
  \Bigl\{&(\lambda x : \tau_1.\ t_1, \lambda x : \tau_1.\ t_2) \mid\\
  \onslide<3->{&\phantom{\land\, }\wt{\tau_1\to\tau_2}(\lambda x : \tau_1.\ t_1, \lambda x : \tau_1.\ t_2)\\}
  \onslide<4->{&\land\forall (v_1,v_2)\in\vint{\tau_1}.\ \bigl(t_1[v_1/x],t_2[v_2/x]\bigr)\in\tint{\tau_2}} \Bigr\}
\end{align*}
% \begin{align*}
  % \vint{\tau_1\to\tau_2}_\rho\coloneqq
  % \Bigl\{&\bigl(\lambda x : \rho(\tau_1).\ t_1, \lambda x : \rho(\tau_1).\ t_2\bigr) \mid\\
  % &\phantom{\land\, }\wt{\rho(\tau_1)\to\rho(\tau_2)}\bigl(\lambda x : \rho(\tau_1).\ t_1, \lambda x : \rho(\tau_1).\ t_2\bigr)\\
  % & \land \forall (v_1,v_2)\in\vint{\tau_1}_\rho.\ \bigl(t_1[v_1/x],t_2[v_2/x]\bigr)\in\tint{\tau_2}_\rho \Bigr\}
% \end{align*}
\end{frame}

\begin{frame}{Relating Type Abstractions: First Try}
\begin{align*}
  \vint{\forall \alpha.\ \tau}\coloneqq
  \Bigl\{&(\Lambda \alpha.\ t_1, \Lambda \alpha.\ t_2) \mid\\
  \onslide<2->{&\phantom{\land\, }\wt{\forall \alpha.\, \tau}(\Lambda \alpha.\ t_1, \Lambda \alpha.\ t_2)\\}
  \onslide<3->{&\land\forall \tau_1,\tau_2.\ \bigl(t_1[\tau_1/\alpha],t_2[\tau_2/\alpha]\bigr)\in\tint{\tau[?/\alpha]}} \Bigr\}
\end{align*}

\uncover<4>{
\alert{Under which type should $t_1[\tau_1/\alpha]$ and $t_2[\tau_2/\alpha]$ be related under?}
}

\end{frame}

\begin{frame}{Relating Type Abstractions: Second Try}
Trick: keep track of the chosen types in a substitution $\rho$
\pause
\begin{align*}
  \vint{\forall \alpha.\ \tau}_{\alert{\rho}}\coloneqq
  \Bigl\{&(\Lambda \alpha.\ t_1, \Lambda \alpha.\ t_2) \mid\\
   &\phantom{\land\, }\wt{\forall \alpha.\, \alert{\rho(\tau)}}(\Lambda \alpha.\ t_1, \Lambda \alpha.\ t_2)\\
 &\land\forall \tau_1,\tau_2.\ \bigl(t_1[\tau_1/\alpha],t_2[\tau_2/\alpha]\bigr)\in\alert{\tint{\tau}_{\rho[\alpha\mapsto(\tau_1,\tau_2)]}} \Bigr\},
\end{align*}

\end{frame}

\begin{frame}{Relating Variables: First Try}
\begin{align*}
\vint{\alpha}_\rho\coloneqq
  \Bigl\{&(v_1,v_2) \mid\\
  \onslide<2->{&\phantom{\land\, }\wt{\rho(\alpha)}(v_1,v_2)}\\
 &\onslide<3->{\land\ \alert{?}}\hspace{5cm}\Bigr\}
\end{align*}

\onslide<3>{
\alert{How should we relate values of possibly different types?}
}
\end{frame}

\begin{frame}{Relating Type Abstractions: Final Version}

Idea: whenever we pick two types $\tau_1,\tau_2$, we also pick a relation on $\tau_1$ and $\tau_2$.
\pause
\begin{align*}
  \vint{\forall \alpha.\ \tau}_\rho\coloneqq
  \Bigl\{&(\Lambda \alpha.\ t_1, \Lambda \alpha.\ t_2) \mid\\
  &\phantom{\land\, }\wt{\forall \alpha.\, \rho(\tau)}(\Lambda \alpha.\ t_1, \Lambda \alpha.\ t_2)\\
  &\land \forall \tau_1,\tau_2,\alert{R\in\rels(\tau_1,\tau_2)}.\ \\
  &\quad\bigl(t_1[\tau_1/\alpha],t_2[\tau_2/\alpha]\bigr)\in\tint{\tau}_{\rho[\alert{\alpha\mapsto(\tau_1,\tau_2,R)}]} \Bigr\},
\end{align*}
\pause
where $R$ is just a relation of closed, well-typed values:
\begin{equation*}
\rels(\tau_1,\tau_2)\coloneqq\bigl\{R\in\mathcal{P}(\values\times \values)\mid \forall(v_1,v_2)\in R.\ \wt{\tau_1}(v_1)\land\wt{\tau_2}(v_2)\bigr\}.
\end{equation*}
\end{frame}

\begin{frame}{Final Updates}
\begin{equation*}
  \vint{\alpha}_\rho\coloneqq
  \bigl\{(v_1,v_2) \in R \mid
  \wt{\rho(\alpha)}(v_1,v_2) \land \rho(\alpha)=(\tau_1,\tau_2,R) \bigr\}
\end{equation*}
\pause
\begin{align*}
  \vint{\tau_1\to\tau_2}_{\alert{\rho}}\coloneqq
    \Bigl\{&\bigl(\lambda x : \alert{\rho(\tau_1)}.\ t_1, \lambda x : \alert{\rho(\tau_1)}.\ t_2\bigr) \mid\\
&\phantom{\land\, }\wt{\alert{\rho(\tau_1)}\to\alert{\rho(\tau_2)}}\bigl(\lambda x : \alert{\rho(\tau_1)}.\ t_1, \lambda x : \alert{\rho(\tau_1)}.\ t_2\bigr)\\
& \land \forall (v_1,v_2)\in\vint{\tau_1}_{\alert{\rho}}.\ \bigl(t_1[v_1/x],t_2[v_2/x]\bigr)\in\tint{\tau_2}_{\alert{\rho}} \Bigr\}
\end{align*}
\begin{align*}
  \tint{\tau}_{\alert{\rho}}\coloneqq\bigl\{(t_1,t_2)\mid
  \wt{\alert{\rho(\tau)}}(t_1,t_2)\land (\nf{t_1},\nf{t_2})\in\vint{\tau}_{\alert{\rho}}\bigr\}
\end{align*}
\end{frame}

\begin{frame}{Parametricity Theorem}
\begin{theorem}[Parametricity Theorem]
  If $\vdash t : \tau$ then
  $(t,t\bigr)\in\tint{\tau}_\emptyset$.
\end{theorem}

\large In other words: \alert{every closed, well-typed term is related to itself.}

\end{frame}

\section{Examples of Free Theorems}

% \begin{frame}{Natural Numbers}
% Assume we have a base type $\mathbb{N}$ with $\suc : \mathbb{N}\to\mathbb{N}$.

% \pause
% Assume we are given some value $t : \forall \alpha.\, (\alpha\to\alpha)\to\alpha\to\alpha$, a type $\tau$, and values $s : \tau\to\tau$ and $z : \tau$.
% What is the result of $t\,[\tau]\,s\,z$?

% \pause
% Set $R\coloneqq \bigl\{(n,\nf{(s^n\, z)})\mid n\in\mathbb{N}\bigr\}$ and note that $(\suc, s)\in\vint{\alpha\to\alpha}_{[\alpha\mapsto(\mathbb{N},\tau,R)]}$:\\
% \pause If $(v_1,v_2)\in\vint{\alpha}_{[\alpha\mapsto(\mathbb{N},\tau,R)]}$
% then $(v_1,v_2)=\bigl(n,\nf{(s^n\, z)}\bigr)$ for some $n$.
% Thus $(\suc\,v_1,s\,v_2)\eqnf\bigl(n+1,\nf{(s^{n+1}\, z)}\bigr)\in R$.

% \pause
% Hence, $\bigl(t\,[\mathbb{N}]\,\suc\, 0,t\,[\tau]\,s\,z\bigr)\in\tint{\alpha}_{[\alpha\mapsto(\mathbb{N},\tau,R)]}$ by the Parametricity Theorem.
% \pause So there is $v' : \mathbb{N}$ and $v : \tau$ such that
% $t\,[\mathbb{N}]\,\suc\, 0\to^*v'$ and $t\,[\tau]\,s\,z\to^*v$ and $(v',v)\in R$.
% \pause Hence $v \eqnf s^n\, z$ where $n$ is determined by $t\,[\mathbb{N}]\,\suc\, 0\to^*v'\eqnf n$.
% \end{frame}

\begin{frame}{Rearranging Lists}
Assume we are given a value
$t : \forall \alpha.\, \listt{\alpha}\to\listt{\alpha}$.

\pause
We show that
\begin{equation*}
  \forall \alpha,\alpha',(f : \alpha\to\alpha'),(xs : \listt{\alpha}).\, \map\,f\,(t\,[\alpha]\,xs)\eqnf t\,[\alpha']\,(\map\,f\,xs)
\end{equation*}

\pause
Pick any $\tau,\tau',f : \tau\to\tau'$.
\pause
By the Parametricity Theorem, for any $R$ and $(xs,xs')\in\vint{\listt{\alpha}}_{[\alpha\mapsto(\tau,\tau',R)]}$, we have $(t\,[\tau]\, xs,t\,[\tau']\, xs')\in\tint{\listt{\alpha}}_{[\alpha\mapsto(\tau,\tau',R)]}$.

\pause
If we specialise $R=\bigl\{(v,\nf{(f\, v)})\mid \wt{\tau}(v)\bigr\}$,
the property $(xs,xs')\in\vint{\listt{\alpha}}_{[\alpha\mapsto(\tau,\tau',R)]}$
translates to $xs'\eqnf \map\, f\, xs$.

\pause
Similarly,
$\bigl(t\,[\tau]\, xs,t\,[\tau']\, xs'\bigr)\in\tint{\listt{\alpha}}_{[\alpha\mapsto(\tau,\tau',R)]}$
translates to
$t\, [\tau']\,xs' \eqnf \map\,f\,(t\,[\tau]\, xs)$.

\pause
Putting it together: $t\, [\tau']\,(\map\, f\, xs) \eqnf \map\,f\,(t\,[\tau]\, xs)$.
\end{frame}

\begin{frame}{Negative Results}
Note that in Haskell \haskell{undefined :: forall a. a}.
Can we define such a term in System F?

\pause
Assume there is a value $u : \forall \alpha.\, \alpha$.
Pick any $\tau,\tau'$ and set $R=\emptyset$.
\pause
Then by the Parametricity Theorem,
$\bigl(u\,[\tau],u[\tau']\bigr)\in R=\emptyset$,
which is impossible.

\end{frame}

\section{Going Beyond System F}
\begin{frame}{Further Applications and Extensions}
\begin{enumerate}[<+->]
\item Representation independence of abstract data types
\item Free Theorems for non-total extensions with general recursion
\item Free Theorems for recursive data types
\item Free Theorems for type constructors and type classes
\item Free Theorems for pure type systems (and hence in particular for dependent type systems)
\item Free Theorems for gradually typed systems
\item Free Theorems in interactive theorem provers (Isabelle: transfer)
\end{enumerate}
\end{frame}

\begin{frame}

\begin{quote}[Wadler]
\Large How useful are the [free] theorems so generated? Only time and experience will tell\dots
\end{quote}

\pause
\vspace{\baselineskip}
\begin{quote}[Me]
It kicked off much fruitful research and the results can indeed be very useful in formal verification.
\end{quote}
\end{frame}

%------------------------------------------------
\begin{frame}[standout]
\Large{\alert{Any questions?}}

\includegraphics[scale=0.49]{wadlers.jpg}
\end{frame}
%----------------------------------------------------------------------------------------
%\begin{frame}[allowframebreaks]{References}
  %\bibliography{../paper/sources.bib}
  %\bibliographystyle{abbrv}
%\end{frame}

% \begin{frame}[allowframebreaks]{Image Sources}
% \begin{itemize}
% \end{itemize}
% \end{frame}

\begin{frame}{Natural Numbers}
Assume we have a base type $\mathbb{N}$ with $\suc : \mathbb{N}\to\mathbb{N}$.

\pause
Assume we are given some value $t : \forall \alpha.\, (\alpha\to\alpha)\to\alpha\to\alpha$, a type $\tau$, and values $s : \tau\to\tau$ and $z : \tau$.
What is the result of $t\,[\tau]\,s\,z$?

\pause
Set $R\coloneqq \bigl\{(n,\nf{(s^n\, z)})\mid n\in\mathbb{N}\bigr\}$ and note that $(\suc, s)\in\vint{\alpha\to\alpha}_{[\alpha\mapsto(\mathbb{N},\tau,R)]}$:\\
\pause If $(v_1,v_2)\in\vint{\alpha}_{[\alpha\mapsto(\mathbb{N},\tau,R)]}$
then $(v_1,v_2)=\bigl(n,\nf{(s^n\, z)}\bigr)$ for some $n$.
Thus $(\suc\,v_1,s\,v_2)\eqnf\bigl(n+1,\nf{(s^{n+1}\, z)}\bigr)\in R$.

\pause
Hence, $\bigl(t\,[\mathbb{N}]\,\suc\, 0,t\,[\tau]\,s\,z\bigr)\in\tint{\alpha}_{[\alpha\mapsto(\mathbb{N},\tau,R)]}$ by the Parametricity Theorem.
\pause So there is $v' : \mathbb{N}$ and $v : \tau$ such that
$t\,[\mathbb{N}]\,\suc\, 0\to^*v'$ and $t\,[\tau]\,s\,z\to^*v$ and $(v',v)\in R$.
\pause Hence $v \eqnf s^n\, z$ where $n$ is determined by $t\,[\mathbb{N}]\,\suc\, 0\to^*v'\eqnf n$.
\end{frame}

\begin{frame}{Negative Results II}
We cannot define a polymorphic equality function $\eq : \forall \alpha.\, \alpha\to\alpha\to\bool$:

We would get $\eq\,[\tau]\,v_1\,v_2 \eqnf \eq\,[\tau']\,(f\,v_1)\,(f\,v_2)$ for any $f : \tau\to\tau',v_1 : \tau,v_2 : \tau$.
\end{frame}

\end{document}


\section{\src{dyn_vert_adv_limiter}}
\label{dyn_vert_adv_limiter}

\subsection{Description}

Kernel \src{dyn_vert_adv_limiter} is taken from the original
subroutine \src{vertical_limiter_thuburn} in \NICAM.
%
This subroutine is originally defined in \src{mod_src_tracer}, that is
to contain several subroutines for tracer advection.
%
Subroutine \src{vertical_limiter_thuburn} is to ensure distribution of
tracer quantities' monotonicity in advection scheme, using the flux
limitter proposed by \cite{Thuburn:1996in}.
%
This subroutine is for vertical advection only and horizontal advection
is treated by other subroutine \src{horizontal_limiter_thuburn}, which
is also kernelized in this pacakage (See \autoref{dyn_horiz_adv_limiter}).
%
See section 4. in \cite{Tomita2010ecmwf} for details of the tracer scheme in \NICAM.

\subsection{Discretization and code}

Argument lists and local variables definition part of this subroutine is
as follows.

\begin{LstF90}[name=vertical_limiter_thuburn]
subroutine vertical_limiter_thuburn( &
     q_h, q_h_pl, &
     q,   q_pl,   &
     d,   d_pl,   &
     ck,  ck_pl   )
!ESC!    use mod_const, only: &
!ESC!       CONST_HUGE, &
!ESC!       CONST_EPS
!ESC!    use mod_adm, only: &
!ESC!       ADM_have_pl, &
!ESC!       ADM_gall,    &
!ESC!       ADM_gall_pl, &
!ESC!       ADM_lall,    &
!ESC!       ADM_lall_pl, &
!ESC!       ADM_kall,    &
!ESC!       ADM_kmin,    &
!ESC!       ADM_kmax
  implicit none

  real(RP), intent(inout) :: q_h   (ADM_gall   ,ADM_kall,ADM_lall   )
  real(RP), intent(inout) :: q_h_pl(ADM_gall_pl,ADM_kall,ADM_lall_pl)
  real(RP), intent(in)    :: q     (ADM_gall   ,ADM_kall,ADM_lall   )
  real(RP), intent(in)    :: q_pl  (ADM_gall_pl,ADM_kall,ADM_lall_pl)
  real(RP), intent(in)    :: d     (ADM_gall   ,ADM_kall,ADM_lall   )
  real(RP), intent(in)    :: d_pl  (ADM_gall_pl,ADM_kall,ADM_lall_pl)
  real(RP), intent(in)    :: ck    (ADM_gall   ,ADM_kall,ADM_lall   ,2)
  real(RP), intent(in)    :: ck_pl (ADM_gall_pl,ADM_kall,ADM_lall_pl,2)

  real(RP) :: Qout_min_k
  real(RP) :: Qout_max_k
  real(RP) :: Qout_min_km1(ADM_gall)
  real(RP) :: Qout_max_km1(ADM_gall)
  real(RP) :: Qout_min_pl(ADM_gall_pl,ADM_kall)
  real(RP) :: Qout_max_pl(ADM_gall_pl,ADM_kall)

  real(RP) :: Qin_minL, Qin_maxL
  real(RP) :: Qin_minU, Qin_maxU
  real(RP) :: qnext_min, qnext_max
  real(RP) :: Cin, Cout
  real(RP) :: CQin_min, CQin_max
  real(RP) :: inflagL, inflagU
  real(RP) :: zerosw

  integer  :: gall, kmin, kmax
  real(RP) :: EPS, BIG

  integer  :: g, k, l
  !---------------------------------------------------------------------------
\end{LstF90}
%
Here \src{q_h} is $q$ at half level of the vertical layer, which modified by the flux limiter.
%
\src{q} is $q$ at grid point,
\src{ck} is Courant number,
\src{d} is a correction factor derived from an artificial viscosity for the total density.
%
Note that \src{ck} has the 4th dimension whose size is 2, which specify
lower/upper face, i.e. half integer level.

The first section of the subroutine is as follows.

\begin{LstF90}[name=vertical_limiter_thuburn]
  call DEBUG_rapstart('____vertical_adv_limiter')

  gall = ADM_gall
  kmin = ADM_kmin
  kmax = ADM_kmax

  EPS  = CONST_EPS
  BIG  = CONST_HUGE

  do l = 1, ADM_lall
     !$omp parallel default(none), &
     !$omp private(g,k,zerosw,inflagL,inflagU,Qin_minL,Qin_minU,Qin_maxL,Qin_maxU, &
     !$omp         qnext_min,qnext_max,Cin,Cout,CQin_min,CQin_max,Qout_min_k,Qout_max_k),  &
     !$omp shared(l,gall,kmin,kmax,q_h,ck,q,d,Qout_min_km1,Qout_max_km1,EPS,BIG)

!OCL XFILL
       !$omp do
       do g = 1, gall
          k = kmin ! peeling

          inflagL = 0.5_RP - sign(0.5_RP,ck(g,k  ,l,1)) ! incoming flux: flag=1
          inflagU = 0.5_RP + sign(0.5_RP,ck(g,k+1,l,1)) ! incoming flux: flag=1

          Qin_minL = min( q(g,k,l), q(g,k-1,l) ) + ( 1.0_RP-inflagL ) * BIG
          Qin_minU = min( q(g,k,l), q(g,k+1,l) ) + ( 1.0_RP-inflagU ) * BIG
          Qin_maxL = max( q(g,k,l), q(g,k-1,l) ) - ( 1.0_RP-inflagL ) * BIG
          Qin_maxU = max( q(g,k,l), q(g,k+1,l) ) - ( 1.0_RP-inflagU ) * BIG

          qnext_min = min( Qin_minL, Qin_minU, q(g,k,l) )
          qnext_max = max( Qin_maxL, Qin_maxU, q(g,k,l) )

          Cin      = (        inflagL ) * ck(g,k,l,1) &
                   + (        inflagU ) * ck(g,k,l,2)
          Cout     = ( 1.0_RP-inflagL ) * ck(g,k,l,1) &
                   + ( 1.0_RP-inflagU ) * ck(g,k,l,2)

          CQin_min = (        inflagL ) * ck(g,k,l,1) * Qin_minL &
                   + (        inflagU ) * ck(g,k,l,2) * Qin_minU
          CQin_max = (        inflagL ) * ck(g,k,l,1) * Qin_maxL &
                   + (        inflagU ) * ck(g,k,l,2) * Qin_maxU

          zerosw = 0.5_RP - sign(0.5_RP,abs(Cout)-EPS) ! if Cout = 0, sw = 1

          Qout_min_k = ( ( q(g,k,l) - qnext_max ) + qnext_max*(Cin+Cout-d(g,k,l)) - CQin_max ) &
                     / ( Cout + zerosw ) * ( 1.0_RP - zerosw )                                 &
                     + q(g,k,l) * zerosw
          Qout_max_k = ( ( q(g,k,l) - qnext_min ) + qnext_min*(Cin+Cout-d(g,k,l)) - CQin_min ) &
                     / ( Cout + zerosw ) * ( 1.0_RP - zerosw )                                 &
                     + q(g,k,l) * zerosw

          Qout_min_km1(g) = Qout_min_k
          Qout_max_km1(g) = Qout_max_k
       enddo
       !$omp end do

       do k = kmin+1, kmax
!OCL XFILL
          !$omp do
          do g = 1, gall
             inflagL = 0.5_RP - sign(0.5_RP,ck(g,k  ,l,1)) ! incoming flux: flag=1
             inflagU = 0.5_RP + sign(0.5_RP,ck(g,k+1,l,1)) ! incoming flux: flag=1

             Qin_minL = min( q(g,k,l), q(g,k-1,l) ) + ( 1.0_RP-inflagL ) * BIG
             Qin_minU = min( q(g,k,l), q(g,k+1,l) ) + ( 1.0_RP-inflagU ) * BIG
             Qin_maxL = max( q(g,k,l), q(g,k-1,l) ) - ( 1.0_RP-inflagL ) * BIG
             Qin_maxU = max( q(g,k,l), q(g,k+1,l) ) - ( 1.0_RP-inflagU ) * BIG

             qnext_min = min( Qin_minL, Qin_minU, q(g,k,l) )
             qnext_max = max( Qin_maxL, Qin_maxU, q(g,k,l) )

             Cin      = (        inflagL ) * ck(g,k,l,1) &
                      + (        inflagU ) * ck(g,k,l,2)
             Cout     = ( 1.0_RP-inflagL ) * ck(g,k,l,1) &
                      + ( 1.0_RP-inflagU ) * ck(g,k,l,2)

             CQin_min = (        inflagL ) * ck(g,k,l,1) * Qin_minL &
                      + (        inflagU ) * ck(g,k,l,2) * Qin_minU
             CQin_max = (        inflagL ) * ck(g,k,l,1) * Qin_maxL &
                      + (        inflagU ) * ck(g,k,l,2) * Qin_maxU

             zerosw = 0.5_RP - sign(0.5_RP,abs(Cout)-EPS) ! if Cout = 0, sw = 1

             Qout_min_k = ( ( q(g,k,l) - qnext_max ) + qnext_max*(Cin+Cout-d(g,k,l)) - CQin_max ) &
                        / ( Cout + zerosw ) * ( 1.0_RP - zerosw )                                 &
                        + q(g,k,l) * zerosw
             Qout_max_k = ( ( q(g,k,l) - qnext_min ) + qnext_min*(Cin+Cout-d(g,k,l)) - CQin_min ) &
                        / ( Cout + zerosw ) * ( 1.0_RP - zerosw )                                 &
                        + q(g,k,l) * zerosw

             q_h(g,k,l) = (        inflagL ) * max( min( q_h(g,k,l), Qout_max_km1(g) ), Qout_min_km1(g) ) &
                        + ( 1.0_RP-inflagL ) * max( min( q_h(g,k,l), Qout_max_k      ), Qout_min_k      )

             Qout_min_km1(g) = Qout_min_k
             Qout_max_km1(g) = Qout_max_k
          enddo
          !$omp end do
       enddo

     !$omp end parallel
  enddo

\end{LstF90}
%
In the long $l$-loop, there seems to be two blocks, but they are almost
the same, except that the first one is only for \src{kmin}, that is the
lowest level, and the second one is the rest of \src{k} to the top level.
%
\src{inflagL} and \src{inflagU} are flag that takes the value $1$ if there is an
incoming flux to the current layer through the lower/upper face.
%
\src{Qin_*} are the smaller/larger values of $q$ at lower/upper
neighboring layer, that is meaningful only if inflag at lower/upper is $1$.
%
\src{Cin} and \src{Cout} are the sum of Courant number at both face of
the layer, for example, \src{Cin} is the sum of \src{ck} at lower face
and upper face, if both of \src{inflagL} and \src{inflagU} is $1$, which
means that there are inflow through both lower/upper face.
%
\src{CQin_*} are the min/max of \src{Cin} times \src{Qin_*}, which
specify the minimun/maximum of inflow.
%
Then \src{CQout_*} are calculated.
%
Finaly \src{q_h} is calculated, which is bounded by \src{Qout_*}.

The second section of this subroutine is as follows.

\begin{LstF90}[name=vertical_limiter_thuburn]
  if ( ADM_have_pl ) then
     do l = 1, ADM_lall_pl

        do k = ADM_kmin, ADM_kmax
          do g = 1, ADM_gall_pl
             inflagL = 0.5_RP - sign(0.5_RP,ck_pl(g,k  ,l,1)) ! incoming flux: flag=1
             inflagU = 0.5_RP + sign(0.5_RP,ck_pl(g,k+1,l,1)) ! incoming flux: flag=1

             Qin_minL = min( q_pl(g,k,l), q_pl(g,k-1,l) ) + ( 1.0_RP-inflagL ) * BIG
             Qin_minU = min( q_pl(g,k,l), q_pl(g,k+1,l) ) + ( 1.0_RP-inflagU ) * BIG
             Qin_maxL = max( q_pl(g,k,l), q_pl(g,k-1,l) ) - ( 1.0_RP-inflagL ) * BIG
             Qin_maxU = max( q_pl(g,k,l), q_pl(g,k+1,l) ) - ( 1.0_RP-inflagU ) * BIG

             qnext_min = min( Qin_minL, Qin_minU, q_pl(g,k,l) )
             qnext_max = max( Qin_maxL, Qin_maxU, q_pl(g,k,l) )

             Cin      = (        inflagL ) * ( ck_pl(g,k,l,1) ) &
                      + (        inflagU ) * ( ck_pl(g,k,l,2) )
             Cout     = ( 1.0_RP-inflagL ) * ( ck_pl(g,k,l,1) ) &
                      + ( 1.0_RP-inflagU ) * ( ck_pl(g,k,l,2) )

             CQin_max = (        inflagL ) * ( ck_pl(g,k,l,1) * Qin_maxL ) &
                      + (        inflagU ) * ( ck_pl(g,k,l,2) * Qin_maxU )
             CQin_min = (        inflagL ) * ( ck_pl(g,k,l,1) * Qin_minL ) &
                      + (        inflagU ) * ( ck_pl(g,k,l,2) * Qin_minU )

             zerosw = 0.5_RP - sign(0.5_RP,abs(Cout)-EPS) ! if Cout = 0, sw = 1

             Qout_min_pl(g,k) = ( ( q_pl(g,k,l) - qnext_max ) + qnext_max*(Cin+Cout-d_pl(g,k,l)) - CQin_max ) &
                              / ( Cout + zerosw ) * ( 1.0_RP - zerosw )                                       &
                              + q_pl(g,k,l) * zerosw
             Qout_max_pl(g,k) = ( ( q_pl(g,k,l) - qnext_min ) + qnext_min*(Cin+Cout-d_pl(g,k,l)) - CQin_min ) &
                              / ( Cout + zerosw ) * ( 1.0_RP - zerosw )                                       &
                              + q_pl(g,k,l) * zerosw
          enddo
          enddo

        do k = ADM_kmin+1, ADM_kmax
        do g = 1, ADM_gall_pl
           inflagL = 0.5_RP - sign(0.5_RP,ck_pl(g,k,l,1)) ! incoming flux: flag=1

           q_h_pl(g,k,l) = (        inflagL ) * max( min( q_h_pl(g,k,l), Qout_max_pl(g,k-1) ), Qout_min_pl(g,k-1) ) &
                         + ( 1.0_RP-inflagL ) * max( min( q_h_pl(g,k,l), Qout_max_pl(g,k  ) ), Qout_min_pl(g,k  ) )
        enddo
        enddo

     enddo
  endif

  call DEBUG_rapend  ('____vertical_adv_limiter')

  return
end subroutine vertical_limiter_thuburn
\end{LstF90}
%
This section is for the pole region, and doing almost the same procedure
with the regular region.

\subsection{Input data and result}

Max/min/sum of input/output data of the kernel subroutine are output as
a log.
%
Below is an example of \src{$IAB_SYS=Ubuntu-gnu-ompi} case.

\begin{LstLog}
 ### Input ###
 +check[q_h_prev        ] max=  7.2663804548391786E+00,min=  0.0000000000000000E+00,sum=  2.4959084727640115E+06
 +check[q_h_prev_pl     ] max=  6.4080655438269076E+00,min=  0.0000000000000000E+00,sum=  1.8117616747458535E+03
 +check[check_q_h       ] max=  7.3763287914601054E+00,min=  0.0000000000000000E+00,sum=  2.4996023860691669E+06
 +check[check_q_h_pl    ] max=  7.0217121722230473E+00,min=  0.0000000000000000E+00,sum=  1.8122948877569047E+03
 +check[q               ] max=  7.3763287914601054E+00,min=  0.0000000000000000E+00,sum=  2.4959084727641600E+06
 +check[q_pl            ] max=  7.0217121722230473E+00,min=  0.0000000000000000E+00,sum=  1.8117616747458526E+03
 +check[d               ] max= -0.0000000000000000E+00,min= -0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[d_pl            ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[ck              ] max=  3.1666977358687308E-02,min= -3.3842023700197510E-02,sum= -3.3888707532669278E+00
 +check[ck_pl           ] max=  2.8817336749971920E-02,min= -3.0878557008837175E-02,sum= -2.9483051886829596E-02
 ### Output ###
 +check[q_h             ] max=  7.3763287914601054E+00,min=  0.0000000000000000E+00,sum=  2.4996023860691669E+06
 +check[q_h_pl          ] max=  7.0217121722230473E+00,min=  0.0000000000000000E+00,sum=  1.8122948877569047E+03
 ### Validation : point-by-point diff ###
 +check[check_q_h       ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[check_q_h_pl    ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 *** Finish kernel
\end{LstLog}

Check the lines below \src{``Validation : point-by-point diff''} line,
that shows difference between calculated output array and
pre-calculated reference array.
These should be zero or enough small to be acceptable.

There are sample output log files in \file{reference/}
in each kernel program directory, for reference purpose.

\subsection{Sample of perfomance result}

Here's an example of the performance result part of the log output.
Below is an example executed with the machine environment described in \autoref{s:measuring_env}.
%
Note that in this program kernel part is iterated one time.

\begin{LstLog}
 *** Computational Time Report
 *** ID=001 : MAIN_dyn_vert_adv_limiter        T=     0.032 N=      1
 *** ID=002 : ____vertical_adv_limiter         T=     0.032 N=      1
\end{LstLog}


\documentclass{article} % For LaTeX2e
\usepackage{format/nips13submit_e}
\nipsfinalcopy % Uncomment for camera-ready version
\usepackage{times}
\usepackage{hyperref}
\usepackage{url}
\usepackage{color}
\definecolor{mydarkblue}{rgb}{0,0.08,0.45}
\hypersetup{
    pdfpagemode=UseNone,
    colorlinks=true,
    linkcolor=mydarkblue,
    citecolor=mydarkblue,
    filecolor=mydarkblue,
    urlcolor=mydarkblue,
    pdfview=FitH}

\usepackage{graphicx, amsmath, amsfonts, bm, lipsum, capt-of}

\usepackage{natbib, xcolor, wrapfig, booktabs, multirow, caption}

\usepackage{float}

\def\ie{i.e.\ }
\def\eg{e.g.\ }

\title{An automatic report for the dataset : 01-airline}

\author{
James Robert Lloyd\\
University of Cambridge\\
Department of Engineering\\
\texttt{jrl44@cam.ac.uk}
\And
David Duvenaud\\
University of Cambridge \\
Department of Engineering \\
\texttt{dkd23@cam.ac.uk}
\And
Roger Grosse\\
M.I.T.\\
Brain and Cognitive Sciences \\
\texttt{rgrosse@mit.edu}
\And
Joshua B. Tenenbaum\\
M.I.T.\\
Brain and Cognitive Sciences \\
\texttt{jbt@mit.edu}
\And
Zoubin Ghahramani\\
University of Cambridge \\
Department of Engineering \\
\texttt{zoubin@eng.cam.ac.uk}
}

\newcommand{\fix}{\marginpar{FIX}}
\newcommand{\new}{\marginpar{NEW}}

\setlength{\marginparwidth}{0.9in}
\input{include/commenting.tex}

%% For submission, make all render blank.
%\renewcommand{\LATER}[1]{}
%\renewcommand{\fLATER}[1]{}
%\renewcommand{\TBD}[1]{}
%\renewcommand{\fTBD}[1]{}
%\renewcommand{\PROBLEM}[1]{}
%\renewcommand{\fPROBLEM}[1]{}
%\renewcommand{\NA}[1]{#1}  % Note, NA's pass through!

\begin{document}

\allowdisplaybreaks

\maketitle

\begin{abstract}
This report was produced automatically by the Gaussian process structure search algorithm.
See \url{http://arxiv.org/abs/1302.4922} for a preliminary paper and see \url{https://github.com/jamesrobertlloyd/gpss-research} for the latest source code.
\end{abstract}

\section{Executive summary}

The raw data and full model posterior with extrapolations are shown in figure~\ref{fig:rawandfit}.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_raw_data} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_all}
\end{tabular}
\caption{Raw data (left) and model posterior with extrapolation (right)}
\label{fig:rawandfit}
\end{figure}

The structure search algorithm has identified four additive components in the data.
The  first 2 additive components explain 99.3\% of the variation in the data as shown by the coefficient of determination ($R^2$) values in table~\ref{table:stats}.
After the first 3 components the cross validated mean absolute error (MAE) does not decrease by more than 0.1\%.
This suggests that subsequent terms are modelling very short term trends, uncorrelated noise or are artefacts of the model or search procedure.
Short summaries of the additive components are as follows:
\begin{itemize}

  \item \input{figures/01-airline/01-airline_1_short_description.tex}

  \item \input{figures/01-airline/01-airline_2_short_description.tex}

  \item \input{figures/01-airline/01-airline_3_short_description.tex}

  \item \input{figures/01-airline/01-airline_4_short_description.tex}

\end{itemize}

\begin{table}[htb]
\begin{center}
{\small
\begin{tabular}{|r|rrrrr|}
\hline
\bf{\#} & {$R^2$ (\%)} & {$\Delta R^2$ (\%)} & {Residual $R^2$ (\%)} & {Cross validated MAE} & Reduction in MAE (\%)\\
\hline
- & - & - & - & 280.30 & -\\

1 & 86.2 & 86.2 & 86.2 & 32.42 & 88.4\\

2 & 99.3 & 13.1 & 95.1 & 9.57 & 70.5\\

3 & 99.8 & 0.5 & 68.1 & 7.54 & 21.2\\

4 & 100.0 & 0.2 & 100.0 & 7.54 & 0.0\\

\hline
\end{tabular}
\caption{
Summary statistics for cumulative additive fits to the data.
The residual coefficient of determination ($R^2$) values are computed using the residuals from the previous fit as the target values; this measures how much of the residual variance is explained by each new component.
The mean absolute error (MAE) is calculated using 10 fold cross validation with a contiguous block design; this measures the ability of the model to interpolate and extrapolate over moderate distances.
The model is fit using the full data so the MAE values cannot be used reliably as an estimate of out-of-sample predictive performance.
}
\label{table:stats}
}
\end{center}
\end{table}

\section{Detailed discussion of additive components}

\subsection{Component 1 : A very smooth monotonically increasing function}

\input{figures/01-airline/01-airline_1_description.tex}

This component explains 86.2\% of the total variance.
The addition of this component reduces the cross validated MAE by 88.4\% from 280.3 to 32.4.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_1} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_1_cum}
\end{tabular}
\caption{Posterior of component 1 (left) and the posterior of the cumulative sum of components with data (right)}
\label{fig:comp1}
\end{figure}

\subsection{Component 2 : An approximately periodic function with a period of 1.0 years and with approximately linearly increasing amplitude}

\input{figures/01-airline/01-airline_2_description.tex}

This component explains 95.1\% of the residual variance; this increases the total variance explained from 86.2\% to 99.3\%.
The addition of this component reduces the cross validated MAE by 70.47\% from 32.42 to 9.57.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_2} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_2_cum}
\end{tabular}
\caption{Posterior of component 2 (left) and the posterior of the cumulative sum of components with data (right)}
\label{fig:comp2}
\end{figure}

\subsection{Component 3 : A smooth function}

\input{figures/01-airline/01-airline_3_description.tex}

This component explains 68.1\% of the residual variance; this increases the total variance explained from 99.3\% to 99.8\%.
The addition of this component reduces the cross validated MAE by 21.22\% from 9.57 to 7.54.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_3} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_3_cum}
\end{tabular}
\caption{Posterior of component 3 (left) and the posterior of the cumulative sum of components with data (right)}
\label{fig:comp3}
\end{figure}

\subsection{Component 4 : Uncorrelated noise with linearly increasing standard deviation}

\input{figures/01-airline/01-airline_4_description.tex}

This component explains 100.0\% of the residual variance; this increases the total variance explained from 99.8\% to 100.0\%.
The addition of this component reduces the cross validated MAE by 0.00\% from 7.54 to 7.54.
This component explains residual variance but does not improve MAE which suggests that this component describes very short term patterns, uncorrelated noise or is an artefact of the model or search procedure.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_4} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_4_cum}
\end{tabular}
\caption{Posterior of component 4 (left) and the posterior of the cumulative sum of components with data (right)}
\label{fig:comp4}
\end{figure}

\section{Extrapolation}

Summaries of the posterior distribution of the full model are shown in figure~\ref{fig:extrap}.
The plot on the left displays the mean of the posterior together with pointwise variance.
The plot on the right displays three random samples from the posterior.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_all} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_all_sample}
\end{tabular}
\caption{Full model posterior. Mean and pointwise variance (left) and three random samples (right)}
\label{fig:extrap}
\end{figure}

\subsection{Component 1 : A very smooth monotonically increasing function}

Some discussion about extrapolation.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_1_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_1_sample} \\
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_1_cum_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_1_cum_sample}
\end{tabular}
\caption{Posterior of component 1. Mean and pointwise variance (left) and three random samples from this distribution (right)}
\label{fig:extrap1}
\end{figure}

\subsection{Component 2 : An approximately periodic function with a period of 1.0 years and with approximately linearly increasing amplitude}

Some discussion about extrapolation.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_2_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_2_sample} \\
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_2_cum_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_2_cum_sample}
\end{tabular}
\caption{Posterior of component 2. Mean and pointwise variance (left) and three random samples from this distribution (right)}
\label{fig:extrap2}
\end{figure}

\subsection{Component 3 : A smooth function}

Some discussion about extrapolation.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_3_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_3_sample} \\
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_3_cum_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_3_cum_sample}
\end{tabular}
\caption{Posterior of component 3. Mean and pointwise variance (left) and three random samples from this distribution (right)}
\label{fig:extrap3}
\end{figure}

\subsection{Component 4 : Uncorrelated noise with linearly increasing standard deviation}

Some discussion about extrapolation.

\begin{figure}[H]
\newcommand{\wmgd}{0.5\columnwidth}
\newcommand{\hmgd}{3.0cm}
\newcommand{\mdrd}{figures/01-airline}
\newcommand{\mbm}{\hspace{-0.3cm}}
\begin{tabular}{cc}
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_4_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_4_sample} \\
\mbm \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_4_cum_extrap} & \includegraphics[width=\wmgd,height=\hmgd]{\mdrd/01-airline_4_cum_sample}
\end{tabular}
\caption{Posterior of component 4. Mean and pointwise variance (left) and three random samples from this distribution (right)}
\label{fig:extrap4}
\end{figure}

\end{document}


\chapter{Case Study}
\label{case_study}
\thispagestyle{empty}

In this chapter we focus on our research goal \textbf{RG1.2} as defined in section \ref{research_goals}. In the previous chapter we had worked with synthetic networks and after having conducted several experiments with them with various parameters we wish to now analyze the bias in recommendations for some empirical networks. We start the chapter by talking about the empirical data we wish to use in our thesis and how we process it and set it up for our experiment. We also list down names and few of the network properties for each of the datasets which we use. In the next section we look at the results of our experiment on each of these datasets individually. We primarily analyze the disparate visibility bias for each of the chosen datasets.

\section{Setup}

We work on the \textbf{Facebook100} \cite{traud2012social} dataset published by Traud et. al. in 2011. This huge dataset contains snapshots of Facebook \textit{`friendship networks'} for 100 universities across the United States of America. We choose 4 datasets among the 100 for our thesis and use our recommendation methods on them to receive the recommended nodes list on which we carry out the disparate visibility analysis as we had done previously for \textit{static networks} in section \ref{static_networks}.

\subsection{Dataset overview}

Table \ref{table_facebook_datadet} gives an overview of the networks we choose from the \textbf{Facebook100} dataset to carry out our experiments. The \textbf{NetworkID} is the same as used to identify individual networks in the original dataset. We choose \textit{gender} as the node attribute to distinguish nodes belonging to the \textit{minority} or \textit{majority} group. The \textbf{Minority} column in the table shows the gender representing the minority group in each network. The fraction of nodes which belong to the minority group is given as $f$. We estimate the homophily value for each group using the method outlined by Karimi et. al. \cite{karimi2018homophily}. The minority and majority homophily values are given as $h_{minority}$ and $h_{majority}$ respectively. As we had mentioned earlier in \ref{back_networks}, real-world networks exhibit asymmetric homophily, which we can observe here for the chosen empirical networks. All values for $f$, $h_{minority}$ and $h_{majority}$ have been rounded off to 2 decimal places for our experiments.

\begin{table}[h]
	\centering
	\begin{tabular}{ |c|c|c|c|c|c|c| }
		\hline
		\textbf{Network ID} & \textbf{Total nodes} & \textbf{Total edges} & \textbf{Minority} & \textbf{$f$} & \textbf{$h_{minority}$} & \textbf{$h_{majority}$} \\
		\hline
		Caltech36 & 703 & 15464 & female & 0.32 & 0.75 & 0.6 \\
		Reed98 & 865 & 15948 & male & 0.42 & 0.73 & 0.7 \\
		%Haverford76 & 1350 & 53904 & male & 0.46 & 0.73 & 0.82 \\
		Simmons81 & 1422 & 30486 & male & 0.01 & 0.47 & 0.87 \\
		Swarthmore42 & 1521 & 53726 & male & 0.49 & 0.72 & 0.78 \\
		\hline
	\end{tabular}
	\caption{Details of chosen empirical networks from \textbf{Facebook100} dataset}
	\label{table_facebook_datadet}
\end{table}

We parse the original dataset, which is provided as a sparse matrix to form our own network adjacency matrices. For each network multiple nodes are found to not possess the \textit{gender} information. We choose to discard such nodes and the edges they form from our final network.

\subsection{Experimental Setup}

For each of the networks $G(V,E)$ chosen by us (as listed in table \ref{table_facebook_datadet}) we use the \textit{Topological} and \textit{Reinforcement} recommender methods (as detailed in chapter \ref{recommender_methods}) to get a recommendation list $L_{v}$ for each node $v \in V$.

Once we have received this recommendation list, we measure the Disparate visibility \cite{fabbri2020effect} for the recommendations (similar to what we did in section \ref{static_networks}).

\section{Results}

\subsection{Caltech36}

For the network \textbf{Caltech36} \textit{females} form the minority group with 32\% of the nodes belonging to this group. The minority group has a homophily value of 0.75 which is slightly higher than the majority group homophily value of 0.6.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dd_caltech.png}
	\caption{Degree distribution for \textbf{Caltech36}}
	\label{dd_caltech}
\end{SCfigure}

Looking at the degree distribution plot (figure \ref{dd_caltech}) we can see that both majority and minority nodes hold quite high degrees. Since both the groups are homophilic in nature with minority being more homophilic, this kind of distribution can be expected for the minority fraction of 0.3.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dv_caltech.png}
	\caption{Disparate Visibility for \textbf{Caltech36}. Black dotted lines represent the range for the disparate visibility measure given the minority fraction and the solid black line shows the equal visibility mark at 0.}
	\label{dv_caltech}
\end{SCfigure}

Upon using our recommender methods, we find that the disparate visibility (figure \ref{dv_caltech}) is positive, which means that the minority nodes are more visible in recommendations than majorities. This result holds for all recommender methods used. The range of disparate visibility measure for this network lies between [-1.48, 3.08].

In our earlier experiments with measuring disparate visibility for static networks in section \ref{static_dv} we had assumed that for a homophilic regime the networks would have higher visibility for majorities. However, here we see that at the homophilic regime minorities are more visible. We however did not have information for the disparate visibility measure at homophily values of $h=0.6$ or $h=0.7$. Thus we might have missed information in our experiments which we can observe in this case.

For the \textbf{PA-Homophily} method we can deduce that minorities are more visible owing to only slightly high homophily value for majorities and a greater homophily among minorities. This would mean that for both type of nodes there is a higher chance of having minorities as node recommendations. This is also seen in the \textbf{reinforcement methods}. In the case of \textbf{Top-Rank} we see much more visibility for minorities at $r=0.0$ and $r=0.5$, but this visibility decreases from others in the case of $r=1.0$. Here we see that the ranking factor actually has a much more sever effect than what we had observed previously in our experiments with static networks. What we can deduce is that since both minority and majority nodes have higher degrees and they both have only slightly varying homophily, the ranking factor in this case plays a major role in boosting the probability for nodes in \textit{click model}. Lesser visibility for minorities would however mean that the Top-Rank method has a higher mix of majority and minority nodes at upper precedence partitions. This is what causes the minority visibility to drop.

\subsection{Reed98}

For the network \textbf{Reed98}, \textit{males} form the minority group with 42\% of the nodes belonging to this group. The minority group has a homophily value of 0.73 which is very close to the majority group homophily value of 0.7, thus having almost symmetric homophily in this network.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dd_reed.png}
	\caption{Degree distribution for \textbf{Reed98}}
	\label{dd_reed}
\end{SCfigure}

Looking at the degree distribution plot (figure \ref{dd_reed}) we can see that both the majority and minority nodes hold high degrees. Since the network is moderately homophilic, with the minority group size quite high this can be expected with both groups supporting themselves.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dv_reed.png}
	\caption{Disparate Visibility for \textbf{Reed98}. Black dotted lines represent the range for the disparate visibility measure given the minority fraction and the solid black line shows the equal visibility mark at 0.}
	\label{dv_reed}
\end{SCfigure}

From the disparate visibility plot (figure \ref{dv_reed}), upon using our recommender methods on the network, we find that visibility for both groups borders the equal visibility mark.

We had seen almost equal visibility for a minority size of $f=0.4$ in our synthetic network experiments too. The results corroborate with our findings for this network.

The range for disparate visibility measure for this network lies between [-1.72, 2.4]. Most values are slightly positive which shows that the minority group is at a very slight advantage, but this is very negligible ($\leq 5\%$). The \textbf{Top-Rank} method at $r=1.0$ however shows opposite behavior than the rest, putting majorities as more visible. The behavior which we had seen earlier in the case of \textbf{Caltech36} is thus seen here too for Top-Rank(r=1.0).

\subsection{Simmons81}

For the network \textbf{Simmons81}, \textit{males} form the minority group with only 1\% of the nodes belonging to this group. The minority group has a homophily value of 0.47 while the majority group has a homophily value of 0.87. This is a group with a very less minority who connects in an almost group-agnostic way while the majority has strong homophilic tendencies. So while the majority nodes have strong in-group support they also get connections from the minorities.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dd_simmons.png}
	\caption{Degree distribution for \textbf{Simmons81}}
	\label{dd_simmons}
\end{SCfigure}

Looking at the degree distribution plot (figure \ref{dd_simmons}) we see that the majority nodes hold much higher degrees compared to the minority as we could expect looking at the homophily values. While a fair amount of majority nodes have degrees above 100, the maximum degree a minority node holds is far less than 100. This shows that majority nodes are much more well-connected than minorities.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dv_simmons.png}
	\caption{Disparate Visibility for \textbf{Simmons81}. Black dotted lines represent the range for the disparate visibility measure given the minority fraction and the solid black line shows the equal visibility mark at 0.}
	\label{dv_simmons}
\end{SCfigure}

From the disparate visibility plot (figure \ref{dv_simmons}), upon using our recommender methods on the nodes in the network, we find that visibility is higher for majority nodes. The range of disparate visibility measure for this network lies in the range of [-1.01, 83.65].

Since the majorities have high homophily and the minorities have almost neutral homophily, the majorities would be winning in the recommendations game in the \textbf{PA-Homophily} and subsequently the \textbf{reinforcement methods} cases. For both the majority and minority nodes there would be more majority nodes which would be suggested. Also since the minorities are so few in number most of them would already be connected with other minorities thus further increasing chances of majorities to be recommended. If the minority group size was higher we would probably see a higher minority visibility for our network.

\subsection{Swarthmore42}

For the network \textbf{Swarthmore42}, \textit{males} barely form the minority group with 49\% of the nodes belonging to this group. The minority group has a homophily value of 0.72 while the majority group has a homophily value of 0.78. This is a network with equal node-group sizes exhibiting almost symmetric homophilic behavior.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dd_swarthmore.png}
	\caption{Degree distribution for \textbf{Swarthmore42}}
	\label{dd_swarthmore}
\end{SCfigure}

Looking at the degree distribution plot (figure \ref{dd_swarthmore}) we see that both majority and minority nodes have an almost equal distribution. The plot however does not strictly demonstrate the properties of a scale-free network as in there are lower degree nodes with lower probability also present in the network. The number of edges in this network is also quite high which would mean that there the nodes are well connected with a higher average degree.

\begin{SCfigure}[1][h!]
	\centering
	\includegraphics[trim=0 10 0 10, clip, width=0.75\textwidth]{images/dv_swarthmore.png}
	\caption{Disparate Visibility for \textbf{Swarthmore42}. Black dotted lines represent the range for the disparate visibility measure given the minority fraction and the solid black line shows the equal visibility mark at 0.}
	\label{dv_swarthmore}
\end{SCfigure}

From the disparate visibility plot (figure \ref{dv_swarthmore}), upon using our recommender methods on the network, we find that visibility for most cases is only negligibly higher for majority nodes. This suggests that the recommendations are quite balanced for both groups as we could have expected for a equal group size. The range of disparate visibility measure for this network lies between [-1.97, 2.03].

For the case of \textbf{Adamic-Adar} we see that the minority seems to have higher visibility than what is projected by the other methods. As we know that the Adamic-Adar method is completely structure dependent this could mean the network structure favors minorities in certain way. However this difference is very negligible to make a concrete comment on why this happens.

\section{Summary}

Using the various recommendation methods $R$ as we had defined in chapter \ref{recommender_methods} we carry out our experiment on empirical networks to get recommendations for each node in the networks. We use selected network from the \textbf{Facebook100} dataset to measure the disparate visibility found in the recommendations.

From our experiments we only see the \textbf{Caltech36} network give a higher visibility score in favor of minorities. The other networks either have an almost equal group-size or have a very small minority size which puts them close to the equal visibility measure.

In \textbf{Caltech36} we see that minorities are more visible which is different from what we were expecting from our experiments on synthetic networks. This clearly points to a limitation of our work since we do not know the disparate visibility behavior in the in-between homophily cases. Our consideration of homophily values for experiments is limited and the behavior in more such cases is something worth exploring in the future.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Sébastien Gardoll copyright all rights reserved %
% email: sebastien@gardoll.fr                             %
% LaTeX Project Public License 1.3c                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Title of the chapter}
\label{chap:title_of_the_chapter}
Some preambule.

\section{Text emphasis}

\textbf{bold text}
\textit{italicied text}
\underline{underlined text}
\emph{emphasising text}

\section{Itemize example}

\begin{itemize}
\item {Item1: \lipsum[1]}
\item {Item2}
\item {Item3}
\end{itemize}
\begin{itemize}
\item {carriaged return item:}
\end{itemize}
\lipsum[1]

\section{Section}

\lipsum[1]
\lipsum[2]

\subsection{Subsection}

\lipsum[1]

\subsubsection{Subsubsection}

\lipsum[1-2]

\section{Image inclusions}

\ref{fig:pic1.png} is an example of a full width page inclusion
of a picture (aspect ratio is kept):

\includeimg{1}{pic1.png}{The caption of the picture.}

\ref{fig:pic2.png} is an example of a scaled down picture:

\includeimg{0.5}{pic2.png}{The caption of the picture.}

\ref{fig:pic3.png} is an example of a rotated picture:

\includeimgsideways{0.5}{pic3.png}{The rotated caption of the picture.}

\section{Citations}

According to \cite{inbook-full}...
This is a footnote citation\footfullcite{incollection-minimal}.

\section{Some fancy maths}

\[\textit{MSE}=E(Y-\hat{Y})^2=\underbrace{\left[F(X)-\hat{F}(X)\right]^2}_{\text{reductible}} + \underbrace{\textit{Var}(\varepsilon)}_{\text{irréductible}}\]

\[d=\left\{
        \begin{array}{l}
        1\ si\ A>\alpha \\
        0\ si\ A\leqslant\alpha
        \end{array}
        \right.
      \]

\[d(x_1,\ x_2)=\sqrt{\ \sum_{j=1}^n\frac{1}{f_n}(f_{1j}-f_{2j})^2}\]

\begin{theo}[Morgan's Law]
\[\overline{P \wedge Q} \Leftrightarrow \bar{P} \vee \bar{Q}\]
\[\overline{P \vee Q} \Leftrightarrow \bar{P} \wedge \bar{Q}\]
\end{theo}

\section{Tables}

From the CTABLE man (link \href{https://ctan.org/pkg/ctable}{here}):

\ctable[
cap     = The Skewing Angles,
caption = The Skewing Angles ($\beta$) for
$\fam0 Mu(H)+X_2$ and $\fam0 Mu(H)+HX$~\tmark,
label   = nowidth,
pos     = h
]{rlcc}{
\tnote{for the abstraction reaction,
$\fam0 Mu+HX \rightarrow MuH+X$.}
\tnote[b]{1 degree${} = \pi/180$ radians.}
\tnote[c]{this is a particularly long note, showing that
footnotes are set in raggedright mode as we don’t like
hyphenation in table footnotes.}
}{                                                          \FL
&            & $\fam0 H(Mu)+F_2$     & $\fam0 H(Mu)+Cl_2$ \ML
&$\beta$(H)  & $80.9^\circ$\tmark[b] & $83.2^\circ$       \NN
&$\beta$(Mu) & $86.7^\circ$          & $87.7^\circ$       \LL
}