Skip to Content.
Sympa Menu

coq-club - [Coq-Club] Rewriting Fails for a Dependent Type Function

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[Coq-Club] Rewriting Fails for a Dependent Type Function


Chronological Thread 
  • From: mukesh tiwari <mukeshtiwari.iiitm AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: [Coq-Club] Rewriting Fails for a Dependent Type Function
  • Date: Sat, 16 Oct 2021 11:37:03 +1100
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mukeshtiwari.iiitm AT gmail.com; spf=Pass smtp.mailfrom=mukeshtiwari.iiitm AT gmail.com; spf=None smtp.helo=postmaster AT mail-ed1-f47.google.com
  • Ironport-hdrordr: A9a23:U1T5iamB4VsV2vE9yMkkbiRAu8XpDfIh3DAbv31ZSRFFG/Fw9vre+8jzsCWftN9/YgBCpTntAsm9qBDnlKKdg7NhX4tKNTOO0ACVxepZnO7fKlPbaknDHy1muZuIsZISNDQ9NzdHZA/BjjWFLw==
  • Ironport-phdr: A9a23:SFBT4xbrgQRzVUYrQEVpAi7/LTHn0IqcDmcuAnoPtbtCf+yZ8oj4OwSHvLMx1gePDNyQtq0MotGVmpioYXYH75eFvSJKW713fDhBt/8rmRc9CtWOE0zxIa2iRSU7GMNfSA0tpCnjYgBaF8nkelLdvGC54yIMFRXjLwp1Ifn+FpLPg8it2O2+5YHfbx9MiTagbr9/LBe7phjNu8cLhodvNrw/wQbTrHtSfORWy2JoJVaNkBv5+8y94p1t/TlOtvw478JPXrn0cKo+TbxDETQpKHs169HxtRnCVgSA+H0RWXgLnxVSAgjF6Bb6Xortsib/q+Fw1jWWMdHwQLspXzmp8qVlRwLyiCofODE38G/ZhM9tgqxFvB2svAZwz5LObYyPKPZyYqHQcNUHTmRBRMZRUClBD5u5b4sSDOoOI/1Yr4ngrFsSrBu/CxOjBPnuyjRVgXL22LA60+c/HgHd3AwgA9MOsXrOo9XvNaceS+G1zKjJzTXfavNbwjj96I3SfRAgpfGAR65/cc3UyUQ2EQ7Ok1qfp5D/MTyPyuQNr3aU7/BmVe+3lWMqqB18riWty8ojioTHiIMYx1Ha+Sh4xIs4OMO1RU97b9OqDJddtjyXO5V5T84mXWxlpjs2xqMItJC0YSQEyJIqzAPRZfyAdoiH+BPjVOCJLDd3hXJlZLK/hwup/kS61uL8Ucy03VBXpSRGitnBrm4B2wDX58SdSfZw/l2t1SiT2w3Q8O1JLkI5mKzGIJA72LEwjIAcsUHbEy/2hkr2iKiWe10h+uey6uTnZqzqqYGBOINpkw3+PKsjl86lDeQ3NQgOWGeb+eCi27H54UL5R7BKguU3kqnfrp/aOdwWqrClDwJRyIou6BayAy243NgEnnQLNl1IdRCfg4jsIV7OIfT4Dfmlg1SrlTdm3/XGPqDiAprTNXjDkKvhfbdz6kFG0gozzMpT55NVCrEAPPLzX1T8tNPdDhAjMgy0x/zrB8l61oMbQW6PGLOWMLvOsV+U4eIiO/WDZIgMuDrkN/cl4+PugmQilF8Gfaip2IMXZ2qiEvRnJUWZe3vsjc0bHWcEpAptBNDt3VaFSHtYY2u4d6M6/DAyToy8XqnZQYX4haGC0Ty7VoFXeWlcCxjYFGrrep6ER/YTYTiTZM5gkyABfbekQo4lkxqpsVmpmPJcMuPI93hA5trY399v6riL/fnd3TNxBsWZlWqKSjMt9ovtbzAz1aF750d6zwXbuUCZq/lRFNgW6v8QFwlmatjTyOt1D920UQXELI/hdQ==


Why does the "rewrite H" fail in np_true?  I am trying to write a (dependent) type function, np_total, that takes a binary natural number N, a proof that it's  less than 256, and returns a byte.  It's fairly straightforward but the problem happens when I am trying to prove the correctness lemma,  np_true. Based on my understanding, so far, of Coq, I need to generalise the terms and therefore this (enriched/generalised) return type:  match (np <? 256) as b return ∀ mp, np = mp ->  (mp <? 256) = b -> _ with but the problem is no matter how I generalise (I have tried a few), I am not able to prove the lemma np_true.  I understand that I can write it as a Sigma type, which is fairly straightforward [1], but I am interested in knowing how to solve this problem.


Lemma np_true : forall np (H : np <? 256 = true) x, of_N np = Some x -> np_total np H = x.
Proof.
  intros. unfold np_total.
(* this rewrite fails *)
 Fail rewrite H.

Definition np_total (np : N):  (np <? 256 = true) ->  byte.
Proof.
  intros H.
  refine(match (np <? 256) as b return ∀ mp, np = mp ->
      (mp <? 256) = b -> _ with
   | true => fun mp Hmp Hmpt =>
      match of_N mp as npt return _ = npt -> _ with
      | Some x => fun _ => x
      | None => fun Hf => _  
      end eq_refl
   | false => fun mp Hmp Hmf => _
  end np eq_refl eq_refl).
  abstract(
  apply of_N_None_iff in Hf;
  apply N.ltb_lt in Hmpt; nia).
  abstract (subst; congruence).
Defined.

Best,
Mukesh


[1] https://gist.github.com/mukeshtiwari/99538fd3ce0715155797528bdeb3d3a9#file-sig-v-L1-L17



Archive powered by MHonArc 2.6.19+.

Top of Page