diff --git a/Labbfiler/OUTCAR b/Labfiles/OUTCAR similarity index 100% rename from Labbfiler/OUTCAR rename to Labfiles/OUTCAR diff --git a/Labbfiler/POSCAR b/Labfiles/POSCAR similarity index 100% rename from Labbfiler/POSCAR rename to Labfiles/POSCAR diff --git a/Labbfiler/matplotlib_example.ipynb b/Labfiles/matplotlib_example.ipynb similarity index 100% rename from Labbfiler/matplotlib_example.ipynb rename to Labfiles/matplotlib_example.ipynb diff --git a/Labbfiler/numpy_example.ipynb b/Labfiles/numpy_example.ipynb similarity index 100% rename from Labbfiler/numpy_example.ipynb rename to Labfiles/numpy_example.ipynb diff --git a/Labbfiler/scipy_example.ipynb b/Labfiles/scipy_example.ipynb similarity index 100% rename from Labbfiler/scipy_example.ipynb rename to Labfiles/scipy_example.ipynb diff --git a/Kompendium/Makefile b/Labnotes/Makefile similarity index 100% rename from Kompendium/Makefile rename to Labnotes/Makefile diff --git a/Kompendium/labbnotes.tex b/Labnotes/labbnotes.tex similarity index 100% rename from Kompendium/labbnotes.tex rename to Labnotes/labbnotes.tex diff --git a/Lecture/AnalyticalMachine_Babbage_London.jpg b/Lecture/AnalyticalMachine_Babbage_London.jpg new file mode 100644 index 0000000000000000000000000000000000000000..960fa9ac6da152ccd35a282944427319976bbc83 Binary files /dev/null and b/Lecture/AnalyticalMachine_Babbage_London.jpg differ diff --git a/Lecture/Apple_II_Monitor.png b/Lecture/Apple_II_Monitor.png new file mode 100644 index 0000000000000000000000000000000000000000..c04c8939c8b31c66449cf0fcecb5be49cca139b4 Binary files /dev/null and b/Lecture/Apple_II_Monitor.png differ diff --git a/Lecture/Half_Adder.pdf b/Lecture/Half_Adder.pdf new file mode 100644 index 0000000000000000000000000000000000000000..74b5b67d45b2099dee89e53907577d40375b9b76 Binary files /dev/null and b/Lecture/Half_Adder.pdf differ diff --git a/Lecture/LiU_primary_black.pdf b/Lecture/LiU_primary_black.pdf new file mode 100644 index 0000000000000000000000000000000000000000..5d630368582785aa3ac04ae672a11c90e9f26ccd Binary files /dev/null and b/Lecture/LiU_primary_black.pdf differ diff --git a/Lecture/LiU_primary_white.pdf b/Lecture/LiU_primary_white.pdf new file mode 100644 index 0000000000000000000000000000000000000000..6aa5479024fb1f681f9ccadc37247339e759aac3 Binary files /dev/null and b/Lecture/LiU_primary_white.pdf differ diff --git a/Lecture/Makefile b/Lecture/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8ec39e77498a5ea1683bdb46c0482c8344ad89c1 --- /dev/null +++ b/Lecture/Makefile @@ -0,0 +1,10 @@ +all: lecture_swe lecture_en + +lecture_swe: lecture_swe.tex + latexmk -xelatex lecture_swe.tex + +#lecture_en: lecture_en.tex +# latexmk -xelatex lecture_en.tex + +clean: + latexmk -c diff --git a/Lecture/Makefile~ b/Lecture/Makefile~ new file mode 100644 index 0000000000000000000000000000000000000000..a7d8c1261e3c5de2fddd28d304206d4fe2bc3d5d --- /dev/null +++ b/Lecture/Makefile~ @@ -0,0 +1,10 @@ +all: lecture_swe lecture_en + +lecture_swe: lecture_swe.tex + latexmk -xelatex lecture_swe.tex + +lecture_en: lecture_en.tex + latexmk -xelatex lecture_en.tex + +clean: + latexmk -c diff --git a/Lecture/Replica-of-first-transistor.jpg b/Lecture/Replica-of-first-transistor.jpg new file mode 100644 index 0000000000000000000000000000000000000000..14482f69fc7df08e44c63a442897ed4b8221e630 Binary files /dev/null and b/Lecture/Replica-of-first-transistor.jpg differ diff --git a/Lecture/Schickardmaschine.jpg b/Lecture/Schickardmaschine.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4316e5dddc4bb4acaec03c0747750befc33fa91f Binary files /dev/null and b/Lecture/Schickardmaschine.jpg differ diff --git a/Lecture/adder-truthtable.png b/Lecture/adder-truthtable.png new file mode 100644 index 0000000000000000000000000000000000000000..929ccce73da29918d8b1874e7c5edc6900042ba0 Binary files /dev/null and b/Lecture/adder-truthtable.png differ diff --git a/Lecture/andgate.png b/Lecture/andgate.png new file mode 100644 index 0000000000000000000000000000000000000000..5f4684416df88b296ec143b1d9a92989e2206a7e Binary files /dev/null and b/Lecture/andgate.png differ diff --git a/Lecture/antikythera.jpg b/Lecture/antikythera.jpg new file mode 100755 index 0000000000000000000000000000000000000000..2bdfe7efddbc28155459420464ca931c7f15b518 Binary files /dev/null and b/Lecture/antikythera.jpg differ diff --git a/Lecture/beamercolorthemeLiU.sty b/Lecture/beamercolorthemeLiU.sty new file mode 100644 index 0000000000000000000000000000000000000000..4f039cd4bfe673ad7c36ff7a6bb2a08603fe5b80 --- /dev/null +++ b/Lecture/beamercolorthemeLiU.sty @@ -0,0 +1,642 @@ +%% beamercolorthemeLiU.sty +%% Copyright 2015 Clas Veibäck +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Clas Veibäck. +% +% This work consists of the files beamer*themeLiU.sty +% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%% SOFTWARE. + +\mode<presentation> + +%% +%% Read Options +%% +\def\LiU@titlecolor{blue}%% Option for color on title page +\DeclareOptionBeamer{titlecolor}{\def\LiU@titlecolor{#1}} +\ProcessOptionsBeamer + +\def\LiU@outlinecolor{green}%% Option for color on outline page +\DeclareOptionBeamer{outlinecolor}{\def\LiU@outlinecolor{#1}} +\ProcessOptionsBeamer + +\def\LiU@endcolor{turquoise}%% Option for color on end page +\DeclareOptionBeamer{endcolor}{\def\LiU@endcolor{#1}} +\ProcessOptionsBeamer + +\def\LiU@blockcolor{blue}%% Option for color in block +\DeclareOptionBeamer{blockcolor}{\def\LiU@blockcolor{#1}} +\ProcessOptionsBeamer + +\def\LiU@complementarycolor{orange}%% Option for complementary color +\DeclareOptionBeamer{complementary}{\def\LiU@complementarycolor{#1}} +\ProcessOptionsBeamer + +\newif\ifLiU@highcontrast\LiU@highcontrastfalse%% Option for high contrast. +\DeclareOptionBeamer{highcontrast}{\LiU@highcontrasttrue} +\ProcessOptionsBeamer + +\newif\ifLiU@superhighcontrast\LiU@superhighcontrastfalse%% Option for super high contrast. +\DeclareOptionBeamer{superhighcontrast}{\LiU@superhighcontrasttrue} +\ProcessOptionsBeamer + +\newif\ifLiU@dark\LiU@darkfalse%% Option for dark colors. +\DeclareOptionBeamer{dark}{\LiU@darktrue} +\ProcessOptionsBeamer + +\newif\ifLiU@handout\LiU@handoutfalse%% Option for handout. +\DeclareOptionBeamer{handout}{\LiU@handouttrue} +\ProcessOptionsBeamer + +\newif\ifLiU@homepage\LiU@homepagefalse%% Option for homepage colors. +\DeclareOptionBeamer{homepage}{\LiU@homepagetrue} +\ProcessOptionsBeamer + +\newif\ifLiU@titlepageimage\LiU@titlepageimagefalse%% Option for homepage colors. +\DeclareOptionBeamer{titlepageimage}{\LiU@titlepageimagetrue} +\ProcessOptionsBeamer + +\newif\ifLiU@footerimage\LiU@footerimagefalse%% Option for homepage colors. +\DeclareOptionBeamer{footerimage}{\LiU@footerimagetrue} +\ProcessOptionsBeamer + +%% +%% Macro Definitions +%% + +%% Set foreground for all logos +\def\LiU@setlogos#1{ + \def\LiU@logo@color@titlepage{#1} + \def\LiU@logo@color@outlinepage{#1} + \def\LiU@logo@color@endpage{#1} + \def\LiU@logo@color@footline{#1} + \def\LiU@logo@color@blue{#1} + \def\LiU@logo@color@green{#1} + \def\LiU@logo@color@turquoise{#1} + \def\LiU@logo@color@homepage{#1} + \def\LiU@logo@color@orange{#1} + \def\LiU@logo@color@purple{#1} + \def\LiU@logo@color@yellow{#1} + \def\LiU@logo@color@gray{#1} +} + +%% Labels for color options +\def\LiU@green{green} +\def\LiU@blue{blue} +\def\LiU@turquoise{turquoise} +\def\LiU@orange{orange} +\def\LiU@purple{purple} +\def\LiU@yellow{yellow} +\def\LiU@gray{gray} +\def\LiU@homepage{homepage} + +%% Labels for logo types +\def\LiU@titlepage{titlepage} +\def\LiU@outline{outlinepage} +\def\LiU@endpage{endpage} +\def\LiU@black{black} +\def\LiU@white{white} +\def\LiU@footline{footline} + +%% Selected foreground for logos +\def\LiU@titlepagelogo{white} +\def\LiU@outlinepagelogo{white} +\def\LiU@endpagelogo{white} +\def\LiU@footlinelogo{black} + +\newcommand{\newcolor}[3]{% + \setbeamercolor{#1}{#2}% + \expandafter\def\csname LiU@logo@color@#1\endcsname{#3} +} + +%% +%% Color Definitions +%% +% Define colors as obtained from graphic manual +\definecolor{LiUblue}{RGB}{0,185,231} +\definecolor{LiUturquoise}{RGB}{23,199,210} +\definecolor{LiUgreen}{RGB}{0,207,181} + +\definecolor{LiUblue2}{RGB}{91,202,236} +\definecolor{LiUturquoise2}{RGB}{101,207,216} +\definecolor{LiUgreen2}{RGB}{86,214,192} + +\definecolor{LiUblue3}{RGB}{143,215,241} +\definecolor{LiUturquoise3}{RGB}{150,218,225} +\definecolor{LiUgreen3}{RGB}{143,223,207} + +\definecolor{LiUblue4}{RGB}{189,230,246} +\definecolor{LiUturquoise4}{RGB}{194,231,236} +\definecolor{LiUgreen4}{RGB}{191,235,225} + +\definecolor{LiUblue5}{RGB}{210,238,249} +\definecolor{LiUturquoise5}{RGB}{215,239,242} +\definecolor{LiUgreen5}{RGB}{213,241,235} + +\definecolor{LiUblue0}{RGB}{0,153,198} +\definecolor{LiUturquoise0}{RGB}{0,156,166} +\definecolor{LiUgreen0}{RGB}{59,168,144} + +\definecolor{LiUorange}{RGB}{255,100,66} +\definecolor{LiUpurple}{RGB}{137,129,211} +\definecolor{LiUyellow}{RGB}{253,239,93} +\definecolor{LiUgray}{RGB}{106,126,145} + +\definecolor{LiUorange3}{RGB}{255,164,154} +\definecolor{LiUpurple3}{RGB}{183,180,225} +\definecolor{LiUyellow3}{RGB}{254,244,165} +\definecolor{LiUgray3}{RGB}{170,178,187} + +\definecolor{LiUorange5}{RGB}{255,220,216} +\definecolor{LiUpurple5}{RGB}{226,224,242} +\definecolor{LiUyellow5}{RGB}{254,250,220} +\definecolor{LiUgray5}{RGB}{221,224,227} + +\definecolor{LiUhomepage}{RGB}{84,216,224} + +%% +%% Beamer Color Definitions +%% +\newcolor{default}{fg=black,bg=white}%% Base for normal frame + +\newcolor{blue}{fg=white,bg=LiUblue}{white} +\newcolor{green}{fg=white,bg=LiUgreen}{white} +\newcolor{turquoise}{fg=white,bg=LiUturquoise}{white} +\newcolor{homepage}{fg=black,bg=LiUhomepage}{black} + +\setbeamercolor{blue inverse}{fg=LiUblue,bg=white} +\setbeamercolor{green inverse}{fg=LiUgreen,bg=white} +\setbeamercolor{turquoise inverse}{fg=LiUturquoise,bg=white} +\setbeamercolor{homepage inverse}{fg=LiUhomepage,bg=black} + +\newcolor{lightblue}{fg=black,bg=LiUblue3}{black} +\newcolor{lightgreen}{fg=black,bg=LiUgreen3}{black} +\newcolor{lightturquoise}{fg=black,bg=LiUturquoise3}{black} +\newcolor{lighthomepage}{fg=black,bg=LiUturquoise3}{black} + +\newcolor{brightblue}{fg=black,bg=LiUblue5}{black} +\newcolor{brightgreen}{fg=black,bg=LiUgreen5}{black} +\newcolor{brightturquoise}{fg=black,bg=LiUturquoise5}{black} +\newcolor{brighthomepage}{fg=black,bg=LiUturquoise5}{black} + +\newcolor{darkblue}{fg=white,bg=LiUblue0}{white} +\newcolor{darkgreen}{fg=white,bg=LiUgreen0}{white} +\newcolor{darkturquoise}{fg=white,bg=LiUturquoise0}{white} +\newcolor{darkhomepage}{fg=white,bg=LiUturquoise0}{white} + +\newcolor{orange}{fg=white,bg=LiUorange}{white} +\newcolor{purple}{fg=white,bg=LiUpurple}{white} +\newcolor{yellow}{fg=white,bg=LiUyellow}{white} +\newcolor{gray}{fg=white,bg=LiUgray}{white} + +\setbeamercolor{orange inverse}{fg=LiUorange,bg=white} +\setbeamercolor{purple inverse}{fg=LiUpurple,bg=white} +\setbeamercolor{yellow inverse}{fg=LiUyellow,bg=white} +\setbeamercolor{gray inverse}{fg=LiUgray,bg=white} + +\newcolor{lightorange}{fg=black, bg=LiUorange3}{black} +\newcolor{lightpurple}{fg=black, bg=LiUpurple3}{black} +\newcolor{lightyellow}{fg=black, bg=LiUyellow3}{black} +\newcolor{lightgray}{fg=black, bg=LiUgray3}{black} + +\newcolor{brightorange}{fg=black, bg=LiUorange5}{black} +\newcolor{brightpurple}{fg=black, bg=LiUpurple5}{black} +\newcolor{brightyellow}{fg=black, bg=LiUyellow5}{black} +\newcolor{brightgray}{fg=black, bg=LiUgray5}{black} + +%% +%% Title Page Theme Definition +%% +\setbeamercolor*{titlepage}{parent=blue} +\setbeamercolor*{titlepage inverse}{parent=blue inverse} +\setbeamercolor*{lighttitlepage}{parent=lightblue} +\setbeamercolor*{brighttitlepage}{parent=brightblue} +\setbeamercolor*{darktitlepage}{parent=darkblue} +\def\LiU@logo@color@titlepage{white} +\ifx\LiU@titlecolor \LiU@blue + \setbeamercolor*{titlepage}{parent=blue} + \setbeamercolor*{titlepage inverse}{parent=blue inverse} + \setbeamercolor*{lighttitlepage}{parent=lightblue} + \setbeamercolor*{brighttitlepage}{parent=brightblue} + \setbeamercolor*{darktitlepage}{parent=darkblue} + \def\LiU@logo@color@titlepage{white} +\fi +\ifx\LiU@titlecolor \LiU@green + \setbeamercolor*{titlepage}{parent=green} + \setbeamercolor*{titlepage inverse}{parent=green inverse} + \setbeamercolor*{lighttitlepage}{parent=lightgreen} + \setbeamercolor*{brighttitlepage}{parent=brightgreen} + \setbeamercolor*{darktitlepage}{parent=darkgreen} + \def\LiU@logo@color@titlepage{white} +\fi +\ifx\LiU@titlecolor \LiU@turquoise + \setbeamercolor*{titlepage}{parent=turquoise} + \setbeamercolor*{titlepage inverse}{parent=turquoise inverse} + \setbeamercolor*{lighttitlepage}{parent=lightturquoise} + \setbeamercolor*{brighttitlepage}{parent=brightturquoise} + \setbeamercolor*{darktitlepage}{parent=darkturquoise} + \def\LiU@logo@color@titlepage{white} +\fi +\ifx\LiU@titlecolor \LiU@homepage + \setbeamercolor*{titlepage}{parent=homepage} + \setbeamercolor*{titlepage inverse}{parent=homepage inverse} + \setbeamercolor*{lighttitlepage}{parent=lighthomepage} + \setbeamercolor*{brighttitlepage}{parent=brighthomepage} + \setbeamercolor*{darktitlepage}{parent=darkhomepage} + \def\LiU@logo@color@titlepage{black} +\fi + +%% +%% Outline Page Theme Definition +%% +\setbeamercolor*{outlinepage}{parent=blue} +\setbeamercolor*{lightoutlinepage}{parent=lightblue} +\setbeamercolor*{brightoutlinepage}{parent=brightblue} +\setbeamercolor*{darkoutlinepage}{parent=darkblue} +\def\LiU@logo@color@outlinepage{white} +\ifx\LiU@outlinecolor \LiU@blue + \setbeamercolor*{outlinepage}{parent=blue} + \setbeamercolor*{lightoutlinepage}{parent=lightblue} + \setbeamercolor*{brightoutlinepage}{parent=brightblue} + \setbeamercolor*{darkoutlinepage}{parent=darkblue} + \def\LiU@logo@color@outlinepage{white} +\fi +\ifx\LiU@outlinecolor \LiU@green + \setbeamercolor*{outlinepage}{parent=green} + \setbeamercolor*{lightoutlinepage}{parent=lightgreen} + \setbeamercolor*{brightoutlinepage}{parent=brightgreen} + \setbeamercolor*{darkoutlinepage}{parent=darkgreen} + \def\LiU@logo@color@outlinepage{white} +\fi +\ifx\LiU@outlinecolor \LiU@turquoise + \setbeamercolor*{outlinepage}{parent=turquoise} + \setbeamercolor*{lightoutlinepage}{parent=lightturquoise} + \setbeamercolor*{brightoutlinepage}{parent=brightturquoise} + \setbeamercolor*{darkoutlinepage}{parent=darkturquoise} + \def\LiU@logo@color@outlinepage{white} +\fi +\ifx\LiU@outlinecolor \LiU@homepage + \setbeamercolor*{outlinepage}{parent=homepage} + \setbeamercolor*{lightoutlinepage}{parent=lighthomepage} + \setbeamercolor*{brightoutlinepage}{parent=brighthomepage} + \setbeamercolor*{darkoutlinepage}{parent=darkhomepage} + \def\LiU@logo@color@outlinepage{black} +\fi + +%% +%% End Page Theme Definition +%% +\setbeamercolor*{endpage}{parent=blue} +\setbeamercolor*{lightendpage }{parent=lightblue} +\setbeamercolor*{brightendpage}{parent=brightblue} + \setbeamercolor*{darkendpage}{parent=darkblue} +\def\LiU@logo@color@endpage{white} +\ifx\LiU@endcolor \LiU@green + \setbeamercolor*{endpage}{parent=green} + \setbeamercolor*{lightendpage}{parent=lightgreen} + \setbeamercolor*{brightendpage}{parent=brightgreen} + \setbeamercolor*{darkendpage}{parent=darkgreen} + \def\LiU@logo@color@endpage{white} +\fi +\ifx\LiU@endcolor \LiU@blue + \setbeamercolor*{endpage}{parent=blue} + \setbeamercolor*{lightendpage}{parent=lightblue} + \setbeamercolor*{brightendpage}{parent=brightblue} + \setbeamercolor*{darkendpage}{parent=darkblue} + \def\LiU@logo@color@endpage{white} +\fi +\ifx\LiU@endcolor \LiU@turquoise + \setbeamercolor*{endpage}{parent=turquoise} + \setbeamercolor*{lightendpage}{parent=lightturquoise} + \setbeamercolor*{brightendpage}{parent=brightturquoise} + \setbeamercolor*{darkendpage}{parent=darkturquoise} + \def\LiU@logo@color@endpage{white} +\fi +\ifx\LiU@endcolor \LiU@homepage + \setbeamercolor*{endpage}{parent=homepage} + \setbeamercolor*{lightendpage}{parent=lighthomepage} + \setbeamercolor*{brightendpage}{parent=brighthomepage} + \setbeamercolor*{darkendpage}{parent=darkhomepage} + \def\LiU@logo@color@endpage{black} +\fi + +%% +%% Block Theme Definition +%% +\setbeamercolor*{region}{parent=brightblue} +\setbeamercolor*{region title}{parent=blue} +\ifx\LiU@blockcolor \LiU@green + \setbeamercolor*{region}{parent=brightgreen} + \setbeamercolor*{region title}{parent=green} +\fi +\ifx\LiU@blockcolor \LiU@blue + \setbeamercolor*{region}{parent=brightblue} + \setbeamercolor*{region title}{parent=blue} +\fi +\ifx\LiU@blockcolor \LiU@turquoise + \setbeamercolor*{region}{parent=brightturquoise} + \setbeamercolor*{region title}{parent=turquoise} +\fi +\ifx\LiU@blockcolor \LiU@homepage + \setbeamercolor*{region}{parent=brighthomepage} + \setbeamercolor*{region title}{parent=homepage} +\fi +\ifx\LiU@blockcolor \LiU@orange + \setbeamercolor*{region}{parent=brightorange} + \setbeamercolor*{region title}{parent=orange} +\fi +\ifx\LiU@blockcolor \LiU@purple + \setbeamercolor*{region}{parent=brightpurple} + \setbeamercolor*{region title}{parent=purple} +\fi +\ifx\LiU@blockcolor \LiU@yellow + \setbeamercolor*{region}{parent=brightyellow} + \setbeamercolor*{region title}{parent=yellow} +\fi +\ifx\LiU@blockcolor \LiU@gray + \setbeamercolor*{region}{parent=brightgray} + \setbeamercolor*{region title}{parent=gray} +\fi + +%% +%% Complementary Theme Definition +%% +\setbeamercolor*{complementary}{parent=orange inverse} +\ifx \LiU@complementarycolor \LiU@orange + \setbeamercolor*{complementary}{parent=orange inverse} +\fi +\ifx\LiU@complementarycolor \LiU@purple + \setbeamercolor*{complementary}{parent=purple inverse} +\fi +\ifx\LiU@complementarycolor \LiU@yellow + \setbeamercolor*{complementary}{parent=yellow inverse} +\fi +\ifx\LiU@complementarycolor \LiU@gray + \setbeamercolor*{complementary}{parent=gray inverse} +\fi + +%% +%% Builtin Elements +%% +\setbeamercolor*{general page}{parent=default} + +%% Normal text and background +\setbeamercolor*{normal text}{parent=general page} +\setbeamercolor*{background canvas}{parent=general page} +\setbeamercolor*{description item}{parent=general page} +\def\LiU@logo@color@footline{black} + +%% Color for titles +\setbeamercolor{title}{parent=titlepage} +\setbeamercolor{subtitle}{parent=titlepage} + +%% Color for normal frame +\setbeamercolor{header}{parent=general page} +\setbeamercolor{frametitle}{parent=general page} +\setbeamercolor{framesubtitle}{parent=general page} +\setbeamercolor{footline}{parent=general page} +\setbeamercolor{headline}{parent=general page} + +%% Color for blocks +\setbeamercolor*{block title}{parent=region title} +\setbeamercolor*{block body}{parent=region} +\setbeamercolor*{description item}{parent=region} + +%% Clear some bad colors +\setbeamercolor*{structure}{parent=complementary} +\setbeamercolor*{alerted text}{parent=complementary} +\setbeamercolor*{qed symbol}{parent=general page} + +%% Remove structure color from navigation symbols +\setbeamercolor*{navigation symbols dimmed}{parent=general page} +\setbeamercolor*{navigation symbols}{parent=general page} + +%% Remove structure color from numbers and bullets in list +\setbeamercolor*{item}{parent=general page} + +%% Color for table of contents +\setbeamercolor{section in toc}{parent=outlinepage} +\setbeamercolor{subsection in toc}{parent=outlinepage} +%\setbeamercolor{section in toc shaded}{parent=outlinepage} +%\setbeamercolor{subsection in toc shaded}{parent=outlinepage} + +%% +%% Contrast Options +%% +\ifLiU@highcontrast + \setbeamercolor*{titlepage}{parent=lighttitlepage} + \setbeamercolor*{outlinepage}{parent=lightoutlinepage} + \setbeamercolor*{endpage}{parent=lightendpage} + \setbeamercolor*{blue}{parent=lightblue} + \setbeamercolor*{green}{parent=lightgreen} + \setbeamercolor*{turquoise}{parent=lightturquoise} + \setbeamercolor*{homepage}{parent=lighthomepage} + \setbeamercolor*{orange}{parent=lightorange} + \setbeamercolor*{purple}{parent=lightpurple} + \setbeamercolor*{yellow}{parent=lightyellow} + \setbeamercolor*{gray}{parent=lightgray} + \setbeamercolor*{general page}{parent=default} + + \LiU@setlogos{black} +\fi + +\ifLiU@superhighcontrast + \setbeamercolor*{titlepage}{parent=brighttitlepage} + \setbeamercolor*{outlinepage}{parent=brightoutlinepage} + \setbeamercolor*{endpage}{parent=brightendpage} + \setbeamercolor*{blue}{parent=brightblue} + \setbeamercolor*{green}{parent=brightgreen} + \setbeamercolor*{turquoise}{parent=brightturquoise} + \setbeamercolor*{homepage}{parent=brighthomepage} + \setbeamercolor*{orange}{parent=brightorange} + \setbeamercolor*{purple}{parent=brightpurple} + \setbeamercolor*{yellow}{parent=brightyellow} + \setbeamercolor*{gray}{parent=brightgray} + \setbeamercolor*{general page}{parent=default} + + \LiU@setlogos{black} +\fi + +\ifLiU@dark + \setbeamercolor*{titlepage}{parent=darktitlepage} + \setbeamercolor*{outlinepage}{parent=darkoutlinepage} + \setbeamercolor*{endpage}{parent=darkendpage} + \setbeamercolor*{blue}{parent=darkblue} + \setbeamercolor*{green}{parent=darkgreen} + \setbeamercolor*{turquoise}{parent=darkturquoise} + \setbeamercolor*{homepage}{parent=darkhomepage} + \setbeamercolor*{general page}{parent=default} + + \LiU@setlogos{white} +\fi + +\ifLiU@homepage + \setbeamercolor*{titlepage}{parent=homepage} + \setbeamercolor*{outlinepage}{parent=homepage} + \setbeamercolor*{endpage}{parent=homepage} + \setbeamercolor*{blue}{parent=homepage} + \setbeamercolor*{green}{parent=homepage} + \setbeamercolor*{turquoise}{parent=homepage} + \setbeamercolor*{general page}{parent=default} + + \LiU@setlogos{black} + \ifLiU@dark + \LiU@setlogos{white} + \fi +\fi + +\only<handout>{\LiU@handouttrue} +\ifLiU@handout + \setbeamercolor*{titlepage}{parent=default} + \setbeamercolor*{outlinepage}{parent=default} + \setbeamercolor*{endpage}{parent=default} + \setbeamercolor*{general page}{parent=default} + \setbeamercolor*{blue}{parent=default} + \setbeamercolor*{green}{parent=default} + \setbeamercolor*{turquoise}{parent=default} + \setbeamercolor*{homepage}{parent=default} + \setbeamercolor*{orange}{parent=default} + \setbeamercolor*{purple}{parent=default} + \setbeamercolor*{yellow}{parent=default} + \setbeamercolor*{gray}{parent=default} + \setbeamercolor*{general page}{parent=default} + + %\setbeamercolor*{block title}{parent=default} + %\setbeamercolor*{block body}{parent=default} + + \LiU@setlogos{black} +\fi + +%% +%% Image Definitions +%% + +%% Dimensions +\newdimen\LiU@logo@large@height +\newdimen\LiU@logo@small@height +\newdimen\LiU@logo@large@width +\newdimen\LiU@logo@small@width +\newdimen\LiU@image@large@height +\newdimen\LiU@image@small@height +\newdimen\LiU@image@large@width +\newdimen\LiU@image@small@width + +\LiU@logo@large@height=14.37548mm +\LiU@logo@large@width=40mm + +\LiU@logo@small@height=8.158084291mm +\LiU@logo@small@width=22.7mm + +\LiU@image@large@height=14.37548mm +\LiU@image@large@width=40mm + +\LiU@image@small@height=8.158084291mm +\LiU@image@small@width=22.7mm + +%% Load images +\pgfdeclareimage[height=\LiU@logo@large@height]{large_logo_white}{LiU_primary_white} +\pgfdeclareimage[height=\LiU@logo@large@height]{large_logo_black}{LiU_primary_black} + +\pgfdeclareimage[height=\LiU@logo@small@height]{small_logo_white}{LiU_primary_white} +\pgfdeclareimage[height=\LiU@logo@small@height]{small_logo_black}{LiU_primary_black} + +\ifLiU@titlepageimage + \pgfdeclareimage[height=\LiU@image@large@height]{large_image_white}{nsclogo-wb.pdf}%% Change to name of title page image + \pgfdeclareimage[height=\LiU@image@large@height]{large_image_black}{nsclogo-bw.pdf}%% Change to name of title page image +\fi + +\ifLiU@footerimage + \pgfdeclareimage[height=\LiU@image@small@height]{small_image_white}{nsclogo-wb.pdf}%% Change to name of footer image + \pgfdeclareimage[height=\LiU@image@small@height]{small_image_black}{nsclogo-bw.pdf}%% Change to name of footer image +\fi + +%% +%% Image Macro Definitions +%% +\def\insertLargeLogoColor#1{% + \def\LiU@logocolor{#1}% + \ifx\LiU@white\LiU@logocolor% + \pgfuseimage{large_logo_white}% + \fi% + \ifx\LiU@black\LiU@logocolor% + \pgfuseimage{large_logo_black}% + \fi% +} + +\def\insertLargeImageColor#1{% + \def\LiU@imagecolor{#1}% + \ifx\LiU@white\LiU@imagecolor% + \pgfuseimage{large_image_white}% + \fi% + \ifx\LiU@black\LiU@imagecolor% + \pgfuseimage{large_image_black}% + \fi% +} + +\def\insertSmallLogoColor#1{% + \def\LiU@logocolor{#1}% + \ifx\LiU@white\LiU@logocolor% + \pgfuseimage{small_logo_white}% + \fi% + \ifx\LiU@black\LiU@logocolor% + \pgfuseimage{small_logo_black}% + \fi% +} + +\def\insertSmallImageColor#1{% + \def\LiU@imagecolor{#1}% + \ifx\LiU@white\LiU@imagecolor% + \pgfuseimage{small_image_white}% + \fi% + \ifx\LiU@black\LiU@imagecolor% + \pgfuseimage{small_image_black}% + \fi% +} +\def\insertLargeLogo#1{% + \def\LiU@param{#1}% + \ifx\csname LiU@logo@color@#1\endcsname\undefined\else% + \def\LiU@logocolor{\csname LiU@logo@color@#1\endcsname}% + \@expandtwoargs\insertLargeLogoColor{\LiU@logocolor}% + \fi% +} + +\def\insertLargeImage#1{% + \def\LiU@param{#1}% + \ifx\csname LiU@logo@color@#1\endcsname\undefined\else% + \def\LiU@imagecolor{\csname LiU@logo@color@#1\endcsname}% + \@expandtwoargs\insertLargeImageColor{\LiU@imagecolor}% + \fi% +} + +\def\insertSmallLogo#1{% + \def\LiU@param{#1}% + \ifx\csname LiU@logo@color@#1\endcsname\undefined\else% + \def\LiU@logocolor{\csname LiU@logo@color@#1\endcsname}% + \@expandtwoargs\insertSmallLogoColor{\LiU@logocolor}% + \fi% +} +\def\insertSmallImage#1{% + \def\LiU@param{#1}% + \ifx\csname LiU@logo@color@#1\endcsname\undefined\else% + \def\LiU@imagecolor{\csname LiU@logo@color@#1\endcsname}% + \@expandtwoargs\insertSmallImageColor{\LiU@imagecolor}% + \fi% +} + +\mode<all> diff --git a/Lecture/beamerfontthemeLiU.sty b/Lecture/beamerfontthemeLiU.sty new file mode 100644 index 0000000000000000000000000000000000000000..f3fed34ca79033587bc02ae9a54427d2ceddb36b --- /dev/null +++ b/Lecture/beamerfontthemeLiU.sty @@ -0,0 +1,131 @@ +%% beamerfontthemeLiU.sty +%% Copyright 2015 Clas Veibäck +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Clas Veibäck. +% +% This work consists of the files beamer*themeLiU.sty +% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%% SOFTWARE. + +\mode<presentation> + +%% +%% Macro Definitions +%% +\def\LiU@latexfont{latex} +\def\LiU@standardfont{standard} +\def\LiU@liufont{liu} +\def\LiU@calibrifont{calibri} +\def\LiU@sansseriffont{sansserif} +\def\LiU@helveticafont{helvetica} + +%% +%% Read Options +%% +\def\LiU@font{\LiU@latexfont}%% Option for fonts to use. +\DeclareOptionBeamer{font}{\def\LiU@font{#1}} +\ProcessOptionsBeamer + +%% +%% Set internal font themes +%% +\usefonttheme{professionalfonts} + +%% +%% Font Selection +%% +\ifx\LiU@font\LiU@latexfont + \usefonttheme{serif} + % Select a different latex font here + %\renewcommand*\rmdefault{cmss} + %\renewcommand*\sfdefault{cmr} +\fi + +%% Use sans serif in normal text +\ifx\LiU@font\LiU@sansseriffont + % Select a different latex font here + %\renewcommand*\rmdefault{cmss} + %\renewcommand*\sfdefault{cmr} +\fi + +%% Use helvetica in normal text +\ifx\LiU@font\LiU@helveticafont + \usepackage[scaled=0.92]{helvet} +\fi + +%% Use standard presentation fonts, they need to be installed and LuaLaTeX is needed +\ifx\LiU@font\LiU@standardfont + \usefonttheme{serif} + \usepackage[no-math]{fontspec} + \setsansfont{Calibri} + \setmainfont{Georgia} +\fi + +%% Use calibri only, it needs to be installed and LuaLaTeX is needed +\ifx\LiU@font\LiU@calibrifont + \usefonttheme{serif} + \usepackage[no-math]{fontspec} + \setsansfont{Calibri} + \setmainfont{Calibri} +\fi + +%% Use KorolevLiU and Georgia fonts, they need to be installed and LuaLaTeX is needed +\ifx\LiU@font\LiU@liufont + \usefonttheme{serif} + \usepackage[no-math]{fontspec} + \setsansfont{KorolevLiU} + \setmainfont{Georgia} +\fi + +%% +%% Element Font Selection +%% +\setbeamerfont{header}{family=\sffamily} + +\setbeamerfont{title}{parent=header,size=\huge} +\setbeamerfont{subtitle}{parent=header, size=\large} +\setbeamerfont{author in title}{parent=header, size=\normalsize} +\setbeamerfont{institute in title}{parent=header, size=\small} + +\setbeamerfont{endtext}{parent=header,size=\huge} +\setbeamerfont{endauthor}{parent=header,size=\large} +\setbeamerfont{endlink}{parent=header,size=\Large} + +\setbeamerfont{section in toc}{parent=header,size=\large} +\setbeamerfont{subsection in toc}{parent=header,size=\small} + +\setbeamerfont{header author}{parent=header} +\setbeamerfont{header date}{parent=header} +\setbeamerfont{header number}{parent=header} +\setbeamerfont{header title}{parent=header} + +\setbeamerfont{frametitle}{parent=header} +\setbeamerfont{framesubtitle}{parent=header} + +\setbeamerfont{block title}{parent=header,size=\normalsize} + +% Structure and description item +%\setbeamerfont{structure}{family=\sffamily} +%\setbeamerfont{description item}{family=\sffamily} + +% Itemize and enumerate text and subitems +%\setbeamertemplate{itemize/enumerate body begin}{\sffamily} +%\setbeamerfont{itemize/enumerate body}{family=\sffamily} + +\mode<all> diff --git a/Lecture/beamerinnerthemeLiU.sty b/Lecture/beamerinnerthemeLiU.sty new file mode 100644 index 0000000000000000000000000000000000000000..93f90e11d92c7ba95848fe5bafb9984dd5783394 --- /dev/null +++ b/Lecture/beamerinnerthemeLiU.sty @@ -0,0 +1,69 @@ +%% beamerinnerthemeLiU.sty +%% Copyright 2015 Clas Veibäck +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Clas Veibäck. +% +% This work consists of the files beamer*themeLiU.sty +% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%% SOFTWARE. + +\mode<presentation> + +%% +%% Read Options +%% +\def\LiU@shadow{false}%% Option for block shadow. +\DeclareOptionBeamer{shadow}{\def\LiU@shadow{true}} +\ProcessOptionsBeamer + +\newif\ifLiU@rounded\LiU@roundedfalse%% Option for rounded block. +\DeclareOptionBeamer{rounded}{\LiU@roundedtrue} +\ProcessOptionsBeamer + +%% +%% Block style +%% +\ifLiU@rounded + \setbeamertemplate{blocks}[rounded][shadow=\LiU@shadow] +\else + \setbeamertemplate{blocks}[default] +\fi + +%% +%% Bullet styles +%% +\setbeamertemplate{itemize item}[circle] +\setbeamertemplate{itemize subitem}{\textbullet\enspace} +\setbeamertemplate{itemize subsubitem}{--} + +%% +%% Wnumeration styles +%% +\setbeamertemplate{enumerate item}{\insertenumlabel.} +\setbeamertemplate{enumerate subitem}{\insertsubenumlabel.} +\setbeamertemplate{enumerate subsubitem}{\insertsubsubenumlabel.} + +%% +%% Outline bullet styles +%% +\setbeamertemplate{section in toc}{\leavevmode\leftskip=2.5em{\hspace{-2.5em}\makebox[2em]{\inserttocsectionnumber}\inserttocsection\par}} +\setbeamertemplate{subsection in toc}{\leavevmode\leftskip=2.9em{\hspace{-0.5em}\inserttocsubsection\par}} +%\setbeamertemplate{subsection in toc}{\qquad{\textbullet}\enspace\inserttocsubsection \par} + +\mode<all> diff --git a/Lecture/beamerouterthemeLiU.sty b/Lecture/beamerouterthemeLiU.sty new file mode 100644 index 0000000000000000000000000000000000000000..204a88cdbff8ac58a32ab3f378822212af3b5aea --- /dev/null +++ b/Lecture/beamerouterthemeLiU.sty @@ -0,0 +1,314 @@ +%% beamerouterthemeLiU.sty +%% Copyright 2015 Clas Veibäck +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Clas Veibäck. +% +% This work consists of the files beamer*themeLiU.sty +% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%% SOFTWARE. + +\mode<presentation> + +%% +%% Read Options +%% +\newif\ifLiU@navigation\LiU@navigationfalse%% Option to add navigation symbols. +\DeclareOptionBeamer{navigation}{\LiU@navigationtrue} +\ProcessOptionsBeamer + +\newif\ifLiU@header\LiU@headertrue%% Option to remove header. +\DeclareOptionBeamer{noheader}{\LiU@headerfalse} +\ProcessOptionsBeamer + +\newif\ifLiU@footer\LiU@footertrue%% Option to remove footer. +\DeclareOptionBeamer{nofooter}{\LiU@footertrue} +\ProcessOptionsBeamer + +\newif\ifLiU@totalframes\LiU@totalframesfalse%% Option to add total number of frames. +\DeclareOptionBeamer{totalframes}{\LiU@totalframestrue} +\ProcessOptionsBeamer + +\newif\ifLiU@tightpage\LiU@tightpagefalse%% Option to get more space on page. +\DeclareOptionBeamer{tightpage}{\LiU@tightpagetrue} +\ProcessOptionsBeamer + +\newif\ifLiU@footerimage\LiU@footerimagefalse%% Option to add image in right side of footer. +\DeclareOptionBeamer{footerimage}{\LiU@footerimagetrue} +\ProcessOptionsBeamer + +\newif\ifLiU@header@title\LiU@header@titletrue%% Option to remove header title. +\newif\ifLiU@header@author\LiU@header@authortrue%% Option to remove header author. +\newif\ifLiU@header@date\LiU@header@datetrue%% Option to remove header date. +\newif\ifLiU@header@number\LiU@header@numbertrue%% Option to remove header number. +\DeclareOptionBeamer{minimalheader}{\LiU@header@titlefalse\LiU@header@authorfalse\LiU@header@datefalse} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheadertitle}{\LiU@header@titlefalse} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheaderauthor}{\LiU@header@authorfalse} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheaderdate}{\LiU@header@datefalse} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheadernumber}{\LiU@header@numberfalse} +\ProcessOptionsBeamer + +%% +%% Dimensions +%% +\newdimen\LiU@headline@height +\newdimen\LiU@headline@leftmargin +\newdimen\LiU@headline@rightmargin +\newdimen\LiU@headline@datespace +\newdimen\LiU@headline@numberwidth + +\newdimen\LiU@frametitle@top +\newdimen\LiU@frametitle@bottom +\newdimen\LiU@subtitle@bottom +\newdimen\LiU@subtitle@top +\newdimen\LiU@frametitle@leftmargin +\newdimen\LiU@frametitle@rightmargin +\newdimen\LiU@frametitle@width + +\newdimen\LiU@footline@top +\newdimen\LiU@footline@separation +\newdimen\LiU@footline@bottom +\newdimen\LiU@footline@navbottom +\newdimen\LiU@footline@imageadjustment +\newdimen\LiU@footline@leftmargin +\newdimen\LiU@footline@rightmargin +\newdimen\LiU@footline@rulelength + + +%% Tight page dimensions +\ifLiU@tightpage + \setbeamersize{text margin left=2.2em,text margin right=2.2em} + \def\LiU@headline@marginfactor{0.5} + \def\LiU@frametitle@marginfactor{0.5} + \def\LiU@footline@marginfactor{0.5} + + \LiU@headline@height=0.6em + + \LiU@frametitle@top=0.0em + \LiU@frametitle@bottom=-0.1em + \LiU@subtitle@top=-0.2em + \LiU@subtitle@bottom=-0.3em + + \LiU@footline@navbottom=1.1em + \LiU@footline@top=0.2em + \LiU@footline@separation=-0.3em + \LiU@footline@bottom=0.0em + \LiU@footline@imageadjustment=-0.5mm + +%% Approved profile dimensions +\else + \setbeamersize{text margin left=4.4em,text margin right=4.4em} + \def\LiU@headline@marginfactor{0.5} + \def\LiU@frametitle@marginfactor{0.55} + \def\LiU@footline@marginfactor{0.5} + + \LiU@headline@height=2em + + \LiU@frametitle@top=1em + \LiU@frametitle@bottom=0.2em + \LiU@subtitle@top=0em + \LiU@subtitle@bottom=0em + + \LiU@footline@navbottom=1.4em + \LiU@footline@top=0.6em + \LiU@footline@separation=0.2em + \LiU@footline@bottom=0.5em + \LiU@footline@imageadjustment=-0.5mm +\fi + +\LiU@footline@leftmargin=\LiU@footline@marginfactor\beamer@leftmargin +\LiU@footline@rightmargin=\LiU@footline@marginfactor\beamer@rightmargin + +\LiU@footline@rulelength=\paperwidth% +\advance \LiU@footline@rulelength by-\LiU@footline@leftmargin +\advance \LiU@footline@rulelength by-\LiU@footline@rightmargin + +\LiU@headline@leftmargin=\LiU@headline@marginfactor\beamer@leftmargin +\LiU@headline@rightmargin=\LiU@headline@marginfactor\beamer@rightmargin +\LiU@headline@datespace=2em +\LiU@headline@numberwidth=2em + +\LiU@frametitle@leftmargin=\LiU@frametitle@marginfactor\beamer@leftmargin +\LiU@frametitle@rightmargin=\LiU@frametitle@marginfactor\beamer@rightmargin + +\LiU@frametitle@width=\paperwidth +\advance \LiU@frametitle@width by-\LiU@frametitle@leftmargin +\advance \LiU@frametitle@width by-\LiU@frametitle@rightmargin + +% +% NAVIGATION +% +\setbeamertemplate{navigation symbols}{} + +\ifLiU@navigation + + % Only place here if image is showed + \ifLiU@footerimage + \setbeamertemplate{navigation symbols}{% + \vspace{-0.5em}% + \insertslidenavigationsymbol% + \insertframenavigationsymbol% + \insertsubsectionnavigationsymbol% + \insertsectionnavigationsymbol% + \insertdocnavigationsymbol% + \insertbackfindforwardnavigationsymbol% + \hspace{\LiU@footline@marginfactor\beamer@rightmargin}% + } + \fi +\fi + +% +% FOOTLINE +% +\setbeamertemplate{footline}[default] + +\ifLiU@footer + + % For colored themes, this needs to be replaced by a beamercolorbox + \defbeamertemplate*{footline}{infolines theme}{% + + \begin{beamercolorbox}[wd=\paperwidth]{footline} + \vspace\LiU@footline@top\vskip0em% + \hskip\LiU@footline@leftmargin\rule{\LiU@footline@rulelength}{0.4pt}% + \vskip\LiU@footline@separation% + \hskip\LiU@footline@leftmargin% + \insertSmallLogo{footline}% + \hfill% + \ifLiU@footerimage% + \raisebox{\LiU@footline@imageadjustment}[\LiU@footline@imageadjustment][\LiU@footline@imageadjustment]{% + \insertSmallImage{footline}% + }% + \hspace{\LiU@footline@rightmargin} % Space required + \fi% + \ifLiU@navigation% + \ifLiU@footerimage\else% + \raisebox{\LiU@footline@navbottom}{% + \insertslidenavigationsymbol% + \insertframenavigationsymbol% + \insertsubsectionnavigationsymbol% + \insertsectionnavigationsymbol% + \insertdocnavigationsymbol% + \insertbackfindforwardnavigationsymbol% + }% + \hspace{\LiU@footline@marginfactor\beamer@rightmargin} % + \fi% + \fi% + \vskip\LiU@footline@bottom% + \end{beamercolorbox}% + } +\fi + +\defbeamertemplate{footline}{LiUframe}[1][blue]{% + \usebeamercolor[fg]{#1}% + \vspace{-\LiUframelogobottom}% + \hskip\LiUframelogomargin \insertLargeLogo{#1} \hfill \ifLiU@titlepageimage \insertLargeImage{#1} \hspace{\LiUframelogomargin} \fi% + \vskip\LiUframelogobottom% +} + +% +% HEADLINE +% +\setbeamertemplate{headline}[default] + +\ifLiU@header + \defbeamertemplate*{headline}{infolines theme}{% + \begin{beamercolorbox}[wd=\paperwidth,ht=\LiU@headline@height]{headline}% + \hskip\LiU@headline@leftmargin% + \usebeamerfont{header title}% + \ifLiU@header@title% + \insertshorttitle% + \fi% + \hfill% + \usebeamerfont{header author}% + \ifLiU@header@author% + \insertshortauthor{}% + \fi% + \hfill% + \usebeamerfont{header date}% + \ifLiU@header@date% + \insertshortdate{}% + \fi% + \hspace*{\LiU@headline@datespace}% + \ifLiU@header@number% + \usebeamerfont{header number}% + \makebox[\LiU@headline@numberwidth][r]{% + \insertframenumber% + \ifLiU@totalframes% + \,/\,\inserttotalframenumber% + \fi% + }% + \fi% + \hspace*{\LiU@headline@rightmargin}% + \end{beamercolorbox}% + } +\fi + +\defbeamertemplate{headline}{LiUframe}{\vspace*{\headheight}} + +% +% FRAMETITLE +% +\defbeamertemplate*{frametitle}{LiU}[1][left]{% + \nointerlineskip% + \begin{beamercolorbox}[wd=\paperwidth]{frametitle}% + \usebeamerfont{frametitle}% + \vskip\LiU@frametitle@top% + \hskip\LiU@frametitle@leftmargin% + \begin{minipage}{\LiU@frametitle@width} + \insertframetitle \strut%\par% + \end{minipage} + \vskip\LiU@frametitle@bottom% + {% + \ifx\insertframesubtitle\@empty\else% + \vskip\LiU@subtitle@top% + {% + \usebeamerfont{framesubtitle}% + \usebeamercolor[fg]{framesubtitle}% + \hskip\LiU@frametitle@leftmargin% + \begin{minipage}{\LiU@frametitle@width}% + \insertframesubtitle \strut\par% + \end{minipage}% + }% + \fi% + }% + \end{beamercolorbox}% + + \vskip\LiU@subtitle@bottom% + \nointerlineskip% +} + +\defbeamertemplate{frametitle}{LiUframe}[1][blue]{% + \usebeamercolor[fg]{#1} + \usebeamerfont{frametitle}% + \vskip20mm% + \hskip1.5\LiUframelogomargin % + \begin{beamercolorbox}[wd=\LiU@titlewidth,left]{author}% + \raggedright\usebeamerfont{title}\insertframetitle\par% + \ifx\insertsubtitle\@empty\else% + \vskip3mm% + {\usebeamerfont{subtitle}\insertframesubtitle\par}% + \fi% + \end{beamercolorbox}% + \vspace{3mm}% +} + +\mode<all> diff --git a/Lecture/beamerthemeLiU.sty b/Lecture/beamerthemeLiU.sty new file mode 100644 index 0000000000000000000000000000000000000000..05ababcc5af2d389bcf12aa1f2238126963a5f37 --- /dev/null +++ b/Lecture/beamerthemeLiU.sty @@ -0,0 +1,318 @@ +%% beamerthemeLiU.sty +%% Copyright 2015 Clas Veibäck +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Clas Veibäck. +% +% This work consists of the files beamer*themeLiU.sty +% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%% SOFTWARE. + +\mode<presentation> + +%% +%% Packages +%% +\usepackage{etex} +\usepackage{multicol} + +%% +%% Read Options +%% +\DeclareOptionBeamer{titlecolor}{\PassOptionsToPackage{titlecolor=#1}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{outlinecolor}{\PassOptionsToPackage{outlinecolor=#1}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{endcolor}{\PassOptionsToPackage{endcolor=#1}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{blockcolor}{\PassOptionsToPackage{blockcolor=#1}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{complementary}{\PassOptionsToPackage{complementary=#1}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{highcontrast}{\PassOptionsToPackage{highcontrast}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{superhighcontrast}{\PassOptionsToPackage{superhighcontrast}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{dark}{\PassOptionsToPackage{dark}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{handout}{\PassOptionsToPackage{handout}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{homepage}{\PassOptionsToPackage{homepage}{beamercolorthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{shadow}{\PassOptionsToPackage{shadow}{beamerinnerthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{rounded}{\PassOptionsToPackage{rounded}{beamerinnerthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{font}{\PassOptionsToPackage{font=#1}{beamerfontthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{navigation}{\PassOptionsToPackage{navigation}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheader}{\PassOptionsToPackage{noheader}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{minimalheader}{\PassOptionsToPackage{minimalheader}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheadertitle}{\PassOptionsToPackage{noheadertitle}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheaderauthor}{\PassOptionsToPackage{noheaderauthor}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheaderdate}{\PassOptionsToPackage{noheaderdate}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{noheadernumber}{\PassOptionsToPackage{noheadernumber}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{nofooter}{\PassOptionsToPackage{nofooter}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{totalframes}{\PassOptionsToPackage{totalframes}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{tightpage}{\PassOptionsToPackage{tightpage}{beamerouterthemeLiU}} +\ProcessOptionsBeamer +\DeclareOptionBeamer{footerimage}{\PassOptionsToPackage{footerimage}{beamerouterthemeLiU}\PassOptionsToPackage{footerimage}{beamercolorthemeLiU}} +\ProcessOptionsBeamer + +\newif\ifLiU@titlepageimage\LiU@titlepageimagefalse%% Option to add image to title page +\DeclareOptionBeamer{titlepageimage}{\LiU@titlepageimagetrue\PassOptionsToPackage{titlepageimage}{beamercolorthemeLiU}} +\ProcessOptionsBeamer + +\newif\ifLiU@endpage\LiU@endpagetrue%% Option for removing end page. +\DeclareOptionBeamer{noendpage}{\LiU@endpagefalse} +\ProcessOptionsBeamer + +\newif\ifLiU@outline\LiU@outlinetrue%% Option for removing outline. +\DeclareOptionBeamer{nooutline}{\LiU@outlinefalse} +\ProcessOptionsBeamer + +\def\LiU@outlinecolumns{1}%% Option for number of outline columns +\DeclareOptionBeamer{outlinecolumns}{\def\LiU@outlinecolumns{#1}} +\ProcessOptionsBeamer + +\newif\ifLiU@institute\LiU@institutefalse%% Option for showing institute on title page. +\DeclareOptionBeamer{showinstitute}{\LiU@institutetrue} +\ProcessOptionsBeamer + +%% +%% Set themes +%% +\useinnertheme{LiU} +\useoutertheme{LiU} +\usecolortheme{LiU} +\usefonttheme{LiU} + +%% +%% LIU FRAME +%% +\newdimen\LiU@titlemargin +\LiU@titlemargin = 25mm + +\newdimen\LiU@logobottom +\LiU@logobottom = 4mm + +\newdimen\LiU@titlewidth +\LiU@titlewidth = \paperwidth +\advance \LiU@titlewidth by-2\LiU@titlemargin + +\newdimen\LiU@logomargin +\LiU@logomargin = \LiU@titlemargin +\advance \LiU@logomargin by-0.5\LiU@logo@large@width%% According to specification + +\newcommand<>{\LiUframe}[2][blue]{% + \begingroup% + \setbeamertemplate{navigation symbols}{}% + \setbeamercolor{background canvas}{parent=#1}% + \setbeamertemplate{footline}[LiUframe][#1]% + \setbeamertemplate{headline}[LiUframe]% + \setbeamertemplate{frametitle}[LiUframe][#1]% + \usebeamercolor[fg]{#1}% + % + \begin{frame}#3% + \begin{center}% + \begin{minipage}[c][0.6\paperheight][c]{1.01\LiUframewidth}% + #2% + \end{minipage} + \end{center}% + \end{frame}% + \endgroup% +} + +% \newcommand<>{\LiUframe}[2][blue]{% + % \begingroup% + % \setbeamertemplate{navigation symbols}{}% + % \begin{frame}#3[plain]% + % \begin{beamercolorbox}[wd=\paperwidth,ht=\paperheight,left]{#1}% + % \begin{center}% + % \begin{minipage}[c][0.6\paperheight][c]{1\LiUframewidth}% + % #2% + % \end{minipage} + % \end{center}% + % \hskip\LiUframelogomargin% + % \vskip0mm% + % \begin{minipage}{\paperwidth}% + % \hskip\LiUframelogomargin \insertLargeLogo{#1} \hfill \ifLiU@titlepageimage \insertLargeImage{#1} \hspace{\LiUframelogomargin} \fi% + % \end{minipage}% + % \vskip\LiUframelogobottom% + % \end{beamercolorbox}% + % \end{frame}% + % \endgroup% +% } + +% +% TITLE PAGE +% +\def\maketitle{% + \ifbeamer@inframe% + \PackageWarning{LiU}{% + \begin{verbatim}% + \maketitle must be called outside frame. + \end{verbatim}% + }% + \else% + \LiUframe[titlepage]{% + \titlepage% + }% + \fi% +}% + +\newdimen\LiU@titlepage@position +\LiU@titlepage@position = 10mm + +\newdimen\LiU@titlepage@titlesparation +\LiU@titlepage@titlesparation = 3mm + +\newdimen\LiU@titlepage@instituteseparation +\LiU@titlepage@instituteseparation = 3mm + +\newdimen\LiU@titlepage@institutebottom +\LiU@titlepage@institutebottom = -10mm + +\defbeamertemplate*{title page}{LiU}[1][]{% + %% + %% Title page is page 0 + \setcounter{framenumber}{0}% + %% + %% Insert title + \raggedright\usebeamerfont{title}\inserttitle\par% + %% + %% Insert subtitle if needed + \ifx\insertsubtitle\@empty\else% + {\usebeamerfont{subtitle}\insertsubtitle\par}% + \fi% + %% + %% Insert author + \vskip\LiU@titlepage@titlesparation% + \raggedright\usebeamerfont{author in title}\insertauthor% + %% + %% Insert institute if needed + \ifx\insertinstitute\@empty\else% + \ifLiU@institute% + \vskip\LiU@titlepage@instituteseparation + \raggedright\usebeamerfont{institute in title}\insertinstitute% + \vspace{\LiU@titlepage@institutebottom}% + \fi% + \fi% + \vspace{\LiU@titlepage@position}% +} + +% +% END PAGE +% +\def\makeend{% + \ifbeamer@inframe% + \PackageWarning{LiU}{% + \begin{verbatim}% + \makeend must be called outside frame. + \end{verbatim}% + }% + \else% + \LiUframe[endpage]{% + \endpage% + }% + \fi% +} + +\newdimen\LiU@endpage@textposition +\LiU@endpage@textposition = 0mm + +\newdimen\LiU@endpage@separation +\LiU@endpage@separation= 2mm + +\defbeamertemplate*{end page}{LiU}[1][]{% + \begin{center}% + \ifx\LiU@finaltext\LiU@empty% + \usebeamerfont{endauthor}\insertauthor\par% + \else% + \usebeamerfont{endtext}\LiU@finaltext\par% + \fi% + \vspace{\LiU@endpage@separation} + \usebeamerfont{endlink}\href{www.liu.se}{www.liu.se}% + \end{center}% + \vspace{\LiU@endpage@textposition}% +} + +\def\endpage{\usebeamertemplate*{end page}} + +\ifLiU@endpage + \AtEndDocument{\makeend} +\fi + +% +% OUTLINE PAGE +% + +\newcommand{\makeoutline}[1][]{% + \begingroup% + \setbeamertemplate{outline page}[LiU][#1]% + \ifbeamer@inframe% + \outlinepage% + \else% + \LiUframe[outlinepage]{% + \outlinepage% + } + \fi% + \endgroup% +} + +\newdimen\LiU@outlineposition +\LiU@outlineposition = -4mm + +\defbeamertemplate*{outline page}{LiU}[1][]{% + \hspace{\LiU@outlineposition} + \begin{minipage}[c]{1.0\LiUframewidth}% + \if\LiU@outlinecolumns1% + \tableofcontents[#1]% + \else% + \begin{multicols}{\LiU@outlinecolumns}% + \tableofcontents[#1]% + \end{multicols}% + \fi% + \end{minipage}% +} + +\def\outlinepage{\usebeamertemplate*{outline page}} + +\ifLiU@outline + \AtBeginSection[]{\makeoutline[currentsection]} +\fi + +%% +%% Macro Export +%% +\def\LiUframewidth{\LiU@titlewidth} +\def\LiUframemargin{\LiU@titlemargin} +\def\LiUframelogomargin{\LiU@logomargin} +\def\LiUframelogobottom{\LiU@logobottom} +\newcommand{\finaltext}[1]{\gdef\LiU@finaltext{#1}} + +\mode<all> diff --git a/Lecture/fig10_47.png b/Lecture/fig10_47.png new file mode 100644 index 0000000000000000000000000000000000000000..85b08a84e76aef1a337429a168159d0a7dcc37f7 Binary files /dev/null and b/Lecture/fig10_47.png differ diff --git a/Lecture/introduction-to-programming-with-c-13-638.jpg b/Lecture/introduction-to-programming-with-c-13-638.jpg new file mode 100644 index 0000000000000000000000000000000000000000..401e134b219c67ee466b724a23edb46c2a9033cb Binary files /dev/null and b/Lecture/introduction-to-programming-with-c-13-638.jpg differ diff --git a/Lecture/lecture_swe.tex b/Lecture/lecture_swe.tex new file mode 100644 index 0000000000000000000000000000000000000000..48ed86998b4301fabfeea31107ecb962affa2ebc --- /dev/null +++ b/Lecture/lecture_swe.tex @@ -0,0 +1,1855 @@ +%% Python lecture +%% (C) Rickard Armiento, 2017 + +%% LiU Beamer Template: Copyright 2015 by Clas Veibäck, Automatic Control, Linköping University +%% Notes on usage +%% With latex and sansserif fonts, pdfLaTeX can be used +%% With standard font, LuaLaTeX needs to be used and Calibri and Georgia need to be installed +%% With LiU font, LuaLaTeX needs to be used and Korolev LiU and Georgi need to be installed +%% With calibri font, LuaLaTeX needs to be used and Calibri need to be installed + +\documentclass[vipdfmx, noamsthm, swedish]{beamer}% +\usepackage[T1]{fontenc}% +\usepackage[swedish]{babel}% +\usepackage{blindtext}% +\usepackage{pdfpages} +\usepackage[absolute,overlay]{textpos} +%% +%% Commands +%% +\newcommand{\function}[3]{% + \begin{center}% + {\usebeamerfont{header}{{\usebeamercolor[fg]{orange inverse}\textbackslash #1}}% + {\usebeamercolor[fg]{green inverse}{[#2]}}% + \{#3\}}% + \end{center}% +} + +\newcommand{\shortfunction}[2]{% + \begin{center}% + {\usebeamerfont{header}{{\usebeamercolor[fg]{orange inverse}\textbackslash #1}}% + \{#2\}}% + \end{center}% +} + +\newcommand{\shortinlinefunction}[2]{% + {\usebeamerfont{header}{{\usebeamercolor[fg]{orange inverse}\textbackslash #1}}% + \{#2\}}% +} + +\newcommand{\macro}[1]{{\usebeamerfont{header}{{\usebeamercolor[fg]{orange inverse}\textbackslash #1}}} +} + +\newcommand{\environ}[3]{% + \begin{center}% + {\usebeamerfont{header}% + {{\usebeamercolor[fg]{orange inverse}\textbackslash begin \{#1\}}}% + {\usebeamercolor[fg]{green inverse}[#2]}% + #3% + {{\usebeamercolor[fg]{orange inverse}\textbackslash end \{#1\}}}}% + \end{center}% +} + +\newcommand{\code}[2][Example Code]{\begin{block}{#1}\small \vspace{-1em}\begin{semiverbatim}#2\end{semiverbatim}\vspace{-1em}\end{block}}% + +\newenvironment{codeblock}[1][Example Code] + {\begin{block}{#1}\footnotesize\vspace{-1em}\begin{semiverbatim}}% + {\end{semiverbatim}\vspace{-1em}\end{block}}% + +%% +%% Theme +%% +\usetheme[% +%% Standard colors {blue, green, turquoise} for title, outline and end pages +titlecolor=blue,% +outlinecolor=green,% +endcolor=turquoise,% +%% Complementary colors {orange, purple, yellow, gray} for some details +complementary=orange,% +%% All colors {blue, green, turquoise, orange, purple, yellow, gray} for blocks +blockcolor=blue,% +%% Font schemes {latex, standard, sansserif, calibri, liu} to use +font=liu,% +%% Select color themes {highcontrast, superhighcontrast, dark} with high contrast or add handout option in documentclass +%highcontrast,% +%superhighcontrast,% +%% Remove outline before each section and end page with {nooutline, noendpage} +%nooutline, % +%noendpage,% +%% Add navigation symbols with {navigation} +%navigation,% +%% Add total number of frames to frame count with {totalframes} +totalframes,% +% Remove parts of header with {noheadertitle, noheaderauthor, noheaderdate, noheadernumber, minimalheader, noheader} +%noheadertitle,% +%noheaderauthor,% +%noheaderdate,% +%noheadernumber,% +%% Show outline in two columns +outlinecolumns=2,% +%titlepageimage,% +%footerimage,% +%noheader,% +nofooter,% +tightpage +]{LiU}% + +%% Add a text on end page, leave blank to add author +\finaltext{Rickard Armiento \\%[-0.5em]% + \small \href{rickard.armiento@liu.se}% + {rickard.armiento@liu.se}\vspace{0.5em} +} + +% Default fixed font does not support bold face +\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold +\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12} % for normal + +% Custom colors +\usepackage{color} +\definecolor{deepblue}{rgb}{0,0,0.5} +\definecolor{deepred}{rgb}{0.6,0,0} +\definecolor{deepgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{escapeinside={<@}{@>}} + +% Python style for highlighting +\newcommand\pythonstyle{\lstset{ +language=Python, +basicstyle=\ttm, +otherkeywords={self}, % Add keywords here +keywordstyle=\ttb\color{deepblue}, +%emph={MyClass,__init__}, % Custom highlighting +emphstyle=\ttb\color{deepred}, % Custom highlighting style +stringstyle=\color{deepgreen}, +%frame=tb, % Any extra options here +frame=single, +showstringspaces=false % +breaklines=true, +basicstyle=\scriptsize\ttfamily, +keywordstyle=\bfseries\color{green!40!black}, +commentstyle=\itshape\color{purple!40!black}, +identifierstyle=\color{black},%\color{blue}, +stringstyle=\color{orange} +}} + +\newcommand\pythoninlinestyle{\lstset{ +language=Python, +basicstyle=\ttm, +otherkeywords={self}, % Add keywords here +keywordstyle=\ttb\color{deepblue}, +emph={MyClass,__init__}, % Custom highlighting +emphstyle=\ttb\color{deepred}, % Custom highlighting style +stringstyle=\color{deepgreen}, +%frame=tb, % Any extra options here +frame=single, +showstringspaces=false % +breaklines=true, +basicstyle=\scriptsize\ttfamily, +keywordstyle=\bfseries\color{green!40!black}, +commentstyle=\itshape\color{purple!40!black}, +identifierstyle=\color{black},%\color{blue}, +stringstyle=\color{orange} +}} + +\newcommand\pythoninlinestylesmall{\lstset{ +language=Python, +basicstyle=\ttm, +otherkeywords={self}, % Add keywords here +keywordstyle=\ttb\color{deepblue}, +emph={MyClass,__init__}, % Custom highlighting +emphstyle=\ttb\color{deepred}, % Custom highlighting style +stringstyle=\color{deepgreen}, +%frame=tb, % Any extra options here +frame=single, +showstringspaces=false % +breaklines=true, +basicstyle=\tiny\ttfamily, +keywordstyle=\bfseries\color{green!40!black}, +commentstyle=\itshape\color{purple!40!black}, +identifierstyle=\color{black},%\color{blue}, +stringstyle=\color{orange} +}} + +\newcommand\pythoninteractivestyle{\lstset{ +language=Python, +basicstyle=\ttm, +otherkeywords={self}, % Add keywords here +keywordstyle=\ttb\color{deepblue}, +emph={MyClass,__init__}, % Custom highlighting +emphstyle=\ttb\color{deepred}, % Custom highlighting style +stringstyle=\color{deepgreen}, +%frame=tb, % Any extra options here +frame=single, +showstringspaces=false % +breaklines=true, +basicstyle=\scriptsize\ttfamily, +keywordstyle=\bfseries\color{green!40!black}, +commentstyle=\itshape\color{purple!40!black}, +identifierstyle=\color{black},%\color{blue}, +stringstyle=\color{orange} +}} + +\newcommand\cstyle{\lstset{ +language=c, +basicstyle=\ttm, +otherkeywords={self}, % Add keywords here +keywordstyle=\ttb\color{deepblue}, +emph={MyClass,__init__}, % Custom highlighting +emphstyle=\ttb\color{deepred}, % Custom highlighting style +stringstyle=\color{deepgreen}, +%frame=tb, % Any extra options here +frame=single, +showstringspaces=false % +breaklines=true, +basicstyle=\scriptsize\ttfamily, +keywordstyle=\bfseries\color{green!40!black}, +commentstyle=\itshape\color{purple!40!black}, +identifierstyle=\color{black},%\color{blue}, +stringstyle=\color{orange} +}} + +% Python environment +\lstnewenvironment{python}[1][] +{ +\pythonstyle +\lstset{#1} +} +{} + +% Python environment +\lstnewenvironment{ccode}[1][] +{ +\cstyle +\lstset{#1} +} +{} + +% Python environment +\lstnewenvironment{ipython}[1][] +{ +\pythoninteractivestyle +\lstset{#1} +} +{} + +% Python for external files +\newcommand\pythonexternal[2][]{{ +\pythonstyle +\lstinputlisting[#1]{#2}}} + +% Python for inline +\newcommand\pythoninline[1]{{\fbox{\pythoninlinestyle\lstinline!#1!}}} +\newcommand\pythoninlinesmall[1]{{\fbox{\pythoninlinestylesmall\lstinline!#1!}}} + +%% +%% Presentation information +%% +\title[Programmering]{Visualiseringsprojektet:\\Programmering, Python, mm.} +\subtitle{\strut\\% +Kandidatprojekt Fysik 2023}% +\author{Rickard Armiento}% +%\institute{Institutionen för Fysik, Kemi och Biologi\\% +%Linköping University}% +\date{\today}% + +\newsavebox{\codeone} +\newsavebox{\codetwo} +\newsavebox{\codethree} +\newsavebox{\codefour} + + +%% +%% Presentation +%% +\begin{document}% + +\maketitle +%\makeoutline + +%% +%\section{Introduction} +%% + +%\begin{frame} +%\includemovie[poster,text={\small(Loading Video...)}]{6cm}{4cm}{a_boy_and_his_atom.mp4} +%\movie{placeholder box}{a_boy_and_his_atom.mp4} +%\href{run:/usr/bin/totem a_boy_and_his_atom.mp4}{Video} +%\href{run:a_boy_and_his_atom.mp4}{Video} +%\end{frame} + +\begin{frame} +\frametitle{Outline} +\begin{itemize} +\item Beräkningar och programmering: + \begin{itemize} + \item historik beräkningar + \item programspråk + \item programmeringsparadigmer + \item objektorientering + \end{itemize} +\item Python: grunder +\item Mer avancerad Python +\item Labb +\end{itemize} +\end{frame} + +\begin{frame} +\Huge Beräkningar och programmering +\end{frame} + +\begin{frame} +\frametitle{Kort historik} +\setlength{\leftmargini}{0pt} +\scriptsize +\begin{itemize}\tiny +\item ca 100 fk: Antikythera mechanism: astronomiskt verktyg/kalender. +\item 1200--: Programmerbara musikinstrument. +\item 1600--1700: Olika mekaniska beräkningsmaskiner (Schickard, Burattini, Morland, Pascal, Grillet, Leibniz) +\item 1770-1854: ''The Mechanical Turk'' av Wolfgang von Kempelen: mekanisk schackspelande maskin som kunde slå de flesta spelare! Reste runt Europa och tros ha inspererat (men: det var fusk!) +\item 1801: Joseph Marie Jacquard: Programmerbar vävstol. +\item 1837: Charles Babbages 'Analytical engine', en 'riktig', mekanisk, dator; generalisering av en maskin för att approximera polynom för bl.a. astronomiska tabeller. Internminne 1000 tal (ca. 16 kB). Lyckas inte bygga den. +\item 1843: Ada Lovelace översätter en beskriving av Babbages maskin; lägger till ett eget program för att beräkna Bernoullital. +\item 1927: Hillbert diskuterar matematikens fundamenta, proof theory; att enumerera 'alla bevis' för att bevisa att 'matematik är konsistent'. (Gödel stoppar detta...) +\item 1930--1950: Alan Turing, arbeten på formalisering av algoritmer och program, Turingmaskinen. Alonzo Church introducerar $\lambda$-kalkyl i studie av matematikens fundamenta och beräkningar. +\item 1947: Transistorn uppfinns... +\end{itemize} +\includegraphics[width=0.2\linewidth]{antikythera.jpg} +\includegraphics[width=0.2\linewidth]{Schickardmaschine.jpg} +\includegraphics[width=0.2\linewidth]{AnalyticalMachine_Babbage_London.jpg} +\includegraphics[width=0.2\linewidth]{Replica-of-first-transistor.jpg} +\end{frame} + +%\begin{frame} +%\frametitle{Bakgrund: transistorer} +%\setlength{\leftmargini}{0pt} +%Transistorer (Modern Fysik II) +%\begin{columns}[c] +%\column{0.80\linewidth} +%\includegraphics[width=\linewidth]{fig10_44_crop.png} +%\column{0.05\linewidth} +%$\Large \Rightarrow$ +%\column{0.10\linewidth} +%\includegraphics[width=\linewidth]{transistorsymbol.png} +%\end{columns} +%\end{frame} + +\begin{frame} +\frametitle{Transistorer $\rightarrow$ Logiska grindar} +\setlength{\leftmargini}{0pt} +Halvledarfysik $\Rightarrow$ Transistorer (Modern Fysik II) +\begin{columns}[T] +\column{0.26\linewidth} +\includegraphics[width=\linewidth]{andgate.png}\\ +\includegraphics[width=\linewidth]{orgate.png} +\column{0.05\linewidth} +\column{0.75\linewidth} +\includegraphics[width=0.8\linewidth]{logicgates2.png}\\ +\end{columns} +\end{frame} + +\begin{frame} +\frametitle{Logiska grindar $\rightarrow$ Beräkningar} +\setlength{\leftmargini}{0pt} +Med några få grindar kan man skapa vilken 'funktion' som helst. (faktum är, det räcker faktiskt med en grind, NAND = inverterad AND).\\ +\includegraphics[width=0.3\linewidth]{Half_Adder.pdf} +\includegraphics[width=0.2\linewidth]{adder-truthtable.png} +\includegraphics[width=0.3\linewidth]{fig10_47.png}\\ +Och med tillräckligt många, realiserar man en 'Analytic Engine', d.v.s.\ Babbages / Turings generella beräkningsmaskin. +\end{frame} + +\begin{frame} +\frametitle{Programmeringsspråk} +Instruktuerar datorn att ta indata, lagra data, manipulera data, och producera utdata. +\begin{itemize} +\item Lågnivåspråk: Maskinkod, Assembler\\ + {\scriptsize I princip direkt översättning till maskinens egna instruktioner.\par} +\item Högre nivå: C, etc.\\ + {\scriptsize Mer abstrakt hantering av datatyper, funktioner, etc. Översätts (kompileras) till assembler/maskinkod.\par} +\item Högnivåspråk: Python, Ruby, Basic, Javascript, etc.\\ + {\scriptsize Högre nivå av abstaktion som, t.ex. containers, $\lambda$-funktioner, garbage collection. Ofta interpreterade.\par} +\end{itemize} +\includegraphics[width=0.5\linewidth]{Apple_II_Monitor.png}\includegraphics[width=0.5\linewidth]{introduction-to-programming-with-c-13-638.jpg}\\ +\end{frame} + +\begin{frame} +\frametitle{Grundläggande programmeringsparadigmer} +{\scriptsize\emph{(Notera: man ska vara försiktig med att se dessa som strikta kategoriseringar. Orden används på olika sätt i olika källor och beroende på sammanhang.)}\par} +\begin{itemize} +\item Procedurell (procedural) {\scriptsize \color{blue}$\quad \leftarrow \sim$ 'normal' Python (mer strax om oo)}\\ + {\scriptsize Steg för steg vad som ska göras, som ett recept. 'Procedurer'/subrutiner/funktioner är grupperingar av steg som anroppas i andra: ''gör en pizzadeg''. Nära assembler och hårdvara. Har stöd i hårdvara m.h.a. stack, mm.\par} +\item Funktionell (functional) {\scriptsize \color{blue}$\leftarrow$ visst stöd i Python \tiny(lambda, map, reduce, filter; closures)}\\ + {\scriptsize Matematisk modell som går tillbaka till $\lambda$-kalkyl, definera (matematiska) funktioner; $f(g(5),h(7))$. Är 'turingkomplett' och lika kapabel som procedurell. Loopar görs med rekursion.\par} +\item Ström (flow) {\scriptsize \color{blue}$\leftarrow$ Inviwo GUI; visst stöd i Python \tiny (list comprehension, generators)}\\ + {\scriptsize Applicera operationer på element i listor $\rightarrow$ nya listor. Begränsad form av automatisk parallellism.\par} +\item Logisk (logical)\\ + {\scriptsize Formulera relationer, och utför en fråga på dessa. Mata in reglerna för derivator, och systemet kan derivera godtyckliga uttryck.\par} +\item[] ... osv ... +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Programmeringsparadigmer: struktur} +\begin{itemize} +\item Monolitisk vs. Modulär\\ + {\scriptsize Modulär: Dela upp program i moduler med isolerad funktionalitet som är så oberoende som möjligt. Interaktion mellan moduler via gränssnitt (interface).\par} +\item Objektorientering (object oriented programming) \\ + {\scriptsize Programrutiner 'metoder' organiseras tillsammans med de data de opererar på i objekt. 'Data först' vs. 'Kod först'.\par} +\end{itemize} +Moduler och OO-objekt (eller klasser, mer strax) är likartade, men inte identiska, koncept. + +\strut + +''Vanligast'' (?): modulär programmering, objektorientering, metoder implementerade som procedurella funktioner. +\end{frame} + +\begin{frame} +\frametitle{Objektorientering, objekt, klasser, metoder} +\includegraphics[width=0.8\linewidth]{ookakor.pdf}\\ +T.ex. klassen Car: +\begin{itemize} +\item Egenskaper: Make, Model, Color, Year, Price +\item Metoder: start, drive, park +\item Event: On\_start, On\_parked, On\_brake +\item Kan innehålla andra objekt: engine, steering\_wheel, ... +\item Kan ärva andra klasser: {\scriptsize car $\leftarrow$ motor\_vehicle $\leftarrow$ vehicle} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Källkods/versionshantering} +Kräver extra arbete och något annorlunda arbetssätt. Organisera arbetet i små enheter som syftar till något specifikt (som också beskrivs vid incheckning.) Ger många fördelar: +\begin{itemize} +\item Backup med full historik +\item Orangiserat sammarbete +\item Provenance: var kom det här ifrån, varför? (och, vem?) +\item Bisection för att hitta buggar +\item Driver fram bättre organiserad programmering +\end{itemize} +Paradigmer: +\begin{itemize} +\item Centraliserad (CVS, SVN, ...)\\ + {\scriptsize Ett master-repository. Undvik konflikter genom att 'checka ut' filer att arbeta på.\par} +\item Distribuerad (git, ...)\\ + {\scriptsize Alla sköter en egen kopia. Man hämtar ändringar ifrån andra ('merge'). Hantering av konflikter ska vara så lätt som möjligt.\par} +\end{itemize} +\end{frame} + +%\begin{frame}{movie} +%\begin{figure}[h!] +%\centering +%\movie[label=show3,width=1.0\textwidth,poster +% ,autostart,showcontrols,loop] +% {x}{montypythonfishslappingdance.mp4} +% \caption{caption} +% \end{figure} +%\end{frame} + +%\begin{frame} +%\frametitle{Python} +%\begin{itemize} +%\item Beautiful is better than ugly +%\item Explicit is better than implicit +%\item Simple is better than complex +%\item Complex is better than complicated +%\item Readability counts +%\end{itemize} +%\href{run:montypythonfishslappingdance.mp4}{>\includegraphics[width=0.5\linewidth]{montypython.png}}%\includegraphics[width=\linewidth]{montypython.png}} +%\end{frame} + +\begin{frame} + \Huge Python: grunder +\end{frame} + +\begin{frame} +\frametitle{Python} +\scriptsize +Highlights: +\begin{itemize} +\item Portable (Unix/Linux, Mac OS X, Windows), Free, Open source +\item Interpreted and interactive +\item Dynamic duck-typed language. +\item Object-oriented, Modular, Exceptions, Automatic garbage collection +\item Enables fast development with simple syntax +\item ``Batteries Included'': Large standard library +\item Lots of third party libraries, especially for numerics and scientific computing. +\item Two (somewhat) incompatible versions: Python 2, 3. +\end{itemize} +\href{run:montypythonfishslappingdance.mp4}{>\includegraphics[width=0.5\linewidth]{montypython.png}} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Hello world!} +Java: +\begin{python} +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} +\end{python} + +\strut + +Python: + \begin{python} +print("Hello world!") +\end{python} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Köra sitt första Python-program} +Skapa filen \texttt{hello\_world.py} +\begin{python} +#!/usr/bin/env python3 +# This program writes out: Hello world! +print("Hello world!") +\end{python} +Kör med python-interpreter: +\begin{ipython} +> python3 hello_world.py +Hello world! +\end{ipython} +Interaktivt mode +\begin{ipython} +> python3 +>>> print("Hello world!") +Hello world! +\end{ipython} +Om tillgänglig, använd med fördel ipython: {\tiny (eller ipython nootbook, jupyter)} +\begin{ipython} +> ipython3 +In [1]: print("Hello world!") +Hello world! +\end{ipython} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Enkla datatyper, tilldelning, operatorer, typomvandling} +\begin{itemize} +\item Integer, float, complex:\quad \pythoninline{x=7},\quad\pythoninline{x=2.0}, \quad \pythoninline{x=3.0 + 5.0j} +\item Simple operations: {\scriptsize +, -, *, /, \%, ** (power), +=, -=, // (heltalsdivision)} +\item Strings: {\tiny (i Python 3 är alla strängar unicode)} +\begin{python} +s3 = "the cat's hat" +s4 = 'who said "what"?' +s5 = """This is a +multiline string""" +>>> "string" + " " + "concatenation" +string concatenation +>>> "multiply "*3 +'multiply multiply multiply ' +\end{python} +\item Typomvandling: \pythoninline{int(2.7)},\quad \pythoninline{str(2.7)}, ... +\begin{python} +>>> "test" + 5 +<@\textcolor{red}{TypeError: cannot concatenate 'str' and 'int' objects}@> +>>> "test" + str(5) +"test5" +\end{python} +\item Kommentarer: \scriptsize \pythoninline{# comment}, kan använda: \pythoninline{'''multi-line comment'''} +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Duck typing} +\scriptsize +\emph{If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck.} +\begin{itemize} +\item I grunden typsvagt: det finns typer, men de behöver aldrig deklareras. +\item Programmera utan att bry sig, ''om det fungerar så fungerar det, annars kastas en exception.'' Testa aldrig för typtillhörighet i onödan. +\begin{python} +def add(x, y): + result = x + y + return result +\end{python} +\begin{python} +>>> add(5,7) +12 +>>> add("five","seven") +'fiveseven' +>>> add(5,"seven") +<@\textcolor{red}{TypeError: unsupported operand type(s) for +: 'int' and 'str'}@> +\end{python} +\item Slipper mycket overhead man har i typstarka språk; generics/templates, etc. T.ex. \emph{''Hur deklarerar jag en lista vars element är antingen strängar eller tal?''} +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Containers} +\scriptsize +\begin{itemize} +\item List:\quad \pythoninline{[1, 2, 3, 4]}, \pythoninline{[1, 'a', 3.24, 4]}, \pythoninline{[1, [2, [3, [4], 5]]} +\item Tuple (immutable):\quad \pythoninline{(1, 2, 3, 4)} +\item Indexing i list/tuple börjar på 0, negativa tal räknar ifrån slutet. \pythoninline{a[3]}, \pythoninline{a[-3]} +\item Set:\quad \pythoninline{\{1, 2, 3, 4\}} +\item Dictionary: +\begin{python} +d = {'a':1, 'b':2, 'c':3, 'd':4} +d['b'] = 12 +>>> d['a'] +1 +>>> del d['a'] +>>> d +{'b': 12, 'c': 3, 'd': 4} +\end{python} +\item Fler i standardbiblioteks-modulen \pythoninline{collections} +\item Range: +\begin{python} +>>> list(range(1, 7, 2)) # start, stop, step +[1, 3, 5] +\end{python} +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Containers} +\scriptsize +Append + qsort med Pythons standardbibliotek:\\ +\begin{python} +a = [4, 2, 6] +a.append(1) +print "Before sorting", a +a.sort() +print "After sorting", a +\end{python} +Append + qsort med C:s standardbibliotek:\\ +\begin{columns}[c] +\column{0.45\linewidth} +\begin{ccode}[ + basicstyle=\ttfamily\tiny, %or \small or \footnotesize etc. +] +#include <stdio.h> +#include <stdlib.h> +int comp(const void * a,const void * b) +{ + const int *ia = (const int *)a; + const int *ib = (const int *)b; + return *ia - *ib; +} +int main(int argc, char **argv) { + int *array, *array2; + int i; + array = (int*) malloc(3*sizeof(int)); + array[0] = 4; + array[1] = 2; + array[2] = 6; + array2 = (int*) malloc(4*sizeof(int)); + +\end{ccode} +\column{0.45\linewidth} +\begin{ccode}[ + basicstyle=\ttfamily\tiny, %or \small or \footnotesize etc. +] + for ( i=0; i < 3; i++ ) + array2[i] = array[i]; + array2[3] = 1; + free(array); + array = array2; + + printf("Before sorting\n"); + for ( i=0; i < 4; i++ ) + printf("%d ", array[i]); + printf("\n"); + qsort(array, 4, sizeof(int),comp); + printf("After sorting\n"); + for ( i=0; i < 4; i++ ) + printf("%d ", array[i]); + printf("\n"); +} +\end{ccode} +\end{columns} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Flödeskontroll och Jämförelser} +\small +\begin{itemize} +\item Booleans and logic: \pythoninlinesmall{True}, \pythoninlinesmall{False}, \pythoninlinesmall{True and False}, \pythoninlinesmall{not False}, \pythoninlinesmall{True or False} +\item Likhet: \pythoninline{[1,2] == [1,2]} +\item Olikhet: \pythoninline{1 > 2}, \pythoninline{1 >= 2} +\item Identisk: \pythoninline{a is b}, \pythoninline{a is not c} +\item None-objekt: \pythoninline{a = None}, \pythoninline{a is None}, \pythoninline{a is not None}. \\ + {\scriptsize \emph{(Notera: använd normalt \pythoninline{if a is None} istället för \pythoninline{if a == None})}} +\rule{\linewidth}{0.4pt} +\item if, elif, else +\only<+>{} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +if a == b: + print("a and b are equal") +elif a > b: + print("a larger than b") +else: + print("a is neither equal or larger than b") +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item for (else) \emph{(!)} +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: + print("step:",i) +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +for i in range(10): + print("step:",i) +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +for i in [2, 5, 7, 8, "hi"]: + if a == i: + break +else: + print("a not in list") +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item while (else) \emph{(!)} +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +while i != a: + i+=1 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item Indentering avgränsar instruktionsgrupper, tom grupp \pythoninline{pass}: +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +if i == 10: + pass +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Funktioner} +\begin{itemize} +\item definera en funktion/procedur +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def print_hello_world(): + print("hello world!") +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item return value +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def return_hello_world(): + return "hello world!" + +>>> return_hello_world() +hello world! +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item arguments +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def add(v1,v2): + return v1+v2 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item keyword arguments +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def show(a,b): + print("a:",a) + print("b:",b) + +>>> show(5,7) +a: 5 +b: 7 + +>>> show(b=5,a=7) +a: 7 +b: 5 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item default arguments \emph{{\tiny(\textbf{only} use immutable types here!)}} +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def add(v1,v2=5): + return v1+v2 + +>>> add(5,7) +12 +>>> add(5) +10 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def count_to_ten(start,step=1,reverse=False): + if not reverse: + return range(start,11,step) + else: + return range(10,start-1,-step) + +>>> count_to_ten(2) +[2, 3, 4, 5, 6, 7, 8, 9, 10] +>>> count_to_ten(2,reverse=True) +[10, 9, 8, 7, 6, 5, 4, 3, 2] +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Variable scoping: Globala och Lokala} +\begin{itemize} +\item Lokala variabler +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +x = 6 +def test(): + x = 5 + print(x) + y = 5 + +>>> test() +5 +>>> x +6 +>>> y +<@\textcolor{red}{NameError: name 'y' is not defined}@> +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item Globala variabler +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +x = 6 +def test(): + print(x) + +>>> test() +6 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item Ändra globala variabler +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +x = 6 +def test(): + print(x) + x = 7 + +>>> test() +<@\textcolor{red}{UnboundLocalError: local variable 'x' referenced before assignment}@> +\end{python} +\emph{{\scriptsize Notera alltså det något förvirrande att lägga till användningen av \pythoninline{x} som lokal variabel längre ned i funktionen påverkar betydelsen av \pythoninline{x} ovanför (!)}}\par +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +x = 6 +def test(): + global x + print(x) + x = 7 + +>>> test() +6 +>>> x +7 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Docstrings} +\scriptsize +\begin{itemize} +\item För inline-dokumentation av funktioner (och klasser, moduler), lägg bara till en trippel-kvoterad sträng i toppen. Används av \pythoninline{help(...)} och system som genererar dokumentation automatiskt (t.ex.\ Sphinx). +\item För formatering, använd reST (restructured text), se PEP 287. Olika format förekommer för att ange parameterar, etc. Det som kallas ''Googles format'' är bra. +\begin{python} +def add(v1,v2): + """ + Adds two numbers. + + Args: + v1: one number + v2: the other number + + Returns: + The sum of the two numbers. + """ + return v1+v2 +\end{python} +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{I/O} +\begin{itemize} +\item Formatering av variabler i strängar +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +# Rekommenderad: +>>> "hello {var} {num:.2f}".format(var="world",num=5.32819) +'hello world 5.33' + +# printf-style: +>>> "hello %s %.2f" % ("world",5.32819) +'hello world 5.33' + +# Sammanfoga en lista till en sträng: +>>> ','.join(["one","two","three"]) +'one,two,three' +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +\item Utskrift på skärm +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +a = 5 +b = {'a':5, 'b':32} + +>>> print("hello world!",a,b) +hello world! 5 {'b': 32, 'a': 5} + +>>> print("hello world!"+str(a)+str(b)) +hello world!5{'b': 32, 'a': 5} + +>>> print("hello world!"+a+b) +<@\textcolor{red}{TypeError: Can't convert 'int' object to str implicitly}@> +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Skriva fil +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +f = open("example.txt",'w') +f.write("Test") +f.close() +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%%\item Lägga till fil +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +f = open("example.txt",'a') +f.write("Test") +f.close() +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Läsa fil +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +f = open("example.txt",'r') +result = f.read() +f.close() + +>>> print(result) +TestTest +\end{python} +\scriptsize Alternativa sätt att få in data ur en öppen fil \pythoninline{f}: +\begin{python} +list_of_lines = f.readlines() +\end{python} +\begin{python} +for line in f: + print(line) +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Exceptions} +\begin{itemize} +\item Oväntade händelser/fel 'kastar exceptions' +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +>>> a = 10*(1/0) +<@\textcolor{red}{ZeroDivisionError: division by zero}@> + +>>> print(a) +<@\textcolor{red}{NameError: name 'a' is not defined}@> +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Exceptions kan fångas +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def test(): + try: + a = 10*(1/0) + except ZeroDivisionError: + print("oops") + +>>> test() +oops +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def test(): + try: + a = 10*(1/0) + except Exception: + print("oops") + +>>> test() +oops +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def divide(denom): + return 10*(1/denom) + +def test(denom): + try: + divide(denom) + except ZeroDivisionError: + print("oops") + except TypeError: + print("oops2") + +>>> test(0) +oops +>>> test("hi") +oops2 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Raise +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def test(): + raise Exception("Something bad happened!") + +>>> test() +<@\textcolor{red}{Exception: Something bad happened!} +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Klasser} +\scriptsize +\begin{itemize} +\item Class definition, constructor +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +class HelloClass: + def __init__(self): + print("Hello world!") + +>>> hello_obj = HelloClass() +Hello world! +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Instance variables +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +class HelloClass: + def __init__(self, name): + self.name = name + print("Hello",self.name+'!') + +>>> hello_obj = HelloClass("universe") +Hello universe! + +>>> print(hello_obj.name) +universe +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Class variables +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +class HelloClass: + greeting = "Hello" + def __init__(self, name): + self.name = name + print(self.greeting,self.name+'!') + +>>> hello_obj = HelloClass("universe") +Hello universe! +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Methods +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +class HelloClass: + def __init__(self, name): + self.name = name + + def greet(self, other): + print("Hello",self.name,"from",other) + +>>> hello_obj = HelloClass("universe") +>>> hello_obj.greet("me") +Hello universe from me +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Inheritence +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +class GreeterClass: + def __init__(self, greeting, name): + self.greeting = greeting + self.name = name + + def greet(self): + print(self.greeting,self.name+'!') + +class HelloClass(GreeterClass): + def __init__(self, name): + super().__init__("hello",name) + +>>> hello_obj = HelloClass("universe") +>>> hello_obj.greet() +Hello universe! +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item (Docstrings) +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +class HelloClass: + """ + Class for saying hello to a name. + """ + def __init__(self, name): + """ + Constructor for class that says hello. + + Args: + name(str): Name to say hello to. + """ + self.name = name + print("Hello",self.name+'!') +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Moduler} +\small +\begin{itemize} +\item Python har ett stort standardbibliotek som består av moduler som kan importeras. + {\scriptsize \emph{(Innan du implementerar något avancerat som verkar ha generisk karaktär, kolla standardbiblioteket!, eller googla åtminstone!)}\par} +\item Pythons modulsystem är 'lite annorlunda' mot vad man ofta är van vid i andra språk. Bra mental modell är att \pythoninline{import modulename} laddar in modulen i ett eget context (egen 'låda') med modulnamnet, vars innehåll man sedan når via \pythoninline{modulename.identifier}. Sedan finns en speciell 'from'-syntax för att lyfta in saker ifrån den lådan till den egna miljön. +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Moduler} +\begin{itemize} +\item Import +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +import statistics +l = [1, 5, 3, 5, 6, 4, 6, 7, 4, 2, 2] + +>>> statistics.mean(l) +4.090909090909091 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item from-type import +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +from statistics import mean +l = [1, 5, 3, 5, 6, 4, 6, 7, 4, 2, 2] + +>>> mean(l) +4.090909090909091 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Generic import \tiny\emph{(uppmuntras ej)} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +from statistics import * +l = [1, 5, 3, 5, 6, 4, 6, 7, 4, 2, 2] + +>>> mean(l) +4.090909090909091 +>>> stdev(l) +1.9211738835693897 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Egna moduler} +\begin{itemize} +\item En vanlig pythonfil 'namn.py' i samma katalog kan importeras med \pythoninline{import namn}. Detta är ett bra sätt att dela upp sitt program i flera filer.\\{\scriptsize (filer i andra kataloger kan importeras genom att sätta systemvariabeln PYTHONPATH.)\par} +\item Mer avancerade moduler och undermoduler konstrueras med kataloger och underkataloger. Varje katalog som är en modul måste innehålla en fil '\_\,\_init\_\,\_.py' +\item '\_\,\_init\_\,\_.py' definerar gränssnittet till modulen ('lådan'). Den innehåller normalt import-statements som importerar filer i modul-katalogen och på så sätt gör sitt innehåll tillgängligt i modulen. +\item Genom att i '\_\,\_init\_\,\_.py' definera \pythoninline{__all__ = ['identifier1','identifier2']} så görs endast dessa tillgängliga +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Egna moduler} +\includegraphics[width=0.8\linewidth]{pythonmodules.png} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Rekommenderad namngivning / style} +PEP 8: Style Guide for Python Code +\begin{itemize} +\item Indentera med 4 mellanslag (ej tab) +\item Identifierare består av: a-z, A-Z, 0-9, och \_, måste börja med en bokstav. +\item Variabler: lowercase, använd \_ mellan ord. +\item Funktioner: lowercase, använd \_ mellan ord. +\item Klasser: börjar med versal, skriv ord som: CamelCase. +\item Moduler: lowercase, korta namn, underscore ok. +\item Finns några förbjudna namn:\\ + {\scriptsize \emph{and, as, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield}\par} +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Lite tankar och tips} +\begin{itemize} +\item I Python fungerar små, enkla klass-hirarkier bäst. Överstrukturera inte.\\ + {\scriptsize \emph{Stora klassträd behövs normalt inte p.g.a. svag typning, och tenderar att bli förvirrande utan ledningen som ges av starka typer.}\par} +\item Duck-typing kommer till sin rätt med få klassmetoder och separata funktioner i moduler för att operera på objekten (liksom allt annat som 'kväker' som objektet!)\\ + {\scriptsize Men å andra sidan är help(obj) och dir(obj) trevliga, så man kan ha one-liners i objektet som anroppar dessa externa rutiner.\par} +\item Vid design av egna klasser, tänk noga igenom valet muteable vs. immutable.\\ + {\scriptsize (d.v.s. ska 'innehållet' i objektet kunna förändras eller ej efter skapandet?). Jämför \pythoninline{x.set_temperature(42)} vs \pythoninline{x.get_new_with_other_temperature(42)}. Inteface till muterbara objekt upplevs kanske först som enklare, men leder lätt till buggar som är svåra, som man slipper med icke-muterbara objekt.\par} +\item Undvik 'premature optimization', läsbart i första hand, optimering för hög fart \emph{bara} där det gör nytta. +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Få mer info och hjälp:} +\begin{itemize} +\item http://docs.python.org/ +\item Tutorial: http://docs.python.org/3/tutorial/ +\item Standardbiblioteket: http://docs.python.org/3/library/ +\item Direkthjälp: \pythoninline{help(...)}, \pythoninline{dir(...)} +\item Frågor och svar: http://stackoverflow.com/ \\ {\scriptsize t.ex. sök: \emph{''merge python dictionaries''} $\rightarrow$ \pythoninline{z = \{**x, **y\}} \par} +\item Kör i python: \pythoninline{import this} och begrunda. +\item Python för vetenskap, scipy-modulen: http://scipy.org/ +\item Python för snabb behandling av numerisk data: numpy (likt matlab): http://www.numpy.org/ +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Vanliga fel} +\begin{itemize} +\item Behöver inte deklarera variabler $\Rightarrow$ felstavade variabler +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +varaible = 42 +print(variable) +<@\textcolor{red}{NameError: name 'variable' is not defined}@> +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item Indenteringsfel +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +print("hello") + print("hello") + +<@\textcolor{red}{IndentationError: unexpected indent}@> +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def func1(): + +def func2(): + print("hello") + +<@\textcolor{red}{IndentationError: expected an indented block}@> +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame} + \Huge Mer avancerad Python +\end{frame} + +\begin{frame}[fragile] +\frametitle{Mer om funktioner} +\begin{itemize} +%%%%%%%%%%%%%%%%%%%% +\item arbitary arguments +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def add(v1,v2,*args): + return v1+v2+sum(args) + +>>> add(5,7,8,10,12) +42 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item arbitary keyword arguments +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def add(v1,v2,**kargs): + print(kargs) + return v1+v2 + +>>> add(5,7,with_extra_cheese=True) +{'with_extra_cheese': True} +12 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item multiple return values {\tiny \emph{(Usually better to return a dict)}} +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def multireturn(): + return 5, 7 + +x, y = multireturn() +>>> print(x,y) +5, 7 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def multireturn(): + return {'number_of_dogs':5, 'number_of_cats':7} + +vals = multireturn() +>>> print(vals['number_of_dogs'],vals['number_of_cats']) +5, 7 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\item anonymous functions (lambda expressions) +%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +f = lambda x:x*x +>>> map(f,[1,2,3,4]) +[1, 4, 9, 16] +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Mer om listor} +\scriptsize +\begin{itemize} +\item Unpacking +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +>>> a, b, c = 1, 2, 3 + +>>> a, b = b, a # swaps a and b +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%\item List comprehension +%%%%%%%%%%%%%%%%%%%%% +\item Slicing +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +s = [1, 2, 3, 4, 5, 6] +>>> s[0:5] # from 0 to 5 +[1, 2, 3, 4, 5] +>>> s[2:5] # from 2 to 5 +[3, 4, 5] +>>> s[2:-2] # from 2 to (two from the end) +[3, 4] +>>> s[:5] # from start to 5 +[1, 2, 3, 4, 5] +>>> s[3:] # from 3 to end +[4, 5, 6] +>>> s[:] # from start to end +[1, 2, 3, 4, 5, 6] +>>> s[2:5:2] # from 2 to 5, step 2 +[3, 5] +>>> s[::2] # from start to end, step 2 +[1, 3, 5] +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Slice assignment +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +a = [1, 2, 3, 4, 5] +a[2:3] = [0, 0] + +>>> a +[1, 2, 0, 0, 4, 5] +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item List comprehension +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +l = [39.2, 36.5, 37.3, 37.8] +>>> [ x**2 for x in l ] +[1536.6400000000003, 1332.25, 1391.2899999999997, 1428.8399999999997] +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +l = [39.2, 36.5, 37.3, 37.8] +>>> [ x**2 for x in l if x < 38 ] +[1332.25, 1391.2899999999997, 1428.8399999999997] +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +l = [2.3232, 4.3232, 8.23323] +>>> [int(x) for x in l if x < 5] +[2, 4] +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Iterators and generators. +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +a = range(10) +ia = iter(a) # ia is an iterator +>>> next(ia) +0 +>>> next(ia) +1 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +a = range(3) +ia = iter(a) # ia is an iterator +>>> for i in ia: + print i +0 +1 +2 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +gen = (x**2 for x in range(10)) +>>> next(gen) +0 +>>> next(gen) +1 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def my_generator(max): + i = 0 + while i < max: + yield i + i = i+1 + +>>> for i in my_generator(3): + print i +0 +1 +2 +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Mer om Exceptions} +\begin{itemize} +%%%%%%%%%%%%%%%%%%%%% +\item Try, Except, Else, Finally +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def test(denom): + try: + 10*(1/denom) + except TypeError: + print("oops") + finally: + print("Do cleanup") + print("Outside try clause") +>>> test(0) +Do cleanup +<@\textcolor{red}{ZeroDivisionError: division by zero}@> +>>> test(1) +Do cleanup +Outside try clause +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +def test(denom): + try: + 10*(1/denom) + except TypeError: + print("oops") + else: + print("After try, before cleanup") + finally: + print("Do cleanup") + print("Outside try clause") +>>> test(0) +Do cleanup +<@\textcolor{red}{ZeroDivisionError: division by zero}@> +>>> test(1) +After try, before cleanup +Do cleanup +Outside try clause +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\item Egna exceptions +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +class MyException(Exception): + pass + +def test(): + raise MyException("My own exception") + +>>> test() +<@\textcolor{red}{MyException: My own exception} +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\\[1ex]\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Andra avancerade ämnen} +\begin{itemize} +\item With statement +\item Raw strings \pythoninline{r"gurk"}, unicode +\item Decorators +\item Overrides för klasser (operatorer, str, anropp, mm.) +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Numpy} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +>>> import numpy as np +>>> b = np.array([(1.5,2,3), (4,5,6)]) +>>> b +array([[ 1.5, 2. , 3. ], + [ 4. , 5. , 6. ]]) +>>> b.shape +(2, 3) +>>> b - b +array([[ 0., 0., 0.], + [ 0., 0., 0.]]) +>>> b*(b+5) +array([[ 9.75, 14. , 24. ], + [ 36. , 50. , 66. ]]) +>>> np.sin(b) +array([[ 0.99749499, 0.90929743, 0.14112001], + [-0.7568025 , -0.95892427, -0.2794155 ]]) +>>> b[:2,:2] +array([[ 1.5, 2. ], + [ 4. , 5. ]]) +>>> np.linalg.inv(b[:2,:2]) +array([[-10., 4.], + [ 8., -3.]]) +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\end{frame} + +\begin{frame}[fragile] +\frametitle{Matplotlib} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +from pylab import * +x = [1, 2, 3, 4] +y = [i**2 for i in x] +plot(x,y) +show() +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\scriptsize (I jupyter, lägg till \pythoninline{\%matplotlib notebook} alt. \pythoninline{\%matplotlib nbagg}, \pythoninline{\%matplotlib inline} på första raden, och show() i slutet är då onödigt) +\end{frame} + +\begin{frame}[fragile] +\frametitle{Scipy} +%%%%%%%%%%%%%%%%%%%%% +\begin{lrbox}{\codeone} +\begin{minipage}{\linewidth} +\begin{python} +from pylab import * +from scipy import special, optimize + +def myfunc(x): + return special.jv(3, x) + +sol = optimize.minimize(myfunc, 6.0) +x = linspace(0, 10, 5000) +plot(x, myfunc(x), '-') +plot(sol.x, sol.fun, 'o') +print("Minimum at:",sol.x) +show() +\end{python} +\end{minipage} +\end{lrbox} +\only<+>{\usebox{\codeone}} +%%%%%%%%%%%%%%%%%%%%% +\scriptsize (I jupyter, lägg till \pythoninline{\%matplotlib notebook} alt. \pythoninline{\%matplotlib nbagg}, \pythoninline{\%matplotlib inline} på första raden, och show() i slutet är då onödigt) +\end{frame} + +\end{document} diff --git a/Lecture/logicgates2.png b/Lecture/logicgates2.png new file mode 100644 index 0000000000000000000000000000000000000000..a8376e8524c4e14f1fd0f84189bcc6b4de4556e3 Binary files /dev/null and b/Lecture/logicgates2.png differ diff --git a/Lecture/montypython.png b/Lecture/montypython.png new file mode 100644 index 0000000000000000000000000000000000000000..0ebc07e90414e0e7d42cc393e541af21817654eb Binary files /dev/null and b/Lecture/montypython.png differ diff --git a/Lecture/ookakor.pdf b/Lecture/ookakor.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f549da64b225343e542d08a0673b19fea23509f9 Binary files /dev/null and b/Lecture/ookakor.pdf differ diff --git a/Lecture/orgate.png b/Lecture/orgate.png new file mode 100644 index 0000000000000000000000000000000000000000..ce4ba4b07cc0d8470e38fc6aa605aac0019ae0f2 Binary files /dev/null and b/Lecture/orgate.png differ diff --git a/Lecture/pythonmodules.png b/Lecture/pythonmodules.png new file mode 100644 index 0000000000000000000000000000000000000000..09d881a5ccaecd3de6fb8dcb0abd90e0395ab1b9 Binary files /dev/null and b/Lecture/pythonmodules.png differ