Commit ffe0be06 by Michael Kohlhase

### more

parent 4072c924
 \begin{omgroup}{Representing and Manipulating Numbers} \begin{note} \begin{omtext} \begin{nomtext} We start with the representation of numbers. There are multiple number systems, as we are interested in the principles only, we restrict ourselves to the natural numbers -- all other number systems can be built on top of these. But even there we have choices about representation, which influence the space we need and how we compute with natural numbers. \end{omtext} \end{note} \end{nomtext} \mhinputref{datastructures/en/natural-numbers} \begin{note} \begin{nomtext} \usemhmodule[path=datastructures/en/natural-numbers]{natural-numbers} \begin{omtext} The \trefiii[natural-numbers]{unary}{natural}{numbers} are very simple and direct, but they are neither space-efficient, nor easy to manipulate. Therefore we will use different ways of representing numbers in practice. \end{omtext} \end{note} \end{nomtext} \mhinputref{datastructures/en/pns} \mhinputref[MiKoMH/GenCS]{pns/en/PNS-common} ... ...
 ... ... @@ -8,7 +8,7 @@ \end{omtext} \end{note} \begin{frame}[fragile,allowframebreaks] \begin{frame}[fragile,allowframebreaks,label=slide.humanities-ex] \frametitle{Example: Correcting and Anonymizing Documents} \begin{itemize} \item ... ... @@ -23,7 +23,6 @@ \begin{itemize} \item we first initialize and load modules \begin{lstlisting} #!/usr/bin/env python3 import re import sys \end{lstlisting} ... ...
 ... ... @@ -25,12 +25,14 @@ \item \lstinline|re.sub($\pmetavar{pat}$,$\pmetavar{sub}$,$\pmetavar{str}$)|: Replace substrings that match $\pmetavar{pat}$ in $\pmetavar{str}$ by $\pmetavar{sub}$. \begin{lstlisting} >>> re.sub(r'\sAND\s', ' & ', 'Baked Beans and Spam') >>> re.sub(r'\sAND|and\s', ' & ', 'Baked Beans and Spam') 'Baked Beans & Spam' \end{lstlisting} \item \lstinline|re.split($\pmetavar{pat}$,$\pmetavar{str}$)|: Split $\pmetavar{str}$ into substrings that match $pmetavar{pat}$. \begin{lstlisting} >>> re.split(r'\W+','When shall we three meet again?')) >>> re.split(r'\s+','When shall we three meet again?')) ['When','shall','we','three','meet','again?'] >>> re.split(r'\s+|\?|\.|!|,|:|;|','When shall we three meet again?')) ['When','shall','we','three','meet','again'] \end{lstlisting} \end{itemize} ... ...
 \begin{module}[id=python-strings] \importmhmodule[path=python/en/datatypes]{python-datatypes} \importmhmodule[repos=MiKoMH/GenCS,path=codes/en/ASCII]{ASCII} \importmhmodule[path=pns/en/PNS-common]{PNS-common} \lstset{language=python} \begin{frame}[fragile] \frametitle{Playing with Strings and Characters in $\pythonLanguage$} ... ... @@ -29,11 +30,11 @@ def uc(c) : \item \begin{example}[id=cap.ex] taking strings apart and re-assembling them. \begin{lstlisting} \begin{lstlisting}[mathescape] def cap(s) : return uc(s[0]) + s[1:len(s)] >>> cap('genICT') 'GenICT' >>> cap('$\text{\useSGvar{courseacronym}}$') '$\text{\useSGvar{courseacronym}}$' \end{lstlisting} \end{example} \end{itemize} ... ... @@ -46,9 +47,9 @@ def cap(s) : objects we are presenting in $\pythonLanguage$. In parcticular, if we lowercase'' a character that is already lowercase -- e.g. by \lstinline|lc('c')|, then we get out of the range of the $\ASCIIcode$ code: the answer is \lstinline|\x83|, which is the character with the hexadecimal code \lstinline|83| (decimal \lstinline|130|). \lstinline|lc('c')|, then we get out of the range of the $\ASCIIcode$ code: the answer is \lstinline|\x83|, which is the character with the \trefi[PNS-common]{hexadecimal} code \lstinline|83| (\trefi[PNS-common]{decimal} \lstinline|130|). In production code (e.g. the $\pythonLanguage$ \lstinline|lower| method), we would have some range checks, etc. ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!