Commit 18cbb10f authored by Marius Frinken's avatar Marius Frinken

marius first and second tutorial material

parent f4e8d4ec
%% tywin.
%% joanna.
%% jamie.
%% tyrion.
%% cersei.
%% robert.
%% joffrey.
%% myrcella.
%% tommen.
father_of(tywin,jamie).
father_of(tywin,tyrion).
father_of(tywin,cersei).
father_of(robert,joffrey).
father_of(robert,myrcella).
father_of(robert,tommen).
mother_of(joanna,jamie).
mother_of(joanna,cersei).
mother_of(joanna,tyrion).
mother_of(cersei,joffrey).
mother_of(cersei,myrcella).
mother_of(cersei,tommen).
father(Person):-
father_of(Person,_).
lannister(tywin).
lannister(Person):-
father_of(Father,Person),
lannister(Father).
baratheon(robert).
baratheon(Person):-
father_of(Father,Person),
baratheon(Father).
sibling_of(Sibling1, Sibling2):-
father_of(Father, Sibling1),
father_of(Father, Sibling2),
mother_of(Mother, Sibling1),
mother_of(Mother, Sibling2),
Sibling1 \= Sibling2,
Sibling1 @> Sibling2.
% list e.g. [1,2,3] or [jamie,cersei], empty list = []
% pattern matching with lists:
% [Head|Tail], where Head is an element and Tail is a List!
%
%TODO:
% append(List,List2,Result).
append([],List2,List2).
append([Head|Tail],List2,[Head|Result]):-
append(Tail,List2,Result).
% numbers and if clauses in Prolog, the Paranthesis are important!
dead_person(joanna).
dead_person(motherOfjohn).
%count_dead_persons(List,NumberOfPersonsInListThatAreDead)
count_dead_persons([],0).
count_dead_persons([Head|Tail],Number):-
count_dead_persons(Tail,OldNumber),
(
dead_person(Head) ->
Number is OldNumber + 1;
Number = OldNumber
).
%%usage of testcases: simply typing in <name>(). and it should be true
%%testcases only show that one example works, you should create more of them for yourself!
%%So there is no guarantee that these testcases ensure that your implementation is correct!
%%==========Problem 1.1===============
%TODO: implement removeDuplicates(List,ListWithoutDuplicates)
delete([],_,[]).
delete([X],X,[]).
delete([Head|Tail],Head,Result):-
delete(Tail,Head,Result).
delete([Head|Tail],X,[Head|Result]):-
Head \= X,
delete(Tail,X,Result).
removeDuplicates([],[]).
removeDuplicates([Head|Tail],[Head|Tail2]):-
delete(Tail,Head,Result),
removeDuplicates(Result,Tail2).
%testcase
testcase_remove():-
removeDuplicates([1,1,1,1,2,2,3,4,1,2,7],[1, 2, 3, 4, 7]).
%--------------------------------------------------------------------
%TODO: implement myReverse(List,ReversedList)
append([],List2,List2).
append([Head|Tail],List2,[Head|Result]):-
append(Tail,List2,Result).
myReverse([],[]).
myReverse([Head|Tail],ReversedList):-
myReverse(Tail,TempList),
append(TempList,[Head],ReversedList).
%testcase
testcase_reverse():-
myReverse([1,2,3,4,5],[5,4,3,2,1]).
%--------------------------------------------------------------------
%TODO: implement myPermutations(List,OnePossiblePermutationOfList)
%note: by re-evaluating the function (using the space bar or ";"), one gets all possible permutations
buildRandom(List,Element,[Element|List]).
buildRandom([Head|Tail],Element,[Head|ResultList]):-
buildRandom(Tail,Element,ResultList).
myPermutations([],[]).
myPermutations([Head|Tail],Result):-
myPermutations(Tail,TempList),
buildRandom(TempList,Head,Result).
%testcase:
testcase_permut(X):-
myPermutations([1,2,3,4],X).
%confirm yourself that your implementation outputs all 16 permutations and produces no doubles
%--------------------------------------------------------------------
%TODO: implement zip(ListA,ListB,ZippedList)
% the length difference of ListA and ListB is at most 1
% ZippedList is a list of Lists with length 2 (the last element may have length 1)
zip([X],[],[[X]]).
zip([],[X],[[X]]).
zip([A],[B],[[A,B]]).
zip([Head1|Tail1],[Head2|Tail2],Result):-
zip(Tail1,Tail2,TempList),
append([[Head1,Head2]],TempList,Result).
%testcase
testcase_zip():-
zip([1,2],[3,4,5],[[1,3],[2,4],[5]]).
%%==========Problem 1.2===============
%Please see the exercise sheet for detailed instructions about what these functions do
tree(nil).
tree(_,L,R):-
tree(L),
tree(R).
%TODO implement construct(List,Tree)
construct(List,Tree):-
insert(List,nil,Tree).
insert([],Tree,Tree).
insert([Head|Tail],TempTree,Tree):-
insert_help(Head,TempTree,NewTempTree),
insert(Tail,NewTempTree,Tree).
insert_help(X, nil, tree(X,nil,nil)).
insert_help(X,tree(Y,L,R), tree(Y,L,NewTree)):-
X>Y,
insert_help(X,R,NewTree).
insert_help(X,tree(Y,L,R), tree(Y,NewTree,R)):-
X<Y,
insert_help(X,L,NewTree).
%testcase
testcase_construct():-
construct([5,2,4,1,3],tree(5,tree(2,tree(1,nil,nil),tree(4,tree(3,nil,nil),nil)),nil)).
%--------------------------------------------------------------------
%TODO: implement count_leaves(Tree,NumberOfLeaves)
count_leaves(nil,0).
count_leaves(tree(_,nil,nil),1):-!.
count_leaves(tree(_,L,R),Result):-
count_leaves(L,Temp1),
count_leaves(R,Temp2),
Result is Temp1 + Temp2.
%testcase
testcase_count():-
count_leaves(tree(3,tree(1,nil,tree(2,nil,nil)),nil),1).
%TODO: Use it to test how cost efficient your previous function is (in terms of the
% structure that you obtain). What can you observe for larger lists of numbers?
% Answer these questions as a comment or hand in a separate file
%--------------------------------------------------------------------
%TODO: implement symmetric(Tree) that is true, if the Tree is symmetric
%symmetric(tree(_,nil,nil)).
symmetric(tree(_,L,R)):-
mirrored(L,R).
mirrored(nil,nil).
mirrored(tree(_,L1,R1), tree(_,L2,R2)):-
mirrored(L1,R2),
mirrored(R1,L2).
%testcase
testcase_symm():-
construct([5,2,3,7,6,8,1],X),
symmetric(X).
%=========================================
%% total test
test(X):-
testcase_remove(),
testcase_reverse(),
testcase_zip(),
testcase_construct(),
testcase_count(),
testcase_symm(),
writeln("everything correct up to myPermutations,"),
writeln("now all permutations of [1,2,3,4]:"),
testcase_permut(X).
removeDuplicates([1,1,1,1,2,2,3,4,1,2,7,500,42,7,500],X).
myReverse([1,42,3,4,1,12],X).
myPermutations([1,2,3],X).
zip([1,2,3],[4,5,6],X).
construct([5,2,4,1,3],tree(5,tree(2,tree(1,nil,nil),tree(4,tree(3,nil,nil),nil)),nil)).
count_leaves(tree(5, tree(2, tree(1, nil, nil), tree(4, tree(3, nil, nil), nil)), nil),X).
symmetric(tree(5, tree(2, tree(1, nil, nil), tree(3, nil, nil)), tree(7, tree(6, nil, nil), tree(8, nil, nil)))).
\documentclass[
hyperref={colorlinks,citecolor=DeepPink4,linkcolor=blue,urlcolor=red}
]{beamer}
\mode<presentation>
{
\usetheme{default} % or try Darmstadt, Madrid, Warsaw, ...
\usecolortheme{default} % or try albatross, beaver, crane, ...
\usefonttheme{default} % or try serif, structurebold, ...
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{caption}[numbered]
}
\usepackage[german,english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{xcolor}
\newcommand{\secc}[1]{\section{#1}\begin{frame}\begin{center}\huge\usebeamercolor[fg]{title}\textbf{\underline{~#1~}}\end{center}\end{frame}}
\newcommand{\seccL}[1]{\section{#1}\begin{frame}\begin{center}\LARGE\usebeamercolor[fg]{title}\textbf{\underline{~#1~}}\end{center}\end{frame}}
\title[AI1.1]{Künstliche Intelligenz -- Übung 1}
\author{Marius Frinken}
\institute{Friedrich Alexander Universität Erlangen--Nürnberg}
\date{31.10.2018}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\tableofcontents
\end{frame}
% \section{Organizational}
% \secpage{Organizational}
\secc{Organizational}
\begin{frame}\frametitle{Personal information}
my email address:
\href{mailto:marius.frinken@fau.de}{marius.frinken@fau.de}
GPG encrypted mails are preferred!
my GPG fingerprint:
\color{red}\texttt{F4BD 7ED4 96A5 9BA6 9FD6 901C 1EEC 9B1B 8CD5 3DA1}
\end{frame}
\begin{frame}\frametitle{The forum}
\url{https://fsi.cs.fau.de/forum/144-Kuenstliche-Intelligenz}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{forum1.png}
\label{fig:forum1}
\end{figure}
\end{frame}
\begin{frame}\frametitle{My tip: Subscribe!}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{forum2.png}
\label{fig:forum2}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{How to hand in your homework I}
\textbf{Deadline:} the exact moment when Friday becomes Saturday, so Friday at 24:00 or Saturday at 00:00.\\
I would recommend to just look at time left in studon, but sometimes...
\pause
\begin{figure}[htbp]
\centering
\includegraphics[width=0.95\textwidth]{studon.png}
\label{fig:studon}
\end{figure}
(studon does not like daylight savings time)
\end{frame}
\begin{frame}[c]\frametitle{How to hand in your homework II}
\textbf{File formats:}
\begin{itemize}
\item Prolog Code: \texttt{*.pl}
\item Text: \texttt{*.pdf} or \texttt{*.txt}
\end{itemize}
For \texttt{*.pdf} we would recommend to use \LaTeX
Not sure about this \LaTeX{} or never heard about it?\tabularnewline
My tip: try \url{https://overleaf.com/}
\end{frame}
\begin{frame}\frametitle{Overleaf}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{ov.png}
\label{fig:ov}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{How to hand in your homework III}
\textbf{Problems?}
Anything specific: write an email!
General questions: forum
\end{frame}
\begin{frame}[c]\frametitle{General organizational stuff}
This tutorial takes place \textbf{57.75 hours} before the deadline!
$\Rightarrow$ please look at and try to solve the homework beforehand
\vspace{1em}
I would like to make this tutorial as interactive as possible.
\vspace{1em}
Bonus Points: up to 10\%, scaling \textbf{should} be linear, but don't pin me down on this.
\end{frame}
%=================================
\secc{Homework 0}
\begin{frame}[c]\frametitle{Homework 0}
\centering
nothing here ;)
\end{frame}
%==================================
\secc{Homework 1}
\begin{frame}[c]\frametitle{Recap: Prolog}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{p1.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{Recap: Prolog II}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{p2.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{Recap: Prolog III}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{p3.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{Prolog live demonstration}
Prolog can be used with \texttt{swipl}, available at \url{http://www.swi-prolog.org/}
Another method is to use a \texttt{swish} notebook online at \url{https://swish.swi-prolog.org/}, but I do not know whether these can be made private.
\vspace{1em}
Some more Prolog syntax stuff you should know:
\begin{itemize}
\item \texttt{trace.} enables step by step mode, good for debugging but can be to overwhelming at first
\item \texttt{halt.} or \textbf{ctrl} + \textbf{D}: exit the program
\item \texttt{\_}: use for singleton variables (variables you do not want to use, but are needed for the structure)
\item \texttt{;} or \textbf{Space bar}: backtrack, when backtracking is possible
\item \texttt{.} or \textbf{Enter}: stop backtrack, when backtracking is possible
\item so much more !
\end{itemize}
\end{frame}
\begin{frame}[c]\frametitle{some more Prolog stuff}
\begin{itemize}
\item you can make backtracking impossible after with the \texttt{!} operator
\item more information is in the documentation: \url{http://www.swi-prolog.org/pldoc/index.html}
\end{itemize}
\end{frame}
\seccL{Misc: Questions, Anecdotes \& etc}
\begin{frame}[c]\frametitle{}
Where are these slides and Prolog examples available?
\url{https://wwwcip.cs.fau.de/~ad96exij/}, hopefully soon at studon
\vspace{2em}
\centering
Questions?
\end{frame}
\end{document}
\ No newline at end of file
\documentclass[
hyperref={colorlinks,citecolor=DeepPink4,linkcolor=blue,urlcolor=red}
]{beamer}
\mode<presentation>
{
\usetheme{default} % or try Darmstadt, Madrid, Warsaw, ...
\usecolortheme{default} % or try albatross, beaver, crane, ...
\usefonttheme{default} % or try serif, structurebold, ...
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{caption}[numbered]
}
\usepackage[german,english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{xcolor}
\newcommand{\secc}[1]{\section{#1}\begin{frame}\begin{center}\huge\usebeamercolor[fg]{title}\textbf{\underline{~#1~}}\end{center}\end{frame}}
\newcommand{\seccL}[1]{\section{#1}\begin{frame}\begin{center}\LARGE\usebeamercolor[fg]{title}\textbf{\underline{~#1~}}\end{center}\end{frame}}
\title[AI1.1]{Künstliche Intelligenz -- Übung 2}
\author{Marius Frinken}
\institute{Friedrich Alexander Universität Erlangen--Nürnberg}
\date{07.11.2018}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\tableofcontents
\end{frame}
% \section{Organizational}
% \secpage{Organizational}
\secc{Organizational}
\begin{frame}\frametitle{Personal information}
my email address:
\href{mailto:marius.frinken@fau.de}{marius.frinken@fau.de}
GPG encrypted mails are preferred!
my GPG fingerprint:
\color{red}\texttt{F4BD 7ED4 96A5 9BA6 9FD6 901C 1EEC 9B1B 8CD5 3DA1}
\end{frame}
\begin{frame}\frametitle{The forum}
\url{https://fsi.cs.fau.de/forum/144-Kuenstliche-Intelligenz}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{forum1.png}
\label{fig:forum1}
\end{figure}
\end{frame}
\begin{frame}\frametitle{My tip: Subscribe!}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{forum2.png}
\label{fig:forum2}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{Handing in your homework}
\begin{block}{cited from Dennis:}
``Please upload your solutions [...] in one \textbf{and only one} of the four tutorials, and please stick with that tutorial for the rest of the semester, as to not cause confusion when we compute your full bonus points at the end of the semester ;)
If you \textbf{need} to switch, please let us know so we can keep track of your points properly.''
\end{block}
\end{frame}
%=================================
\secc{Homework 1}
\begin{frame}[c]\frametitle{Homework 1}
\centering
have a look at the solution
(the official solution should be available soon at \url{https://kwarc.info/teaching/AI/})
\end{frame}
%==================================
\secc{Homework 2}
\begin{frame}[c]\frametitle{Recap Agents}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{a.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{Recap PEAS}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{peas.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{Recap PEAS Environment}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{env.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{}
look at Problem 2.1 and 2.2
\end{frame}
\begin{frame}[c]\frametitle{Remark to Problem 2.2}
Don't forget about the last part:
\vspace{1em}
``Choose suitable designs for the agents.''
\vspace{1em}
one of the following:
\begin{enumerate}
\item simple reflex agents
\item reflex agents with state
\item goal-based agents
\item utility-based agents
\end{enumerate}
\end{frame}
\begin{frame}[c]\frametitle{Recap Big $ \mathcal{O}$}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{o.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{Some more Big $ \mathcal{O}$}
*look at some other slides*
\vspace{1em}
Some rules for calculating with Big $ \mathcal{O}$:
\vspace{1em}
Given $f(n) \in \mathcal{O}(r(n))$ and $g(n) \in \mathcal{O}(s(n))$ and $c > 0$ constant.
\begin{enumerate}
\item $[f(n) + g(n)] \in \mathcal{O}(r(n)+s(n)) = \mathcal{O}(max\{r(n),s(n)\})$
\item $[f(n) \cdot g(n)] \in \mathcal{O}(r(n)\cdot s(n))$
\item $c \cdot f(n)\in \mathcal{O}(r(n))$
\item $f(n) \pm c \in \mathcal{O}(r(n)) $
\end{enumerate}
\end{frame}
\begin{frame}[c]\frametitle{Why Big $ \mathcal{O}$ ?}
Because the runtime is important!
\vspace{1em}
Especially between $ \mathcal{O}(n^k)$ and $ \mathcal{O}(k^n)$, there is a huge difference!
\end{frame}
\begin{frame}[c]\frametitle{A relevant comic I}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{s1.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{A relevant comic II}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{s2.png}
\end{figure}
\end{frame}
\begin{frame}[c]\frametitle{A relevant comic III}
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{s3.png}
\end{figure}
\scriptsize Source: \url{https://www.smbc-comics.com/comics/1540906340-20181030\%20(1).png}
\end{frame}
\seccL{Misc: Questions, Anecdotes \& etc}
\begin{frame}[c]\frametitle{Bonus Challenge}
see \url{https://www.csee.umbc.edu/~finin/prolog/sibling/siblings.html}
\end{frame}
\begin{frame}[c]\frametitle{}
Where are these slides and Prolog examples available?
\url{https://wwwcip.cs.fau.de/~ad96exij/}, hopefully soon at studon
\vspace{2em}
\centering
Questions?
\end{frame}