-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise 1.2
More file actions
173 lines (163 loc) · 5.91 KB
/
Exercise 1.2
File metadata and controls
173 lines (163 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
Calculation:
(3 + x) · (5 - x)
=⟨ “Distributivity of · over -” ⟩
(3 + x) · 5 - (3 + x) · x
=⟨ “Distributivity of · over +” ⟩
(3 · 5 + x · 5) - (3 · x + x · x )
=⟨ “Subtraction” ⟩
(3 · 5 + x · 5) + - (3 · x + x · x )
=⟨ “Distributivity of unary minus over +” ⟩
(3 · 5 + x · 5) + ((- (3 · x)) + (- (x · x)))
=⟨ “Associativity of +” ⟩
(3 · 5 + (x · 5 + (- (3 · x)))) + (- (x · x))
=⟨ “Subtraction” ⟩
(3 · 5 + (x · 5 - 3 · x)) - x · x
=⟨ “Symmetry of ·” ⟩
(3 · 5 + (5 · x - 3 · x)) - x · x
=⟨ “Distributivity of · over -” ⟩
(3 · 5 + (5 - 3) · x) - x · x
=⟨ Fact `3 · 5 = 15` ⟩
(15 + (5 - 3) · x) - x · x
=⟨ Fact `5 - 3 = 2` ⟩
(15 + 2 · x) - x · x
Calculation:
(3 · x - 2) · (5 · y + z)[x, y, z ≔ 2, 3, x]
=⟨ Substitution ⟩
(3 · x - 2) · (5 · 3 + x)
=⟨ Fact `5 · 3 = 15` ⟩
((3 · x) - 2) · (15 + x)
=⟨ “Distributivity of · over -” ⟩
((3 · x)· (15 + x)) - (2 · (15 + x))
=⟨ “Distributivity of · over +” ⟩
((3 · x) · 15 + (3 · x) · x) - (2 · 15 + 2 · x)
=⟨ “Associativity of ·” ⟩
(3 · (x · 15) + 3 · (x · x)) - (2 · 15 + 2 · x)
=⟨ “Symmetry of ·” ⟩
(3 · (15 · x) + 3 · (x · x)) - (2 · 15 + 2 · x)
=⟨ “Associativity of ·” ⟩
((3 · 15) · x + 3 · (x · x)) - (2 · 15 + 2 · x)
=⟨ Fact `3 · 15 = 45` ⟩
(45 · x + 3 · (x · x)) - (2 · 15 + 2 · x)
=⟨ Fact `2 · 15 = 30` ⟩
(45 · x + 3 · (x · x)) - (30 + 2 · x)
=⟨ “Symmetry of +” ⟩
(3 · (x · x) + 45 · x) - (2 · x + 30)
=⟨ “Mutual associativity of + and -” ⟩
3 · (x · x) + (45 · x - (2 · x + 30))
=⟨ “Subtraction of addition” ⟩
3 · (x · x) + ((45 · x - 2 · x) - 30)
=⟨ “Distributivity of · over -” ⟩
3 · (x · x) + ((45 - 2)· x - 30)
=⟨ Fact `45 - 2 = 43` ⟩
3 · (x · x) + (43 · x - 30)
Calculation:
((5 · x + 3) - 5 · x)[x ≔ 56 · y + 27 · (z + 19)]
=⟨ “Symmetry of +” ⟩
((3 + 5 · x) - 5 · x)[x ≔ 56 · y + 27 · (z + 19)]
=⟨ “Mutual associativity of + and -” ⟩
(3 + (5 · x - 5 · x))[x ≔ 56 · y + 27 · (z + 19)]
=⟨ “Distributivity of · over -” ⟩
(3 + (5 - 5) · x)[x ≔ 56 · y + 27 · (z + 19)]
=⟨ Fact `5 - 5 = 0` ⟩
(3 + 0 · x)[x ≔ 56 · y + 27 · (z + 19)]
=⟨ “Symmetry of ·” ⟩
(3 + x · 0)[x ≔ 56 · y + 27 · (z + 19)]
=⟨ “Zero of ·” ⟩
(3 + 0)[x ≔ 56 · y + 27 · (z + 19)]
=⟨ “Identity of +” ⟩
(3)[x ≔ 56 · y + 27 · (z + 19)]
=⟨ Substitution ⟩
3
Theorem “Contradiction”: ¬ p ∧ p ≡ false
Proof:
¬ p ∧ p
=⟨ “Double negation” ⟩
¬ p ∧ ¬ ¬ p
=⟨ “De Morgan” ⟩
¬ (p ∨ ¬ p)
=⟨ “Excluded middle” ⟩
¬ (true)
=⟨ “Definition of `false`” ⟩
false
Theorem “Excluded middle”: ¬ p ∨ p ≡ true
Proof:
¬ p ∨ p
=⟨ “Double negation” ⟩
¬ p ∨ ¬ ¬ p
=⟨ “De Morgan” ⟩
¬ (p ∧ ¬ p)
=⟨ “Contradiction” ⟩
¬ false
=⟨ “Negation of `false`” ⟩
true
Theorem (3.44b) “Absorption”: p ∨ (¬ p ∧ q) ≡ p ∨ q
Proof:
p ∨ (¬ p ∧ q)
=⟨ “Distributivity of ∨ over ∧” ⟩
(p ∨ ¬ p) ∧ (p ∨ q)
=⟨ “Excluded middle” ⟩
true ∧ (p ∨ q)
=⟨ “Identity of ∧” ⟩
p ∨ q
Theorem (3.44c) “Absorption”: ¬ p ∧ (p ∨ q) ≡ ¬ p ∧ q
Proof:
¬ p ∧ (p ∨ q)
=⟨ “Distributivity of ∧ over ∨” ⟩
(¬ p ∧ p) ∨ (¬ p ∧ q)
=⟨ “Contradiction” ⟩
false ∨ (¬ p ∧ q)
=⟨ “Identity of ∨” ⟩
¬ p ∧ q
Theorem (3.43a) “Absorption”: p ∧ (p ∨ q) ≡ p
Proof:
p ∧ (p ∨ q)
=⟨ “Distributivity of ∧ over ∨” ⟩
(p ∧ p) ∨ (p ∧ q)
=⟨ “Idempotency of ∧” ⟩
p ∨ (p ∧ q)
=⟨ “Identity of ∧” ⟩
(p ∧ true) ∨ (p ∧ q)
=⟨ “Distributivity of ∧ over ∨” ⟩
p ∧ (true ∨ q)
=⟨ “Zero of ∨” ⟩
p ∧ true
=⟨ “Identity of ∧” ⟩
p
Lemma “Loop body invariant 1”:
(s = x · x ∧ d = 2 · x + 1)
⇒⁅ s := s + d ⨾ d := d + 2 ⨾ x := x + 1 ⁆
(s = x · x ∧ d = 2 · x + 1)
Proof:
(s = x · x ∧ d = 2 · x + 1)
≡⟨ “Cancellation of +” ⟩
(s + d = (x · x) + d ∧ d = 2 · x + 1)
≡⟨ Substitution ⟩
(s = (x · x) + d ∧ d = 2 · x + 1)[s ≔ s + d]
⇒⁅ s := s + d ⁆ ⟨ “Assignment” ⟩
(s = (x · x) + d ∧ d = 2 · x + 1)
≡⟨ “Replacement in equality with addition” ⟩
(s = (x · x) + 2 · x + 1 ∧ d = 2 · x + 1)
≡⟨ “Cancellation of +” ⟩
(s = (x · x) + 2 · x + 1 ∧ d + 2 = 2 · x + 1 + 2)
≡⟨ Substitution ⟩
(s = (x · x) + 2 · x + 1 ∧ d = 2 · x + 1 + 2)[d ≔ d + 2]
⇒⁅ d := d + 2 ⁆ ⟨ “Assignment” ⟩
(s = (x · x) + 2 · x + 1 ∧ d = 2 · x + 1 + 2)
≡⟨ “Symmetry of +” ⟩
(s = (x · x) + 2 · x + 1 ∧ d = 2 · x + 2 + 1)
≡⟨ Fact `2 = 1 + 1` ⟩
(s = (x · x) + (1 + 1) · x + 1 ∧ d = 2 · x + 2 + 1)
≡⟨ “Distributivity of · over +” ⟩
(s = (x · x) + 1 · x + 1 · x + 1 ∧ d = 2 · x + 2 + 1)
≡⟨ “Symmetry of ·” ⟩
(s = (x · x) + x · 1 + 1 · x + 1 ∧ d = 2 · x + 2 + 1)
≡⟨ “Identity of ·” ⟩
(s = (x · x) + x · 1 + 1 · x + 1 · 1 ∧ d = 2 · x + 2 · 1 + 1)
≡⟨ “Distributivity of · over +” ⟩
(s = x · (x + 1) + 1 · (x + 1) ∧ d = 2 · x + 2 · 1 + 1)
≡⟨ “Distributivity of · over +” ⟩
(s = (x + 1) · (x + 1) ∧ d = 2 · (x + 1) + 1)
≡⟨ Substitution ⟩
(s = x · x ∧ d = 2 · x + 1)[x ≔ x + 1]
⇒⁅ x := x + 1 ⁆ ⟨ “Assignment” ⟩
(s = x · x ∧ d = 2 · x + 1)