coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Elias Castegren <eliasca AT kth.se>
- To: "coq-club AT inria.fr" <coq-club AT inria.fr>
- Subject: [Coq-Club] Moving between extrinsic and intrinsic proofs
- Date: Wed, 9 Oct 2019 15:16:15 +0000
- Accept-language: sv-SE, en-US
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=eliasca AT kth.se; spf=Pass smtp.mailfrom=eliasca AT kth.se; spf=Pass smtp.helo=postmaster AT smtp-4.sys.kth.se
- Ironport-phdr: 9a23:w26h7R9o3WTWY/9uRHKM819IXTAuvvDOBiVQ1KB40uMcTK2v8tzYMVDF4r011RmVBN6dtasP1rOempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffgtFiCC8bL9vIxm7rRjdvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/6apgVR3mhzodNzMh8G/ZlNF+jL5Vrhyiphxw34HbbZqPO/ZiZK7QZ88WSXZcUstXSidPApm8b4wKD+cZMuhYq4j9qEEVrRCjGwSjHvjvyiNWiX/5x601zeIhGhzB0QM+G9IOsW7brM7pO6gISu21z7XIzTXZY/NNxzjw8Y7FeQ0ir/GURb98bMTcxVU1Gw/bgFidq5bpMjyW2+gXrmSW6+RtWfqshmMpsQ19vDiiytk2hoTKm44Z0FTJ+CNky4gvP9K4UlR0Ydu8HZtQqS6aM4x2T9s5Q2FtpCY60qQKtJGhcCgRyJUn3ATTa/+bc4iI+B7jT/ieLS95hHJjZr2/mw6//VWux+HgTMW4zlhHoyhfntTDtX0BzQHf58yJR/dl+0euwzeP1wTd6uFeJkA0kLLWJIAlwr4xjJUTqljMETXtlUX1kK+Wdl8o+vO25Oj/eLXpuoecN5NoigH5Kqkhhsu/Af0hPgcSW2ib5P+z2ab4/Uz5RbVKluc5nrPYsJDcP8Qbp7S2DxVb0oY5uF6DCGLs29MB2HIDMVhteRSdjoGvNUuEaKTzCu76iFCxmh9qwerHN/vvGMOeAGLEleLMebd08AZ3wREvwN9F6pQcXrwFIfvoUUbZt8DYSAQ0ZV/ni937Aclwg9tNEVmEBbWUZfuL7Q24o9k3KuzJX7c7/S7nIqh35OLuy2Q0ywdELPuZmKAPYXX9JcxIZkCQYH7imNAEQTUJogp4V+G40QTfAw4WXG67WucH3h9+CI+iCt6SFJuonKTEgGGgD4YQZXxGTEuBQy7l
Hi Coq clubbers
I'm looking for ideas on how to smoothly go from extrinsic proofs
to code with intrinsic proofs. As an example, consider the
following simplified scenario.
I have some property "foo" on natural numbers, and a data type
"bar" which carries with it a number for which "foo" holds:
Definition foo (x : nat) := x < 5.
Inductive bar :=
Bar : {x | foo x} -> bar.
In addition, I have created an algorithm which checks if the
"foo" property holds. I have also proven it correct:
Definition check_foo (x : nat) :=
match x
with
| S (S (S (S (S _)))) => false
| _ => true
end.
Require Import Lia.
Theorem check_foo_correct :
forall x, check_foo x = true <-> foo x.
Proof.
unfold foo. unfold check_foo.
intros. split.
- intros H. do 5 (destruct x; try lia).
inversion H.
- intros Hlt. do 5 (destruct x; try reflexivity).
lia.
Qed.
What I would like now is a function of type "nat -> option bar"
which builds a "bar" from a natural number only if "foo" holds for
that number. So far I have found two ways to do it, but none of
them are very attractive.
One variant runs the checking function and captures the equality
proof "check_foo n = true", and then uses the correctness theorem
as a function to get the property "foo n" with which the argument
of "Bar" can be built:
Theorem check_foo_correct_fun :
forall x, check_foo x = true -> foo x.
Proof.
apply check_foo_correct.
Qed.
Definition build_bar (n : nat) : option bar :=
let Heq :=
if check_foo n as res return option (res = true)
then Some eq_refl
else None
in
match Heq
with
| Some refl =>
let arg := exist foo n (check_foo_correct_fun n refl)
in
Some (Bar arg)
| None => None
end.
This is unattractive because it requires dependent pattern
matching and explicitly passes around an equality proof in an
option type just to make the typechecker happy.
The second approach builds the function with a proof script:
Definition build_bar' (n : nat) : option bar.
remember (check_foo n) as res.
symmetry in Heqres. destruct res.
- apply check_foo_correct in Heqres.
apply (Some (Bar (exist foo n Heqres))).
- apply None.
Defined.
While this version is shorter, it is arguably worse from a
software engineering perspective as you need to step through the
script to see what it is doing.
Ideally, what I would want is something like this, where the key
inference needed is that "check_foo n = true" since we are in the
"then" branch.
Definition build_bar'' (n : nat) : option bar :=
if check_foo n
then Some (Bar (exist foo n _))
(* This does not typecheck *)
else None.
I'm guessing that I won't be able to get something this short, but
I'm interested in hearing if there are cleaner solutions than the
two working versions I have found so far.
Cheers
/Elias
- [Coq-Club] Moving between extrinsic and intrinsic proofs, Elias Castegren, 10/09/2019
- Re: [Coq-Club] Moving between extrinsic and intrinsic proofs, Xavier Leroy, 10/09/2019
- Re: [Coq-Club] Moving between extrinsic and intrinsic proofs, Elias Castegren, 10/10/2019
- Re: [Coq-Club] Moving between extrinsic and intrinsic proofs, Maximilian Wuttke, 10/09/2019
- Re: [Coq-Club] Moving between extrinsic and intrinsic proofs, Laurent Thery, 10/09/2019
- Re: [Coq-Club] Moving between extrinsic and intrinsic proofs, Xavier Leroy, 10/09/2019
Archive powered by MHonArc 2.6.18.