2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

Misc; E-Mail von Moritz

This commit is contained in:
Martin Thoma 2014-04-05 18:18:47 +02:00
parent 9c0864f122
commit 0508de3f6a
14 changed files with 122 additions and 16 deletions

View file

@ -111,7 +111,13 @@ Die Call-By-Name Auswertung wird in Funktionen verwendet.
Haskell verwendet die Call-By-Name Auswertungsreihenfolge zusammen mit \enquote{sharing}. Dies nennt man \textit{Lazy Evaluation}. Ein spezialfall der Lazy-Evaluation ist die sog. \textit{Kurzschlussauswertung}.\xindex{Kurzschlussauswertung}\xindex{Short-circuit evaluation}
Das bezeichnet die Lazy-Evaluation von booleschen Ausdrücken.
\todo[inline]{Was ist sharing?}
\todo[inline]{Was ist sharing? Vermutlich so etwas wie in folgendem Beispiel:}
\begin{beispiel}[Sharing]
In dem Ausdruck \texttt{(plus, (fac, 42), (fac, 42))} muss der Teilausdruck
\texttt{(fac, 42)} nicht zwei mal ausgewertet werden, wenn er Seiteneffektfrei
ist.
\end{beispiel}
\begin{definition}[Call-By-Value]\xindex{Call-By-Value}%
In der Call-By-Value Auswertung wird der linkeste Redex reduziert, der

View file

@ -189,10 +189,10 @@ Sammelt Daten, die in einer Prozeßgruppe verteilt sind, ein.
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-reduce-example.c}
\section{Beispiele}
\subsection{sum-reduce Implementierung}
\subsection{sum-reduce Implementierung}\xindex{MPI\_Reduce@\texttt{MPI\_Reduce}}%
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-sum-reduce.c}
\subsection[broadcast Implementierung]{broadcast Implementierung\footnote{Klausur WS 2012 / 2013}}
\subsection[broadcast Implementierung]{broadcast Implementierung\footnote{Klausur WS 2012 / 2013}}\xindex{MPI\_Bcast@\texttt{MPI\_Bcast}}%
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-mybroadcast.c}
\section{Weitere Informationen}

View file

@ -75,7 +75,8 @@ MISD ist nicht so richtig sinnvoll.
\begin{definition}[Nick's Class]\index{NC|see{Nick's Class}}\xindex{Nick's Class}%
Nick's Class (in Zeichen: $\mathcal{NC}$) ist die Klasse aller Probleme,
die im PRAM-Modell in logarithmischer Laufzeit lösbar sind.
die im PRAM-Modell in logarithmischer Laufzeit lösbar sind, wobei die
Anzahl der Prozessoren polynomiell in der Eingabegröße beschränkt ist.
\end{definition}
\begin{beispiel}[Nick's Class]%

View file

@ -40,7 +40,7 @@
\end{beispiel}
Ein Problem von rekursiven Funktionen in Computerprogrammen ist der
Speicherbedarf. Für jeden rekursiven Aufruf müssen alle Umgebungsvariablen
Speicherbedarf. Für jeden rekursiven Aufruf müssen alle lokalen Variablen
der aufrufenden Funktion (\enquote{stack frame}) gespeichert bleiben,
bis der rekursive Aufruf beendet ist. Im Fall der Fibonacci-Funktion
sieht ist der Call-Stack in \cref{fig:fib-callstack} abgebildet.

View file

@ -1,3 +1,4 @@
%!TEX root = Programmierparadigmen.tex
\chapter{Prolog}
\index{Prolog|(}
@ -111,6 +112,44 @@ Weitere nützliche Standard-Listenprädikate sind:\xindex{sort(+List, -Sorted)@\
\underline{Hinweis}: \texttt{sort} entfernt Duplikate, \texttt{msort} hingegen nicht.
Eine Liste kann mit \texttt{rev/2}\xindex{rev/2@\texttt{rev/2}} umgedreht werden:
\inputminted[numbersep=5pt, tabsize=4]{prolog}{scripts/prolog/reverse-list.pl}
\subsection{Bäume}
Bäume können in Prolog wie folgt erstellt werden:
\inputminted[numbersep=5pt, tabsize=4]{prolog}{scripts/prolog/binary-tree-example.pl}
\begin{figure}[htp]
\centering
\input{figures/binary-tree.tex}
\caption{Binärbaum \texttt{T2}}
\label{fig:binary-tree-t2}
\end{figure}
Dabei ist
\begin{itemize}
\item \texttt{T0} der einzelne Knoten \texttt{a},
\item \texttt{T1} der Baum, der \texttt{a} als Wurzel und \texttt{b} und
\texttt{c} als Kinder hat,
\item \texttt{T2} ist in \cref{fig:binary-tree-t2} dargestellt und
\item \texttt{T3} ist der leere Baum.
\end{itemize}
Die folgenden Prädikate stammen von \url{https://sites.google.com/site/prologsite/prolog-problems/4}:
\subsection{Binärbaum-Check}
Das folgende Prädikate \texttt{istree/1} überprüft, ob es sich bei dem Parameter
um einen Binärbaum handelt:
\inputminted[numbersep=5pt, tabsize=4]{prolog}{scripts/prolog/istree.pl}
\subsection{Balancierte Binärbaumkonstruktion}
Das folgende Prädikate \texttt{cbal\_tree(n, T)} erstellt einen balancierten
Binärbaum mit \texttt{n} Knoten in \texttt{T}:
\inputminted[numbersep=5pt, tabsize=4]{prolog}{scripts/prolog/balancedtreeconstruction.pl}
\section{Beispiele}
\subsection{Humans}
Erstelle folgende Datei:

View file

@ -41,11 +41,11 @@ $\psi \vdash \varphi$ & Syntaktische Herleitbarkeit\newline Die Formel $\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Weiteres}
\settowidth\mylengtha{$a \Parr b$}
\settowidth\mylengtha{$\tau \succeq \tau'$}
\setlength\mylengthb{\dimexpr\columnwidth-\mylengtha-2\tabcolsep\relax}
\begin{xtabular}{@{} p{\mylengtha} P{\mylengthb} @{}}
$\bot$ & Bottom\\
$a \Parr b$ & $a$ wird zu $b$ unifiziert\\
$\succeq$& Typschemainstanziierung\\
$\tau \succeq \tau'$& $\tau$ wird durch $\tau'$ instanziiert\\\
\end{xtabular}

View file

@ -67,7 +67,7 @@ Mit folgenderweise typisiert werden:
In der letzten Typisierung stellt $\alpha$ einen beliebigen Typen dar.
\section{Typsystem}
\begin{definition}[Typsystem $\Gamma \vdash t: T$\footnotemark]\label{def:typsystem-t1}\xindex{Typregel}\xindex{Typsystem}%
\begin{definition}[Typsystem $\Gamma \vdash t: T$\footnotemark]\label{def:typsystem-t1}\xindex{Typregel}\xindex{Typsystem}\xindex{APP@$\APP$}\xindex{ABS@$\ABS$}\xindex{VAR@$\VAR$}\xindex{CONST@$\CONST$}%
Ein Typkontext $\Gamma$ ordnet jeder freien Variable $x$ einen Typ $\Gamma(x)$
durch folgende Regeln zu:
@ -78,7 +78,7 @@ In der letzten Typisierung stellt $\alpha$ einen beliebigen Typen dar.
&\\
\ABS: &\frac{\Gamma, x: \tau_1 \vdash t: \tau_2}{\Gamma \vdash \lambda x. t: \tau_1 \rightarrow \tau_2}\\
&\\
\APP: &\frac{\Gamma \vdash t_1, \tau_2 \tau\;\;\; \Gamma \vdash t_2: \tau_2}{\Gamma \vdash t_1 t_2: \tau}
\APP: &\frac{\Gamma \vdash t_1: \tau_2 \rightarrow \tau\;\;\; \Gamma \vdash t_2: \tau_2}{\Gamma \vdash t_1 t_2: \tau} \\
\end{align*}
\end{definition}
\footnotetext{WS 2013 / 2014, Folie 192}
@ -110,6 +110,19 @@ verwendet. Man schreibt also beispielsweise:
\[\frac{\Gamma \vdash b: \text{\texttt{bool}}\;\;\; \Gamma \vdash x: \tau \;\;\; \Gamma \vdash y: \tau }{\Gamma \vdash \text{\textbf{if} b \textbf{then} x \textbf{else} y} : \tau}\]
\end{beispiel}
\section{Constraint-Mengen}
Die Konstraint-Mengen ergeben sich direkt aus den Typisierungsregeln:
\begin{align*}
\CONST:&\text{z.~B.} \CONST \frac{2 \in \text{Const}}{\Gamma \vdash 2 : \alpha_5} \text{ ergibt } \alpha_5 = \text{\texttt{int}}\\
&\\
\VAR: &\\
&\\
\ABS: &\frac{\alpha_2 \vdash \alpha_3}{\alpha_1} \text{ ergibt } \alpha_1 = \alpha_2 \rightarrow \alpha_3\\
&\\
\APP: &\frac{\vdash \alpha_2 \;\;\; \vdash \alpha_3}{\alpha_1} \text{ ergibt } \alpha_2 = \alpha_3 \rightarrow \alpha_1\\
\end{align*}
\section{Let-Polymorphismus}\xindex{let-Polymorphismus}\footnote{WS 2013 / 2014, Folie 205ff}%
Das Programm $P = \text{let } f = \lambda x.\ 2 \text{ in } f\ (f\ \text{\texttt{true}})$
ist eine polymorphe Hilfsfunktion, da sie beliebige Werte auf 2 Abbildet.

View file

@ -0,0 +1,16 @@
\tikzstyle{vertex}=[draw,fill=black!15,circle,minimum size=20pt,inner sep=0pt]
\begin{tikzpicture}[very thick,level/.style={sibling distance=60mm/#1}]
\node [vertex] (r){$a$}
child {
node [vertex] (a) {$b$}
child {
node [vertex] {$c$}
}
child {
node [vertex] {$d$}
}
}
child {
node [vertex] {$e$}
};
\end{tikzpicture}

View file

@ -1,18 +1,24 @@
void my_bcast(void* data, int count, MPI_Datatype type,
void my_bcast(void* data, int count,
MPI_Datatype type,
int root, MPI_Comm comm) {
int my_rank;
int my_rank, comm_size;
MPI_Comm_rank(comm, &my_rank);
int comm_size;
MPI_Comm_size(comm, &comm_size);
if (my_rank == root) {
// If we are the root process, send our data to every one
// If we are the root process, send our
// data to every one
for (int i = 0; i < comm_size; i++) {
if (i != my_rank) {
MPI_Send(data, count, type, i, 0, comm);
MPI_Send(data, count,
type, i, 0, comm);
}
}
} else {
// If we are a receiver process, receive the data from root
MPI_Recv(data, count, type, root, 0, comm, MPI_STATUS_IGNORE);
// If we are a receiver process,
// receive the data from root
MPI_Recv(data, count, type, root, 0,
comm, MPI_STATUS_IGNORE);
}
}

View file

@ -0,0 +1,10 @@
cbal_tree(0,nil) :- !.
cbal_tree(N,t(x,L,R)) :- N > 0,
N0 is N - 1,
N1 is N0//2, N2 is N0 - N1,
distrib(N1,N2,NL,NR),
cbal_tree(NL,L), cbal_tree(NR,R).
distrib(N,N,N,N) :- !.
distrib(N1,N2,N1,N2).
distrib(N1,N2,N2,N1).

View file

@ -0,0 +1,8 @@
T0 = t(a, nil, nil).
T1 = t(a, t(b, nil), t(c, nil)).
T2 = t(a, t(b, t(c, nil, nil),
t(d, nil, nil)
),
t(e, nil, nil)
).
T3 = nil

View file

@ -0,0 +1,2 @@
istree(nil).
istree(t(_,L,R)) :- istree(L), istree(R).

View file

@ -0,0 +1,5 @@
rev([], []).
rev([X|Xs], Ys) :- rev(Xs, Zs), append(Zs, [X], Ys).
?- rev([1,2,3,4,5], L).
L = [5, 4, 3, 2, 1].