Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Unfolded not cannot be refolded

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Unfolded not cannot be refolded


Chronological Thread 
  • From: Jason -Zhong Sheng- Hu <fdhzs2010 AT hotmail.com>
  • To: ikdc <ikdc AT mit.edu>, "coq-club AT inria.fr" <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Unfolded not cannot be refolded
  • Date: Mon, 9 Apr 2018 19:15:27 +0000
  • Accept-language: en-CA, en-US
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=fdhzs2010 AT hotmail.com; spf=Pass smtp.mailfrom=fdhzs2010 AT hotmail.com; spf=Pass smtp.helo=postmaster AT NAM03-DM3-obe.outbound.protection.outlook.com
  • Ironport-phdr: 9a23:GyYhJB0n3s85WAxDsmDT+DRfVm0co7zxezQtwd8ZseIRKfad9pjvdHbS+e9qxAeQG9mDsLQc06L/iOPJYSQ4+5GPsXQPItRndiQuroEopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZvJuTyB4Xek9m72/q99pHPbQhEniaxba9vJxiqsAvdsdUbj5F/Iagr0BvJpXVIe+VSxWx2IF+Yggjx6MSt8pN96ipco/0u+dJOXqX8ZKQ4UKdXDC86PGAv5c3krgfMQA2S7XYBSGoWkx5IAw/Y7BHmW5r6ryX3uvZh1CScIMb6S645WTO44KdwVB/nkiMHPCM9/GzZlsB8kKdXrRS8rBJ93oHUepmYOvpgcK3AYdMUS2lPXshTWCNdDYyxdJEAA/YdMetCs4Xxu0UCoB2jDgesHuPvzTpIi2fy06IgyOQhFgfG1xE5E90NsHTUq9P1NKgPWu6ozKnH0zPDb/xP1Tzg6obIbw0qrPaCXb1tccrQyFIvGx3ZglmNtYDoJDOV1uMRs2ie9eVgVOavh3Q7pAF2pzii38EhgZTHiIISz1DL7yR5wIAtKN23SU57fd6kEIZLuC2AK4R2RcYiTmd1syg50r0LoZG2cDQQxJkj2RLTcf+Kf5KW7h79UuuaPC12i2h/eL2lgha/6UigxfP4VsmzyFtEtjZInN7Qun0DzhDd5M+JR/Vk8kemwjmAyRrf6uZZIUAojqXbLIMhwrgtmZYJqUTDBCj2mFnog6CKakUk+++o6+L9brXhu5+cK4t0igb5MqQtgMCwHeM4Mg0WU2ia/+SzyqHj8FX2TblWlPE7lrfVvIrZKMgBuKK1HRdZ0oM55Ba+Czem3s4YnX4CLF9ddhKIkojpOlDVIPzmEfuznkignSxrx/DBIr3hB4/CLnnHkLv7Ybl97EtcxBIpzd9D/5JUFq0BIPXrV0Dts9zYFwY1PBCww+b6E9pwzZgeWGKKAq+BKqzeq16I5uQ1I+mNfoAZojj9K+J2r8Lp2H46lVRVKaiq0ZA/bXGkWPlqPhPdKTDnhc5EGmMXtCI/SvbrgRuMS3QbM321Ruc34iwxIIOgF4bKAI631u+vxiC+S79ffWdAQhW+EXDueM2/W/oKZ2faAtIpxjIIVaq6Edd4jTmusxP/wrtjaOHT/3tL5trYyNFp6riKxlkJ/jtuApHGiznUHjNE21gQTjpz55hR5El0y1ONy6992qcKFdtP4vpIVkExMpuOlrUmWeC3YRrIe5KycHjjWs+vWGpjTtUtxtYPZwB2HNDw1kmejRrvOKcckvmwPLJx8q/Y2CSudeBU7i6dkYUE1BwhSMYJMnC6jKli8QSVH5TOj0iSi6etc+IbwTLJ82CAi2GJuRMBXQ==

Thank you ikdc, this tactic does work.


However, it seems in some situations, it will cause stack overflow. I've got no idea how to quantify "situations" here, but I am looking further to see why it's happening.


Sincerely Yours,

Jason Hu

From: ikdc <ikdc AT mit.edu>
Sent: March 30, 2018 11:04:40 PM
To: coq-club AT inria.fr; Jason -Zhong Sheng- Hu
Subject: Re: [Coq-Club] Unfolded not cannot be refolded
 
On 03/28/2018 06:39 PM, Jason -Zhong Sheng- Hu wrote:
> Hi all,
>
>
> Please consider following code:
>
>
> Goal (forall n : nat, ~ (n >= 0) -> False) -> True.
>    unfold not. fold not.
>
> This code unfolded not, so the goal becomes
>
>
> (forall n : nat, (n >= 0 -> False) -> False) -> True
>
>
> But the next one fold not is not able to refold the not to turn the inner condition back to ~ (n >= 0).
>
>
> In general, I tried to write code like this,
>
>
>    intros.
>    match goal with
>    | [ _ : forall _, ?T |- _ ] =>
>      idtac T
>    end.
>
> following the program above, in my Coq 8.6, it says no matching clause. But I suspect this error message is bogus, the real error should be Coq wouldn't allow us to capture a dependent right hand side of implication, due to the potential misuse of free variables. That probably also explains why fold cannot undo what unfold has done.
>
>
> This is especially disturbing, when I do autounfold in *. There are many lemmas expressed with the presence of not, and if not is unfolded, auto family does not seem work well with that form anymore. Might I ask how do you guys handle it?
>
>
> In general, is there a way to manipulate dependent rhs of implication?
>
>
> Sincerely Yours,
>
> Jason Hu
>
>

(* I found the problem interesting, so I decided to take a stab at it.
  * First, I tried using setoid_rewrite. *)

Require Import Coq.Classes.Morphisms.
Require Import Setoid.
Local Existing Instance eq_subrelation | 5.

Goal (forall n : nat, ((n >= 0) -> False) -> False) -> True.
   intro.
   (* H : forall n : nat, (n >= 0 -> False) -> False *)
   assert (forall P : Prop, (P -> False) = ~P) as E by reflexivity.
   setoid_rewrite E in H.
   (* H : forall n : nat, ~ (n >= 0 -> False) *)
   Fail setoid_rewrite E in H. (* why? *)
Abort.

Goal (forall n : nat, ((n >= 0) -> False) -> False) -> True.
   intro.
   (* H : forall n : nat, (n >= 0 -> False) -> False *)
   assert (forall P : Prop, (P -> False) = ~P) as E by reflexivity.
   setoid_rewrite E in H at 2.
   (* H : forall n : nat, ~ n >= 0 -> False *)
   setoid_rewrite E in H.
   (* H : forall n : nat, ~ ~ n >= 0 *)
Abort.

(* However, I found that this only worked if it rewrote in a certain order.
  * I don't know why the second rewrite fails.
  * Hopefully someone can give an explanation or a way to make it work *)

(* Using an idea from Jason Gross in
<https://github.com/coq/coq/issues/6243>,
  * I managed to write a context match on the body of the forall. *)

Ltac fold_not_under_forall :=
   repeat
     match goal with
     | H : forall n : ?T, @?x n |- _ =>
       match x with
       | fun n : T => ?b =>
         let not_n := fresh in
         let b''' :=
             constr:(
               fun n : T =>
                 match b with
                 | not_n =>
                   ltac:(let b' := (eval cbv delta [not_n] in not_n) in
                         match b' with
                         | context C[?P -> False] =>
                           let b'' := context C[~ P] in
                           exact b''
                         end)
                 end) in
         let tH' := eval cbn beta in (forall n : T, b''' n) in
             let tH := type of H in
             change tH with tH' in H
       end
     end.

Goal (forall n : nat, ((n >= 0) -> False) -> False) -> True.
   intro.
   (* H : forall n : nat, (n >= 0 -> False) -> False *)
   fold_not_under_forall.
   (* H : forall n : nat, ~ ~ n >= 0 *)
Abort.

(* It works, but it's the ugliest Ltac I've ever written.
  * Hopefully it can be improved? *)



Archive powered by MHonArc 2.6.18.

Top of Page