Skip to Content.
Sympa Menu

coq-club - RE: [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

RE: [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: RE: [Coq-Club] Struggling to convert a simple Program Fixpoint using just induction and exact into a Fixpoint with match
  • Date: Wed, 21 Aug 2019 11:11:57 +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 mga17.intel.com
  • Dlp-product: dlpe-windows
  • Dlp-reaction: no-action
  • Dlp-version: 11.2.0.6
  • Ironport-phdr: 9a23:FVwxJB/tYO41Xv9uRHKM819IXTAuvvDOBiVQ1KB31uwcTK2v8tzYMVDF4r011RmVBN+dsq4fwLGJ+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhWiDanfL9/Ixu7oQrfu8QUnIBvNrs/xhzVr3VSZu9Y33loJVWdnxb94se/4ptu+DlOtvwi6sBNT7z0c7w3QrJEAjsmNXs15NDwuhnYUQSP/HocXX4InRdOHgPI8Qv1Xpb1siv9q+p9xCyXNtD4QLwoRTiv6bpgRRn1gykFKjE56nnahMxugqxGvBKvqR9xw4DWb4GUKPVxcazTcMgGRWVaWstdSzBNDp++YoYJEuEPPfxYr474p1YWoxewGA6sC/3gyj9UnH/22rU63/w8Gg/B3QwvA9IOv27Ko9XxOqsZTOe4zKzJzTrfb/NZwyny6IzSfhA6pvGDQ71wcdbLyUkoDwPIlVSQqYr5PzyL0uQBqXSU7+1lVe+2jWMstg9/oj+qxsg2i4nJgJoYylHC9SVl3ok1Ice0R1NlbtOiDZBetDmaOpNrTs4mXW1koiY3x70ctZO7YiQG0okryh7CZ/CfboSF4xzuWPyfLDp2nn5pZryyihKo/US9yeDwStG43EtLoydBiNXAqHAA2hPJ5sSZUPdw/EGs0iuV2Q/J8OFLO0U0mLLbK5E/xr4wkYIesUHMHiDshUn7jrWadkQi+ui09evnZq/qqYObN49xkg3+M6IuldKjAekgLwQDW3aX9f682bDj50H0QKtGgucrnqTZrZzWPcEbqbS4Aw9R3IYj8RG/DzK+3dQdnHkIMFJFdwiZgIjtIV3OO/f4Aumwg1SwijdrwOjGM6bgApXLMnjMjrPhcaxh5E5bzQo/1cpf6I5MCrEdPPLzXVf8u8DfDh8gKgC73+LnCMhm2Y4FQmKOAqqZMLvIvlOS5+IvJfOMZI4PtzrnJfgl/a2msXhs01QaZOyi2YYdQHG+BPVvZUuDKzK4idAYVGwOowAWTerwiVTEXyQFNFioWKdprAo8BY26F4DbAsiIgbeB1Sq/VNUCY2FNClmBFTHzcIiLR+0LcAqTJNNslnoPUr33GNxp7g2nqAKvk+kvFeHT4CBN7cuyhugw3PXakFQJzRIxCs2c12+XSGQtxzEJQSM72OZ0pkkvkw7fg5g9uORREJlo390MSh0zbMeOzupmBtS0UQXELI/QFQSWB+6+CDR0deofht8DZ0EkRIengRmagGyrBaMYk/qAA5lmqq8=

Dear Laurent,

your suggestion works like a charm in many cases, but I got across one case I
don't see how I could solve it:

Require Import Coquelicot.Coquelicot.
Require Import Reals.

Definition Mprepend_row {T : Type} {m n : nat} (V : @Tn n T) (M : @matrix T m
n) : @matrix T (S m) n := (V, M).

Fixpoint Mprepend_col {T : Type} {m n : nat} : @Tn m T -> @matrix T m n ->
@matrix T m (S n) :=
match m return @Tn m T -> @matrix T m n -> @matrix T m (S n) with
| 0 => (fun V M => tt)
| S m' => (fun V M => (fst V, fst M, Mprepend_col (snd V) (snd M)) )
end.

(* The above works, but replacing the pair with a call to Mprepend_row
doesn't work: *)

Fixpoint Mprepend_col' {T : Type} {m n : nat} : @Tn m T -> @matrix T m n ->
@matrix T m (S n) :=
match m return @Tn m T -> @matrix T m n -> @matrix T m (S n) with
| 0 => (fun V M => tt)
| S m' => (fun V M => Mprepend_row (fst V, fst M) (Mprepend_col (snd V)
(snd M)) )
end.

It fails with

The term "(fst V, fst M)" has type "(T * Tn n T)%type" while it is expected
to have type "Tn ?n ?T".

Here Coq doesn't see that ?n is (S n), so that Tn ?n T is T * Tn n T. It is
understandable that unification can't handle this without knowing that ?n=S
n, but I wonder if there is a way to fix it. It is not so nice that replacing
a pair with a function which does the same just with more restricted types
doesn't work. I find the variant using Mprepend_row more readable and easier
to write, because it is more restricted in its argument types.

Another interesting point is that I usually need the return annotation to get
around the first case in case the second case is wrong. But if the second
case is correct, the return statement is not needed. That is if I remove the
return in the above example, it fails in the first branch. I think this is a
bit odd because the return statement I give is the same as the return type of
the function and thus the type match should return. I am not sure why it
makes a difference to match - it looks a bit redundant.

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