Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sophie Quinton
rt-proofs
Commits
839079c7
Commit
839079c7
authored
Apr 03, 2017
by
Felipe Cerqueira
Browse files
Add more lemmas about pick
parent
3a2bf991
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
61 deletions
+127
-61
util/pick.v
util/pick.v
+127
-61
No files found.
util/pick.v
View file @
839079c7
...
@@ -53,10 +53,8 @@ Notation "[ 'pick-max' x < N | P ]" :=
...
@@ -53,10 +53,8 @@ Notation "[ 'pick-max' x < N | P ]" :=
(
pick_max
N
(
fun
x
:
'
I_N
=>
P
%
B
))
(
pick_max
N
(
fun
x
:
'
I_N
=>
P
%
B
))
(
at
level
0
,
x
ident
,
only
parsing
)
:
form_scope
.
(
at
level
0
,
x
ident
,
only
parsing
)
:
form_scope
.
(** Lemmas *)
(** Lemmas
about pick_any
*)
(* First, we show that any property P of (pick_any n p) can be proven by showing that
P holds for any number < n that satisfies p. *)
Section
PickAny
.
Section
PickAny
.
Variable
n
:
nat
.
Variable
n
:
nat
.
...
@@ -68,6 +66,8 @@ Section PickAny.
...
@@ -68,6 +66,8 @@ Section PickAny.
Hypothesis
HOLDS
:
forall
x
,
p
x
->
P
x
.
Hypothesis
HOLDS
:
forall
x
,
p
x
->
P
x
.
(* First, we show that any property P of (pick_any n p) can be proven by showing
that P holds for any number < n that satisfies p. *)
Lemma
pick_any_holds
:
P
(
pick_any
n
p
).
Lemma
pick_any_holds
:
P
(
pick_any
n
p
).
Proof
.
Proof
.
rewrite
/
pick_any
/
default0
.
rewrite
/
pick_any
/
default0
.
...
@@ -79,8 +79,7 @@ Section PickAny.
...
@@ -79,8 +79,7 @@ Section PickAny.
End
PickAny
.
End
PickAny
.
(* Next, we show that any property P of (pick_min n p) can be proven by showing that
(** Lemmas about pick_min *)
P holds for the smallest number < n that satisfies p. *)
Section
PickMin
.
Section
PickMin
.
Variable
n
:
nat
.
Variable
n
:
nat
.
...
@@ -88,40 +87,73 @@ Section PickMin.
...
@@ -88,40 +87,73 @@ Section PickMin.
Variable
P
:
nat
->
Prop
.
Variable
P
:
nat
->
Prop
.
(* Assume that there is some number < n that satisfies p. *)
Hypothesis
EX
:
exists
x
:
'
I_n
,
p
x
.
Hypothesis
EX
:
exists
x
:
'
I_n
,
p
x
.
Hypothesis
MIN
:
Section
Bound
.
forall
x
,
p
x
->
(* First, we show that (pick_min n p) < n. *)
(
forall
y
,
p
y
->
x
<=
y
)
->
Lemma
pick_min_ltn
:
pick_min
n
p
<
n
.
P
x
.
Proof
.
rewrite
/
pick_min
/
odflt
/
oapp
.
case
:
pickP
.
{
move
=>
x
/
andP
[
PRED
/
forallP
ALL
].
by
rewrite
/
default0
.
}
{
intros
NONE
;
red
in
NONE
;
exfalso
.
move
:
EX
=>
[
x
PRED
]
;
clear
EX
.
set
argmin
:
=
arg_min
x
p
id
.
specialize
(
NONE
argmin
).
suff
ARGMIN
:
(
pred_min_nat
n
p
)
argmin
by
rewrite
ARGMIN
in
NONE
.
rewrite
/
argmin
;
case
:
arg_minP
;
first
by
done
.
intros
y
Py
MINy
.
apply
/
andP
;
split
;
first
by
done
.
by
apply
/
forallP
;
intros
y0
;
apply
/
implyP
;
intros
Py0
;
apply
MINy
.
}
Qed
.
End
Bound
.
Section
Minimum
.
Hypothesis
MIN
:
forall
x
,
p
x
->
x
<
n
->
(
forall
y
,
p
y
->
x
<=
y
)
->
P
x
.
(* Next, we show that any property P of (pick_min n p) can be proven by showing
that P holds for the smallest number < n that satisfies p. *)
Lemma
pick_min_holds
:
P
(
pick_min
n
p
).
Proof
.
rewrite
/
pick_min
/
odflt
/
oapp
.
case
:
pickP
.
{
move
=>
x
/
andP
[
PRED
/
forallP
ALL
].
apply
MIN
;
try
(
by
done
).
by
intros
y
Py
;
specialize
(
ALL
y
)
;
move
:
ALL
=>
/
implyP
ALL
;
apply
ALL
.
}
{
intros
NONE
;
red
in
NONE
;
exfalso
.
move
:
EX
=>
[
x
PRED
]
;
clear
EX
.
set
argmin
:
=
arg_min
x
p
id
.
specialize
(
NONE
argmin
).
suff
ARGMIN
:
(
pred_min_nat
n
p
)
argmin
by
rewrite
ARGMIN
in
NONE
.
rewrite
/
argmin
;
case
:
arg_minP
;
first
by
done
.
intros
y
Py
MINy
.
apply
/
andP
;
split
;
first
by
done
.
by
apply
/
forallP
;
intros
y0
;
apply
/
implyP
;
intros
Py0
;
apply
MINy
.
}
Qed
.
End
Minimum
.
Lemma
pick_min_holds
:
P
(
pick_min
n
p
).
Proof
.
rewrite
/
pick_min
/
odflt
/
oapp
.
case
:
pickP
.
{
move
=>
x
/
andP
[
PRED
/
forallP
ALL
].
apply
MIN
;
first
by
done
.
by
intros
y
Py
;
specialize
(
ALL
y
)
;
move
:
ALL
=>
/
implyP
ALL
;
apply
ALL
.
}
{
intros
NONE
;
red
in
NONE
;
exfalso
.
move
:
EX
=>
[
x
PRED
]
;
clear
EX
.
set
argmin
:
=
arg_min
x
p
id
.
specialize
(
NONE
argmin
).
suff
ARGMIN
:
(
pred_min_nat
n
p
)
argmin
by
rewrite
ARGMIN
in
NONE
.
rewrite
/
argmin
;
case
:
arg_minP
;
first
by
done
.
intros
y
Py
MINy
.
apply
/
andP
;
split
;
first
by
done
.
by
apply
/
forallP
;
intros
y0
;
apply
/
implyP
;
intros
Py0
;
apply
MINy
.
}
Qed
.
End
PickMin
.
End
PickMin
.
(* Next, we show that any property P of (pick_max n p) can be proven by showing that
(** Lemmas about pick_max *)
P holds for the largest number < n that satisfies p. *)
Section
PickMax
.
Section
PickMax
.
Variable
n
:
nat
.
Variable
n
:
nat
.
...
@@ -129,34 +161,68 @@ Section PickMax.
...
@@ -129,34 +161,68 @@ Section PickMax.
Variable
P
:
nat
->
Prop
.
Variable
P
:
nat
->
Prop
.
(* Assume that there is some number < n that satisfies p. *)
Hypothesis
EX
:
exists
x
:
'
I_n
,
p
x
.
Hypothesis
EX
:
exists
x
:
'
I_n
,
p
x
.
Hypothesis
MAX
:
Section
Bound
.
forall
x
,
p
x
->
(* First, we show that (pick_max n p) < n. *)
(
forall
y
,
p
y
->
x
>=
y
)
->
Lemma
pick_max_ltn
:
pick_max
n
p
<
n
.
P
x
.
Proof
.
rewrite
/
pick_max
/
odflt
/
oapp
.
case
:
pickP
.
{
move
=>
x
/
andP
[
PRED
/
forallP
ALL
].
by
rewrite
/
default0
.
}
{
intros
NONE
;
red
in
NONE
;
exfalso
.
move
:
EX
=>
[
x
PRED
]
;
clear
EX
.
set
argmax
:
=
arg_max
x
p
id
.
specialize
(
NONE
argmax
).
suff
ARGMAX
:
(
pred_max_nat
n
p
)
argmax
by
rewrite
ARGMAX
in
NONE
.
rewrite
/
argmax
;
case
:
arg_maxP
;
first
by
done
.
intros
y
Py
MAXy
.
apply
/
andP
;
split
;
first
by
done
.
by
apply
/
forallP
;
intros
y0
;
apply
/
implyP
;
intros
Py0
;
apply
MAXy
.
}
Qed
.
End
Bound
.
Section
Maximum
.
Hypothesis
MAX
:
forall
x
,
p
x
->
x
<
n
->
(
forall
y
,
p
y
->
x
>=
y
)
->
P
x
.
(* Next, we show that any property P of (pick_max n p) can be proven by showing that
P holds for the largest number < n that satisfies p. *)
Lemma
pick_max_holds
:
P
(
pick_max
n
p
).
Proof
.
rewrite
/
pick_max
/
odflt
/
oapp
.
case
:
pickP
.
{
move
=>
x
/
andP
[
PRED
/
forallP
ALL
].
apply
MAX
;
try
(
by
done
).
by
intros
y
Py
;
specialize
(
ALL
y
)
;
move
:
ALL
=>
/
implyP
ALL
;
apply
ALL
.
}
{
intros
NONE
;
red
in
NONE
;
exfalso
.
move
:
EX
=>
[
x
PRED
]
;
clear
EX
.
set
argmax
:
=
arg_max
x
p
id
.
specialize
(
NONE
argmax
).
suff
ARGMAX
:
(
pred_max_nat
n
p
)
argmax
by
rewrite
ARGMAX
in
NONE
.
rewrite
/
argmax
;
case
:
arg_maxP
;
first
by
done
.
intros
y
Py
MAXy
.
apply
/
andP
;
split
;
first
by
done
.
by
apply
/
forallP
;
intros
y0
;
apply
/
implyP
;
intros
Py0
;
apply
MAXy
.
}
Qed
.
End
Maximum
.
Lemma
pick_max_holds
:
P
(
pick_max
n
p
).
Proof
.
rewrite
/
pick_max
/
odflt
/
oapp
.
case
:
pickP
.
{
move
=>
x
/
andP
[
PRED
/
forallP
ALL
].
apply
MAX
;
first
by
done
.
by
intros
y
Py
;
specialize
(
ALL
y
)
;
move
:
ALL
=>
/
implyP
ALL
;
apply
ALL
.
}
{
intros
NONE
;
red
in
NONE
;
exfalso
.
move
:
EX
=>
[
x
PRED
]
;
clear
EX
.
set
argmax
:
=
arg_max
x
p
id
.
specialize
(
NONE
argmax
).
suff
ARGMAX
:
(
pred_max_nat
n
p
)
argmax
by
rewrite
ARGMAX
in
NONE
.
rewrite
/
argmax
;
case
:
arg_maxP
;
first
by
done
.
intros
y
Py
MAXy
.
apply
/
andP
;
split
;
first
by
done
.
by
apply
/
forallP
;
intros
y0
;
apply
/
implyP
;
intros
Py0
;
apply
MAXy
.
}
Qed
.
End
PickMax
.
End
PickMax
.
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment