1461
|
1 {-# OPTIONS --cubical-compatible --safe #-}
|
|
2
|
431
|
3 module logic where
|
|
4
|
|
5 open import Level
|
|
6 open import Relation.Nullary
|
|
7 open import Relation.Binary hiding (_⇔_ )
|
|
8 open import Data.Empty
|
|
9
|
1461
|
10
|
1175
|
11 data Bool : Set where
|
|
12 true : Bool
|
|
13 false : Bool
|
431
|
14
|
|
15 record _∧_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where
|
|
16 constructor ⟪_,_⟫
|
|
17 field
|
|
18 proj1 : A
|
|
19 proj2 : B
|
|
20
|
|
21 data _∨_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where
|
|
22 case1 : A → A ∨ B
|
|
23 case2 : B → A ∨ B
|
|
24
|
|
25 _⇔_ : {n m : Level } → ( A : Set n ) ( B : Set m ) → Set (n ⊔ m)
|
|
26 _⇔_ A B = ( A → B ) ∧ ( B → A )
|
|
27
|
|
28 contra-position : {n m : Level } {A : Set n} {B : Set m} → (A → B) → ¬ B → ¬ A
|
|
29 contra-position {n} {m} {A} {B} f ¬b a = ¬b ( f a )
|
|
30
|
|
31 double-neg : {n : Level } {A : Set n} → A → ¬ ¬ A
|
|
32 double-neg A notnot = notnot A
|
|
33
|
|
34 double-neg2 : {n : Level } {A : Set n} → ¬ ¬ ¬ A → ¬ A
|
|
35 double-neg2 notnot A = notnot ( double-neg A )
|
|
36
|
|
37 de-morgan : {n : Level } {A B : Set n} → A ∧ B → ¬ ( (¬ A ) ∨ (¬ B ) )
|
|
38 de-morgan {n} {A} {B} and (case1 ¬A) = ⊥-elim ( ¬A ( _∧_.proj1 and ))
|
|
39 de-morgan {n} {A} {B} and (case2 ¬B) = ⊥-elim ( ¬B ( _∧_.proj2 and ))
|
|
40
|
|
41 dont-or : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ A → B
|
|
42 dont-or {A} {B} (case1 a) ¬A = ⊥-elim ( ¬A a )
|
|
43 dont-or {A} {B} (case2 b) ¬A = b
|
|
44
|
|
45 dont-orb : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ B → A
|
|
46 dont-orb {A} {B} (case2 b) ¬B = ⊥-elim ( ¬B b )
|
|
47 dont-orb {A} {B} (case1 a) ¬B = a
|
|
48
|
1175
|
49 infixr 130 _∧_
|
|
50 infixr 140 _∨_
|
|
51 infixr 150 _⇔_
|
|
52
|
|
53 _/\_ : Bool → Bool → Bool
|
|
54 true /\ true = true
|
|
55 _ /\ _ = false
|
|
56
|
|
57 _\/_ : Bool → Bool → Bool
|
|
58 false \/ false = false
|
|
59 _ \/ _ = true
|
|
60
|
|
61 not : Bool → Bool
|
|
62 not true = false
|
|
63 not false = true
|
|
64
|
|
65 _<=>_ : Bool → Bool → Bool
|
|
66 true <=> true = true
|
|
67 false <=> false = true
|
|
68 _ <=> _ = false
|
|
69
|
1461
|
70 infixr 130 _\/_
|
|
71 infixr 140 _/\_
|
1175
|
72
|
1461
|
73 open import Relation.Binary.PropositionalEquality
|
1175
|
74
|
|
75 record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
|
|
76 field
|
|
77 fun← : S → R
|
|
78 fun→ : R → S
|
|
79 fiso← : (x : R) → fun← ( fun→ x ) ≡ x
|
|
80 fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
|
|
81
|
|
82 injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
|
|
83 injection R S f = (x y : R) → f x ≡ f y → x ≡ y
|
|
84
|
|
85
|
1461
|
86 not-not-bool : { b : Bool } → not (not b) ≡ b
|
|
87 not-not-bool {true} = refl
|
|
88 not-not-bool {false} = refl
|
|
89
|
1175
|
90 ¬t=f : (t : Bool ) → ¬ ( not t ≡ t)
|
|
91 ¬t=f true ()
|
|
92 ¬t=f false ()
|
|
93
|
|
94 ≡-Bool-func : {A B : Bool } → ( A ≡ true → B ≡ true ) → ( B ≡ true → A ≡ true ) → A ≡ B
|
|
95 ≡-Bool-func {true} {true} a→b b→a = refl
|
|
96 ≡-Bool-func {false} {true} a→b b→a with b→a refl
|
|
97 ... | ()
|
|
98 ≡-Bool-func {true} {false} a→b b→a with a→b refl
|
|
99 ... | ()
|
|
100 ≡-Bool-func {false} {false} a→b b→a = refl
|
|
101
|
|
102 bool-≡-? : (a b : Bool) → Dec ( a ≡ b )
|
|
103 bool-≡-? true true = yes refl
|
|
104 bool-≡-? true false = no (λ ())
|
|
105 bool-≡-? false true = no (λ ())
|
|
106 bool-≡-? false false = yes refl
|
|
107
|
|
108 ¬-bool-t : {a : Bool} → ¬ ( a ≡ true ) → a ≡ false
|
|
109 ¬-bool-t {true} ne = ⊥-elim ( ne refl )
|
|
110 ¬-bool-t {false} ne = refl
|
|
111
|
|
112 ¬-bool-f : {a : Bool} → ¬ ( a ≡ false ) → a ≡ true
|
|
113 ¬-bool-f {true} ne = refl
|
|
114 ¬-bool-f {false} ne = ⊥-elim ( ne refl )
|
|
115
|
|
116 ¬-bool : {a : Bool} → a ≡ false → a ≡ true → ⊥
|
|
117 ¬-bool refl ()
|
|
118
|
|
119 lemma-∧-0 : {a b : Bool} → a /\ b ≡ true → a ≡ false → ⊥
|
|
120 lemma-∧-0 {true} {false} ()
|
|
121 lemma-∧-0 {false} {true} ()
|
|
122 lemma-∧-0 {false} {false} ()
|
1461
|
123 lemma-∧-0 {true} {true} eq1 ()
|
1175
|
124
|
|
125 lemma-∧-1 : {a b : Bool} → a /\ b ≡ true → b ≡ false → ⊥
|
|
126 lemma-∧-1 {true} {false} ()
|
|
127 lemma-∧-1 {false} {true} ()
|
|
128 lemma-∧-1 {false} {false} ()
|
1461
|
129 lemma-∧-1 {true} {true} eq1 ()
|
1175
|
130
|
|
131 bool-and-tt : {a b : Bool} → a ≡ true → b ≡ true → ( a /\ b ) ≡ true
|
|
132 bool-and-tt refl refl = refl
|
|
133
|
|
134 bool-∧→tt-0 : {a b : Bool} → ( a /\ b ) ≡ true → a ≡ true
|
1461
|
135 bool-∧→tt-0 {true} {true} eq = refl
|
1175
|
136 bool-∧→tt-0 {false} {_} ()
|
|
137
|
|
138 bool-∧→tt-1 : {a b : Bool} → ( a /\ b ) ≡ true → b ≡ true
|
1461
|
139 bool-∧→tt-1 {true} {true} eq = refl
|
1175
|
140 bool-∧→tt-1 {true} {false} ()
|
|
141 bool-∧→tt-1 {false} {false} ()
|
|
142
|
|
143 bool-or-1 : {a b : Bool} → a ≡ false → ( a \/ b ) ≡ b
|
1461
|
144 bool-or-1 {false} {true} eq = refl
|
|
145 bool-or-1 {false} {false} eq = refl
|
1175
|
146 bool-or-2 : {a b : Bool} → b ≡ false → (a \/ b ) ≡ a
|
1461
|
147 bool-or-2 {true} {false} eq = refl
|
|
148 bool-or-2 {false} {false} eq = refl
|
1175
|
149
|
|
150 bool-or-3 : {a : Bool} → ( a \/ true ) ≡ true
|
|
151 bool-or-3 {true} = refl
|
|
152 bool-or-3 {false} = refl
|
|
153
|
|
154 bool-or-31 : {a b : Bool} → b ≡ true → ( a \/ b ) ≡ true
|
1461
|
155 bool-or-31 {true} {true} eq = refl
|
|
156 bool-or-31 {false} {true} eq = refl
|
1175
|
157
|
|
158 bool-or-4 : {a : Bool} → ( true \/ a ) ≡ true
|
|
159 bool-or-4 {true} = refl
|
|
160 bool-or-4 {false} = refl
|
|
161
|
|
162 bool-or-41 : {a b : Bool} → a ≡ true → ( a \/ b ) ≡ true
|
1461
|
163 bool-or-41 {true} {b} eq = refl
|
1175
|
164
|
|
165 bool-and-1 : {a b : Bool} → a ≡ false → (a /\ b ) ≡ false
|
1461
|
166 bool-and-1 {false} {b} eq = refl
|
1175
|
167 bool-and-2 : {a b : Bool} → b ≡ false → (a /\ b ) ≡ false
|
1461
|
168 bool-and-2 {true} {false} eq = refl
|
|
169 bool-and-2 {false} {false} eq = refl
|
|
170 bool-and-2 {true} {true} ()
|
|
171 bool-and-2 {false} {true} ()
|
1175
|
172
|
|
173
|