Skip to Content.
Sympa Menu

coq-club - [Coq-Club] Struggling to convert a simple Program Fixpoint using just induction and exact into a Fixpoint with match

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[Coq-Club] Struggling to convert a simple Program Fixpoint using just induction and exact into a Fixpoint with match


Chronological Thread 
  • From: "Soegtrop, Michael" <michael.soegtrop AT intel.com>
  • To: "coq-club AT inria.fr" <coq-club AT inria.fr>
  • Subject: [Coq-Club] Struggling to convert a simple Program Fixpoint using just induction and exact into a Fixpoint with match
  • Date: Tue, 20 Aug 2019 12:47:08 +0000
  • Accept-language: de-DE, en-US
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=michael.soegtrop AT intel.com; spf=Pass smtp.mailfrom=michael.soegtrop AT intel.com; spf=None smtp.helo=postmaster AT mga07.intel.com
  • Dlp-product: dlpe-windows
  • Dlp-reaction: no-action
  • Dlp-version: 11.2.0.6
  • Ironport-phdr: 9a23:g47fuBVATC/1HdjuzQm6Y8jrvRXV8LGtZVwlr6E/grcLSJyIuqrYbBGPt8tkgFKBZ4jH8fUM07OQ7/m6HzVcuN3d6TgrS99lb1c9k8IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUhrwOhBoKevrB4Xck9q41/yo+53Ufg5EmCexbal9IRmrswndrNQajIR/Jqo+xRbFv2ZDdvhLy29vOV+dhQv36N2q/J5k/SRQuvYh+NBFXK7nYak2TqFWASo/PWwt68LlqRfMTQ2U5nsBSWoWiQZHAxLE7B7hQJj8tDbxu/dn1ymbOc32Sq00WSin4qx2RhLklDsLOjgk+2zRl8d+jr9UoAi5qhJ/3YDafZ2VOvR9cKPcYdwVSnFMUdxNWyFFGI6wc5cDA/QHMO1Fr4f9vVwOrR6mCAWiGe3vzSFHhnDq3a0g1OQhCRnK1xEnEdIPrHvUrM/6O7kWUey70aLFyjDDb/JK1jf98ofHbBQhreuXXbJ3b8XRxlUvFxnCjlWIsoHlPjWV1vgTvGif9eZvSeWvi2s+pgx3vzOhyMAsiozTiYIUzFDJ7SR5wIApJdKmTE53e8OrH4VWuiqHNIV2WtsvT3xmtSs10LEKpJC2cScQxJg6yRPSauaLf5WU7h7/TOqdPDZ1iXx/dL+xiRu+61asx+P4W8WuzVpHrTRJnsHRun0M0xHf8NaLR/ty80u7xzqDzQLe5+dZKk4uj6XbMYQuwrsom5oTr0vDGij2lV3zjK+ZbEoo5uql5/7mYrXgup+TKYt0hhviPaQpn8yzGeU4Mg4QUGiH4emwybPu8ELjTLlXgPA7nbPVvI3UKMkavKK1HhNZ3po75xa6FTim0dAYnXcdLFJCfRKKl43pO1DSL/D4F/iwnVCsnC1wx/DBILLhDYnNLmLEkLf5Zrt96khcyBYtwtBb/Z5bFrYBIPfrVk/rqNPYFgM5MxCzw+v/FNp90ZoeVXuTDa+dLaPdqkSF5vkvIumJfI8aoizxK/kj5/70jH82g0URfaez3chfVHftVP9hOgCSZWfmqtYHC2YD+AQkBqS+g1qbFDVXenyaXqQm5zh9BpjwXqnZQYX4yoeG0SinBJpOIihjC1uMGHrsPc3QXvYHaCufJol6lTELSaKmU6cg0w2jsEnxzL8xfbmcwTERqZ+2jIs93ObUjxxnrWUlXfTY6HmESiRPpk1NQjY32K5lpkkkkwWC17R1h7pTEtkBvqoVADd/DobVyqlBM/63QhjIJ47bSVC6T9HgCjY0HIpono0+Jn1lEtDntSjtmiqnB7hMyO6OC5VsreTd2WT8I4B2zHOUjKQ=

Dear Coq Users,

 

I am experimenting with the matrix definition of Coquelicot. I wanted to implement some purely structural operations like transpose trying to avoid the requirement for a zero element, which is used inside Coquelicot as error element for matrix element access functions. Not that it would be terribly bad to require a zero element for e.g. transpose, but I am sometimes a bit stubborn and think it should work without it.

 

A simple example for a structural operation is a function which returns the first column of a matrix as m x 1 matrix. I managed to define a first_col function using Program Fixpoint. Although the Program Fixpoint “proof” is trivial, containing just 1 induction and 2 exact tactics, I am struggling to write a corresponding Fixpoint definition using match:

 

 

Require Import Coquelicot.Coquelicot.

Require Import Program.

 

Program Fixpoint first_col_PF {T : Type} {m n : nat} (M : @matrix T m (S n)) : @matrix T m 1 := _.

Next Obligation.

  induction m.

  - exact ().

  - exact ( (fst (fst M), ()), IHm (snd M) ).

Defined.

 

(* ... which is equivalent to ... *)

 

Definition first_col_NR {T : Type} {m n : nat} (M : @matrix T m (S n)) : @matrix T m 1 :=

  nat_rect

    (fun m' : nat => matrix m' (S n) -> matrix m' 1)

    (fun _ : matrix 0 (S n) => ())

    (fun m' IHm M' => ( (fst (fst M'), ()), IHm (snd M') )  )

    m M.

 

(* ... which in turn should be equivalent to ... *)

 

Fixpoint first_col {T : Type} {m n : nat} (M : @matrix T m (S n)) : @matrix T m 1 :=

  match m return @matrix T m 1 with

  | 0    => ()

  | S m' => ( (fst (fst M), ()), first_col (snd M))

  end.

 

 

Coq does not see that since m=S m', M has at least one row in “fst M”. I guess I need a more fancy in/as/return annotation for the match or some explicit type annotations here and there, but I can’t figure it out. Btw.: the return as given is required – without it Coq doesn’t accept the 0 case term.

 

I guess this would be much easier with the Equations plugin. I guess it is due time to look into it, but I also find it worthwhile to understand how it would work in basic Coq.

Best regards,

 

Michael

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928




Archive powered by MHonArc 2.6.18.

Top of Page