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