Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Can one define an implicit coercion from a 1x1 matrix to a scalar?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Can one define an implicit coercion from a 1x1 matrix to a scalar?


Chronological Thread 
  • From: Robert Rand <rrand AT seas.upenn.edu>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Can one define an implicit coercion from a 1x1 matrix to a scalar?
  • Date: Fri, 30 Aug 2019 14:50:14 -0400
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=rrand AT seas.upenn.edu; spf=Pass smtp.mailfrom=rrand AT seas.upenn.edu; spf=None smtp.helo=postmaster AT mx0a-000c2a01.pphosted.com
  • Ironport-phdr: 9a23:p2djlhFfTa5KQt4PJVDGd51GYnF86YWxBRYc798ds5kLTJ78rsmwAkXT6L1XgUPTWs2DsrQY0rCQ6v68EjVbud6oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vMhm6txjdu8gZjIdtN6o8xAfFqWZUdupLwm9lOUidlAvm6Meq+55j/SVQu/Y/+MNFTK73Yac2Q6FGATo/K2w669HluhfFTQuU+3sTSX4WnQZSAwjE9x71QJH8uTbnu+Vn2SmaOcr2Ta0oWTmn8qxmRgPkhDsBOjUk9mzcl85+g79BoB+5qBN/zYzbboGbOvR9Y63TY88VSHFbUcpNTSFMGJ+wY5cNAucHIO1Wr5P9p1wLrRamGQesA/jgxSFShn/qwKY0z/4uEQfb0wc9GN8Oqm7Uo8/zNKgPSu2117fHwi/Yb/9MxDf98JbHchYnof2WQ71/bNfRxFApGgjYgFuQronlMCmU1uQLq2Wb7uxgVfiui2E9sQ1xrCKvyt8tionPmoIa1FTE+T9kz4krI9CzVU11Yca8HZdNuCyXNJF6Tt4jTmxmoio2170LtYOhcCUO1pgr3wDTZ+CDfoSS4R/uVPydLSp5iX54Yr6yiBa//E69wePmTMa0ykxFri9dn9nMqH8N0xvT59CCSvpy4kuuwy+D2xzP5u1YPU84i7DUJ4I8zrIqjpoTqUTDHijtmEXqkqCZa18o9fSv6+Tiernmp5mcOJFoigzmL6gjlc+yDf4lPgUPUWWX4/mw2b3+8UHjRLhGkOU6kqzDv5DbIcQbqLS5AwhQ0os78Ra/FS2p0NIFknQcN1JKZgiIj5PzN1HTOPD3E/G/g1K2nDh12v/GI6XtAo/RIXjbjLfhYbF95lZAxwo01NBT/o5bCrUcIP3oQULxr9zZDhohMwOu2ernCdN91pkfWW2VGKOZPrnS4he04bckJPDJb4sIsh78LeIk7rjglywXg1gYKJOu15YNdDiCF/JqaxGDe3Pqjv8aHG4R+BcmQerszlCOTGgAND6JQ6sg62RjW8qdBoDZS9X12eDT7GKABpRTI1t+JBWUC36xKdefVv4XLj+KL8ln1DEISOr5EtJz5VSVrAb/joFfAK/U9ykf78Kx0cgt7qiLzUk5rzUsVoKFy2GKVH15kiUDQDpkhPku83w48U+K1O1Du9IdENVS4/1TVQJja8zHwuVhTc3qVwTHONqFVQT/Tw==

Using QWIRE's matrices I was able to define:

```
Definition to_scalar (A : Matrix 1 1) : C := A 0 0.

Notation Matrix11 := (Matrix 1 1).

Coercion to_scalar : Matrix11 >-> C.
```

but I get the warning "to_scalar does not respect the uniform inheritance condition" which seems to imply "this coercion will not work". 

(The Coq documentation https://coq.inria.fr/refman/addendum/implicit-coercions.html implies that I shouldn't even be able to define a coercion that doesn't respect the uniform inheritance condition so I'm not sure why this gives a warning rather than an error.)

Alternatively, I can define:

```
Definition to_scalar (m n : nat) (A: Matrix m n) : C := A 0 0.

Coercion to_scalar : Matrix >-> C.
```

This works, but it doesn't obey your restriction that it only applies to Matrix 1 1 (which is a desirable restriction).

I would also like the ability to say `Coercion to_scalar : forall A, Matrix A -> A` (assuming parametric matrices) but `Coercion` doesn't seem to support any kind of dependency.

Best,
Robert


On Wed, Aug 21, 2019 at 12:07 PM Soegtrop, Michael <michael.soegtrop AT intel.com> wrote:

Dear Coq Users,

 

I wonder if it is possible to define an implicit coercion between a 1x1 matrix (either using mathcomponent’s or Coquelicot’s definition) and the respective scalar type?

 

I see two problems with this:

 

1.)    I don’t see how I could specialize the coercion to the size parameters 1x1. I can define this as separate type mat11, but then I need to use a type annotation to mat11 to enable the coercion. I tried to make an identity coercion between matrix and mat11 but couldn’t figure it out.

2.)    Ideally I would like to have this for matrices of any types, not just specific types like R or C. But I don’t see a way to use a parameter of the first class as second class.

 

Is it possible to do this?

 

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