diff options
Diffstat (limited to 'ws2015/eip/blaetter/03')
-rw-r--r-- | ws2015/eip/blaetter/03/H3-1.md | 39 | ||||
-rw-r--r-- | ws2015/eip/blaetter/03/H3-2.md | 84 | ||||
-rw-r--r-- | ws2015/eip/blaetter/03/H3-3.md | 33 | ||||
-rw-r--r-- | ws2015/eip/blaetter/03/manifest | 3 |
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 | --- | ||
2 | header-includes: | ||
3 | - \usepackage{bussproofs} | ||
4 | - \renewcommand{\implies}{\rightarrow} | ||
5 | - \EnableBpAbbreviations | ||
6 | --- | ||
7 | # Hoare-Tripel II | ||
8 | |||
9 | d) | ||
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 | |||
22 | e) Nimm als Gegenbeispiel: | ||
23 | |||
24 | ~~~ | ||
25 | a = -1 | ||
26 | b = 0 | ||
27 | ~~~ | ||
28 | |||
29 | f) 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 | --- | ||
2 | header-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 | |||
18 | Wir bezeichnen mit $P'$: | ||
19 | |||
20 | ~~~ | ||
21 | a = a + c | ||
22 | b = b + 1 | ||
23 | c = c + 6*b | ||
24 | ~~~ | ||
25 | |||
26 | Wir bezeichnen mit $J$: | ||
27 | |||
28 | ~~~ | ||
29 | a = 0 | ||
30 | b = 0 | ||
31 | c = 1 | ||
32 | ~~~ | ||
33 | |||
34 | und setzen $J'$ derart, dass $\{\} J \{J'\}$ gültig ist. | ||
35 | |||
36 | Wir bezeichnen zudem mit $\bar P$: | ||
37 | |||
38 | ~~~ | ||
39 | while (b != n) { | ||
40 | a = a + c | ||
41 | b = b + 1 | ||
42 | c = c + 6*b | ||
43 | } | ||
44 | ~~~ | ||
45 | |||
46 | Es 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 | |||
70 | Es bleibt zu zeigen, dass $a(n) = n^3$. | ||
71 | Es gilt wegen $P'$ und $J$: | ||
72 | \begin{align*} | ||
73 | c(0) &= 1 \\ | ||
74 | c(k) &= c(k - 1) + 6 \cdot k \\ | ||
75 | &= 1 + \sum_{i = 0}^{k} 6i \\ | ||
76 | a(0) &= 0 \\ | ||
77 | a(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 @@ | |||
1 | H3-1.pdf | ||
2 | H3-2.pdf | ||
3 | H3-3.pdf \ No newline at end of file | ||