\chapter{Extending QuTiP with Quantum Information Functionality}
\chaptermark{Extending QuTiP with QI Functionality}

Now we are ready to deal with the primary concern of this project: extending QuTiP with QI functionality, focusing in particular on quantum entanglement tests and measures. This chapter details the implementation of these functions. All the new functions written will be stored in a module \texttt{quantinf} to be easily accessible from other programs.
\par We start by importing the modules that we shall use as our base.
\begin{verbatim}
from qutip import *
import numpy as np
\end{verbatim}
For convenience we can import functions by name to avoid having to use the \texttt{module.function} convention when using them.
\begin{verbatim}
from numpy import log2
\end{verbatim}
\par We now start with the entanglement tests that we saw in chapter 3.
\section{Purity of Reduced DM}
The most primitive entanglement test we saw in chapter 1 is to check if the reduced density matrix of a bipartite state represents a mixed state. We saw that for entangled states, the reduced density matrix will always be mixed. Let us keep in mind though that this test only works if the joint density matrix is a pure state and fails for mixed states.
\par The logical structure of this function is such that it would make sense to divide it into many smaller functions so that the code is easily reusable. Hence we define separate functions for checking purity of complete and reduced density matrices and make them depend on each other as needed. The function that we are after is \texttt{ismixed\_reduced}. The others defined before it can be thought of as helper functions.
\begin{verbatim}
def purity(dm):
    """ Calculates trace of density matrix square

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    Returns
    -------
    purity:
        Purity of the state. 1 for pure, 0.5 for maximally mixed.

    """
    if dm.type == 'ket':
        dm = ket2dm(dm)
    if dm.type != 'oper':
        raise TypeError("Input must be a state ket or density matrix")
    purity = (dm**2).tr()
    return purity

def purity_of_reduced(rho):
    """ Calculates trace of reduced density matrix square

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    Returns
    -------
    purityreduced:
        Purity of the reduced DM. 1 for pure, 0.5 for maximally mixed.

    """

    rhopartial = ptrace(rho,0)
    purityreduced = purity(rhopartial)
    return purityreduced

def ispure(dm):
    """ Checks whether or not a density matrix represents a pure state

    Parameters
    ----------
    dm : qobj/array-like
        Density operator representing the state.

    -------
    pure : bool
        Whether or not the state is pure. True: Pure, False: Mixed.

    """

    if np.round(purity(dm),8) == 1:
        return True
    else:
        return False

def ismixed_reduced(dm):
    """ One way to check for entanglement is that the reduced density
    matrix is mixed. This function checks for that criterion.

    Parameters
    ----------
    dm : qobj/array-like
        Density operator representing the state.

    -------
    mixed : bool
        Whether or not the reduced DM is mixed. True: Mixed, False: Pure

    """

    if np.round(purity_of_reduced(dm),8) != 1:
        return True
    else:
        return False

\end{verbatim}
What we are basically doing in \texttt{ismixed\_reduced} is that we are taking the partial trace of the input density matrix with respect to B and then squaring it and taking its trace to see if the reduced DM is mixed. \texttt{ismixed\_reduced} will return \texttt{True} if the reduced DM is mixed and return \texttt{False} if it is pure.

\section{The Peres-Horodecki Criterion}
The Peres-Horodecki criterion is a more general and reliable test for checking entanglement. It works for both pure and mixed states. It involves taking the partial transpose of the joint density matrix with respect to one of the subsystems (say B) and checking for negative eigenvalues. If there is a negative eigenvalue then the state is entangled.
\begin{verbatim}
def peres_horodecki_bipartite(rho, mask=[0,1]):
    """ Tests the given bipartite state for Peres-Horodecki criterion

    Parameters
    ----------
    rho: qobj/array-like
        Density operator for the state
    mask: list of int, length 2
        mask used for partial transpose

    Returns
    -------
    isentangled: bool
        True for entangled, False for disentangled

    """
    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")
    rhopt = partial_transpose(rho,mask)
    rhopt_eigs = rhopt.eigenenergies()
    if min(rhopt_eigs) < 0:
        isentangled = True
    else:
        isentangled = False
    return isentangled
\end{verbatim}
This function will return \texttt{True} if a given density matrix represents an entangled state by the Peres-Horodecki criterion and return \texttt{False} otherwise.
\\
\par Now we implement some entanglement measures.
\section{Entropy of Entanglement}
Recall the definition of entropy of entanglement:
\begin{align*}
S(\rho_A) = - tr \{ \rho_A \log \rho_A \}
\end{align*}
where $\rho_A$ is the reduced density matrix for subsystem $A$, obtained by partial trace w.r.t. subsystem $B$.
\begin{verbatim}
def entropy_entg(rho, base=2):
    """ Calculates the entropy of entanglement of a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix
    base:
        Base of log

    Returns:
    --------
    ent_entg: Entropy of Entanglement

    """
    if rho.type == 'ket':
        rho = ket2dm(rho)
    if rho.type != 'oper':
        raise TypeError("Input must be density matrix")
    rhopartial = ptrace(rho,0)
    ent_entg = entropy_vn(rhopartial,base)
    return ent_entg
\end{verbatim}

\section{Linear Entropy of Entanglement}
Linear entropy of entanglement is the linear approximation to entropy of entanglement and is given by
\begin{align*}
S_L(\rho_A) = 1 - tr(\rho_A^2)
\end{align*}
where $\rho_A$ is obtained by a partial trace w.r.t. $B$.
\par To write the function for linear entropy of entanglement, we first need to write our own function for linear entropy which is more suited to the task than QuTiP's current implementation. Then we define a linear entropy of entanglement function based on that.
\begin{verbatim}
def linear_entropy(dm, normalize=False):
    """ Returns the linear entropy of a state.

    Parameters
    ----------
    dm : qobj/array-like
        Density operator representing the state.
    normalize : bool
        Optional argument to normalize linear entropy such that the
        completely mixed state has LE = 1 rather than 1-1/d. [1]
        Default: False

    ----------
    le : float
        Linear entropy

    ----------
    References:
        [1] "Linear entropy and Bell inequalities", Santos and Ferrero,
            Phys. Rev. A 62, 024101

    """
    if dm.type not in ('oper','ket'):
        raise TypeError("Input must be a Qobj representing a state.")
    if dm.type=='ket':
        dm = ket2dm(dm)

    le = 1 - (dm**2).tr()
    if normalize:
        d = dm.shape[0]
        le = le * d/(d-1)
    return le

def entropy_linear_entg(rho, normalize=True):
    """ Calculates the linear entropy of entanglement of a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix
    normalize : bool
        Optional argument to normalize linear entropy of entanglement
        such that the completely entangled state has value = 1.
        Default: True

    Returns:
    --------
    linent_entg: Linear Entropy of Entanglement

    """
    if rho.type == 'ket':
        rho = ket2dm(rho)
    if rho.type != 'oper':
        raise TypeError("Input must be density matrix")
    rhopartial = ptrace(rho,0)
    linent_entg = linear_entropy(rhopartial,normalize)
    return linent_entg
\end{verbatim}

\section{Renyi Entanglement Entropy}
Renyi entanglement entropy of a density matrix $\rho$ is
\begin{align*}
S_\alpha (\rho_A) &= \frac{1}{1-\alpha} \log \left( \sum_i q_i^\alpha \right) , \quad \alpha \neq 1 \: \text{and} \: \alpha > 0
\end{align*}
where $\alpha$ is the Reyi index and $q_i$ are the eigenvalues of the reduced density matrix.
\par Once again we define two separate functions to allow for maximum code reuse: one function to calculate the usual Renyi entropy of the whole density matrix and the other to pass the reduced density matrix to the former function.
\begin{verbatim}
def entropy_renyi(rho,alpha):
    """ Calculate Renyi entropy of the density matrix with given index
    (Currently limited to 2-level systems)

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    alpha: Renyi index alpha

    Returns
    -------
    ent_rn: Renyi Entropy

    """
    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")

    qi = rho.eigenenergies()

    if alpha == 1:
        ent_rn = entropy_vn(rho,2)
    elif alpha >= 0:
        ent_rn = ( 1/(1-alpha) ) * log2 ( sum( qi**alpha ) )
    else:
        raise ValueError("alpha must be a non-negative number")

    return ent_rn

def entropy_renyi_entg(rho,alpha):
    """ Calculate Renyi entropy of entanglement for the DM with given index
    (Currently limited to 2-level systems)

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    alpha: Renyi index alpha

    Returns
    -------
    ent_rn_entg: Renyi Entropy of Entanglement

    """
    rhopartial = ptrace(rho,0)
    ent_rn_entg = entropy_renyi(rhopartial,alpha)
    return ent_rn_entg

\end{verbatim}

\section{Negativity}
Negativity of a density matrix $\rho$ is given by
\begin{align*}
N(\rho) = \frac{\lVert \rho^{T_A} \rVert_1 - 1}{2}
\end{align*}
Implementing in QuTiP:
\begin{verbatim}
def negativity(rho,mask=[1,0]):
    """ Calculate the negativity for a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix

    Returns:
    --------
    neg : Negativity

    """

    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")
    rhopt = partial_transpose(rho,mask)
    neg = ( rhopt.norm() - 1 ) / 2
    return neg
\end{verbatim}

\section{Logarithmic Negativity}
Logarithmic negativity for a density matrix $\rho$ is given by
\begin{align*}
E_N(\rho) = log_2 \lVert \rho^{T_A} \rVert_1
\end{align*}
Implementing in QuTiP:
\begin{verbatim}
def log_neg(rho,mask=[1,0]):
    """ Calculate the logarithmic negativity for a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix

    Returns:
    --------
    logneg: Logarithmic Negativity

    """

    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")
    rhopt = partial_transpose(rho,mask)
    logneg = log2( rhopt.norm() )
    return logneg
\end{verbatim}

\section{Other Quantum Information Functions}
\par Some functions other than entanglement tests and measures were also implemented as part of exploration of the various QI toolboxes.
\subsection{Schmidt Decomposition}
If $\ket{\psi_{AB}}$ is a pure bipartite state and $\{\ket{i^A}\}$ and $\{\ket{j^B}\}$ are the bases for subsystems $A$ and $B$, then $\ket{\psi_{AB}}$ can be written as
\begin{align*}
\ket{\psi_{AB}} &= \sum_{i,j} \beta_{ij} \ket{i^A} \ket{j^B}
\end{align*}
where $\beta_ij$ is a complex number.
\par The Schmidt decomposition rewrites the state in two new bases $\{\ket{\psi_i^A}\}$ and $\{\ket{\phi_i^B}\}$ such that
\begin{align*}
\ket{\psi_{AB}} &= \sum_{i} \alpha_i \ket{\psi_i^A} \ket{\phi_i^B}
\end{align*}
Now the sum is only over one index $i$ which is easier to calculate.
\par To implement Schmidt decomposition, we take some hints from QETLAB and use the singular value decomposition function from NumPy's linear algebra module.
\begin{verbatim}
def schmidt_decomposition(vec):
    """ Schmidt decomposition of a bipartite vector
    Logic based on the implementation in QETLAB 0.9
    which was written by Nathaniel Johnston (nathaniel@njohnston.ca)
    and as of this port, last updated on December 1, 2012

    Parameters
    ----------
    vec : qobj, ket vector of product state
        ket vector representing the bipartite state

    -------
    Returns:
    [s, u, v]
    s : list of floats
        Schmidt coefficients
    u : list of Qobj
        list of left Schmidt vectors of ket
    v : list of Qobj
        list of right Schmidt vectors of ket

    """

    if vec.type != 'ket':
        raise TypeError("Input must be a ket vector.")
    if len(vec.dims[0])==1:
        raise TypeError("Input must be a joint state.")

    dim = vec.dims[0][0]
    vecnp = vec.full()
    vecnpr = np.reshape(vecnp,[dim,dim])
    um,s,vm = np.linalg.svd(vecnpr)

    s = list(s)

    def extract_vecs(mat):
        veclist = list()
        for j in range(mat.shape[1]):
            veclist.append(Qobj(mat[:,j]))
        return veclist
    u = extract_vecs(um)
    v = extract_vecs(vm)

    return [s,u,v]
\end{verbatim}

\subsection{Kullback-Leibler Distance}
The Kullback-Leibler distance - also known as relative entropy in quantum information - is a measure of distance between two density matrices. It is not a true distance measure because it is not symmetric. Nevertheless it is a useful function in quantum information theory as it generates a good entanglement measure when used in conjunction with relative entropy of entanglement (see section 3.7.7). \cite{vedralteleportation}
\begin{align*}
S(\rho||\sigma) &= tr ( \rho \log \rho - \rho \log \sigma )
\end{align*}
Implementing in code:
\begin{verbatim}
def dist_kl(rho, sgm):
    """ Calculates the Kullback-Leibler distance (a.k.a. relative entropy)
    between DMs rho and sgm representing two-level systems.

    Parameters
    ----------
    rho : qobj/array-like
        First density operator.

    sgm : qobj/array-like
        Second density operator.

    Returns
    -------
    kldist : float
        Relative Entropy between rho and sgm.

    Examples
    --------
    >>>

    """

    if rho.type != 'oper' or sgm.type != 'oper':
        raise TypeError("Inputs must be density matrices..")

    ent_vn = entropy_vn(rho,2)

    r_eigs = rho.eigenenergies()
    s_eigs = sgm.eigenenergies()
    # too small negtive values may give trouble
    s_eigs = np.round(s_eigs,8)

    kldist = -ent_vn
    for pj, qj in zip(r_eigs,s_eigs):
        if qj==0:
            pass
        else:
            kldist -= pj * log2(qj)

    kldist = abs(kldist)
    return kldist
\end{verbatim}

\section{Example Usage of the New Functions}
We can now explore some example cases with the newly written QI functions.

\subsection{Time Evolution under a Joint Hamiltonian}
Let us go back to the example of two particles getting entangled as a result of time evolution under a joint Hamiltonian from section 5.2.3. This time we shall plot the different tests and measures of entanglement as the state evolves.
\begin{verbatim}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Time Evolution under a Joint Hamiltonian

An initially separable state evolves under a joint Hamiltonian
and becomes entangled. This program plots various entanglement
tests and measures as the state evolves.

@author: Muhammad Saad <muhammad.saad@yandex.com>
"""

from qutip import *
import numpy as np
from matplotlib import pyplot as plt
import quantinf

h = basis(2,0)
v = basis(2,1)

psi_a = 1/np.sqrt(2) * ( h + v )
psi_b = 1/np.sqrt(2) * ( h + v )
psi_ab_t0 = tensor(psi_a,psi_b)
print("Original state of psi_ab at time t0 =\n",psi_ab_t0.full())
print()
rho_ab_t0 = ket2dm(psi_ab_t0)

hmlt = Qobj([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,-1]])
hmlt.dims = [[2, 2], [2, 2]]
print("Hamiltonian H =\n", hmlt.full())
print()

tf = np.pi/2
t = np.linspace(0,tf)

measures = {'ent_entg':None,'linent_entg':None,'neg':None,'logneg':None,
            'entrn_entg_2':None,'entrn_entg_3':None,'entrn_entg_4':None,
            'cncr':None,'entrel':None,'reducedmixed':None,'phcrit':None}

for i in measures:
    measures[i] = np.zeros(len(t))

for i in range(len(t)):
    hmltpr = (-1j*t[i]) * hmlt
    hmlt_tf = hmltpr.expm()
    psi_ab_tf = hmlt_tf * psi_ab_t0
    rho_ab_tf = ket2dm(psi_ab_tf)
    # Round off very small decimals
    measures['cncr'][i] = concurrence(rho_ab_tf)
    measures['ent_entg'][i] = quantinf.entropy_entg(rho_ab_tf)
    measures['linent_entg'][i] = quantinf.entropy_linear_entg(rho_ab_tf)
    measures['entrn_entg_2'][i] = quantinf.entropy_renyi_entg(rho_ab_tf,2)
    measures['entrn_entg_3'][i] = quantinf.entropy_renyi_entg(rho_ab_tf,3)
    measures['entrn_entg_4'][i] = quantinf.entropy_renyi_entg(rho_ab_tf,4)
    measures['neg'][i] = quantinf.negativity(rho_ab_tf)
    measures['logneg'][i] = quantinf.log_neg(rho_ab_tf)
    measures['entrel'][i] = \
                 quantinf.dist_kl(ptrace(rho_ab_tf,0),ptrace(rho_ab_t0,0))
    measures['reducedmixed'][i] = quantinf.ismixed_reduced(rho_ab_tf)
    measures['phcrit'][i] = quantinf.peres_horodecki_bipartite(rho_ab_tf)

print("Final operator at time tf (t0 + pi*hbar/2) =\n",hmlt_tf.full())
print()
print("Final state of psi_ab at time tf =\n", psi_ab_tf.full())
print()

# Font size for plot
fsz = 12
# Limit for x axis
xlm = [0,tf]
# Limit for y axis
ylm = [0,1]

plt.figure(1)
plt.suptitle("Comparison of measures and tests of entanglement",fontsize=14)
plt.subplots_adjust(hspace=.5)

plt.subplot(331)
plt.plot(t, measures['ent_entg'])
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Entr. Entanglement",fontsize=fsz)
plt.title("Increase in Entropy of Entanglement",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(332)
plt.plot(t, measures['linent_entg'])
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Lin. Entr. Entanglement",fontsize=fsz)
plt.title("Increase in Linear Entropy of Entanglement",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(333)
plt.plot(t, measures['entrn_entg_2'],'r-', label='alpha = 2')
plt.plot(t, measures['entrn_entg_3'],'b--', label='alpha = 3')
plt.plot(t, measures['entrn_entg_4'],'g:', label='alpha = 4')
plt.legend(loc='upper left', fontsize='small')
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Renyi Entanglement Entropy",fontsize=fsz)
plt.title("Renyi Entanglement Entropy with diff. values of alpha",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(334)
plt.plot(t, measures['neg'])
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Negativity",fontsize=fsz)
plt.title("Increase in Negativity",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(335)
plt.plot(t, measures['logneg'])
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Log Negativity",fontsize=fsz)
plt.title("Increase in Logarithmic Negativity",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(336)
plt.plot(t, measures['entrel'])
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("K-L Distance",fontsize=fsz)
plt.title("Increase in K-L Dist. of rho_A from its original state",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(337)
plt.plot(t, measures['cncr'])
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Concurrence",fontsize=fsz)
plt.title("Increase in Concurrence",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

xlm = [-0.04,tf+0.02]
ylm = [-0.1,1.1]

plt.subplot(338)
plt.plot(t, measures['reducedmixed'], 'ro')
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Entangled Status",fontsize=fsz)
plt.title("Entanglement Test: Reduced DM is Mixed",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(339)
plt.plot(t, measures['phcrit'], 'ro')
plt.xlabel("Time t",fontsize=fsz)
plt.ylabel("Entangled Status",fontsize=fsz)
plt.title("Entanglement Test: Peres-Horodecki Criterion",fontsize=fsz)
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.show()

\end{verbatim}
\par This program generates a number of plots for various tests and measures of entanglement as the state evolves in time. Time in these plots is measured in units of $\hbar$. Let us take a look at all of them individually.
\pagebreak
\subsubsection{Mixedness of the Reduced Density Matrix}
This plot shows whether or not the state of an individual subsystem (the reduced density matrix) is mixed at all stages in its evolution. We plot the result as \texttt{False = 0} or \texttt{True = 1}. \texttt{True} means that the reduced density matrix is mixed and \texttt{False} means the reverse.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-08.png}
    \caption{Checking for whether or not the reduced density matrix of the pair is mixed at various stages in the Hamiltonian evolution.\newline \texttt{0 = False = Separable,    1 = True = Entangled} }
    \label{fig: Time Evolution: Mixedness of Reduced DM}
  \end{center}
\end{figure}
\end{center}

This entanglement test has the limitation that it only works for pure states. However that is not a problem here because we are dealing with a pure state.
\par We see that the particles start getting entangled as soon as they start interacting with each other.

\pagebreak
\subsubsection{The Peres-Horodecki Criterion}
This is the plot of whether or not the state is entangled by the Peres-Horodecki criterion during all stages in its evolution. It follows the same convention: 0 represents \texttt{False} which means the state is separable; 1 represents \texttt{True} which means the state is entangled.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-09.png}
    \caption{Checking the Peres-Horodecki criterion for entanglement at various stages in the Hamiltonian evolution.\newline \texttt{0 = False = Separable,    1 = True = Entangled}}
    \label{fig: Time Evolution: Peres-Horodecki Critetrion}
  \end{center}
\end{figure}
\end{center}

This entanglement test is more general and works well for both pure and mixed states.
\par We see that the particles start getting entangled as soon as they start interacting with each other.

\pagebreak
\subsubsection{Entropy of Entanglement and Linear Entropy of Entanglement}
The particle pair starts off with a disentangled state. Both the entropy of entanglement and the relative entropy of entanglement at time $t=0$ are zero as expected. As the state evolves and gets entangled, both of the entropies start increasing and reach their maximum values at time $t=\pi\hbar/2$. These two graphs display the trend of increase for both.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-01.png}
    \caption{Increase in the entropy of entanglement of the bipartite state as it evolves under a joint Hamiltonian}
    \label{fig: Time Evolution: Entropy of Entanglement}
  \end{center}
\end{figure}
\end{center}

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-02.png}
    \caption{Increase in the linear entropy of entanglement of the bipartite state as it evolves under a joint Hamiltonian}
    \label{fig: Time Evolution: Linear Entropy of Entanglement}
  \end{center}
\end{figure}
\end{center}

The linear entropy of entanglement in this example is calculated with \texttt{normalize=True}, which normalizes it so that the completely entangled state has value 1 rather than $(1-\frac{1}{d})$ \cite{linentropybellineq}. We see that the linear entropy of entanglement closely traces the same path as the entropy of entanglement, since it is a linear approximation, and becomes 1 for the maximally entangled state.

\pagebreak
\subsubsection{Renyi Entanglement Entropies}
The Renyi entanglement entropies start with zero at the disentangled state. As the state evolves, they increase and finally reach the maximum value for the maximally entangled state.
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-03.png}
    \caption{Increase in the Renyi entanglement entropies of the bipartite state for various values of $\alpha$}
    \label{fig: Time Evolution: Renyi Entanglement Entropies}
  \end{center}
\end{figure}

We observe that the minimum and maximum values for all values of $\alpha$ are the same: 0 and 1 respectively. With increasing value of $\alpha$, the curve shifts to the right.
\par Let us look at the Renyi entanglement entropies for a continuous range of $\alpha$ in the following 3-dimensional plot.

\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.68]{figures/renyi-entg-3d.png}
    \caption{Increase in Renyi entanglement entropies with time for a range of values of $\alpha$. Time ranges from 0 to $\pi\hbar/2$ and $\alpha$ ranges from 0 to 10. Z-axis represents the Renyi entanglement entropies for all the combinations.}
    \label{fig: Time Evolution: Renyi Entanglement Entropies (3D)}
  \end{center}
\end{figure}

We observe the same trend for increasing value of $\alpha$. If we single out the curve for $\alpha=1$, we will find that it is the same as the entropy of entanglement.

\pagebreak
\subsubsection{Negativity and Logarithmic Negativity}
Negativity and logarithmic negativity both start at zero for the disentangled state. As the state evolves, they increase and reach their maximum values for the maximally entangled state.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-04.png}
    \caption{Increase in negativity of the bipartite state}
    \label{fig: Time Evolution: Negativity}
  \end{center}
\end{figure}
\end{center}

Negativity of the state starts at 0 when the pair is disentangled. As the state evolves, negativity gradually increases until it reaches 0.5 for the maximally entangled bipartite state.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-05.png}
    \caption{Increase in logarithmic negativity of the bipartite state}
    \label{fig: Time Evolution: Logaritmic Negativity}
  \end{center}
\end{figure}
\end{center}

Logarithmic negativity is an entanglement measure based on negativity that in addition has the additivity property. This plot illustrates the trend for increase in logarithmic negativity as it starts with 0 for the disentangled state and reaches a maximum value of 1 for the maximally entangled state.

\pagebreak
\subsubsection{Kullback-Leibler Distance}
The Kullback-Leibler distance can be used for defining an entanglement measure by searching over the space of all possible separable states. However here for simplicity we take a different route. We measure the KL-distance of one of the subsystems with respect to its original disentangled state to see how it changes in time. Please note that this particular graph \textit{does not} show an entanglement measure. It is just a speculative experiment.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-06.png}
    \caption{As the bipartite system evolves under the joint Hamiltonian, the Kullback-Leibler distance of both subsystems $\rho_A$ and $\rho_B$ with respect to their respective original states increases. This indicates that the density matrix of each subsystem is evolving and becoming different from what it was.}
    \label{fig: Time Evolution: Kullback-Leibler Distance}
  \end{center}
\end{figure}
\end{center}

To use (computationally) the Kullback-Leibler distance for defining an entanglement measure, we will have to generate the set of all possible separable states and compute the distances from our state $\rho_{AB}$ to each of them. The minimum of these distances will give the \textit{relative entropy of entanglement} for our joint density matrix $\rho_{AB}$.

\pagebreak
\subsubsection{Concurrence}
To compute concurrence, the function \texttt{concurrence} already available in QuTiP has been used. This plot illustrates the increasing trend in concurrence under the Hamiltonian evolution in question.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-07.png}
    \caption{Increase in concurrence of the bipartite state under joint Hamiltonian evolution}
    \label{fig: Time Evolution: Concurrence}
  \end{center}
\end{figure}
\end{center}

We observe that concurrence starts with zero for the disentangled state and becomes 1 for the maximally entangled state.

\pagebreak
\subsubsection{What Happens After Time $\pi\hbar/2$?}
It should be noted that the plot upto time $\pi\hbar/2$ is not the complete picture. The system does not stay constantly at the point of maximum entanglement under this Hamiltonian evolution. We can observe changes in the amount of entanglement if we increase the time interval from $\pi\hbar/2$.
\par For example, here is the plot of concurrence from 0 to $3\pi\hbar$.

\begin{center}
\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/timeevolution-10.png}
    \caption{Concurrence as a function of time under joint Hamiltonian evolution, time ranging from 0 to $3\pi\hbar$. \newline We see that the state keeps oscillating between entangled and disentangled. At times which are multiples of $\pi\hbar$, the state becomes disentangled again.}
    \label{fig: Time Evolution: Concurrence (extended)}
  \end{center}
\end{figure}
\end{center}

\pagebreak

\subsection{Werner States}
An example of a mixed entangled state is a Werner state. Werner states are a useful test case to demonstrate the limitations of entanglement tests and measures which fail for mixed states.
\par A Werner state is defined as:
\begin{align*}
\rho_W = F \ket{\Phi^+} \bra{\Phi^+} + \frac{1-F}{3} \left( \ket{\Phi^-} \bra{\Phi^-} + \ket{\Psi^+} \bra{\Psi^+} + \ket{\Psi^-} \bra{\Psi^-} \right)
\end{align*}
where $0 \leq F \leq 1$ is the \textit{singlet fidelity}.
\par Werner states are inseparable for $F > 1/2$. We shall now see if our entanglement tests and measures work as expected on these states.

\begin{verbatim}
# -*- coding: utf-8 -*-
"""
Werner States
=============
Generate a range of Werner state with possible values of fidelity
and plot various tests and measures of entanglement

@author: Muhammad Saad
"""

from qutip import *
import numpy as np
from matplotlib import pyplot as plt
import quantinf

def werner_state(f):
    phipls = bell_state('00')
    phimns = bell_state('01')
    psipls = bell_state('10')
    psimns = bell_state('11')
    werner = ( f * phipls*phipls.dag() ) + ( ((1-f)/3) * \
             ( (phimns*phimns.dag()) + (psipls*psipls.dag()) \
             + (psimns*psimns.dag()) ) )
    return werner

fid = np.linspace(0,1)
measures = {'ent_entg':None,'neg':None,'logneg':None,'cncr':None,
            'reducedmixed':None,'phcrit':None}

for m in measures:
    measures[m] = np.zeros(len(fid))

for i in range(len(fid)):
    wrn = werner_state(fid[i])
    measures['cncr'][i] = concurrence(wrn)
    measures['ent_entg'][i] = quantinf.entropy_entg(wrn)
    measures['neg'][i] = quantinf.negativity(wrn)
    measures['logneg'][i] = quantinf.log_neg(wrn)
    measures['reducedmixed'][i] = quantinf.ismixed_reduced(wrn)
    measures['phcrit'][i] = quantinf.peres_horodecki_bipartite(wrn)

# Font size for plot
fsz = 12
# Limit for x axis
xlm = [0,1]
# Limit for y axis
ylm = [0,1]

plt.figure(1)
plt.suptitle("Tests and Measures of Entanglement on Werner States",fontsize=14)
plt.subplots_adjust(hspace=.5)

plt.subplot(321)
plt.xlabel("Fidelity",fontsize=fsz)
plt.ylabel("Concurrence",fontsize=fsz)
plt.title("Concurrence of Werner States",fontsize=fsz)
plt.plot(fid, measures['cncr'])
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(322)
plt.xlabel("Fidelity",fontsize=fsz)
plt.ylabel("Entr. Entanglement",fontsize=fsz)
plt.title("Entropy of Entanglement of Werner States",fontsize=fsz)
plt.plot(fid, measures['ent_entg'])
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(323)
plt.xlabel("Fidelity",fontsize=fsz)
plt.ylabel("Negativity",fontsize=fsz)
plt.title("Negativity of Werner States",fontsize=fsz)
plt.plot(fid, measures['neg'])
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(324)
plt.xlabel("Fidelity",fontsize=fsz)
plt.ylabel("Log. Negativity",fontsize=fsz)
plt.title("Logarithmic Negativity of Werner States",fontsize=fsz)
plt.plot(fid, measures['logneg'])
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

xlm = [-0.04,1.02]
ylm = [-0.1,1.1]

plt.subplot(325)
plt.xlabel("Fidelity",fontsize=fsz)
plt.ylabel("Entangled Status",fontsize=fsz)
plt.title("Entanglement Test: Reduced DM is Mixed",fontsize=fsz)
plt.plot(fid, measures['reducedmixed'], 'D')
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.subplot(326)
plt.xlabel("Fidelity",fontsize=fsz)
plt.ylabel("Entangled Status",fontsize=fsz)
plt.title("Entanglement Test: Peres-Horodecki Criterion",fontsize=fsz)
plt.plot(fid, measures['phcrit'], 'D')
plt.xlim(xlm)
plt.ylim(ylm)
plt.grid(True)

plt.show()

\end{verbatim}

\par This program gnerates a number of plots for various entanglement tests and measures. The x-axis on all these plots represents singlet fidelity. Each value of singlet fidelity corresponds to a unique Werner state. The entanglement tests and measures are plotted as a function of the fidelity.
\par In the time evolution case from section 6.9.1, we dealt with a pure state and saw that all the tests and measures discussed so far work for pure states. However we also stressed that some of them do not work for mixed states. Some, for example, depend on the mixedness of reduced density matrix and cannot differentiate between entangled states whose reduced density matrices are mixed and states that are already mixed.
\par Werner states are a useful test case for determining which entanglement tests and measures work for mixed states. Here we take a look at some of them, starting with the ones that fail.

\subsubsection{Mixedness of Reduced Density Matrix}
This plot shows whether or not the reduced density matrix is mixed for all values of singlet fidelity for Werner states. The value 1 indicates \texttt{True} which means that the reduced density matrix is mixed. The value 0 indicates \texttt{False} which means that the reduced density matrix is pure.

\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/wernerstates-reducedmixed.png}
    \caption{Applying the entanglement test of mixedness of reduced density matrix to all possible Werner states.\newline \texttt{1 = True = Entangled,    0 = False = Separable}}
    \label{fig: Werner States: Mixedness of Reduced DM}
  \end{center}
\end{figure}

We can see that this test is failing to differentiate between separable and entangled states, showing all Werner states as entangled. This is in contrast to the time evolution example where we were dealing with a pure state. Hence we can conclude that this entanglement test is only good for pure states.

\subsubsection{Entropy of Entanglement}

\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/wernerstates-entropyentg.png}
    \caption{Entropy of Entanglement for all possible Werner states.}
    \label{fig: Werner States: Entropy of Entanglement}
  \end{center}
\end{figure}
We can see that this measure is failing to differentiate between separable and entangled states, showing maximal entanglement for all Werner states. This is due to the dependence of this measure on mixedness of the reduced density matrix, which makes it unable to identify states that are already mixed. Entropy of entanglement is good only as a measure of entanglement for pure states.
\newline
\par However, there are still a number of entanglement tests and measures that work with pure states as well as mixed states. The following are some of those tests and measures.

\subsubsection{The Peres-Horodecki Criterion}

\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/wernerstates-phcriterion.png}
    \caption{Applying the Peres-Horodecki criterion to all possible Werner states.\newline \texttt{1 = True = Entangled,    0 = False = Separable}}
    \label{fig: Werner States: Peres-Horodecki Criterion}
  \end{center}
\end{figure}

\par We can see that the Peres-Horodecki criterion is working as a reliable entanglement witness and showing Werner states with $F>1/2$ as entangled. It worked well for pure states in the Hamiltonian evolution case and it is also working for mixed states in the case of Werner states. This shows that the Peres-Horodecki criterion is a general entanglement witness which works well for pure as well as mixed states.

\subsubsection{Negativity and Logarithmic Negativity}

\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/wernerstates-negativity.png}
    \caption{Negativity of Werner states for all possible values of singlet fidelity.}
    \label{fig: Werner States: Negativity}
  \end{center}
\end{figure}

We see that negativity starts increasing after $F=1/2$ and goes to the maximum value of 0.5 showing the state for $F=1$ as maximally entangled. This shows that negativity is a reliable measure of entanglement for both pure and mixed states.

\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/wernerstates-logneg.png}
    \caption{Logarithmic Negativity of Werner states for all possible values of singlet fidelity.}
    \label{fig: Werner States: Logarithmic Negativity}
  \end{center}
\end{figure}

As with negativity, logarithmic negativity also starts increasing after $F=1/2$ and reaches its maximum value for $F=1$. This shows that logarithmic negativity is also a good measure of entanglement for both pure and mixed states.

\subsubsection{Concurrence}

\begin{figure}[H]
  \begin{center}
    \includegraphics[scale=0.62]{figures/wernerstates-concurrence.png}
    \caption{Concurrence of Werner states for all possible values of singlet fidelity. The states start getting entangled after singlet fidelity exceeds $1/2$ and reach maximum entanglement for fidelity $F=1$.}
    \label{fig: Werner States: Concurrence}
  \end{center}
\end{figure}
We see that concurrence stays 0 for $F \leq 1/2$ when the states are disentangled. It starts increasing after $F$ exceeds $1/2$ and reaches its maximum value 1 for the maximally entangled state at $F=1$. This indicates that concurrence works for mixed states too and is a reliable measure of entanglement for both pure and mixed states.

\section{A Note About Optimizations}
QuTiP has a number of tricks available to make the functions much faster than our current implementation. However, since this project deals with the initial phase of implementing QI functions, we have not dwelled on the problem of speed optimizations. Rather we have focused primarily on implementing as many QI functions as possible. Later works on the subject can add the goal of making them faster.


\section{Task D}
\label{sec:task-d}

The logarithmic strain model from chapter 5 \cite{Ekh2016} was implemented
in Matlab function \texttt{neo\_hooke\_plast\_log\_strain.m} (see
section \ref{app:matlab-code}) and applied to solve the same boundary
value problem as in section \ref{sec:task-c}.
Figure \ref{fig:forming-bvp-log-strain} compares the total reaction force
plotted against displacement of the top nodes for the two models.
The two models yield virtually the same graphs.
\begin{figure}[th]
  \centering
  % Reaction force
    \begin{tikzpicture}
      \begin{axis}[
        width = 0.95\textwidth,
        height=\axisdefaultheight,
        tick label style={/pgf/number format/fixed},
        try min ticks=6,
        minor tick num=1,
        grid=both,
        legend style={at={(0.5,0)},
          anchor=south},
        xlabel = {\(u_{x}\), [mm]},
        ylabel = {Reaction force, [N]},
        xmin=0, xmax=5,
        ]
        \addplot[mark=none, blue] table[skip first n=1]
        {data/force_displacement_forming.dat};
        \addlegendentry{Neo-Hooke}
        \addplot[mark=none, red, dashed] table[skip first n=1]
        {data/force_displacement_log_strain.dat};
        \addlegendentry{Neo-Hooke, log strain}
      \end{axis}
    \end{tikzpicture}
    \caption{Reaction force versus displacement.}
  \label{fig:forming-bvp-log-strain}
\end{figure}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../main"
%%% End:


% Part: first-order-logic
% Chapter: model-theory
% Section: nonstandard-arithmetic

\documentclass[../../../include/open-logic-section]{subfiles}

\begin{document}

\olfileid{mod}{bas}{nsa}
\section{Non-standard Models of Arithmetic}

\begin{defn}
Let $\Lang{L_N}$ be the !!{language} of arithmetic, comprising a
!!{constant} $\Obj{0}$, a 2-place !!{predicate} $<$, a 1-place
!!{function} $\prime$, and 2-place !!{function}s $+$ and $\times$.
\begin{enumerate}
\item The \emph{standard model} of arithmetic is the !!{structure}
  $\Struct{N}$ for $\Lang{L_N}$ having $\Nat = \{ 0, 1, 2, \dots\}$
  and interpreting $\Obj{0}$ as $0$, $<$ as the less-than relation
  over~$\Nat$, and $\prime$, $+$ and $\times$ as successor, addition,
  and multiplication over $\Nat$, respectively.
\item \emph{True arithmetic} is the theory $\Theory{N}$.
\end{enumerate}
\end{defn}

When working in $\Lang{L_N}$ we abbreviate each term of
the form $\Obj{0}^{\prime\dots\prime}$, with $n$ applications of the
successor function to $\Obj{0}$, as~$\num{n}$.

\begin{defn}
A !!{structure}~$\Struct{M}$ for $\Lang{L_N}$ is \emph{standard} if
and only $\Struct{N} \iso \Struct{M}$.
\end{defn}

\begin{thm}\ollabel{thm:non-std}
There are non-standard !!{enumerable} models of true arithmetic.
\end{thm}

\begin{proof}
Expand $\Lang{L_N}$ by introducing a new !!{constant}~$c$, and
consider the theory
\[
\Theory{N} \cup \Setabs{\num{n} < c}{n \in \Nat}.
\]
The theory is finitely satisfiable, so by compactness it has a model
$\Struct{M}$, which can be taken to be !!{enumerable} by the Downward
L\"owenheim-Skolem theorem. Where $\Domain{M}$ is the domain of
$\Struct{M}$, let $\Struct{M}$ interpret the non-logical constants of
$\Lang{L}$ as $\mathbf{z} = \Assign{\Obj{0}}{M} \in \Domain{M}$, ${\prec} =
\Assign{<}{M} \subseteq M^2$, $* = \Assign{\prime}{M} \colon
\Domain{M} \to \Domain{M}$, and $\oplus = \Assign{+}{M}, \otimes =
\Assign{\times}{M} \colon \Domain{M}^2 \to \Domain{M}$. For each $x
\in \Domain{M}$, we write $x^*$ for the element of $\Domain{M}$
obtained from $x$ by application of~$*$.

Now, if $h$ were an isomorphism of $\Struct{N}$ and $\Struct{M}$,
there would be $n \in \Nat$ such that $h(n) = \Assign{c}{M}$.  So let
$s$ be any assignment in $\Struct{N}$ such that $s(x) = n$. Then
$\Sat{N}{\eq[\num{n}][x]}[s]$; by the proof of \olref[iso]{thm:isom},
also $\Sat{M}{\eq[\num{n}][x]}[h \circ s]$, so that $\Assign{c}{M} =
\mathbf{z}^{*\cdots *}$ (with $*$ iterated $n$ times). But this is impossible
since by assumption $\Sat{M}{\num{n} < c}$ and $\prec$ is
irreflexive. So $\Struct{M}$ is non-standard.
\end{proof}

\begin{prob}
A relation $R$ over a set $X$ is \emph{well-founded} if and only if
there are no infinite descending chains in~$R$, i.e., if there are no
$x_0$, $x_1$, $x_2$,~\dots in $X$ such that $\dots x_2Rx_1Rx_0$.  Assuming
Zermelo-Fraenkel set theory~$ZF$ is consistent, show that there are
non-well-founded models of $ZF$, i.e., models $\mathfrak{M}$ such that
$\dots x_2 \in x_1 \in x_0$.
\end{prob}

Since the non-standard model $\Struct{M}$ from \olref{thm:non-std} is
elementarily equivalent to the standard one, a number of properties of
$\Struct{M}$ can be derived. The rest of this section is devoted to
such a task, which will allow us to obtain a precise characterization
of !!{enumerable} non-standard models of $\Theory{N}$.

\begin{enumerate}
\item No member of $\Domain{M}$ is $\prec$-less than itself: the sentence
  $\lforall[x][\lnot x < x]$ is true in $\Struct{N}$ and therefore in
  $\Struct{M}$.
\item By a similar reasoning we obtain that $\prec$ is a \emph{linear
    ordering} of $\Domain{M}$, i.e., a total, irreflexive, transitive relation
  on $\Domain{M}$.
\item The element $\mathbf{z}$ is the $\prec$-least element of $\Domain{M}$.
\item Any member of $\Domain{M}$ is $\prec$-less than its $*$-successor and
  $x^*$ is the $\prec$-least member of $\Domain{M}$ greater than $x$.
\item $\Struct{M}$ contains an initial segment (of $\prec$) isomorphic
  to $\Nat$: $\mathbf{z}, \mathbf{z}^*, \mathbf{z}^{**}, \dots$, which
  we call the \emph{standard part} of $\Domain{M}$. Any other member
  of $\Domain{M}$ is \emph{non-standard}. There must be non-standard
  members of $\Domain{M}$, or else the function $h$ from the proof of
  \olref{thm:non-std} is an isomorphism.  We use $n, m, \dots$ as
  !!{variable}s ranging on this standard part of $\Struct{M}$.
\item Every non-standard element is greater than any standard one;
  this is because for every $n \in \Nat$,
  \[
  \Sat{N}{\lforall[z][(\lnot(\eq[z][\Obj{0}] \lor
  \dots \lor \eq[z][\num{n}]) \lif \num{n} < z)]},
  \]
  so if $z \in \Domain{M}$ is different from all the standard
  elements, it must be \emph{greater} than all of them.
\item Any member of $\Domain{M}$ other than $\mathbf{z}$ is the
  $*$-successor of some unique element of $\Domain{M}$, denoted by
  $^*x$. If $x = y^*$ then both $x$ and $y$ are standard if one of
  them is (and both non-standard if one of them is).
\item Define an equivalence relation $\approx$ over $\Domain{M}$ by
  saying that $x \approx y$ if and only if for some \emph{standard}
  $n$, either $x \oplus n = y$ or $y \oplus n =x$. In other words, $x
  \approx y$ if and only if $x$ and $y$ are a finite distance
  apart. If $n$ and $m$ are standard then $n \approx m$. Define the
  \emph{block} of $x$ to be the equivalence class $[x] = \Setabs{y}{x
  \approx y}$.
\item Suppose that $x \prec y$ where $x \not\approx y$. Since
  $\Sat{N}{\lforall[x][\lforall[y][(x < y \lif (x' < y \lor x' =
      y))]]}$, either $x^* \prec y$ or $x^* = y$. The latter is
  impossible because it implies $x \approx y$, so $x \prec
  y$. Similarly, if $x \prec y$ and $x \not\approx y$, then $x \prec
  {^*y}$. Therefore if $x \prec y$ and $x \not\approx y$, then every
  $w \approx x$ is $\prec$-less than every $v \approx y$. Accordingly,
  each block $[x]$ forms a doubly infinite chain
  \[
  \cdots \prec  {^{**}x} \prec {^*}x \prec x \prec x^* \prec x^{**}
  \prec \cdots
  \]
  which is referred to as a $Z$-chain because it has the order type of
  the integers.
\item The $\prec$ ordering can be lifted up to the blocks: if $x \prec y$
  then the block of $x$ is less than the block of $y$. A block is
  \emph{non-standard} if it contains a non-standard element. The
  standard block is the least block.
\item There is no least non-standard block: if $y$ is non-standard
  then there is a $x \prec y$ where $x$ is also non-standard and $x
  \not\approx y$. Proof: in the standard model $\Struct{N}$, every
  number is divisible by two, possibly with remainder one, i.e.,
  $\Sat{N}{\lforall[y][\lforall[x][(y = x + x \lor y = x + x +
        \Obj{0}')]]}$. By elementary equivalence, for every $y \in
  \Domain{M}$ there is $x \in \Domain{M}$ such that either $x \oplus x
  = y$ or $x \oplus x \oplus \mathbf{z}^*= y$. If $x$ were standard,
  then so would be $y$; so $x$ is non-standard. Furthermore, $x$ and
  $y$ belong to different blocks, i.e, $x \not\approx y$.  To see
  this, assume they did belong to the same block, i.e., $x \oplus n =
  y$ for some standard $n$. If $y = x \oplus x$, then $x \oplus n = x
  \oplus x$, whence $x = n$ by the cancellation law for addition
  (which holds in $\Struct{N}$ and therefore in $\Struct{M}$ as well),
  and $x$ would be standard after all. Similarly if $y = x \oplus x
  \oplus \mathbf{z}^*$.
\item By a similar argument, there is no greatest block.
\item The ordering of the blocks is dense: if $[x]$ is less than $[y]$
  (where $x \not\approx y$), then there is a block $[z]$ distinct from
  both that is between them. Suppose $x \prec y$. As before, $x \oplus
  y$ is divisible by two (possibly with remainder) so there is a $u
  \in \Domain{M}$ such that either $x \oplus y = u \oplus u$ or $x
  \oplus y = u \oplus u \oplus \mathbf{z}^*$. The element $u$ is the
  average of $x$ and $y$, and so is between them. Assume $x \oplus y =
  u \oplus u$ (the other case being similar): if $u \approx x$ then
  for some standard $n$:
  \[
  x \oplus y = x \oplus n \oplus x \oplus n,
  \]
  so $y = x \oplus n \oplus n$ and we would have $x \approx y$,
  against assumption. We conclude that $u \not\approx x$. A similar
  argument gives $u \not\approx y$.
\end{enumerate}
The non-standard blocks are therefore ordered like the rationals: they
form !!a{enumerable} linear ordering without endpoints.  It follows
that for any two !!{enumerable} non-standard models $\Struct{M}_1$ and
$\Struct{M_2}$ of true arithmetic, their reducts to the language
containing $<$ and $=$ only are isomorphic. Indeed, an isomorphism $h$
can be defined as follows: the standard parts of $\Struct{M_1}$ and
$\Struct{M_2}$ are isomorphic to the standard model $\Struct{N}$ and
hence to each other. The blocks making up the non-standard part are
themselves ordered like the rationals and therefore by
\olref[dlo]{thm:cantorQ} are isomorphic; an isomorphism of the blocks
can be extended to an isomorphism \emph{within} the blocks by matching
up arbitrary elements in each, and then taking the image of the
successor of $x$ in $\Struct{M_1}$ to be the successor of the image of
$x$ in $\Struct{M_2}$. Note that it does \emph{not} follow that
$\mathfrak{M}_1$ and $\mathfrak{M}_2$ are isomorphic in the full
language of arithmetic (indeed, isomorphism is always relative to a
signature), as there are non-isomorphic ways to define addition and
multiplication over $\Domain{M_1}$ and $\Domain{M_2}$. (This also
follows from a famous theorem due to Vaught that the number of
countable models of a complete theory cannot be~2.)

\begin{prob}
Show that there can be no greatest block in a non-standard model of
arithmetic.
\end{prob}

\begin{prob}
Let $\Lang{L}$ be the first-order !!{language} containing $<$ as its
only !!{predicate} (besides $\eq$), and let $\Struct{N} = (\Nat,
<)$. All the finite or cofinite subsets of $\Struct{N}$ are
definable. Show that these are the \emph{only} definable subsets of
$\Struct{N}$.

(Hint: First, let $\Obj{prc}(x,y)$ be the
$\Lang{L}$-formula abbreviating ``$x$ is the immediate predecessor
of $y$:''
\[
x<y \land \lnot \lexists[z][(x<z \land z < y)].
\]
Now, to any definable subset of $\Struct{N}$ there corresponds a
formula $!A(x)$ in $\Lang{L}$. For any such $!A$,
consider the sentence $!D$:
\[
\lexists[x][\lforall[y][\lforall[z][((x<y \land x<z \land \Obj{prc}(y,z)
  \land !A(y)) \lif !A(z))]]].
\]
Show that $\Sat{N}{!D}$ if and only if the subset of
$\Struct{N}$ defined by $!A$ is either finite or cofinite.

Now, let $\Struct{M}$ be a non-standard model elementarily
equivalent to $\Struct{N}$.  If $a \in \Domain{M}$ is
non-standard, let $b, c \in \Domain{M}$ be greater than $a$, and
let $b$ be the immediate predecessor of~$c$. Then there is an
automorphism $h$ of $\Domain{M}$ such that $h(b)=c$
(why?). Therefore, if $b$ satisfies $!A$, so does $c$ (why?). It
follows that $!D$ is true in $\Struct{M}$, and hence also in
$\Struct{N}$. But this implies that the subset of $\Struct{N}$
defined by $!A$ is either finite or co-finite.
\end{prob}

\end{document}


\chapter{Solutions for Chapter 2}

\ex{2.1}
In order to solve this problem, many assumptions must be made.
Different people may assume slightly different values for parameters.
This is OK.
What is important is making good assumptions and checking our conclusions to make sure they are reasonable.

To solve for the current in the LED, let us assume we know the LED is red, so it follows the red LED curve from Figure 2.8 in the book.
Let us also assume the transistor is acting like a closed switch, so the collector voltage of Q1 is close to \SI{0}{\V}.
Let us also assume the LED is ON, so it's voltage is approximately $V_\text{LED} = \SI{2}{V}$. From the preceding assumptions, we can calculate that the LED current is
\[I_\text{LED} = \frac{\SI{3.3}{\V} - \SI{2}{\V}}{\SI{330}{\ohm}} = \frac{\SI{1.3}{\V}}{\SI{330}{\ohm}} \approx \SI{3.94}{\mA}\]
If we use Figure 2.8 (from the textbook) to check our numbers, we see that a current of \SI{3.94}{\mA} roughly correlates to an LED voltage of $V_\text{LED} = \SI{1.7}{V}$.  We will run the same calculation again to reduce our error.
\[I^{*}_\text{LED} = \frac{\SI{3.3}{\V} - \SI{1.7}{\V}}{\SI{330}{\ohm}} = \frac{\SI{1.6}{\V}}{\SI{330}{\ohm}} \approx \mans{\SI{4.85}{\mA}}\]

In order to determine the minimum current gain required from our transistor, we must calculate the base current.
Let us assume we know the base-emitter voltage $V_\text{BE} = \SI{0.6}{\V}$.
Therefore
\[I_\text{B} = \frac{\SI{3.3}{\V} - \SI{0.6}{\V}}{\SI{10}{\kohm}} = \SI{270}{\uA}\]
So the minimum current gain must be
\[\beta_\text{min} = \frac{I^{*}_\text{LED}}{I_\text{B}} \approx \frac{\SI{4.85}{\mA}}{\SI{270}{\uA}} \approx \mans{18.0}\]

\todoex{2.2}

\todoex{2.3}

\todoex{2.4}

\todoex{2.5}

\todoex{2.6}

\todoex{2.7}

\todoex{2.8}

\todoex{2.9}

\todoex{2.10}

\todoex{2.11}

\todoex{2.12}

\todoex{2.13}

\todoex{2.14}

\todoex{2.15}

\todoex{2.16}

\todoex{2.17}

\todoex{2.18}

\todoex{2.19}

\todoex{2.20}

\todoex{2.21}

\todoex{2.22}

\todoex{2.23}

\todoex{2.24}

\todoex{2.25}

\todoex{2.26}

\todoex{2.27}

\todoex{2.28}

\todoex{2.29}

\todoex{2.30}  % the last Exercise in chapter 2.

% Here ends Chapter 2.


\chapter{Applications of algebraic general topology}

\section{``Hybrid'' objects}

Algebraic general topology allows to construct ``hybrid'' objects of ``continuous'' (as topological spaces)
and discrete (as graphs).

Consider for example $D\sqcup T$ where $D$ is a digraph and $T$ is a topological space.

The $n$-th power $(D\sqcup T)^n$ yields an expression with $2^n$ terms.
So treating $D\sqcup T$ as one object (what becomes possible using algebraic general topology)
rather than the join of two objects may have an exponential benefit for simplicity of formulas.

\section{A way to construct directed topological spaces}

\subsection{Some notation}

I use~$\mathcal{E}$ and $\iota$ notations from {\tt volume-2.pdf}. \fxwarning{Reorder document fragments to describe it before use.}

I remind that $f|_X = f\circ \id_X$ for binary relations, funcoids, and reloid.

$f\parallel_X = f\circ(\mathcal{E}^X)^{-1}$.

$f\square X = \id_X\circ f\circ\id_X^{-1}$.

As proved in {\tt volume-2.pdf}, the following are bijections and moreover isomorphisms (for $R$ being either funcoids or reloids or binary relations):
\begin{enumerate}
\item $\setcond{(f|_X,f\parallel_X)}{f\in R}$;
\item $\setcond{(f\square X,\iota_X f)}{f\in R}$.
\end{enumerate}

As easily follows from these isomorphisms and theorem~\bookref{rect-cont}:

\begin{prop}
For funcoids, reloids, and binary relations:
\begin{enumerate}
\item $f\in\continuous(\mu,\nu)\Rightarrow f\parallel_{A}\in\continuous(\iota_A\mu,\nu)$;
\item $f\in\continuous'(\mu,\nu)\Rightarrow f\parallel_{A}\in\continuous'(\iota_A\mu,\nu)$;
\item $f\in\continuous''(\mu,\nu)\Rightarrow f\parallel_{A}\in\continuous''(\iota_A\mu,\nu)$.
\end{enumerate}
\end{prop}

\subsection{Directed line and directed intervals}

Let $\mathfrak{A}$ be a poset. We will denote $\overline{\mathfrak{A}}=\mathfrak{A}\cup\{-\infty,+\infty\}$ the poset
with two added elements $-\infty$ and $+\infty$, such that $+\infty$ is strictly greater than every element of~$\mathfrak{A}$
and $-\infty$ is strictly less.

\fxnote{Generalize from~$\mathbb{R}$ to a wider class of posets.}

\begin{defn}
For an element~$a$ of a poset~$\mathfrak{A}$
\begin{enumerate}
\item $J_{\geq}(a) = \setcond{x\in\mathfrak{A}}{x\geq a}$;
\item $J_{>}(a) = \setcond{x\in\mathfrak{A}}{x>a}$;
\item $J_{\leq}(a) = \setcond{x\in\mathfrak{A}}{x\leq a}$;
\item $J_{<}(a) = \setcond{x\in\mathfrak{A}}{x<a}$;
\item $J_{\ne}(a) = \setcond{x\in\mathfrak{A}}{x\ne a}$.
\end{enumerate}
\end{defn}

\begin{defn}
Let $a$ be an element of a poset~$\mathfrak{A}$.
\begin{enumerate}
\item $\Delta(a) = \bigsqcap^{\mathscr{F}} \setcond{]x;y[}{x,y\in\overline{\mathfrak{A}}, x<a\land y>a}$;
\item $\Delta_{\geq}(a) = \bigsqcap^{\mathscr{F}} \setcond{[a;y[}{y\in\overline{\mathfrak{A}}, y>a}$;
\item $\Delta_{>}(a) = \bigsqcap^{\mathscr{F}} \setcond{]a;y[}{y\in\overline{\mathfrak{A}}, x<a\land y>a}$;
\item $\Delta_{\leq}(a) = \bigsqcap^{\mathscr{F}} \setcond{]x;a]}{x\in\overline{\mathfrak{A}}, x<a}$;
\item $\Delta_{<}(a) = \bigsqcap^{\mathscr{F}} \setcond{]x;a[}{x\in\overline{\mathfrak{A}}, x<a}$;
\item $\Delta_{\ne}(a) = \Delta(a) \setminus \{a\}$.
\end{enumerate}
\end{defn}

\begin{obvious}
~
\begin{enumerate}
\item $\Delta_{\geq}(a) = \Delta(a)\sqcap^{\mathscr{F}} @J_{\geq}(a)$;
\item $\Delta_{>}(a) = \Delta(a)\sqcap^{\mathscr{F}} @J_{>}(a)$;
\item $\Delta_{\leq}(a) = \Delta(a)\sqcap^{\mathscr{F}} @J_{\leq}(a)$;
\item $\Delta_{<}(a) = \Delta(a)\sqcap^{\mathscr{F}} @J_{<}(a)$;
\item $\Delta_{\ne}(a) = \Delta(a)\sqcap^{\mathscr{F}} @J_{\ne}(a)$.
\end{enumerate}
\end{obvious}

\begin{defn}
~
Given a partial order~$\mathfrak{A}$ and~$x\in\mathfrak{A}$, the following defines complete funcoids:
\begin{enumerate}
\item $\rsupfun{|\mathfrak{A}|}\{x\} = \Delta(x)$;
\item $\rsupfun{|\mathfrak{A}|_{\geq}}\{x\} = \Delta_{\geq}(x)$;
\item $\rsupfun{|\mathfrak{A}|_{>}}\{x\} = \Delta_{>}(x)$;
\item $\rsupfun{|\mathfrak{A}|_{\leq}}\{x\} = \Delta_{\leq}(x)$;
\item $\rsupfun{|\mathfrak{A}|_{<}}\{x\} = \Delta_{<}(x)$;
\item $\rsupfun{|\mathfrak{A}|_{\ne}}\{x\} = \Delta_{\ne}(x)$.
\end{enumerate}
\end{defn}

\begin{prop}
The complete funcoid corresponding to the order topology\footnote{See Wikipedia for a definition of ``Order topology''.}
is equal to $|\mathfrak{A}|$.
\end{prop}

\begin{proof}
Because every open set is a finite union of open intervals, the complete funcoid~$f$ corresponding to the order topology
is described by the formula: $\rsupfun{f}\{x\} = \bigsqcap^{\mathscr{F}}\setcond{]a;b[}{a,b\in\overline{\mathfrak{A}}, a<x\land b>x} =
\Delta(x) = \rsupfun{|\mathfrak{A}|}\{x\}$. Thus $f=|\mathfrak{A}|$.
\end{proof}

\begin{xca}
Show that $|\mathfrak{A}|_{\geq}$ (in general) is not the same as ``right order topology''\footnote{See Wikipedia}.
\end{xca}

\begin{prop}
~
\begin{enumerate}
\item $\rsupfun{|\mathfrak{A}|_{\geq}^{-1}}@X = @\setcond{a\in\mathfrak{A}}{\forall y\in\overline{\mathfrak{A}}:(y>a \Rightarrow X\cap[a;y[\ne\emptyset)}$;
\item $\rsupfun{|\mathfrak{A}|_{>}^{-1}}@X = @\setcond{a\in\mathfrak{A}}{\forall y\in\overline{\mathfrak{A}}:(y>a \Rightarrow X\cap]a;y[\ne\emptyset)}$;
\item $\rsupfun{|\mathfrak{A}|_{\leq}^{-1}}@X = @\setcond{a\in\mathfrak{A}}{\forall x\in\overline{\mathfrak{A}}:(x<a \Rightarrow X\cap]x;a]\ne\emptyset)}$;
\item $\rsupfun{|\mathfrak{A}|_{<}^{-1}}@X = @\setcond{a\in\mathfrak{A}}{\forall x\in\overline{\mathfrak{A}}:(x<a \Rightarrow X\cap]x;a[\ne\emptyset)}$.
\end{enumerate}
\end{prop}

\begin{proof}
$a\in\rsupfun{|\mathfrak{A}|_{\geq}^{-1}}@X \Leftrightarrow
@\{a\} \nasymp \rsupfun{|\mathfrak{A}|_{\geq}^{-1}}@X \Leftrightarrow
\rsupfun{|\mathfrak{A}|_{\geq}}@\{a\} \nasymp @X \Leftrightarrow
\Delta_{\geq}(a) \nasymp @X \Leftrightarrow
\forall y\in\overline{\mathfrak{A}}:(y>a \Rightarrow X\cap[a;y[\ne\emptyset)$.

$a\in\rsupfun{|\mathfrak{A}|_{>}^{-1}}@X \Leftrightarrow
@\{a\} \nasymp \rsupfun{|\mathfrak{A}|_{>}^{-1}}@X \Leftrightarrow
\rsupfun{|\mathfrak{A}|_{>}}@\{a\} \nasymp @X \Leftrightarrow
\Delta_{>}(a) \nasymp @X \Leftrightarrow
\forall y\in\overline{\mathfrak{A}}:(y>a \Rightarrow X\cap]a;y[\ne\emptyset)$.

The rest follows from duality.
\end{proof}

\begin{rem}
On trivial ultrafilters these obviously agree:
\begin{enumerate}
\item $\rsupfun{|\mathbb{R}|_{\geq}}\{x\} = \rsupfun{|\mathbb{R}| \sqcap \geq}\{x\}$;
\item $\rsupfun{|\mathbb{R}|_{>}}\{x\} = \rsupfun{|\mathbb{R}| \sqcap >}\{x\}$;
\item $\rsupfun{|\mathbb{R}|_{\leq}}\{x\} = \rsupfun{|\mathbb{R}| \sqcap \leq}\{x\}$;
\item $\rsupfun{|\mathbb{R}|_{<}}\{x\} = \rsupfun{|\mathbb{R}| \sqcap <}\{x\}$.
\end{enumerate}
\end{rem}

\begin{cor}
~
\begin{enumerate}
\item $|\mathbb{R}|_{\geq} = \Compl(|\mathbb{R}| \sqcap \geq)$;
\item $|\mathbb{R}|_{>} = \Compl(|\mathbb{R}| \sqcap >)$;
\item $|\mathbb{R}|_{\leq} = \Compl(|\mathbb{R}| \sqcap \leq)$;
\item $|\mathbb{R}|_{<} = \Compl(|\mathbb{R}| \sqcap <)$.
\end{enumerate}
\end{cor}

\begin{obvious}
~ \fxnote{also what is the values of $\setminus$ operation}
\begin{enumerate}
\item $|\mathbb{R}|_{\geq} = |\mathbb{R}|_{>} \sqcup 1$;
\item $|\mathbb{R}|_{\leq} = |\mathbb{R}|_{<} \sqcup 1$.
\end{enumerate}
\end{obvious}

\section{Some inequalities}

\fxwarning{Define the ultrafilter ``at the left'' and ``at the right'' of a real number.
Also define ``convergent ultrafilter''.}

Denote $\Delta_{+ \infty} = \bigsqcap_{x \in \mathbb{R}}] x ; + \infty [$ and
$\Delta_{- \infty} = \bigsqcap_{x \in \mathbb{R}}] - \infty ; x [$.

The following proposition calculates $\langle \geq \rangle x$ and $\langle > \rangle x$ for all
kinds of ultrafilters on $\mathbb{R}$:

\begin{prop}
~
\begin{enumerate}
\item\label{g-uf-v-triv} $\supfun{\geq} \{ \alpha \} = [\alpha ; + \infty [$ and
  $\supfun{>} \{ \alpha \} = ]\alpha ; + \infty [$.
\item\label{g-uf-v-right} $\supfun{\geq} x = \supfun{>} x = ] \alpha ; + \infty [$
  for ultrafilter $x$ at the right of a number $\alpha$.
\item\label{g-uf-v-left} $\supfun{\geq} x = \supfun{>} x = \Delta_{<} (\alpha) \sqcup [\alpha ; + \infty [=
  \Delta_{\leq} (\alpha) \sqcup] \alpha ; + \infty [$ for ultrafilter $x$ at the left of a number $\alpha$.
\item\label{g-uf-v-posinf} $\supfun{\geq} x = \supfun{>} x = \Delta_{+ \infty}$ for
  ultrafilter $x$ at positive infinity.
\item\label{g-uf-v-neginf} $\supfun{\geq} x = \supfun{>} x = \mathbb{R}$ for
  ultrafilter $x$ at negative infinity.
\end{enumerate}
\end{prop}

\begin{proof}
~
\begin{widedisorder}
\item[\ref{g-uf-v-triv}] Obvious.
\item[\ref{g-uf-v-right}]
  \begin{gather*}
  \supfun{\geq} x = \bigsqcap^{\mathscr{F}}_{X \in \up x} \supfun{\geq} (X \sqcap] \alpha ; + \infty [) =
  \bigsqcap^{\mathscr{F}}_{X \in \up x}] \alpha ; + \infty [=] \alpha ; + \infty [; \\
  \supfun{>} x = \bigsqcap^{\mathscr{F}}_{X \in \up x} \supfun{>} (X \sqcap] \alpha ; + \infty [) =
  \bigsqcap^{\mathscr{F}}_{X \in \up x}] \alpha ; + \infty [=] \alpha ; + \infty [.
  \end{gather*}
\item[\ref{g-uf-v-left}] $\Delta_{<} (\alpha) \sqcup [\alpha ; + \infty [=
  \Delta_{\leq} (\alpha) \sqcup] \alpha ; + \infty [$ is obvious.
  \[ \supfun{>} x = \bigsqcap^{\mathscr{F}}_{X \in \up x} \supfun{>} X \sqsupseteq \bigsqcap^{\mathscr{F}}_{X \in \up x} (\Delta_{<}
  (\alpha) \sqcup] \alpha ; + \infty [) = \Delta_{<} (\alpha) \sqcup] \alpha ; +
  \infty [ \]
  but $\supfun{\geq} x \sqsubseteq \Delta_{<} (\alpha) \sqcup
  [\alpha ; + \infty [$ is obvious. It remains to take into account that
  $\supfun{>} x \sqsubseteq \supfun{\geq} x$.
\item[\ref{g-uf-v-posinf}] $\supfun{\geq} x = \bigsqcap^{\mathscr{F}}_{X \in \up x} \supfun{\geq} X =
  \bigsqcap^{\mathscr{F}}_{X \in \up x, \inf X \in X}
  \supfun{\geq} (X \sqcap] \alpha ; + \infty [) =
  \bigsqcap^{\mathscr{F}}_{X \in \up x} [\inf X ; + \infty [=
  \bigsqcap^{\mathscr{F}}_{x > \alpha} [x ; + \infty [= \Delta_{+ \infty}$;
  $\supfun{>} x = \bigsqcap^{\mathscr{F}}_{X \in \up x} \supfun{>} X =
  \bigsqcap^{\mathscr{F}}_{X \in \up x, \inf X \in X}
  \supfun{>} (X \sqcap] \alpha ; + \infty [) =
  \bigsqcap^{\mathscr{F}}_{X \in \up x} ]\inf X ; + \infty [=
  \bigsqcap^{\mathscr{F}}_{x > \alpha} [x ; + \infty [= \Delta_{+ \infty}$.
\item[\ref{g-uf-v-neginf}] $\supfun{\geq} x \sqsupseteq \supfun{>} x =
  \bigsqcap^{\mathscr{F}}_{X \in \up x} \supfun{>} X$ but $\supfun{>} X =] - \infty ; + \infty [$ for $X \in \up x$
  because $X$ has arbitrarily small elements.
\end{widedisorder}
\end{proof}

\begin{lem}
$\langle \lvert \mathbb{R} \rvert \rangle x \sqsubseteq \supfun{>} x = \supfun{\geq} x$ for every nontrivial ultrafilter $x$.
\end{lem}

\begin{proof}
$\supfun{>} x = \supfun{\geq} x$ follows from the previous proposition.

$\supfun{\lvert \mathbb{R} \rvert } x = \bigsqcap_{X \in \up x} \supfun{\lvert \mathbb{R} \rvert } X =
\bigsqcap_{X \in \up x} \bigsqcup_{y \in X} \Delta (y)$.

Consider cases:

\begin{description}
  \item[$x$ is an ultrafilter at the right of some number $\alpha$] \hfill \\ $\langle
  | \mathbb{R} | \rangle x = \bigsqcap_{X \in \up x} \bigsqcup_{y \in
  X \sqcap] \alpha ; + \infty [} \Delta (y) \sqsubseteq] \alpha ; + \infty
  [= \langle \geq \rangle x$ because $\bigsqcup_{y \in X \sqcap] \alpha ; +
  \infty [} \Delta (y) \sqsubseteq] \alpha ; + \infty [$.

  \item[$x$
  is an ultrafilter at the left of some number $\alpha$] \hfill \\ $\langle |
  \mathbb{R} | \rangle x \sqsubseteq \Delta (\alpha)$ is obvious. But
  $\langle \geq \rangle x \sqsupseteq \Delta (\alpha)$.

  \item[$x$ is an ultrafilter at positive infinity] \hfill \\ $\langle | \mathbb{R} |
  \rangle x \sqsubseteq \Delta_{+ \infty}$ is obvious. But $\langle \geq
  \rangle x = \Delta_{+ \infty}$.

  \item[$x$ is an ultrafilter at negative infinity] \hfill \\ Because $\langle \geq
  \rangle x =\mathbb{R}$.
\end{description}
\end{proof}

\begin{cor}
$\supfun{ | \mathbb{R} | \sqcap \geq } x = \supfun{ | \mathbb{R} |
} x$ for every nontrivial ultrafilter $x$.
\end{cor}

\begin{proof}
$\supfun{ | \mathbb{R} | \sqcap \geq } x = \supfun{ | \mathbb{R} | } \sqcap \supfun{\geq} x =
\supfun{ | \mathbb{R} | } x$.
\end{proof}

So $\supfun{ | \mathbb{R} | \sqcap \geq }$ and $\supfun{ | \mathbb{R} | }$ agree on all ultrafilters except trivial ones.

\begin{prop}
$| \mathbb{R} |_{>} \sqcap > = | \mathbb{R} |_{>} \sqcap \geq = | \mathbb{R} |_{>}$.
\end{prop}

\begin{proof}
$| \mathbb{R} |_{>} \sqsubseteq \mathord{>}$ because $\rsupfun{| \mathbb{R} |_{>}} x \sqsubseteq \rsupfun{>} x$ and
$| \mathbb{R} |_{>}$ is a complete funcoid.
\end{proof}

\begin{lem}
$\supfun{ | \mathbb{R} |_{>} } x \sqsubset \supfun{ | \mathbb{R} |_{\geq} } x$ for a nontrivial ultrafilter~$x$.
\end{lem}

\begin{proof}
It enough to prove $\supfun{ | \mathbb{R} |_{>} } x \ne \supfun{| \mathbb{R} |_{\geq} } x$.

Take $x$ be an ultrafilter with limit point~$0$ on $\im z$ where $z$ is the sequence $n\mapsto \frac{1}{n}$.

\[ \supfun{ | \mathbb{R} |_{>} } x \sqsubseteq \rsupfun{ | \mathbb{R} |_{>} } \im z =
\bigsqcup_{n\in\im z} \Delta_{>}\left(\frac{1}{n}\right) \sqsubseteq
\bigsqcup_{n\in\im z} \left]\frac{1}{n};\frac{1}{n-1}-\frac{1}{n}\right[ \asymp \im z. \]
Thus $\supfun{ | \mathbb{R} |_{>} } x \asymp \im z$. But
$\supfun{ | \mathbb{R} |_{\geq} } x \sqsubseteq \supfun{=} x \nasymp \im z$.
\end{proof}

\begin{cor}
$| \mathbb{R} |_{>} \sqsubset | \mathbb{R} |_{\geq}$.
\end{cor}

\begin{prop}
$| \mathbb{R} |_{>} \sqsubset | \mathbb{R} |_{\geq} \sqcap >$.
\end{prop}

\begin{proof}
It's enough to prove $| \mathbb{R} |_{>} \neq | \mathbb{R} |_{\geq} \sqcap >$.

Really, $\supfun{ | \mathbb{R} |_{\geq} \sqcap > } x = \supfun{ | \mathbb{R}
|_{\geq} } x \neq \supfun{ | \mathbb{R} |_{>} } x$ (lemma).
\end{proof}

\begin{prop}
~
\begin{enumerate}
\item\label{comp-ord-ge} $| \mathbb{R} |_{\geq} \circ | \mathbb{R} |_{\geq} = | \mathbb{R} |_{\geq}$;
\item\label{comp-ord-gt} $| \mathbb{R} |_{>} \circ | \mathbb{R} |_{>} = | \mathbb{R} |_{>}$;
\item $| \mathbb{R} |_{\geq} \circ | \mathbb{R} |_{>} = | \mathbb{R} |_{>}$;
\item $| \mathbb{R} |_{>} \circ | \mathbb{R} |_{\geq} = | \mathbb{R} |_{>}$.
\end{enumerate}
\end{prop}

\begin{proof}
??
\end{proof}

\begin{conjecture}
~
\begin{enumerate}
\item $(|\mathbb{R}| \sqcap {\geq}) \circ (|\mathbb{R}| \sqcap {\geq}) = |\mathbb{R}| \sqcap {\geq}$.
\item $(|\mathbb{R}| \sqcap {>}) \circ (|\mathbb{R}| \sqcap {>}) = |\mathbb{R}| \sqcap {>}$.
\end{enumerate}
\end{conjecture}

\section{Continuity}

I will say that a property holds on a filter~$\mathcal{A}$ iff there is $A\in\up\mathcal{A}$ on which the property holds.

\fxnote{$f\in\continuous(A,B)\land f\in\continuous(\iota_A|\mathbb{R}|_{\geq},\iota_B|\mathbb{R}|_{\geq}) \Leftrightarrow
(f,f)\in\continuous((A,\iota_A|\mathbb{R}|_{\geq}),(B,\iota_B|\mathbb{R}|_{\geq}))$}

\begin{lem}
Let function~$f:A\rightarrow B$ where
$A,B\in\subsets\mathbb{R}$ and $\iota_A|\mathbb{R}|$~is connected.
\begin{enumerate}
\item $f$ is monotone and $f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)$ iff
$f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)\cap\continuous(\iota_{A}|\mathbb{R}|_{\geq},\iota_{B}|\mathbb{R}|_{\geq})$ iff
$f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)\cap\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{\geq})$ iff
$f\in\continuous(\iota_{A}|\mathbb{R}|_{\geq},\iota_{B}|\mathbb{R}|_{\geq})\cap
\continuous(\iota_{A}|\mathbb{R}|_{\leq},\iota_{B}|\mathbb{R}|_{\leq})$.
\item $f$ is strictly monotone and $f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)$ iff
$f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)\cap\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{>})$ iff
$f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{>})\cap
\continuous(\iota_{A}|\mathbb{R}|_{<},\iota_{B}|\mathbb{R}|_{<})$.
\end{enumerate}
\fxnote{Generalize for arbitrary posets.}
\fxnote{Generalize for $f$ being a funcoid.}
\fxnote{Can add more conditions with~$<$.}
\end{lem}

\begin{proof}
Because $f$ is continuous, we have $\rsupfun{f\circ\iota_{A}|\mathbb{R}|}\{x\} \sqsubseteq \rsupfun{\iota_{B}|\mathbb{R}|\circ f}\{x\}$
that is $\rsupfun{f}(A\sqcap\Delta(x)) \sqsubseteq B\sqcap\Delta(f(x))$ for every~$x\in A$.

If $f$ is monotone, we have $\rsupfun{f} \Delta_{\geq}(x) \sqsubseteq [f(x);\infty[$.
Thus $\rsupfun{f} (A\sqcap\Delta_{\geq}(x)) \sqsubseteq B\sqcap\Delta_{\geq}(f(x))$, that is
$\rsupfun{f\circ \iota_{A}|\mathbb{R}|_{\geq}}\{x\} \sqsubseteq \rsupfun{\iota_{B}|\mathbb{R}|_{\geq}\circ f}\{x\}$, thus
$f\in\continuous(\iota_{A}|\mathbb{R}|_{\geq},\iota_{B}|\mathbb{R}|_{\geq})$.

If $f$ is strictly monotone, we have $\rsupfun{f} \Delta_{>}(x) \sqsubseteq ]f(x);\infty[$.
Thus $\rsupfun{f} \Delta_{>}(x) \sqsubseteq \Delta_{>}(f(x))$, that is
$\rsupfun{f\circ \iota_{A}|\mathbb{R}|_{>}}\{x\} \sqsubseteq \rsupfun{\iota_{B}|\mathbb{R}|_{>}\circ f}\{x\}$, thus
$f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{>})$.

Let now $f\in\continuous(\iota_{A}|\mathbb{R}|_{\geq},\iota_{B}|\mathbb{R}|_{\geq})$.

Take any~$a\in {A}$ and let $c=\sup\setcond{b\in {B}}{b\geq a, \forall x\in[a;b[: f(x)\geq f(a)}$ (makes sense because $A$~is connected).
It's enough to prove that $c$ is the right endpoint (finite or infinite) of~${A}$.

Indeed by continuity $f(a)\leq f(c)$ and if $c$ is not already the right endpoint of~${A}$, then
there is $b'>c$ such that $\forall x\in[c;b'[: f(x)\geq f(c)$ (makes sense because $A$~is connected).
So we have $\forall x\in[a;b'[: f(x)\geq f(c)$ what contradicts to the above.

So $f$ is monotone on the entire~${A}$.

$f\in\continuous(\iota_{A}|\mathbb{R}|_{\geq},\iota_{B}|\mathbb{R}|_{\geq}) \Rightarrow f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{\geq})$ is obvious. Reversely
$f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{\geq}) \Leftrightarrow
f\circ \iota_{A}|\mathbb{R}|_{>} \sqsubseteq \iota_{B}|\mathbb{R}|_{\geq}\circ f \Leftrightarrow
\forall x\in A: \supfun{f}\rsupfun{\iota_{A}|\mathbb{R}|_{>}}\{x\} \sqsubseteq \rsupfun{\iota_{B}|\mathbb{R}|_{\geq}}\rsupfun{f}\{x\} \Leftrightarrow
\forall x\in A: \supfun{f}(A\sqcap\Delta_{>}(x)) \sqsubseteq B\sqcap\Delta_{\geq}f(x) \Leftrightarrow
\forall x\in A: \supfun{f}(A\sqcap\Delta_{>}(x)) \sqcup \{f(x)\} \sqsubseteq B\sqcap\Delta_{\geq}f(x) \Leftrightarrow
\forall x\in A: \supfun{f}((A\sqcap\Delta_{>}(x)) \sqcup \{x\}) \sqsubseteq B\sqcap\Delta_{\geq}f(x) \Leftrightarrow
\forall x\in A: \supfun{f}(A\sqcap\Delta_{\geq}(x)) \sqsubseteq B\sqcap\Delta_{\geq}f(x) \Leftrightarrow
\forall x\in A: \supfun{f}\rsupfun{\iota_{A}|\mathbb{R}|_{\geq}}\{x\} \sqsubseteq \rsupfun{\iota_{B}|\mathbb{R}|_{\geq}}\rsupfun{f}\{x\} \Leftrightarrow
f\circ \iota_{A}|\mathbb{R}|_{\geq} \sqsubseteq \iota_{B}|\mathbb{R}|_{\geq}\circ f \Leftrightarrow
f\in\continuous(\iota_{A}|\mathbb{R}|_{\geq},\iota_{B}|\mathbb{R}|_{\geq})$.

Let $f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{>})$. Then $f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{\geq})$ and thus it is monotone.
We need to prove that $f$ is strictly monotone.
Suppose the contrary. Then there is a nonempty interval $[p;q]\subseteq {A}$ such that $f$ is constant on this interval.
But this is impossible because $f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{>})$.

Prove that $f\in\continuous(\iota_{A}|\mathbb{R}|_{\geq},\iota_{B}|\mathbb{R}|_{\geq})\cap
\continuous(\iota_{A}|\mathbb{R}|_{\leq},\iota_{B}|\mathbb{R}|_{\leq})$ implies
$f\in\continuous({A},{B})$. Really, it implies
$\supfun{f}(A\sqcap\Delta_{\leq}(x))\sqsubseteq B\sqcap\Delta_{\leq}(fx)$ and $\supfun{f}(A\sqcap\Delta_{\geq}(x))\sqsubseteq B\sqcap\Delta_{\geq}(fx)$
thus $\supfun{f}(A\sqcap\Delta(x)) = \supfun{f}(A\sqcap(\Delta_{\leq}(x)\sqcup\{x\}\sqcup\Delta_{\geq}(x))) \sqsubseteq
B\sqcap(\Delta_{\leq}f(x)\sqcup\{f(x)\}\sqcup\Delta_{\geq}f(x)) =
B\sqcap\Delta(f(x))$.

Prove that $f\in\continuous(\iota_{A}|\mathbb{R}|_{>},\iota_{B}|\mathbb{R}|_{>})\cap
\continuous(\iota_{A}|\mathbb{R}|_{<},\iota_{B}|\mathbb{R}|_{<})$
$f\in\continuous({A},{B})$. Really, it implies
$\supfun{f}(A\sqcap\Delta_{<}(x))\sqsubseteq B\sqcap\Delta_{<}(fx)$ and $\supfun{f}(A\sqcap\Delta_{>}(x))\sqsubseteq B\sqcap\Delta_{>}(fx)$
thus $\supfun{f}(A\sqcap\Delta(x)) = \supfun{f}(A\sqcap(\Delta_{<}(x)\sqcup\{x\}\sqcup\Delta_{>}(x))) \sqsubseteq
B\sqcap(\Delta_{<}f(x)\sqcup\{f(x)\}\sqcup\Delta_{>}f(x)) = B\sqcap\Delta(f(x))$.
\end{proof}

\begin{thm}
\fxwarning{Counterexample: \url{https://math.stackexchange.com/a/3702872/4876}}
Let function~$f:A\rightarrow B$ where $A,B\in\subsets\mathbb{R}$.
\begin{enumerate}
\item $f$ is locally monotone and $f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)$ iff
$f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)\cap\continuous(\iota_A|\mathbb{R}|_{\geq},\iota_B|\mathbb{R}|_{\geq})$ iff
$f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)\cap\continuous(\iota_A|\mathbb{R}|_{>},\iota_B|\mathbb{R}|_{\geq})$ iff
$f\in\continuous(\iota_A|\mathbb{R}|_{\geq},\iota_B|\mathbb{R}|_{\geq})\cap
\continuous(\iota_A|\mathbb{R}|_{\leq},\iota_B|\mathbb{R}|_{\leq})$.
\item $f$ is locally strictly monotone and $f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)$ iff
$f\in\continuous(\iota_A|\mathbb{R}|,\iota_B|\mathbb{R}|)\cap\continuous(\iota_A|\mathbb{R}|_{>},\iota_B|\mathbb{R}|_{>})$ iff
$f\in\continuous(\iota_A|\mathbb{R}|_{>},\iota_B|\mathbb{R}|_{>})\cap
\continuous(\iota_A|\mathbb{R}|_{<},\iota_B|\mathbb{R}|_{<})$.
\end{enumerate}
\end{thm}

\begin{proof}
By the lemma it is (strictly) monotone on each connected component.
\fxerror{It is not enough if for example $A=\mathbb{Q}$.}
\end{proof}

See also related math.SE questions:
\begin{enumerate}
\item \url{http://math.stackexchange.com/q/1473668/4876}
\item \url{http://math.stackexchange.com/a/1872906/4876}
\item \url{http://math.stackexchange.com/q/1875975/4876}
\end{enumerate}

\subsection{Directed topological spaces}

Directed topological spaces are defined at\\
\url{http://ncatlab.org/nlab/show/directed+topological+space}

\begin{defn}
A \emph{directed topological space} (or \emph{d-space} for short) is a pair $(X,d)$ of a topological space~$X$ and
a set $d\subseteq\continuous([0;1],X)$ (called \emph{directed paths} or \emph{d-paths}) of paths in~$X$ such that
\begin{enumerate}
\item (constant paths) every constant map $[0;1]\to X$ is directed;
\item (reparameterization) $d$ is closed under composition with increasing continuous maps $[0;1]\to [0;1]$;
\item (concatenation) $d$ is closed under path-concatenation: if the d-paths $a$, $b$ are consecutive in $X$ ($a(1)=b(0)$), then their ordinary concatenation $a+b$ is also a d-path
\begin{gather*}
(a+b)(t) = a(2t),\,\text{if}\, 0\le t\le \frac{1}{2}, \\
(a+b)(t) = b(2t-1),\,\text{if}\, \frac{1}{2}\le t\le 1.
\end{gather*}
\end{enumerate}
\end{defn}

I propose a new way to construct a directed topological space. My way is more geometric/topological as it does not involve dealing with particular paths.

\begin{defn}
Let $ T$ be the complete endofuncoid corresponding to a topological space
and $\nu\sqsubseteq T$ be its ``subfuncoid''. The $\mathrm{d}$-space $\operatorname{(dir)}(T,\nu)$ induced by the pair $(T,\nu)$
consists of~$ T$ and paths $f\in\continuous([0;1], T) \cap \continuous(|[0;1]|_{\geq}, \nu)$
such that $f(0)=f(1)$.
\end{defn}

\begin{prop}
It is really a $\mathrm{d}$-space.
\end{prop}

\begin{proof}
Every $\mathrm{d}$-path is continuous.

Constant path are $\mathrm{d}$-paths because $\nu$ is reflexive.

Every reparameterization is a $\mathrm{d}$-path because they are $\continuous(|[0;1]|_{\geq}, \nu)$ and we can apply the theorem about
composition of continuous functions.

Every concatenation is a $\mathrm{d}$-path. Denote
$f_0 = \mylambda{t}{[0;\frac{1}{2}]}{a(2t)}$ and $f_1 = \mylambda{t}{[\frac{1}{2};1]}{b(2t-1)}$.
Obviously $f_0,f_1 \in \continuous([0;1],\mu) \cap \continuous(|[0;1]|_{\geq}, \nu)$.
Then we conclude that $a+b = f_1\sqcup f_1$ is in $f_0,f_1 \in \continuous([0;1],\mu) \cap \continuous(|[0;1]|_{\geq}, \nu)$
using the fact that the operation $\circ$ is distributive over $\sqcup$.
\end{proof}

Below we show that not every $\mathrm{d}$-space is induced by a pair of an endofuncoid and its subfuncoid.
But are $\mathrm{d}$-spaces not represented this way good anything except counterexamples?

Let now we have a $\mathrm{d}$-space $(X,d)$. Define funcoid~$\nu$ corresponding to the $\mathrm{d}$-space by the formula
$\nu = \bigsqcup_{a\in d}(a\circ |\mathbb{R}|_{\geq}\circ a^{-1})$.

\begin{example}
The two directed topological spaces, constructed from a fixed topological space and two different reflexive funcoids,
are the same.
\end{example}

\begin{proof}
Consider the indiscrete topology~$T$ on $\mathbb{R}$ and the funcoids~$1^{\mathsf{FCD}(\mathbb{R},\mathbb{R})}$
and $1^{\mathsf{FCD}(\mathbb{R},\mathbb{R})}\sqcup(\{0\}\times^{\mathsf{FCD}} \Delta_{\geq})$.
The only $\mathrm{d}$-paths in both these settings are constant functions.
\end{proof}

\begin{example}
A $\mathrm{d}$-space is not determined by the induced funcoid.
\end{example}

\begin{proof}
The following a $\mathrm{d}$-space induces the same funcoid as the $\mathrm{d}$-space of all paths on the plane.

Consider a plane $\mathbb{R}^2$ with the usual topology. Let $\mathrm{d}$-paths be paths lying inside a polygonal chain (in the plane).
\end{proof}

\begin{conjecture}
A $\mathrm{d}$-path~$a$ is determined by the funcoids (where $x$ spans $[0;1]$)
\[ (\mylambda{t}{\mathbb{R}}{a(x+t)})|_{\Delta(0)}. \]
\end{conjecture}

\section{A way to construct directed topological spaces}

I propose a new way to construct a directed topological space. My way is more geometric/topological as it does not involve dealing with particular paths.

\begin{conjecture}
Every directed topological space can be constructed in the below described way.
\end{conjecture}

Consider topological space $T$ and its subfuncoid $F$ (that is $F$ is a funcoid which is less that $T$ in the order of funcoids).
Note that in our consideration $F$ is an endofuncoid (its source and destination are the same).

Then a directed path from point $A$ to point $B$ is defined as a continuous function $f$ from $[0;1]$ to $F$ such that $f(0)=A$ and $f(1)=B$.
\fxwarning{Specify whether the interval $[0;1]$ is treated as a proximity, pretopology, or preclosure.}

Because $F$ is less that $T$, we have that every directed path is a path.

\begin{conjecture}
The two directed topological spaces, constructed from a fixed topological space and two different funcoids,
are different.
\end{conjecture}

For a counter-example of (which of the two?) the conjecture consider funcoid $T\sqcap(\mathbb{Q}\times^{\mathsf{FCD}}\mathbb{Q})$
where $T$ is the usual topology on real line.We need to consider stability of existence and uniqueness of a path under transformations of our funcoid and
under transformations of the vector field. Can this be a step to solve Navier-Stokes existence and smoothness problems?

\section{Integral curves}

We will consider paths in a normed vector space~$V$.

\begin{defn}
Let $D$ be a connected subset of~$\mathbb{R}$. A \emph{path} is a function $D\rightarrow V$.
\end{defn}

Let $d$ be a vector field in a normed vector space~$V$.

\begin{defn}
\emph{Integral curve} of a vector field~$d$ is a differentiable function $f:D\rightarrow V$ such that $f'(t)=d(f(t))$ for every $t\in D$.
\end{defn}

\begin{defn}
The definition of \emph{right side integral curve} is the above definition with right derivative of~$f$ instead of derivative~$f'$.
\emph{Left side integral curve} is defined similarly.
\end{defn}

\subsection{Path reparameterization}

$C^1$~is a function which has continuous derivative on every point of the domain.

By $D^1$ I will denote a $C^1$ function whose derivative is either nonzero at every point or is zero everywhere.

\begin{defn}
A \emph{reparameterization} of a $C^1$ path is a bijective $C^1$ function $\phi:D\rightarrow D$ such that
$\phi'(t)>0$. A curve $f_2$ is called a reparametrized curve $f_1$ if there is a reparameterization~$\phi$ such that
$f_2=f_1\circ\phi$.
\end{defn}

It is well known that this defines an equivalence relation of functions.

\begin{prop}
Reparameterization of $D^1$ function is $D^1$.
\end{prop}

\begin{proof}
If the function has zero derivative, it is obvious.

Let $f_1$ has everywhere nonzero derivative. Then $f_2'(t) = f_1'(\phi(t))\phi'(t)$ what is trivially nonzero.
\end{proof}

\begin{defn}
Vectors~$p$ and~$q$ have the \emph{same direction} ($p\upuparrows q$) iff there exists a strictly positive real~$c$ such that $p=cq$.
\end{defn}

\begin{obvious}
Being same direction is an equivalence relation.
\end{obvious}

\begin{obvious}
The only vector with the same direction as the zero vector is zero vector.
\end{obvious}

\begin{thm}
A $D^1$ function~$y$ is some reparameterization of a $D^1$ integral curve~$x$ of a continuous vector field~$d$ iff
$y'(t)\upuparrows d(y(t))$ that is vectors~$y'(t)$ and $d(y(t))$ have the same direction (for every $t$).
\end{thm}

\begin{proof}
If $y$ is a reparameterization of~$x$, then $y(t)=x(\phi(t))$. Thus $y'(t)=x'(\phi(t))\phi'(t)=d(x(\phi(t)))\phi'(t)=d(y(t))\phi'(t)$.
So $y'(t)\upuparrows d(y(t))$ because $\phi'(t)>0$.

Let now $x'(t)\upuparrows d(x(t))$ that is that is there is a strictly positive function $c(t)$ such that
$x'(t) = c(t) d(x(t))$.

If $x'(t)$ is zero everywhere, then $d(x(t))=0$ and thus $x'(t)=d(x(t))$ that is $x$ is an Integral curve.
Note that $y$ is a reparameterization of itself.

We can assume that $x'(t)\ne 0$ everywhere. Then $F(x(t))\ne 0$. We have
that $c(t) = \frac{||x'(t)||}{||d(x(t))||}$ is a continuous function. \fxnote{Does it work for non-normed spaces?}

Let $y(u(t)) = x(t)$, where \[ u(t)=\int_0^t c(s)ds, \]
which is defined and finite because $c$ is continuous and monotone (thus having inverse defined on its image)
because $c$ is positive.

Then
\begin{align*}
y'(u(t)) u'(t) &= x'(t) \\
&= c(t) d(x(t)) \text{, so}\\
y'(u(t)) c(t) &= c(t) d(y(u(t))) \\
y'(u(t))  &=  d(y(u(t)))
\end{align*}
and letting $s=u(t)$ we have $y'(s)=d(y(s))$ for a reparameterization~$y$ of~$x$.
\end{proof}

\subsection{Vector space with additional coordinate}

Consider the normed vector space with additional coordinate~$t$.

Our vector field~$d(t)$ induces vector field~$\hat{d}(t,v)=(1,d(v))$ in this space. Also $\hat{f}(t)=(t,f(t))$.

\begin{prop}
Let $f$ be a $D^1$ function. $f$ is an integral curve of~$d$ iff $\hat{f}$ is a reparametrized integral curve of~$\hat{d}$.
\end{prop}

\begin{proof}
First note that $\hat{f}$ always has a nonzero derivative.
$\hat{f}'(t)\upuparrows \hat{d}(\hat{f}(t)) \Leftrightarrow (1,f'(t))\upuparrows (1,d(f(t))) \Leftrightarrow
f'(t)=d(f(t))$.
\end{proof}

Thus we have reduced (for $D^1$ paths) being an integral curve to being a reparametrized integral curve.
We will also describe being a reparametrized integral curve topologically (through funcoids).

\subsection{Topological description of $C^1$ curves}

Explicitly construct this funcoid as follows:

$R(d,\phi) = \setcond{v\in V}{\widehat{vd}<\phi, v\ne 0}$ for $d\ne 0$ and $R(0,\phi) = \{0\}$,
where $\widehat{ab}$ is the angle between the vectors $a$ and $b$,
for a direction~$d$ and an angle~$\phi$.

\begin{defn}
$W(d) = \bigsqcap^{\mathsf{RLD}}\setcond{R(d,\phi)}{\phi\in\mathbb{R},\phi>0} \sqcap \bigsqcap^{\mathsf{RLD}}_{r>0}B_r(0)$.
\fxnote{This is defined for infinite dimensional case.}
\fxnote{Consider also $\mathsf{FCD}$ instead of $\mathsf{RLD}$.}
\end{defn}

\begin{prop}
For finite dimensional case~$\mathbb{R}^n$ we have
$W(d) = \bigsqcap^{\mathsf{RLD}}\setcond{R(d,\phi)}{\phi\in\mathbb{R},\phi>0} \sqcap \Delta^{(\mathsf{RLD})n}$
where \[ \Delta^{(\mathsf{RLD})n} = \underbrace{\Delta\times^{\mathsf{RLD}}\dots\times^{\mathsf{RLD}}\Delta}_{n\text{ times}}. \]
\end{prop}

\begin{proof}
??
\end{proof}

Finally our funcoids are the complete funcoids~$Q_+$ and~$Q_-$ described by the formulas
\[
\rsupfun{Q_+}@\{p\} = \supfun{p+} W(d(p)) \quad\text{and}\quad \rsupfun{Q_-}@\{p\} = \supfun{p+} W(-d(p)).
\]
Here $\Delta$ is taken from the ``counter-examples'' section.

In other words,
\[
Q_+ = \bigsqcup_{p\in\mathbb{R}} (@\{p\}\times^{\mathsf{FCD}}\supfun{p+}{W(d(p))});
\quad
Q_- = \bigsqcup_{p\in\mathbb{R}} (@\{p\}\times^{\mathsf{FCD}}\supfun{p+}{W(-d(p))}).
\]

That is $\rsupfun{Q_+}@\{p\}$ and $\rsupfun{Q_-}@\{p\}$ are something like infinitely small spherical sectors
(with infinitely small aperture and infinitely small radius).

\fxnote{Describe the co-complete funcoids reverse to these complete funcoids.}

\begin{thm}
A $D^1$ curve~$f$ is an reparametrized integral curve for a direction field~$d$ iff
$f\in\continuous(\iota_D|\mathbb{R}|_{>},Q_+)\cap\continuous(\iota_D|\mathbb{R}|_{<},Q_-)$.
\end{thm}

\begin{proof}
Equivalently transform $f\in\continuous(\iota_D|\mathbb{R}|,Q_+)$; $f\circ \iota_D|\mathbb{R}|\sqsubseteq Q_+\circ f$;
$\rsupfun{f\circ \iota_D|\mathbb{R}|}@\{t\}\sqsubseteq \rsupfun{Q_+\circ f}@\{t\}$;
$\rsupfun{f}\Delta_{>}(t)\sqcap D\sqsubseteq \rsupfun{Q_+}f(t)$;
$\rsupfun{f}\Delta_{>}(t)\sqsubseteq \rsupfun{Q_+}f(t)$;
$\rsupfun{f}\Delta_{>}(t)\sqsubseteq f(t)+W(D(f(t)))$;
$\rsupfun{f}\Delta_{>}(t)-f(t)\sqsubseteq W(D(f(t)))$;
\[ \forall r>0, \phi>0 \exists\delta>0: \rsupfun{f}(]t;t+\delta[)-f(t)\subseteq R(d(f(t)),\phi) \cap B_r(f(t)); \]
\[ \forall r>0, \phi>0 \exists\delta>0 \forall 0<\gamma<\delta: \rsupfun{f}(]t;t+\gamma[)-f(t)\subseteq R(d(f(t)),\phi) \cap B_r(f(t)); \]
\[ \forall r>0, \phi>0 \exists\delta>0 \forall 0<\gamma<\delta: \frac{\rsupfun{f}(]t;t+\gamma[)-f(t)}{\gamma}\subseteq R(d(f(t)),\phi) \cap B_{r/\delta}(f(t)); \]
\[ \forall r>0, \phi>0 \exists\delta>0: \partial_+ f(t)\subseteq R(d(f(t)),\phi) \cap B_{r/\delta}(f(t)); \]
\[ \forall r>0, \phi>0: \partial_+ f(t)\subseteq R(d(f(t)),\phi); \]
\[ \partial_+ f(t) \upuparrows d(f(t)) \]
where $\partial_+$ is the right derivative.

In the same way we derive that $\continuous(|\mathbb{R}|_{<},Q_-)\Leftrightarrow \partial_- f(t) \upuparrows d(f(t))$.

Thus $f'(t) \upuparrows d(f(t))$ iff $f\in\continuous(|\mathbb{R}|_{>},Q_+)\cap\continuous(|\mathbb{R}|_{<},Q_-)$.
\end{proof}

\subsection{$C^n$ curves}

We consider the differential equation $f'(t) = d(f(t))$.

We can consider this equation in any topological vector
space~$V$ (\url{https://en.wikipedia.org/wiki/Frechet_derivative}), see also
\url{https://math.stackexchange.com/q/2977274/4876}.
Note that I am not an expert in topological vector spaces
and thus my naive generalizations may be wrong in details.

$n$-th derivative $f^{(n)}(t)=d_n(f(t))$;
$f^{(n+1)}(t)=d_n'(f(t))\circ f'(t)=d_n'(f(t))\circ d(f(t))$.
So $d_{n+1}(y)=d_n'(y)\circ d(y)$.

Given a point~$y\in V$
define \[R^n(y) = \setcond{v\in V}{\widehat{vd_0(y)}<
\frac{d_1}{1!}(y)|v|+\frac{d_2(y)}{2!}|v|^2+\dots+\frac{d_{n-1}(y)}{(n-1)!}|v|^{n-1}+O(|v|^n), v\ne 0}\] for $d_0(y)\ne 0$ and $R^n = \{0\}$ if $d_0(y)=0$.

\begin{defn}
$R^\infty(y) = R^0(y)\sqcap R^1(y)\sqcap R^2(y)\sqcap\dots$.
\end{defn}

\fxerror{It does not work:
\url{https://math.stackexchange.com/a/2978532/4876}.}

\begin{defn}
$W^n(y) = R^n(y) \sqcap \bigsqcap^{\mathsf{RLD}}_{r>0}B_r(0)$;
$W^\infty(y) = R^\infty(y) \sqcap \bigsqcap^{\mathsf{RLD}}_{r>0}B_r(0)$.
\end{defn}

Finally our funcoids are the complete funcoids~$Q_+^n$ and~$Q_-^n$ described by the formulas
\[
\rsupfun{Q_+^n}@\{p\} = \supfun{p+} W^n(p) \quad\text{and}\quad \rsupfun{Q_-^n}@\{p\} = \supfun{p+} {W^-}^n(p)
\]
where $W^-$ is $W$ for the reverse vector field~$-d(y)$.

\fxnote{Related questions:
\url{http://math.stackexchange.com/q/1884856/4876}
\url{http://math.stackexchange.com/q/107460/4876}
\url{http://mathoverflow.net/q/88501}}

\begin{lem}
Let for every $x$ in the domain of the path for small $t > 0$ we have $f (x + t) \in R^n (F (f (x)))$ and $f (x - t) \in R^n (- F (f (x)))$.
Then $f$ is $C^n$ smooth.
\end{lem}

\begin{proof}
\fxerror{Not yet proved!}\\
See also \url{http://math.stackexchange.com/q/1884930/4876}.
\end{proof}

\begin{conjecture}
A path~$f$ is conforming to the above differentiable
equation and $C^n$ (where~$n$ is natural or infinite) smooth iff $f\in\continuous(\iota_D|\mathbb{R}|_{>},Q_+^n)\cap\continuous(\iota_D|\mathbb{R}|_{<},Q_-^n)$.
\end{conjecture}

\begin{proof}
Reverse implication follows from the lemma.

Let now a path~$f$ is $C^n$. Then
\[
f(x+t) = \sum_{i=0}^n f^{(i)}(x)\frac{t^i}{i!} + o(t^i) =
f(x)+f'(x)t + \sum_{i=2}^n f^{(i)}(x)\frac{t^i}{i!} + o(t^i)
\]
\end{proof}

\subsection{Plural funcoids}

Take $I_+$ and $Q_+$ as described above in forward direction and $I_-$ and $Q_-$ in backward direction. Then
\[ f\in\continuous(I_+,Q_+)\land f\in\continuous(I_-,Q_-) \Leftrightarrow f\times f\in\continuous(I_+\times^{(A)}I_-,Q_+\times^{(A)}Q_-)? \]

To describe the above we can introduce new term \emph{plural funcoids}. This is simply a map
from an index set to funcoids. Composition is defined component-wise. Order is defined as product order.
Well, do we need this? Isn't it the same as infimum product of funcoids?

\subsection{Multiple allowed directions per point}

\[ \rsupfun{Q}@\{p\} = \bigsqcup_{d\in d(p)} \supfun{p+} W(d). \]

It seems (check!) that solutions not only of differential equations but also of difference equations can be
expressed as paths in funcoids.


Success in calculus depends on your background in algebra, trigonometry,
analytic geometry and functions. In this chapter, we review many of the
concepts you will need to be familiar with in order to succeed in this course.

\section{Algebra}\label{sec:Algebra}

% Input each subsection
\input{1-review/1-1-1-numbers-systems-sets}
\input{1-review/1-1-4-inequalities-and-intervals}
\input{1-review/1-1-2-law-of-exponents}
\input{1-review/1-1-3-quadratic-formula}
\input{1-review/1-1-5-absolute-value}
\input{1-review/1-1-6-absolute-value-and-inequalities}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%    EXERCISES    %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:Algebra}}

\begin{enumialphparenastyle}

\begin{multicols}{2}
%%%%%%%%%%

\begin{ex}
Write the set using interval notation.
\begin{tabular}{lll}
(a) \hspace{2mm} 	$\{x\,|\, x \neq 5 \}$
&& (b) \hspace{2mm} 	$\{x\,|\, x \neq -1 \}$ \\
(c) \hspace{2mm}   $\{x\,|\, x \neq -3,\, 4 \}$
& & (d) \hspace{2mm}	$\{x\,|\, x \neq 0, \, 2 \}$ \\
(e) \hspace{2mm} $\{x\,|\, x \neq 2, \, -2 \}$
& & \\
(f) \hspace{2mm}  $\{x\,|\, x \neq 0,\, \pm 4 \}$ && \\
 (g) \hspace{2mm} $\{x\,|\, x \leq -1 \, \text{or} \, x \geq 1 \}$ &&\\
  (h) \hspace{2mm} 	$\{x\,|\, x < 3 \, \text{or} \, x \geq 2 \}$  && \\
(i) \hspace{2mm} $\{x\,|\, x \leq -3 \, \text{or} \, x > 0 \}$ && \\
 (j) \hspace{2mm}  $\{x\,|\, x \leq 5 \, \text{or} \, x = 6 \}$ && \\
(k) \hspace{2mm} $\{x\,|\, x > 2 \, \text{or} \, x = \pm 1 \}$ &&\\
\end{tabular}
\begin{sol}
\end{sol}
\end{ex}

\begin{ex}
Simplify the following expressions as much as possible assuming $x,y>0$:
\begin{enumerate}
	\item	$\ds\frac{x^3y^{-1/3}}{\sqrt[3]{y^2}x^2}$
	\item	$\ds\frac{3x^{-1/3}y^{-2}\sqrt[3]{x^4}}{\sqrt{9x}y^{-3}}$
	\item	$\ds\left(\frac{16x^2y}{x^4}\right)^{1/2}\frac{\sqrt[3]{x^2}}{2\sqrt{y}}$
\end{enumerate}
\begin{sol}
\begin{enumerate}
	\item	$\ds\frac{x}{y}$
	\item	$\sqrt{x}y$
	\item	$\ds\frac{2}{\sqrt[3]{x}}$
\end{enumerate}
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Find the constants $a,b,c$ if the expression
$$\frac{4x^{-1}y^2\sqrt[3]{x}}{2x\sqrt{y}}$$
is written in the form $ax^by^c$.
\begin{sol}
	$a=2$, $b=-\frac{5}{3}$, $c=\frac{3}{2}$.
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Find the roots of the quadratic equation
$$x^2-2x-24=0$$
\begin{sol}
$x=-4$ and $x=6$.
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Solve the equation \\
$$\frac{x}{4x-16}-2=\frac{1}{x-3}.$$
\end{ex}

%\vfill \null
%\columnbreak

%%%%%%%%%%
\begin{ex}
Solve the following inequalities. Write your answer as a union of intervals.
\begin{multicols}{2}
\begin{enumerate}
	\item	$3x+1>6$
	\item	$0\leq 7x-1 < 1$
	\item	$\ds{\frac{x^2(x-1)}{(x+2)(x+3)^3}\leq 0}$
	\item	$x^2+1>0$
	\item	$x^2+1<0$
	\item	$x^2+1>2x$
	\item	$x^3>4x$
	\item	$x^3\geq4x^2$
	\item	$\dfrac{1}{x}>2$
	\item	$\dfrac{x}{x+2}\leq\dfrac{2}{x-1}$
\end{enumerate}
\end{multicols}
\begin{sol}
\begin{enumerate}
	\item	$(5/3,\infty)$
	\item	$[1/7,2/7]$
	\item	$(-\infty,-3)\cup(-2,1]$
	\item	$(-\infty,\infty)$
	\item	No solution
	\item	$(-\infty,1)\cup(1,\infty)$
	\item	$(-2,0)\cup(2,\infty)$
	\item	$[4,\infty)\cup\{0\}$
	\item	$(0,\frac{1}{2})$
	\item	$(-2,-1]\cup(1,4]$
\end{enumerate}
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Solve the equation $|6x+2|=1$.
\begin{sol}
$x=-\frac{1}{2}$ and $x=-\frac{1}{6}$.
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Find solutions to the following absolute value inequalities. Write your answer as a union of intervals.
\begin{multicols}{2}
\begin{enumerate}
	\item	$|x|\geq 2$
	\item	$|x-3|\leq 1$
	\item	$|2x+5|\geq 4$
	\item	$|x+2|<3x-6$
	\item	$|2x+5|+4\geq 1$
	\item	$5<|x+1|<8$
\end{enumerate}
\end{multicols}
\begin{sol}
\begin{multicols}{2}
\begin{enumerate}
	\item	$(-\infty,-2]\cup[2,\infty)$
	\item	$[2,4]$
	\item	$(-\infty,-9/2]\cup[-1/2,\infty)$
	\item	$(4,\infty)$
	\item	$(-\infty,\infty)$
	\item	$(-9,-6)\cup(4,7)$
\end{enumerate}
\end{multicols}
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Solve the equation $\sqrt{1-x}+x=1$.
\end{ex}

\end{multicols}

\end{enumialphparenastyle}