File tree Expand file tree Collapse file tree 5 files changed +1317
-12
lines changed
Expand file tree Collapse file tree 5 files changed +1317
-12
lines changed Original file line number Diff line number Diff line change 1+ /* Comparison datatype
2+
3+ By Quentin Garchery (May 2021 ). */
4+
5+ require open Blanqui .Lib .Set Blanqui .Lib .Prop Blanqui .Lib .FOL Blanqui .Lib .Eq
6+ Blanqui .Lib .Bool ;
7+
8+ inductive Comp : TYPE ≔
9+ | Eq : Comp
10+ | Lt : Comp
11+ | Gt : Comp ;
12+
13+ // set code for Comp
14+
15+ constant symbol comp : Set ;
16+
17+ rule τ comp ↪ Comp ;
18+
19+ // Boolean functions for testing head constructor
20+
21+ symbol isEq : Comp → 𝔹;
22+
23+ rule isEq Eq ↪ true
24+ with isEq Lt ↪ false
25+ with isEq Gt ↪ false ;
26+
27+ symbol isLt : Comp → 𝔹;
28+
29+ rule isLt Eq ↪ false
30+ with isLt Lt ↪ true
31+ with isLt Gt ↪ false ;
32+
33+ symbol isGt : Comp → 𝔹;
34+
35+ rule isGt Eq ↪ false
36+ with isGt Lt ↪ false
37+ with isGt Gt ↪ true ;
38+
39+ // Discriminate constructors
40+
41+ symbol Lt ≠Eq : π (Lt ≠ Eq ) ≔
42+ begin
43+ assume h ; refine ind_eq h (λ n , istrue (isEq n )) top
44+ end ;
45+
46+ symbol Gt ≠Eq : π (Gt ≠ Eq ) ≔
47+ begin
48+ assume h ; refine ind_eq h (λ n , istrue (isEq n )) top
49+ end ;
50+
51+ symbol Gt ≠Lt : π (Gt ≠ Lt ) ≔
52+ begin
53+ assume h ; refine ind_eq h (λ n , istrue (isLt n )) top
54+ end ;
55+
56+ // Opposite of a Comp
57+
58+ symbol opp : Comp → Comp ;
59+
60+ rule opp Eq ↪ Eq
61+ with opp Lt ↪ Gt
62+ with opp Gt ↪ Lt ;
63+
64+ symbol opp_idem c : π (opp (opp c ) = c ) ≔
65+ begin
66+ induction { reflexivity ; } { reflexivity ; } { reflexivity ; }
67+ end ;
68+
69+ // Conditional
70+
71+ symbol case_Comp [A ] : Comp → τ A → τ A → τ A → τ A ;
72+
73+ rule case_Comp Eq $x _ _ ↪ $x
74+ with case_Comp Lt _ $x _ ↪ $x
75+ with case_Comp Gt _ _ $x ↪ $x ;
You can’t perform that action at this time.
0 commit comments