

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{A Glance at Numbers}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Numbers}

\begin{itemize}
\item SmallInteger, Integer,
\begin{itemize}
\item 4, 2r100 (4 in base 2), 3r11 (4 in base 3)
\end{itemize}

\item Automatic coercion
\begin{itemize}
\item \code{1 + 2.3} -\textgreater{} 3.3
\item \code{1 class} -\textgreater{} SmallInteger
\item \code{1 class maxVal class} -\textgreater{} SmallInteger
\item \code{(1 class maxVal + 1) class} -\textgreater{} LargePositiveInteger
\end{itemize}

\item Fraction, Float
\begin{itemize}
\item 3/4, 2.4e7 
\item \code{(1/3) + (2/3)} -\textgreater{} 1 
\item \code{1000 factorial / 999 factorial} -\textgreater{} 1000
\item \code{2/3 + 1} -\textgreater{} (5/3)
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\label{Outline}
\frametitle{Numbers}


\begin{center}
\includegraphics[width=0.8\textwidth]{figures/NumberHierarchy.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\label{funsmallint}
\frametitle{Small Integers are Real Objects}

\begin{itemize}
\item Small ints are real objects: instance of class \code{SmallInteger}
\item No need for boxing or unboxing
\end{itemize}

\begin{listing}{}
	1 class
	> SmallInteger
\end{listing}

\begin{itemize}
\item Operations on small integers are plain messages (no exception to the rule)
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Small integers are optimized}

But small integers are heavily optimized

\begin{itemize}
\item Small integers encoded on 30 bits
\item The pointer itself is the small integer
\end{itemize}

\begin{listing}{}
    2 raisedTo: 30  
    > 1073741823
\end{listing}

\begin{listing}{}
    SmallInteger maxVal
    > 1073741823
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Automatic Coercion}

What is the largest small integer?

\begin{listing}{}
	1 class maxVal
	> 1073741823
\end{listing}

What is the smallest large integer?

\begin{listing}{}
	1 class maxVal +1
	> 1073741824

	(1 class maxVal + 1) class
	> LargePositiveInteger
\end{listing}
\end{frame}



\begin{frame}[fragile]

\label{funsmallint}
\frametitle{Fun With Numbers}
\end{frame}



\begin{frame}[fragile]

\frametitle{Fun With Large Numbers}

\code{factorial} is not optimized

\begin{listing}{}
1000 factorial numberOfDigits
> 2568 
\end{listing}

\begin{listing}{}
100000 factorial numberOfDigits
> 456574 
\end{listing}

\begin{itemize}
\item Takes some seconds :)
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Fraction}

\code{Fraction}

\begin{itemize}
\item \code{denominator}, \code{numerator}, ....
\item Can handle large numbers
\end{itemize}

\begin{listing}{}
1000 factorial / 999 factorial
> 1000
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Messages Sent to Objects}

\begin{itemize}
\item Operations on numbers are plain messages 
\item No exceptions
\end{itemize}

\begin{listing}{}
	(1 / 3) + (2 / 3)
	>1
\end{listing}

\begin{listing}{}
	2 / 3 + 1
	> 5 / 3
\end{listing}

\begin{itemize}
\item Numbers are objects
\item Mathematical operations are messages sent to objects
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Message Limits}

\begin{itemize}
\item There is no notion of precedence
\end{itemize}

\begin{listing}{}
2 * 3 + 5
> 11
\end{listing}

\begin{listing}{}
2 + 3 * 5 
> 25 !!!
\end{listing}

\begin{itemize}
\item Use parenthesis to enforce precedence
\end{itemize}

\begin{listing}{}
2 + (3 * 5)
> 11
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Points}

\begin{itemize}
\item A point has an x and y
\item Points are created using the message \code{@} or \code{x:y:}
\end{itemize}

\begin{listing}{}
10 @ 100
(10 @ 100) x
> 10
(10 @ 100) y
>100
\end{listing}

Alternative

\begin{listing}{}
Point new x: 100 y: 100
\end{listing}

Class written in a functional way: Most \code{Point} methods are returning new points
\end{frame}



\begin{frame}[fragile]

\frametitle{Rectangles}

\begin{itemize}
\item Geometric and expected operations
\item \code{areasOutside:}, \code{expandBy:}, \code{insetBy:}, \code{intersect:}
\end{itemize}

\begin{listing}{}
Rectangle left: 10 right: 100 top: 20  bottom: 40
> (10@20) corner: (100@40)
\end{listing}

\begin{listing}{}
Rectangle origin: 20@20	corner: 100@200
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Margins}

\begin{columns}

\begin{column}{0.6\textwidth}

\begin{itemize}
\item Delta to apply to a rectangle
\item Useful for GUI
\item Encodes 4 numbers, expressed in 3 different ways
\begin{itemize}
\item a number (same space all around)
\item two numbers (same left/right and top/bottom)
\item four numbers
\end{itemize}

\item Used to compute the extended (or inner) rectangle
\end{itemize}
\end{column}


\begin{column}{0.4\textwidth}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/Margin.png}\end{center}

\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\label{points}
\frametitle{Summary}

\begin{itemize}
\item Numbers are real objects
\item Automatic coercion
\item Number can be infinitely large
\item Abstractions are built on top: \code{Point}, \code{Rectangle}, \code{Margin}
\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
