coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Xavier Leroy <Xavier.Leroy AT inria.fr>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Compute a general recursive function on dependent types.
- Date: Sun, 19 Aug 2018 18:20:09 +0200
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=xavier.leroy AT gmail.com; spf=Pass smtp.mailfrom=xavier.leroy AT gmail.com; spf=None smtp.helo=postmaster AT mail-wm0-f68.google.com
- Autocrypt: addr=Xavier.Leroy AT inria.fr; prefer-encrypt=mutual; keydata= xsDiBD77B+8RBADMHU3Y4gPr8mwulmfg2I33I0rX2xEqn8uoKWYJqHYrsviH0aF8s9bu55X4 FQ9kgkhI/KRom3Tz0Pp9GIe5QsxB1JHDFjaw+0TjZR9Akqfy19dPxo/g0N6T8JGuGP5Zsf5T LOT+afrxoxHTZ7Y5fWxuVCfWV5nlf1ttaEYik1HS8wCgrA9sHfKAT812ERkRNLsy6/BkCcsE AL2I3NpwLWtzluuUAv6DNelpPVLpAsAU92X7wThJEn4J7lRJMv2RBOzUp4x6VSA4pSn1VV1x 0N4EBB8YzXW2q6QP2lmhI1FQO53KDb7lmpAew6S4h9jJLv85KoI/mzacM/OdPGIc/+wQl0nL 3tZOv4QBh2XEI3cRhdIOVsMxqMCXBACiPinMdBVlJC8JIasE0vZem4MxWaGBpwcBRdWXiWtW 5wKG7BlK0sPoUc1Mv8e9gYJIlNMu23EAiafvr1ix1ZPiREkbovcWrs2vS88hbh5tJpQMrYcs cwrSritH3x1nwcu3lkvzgvMvaUcDGmCfVou3lo7dG4vUsESWMRBhoZzS5s0qWGF2aWVyIExl cm95IChncGcpIDxYYXZpZXIuTGVyb3lAaW5yaWEuZnI+wlcEExECABcFAj77B+8FCwcKAwQD FQMCAxYCAQIXgAAKCRB+qv63rkH5YEl0AKCqRCFWMV994oathu1Sz4DZhpAAkQCgkRWhkdJK Dcux2cPCyPg6njiGeUTOwEwEPvsH8hAEAPjqRhLjRdM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Z7TdkuT3xrtSs40LEKp5G2cSwQxJkoxBPSbeGMfZKS7RL5TumRJC91hHJ7d7K7gBa/6U2gxff9VsmwyVpLoC9FnsXVunAD1hHe6dKLSvR6/kem1jaP0x7c5vtYLkAzkKrXM58hwrgumZoPqUnOHCD7lF/rgKOIdkgo4Oul5/r9brjnpZKQL4p0hRv/MqQqlMy/G+M4Mg0WUmmU4+u8yrzj8lPjQLlQiv05jLPZsJfaJMkAqa65BhVa0ocn6xqlEzim19EYkWEdLF1ZYBKHk5TpO1bWLf/kCve/mk2gnytvx/DbJbLsGY7NL3jGkLf5Z7lx8U9cyAwpzdBe/Z1YEL8BIOigEnP24dffF1oyNxG+6+fhEtR0kI0ECkyVBarMAKrMsFKSrsYiOe6dLNslsSj8JuJjw/P0im4RmFkHfKDv04FBOyPwJehvP0jMOSmkudwGC2pf5lNvHtyvs0WLVHtoX1j3Wqs94j8hD4f/VNXMQ4mshPqK2yLpR8QKNFADMUiFFDLTT6vBQ+0FMXvALcpokzhCXr+kGdd4iEOe8TTiwr8iFdL6vy0VsZW5iYpw7uzX0A43rXl6UZTb3GaKQGV52GgPQm1u0Q==
- Openpgp: preference=signencrypt
On 08/19/2018 02:23 AM, Shengyi Wang wrote:
>
> After some thought, I think my question is "How to preserve the "phase
> distinction" in proofs used in a function?". I'm not sure opaque terns in
> Pos_lt_wf' are the only causes. How about other lemmas involved in the
> function definition such as "ptr_ok"?
>
I don't think there is a general answer to your question beyond "try to
evaluate and see what happens".
My personal experience with { x : A | P x } types and other instances of mild
uses of dependent types is that they compute well most of the time.
For proofs of well-foundedness / accessibility, there exists a neat trick to
turn an opaque proof (or a proof that computes very inefficiently) into a
transparent, computationally-cheap proof that lets you evaluate general
recursive definitions efficiently:
https://sympa.inria.fr/sympa/arc/coq-club/2013-09/msg00034.html
I wish this trick was made available in the Coq stdlib.
- Xavier Leroy
> Thank you,
>
> Shengyi Wang
>
> Cell: +65-83509639
>
>
> Jason -Zhong Sheng- Hu
> <fdhzs2010 AT hotmail.com
>
> <mailto:fdhzs2010 AT hotmail.com>>
> 于2018年8月19日周日 上午2:29写道:
>
> Hi Shengyi,
>
>
> are you referring to the opaque term issue? Yes, it causes that.
> Specifically, in your proof of accessibility:
>
>
> Lemma Pos_lt_wf': forall x y : positive, x < y -> Acc Pos.lt x.
> Proof.
> intros. rewrite Pos2Nat.inj_lt in H.
> remember (Pos.to_nat y) as n. clear y Heqn. revert x H. induction n;
> intros.
> - pose proof (Pos2Nat.is_pos x). exfalso; intuition.
> - apply lt_n_Sm_le, le_lt_or_eq in H. destruct H; auto.
> constructor. intros. rewrite Pos2Nat.inj_lt, H in H0. apply IHn.
> assumption.
> Defined.
>
> all highlighted terms are opaque. I use emacs + company-coq, so for me
> `(company-coq-term-doc TERM)` will tell me if the term is opaque.
> Effectively, you want to make the entire well-formedness proof transparent,
> so probably all of them are the problem.
>
>
> I got a question related to this: I am not sure if Pos2Nat.is_pos being
> opaque matters here as the branch is discharged by falsehood. In this case,
> we should not get into that branch. Is it correct to say that we would
> never have to care about reducibility of lemmas concluding falsehood?
>
>
> *Sincerely Yours,
> *
> *
> Jason Hu*
>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *From:*
> coq-club-request AT inria.fr
>
> <mailto:coq-club-request AT inria.fr>
>
> <coq-club-request AT inria.fr
>
> <mailto:coq-club-request AT inria.fr>>
> on behalf of Shengyi Wang
> <txyyss AT gmail.com
>
> <mailto:txyyss AT gmail.com>>
> *Sent:* August 18, 2018 12:34:57 PM
> *To:*
> coq-club AT inria.fr
>
> <mailto:coq-club AT inria.fr>
> *Subject:* [Coq-Club] Compute a general recursive function on dependent
> types.
>
> Dear Coq users,
>
> Recently I defined a map of "sig" type from positive to positive. The
> map should satisfy a property: it always maps a value v to a value which is
> not greater than v. Formally the definition is:
>
> Definition pos_map_prop (t: PM.tree positive) : Prop :=
> forall i j, PM.find i t = Some j -> j <= i.
>
> Definition PosMap := {pm : PM.tree positive | pos_map_prop pm}.
>
> Such a map can be viewed as a forest: each key in the map is a node.
> Each node points to a smaller value or itself.
>
> Then I successfully defined a general recursive function
> "pm_trace_root" which traces back such a node along the pointers until to a
> self-pointing "root". The property of the map ensures the termination.
>
> So far everything seems fine until I try to run the function in Coq. I
> defined a test_map which is essentially {1 -> 1, 2 -> 2}. I tested:
>
> Compute (PM.find 2 (proj1_sig test_map)).
> ===> Some 1
>
> Compute (PM.find 1 (proj1_sig test_map)).
> ===> Some 1
>
> The function pm_trace_root works for 1:
>
> Compute (pm_trace_root 1 test_map).
> ===> Some 1
>
> But for 2, "Compute (pm_trace_root 2 test_map)." generates an output of
> 912 lines.
>
> I doubt it is caused by the similar problem mentioned in Xavier Leroy's
> blog: http://gallium.inria.fr/blog/coq-eval/
>
> But I'm not sure. Even it is for the same reason, I can not figure out
> which proof term caused this problem. I attached the code. Could anyone
> tell me how to debug this kind of things?
>
> Thank you very much,
>
> Shengyi Wang
>
> Cell: +65-83509639
>
- [Coq-Club] Compute a general recursive function on dependent types., Shengyi Wang, 08/18/2018
- Re: [Coq-Club] Compute a general recursive function on dependent types., Jason -Zhong Sheng- Hu, 08/18/2018
- Re: [Coq-Club] Compute a general recursive function on dependent types., Shengyi Wang, 08/19/2018
- Re: [Coq-Club] Compute a general recursive function on dependent types., Xavier Leroy, 08/19/2018
- Re: [Coq-Club] Compute a general recursive function on dependent types., Shengyi Wang, 08/20/2018
- Re: [Coq-Club] Compute a general recursive function on dependent types., Xavier Leroy, 08/19/2018
- Re: [Coq-Club] Compute a general recursive function on dependent types., Shengyi Wang, 08/19/2018
- Re: [Coq-Club] Compute a general recursive function on dependent types., Jason -Zhong Sheng- Hu, 08/18/2018
Archive powered by MHonArc 2.6.18.