Skip to content

Commit 920f59e

Browse files
qbuzetfblanqui
andauthored
Library on natural numbers and lists inspired by ssrnat.v and seq.v (#5)
Co-authored-by: Frédéric Blanqui <frederic.blanqui@inria.fr>
1 parent ca484ec commit 920f59e

File tree

9 files changed

+3033
-252
lines changed

9 files changed

+3033
-252
lines changed

Bool.lp

Lines changed: 128 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,159 @@
1-
// Booleans
1+
/* Library on booleans. */
22

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;
44

55
inductive 𝔹 : TYPE
66
| true : 𝔹
77
| false : 𝔹;
88

9-
// set code for 𝔹
10-
119
constant symbol bool : Set;
12-
1310
rule τ bool ↪ 𝔹;
1411

15-
// 𝔹oolean not
12+
// induction principle with equalities
13+
14+
opaque symbol case_𝔹 b : π (b = trueb = 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 falsetrue : π (falsetrue) ≔
35+
begin
36+
assume h; refine ind_eq h istrue top
37+
end;
38+
39+
opaque symbol truefalse : π (truefalse) ≔
40+
begin
41+
assume h; apply falsetrue; symmetry; apply h
42+
end;
43+
44+
// not
1645

1746
symbol not : 𝔹 → 𝔹;
1847

1948
rule not truefalse
2049
with not falsetrue;
2150

22-
// 𝔹oolean or
51+
// or
2352

24-
symbol or : 𝔹 → 𝔹 → 𝔹;
25-
26-
notation or infix left 6;
53+
symbol or : 𝔹 → 𝔹 → 𝔹; notation or infix left 20;
2754

2855
rule true or _ ↪ true
2956
with _ or truetrue
3057
with false or $b ↪ $b
3158
with $b or false ↪ $b;
3259

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 pistrue 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 pistrue 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 pistrue 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;
38113

39114
rule true and $b ↪ $b
40115
with $b and true ↪ $b
41116
with false and _ ↪ false
42117
with _ and falsefalse;
43118

44-
// Conditional
119+
opaque symbol ∧_istrue [p q] : π(istrue (p and q)) → π(istrue pistrue 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 pistrue 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
45157

46158
symbol if : 𝔹 → Π [a], τ a → τ a → τ a;
47159

Eq.lp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,15 @@ builtin "eq" ≔ =;
1313
builtin "refl"eq_refl;
1414
builtin "eqind"ind_eq;
1515

16-
// inequality
16+
symbol ≠ [a] (x y : τ a) ≔ ¬ (x = y); notationinfix 10; // \neq
1717

18-
symbol ≠ [a] (x y : τ a) ≔ ¬ (x = y); // \neq
19-
20-
notationinfix 1;
21-
22-
// symmetry
23-
24-
opaque symbol eq_sym [a] (x ya) : π (x = yy = x) ≔
18+
opaque symbol feq [a b] (fa → τ b) [x x':τ a] : π(x = x') → π(f x = f x') ≔
2519
begin
26-
assume a x y xy;
27-
symmetry;
28-
apply xy
20+
assume a b f x x' xx'; rewrite xx'; reflexivity;
2921
end;
3022

31-
// monotony wrt function application
32-
33-
opaque symbol feq [a b] (fa → τ b) [x ya] : π(x = yf x = f y) ≔
23+
opaque symbol feq2 [a b c] (fa → τ b → τ c):
24+
Π [x x':τ a], π(x = x') → Π [y y':τ b], π(y = y') → π(f x y = f x' y') ≔
3425
begin
35-
assume a b f x y xy;
36-
apply ind_eq xyz, f z = f y);
37-
reflexivity
26+
assume a b c f x x' xx' y y' yy'; rewrite xx'; rewrite yy'; reflexivity
3827
end;

0 commit comments

Comments
 (0)