Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stdpp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
47
Issues
47
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Iris
stdpp
Commits
44b18f4d
Commit
44b18f4d
authored
Feb 11, 2016
by
Robbert Krebbers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shorter names for common math notions.
Also do some minor clean up.
parent
7ebc1859
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
293 additions
and
307 deletions
+293
-307
theories/base.v
theories/base.v
+75
-89
theories/countable.v
theories/countable.v
+10
-10
theories/decidable.v
theories/decidable.v
+1
-1
theories/error.v
theories/error.v
+2
-2
theories/fin_collections.v
theories/fin_collections.v
+1
-1
theories/fin_maps.v
theories/fin_maps.v
+30
-30
theories/finite.v
theories/finite.v
+29
-29
theories/gmap.v
theories/gmap.v
+1
-1
theories/list.v
theories/list.v
+68
-68
theories/numbers.v
theories/numbers.v
+13
-13
theories/option.v
theories/option.v
+5
-5
theories/orders.v
theories/orders.v
+36
-36
theories/pmap.v
theories/pmap.v
+16
-16
theories/pretty.v
theories/pretty.v
+1
-1
theories/strings.v
theories/strings.v
+1
-1
theories/tactics.v
theories/tactics.v
+2
-2
theories/vector.v
theories/vector.v
+2
-2
No files found.
theories/base.v
View file @
44b18f4d
...
...
@@ -514,71 +514,71 @@ Arguments insertE _ _ _ _ _ _ !_ _ !_ / : simpl nomatch.
(** ** Common properties *)
(** These operational type classes allow us to refer to common mathematical
properties in a generic way. For example, for injectivity of [(k ++)] it
allows us to write [inj
ective
(k ++)] instead of [app_inv_head k]. *)
Class
Inj
ective
{
A
B
}
(
R
:
relation
A
)
(
S
:
relation
B
)
(
f
:
A
→
B
)
:
Prop
:
=
inj
ective
:
∀
x
y
,
S
(
f
x
)
(
f
y
)
→
R
x
y
.
Class
Inj
ective
2
{
A
B
C
}
(
R1
:
relation
A
)
(
R2
:
relation
B
)
allows us to write [inj (k ++)] instead of [app_inv_head k]. *)
Class
Inj
{
A
B
}
(
R
:
relation
A
)
(
S
:
relation
B
)
(
f
:
A
→
B
)
:
Prop
:
=
inj
x
y
:
S
(
f
x
)
(
f
y
)
→
R
x
y
.
Class
Inj2
{
A
B
C
}
(
R1
:
relation
A
)
(
R2
:
relation
B
)
(
S
:
relation
C
)
(
f
:
A
→
B
→
C
)
:
Prop
:
=
inj
ective2
:
∀
x1
x2
y1
y2
,
S
(
f
x1
x2
)
(
f
y1
y2
)
→
R1
x1
y1
∧
R2
x2
y2
.
inj
2
x1
x2
y1
y2
:
S
(
f
x1
x2
)
(
f
y1
y2
)
→
R1
x1
y1
∧
R2
x2
y2
.
Class
Cancel
{
A
B
}
(
S
:
relation
B
)
(
f
:
A
→
B
)
(
g
:
B
→
A
)
:
Prop
:
=
cancel
:
∀
x
,
S
(
f
(
g
x
))
x
.
Class
Surj
ective
{
A
B
}
(
R
:
relation
B
)
(
f
:
A
→
B
)
:
=
surj
ective
:
∀
y
,
∃
x
,
R
(
f
x
)
y
.
Class
Idem
potent
{
A
}
(
R
:
relation
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
idemp
otent
:
∀
x
,
R
(
f
x
x
)
x
.
Class
Comm
utative
{
A
B
}
(
R
:
relation
A
)
(
f
:
B
→
B
→
A
)
:
Prop
:
=
comm
utative
:
∀
x
y
,
R
(
f
x
y
)
(
f
y
x
).
cancel
:
∀
x
,
S
(
f
(
g
x
))
x
.
Class
Surj
{
A
B
}
(
R
:
relation
B
)
(
f
:
A
→
B
)
:
=
surj
y
:
∃
x
,
R
(
f
x
)
y
.
Class
Idem
P
{
A
}
(
R
:
relation
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
idemp
x
:
R
(
f
x
x
)
x
.
Class
Comm
{
A
B
}
(
R
:
relation
A
)
(
f
:
B
→
B
→
A
)
:
Prop
:
=
comm
x
y
:
R
(
f
x
y
)
(
f
y
x
).
Class
LeftId
{
A
}
(
R
:
relation
A
)
(
i
:
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
left_id
:
∀
x
,
R
(
f
i
x
)
x
.
left_id
x
:
R
(
f
i
x
)
x
.
Class
RightId
{
A
}
(
R
:
relation
A
)
(
i
:
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
right_id
:
∀
x
,
R
(
f
x
i
)
x
.
Class
Assoc
iative
{
A
}
(
R
:
relation
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
assoc
iative
:
∀
x
y
z
,
R
(
f
x
(
f
y
z
))
(
f
(
f
x
y
)
z
).
right_id
x
:
R
(
f
x
i
)
x
.
Class
Assoc
{
A
}
(
R
:
relation
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
assoc
x
y
z
:
R
(
f
x
(
f
y
z
))
(
f
(
f
x
y
)
z
).
Class
LeftAbsorb
{
A
}
(
R
:
relation
A
)
(
i
:
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
left_absorb
:
∀
x
,
R
(
f
i
x
)
i
.
left_absorb
x
:
R
(
f
i
x
)
i
.
Class
RightAbsorb
{
A
}
(
R
:
relation
A
)
(
i
:
A
)
(
f
:
A
→
A
→
A
)
:
Prop
:
=
right_absorb
:
∀
x
,
R
(
f
x
i
)
i
.
Class
AntiSymm
etric
{
A
}
(
R
S
:
relation
A
)
:
Prop
:
=
anti_symm
etric
:
∀
x
y
,
S
x
y
→
S
y
x
→
R
x
y
.
right_absorb
x
:
R
(
f
x
i
)
i
.
Class
AntiSymm
{
A
}
(
R
S
:
relation
A
)
:
Prop
:
=
anti_symm
x
y
:
S
x
y
→
S
y
x
→
R
x
y
.
Class
Total
{
A
}
(
R
:
relation
A
)
:
=
total
x
y
:
R
x
y
∨
R
y
x
.
Class
Trichotomy
{
A
}
(
R
:
relation
A
)
:
=
trichotomy
:
∀
x
y
,
R
x
y
∨
x
=
y
∨
R
y
x
.
trichotomy
x
y
:
R
x
y
∨
x
=
y
∨
R
y
x
.
Class
TrichotomyT
{
A
}
(
R
:
relation
A
)
:
=
trichotomyT
:
∀
x
y
,
{
R
x
y
}
+
{
x
=
y
}
+
{
R
y
x
}.
trichotomyT
x
y
:
{
R
x
y
}
+
{
x
=
y
}
+
{
R
y
x
}.
Arguments
irreflexivity
{
_
}
_
{
_
}
_
_
.
Arguments
inj
ective
{
_
_
_
_
}
_
{
_
}
_
_
_
.
Arguments
inj
ective
2
{
_
_
_
_
_
_
}
_
{
_
}
_
_
_
_
_
.
Arguments
inj
{
_
_
_
_
}
_
{
_
}
_
_
_
.
Arguments
inj2
{
_
_
_
_
_
_
}
_
{
_
}
_
_
_
_
_
.
Arguments
cancel
{
_
_
_
}
_
_
{
_
}
_
.
Arguments
surj
ective
{
_
_
_
}
_
{
_
}
_
.
Arguments
idemp
otent
{
_
_
}
_
{
_
}
_
.
Arguments
comm
utative
{
_
_
_
}
_
{
_
}
_
_
.
Arguments
surj
{
_
_
_
}
_
{
_
}
_
.
Arguments
idemp
{
_
_
}
_
{
_
}
_
.
Arguments
comm
{
_
_
_
}
_
{
_
}
_
_
.
Arguments
left_id
{
_
_
}
_
_
{
_
}
_
.
Arguments
right_id
{
_
_
}
_
_
{
_
}
_
.
Arguments
assoc
iative
{
_
_
}
_
{
_
}
_
_
_
.
Arguments
assoc
{
_
_
}
_
{
_
}
_
_
_
.
Arguments
left_absorb
{
_
_
}
_
_
{
_
}
_
.
Arguments
right_absorb
{
_
_
}
_
_
{
_
}
_
.
Arguments
anti_symm
etric
{
_
_
}
_
{
_
}
_
_
_
_
.
Arguments
anti_symm
{
_
_
}
_
{
_
}
_
_
_
_
.
Arguments
total
{
_
}
_
{
_
}
_
_
.
Arguments
trichotomy
{
_
}
_
{
_
}
_
_
.
Arguments
trichotomyT
{
_
}
_
{
_
}
_
_
.
Instance
id_inj
ective
{
A
}
:
Injective
(=)
(=)
(@
id
A
).
Instance
id_inj
{
A
}
:
Inj
(=)
(=)
(@
id
A
).
Proof
.
intros
??
;
auto
.
Qed
.
(** The following lemmas are specific versions of the projections of the above
type classes for Leibniz equality. These lemmas allow us to enforce Coq not to
use the setoid rewriting mechanism. *)
Lemma
idemp
otent_L
{
A
}
(
f
:
A
→
A
→
A
)
`
{!
Idempotent
(=)
f
}
x
:
f
x
x
=
x
.
Lemma
idemp
_L
{
A
}
(
f
:
A
→
A
→
A
)
`
{!
IdemP
(=)
f
}
x
:
f
x
x
=
x
.
Proof
.
auto
.
Qed
.
Lemma
comm
utative_L
{
A
B
}
(
f
:
B
→
B
→
A
)
`
{!
Commutative
(=)
f
}
x
y
:
Lemma
comm
_L
{
A
B
}
(
f
:
B
→
B
→
A
)
`
{!
Comm
(=)
f
}
x
y
:
f
x
y
=
f
y
x
.
Proof
.
auto
.
Qed
.
Lemma
left_id_L
{
A
}
(
i
:
A
)
(
f
:
A
→
A
→
A
)
`
{!
LeftId
(=)
i
f
}
x
:
f
i
x
=
x
.
Proof
.
auto
.
Qed
.
Lemma
right_id_L
{
A
}
(
i
:
A
)
(
f
:
A
→
A
→
A
)
`
{!
RightId
(=)
i
f
}
x
:
f
x
i
=
x
.
Proof
.
auto
.
Qed
.
Lemma
assoc
iative_L
{
A
}
(
f
:
A
→
A
→
A
)
`
{!
Associative
(=)
f
}
x
y
z
:
Lemma
assoc
_L
{
A
}
(
f
:
A
→
A
→
A
)
`
{!
Assoc
(=)
f
}
x
y
z
:
f
x
(
f
y
z
)
=
f
(
f
x
y
)
z
.
Proof
.
auto
.
Qed
.
Lemma
left_absorb_L
{
A
}
(
i
:
A
)
(
f
:
A
→
A
→
A
)
`
{!
LeftAbsorb
(=)
i
f
}
x
:
...
...
@@ -593,7 +593,7 @@ Proof. auto. Qed.
relation [R] instead of [⊆] to support multiple orders on the same type. *)
Class
PartialOrder
{
A
}
(
R
:
relation
A
)
:
Prop
:
=
{
partial_order_pre
:
>
PreOrder
R
;
partial_order_anti_symm
etric
:
>
AntiSymmetric
(=)
R
partial_order_anti_symm
:
>
AntiSymm
(=)
R
}.
Class
TotalOrder
{
A
}
(
R
:
relation
A
)
:
Prop
:
=
{
total_order_partial
:
>
PartialOrder
R
;
...
...
@@ -746,31 +746,17 @@ Proof. intuition. Qed.
Lemma
symmetry_iff
`
(
R
:
relation
A
)
`
{!
Symmetric
R
}
x
y
:
R
x
y
↔
R
y
x
.
Proof
.
intuition
.
Qed
.
(** ** Pointwise relations *)
(** These instances are in Coq trunk since revision 15455, but are not in Coq
8.4 yet. *)
Instance
pointwise_reflexive
{
A
}
`
{
R
:
relation
B
}
:
Reflexive
R
→
Reflexive
(
pointwise_relation
A
R
)
|
9
.
Proof
.
firstorder
.
Qed
.
Instance
pointwise_symmetric
{
A
}
`
{
R
:
relation
B
}
:
Symmetric
R
→
Symmetric
(
pointwise_relation
A
R
)
|
9
.
Proof
.
firstorder
.
Qed
.
Instance
pointwise_transitive
{
A
}
`
{
R
:
relation
B
}
:
Transitive
R
→
Transitive
(
pointwise_relation
A
R
)
|
9
.
Proof
.
firstorder
.
Qed
.
(** ** Unit *)
Instance
unit_equiv
:
Equiv
unit
:
=
λ
_
_
,
True
.
Instance
unit_equivalence
:
Equivalence
(@
equiv
unit
_
).
Proof
.
repeat
split
.
Qed
.
(** ** Products *)
Instance
prod_map_injective
{
A
A'
B
B'
}
(
f
:
A
→
A'
)
(
g
:
B
→
B'
)
:
Injective
(=)
(=)
f
→
Injective
(=)
(=)
g
→
Injective
(=)
(=)
(
prod_map
f
g
).
Instance
prod_map_inj
{
A
A'
B
B'
}
(
f
:
A
→
A'
)
(
g
:
B
→
B'
)
:
Inj
(=)
(=)
f
→
Inj
(=)
(=)
g
→
Inj
(=)
(=)
(
prod_map
f
g
).
Proof
.
intros
??
[??]
[??]
?
;
simpl
in
*
;
f_equal
;
[
apply
(
inj
ective
f
)|
apply
(
injective
g
)]
;
congruence
.
[
apply
(
inj
f
)|
apply
(
inj
g
)]
;
congruence
.
Qed
.
Definition
prod_relation
{
A
B
}
(
R1
:
relation
A
)
(
R2
:
relation
B
)
:
...
...
@@ -815,17 +801,17 @@ Lemma and_wlog_l (P Q : Prop) : (Q → P) → Q → (P ∧ Q).
Proof
.
tauto
.
Qed
.
Lemma
and_wlog_r
(
P
Q
:
Prop
)
:
P
→
(
P
→
Q
)
→
(
P
∧
Q
).
Proof
.
tauto
.
Qed
.
Instance
:
∀
A
B
(
x
:
B
),
Comm
utative
(=)
(
λ
_
_
:
A
,
x
).
Instance
:
∀
A
B
(
x
:
B
),
Comm
(=)
(
λ
_
_
:
A
,
x
).
Proof
.
red
.
trivial
.
Qed
.
Instance
:
∀
A
(
x
:
A
),
Assoc
iative
(=)
(
λ
_
_
:
A
,
x
).
Instance
:
∀
A
(
x
:
A
),
Assoc
(=)
(
λ
_
_
:
A
,
x
).
Proof
.
red
.
trivial
.
Qed
.
Instance
:
∀
A
,
Assoc
iative
(=)
(
λ
x
_
:
A
,
x
).
Instance
:
∀
A
,
Assoc
(=)
(
λ
x
_
:
A
,
x
).
Proof
.
red
.
trivial
.
Qed
.
Instance
:
∀
A
,
Assoc
iative
(=)
(
λ
_
x
:
A
,
x
).
Instance
:
∀
A
,
Assoc
(=)
(
λ
_
x
:
A
,
x
).
Proof
.
red
.
trivial
.
Qed
.
Instance
:
∀
A
,
Idem
potent
(=)
(
λ
x
_
:
A
,
x
).
Instance
:
∀
A
,
Idem
P
(=)
(
λ
x
_
:
A
,
x
).
Proof
.
red
.
trivial
.
Qed
.
Instance
:
∀
A
,
Idem
potent
(=)
(
λ
_
x
:
A
,
x
).
Instance
:
∀
A
,
Idem
P
(=)
(
λ
_
x
:
A
,
x
).
Proof
.
red
.
trivial
.
Qed
.
Instance
left_id_propholds
{
A
}
(
R
:
relation
A
)
i
f
:
...
...
@@ -841,7 +827,7 @@ Instance right_absorb_propholds {A} (R : relation A) i f :
RightAbsorb
R
i
f
→
∀
x
,
PropHolds
(
R
(
f
x
i
)
i
).
Proof
.
red
.
trivial
.
Qed
.
Instance
idem_propholds
{
A
}
(
R
:
relation
A
)
f
:
Idem
potent
R
f
→
∀
x
,
PropHolds
(
R
(
f
x
x
)
x
).
Idem
P
R
f
→
∀
x
,
PropHolds
(
R
(
f
x
x
)
x
).
Proof
.
red
.
trivial
.
Qed
.
Instance
:
∀
`
{
R1
:
relation
A
,
R2
:
relation
B
}
(
x
:
B
),
...
...
@@ -849,47 +835,47 @@ Instance: ∀ `{R1 : relation A, R2 : relation B} (x : B),
Proof
.
intros
A
R1
B
R2
x
?
y1
y2
;
reflexivity
.
Qed
.
Instance
:
@
PreOrder
A
(=).
Proof
.
split
;
repeat
intro
;
congruence
.
Qed
.
Lemma
inj
ective
_iff
{
A
B
}
{
R
:
relation
A
}
{
S
:
relation
B
}
(
f
:
A
→
B
)
`
{!
Inj
ective
R
S
f
}
`
{!
Proper
(
R
==>
S
)
f
}
x
y
:
S
(
f
x
)
(
f
y
)
↔
R
x
y
.
Lemma
inj_iff
{
A
B
}
{
R
:
relation
A
}
{
S
:
relation
B
}
(
f
:
A
→
B
)
`
{!
Inj
R
S
f
}
`
{!
Proper
(
R
==>
S
)
f
}
x
y
:
S
(
f
x
)
(
f
y
)
↔
R
x
y
.
Proof
.
firstorder
.
Qed
.
Instance
:
Inj
ective
(=)
(=)
(@
inl
A
B
).
Instance
:
Inj
(=)
(=)
(@
inl
A
B
).
Proof
.
injection
1
;
auto
.
Qed
.
Instance
:
Inj
ective
(=)
(=)
(@
inr
A
B
).
Instance
:
Inj
(=)
(=)
(@
inr
A
B
).
Proof
.
injection
1
;
auto
.
Qed
.
Instance
:
Inj
ective
2
(=)
(=)
(=)
(@
pair
A
B
).
Instance
:
Inj2
(=)
(=)
(=)
(@
pair
A
B
).
Proof
.
injection
1
;
auto
.
Qed
.
Instance
:
∀
`
{
Inj
ective2
A
B
C
R1
R2
R3
f
}
y
,
Injective
R1
R3
(
λ
x
,
f
x
y
).
Proof
.
repeat
intro
;
edestruct
(
inj
ective
2
f
)
;
eauto
.
Qed
.
Instance
:
∀
`
{
Inj
ective2
A
B
C
R1
R2
R3
f
}
x
,
Injective
R2
R3
(
f
x
).
Proof
.
repeat
intro
;
edestruct
(
inj
ective
2
f
)
;
eauto
.
Qed
.
Instance
:
∀
`
{
Inj
2
A
B
C
R1
R2
R3
f
}
y
,
Inj
R1
R3
(
λ
x
,
f
x
y
).
Proof
.
repeat
intro
;
edestruct
(
inj2
f
)
;
eauto
.
Qed
.
Instance
:
∀
`
{
Inj
2
A
B
C
R1
R2
R3
f
}
x
,
Inj
R2
R3
(
f
x
).
Proof
.
repeat
intro
;
edestruct
(
inj2
f
)
;
eauto
.
Qed
.
Lemma
cancel_inj
ective
`
{
Cancel
A
B
R1
f
g
}
`
{!
Equivalence
R1
}
`
{!
Proper
(
R2
==>
R1
)
f
}
:
Inj
ective
R1
R2
g
.
Lemma
cancel_inj
`
{
Cancel
A
B
R1
f
g
}
`
{!
Equivalence
R1
}
`
{!
Proper
(
R2
==>
R1
)
f
}
:
Inj
R1
R2
g
.
Proof
.
intros
x
y
E
.
rewrite
<-(
cancel
f
g
x
),
<-(
cancel
f
g
y
),
E
.
reflexivity
.
Qed
.
Lemma
cancel_surj
ective
`
{
Cancel
A
B
R1
f
g
}
:
Surjective
R1
f
.
Lemma
cancel_surj
`
{
Cancel
A
B
R1
f
g
}
:
Surj
R1
f
.
Proof
.
intros
y
.
exists
(
g
y
).
auto
.
Qed
.
Lemma
impl_transitive
(
P
Q
R
:
Prop
)
:
(
P
→
Q
)
→
(
Q
→
R
)
→
(
P
→
R
).
Proof
.
tauto
.
Qed
.
Instance
:
Comm
utative
(
↔
)
(@
eq
A
).
Instance
:
Comm
(
↔
)
(@
eq
A
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Comm
utative
(
↔
)
(
λ
x
y
,
@
eq
A
y
x
).
Instance
:
Comm
(
↔
)
(
λ
x
y
,
@
eq
A
y
x
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Comm
utative
(
↔
)
(
↔
).
Instance
:
Comm
(
↔
)
(
↔
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Comm
utative
(
↔
)
(
∧
).
Instance
:
Comm
(
↔
)
(
∧
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Assoc
iative
(
↔
)
(
∧
).
Instance
:
Assoc
(
↔
)
(
∧
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Idem
potent
(
↔
)
(
∧
).
Instance
:
Idem
P
(
↔
)
(
∧
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Comm
utative
(
↔
)
(
∨
).
Instance
:
Comm
(
↔
)
(
∨
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Assoc
iative
(
↔
)
(
∨
).
Instance
:
Assoc
(
↔
)
(
∨
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
Idem
potent
(
↔
)
(
∨
).
Instance
:
Idem
P
(
↔
)
(
∨
).
Proof
.
red
;
intuition
.
Qed
.
Instance
:
LeftId
(
↔
)
True
(
∧
).
Proof
.
red
;
intuition
.
Qed
.
...
...
@@ -911,26 +897,26 @@ Instance: LeftId (↔) True impl.
Proof
.
unfold
impl
.
red
;
intuition
.
Qed
.
Instance
:
RightAbsorb
(
↔
)
True
impl
.
Proof
.
unfold
impl
.
red
;
intuition
.
Qed
.
Lemma
not_inj
ective
`
{
Injective
A
B
R
R'
f
}
x
y
:
¬
R
x
y
→
¬
R'
(
f
x
)
(
f
y
).
Lemma
not_inj
`
{
Inj
A
B
R
R'
f
}
x
y
:
¬
R
x
y
→
¬
R'
(
f
x
)
(
f
y
).
Proof
.
intuition
.
Qed
.
Instance
inj
ective
_compose
{
A
B
C
}
R1
R2
R3
(
f
:
A
→
B
)
(
g
:
B
→
C
)
:
Inj
ective
R1
R2
f
→
Injective
R2
R3
g
→
Injective
R1
R3
(
g
∘
f
).
Instance
inj_compose
{
A
B
C
}
R1
R2
R3
(
f
:
A
→
B
)
(
g
:
B
→
C
)
:
Inj
R1
R2
f
→
Inj
R2
R3
g
→
Inj
R1
R3
(
g
∘
f
).
Proof
.
red
;
intuition
.
Qed
.
Instance
surj
ective
_compose
{
A
B
C
}
R
(
f
:
A
→
B
)
(
g
:
B
→
C
)
:
Surj
ective
(=)
f
→
Surjective
R
g
→
Surjective
R
(
g
∘
f
).
Instance
surj_compose
{
A
B
C
}
R
(
f
:
A
→
B
)
(
g
:
B
→
C
)
:
Surj
(=)
f
→
Surj
R
g
→
Surj
R
(
g
∘
f
).
Proof
.
intros
??
x
.
unfold
compose
.
destruct
(
surj
ective
g
x
)
as
[
y
?].
destruct
(
surj
ective
f
y
)
as
[
z
?].
exists
z
.
congruence
.
intros
??
x
.
unfold
compose
.
destruct
(
surj
g
x
)
as
[
y
?].
destruct
(
surj
f
y
)
as
[
z
?].
exists
z
.
congruence
.
Qed
.
Section
sig_map
.
Context
`
{
P
:
A
→
Prop
}
`
{
Q
:
B
→
Prop
}
(
f
:
A
→
B
)
(
Hf
:
∀
x
,
P
x
→
Q
(
f
x
)).
Definition
sig_map
(
x
:
sig
P
)
:
sig
Q
:
=
f
(
`
x
)
↾
Hf
_
(
proj2_sig
x
).
Global
Instance
sig_map_inj
ective
:
(
∀
x
,
ProofIrrel
(
P
x
))
→
Inj
ective
(=)
(=)
f
→
Injective
(=)
(=)
sig_map
.
Global
Instance
sig_map_inj
:
(
∀
x
,
ProofIrrel
(
P
x
))
→
Inj
(=)
(=)
f
→
Inj
(=)
(=)
sig_map
.
Proof
.
intros
??
[
x
Hx
]
[
y
Hy
].
injection
1
.
intros
Hxy
.
apply
(
inj
ective
f
)
in
Hxy
;
subst
.
rewrite
(
proof_irrel
_
Hy
).
auto
.
apply
(
inj
f
)
in
Hxy
;
subst
.
rewrite
(
proof_irrel
_
Hy
).
auto
.
Qed
.
End
sig_map
.
Arguments
sig_map
_
_
_
_
_
_
!
_
/.
theories/countable.v
View file @
44b18f4d
...
...
@@ -15,13 +15,13 @@ Definition encode_nat `{Countable A} (x : A) : nat :=
pred
(
Pos
.
to_nat
(
encode
x
)).
Definition
decode_nat
`
{
Countable
A
}
(
i
:
nat
)
:
option
A
:
=
decode
(
Pos
.
of_nat
(
S
i
)).
Instance
encode_inj
ective
`
{
Countable
A
}
:
Injective
(=)
(=)
encode
.
Instance
encode_inj
`
{
Countable
A
}
:
Inj
(=)
(=)
encode
.
Proof
.
intros
x
y
Hxy
;
apply
(
inj
ective
Some
).
intros
x
y
Hxy
;
apply
(
inj
Some
).
by
rewrite
<-(
decode_encode
x
),
Hxy
,
decode_encode
.
Qed
.
Instance
encode_nat_inj
ective
`
{
Countable
A
}
:
Injective
(=)
(=)
encode_nat
.
Proof
.
unfold
encode_nat
;
intros
x
y
Hxy
;
apply
(
inj
ective
encode
)
;
lia
.
Qed
.
Instance
encode_nat_inj
`
{
Countable
A
}
:
Inj
(=)
(=)
encode_nat
.
Proof
.
unfold
encode_nat
;
intros
x
y
Hxy
;
apply
(
inj
encode
)
;
lia
.
Qed
.
Lemma
decode_encode_nat
`
{
Countable
A
}
x
:
decode_nat
(
encode_nat
x
)
=
Some
x
.
Proof
.
pose
proof
(
Pos2Nat
.
is_pos
(
encode
x
)).
...
...
@@ -70,11 +70,11 @@ Section choice.
Definition
choice
(
HA
:
∃
x
,
P
x
)
:
{
x
|
P
x
}
:
=
_
↾
choose_correct
HA
.
End
choice
.
Lemma
surj
ective
_cancel
`
{
Countable
A
}
`
{
∀
x
y
:
B
,
Decision
(
x
=
y
)}
(
f
:
A
→
B
)
`
{!
Surj
ective
(=)
f
}
:
{
g
:
B
→
A
&
Cancel
(=)
f
g
}.
Lemma
surj_cancel
`
{
Countable
A
}
`
{
∀
x
y
:
B
,
Decision
(
x
=
y
)}
(
f
:
A
→
B
)
`
{!
Surj
(=)
f
}
:
{
g
:
B
→
A
&
Cancel
(=)
f
g
}.
Proof
.
exists
(
λ
y
,
choose
(
λ
x
,
f
x
=
y
)
(
surj
ective
f
y
)).
intros
y
.
by
rewrite
(
choose_correct
(
λ
x
,
f
x
=
y
)
(
surj
ective
f
y
)).
exists
(
λ
y
,
choose
(
λ
x
,
f
x
=
y
)
(
surj
f
y
)).
intros
y
.
by
rewrite
(
choose_correct
(
λ
x
,
f
x
=
y
)
(
surj
f
y
)).
Qed
.
(** * Instances *)
...
...
@@ -197,7 +197,7 @@ Lemma list_encode_app' `{Countable A} (l1 l2 : list A) acc :
Proof
.
revert
acc
;
induction
l1
;
simpl
;
auto
.
induction
l2
as
[|
x
l
IH
]
;
intros
acc
;
simpl
;
[
by
rewrite
?(
left_id_L
_
_
)|].
by
rewrite
!(
IH
(
Nat
.
iter
_
_
_
)),
(
assoc
iative
_L
_
),
x0_iter_x1
.
by
rewrite
!(
IH
(
Nat
.
iter
_
_
_
)),
(
assoc_L
_
),
x0_iter_x1
.
Qed
.
Program
Instance
list_countable
`
{
Countable
A
}
:
Countable
(
list
A
)
:
=
{|
encode
:
=
list_encode
1
;
decode
:
=
list_decode
[]
0
|}.
...
...
@@ -211,7 +211,7 @@ Next Obligation.
{
by
intros
help
l
;
rewrite
help
,
(
right_id_L
_
_
).
}
induction
l
as
[|
x
l
IH
]
using
@
rev_ind
;
intros
acc
;
[
done
|].
rewrite
list_encode_app'
;
simpl
;
rewrite
<-
x0_iter_x1
,
decode_iter
;
simpl
.
by
rewrite
decode_encode_nat
;
simpl
;
rewrite
IH
,
<-(
assoc
iative
_L
_
).
by
rewrite
decode_encode_nat
;
simpl
;
rewrite
IH
,
<-(
assoc_L
_
).
Qed
.
Lemma
list_encode_app
`
{
Countable
A
}
(
l1
l2
:
list
A
)
:
encode
(
l1
++
l2
)%
list
=
encode
l1
++
encode
l2
.
...
...
theories/decidable.v
View file @
44b18f4d
...
...
@@ -12,7 +12,7 @@ Proof. firstorder. Qed.
Lemma
Is_true_reflect
(
b
:
bool
)
:
reflect
b
b
.
Proof
.
destruct
b
.
by
left
.
right
.
intros
[].
Qed
.
Instance
:
Inj
ective
(=)
(
↔
)
Is_true
.
Instance
:
Inj
(=)
(
↔
)
Is_true
.
Proof
.
intros
[]
[]
;
simpl
;
intuition
.
Qed
.
(** We introduce [decide_rel] to avoid inefficienct computation due to eager
...
...
theories/error.v
View file @
44b18f4d
...
...
@@ -47,7 +47,7 @@ Lemma error_fmap_bind {S E A B C} (f : A → B) (g : B → error S E C) x s :
((
f
<$>
x
)
≫
=
g
)
s
=
(
x
≫
=
g
∘
f
)
s
.
Proof
.
by
compute
;
destruct
(
x
s
)
as
[|[??]].
Qed
.
Lemma
error_assoc
iative
{
S
E
A
B
C
}
(
f
:
A
→
error
S
E
B
)
(
g
:
B
→
error
S
E
C
)
x
s
:
Lemma
error_assoc
{
S
E
A
B
C
}
(
f
:
A
→
error
S
E
B
)
(
g
:
B
→
error
S
E
C
)
x
s
:
((
x
≫
=
f
)
≫
=
g
)
s
=
(
a
←
x
;
f
a
≫
=
g
)
s
.
Proof
.
by
compute
;
destruct
(
x
s
)
as
[|[??]].
Qed
.
Lemma
error_of_option_bind
{
S
E
A
B
}
(
f
:
A
→
option
B
)
o
e
:
...
...
@@ -114,7 +114,7 @@ Tactic Notation "error_proceed" :=
|
H
:
(
gets
_
≫
=
_
)
_
=
_
|-
_
=>
rewrite
error_left_gets
in
H
|
H
:
(
modify
_
≫
=
_
)
_
=
_
|-
_
=>
rewrite
error_left_modify
in
H
|
H
:
((
_
<$>
_
)
≫
=
_
)
_
=
_
|-
_
=>
rewrite
error_fmap_bind
in
H
|
H
:
((
_
≫
=
_
)
≫
=
_
)
_
=
_
|-
_
=>
rewrite
error_assoc
iative
in
H
|
H
:
((
_
≫
=
_
)
≫
=
_
)
_
=
_
|-
_
=>
rewrite
error_assoc
in
H
|
H
:
(
error_guard
_
_
_
)
_
=
_
|-
_
=>
let
H'
:
=
fresh
in
apply
error_guard_ret
in
H
;
destruct
H
as
[
H'
H
]
|
_
=>
progress
simplify_equality'
...
...
theories/fin_collections.v
View file @
44b18f4d
...
...
@@ -108,7 +108,7 @@ Lemma size_union_alt X Y : size (X ∪ Y) = size X + size (Y ∖ X).
Proof
.
rewrite
<-
size_union
by
solve_elem_of
.
setoid_replace
(
Y
∖
X
)
with
((
Y
∪
X
)
∖
X
)
by
solve_elem_of
.
rewrite
<-
union_difference
,
(
comm
utative
(
∪
))
;
solve_elem_of
.
rewrite
<-
union_difference
,
(
comm
(
∪
))
;
solve_elem_of
.
Qed
.
Lemma
subseteq_size
X
Y
:
X
⊆
Y
→
size
X
≤
size
Y
.
Proof
.
intros
.
rewrite
(
union_difference
X
Y
),
size_union_alt
by
done
.
lia
.
Qed
.
...
...
theories/fin_maps.v
View file @
44b18f4d
...
...
@@ -820,28 +820,28 @@ Proof.
intros
??.
apply
map_eq
.
intros
.
by
rewrite
!(
lookup_merge
f
),
lookup_empty
,
(
right_id_L
None
f
).
Qed
.
Lemma
merge_comm
utative
m1
m2
:
Lemma
merge_comm
m1
m2
:
(
∀
i
,
f
(
m1
!!
i
)
(
m2
!!
i
)
=
f
(
m2
!!
i
)
(
m1
!!
i
))
→
merge
f
m1
m2
=
merge
f
m2
m1
.
Proof
.
intros
.
apply
map_eq
.
intros
.
by
rewrite
!(
lookup_merge
f
).
Qed
.
Global
Instance
:
Comm
utative
(=)
f
→
Commutative
(=)
(
merge
f
).
Global
Instance
:
Comm
(=)
f
→
Comm
(=)
(
merge
f
).
Proof
.
intros
???.
apply
merge_comm
utative
.
intros
.
by
apply
(
commutative
f
).
intros
???.
apply
merge_comm
.
intros
.
by
apply
(
comm
f
).
Qed
.
Lemma
merge_assoc
iative
m1
m2
m3
:
Lemma
merge_assoc
m1
m2
m3
:
(
∀
i
,
f
(
m1
!!
i
)
(
f
(
m2
!!
i
)
(
m3
!!
i
))
=
f
(
f
(
m1
!!
i
)
(
m2
!!
i
))
(
m3
!!
i
))
→
merge
f
m1
(
merge
f
m2
m3
)
=
merge
f
(
merge
f
m1
m2
)
m3
.
Proof
.
intros
.
apply
map_eq
.
intros
.
by
rewrite
!(
lookup_merge
f
).
Qed
.
Global
Instance
:
Assoc
iative
(=)
f
→
Associative
(=)
(
merge
f
).
Global
Instance
:
Assoc
(=)
f
→
Assoc
(=)
(
merge
f
).
Proof
.
intros
????.
apply
merge_assoc
iative
.
intros
.
by
apply
(
associative
_L
f
).
intros
????.
apply
merge_assoc
.
intros
.
by
apply
(
assoc
_L
f
).
Qed
.
Lemma
merge_idemp
otent
m1
:
Lemma
merge_idemp
m1
:
(
∀
i
,
f
(
m1
!!
i
)
(
m1
!!
i
)
=
m1
!!
i
)
→
merge
f
m1
m1
=
m1
.
Proof
.
intros
.
apply
map_eq
.
intros
.
by
rewrite
!(
lookup_merge
f
).
Qed
.
Global
Instance
:
Idem
potent
(=)
f
→
Idempotent
(=)
(
merge
f
).
Proof
.
intros
??.
apply
merge_idemp
otent
.
intros
.
by
apply
(
idempotent
f
).
Qed
.
Global
Instance
:
Idem
P
(=)
f
→
IdemP
(=)
(
merge
f
).
Proof
.
intros
??.
apply
merge_idemp
.
intros
.
by
apply
(
idemp
f
).
Qed
.
End
merge
.
Section
more_merge
.
...
...
@@ -1033,19 +1033,19 @@ Global Instance: LeftId (@eq (M A)) ∅ (union_with f).
Proof
.
unfold
union_with
,
map_union_with
.
apply
_
.
Qed
.
Global
Instance
:
RightId
(@
eq
(
M
A
))
∅
(
union_with
f
).
Proof
.
unfold
union_with
,
map_union_with
.
apply
_
.
Qed
.
Lemma
union_with_comm
utative
m1
m2
:
Lemma
union_with_comm
m1
m2
:
(
∀
i
x
y
,
m1
!!
i
=
Some
x
→
m2
!!
i
=
Some
y
→
f
x
y
=
f
y
x
)
→
union_with
f
m1
m2
=
union_with
f
m2
m1
.
Proof
.
intros
.
apply
(
merge_comm
utative
_
).
intros
i
.
intros
.
apply
(
merge_comm
_
).
intros
i
.
destruct
(
m1
!!
i
)
eqn
:
?,
(
m2
!!
i
)
eqn
:
?
;
simpl
;
eauto
.
Qed
.
Global
Instance
:
Comm
utative
(=)
f
→
Commutative
(@
eq
(
M
A
))
(
union_with
f
).
Proof
.
intros
???.
apply
union_with_comm
utative
.
eauto
.
Qed
.
Lemma
union_with_idemp
otent
m
:
Global
Instance
:
Comm
(=)
f
→
Comm
(@
eq
(
M
A
))
(
union_with
f
).
Proof
.
intros
???.
apply
union_with_comm
.
eauto
.
Qed
.
Lemma
union_with_idemp
m
:
(
∀
i
x
,
m
!!
i
=
Some
x
→
f
x
x
=
Some
x
)
→
union_with
f
m
m
=
m
.
Proof
.
intros
.
apply
(
merge_idemp
otent
_
).
intros
i
.
intros
.
apply
(
merge_idemp
_
).
intros
i
.
destruct
(
m
!!
i
)
eqn
:
?
;
simpl
;
eauto
.
Qed
.
Lemma
alter_union_with
(
g
:
A
→
A
)
m1
m2
i
:
...
...
@@ -1100,14 +1100,14 @@ End union_with.
(** ** Properties of the [union] operation *)
Global
Instance
:
LeftId
(@
eq
(
M
A
))
∅
(
∪
)
:
=
_
.
Global
Instance
:
RightId
(@
eq
(
M
A
))
∅
(
∪
)
:
=
_
.
Global
Instance
:
Assoc
iative
(@
eq
(
M
A
))
(
∪
).
Global
Instance
:
Assoc
(@
eq
(
M
A
))
(
∪
).
Proof
.
intros
A
m1
m2
m3
.
unfold
union
,
map_union
,
union_with
,
map_union_with
.
apply
(
merge_assoc
iative
_
).
intros
i
.
apply
(
merge_assoc
_
).
intros
i
.
by
destruct
(
m1
!!
i
),
(
m2
!!
i
),
(
m3
!!
i
).
Qed
.
Global
Instance
:
Idem
potent
(@
eq
(
M
A
))
(
∪
).
Proof
.
intros
A
?.
by
apply
union_with_idemp
otent
.
Qed
.
Global
Instance
:
Idem
P
(@
eq
(
M
A
))
(
∪
).
Proof
.
intros
A
?.
by
apply
union_with_idemp
.
Qed
.
Lemma
lookup_union_Some_raw
{
A
}
(
m1
m2
:
M
A
)
i
x
:
(
m1
∪
m2
)
!!
i
=
Some
x
↔
m1
!!
i
=
Some
x
∨
(
m1
!!
i
=
None
∧
m2
!!
i
=
Some
x
).
...
...
@@ -1140,9 +1140,9 @@ Proof. intro. rewrite lookup_union_Some_raw; intuition. Qed.
Lemma
lookup_union_Some_r
{
A
}
(
m1
m2
:
M
A
)
i
x
:
m1
⊥
ₘ
m2
→
m2
!!
i
=
Some
x
→
(
m1
∪
m2
)
!!
i
=
Some
x
.
Proof
.
intro
.
rewrite
lookup_union_Some
;
intuition
.
Qed
.
Lemma
map_union_comm
utative
{
A
}
(
m1
m2
:
M
A
)
:
m1
⊥
ₘ
m2
→
m1
∪
m2
=
m2
∪
m1
.
Lemma
map_union_comm
{
A
}
(
m1
m2
:
M
A
)
:
m1
⊥
ₘ
m2
→
m1
∪
m2
=
m2
∪
m1
.
Proof
.
intros
Hdisjoint
.
apply
(
merge_comm
utative
(
union_with
(
λ
x
_
,
Some
x
))).
intros
Hdisjoint
.
apply
(
merge_comm
(
union_with
(
λ
x
_
,
Some
x
))).
intros
i
.
specialize
(
Hdisjoint
i
).
destruct
(
m1
!!
i
),
(
m2
!!
i
)
;
compute
;
naive_solver
.
Qed
.
...
...
@@ -1160,7 +1160,7 @@ Proof.
Qed
.
Lemma
map_union_subseteq_r
{
A
}
(
m1
m2
:
M
A
)
:
m1
⊥
ₘ
m2
→
m2
⊆
m1
∪
m2
.
Proof
.
intros
.
rewrite
map_union_comm
utative
by
done
.
by
apply
map_union_subseteq_l
.
intros
.
rewrite
map_union_comm
by
done
.
by
apply
map_union_subseteq_l
.
Qed
.
Lemma
map_union_subseteq_l_alt
{
A
}
(
m1
m2
m3
:
M
A
)
:
m1
⊆
m2
→
m1
⊆
m2
∪
m3
.
Proof
.
intros
.
transitivity
m2
;
auto
using
map_union_subseteq_l
.
Qed
.
...
...
@@ -1175,7 +1175,7 @@ Qed.
Lemma
map_union_preserving_r
{
A
}
(
m1
m2
m3
:
M
A
)
:
m2
⊥
ₘ
m3
→
m1
⊆
m2
→
m1
∪
m3
⊆
m2
∪
m3
.
Proof
.
intros
.
rewrite
!(
map_union_comm
utative
_
m3
)
intros
.
rewrite
!(
map_union_comm
_
m3
)
by
eauto
using
map_disjoint_weaken_l
.
by
apply
map_union_preserving_l
.
Qed
.
...
...
@@ -1189,19 +1189,19 @@ Qed.
Lemma
map_union_reflecting_r
{
A
}
(
m1
m2
m3
:
M
A
)
:
m1
⊥
ₘ
m3
→
m2
⊥
ₘ
m3
→
m1
∪
m3
⊆
m2
∪
m3
→
m1
⊆
m2
.
Proof
.
intros
??.
rewrite
!(
map_union_comm
utative
_
m3
)
by
done
.
intros
??.
rewrite
!(
map_union_comm
_
m3
)
by
done
.
by
apply
map_union_reflecting_l
.
Qed
.
Lemma
map_union_cancel_l
{
A
}
(
m1
m2
m3
:
M
A
)
:
m1
⊥
ₘ
m3
→
m2
⊥
ₘ
m3
→
m3
∪
m1
=
m3
∪
m2
→
m1
=
m2
.
Proof
.
intros
.
apply
(
anti_symm
etric
(
⊆
))
;
intros
.
apply
(
anti_symm
(
⊆
))
;
apply
map_union_reflecting_l
with
m3
;
auto
using
(
reflexive_eq
(
R
:
=(
⊆
))).
Qed
.
Lemma
map_union_cancel_r
{
A
}
(
m1
m2
m3
:
M
A
)
:
m1
⊥
ₘ
m3
→
m2
⊥
ₘ
m3
→
m1
∪
m3
=
m2
∪
m3
→
m1
=
m2
.
Proof
.
intros
.
apply
(
anti_symm
etric
(
⊆
))
;
intros
.
apply
(
anti_symm
(
⊆
))
;
apply
map_union_reflecting_r
with
m3
;
auto
using
(
reflexive_eq
(
R
:
=(
⊆
))).
Qed
.