summaryrefslogtreecommitdiff
path: root/ws2015
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-11-07 14:00:29 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2015-11-07 14:00:29 +0000
commit46bff23a54eef783610ecb98070de2368a8c9192 (patch)
tree76b7e669434333793d611ab6cddc9f1378f0a919 /ws2015
parent8543a09639917b2a7b6dcb6c553a9bcd9945fe77 (diff)
downloaduni-46bff23a54eef783610ecb98070de2368a8c9192.tar
uni-46bff23a54eef783610ecb98070de2368a8c9192.tar.gz
uni-46bff23a54eef783610ecb98070de2368a8c9192.tar.bz2
uni-46bff23a54eef783610ecb98070de2368a8c9192.tar.xz
uni-46bff23a54eef783610ecb98070de2368a8c9192.zip
EiP - Blatt 03
Diffstat (limited to 'ws2015')
-rw-r--r--ws2015/EiP/blaetter/03/H3-1.md39
-rw-r--r--ws2015/EiP/blaetter/03/H3-2.md84
-rw-r--r--ws2015/EiP/blaetter/03/H3-3.md33
-rw-r--r--ws2015/EiP/blaetter/03/manifest3
4 files changed, 159 insertions, 0 deletions
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 @@
1---
2header-includes:
3 - \usepackage{bussproofs}
4 - \renewcommand{\implies}{\rightarrow}
5 - \EnableBpAbbreviations
6---
7# Hoare-Tripel II
8
9d)
10
11\begin{prooftree}
12\AXC{$\forall \phi \ldotp \phi \implies \phi$}
13\UIC{$(0 < n + 1 \land n < m) \implies (0 < n + 1 \land n < m)$}
14\RightLabel{Umformung}
15\UIC{$(0 < n + 1 \land n < m) \implies (0 < n + 1 \land n \leq m - 1)$}
16\RightLabel{Umformung}
17\UIC{$(0 < n + 1 \land n < m) \implies (0 < n + 1 \land n + 1 \leq m)$}
18\RightLabel{Zuweisung}
19\UIC{$ \{ 0 < n + 1 \land n < m \} $ \texttt{n = n + 1} $ \{ 0 < n \land n \leq m \} $}
20\end{prooftree}
21
22e) Nimm als Gegenbeispiel:
23
24~~~
25a = -1
26b = 0
27~~~
28
29f) Seit $\phi$ die Nachfolgerfunktion auf $\mathbb{N}$.
30
31\begin{prooftree}
32\AXC{$\forall n \in \mathbb{N} \ldotp \phi(n) > n$}
33\UIC{$1 > 0$}
34\UIC{$((x + 1) + y > x + y)$}
35\UIC{$(z = x + y) \implies ((x + 1) + y > z)$}
36\UIC{$ \{ z = x + y \} $ \texttt{ x = x + 1} $ \{ x + y > z \} $}
37\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 \} $}
38\UIC{$ \{ z = x + y \} $ \texttt{if (z \% 2 == 0) x = x + 1; else y = y + 1;} $ \{ x + y > z \} $}
39\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 @@
1---
2header-includes:
3 - \usepackage{bussproofs}
4 - \renewcommand{\implies}{\rightarrow}
5 - \EnableBpAbbreviations
6---
7# Hoare-Logik: While-Schleife II
8
9| Schleifendurchlauf | \texttt{n} | \texttt{a} | \texttt{b} | \texttt{c} |
10|--------------------+------------+------------+------------+------------|
11| 0 | 5 | 0 | 0 | 1 |
12| 1 | 5 | 1 | 1 | 7 |
13| 2 | 5 | 8 | 2 | 19 |
14| 3 | 5 | 27 | 3 | 37 |
15| 4 | 5 | 64 | 4 | 61 |
16| 5 | 5 | 125 | 5 | 91 |
17
18Wir bezeichnen mit $P'$:
19
20~~~
21a = a + c
22b = b + 1
23c = c + 6*b
24~~~
25
26Wir bezeichnen mit $J$:
27
28~~~
29a = 0
30b = 0
31c = 1
32~~~
33
34und setzen $J'$ derart, dass $\{\} J \{J'\}$ gültig ist.
35
36Wir bezeichnen zudem mit $\bar P$:
37
38~~~
39while (b != n) {
40 a = a + c
41 b = b + 1
42 c = c + 6*b
43}
44~~~
45
46Es sei zudem $I = (c = (b + 1)^3 - b^3)$.
47
48\begin{prooftree}
49\AXC{$ 1 = (0 + 1)^3 - 0 $}
50\UIC{$ (a, b, c) = (0, 0, 1) \implies c = ( b + 1 )^3 - b^3$}
51\UIC{$J' \implies I$}
52\end{prooftree}
53
54\begin{prooftree}
55\AXC{$0 = 0$}
56\RightLabel{Algebraische Umformung}
57\UIC{$(b + 1)^3 - b^3 + 6 \cdot (b + 1) = (b + 2)^3 - (b + 1)^3$}
58\UIC{$c = ( b + 1 )^3 - b^3 \implies c + 6 \cdot (b + 1) = (b + 2)^3 - (b + 1)^3$}
59\UIC{$\{c = ( b + 1 )^3 - b^3 \land b \neq n \}$ $P'$ $\{ c = (b + 1)^3 - b^3 \}$}
60\UIC{$\{ I \land b \}$ $P'$ $ \{ I \} $}
61\end{prooftree}
62
63\begin{prooftree}
64\AXC{$J' \implies I$}
65\AXC{$\{I \land b\}$ $P'$ $\{ I \}$}
66\AXC{$I \land b = n \implies a = n^3$}
67\TIC{$ \{ n > 0 \land J' \} $ $ \bar P $ $ \{ a = n^3 \} $}
68\end{prooftree}
69
70Es bleibt zu zeigen, dass $a(n) = n^3$.
71Es gilt wegen $P'$ und $J$:
72\begin{align*}
73c(0) &= 1 \\
74c(k) &= c(k - 1) + 6 \cdot k \\
75 &= 1 + \sum_{i = 0}^{k} 6i \\
76a(0) &= 0 \\
77a(k) &= a(k - 1) + c(k - 1) \\
78 &= a(k - 1) + 1 + \sum_{i = 0}^{k - 1} 6i \\
79 &= \sum_{j = 0}^{k} \left ( 1 + \sum_{i = 0}^{j - 1} 6i \right ) \\
80 &= k + \sum_{j = 0}^{k} \sum_{i = 0}^{j - 1} 6i \\
81 &= k + \sum_{j = 0}^{k} \left ( 3j (j - 1) \right ) \\
82 &= k + \left ( k^3 - k \right ) \\
83 &= k^3
84\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 @@
1# Code Verständnis
2
3| Zeile | Zuweisung |
4|-------+-----------|
5| 010 | x = 42 |
6| 030 | y = 36 |
7| 070 | z = 1 |
8| 080 | z = 2 |
9| 090 | z = 3 |
10| 100 | y = 39 |
11| 120 | z = 6 |
12| 070 | z = 1 |
13| 080 | z = 2 |
14| 090 | z = 3 |
15| 100 | y = 42 |
16| 120 | z = 6 |
17| 230 | x = 53 |
18| 240 | z = 0 |
19| 250 | x = 57 |
20| 260 | y = 36 |
21| 270 | z = 1 |
22| 240 | z = 1 |
23| 250 | x = 61 |
24| 260 | y = 37 |
25| 270 | z = 2 |
26| 240 | z = 2 |
27| 250 | x = 65 |
28| 260 | y = 39 |
29| 270 | z = 3 |
30| 240 | z = 3 |
31| 250 | x = 69 |
32| 260 | y = 42 |
33| 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 @@
1H3-1.pdf
2H3-2.pdf
3H3-3.pdf \ No newline at end of file