From ab9484b343abd995cba915bb0ba4be8907dfa6ec Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 13 Nov 2015 23:45:26 +0000 Subject: Shorter lecture names --- ws2015/eip/blaetter/01/Basistypen.md | 14 ++++++ ws2015/eip/blaetter/01/GreatEscape.java | 11 +++++ ws2015/eip/blaetter/01/manifest | 2 + ws2015/eip/blaetter/02/Arithmetik.java | 33 +++++++++++++ ws2015/eip/blaetter/02/H2-1.md | 18 +++++++ ws2015/eip/blaetter/02/H2-2.md | 13 +++++ ws2015/eip/blaetter/02/H2-3.java | 1 + ws2015/eip/blaetter/02/manifest | 3 ++ ws2015/eip/blaetter/02/test.sh | 20 ++++++++ ws2015/eip/blaetter/03/H3-1.md | 39 +++++++++++++++ ws2015/eip/blaetter/03/H3-2.md | 84 +++++++++++++++++++++++++++++++++ ws2015/eip/blaetter/03/H3-3.md | 33 +++++++++++++ ws2015/eip/blaetter/03/manifest | 3 ++ 13 files changed, 274 insertions(+) create mode 100644 ws2015/eip/blaetter/01/Basistypen.md create mode 100644 ws2015/eip/blaetter/01/GreatEscape.java create mode 100644 ws2015/eip/blaetter/01/manifest create mode 100644 ws2015/eip/blaetter/02/Arithmetik.java create mode 100644 ws2015/eip/blaetter/02/H2-1.md create mode 100644 ws2015/eip/blaetter/02/H2-2.md create mode 120000 ws2015/eip/blaetter/02/H2-3.java create mode 100644 ws2015/eip/blaetter/02/manifest create mode 100644 ws2015/eip/blaetter/02/test.sh create mode 100644 ws2015/eip/blaetter/03/H3-1.md create mode 100644 ws2015/eip/blaetter/03/H3-2.md create mode 100644 ws2015/eip/blaetter/03/H3-3.md create mode 100644 ws2015/eip/blaetter/03/manifest (limited to 'ws2015/eip') diff --git a/ws2015/eip/blaetter/01/Basistypen.md b/ws2015/eip/blaetter/01/Basistypen.md new file mode 100644 index 0000000..0074be2 --- /dev/null +++ b/ws2015/eip/blaetter/01/Basistypen.md @@ -0,0 +1,14 @@ +# Aufgabe H1-2 -- Basistypen II + +a) + `(double)3.0` +b) + `(double)1.3333333333333333` +c) + `(double)1.6666666666666665` +d) + `(double)1.75` +e) + `(string)"7.27"` +f) + `(string)"374.2"` diff --git a/ws2015/eip/blaetter/01/GreatEscape.java b/ws2015/eip/blaetter/01/GreatEscape.java new file mode 100644 index 0000000..35fa406 --- /dev/null +++ b/ws2015/eip/blaetter/01/GreatEscape.java @@ -0,0 +1,11 @@ +public class GreatEscape +{ + public static void main (String[] args) + { + System.out.println(" \\__/ \\__/"); + System.out.println(" (\"\") (\"\")"); + System.out.println(" .-----\\/ \\/-----."); + System.out.println(" /|_____| |_____|\\"); + System.out.println("\" | \\ || || / | \""); + } +} diff --git a/ws2015/eip/blaetter/01/manifest b/ws2015/eip/blaetter/01/manifest new file mode 100644 index 0000000..775d7e2 --- /dev/null +++ b/ws2015/eip/blaetter/01/manifest @@ -0,0 +1,2 @@ +GreatEscape.java +Basistypen.pdf \ No newline at end of file diff --git a/ws2015/eip/blaetter/02/Arithmetik.java b/ws2015/eip/blaetter/02/Arithmetik.java new file mode 100644 index 0000000..90335a4 --- /dev/null +++ b/ws2015/eip/blaetter/02/Arithmetik.java @@ -0,0 +1,33 @@ +import java.util.Scanner; + +class Arithmetik +{ + public static void main (String[] args) + { + Scanner scanner = new Scanner(System.in); + + System.out.print("Vorname: "); + String vorname = scanner.nextLine(); + System.out.print("Nachname: "); + String nachname = scanner.nextLine(); + System.out.print("x_1 = "); + int x1 = scanner.nextInt(); + System.out.print("x_2 = "); + int x2 = scanner.nextInt(); + + System.out.print("Hallo " + vorname.substring(0,1) + ". " + nachname + "! "); + + if (x1 < x2) + { + System.out.println("Der Mittelwert von " + x1 + " und " + x2 + " ist übrigens " + ((x1 + x2) / 2.0) + "!"); + } + else if (x1 > 0 && x2 > 0) + { + System.out.println("Der Kehrwert von " + x1 + " ist ungefähr " + 1.0/x1 + "!"); + } + else + { + System.out.println(x1 + x2); + } + } +} diff --git a/ws2015/eip/blaetter/02/H2-1.md b/ws2015/eip/blaetter/02/H2-1.md new file mode 100644 index 0000000..e2fa908 --- /dev/null +++ b/ws2015/eip/blaetter/02/H2-1.md @@ -0,0 +1,18 @@ +# Speicherbild + +Wir notieren eine Referenz mit Variablennamen `x` auf ein Objekt, dessen Repräsentation als String `...` ist, wie folgt: + +~~~ {.java} +x -> ... +~~~ + +~~~ {.java} +Int x = 9 +Prof prof1 -> Prof[name="Chris",teaching=9] +Prof prof2 -> Prof[name="Dora",teaching=9] +Student student1 -> Student[name="Alois",matrikel=1234] +Student student2 -> Student[name="Bine",matrikel=4567] +Student student3 -> Student[name="Alois",matrikel=1234] +~~~ + +`student1` und `student3` zeigen auf unterschiedliche Speicherbereiche. diff --git a/ws2015/eip/blaetter/02/H2-2.md b/ws2015/eip/blaetter/02/H2-2.md new file mode 100644 index 0000000..430d28e --- /dev/null +++ b/ws2015/eip/blaetter/02/H2-2.md @@ -0,0 +1,13 @@ +# Variablen + +2 -- `int x` + ~ Instanzvariable -- Lebenspanne identisch mit der des Objekts, Sichtbar (und nicht überschattet) in 9, und 13 + +4 -- `int x` + ~ Parameter -- Lebenspanne bis 6, Sichtbar in 5 + +12 -- `int y` + ~ Parameter -- Lebenspanne bis 17, Sichtbar in 13--16 + +14 -- `int x` + ~ Lokale Variable -- Lebenspanne bis 17, Sichtbar in 15--16 diff --git a/ws2015/eip/blaetter/02/H2-3.java b/ws2015/eip/blaetter/02/H2-3.java new file mode 120000 index 0000000..34aea7f --- /dev/null +++ b/ws2015/eip/blaetter/02/H2-3.java @@ -0,0 +1 @@ +Arithmetik.java \ No newline at end of file diff --git a/ws2015/eip/blaetter/02/manifest b/ws2015/eip/blaetter/02/manifest new file mode 100644 index 0000000..9cec2d1 --- /dev/null +++ b/ws2015/eip/blaetter/02/manifest @@ -0,0 +1,3 @@ +H2-1.pdf +H2-2.pdf +H2-3.java \ No newline at end of file diff --git a/ws2015/eip/blaetter/02/test.sh b/ws2015/eip/blaetter/02/test.sh new file mode 100644 index 0000000..5647e13 --- /dev/null +++ b/ws2015/eip/blaetter/02/test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env zsh + +runTest() { + ret=$(echo $1 | java Arithmetik | tail -c +32) + if [[ $ret != $2 ]]; then + echo "Input:" + echo $1 + echo "Should return:" + echo $2 + echo "But returns:" + echo $ret + exit 1 + fi +} + +gup --update Arithmetik.class || exit 1 + +runTest "Christian\nElegans\n2\n7" "Hallo C. Elegans! Der Mittelwert von 2 und 7 ist übrigens 4.5!" +runTest "Gustav\nEnauer\n70\n15" "Hallo G. Enauer! Der Kehrwert von 70 ist ungefähr 0.014285714285714!" +runTest "Karla\nEhr-Wert\n7\n3" "Hallo K. Ehr-Wert! Der Kehrwert von 7 ist ungefähr 0.143!" diff --git a/ws2015/eip/blaetter/03/H3-1.md b/ws2015/eip/blaetter/03/H3-1.md new file mode 100644 index 0000000..bb3d2ca --- /dev/null +++ b/ws2015/eip/blaetter/03/H3-1.md @@ -0,0 +1,39 @@ +--- +header-includes: + - \usepackage{bussproofs} + - \renewcommand{\implies}{\rightarrow} + - \EnableBpAbbreviations +--- +# Hoare-Tripel II + +d) + +\begin{prooftree} +\AXC{$\forall \phi \ldotp \phi \implies \phi$} +\UIC{$(0 < n + 1 \land n < m) \implies (0 < n + 1 \land n < m)$} +\RightLabel{Umformung} +\UIC{$(0 < n + 1 \land n < m) \implies (0 < n + 1 \land n \leq m - 1)$} +\RightLabel{Umformung} +\UIC{$(0 < n + 1 \land n < m) \implies (0 < n + 1 \land n + 1 \leq m)$} +\RightLabel{Zuweisung} +\UIC{$ \{ 0 < n + 1 \land n < m \} $ \texttt{n = n + 1} $ \{ 0 < n \land n \leq m \} $} +\end{prooftree} + +e) Nimm als Gegenbeispiel: + +~~~ +a = -1 +b = 0 +~~~ + +f) Seit $\phi$ die Nachfolgerfunktion auf $\mathbb{N}$. + +\begin{prooftree} +\AXC{$\forall n \in \mathbb{N} \ldotp \phi(n) > n$} +\UIC{$1 > 0$} +\UIC{$((x + 1) + y > x + y)$} +\UIC{$(z = x + y) \implies ((x + 1) + y > z)$} +\UIC{$ \{ z = x + y \} $ \texttt{ x = x + 1} $ \{ x + y > z \} $} +\UIC{$ \{ z = x + y \land z \equiv 0 \mod 2 \} $ \texttt{x = x + 1} $ \{ x + y > z \} $ \quad $ \{ z = x + y \land z \equiv 1 \mod 2 \} $ \texttt{x = x + 1} $ \{ x + y > z \} $} +\UIC{$ \{ z = x + y \} $ \texttt{if (z \% 2 == 0) x = x + 1; else y = y + 1;} $ \{ x + y > z \} $} +\end{prooftree} diff --git a/ws2015/eip/blaetter/03/H3-2.md b/ws2015/eip/blaetter/03/H3-2.md new file mode 100644 index 0000000..62d8fc2 --- /dev/null +++ b/ws2015/eip/blaetter/03/H3-2.md @@ -0,0 +1,84 @@ +--- +header-includes: + - \usepackage{bussproofs} + - \renewcommand{\implies}{\rightarrow} + - \EnableBpAbbreviations +--- +# Hoare-Logik: While-Schleife II + +| Schleifendurchlauf | \texttt{n} | \texttt{a} | \texttt{b} | \texttt{c} | +|--------------------+------------+------------+------------+------------| +| 0 | 5 | 0 | 0 | 1 | +| 1 | 5 | 1 | 1 | 7 | +| 2 | 5 | 8 | 2 | 19 | +| 3 | 5 | 27 | 3 | 37 | +| 4 | 5 | 64 | 4 | 61 | +| 5 | 5 | 125 | 5 | 91 | + +Wir bezeichnen mit $P'$: + +~~~ +a = a + c +b = b + 1 +c = c + 6*b +~~~ + +Wir bezeichnen mit $J$: + +~~~ +a = 0 +b = 0 +c = 1 +~~~ + +und setzen $J'$ derart, dass $\{\} J \{J'\}$ gültig ist. + +Wir bezeichnen zudem mit $\bar P$: + +~~~ +while (b != n) { + a = a + c + b = b + 1 + c = c + 6*b +} +~~~ + +Es sei zudem $I = (c = (b + 1)^3 - b^3)$. + +\begin{prooftree} +\AXC{$ 1 = (0 + 1)^3 - 0 $} +\UIC{$ (a, b, c) = (0, 0, 1) \implies c = ( b + 1 )^3 - b^3$} +\UIC{$J' \implies I$} +\end{prooftree} + +\begin{prooftree} +\AXC{$0 = 0$} +\RightLabel{Algebraische Umformung} +\UIC{$(b + 1)^3 - b^3 + 6 \cdot (b + 1) = (b + 2)^3 - (b + 1)^3$} +\UIC{$c = ( b + 1 )^3 - b^3 \implies c + 6 \cdot (b + 1) = (b + 2)^3 - (b + 1)^3$} +\UIC{$\{c = ( b + 1 )^3 - b^3 \land b \neq n \}$ $P'$ $\{ c = (b + 1)^3 - b^3 \}$} +\UIC{$\{ I \land b \}$ $P'$ $ \{ I \} $} +\end{prooftree} + +\begin{prooftree} +\AXC{$J' \implies I$} +\AXC{$\{I \land b\}$ $P'$ $\{ I \}$} +\AXC{$I \land b = n \implies a = n^3$} +\TIC{$ \{ n > 0 \land J' \} $ $ \bar P $ $ \{ a = n^3 \} $} +\end{prooftree} + +Es bleibt zu zeigen, dass $a(n) = n^3$. +Es gilt wegen $P'$ und $J$: +\begin{align*} +c(0) &= 1 \\ +c(k) &= c(k - 1) + 6 \cdot k \\ + &= 1 + \sum_{i = 0}^{k} 6i \\ +a(0) &= 0 \\ +a(k) &= a(k - 1) + c(k - 1) \\ + &= a(k - 1) + 1 + \sum_{i = 0}^{k - 1} 6i \\ + &= \sum_{j = 0}^{k} \left ( 1 + \sum_{i = 0}^{j - 1} 6i \right ) \\ + &= k + \sum_{j = 0}^{k} \sum_{i = 0}^{j - 1} 6i \\ + &= k + \sum_{j = 0}^{k} \left ( 3j (j - 1) \right ) \\ + &= k + \left ( k^3 - k \right ) \\ + &= k^3 +\end{align*} diff --git a/ws2015/eip/blaetter/03/H3-3.md b/ws2015/eip/blaetter/03/H3-3.md new file mode 100644 index 0000000..ca9fbd8 --- /dev/null +++ b/ws2015/eip/blaetter/03/H3-3.md @@ -0,0 +1,33 @@ +# Code Verständnis + +| Zeile | Zuweisung | +|-------+-----------| +| 010 | x = 42 | +| 030 | y = 36 | +| 070 | z = 1 | +| 080 | z = 2 | +| 090 | z = 3 | +| 100 | y = 39 | +| 120 | z = 6 | +| 070 | z = 1 | +| 080 | z = 2 | +| 090 | z = 3 | +| 100 | y = 42 | +| 120 | z = 6 | +| 230 | x = 53 | +| 240 | z = 0 | +| 250 | x = 57 | +| 260 | y = 36 | +| 270 | z = 1 | +| 240 | z = 1 | +| 250 | x = 61 | +| 260 | y = 37 | +| 270 | z = 2 | +| 240 | z = 2 | +| 250 | x = 65 | +| 260 | y = 39 | +| 270 | z = 3 | +| 240 | z = 3 | +| 250 | x = 69 | +| 260 | y = 42 | +| 270 | z = 4 | diff --git a/ws2015/eip/blaetter/03/manifest b/ws2015/eip/blaetter/03/manifest new file mode 100644 index 0000000..ff79ea4 --- /dev/null +++ b/ws2015/eip/blaetter/03/manifest @@ -0,0 +1,3 @@ +H3-1.pdf +H3-2.pdf +H3-3.pdf \ No newline at end of file -- cgit v1.2.3