Skip to content

Commit d1bdf8f

Browse files
authored
Bool: declare istrue as a coercion (#22)
1 parent 91aa5e7 commit d1bdf8f

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

Bool.lp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ begin
2525
assume p b t f; refine ∨ₑ (case_𝔹 b) t f;
2626
end;
2727

28-
// non confusion of constructors
28+
// istrue predicate
2929

3030
injective symbol istrue : 𝔹 → Prop;
3131

3232
rule istrue true ↪ ⊤
3333
with istrue false ↪ ⊥;
3434

35+
coerce_rule coerce 𝔹 Prop $xistrue $x;
36+
37+
// non confusion of constructors
38+
3539
opaque symbol falsetrue : π (falsetrue) ≔
3640
begin
3741
assume h; refine ind_eq h istrue ⊤ᵢ
@@ -51,46 +55,48 @@ with not false ↪ true;
5155

5256
// or
5357

54-
symbol or : 𝔹 → 𝔹 → 𝔹; notation or infix left 20;
58+
symbol or : 𝔹 → 𝔹 → 𝔹;
59+
60+
notation or infix left 20;
5561

5662
rule true or _ ↪ true
5763
with _ or truetrue
5864
with false or $b ↪ $b
5965
with $b or false ↪ $b;
6066

61-
opaque symbol ∨_istrue [p q] : π(istrue(p or q)) → π(istrue p istrue q) ≔
67+
opaque symbol ∨_istrue [p q : 𝔹] : π(p or q) → π(pq) ≔
6268
begin
6369
induction
6470
{ assume q h; apply ∨ᵢ₁; apply ⊤ᵢ; }
6571
{ assume q h; apply ∨ᵢ₂; apply h; }
6672
end;
6773

68-
opaque symbol istrue_or [p q] : π(istrue pistrue q) → π(istrue(p or q)) ≔
74+
opaque symbol istrue_or [p q : 𝔹] : π(pq) → π(p or q) ≔
6975
begin
7076
induction
7177
{ assume q h; apply ⊤ᵢ; }
7278
{ assume q h; apply ∨ₑ h { assume i; apply ⊥ₑ i; } { assume i; apply i; } }
7379
end;
7480

75-
opaque symbol orᵢ₁ [p] q : π (istrue p) → π (istrue (p or q)) ≔
81+
opaque symbol orᵢ₁ [p : 𝔹] q : π p → π (p or q) ≔
7682
begin
7783
induction
7884
{ simplify; assume b h; apply ⊤ᵢ }
7985
{ simplify; assume b h; apply ⊥ₑ h }
8086
end;
8187

82-
opaque symbol orᵢ₂ p [q] : π (istrue q) → π (istrue (p or q)) ≔
88+
opaque symbol orᵢ₂ p [q : 𝔹] : π q → π (p or q) ≔
8389
begin
8490
induction
8591
{ simplify; assume b h; apply ⊤ᵢ }
8692
{ simplify; assume b h; apply h }
8793
end;
8894

89-
opaque symbol orₑ [p q] r : π(istrue(p or q)) →
90-
(π(istrue p) → π(istrue r)) → (π(istrue q) → π(istrue r)) → π(istrue r)
95+
opaque symbol orₑ [p q : 𝔹] (r : 𝔹) :
96+
π (p or q) → p → π r) → (π q → π r) → π r
9197
begin
9298
assume p q r pq pr qr;
93-
have h: π(istrue pistrue q) { apply @∨_istrue p q pq /*FIXME*/ };
99+
have h: π(pq) { apply ∨_istrue pq };
94100
apply ∨ₑ h pr qr;
95101
end;
96102

@@ -110,14 +116,16 @@ end;
110116

111117
// and
112118

113-
symbol and : 𝔹 → 𝔹 → 𝔹; notation and infix left 7;
119+
symbol and : 𝔹 → 𝔹 → 𝔹;
120+
121+
notation and infix left 7;
114122

115123
rule true and $b ↪ $b
116124
with $b and true ↪ $b
117125
with false and _ ↪ false
118126
with _ and falsefalse;
119127

120-
opaque symbol ∧_istrue [p q] : π(istrue (p and q)) → π(istrue p istrue q) ≔
128+
opaque symbol ∧_istrue [p q : 𝔹] : π(p and q) → π(pq) ≔
121129
begin
122130
induction
123131
{ induction
@@ -127,26 +135,26 @@ begin
127135
{ assume q h; apply ⊥ₑ h; }
128136
end;
129137

130-
opaque symbol istrue_and [p q] : π(istrue pistrue q) → π(istrue (p and q)) ≔
138+
opaque symbol istrue_and [p q : 𝔹] : π(pq) → π(p and q) ≔
131139
begin
132140
induction
133141
{ assume q h; apply ∧ₑ₂ h; }
134142
{ assume q h; apply ∧ₑ₁ h; }
135143
end;
136144

137-
opaque symbol andᵢ [p q] : π(istrue p) → π(istrue q) → π(istrue (p and q)) ≔
145+
opaque symbol andᵢ [p q : 𝔹] : π p → π q → π(p and q) ≔
138146
begin
139147
assume p q h i; apply @istrue_and p q; apply ∧ᵢ h i;
140148
end;
141149

142-
opaque symbol andₑ₁ [p q] : π (istrue (p and q)) → π (istrue p)
150+
opaque symbol andₑ₁ [p q : 𝔹] : π (p and q) → π p
143151
begin
144152
induction
145153
{ assume q i; apply ⊤ᵢ; }
146154
{ assume q i; apply i; }
147155
end;
148156

149-
opaque symbol andₑ₂ [p q] : π (istrue (p and q)) → π (istrue q)
157+
opaque symbol andₑ₂ [p q : 𝔹] : π (p and q) → π q
150158
begin
151159
induction
152160
{ assume q i; apply i; }
@@ -159,4 +167,3 @@ symbol if : 𝔹 → Π [a], τ a → τ a → τ a;
159167

160168
rule if true $x _ ↪ $x
161169
with if false _ $y ↪ $y;
162-

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
55

66
## Unreleased
77

8+
- Bool: declare istrue as a coercion
89
- Add files for higher-order logic:
910
HOL: Set constructor ⤳ for quantifying over function types
1011
Impred: Set constructor o for quantifying over propositions

List.lp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ with eql _ (_ ⸬ _) □ ↪ false
258258
with eql _ □ (_ ⸬ _) ↪ false
259259
with eql $beq ($x ⸬ $l) ($y ⸬ $m) ↪ ($beq $x $y) and (eql $beq $l $m);
260260

261-
opaque symbol eql_correct a beq: π(`∀ x:τ a, `∀ y, istrue(beq x y) ⇒ x = y) →
262-
π(`∀ l, `∀ m, istrue(eql beq l m)l = m) ≔
261+
opaque symbol eql_correct a (beqa → τ a → 𝔹) :
262+
π(`∀ x, `∀ y, beq x yx = y) → π(`∀ l, `∀ m, eql beq l ml = m) ≔
263263
begin
264264
assume a beq beq_correct; induction
265265
{ induction
@@ -277,8 +277,8 @@ begin
277277
}
278278
end;
279279

280-
opaque symbol eql_complete a beq: π(`∀ x:τ a, `∀ y, x = yistrue(beq x y)) →
281-
π(`∀ l, `∀ m, l = mistrue(eql beq l m)) ≔
280+
opaque symbol eql_complete a (beq : τ a → τ a → 𝔹) :
281+
π(`∀ x, `∀ y, x = ybeq x y) → π(`∀ l, `∀ m, l = meql beq l m) ≔
282282
begin
283283
assume a beq beq_complete; induction
284284
{ assume m i; rewrite left i; apply ⊤ᵢ; }
@@ -586,7 +586,7 @@ rule all2 _ □ □ ↪ true
586586
with all2 $p ($x ⸬ $l) ($y ⸬ $m) ↪ ($p $x $y) and (all2 $p $l $m);
587587

588588
opaque symbol unzip1_zip [a b] (la:𝕃 a) (lb:𝕃 b) :
589-
π (istrue (size lasize lb)) → π (unzip1 (zip la lb) = la) ≔
589+
π (size lasize lb) → π (unzip1 (zip la lb) = la) ≔
590590
begin
591591
assume a b; induction
592592
{ reflexivity; }
@@ -597,7 +597,7 @@ begin
597597
end;
598598

599599
opaque symbol unzip2_zip [a b] (la:𝕃 a) (lb:𝕃 b) :
600-
π (istrue (size lbsize la)) → π (unzip2 (zip la lb) = lb) ≔
600+
π (size lbsize la) → π (unzip2 (zip la lb) = lb) ≔
601601
begin
602602
assume a b; induction
603603
{ assume lb h;
@@ -610,7 +610,7 @@ begin
610610
end;
611611

612612
opaque symbol size1_zip [a b] (la:𝕃 a) (lb:𝕃 b) :
613-
π (istrue (size lasize lb)) → π (size (zip la lb) = size la) ≔
613+
π (size lasize lb) → π (size (zip la lb) = size la) ≔
614614
begin
615615
assume a b; induction
616616
{ reflexivity; }
@@ -621,7 +621,7 @@ begin
621621
end;
622622

623623
opaque symbol size2_zip [a b] (la:𝕃 a) (lb:𝕃 b) :
624-
π (istrue (size lbsize la)) → π (size (zip la lb) = size lb) ≔
624+
π (size lbsize la) → π (size (zip la lb) = size lb) ≔
625625
begin
626626
assume a b; induction
627627
{ assume lb h; symmetry; apply0 (size lb) h; }
@@ -720,8 +720,7 @@ begin
720720
reflexivity;
721721
end;
722722

723-
opaque symbol drop_oversize [a] n (l:𝕃 a) :
724-
π (istrue (size ln)) → π (drop n l = □) ≔
723+
opaque symbol drop_oversize [a] n (l:𝕃 a) : π (size ln) → π (drop n l = □) ≔
725724
begin
726725
assume a; induction
727726
{ assume l h;
@@ -822,8 +821,7 @@ begin
822821
{ assume e l h; simplify; rewrite h; reflexivity; }
823822
end;
824823

825-
opaque symbol take_oversize [a] n (l:𝕃 a) :
826-
π (istrue (size ln)) → π (take n l = l) ≔
824+
opaque symbol take_oversize [a] n (l:𝕃 a) : π (size ln) → π (take n l = l) ≔
827825
begin
828826
assume a; induction
829827
{ assume l h; simplify; symmetry; apply size0nil l; apply0 (size l) h; }
@@ -844,7 +842,7 @@ begin
844842
end;
845843

846844
opaque symbol size_takel [a] n (l:𝕃 a) :
847-
π (istrue (nsize l)) → π (size (take n l) = n) ≔
845+
π (nsize l) → π (size (take n l) = n) ≔
848846
begin
849847
assume a; induction
850848
{ reflexivity; }
@@ -884,7 +882,7 @@ begin
884882
end;
885883

886884
opaque symbol takel_cat [a] (l1 l2:𝕃 a) n :
887-
π (istrue (nsize l1)) → π (take n (l1 ++ l2) = take n l1) ≔
885+
π (nsize l1) → π (take n (l1 ++ l2) = take n l1) ≔
888886
begin
889887
assume a; induction
890888
{ assume l2 n h; have t:π (n = 0) { apply0 n h }; rewrite t; reflexivity; }
@@ -967,8 +965,7 @@ begin
967965
rewrite cat_take_drop n0 l; reflexivity;
968966
end;
969967

970-
opaque symbol rot_oversize [a] n (l:𝕃 a) :
971-
π (istrue (size ln)) → π (rot n l = l) ≔
968+
opaque symbol rot_oversize [a] n (l:𝕃 a) : π (size ln) → π (rot n l = l) ≔
972969
begin
973970
assume a n l h; simplify; rewrite drop_oversize n l h;
974971
rewrite take_oversize n l h; reflexivity;
@@ -989,7 +986,7 @@ begin
989986
end;
990987

991988
opaque symbol take_take [a] n m :
992-
π (istrue (nm)) → π (`∀ l:𝕃 a, take n (take m l) = take n l) ≔
989+
π (nm) → π (`∀ l:𝕃 a, take n (take m l) = take n l) ≔
993990
begin
994991
assume a; induction
995992
{ reflexivity; }
@@ -1064,21 +1061,21 @@ begin
10641061
end;
10651062

10661063
opaque symbol mem_head [a] beq (xa) l :
1067-
π (beq x x = true) → π (istrue (beq x (xl))) ≔
1064+
π (beq x x = true) → π (∈ beq x (xl)) ≔
10681065
begin
10691066
assume a beq x l hrefl; simplify; rewrite hrefl; apply ⊤ᵢ;
10701067
end;
10711068

10721069
opaque symbol mem_take [a] beq n l (xa) :
1073-
π (istrue (beq x (take n l))) → π (istrue (beq x l)) ≔
1070+
π (∈ beq x (take n l)) → π (∈ beq x l) ≔
10741071
begin
10751072
assume a beq n l x h; rewrite left cat_take_drop n l;
10761073
rewrite mem_cat beq x (take n l) (drop n l);
10771074
refine @orᵢ₁ (∈ beq x (take n l)) (∈ beq x (drop n l)) h;
10781075
end;
10791076

10801077
opaque symbol mem_drop [a] beq n l (xa) :
1081-
π (istrue (beq x (drop n l))) → π (istrue (beq x l)) ≔
1078+
π (∈ beq x (drop n l)) → π (∈ beq x l) ≔
10821079
begin
10831080
assume a beq n l x h; rewrite left cat_take_drop n l;
10841081
rewrite mem_cat beq x (take n l) (drop n l);
@@ -1095,8 +1092,7 @@ with index $beq $x ($y ⸬ $l) ↪ if ($beq $x $y) 0 (index $beq $x $l +1);
10951092
assertindex eqn 2 (422513 ⸬ □) ≡ 1;
10961093
assertindex eqn 26 (422513 ⸬ □) ≡ 4;
10971094

1098-
opaque symbol index_size [a] beq (xa) l :
1099-
π (istrue (index beq x lsize l)) ≔
1095+
opaque symbol index_size [a] beq (xa) l : π (index beq x lsize l) ≔
11001096
begin
11011097
assume a beq x; induction
11021098
{ apply ⊤ᵢ; }
@@ -1145,13 +1141,12 @@ with find $p ($x ⸬ $l) ↪ if ($p $x) 0 (find $p $l +1);
11451141
assertfindx, eqn (x + 1) 3) (422513 ⸬ □) ≡ 1;
11461142
assertfindx, eqn (x + 1) 3) (424513 ⸬ □) ≡ 4;
11471143

1148-
opaque symbol find_size [a] (pa → 𝔹) l :
1149-
π (istrue (find p lsize l)) ≔
1144+
opaque symbol find_size [a] (pa → 𝔹) l : π (find p lsize l) ≔
11501145
begin
11511146
assume a p; induction
11521147
{ apply ⊤ᵢ; }
11531148
{ assume e l h;
1154-
refine ind_𝔹 (λ x:𝔹, istrue (if x 0 (find p l +1) ≤ size l +1)) _ _ (p e) {
1149+
refine ind_𝔹 (λ x, istrue (if x 0 (find p l +1) ≤ size l +1)) _ _ (p e) {
11551150
apply ⊤ᵢ;
11561151
} {
11571152
simplify; apply h;
@@ -1169,12 +1164,12 @@ with count $p ($x ⸬ $l) ↪ if ($p $x) (count $p $l +1) (count $p $l);
11691164
assertcountx, eqn (x + 1) 3) (424513 ⸬ □) ≡ 0;
11701165
assertcountx, eqn (x + 1) 3) (2222 ⸬ □) ≡ 4;
11711166

1172-
opaque symbol count_size [a] (pa → 𝔹) l : π(istrue (count p lsize l)) ≔
1167+
opaque symbol count_size [a] (pa → 𝔹) l : π(count p lsize l) ≔
11731168
begin
11741169
assume a p; induction
11751170
{ apply ⊤ᵢ; }
11761171
{ assume e l h; simplify;
1177-
refine ind_𝔹 (λ x:𝔹, istrue (if x (count p l +1) (count p l) ≤ size l +1)) _ _ (p e) {
1172+
refine ind_𝔹 (λ x, istrue (if x (count p l +1) (count p l) ≤ size l +1)) _ _ (p e) {
11781173
simplify; apply h;
11791174
} {
11801175
simplify;
@@ -1340,7 +1335,7 @@ begin
13401335
end;
13411336

13421337
opaque symbol eq_find [a] beq p (l1 l2:𝕃 a) :
1343-
π (istrue (eql beq l1 l2)) → π (istrue (eqn (find p l1) (find p l2))) ≔
1338+
π (eql beq l1 l2) → π (eqn (find p l1) (find p l2)) ≔
13441339
begin
13451340
abort;
13461341

@@ -1354,8 +1349,7 @@ with undup $beq ($x ⸬ $l)
13541349

13551350
assertundup eqn (42251323 ⸬ □) ≡ 425123 ⸬ □;
13561351

1357-
opaque symbol size_undup [a] beq (l:𝕃 a) :
1358-
π (istrue (size (undup beq l) ≤ size l)) ≔
1352+
opaque symbol size_undup [a] beq (l:𝕃 a) : π (size (undup beq l) ≤ size l) ≔
13591353
begin
13601354
assume a beq; induction
13611355
{ apply ⊤ᵢ; }
@@ -1369,8 +1363,7 @@ begin
13691363
}
13701364
end;
13711365

1372-
opaque symbol undup_uniq [a] beq (l:𝕃 a) :
1373-
π (istrue (uniq beq (undup beq l))) ≔
1366+
opaque symbol undup_uniq [a] beq (l:𝕃 a) : π (uniq beq (undup beq l)) ≔
13741367
begin
13751368
assume a beq; induction
13761369
{ apply ⊤ᵢ; }
@@ -1389,7 +1382,7 @@ begin
13891382
abort;
13901383

13911384
opaque symbol count_undup [a] beq p (l:𝕃 a) :
1392-
π (istrue (count p (undup beq l) ≤ count p l)) ≔
1385+
π (count p (undup beq l) ≤ count p l) ≔
13931386
begin
13941387
abort;
13951388

0 commit comments

Comments
 (0)