\documentclass[11pt,a4paper]{article}
\usepackage[xetex]{hyperref}
\usepackage{mathtools,latexsym,amsfonts,amssymb,MnSymbol}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{ccicons}
\hypersetup{colorlinks=true}
\pagestyle{fancy}

\fancyhf{}
\cfoot{\thepage}
\rfoot{\ccby}
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.0pt}

\newcommand{\key}[1]{\textrm{\textbf{#1}}}
\newcommand{\nbkey}[1]{\textrm{#1}}
\newcommand{\record}[1]{\{\!\!\shortmid #1 \shortmid\!\!\}}
\newcommand{\overld}[3]{\largecircle^{#1}_{#2}{#3}}
\newcommand{\irecrd}[2]{\largesquare^{#1}{#2}}
\newcommand{\tyvarsubst}[2]{#1\ \hspace{-0.2ex}:\hspace{1pt}=\ #2}
\newcommand{\ovldrefine}[2]{#1\ \circ\hspace{-0.3ex}=\ #2}
\newcommand{\irecextend}[2]{#1\ \smallsquare\hspace{-0.3ex}=\ #2}
\newcommand{\lab}{\nbkey{lab}}
\newcommand{\rigdvar}[1]{\ddot{#1}}
\newcommand{\flexvar}[1]{\tilde#1}

\newcommand{\comment}[1]{\textit{\color{olive}#1}}
\newcommand{\ifclause}[1]{\textit{if}\hspace{1.5ex}#1}
\newcommand{\whereclause}[1]{\textit{where}\hspace{1.5ex}#1}

\newcommand{\unify}[3]{#1\,{\color{brown}{\simeq}}\,#2 \Rightarrow #3}
\newcommand{\subst}[2]{[#1]\,#2}
\newcommand{\braced}[1]{\{#1\}}

\newcommand{\compose}[2]{#1 \circ #2}

\newcommand{\tycon}{\mathbb{C}}
\newcommand{\tyfun}{\zeta}
\newcommand{\type}{\tau}
\newcommand{\qualtype}[2]{#1 \triangleright #2}
\newcommand{\scheme}{\delta}
\newcommand{\substitute}{\rho}
\newcommand{\equality}{\epsilon}
\newcommand{\eqyes}{\equiv}
\newcommand{\eqnot}{\nequiv}

\newcommand{\wildcard}{{\color{gray}\scriptstyle\textbf{*}}}
\newcommand{\vect}[1]{\overline{#1}}

\begin{document}

\title {A pure specification of MLton - Part 1. types}
\author{Wu Jiasen $\langle$\href{mailto:wujiasen@yahoo.com}{wujiasen@yahoo.com}$\rangle$}
\maketitle
\thispagestyle{fancy}

\section{Type in Standard ML}
\newcommand{\q}     {\textrm{'}}
\newcommand{\Env}   {\textrm{E}}
\newcommand{\vdashT}{\ \vdash_{\textrm{\tiny T}}\  }
\newcommand{\inTE}  {\ \in^{\textrm{\tiny TE}}\  }
\[\begin{array}{lcll}
type & = & \q a                                             & \\
     & | & \q\q a                                           & \\
     & | & tycon\ \vect{type}              	            	&\comment{constructor}\\
     & | & \braced{\vect{\lab:type}}       		        	&\comment{record type}\\
\end{array}\]

\section{Type in Core-Lang}
{\renewcommand{\arraystretch}{1.2}\[
\begin{array}{lcll}
\type
     & = & \alpha                                           & \\
     & | & \tycon\ \vect\type              	            	&\comment{constructor}\\
     & | & \record{\vect{\lab:\type}}       		    		&\comment{record type}\\
     & | & \irecrd{\alpha}{[\vect{\lab:\type}]}         		&\comment{incomplete record type}\\
     & | & \overld{\alpha}{\type}{[\vect\scheme]}     		&\comment{overloading type}\\
\alpha
     & = & \rigdvar{\alpha}^{\equality}                     &\comment{rigid type variable}\\
     & | & \flexvar{\alpha}                                 &\comment{flexible type variable}\\
\\
\qualtype{\vect\type_1}{\type_2} & &                        &\comment{qualified type} \\
                            & &                             &\comment{$\vect\type_1$ are types that must admit equality} \\
\\
\scheme
     & = & \forall \vect{\alpha}\,.\,\qualtype{\vect\type_1}{\type_2}
                                                            &\\
\\
\equality
	& = & \eqyes	& \comment{admitting equality}     \\
	& | & \eqnot	& \comment{not admitting equality} \\
\\
\substitute
     & = & \tyvarsubst{\alpha}{\type}                   	&\comment{substitute a tyvar}\\
     & | & \irecextend{\alpha}{[\lab:\type]}	     	    &\comment{extend an incomplete record}\\
     & | & \ovldrefine{\alpha}{[\scheme]}               	&\comment{refine a overloading type}\\

\tyfun
     & = & \Lambda{\vect{\alpha}}\,.\,{\qualtype{\vect\type_1}{\type_2}}
                                                            &\comment{type function}\\
\end{array}
\]}

\section {computing equality of types}
\begin{minipage}{0.7\textwidth}
\[\begin{array}{lcl}
eq(\rigdvar{\alpha}^\equality) 						&=& \equality \\
eq(\flexvar{\alpha})                                &=& \eqyes    \\
eq(\tycon^\equality\ \vect\type) 					&=& \equality + eq(\vect\type) \\
eq(\record{\vect{\lab:\type}})			        	&=& eq(\vect\type)    \\
eq(\irecrd{\alpha}{[\vect{\lab:\type}]})	    		&=& eq(\vect\type)    \\
eq(\overld{\alpha}{\type}{[\vect\scheme]})			&=& \eqnot                \\
eq(\type_1\ \type_2\ \cdots\ \type_n)			    &=& \sum_i^n eq(\type_i)  \\
\end{array}\]
\end{minipage}
\begin{minipage}{0.3\textwidth}
\[\begin{array}{ccccccccl}
\eqyes &+& \eqyes &=& \eqyes \\
\eqnot &+& \eqnot &=& \eqnot \\
\eqyes &+& \eqnot &=& \eqnot &+& \eqyes &=& \eqnot \\
\\ \\ \\ \\ \\
\end{array}\]
\end{minipage}

\section {Substitution}
\newcommand{\s}{\vect{\delta}}
\newcommand{\ts}{\vect{\type}}
\vspace{-25pt}
\begin{flushright}
\framebox{ $\subst{\rho}{\type} \Rightarrow \type'$ }
\end{flushright}
{\renewcommand{\arraystretch}{1.2}\[
\begin{array}{lcl}
\subst{\tyvarsubst{\alpha}{\type_1}}{\alpha} & \Rightarrow & \type_1	 \\
\subst{\tyvarsubst{\alpha}{\type_1}}{\tycon\ \ts} & \Rightarrow & \tycon\ \subst{\tyvarsubst{\alpha}{\type_1}}{\ts} \\
\subst{\tyvarsubst{\alpha}{\type_1}}{\record{flds}}   & \Rightarrow & \record{\subst{\tyvarsubst{\alpha}{\type_1}}{flds}}   \\
\subst{\tyvarsubst{\alpha}{\type_1}}{\overld{\alpha}{\type_2}{\s_2}} & \Rightarrow & \type_1  \\
\subst{\tyvarsubst{\alpha}{\type_1}}{\overld{\beta}{\type_2}{\s_2}} & \Rightarrow &
    \overld{\beta}{\subst{\tyvarsubst{\alpha}{\type_1}}{\type_2}}{\s_2}  \\
\subst{\tyvarsubst{\alpha}{\type_1}}{\irecrd{\alpha}{flds}} & \Rightarrow & \type_1  \\
\subst{\tyvarsubst{\alpha}{\type_1}}{\irecrd{\beta}{flds}} & \Rightarrow &
    \irecrd{\beta}{\subst{\tyvarsubst{\alpha}{\type_1}}{flds}} \\
 & & \\
\subst{\ovldrefine{\alpha}{\s_1}}{\alpha} & \Rightarrow & \perp	 \\
\subst{\ovldrefine{\alpha}{\s_1}}{\tycon\ \ts} & \Rightarrow & \tycon\ \subst{\ovldrefine{\alpha}{\s_1}}{\ts} \\
\subst{\ovldrefine{\alpha}{\s_1}}{\record{flds}}   & \Rightarrow & \record{\subst{\ovldrefine{\alpha}{\s_1}}{flds}}   \\
\subst{\ovldrefine{\alpha}{\s_1}}{\overld{\alpha}{\type}{\s_2}} & \Rightarrow & \overld{\alpha}{\type}{\s_1}
    \quad\ifclause{\s_1 \subseteq \s_2} \\
\subst{\ovldrefine{\alpha}{\s_1}}{\overld{\beta}{\type}{\s_2}} & \Rightarrow &
    \overld{\beta}{\subst{\ovldrefine{\alpha}{\s_1}}{\type}}{\s_2} \\
\subst{\ovldrefine{\alpha}{\s_1}}{\irecrd{\beta}{flds}} & \Rightarrow &
    \irecrd{\beta}{\subst{\ovldrefine{\alpha}{\s_1}}{flds_1}} \\
 & & \\
\subst{\irecextend{\alpha}{flds_1}}{\alpha}                 & \Rightarrow & \perp	 \\
\subst{\irecextend{\alpha}{flds_1}}{\tycon\ \ts}        & \Rightarrow & \tycon\ \subst{\irecextend{\alpha}{flds_1}}{\ts} \\
\subst{\irecextend{\alpha}{flds_1}}{\record{flds_2}}        & \Rightarrow & \record{\subst{\irecextend{\alpha}{flds_1}}{flds_2}}\\
\subst{\irecextend{\alpha}{flds_1}}{\overld{\beta}{\type}{\s}}   & \Rightarrow & \overld{\beta}{\subst{\irecextend{\alpha}{flds_1}}{\type}}{\s} \\
\subst{\irecextend{\alpha}{flds_1}}{\irecrd{\alpha}{flds_2}}& \Rightarrow & \irecrd{\alpha}{flds_1}\\
\subst{\irecextend{\alpha}{flds_1}}{\irecrd{\beta}{flds_2}} & \Rightarrow & \irecrd{\alpha}{\subst{\irecextend{\alpha}{flds_1}}{flds_2}}\\
 & & \\
\subst{\rho}{\qualtype{\vect\type_1}{\type_2}}              & \Rightarrow & \qualtype{\subst{\rho}{\vect\type_1}}{\subst{\rho}{\type_2}} \\
\subst{\rho}{\type_1\ \type_2\ \cdots\ \type_n} 			& \Rightarrow & \subst{\rho}\type_1\ \subst{\rho}\type_2\ \cdots \subst{\rho}\type_n \\
\end{array}
\]}

\section {Generalization and Instantiation}
{\renewcommand{\arraystretch}{1.2}\[\begin{array}{lcll}
free(\alpha)                  & = & \braced{\alpha}                 &       \\
free({\tycon\ \ts})           & = & free(\ts)                 		&       \\
free(\record{flds})           & = & free(flds)                      &       \\
free({\overld{\alpha}{\type}{\s}}) & = & \braced{\alpha} \cup free(\type)    & \\
free({\irecrd{\alpha}{flds}}) & = & \braced{\alpha} \cup free(flds) &       \\
free(\qualtype{\vect\type_1}{\type_2})
                              & = & free(\vect\type_1) \cup free(\type_2)&       \\
free(\type_1\ \type_2\ \cdots\ \type_n)
							  & = & free(\type_1) \cup free(\type_2) \cdots \cup free(\type_n) & \\
& & \\
gen_{env}(\qualtype{\vect\type_1}{\type_2})
                              & = & \forall \vect{\alpha}. \qualtype{\vect\type_1}{\type_2}
                                                                    & \whereclause{\vect{\alpha} = free(\qualtype{\type_1}{\type_2}) - free(env)} \\
inst(\forall \vect{\alpha}.\qualtype{\vect\type_1}{\type_2})
                              & = &[\rho]\qualtype{\vect\type_1}{\type_2}& \whereclause{\rho = \braced{\alpha_i \mapsto \flexvar{\beta}_i \ |\ \flexvar{\beta}_i\ \textrm{is a fresh tyvar}}} \\
\end{array}\]}

\section{Instance relationship}
\vspace{-25pt}
\begin{flushright}
\framebox{ $\type \prec \scheme$}
\end{flushright}
\[
	\cfrac{ \unify{\type}{inst(\s)}{\_}}{\type \prec \s}
\]

\section{Unification}
\vspace{-25pt}
\begin{flushright}
\framebox{ $\unify{\type_1}{\type_2}{\rho}$}
\end{flushright}

\[
\begin{array}{ccc}
 \multicolumn{3}{c}{\unify{\alpha}{\alpha}{\braced{}}} \\
 &                                                                                \\
 {\unify{\flexvar{\alpha}}{\type}{\{\tyvarsubst{\flexvar\alpha}{\type}\}}} & \quad &
 {\unify{\type}{\flexvar{\alpha}}{\{\tyvarsubst{\flexvar\alpha}{\type}\}}}                                  \\
 &                                                                                \\
 {\unify{\rigdvar{\alpha}}{\type}{\perp}} & \quad &
 {\unify{\type}{\rigdvar{\alpha}}{\perp}}                                                                   \\
 &                                                                                \\
 \unify{\tycon_1\ \ts}{\record{flds}}{\perp}     & \quad & \unify{\record{flds}}{\tycon_1\ \ts}{\perp}      \\
 &                                                                                \\
 \unify{\tycon_1\ \ts}{\irecrd{\alpha}{flds}}{\perp} & \quad & \unify{\irecrd{\alpha}{flds}}{\tycon_1\ \ts}{\perp}  \\
 &                                                                                \\
 \cfrac
  {\unify{\ts_1}{\ts_2}{\rho} \quad \tycon_1 = \tycon_2}
  {\unify{\tycon_1\ \ts_1}{\tycon_2\ \ts_2}{\rho}} & \quad &
 \cfrac
  {\tycon_1 \ne \tycon_2}
  {\unify{\tycon_1\ \ts_1}{\tycon_2\ \ts_2}{\perp}}                                                         \\
 &                                                                                \\
 \multicolumn{3}{c}{ \cfrac
  {\unify{flds_1}{flds_2}{\rho}}
  {\unify{\record{flds_1}}{\record{flds_2}}{\rho}} }                                                        \\
\end{array}
\]
\[
\begin{array}{ccc}
 \multicolumn{3}{c}{\cfrac
  {\unify{\alpha_1}{\alpha_2}{\rho_1} \quad \unify{\subst{\rho_1}{\type_1}}{\subst{\rho_2}{\type_2}}{\rho_2} \quad
   \exists \s \in \s_1 \cap \s_2. (\subst{\rho_2}{\type_1} \prec \s)}
  {\unify{\overld{\alpha}{\type_1}{\s_1}}{\overld{\alpha}{\type_2}{\s_2}}
         {\rho_2 \circ \{\ovldrefine{\subst{\rho_1}{\alpha_1}}{\s_1 \cap \s_2}\} \circ \rho_1}}}              \\
 & &                                                                                \\
 \cfrac
  {\unify{\type_1}{\type_2}{\rho} \quad \exists \s \in \s_1. (\subst{\rho}{\type_1} \prec \s)}
  {\unify{\overld{\alpha}{\type_1}{\s_1}}{\type_2}{\rho}} & \quad &
 \cfrac
  {\unify{\type_1}{\type_2}{\rho} \quad \exists s \in \s_1. (\subst{\rho}{\type_2} \prec s)}
  {\unify{\type_1}{\overld{\alpha_2}{\type_2}{\s_1}}{\rho}}                                                          \\
 & &                                                                                \\
 \multicolumn{3}{c}{\cfrac
  {\unify{\alpha_1}{\alpha_2}{\rho_1} \quad
   \unify{\subst{\rho_1}{flds_1}}{\subst{\rho_1}{flds_2}}{\rho_2} \quad
   flds_1 \subseteq flds_2 \vee flds_2 \subseteq flds_1 }
  {\unify{\irecrd{\alpha_1}{flds_1}}{\irecrd{\alpha_2}{flds_2}}
         {\rho_2 \circ \{\irecextend{\subst{\rho_1}{\alpha_1}}{flds_1 \cup flds_2}\} \circ \rho_1}}}        \\
 & &                                                                                \\
 \multicolumn{3}{c}{\cfrac
  {\unify{flds_1}{flds_2}{\rho} \quad flds_1 \subseteq flds_2}
  {\unify{\irecrd{\alpha_1}{flds_1}}{\record{flds_2}}
         {\compose{\braced{\tyvarsubst{\alpha_1}{[\rho]flds_2}}}{\rho}}}}                                   \\
 & &                                \\
 \multicolumn{3}{c}{\cfrac
  {\unify{flds_1}{flds_2}{\rho} \quad flds_1 \subseteq flds_2}
  {\unify{\record{flds_2}}{\irecrd{\alpha_1}{flds_1}}
         {\compose{\braced{\tyvarsubst{\alpha_1}{[\rho]flds_2}}}{\rho}}}}                                   \\
\end{array}
\]

\section{Elaboration of types}
\vspace{-25pt}
\begin{flushright}
\framebox{ $ \Env, type \vdashT \qualtype{\vect\type_1}{\type_2}$ }
\end{flushright}
\[
  \Env, \q a \vdashT \qualtype{}{\rigdvar{\alpha}^{\eqnot}}
\]
\[
  \Env, \q\q a \vdashT \qualtype{\braced{\rigdvar{\alpha}^{\eqyes}}}{\rigdvar{\alpha}^{\eqyes}}
\]
\[
\cfrac
 {tycon \mapsto (k, \tycon^\equality,\wildcard) \inTE \Env    \qquad
  \Env,type_i\vdash \qualtype{p_i}{\type_i}}
 {\Env, tycon\ \vect{type}^{(k)} \vdashT \qualtype{(\sum_{i} p_i)}{\tycon^\equality\ \vect{\type}}}
\]
\[
\cfrac
 {tycon \mapsto (k, \zeta,\wildcard) \inTE \Env    \qquad
  \Env,type_i\vdash \qualtype{p_i}{\type_i}}
 {\Env, tycon\ \vect{type}^{(k)} \vdashT \qualtype{(\sum_{i} p_i)}{\zeta\ \vect{\type}}}
\]

\[
\cfrac
 {\Env,type_i\vdash \qualtype{p_i}{\type_i}}
 {\Env, \braced{\vect{\lab:type}} \vdashT \qualtype{(\sum_{i} p_i)}{\record{\vect{\lab:\type}}}}
\]

\end{document}


\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{pxfonts}
%\usepackage{graphicx}
\usepackage{geometry}

\geometry{letterpaper,left=.5in,right=.5in,top=0.5in,bottom=.75in,headsep=5pt,footskip=20pt}

\title{PSYC 51.09: Problem Set 5}
%\author{Jeremy R. Manning}
\date{}

\begin{document}
\maketitle
\vspace{-0.75in}
\section*{Introduction}
This problem set is intended to solidify the concepts you learned about in this week's lectures and readings.  Your responses will be worth 3\% of your final grade.  You are encouraged to work together with your classmates in small groups, and/or to post and answer questions on the course’s Canvas site.  \textbf{\textit{However, you must clearly indicate who your collaborated with and submit your own (uniquely worded) responses.}}

We will go over the answers to this problem set in class on \textbf{Monday, February 15, 2016 at 1:45 pm}.  You must upload your answers before then in order to receive credit.  No late submissions will be accepted.

\section*{Readings}
\begin{enumerate}
\item Read Chapter 5 of \textit{Foundations of Human Memory} (if you
  have not already done so).  What were your thoughts on the reading?
  \textbf{(Ungraded)}

\item Read Chapter 6 of \textit{Foundations of Human Memory}.  What were your thoughts on the reading?
  \textbf{(Ungraded)}
\end{enumerate}

\section*{Graded questions}

For this problem set, your job is to create your own neural
  network model of memory (a Hopfield network).  Below are two
  memories, $\mathbf{m}_1$ and $\mathbf{m}_2$ that you will store in
  your network.  Use the techniques we discussed in class (and in
  the book), along with the provided equations, to answer the
  following questions.  Show your work!
\[
  \mathbf{m}_1=
  \begin{pmatrix}
    1\\
    -1\\
    -1\\
    1\\
    -1\\
    -1
  \end{pmatrix}\quad
  \mathbf{m}_2=
  \begin{pmatrix}
    -1\\
    -1\\
    1\\
    -1\\
    -1\\
    1\\
  \end{pmatrix}\quad
\mathbf{x}_1=
  \begin{pmatrix}
    -1\\
    -1\\
    0\\
    0\\
    0\\
    0\\
  \end{pmatrix}\quad
\mathbf{x}_2=
  \begin{pmatrix}
    1\\
    -1\\
    0\\
    0\\
    0\\
    0\\
  \end{pmatrix}
\]
Learning rule:
\[
W(i,j) = \sum_{k = 1}^L a_k(i)a_k(j)
\]
Dynamic rule:
\[
a(i) = \mathrm{sign}\left(\sum_{j=1}^N W(i,j)a(j)\right)
\]

\begin{enumerate}
\item Create a weight matrix, using Hebbian learning, that contains
  both $\mathbf{m}_1$ and $\mathbf{m}_2$ as stable memories.
  \textbf{(1.5 points)}

\item For each of the partial cues, $\mathbf{x}_1$ and $\mathbf{x}_2$,
  the activity of the first two neurons is known.  Use
  \textbf{asynchronous updating} to calculate the activities of the
  remaining four neurons (in whatever order you want).  Can the
  network retrieve both memories?  Hint: update neurons 3, 4, 5, and 6
  (in any order).  Then continue updating those 4 neurons until none of the
  values change to show that the network has stabilized.\textbf{(1.5 points)}
\end{enumerate}

\end{document}

problem sets/previous years/problem set 5/ps5_2016.tex