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
Merge requests
!145
Add `encode_Z` function to encode element of countable type as `Z`.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add `encode_Z` function to encode element of countable type as `Z`.
robbert/encode_Z
into
master
Overview
5
Commits
1
Pipelines
0
Changes
2
Merged
Robbert Krebbers
requested to merge
robbert/encode_Z
into
master
5 years ago
Overview
5
Commits
1
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
master
version 1
e4ea3a2c
5 years ago
master (base)
and
latest version
latest version
94b04a14
1 commit,
5 years ago
version 1
e4ea3a2c
1 commit,
5 years ago
2 files
+
16
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
theories/countable.v
+
14
−
4
Options
@@ -12,15 +12,16 @@ Hint Mode Countable ! - : typeclass_instances.
Arguments
encode
:
simpl
never
.
Arguments
decode
:
simpl
never
.
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
`{
Countable
A
}
:
Inj
(
=
)
(
=
)
(
encode
(
A
:=
A
))
.
Proof
.
intros
x
y
Hxy
;
apply
(
inj
Some
)
.
by
rewrite
<-
(
decode_encode
x
),
Hxy
,
decode_encode
.
Qed
.
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_nat_inj
`{
Countable
A
}
:
Inj
(
=
)
(
=
)
(
encode_nat
(
A
:=
A
))
.
Proof
.
unfold
encode_nat
;
intros
x
y
Hxy
;
apply
(
inj
encode
);
lia
.
Qed
.
Lemma
decode_encode_nat
`{
Countable
A
}
(
x
:
A
)
:
decode_nat
(
encode_nat
x
)
=
Some
x
.
@@ -30,6 +31,15 @@ Proof.
by
rewrite
Pos2Nat
.
id
,
decode_encode
.
Qed
.
Definition
encode_Z
`{
Countable
A
}
(
x
:
A
)
:
Z
:=
Zpos
(
encode
x
)
.
Definition
decode_Z
`{
Countable
A
}
(
i
:
Z
)
:
option
A
:=
match
i
with
Zpos
i
=>
decode
i
|
_
=>
None
end
.
Instance
encode_Z_inj
`{
Countable
A
}
:
Inj
(
=
)
(
=
)
(
encode_Z
(
A
:=
A
))
.
Proof
.
unfold
encode_Z
;
intros
x
y
Hxy
;
apply
(
inj
encode
);
lia
.
Qed
.
Lemma
decode_encode_Z
`{
Countable
A
}
(
x
:
A
)
:
decode_Z
(
encode_Z
x
)
=
Some
x
.
Proof
.
apply
decode_encode
.
Qed
.
(** * Choice principles *)
Section
choice
.
Context
`{
Countable
A
}
(
P
:
A
→
Prop
)
.
Loading