Browse Source

fixed minted label issue

Martin Thoma 11 years ago
parent
commit
3e4c3f876f

+ 0 - 73
documents/Programmierparadigmen/Lambda.tex

@@ -300,79 +300,6 @@ Insbesondere ist also $f \ g$ ein Fixpunkt von $g$.
     $\qed$
 \end{beweis}
 
-\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.
-Auch solche Ausdrücke sollen typisierbar sein.
-
-Die Kodierung 
-\[\text{let} x = t_1 \text{ in } t_2\]
-ist bedeutungsgleich mit
-\[(\lambda x.\ t_2) t_1\]
-
-Das Problem ist, dass 
-\[P = \lambda f. \ f (f\ \text{\texttt{true}})\ (\lambda x.\ 2)\]
-so nicht typisierbar ist, da in
-\[\ABS \frac{f: \tau_f \vdash f\ (f\ \text{\texttt{true}}): \dots}{\vdash \lambda f.\ f\ (f\ \text{\texttt{true}}): \dots}\]
-müsste 
-\[\tau_f = \text{bool} \rightarrow \text{int}\]
-und zugleich
-\[\tau_f = \text{int} \rightarrow \text{int}\]
-in den Typkontext eingetragen werden. Dies ist jedoch nicht möglich. Stattdessen
-wird 
-\[\text{let} x = t_1 \text{ in } t_2\]
-als neues Konstrukt im $\lambda$-Kalkül erlaubt.
-
-\begin{definition}[Typschema]\xindex{Typschema}%
-    Ein Typ der Gestalt $\forall \alpha_1.\ \forall \alpha_2.\ \dots\ \forall \alpha_n. \tau$
-    heißt \textbf{Typschema}. Es bindet freie Variablen $\alpha_1, \dots, \alpha_n$
-    in $\tau$.
-\end{definition}
-
-\begin{beispiel}[Typschema]
-    Das Typschema $\forall \alpha.\ \alpha \rightarrow \alpha$ steht für unendlich
-    viele Typen und insbesondere für folgende:
-    \begin{bspenum}
-        \item int $\rightarrow$ int, bool $\rightarrow$ bool, \dots
-        \item (int $\rightarrow$ int) $\rightarrow$ (int $\rightarrow$ int), \dots
-        \item \dots
-    \end{bspenum}
-\end{beispiel}
-
-\begin{definition}[Typschemainstanziierung]\xindex{Typschemainstanziierung}%
-    Sei $\tau_2$ ein Nicht-Schema-Typ. Dann heißt der Typ
-    \[\tau[\alpha \mapsto \tau_2]\]
-    eine \textbf{Instanziierung} vom Typschema $\forall \alpha.\ \tau$
-    und man schreibt:
-    \[(\forall \alpha.\ \tau) \succeq \tau [\alpha \mapsto \tau_2]\]
-\end{definition}
-
-\begin{beispiel}[Typschemainstanziierung]
-    Folgendes sind Beispiele für Typschemainstanziierungen:
-    \begin{bspenum}
-        \item $\forall \alpha.\ \alpha \rightarrow \alpha \succeq \text{int} \rightarrow \text{int}$
-        \item $\forall \alpha.\ \alpha \rightarrow \alpha \succeq (\text{int} \rightarrow \text{int}) \rightarrow (\text{int} \rightarrow \text{int})$
-        \item $\text{int} \succeq \text{int}$
-    \end{bspenum}
-
-    Folgendes sind keine Typschemainstanziierungen:
-    \begin{bspenum}
-        \item $\alpha \rightarrow \alpha \nsucceq \text{int} \rightarrow \text{int}$
-        \item $\alpha \nsucceq \text{bool}$
-        \item $\forall \alpha.\ \alpha \rightarrow \alpha \nsucceq \text{bool}$
-    \end{bspenum}
-\end{beispiel}
-
-Zu Typschemata gibt es angepasste Regeln:
-
-\[\VAR \frac{\Gamma(x)= \tau' \;\;\; \tau' \succeq \tau}{\gamma \vdash x: \tau}\]
-
-und
-
-\[\ABS \frac{\Gamma, x: \tau_1 \vdash t: \tau_2 \;\;\; \tau_1 \text{ kein Typschema}}{\Gamma \vdash  \lambda x. t: \tau_1 \rightarrow \tau_2}\]
-
-\todo[inline]{Folie 208ff}
-
 \section{Literatur}
 
 \begin{itemize}

BIN
documents/Programmierparadigmen/Programmierparadigmen.pdf


+ 15 - 0
documents/Programmierparadigmen/Programmierparadigmen.tex

@@ -97,6 +97,21 @@
   pdfkeywords = {Programmierparadigmen}, 
   pdftitle    = {Programmierparadigmen} 
 }
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% The patch for minted: http://tex.stackexchange.com/a/168021/5645
+\makeatletter
+\def\FV@BeginListFrame@Lines{%
+  \begingroup
+  \lineskip\z@skip
+  \FV@SingleFrameLine{\z@}%
+  \kern-0.5\baselineskip\relax
+  \baselineskip\z@skip
+  \kern\FV@FrameSep\relax
+  \penalty\@M% added line
+\endgroup}
+\makeatother
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 
 \makeindex
 \allowdisplaybreaks

+ 76 - 2
documents/Programmierparadigmen/Typinferenz.tex

@@ -66,7 +66,8 @@ Mit folgenderweise typisiert werden:
 
 In der letzten Typisierung stellt $\alpha$ einen beliebigen Typen dar.
 
-\begin{definition}[Typsystem $\Gamma \vdash t: T$]\label{def:typsystem-t1}
+\section{Typsystem}
+\begin{definition}[Typsystem $\Gamma \vdash t: T$\footnotemark]\label{def:typsystem-t1}\xindex{Typregel}\xindex{Typsystem}%
 	Ein Typkontext $\Gamma$ ordnet jeder freien Variable $x$ einen Typ $\Gamma(x)$
 	durch folgende Regeln zu:
 
@@ -80,7 +81,7 @@ In der letzten Typisierung stellt $\alpha$ einen beliebigen Typen dar.
 		\APP:  &\frac{\Gamma \vdash t_1, \tau_2 \tau\;\;\; \Gamma \vdash t_2: \tau_2}{\Gamma \vdash t_1 t_2: \tau}
 	\end{align*}
 \end{definition}
-
+\footnotetext{WS 2013 / 2014, Folie 192}
 
 
 Dabei ist der lange Strich kein Bruchstrich, sondern ein Symbol der Logik das als
@@ -109,6 +110,79 @@ 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{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.
+Auch solche Ausdrücke sollen typisierbar sein.
+
+Die Kodierung 
+\[\text{let} x = t_1 \text{ in } t_2\]
+ist bedeutungsgleich mit
+\[(\lambda x.\ t_2) t_1\]
+
+Das Problem ist, dass 
+\[P = \lambda f. \ f (f\ \text{\texttt{true}})\ (\lambda x.\ 2)\]
+so nicht typisierbar ist, da in
+\[\ABS \frac{f: \tau_f \vdash f\ (f\ \text{\texttt{true}}): \dots}{\vdash \lambda f.\ f\ (f\ \text{\texttt{true}}): \dots}\]
+müsste 
+\[\tau_f = \text{bool} \rightarrow \text{int}\]
+und zugleich
+\[\tau_f = \text{int} \rightarrow \text{int}\]
+in den Typkontext eingetragen werden. Dies ist jedoch nicht möglich. Stattdessen
+wird 
+\[\text{let} x = t_1 \text{ in } t_2\]
+als neues Konstrukt im $\lambda$-Kalkül erlaubt.
+
+\begin{definition}[Typschema]\xindex{Typschema}%
+    Ein Typ der Gestalt $\forall \alpha_1.\ \forall \alpha_2.\ \dots\ \forall \alpha_n. \tau$
+    heißt \textbf{Typschema}. Es bindet freie Variablen $\alpha_1, \dots, \alpha_n$
+    in $\tau$.
+\end{definition}
+
+\begin{beispiel}[Typschema]
+    Das Typschema $\forall \alpha.\ \alpha \rightarrow \alpha$ steht für unendlich
+    viele Typen und insbesondere für folgende:
+    \begin{bspenum}
+        \item int $\rightarrow$ int, bool $\rightarrow$ bool, \dots
+        \item (int $\rightarrow$ int) $\rightarrow$ (int $\rightarrow$ int), \dots
+        \item \dots
+    \end{bspenum}
+\end{beispiel}
+
+\begin{definition}[Typschemainstanziierung]\xindex{Typschemainstanziierung}%
+    Sei $\tau_2$ ein Nicht-Schema-Typ. Dann heißt der Typ
+    \[\tau[\alpha \mapsto \tau_2]\]
+    eine \textbf{Instanziierung} vom Typschema $\forall \alpha.\ \tau$
+    und man schreibt:
+    \[(\forall \alpha.\ \tau) \succeq \tau [\alpha \mapsto \tau_2]\]
+\end{definition}
+
+\begin{beispiel}[Typschemainstanziierung]
+    Folgendes sind Beispiele für Typschemainstanziierungen:
+    \begin{bspenum}
+        \item $\forall \alpha.\ \alpha \rightarrow \alpha \succeq \text{int} \rightarrow \text{int}$
+        \item $\forall \alpha.\ \alpha \rightarrow \alpha \succeq (\text{int} \rightarrow \text{int}) \rightarrow (\text{int} \rightarrow \text{int})$
+        \item $\text{int} \succeq \text{int}$
+    \end{bspenum}
+
+    Folgendes sind keine Typschemainstanziierungen:
+    \begin{bspenum}
+        \item $\alpha \rightarrow \alpha \nsucceq \text{int} \rightarrow \text{int}$
+        \item $\alpha \nsucceq \text{bool}$
+        \item $\forall \alpha.\ \alpha \rightarrow \alpha \nsucceq \text{bool}$
+    \end{bspenum}
+\end{beispiel}
+
+Zu Typschemata gibt es angepasste Regeln:\xindex{Typregel!mit Typabstraktionen}%
+
+\[\VAR \frac{\Gamma(x)= \tau' \;\;\; \tau' \succeq \tau}{\gamma \vdash x: \tau}\]
+
+und
+
+\[\ABS \frac{\Gamma, x: \tau_1 \vdash t: \tau_2 \;\;\; \tau_1 \text{ kein Typschema}}{\Gamma \vdash  \lambda x. t: \tau_1 \rightarrow \tau_2}\]
+
+\todo[inline]{Folie 208ff}
+
 \section{Beispiele}
 Im Folgenden wird die Typinferenz für einige $\lambda$-Funktionen durchgeführt.
 

+ 85 - 0
documents/Programmierparadigmen/scripts/x10/Mergesort.x10

@@ -0,0 +1,85 @@
+import x10.io.Console;
+import x10.util.Random;
+
+public class Mergesort {
+  private static val rand = new Random();
+  private static val MIN_ELEMENTS_PARALLEL = 65536;
+
+  public static def sort(values : Array[Int](1)) : Array[Int](1) {
+    val numbers = new Array[Int](values.size);
+    val helper = new Array[Int](values.size);
+    Array.copy(values, numbers);
+
+    mergesort(0, values.size - 1, numbers, helper);
+
+    return numbers;
+  }
+
+  private static def mergesort(low : Int, high : Int, numbers : Array[Int](1), helper : Array[Int](1)) {
+    if (low < high) {
+      val middle = (low + high) / 2;
+      if (high - low >= MIN_ELEMENTS_PARALLEL) {
+        finish {
+          async mergesort(low, middle, numbers, helper);
+          async mergesort(middle + 1, high, numbers, helper);
+        }
+      } else {
+        mergesort(low, middle, numbers, helper);
+        mergesort(middle + 1, high, numbers, helper);
+      }
+      merge(low, middle, high, numbers, helper);
+    }
+  }
+
+  private static def merge(low : Int, middle : Int, high : Int, numbers : Array[Int](1), helper : Array[Int](1)) {
+    // Copy the part to be merged into the helper (from low to high)
+    Array.copy(numbers, low, helper, low, high - low + 1);
+
+    var left : Int = low;
+    var right : Int = middle + 1;
+    var position : Int = low;
+
+    while(left <= middle && right <= high) {
+      if (helper(left) <= helper(right)) {
+      numbers(position++) = helper(left++);
+      } else {
+      numbers(position++) = helper(right++);
+      }
+    }
+
+    while(left <= middle) {
+      numbers(position++) = helper(left++);
+    }
+    // Nothing needs to be done for the right half, because is still
+    // is where it was copied from, which happens to be the right
+    // location.
+  }
+
+  public static def main(args:Array[String](1)) {
+    if (args.size < 1) {
+      Console.OUT.println("Expect array length as argument");
+      return;
+    }
+
+    val sort_count = Int.parse(args(0));
+    val to_sort:Array[Int] = new Array[Int](sort_count, (_:Int) => { return rand.nextInt(); });
+
+    for (i in to_sort) {
+      Console.OUT.print(to_sort(i) + " ");
+    }
+    Console.OUT.println();
+
+    val start = System.nanoTime();
+    val sorted = sort(to_sort);
+    val duration = System.nanoTime() - start;
+
+    Console.OUT.println("Sorting took " + duration / 1000000.0 + "ms");
+
+    Console.OUT.println("Checking for sortedness...");
+
+    for (i in sorted) {
+       Console.OUT.print(sorted(i) + " ");
+    }
+    Console.OUT.println();
+  }
+}

+ 68 - 0
documents/Programmierparadigmen/scripts/x10/output.txt

@@ -0,0 +1,68 @@
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:8: Could not find type "Array(x10.lang.Long)".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:9: Could not find type "Array".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:9: Field size not found in type "Array[x10.lang.Int]{self==values}".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:10: Could not find type "Array".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:10: Field size not found in type "Array[x10.lang.Int]{self==values}".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:11: Could not find Array
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:11: No valid method call found for call in given type.    
+     	 Call: copy(Array[x10.lang.Int], Array[x10.lang.Int])    
+     	 Type: Array
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:13: Field size not found in type "Array[x10.lang.Int]{self==values}".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:18: Could not find type "Array(x10.lang.Long)".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:15: Cannot return expression; base type incompatible with method return type.    
+     	 Expression: numbers    
+     	 Base type: Array[x10.lang.Int]    
+     	 Expected base type: Array[x10.lang.Int]
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:23: No valid method call found for call in given type.    
+     	 Call: mergesort(x10.lang.Int, x10.lang.Long, Array[x10.lang.Int], Array[x10.lang.Int])    
+     	 Type: Mergesort
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:24: No valid method call found for call in given type.    
+     	 Call: mergesort(x10.lang.Long, x10.lang.Int, Array[x10.lang.Int], Array[x10.lang.Int])    
+     	 Type: Mergesort
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:27: No valid method call found for call in given type.    
+     	 Call: mergesort(x10.lang.Int, x10.lang.Long, Array[x10.lang.Int], Array[x10.lang.Int])    
+     	 Type: Mergesort
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:28: No valid method call found for call in given type.    
+     	 Call: mergesort(x10.lang.Long, x10.lang.Int, Array[x10.lang.Int], Array[x10.lang.Int])    
+     	 Type: Mergesort
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:34: Could not find type "Array(x10.lang.Long)".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:30: No valid method call found for call in given type.    
+     	 Call: merge(x10.lang.Int, x10.lang.Long, x10.lang.Int, Array[x10.lang.Int], Array[x10.lang.Int])    
+     	 Type: Mergesort
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:36: Could not find Array
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:36: No valid method call found for call in given type.    
+     	 Call: copy(Array[x10.lang.Int], x10.lang.Int, Array[x10.lang.Int], x10.lang.Int, x10.lang.Long)    
+     	 Type: Array
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:39: Cannot assign expression to target; base types are incompatible.    
+     	 Expression: x10.lang.Long.implicit_operator_as(middle) + 1L    
+     	 Expected base type: x10.lang.Int    
+     	 Found base type: x10.lang.Long
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:43: Method or static constructor not found for given call.    
+     	 Call: helper(x10.lang.Int)
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:44: Method or static constructor not found for given call.    
+     	 Call: helper(x10.lang.Int)
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:46: Method or static constructor not found for given call.    
+     	 Call: helper(x10.lang.Int)
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:51: Method or static constructor not found for given call.    
+     	 Call: helper(x10.lang.Int)
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:58: Could not find type "Array(x10.lang.Long)".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:59: Field size not found in type "Array[x10.lang.String]{self==args}".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:64: Method or static constructor not found for given call.    
+     	 Call: args(x10.lang.Long{self==0L})
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:65: Could not find type "Array".
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:65: No valid constructor found for Array[x10.lang.Int](x10.lang.Int{self==sort_count}, (_:x10.lang.Int)=> x10.lang.Int).
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:65: Cannot assign expression to target; base types are incompatible.    
+     	 Expression: new Array[x10.lang.Int](...)    
+     	 Expected base type: Array[x10.lang.Int]    
+     	 Found base type: Array[x10.lang.Int]
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:67: Could not infer type for formal parameter.    
+     	 Formal parameter name: i
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:67-69: The loop iterator is a Point whose rank is not the same as the rank of the loop domain.
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:73: No valid method call found for call in given type.    
+     	 Call: sort(Array[x10.lang.Int])    
+     	 Type: Mergesort
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:80: Could not infer type for formal parameter.    
+     	 Formal parameter name: i
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:81: Possible closure call on uninitialized variable sorted.
+/home/moose/Downloads/LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Mergesort.x10:80-82: The loop iterator is a Point whose rank is not the same as the rank of the loop domain.
+35 errors.