\input{settings}

\begin{document}

\lhead{Sergio Arnaud}
\rhead{ Statistical learning (MT7038) \\ Proyect 3 - Neural networks }
\cfoot{\thepage of \pageref{LastPage}}

\section{Backpropagation}

The purpose of this assignment is to implement a complete solution for training a neural network. In practice this is of course done by packages and programs, but it is important to have done it at least once yourselves.

Using backpropagation and stochastic gradient descent we will fit a nerual network with two hidden layers, and sigmoid activation, to the function $y(x) = x^3$ on the interval $(-2, 2)$. Let $\theta = \{(W_i, b_i), i = 1, 2, 3\}$ be the parameters of the model, then the network function is given by

\begin{align*}
    f(x,\theta) = W_3h_2 + b_3 \quad h_2 = \sigma(W_2h_1 + b_2) \quad h_1 = \sigma(W_1x + b_1)
\end{align*}

\subsection{Dimensions of the Parameters}

Assume that both hidden layers has $n$ hidden units, i.e. $h = (h1, . . . , hn)$ . Give the dimensions of all the
parameters $(W_i,bi)$, $i=1,2,3$
\begin{align*}
    W_1 \in \mathbb{R}^{n \times 1} \quad b_1 \in \mathbb{R}^{n \times 1}\\
    W_2 \in \mathbb{R}^{n \times n} \quad b_2 \in \mathbb{R}^{n \times 1} \\
    W_3 \in \mathbb{R}^{1 \times n} \quad b_3 \in \mathbb{R} \ \ \ \ \
\end{align*}

\subsection{Calculating the Derivatives.}

Let $L(x_i, y_i, \theta) = (y_i - f(x_i; \theta))^2$. Given the observation $(x,y)$ calculate the derivatives of $L(x,y;\theta)$.

\begin{align*}
    \frac{\partial L}{\partial W_{i}^3} &= 2(y-f(x,\theta))h^2_i\\
    \frac{\partial L}{\partial b_{i}^3} &= 2(y-f(x,\theta))\\
    \frac{\partial L}{\partial h_{i}^2} &= \frac{\partial L}{\partial b_{i}^3}W_i^3 \\\\
    \frac{\partial L}{\partial W_{ij}^2} &= \frac{\partial L}{\partial h_{i}^2}(h_i^2(1-h_i2))h_j^1 \\
    \frac{\partial L}{\partial b_{i}^2} &=  \frac{\partial L}{\partial h_{i}^2}(h_i^2(1-h_i2)) \\
    \frac{\partial L}{\partial h_{i}^1} &= \frac{\partial L}{\partial b_{i}^2}W_{ii}^2 \\\\
    \frac{\partial L}{\partial W_{i}^3} &= \frac{\partial L}{\partial h_{i}^1}(h_i^1(1-h_i^1))x \\
    \frac{\partial L}{\partial b_{i}^3} &= \frac{\partial L}{\partial h_{i}^1}(h_i^1(1-h_i^1)) \\
\end{align*}

\subsection{Fitting the Model}

The following code fites a feed forward neural network with 2 hiddel layers (125 hidden units) to the function $y(x) = x^3$.

\begin{lstlisting}[language=R]

sigm <- function(x){
  f <- function(y){
    return(1/(1+exp(-y)))
  }
  return( sapply(x,f) )
}

initParams <- function(nrHiddenUnits, xDim) {
  W <- list()
  b <- list()

  # First hidden layer
  W_1 <- matrix(0.05*rnorm(nrHiddenUnits * xDim), ncol = xDim,
  nrow = nrHiddenUnits, byrow = TRUE)
  b_1 <- matrix(0.05*rnorm(nrHiddenUnits), ncol = 1,
  nrow = nrHiddenUnits, byrow = TRUE)

  # Second hidden layer
  W_2 <- matrix(0.05*rnorm(nrHiddenUnits * xDim), ncol = nrHiddenUnits,
  nrow = nrHiddenUnits, byrow = TRUE)
  b_2 <- matrix(0.05*rnorm(nrHiddenUnits), ncol = 1,
  nrow = nrHiddenUnits, byrow = TRUE)

  # Output layer
  W_3 <- matrix(0.05*rnorm(nrHiddenUnits), ncol = nrHiddenUnits,
  nrow = 1, byrow = TRUE)
  b_3 <- 0.05*rnorm(1)

  W[[1]] <- W_1
  W[[2]] <- W_2
  W[[3]] <- W_3

  b[[1]] <- b_1
  b[[2]] <- b_2
  b[[3]] <- b_3

  return(list("W" = W,"b" = b))
}

forwardPass <- function(x,W,b){
  #First hidden Layer
  h_1 <- sigm(W[[1]] %*% x + b[[1]])

  #Second hidden Layer
  h_2 <- sigm(W[[2]] %*% h_1 + b[[2]])

  #Output Layer
  y <- W[[3]] %*% h_2 + b[[3]]

  return( list("output" = y, "hiddenLayer1" = h_1, "hiddenLayer2" = h_2 ) )
}

gradient <- function(x,y,W,b){

  net <- forwardPass(x,W,b)
  h_1 <- net$hiddenLayer1
  h_2 <- net$hiddenLayer2

  output <- net$output[[1]]

  W_3 <- W[[3]]
  W_2 <- W[[2]]
  W_1 <- W[[1]]

  b_1 <- b[[1]]
  b_2 <- b[[2]]
  b_3 <- b[[3]]

  #dL/dW_3
  dW_3 <- 0*W_3
  for (j in 1:dim(dW_3)[2]) {
    dW_3[1,j] <- -2*(y-output)*h_2[j]
  }
  #dL/db_3
  db_3 <- -2*(y-output)
  #dL/dh_2
  dh_2 <- 0*h_2
  for ( i in 1:length(h_2) ) {
    dh_2[i] <- db_3*W_3[1,i]
  }

  #dL/dW_2
  dW_2 <- 0*W_2
  for (i in 1:(dim(dW_2)[1])){
    for (j in 1:(dim(dW_2)[2])) {
      dW_2[i,j] <- dh_2[i]*(h_2[i]*(1-h_2[i]))*h_1[j]
    }
  }
  #dL/db_2
  db_2 <- 0*b_2
  for (i in 1:length(db_2)) {
   db_2[i] <- dh_2[i]*(h_2[i]*(1-h_2[i]))
  }
  #dL/dh_1
  dh_1 <- 0*h_1
  for (i in 1:length(dh_1)) {
   dh_1[i] <- db_2[i]*W_2[i,i]
  }

  #dL/dW_1
  dW_1 <- 0*W_1
  for (i in 1:(dim(dW_1)[1])){
    for (j in 1:(dim(dW_1)[2])) {
      dW_1[i,j] <- dh_1[i]*(h_1[i]*(1-h_1[i]))*x
    }
  }
  #dL/db_1
  db_1 <- 0*b_1
  for (i in 1:length(db_1)) {
   db_1[i] <- dh_1[i]*(h_1[i]*(1-h_1[i]))
  }

  return( list("dW_1" = dW_1, "dW_2" = dW_2, "dW_3" = dW_3,
  "db_1" = db_1, "db_2" = db_2, "db_3" = db_3) )
}

backPropagation <- function(){
  learningRate <- 0.01
  params <- initParams(125,1)

  N= 100000
  for (iter in 1:N) {
    x <- -2+4*runif(1)
    y <- x^3
    grad <- gradient(x,y,params$W, params$b)

    params$W[[1]] <- params$W[[1]]-learningRate*grad$dW_1
    params$W[[2]] <- params$W[[2]]-learningRate*grad$dW_2
    params$W[[3]] <- params$W[[3]]-learningRate*grad$dW_3

    params$b[[1]] <- params$b[[1]]-learningRate*grad$db_1
    params$b[[2]] <- params$b[[2]]-learningRate*grad$db_2
    params$b[[3]] <- params$b[[3]]-learningRate*grad$db_3

    #if (iter %% 1000 == 0) print(iter)
  }
  return( params )
}

ans = backPropagation()
\end{lstlisting}

Now, we plot the predicted values of our model against the true curve $f(x) = x^3$. As we can see, the results resemble the true model really good.

\begin{lstlisting}[language=R]
call_forward_pass <- function(x){
  forwardPass(x,ans$W, ans$b)$output
}

df <- tibble(x = seq(-2,2,.05)) %>%
        mutate(y = map(x, ~call_forward_pass(.x)), y = as.numeric(y))

ggplot(df, aes(x,y)) +
  geom_point() +
  stat_function(fun=function(x) x^3, col = 'red') +
  scale_colour_manual("Lgend title", values = c("red", "blue"))
\end{lstlisting}

\begin{figure}[H]
    \begin{center}
        \includegraphics[width=0.9\textwidth]{img/img1.jpg}
        \caption{}
    \end{center}
\end{figure}

\section{Learning Keras}
In this assignment we will fit a neural network for classifying images. We will use Keras, which is an extensive deep learning package in Python. Keras can be used in R through the keras package. But first we need to install it, see the steps below.

To get started with Keras follow the tutorial at \url{https://keras.rstudio.com/articles/getting\_started.html}.

The documentationt to the fit function is availible at: \url{https://keras.rstudio.com/reference/fit.keras.engine}. training.Model.html. Look at the documentation and answer the following questions:

- Explain what a batch size is.
- Explain what an epoch is.
- Explain why the shuffle argument is default set to true, i.e. why do you want to shuffle? Can you think of example’s when shuffling is a bad idea?

\subsection{Batch Size}
Is the number of samples that will be propagated through the network per gradient update, that is to say in one forward/backward pass. Some of the advantages of using a batch size smaller than the number of all samples are that it requires less memory and that the training process is usually faster because we update the weights after each propagation. A disadvantage of using a batch size smaller than the number of samples is that the smaller the batch the less accurate the estimate of the gradient will be. In general we have
\begin{itemize}
    \item  \textbf{Batch Gradient Descent}. Batch Size = Size of Training Set
    \item \textbf{Stochastic Gradient Descent}. Batch Size = 1
    \item \textbf{Mini-Batch Gradient Descent}. 1 < Batch Size < Size of Training Set. Popular batch sizes include 32, 64, and 128 samples.
\end{itemize}

\subsection{Epoch}
In general, one epoch means that each sample in the training dataset has had an opportunity to update the internal model parameters, an epoch is comprised of one or more batches. A way to understand it is the following: we have a first for-loop over the number of epochs, in each loop we will a nested for-loop that iterates over each batch of sample.

In keras, the epoch parameter defines the number times that the learning algorithm will work through the entire training dataset.

\subsection{Shuffle}
This argument is a boolean that determines whether to shuffle the trining data before each epoch. The reason to set it by default is that we want the model to understand all inputs equally. For example, if the data is ordered by class, then the training result will be a bad one because the model will have a higher accuracy for the last class it trains than the first one.

Another reason why shuffle is true by default is that the objective function might have numerous minima, and therefore gradient descent algorithms are susceptible to becoming "stuck" in those minima. This is likely to occur if the set of observations is unchanged over all training iterations. Shuffling observations might help the solver to "bounce" out of a local minimum.

For the Batch Gradient Descent process (Batch Size = Size of Training Set) shuffling is unnecessary.

\section{Fitting a Model in keras}

Now we'll fit a feed-forward neural network to the dataset \textit{dataset\_fashion\_mnist()}. For the following part python was used.

\begin{python}
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D
from keras.datasets import fashion_mnist

from matplotlib import pyplot as plt

# Loading fashion_mnist dataset
fashion_mnist = keras.datasets.fashion_mnist
(train, test = fashion_mnist.load_data()
(train_images, train_labels) = train
(test_images, test_labels) = test

# Turning pixel values to values in the interval $[0,1]$
train_images = train_images / 255.0
test_images = test_images / 255.0

# Reshaping
train_images = train_images.reshape(-1,28,28,1)
train_images = train_images.astype('float32')
test_images = test_images.reshape(-1,28,28,1)
test_images = test_images.astype('float32')

# Neural net architecture
model = Sequential()

# Convolutional and max pooling layers since we are dealing with images
model.add(Conv2D(filters=64, kernel_size=2,
                 padding='same', activation='relu',
                 input_shape=(28,28,1)))
model.add(MaxPooling2D(pool_size=2))
# Dropout to deal with overfitting
model.add(Dropout(0.25))

# Repeat convolutional - max pooling - dropout
model.add(Conv2D(filters=32, kernel_size=2,
                 padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(0.25))

# Flattening
model.add(Flatten())

# Dense layer with 128 hidden units and relu activation
model.add(Dense(128, activation='relu'))

# Droput to deal with overfitting
model.add(Dropout(0.5))

# Output layer
model.add(Dense(10, activation='softmax'))

# Compiling model
model.compile(loss = 'sparse_categorical_crossentropy',
              optimizer = keras.optimizers.adam(),
              metrics = ['accuracy'])

# Training
model.fit(train_images, train_labels, epochs=10, validation_split=0.2)

# Evaluating
test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)
# Test error = 0.914

# Plotting validation curve
history = model.history
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'val'], loc='upper left')
plt.show()
\end{python}

The test error was $.914$ and the validation curve is given in the following figure:
\begin{figure}[H]
    \begin{center}
        \includegraphics[width=0.8\textwidth]{img/img2.jpg}
        \caption{Validation curve}
    \end{center}
\end{figure}

\end{document}


\chapter{Interpreting a Logistic Regression Model \label{chapter:logreg}}

This chapter is similar to Chapter~\ref{chapter:linreg} but focuses on logistic regression models. As we saw in Chapter~\ref{chapter:linreg}, linear regression models are used in situations where the outcome of a supervised learning problem, $y$, follows a normal distribution, conditional on the values of the predictors. \textbf{Logistic regression} models, in contrast, handle situations where the outcome, $y$, is binary: either 0 or 1. We first encountered these models as examples of classification algorithms in Chapter~\ref{chapter:classification}. Because of their popularity in the clinical domain, it's important to understand how these models are fit and how to interpret the summary output produced by software.

Unfortunately, a full understanding of logistic regression requires knowledge of maximum likelihood estimation. We will, therefore, skip over some of the details until we've had more time to explore this topic.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{ER Readmissions Example from Chapter~\ref{chapter:classification} \label{sect:eragain}}

In Chapter~\ref{chapter:classification}, we saw an example where information about two predictors -- a disease severity score ($x_1$) and a social determinants score ($x_2$) -- was used to predict a binary outcome: whether a patient would be readmitted to the ER within 30 days of discharge. We tried three different supervised learning algorithms, one of which was a logistic regression model (Section~\ref{ssect:logreg}). The output from that model is repeated below.

\begin{center}
\includegraphics[width=0.35\textwidth]{img/esl-logistic.png}
\includegraphics[width=0.64\textwidth]{img/glm-binomial-example.png}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Understanding the Model Summary}

A logistic regression model looks like this (see also Section~\ref{ssect:logreg}):
\begin{equation} \log \frac{\mu}{1-\mu} = \beta_0 + \beta_1 x_1 + \dots + \beta_p x_p \label{eqn:logistic} \end{equation}
where $\mu$ is the mean of the Bernoulli distribution (see Section~\ref{sect:bernoulli}) governing our binary outcome, $y$; in other words, it is the probability that $y = 1$.

You will note that there is no independent error term here as there was in linear regression. That's because the variance and mean of a Bernoulli distribution are coupled and depend only on $\mu$ (again, see Section~\ref{sect:bernoulli}).
\vspace{3mm}

\begin{question}{question:logreglink}
In logistic regression, $\mu$ itself is not equal the sum of the predictors; instead, the \textbf{logit} of $\mu$ is their sum. Based on what you know about $\mu$, why is a logistic regression model not of the form
$$ \mu = \beta_0 + \beta_1 x_1 + \dots + \beta_p x_p \text{?}$$
We will explore this further in Chapter~\ref{chapter:glms}.
\end{question}

\begin{question}{}
The decision boundary in logistic regression (see picture above) occurs where the sum of the linear predictors, $\beta_0 + \beta_1 x_1 + \dots + \beta_p x_p$, is zero. What value of $\mu$ does this correspond to? Why does this make sense, intuitively?
\end{question}

\subsection{The Call}

The first line of the output repeats the call you made to the \verb|glm| function in R to fit the model. The \texttt{glm} package fits a variety of different generalized linear models using maximum likelihood estimation (see Chapter~\ref{chapter:mlebasics}; this will also be discussed in more detail in Chapter~\ref{chapter:glms}). The \texttt{family = "binomial"} argument tells the function to fit a logistic regression model.

\subsection{Coefficients and Standard Errors}

Logistic regression models, like other GLMs, are fit using maximum likelihood (see Chapter~\ref{chapter:mlebasics} for a brief introduction). We will skip most of the details for now, but you can gain intuition by staring at Equation~\ref{eqn:logistic}. This equation says that the model's predicted value of $\mu$, the probability that the outcome will be positive ($y=1$), is controlled by the values of the predictors and their coefficients $\beta_0, \dots, \beta_p$.

By adjusting the values of the $\beta$s, the model causes $\mu$ to be high in regions of the feature space where $y=1$ and low where $y=0$. The values of the $\beta$s that do this the best are called the \textbf{maximum likelihood estimates}, and they are the coefficients shown in the model output.

As with linear regression, a full understanding of the standard errors requires matrix multiplication. However, they are related to the same factors that drive the standard errors in linear regression: (1) the spread of the values of the corresponding covariate about its mean (more spread will decrease the standard error) and (2) correlations between that covariate and other covariates in the model (tighter correlations will increase the standard error).
\vspace{5mm}

\begin{question}{}
Looking at the form of the logistic regression model
$$ \log \frac{\mu}{1-\mu} = \beta_0 + \beta_1 x_1 + \dots + \beta_p x_p $$
what does the value of each of the $\beta$s mean? What is $\beta_j$ telling us about how $y$ varies with the predictor $j$, all else being equal?
\end{question}

\begin{question}{}
The \textbf{odds} of something happening are defined as $\mu/(1-\mu)$, where $\mu$ is the probability that the thing occurs. In our example model, we are interested in the odds that $y=1$ (the patient is readmitted). Does a unit increase in $x_1$ (disease severity score) increase or decrease the odds that a patient will be readmitted? What about $x_2$ (social determinants score)?
\end{question}

\begin{question}{}
What are the odds of readmission for a patient with:
\begin{enumerate}[label=(\alph*)]
\item $x_1 = 0.1$ and $x_2 = 0.3$?
\item $x_1 = 0.1$ and $x_2 = -1.3$?
\item $x_1 = 1.1$ and $x_2 = 0.3$?
\end{enumerate}
\end{question}

\subsection{Hypothesis Tests of Coefficients}

Just as in linear regression, we can use our coefficients and standard errors to perform a hypothesis test on each regression coefficient, $\beta_j$, against the null hypothesis that $\beta_j = 0$ (the predictor $x_j$ has no effect on the outcome). In logistic regression, the quantity $\hat{\beta_j}/\text{se}(\hat{\beta}_j)$ will follow a normal distribution under the null.
\vspace{3mm}

\begin{question}{question:nulllogregexample}
Below are the null distributions for the hypothesis tests of our three regression coefficients, $\beta_0$, $\beta_1$, and $\beta_2$. In each graph, the maximum likelihood estimate of the coefficient is shown as a vertical dashed line. Based on these graphs, can you tell why the $p$-values for $\beta_0$ and $\beta_2$ are low and the one for $\beta_1$ is high? What is the intuition behind this?
\begin{center}
\includegraphics[width=0.45\textwidth]{img/logreg-example-beta-0.png}
\includegraphics[width=0.45\textwidth]{img/logreg-example-beta-1.png}
\includegraphics[width=0.45\textwidth]{img/logreg-example-beta-2.png}
\end{center}
\end{question}

\subsection{Deviance and Deviance Residuals}

The \textbf{deviance} (called \textbf{residual deviance} in the model output) plays a role in GLMs akin to that of the residual standard error in linear regression; it is a measure of the residual variation in the outcome not explained by the model. The \textbf{null deviance} is the deviance for a model that only includes an intercept. Under the null hypothesis that all of the $\beta$s are zero except the intercept (i.e, a model with no predictors explains the data as well as our model), the difference
$$ \text{null deviance} - \text{residual deviance} $$
is distributed as $\chi^2_p$, a chi-squared distribution (see Section~\ref{sect:chisqdist}) with $p$ degrees of freedom, where $p$ is the number of predictors.
\vspace{5mm}

\begin{question}{}
This test is a hypothesis test of the null hypothesis that a model with no predictors fits our data as well as our model, where goodness of fit is measured by the deviance (lower is better). What is this hypothesis test akin to in the linear regression model output?
\end{question}

\begin{question}{}
The difference in null and residual deviances in this case is $67.72$. It follows a $\chi^2_2$ distribution under the null. A plot of the $\chi^2_2$ distribution and our test statistic is shown below. What do these findings indicate about the $p$-value of this goodness of fit test and what does it mean?
\begin{center}
\includegraphics[width=0.7\textwidth]{img/logreg-example-goodness-of-fit-test.png}
\end{center}
\end{question}

In the GLM context, there are multiple types of residual (more on this later). \textbf{Deviance residuals} quantify the contributions of the individual samples to the deviance. Unfortunately, the output from \texttt{glm} is confusing because what \texttt{glm} calls a deviance residual in the model summary is actually something called a \textbf{working residual}. We will ignore this part of the output until we understand more about the inner workings of GLMs.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Example: Low Birthweight Dataset \label{sect:lowbwt}}

The goal of this study was to identify risk factors associated with giving birth to a low birth weight baby (a baby weighing less than 2500 grams). Infant mortality rates and birth defect rates are very high for low birth weight babies. A woman's behavior during pregnancy (including diet, smoking habits, and receiving prenatal care) can greatly alter the chances of carrying the baby to term and, consequently, of delivering a baby of normal birth weight.

Data were collected on 189 women, 59 of which had low birth weight babies and 130 of which had normal birth weight babies\footnote{SOURCE: Hosmer and Lemeshow (2000) \emph{Applied Logistic Regression: Second Edition}. Data were collected at Baystate Medical Center, Springfield, Massachusetts during 1986.}.

\begin{center}
\texttt{ \small
\begin{tabular}{ll}
\toprule
LOW & Low birth weight (0 = birth weight $\geq$ 2500 g;\\
& 1 = birth weight $< 2500$ g) \\
AGE & Age of mother in years \\
LWT & Mother's weight in pounds at last menstrual period \\
RACE & Race (1 = white, 2 = black, 3 = other) \\
SMOKE & Smoking status during pregnancy (1 = yes, 0 = no) \\
PTL & History of premature labor (0 = none, 1 = one, etc.) \\
HT & History of hypertension (0 = no, 1 = yes) \\
UI & Presence of uterine irritability (0 = no, 1 = yes) \\
FTV & Number of physician visits during the first trimester \\
BWT & Birth weight in grams \\
\bottomrule
\end{tabular}
}
\end{center}

We will build a model that predicts the value of \texttt{LOW} based on all of the other covariates except, of course, \texttt{BWT}. (Why not use \texttt{BWT}?)

\begin{center}
\includegraphics[width=0.7\textwidth]{img/logreg-low-bwt-example-model.png}
\end{center}

\begin{question}{}
In this model, is the effect of one predictor (say, \verb|AGE|) impacted by the value(s) of any of the other predictor(s)? How does this differ from the other classification algorithms we've seen (KNN and decision trees)? What are the advantages and disadvantages of this choice?
\end{question}

\begin{question}{}
Comment on how the variable \texttt{RACE} enters into the model here. Does this make sense in light of what that variable means and how it potentially interacts with the other study variables?
\end{question}

\begin{question}{}
Interpret the values of each of these coefficients. Based on the coefficient values and their standard errors, which predictor(s) do you think have the greatest impact on whether or not a woman has a low birthweight baby?
\end{question}


    \filetitle{normal}{Create function proportional to log of Normal or Student distribution}{logdist/normal}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
F = logdist.normal(Mean,Std,Df)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{Mean} {[} numeric {]} - Mean of the normal distribution.
\item
  \texttt{Std} {[} numeric {]} - Std dev of the normal distribution.
\item
  \texttt{W} {[} numeric {]} - Optional input containing mixture
  weights.
\end{itemize}

Multivariate cases are supported. Evaluating multiple vectors as an
array of column vectors is supported.

If the mean and standard deviation are cell arrays then the distribution
will be a mixture of normals. In this case the third argument is the
vector of mixture weights.

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{F} {[} function\_handle {]} - Function handle returning a
  value proportional to the log of Normal density.
\end{itemize}

\paragraph{Description}\label{description}

See \href{logdist/Contents}{help on the logdisk package} for details on
using the function handle \texttt{F}.

\paragraph{Example}\label{example}


\documentclass[12pt]{amsart}

\newtheorem{theorem}{Theorem}
\newtheorem*{corollary}{Corollary}
\newtheorem*{lemma}{Lemma}
\theoremstyle{definition}
\newtheorem{problem}{Problem}

\newcommand{\C}{\mathbb{C}}
\DeclareMathOperator{\re}{Re}
\renewcommand{\iint}{\int\!\!\!\int}
\newcommand{\Beta}{B}

\addtolength{\headheight}{1.5pt}

\begin{document}

\title{Lu Qi-Keng's Problem}

\author{Harold P. Boas}

\address{Department of Mathematics, Texas A\&M University,
  College Station, TX 77843--3368, USA}

\email{boas@math.tamu.edu}

\thanks{This article is based on a lecture at the third Korean
  several complex variables symposium in December 1998.  The
  author thanks GARC, the Global Analysis Research Center at
  Seoul National University, for sponsoring his participation in
  this international conference.}

\thanks{The author's research was partially supported by grant
  number DMS-9801539 from the National Science Foundation of the
  United States of America.}

\begin{abstract}
  This expository article, intended to be accessible to students,
  surveys results about the presence or absence of zeroes of the
  Bergman kernel function of a bounded domain in~\(\C^n\). Six
  open problems are stated.
\end{abstract}

\subjclass{Primary 32H10}

\maketitle

\setcounter{tocdepth}{1}
\tableofcontents

\section{Introduction}
When does a convergent infinite series of holomorphic functions
have zeroes?  This question is a fundamental, difficult problem
in mathematics.

For example, the series \(\sum_{n=0}^\infty z^n/n!\) is
zero-free, but how can one tell this without a priori knowledge
that the series represents the exponential function? Changing the
initial term of this series produces a new series that does have
zeroes, since the range of the exponential function is all
non-zero complex numbers. The problem of determining when a
series has zeroes is essentially equivalent to the hard problem
of determining the range of a holomorphic function that is
presented as a series.

A famous instance of the problem of locating zeroes of infinite
series is the Riemann hypothesis about the zeta function: namely,
the conjecture that when \(0<\re z<1/2\), the convergent series
\(\sum_{n=1}^\infty (-1)^n/n^z\) has no zeroes. This formulation
of the Riemann hypothesis is equivalent to the usual statement
that the zeroes of \(\zeta(z)\) in the critical strip where
\(0<\re z<1\) all lie on the line where \(\re z=1/2\). Indeed,
when \(\re z>1\), absolute convergence justifies writing that
\begin{equation*}
\sum_{n=1}^\infty \frac{(-1)^n}{n^z} = -\sum_{n=1}^\infty
\frac{1}{n^z} +2\sum_{\text{even \(n\)}}\frac{1}{n^z}
=\zeta(z)(2^{1-z}-1).
\end{equation*}
By the principle of persistence of functional relationships, the
expressions on the outer ends of this equality still agree when
\(0<\re z<1\), so \(\zeta(z)\) and \(\sum_{n=1}^\infty
(-1)^n/n^z\) have the same zeroes in the interior of the critical
strip. Moreover, the well known functional equation for the zeta
function implies that the zeroes of~\(\zeta\) in the critical
strip are symmetric about the point~\(1/2\), so it suffices to
examine the left half of the critical strip for zeroes.

In this article, I shall discuss a different instance of the
general problem of locating zeroes of infinite series.  The
Bergman kernel function is most conveniently expressed as the sum
of a convergent infinite series.  In 1966, Lu Qi-Keng \cite{lu}
asked: for which domains is the Bergman kernel function
\(K(z,w)\) zero-free? I shall address three general methods for
approaching this problem, and I shall give examples both of
domains whose Bergman kernel functions are zero-free and of
domains whose Bergman kernel functions have zeroes.

\section{The Bergman kernel function}
\subsection{Definition}
The Bergman kernel function \(K(z,w)\) of a domain~\(D\) in
\(\C^n\) is the unique
sesqui-holomorphic\footnote{Sesqui-holomorphic means holomorphic
  in the first variable and conjugate holomorphic in the second
  variable.} function satisfying the skew-symmetry property that
\(K(z,w)=\overline {K(w,z)}\) and the reproducing property that
\begin{equation*}
f(z)=\int_D K(z,w) f(w) \,d\text{Volume}_w  \qquad \text{for all
  $z$ in $D$}
\end{equation*}
for every square-integrable holomorphic function~\(f\) on~\(D\).
Equivalently, \(K(z,w)=\sum_j
\varphi_j(z)\overline{\varphi_j(w)}\), where \(\{\varphi_j\}\) is
an orthonormal basis for the Hilbert space of square-integrable
holomorphic functions on~\(D\). To compute the Bergman kernel
function, one typically chooses an orthogonal basis, calculates
the normalizing factors, and sums the series.

For example, the monomials \(1\), \(z\), \(z^2\),
\ldots, are orthogonal on the unit disk in the complex plane, and
the norm of \(z^k\) is \((\int_{0}^{2\pi} \int_{0}^{1}
r^{2k+1}\,dr\,d\theta)^{1/2}\), or \(\sqrt{2\pi/(2k+2)}\).
Therefore the Bergman kernel function \(K(z,w)\) of the unit disk
equals
\begin{equation}
  \label{eq:disk}
  \sum_{k=0}^\infty \frac{k+1}{\pi} \cdot z^k \bar w^k
  = \frac{1}{\pi}\cdot \frac{1}{(1-z\bar w)^2}.
\end{equation}
This result is compatible with the Cauchy integral formula
\begin{equation*}
f(z)=\frac{1}{2\pi i}\oint_{|w|=1}
\frac{f(w)}{w-z}\,dw,
\end{equation*}
which can be rewritten by Green's formula as
\begin{equation*}
f(z)=\frac{1}{\pi}\iint_{|w|<1} \frac{f(w)}{(1-z\bar w)^2}
\,d\text{Area}_w,
\end{equation*}
thus confirming that the kernel function~\eqref{eq:disk} does
have the required reproducing property.

\subsection{Transformation rule}
If \(f:D_1\to D_2\) is a biholomorphic\footnote{Biholomorphic
  means holomorphic with a holomorphic inverse.} mapping, and if
\(K_1\) and~\(K_2\) denote the Bergman kernel functions of the
domains \(D_1\) and~\(D_2\) in~\(\C^n\), then
\begin{equation}
\label{eq:transform}
K_1(z,w)=(\det f'(z)) K_2(f(z), f(w)) (\,\overline{\det f'(w)}\,).
\end{equation}
This relationship holds because if \(\{\varphi_j\}\) is an
orthonormal basis for the square-integrable holomorphic functions
on~\(D_2\), then \(\{(\det f') \,\varphi_j\circ f\}\) is an
orthonormal basis for the square-integrable holomorphic functions
on~\(D_1\). For example, scaling~\eqref{eq:disk} shows that the
Bergman kernel function of the disk of radius~\(r\) is equal to
\(\dfrac{1}{\pi r^2}\cdot \dfrac{1}{(1-z\bar w/r^2)^2}\).

It is an observation of Steven~R. Bell \cite{bell1981, bell1982}
that a similar transformation rule holds even when \(f:D_1\to
D_2\) is a branched \(m\)-fold covering (a proper holomorphic
mapping): namely,
\begin{equation*}
\sum_{k=1}^m K_1(z, f_k^{-1}(w))
(\,\overline{\det (f_k^{-1})'(w)}\,) =
(\det f'(z)) K_2(f(z),w),
\end{equation*}
where the \(f_k^{-1}\) are the \(m\) holomorphic local inverses
of~\(f\).  This formula is not valid on the branching set, where
local inverses are not defined.

The Bergman kernel function \(K(z,w)\) of a simply-connected
planar domain~\(D\) is related to the Riemann mapping
function~\(f\) that maps~\(D\) onto the unit disk, taking the
point~\(a\) to~\(0\): namely,
\begin{equation}
\label{eq:riemann}
f'(z)=K(z,a)\sqrt{\frac{\pi}{K(a,a)}}.
\end{equation}
Indeed, the  transformation rule~\eqref{eq:transform} implies that
\begin{equation*}
K(z,w)=f'(z)\cdot\frac{1}{\pi}\cdot
\frac{1}{(1-f(z)\overline{f(w)}\,)^2}\cdot\overline{f'(w)}.
\end{equation*}
Since \(f(a)=0\), and \(f'(a)\) is real and positive,
setting \(w=a\) implies that
\begin{math}
\pi K(z,a)=f'(z) f'(a)
\end{math},
and then setting \(z=a\) makes it possible to eliminate~\(f'(a)\)
to obtain~\eqref{eq:riemann}.

Since the Riemann mapping function solves a certain extremal
problem, the connection in one dimension with the Bergman kernel
function suggests studying the Bergman kernel function in higher
dimensions in connection with extremal problems.

\subsection{Extremal properties}
\label{extremal}
One can use extremal characterizations of the Bergman kernel
function to help prove theorems about convergence of the Bergman
kernel functions of a convergent sequence of domains.  In the
following two properties, the point~\(w\) is fixed in a
domain~\(D\) in~\(\C^n\), and \(\{\varphi_j\}\) is an orthonormal
basis for the Hilbert space \(A^2(D)\) of square-integrable
holomorphic functions on~\(D\).

\begin{enumerate}
\item In the class of holomorphic functions~\(f\) on~\(D\) such
  that \(\int_D |f|^2\le 1\), the maximal value of \(|f(w)|^2\)
  is \(K(w,w)\). In other words, \(K(w,w)\) is the square of the
  norm of the functional from \(A^2(D)\) to~\(\C\) that
  evaluates a function at the point~\(w\).

  Indeed, if \(f(z)=\sum_j c_j \varphi_j(z)\), and if \(\sum_j
  |c_j|^2\le1\), then the Cauchy-Schwarz inequality implies that
  \(|\sum_j c_j \varphi_j(w)|^2\) is bounded above by \(\sum_j
  |\varphi_j(w)|^2\), which equals \(K(w,w)\); and the upper
  bound is attained if \(c_j\) is taken equal to
  \(\overline{\varphi_j(w)}/(\sum_j |\varphi_j(w)|^2)^{1/2}\).

\item In the class of holomorphic functions~\(f\) on~\(D\)
  satisfying the nonlinear constraint that \(f(w)\ge \int_D
  |f|^2\), the function with the maximal value at~\(w\) is
  \(K(\cdot,w)\).

  Indeed, it is evident that the function \(K(\cdot,w)= \sum_j
  \overline{\varphi_j(w)}\,\varphi_j\) is in the class. On the
  other hand, if \(f=\sum_j c_j \varphi_j\) is an arbitrary
  member of the class, then the preceding extremal property
  implies that \(f(w)^2\le K(w,w)\sum_j |c_j|^2\); and since the
  defining property of the class implies that \((\sum_j
  |c_j|^2)^2 \le f(w)^2\), it follows that \(\sum_j|c_j|^2\le
  K(w,w)\), and hence \(f(w)\le K(w,w)\).
\end{enumerate}

\section{Motivation for Lu Qi-Keng's problem}
The Riemann mapping theorem characterizes the planar domains that
are biholomorphically equivalent to the unit disk. In higher
dimensions, there is no Riemann mapping theorem,\footnote{More
  precisely, in order to obtain a generalized Riemann mapping
  theorem, one needs either new hypotheses \cite{chernji} or new
  definitions \cite{semmes}.} and two natural problems arise.

\begin{enumerate}
\item Are there canonical representatives of biholomorphic
  equivalence classes of domains?

\item How can one tell that two particular domains are
biholomorphically inequivalent?
\end{enumerate}

As an approach to the first question, Stefan Bergman introduced
the notion of a ``representative domain'' to which a given domain
may be mapped by ``representative coordinates''.  If \(g_{jk}\)
denotes the Bergman metric
\begin{math}
\dfrac{\partial^2}{\partial z_j\partial\bar  z_k}\log K(z,z)
\end{math},
where \(K\)~is the Bergman kernel function, then the local
representative coordinates based at the point~\(a\) are
\begin{equation*}
\sum_{k=1}^n
g_{kj}^{-1}(a) \left. \frac{\partial}{\partial \bar w_k} \log
\frac{K(z,w)}{K(w,w)} \right|_{w=a}, \qquad j=1, \dotsc, n.
\end{equation*}
These coordinates take \(a\) to~\(0\) and have complex Jacobian
matrix at~\(a\) equal to the identity.

Zeroes of the Bergman kernel function \(K(z,w)\) evidently pose
an obstruction to the global definition of Bergman representative
coordinates. This observation was Lu Qi-Keng's motivation for
asking which domains have zero-free Bergman kernel functions.

On the other hand, if the Bergman kernel function of a domain
does have zeroes, then the transformation
rule~\eqref{eq:transform} shows that the zero set is a
biholomorphically invariant object. Therefore zero sets of
Bergman kernel functions could be a tool for addressing the
second question stated above. This idea has not yet been
exploited in the literature.

\section{First examples}
\label{first}
The Bergman kernel function~\eqref{eq:disk} of the unit disk is
evidently zero-free.  Consequently, the Bergman kernel function
of every bounded, simply connected, planar domain is zero-free:
apply either the transformation rule~\eqref{eq:transform} or the
explicit formula~\eqref{eq:riemann} relating the Riemann mapping
function to the Bergman kernel function.

On the other hand, the Bergman kernel function of every annulus
does have zeroes \cite{rosenthal,skwar}; more generally, the
Bergman kernel function of every bounded, multiply connected,
planar domain with smooth boundary has zeroes \cite{suitayamada}.

Isolated singularities of square-integrable holomorphic functions
are removable, and therefore the Bergman kernel function does not
see isolated punctures in a domain.  For example, the Bergman
kernel function of a punctured disk is zero-free. On the other
hand, a finitely connected planar domain with no singleton
boundary component can be mapped biholomorphically to a smoothly
bounded domain.  Consequently, if a bounded planar domain is
finitely connected and has at least two non-singleton boundary
components, then its Bergman kernel function has zeroes.

I do not know if a corresponding statement holds for infinitely
connected planar domains. For example, delete from the open unit
disk a countable sequence of pairwise disjoint closed disks that
accumulate only at the boundary of the unit disk. Does the
Bergman kernel function of the resulting domain have zeroes?

\begin{problem}
  Give necessary and sufficient conditions on an infinitely
  connected planar domain for its Bergman kernel function to have
  zeroes.
\end{problem}

It is easy to see that in higher dimensions, the Bergman kernel
function of a product domain is the product of the Bergman kernel
functions of the lower dimensional domains. Consequently, the
Bergman kernel function of a polydisc is zero-free, while the
Bergman kernel function of the Cartesian product of a disc with
an annulus does have zeroes. The Bergman kernel function
\(K(z,w)\) of the unit ball in~\(\C^n\) is the zero-free function
\(\dfrac{n!}{\pi^n}\cdot \dfrac{1}{(1-\langle
z,w\rangle)^{n+1}}\), where \(\langle z,w\rangle\) denotes the
scalar product \(z_1\bar w_1 + \dots + z_n \bar w_n\).

Even without knowing this explicit formula, one can see that the
Bergman kernel function of the unit ball is zero-free.  Since the
ball is a complete circular domain,\footnote{A domain is called
  complete circular if whenever it contains a point~\(z\), it
  also contains the one-dimensional disk \(\{\,\lambda z:
  |\lambda|\le1\,\}\).}  its space of square-integrable
holomorphic functions has an orthonormal basis whose first
element is a constant (namely, the reciprocal of the square root
of the volume of the domain) and whose other elements are
functions that vanish at the origin.  Consequently, the Bergman
kernel function~\(K\) has the property that \(K(z,0)\) is a
non-zero constant function of~\(z\). Since the ball is
homogeneous,\footnote{A domain is called homogeneous if it has a
  transitive automorphism group, that is, if any point of the
  domain can be mapped to any other point by a biholomorphic
  self-mapping of the domain.}  the transformation
rule~\eqref{eq:transform} implies that the Bergman kernel
function is nowhere zero. The same argument shows that every
bounded, homogeneous, complete circular domain has a zero-free
Bergman kernel function \cite{belldavid}.

For many years it was thought that sufficiently nice,
topologically trivial, bounded domains in~\(\C^n\) should have
zero-free Bergman kernel functions. For example, all strongly
convex,\footnote{The statement is also true for strongly
  pseudoconvex domains, that is, domains that locally can be
  mapped biholomorphically to strongly convex domains.}
sufficiently small perturbations of the ball have zero-free
Bergman kernel functions if ``small'' is interpreted in the
\(C^\infty\) topology on domains \cite{greenekrantz}.  It turns
out, however, to be the generic situation for the Bergman kernel
function of a domain of holomorphy to have zeroes, if ``generic''
is interpreted in the very flexible Hausdorff topology on domains
\cite{boasgeneric}.

\begin{problem}
  Do there exist arbitrarily small class \(C^1\) perturbations of
  the ball whose Bergman kernel functions have zeroes?
\end{problem}

I shall now discuss three techniques that can be used to show the
existence of interesting domains whose Bergman kernel functions
have zeroes.

\section{Variation of domains}
\label{variation-domains}
If reasonable domains \(\Omega_j\) converge in a reasonable way
to a limiting domain \(\Omega\), then the Bergman kernel
functions \(K_{\Omega_j}(z,w)\) converge to \(K_\Omega(z,w)\)
uniformly on compact subsets of \(\Omega\times\Omega\).  The word
``reasonable'' can be made precise \cite{boasgeneric}, but here I
will simply mention two examples of reasonable behavior. The
first example is a fundamental theorem of I.~P. Ramadanov
\cite{ramadanov} which started the whole theory.
\begin{itemize}
\item The \(\Omega_j\) form an increasing sequence whose union
  is~\(\Omega\).

\item The \(\Omega_j\) are bounded pseudoconvex\footnote{A domain
is pseudoconvex if it is the union of an increasing sequence of
strongly pseudoconvex domains, as defined in the preceding
footnote. According to the solution of the Levi problem (see, for
example, \cite{Krantz}), pseudoconvex domains are the same as
domains of holomorphy.} domains whose complements converge in the
Hausdorff metric to the complement of an~\(\Omega\) whose
boundary is locally a graph.
\end{itemize}
An example of unreasonable convergence is a sequence of disks
shrinking down to a disk with a slit \cite{skwarczynski}.

The proof of the convergence theorem exploits the extremal
characterization of the Bergman kernel function from
section~\ref{extremal}. The application to Lu Qi-Keng's problem
is that by Hurwitz's theorem, if the Bergman kernel function of
the limiting domain~\(\Omega\) has zeroes, then so does the
Bergman kernel function of the approximating domain~\(\Omega_j\)
when \(j\)~is sufficiently large.

Consequently, to construct a nice domain whose Bergman kernel
function has zeroes, it suffices to construct a degenerate domain
whose Bergman kernel function has zeroes, and then to approximate
the degenerate domain by nice ones. For example, an easy
calculation shows that constant functions are not
square-integrable on the domain
\begin{equation}
\label{eq:counterex}
  \left\{\, (z_1,z_2)\in\mathbf{C}^2: |z_2|<\frac{1}{1+|z_1|}\,
\right\},
\end{equation}
although the domain does support some non-constant
square-integrable holomorphic functions. Therefore the Bergman
kernel function of this domain has a zero at the origin, but is
not identically zero.  By approximating this domain from inside,
one sees that there exists a bounded, smooth, logarithmically
convex, complete Reinhardt domain\footnote{A domain is called
  complete Reinhardt if whenever it contains a point
  \((z_1,\dotsc,z_n)\), it also contains the polydisc
  \(\{\,(\lambda_1z_1, \dotsc, \lambda_nz_n): |\lambda_1|\le1,
  \dotsc, |\lambda_n|\le1\,\}\). The logarithmically convex
  complete Reinhardt domains are the convergence domains of power
  series.}  whose Bergman kernel function has zeroes
\cite{boascounterexample}.  This example was surprising when it
was first discovered; indeed, it contradicts a theorem previously
published by two different authors \cite[Theorem~1]{matsuura},
\cite[Corollary]{kakurai} and applied by a third \cite{kanemaru}.

Nguy\^en Vi\^et Anh, a student in Marseille, recently showed
\cite{anh} how to approximate the domain~\eqref{eq:counterex}
from inside by \emph{concrete} domains that are smooth,
algebraic, logarithmically convex, complete Reinhardt domains.
Namely, the domain defined by the inequality
\begin{equation}
\label{eq:anh}
  |z_2|^{2k}(1+|z_1|)^{2k} + |z_2|^{2k}(1-|z_1|)^{2k} + \left(
  \frac{|z_1|^2+|z_2|^2} {k}\right)^k <1
\end{equation}
has the indicated properties when \(k\)~is a positive integer,
and so the Bergman kernel function of this domain must have
zeroes when \(k\)~is sufficiently large.

\begin{problem}
  How large must \(k\) be in order for the Bergman kernel
  function of the domain~\eqref{eq:anh} to have zeroes?
\end{problem}

The technique of variation of domains can be used to prove the
statement at the end of section~\ref{first} that every nice
domain can be arbitrarily closely approximated in the Hausdorff
metric by a nice domain whose Bergman kernel function has zeroes.
View the starting domain as the Earth, and place in orbit around
the Earth a small copy of one of the bounded domains just
discussed. The Bergman kernel function of this disconnected
region has zeroes because the Bergman kernel function of the
satellite has zeroes. Now attach the satellite to the Earth by a
thin tether. If the tether is sufficiently thin, then the
principle of variation of domains implies that the Bergman kernel
function of the joined domain has zeroes. According to the
barbell lemma \cite[Chapter~5, Exercise~21]{Krantz} in a suitable
formulation \cite{boasgeneric}, the joined domain can be made
strongly pseudoconvex if the Earth is.

\section{Variation of weights}
In the representation of the Bergman kernel function as an
infinite series \(\sum_j \varphi_j(z)\overline{\varphi_j(w)}\),
the basis elements~\(\varphi_j\) are supposed to be orthonormal
for integration with respect to Lebesgue measure.  It is natural
to consider the analogous construction when Lebesgue measure is
multiplied by a positive weight function.

For instance, if \(G\)~is a domain in~\(\C^n\), and \(\Omega\)~is
a Hartogs domain in~\(\C^{n+1}\) with base~\(G\), which means
that \(\Omega = \{\,(z,z_{n+1})\in\C^{n+1}: z\in G\) and
\(|z_{n+1}|<r(z)\,\}\), where \(r\)~is a positive function
on~\(G\), then the Bergman kernel function of~\(\Omega\)
restricted to the base~\(G\) equals the weighted Bergman kernel
function of~\(G\) corresponding to the weight \(\pi r^2\). This
follows because the Bergman kernel function is uniquely
determined by its reproducing property, and holomorphic functions
on~\(G\) correspond to holomorphic functions on~\(\Omega\) that
are independent of the extra variable. Consequently, zeroes of
weighted Bergman kernel functions give rise to zeroes of ordinary
Bergman kernel functions of higher-dimensional domains.

As a concrete example, consider on a bounded domain~\(G\)
in~\(\C^n\) containing the origin the weight function
\(\exp(-t\|z\|)\), where \(t\) is a real parameter, and
\(\|z\|\)~denotes the Euclidean length
\(\sqrt{|z_1|^2+\dots+|z_n|^2}\).  Let \(K_t(z,w)\) denote the
Bergman kernel function of~\(G\) with respect to this weight. It
is a special case of a recent theorem of Miroslav Engli{\v{s}}
\cite{englis} that this weighted Bergman kernel function must
have zeroes near the origin when \(t\)~is sufficiently large.

Remarkably, the proof depends on the non-smoothness of the weight
function.  The idea is to show that
\(\lim_{t\to\infty}K_t(z,z)^{1/t}=e^{\|z\|}\). It follows that
the function \(K_t(z,w)\) cannot be zero-free for every
large~$t$, for if it were, then a sesqui-holomorphic branch of
\(K_t(z,w)^{1/t}\) could be defined near the origin.  When
\(t\to\infty\), there would be a limiting sesqui-holomorphic
function \(L(z,w)\) such that \(L(z,z)=e^{\|z\|}\); but this is
impossible because the function~\(e^{\|z\|}\) is not real
analytic at the origin.

The verification that
\(\lim_{t\to\infty}K_t(z,z)^{1/t}=e^{\|z\|}\) is carried out via
an upper estimate and a lower estimate.  Let \(\|f\|_t\) denote
the weighted norm \((\int_G |f(w)|^2 e^{-t\|w\|}\, dV_w)^{1/2}\).
If \(f\)~is a holomorphic function, and \(B_z\)~is a small ball
centered at~\(z\) with volume \(|B_z|\), then the mean-value
property of holomorphic functions and the Cauchy-Schwarz
inequality imply that \(|f(z)|\) is bounded above by \(\|f\|_{t}
\,|B_z|^{-1} (\int_{B_z} e^{t\|w\|}\, dV_w)^{1/2}\). Therefore
\(K_t(z,z)\), which is the square of the norm of the point
evaluation functional, is bounded above by \(|B_z|^{-1}
\sup_{w\in B_z} e^{t\|w\|}\), and so \(\limsup_{t\to \infty}
K_t(z,z)^{1/t} \le \sup_{w\in B_z} e^{\|w\|}\). Now let the
radius of the ball~\(B_z\) shrink to zero to conclude that
\(\limsup_{t\to \infty} K_t(z,z)^{1/t} \le e^{\|z\|}\).

For the lower bound, use the convexity of the Euclidean norm and
the representation of a supporting hyperplane as the zero set of
the real part of a linear holomorphic function. For each
point~\(z\) in the domain, there is a holomorphic function~\(g\)
such that \(\re g(w)\le\|w\|\) for all~\(w\), and \(\re
g(z)=\|z\|\).  Since \(K_t(z,z)\) is the square of the norm of
the point evaluation functional, it is no smaller than
\(|e^{tg(z)}|/\|e^{tg/2}\|_t^2\), which in turn is no smaller
than \(e^{t\|z\|}\) divided by the volume of the domain.
Consequently, \(\liminf_{t\to\infty} K_t(z,z)^{1/t}\ge
e^{\|z\|}\).

  \begin{problem}
    For concrete examples, determine how large \(t\) must be
    taken in Engli{\v{s}}'s theorem to guarantee that the
    weighted Bergman kernel function has zeroes.
  \end{problem}

\section{Weighted disk kernels and convex domains}
In the preceding section, I remarked that the Bergman kernel
function of a Hartogs domain in~\(\C^{n+1}\) is related to a
weighted Bergman kernel function on the base domain in~\(\C^n\).
For the same reason, a multi-dimensional domain that is fibered
over a one-dimensional base has a Bergman kernel function that is
related to a weighted Bergman kernel function on the base.  In
this section, I shall discuss an interesting example of this
general principle.

The domain in~\(\C^n\) defined by the inequality
\begin{equation}
\label{eq:ex}
|z_1| + |z_2|^{2/p_2} + \dots + |z_n|^{2/p_n} <1
\end{equation}
has a Bergman kernel function whose restriction to the
\(z_1\)-axis is proportional to the weighted Bergman kernel
function for the unit disk \(\{z\in\C: |z|<1\}\) with weight
\((1-|z|)^{p_2+\dots+p_n}\).  Here the~\(p_j\) can be arbitrary
positive real numbers, and the proportionality constant is the
volume of the \((n-1)\)-dimensional domain defined by the
inequality
\begin{equation*}
|z_2|^{2/p_2} + \dots + |z_n|^{2/p_n} <1.
\end{equation*}

Accordingly, it is useful to compute explicitly the weighted
Bergman kernel function~\(K_q\) for the unit disk with weight
\((1-|z|)^q\), where \(q>0\).  The square of the norm of the
monomial \(z^k\) with weight factor \( (1-|z|)^q\) is
\begin{equation*}
\int_0^{2\pi}\int_0^1 r^{2k+1} (1-r)^q \,dr\,d\theta =
2\pi \Beta(2k+2,q+1),
\end{equation*}
where \(\Beta\) is the Beta function defined in terms of the
Gamma function by \(\Beta(a,b)= \Gamma(a)
\Gamma(b)/\Gamma(a+b)\).  Consequently, the weighted Bergman
kernel function \(K_q(z,w)\) equals
\((2\pi)^{-1}\sum_{k=0}^\infty (z\bar w)^k/\Beta(2k+2,q+1)\). A
closed form expression for this series is most conveniently
written in terms of the squares of the variables:
\begin{equation}
\label{eq:q}
K_q(z^2, w^2)= \frac{(q+1)}{4\pi z\bar w} \left[ \frac{1}{(1-z\bar
w)^{q+2}} - \frac{1}{(1+z\bar w)^{q+2}} \right].
\end{equation}
The powers of $(1\pm z\bar w)$ are to be understood as principal
branches.  The validity of this closed form expression can be
verified by the binomial series expansion.

The explicit expression~\eqref{eq:q} implies that the weighted
Bergman kernel function~\(K_q\) has zeroes in the interior of the
unit disk if and only if \(q>2\). Indeed, taking limits
in~\eqref{eq:q} shows that \(K_q\)~is not equal to~\(0\) when
either coordinate is equal to~\(0\), so it is only necessary to
decide if \((1-t)^{q+2}=(1+t)^{q+2}\) for some non-zero~\(t\) in
the unit disk. Since the mapping \(t\mapsto (1+t)/(1-t)\) takes
the unit disk bijectively to the right half-plane, with the
origin going to the point~\(1\), following this mapping by the
mapping \(u\mapsto u^{q+2}\) produces a composite mapping that
takes some non-zero point of the open unit disk to the
point~\(1\) if and only if \(q>2\).

Consequently, the Bergman kernel function of the
domain~\eqref{eq:ex} is guaranteed to have zeroes if
\(p_2+\dots+p_n >2\). Moreover, this domain is geometrically
convex if no~\(p_j\) exceeds~\(2\).  Therefore, one can exhibit
many concrete examples of convex domains whose Bergman kernel
functions have zeroes \cite{boasfustraube}. Here are some:
\begin{equation}
\label{eq:convex}
\begin{gathered}
\{\,z\in\C^3: |z_1|+|z_2|+|z_3|<1\,\}, \\
\{\,z\in\C^3: |z_1|+|z_2|+|z_3|^2<1\,\}, \\
\{\,z\in\C^4: |z_1|+|z_2|^2+|z_3|^2+|z_4|^4<1\,\}.
\end{gathered}
\end{equation}

Using a different method, Peter Pflug and E.~H. Youssfi found
some other interesting examples of convex domains whose Bergman
kernel functions have zeroes.  Even though the ``minimal ball''
in~\(\C^n\) defined by the inequality
\begin{equation}
\label{eq:minimal}
  |z_1|^2+\dots+|z_n|^2 + |z_1^2+\dots+z_n^2| <1
\end{equation}
lacks multi-circular symmetry, its Bergman kernel function is
known explicitly \cite{opy}, and in \cite{pflugyoussfi} the
authors analyzed the explicit formula to see that the Bergman
kernel function of this domain has zeroes when \(n\ge4\).

Although the convex domains defined by \eqref{eq:convex}
and~\eqref{eq:minimal} do not have smooth boundaries, they can be
approximated from inside by smoothly bounded, strongly convex
domains.  From the method of variation of domains in
section~\ref{variation-domains}, it follows that when \(n\ge3\),
there exist smoothly bounded, strongly convex domains in~\(\C^n\)
whose Bergman kernel functions have zeroes.  Pflug and Youssfi
even showed in \cite{pflugyoussfi} how to write down concrete
examples of bounded, smooth, algebraic, strongly convex domains
that approximate~\eqref{eq:minimal} from inside.

Using the same idea, Nguy\^en Vi\^et Anh \cite{anh} gave concrete
examples of bounded, smooth, algebraic, strongly convex,
Reinhardt domains in~\(\C^n\) whose Bergman kernel functions have
zeroes when \(n\ge3\). For example, when \(k\)~is a sufficiently
large positive integer, the inequality
\begin{equation}
\label{eq:alg}
(|z_1|^2+|z_2|^2+|z_3|^2)^{2k} + \sum_{\substack{ \pm \\ \text{(8
terms)}}} (\pm |z_1| \pm |z_2| \pm |z_3|)^{2k} <1
\end{equation}
defines such a domain in~\(\C^3\).

To see that~\eqref{eq:alg} has the required properties, first
observe that the \(\ell_{2k}\) norm decreases to the
\(\ell_\infty\) norm as \(k\to\infty\), so these domains are
interior approximations to the domain \(\{\,z\in\C^3:
|z_1|+|z_2|+|z_3|<1\,\}\), which is one of the domains
\eqref{eq:convex} whose Bergman kernel functions have zeroes.
The odd powers of the \(|z_j|\) in the expansion
of~\eqref{eq:alg} cancel out by symmetry, so the defining
function is equivalent to a polynomial.  It would be obvious that
the defining function~\eqref{eq:alg} is convex if it had \(\re
z_j\) in place of~\(|z_j|\), for a convex function of a linear
function is convex; now observe that positive combinations of
even powers are increasing, and the composite of a convex
increasing function with the convex function~\(|z_j|\) is convex.

The two-dimensional domain defined by the inequality
\(|z_1|+|z_2|<1\) is a borderline case for the preceding
considerations. It turns out \cite{boasfustraube} that the
Bergman kernel function of this domain has no zeroes in the
interior of the domain, although it does have zeroes on the
boundary.

\begin{problem}
  Exhibit a bounded convex domain in~\(\C^2\) whose Bergman
  kernel function has zeroes in the interior of the domain.
\end{problem}

\section{Conclusion}
It is a difficult problem to determine whether the Bergman kernel
function of a specific domain has zeroes or not. If the kernel
function is presented as an infinite series, then locating the
zeroes may be of the same order of difficulty as proving the
Riemann hypothesis; and even if the series can be summed in
closed form, determining whether or not \(0\)~is in the range may
be hard.

In this article, I have emphasized examples in which the Bergman
kernel function does have zeroes. As the subject developed
historically, such examples were considered surprising. From our
current perspective, it would be more surprising to find some
simple geometric condition guaranteeing that the Bergman kernel
function is zero-free.

Students planning further investigation of the Bergman kernel
function might consult, in addition to the journal articles I
have cited, Bell's book \cite{bellbook} about the one-dimensional
theory, the book of Jarnicki and Pflug \cite{jarnickipflug}, and
Stefan Bergman's own book \cite{bergman}.  I offer the following
problem as an illustration of how much remains to be discovered
about the zeroes of the Bergman kernel function.

\begin{problem}
  Characterize the vectors \((p_1, p_2, \dots, p_n)\) of positive
  numbers for which the Bergman kernel function of the domain
  in~\(\C^n\) defined by the inequality
\begin{equation*}
|z_1|^{2/p_1}+|z_2|^{2/p_2} + \dots + |z_n|^{2/p_n} <1
\end{equation*}
is zero-free.
\end{problem}

%\bibliographystyle{amsplain} \bibliography{luqikeng}
%\providecommand{\bysame}{\leavevmode\hbox to3em{\hrulefill}\thinspace}

\begin{thebibliography}{10}

\bibitem{anh} Nguy\^en~Vi\^et Anh, \emph{The {L}u {Q}i-{K}eng
conjecture fails for strongly convex algebraic complete
{R}einhardt domains in $\mathbf{C}\sp n\ (n\ge3)$},
Proc. Amer. Math. Soc., to appear.

\bibitem{belldavid} David Bell, \emph{Some properties of the
{B}ergman kernel function}, Compositio Math. \textbf{21} (1969),
329--330.

\bibitem{bell1981} Steven~R. Bell, \emph{Proper holomorphic
mappings and the {B}ergman projection}, Duke Math. J. \textbf{48}
(1981), no.~1, 167--175.

\bibitem{bell1982} \bysame, \emph{The {B}ergman kernel function
and proper holomorphic mappings},
Trans. Amer. Math. Soc. \textbf{270} (1982), no.~2, 685--691.

\bibitem{bellbook} \bysame, \emph{The {C}auchy transform,
potential theory, and conformal mapping}, CRC Press, 1992.

\bibitem{bergman} Stefan Bergman, \emph{The kernel function and
conformal mapping}, revised ed., American Mathematical Society,
1970.

\bibitem{boascounterexample} Harold~P. Boas, \emph{Counterexample
to the {L}u {Q}i-{K}eng conjecture}, Proc.
Amer. Math. Soc. \textbf{97} (1986), no.~2, 374--375.

\bibitem{boasgeneric} \bysame, \emph{The {L}u {Q}i-{K}eng
conjecture fails generically}, Proc. Amer.
Math. Soc. \textbf{124} (1996), no.~7, 2021--2027.

\bibitem{boasfustraube} Harold~P. Boas, Siqi Fu, and
Emil~J. Straube, \emph{The {B}ergman kernel function: explicit
formulas and zeroes}, Proc. Amer. Math. Soc. \textbf{127} (1999),
no.~3, 805--811.

\bibitem{chernji} Shiing-Shen Chern and Shanyu Ji, \emph{On the
{R}iemann mapping theorem}, Ann.  of Math. (2) \textbf{144}
(1996), no.~2, 421--439.

\bibitem{englis} Miroslav Engli{\v{s}}, \emph{Asymptotic
behaviour of reproducing kernels of weighted {B}ergman spaces},
Trans. Amer. Math. Soc. \textbf{349} (1997), no.~9, 3717--3735.

\bibitem{greenekrantz} R.~E. Greene and Steven~G. Krantz,
  \emph{Stability properties of the {B}ergman kernel and
    curvature properties of bounded domains}, Recent developments
  in several complex variables, Princeton Univ. Press, 1981,
  pp.~179--198.

\bibitem{jarnickipflug} Marek Jarnicki and Peter Pflug,
  \emph{Invariant distances and metrics in complex analysis},
  Walter de Gruyter \& Co., 1993.

\bibitem{kakurai}
Shigeki Kakurai, \emph{On the Lu Qi-Keng conjecture},
Rep. Fac. Engrg. Kanagawa Univ. no.~17 (1979), 3--4.

\bibitem{kanemaru}
Tadayoshi Kanemaru,
\emph{A remark on the Lu Qi Keng conjecture},
Mem. Fac. Ed. Kumamoto Univ. Natur. Sci. no.~31 (1982), 1--3.

\bibitem{Krantz} Steven~G. Krantz, \emph{Function theory of
several complex variables}, second ed., Wadsworth \& Brooks/Cole,
1992.

\bibitem{lu} Lu~Qi-keng, \emph{On {K}aehler manifolds with
constant curvature}, Chinese Math.--Acta \textbf{8} (1966),
283--298.

\bibitem{matsuura} Shozo Matsuura, \emph{On the {L}u {Q}i-{K}eng
conjecture and the {B}ergman representative domains}, Pacific
J. Math. \textbf{49} (1973), 407--416.

\bibitem{opy} K.~Oeljeklaus, P.~Pflug, and E.~H. Youssfi,
\emph{The {B}ergman kernel of the minimal ball and applications},
Ann. Inst. Fourier (Grenoble) \textbf{47} (1997), no.~3,
915--928.

\bibitem{pflugyoussfi} P.~Pflug and E.~H. Youssfi, \emph{The {L}u
{Q}i-{K}eng conjecture fails for strongly convex algebraic
domains}, Arch. Math. (Basel) \textbf{71} (1998), no.~3,
240--245.

\bibitem{ramadanov} I.~Ramadanov, \emph{Sur une propri\'et\'e de
la fonction de {B}ergman}, C. R.  Acad. Bulgare Sci. \textbf{20}
(1967), 759--762.

\bibitem{rosenthal} Paul Rosenthal, \emph{On the zeros of the
{B}ergman function in doubly-connected domains},
Proc. Amer. Math. Soc. \textbf{21} (1969), 33--35.

\bibitem{semmes} Stephen Semmes, \emph{A generalization of
{R}iemann mappings and geometric structures on a space of domains
in $\mathbf{C}\sp n$}, Mem. Amer. Math. Soc.  \textbf{98} (1992),
no.~472.

\bibitem{skwar} M.~Skwarczy{\'n}ski, \emph{The invariant distance
in the theory of pseudoconformal transformations and the {L}u
{Q}i-keng conjecture}, Proc.  Amer. Math. Soc. \textbf{22}
(1969), 305--310.

\bibitem{skwarczynski} Maciej Skwarczy{\'n}ski,
\emph{Biholomorphic invariants related to the {B}ergman
function}, Dissertationes Math. \textbf{173} (1980).

\bibitem{suitayamada} Nobuyuki Suita and Akira Yamada, \emph{On
the {L}u {Q}i-keng conjecture}, Proc.
Amer. Math. Soc. \textbf{59} (1976), no.~2, 222--224.

\end{thebibliography}

\end{document}


%\documentclass[notitlepage,aps,pre,onecolumn]{revtex4-1}
\documentclass{article}
\usepackage{fullpage}

\usepackage{color}
\usepackage{amsmath,amsfonts,graphicx,enumerate,color,hyperref}
\usepackage{bm,braket,cancel}
\usepackage{tabularx}
\usepackage[normalem]{ulem}
\newcommand{\pa}{\partial}
\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\avg}[1]{\left\langle #1 \right\rangle}
\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\dd}[2]{\frac{d^2 #1}{d #2^2}}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\pdd}[2]{\frac{\partial^2 #1}{{\partial #2}^2}}
\renewcommand{\L}{\mathfrak{L}}
\renewcommand{\O}{\mathcal{O}\left(\epsilon^2\right)}
\newcommand{\s}[1]{^{(#1)}}
\newcommand{\0}{^{(0)}}

\usepackage[usenames]{xcolor}
\hypersetup{
    colorlinks,
    linkcolor={blue!50!black},%{red!80!black},
    citecolor={blue!50!black},
    urlcolor={blue!80!black}
}
\begin{document}
\title{Advection-diffusion of a scalar}
\author{YBS}
\maketitle

\section{Governing equations}
The time evolution of the concentration $c(\bm r, t)$ of a chemical which undergoes simultaneous diffusion (with diffusion constant $\eta$) and advection by a velocity field $\bm v(\bm r , t)$ is given by
\begin{align}
\pd{c}{t}+\bm v \cdot \nabla c=\eta \nabla^2 c
\label{eq:eom}
\end{align}
Te left-hand-side is the material time derivative (aka advective derivative).  The right-hand-side is diffusion. Physically, $\bm v$ should also satisfy an evolution equation of its own, but for our purposes we'll just assume it's constant in time. However, we will add the (physically valid) constraint that $\bm v$ is divergence-free, i.e.~$\nabla\cdot v=\sum_i \pa_i v_i=0$. In 2D, a divergence-free vector field over a periodic domain $[0,2\pi]\times[0,2\pi]$ can be decomposed to Fourier components of the form
\begin{align}
v_x&= \sum_i A_i m_i \cos (m_i y+\beta_i ) \cos (n_i x+\alpha_i )\ , &
v_y&=\sum_i A_i  n_i \sin (m_i y+\beta_i ) \sin (n_i x+\alpha_i )\ ,
\end{align}
where $A_i$ is the amplitude, $m_i, n_i$ are integers ($(m_i, n_i)$  is the wave-vector), and $\alpha_i, \beta_i$ are phases. For the simulation I simply draw all these parameters from a uniform distribution, using 5 terms for each simulation.

\section{Numerical implementation}
First, we write the time derivative explicitly as
\begin{align}
\pd{c}{t}=\eta \nabla^2 c - \bm v\cdot\nabla c=\eta \nabla^2 c - \nabla \cdot (c \bm v)\ .
\label{eq:3}
\end{align}
The last transition is valid because $\nabla\cdot \bm v=0$.

The equations are solved on a square grid, using a staggered grid for $v$. That is, $c$ is calculated on the points $ \left(2\pi \frac{i}{N},2\pi \frac{j}{N}\right)$ where $N$ is the number of grid points in each dimension (currently 200) and $i,j$ are integers between 0 and $N-1$. $v$ is (pre-)computed on the points $ \left(2\pi \frac{i-\frac{1}{2}}{N},2\pi \frac{j-\frac{1}{2}}{N}\right)$. This allows implementing the right-hand-side of Eq.~\eqref{eq:3} in a conservative way, i.e.~the spatial integral the right-hand-side vanishes (or alternatively, the spatial integral of $c$ remains constant in time, as it should).

The generation of the velocity field (and the shifted spatial mesh) is done by \verb|generate_v_field|. The script \verb|run_collect_save| runs many simulations and collects them in a \verb|hdf5| file.
The file produced by \texttt{run\_collect\_save} have this format:

\begin{itemize}
	\item The name of the file is the value of $\eta$.
	\item \verb|t| is the list of times for which the solutions are calculated	(uniformly spaced).
	\item \verb|x| and \verb|y| are matrices of shape $N\times N$ with the \texttt{x} and \texttt{y} coordinates of the	finite-differences grid for \verb|c|.
	\item Each file contains 50 realizations, which are at groups \texttt{/001},
	\texttt{/002}, \ldots{}, \texttt{/050}:
	\item \texttt{/XXX/c} is an
	\texttt{ndarray} of shape \texttt{[n,n,len(t)]} that contains the
	concentration field. \texttt{c[i,j,k]} is the value of the
	concentration field at position \texttt{x[i,j]} and
	\texttt{y[i,j]} at time \texttt{t[k]}. In other words,
	\texttt{c[...,i]} is the snapshot of the concentration field at time
	\texttt{t[i]}.
	\item The group \texttt{/XXX} also contains
	\texttt{/XXX/u},\texttt{/XXX/v}, which are the \texttt{x} and \texttt{y}
	components of the velocity field. Note that \texttt{u} and \texttt{v}
	are not evaluated at the same grid points as c since we use a staggered
	scheme to ensure conservation. The functional form of \texttt{u} and
	\texttt{v} is given in both MATLAB and Mathematica syntax in the
	attributes of \texttt{/XXX}.
\end{itemize}

\end{document}


\subsection{Extreme learning machines}

This is an alternative to backprobagation for training a feedforward neural network.

We start with random parameters for each layer \(W_i\).

We have:

\(\hat y=W_2\sigma (W_1 x)\)

Etc.

We calculate:

\(W_2=\sigma(W_1x)^+Y\)

So \(W_1\) is random and not updated.

\(W_2\) is assigned to minimise loss, where \(W_2\) has no activation function.


\documentclass[12pt]{cdblatex}
\usepackage{examples}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% ============================================================================================
\bgroup
\CdbSetup{action=hide}
\begin{cadabra}
   import cdblib
   checkpoint_file = 'tests/semantic/output/example-05.json'
   cdblib.create (checkpoint_file)
   checkpoint = []
\end{cadabra}
\egroup

\clearpage

% ============================================================================================
\section*{Example 5a Keeping focused}

\begin{cadabra}
   {a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices.

   expr := A_{a} v^{a} + B_{a} v^{a} + C_{a} v^{a}.  # cdb (ex-05.100,expr)

   zoom (expr,$B_{a} Q??$)                           # cdb (ex-05.101,expr)
   substitute (expr, $v^{a} -> w^{a}$)               # cdb (ex-05.102,expr)
   unzoom (expr)                                     # cdb (ex-05.103,expr)

   checkpoint.append (expr)
\end{cadabra}

\begin{align*}
   \cdb{ex-05.100} &= \Cdb{ex-05.101}\\
                   &= \Cdb{ex-05.102}\\
                   &= \Cdb{ex-05.103}
\end{align*}

\clearpage

% ============================================================================================
\section*{Example 5b Tags}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices(position=independent).

   def add_tags (obj,tag):
      n = 0
      ans = Ex('0')
      for i in obj.top().terms():
         foo = obj[i]
         bah = Ex(tag+'_{'+str(n)+'}')
         ans := @(ans) + @(bah) @(foo).
         n = n + 1
      return ans

   def clear_tags (obj,tag):
      ans := @(obj).
      foo  = Ex(tag+'_{a?} -> 1')
      substitute (ans,foo)
      return ans

   expr := 2 V_{p q} - 3 V_{q p}.                    # cdb (ex-05.200,expr)

   expr = add_tags (expr,'\\mu')                     # cdb (ex-05.201,expr)

   zoom       (expr, $\mu_{1} Q??$)                  # cdb (ex-05.202,expr)
   substitute (expr, $V_{a b} -> - V_{b a}$)         # cdb (ex-05.203,expr)
   unzoom     (expr)                                 # cdb (ex-05.204,expr)

   expr = clear_tags (expr,'\\mu')                   # cdb (ex-05.205,expr)

   checkpoint.append (expr)
\end{cadabra}

\begin{align*}
   \cdb{ex-05.200} &= \Cdb{ex-05.201}\\
                   &= \Cdb{ex-05.202}\\
                   &= \Cdb{ex-05.203}\\
                   &= \Cdb{ex-05.204}\\
                   &= \Cdb{ex-05.205}
\end{align*}

\clearpage

% ============================================================================================
% export to json format

\bgroup
\CdbSetup{action=hide}
\begin{cadabra}
   for i in range( len(checkpoint) ):
      cdblib.put ('check{:03d}'.format(i),checkpoint[i],checkpoint_file)
\end{cadabra}
\egroup

\end{document}


\input{../../UCLHeader.tex}
\input{../../UCLCommands.tex}
\begin{document}
\title{Error Correction - Lecture 1}
\author{with Dan Browne}
\maketitle
\tableofcontents

\section{Introduction}
Error correction is at the core of realistic quantum computing. If you think of quantum computation, you should also think of error correction. Any vision of quantum computing without error correction is fundamentally flawed. This course will introduce all the various notions of quantum error correction that are common in the field.

\section{Classical Repetition Code}
In this section, we will first have a look at classical repetition code in order to understand how classical error correction is done.

For the classical bit $x$, which can take on values $ x \in [0,1]$, there are two possible errors. Either the bit gets flipped, such that $0 \rightarrow 1 $ or $1 \rightarrow 0$, or the bit is lost.

We can decompose most codes in terms of these errors. To protect from these errors, we \textbf{encode} our bits into several bits, such that
\beq
0 \rightarrow 000
\eeq
\beq
1 \rightarrow 111
\eeq
Then, an error on the 2nd bit would cause
\beq
000 \rightarrow 010
\eeq
\beq
111 \rightarrow 101
\eeq
If we query the values of the bits, we can take a majority vote and then correct the bit accordingly. This would work for the error described above. However, for two errors on two of the qubits, we find
\beq
000 \xrightarrow{error} 110 \xrightarrow{correction} 111 \xrightarrow{decoding} 1
\eeq
\beq
111 \xrightarrow{error} 001 \xrightarrow{correction} 000 \xrightarrow{decoding} 0
\eeq
As we can see, the correction and decoding process are unable to correctly negate the error.

We call the expression for the encoded bit a \textbf{codeword}. We also make a distinction between detection and correction of an error. It is always true that correction is easier than correction. Finally, consider
\beq
000 \xrightarrow{error} 111
\eeq
\beq
111 \xrightarrow{error} 000
\eeq
This error cannot be corrected because we cannot detect it. Whenever an error maps a codeword into another codeword, we become unable to correct it. It is a very general concept.

\section{Code distance}
We can define the \textbf{Hamming distance}. Given two $n$ bit strings, $A$ and $B$, the Hamming distance is the number of bits that you need to flip in order to go from $A$ to $B$. As an example, let $A = 010$ and $B = 001$. We require two flips to go from $A$ to $B$. Thus, $D_H = 2$.

It also follows that the Hamming distance is the number of errors that we cannot correct for.

Let us define another important concept, the \textbf{Hamming weight}. The Hamming weight is the number of nonzero bits in our codeword.

Finally, the \textbf{code distance} is the maximum distance of the code, which in turn is the smallest Hamming distance between codewords.

\emph{Example}: For an $n$ bit repetition code, the distance of the code is $n$. A number of $n-1$ bitflips are detectable.

Ultimately, the error correction that we perform is limited by our choice of correction method. Consider the following table of errors on the $000$ codeword:

\begin{tabular}{c| c}
\hline
No. of errors &Codeword\\
0 & 000 \\
1 & 001 \\ \hline
2 & 011 \\
3 &111
\end{tabular}
We have drawn the line at the point where we can no longer correct for errors. We can draw the Hamming distance around a codeword as a sphere. Every error inside the sphere will be mapped onto the codeword at its centre, but once an error takes us out of the sphere, it will be corrected into a codeword different from its original one.

In other words, we don't want the spheres to overlap. This leaves us with a number of $\frac{n-1}{2}$ correctable errors for an $n$ bit repetition code. Note that when $n-1$ is odd, we must always round down to the nearest integer.

\section{Computations}
Consider the encoded NOT gate. It has the following function on the encoded bits:
\beq
0 \xrightarrow{NOT} 1
\eeq
\beq
1 \xrightarrow{NOT} 0
\eeq
In the repetition code, flipping all $n$ bits implements a \textbf{logical NOT gate}. By logical, we mean that the gate affects the entire codeword that we have stored to mimic the effect of a single bit.

\section{Going Quantum}
Would the same concepts carry over without any problem into the quantum regime? Unfortunately not. The repetition code is a prime example where the \textbf{no-cloning theorem} prevents us from copying arbitrary quantum states into multiples of themselves.

The following aspects significantly complicate the transition to quantum error correction:
\begin{itemize}
\item[1] The no-cloning theorem forbids arbitrary qubit states from being copied.
\item[2] Measurements change the state, which complicates detection.
\item[3] Quantum errors are much more complicated than classical errors - there are more ways in which they can occur.
\end{itemize}

The last point might require some clarification. Any unitary transformation can become an error. In addition, we have the various ways in which a quantum state can decohere. Together, they add up to an infinite amount of errors, compared to just the single classical error!

\section{The Quantum Repetition Code}
This is an example of the most naive way in which we can start considering the quantum correction of errors. However, as we shall see later, even the quantum repetition code is an example of a more powerful formalism.

We take the basis states, and we clone the computational basis states, such that
\beq
\ket{0} \rightarrow \ket{000} = \ket{0}_L
\eeq
\beq
\ket{1} \rightarrow \ket{111} = \ket{1}_L
\eeq
Here, $\ket{0}_L$ and $\ket{1}_L$ are the logical qubits. We also say that the codewords, $\ket{000}, \ket{111}$ live in a \textbf{codespace}. We say that the codespace is spanned by the codewords.

For an arbitrary superposition, we obtain
\beq
\alpha \ket{0} + \beta \ket{1} \rightarrow \alpha \ket{000} + \beta \ket{111}
\eeq
Note that since we are only copying the basis states, it is not cloning and therefore perfectly allowed.

\subsection{The bit-flip error}
The bit-flip error takes us
\beq
\ket{0} \rightarrow \ket{1}
\eeq
and vice versa. It is equivalent to the Pauli $X$ matrix
\beq
X = \bpmat 0 & 1 \\ 1 & 0\epmat
\eeq
So an error on the 2nd qubit of our three-qubit example would look like
\beq
I \otimes X \otimes I = \alpha \ket{010} + \beta \ket{101}
\eeq
How can we correct for this error? We are not allowed to measure the qubits individually, since this measurement would tell us about the state and thus collapse the superposition. Instead, we introduce the concept of \textbf{parity}. The state $\ket{00}$ has even parity, and $\ket{01}$ has odd parity. We can then measure without collapsing the superposition, because the states in the above superposition, for example, have the same parity. We can measure a property as long as it belongs to every state in the superposition.

For the three-qubit code example, we have that $\ket{000}$, and $\ket{111}$ are examples of even parity states, and $\ket{010}, \ket{110}$ are examples of odd parity states.

So, we need a measurement that tells us about the parity without distinguishing the states. In order to perform this measurement, we require a CNOT gate and an ancilla qubit. Then, we apply the CNOT gate to each of our two (or three) qubits and the ancilla, and finally we read off the ancilla. Thus,
\beq
\ket{00} \rightarrow \ket{0}_A
\eeq
\beq
\ket{11} \rightarrow \ket{0}_A
\eeq
\beq
\ket{01} \rightarrow \ket{1}_A
\eeq
\beq
\ket{10} \rightarrow \ket{1}_A
\eeq
where $\ket{0}_A$ is the ancilla. However, we can also perform this measurement in a simpler way, that uses fewer gates. For example, the $Z$ gate will measure Pauli $Z$ in the computational basis. This will tell us about the parity of the qubits.

We must consider the parity of all the pair of the code. For the three-qubit code, the $Z\otimes Z$ measurement will have outcome $+1$ for even parity, and $-1$ for odd parity when applied to two of the three qubits.

So, for the three-qubit repetition code, we can think of three measurements that allows us to check the parity.
\beq
Z \otimes Z \otimes I
\eeq
\beq
Z \otimes I \otimes Z
\eeq
\beq
I \otimes Z \otimes Z
\eeq
But note that since $ZZ = I$, the last measurement can actually be formed as a product of the other two. This is a sign of an underlying group-theoretical structure which we will explore more thoroughly in upcoming lectures.

\section{Correcting quantum errors}
Assume that there is only one error on our arbitrary superposition,
\beq
Z \otimes I \otimes I \left( \alpha \ket{000} + \beta \ket{111} \right) = \alpha \ket{100} + \beta \ket{011}
\eeq
Then, if we apply the parity measurements defined above, we find
\beq
Z \otimes Z \otimes I \rightarrow - 1
\eeq
\beq
Z \otimes I \otimes Z \rightarrow - 1
\eeq
\beq
I \otimes Z \otimes Z \rightarrow +1
\eeq
and similarly for every other error.

We can write down a so-called \textbf{syndrome table} for all possible one-qubit $X$ errors.

\begin{tabular}{|c|c|c|}
$X\otimes I \otimes I $& $I \otimes X \otimes I$ & $I \otimes I \otimes X$ \\ \hline
--  &-- & + \\ \hline
-- & + & -- \\ \hline
+ & -- & --  \\ \hline
\end{tabular}

So, our correction strategy should be:
\begin{itemize}
\item Identify where the error occurred
\item Apply a bit-flip operation where the error occurs
\end{itemize}

\section{More general errors}
Let us consider a general error
\beq
U = e^{- i \theta X} = \cos{\theta} I - i \sin{\theta} X
\eeq
So that for our general superposition, we have
\beq
\alpha \ket{000} + \beta \ket{111} = \cos{\theta} \left( \alpha \ket{000} + \beta \ket{111} \right) - i \sin{\theta} \left( \alpha \ket{100} + \beta \ket{011} \right)
\eeq
But now, measuring with $Z\otimes Z \otimes I$ collapses the superposition to either of the terms. But, if $\theta \ll 1$, then detecting the error will correct it!

This simple example is very powerful. It tells us that our error correction strategy will work in general.

\section{The encoding circuit}
In order to encode our qubits into logical qubits, for the case of the repetition code we want a circuit that gives us
\beq
\alpha \ket{0} \rightarrow \alpha \ket{000}
\eeq
This cannot be just a unitary. Instead, we need an \textbf{isometry}, which is a unitary plus a Hilbert space expansion. The following circuit encodes the qubit:

stuff

All encoding is based on CNOT gates. In summary, we have that
\begin{itemize}
\item The encoding circuit encodes the state
\item Two measurements detect the errors
\item $X$ gates corrects the errors
\end{itemize}

\section{Logical operators}
Consider the logical $X$ operator. It flips the computational basis state. How can we achieve this on our encoded qubit? One stupid way to do this would be to decode our codewords, such that
\beq
\alpha \ket{000} + \beta \ket{111} \rightarrow \alpha \ket{0} + \beta \ket{1}
\eeq
apply a single gate and then re-encode them. This is not a good way, since it requires a lot of gates.

The good way would be to apply the operator
\beq
X\otimes X \otimes X = \bar{X}
\eeq
which we call the logical $X$ operator.  Clearly
\beq
\bar{X} \ket{0}_L = \bar{X} \ket{000} = \ket{111} = \ket{1}_L
\eeq
which is what we want.

Similarly for the logical $Z$ operator, we want
\beq
\alpha \ket{000} + \beta \ket{111} \rightarrow \alpha \ket{000} - \beta \ket{111}
\eeq
But now, there are many different ways in which we can do this. We have $ZII, IZI, IIZ, $ and $ZZZ$ that all achieve the right thing (note that we have dropped the tensor product notation). Each of the first three operators has weight 1. This means that they are indistinguishable from a single $Z$ error.

Recalling what we said before about code distance and the Hamming distance, it means that the code cannot protect against a $Z$ error, also called a phase error.

\section{Distance of a Quantum Code}
The logical operators are equal to the smallest undetectable error. We can define the minimum distance $d$ in a quantum code as the smallest weight of a non-identity logical operator. That is, the smallest weight is the undetectable error.

So, given what we know about the repetition code, we find that it has distance $d = 1$, which is very bad.

\emph{Note on notation}: we will use so called ($n,k,d$) notation,  where \\
$n$ is the number of physical qubits used to write one logical qubit, \\$k$ is the number of encoded qubits \\
$d$ is the quantum distance of the code

It follows that $k < n$ always.

\section{Correcting phase errors}
Can we think of a way to correct a single $Z$ error? We first note that
\beq
Z = HXH
\eeq
and we know that the repetition code can correct for $X$ error. Thus, we try applying $H\otimes H\otimes H $ on the repetition code. We find
\beq
\alpha \ket{000} + \beta \ket{111} \rightarrow \alpha \ket{+++} + \beta \ket{---}
\eeq
Then, we measure with the operators $XXI, XIX$ and $IXX$. Again note that the last measurement can be made up of the previous two. We then measure the parity in the $\{\ket{+}, \ket{-}\}$ basis. We again make use of   CNOT and an ancilla to record the measurement.

We get positive outcomes for even parity, and negative outcomes for odd parity. This works exactly the same as in the $\{\ket{0}, \ket{1}\}$ basis.

But just like the previous code failed for phase errors, this code fails for bit-flip errors. So is there a way to combine both approaches?

\section{The Shor code}
The code idea is: encode a bit-flip code in a phase flip code. That is, take
\beq
\ket{+} \rightarrow \ket{+++}
\eeq
\beq
\ket{-} \rightarrow \ket{---}
\eeq
Take each qubit and encode them in the bit-flip code. This is called \textbf{code concatenation}. We encode each codeword into more codewords.

So we get the following code
\beq
\ket{0}_L \rightarrow \ket{+}_{bitflip} \ket{+}_{bitflip} \ket{+}_{bitflip} = \left( \ket{000} + \ket{111} \right)^{\otimes 3}
\eeq
\beq
\ket{1}_L \rightarrow \ket{-}_{bitflip} \ket{-}_{bitflip}\ket{-}_{bitflip} = \left( \ket{000}- \ket{111} \right)^{\otimes 3}
\eeq
Note here that we have neglected to write out the normalisation. This is intentional, as it would quickly get very messy.

The logical operators are then for this code
\beq
\bar{X} = ZII \otimes ZII \otimes ZII = ZIIZIIZII
\eeq
\beq
\bar{Z} = XXXIIIIII
\eeq
The distance of the Shor code is 3, and the error that we can correct for is
\beq
\frac{3-1}{2} \sim 1
\eeq
\end{document}

Error Correction Lecture 22 Feb 2016.tex


\documentclass{article}

\usepackage[letterpaper, margin=1.3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{mathtools}
\usepackage{multicol}

\title{ECE 203 Problem Set 6}
\author{Michael Kwok}
\begin{document}

\maketitle
\begin{multicols}{2}
\section*{1}
\subsection*{a}
\begin{align}
    \left(I_1 + 10^{-5} V_2\right) 1000 &= V_1\\
    10000 I_2 - 100 V_1 &= V_2
\end{align}

Expanding equation (1) then substituting in equation (2):

\begin{align*}
    &1000 I_1 + 0.01 V_2 = V_1\\
    &1000 I_1 + 0.01 \left(10000 I_2 - 100 V_1\right) = V_1\\
    &1000 I_1 + 100 I_2 = 2 V_1
\end{align*}

Forming the following equations:

\begin{align}
    V_1 &= 500 I_1 + 50 I_2\\
    V_2 &= -50000 I_1 + 5000 I_2
\end{align}

$$
  [Z] =
  \begin{bmatrix}
  500 & 50\\
  -50000 & 5000
  \end{bmatrix}
  \si{\ohm}
$$
\subsection*{b}
The network is not reciprocal. $Z_{12} \neq Z_{21}$
\subsection*{c}
$$
\frac{V_1}{I_1} = R_{in}
$$
\begin{align*}
    V_2 &= -I_2 R_L\\
    &= -4000 I_2
\end{align*}
\begin{align*}
    -4000 I_2 &= -50000 I_1 + 5000 I_2\\
    -9000 I_2 &= -50000 I_1\\
    I_2 &= \frac{50}{9}I_1\\
    V_1 &= 500 I_1 + \frac{2500}{9} I_1\\
    \frac{V_1}{I_1} &= \SI{778}{\ohm}\\
    R_in &= \SI{778}{\ohm}
\end{align*}
\section*{2}
\begin{align}
    I_1 &= \frac{V_1}{100} + \frac{V_a}{500} + \frac{V_1}{250}\\
    I_2 &= \frac{V_2}{200} - \frac{V_1}{250}\\
    V_a &= 250 I_2 + V_1
\end{align}

Equation (7) into (5)

\begin{equation}
    I_1 = \frac{V_1}{100} + \frac{250 I_2 + V_1}{500} + \frac{V_1}{250}
\end{equation}
\begin{align*}
    500 I_1 &- 250 I_2 = 5 V_1 + V_1 + 2 V_1\\
    500 I_1 &- 250 I_2 = 8 V_1 \\
    500 I_1 &- 250 \left( \frac{V_2}{200} - \frac{V_1}{250} \right) = 8 V_1\\
    500 I_1 &- \frac{250}{200} V_2 + V_1 = 8 V_1\\
    7V_1 &= 500 I_1 - \frac{5}{4}V_2\\
    V_1 &= \frac{500}{7} I_1 - \frac{5}{28} V_2
\end{align*}

\begin{align*}
    I_2 &= \frac{V_2}{200} - \frac{1}{250} \frac{500}{7} I_1 + \frac{5}{28}\frac{1}{250} V_2\\
    &= -\frac{2}{7} I_1 + \frac{1}{175} V_2
\end{align*}

$$
  [h] =
  \begin{bmatrix}
  \frac{500}{7} & -\frac{5}{28}\\
  -\frac{2}{7} & \frac{1}{175}
  \end{bmatrix}
$$

$h_{11}$ has unit of $\si{\ohm}$, $h_{22}$ has unit of $\si{\per\ohm}$

\section*{3}
$R_{eq}$ can be calculated with $V_s = 0$

$$
    V_1 = -4 I_1
$$

\begin{align}
    -4 I_1 &= 2 I_1 + V_2\\
    I_2 &= 5 I_1 + 2 V_2
\end{align}
\begin{align*}
    -6 I_1 &= V_2\\
    I_1 &= -\frac{1}{6} V_2
\end{align*}
\begin{align*}
    I_2 &= -\frac{5}{6} V_2 + 2 V_2\\
    \frac{I_2}{V_2} &= \frac{7}{6}\\
    R_{eq} &= \frac{6}{7}\si{\ohm}
\end{align*}

\section*{4}
For $y_1$, the CL circuit.
\begin{align}
I_1 = \frac{V_1}{\frac{1}{sC}} + \frac{V_1 - V_2}{sL}\\
I_2 = \frac{V_2 - V_1}{sL} + \frac{V_2}{\frac{1}{sC}}
\end{align}
\begin{align*}
    I_1 = sV_1 + \frac{1}{s} V_1 - \frac{1}{s}V_2\\
    I_2 = sV_2 + \frac{1}{s} V_2 - \frac{1}{s}V_1
\end{align*}
$$
  [y_1] =
  \begin{bmatrix}
  \frac{s^2 +1}{s} & -\frac{1}{s}\\
  -\frac{1}{s} & \frac{s^2 +1}{s}
  \end{bmatrix}
  \si{\per\ohm}
$$
For $y_2$, the RC circuit.
\begin{align}
I_1 = \frac{V_1-V_2}{\frac{1}{sC}} + \frac{V_1}{1}\\
I_2 = \frac{V_2-V_1}{\frac{1}{sC}} + \frac{V_2}{1}
\end{align}
\begin{align*}
    I_1 = (s+1)V_1 - s V_2\\
    I_2 = -sV_1 + (s+1)V_2
\end{align*}
$$
  [y_2] =
  \begin{bmatrix}
  s+1 & -s\\
  -s & s+1
  \end{bmatrix}
  \si{\per\ohm}
$$
$$
[y] = [y_1] + [y_2] =
  \begin{bmatrix}
  \frac{2s^2 + s + 1}{s} & -\frac{s^2+1}{s}\\
  -\frac{s^2+1}{s} & \frac{2s^2 + s + 1}{s}
  \end{bmatrix}
  \si{\per\ohm}
$$
\section*{5}
\subsection*{a}
\begin{align}
    I_1 &= \frac{V_1}{4} + \frac{V_1 - V_2}{2}\\
    I_2 &= \frac{V_2}{3} + \frac{V_2 - V_1}{2}
\end{align}
\begin{align}
    4 I_1 &= V_1 + 2 V_1 - 2 V_2\\
    6 I_2 &= 2 V_2 + 3 V_2 - 3 V_1
\end{align}
Using Equation (18):
\begin{align*}
    6 I_2 - 5 V_2 &= - 3 V_1\\
    V_1 &= \frac{5}{3} V_2 - 2 I_2
\end{align*}

Using Equation (17):
\begin{align*}
    4 I_1 &= 5 V_2 - 6 I_2 -2 V_2\\
    4 I_1 &= 3 V_2 - 6 I_2\\
    I_1 &= \frac{3}{4} V_2 - \frac{3}{2} I_2
\end{align*}

\begin{align*}
3 V_1 &= 4 I_1 + 2 V_2\\
 V_1 &= \frac{4}{3} \left( \frac{3}{4} V_2 - \frac{3}{2} I_2\right) +\frac{2}{3} V_2\\
 &= V_2 - 2 I_2 + \frac{2}{3} V_2\\
 &= \frac{5}{3} V_2 - 2I_2
\end{align*}
$$
[t] =
  \begin{bmatrix}
  \frac{5}{3} & 2\\
  \frac{3}{4} & \frac{3}{2}
  \end{bmatrix}
$$
$t_{12}$ has unit of $\si{\ohm}$, $t_{21}$ has unit of $\si{\per\ohm}$
\subsection*{b}
$$
[t] = [t_1][t_2] =
  \begin{bmatrix}
  \frac{5}{3} & 2\\
  \frac{3}{4} & \frac{3}{2}
  \end{bmatrix}
  \begin{bmatrix}
  1 & 0\\
  \frac{1}{6} & 1
  \end{bmatrix}
$$
$$
=
  \begin{bmatrix}
  2 & 2\\
  1 & \frac{3}{2}
  \end{bmatrix}
$$

\end{multicols}
\end{document}


\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% Main maths packages
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}

\usepackage{tabularx}

% First and foremost, never use the environment eqnarray. It is not recommended because spacing is inconsistent.

\begin{document}

\section*{System of equations}

\subsection*{Summary of the environments}

\begin{table}[h]
	\begin{tabularx}{\textwidth}{| X | X | X |}
	\hline
	\textbf{Environment names} & \textbf{Description} & \textbf{Notes} \\
	\hline
	\emph{gather} and \emph{gather*} & Consecutive equations with an alignment to the center. & \\
	\hline
	\emph{align}, \emph{align*}, \emph{aligned} and \emph{split} & Consecutive equations with user-defined alignment. & \\
	\hline
	\emph{flalign} and \emph{flalign*} & Similar to \emph{align}, but left aligns first equation column, and right aligns last column. & \\
	\hline
	\emph{alignat} and \emph{alignat*} & Takes an argument specifying number of columns. Allows control of the horizontal space between equations. & This environment takes one argument, the number of “equation columns”: count the maximum number of \&s in any row, add 1 and divide by 2. \\
	\hline
	\emph{array} & Advanced alignment scenario. Enables to control how to columns are aligned. & \\
	\hline
	\emph{multline} and \emph{multline*} & First line left aligned, last line right aligned. & Equation number aligned vertically with first line and not centered as with other environments. \\
	\hline
	\emph{eqnarray} and \emph{eqnarray*} & Similar to \emph{align} and \emph{align*}. & Not recommended because spacing is inconsistent. \\
	\hline
	\end{tabularx}
\end{table}

This table is based on the one available on Wikibooks, \LaTeX Advanced Mathematics.

\newpage

\subsection*{Grouping and centering equations with \emph{gather}}

\begin{gather}
	x + 2y - z = 4 \\
	x + y - 5z = -1 \\
	2x - z = 10
\end{gather}

In addition, the environment \emph{gather*} removes the equation numbering. The environment \emph{gathered} and can be used in another mathematical environment.

\subsection*{Align equations with \emph{align}}

\begin{align}
	x + 2y - z &= 4 \\
	x + y - 5z &= -1 \\
	2x - z &= 10
\end{align}

This environment can also be used to align equations on the same line:

\begin{align*}
	f(x)  &= a x^2+b x +c   &   g(x)  &= d x^3 \\
	f'(x) &= 2 a x +b       &   g'(x) &= 3 d x^2
\end{align*}

In addition, the environment \emph{align*} removes the equation numbering. The environment \emph{aligned} and \emph{split} are the similar to \emph{align} and \emph{align*} but can be used in another mathematical environment.

\subsubsection*{Align equations with \emph{align} and \emph{subequations}}

The environment \emph{subequations} changes the way how \LaTeX counts the equations.

\begin{subequations}
	\begin{align}
		x + 2y - z &= 4 \\
		x + y - 5z &= -1 \\
		2x - z &= 10
	\end{align}
\end{subequations}

\subsubsection*{Braces a system of equations}

The environment \emph{aligned} is similar to align, to be used inside another mathematics environment.

% The commands \left and \right insert a brace. The type of the brace is written just after the command.
% When \left is called, \right is mandatory.
\[
\left(
\begin{aligned}
	x + 2y - z &= 4 \\
	x + y - 5z &= -1 \\
	2x - z &= 10
\end{aligned}
\right)
\]

% In the case where only one brace is needed, the other brace must be marked with a point (.) to hide it.
\[
\left\{
\begin{aligned}
x + 2y - z &= 4 \\
x + y - 5z &= -1 \\
2x - z &= 10
\end{aligned}
\right.
\]

\subsection*{Align equations to the left with \emph{flalign}}

\begin{flalign}
a &= b+c &\\
&= 1+1 &\\
&= 2  &
\end{flalign}

In addition, the environment \emph{flalign*} removes the equation numbering.

\subsection*{Align equations with \emph{alignat}}

The environment \emph{alignat} enables to control of the horizontal space between equations. Indeed, no addition space is added between equation, at the opposite of the environment \emph{align}.

The mathematical development below is aligned according the arrow and the equal signs.

\begin{alignat}{2}
	&& \sqrt{4 x^2} - 1 &= 0 \\
	&\Rightarrow & \sqrt{4} \sqrt{x^2} &= 1 \\
	&\Rightarrow & 2 \left|x\right| &= 1 \\
	&\Rightarrow & x &= \pm \frac{1}{2}
\end{alignat}

This environment takes an argument specifying number of columns. The rule of thumb to determine the argument is to count the maximum number of \& symbols on one row, add 1 and divide by 2.

In addition, the environment \emph{alignat*} removes the equation numbering. The environment \emph{alignedat} and \emph{alignedat*} and can be used in another mathematical environment.

\subsection*{Align equations with \emph{array}}

The environment \emph{array} is for more advanced scenario. It is basically the same as \emph{align}, but the columns and their alignment are explicitly indicated. It must be used in the math mode.

\[
\left\{
\begin{array}{ r c l}
		x + z &=& y - 4 \\
		5z &=& x + y -1 \\
		2x - y &=& 10 - y
\end{array}
\right.
\]

\subsection*{Displaying long equations}

The environment \emph{multline} can be used to display formula on multiple lines.

\begin{multline*}
	f(x) = 60x^{15} + 56x^{14} + 52x^{13} + 48x^{12} + 44x^{11} + 40x^{10} + 36x^{9} + 32x^{8}\\
	+ 28x^{7} + 24x^{6} + 20x^{5} + 16x^{4} + 12x^{3} + 8x^{2} + 4
\end{multline*}

\end{document}


\subsection{The Euler equation with liquidity constraints}

\(u'(x_t)=(1+\delta)(1+r_t)u'(x_{t+1})+\lambda_{t+1}\)