Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stdpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Iris
stdpp
Commits
d101c562
Commit
d101c562
authored
9 years ago
by
Robbert Krebbers
Browse files
Options
Downloads
Patches
Plain Diff
Indexed map function for finite maps.
parent
c5bdf622
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theories/fin_maps.v
+23
-0
23 additions, 0 deletions
theories/fin_maps.v
with
23 additions
and
0 deletions
theories/fin_maps.v
+
23
−
0
View file @
d101c562
...
@@ -104,6 +104,12 @@ index contains a value in the second map as well. *)
...
@@ -104,6 +104,12 @@ index contains a value in the second map as well. *)
Instance
map_difference
`{
Merge
M
}
{
A
}
:
Difference
(
M
A
)
:=
Instance
map_difference
`{
Merge
M
}
{
A
}
:
Difference
(
M
A
)
:=
difference_with
(
λ
_
_,
None
)
.
difference_with
(
λ
_
_,
None
)
.
(** A stronger variant of map that allows the mapped function to use the index
of the elements. Implemented by conversion to lists, so not very efficient. *)
Definition
map_imap
`{
∀
A
,
Insert
K
A
(
M
A
),
∀
A
,
Empty
(
M
A
),
∀
A
,
FinMapToList
K
A
(
M
A
)}
{
A
B
}
(
f
:
K
→
A
→
option
B
)
(
m
:
M
A
)
:
M
B
:=
map_of_list
(
omap
(
λ
ix
,
(
fst
ix
,)
<$>
curry
f
ix
)
(
map_to_list
m
))
.
(** * Theorems *)
(** * Theorems *)
Section
theorems
.
Section
theorems
.
Context
`{
FinMap
K
M
}
.
Context
`{
FinMap
K
M
}
.
...
@@ -585,6 +591,23 @@ Proof.
...
@@ -585,6 +591,23 @@ Proof.
exists
i
x
.
rewrite
<-
elem_of_map_to_list
,
Hm
.
by
left
.
exists
i
x
.
rewrite
<-
elem_of_map_to_list
,
Hm
.
by
left
.
Qed
.
Qed
.
(** Properties of the imap function *)
Lemma
lookup_imap
{
A
B
}
(
f
:
K
→
A
→
option
B
)
m
i
:
map_imap
f
m
!!
i
=
m
!!
i
≫=
f
i
.
Proof
.
unfold
map_imap
;
destruct
(
m
!!
i
≫=
f
i
)
as
[
y
|]
eqn
:
Hi
;
simpl
.
*
destruct
(
m
!!
i
)
as
[
x
|]
eqn
:?;
simplify_equality'
.
apply
elem_of_map_of_list_1_help
.
{
apply
elem_of_list_omap
;
exists
(
i
,
x
);
split
;
[
by
apply
elem_of_map_to_list
|
by
simplify_option_equality
]
.
}
intros
y'
;
rewrite
elem_of_list_omap
;
intros
([
i'
x'
]
&
Hi'
&
?)
.
by
rewrite
elem_of_map_to_list
in
Hi'
;
simplify_option_equality
.
*
apply
not_elem_of_map_of_list
;
rewrite
elem_of_list_fmap
.
intros
([
i'
x
]
&
->
&
Hi'
);
simplify_equality'
.
rewrite
elem_of_list_omap
in
Hi'
;
destruct
Hi'
as
([
j
y
]
&
Hj
&
?)
.
rewrite
elem_of_map_to_list
in
Hj
;
simplify_option_equality
.
Qed
.
(** ** Properties of conversion from collections *)
(** ** Properties of conversion from collections *)
Lemma
lookup_map_of_collection
{
A
}
`{
FinCollection
K
C
}
Lemma
lookup_map_of_collection
{
A
}
`{
FinCollection
K
C
}
(
f
:
K
→
option
A
)
X
i
x
:
(
f
:
K
→
option
A
)
X
i
x
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment