% This is the LaTeX template file for preparing lecture notes for 
% courses taught by Neil Calkin.  When preparing 
% LaTeX notes for this class, please use this template.
%
% The body contains examples: study them, run 
%
%	pdflatex <yourfilename.tex>
%
% and see how they work.   View the output file with acrobat,
% or print it out to compare input and result.
%
%
%
%
%


\documentclass{article}
\usepackage{epsfig,amsmath,amssymb}
\usepackage{graphicx}
\usepackage[myheadings]{fullpage}
%
% The following commands set up the lecnum (lecture number)
% counter and make various numbering schemes work relative
% to the lecture number.
%
\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\thefigure}{\thelecnum.\arabic{figure}}
\renewcommand{\thetable}{\thelecnum.\arabic{table}}

%
% The following macro is used to generate the header.
%
\newcommand{\lecture}[4]{
   \pagestyle{myheadings}
   \thispagestyle{plain}
   \newpage
   \setcounter{lecnum}{#1}
   \setcounter{page}{1}
   \noindent
   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 6.28in { {\bf Combinatorial Analyis
                        \hfill Fall 2010} }
       \vspace{4mm}
       \hbox to 6.28in { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 6.28in { {\it Lecturer: #3 \hfill Scribe: #4} }
      \vspace{2mm}}
   }
   \end{center}
   \markboth{Lecture #1: #2}{Lecture #1: #2}
   {\bf Disclaimer}: {\it These notes are intended for students in the class
listed above: they are not guaranteed to be complete or even necessarily
correct.  They may only be redistributed with permission, which you may
expect will be liberally granted.  Ask first, please.} \vspace*{4mm}
}

%
% Convention for citations is authors' initials followed by the year.
% For example, to cite a paper by Leighton and Maggs you would type
% \cite{LM89}, and to cite a paper by Strassen you would type \cite{S69}.
% (To avoid bibliography problems, for now we redefine the \cite command.)
% Also commands that create a suitable format for the reference list.
\renewcommand{\cite}[1]{[#1]}
\def\beginrefs{\begin{list}%
        {[\arabic{equation}]}{\usecounter{equation}
         \setlength{\leftmargin}{2.0truecm}\setlength{\labelsep}{0.4truecm}%
         \setlength{\labelwidth}{1.6truecm}}}
\def\endrefs{\end{list}}
\def\bibentry#1{\item[\hbox{[#1]}]}

%Use this command for a figure; it puts a figure in wherever you want it.
%usage: \fig{NUMBER}{SPACE-IN-INCHES}{CAPTION}
\newcommand{\fig}[3]{
			\vspace{#2}
			\begin{center}
			Figure \thelecnum.#1:~#3
			\end{center}
	}
% Use these for theorems, lemmas, proofs, etc.
\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}}


\def\Z{\hbox{$\mathbb Z$}}
\def\Q{\hbox{$\mathbb Q$}}
\def\R{\hbox{$\mathbb R$}}
\def\N{\hbox{$\mathbb N$}}
\def\C{\hbox{$\mathbb C$}}



% **** IF YOU WANT TO DEFINE ADDITIONAL MACROS FOR YOURSELF, PUT THEM HERE:

\begin{document}
%FILL IN THE RIGHT INFO.
%\lecture{**LECTURE-NUMBER**}{**DATE**}{**LECTURER**}{**SCRIBE**}
\lecture{10}{September 08}{Neil Calkin}{Reid Sanders and Grady Thomas}

\begin{flushleft}

\section{Computing values of functions efficiently}
\emph{Aside: Today we need to work over $\mathbb{Q}$, not over $\mathbb{R}$ - we need division.}

How to compute values of $f(x)^n$ assuming they exist? In fact for each of the following functions how do we compute them:

\begin{enumerate}
\item $f(x)^n:$ f arbitrary, $n \in \mathbb{N}$
\item $f(x)^a: f(0) = 1$
\item $e^{f(x)},f(0)=0$
\item $log(1+f(x)): f(0)=0$
\end{enumerate}
\section{Computing $g(x) = f(x)^n$}
Last time we saw that we can compute $f(x)^n$ via iterated squaring: 

\begin{indent}
Compute $f(x)^2, f(x)^{2^2}, f(x)^{2^3},\ldots$
and multiply appropriate ones to get $f(x)^n$.
\end{indent}
How long will this take to compute coefficients up to $x^N, N=2^k$ say?

%Assume $g(a)$ (i.e in a ring)  %%%wg
Assume g(a) is defined over a ring.
 Multiplication takes time m. Then computing $g(x)^2$ up to $x^N$ requires computing 
 \begin{align*}
 &\sum_{l=0}^j g_l g_{j-l}  &0 \leq j \leq N\\
 &n+1 \text{ multiplications}& 1+2+3+...+(N+1) = {N+2 \choose 2} \text{ total multiplications}\\
 &n \text{ additions}& 1+2+3+...+N = {N+1 \choose 2} \text{ total additions}
 \end{align*}
We need to compute $f(x)^{2^j}$ for all $j$ with $2^j \leq n$. 

So $j \leq log_2{n}$.

So we need to do $\lfloor{log_2{n}}\rfloor$ squarings. %Multiplying power series. 
So:
\begin{align*}
&2\lfloor{log_2{n}}\rfloor{N+2 \choose 2} \text{ multiplications in } \mathbb{R}\\
&2\lfloor{log_2{n}}\rfloor{N+1 \choose 2} \text{ additions in }\mathbb{R}
\end{align*}
For now we will skip the question of the possibility of doing these operations
\section{Computing $g(x) = e^{f(x)}$}
\emph{Aside: From here on we are assuming working in $\mathbb{Q}$.}
How to compute coefficient of $g(x) = e^{f(x)}, f(0) = 0$ for terms up to $x^N$?
Differentiate and multiply by x:
\begin{align*}
	&x \frac{d}{dx}g(x) = xg'(x) = \sum_{n \geq 0} nx^n g_n = \sum_{n \geq 1} n g_n x^n\\
	&x\frac{d}{dx}e^{f(x)} \\
	&= xf'(x)e^{f(x)} \\
	&= xf'(x)g(x)\\
	&= \left(\sum_{s \geq 0} s f_n x^n\right)\left(\sum_{r = 0} g_r x^r\right)
\end{align*}
So extracting the coefficient:
\begin{align*}
	&\left[x^n\right]g'(x) \\
	&= n g_n \\
	&= \sum_{s=0}sf_sg_{n-s}\\
	&= \sum_{s=1} s f_s g_{n-s} &g_0,g_1,\ldots,g_{n-1}
\end{align*}

%%%%%%% split %%%%%%%%%
Perhaps we can improve things a little: \\
Let $g(x)=\displaystyle\sum_{s=0}^\infty h_s\frac{x^s}{s!}$ instead. So, $g'(x)=\displaystyle\sum_{s=0}^\infty h_{s+1}\frac{x^s}{s!}$ \\
Then, $\frac{h_n}{(n-1)!}=\lbrack x^{n-1}\rbrack g'(x)$ and, as before, $g'(x)=f'(x)g(x)$. \\

\vspace{4mm}
\textbf{exercise NTBHI: } Find the recurrence for $h_n$ in terms of $h_0,h_1,\ldots,h_{n-1}$ that this gives.
\vspace{4mm}

Computing $g_n$ once $g_0,\ldots,g_{n-1}$ are computed takes $2n$ multiplications, $n-1$ additions, and $1$ division.  So computing $g_N$ takes $2$ $N+1\choose 2$ multiplications, $N\choose 2$ additions, and $N$ divisions.  So this is quadratic in $N$. \\

$g(x)=log(1+f(x)):$ \\
\begin{equation}
x \frac{d}{dx} log(1+f(x))=\frac{xf'(x)}{1+f(x)} \text{ so, } xg'(x)(1+f(x))=xf'(x)
\end{equation}

\vspace{4mm}
\textbf{exercise: } Determine the recurrence you get in the form $ng_n=\displaystyle\sum \cdots$. Using this find terms up to $x^{10}$ in $log(cos(x))$. (Use Sage/Maple to compare with Taylor series of $log(cos(x))$)
\vspace{4mm}

\section{Back to $g(x) = f(x)^a$}
Differentiating:

\begin{align*}
&xg'(x)=xaf(x)^{a-1}f'(x) \\
&\text{so } xg'(x)f(x)=xaf'(x)g(x) \\
&\text{so } \lbrack x^n\rbrack xg'(x)f(x)=\lbrack x^n\rbrack xaf'(x)g(x) \\
&\displaystyle\sum_{k=0}^nkg_kf_{n-k}=\displaystyle\sum_{k=0}^nag_k(n-k)f_{n-k} \\
&ng_n=-\displaystyle\sum_{k=0}^{n-1}kg_kf_{n-k} + \displaystyle\sum_{k=0}^{n-1}a(n-k)g_kf_{n-k} = \displaystyle\sum_{k=0}^{n-1}(a_n-(a+1)k)g_kf_{n-k} \\
\end{align*}

\vspace{4mm}
\textbf{exercise: } By hand, compute terms up to $x^8$ of $(1+2x+4x^2+7x^3)^8$ and $(1+2x+4x^2+7x^3)^7$ using 
\begin{enumerate}
\item Iterated squaring 
\item The method above.
\end{enumerate}


\end{flushleft}

\end{document}
