|
1 | | -// Booleans |
| 1 | +/* Library on booleans. */ |
2 | 2 |
|
3 | | -require open Blanqui.Lib.Set Blanqui.Lib.Prop Blanqui.Lib.FOL; |
| 3 | +require open Blanqui.Lib.Set Blanqui.Lib.Prop Blanqui.Lib.FOL Blanqui.Lib.Eq; |
4 | 4 |
|
5 | 5 | inductive 𝔹 : TYPE ≔ |
6 | 6 | | true : 𝔹 |
7 | 7 | | false : 𝔹; |
8 | 8 |
|
9 | | -// set code for 𝔹 |
10 | | - |
11 | 9 | constant symbol bool : Set; |
12 | | - |
13 | 10 | rule τ bool ↪ 𝔹; |
14 | 11 |
|
15 | | -// 𝔹oolean not |
| 12 | +// induction principle with equalities |
| 13 | + |
| 14 | +opaque symbol case_𝔹 b : π (b = true ∨ b = false) ≔ |
| 15 | +begin |
| 16 | + induction |
| 17 | + { apply ∨ᵢ₁; reflexivity; } |
| 18 | + { apply ∨ᵢ₂; reflexivity; } |
| 19 | +end; |
| 20 | + |
| 21 | +opaque symbol ind_𝔹_eq p b: |
| 22 | + (π(b = true) → π(p b)) → (π(b = false) → π(p b)) → π(p b) ≔ |
| 23 | +begin |
| 24 | + assume p b t f; refine ∨ₑ (case_𝔹 b) t f; |
| 25 | +end; |
| 26 | + |
| 27 | +// non confusion of constructors |
| 28 | + |
| 29 | +symbol istrue : 𝔹 → Prop; |
| 30 | + |
| 31 | +rule istrue true ↪ ⊤ |
| 32 | +with istrue false ↪ ⊥; |
| 33 | + |
| 34 | +opaque symbol false≠true : π (false ≠ true) ≔ |
| 35 | +begin |
| 36 | + assume h; refine ind_eq h istrue top |
| 37 | +end; |
| 38 | + |
| 39 | +opaque symbol true≠false : π (true ≠ false) ≔ |
| 40 | +begin |
| 41 | + assume h; apply false≠true; symmetry; apply h |
| 42 | +end; |
| 43 | + |
| 44 | +// not |
16 | 45 |
|
17 | 46 | symbol not : 𝔹 → 𝔹; |
18 | 47 |
|
19 | 48 | rule not true ↪ false |
20 | 49 | with not false ↪ true; |
21 | 50 |
|
22 | | -// 𝔹oolean or |
| 51 | +// or |
23 | 52 |
|
24 | | -symbol or : 𝔹 → 𝔹 → 𝔹; |
25 | | - |
26 | | -notation or infix left 6; |
| 53 | +symbol or : 𝔹 → 𝔹 → 𝔹; notation or infix left 20; |
27 | 54 |
|
28 | 55 | rule true or _ ↪ true |
29 | 56 | with _ or true ↪ true |
30 | 57 | with false or $b ↪ $b |
31 | 58 | with $b or false ↪ $b; |
32 | 59 |
|
33 | | -// 𝔹oolean and |
34 | | - |
35 | | -symbol and : 𝔹 → 𝔹 → 𝔹; |
36 | | - |
37 | | -notation and infix left 7; |
| 60 | +opaque symbol ∨_istrue [p q] : π(istrue(p or q)) → π(istrue p ∨ istrue q) ≔ |
| 61 | +begin |
| 62 | + induction |
| 63 | + { assume q h; apply ∨ᵢ₁; apply top; } |
| 64 | + { assume q h; apply ∨ᵢ₂; apply h; } |
| 65 | +end; |
| 66 | + |
| 67 | +opaque symbol istrue_or [p q] : π(istrue p ∨ istrue q) → π(istrue(p or q)) ≔ |
| 68 | +begin |
| 69 | + induction |
| 70 | + { assume q h; apply top; } |
| 71 | + { assume q h; apply ∨ₑ h { assume i; apply ⊥ₑ i; } { assume i; apply i; } } |
| 72 | +end; |
| 73 | + |
| 74 | +opaque symbol orᵢ₁ [p] q : π (istrue p) → π (istrue (p or q)) ≔ |
| 75 | +begin |
| 76 | + induction |
| 77 | + { simplify; assume b h; apply top } |
| 78 | + { simplify; assume b h; apply ⊥ₑ h } |
| 79 | +end; |
| 80 | + |
| 81 | +opaque symbol orᵢ₂ p [q] : π (istrue q) → π (istrue (p or q)) ≔ |
| 82 | +begin |
| 83 | + induction |
| 84 | + { simplify; assume b h; apply top } |
| 85 | + { simplify; assume b h; apply h } |
| 86 | +end; |
| 87 | + |
| 88 | +opaque symbol orₑ [p q] r : π(istrue(p or q)) → |
| 89 | + (π(istrue p) → π(istrue r)) → (π(istrue q) → π(istrue r)) → π(istrue r) ≔ |
| 90 | +begin |
| 91 | + assume p q r pq pr qr; |
| 92 | + have h: π(istrue p ∨ istrue q) { apply @∨_istrue p q pq /*FIXME*/ }; |
| 93 | + apply ∨ₑ h pr qr; |
| 94 | +end; |
| 95 | + |
| 96 | +opaque symbol orC p q : π (p or q = q or p) ≔ |
| 97 | +begin |
| 98 | + induction |
| 99 | + { reflexivity; } |
| 100 | + { reflexivity; } |
| 101 | +end; |
| 102 | + |
| 103 | +opaque symbol orA p q r : π ((p or q) or r = p or (q or r)) ≔ |
| 104 | +begin |
| 105 | + induction |
| 106 | + { reflexivity; } |
| 107 | + { reflexivity; } |
| 108 | +end; |
| 109 | + |
| 110 | +// and |
| 111 | + |
| 112 | +symbol and : 𝔹 → 𝔹 → 𝔹; notation and infix left 7; |
38 | 113 |
|
39 | 114 | rule true and $b ↪ $b |
40 | 115 | with $b and true ↪ $b |
41 | 116 | with false and _ ↪ false |
42 | 117 | with _ and false ↪ false; |
43 | 118 |
|
44 | | -// Conditional |
| 119 | +opaque symbol ∧_istrue [p q] : π(istrue (p and q)) → π(istrue p ∧ istrue q) ≔ |
| 120 | +begin |
| 121 | + induction |
| 122 | + { induction |
| 123 | + { assume h; apply ∧ᵢ { apply top } { apply top } } |
| 124 | + { assume h; apply ⊥ₑ h; } |
| 125 | + } |
| 126 | + { assume q h; apply ⊥ₑ h; } |
| 127 | +end; |
| 128 | + |
| 129 | +opaque symbol istrue_and [p q] : π(istrue p ∧ istrue q) → π(istrue (p and q)) ≔ |
| 130 | +begin |
| 131 | + induction |
| 132 | + { assume q h; apply ∧ₑ₂ h; } |
| 133 | + { assume q h; apply ∧ₑ₁ h; } |
| 134 | +end; |
| 135 | + |
| 136 | +opaque symbol andᵢ [p q] : π(istrue p) → π(istrue q) → π(istrue (p and q)) ≔ |
| 137 | +begin |
| 138 | + assume p q h i; //FIXME: apply istrue_and fails |
| 139 | + apply @istrue_and p q; apply ∧ᵢ h i; |
| 140 | +end; |
| 141 | + |
| 142 | +opaque symbol andₑ₁ [p q] : π (istrue (p and q)) → π (istrue p) ≔ |
| 143 | +begin |
| 144 | + induction |
| 145 | + { assume q i; apply top; } |
| 146 | + { assume q i; apply i; } |
| 147 | +end; |
| 148 | + |
| 149 | +opaque symbol andₑ₂ [p q] : π (istrue (p and q)) → π (istrue q) ≔ |
| 150 | +begin |
| 151 | + induction |
| 152 | + { assume q i; apply i; } |
| 153 | + { assume q i; apply ⊥ₑ i; } |
| 154 | +end; |
| 155 | + |
| 156 | +// if-then-else |
45 | 157 |
|
46 | 158 | symbol if : 𝔹 → Π [a], τ a → τ a → τ a; |
47 | 159 |
|
|
0 commit comments