Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] normalize all closed terms of a given type

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] normalize all closed terms of a given type


Chronological Thread 
  • From: Jason Gross <jasongross9 AT gmail.com>
  • To: coq-club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] normalize all closed terms of a given type
  • Date: Thu, 15 Oct 2020 18:52:40 -0400
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=jasongross9 AT gmail.com; spf=Pass smtp.mailfrom=jasongross9 AT gmail.com; spf=None smtp.helo=postmaster AT mail-ej1-f49.google.com
  • Ironport-phdr: 9a23:nT239RcxB1bauvnxa1Ee78OplGMj4u6mDksu8pMizoh2WeGdxcS+Zx7h7PlgxGXEQZ/co6odzbaP7Oa+BSdYsN6oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vLhi6twTcu8YZjYd+Lqs61wfErGZPd+lK321jOEidnwz75se+/Z5j9zpftvc8/MNeUqv0Yro1Q6VAADspL2466svrtQLeTQSU/XsTTn8WkhtTDAfb6hzxQ4r8vTH7tup53ymaINH2QLUpUjms86tnVBnlgzoBOjUk8m/Yl9ZwgbpUrxKvpRNxw4DaboKIOvRgYqzQZskVSXZbU8tLSyBNHoGxYo0SBOQBJ+ZYqIz9qkMKoxSkHgmsA+XvwSJJiH/s2q06yP8hGhzB0QwiBd0Oq3PUrNP6NKcIVuC117LIwDHYYvNZ3Dfy8onIchQ7rf6QWrJwdNPcxE8yHAzKklues5bqPy+J1usTqWib6fJtWOahhWMntw18rSSiy8cshIXXiI8YyU7I+DtlzIs7OdC1SUp2bNGrHpdMqSyUN4l7T8IiTWxnpCs0xb4Lt5ClcSUM1Z8pyRnfa/mdfIiJ5BLuTPqeITBihHJjZr2/gxKy/VK+xeLhS8m51ktBoCldktTUqHwByxje5tKER/Z95EutxyuD2gPJ5uxLJU05k7fQJYQ7zb4qjJUTtFzOHi/ol0Xyi6+bbkAk9fKp6+Tje7npuJ2cO5JthgHwPakjntazAes/MggJUGib/fqz2Kf/8k3+RbVGlvw2kq/Hv5DGPckXuLK1DgtP3osg6xuzFSmq3MkbkHUdI19IfAqLj43zNFHPJPD4A+2/g1OpkDpzxfDJJKbhApLLLnjMirfheq1961VYxQcowtBf4ohbCrAFIP7pRkDxs9nYAgcjMwOo2+bnFMl91oQGVG2TBa+ZKbrevkOM5uIyOOaBf5QVuTb4K/g9/fHil345mVkHfamox5Qbcn64Hu41a3meNHHrm5IKFXoA9l41S/Wvg1mfWxZSYWyzVuQy/GdoJpihCNLhT5uqhvSuxiCgBdUCZGldDVaDC3DzbNSsVPIFaSbUKchkxG9XHYO9QpMsgEn9/DTxzKBqe7KNq38o8Kn73d0w3NX90BQ79Dh6FcOYijjfQGR9n2dOTDgzjvkm/B5Nj2yb2K09uMR2UNxe4/QTD1U/PJ/YiuF4UpX8BlOHcdCOR1KrBN6hBGNpF45j85o1e094Xu6aoFXbxSPzWu0akrWKANo/9aeOh3U=

I think if you wanted to pick out an efficient primitive to make available in Ltac2/OCaml, the primitive would be:
Given a term t and a tactic k:
for every subterm t' of t in topdown order:
  invoke k on (t', the type of t', the set of context variables t' depends on, the set of de Bruijn indices used but not bound in t' or its type)

To be completely efficient, this would have to be interwoven with the retyping algorithm and either be cached or else implemented in CPS, 

On Thu, Oct 15, 2020 at 6:39 PM Jason Gross <jasongross9 AT gmail.com> wrote:
Inductive marker := mark.
Ltac norm T :=
  let check_and_change v :=
      assert_fails has_evar v;
      let T' := type of v in
      unify T T';
      let v' := (eval vm_compute in v) in
      progress ( change v with v' in * ) in
  pose proof mark;
  repeat match goal with H : _ |- _ => revert H end;
  repeat match goal with
         | [ |- context[?e] ] => check_and_change e
         end;
  repeat lazymatch goal with
         | [ |- marker -> _ ] => fail
         | _ => intro
         end;
  intros _.

Goal forall a b c, a + (5 + 6) + c = 1 + 1 + b.
  intros a b.
  norm nat.



Note that this may not play well with section variables.

On Thu, Oct 15, 2020 at 5:56 PM Abhishek Anand <abhishek.anand.iitg AT gmail.com> wrote:
Yeah, closed means no evars and no local variables.
For example, in the proof below, I want 2^64 to be normalized and leave everything else unchanged.
I can use the tactic `norm` below to manually pick terms to normalize. But I wish there was an automatic way to pick all closed terms of a given type.


Require Import ZArith.
Open Scope Z_scope.
Ltac norm T :=
  match goal with
    [ |- context[T] ] => let Tc := eval vm_compute in T in
                       change T with Tc
  end.

Lemma xx (x:Z) : (2^64)*x=1.
  norm (2^64).

On Thu, Oct 15, 2020 at 5:44 AM Beta Ziliani <beta AT mpi-sws.org> wrote:
I was going to ask the same question. Perhaps an example could help?

On Thu, Oct 15, 2020 at 3:08 AM Fabian Kunze <fabian.kunze AT cs.uni-saarland.de> wrote:
By closed, do you mean no evars, or no local variables?

15 Oct 2020 07:42:39 Abhishek Anand <abhishek.anand.iitg AT gmail.com>:

Sorry, I was not clear. I want to only strongly normalize closed subterms of the type and leave the rest unchanged.

On Wed, Oct 14, 2020 at 6:54 PM Jason Gross <jasongross9 AT gmail.com> wrote:
Sorry, that only does goal, but doing the context isn't much different

On Wed, Oct 14, 2020, 20:53 Jason Gross <jasongross9 AT gmail.com> wrote:
Here is a slow tactic to do this:
Ltac norm T :=
  repeat match goal with
          | [ |- context [?e] ] => let e' := eval vm_compute in (e : T) in progress change e with e'
         end.

You may want a different typing check if you don't want coercion insertion or only want to check up to syntactic typing rather than unification.

On Wed, Oct 14, 2020, 20:20 Abhishek Anand <abhishek.anand.iitg AT gmail.com> wrote:
Is there a tactic to strongly normalize all closed terms of a given type in the Coq goal and context?
Is there a way to write such a tactic in Ltac/Ltac2/Mtac2.... ?




Archive powered by MHonArc 2.6.19+.

Top of Page