% !TEX root =  ../thesis.tex

In this Chapter the witnesses for several standard optimizations are defined. These optimizations are chosen for their commonality and in order to illustrate features of the witness generation. We consider constant propagation, dead code elimination, control-flow graph compression and loop optimizations. Some transformation can be witnessed with a simple step simulation, however other transformations require the simulation to be stuttering, as the transformation can result in the target being shorter or longer than the source. As a side result of the examples, it is shown that the analysis required to check if a transformation can be triggered is more difficult than the witness generation procedure, showing that witness generation can be, in theory, an efficient transformation checker. Witness generation, essentially, makes explicit the implicit invariants gathered during the analysis. These examples confirm also the concept that, from a theoretical point of view, a witness can be generated for every kind of optimization, even though the complexity of the optimization will impact on the complexity of the witness. The examples are taken from \cite{zucknamjoshi}, and modified to highlight the details that this chapter wants to stress out.

The actual implementation for some of these transformations will be exposed in Chapter~\ref{cha:hacking_llvm}. Therefore all the details concerning the implementation will be put aside, in order to focus on the key concepts both of witness generation and invariant propagation.

\section{Constant Propagation}
\label{sec:constant_propagation_th}

In the \emph{Constant Propagation} pass, the analysis checks if any variable has a static assigned constant value. In the example of Figure~\ref{fig:constprop_th} all the values are constant-folded up.

\begin{figure}[t]
  \begin{mdframed}
  \centering
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L1: x = 1+2;
L2: y = x+x;
L3: y = y+1;
L4: x = y;
    \end{lstlisting}
    \caption{Source}
    \label{fig:sconstprop_th}
  \end{subfigure}
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L1: x = 3;
L2: y = 6;
L3: y = 7;
L4: x = 7;
    \end{lstlisting}
    \caption{Target}
    \label{fig:tconstprop_th}
  \end{subfigure}
  \end{mdframed}
  \caption{Constant propagation example}
  \label{fig:constprop_th}
\end{figure}

The witness generation for constant propagation basically draws from the invariants generated during the analysis. The invariant, called $constant(l)$, simply describes the set of variables that have a statically computed constant value at location $l$. For example, the invariant at \texttt{L3} is $x =3 \land y = 6$.

The witness relation is expressed in a symbolic form. The general shape of the relation for constant propagation is the following: a target state $(m, t)$ is related to a source state $(l, s)$ if and only if:
\begin{itemize}
  \item labels are identical (i.e., $m = l$),
  \item variables have identical values (i.e., for every variable $x, s(x) = t(x)$), and
  \item variables in the source system have values given by their invariant (i.e., $constants(l)$ holds at $s$)
\end{itemize}
Where for every variable $x$ in the source, $\bar{x}$ indicates its corresponding version in the target. For example, in symbolic form, the relation includes the clause
\[
  @L3 \land @\bar{L3} \land (x = \bar{x}) \land (y = \bar{y}) \land (z = \bar{z}) \land x = 3 \land y = 6
\]

It's necessary that the invariants hold at the source location, because this establishes the correspondence between target and source. For instance, the transition from $L2$ to $L3$ is matched by the transition from $\bar{L2}$ to $\bar{L3}$ only because the value of $x$ is defined as constant in $constant(L2)$

\section{Dead Code Elimination}
\label{sec:dce_and_cfgc_th}

Dead code elimination analyzes the code, building use-define chains for every assignment instruction, and marks all those instructions for which use set is empty. This means that the assigned value is not being used in any of the program computation and removing it doesn't change the semantics of the code. In this context, dead code elimination is split in two separate phases, the second being a restrictd instance of control flow graph compression. If the transition from location $m$ to location $n$ assigns a value to a variable $v$ that is dead (i.e., not live) at $n$, this assignment may be replaced with a skip statement. This is illustrated in Figure~\ref{fig:dce_th} which performs dead-code detection for the output of the constant propagation analysis. The result of the liveness analysis is a set, denoted $live(l)$, for each location $l$ of the source program.

\begin{figure}[t]
  \begin{mdframed}
  \centering
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L1: x = 3;
L2: y = 6;
L3: y = 7;
L4: x = 7;
    \end{lstlisting}
    \caption{Source}
    \label{fig:sdce_th}
  \end{subfigure}
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L1: x = skip;
L2: y = skip;
L3: y = 7;
L4: x = 7;
    \end{lstlisting}
    \caption{Target}
    \label{fig:tdce_th}
  \end{subfigure}
  \end{mdframed}
  \caption{Dead code elimination example}
  \label{fig:dce_th}
\end{figure}

Here is described a general procedure for generating a witness for DCE. A target state $(m, t)$ is related to a source state $(l, s)$ if and only if:
\begin{itemize}
  \item labels are identical (i.e., $m = l$), and
  \item every variable that is live at $l$ has the same value as the corresponding variable at $m$. I.e., for every variable $x$ such that $x \in live(l): s(x) = t(x)$.
\end{itemize}
For example, in symbolic form, the relation includes the clause
\[
  @\bar{L4} \land @L4 \land (y = \bar{y})
\]
as only the variable $x$ is live at $L4$. For any correct dead code elimination transformation, the relation defined above is a strong simulation witness.

Continuing the example from the result of dead code elimination, the control flow graph has unnecessary \emph{skip} statements. These may be removed using the rewrite rule $skip; S \rightarrow S$, for any statement $S$. This compresses the control flow graph. Other instances of compression may occur in the following situations:
\begin{itemize}
  \item a sequence such as \texttt{goto L1; L1:S} is replaced with \texttt{L1:S}, or
\item the sequence \texttt{S1; if (C) skip else skip; S2} is replaced with \texttt{S1;S2}.
\end{itemize}
In all these cases the computation in the target is shorter than the one in the source,

The general witness definition relates a target state $(m,t)$ to a source state $(l,s)$ if $s = t$ and either $l = m$ or $l$ lies on a linear chain of \emph{skip} statements from $m$ in the source graph.

\begin{figure}[t]
  \begin{mdframed}
  \centering
  \begin{subfigure}[b]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L1: x = skip;
L2: y = skip;
L3: y = 7;
L4: x = 7;
%*\vspace{0cm}
    \end{lstlisting}
    \caption{Source}
    \label{fig:scfgc_th}
  \end{subfigure}
  \begin{subfigure}[b]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L3: y = 7;
L4: x = 7;
%*\vspace{0cm}
    \end{lstlisting}
    \caption{Target}
    \label{fig:tcfgc_th}
  \end{subfigure}
  \end{mdframed}
  \caption{Control-Flow-Graph compression example}
  \label{fig:cfgc_th}
\end{figure}

For a correct control-flow graph compression, the defined relation is a stuttering simulation witness. Moreover, as a result of the closure property for stuttering simulation, it is possible to take the witnesses for constant propagation $W_1$, dead-code elimination $W_2$, and control-flow graph compression $W_3$ and compose them to form a single witness $W = W_1;W_2;W_3$for the transformation from the program in Figure~\ref{fig:sconstprop_th} to the program in Figure~\ref{fig:tcfgc_th}.

\section{Reordering Transformations}
\label{sec:reordering_transformations}

A \emph{reordering transformation} is a program transformation that changes the order of execution of the code, without adding or deleting any statements. It preserves a dependence if it preserves the relative execution order of the source and target of that dependence, and thus preserves the semantical meaning of the program. Reordering transformations cover many loop optimizations, including fusion, distribution, interchange, tiling, and reordering of statements within a loop body.

A generic loop can be described, as introduced in \cite{zuck2005translation}, by the statement \texttt{for $i \in \mathcal{I}$ by $\prec_{\mathcal{I}}$ do B(i) } where $i$ is the loop induction variable and $\mathcal{I}$ is the set of the values assumed by $i$ through the different iterations of the loop. The set $\mathcal{I}$ can typically be characterized by a set of linear inequalities. While in \cite{zuck2005translation} ``structure preserving'' and ``Reordering'' transformation passes are treated differently, here we follow \cite{zucknamjoshi} and let the witness relation to be defined so that it allows for uniform treatment of the two types of transformations.

\section{Loop Invariant code motion}
\label{sec:a_simple_reordering_transformation}

\emph{Loop invariant code motion} (also referred to as ``hoisting'') moves some instructions from the inner to the outer body of a loop without affecting the semantics of the program. Usually a reaching definitions analysis is used to detect whether a statement or expression is loop invariant. For example, if all reaching definitions for the operands of some simple assignment are outside of the loop, the assignment can be moved out of the loop. Moreover, in order to move instructions outside the loop, LICM analysis must guarantee that there is at least one iteration for every different computation case of the program. See for example Figure~\ref{fig:licm_th} which is a simplified version of an example from \cite{steven1997advanced}. Since the loop is going to be executed at least once, the assignments to $a$ and $c$, which are not dependent on any statement in the loop body, can be moved outside of the loop.

\begin{figure}[t]
  \begin{mdframed}
  \centering
  \begin{subfigure}[b]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L0: i = 1;
L1: while(i<100){
L2:   c = 3;
L3:   i = i + 1;
    }
    \end{lstlisting}
    \caption{Source}
    \label{fig:slicm_th}
  \end{subfigure}
  \begin{subfigure}[b]{0.49\textwidth}
    \centering
    \begin{lstlisting}
L0: i = 1;
L2: c = 3;
L1: while(i<100){
L3:   i = i + 1;
    }
    \end{lstlisting}
    \caption{Target}
    \label{fig:tlicm_th}
  \end{subfigure}
  \end{mdframed}
  \caption{Loop Invariant Code Motion example}
  \label{fig:licm_th}
\end{figure}

The transformation analyzer will detect the lack of dependencies of the statement in $L2$ on the other statements in the body, together with the fact that the loop is guaranteed to be executed at least once. The witness is generated in the following fashion. The simulation maps the first statements of the target program (In this case $L0$) and the first iteration of the target loop into the first iteration of the source loop. This mapping of course stutters, as there are more instructions in the target program segment than in the source program segment. Thus, the corresponding symbolic (stuttering simulation) will include the following clause: $L3 \land \bar{L3} \land i=\bar{i} \land c=\bar{c} \land c=3$. From the second iteration onwards, when $i>1$, the two loops are linked one by one in a stuttering simulation (since one target instruction in the target loop is mapped over two instructions in the source loop).

There is also a more general Loop invariant code motion that combines ``hoisting'' (where the instructions are moved before the loop body, as seen above) and ``sinking'' (where the instructions are moved after the loop body). For sinking, it must be checked that the moved instruction is not used inside the loop and that the loop is executed at least once. Given that, the witness generation follows the one described for the hoisting loop invariant code motion.


%\addtocontents{toc}{\protect\newpage}	% changes TOC so that line for this chapter does not appear at very bottom of page (starts new page before listing this chapter)
\chapter{Some curvilinear coordinate systems}


\documentclass{article}
\newsavebox{\oldepsilon}
\savebox{\oldepsilon}{\ensuremath{\epsilon}}
\usepackage[minionint,mathlf,textlf]{MinionPro} % To gussy up a bit
\renewcommand*{\epsilon}{\usebox{\oldepsilon}}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx} % For .eps inclusion
%\usepackage{indentfirst} % Controls indentation
\usepackage[compact]{titlesec} % For regulating spacing before section titles
\usepackage{adjustbox} % For vertically-aligned side-by-side minipages
\usepackage{array, amsmath,  mhchem}
\usepackage[hidelinks]{hyperref}
\usepackage{courier, subcaption}
\usepackage{multirow, enumerate}

\usepackage{float}
\restylefloat{table}

\pagenumbering{gobble}
\setlength\parindent{0 cm}
\renewcommand{\arraystretch}{1.2}
\begin{document}
\large

MCB 135 Problem Set 2 \hfill Due Wednesday, February 18, 2015 at 2:30 PM

\section*{Problem 1: Product Inhibition (Ingalls 3.7.4, 20 points)}

Many enzymatic reactions that are irreversible are nevertheless subject to \textit{product inhibition}, meaning that the product readily rebinds the free enzyme. To describe product inhibition, consider the scheme:
\begin{eqnarray*}
\ce{ S + E <=>[k_1][k_{-1}] \textrm{C}_1 ->[k_r] \textrm{C}_2  <=>[k_2][k_{-2}] P + E}
\end{eqnarray*}

From this reaction scheme, derive the rate law:
\[\frac{d\left[ P \right]}{dt} = V = \frac{V_{\textrm{max}} \left[ S \right]}{\left[ S \right] + K_M \left( 1 + \frac{\left[ P \right]}{K_P} \right)} \]

Note: This is a specific example of the general phenomenon of competitive inhibition.

\section*{Problem 2: Non-competitive Inhibition (20 points)}

Non-competitive inhibition occurs when an inhibitor prevents catalysis from occurring by binding to the enzyme independently of the substrate:

\begin{figure}[htp] \centering{
\includegraphics[width=0.4\textwidth]{non-competitive.pdf}}
\caption{Binding scheme for non-competitive inhibition.} \label{fig:noncompete}
\end{figure}

By applying quasi-steady-state approximations to all three complexes and accounting for conservation of the enzyme moiety, show that:
\[\frac{d\left[ P \right]}{dt} = V = \left( \frac{V_{\textrm{max}}}{1 + \frac{\left[ I \right]}{K_I}} \right) \frac{\left[ S \right]}{\left[ S \right] + K_M } \]

\section*{Problem 3: Lineweaver-Burk Plots (30 points)}

$K_M$ and $V_{\textrm{max}}$ can be determined from measurements of the rate of product formation vs. initial substrate concentration. It is possible to estimate these values from a plot of production formation rate $V$ vs. substrate concentration $[S]$, but only if the substrate concentrations tested were chosen appropriatley.

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\item Describe how you would roughly estimate $K_M$ and $V_{\textrm{max}}$ for the data given in figure \ref{fig:mm}.
\end{enumerate}

\begin{figure}[htp] \centering{
\includegraphics[width=0.4\textwidth]{mm_plot.pdf}}
\caption{An example plot of reaction rate vs. substrate concentration.} \label{fig:mm}
\end{figure}

When this approach is not possible due to an inappropriate choice of data points or noise, $K_M$ and $V_{\textrm{max}}$ can still be estimated using a Lineweaver-Burk (aka double reciprocal) plot of $1/V$ vs. $1/[S]$.

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\setcounter{enumi}{1}
\item Rearrange the Michaelis-Menten expression,
\[ \frac{dP}{dt} = V = \frac{V_{\textrm{max}} \left[ S \right]}{K_M + \left[ S \right]}, \]
to find a linear expression for $1/V$ in terms of $1/[S]$. Describe how you can determine $K_M$ and $V_{\textrm{max}}$ from the slope and intercept of the line.
\item Lineweaver-Burk plots can also be used to determine the general mechanism of enzymatic inhibitors. Describe how you would expect the plot to differ in the presence vs. absence of:
\begin{enumerate}
\item A competitive inhibitor
\item A non-competitive inhibitor
\end{enumerate}
You may find it helpful to refer to the rate laws derived in problems 1 and 2.
\item Apply your approach to the data provided on the course website in the file \texttt{rate\_data.tsv}. Estimate $K_M$ and $V_{\textrm{max}}$ in the presence and absence of inhibitor. What type of inhibitor is this?
\end{enumerate}

\section*{Problem 4: Concerted Model of Cooperativity (Ingalls 3.7.11, 30 points)}

In 1965, Jacques Monod, Jeffries Wyman, and Jean-Pierre Changeux proposed a mechanistic model of cooperativity (Monod et al., 1965). Their model addresses a multimeric protein composed of identical subunits, each with one ligand binding site. They supposed that each subunit could transition between two conformations: a tensed state $T$ and a relaxed state $R$. For each protein molecule, all of the subunits are presumed to have the same conformation at any given time: transitions between the relaxed and tense states are \textit{concerted}.\\

In the absence of ligand, the tensed state is more stable than the relaxed state. The relaxed state, however, has a higher affinity for ligand. Thus, at a sufficiently high ligand concentration, ligand binding causes the protein to adopt the relaxed state. This increases the protein's affinity for ligand, triggering a positive feedback, and resulting in a sigmoidal binding curve.

\begin{figure}[htp] \centering{
\includegraphics[width=0.4\textwidth]{ingallsmwc.pdf}}
\caption{Binding scheme for concerted model of cooperativity (Ingalls problem 3.7.11).} \label{fig:ingallsmwc}
\end{figure}

This mechanism is called the \textit{MWC model}, or the \textit{concerted model}. The ligand binding scheme for a dimer is shown in figure \ref{fig:ingallsmwc}, where $R_2$ is the dimer of two relaxed monomers, and $T_2$ is the dimer of two tensed monomers.

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\item Let $K$ be the equilibrium constant for the $R_2 \leftrightarrow T_2$ conversion, i.e.:
\[  K = \frac{[T_2]}{[R_2]} \textrm{ at steady state} \]
Suppose that the dissociation constant for ligand binding to $R_2$ is $K_R$, and that the dissociation constant for ligand binding to $T_2$ is $K_T$. (The dissociation constants for the first and second binding event are the same, but the association/dissociation rates will depend on stoichiometry factors that reflect the number of sites.)\\

Confirm that in steady state, the concentrations satisfy
\begin{eqnarray*}
\left[ R_2 \right] = \frac{\left[ T_2 \right] }{K}  \hspace{ 2 cm} \left[ R_2X_1 \right] = \frac{2 \left[ X \right]  \left[ R_2 \right] }{K_R} \hspace{2 cm} \left[ R_2X_2 \right] = \frac{\left[ X \right]  \left[ R_2X_1 \right] }{2 K_R} \\
\left[ T_2X_1 \right] = \frac{2 \left[ X \right]  \left[ T_2 \right] }{K_T} \hspace{2 cm} \left[ T_2X_2 \right] = \frac{\left[ X \right]  \left[ T_2X_1 \right] }{2 K_T} \hspace{ 2 cm}
\end{eqnarray*}

(The stoichiometric prefactors reflect the availability of binding sites.) Use these equilibrium conditions to verify that in steady state, the fractional saturation is given by
\begin{eqnarray}
Y = \frac{K \frac{\left[ X \right]}{K_T} \left( 1 + \frac{\left[ X \right]}{K_T} \right) + \frac{\left[ X \right]}{K_R}  \left( 1 + \frac{\left[ X \right]}{K_R} \right) }{K \left( 1 + \frac{\left[ X \right]}{K_T}  \right)^2 + \left( 1 + \frac{\left[ X \right]}{K_R}  \right)^2} \label{eqn:fracsatmwc}
\end{eqnarray}

Plot the corresponding binding curves for $K_T = 1000$, $K_R = 1$, and $K = 500$, $1000$, and $2000$. Verify that although this is not a Hill function, the curves are nevertheless sigmoidal.
\item Consider the special case of the concerted mechanism in which $K=0$. Interpret the resulting binding mechanism and use formula \ref{eqn:fracsatmwc} to verify that the resulting binding curve is hyperbolic. Repeat for the case when $K_R = K_T$.
\item Verify that when the concerted model is applied to a tetramer (such as hemoglobin), the resulting fractional saturation is

\begin{eqnarray*}
Y = \frac{K \frac{\left[ X \right]}{K_T} \left( 1 + \frac{\left[ X \right]}{K_T} \right)^3 + \frac{\left[ X \right]}{K_R}  \left( 1 + \frac{\left[ X \right]}{K_R} \right)^3 }{K \left( 1 + \frac{\left[ X \right]}{K_T}  \right)^4 + \left( 1 + \frac{\left[ X \right]}{K_R}  \right)^4}
\end{eqnarray*}

\end{enumerate}

\end{document}


\subsection{Quadratic curves}\label{subsec:quadratic_curves}

This subsection is dedicated to \hyperref[def:hypersurface/algebraic]{curves} in \( \BbbR^2 \) described by \hyperref[def:polynomial_degree]{quadratic polynomials}. We first formalize the meaning of \hyperref[def:affine_algebraic_set/variety]{algebraic variety} and \hyperref[def:affine_algebraic_set/curve]{algebraic curve}, but do not go into algebraic geometry beyond that. After that, we restrict ourselves to the classical theory of quadratic curves.

\begin{definition}\label{def:krull_dimension}\mcite[67]{КоцевСидеров2016}
  The \term{Krull dimension} \( \dim R \) of a \hyperref[def:ring/commutative]{commutative unital ring} \( R \) is the \hyperref[thm:union_of_set_of_ordinals/supremum]{ordinal supremum} of the lengths \( n \) of chains
  \begin{equation*}
    \set{ 0 } \subsetneq P_1 \subsetneq P_2 \subsetneq \cdots \subsetneq P_n \subsetneq R
  \end{equation*}
  of nontrivial prime ideals strictly contained in \( R \).

  The Krull dimension is either a nonnegative integer or the smallest \hyperref[def:successor_and_limit_cardinal/weak_limit]{limit cardinal} \( \aleph_0 \), which we denote via \( \infty \).
\end{definition}

\begin{proposition}\label{thm:def:krull_dimension}
  \hyperref[def:krull_dimension]{Krull dimensions} have the following properties:
  \begin{thmenum}
    \thmitem{thm:def:krull_dimension/field} The dimension of a \hyperref[def:field]{field} is \( 0 \).

    \thmitem{thm:def:krull_dimension/quotient} If \( I \) is an ideal of \( R \), then \( \dim R / I \leq \dim R \).

    \thmitem{thm:def:krull_dimension/localization}\mcite[thm. 1]{CoquandLombardi2005} We have \( 1 \leq \dim R \leq n \) if and only if \( \dim S_{\set{ x }}^{-1} R \leq n - 1 \) for every \( x \in R \), where
    \begin{equation*}
      S_{\set{ x }} = \set{ z \in R \given \qexists {n \in \BbbZ_{\geq 0}} \qexists {a \in R} z = x^n (1 + ax) }.
    \end{equation*}

    \thmitem{thm:def:krull_dimension/expanded_localization}\mcite[corr. 2]{CoquandLombardi2005} We have \( 1 \leq \dim R \leq n \) if and only if, for every sequence \( x_1, \ldots, x_{n+1} \) in \( R \), there exists a sequence \( a_1, \ldots, a_{n+1} \) in \( R \) and nonnegative integers \( m_1, \ldots, m_{n+1} \) such that
    \begin{equation*}
      x_1^{m_1} ( \cdots ( x_{n+1}^{m_{n+1}} ( 1 + a_{n+1} x_{n+1} ) + \cdots ) + a_1 x_1 ) = 0.
    \end{equation*}

    \thmitem{thm:def:krull_dimension/independent}\mcite[corr. 3]{CoquandLombardi2005} For an \hyperref[def:algebra_over_ring]{algebra} \( M \) over a \hyperref[def:field]{field} \( \BbbK \), if every sequence \( x_1, \ldots, x_{n+1} \) is \hyperref[def:algebraic_dependence]{algebraically dependent}, then \( \dim M \leq n \).

    \thmitem{thm:def:krull_dimension/affine_space}\mcite[corr. 4]{CoquandLombardi2005} For a \hyperref[def:field]{field} \( \BbbK \), the polynomial ring \( \BbbK[X_1, \ldots, X_n] \) has dimension \( n \). We call \( \BbbK[X_1, \ldots, X_n] \) the \( n \)-dimensional \term{affine space} over \( \BbbK \).
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:def:krull_dimension/field} A field is a \hyperref[def:ring/simple]{simple ring} by definition, hence it has zero proper nontrivial ideals.

  \SubProofOf{thm:def:krull_dimension/quotient} Follows from \fullref{thm:quotient_ideal_lattice_theorem}.

  \SubProofOf{thm:def:krull_dimension/localization} Suppose that
  \begin{equation*}
    \braket{ 0_R } \subsetneq S^{-1} P_1 \subsetneq \cdots \subsetneq S^{-1} P_m \subsetneq S^{-1} R
  \end{equation*}
  is a chain of prime ideals in \( S^{-1} R \). By \fullref{thm:def:ring_localization/prime_ideals},
  \begin{equation*}
    \braket{ 0_R } \subsetneq P_1 \subsetneq \cdots \subsetneq P_m \subsetneq R.
  \end{equation*}
  is a chain of prime ideals in \( R \). Then clearly \( m \leq \dim R \).

  We will now show that \( m \leq \dim R - 1 \). We will need the following observations:
  \begin{itemize}
    \item For every \( x \in R \), every maximal ideal \( M \) in \( R \) intersects \( S_{\set{ x }} \). This is obvious if \( x \in M \). Otherwise, since \( M \) is maximal, \( R = M + \braket{ x } \). Hence, there exist \( m \in M \) and \( a \in R \) such that \( m + ax = 1 \). Then \( 1 - ax \in M \cap S_{\set{ x }} \).

    \item No nested prime ideal \( P \subsetneq M \) intersects \( S_{\set{ x }} \) for \( x \in M \setminus R \). Indeed, suppose that \( x^n(1 + ax) \in S_{\set{ x }} \cap P \). Since \( P \) is prime, \( x^n \not\in P \), and hence \( 1 + ax \in P \). Since \( x \in M \), then \( ax \in M \), and thus from \( 1 + ax \in M \) it follows that \( 1 \in M \), contradicting the maximality of \( M \).
  \end{itemize}

  It follows that for any maximal ideal \( M \) of \( R \), \( S_{\set{ x }}^{-1} M \) is not a prime ideal for any \( x \in R \), while for any prime ideal \( P \subsetneq M \) and \( x \in M \setminus P \), \( S_{\set{ x }}^{-1} P \) is a prime ideal. Therefore, \( m \leq \dim R - 1 \) and, in general, this estimate is strict.

  \SubProofOf{thm:def:krull_dimension/expanded_localization}

  \SufficiencySubProof* We use induction on \( n \). The base case \( n = 1 \) follows directly from \fullref{thm:def:krull_dimension/localization}.

  Suppose that the statement holds for \( n - 1 \) and let \( \dim R = n \). By \fullref{thm:def:krull_dimension/localization}, \( \dim S_{\set{ x }}^{-1} R \leq n - 1 \) for every \( x \in R \).

  Let \( x_1, \ldots, x_{n+1} \) be members of \( R \). By using the inductive hypothesis on \( S_{\set{ x_{n+1} }}^{-1} R \), we obtain members \( a_1, \ldots, a_n \) and \( b_1, \ldots, b_n \) of \( R \) and nonnegative integers \( m_1, \ldots, m_n \) and \( k_1, \ldots, k_n \), such that
  \begin{equation*}
    x_1^{m_1} \parens*{ \cdots \parens*{ x_n^{m_n} \parens*{ 1 + \frac {a_n} {x_{n+1}^{k_n} (1 + b_n x_{n+1}) } x_n } + \cdots } + \frac {a_1} {x_{n+1}^{k_1} (1 + b_1 x_{n+1}) } x_1 } = 0.
  \end{equation*}

  Put
  \begin{equation*}
    c_i \coloneqq \prod_{j \neq i} x_{n+1}^{k_j} (1 + b_j x_{n+1})
  \end{equation*}
  and
  \begin{equation*}
    c \coloneqq \prod_{j=1}^{n+1} x_{n+1}^{k_j} (1 + b_j x_{n+1}).
  \end{equation*}

  Let \( m_{n+1} \coloneqq \prod_{j=1}^{n+1} k_j \). Since \( c \) is a member of \( S_{\set{ x_{n+1} }} \), there exists \( a_{n+1} \) (which we can obtain explicitly if desired) such that
  \begin{equation*}
    c = x_{n+1}^{m_{n+1}} (1 + a_{n+1} x_{n+1}).
  \end{equation*}

  Then
  \begin{equation*}
    x_1^{m_1} \parens{ \cdots \parens{ x_n^{m_n} \parens{ \underbrace{ x_{n+1}^{m_{n+1}} (1 + a_{n+1} x_{n+1}) }_c + a_n c_n x_n } + \cdots } + a_1 c_1 x_1 } = 0.
  \end{equation*}

  \NecessitySubProof* Follows from following the sufficiency subproof in the reverse direction.

  \SubProofOf{thm:def:krull_dimension/independent} Suppose that every sequence of \( n + 1 \) members of \( M \) is algebraically dependent. Let \( x_1, \ldots, x_{n+1} \) be members of \( M \). Then there exists a polynomial \( p(X_1, \ldots, X_{n+1}) \) such that \( p(x_1, \ldots, x_{n+1}) = 0 \).

  The polynomial can be written (in multiple ways) as
  \begin{equation*}
    p(X_1, \ldots, X_{n+1}) = X_1^{\gamma_1} \parens[\Big]{ \cdots \parens[\Big]{ X_{n+1}^{\gamma_{n+1}} \parens[\Big]{ 1 + q_{n+1}(X_{n+1}) X_{n+1} } + \cdots } + q_1(X_1, \ldots, X_{n+1}) X_1 }.
  \end{equation*}

  Then, by \fullref{thm:def:krull_dimension/expanded_localization}, \( \dim M \leq n \).

  \SubProofOf{thm:def:krull_dimension/affine_space} The \hyperref[def:vector_space]{vector space} \( \BbbK[X_1, \ldots, X_n] \) has dimension \( n \). By \fullref{thm:def:algebraic_dependence/n_plus_one_dependent}, every \( n + 1 \) polynomials are algebraically independent. From \fullref{thm:def:krull_dimension/independent} it follows that \( \dim \BbbK[X_1, \ldots, X_n] \leq n \).

  Furthermore, we have the following chain of prime ideals
  \begin{equation*}
    \braket{ 0 } \subsetneq \braket{ X_1 } \subsetneq \braket{ X_1, X_2 } \subsetneq \braket{ X_1, \ldots, X_n } \subsetneq \BbbK[X_1, \ldots, X_n].
  \end{equation*}

  Therefore, \( \dim \BbbK[X_1, \ldots, X_n] \geq n \).
\end{proof}

\begin{definition}\label{def:affine_algebraic_set}\mcite[69]{КоцевСидеров2016}
  For each ideal \( I \) of the \hyperref[def:polynomial_algebra]{polynomial ring} \( \BbbK[X_1, \ldots, X_n] \) over a \hyperref[def:field]{field} \( \BbbK \), we define its \term[bg=алгебрично многообразие, ru=алгебрическое многообразие]{affine algebraic set} as the locus of the simultaneous roots of all polynomials in \( I \),
  \begin{equation*}
    \mscrV(I) \coloneqq \set{ (x_1, \ldots, x_{n+1}) \in \BbbK^n \given \qforall {p \in I} p(x_1, \ldots, x_{n+1}) = 0 }.
  \end{equation*}

  \begin{thmenum}
    \thmitem{def:affine_algebraic_set/coordinate_ring} The quotient \( \BbbK[X_1, \ldots, X_n] / I \) is called a \term{coordinate ring} of \( \mscrV(I) \).

    \thmitem{def:affine_algebraic_set/dimension} The \term{dimension} \( \dim(\mscrV(I)) \) of an affine set is defined as the \hyperref[def:krull_dimension]{Krull dimension} of the coordinate ring \( \BbbK[X_1, \ldots, X_n] / I \).

    By \fullref{thm:quotient_submodule_lattice_theorem}, the dimension is the supremum of the length of prime ideal chains starting at \( I \):
    \begin{equation*}
      I \subsetneq P_1 \subsetneq P_2 \subsetneq \cdots \subsetneq P_n \subsetneq \BbbK[X_1, \ldots, X_n].
    \end{equation*}

    \thmitem{def:affine_algebraic_set/variety} If \( I \) is a \hyperref[def:semiring_ideal/prime]{prime ideal}, we say that \( \mscrV(I) \) is an \term{algebraic variety}.

    \thmitem{def:affine_algebraic_set/curve} An \term{algebraic curve} over \( \BbbK^n \) is an affine variety of dimension one.

    \thmitem{def:affine_algebraic_set/surface} An \term{algebraic surface} over \( \BbbK^n \) is an affine variety of dimension two.
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:quadratic_curves}
  We will work in the ring \( \BbbR[X, Y] \) of real polynomials in two indeterminates. Take the quadratic polynomial
  \begin{equation*}
    p(X, Y) \coloneqq a X^2 + b XY + c Y^2 + d X + e Y + f.
  \end{equation*}

  Then the \hyperref[def:affine_algebraic_set]{affine algebraic set} \( \mscrV(\braket{ p(X, Y) }) \) is an \hyperref[def:affine_algebraic_set/variety]{algebraic curve} if and only if \( p(X, Y) \) is an \hyperref[def:domain_divisibility/irreducible]{irreducible polynomial}.
\end{proposition}
\begin{proof}
  By \fullref{thm:polynomial_ring_over_gcd_domain}, \( \BbbR[X, Y] \) is a \hyperref[def:gcd_domain]{GCD domain}, and, by \fullref{thm:def:gcd_domain/irreducible_is_prime}, every \hyperref[def:domain_divisibility/irreducible]{irreducible polynomial} is \hyperref[def:domain_divisibility/prime]{prime}.

  Thus, if \( p(X, Y) \) is a nonconstant \hyperref[def:domain_divisibility/irreducible]{irreducible polynomial}, then the following \hyperref[def:hasse_diagram]{Hasse diagram} shows how the principal ideal of \( p(X, Y) \) relates to other prime ideals
  \begin{equation*}
    \begin{aligned}
      \includegraphics[page=1]{output/ex__quadratic_curves.pdf}
    \end{aligned}
  \end{equation*}

  By \fullref{thm:def:krull_dimension/affine_space}, the \hyperref[def:krull_dimension]{Krull dimension} of \( \BbbR[X, Y] \) is \( 2 \). Hence, by \fullref{thm:quotient_ideal_lattice_theorem}, the chain of \hyperref[def:ring/quotient]{quotients}
  \begin{equation*}
    \frac {\braket{ p(X, Y) }} {\braket{ p(X, Y) }} \subsetneq \frac {\braket{ X, Y }} {\braket{ p(X, Y) }} \subsetneq \frac {\BbbR[X, Y]} {\braket{ p(X, Y) }}
  \end{equation*}
  is a maximal chain of prime ideals.

  Therefore, the coordinate ring of \( \mscrV(\braket{ p(X, Y) }) \) has Krull dimension \( 1 \), and hence the affine algebraic set itself is an \hyperref[def:affine_algebraic_set/curve]{algebraic curve}.
\end{proof}

\begin{lemma}\label{thm:irreducible_polynomial_affine_change}
  Fix an \hyperref[def:integral_domain]{integral domain} \( D \) and let \( a \) and \( b \) be some members of \( D \). Assume that \( a \) is a unit. Then the polynomial \( p(X) \) is irreducible over \( D[X] \) if and only if \( p(aY + b) \) is irreducible over \( D[Y] \).
\end{lemma}
\begin{proof}
  Consider the evaluation \( X \mapsto aY + b \) and the corresponding \hyperref[thm:polynomial_algebra_universal_property]{evaluation homomorphism} \( \Phi: D[X] \to D[Y] \).

  Since \( a \) is a unit, we can also consider the evaluation homomorphism \( \Psi: D[Y] \to D[X] \) given by
  \begin{equation*}
    Y \mapsto \frac X b + \frac a b.
  \end{equation*}

  Clearly \( \Phi \) and \( \Psi \) are mutual inverses, hence both are isomorphisms. By \fullref{thm:def:domain_divisibility/primes_and_isomorphisms}, \( p(X) \) is irreducible in \( D[X] \) if and only if \( \Phi(p) = p(aY + b) \)  is irreducible in \( D[Y] \).
\end{proof}


\subsection{Scope}
\label{sec:intro_scope}

This thesis aims to thoroughly describe a financial machine learning pipeline for strategy training and validation. It will be exercised over bitcoin price with a fundamental momentum strategy. Multiple source features will be examined and used: financial, bitcoin and Bitcoin features, social media and structural break features. Feature engineering for time series will be applied and discussed in favor of determining the implications of sample uniqueness and series stationarity. Ensemble tree models will be used, trained and verified via cross validation with sample adjustments in favor of reduced leakage. Strategy and hyperparameter optimization, and feature selection will be conducted prior to back testing. The final stage will assign bet sizes and run back tests with budget metrics to quantitatively determine whether staking, momentum alone or this full strategy is the best one. Figure \ref{fig:pipeline}, which is in section \ref{sec:methods_pipeline}, shows the aforementioned pipeline.


\chapter{Conclusion}
\label{conclusion}
%What I did ( couple sentences), why I did it (more), why I think they worked or didn't work  (biggest)
%more about future uses and less about results

This project incorporated neural networks into a process of recognizing zebra stripe crosswalks in images. This process may be effective in aiding a visually impaired user across a crosswalk.

Neural networks are used in many image processing platforms, but they haven't yet been applied to recognizing zebra crosswalks in this way.

%An improvement of about 887\% increase in q-value was seen when comparing the same code using neural networks vs not using neural networks on the same dataset. With neural networks, there was an increase in runtime due to the calculations required for the neural network, but with optimizations that could be reduced. The dataset used was reasonably large and diverse and garnered decent results. It would definitely be worth looking into this method further for real world use.

Using the same dataset, a substantial improvement in false discovery rate (937\%) was seen when comparing the same code using neural networks versus without them. The false discovery rate is important because the higher it is, the more confidence can be given to a positive prediction. There was an increase in runtime due to the calculations required for the neural network inputs, but optimizations could reduce that impact. The dataset used was large and diverse. The results presented in this paper show that using neural networks is a promising tool in zebra crosswalk detection, and is well worth further investigation.


% Type realizability of the two-variable first-order logic with equivalences in
% refinement
In this section we consider the logic $\Lvp\Fo2\nopow\Eea\sze\agrefine$
featuring $\sze \geq 1$ equivalence symbols $\see1,\see2,\dots,\see\sze$ in
refinement.
By convention let $\see0$ be the formal equality, so that
$\Lvp\Fo2\nopow\Eea0\agrefine$ means $\vFo2$.
Abbreviate the coarsest equivalence symbol $\se = \see\sze$.

The following reductions carry over from the previous section:
\begin{align*}
  \FinASat{\vFo2\Eea\sze\agrefine} &\red\cNP \FinAClSat{\vFo2\Eea\sze\agrefine}
  \\
  \FinAClSat{\Lvp\Fo2\nopow\Eea\sze\agrefine} &\red\cNExpTime
  \FinAReal{\Lvp\Fo2\nopow\Eea\sze\agrefine}.
\end{align*}

We proceed to define new terms.
The terminology is based on~\cite{MALQ:MALQ201400102}.

Let $\ClSig\SigS\sms$ be a predicate signature over $\vFo2\Eea\sze\agrefine$.
A \twotype/ $\tpt \in \TpT\SigS$ is a \emph{galactic type} if
$\se(\xx,\yy) \in \tpt$.
Otherwise, that is if $(\lnot\se(\xx,\yy)) \in \tpTt$,
the \twotype/ $\tpt$ is a \emph{cosmic type}.
Let $\TI$ be a type instance over $\ClSig\SigS\sms$.
The sets of galactic and cosmic types in $\TI$ are $\gls{galactic-T}$ and
$\gls{cosmic-T}$, respectively.
Two \onetypes/ $\tpp, \tppp \in \TP\TI$ are \emph{cosmically connectable} if
some cosmic $\tpt \in \TIc$ connects them.
A \onetype/ $\gls{noble-n}$ is a \emph{noble type} if it is not cosmically
connectable with itself;
the set of noble types over $\TI$ is $\gls{noble-types-T}$.
A \onetype/ $\tpp$ that is not a noble type is a \emph{peasant type};
the set of peasant types is $\gls{peasant-types-T}$.
So we have $\TP\TI = \TN\TI \cup \TPs\TI$,
$\TK\TI \subseteq \TN\TI$ and $\TPs\TI \subseteq \TW\TI$.

We think of the $\se$-classes in a $\ClSig\SigS\sms$-structure as
\emph{galaxies};
of the whole structure as the \emph{cosmos};
of the galactic \twotypes/ as characterizing the
interactions in the interior of the galaxies
and of cosmic \twotypes/ characterize the interactions between different
galaxies.

Let $\StrA$ be a model for $\TI$.
An element realizing a noble type is a \emph{noble element}.
An element realizing a peasant type is a \emph{peasant element}.
We denote the galaxies of $\StrA$ by $\gls{galaxies-A} = \Ecl{\at\StrA\se}$.
A galaxy $\galX\in\Gals\StrA$ is a \emph{noble galaxy} if it contains a noble
element.
Otherwise, that is if every $\ea\in\galX$ is a peasant,
the galaxy $\galX$ is a \emph{peasant galaxy}.
The sets of noble and peasant galaxies are $\gls{noble-galaxies-A}$ and
$\gls{peasant-galaxies-A}$, respectively.
So we have $\Gals\StrA = \GalsN\StrA \cup \GalsP\StrA$.
If $\galX \in \Gals\StrA$ is a galaxy, denote
$\gls{types-in-X} = \setbd{\tpIa\StrA\ea}{\ea\in\galX}$ to be the set of
\onetypes/ realized by elements of $\galX$.

\begin{lemma}[Galaxy characterization] Let $\StrA$ be a model for $\TI$.
Then:
\begin{enumerate}
  \item
  If $\tpp\in\TP\TI$ then some $\galX\in\Gals\StrA$ has
  $\tpp\in\tpIa\StrA\galX$.

  If $\galX\in\Gals\StrA$ then $\tpIa\StrA\galX\subseteq\TP\TI$, or equivalently
  every $\tpp\in\tpIa\StrA\galX$ has $\tpp\in\TP\TI$.

  \item
  Let $\galX\in\Gals\StrA$.
  Then $\galX\in\GalsN\StrA$ iff $\tpIa\StrA\galX\cap\TN\TI\neq\eset$,
  or equivalently iff some $\tpn\in\tpIa\StrA\galX$ has $\tpn\in\TN\TI$.

  \item
  Let $\galX\in\Gals\StrA$.
  Then $\galX\in\GalsP\StrA$ iff $\tpIa\StrA\galX \subseteq \TPs\TI$,
  or equivalently iff every $\tpp\in\tpIa\StrA\galX$ has $\tpp\in\TP\TI$.

  \item
  Let $\tpn\in\TP\TI$.
  Then $\tpn\in\TN\TI$ iff a unique $\galX\in\Gals\StrA$ has
  $\tpn\in\tpIa\StrA\galX$.

  \item
  Let $\tpp\in\TP\TI$.
  Then $\tpp\in\TPs\TI$ iff for every $\galX\in\Gals\StrA$ such that
  $\tpp\in\tpIa\StrA\galX$ there is some $\galY\in\Gals\StrA\sub\set\galX$
  having $\tpp\in\tpIa\StrA\galY$.
\end{enumerate}
We will be applying this lemma implicitly.
\end{lemma}
\begin{proof}
\begin{enumerate}
  \item
  If $\tpp\in\TP\TI$, then some $\ea\in\domA$ has $\tpIa\StrA\ea = \tpp$,
  so $\galX = \at\StrA\se[\ea] \in \Gals\StrA$ has $\tpp\in\tpIa\StrA\galX$.
  If some $\galX\in\Gals\StrA$ has $\tpp\in\tpIa\StrA\galX$, then some
  $\ea\in\galX$ has $\tpIa\StrA\ea = \tpp$, so $\tpp\in\TP\TI$.

  \item This follows by the definition of noble galaxy.

  \item This follows by the definition of peasant galaxy.

  \item
  If $\tpn\in\TN\TI$, then some $\galX\in\Gals\StrA$ has
  $\tpn\in\tpIa\StrA\galX$, so some $\ea\in\galX$ has $\tpIa\StrA\ea = \tpn$.
  Suppose towards a contradiction that some other
  $\galY\in\Gals\StrA\sub\set\galX$ has $\tpn\in\tpIa\StrA\galY$,
  so some $\eb\in\galY$ has $\tpIa\StrA\eb = \tpn$.
  Then $\tpt = \tpIab\StrA\ea\eb \in \TI$ is a cosmic type connecting $\tpn$
  with itself --- a contradiction.

  Next suppose that $\tpp\in\TP\TI\sub\TN\TI = \TPs\TI$, so some cosmic
  $\tpt\in\TI$ connects $\tpp$ with itself.
  Then some $\ea\in\domA$ and $\eb\in\domA\sub\set\ea$
  have $\tpIab\StrA\ea\eb = \tpt$.
  Let $\galX = \at\StrA\se[\ea] \in \Gals\StrA$
  and $\galY = \at\StrA\se[\eb] \in \Gals\StrA$.
  Since $\tpt$ is cosmic, $\galX\neq\galY$.
  So we have that $\tpp\in\tpIa\StrA\galX$
  $\tpp\in\tpIa\StrA\galY$ is realized in at least $2$ galaxies.

  \item
  First suppose that $\tpp\in\TPs\TI$ and that $\galX\in\Gals\StrA$
  has $\tpp \in \tpIa\StrA\galX$.
  Since $\tpp\not\in\TN\TI$, $\galX$ is not unique,
  so there must be some other $\galY\in\Gals\StrA\sub\set\galX$ such that
  $\tpp\in\tpIa\StrA\galY$.

  Next let $\tpp\in\TP\TI$ and suppose that for every $\galX\in\Gals\StrA$ such
  that $\tpp\in\tpIa\StrA\galX$ there is some $\galY\in\Gals\StrA\sub\set\galX$
  having $\tpp\in\tpIa\StrA\galY$.
  Since $\tpp\in\TP\TI$, some $\galX\in\Gals\StrA$ has $\tpp\in\tpIa\StrA\galX$.
  Then some $\galY\in\Gals\StrA\sub\set\galX$ has $\tpp\in\tpIa\StrA\galY$,
  so $\tpp\not\in\TN\TI$, so $\tpp\in\TPs\TI$.
\end{enumerate}
\end{proof}
Note that a noble galaxy might contain a peasant element.
We will define a class of models --- the \emph{nobly distinguished} models
--- where this doesn't happen.
For this we first define \emph{peasantly united} models.

\begin{definition}
The model $\StrA$ for $\TI$ is \emph{peasantly united}
if whenever $\tpp \in \TP\TI$ is a peasant type that is realized in
some peasant galaxy:
$\tpp \in \tpIa\StrA\galX$ for some $\galX\in\GalsP\StrA$,
then $\tpp$ is also realized in some other peasant galaxy:
$\tpp \in \tpIa\StrA\galY$ for some $\galY\in\GalsP\StrA\sub\set\galX$.
\end{definition}
\begin{lemma}[Peasant unitedness]\label{lem:peasant-unitedness}
If the type instance $\TI$ has a (finite) model, then it has a (finite)
peasantly united model.
\end{lemma}
\begin{proof}
Suppose that $\StrA$ is a (finite) model for $\TI$.
We copy its peasant galaxies.
We describe the (finite) model $\StrAp$ by describing its galaxies
$\Gals\StrAp$.
The noble galaxies $\GalsN\StrAp$ of $\StrAp$ coincide with the noble galaxies
$\GalsN\StrA$ of $\StrA$.
The peasant galaxies $\GalsP\StrAp$ of $\StrAp$ consist of two copies
$\galXX1,\galXX2$ of each peasant galaxy $\galX\in\GalsP\StrA$ of $\StrA$.
This naturally induces the \onetype/ of every $\ea \in \domAp$ and the
\twotype/ between distinct elements that do not come from the two
copies of the same peasant galaxy.
Already at this point, the partial structure $\StrAp$ satisfies the existential
parts~\cref{eq:twovar-ms-iinter}, so it is a \emph{partial}
$\ClSig\SigS\sms$-structure.
We proceed to complete $\StrAp$.
Let $\galX\in\GalsP\StrA$ be any peasant $\StrA$-galaxy and let
$\eaa1\in\galXX1$ and $\ebb2\in\galXX2$ be any elements from the different
copies of $\galX$ in $\StrAp$.
Note that $\ea, \eb \in \galX$ and let $\tpp = \tpIa\StrAp\ea = \tpIa\StrA\ea$.
Since $\galX$ is a peasant galaxy,
$\tpp$ must be a peasant type,
so some $\galY\in\Gals\StrA\sub\set\galX$ has $\tpp\in\tpIa\StrA\galY$,
so some $\eap\in\galY$ has $\tpIa\StrA\eap = \tpp$.
Then $\tpt = \tpIab\StrA\eap\eb$ is cosmic and the assignment
$\tpIab\StrAp{\eaa1}{\ebb2} = \tpIab\StrA\eap\eb$ is appropriate.
The model $\StrAp$ is peasantly united by construction:
any peasant type that is realized in a peasant galaxy $\galXX\ii$ is also
realized in the peasant galaxy $\galXX{3-\ii}$.
\end{proof}

\begin{definition}
The model $\StrA$ for $\TI$ is \emph{nobly distinguished} if every noble galaxy
contains only noble elements.
That is if $\galX\in\GalsN\StrA$, then $\tpIa\StrA\galX \subseteq \TN\TI$.
\end{definition}

\begin{definition}
The (finite) nobly distinguished type realizability problem for the logic
$\vFo2\Eea\sze\agrefine$ is the following: given a classified signature
$\ClSig\SigS\sms$ and a type instance $\TI$ over $\ClSig\SigS\sms$,
is there a (finite) nobly distinguished model for $\TI$.
Denote the nobly distinguished type realizability problem by
$\NDReal{\vFo2\Eea\sze\agrefine}$ and its finite version by
$\FinNDReal{\vFo2\Eea\sze\agrefine}$.
\end{definition}

Let $\TI$ be a type instance over $\ClSig\SigS\sms$.
For every noble type $\tpn \in \TN\TI$,
let $\spp\tpn$ be a new unary predicate symbol.
Let $\SigSp = \SigS + \seqbd{\spp\tpn}{\tpn \in \TN\TI}$ be an
enrichment of $\SigS$ featuring these new symbols. Consider the following sets
of literals over $\SigSp$:
\[
  \sPe\tpn(\xx) = \set{\spp\tpn(\xx)} \cup
  \setbd{\lnot\spp\tpnp(\xx)}{\tpnp \in \TN\TI \sub \set\tpn}.
\]
Let $\bot$ be a special element and define the special set of literals:
\[
  \sPe\bot(\xx) =
  \setbd{\lnot\spp\tpn(\xx)}{\tpn \in \TN\TI}.
\]
If $\tpp \in \TP\TI$ is a \onetype/ and $\tpr \in \TN\TI\cup\set\bot$,
let $\mr\tpp\tpr$ be the following \onetype/ over $\SigSp$:
\[
  \mr\tpp\tpr = \tpp \cup \sPe\tpr(\xx).
\]
We refer to $\mr\tpp\tpr$ as the \emph{$\tpr$-copy of $\tpp$}.
If $\tpt \in \TI$ and $\tpr, \tprp \in \TN\TI\cup\set\bot$,
let $\mrr\tpt\tpr\tprp$ be the following \twotype/ over $\SigSp$:
\[
  \mrr\tpt\tpr\tprp = \tpt \cup \sPe\tpr(\xx) \cup \sPe\tprp(\yy).
\]
So we have
$\tpx{(\mrr\tpt\tpr\tprp)} = \mr{(\tpx\tpt)}\tpr$ and
$\tpy{(\mrr\tpt\tpr\tprp)} = \mr{(\tpy\tpt)}\tprp$.
Define the set $\TIpm$ of \twotypes/ over $\ClSig\SigSp\sms$ as follows:
\[
  \TIpm = \setbd{\mrr\tpt\tpr\tprp}{\tpt\in\TI,
  \tpr,\tprp\in\TN\TI\cup\set\bot}.
\]
Note that $\TIpm$ is constructible in deterministic polynomial time from $\TI$.
\begin{definition}
A \emph{promotion} for the type instance $\TI$ over $\ClSig\SigS\sms$
is a type instance $\TIp \subseteq \TIpm$ over $\ClSig\SigSp\sms$ such that for
every $\tpt \in \TI$ there are some $\tpr,\tprp \in \TN\TI\cup\set\bot$ such
that $\mrr\tpt\tpr\tprp \in \TIp$.
\end{definition}

\begin{lemma}[Noble distinguishability]\label{lem:noble-distinguishability}
The type instance $\TI$ has a (finite) model iff there is some promotion $\TIp$
for $\TI$ that has a (finite) nobly distinguished model.
\end{lemma}
\begin{proof}
First, suppose that $\StrA$ is (finite) a model for $\TI$.
By~\Cref{lem:peasant-unitedness}, without loss of generality assume that $\StrA$
is peasantly united.
We define a promotion $\TIp$ for $\TI$ and a $\SigSp$-enrichment $\StrAp$ that
is a nobly distinguished model for $\TIp$.
For every noble galaxy $\galX\in\GalsN\StrA$ choose any noble type
$\tpn\in\tpIa\StrA{\galX}$ realized in it and define $\galX = \galXX\tpn$.
Define the enrichment $\StrAp$ as follows: for every $\ea \in \domA$:
\begin{enumerate}
  \item
  If $\ea \in \galXX\tpn$ is an element of some noble galaxy, then let
  $\tpIa\StrAp\ea = \mr{\tpIa\StrA\ea}\tpn$.
  \item
  Otherwise, if $\ea \in \galX$ is an element of a peasant galaxy, then
  let $\tpIa\StrAp\ea = \mr{\tpIa\StrA\ea}\bot$.
\end{enumerate}
Note that we have the following characterization of this construction:
for every $\galX \in \Gals\StrAp$:
\begin{enumerate}
  \item
  If $\tpn\in\TN\TI$ and
  $\mr\tpp\tpn\in\tpIa\StrAp\galX$ for some $\tpp\in\TP\TI$,
  then $\tpn\in\tpIa\StrA\galX$.

  Indeed, if $\mr\tpp\tpn\in\tpIa\StrAp\galX$
  then some $\ea\in\galX$ has $\tpIa\StrAp\ea = \mr\tpp\tpn$,
  so by construction $\galX = \galXX\tpn$, so $\tpn\in\galX$.
  \item
  If $\tpp\in\TP\TI$ and $\mr\tpp\bot\in\tpIa\StrAp\galX$, then
  $\galX\in\GalsP\StrA$ is a peasant galaxy and
  $\tpp\in\tpIa\StrA\galX$ is a peasant type.

  Indeed, if $\mr\tpp\bot\in\tpIa\StrAp\galX$
  then some $\ea\in\galX$ has $\tpIa\StrAp\ea = \mr\tpp\bot$,
  so by construction
  $\galX\in\GalsP\StrA$ and
  $\tpIa\StrAp\ea = \mr{\tpIa\StrA\ea}\bot$,
  so $\tpp = \tpIa\StrA\ea \in \tpIa\StrA\galX$ is a peasant type.
\end{enumerate}
Let $\TIp = \TIS\StrAp$ be the type instance of $\StrAp$.
By construction $\TIp \subseteq \TIpm$.
If $\tpt\in\TI$, then some $\ea\in\domA$ and $\eb\in\domA\sub\set\ea$ have
$\tpIab\StrA\ea\eb = \tpt$.
Let $\tpIa\StrAp\ea = \mr{\tpIa\StrA\ea}\tpr$ and
$\tpIa\StrAp\eb = \mr{\tpIa\StrA\eb}\tprp$,
so $\mr\tpt{\tpr\tprp} = \tpIab\StrAp\ea\eb \in \TIp$.
So $\TIp$ is a promotion of $\TI$.

We claim that $\tppp\in\TP\TIp$ is a noble type iff
$\tppp = \mr\tpp\tpn$ for some $\tpp\in\TP\TI$ and $\tpn\in\TN\TI$, or
equivalently:
\[
  \TN\TIp = \setbd{\mr\tpp\tpn \in \TP\TIp}{\tpp\in\TP\TI,\tpn\in\TN\TI}.
\]

First, suppose that $\mr\tpp\tpn\in\TP\TIp$ for some $\tpp\in\TP\TI$ and
$\tpn\in\TN\TI$.
Let $\galX\in\Gals\StrAp$ be such that $\mr\tpp\tpn\in\tpIa\StrAp\galX$.
Suppose towards a contradiction that $\mr\tpp\tpn\in\TPs\TIp$ is a peasant type.
Then there is some $\galY\in\Gals\StrAp\sub\set\galX$ such that
$\mr\tpp\tpn\in\tpIa\StrAp\galY$.
Then by construction $\tpn\in\tpIa\StrA\galX$ and $\tpn\in\tpIa\StrA\galY$
--- a contradiction.

Next, suppose that $\mr\tpp\bot\in\TP\TIp$ and let $\galX\in\Gals\StrAp$ be such
that $\mr\tpp\bot\in\tpIa\StrAp\galX$.
Then by construction $\galX\in\GalsP\StrA$ is a peasant galaxy and
$\tpp\in\tpIa\StrA\galX$ is a peasant type.
Since $\StrA$ is peasantly united, there is some
$\galY\in\GalsP\StrA\sub\set\galX$ having $\tpp\in\tpIa\StrA\galY$.
So by construction $\mr\tpp\bot = \tpIa\StrAp\galY$,
so $\mr\tpp\bot\in\TPs\TIp$.

Finally, we check that $\StrAp$ is nobly distinguished.
Indeed, let $\galX \in \GalsN\StrAp$ be any noble galaxy.
Then some $\ea\in\galX$ has $\tpIa\StrAp\ea \in \TN\TIp$, so
$\galX = \galXX\tpn$ for some noble $\tpn\in\TN\TI$.
Let $\eb\in\galX$ be any.
Then by construction $\tpIa\StrAp\eb = \mr{\tpIa\StrA\eb}\tpn$,
so $\tpIa\StrAp\galX \subseteq \TN\TIp$.

Next, suppose that $\TIp$ is any promotion of $\TI$ and that $\StrAp$ is model
for $\TIp$. Then the reduct of $\StrAp$ to a $\SigS$-structure is a model for
$\TI$ by the promotion condition that
if $\tpt\in\TI$ then $\mr\tpt{\tpr\tprp}\in\TIp$ for some
$\tpr,\tprp\in\TN\TI\cup\set\bot$.
\end{proof}
\begin{corollary}\label{cor:trealiz-nd}
The (finite) type realizability problem is reducible in nondeterministic
polynomial time to the (finite) nobly distinguished type realizability problem.
\[
  \FinAReal{\vFo2\Eea\sze\agrefine} \red\cNP
  \FinANDReal{\vFo2\Eea\sze\agrefine}.
\]
\end{corollary}

\begin{remark}
Suppose that $\StrA$ is a nobly distinguished model for $\TI$.
Then $\StrA$ is peasantly united.
\end{remark}
\begin{proof}
Suppose that $\tpp\in\TPs\TI$ is a peasant type,
$\galX\in\GalsP\StrA$ is a peasant galaxy
and $\tpp\in\tpIa\StrA\galX$.
Since $\tpp$ is a peasant type, some $\galY\in\Gals\StrA\sub\set\galX$ has
$\tpp\in\tpIa\StrA\galY$.
Since $\StrA$ is nobly distinguished, $\galY\in\GalsP\StrA$ is a peasant galaxy.
Hence $\StrA$ is peasantly united.
\end{proof}

\section{Cosmic spectrums}
Let $\TI$ be a type instance over the
$\vFo2\Eea\sze\agrefine$-classified signature $\ClSig\SigS\sms$.
\begin{definition}\label{def:cosmic-spectrum}
A \emph{cosmic spectrum}
$\gls{cosmic-spectrum-s} = (\cii\csps,\cie\csps,\cei\csps,\cee\csps)$ over $\TI$
consists of four sets of \twotypes/ satisfying the following conditions:
\begin{itemize}
  \item[\condcspII]\label{cond:cspII}
  The set of \emph{internal types} $\cii\csps \subseteq \TIg$ is a set of
  galactic types that is closed under inversion.

  \item[\condcspIE]\label{cond:cspIE}
  The set of \emph{boundary types} $\cie\csps \subseteq \TIc$ is a nonempty set
  of cosmic types.

  \item[\condcspEI]\label{cond:cspEI}
  The set of \emph{inverted boundary types} is:
  $\cei\csps = \setbd{\inv\tpt}{\tpt\in\cie\csps}$.

  \item[\condcspEE]\label{cond:cspEE}
  The set of \emph{external types} $\cee\csps \subseteq \TI$ is a set of
  \twotypes/ that is closed under inversion.

  \item[\condcspT]\label{cond:cspT}
  We require that
  $\TI = \cii\csps \cup \cie\csps \cup \cei\csps \cup \cee\csps$.

  \item[\condcspNP]\label{cond:cspNP}
  The (nonempty) set $\gls{internal-types-s} = (\tpx\restriction{\cie\csps})$ is
  the set of \emph{internal \onetypes/} of~$\csps$.
  The (nonempty) set $\gls{external-types-s} = (\tpy\restriction{\cie\csps})$ is
  the set of \emph{external \onetypes/} of~$\csps$.
  We require that either $\Tpx\csps \subseteq \TN\TI$, in which case $\csps$ is
  a \emph{noble cosmic spectrum}, or $\Tpx\csps \subseteq \TPs\TI$, in which
  case $\csps$ is a \emph{peasant cosmic spectrum}.
  Note that a \onetype/ may be both internal and external.
\end{itemize}
\end{definition}

For any \onetype/ $\tpp$ or a \twotype/ $\tpt$ over $\SigS$ denote by
$\gls{reduct-p-e}$ or $\noe\tpt$ the reducts of $\tpp$ and $\tpt$ to the language $\SigS - \seq{\se}$.
That is, $\noe\tpp \subset \tpp$ and $\noe\tpt \subset \tpt$ consist of those
literals that do not feature $\se$.
Let $\gls{si}$ be a new unary predicate symbol
and let $\SigSp = \SigS - \seq{\se} + \seq{\si}$ be the predicate signature
obtained from $\SigS$ by removing the coarsest equivalence symbol $\se$ and
adding the new predicate symbol $\si$.
Define the following \onetypes/ and \twotypes/ over $\SigSp$:
\begin{align*}
\di\tpp &= \noe\tpp\cup\set{\si(\xx)} \\
\de\tpp &= \noe\tpp\cup\set{\lnot\si(\xx)} \\
\dii\tpt &= \noe\tpt\cup\set{\si(\xx),\si(\yy)} \\
\die\tpt &= \noe\tpt\cup\set{\si(\xx),\lnot\si(\yy)} \\
\dei\tpt &= \noe\tpt\cup\set{\lnot\si(\xx),\si(\yy)} \\
\dee\tpt &= \noe\tpt\cup\set{\lnot\si(\xx),\lnot\si(\yy)}.
\end{align*}
Note that we have $\tpx{(\tpt_{\mathcal{X}\mathcal{Y}})} =
(\tpx\tpt)_{\mathcal{X}}$ and $\tpy{(\tpt_{\mathcal{X}\mathcal{Y}})} =
(\tpy\tpt)_{\mathcal{Y}}$ for $\mathcal{X},\mathcal{Y} \in
\set{\mathcal{I},\mathcal{E}}$.
\begin{definition}
The \emph{spectral type instance} $\gls{spectral-type-instance-s}$ of the cosmic
spectrum $\csps$ is a type instance over the \emph{simpler}
$\vFo2\Eea{(\sze-1)}\agrefine$-classified signature $\ClSig\SigSp\sms$ defined
as follows:
\[
  \TIs = \dii\TIs \cup \die\TIs \cup \dei\TIs \cup
  \dee\TIs,
\]
where $\TIs_{\mathcal{X}\mathcal{Y}} =
\setbd{\tpt_{\mathcal{X}\mathcal{Y}}}{\tpt \in
\csps^{\mathcal{X}\mathcal{Y}}}$ for
$\mathcal{X},\mathcal{Y}\in\set{\IntChar,\ExtChar}$.
Note that $\TIs$ is constructible in deterministic polynomial time from $\TI$
and $\csps$.
\end{definition}
This is indeed a type instance, since $\die\TIs$ is nonempty
by~\refcondcspIE{}
and since $\dii\TIs$, $(\die\TIs\cup\dei\TIs)$ and
$\dee\TIs$ are closed under inversion by~\refcondcspII, \refcondcspEI{}
and \refcondcspEE.
The size of a cosmic spectrum over a type instance is linear with
respect to the size of the type instance.
Define $\TPIs\csps = \setbd{\di\tpp}{\tpp\in\Tpx\csps} =
(\tpx\restriction\die\TIs)$ to be the set of
\emph{internal spectral \onetypes/}
and $\TPEs\csps = \setbd{\de\tpp}{\tpp\in\Tpy\csps} =
(\tpy\restriction\die\TIs)$ to be the set of \emph{external spectral
\onetypes/}.
\begin{definition}\label{def:locally-consistent-cosmic-spectrum}
The cosmic spectrum $\csps$ is \emph{locally consistent} if its spectral type
instance $\TIs$ has a model.
\end{definition}
\begin{definition}
Let $\StrA$ be a nobly distinguished model for $\TI$ such that $\relE =
\at\StrA\se \neq \domAA$ is not full on $\domA$
(equivalently, there are at least $2$ galaxies).
If $\galX\in\Gals\StrA$ is any galaxy, the \emph{cosmic spectrum}
$\csps=\cspIX\StrA\galX$ of $\galX$ is defined by:
\begin{align*}
  \cii\csps &= \setbd{\tpIab\StrA\ea\eb}{\ea \in \galX, \eb \in \galX \sub
  \set\ea} \\
  \cie\csps &= \setbd{\tpIab\StrA\ea\eb}{\ea \in \galX, \eb \in \domA \sub
  \galX} \\
  \cei\csps &= \setbd{\tpIab\StrA\ea\eb}{\ea \in \domA\sub\galX, \eb\in\galX} \\
  \cee\csps &= \setbd{\tpIab\StrA\ea\eb}{\ea \in \domA \sub \galX, \eb \in
  (\domA \sub \galX) \sub \set\ea}.
\end{align*}
\end{definition}
\begin{remark}\label{rem:nd-csps}
Indeed $\csps = \cspIX\StrA\galX$ is a locally consistent cosmic spectrum over
$\TI$ in the sense of~\Cref{def:locally-consistent-cosmic-spectrum}.
\end{remark}
\begin{proof}
First we check that $\csps$ is a cosmic spectrum over $\TI$ in the sense
of~\Cref{def:cosmic-spectrum}.
\begin{itemize}
  \item[\refcondcspII]
  If $\tpt\in\cii\csps$,
  then $\tpt = \tpIab\StrA\ea\eb$ for some $\ea\in\galX$ and
  $\eb\in\galX\sub\set\ea$,
  so $\tpt$ is galactic and $\inv\tpt = \tpIab\StrA\eb\ea\in\cii\csps$, so
  $\cii\csps$ is closed under inversion.

  \item[\refcondcspIE]
  First, since $\relE$ is not full on $\domA$, there is some $\ea\in\galX$ and
  $\eb\in\domA\sub\galX$, so $\tpIab\StrA\ea\eb\in\cie\csps$, so $\cie\csps$ is
  nonempty.
  Next, if $\tpt\in\cie\csps$ then $\tpt=\tpIab\StrA\ea\eb$ for some
  $\ea\in\galX$ and $\eb\in\domA\sub\galX$, so $\tpt$ is cosmic.

  \item[\refcondcspEI]
  If $\tpt\in\cie\csps$, then $\tpt=\tpIab\StrA\ea\eb$ for some $\ea\in\galX$
  and $\eb\in\domA\sub\galX$, so $\inv\tpt=\tpIab\StrA\eb\ea\in\cei\csps$.
  If $\tpt\in\cei\csps$, then $\tpt=\tpIab\StrA\ea\eb$ for some
  $\ea\in\domA\sub\galX$ and $\eb\in\galX$, so
  $\inv\tpt=\tpIab\StrA\eb\ea\in\cie\csps$, so $\tpt = \inv\tptp$ for
  $\tptp=\inv\tpt\in\cie\csps$.

  \item[\refcondcspEE]
  If $\tpt\in\cee\csps$, then $\tpt=\tpIab\StrA\ea\eb$ for some
  $\ea\in\domA\sub\galX$ and $\eb\in(\domA\sub\galX)\sub\set\ea$, so
  $\inv\tpt=\tpIab\StrA\eb\ea\in\cee\csps$ and hence $\cee\csps$ is closed under
  inversion.

  \item[\refcondcspT]
  We have that $\cii\csps \cup \cie\csps \cup \cei\csps \cup \cee\csps =
  \setbd{\tpIab\StrA\ea\eb}{\ea\in\domA,\eb\in\domA\sub\set\ea} = \TI$ since
  $\StrA$ is a model for $\TI$.

  \item[\refcondcspNP]
  First suppose that $\galX$ is a noble galaxy.
  Let $\tpp\in\Tpx\csps$, so some $\tpt\in\cie\csps$ has $\tpx\tpt=\tpp$, so
  some $\ea\in\galX$ and $\eb\in\domA\sub\galX$ has $\tpIab\StrA\ea\eb=\tpt$, so
  $\tpp=\tpIa\StrA\ea$ is noble, since $\StrA$ is nobly distinguished.
  Next suppose that $\galX$ is a peasant galaxy.
  Similarly, let $\tpp\in\Tpx\csps$, so some $\tpt\in\cie\csps$ has
  $\tpx\tpt=\tpp$, so some $\ea\in\galX$ and $\eb\in\domA\sub\galX$ has
  $\tpIab\StrA\ea\eb=\tpt$, so $\tpp=\tpIa\StrA\ea$ is peasant, since $\galX$ is
  a peasant galaxy.
\end{itemize}

We transform $\StrA$ to a $\ClSig\SigSp\sms$-structure $\StrAp$ by forgetting
the interpretation of $\se$ and by interpreting $\at\StrAp\si = \galX$.
Then:
\begin{align*}
\tpIab\StrAp\ea\eb &= \dii{\tpIab\StrA\ea\eb}
\text{ if } \ea\in\galX,\eb\in\galX\sub\set\ea \\
\tpIab\StrAp\ea\eb &= \die{\tpIab\StrA\ea\eb}
\text{ if } \ea\in\galX,\eb\in\domA\sub\galX \\
\tpIab\StrAp\ea\eb &= \dei{\tpIab\StrA\ea\eb}
\text{ if } \ea\in\domA\sub\galX,\eb\in\galX \\
\tpIab\StrAp\ea\eb &= \dee{\tpIab\StrA\ea\eb}
\text{ if } \ea\in\domA\sub\galX,\eb\in(\domA\sub\galX)\sub\set\ea.
\end{align*}
This shows that $\StrAp$ is a model for $\TIs$, so $\csps$ is locally
consistent.
\end{proof}

\section{Locally consistent cosmic spectrums}
Let $\csps$ be a locally consistent cosmic spectrum over $\TI$.

\begin{lemma}[Spectral characterization]\label{rem:lccsp-char}
Let $\StrAs$ be a model for the spectral type instance $\TIs$
and let $\galXs = \at\StrAs\si$ be the set of \emph{internal
spectral elements}.
Then:
\begin{align*}
\dii\TIs &=
\setbd{\tpIab\StrAs\ea\eb}{
  \ea\in\galXs,
  \eb\in\galXs\sub\set\ea} \\
\die\TIs &=
\setbd{\tpIab\StrAs\ea\eb}{
  \ea\in\galXs,
  \eb\in\domAs\sub\galXs} \\
\dei\TIs &=
\setbd{\tpIab\StrAs\ea\eb}{
  \ea\in\domAs\sub\galXs,
  \eb\in\galXs} \\
\dee\TIs &=
\setbd{\tpIab\StrAs\ea\eb}{
  \ea\in\domAs\sub\galXs,
  \eb\in(\domAs\sub\galXs)\sub\set\ea} \\
\TPIs\csps &=
  \setbd{\tpIa\StrAs\ea}{\ea\in\galXs} \\
\TPEs\csps &=
  \setbd{\tpIa\StrAs\ea}{\ea\in\domAs\sub\galXs}.
\end{align*}

In other words:
\begin{enumerate}
  \item
  If $\tpt\in\cii\csps$ then $\tpIab\StrAs\ea\eb = \dii\tpt$
  for some $\ea\in\galXs$ and $\eb\in\galXs\sub\set\ea$.

  If $\ea\in\galXs$ and $\eb\in\galXs\sub\set\ea$
  then some $\tpt\in\cii\csps$ has $\tpIab\StrAs\ea\eb = \dii\tpt$.

  \item
  If $\tpt\in\cie\csps$ then $\tpIab\StrAs\ea\eb = \die\tpt$
  for some $\ea\in\galXs$ and $\eb\in\domAs\sub\galXs$.

  If $\ea\in\galXs$ and $\eb\in\domAs\sub\galXs$
  then some $\tpt\in\cie\csps$ has $\tpIab\StrAs\ea\eb = \die\tpt$.

  \item
  If $\tpt\in\cei\csps$ then $\tpIab\StrAs\ea\eb = \dei\tpt$
  for some $\ea\in\domAs\sub\galXs$ and $\eb\in\galXs$.

  If $\ea\in\domAs\sub\galXs$ and $\eb\in\galX$
  then some $\tpt\in\cei\csps$ has $\tpIab\StrAs\ea\eb = \dei\tpt$.

  \item
  If $\tpt\in\cee\csps$ then $\tpIab\StrAs\ea\eb = \dee\tpt$
  for some $\ea\in\domAs\sub\galXs$ and $\eb\in(\domAs\sub\galXs)\sub\set\ea$.

  If $\ea\in\domAs\sub\galXs$ and $\eb\in(\domAs\sub\galXs)\sub\set\ea$
  then some $\tpt\in\cee\csps$ has $\tpIab\StrAs\ea\eb = \dee\tpt$.
  \item
  Both $\galXs$ and $\domAs\sub\galXs$ are nonempty.
  \item
  If $\tpp\in\Tpx\csps$ then some $\ea\in\galX$
  has $\tpIa\StrAs\ea = \di\tpp$

  If $\ea\in\galX$ then $\tpIa\StrAs\ea = \di\tpp$
  for some $\tpp\in\Tpx\csps$.
  \item
  If $\tpp\in\Tpy\csps$ then some $\ea\in\domAs\sub\galXs$
  has $\tpIa\StrAs\ea = \de\tpp$

  If $\ea\in\domAs\sub\galXs$ then $\tpIa\StrAs\ea = \de\tpp$
  for some $\tpp\in\Tpy\csps$.
\end{enumerate}
We will be applying this lemma implicitly.
\end{lemma}
\begin{proof}
\begin{enumerate}
  \item
  If $\tpt\in\cii\csps$ then $\dii\tpt\in\dii\TIs\subseteq\TIs$,
  so some $\ea\in\domAs$ and $\eb\in\domAs\sub\set\ea$ have
  $\tpIab\StrAs\ea\eb = \dii\tpt$.
  We have that
  $\si(\xx)\in\di{(\tpx\tpt)}=\tpx{(\dii\tpt)}=\tpIa\StrAs\ea$,
  so $\ea\in\galXs$.
  Similarly,
  $\si(\xx)\in\di{(\tpy\tpt)}=\tpy{(\dii\tpt)}=\tpIa\StrAs\eb$,
  so $\eb\in\galXs\sub\set\ea$.

  Next, suppose that $\ea\in\galXs$ and $\eb\in\galXs\sub\set\ea$
  and let $\tptp = \tpIab\StrAs\ea\eb$.
  Then $\si(\xx) \in \tpIa\StrAs\ea = \tpx\tptp$
  and $\si(\xx) \in \tpIa\StrAs\eb = \tpy\tptp$, so
  $\tptp = \dii\tpt$ for some $\tpt\in\cii\csps$.

  \item
  If $\tpt\in\cie\csps$ then $\die\tpt\in\die\TIs\subseteq\TIs$,
  so some $\ea\in\domAs$ and $\eb\in\domAs\sub\set\ea$ have
  $\tpIab\StrA\ea\eb = \die\tpt$.
  We have that
  $\si(\xx)\in\di{(\tpx\tpt)}=\tpx{(\die\tpt)}=\tpIa\StrAs\ea$,
  so $\ea\in\galXs$.
  Similarly,
  $(\lnot\si(\xx))\in\de{(\tpy\tpt)}=\tpy{(\die\tpt)}=\tpIa\StrA\eb$,
  so $\eb\in\domAs\sub\galXs$.

  Next, suppose that $\ea\in\galXs$ and $\eb\in\domAs\sub\galXs$.
  and let $\tptp = \tpIab\StrAs\ea\eb$.
  Then $\si(\xx) \in \tpIa\StrAs\ea = \tpx\tptp$
  and $(\lnot\si(\xx)) \in \tpIa\StrA\eb = \tpy\tptp$, so
  $\tptp = \die\tpt$ for some $\tpt\in\cie\csps$.

  \item
  If $\tpt\in\cei\csps$ then $\inv\tpt\in\cie\csps$,
  so some $\ea\in\galXs$ and $\eb\in\domAs\sub\galXs$ have
  $\tpIab\StrAs\ea\eb = \die{(\inv\tpt)}$,
  so $\tpIab\StrAs\eb\ea = \dei\tpt$.

  If $\ea\in\domAs\sub\galXs$ and $\eb\in\galXs$ then some $\tpt\in\cie\csps$
  has $\tpIab\StrAs\eb\ea = \die\tpt$,
  so $\tpIab\StrAs\ea\eb = \dei\tpt'$ for $\tptp = \inv\tpt \in \cei\csps$.

  \item
  If $\tpt\in\cee\csps$ then $\dee\tpt\in\dee\TIs\subseteq\TIs$,
  so some $\ea\in\domAs$ and $\eb\in\domAs\sub\set\ea$
  have $\tpIab\StrAs\ea\eb = \dee\tpt$.
  We have that
  $(\lnot\si(\xx))\in\de{(\tpx\tpt)} = \tpx{(\dee\tpt)} = \tpIa\StrAs\ea$, so
  $\ea\in\domAs\sub\galXs$.
  Similarly,
  $(\lnot\si(\xx))\in\de{(\tpy\tpt)} = \tpy{(\dee\tpt)} = \tpIa\StrAs\eb$, so
  $\eb\in(\domAs\sub\galXs)\sub\set\ea$.

  Next, suppose that $\ea\in\domAs\sub\galXs$ and
  $\eb\in(\domAs\sub\galXs)\sub\set\ea$ and let $\tptp = \tpIab\StrAs\ea\eb$.
  Then $(\lnot\si(\xx)) \in \tpIa\StrAs\ea = \tpx\tptp$ and
  $(\lnot\si(\xx)) \in \tpIa\StrAs\eb = \tpy\tptp$, so $\tptp = \dee\tpt$ for
  some $\tpt\in\cee\csps$.
  \item
  $\cie\csps$ is nonempty by~\refcondcspIE,
  so let $\tpt\in\cie\csps$ be any.
  Then some $\ea\in\galXs$ and
  $\eb\in\domAs\sub\galXs$ have $\tpIab\StrAs\ea\eb = \die\tpt$,
  so in particular both $\galXs$ and $\domAs\sub\galXs$ are nonempty.

  \item
  If $\tpp\in\Tpx\csps$ then some $\tpt\in\cie\csps$ has $\tpx\tpt=\tpp$,
  so some $\ea\in\galXs$ and $\eb\in\domA\sub\galXs$ have
  $\tpIab\StrA\ea\eb = \die\tpt$,
  so $\tpIa\StrAs\ea = \di\tpp$.

  Next, suppose that $\ea\in\galXs$.
  Let $\eb\in\domAs\sub\galXs$, which is nonempty.
  Then $\tpIab\StrAs\ea\eb = \die\tpt$ for some $\tpt\in\cie\csps$.
  Then $\tpp = \tpx\tpt \in \Tpx\csps$.
  Then $\tpIa\StrAs\ea = \tpx{(\die\tpt)} = \di\tpp$.

  \item
  If $\tpp\in\Tpy\csps$, then some $\tpt\in\cie\csps$ has $\tpy\tpt=\tpp$,
  so some $\ea\in\galXs$ and $\eb\in\domA\sub\galXs$ have
  $\tpIab\StrA\ea\eb = \die\tpt$,
  so $\tpIa\StrAs\eb = \de\tpp$.

  Next, suppose that $\eb\in\galXs$.
  Let $\ea\in\galXs$, which is nonempty.
  Then $\tpIab\StrAs\ea\eb = \die\tpt$ for some $\tpt\in\cie\csps$.
  Then $\tpp = \tpy\tpt \in \Tpy\csps$.
  Then $\tpIa\StrAs\eb = \tpy{(\die\tpt)} = \de\tpp$.
\end{enumerate}
\end{proof}

\begin{remark}\label{rem:lccsp-pcup}
We have that $\TP\TIs = \TPIs\csps \cup \TPEs\csps$.
\end{remark}
\begin{proof}
Let $\StrAs$ be a model for $\TIs$
and let $\galXs = \at\StrAs\si$ be the set of internal spectral elements.
Then
\[
\TP\TIs =
\setbd{\tpIa\StrAs\ea}{\ea\in\domAs} =
\setbd{\tpIa\StrAs\ea}{\ea\in\galXs}\cup
\setbd{\tpIa\StrAs\ea}{\ea\in\domAs\sub\galXs} =
\TPIs\csps \cup \TPEs\csps
\]
by~\Cref{rem:type-char} and by~\Cref{rem:lccsp-char}.
\end{proof}

\begin{remark}\label{rem:lccsp-sub}
If $\tpt\in\cii\csps$ then $\tpx\tpt\in\Tpx\csps$.
If $\tpt\in\cee\csps$ then $\tpx\tpt\in\Tpy\csps$.
Equivalently, $(\tpx\restriction\cii\csps) \subseteq \Tpx\csps$
and $(\tpx\restriction\cee\csps) \subseteq \Tpy\csps$.
\end{remark}
\begin{proof}
Let $\StrAs$ be a model for $\TIs$ and let $\galXs = \at\StrAs\si$ be the set of
internal spectral elements.

If $\tpt\in\cii\csps$ then some $\ea\in\galXs$ and $\eb\in\galXs\sub\set\ea$
have $\tpIab\StrAs\ea\eb = \dii\tpt$, so $\tpIa\StrAs\ea = \tpx{(\dii\tpt)} =
\di{(\tpx\tpt)}$, so $\tpx\tpt\in\Tpx\csps$.

If $\tpt\in\cee\csps$ then some $\ea\in\domAs\sub\galXs$ and
$\eb\in\domAs\sub\galXs\sub\set\ea$ have $\tpIab\StrAs\ea\eb = \dee\tpt$, so
$\tpIa\StrAs\ea = \tpx{(\dee\tpt)} = \de{(\tpx\tpt)}$, so
$\tpx\tpt\in\Tpy\csps$.
\end{proof}

\begin{remark}\label{rem:lccsp-tpcup}
We have that $\TP\TI = \Tpx\csps \cup \Tpy\csps$.
\end{remark}
\begin{proof}
Let $\tpp\in\TP\TI$ be any \onetype/,
so some $\tpt\in\TI$ has $\tpx\tpt = \tpp$.
By~\refcondcspT{} we have that
$\tpt \in \cii\csps \cup \cie\csps \cup \cei\csps \cup \cee\csps$.
If $\tpt\in\cii\csps$, then $\tpp\in\Tpx\csps$ by~\Cref{rem:lccsp-sub}.
If $\tpt\in\cie\csps$, then $\tpp\in\Tpx\csps$ by definition.
If $\tpt\in\cei\csps$, then $\inv\tpt\in\cie\csps$, so $\tpp =
\tpx\tpt=\tpy{(\inv\tpt)}\in\Tpy\csps$ by definition.
If $\tpt\in\cee\csps$, then $\tpp\in\Tpy\csps$ by~\Cref{rem:lccsp-sub}.
\end{proof}

\begin{remark}\label{rem:lccsp-xy}
If $\tpp\in\Tpx\csps$ and $\tppp\in\Tpy\csps$, then some $\tpt\in\cie\csps$ has
$\tpx\tpt=\tpp$ and $\tpy\tpt=\tppp$.
\end{remark}
\begin{proof}
Let $\StrAs$ be a model for $\TIs$
and let $\galXs = \at\StrAs\si$ be the set of internal spectral elements.
Then some $\ea\in\galXs$ has $\tpIa\StrAs\ea = \di\tpp$
and some $\eb\in\domAs\sub\galXs$ has $\tpIa\StrAs\eb = \de\tpp$.
Then $\tpIab\StrAs\ea\eb = \die\tpt$ for some $\tpt\in\cie\csps$.
Then $\tpx\tpt = \tpp$ and $\tpy\tpt = \tppp$.
\end{proof}

\begin{remark}\label{rem:lccsp-ps}
If $\tpp\in\TPs\TI$ is any peasant type, then $\tpp\in\Tpy\csps$.
\end{remark}
\begin{proof}
Let $\tpt \in \TIc$ be any cosmic type connecting the peasant type $\tpp$ with
itself.
Then by~\refcondcspT,
$\tpt \in \cie\csps \cup \cei\csps \cup \cee\csps$.

If $\tpt \in \cie\csps$, then $\tpp = \tpy\tpt \in \Tpy\csps$.
If $\tpt \in \cei\csps$, then $\tpp = \tpy(\inv\tpt) \in \Tpy\csps$.
Suppose that $\tpt \in \cee\csps$.
Let $\StrAs$ be a model for $\TIs$
and let $\galXs = \at\StrAs\si$ be the set of internal spectral elements.
Then $\tpIab\StrAs\ea\eb = \dee\tpt$
for some $\ea\in\domAs\sub\galXs$ and $\eb\in(\domAs\sub\galXs)\sub\set\ea$.
Then $\tpIa\StrAs\ea = \de\tpp$, so $\tpp\in\Tpy\csps$.
\end{proof}

\begin{remark}\label{rem:lccsp-n}
If $\tpn\in\Tpx\csps \cap \TN\TI$ is an internal noble type, then
$\tpn\not\in\Tpy\csps$.
\end{remark}
\begin{proof}
Suppose towards a contradiction that $\tpn\in\Tpy\csps$.
Then by~\Cref{rem:lccsp-xy},
some $\tpt\in\cie\csps$ has $\tpx\tpt = \tpy\tpt = \tpn$.
By~\refcondcspIE, $\tpt$ is cosmic --- a contradiction.
\end{proof}

\begin{remark}\label{rem:lccsp-ki}
If $\tpk\in\Tpx\csps\cap\TK\TI$ is an internal king type, then
$\di\tpk\in\TK\TIs$ is an internal spectral king type.
\end{remark}
\begin{proof}
Suppose towards a contradiction that $\di\tpk$ is not a king type, so some
$\tptp \in \TIs$ connects $\di\tpk$ with itself.
We must have that $\tptp \in \dii\TIs$, so $\tptp = \dii\tpt$
for some $\tpt \in \cii\csps$, so $\tpt$ connects $\tpk$ with itself
--- a contradiction.
\end{proof}

\begin{remark}\label{rem:lccsp-ke}
If $\tpk \in \Tpy\csps\cap\TK\TI$ is an external king type, then
$\de\tpk\in\TK\TIs$ is an external spectral king type.
\end{remark}
\begin{proof}
Suppose towards a contradiction that $\de\tpk$ is not a king type, so some
$\tptp \in \TIs$ connects $\de\tpk$ with itself.
We must have that $\tptp \in \dee\TIs$, so $\tptp = \dee\tpt$
for some $\tpt \in \cee\csps$, so $\tpt$ connects $\tpk$ with itself
--- a contradiction.
\end{proof}

\begin{remark}\label{rem:lccsp-nw}
Suppose that $\csps$ is noble. Then:
\begin{enumerate}
  \item
  If $\tpn\in(\Tpx\csps)\cap\TW\TI$ is an internal worker type,
  then $\di\tpn \in \TW\TIs$ is an internal spectral worker type.
  \item
  If $\tpp\in(\Tpy\csps)\cap\TW\TI$ is an external worker type,
  then $\de\tpp\in\TW\TIs$ is an external spectral worker type.
\end{enumerate}
\end{remark}
\begin{proof}
\begin{enumerate}
  \item
  Since $\csps$ is noble, by~\refcondcspNP{} we have that $\tpn$ must be noble.
  Since $\tpn$ is noble and is not a king type,
  there must be some galactic $\tpt\in\TIg$ connecting $\tpn$ with itself.
  Then by~\refcondcspT{} we have $\tpt \in \cii\csps \cup \cee\csps$.

  If $\tpt\in\cii\csps$, then $\dii\tpt \in \dii\TIs$ connects $\di\tpn$ with
  itself, so $\di\tpn$ is a worker type.

  If $\tpt\in\cee\csps$, then by~\Cref{rem:lccsp-sub} $\tpn\in\Tpy\csps$.
  Then by~\Cref{rem:lccsp-xy} some $\tpt\in\cie\csps$ connects $\tpn$
  with itself. But then $\tpt$ is cosmic --- a contradiction.

  \item
  Since $\tpp$ is a worker type, $\tpp\not\in\Tpx\csps$ and some $\tpt\in\TI$
  connects $\tpp$ with itself.
  Then we must have that $\tpt\in\cee\csps$.
  Hence $\dee\tpt$ connects $\de\tpp$ with itself, so $\de\tpp$ is an external
  spectral worker type.
\end{enumerate}
\end{proof}

For any $\tpps\csps \in \TP\TIs$ or $\tpts\csps \in \TIs$,
denote by $\noin{\tpps\csps}$ and $\noin{\tpts\csps}$ the
reducts of $\tpps\csps$ and $\tpts\csps$ to the language
$\SigS - \seq{\se} = \SigSp - \seq{\si}$.
Define the following types over $\SigS$:
\begin{align*}
\ci{\tpps\csps} &= \ce{\tpps\csps} =
  \noin{\tpps\csps} \cup \set{\se(\xx,\xx)} \\
\cii{\tpts\csps} &= \noin{\tpts\csps} \cup
\set{\se(\xx,\xx),\se(\yy,\yy),\se(\xx,\yy),\se(\yy,\xx)}\\
\cie{\tpts\csps} &= \noin{\tpts\csps} \cup
\set{\se(\xx,\xx),\se(\yy,\yy),\lnot\se(\xx,\yy), \lnot\se(\yy,\xx)}.
\end{align*}
That is, these are \emph{inverses} of the previous operations:
$\ci{(\di\tpp)} = \ce{(\de\tpp)} = \tpp$ for $\tpp \in \TP\TI$ and
$\cii{(\dii\tpt)} = \cie{(\die\tpt)} = \tpt$ for $\tpt \in \TI$.

\begin{definition}
Let $\StrAs$ be a model for $\TIs$, and let $\galXs =
\at\StrAs\si$ be the set of internal spectral elements.
Recall that both $\galXs$ and $\StrAs\sub\galXs$ are nonempty.
Transform
$(\StrAs\restriction\galXs)$ to a model $\StrXs$ for $\SigS$ by forgetting the interpretation of $\si$ and by
interpreting $\at\StrXs\se = \galXs \cprod \galXs$ as the full
relation on $\galXs$.
Call $\StrXs$ the \emph{galaxy} of the model $\StrAs$.
Note that $\StrXs$ is a $\SigS$-structure,
but is not necessarily a $\ClSig\SigS\sms$-structure, since some message symbols
might be witnessed only by an element outside of $\galXs$ in $\StrAs$.

For any internal spectral element $\ea\in\galXs$ define its \emph{intended
star-type} $\stps(\ea)$ by:
\[
  \stps(\ea) =
  \setbd{\cii{\tpIab\StrAs\ea\eb}}{\eb \in \galXs \sub \set\ea} \cup
  \setbd{\cie{\tpIab\StrAs\ea\eb}}{\eb \in \domAs \sub \galXs}.
\]
Define the \emph{intended \onetype/} of $\ea$ by:
$\tpp(\ea) = \tpx{(\stps(\ea))} = \ci{\tpIa\StrAs\ea} = \tpIa\StrXs\ea$.
\end{definition}
\begin{lemma}\label{rem:istp-stp}
The intended star-type $\stps=\stps(\ea)$ is a star-type over $\TI$.
\end{lemma}
\begin{proof}
Since $\domAs\sub\galXs$ is nonempty, $\stps$ is nonempty.
We verify the conditions for a star-type over $\TI$:
\begin{itemize}
  \item[\refcondstpx]
  If $\tpt, \tptp \in \stps$,
  then $\tpx\tpt = \tpx\tptp = \ci{\tpIa\StrAs\ea} = \tpp(\ea)$.
  Let $\tpp = \tpp(\ea)$ be the intended \onetype/ of $\ea$.

  \item[\refcondstppy]
  Let $\tppp\in\nb\TI\tpp$.
  We have to find some $\tpt\in\stps$ having $\tpy\tpt = \tppp$.
  By~\Cref{rem:lccsp-tpcup}, $\tppp\in\Tpx\csps\cup\Tpy\csps$.

  First suppose that $\tppp\neq\tpp$.
  If $\tppp\in\Tpx\csps$, then some $\eb\in\galXs$
  has $\tpIa\StrAs\eb = \di\tpp'$
  and since $\tppp\neq\tpp$ we have $\eb\in\galXs\sub\set\ea$.
  Then $\tpt = \cii{\tpIab\StrAs\ea\eb} \in \stps$
  has $\tpy\tpt = \ci{\tpIa\StrAs\eb} = \ci{(\di\tpp')} = \tppp$.
  If $\tppp\in\Tpy\csps$, then some $\eb\in\domAs\sub\galXs$
  has $\tpIa\StrAs\eb = \de\tpp'$.
  Then $\tpt = \cie{\tpIab\StrAs\ea\eb} \in \stps$
  has $\tpy\tpt = \ce{\tpIa\StrAs\eb} = \ce{(\de\tpp')} = \tppp$.

  Next suppose that $\tppp = \tpp$, so $\tpp$ is not a king type.
  So some $\tptp\in\TI$ connects $\tpp$ with itself.
  By~\refcondcspT,
  $\tptp\in\cii\csps \cup \cie\csps \cup \cei\csps \cup \cee\csps$.

  If $\tptp\in\cii\csps$
  then some $\eap\in\galXs$ and $\ebp\in\galXs\sub\set\eap$ have
  $\tpIab\StrAs\eap\ebp = \dii\tpt'$.
  So $\tpIa\StrAs\eap = \tpx{(\dii\tpt')} = \di{(\tpx\tptp)} = \di\tpp'$
  and $\tpIa\StrAs\ebp = \tpy{(\dii\tpt')} = \di{(\tpy\tptp)} = \di\tpp'$.
  Let $\eb\in\set{\eap,\ebp}\sub\set\ea$, which is nonempty.
  Then $\tpt = \cii{\tpIab\StrAs\ea\eb} \in \stps$
  has $\tpy\tpt = \ci{\tpIa\StrAs\eb} = \ci{(\di\tpp')} = \tppp$.

  If $\tptp\in\cie\csps$
  then some $\eap\in\galXs$ and $\ebp\in\domAs\sub\galXs$
  have $\tpIab\StrAs\eap\ebp = \die\tpt'$.
  So for $\eb = \ebp$,
  $\tpIa\StrAs\eb = \tpy{(\die\tpt')} = \de{(\tpy\tptp)} = \de\tpp'$.
  Then $\tpt = \cie{\tpIab\StrAs\ea\eb} \in \stps$
  has $\tpy\tpt = \ce{\tpIa\StrAs\eb} = \ce{(\de\tpp')} = \tppp$.

  If $\tptp\in\cei\csps$
  then some $\eap\in\domAs\sub\galXs$ and $\ebp\in\galXs$
  have $\tpIab\StrAs\eap\ebp = \dei\tpt'$.
  So for $\eb = \eap$,
  $\tpIa\StrAs\eb = \tpx{(\dei\tpt')} = \de{(\tpx\tptp)} = \de\tpp'$.
  Then $\tpt = \cie{\tpIab\StrAs\ea\eb} \in \stps$
  has $\tpy\tpt = \ce{(\de\tpp')} = \tppp$.

  If $\tptp\in\cee\csps$
  then some $\eap\in\domAs\sub\galXs$ and
  $\ebp\in(\domAs\sub\galXs)\sub\set\eap$
  have $\tpIab\StrAs\eap\ebp = \dee\tpt'$.
  So for $\eb = \eap$.
  $\tpIa\StrAs\eb = \tpx{(\dee\tpt')} = \de{(\tpx\tptp)} = \de\tpp'$.
  Then $\tpt = \cie{\tpIab\StrAs\ea\eb} \in \stps$
  has $\tpy\tpt = \ce{(\de\tpp')} = \tppp$.

  \item[\refcondstpky]
  Suppose that $\tpkp\in\nb\TI\tpp\cap\TK\TI$
  and that $\tpt,\tptp\in\stps$ have $\tpy\tpt = \tpy\tptp = \tpkp$.

  If $\tpt = \cii{\tpIab\StrAs\ea\eb}$ for some $\eb\in\galXs\sub\set\ea$
  and $\tptp = \cii{\tpIab\StrAs\ea\ebp}$ for some $\ebp\in\galXs\sub\set\ea$,
  then $\tpIa\StrAs\eb = \tpIa\StrAs\ebp = \di\tpk'$.
  Suppose towards a contradiction that $\eb\neq\ebp$,
  so $\tpIab\StrAs\eb\ebp = \dii\tpt''$ for some $\tptpp\in\cii\csps$,
  so $\tptpp$ connects $\tpkp$ with itself --- a contradiction.
  Hence $\eb = \ebp$ so $\tpt = \tptp$.

  If $\tpt = \cii{\tpIab\StrAs\ea\eb}$ for some $\eb\in\galXs\sub\set\ea$
  and $\tptp = \cie{\tpIab\StrAs\ea\ebp}$ for some $\ebp\in\galXs\sub\set\ea$,
  then $\tpIa\StrAs\eb = \di\tpk'$ and $\tpIa\StrAs\ebp = \de\tpk'$.
  Then $\tpIab\StrAs\eb\ebp = \die\tpt''$ for some $\tpt''\in\cie\csps$,
  so $\tpt''$ connects $\tpkp$ with itself --- a contradiction.

  If $\tpt = \cie{\tpIab\StrAs\ea\eb}$ for some $\eb\in\domAs\sub\galXs$
  and $\tptp = \cie{\tpIab\StrAs\ea\ebp}$ for some $\ebp\in\domAs\sub\galXs$,
  then $\tpIa\StrAs\eb = \tpIa\StrAs\ebp = \de\tpk'$.
  Suppose towards a contradiction that $\eb\neq\ebp$,
  so $\tpIab\StrAs\eb\ebp = \dee\tpt''$ for some $\tptpp\in\cee\csps$,
  so $\tpt''$ connects $\tpkp$ with itself --- contradiction.
  Hence $\eb = \ebp$ so $\tpt = \tptp$.
  \item[\refcondstpm]
  Let $\sm\in\sms$.
  Since $\StrAs$ is a model for $\TIs$,
  some $\eb\in\domA\sub\set\ea$ has $\sm(\xx,\yy)\in\tpIab\StrAs\ea\eb$.
  If $\eb\in\galX$,
  then $\sm(\xx,\yy)\in\cii{\tpIab\StrA\ea\eb}\in\stps$.
  If $\eb\in\domA\sub\galX$, then
  $\sm(\xx,\yy)\in\cie{\tpIab\StrA\ea\eb}\in\stps$.
\end{itemize}
\end{proof}

\begin{lemma}[Type characterization]\label{rem:gal-char}
Let $\TI$ be a type instance, $\csps$ be a locally consistent cosmic spectrum
over $\TI$,
$\StrAs$ be a model for the spectral type instance $\TIs$,
$\galXs$ be the set of internal spectral elements of $\StrAs$
and let $\StrXs$ be the galaxy of $\StrAs$.
Then:
\begin{enumerate}
  \item
  If $\tpp\in\Tpx\csps$
  then some $\ea\in\galXs$ has $\tpp(\ea) = \tpp$.

  If $\ea\in\galXs$
  then $\tpp(\ea)\in\Tpx\csps$.

  Equivalently $\Tpx\csps = \setbd{\tpp(\ea)}{\ea\in\galXs}$.
  \item
  If $\tpt\in\cii\csps$
  then some $\ea\in\galXs$ and $\eb\in\galXs\sub\set\ea$
  have $\tpIab\StrXs\ea\eb = \tpt$.

  If $\ea\in\galXs$ and $\eb\in\domAs\sub\galXs$
  then $\tpIab\StrXs\ea\eb\in\cii\csps$.

  Equivalently
  $\cii\csps =
  \setbd{\tpIab\StrXs\ea\eb}{\ea\in\galXs,\eb\in\galXs\sub\set\ea}$.
  \item
  If $\tpt\in\cie\csps$ then some $\ea\in\galXs$ has $\tpt\in\stps(\ea)$.

  If $\ea\in\galXs$ and $\tpt\in\stps(\ea)$ is cosmic,
  then $\tpt\in\cie\csps$.

  Equivalently
  $\cie\csps = \setbd{\stps(\ea)}{\ea\in\galXs} \cap \TIc$.
\end{enumerate}
We will be applying this lemma implicitly.
\end{lemma}
\begin{proof}
\begin{enumerate}
  \item
  If $\tpp\in\Tpx\csps$
  then some $\ea\in\galXs$ has $\tpIa\StrAs\ea = \di\tpp$,
  so $\tpp(\ea) = \ci{\tpIa\StrAs\ea} = \tpp$.

  If $\ea\in\galXs$ then $\tpIa\StrAs\ea = \di\tpp$ for some $\tpp\in\Tpx\csps$,
  so $\tpp(\ea) = \ci{\tpIa\StrAs\ea} = \tpp$.

  \item
  If $\tpt\in\cii\csps$ then some $\ea\in\galXs$ and $\eb\in\galXs\sub\set\ea$
  have $\tpIab\StrAs\ea\eb = \dii\tpt$, so
  $\tpIab\StrXs\ea\eb = \cii{\tpIab\StrAs\ea\eb} = \tpt$.

  If $\ea\in\galXs$ and $\eb\in\galXs\sub\set\ea$ then $\tpIab\StrAs\ea\eb =
  \dii\tpt$ for some $\tpt\in\cii\csps$, so
  $\tpIab\StrXs\ea\eb = \tpt$.

  \item
  If $\tpt\in\cie\csps$ then some $\ea\in\galXs$ and $\eb\in\domAs\sub\galXs$
  have $\tpIab\StrAs\ea\eb = \die\tpt$, so
  $\tpt = \cie{\tpIab\StrAs\ea\eb} \in \stps(\ea)$.

  Let $\ea\in\galXs$ and let $\tpt\in\stps(\ea)$ be cosmic.
  Then $\tpt = \cie{\tpIab\StrAs\ea\eb}$ for some $\eb\in\domAs\sub\galXs$,
  so $\tpt\in\cie\csps$.
\end{enumerate}
\end{proof}

\begin{definition}
A \emph{certificate} $\Cert$ for the type instance~$\TI$ is a nonempty set of
locally consistent cosmic spectrums over $\TI$ satisfying the following
conditions:
\begin{itemize}
  \item[\condcertTc]\label{cond:certTc}
  If $\tpt\in\TIc$ then some $\csps\in\Cert$ has $\tpt\in\cie\csps$.
  \item[\condcertTg]\label{cond:certTg}
  If $\tpt\in\TIg$ then some $\csps\in\Cert$ has $\tpt\in\cii\csps$.
  \item[\condcertn]\label{cond:certn}
  If $\tpn\in\TN\TI$ and $\csps,\cspsp\in\Cert$ have $\tpn\in\Tpx\csps$ and
  $\tpn\in\Tpx\cspsp$, then $\cspsp = \csps$.
\end{itemize}
\end{definition}

\begin{remark}\label{rem:many-cert-p}
Let $\Cert$ be a certificate for the type instance $\TI$.
If $\tpp\in\TP\TI$ then some $\csps\in\Cert$ has $\tpp\in\Tpx\csps$.
\end{remark}
\begin{proof}
Let $\tpp\in\TP\TI$, so some $\tpt\in\TI$ has $\tpx\tpt = \tpp$.
If $\tpt$ is cosmic,
by~\refcondcertTc{} some $\csps\in\Cert$ has $\tpt\in\cie\csps$,
so $\tpp\in\Tpx\csps$.
If $\tpt$ is galactic,
by~\refcondcertTg{} some $\csps\in\Cert$ has $\tpt\in\cii\csps$,
so by~\Cref{rem:lccsp-sub} $\tpp\in\Tpx\csps$.
\end{proof}

\begin{remark}\label{rem:many-cert-n}
Let $\Cert$ be a certificate for the type instance $\TI$.
If $\tpn\in\TN\TI$, then a unique $\csps\in\Cert$ has $\tpn\in\Tpx\csps$.
\end{remark}
\begin{proof}
Let $\tpn\in\TN\TI$. By~\Cref{rem:many-cert-p}, some $\csps\in\Cert$ has
$\tpn\in\Tpx\csps$.
By~\refcondcertn{} such $\csps\in\Cert$ is unique.
\end{proof}

\begin{lemma}[Certificate extraction]\label{lem:cert-ext-many}
Let $\StrA$ be a nobly distinguished model for the type instance $\TI$ over the
$\vFo2\Eea\sze\agrefine$-classified signature $\ClSig\SigS\sms$ such that
$\relE=\at\StrA\se$ is not full on $\domA$. For each \twotype/ $\tpt\in\TI$ let
$\eat\tpt\neq\ebt\tpt\in\domA$ realize $\tpt$, that is
$\tpIab\StrA{\eat\tpt}{\ebt\tpt}=\tpt$.
Let
\[
\Cert = \setbd{\cspIX\StrA{\relE[\eat\tpt]}}{\tpt\in\TI}.
\]
Then $\Cert$ is a certificate for $\TI$.
Note that the size of $\Cert$ is polynomially bounded with respect to the size
of $\TI$.
\end{lemma}
\begin{proof}
That $\Cert$ is nonempty follows since $\relE$ is not full on $\domA$.
That the elements of $\Cert$ are locally consistent cosmic spectrums follows
from~\Cref{rem:nd-csps}. We check the conditions for a certificate:
\begin{itemize}
  \item[\refcondcertTc]
  Let $\tpt\in\TIc$ be any cosmic type, let $\eat\tpt\in\domA$ be the
  selected $\xx$-element for $\tpt$ and let
  $\csps=\cspIX\StrA{\relE[\eat\tpt]}$.
  Then $\ebt\tpt\in\domA\sub\relE[\eat\tpt]$ and so
  $\tpt=\tpIab\StrA{\eat\tpt}{\ebt\tpt} \in \die\csps$.
  \item[\refcondcertTg]
  Let $\tpt\in\TIg$ be any galactic type, and consider $\eat\tpt$ and
  $\ebt\tpt$. Then $(\eat\tpt,\ebt\tpt)\in\relE$, so
  $\tpt=\tpIab\StrA{\eat\tpt}{\ebt\tpt}\in\dii\csps$ for $\csps =
  \cspIX\StrA{\eat\tpt}$.
  \item[\refcondcertn]
  Let $\tpn\in\TN\TI$ be any noble type.
  Then a unique galaxy $\galX$ realizes $\tpn$.
  Then if $\csps\in\Cert$ has $\tpn\in\Tpx\csps$, then $\csps=\cspIX\StrA\galX$.
\end{itemize}
\end{proof}

\begin{theorem}[Certificate expansion]\label{lem:cert-exp-many}
Let $\Cert$ be a certificate for the type instance $\TI$ over the
$\vFo2\Eea\sze\agrefine$-classified signature $\ClSig\SigS\sms$.
Then $\TI$ has a finite model.
More precisely, let $\pt\geq\card{T}$ be a parameter.
Then $\TI$ has a finite model in which each worker type is realized at least
$\pt$ times.
\end{theorem}
\begin{proof}
We use induction on $\sze$. We build a model $\StrA$ for $\TI$.
Note that $\Cert$ is a nonempty set of cosmic spectrums over $\TI$, and
by~\refcondcspIE, $\TI$ must contain a cosmic type.
Hence any model of $\TI$ has at least $2$ galaxies.

First for every $\csps \in \Cert$, we obtain a finite model $\StrAs$ for $\TIs$
having the property that if $\csps$ is noble then every worker type over $\TIs$
is realized at least $(3\pt)$ times in $\StrAs$.
\begin{itemize}
  \item
  First suppose $\sze=1$. Let $\csps\in\Cert$ be any locally consistent
  cosmic spectrum from $\Cert$. Consider the spectral type instance $\TIs$.
  Let $\pt' = \max\set{t,\card{\TIs}}$.
  Then $\TIs$ is realizable over $\vFo2$.
  By~\Cref{lem:cert-extract} the type instance $\TIs$ has a finite $\vFo2$-model
  $\StrAs$ in which every worker type is realized at least $(3\pt')$ times,
  so also at least $(3\pt)$ times.

  \item
  Next suppose $\sze > 1$ and the induction hypothesis for $(\sze-1)$.
  Let $\csps\in\Cert$ be any locally consistent cosmic spectrum from $\Cert$,
  so $\TIs$ is realizable over $\vFo2\Eea{(\sze-1)}\agrefine$.
  By~\Cref{lem:noble-distinguishability}, some promotion $\TIsp$ of
  $\TIs$ has a nobly distinguished $\vFo2\Eea{(\sze-1)}\agrefine$-model
  $\StrBsp$.
  Note that since $\TI$ is realizable and contains a cosmic type, $\TIsp$
  must also contain a cosmic type, so $\StrBsp$ must have at least two galaxies.
  By~\Cref{lem:cert-ext-many}, there exists a certificate $\Certsp$ for $\TIsp$
  over $\vFo2\Eea{(\sze-1)}\agrefine$.
  Let $\pt' = \max\set{t,\card{\TIsp}}$.
  By induction hypothesis, $\TIsp$ has a finite
  $\vFo2\Eea{(\sze-1)}\agrefine$-model $\StrAsp$ in which every worker type is realized at least $(3\pt')$ times.
  Then the reduct $\StrAs$ of $\StrAsp$ to the language of $\TIs$ is a finite
  model for $\TIs$. If $\csps$ is noble, by~\Cref{rem:lccsp-nw} any worker type
  over $\TI$ is realized at least $(3\pt)$ times in $\StrAs$.
\end{itemize}
Let $\StrXs$ be the galaxy of $\StrAs$.
The galaxies of $\StrA$ are:
\begin{itemize}
  \item
  A single copy of $\StrXs$ for every noble $\csps \in \Cert$.
  These galaxies are the \emph{noble galaxies}.
  \item
  $3\pt$ copies $\StrXsij\csps\ii\jj$ of $\StrXs$ for every peasant
  $\csps \in \Cert$, where $\ii \in \set{0,1,2}$ and $\jj \in [1,\pt]$.
  These galaxies are the \emph{peasant galaxies}.
\end{itemize}
Let $\stps(\ea)$ be the intended star-type of $\ea$ and let
$\tpp(\ea) = \tpx{(\stps(\ea))}$ be the intended \onetype/ of $\ea$ for
$\ea\in\domA$.
Let $\domAtp\tpp = \setbd{\ea\in\domA}{\tpp(\ea)=\tpp}$ be the set of elements
having intended \onetype/ $\tpp\in\TP\TI$.
Consider any noble $\tpn\in\TN\TI$.
By~\Cref{rem:many-cert-n} a unique $\csps\in\Cert$ has $\tpn\in\Tpx\csps$.
Note that $\csps$ is noble and $\domAtp\tpn\subseteq\galXs$.

If $\tpk\in\TK\TI$ is any king type, then since $\tpk$ is noble, there is a
unique $\csps\in\Cert$ having $\tpk\in\Tpx\csps$.
By~\Cref{rem:lccsp-ki}, $\di\tpk\in\TK\TIs$ is an internal spectral king type,
so $\domAtp\tpk = \set{\ea^\tpk} \subseteq \galXs$ is a singleton, so
$\ea=\ea^\tpk$ is the unique $\ea\in\domA$ having $\tpp(\ea) = \tpk$.

If $\tpn\in\TN\TI\sub\TK\TI$ is any noble type that is not a king type,
then by~\Cref{rem:lccsp-nw}
$\di\tpn\in\TW\TIs$ is an internal worker spectral type for the unique
(noble) $\csps\in\Cert$ having $\tpn\in\Tpx\csps$.
So $\domAtp\tpn = \setbd{\ea\in\galXs}{\tpIa\StrAs\ea=\di\tpn}$ and
since there are at least $3\pt$ elements from $\StrAs$ realizing the worker
type $\di\tpn$, we may choose a partition
$\domAtp\tpn = \domAtpi\tpn0 \cup \domAtpi\tpn1 \cup \domAtpi\tpn2$ such that
$\card{\domAtpi\tpn\ii}\geq\pt$ for $\ii\in\set{0,1,2}$.

If $\tpp\in\TPs\TI$ is any peasant type,
let $\Certtp\tpp = \setbd{\csps\in\Cert}{\tpp\in\Tpx\csps}$ be the set of
(peasant) cosmic spectrums including $\tpp$.
By~\Cref{rem:many-cert-p}, $\Certtp\tpp$ is nonempty.
Then:
\[
  \domAtp\tpp = \setbd{\ea\in\galXsij\csps\ii\jj}{
  \csps\in\Certtp\tpp,
  \ii\in\set{0,1,2},
  \jj\in[1,\pt],
  \tpp(\ea) = \tpp}.
\]
By~\Cref{rem:gal-char}:
\[
  \domAss\tpp = \setbd{\ea\in\galXsij\csps\ii\jj}{
  \csps\in\Certtp\tpp,
  \ii\in\set{0,1,2},
  \jj\in[1,\pt],
  \tpIa\StrAs\ea = \di\tpp}.
\]

Consider the partition
$\domAtp\tpp = \domAtpi\tpp0 \cup \domAtpi\tpp1 \cup \domAtpi\tpp2$, where:
\[
  \domAtpi\tpp\ii = \setbd{\ea\in\galXsij\csps\ii\jj}{
  \csps\in\Certtp\tpp,
  \jj\in[1,\pt],
  \tpp(\ea)=\tpp}.
\]
Then $\card{\domAtpi\tpp\ii}\geq\pt$ and whenever $\tpp,\tppp\in\TP\TI$ and
$\ii\neq\iip\in\set{0,1,2}$,
no $\ea\in\domAtpi\tpp\ii$ and $\eap\in\domAtpi\tppp\iip$ are in the same
galaxy.
\begin{description}
\item[Realization of kings]
Let $\tpkp\in\TK\TI$ be any king type,
let $\cspsp\in\Cert$ be the unique (noble) cosmic spectrum having
$\tpkp\in\Tpx\cspsp$
and let $\ea = \as\tpkp\in\galXsp$ be the unique element in $\domA$ having
$\tpp(\ea) = \tpkp$.
Let $\stpsp = \stps(\ea)$ be the intended star-type of $\ea$, so $\tpkp =
\tpx\stpsp$.
Note that some \twotype/ is already assigned between $\ea$ and each
other element from the galaxy $\galXsp$ of $\ea$.
Let $\eb\in\domA\sub\galXsp$ be any element outside the galaxy of $\ea$.
Let $\tpp = \tpp(\eb)$ and $\stps = \stps(\eb)$ be the intended \onetype/ and
star-type of $\eb$, respectively.
Let $\StrXs_{(ij)}$ be the galaxy of $\eb$,
so $\tpp\in\Tpx\csps$ and $\eb\in\galXs_{(ij)} \neq \galXsp$.
By construction $\cspsp\neq\csps$, since $\StrA$ contains a unique noble galaxy
for each noble cosmic spectrum from $\Cert$ and since $\cspsp$ is noble.
Then $\tpkp\not\in\Tpx\csps$.
Indeed, if $\tpkp\in\Tpx\csps$ then since $\tpkp\in\Tpx\cspsp$,
we have a contradiction of~\refcondcertn.
Then $\tpp\neq\tpkp$, since $\tpp\in\Tpx\csps$.
So $\tpkp\in\nb\TI\tpp\cap\TK\TI$ and by~\refcondstpky{} there is a unique
$\tpt\in\stps$ having $\tpy\tpt=\tpkp$.
If $\tpt$ is galactic, then $\tpt\in\cii\csps$ by construction, so
$\tpkp = \tpy\tpt \in \Tpx\csps$ --- a contradiction.
So $\tpt$ must be cosmic.
Assign $\tpIab\StrA\eb\ea = \tpt$.
We claim that this assignments are appropriate.

First, these assignments are symmetric between kings:
suppose that $\eb$ is a king and let $\tpk = \tpp = \tpp(\eb) \neq \tpkp$ be its
intended \onetype/.
Then $\tpk\in\nb\TI\tpkp\cap\TK\TI$ and by~\refcondstpky, there is a unique
$\tptp\in\stps(\ea) = \stpsp$ such that $\tpy\tptp = \tpkp$.
We claim that $\tptp = \inv\tpt$.
Indeed, since $\tpt\in\stps$ is cosmic we have $\tpt\in\cie\csps$,
so $\inv\tpt\in\TIc$,
so some $\cspspp\in\Cert$ has $\inv\tpt\in\cie\cspspp$ by~\refcondcertTc.
So $\tpk = \tpx{(\inv\tpt)} \in \Tpx\cspspp$, so $\cspspp=\csps$.
Then some $\eap\in\galXs$ has
$\inv\tpt\in\stps(\eap)$.
But then $\tpp(\eap) = \tpk$, so $\eap = \ea$.
So $\inv\tpt\in\stpsp$ and since $\tpy{(\inv\tpt)} = \tpkp \in \TK\TI$,
by~\refcondstpky{} we must have $\tptp = \inv\tpt$.

Next, every $\tpt\in\stpsp = \stps(\ea)$ is realized.
If $\tpt$ is galactic, then some
$\eb\in\galXs\sub\set\ea$ has $\tpIab\StrXs\ea\eb=\tpt$,
so $\tpt$ is realized within the galaxy of $\ea$.
If $\tpt$ is cosmic, then $\inv\tpt$ is cosmic and by~\refcondcertTc{} some
$\csps\in\Cert$ has $\inv\tpt\in\cie\csps$.
Then some $\eb\in\galXs$ has
$\inv\tpt\in\stps(\eb)$, so some $\eb\in\domA\sub\galXs$ has
$\inv\tpt\in\stps(\eb)$.
But $\tpy{(\inv\tpt)}=\tpkp\in\TK\TI$,
so $\inv\tpt\in\stps(\eb)$ is the unique having $\tpy{(\inv\tpt)}=\tpkp$,
so we had assigned $\tpIab\StrA\eb\ea=\inv\tpt$.

\item[Realization of workers]
Let $\tpp\in\TW\TI$ be any worker type
and let $\ea \in \domAtpi\tpp\ii$ be any element having intended \onetype/
$\tpp$.
Let $\iip = (\ii+1\bmod3)\in\set{0,1,2}$ be the index of the next copy of
elements.
Consider the cosmic spectrum $\csps\in\Cert$ for $\ea$:
if $\tpp$ is noble, then let $\csps\in\Cert$ be such that $\ea\in\galXs$;
otherwise $\tpp$ is peasant so let $\csps\in\Cert$ and $\jj\in[1,\pt]$ be such
that $\ea\in\galXs_{\ii\jj}$.
Consider $\stps=\stps(\ea)$ and let $\tpt\in\stps$ be any.
If $\tpt$ is galactic, then it is realized between $\ea$ and some other element
in the galaxy of $\ea$.
If $\tpy\tpt\in\TK\TI$ is a king type, then we have already seen that it is
realized during the realization of kings.

So only the case where $\tpt$ is cosmic and $\tppp=\tpy\tpt \in \TW\TI$ is a
worker type remains.
Let $\TU=\setbd{\tpu\in\stps}{\tpy\tpu=\tppp}$ be the set of all \twotypes/
parallel to $\tpt$ in $\stps$.
Note that $\card{\TU} \leq \pt$.
We simultaneously find distinct $\ebt\tpu$ from the \emph{next copy} of elements
for the assignments $\tpIab\StrA\ea{\ebt\tpu} = \tpu$:
Since $\card{\domAtpi\tppp\iip}\geq\pt$, there are enough such elements.
We claim that every element from $\domAtpi\tppp\iip$ is from a galaxy different
than the galaxy of $\ea$.
If $\tppp$ is a peasant type, this is immediate by our remark right after we
defined $\domAtpi\tppp\iip$.

Next, suppose that $\tppp \in \TN\TI$ is a noble worker type.
We claim that $\tppp\not\in\Tpx\csps$.
Suppose that $\tppp\in\Tpx\csps$.
Since $\tpt\in\stps$ is cosmic, we have that $\tpt\in\cie\csps$.
Since $\tpy\tpt = \tppp$, we have $\tppp\in\Tpy\csps$.
By~\Cref{rem:lccsp-xy}, some (cosmic) $\tptp\in\cie\csps$ connects $\tppp$ with
itself --- a contradiction.
So $\tppp\not\in\Tpx\csps$, so each element from $\domAtpi\tppp\iip$ is not from
the galaxy of $\ea$.

These assignments are consistent, since they have been made between elements
from consecutive copies.

\item[Completion]
Suppose that $\ea\neq\eb\in\domA$ are any elements that have not yet been
assigned a \twotype/.
Then $\ea$ and $\eb$ come from distinct galaxies.
We claim that some cosmic $\tpt\in\TIc$ has $\tpx\tpt=\tpp$ and
$\tpy\tpt=\tppp$.
Let $\tpp=\tpp(\ea)$ and $\tppp=\tpp(\eb)$ and let $\StrXs$ be the galaxy
of~$\ea$.

First suppose that $\tppp$ is noble.
If $\tppp\in\Tpx\csps$, then $\csps$ is noble, so $\eb$ and $\ea$ come from the
same galaxy --- a contradiction.
Otherwise $\tppp\in\Tpy\csps$ and by~\Cref{rem:lccsp-xy} some $\tpt\in\cie\csps$
has $\tpx\tpt=\tpp$ and $\tpy\tpt=\tppp$.

Next suppose that $\tppp$ is peasant.
Then by~\Cref{rem:lccsp-ps} $\tppp\in\Tpy\csps$ and so by~\Cref{rem:lccsp-xy}
some $\tpt\in\cie\csps$ has $\tpx\tpt=\tpp$ and $\tpy\tpt=\tppp$.
\end{description}
\end{proof}

\begin{remark}\label{rem:nd-no-cosmic-type}
Let $\sze\geq1$ and let $\TI$ be a type instance over the classified signature
$\ClSig\SigS\sms$ over $\vFo2\Eea\sze\agrefine$.
Suppose that $\TI$ contains no cosmic type.
Then $\TI$ has a (finite) model over $\vFo2\Eea\sze\agrefine$ iff $\TI$ has a
(finite) model over $\vFo2\Eea{(\sze-1)}\agrefine$.
\end{remark}
\begin{proof}
The forward direction is immediate.
For the backward direction, let $\se$ be the coarsest equivalence symbol
over $\SigS$ and suppose that $\StrA$ is a (finite) model for $\TI$ over
$\vFo2\Eea{(\sze-1)}\agrefine$.
Since $\TI$ contains no cosmic type and $\se(\xx,\xx)\in\tpt$ for every
$\tpt\in\TI$, the symbol $\se$ must be interpreted as the full relation on
$\domA$.
Hence $\StrA$ is a $\vFo2\Eea\sze\agrefine$-structure, so $\StrA$ is a (finite)
model for $\TI$ over $\vFo2\Eea\sze\agrefine$.
\end{proof}

\begin{proposition}
Let $\sze\geq0$.
The type realizability problem for $\vFo2\Eea\sze\agrefine$ coincides with the
finite type realizability problem for $\vFo2\Eea\sze\agrefine$ and is in $\cNP$.
\end{proposition}
\begin{proof}
We use induction on $\sze$.
If $\sze=0$, this is~\Cref{prop:tprealiz-1}.
Suppose that $\sze\geq1$ and assume the induction hypothesis for $(e-1)$.
Consider any type instance $\TI$ over the classified signature $\ClSig\SigS\sms$
over $\vFo2\Eea\sze\agrefine$.

First suppose that $\TI$ contains no cosmic types.
Then by~\Cref{rem:nd-no-cosmic-type} $\TI$ has a (finite) model over
$\vFo2\Eea\sze\agrefine$ iff $\TI$ has a (finite) model over
$\vFo2\Eea\sze\agrefine$ so the claim follows by induction hypothesis.

Next suppose that $\TI$ contains a cosmic type.
Then guess a promotion $\TIp$ of $\TI$ and a polynomial certificate
$\Cert_{\bullet}$ for $\TIp$ and declare that $\TI$ has a (finite) model. By
induction hypothesis, the property that the certificate $\Cert$ consists of \emph{locally consistent} cosmic
spectrums can be \emph{verified in nondeterministic polynomial time}.
Let us check the correctness of this procedure.
\begin{itemize}
  \item
  If $\TI$ has a (finite) model, then by~\Cref{lem:noble-distinguishability} some
  promotion $\TIp$ has a (finite) nobly distinguished model. In this case since
  $\TI$ is realizable and contains a cosmic type, $\TIp$ must contain a cosmic
  type, so any model of $\TIp$ must contain at least two galaxies.
  Let $\StrA_{\bullet}$ be a nobly distinguished model for $\TIp$.
  By~\Cref{lem:cert-ext-many}, there is a polynomial certificate
  $\Cert_{\bullet}$ for $\TIp$.
  \item
  Suppose that $\TIp$ is a promotion for $\TI$ and $\Cert_{\bullet}$ is a
  certificate for $\TIp$.
  By~\Cref{lem:cert-exp-many}, $\TIp$ has a finite model $\StrA_{\bullet}$. Then
  the reduct $\StrA$ of $\StrA_{\bullet}$ to the language of $\TI$ is a finite
  model for $\TI$.
\end{itemize}
\end{proof}

\begin{corollary}\label{cor:twovar-log}
For any $\sze \geq 1$, the logic $\vFo2\Eea\sze\agrefine$ has the finite model
property and its (finite) satisfiability problem is in $\cNExpTime$.

By~\Cref{prop:global-to-refine-n} and~\Cref{prop:local-to-refine-n}, the same
holds for $\vFo2\Eea\sze\agglobal$ and
$\vFo2\Eea\sze\aglocal$.
\end{corollary}

\begin{corollary}
The logic $\vFo2\Eea\nosze\agrefine$ has the finite model property and its
(finite) satisfiability problem is in $\ceNExpTime{2}$.

By~\Cref{prop:global-to-refine} and~\Cref{prop:local-to-refine}, the same holds
for $\vFo2\Eea\nosze\agglobal$ and
$\vFo2\Eea\sze\aglocal$.
\end{corollary}