431
|
1 module logic where
|
|
2
|
|
3 open import Level
|
|
4 open import Relation.Nullary
|
|
5 open import Relation.Binary hiding (_⇔_ )
|
|
6 open import Data.Empty
|
|
7
|
1175
|
8 data Bool : Set where
|
|
9 true : Bool
|
|
10 false : Bool
|
431
|
11
|
|
12 data Two : Set where
|
|
13 i0 : Two
|
|
14 i1 : Two
|
|
15
|
|
16 record _∧_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where
|
|
17 constructor ⟪_,_⟫
|
|
18 field
|
|
19 proj1 : A
|
|
20 proj2 : B
|
|
21
|
|
22 data _∨_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where
|
|
23 case1 : A → A ∨ B
|
|
24 case2 : B → A ∨ B
|
|
25
|
|
26 _⇔_ : {n m : Level } → ( A : Set n ) ( B : Set m ) → Set (n ⊔ m)
|
|
27 _⇔_ A B = ( A → B ) ∧ ( B → A )
|
|
28
|
1175
|
29 ∧-exch : {n m : Level} {A : Set n} { B : Set m } → A ∧ B → B ∧ A
|
|
30 ∧-exch p = ⟪ _∧_.proj2 p , _∧_.proj1 p ⟫
|
|
31
|
|
32 ∨-exch : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → B ∨ A
|
|
33 ∨-exch (case1 x) = case2 x
|
|
34 ∨-exch (case2 x) = case1 x
|
|
35
|
431
|
36 contra-position : {n m : Level } {A : Set n} {B : Set m} → (A → B) → ¬ B → ¬ A
|
|
37 contra-position {n} {m} {A} {B} f ¬b a = ¬b ( f a )
|
|
38
|
|
39 double-neg : {n : Level } {A : Set n} → A → ¬ ¬ A
|
|
40 double-neg A notnot = notnot A
|
|
41
|
|
42 double-neg2 : {n : Level } {A : Set n} → ¬ ¬ ¬ A → ¬ A
|
|
43 double-neg2 notnot A = notnot ( double-neg A )
|
|
44
|
|
45 de-morgan : {n : Level } {A B : Set n} → A ∧ B → ¬ ( (¬ A ) ∨ (¬ B ) )
|
|
46 de-morgan {n} {A} {B} and (case1 ¬A) = ⊥-elim ( ¬A ( _∧_.proj1 and ))
|
|
47 de-morgan {n} {A} {B} and (case2 ¬B) = ⊥-elim ( ¬B ( _∧_.proj2 and ))
|
|
48
|
1175
|
49 de-morgan∨ : {n : Level } {A B : Set n} → A ∨ B → ¬ ( (¬ A ) ∧ (¬ B ) )
|
|
50 de-morgan∨ {n} {A} {B} (case1 a) and = ⊥-elim ( _∧_.proj1 and a )
|
|
51 de-morgan∨ {n} {A} {B} (case2 b) and = ⊥-elim ( _∧_.proj2 and b )
|
|
52
|
431
|
53 dont-or : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ A → B
|
|
54 dont-or {A} {B} (case1 a) ¬A = ⊥-elim ( ¬A a )
|
|
55 dont-or {A} {B} (case2 b) ¬A = b
|
|
56
|
|
57 dont-orb : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ B → A
|
|
58 dont-orb {A} {B} (case2 b) ¬B = ⊥-elim ( ¬B b )
|
|
59 dont-orb {A} {B} (case1 a) ¬B = a
|
|
60
|
1175
|
61 infixr 130 _∧_
|
|
62 infixr 140 _∨_
|
|
63 infixr 150 _⇔_
|
|
64
|
|
65 _/\_ : Bool → Bool → Bool
|
|
66 true /\ true = true
|
|
67 _ /\ _ = false
|
|
68
|
|
69 _\/_ : Bool → Bool → Bool
|
|
70 false \/ false = false
|
|
71 _ \/ _ = true
|
|
72
|
|
73 not : Bool → Bool
|
|
74 not true = false
|
|
75 not false = true
|
|
76
|
|
77 _<=>_ : Bool → Bool → Bool
|
|
78 true <=> true = true
|
|
79 false <=> false = true
|
|
80 _ <=> _ = false
|
|
81
|
|
82 open import Relation.Binary.PropositionalEquality
|
|
83
|
|
84 not-not-bool : { b : Bool } → not (not b) ≡ b
|
|
85 not-not-bool {true} = refl
|
|
86 not-not-bool {false} = refl
|
|
87
|
|
88 record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
|
|
89 field
|
|
90 fun← : S → R
|
|
91 fun→ : R → S
|
|
92 fiso← : (x : R) → fun← ( fun→ x ) ≡ x
|
|
93 fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
|
|
94
|
|
95 injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
|
|
96 injection R S f = (x y : R) → f x ≡ f y → x ≡ y
|
|
97
|
|
98
|
|
99 ¬t=f : (t : Bool ) → ¬ ( not t ≡ t)
|
|
100 ¬t=f true ()
|
|
101 ¬t=f false ()
|
|
102
|
|
103 infixr 130 _\/_
|
|
104 infixr 140 _/\_
|
|
105
|
|
106 ≡-Bool-func : {A B : Bool } → ( A ≡ true → B ≡ true ) → ( B ≡ true → A ≡ true ) → A ≡ B
|
|
107 ≡-Bool-func {true} {true} a→b b→a = refl
|
|
108 ≡-Bool-func {false} {true} a→b b→a with b→a refl
|
|
109 ... | ()
|
|
110 ≡-Bool-func {true} {false} a→b b→a with a→b refl
|
|
111 ... | ()
|
|
112 ≡-Bool-func {false} {false} a→b b→a = refl
|
|
113
|
|
114 bool-≡-? : (a b : Bool) → Dec ( a ≡ b )
|
|
115 bool-≡-? true true = yes refl
|
|
116 bool-≡-? true false = no (λ ())
|
|
117 bool-≡-? false true = no (λ ())
|
|
118 bool-≡-? false false = yes refl
|
|
119
|
|
120 ¬-bool-t : {a : Bool} → ¬ ( a ≡ true ) → a ≡ false
|
|
121 ¬-bool-t {true} ne = ⊥-elim ( ne refl )
|
|
122 ¬-bool-t {false} ne = refl
|
|
123
|
|
124 ¬-bool-f : {a : Bool} → ¬ ( a ≡ false ) → a ≡ true
|
|
125 ¬-bool-f {true} ne = refl
|
|
126 ¬-bool-f {false} ne = ⊥-elim ( ne refl )
|
|
127
|
|
128 ¬-bool : {a : Bool} → a ≡ false → a ≡ true → ⊥
|
|
129 ¬-bool refl ()
|
|
130
|
|
131 lemma-∧-0 : {a b : Bool} → a /\ b ≡ true → a ≡ false → ⊥
|
|
132 lemma-∧-0 {true} {true} refl ()
|
|
133 lemma-∧-0 {true} {false} ()
|
|
134 lemma-∧-0 {false} {true} ()
|
|
135 lemma-∧-0 {false} {false} ()
|
|
136
|
|
137 lemma-∧-1 : {a b : Bool} → a /\ b ≡ true → b ≡ false → ⊥
|
|
138 lemma-∧-1 {true} {true} refl ()
|
|
139 lemma-∧-1 {true} {false} ()
|
|
140 lemma-∧-1 {false} {true} ()
|
|
141 lemma-∧-1 {false} {false} ()
|
|
142
|
|
143 bool-and-tt : {a b : Bool} → a ≡ true → b ≡ true → ( a /\ b ) ≡ true
|
|
144 bool-and-tt refl refl = refl
|
|
145
|
|
146 bool-∧→tt-0 : {a b : Bool} → ( a /\ b ) ≡ true → a ≡ true
|
|
147 bool-∧→tt-0 {true} {true} refl = refl
|
|
148 bool-∧→tt-0 {false} {_} ()
|
|
149
|
|
150 bool-∧→tt-1 : {a b : Bool} → ( a /\ b ) ≡ true → b ≡ true
|
|
151 bool-∧→tt-1 {true} {true} refl = refl
|
|
152 bool-∧→tt-1 {true} {false} ()
|
|
153 bool-∧→tt-1 {false} {false} ()
|
|
154
|
|
155 bool-or-1 : {a b : Bool} → a ≡ false → ( a \/ b ) ≡ b
|
|
156 bool-or-1 {false} {true} refl = refl
|
|
157 bool-or-1 {false} {false} refl = refl
|
|
158 bool-or-2 : {a b : Bool} → b ≡ false → (a \/ b ) ≡ a
|
|
159 bool-or-2 {true} {false} refl = refl
|
|
160 bool-or-2 {false} {false} refl = refl
|
|
161
|
|
162 bool-or-3 : {a : Bool} → ( a \/ true ) ≡ true
|
|
163 bool-or-3 {true} = refl
|
|
164 bool-or-3 {false} = refl
|
|
165
|
|
166 bool-or-31 : {a b : Bool} → b ≡ true → ( a \/ b ) ≡ true
|
|
167 bool-or-31 {true} {true} refl = refl
|
|
168 bool-or-31 {false} {true} refl = refl
|
|
169
|
|
170 bool-or-4 : {a : Bool} → ( true \/ a ) ≡ true
|
|
171 bool-or-4 {true} = refl
|
|
172 bool-or-4 {false} = refl
|
|
173
|
|
174 bool-or-41 : {a b : Bool} → a ≡ true → ( a \/ b ) ≡ true
|
|
175 bool-or-41 {true} {b} refl = refl
|
|
176
|
|
177 bool-and-1 : {a b : Bool} → a ≡ false → (a /\ b ) ≡ false
|
|
178 bool-and-1 {false} {b} refl = refl
|
|
179 bool-and-2 : {a b : Bool} → b ≡ false → (a /\ b ) ≡ false
|
|
180 bool-and-2 {true} {false} refl = refl
|
|
181 bool-and-2 {false} {false} refl = refl
|
|
182
|
|
183
|
|
184 open import Data.Nat
|
|
185 open import Data.Nat.Properties
|
|
186
|
|
187 _≥b_ : ( x y : ℕ) → Bool
|
|
188 x ≥b y with <-cmp x y
|
|
189 ... | tri< a ¬b ¬c = false
|
|
190 ... | tri≈ ¬a b ¬c = true
|
|
191 ... | tri> ¬a ¬b c = true
|
|
192
|
|
193 _>b_ : ( x y : ℕ) → Bool
|
|
194 x >b y with <-cmp x y
|
|
195 ... | tri< a ¬b ¬c = false
|
|
196 ... | tri≈ ¬a b ¬c = false
|
|
197 ... | tri> ¬a ¬b c = true
|
|
198
|
|
199 _≤b_ : ( x y : ℕ) → Bool
|
|
200 x ≤b y = y ≥b x
|
|
201
|
|
202 _<b_ : ( x y : ℕ) → Bool
|
|
203 x <b y = y >b x
|
|
204
|
1174
|
205 open import Relation.Binary.PropositionalEquality
|
|
206
|
|
207 ¬i0≡i1 : ¬ ( i0 ≡ i1 )
|
|
208 ¬i0≡i1 ()
|
|
209
|
|
210 ¬i0→i1 : {x : Two} → ¬ (x ≡ i0 ) → x ≡ i1
|
|
211 ¬i0→i1 {i0} ne = ⊥-elim ( ne refl )
|
|
212 ¬i0→i1 {i1} ne = refl
|
|
213
|
|
214 ¬i1→i0 : {x : Two} → ¬ (x ≡ i1 ) → x ≡ i0
|
|
215 ¬i1→i0 {i0} ne = refl
|
|
216 ¬i1→i0 {i1} ne = ⊥-elim ( ne refl )
|
|
217
|