Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Type casting of a dependent type

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Type casting of a dependent type


Chronological Thread 
  • From: 劉弘毅 <liukoki AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Type casting of a dependent type
  • Date: Mon, 28 Sep 2020 23:34:24 +0900
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=liukoki AT gmail.com; spf=Pass smtp.mailfrom=liukoki AT gmail.com; spf=None smtp.helo=postmaster AT mail-oi1-f173.google.com
  • Ironport-phdr: 9a23:puc6vR3JEmiMQCNUsmDT+DRfVm0co7zxezQtwd8Zse0TLvad9pjvdHbS+e9qxAeQG9mCtLQe1aGL7ejJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglVhjexe61+IRS5oQjRt8QdnJdvJLs2xhbVuHVDZv5YxXlvJVKdnhb84tm/8Zt++ClOuPwv6tBNX7zic6s3UbJXAjImM3so5MLwrhnMURGP5noHXWoIlBdDHhXI4wv7Xpf1tSv6q/Z91SyHNsD4Ubw4RTKv5LptRRT1iikIKiQ5/XnYhcx+jq1VoByvqR9izYDKfI6YL+Bxcr/HcN4AWWZNQsRcWipcCY28dYsPCO8BMP5erYv7oVkFsByzBQ2tBOPyyT9IgXz23awh3uQuFAHJxg0gH9YUvHvIq9X1Mb4fXOaox6bH0TvNdelZ2Svh6IfWaBAhp+mBULx+fMfPykQhGR/Ig0uQpIHkIj+b2eAAvnaZ4uRuSO+jlXMqph91rzSxyckhlofEiIwRx13a9ih03YY7KN2lREN9fNWqE4NQujmEO4dqRs4uWWJltSYgxrEbuJO2fjIGxIklyhPRbfGMbpKG7Qj5VOmLJDd1nHJld6y7hxa16UWgz/fzVsiw0FpTqSpFk8TAumkD1xDO6MWKROFx/kim2TaI2ADT7v9LLVoomqrcLp4t2r8wlpwNvkTfBiL6hln6gauMekgn+uWk8fnrb7Tkq5OGKoN5iA/zPrwrmsOlAOQ4NgYOX3Kc+eS5zLDj+Uz5QKhJjv0xkanZsYvXJcsepqGjAg9V1pwv5Aq4DzejyNgYh2UILEpZeBKbiIjkI03BIPfhDfumn1uslCpryOvdM736ApTNK2DDn637cbZ87U5c0gszwspF65JaELFSaM70D0T2rZnTCgIzGw2y2efuTttnha0EXmfa+ldhePfWsEKL4eEuC+aJbY4R/j36Lq52tLbVkXYllApFLuGS1pwNZSXgR6g0EwCieXPpx+w5PyISpANnFb7ljVSDVXhYYHPgB/thtAF+M5qvCML4fq7ogLGF233lTJhfZ2QDDVHVVHmxKN7CVPALZyafZMRml25cDOnze8oazRir8TTC5f9iJ+vQ9DcfsMu6htdw7uzX0xo18G4tAg==

Thanks! With the method you showed me, I successfully made the typecasting.

Could I ask you another question? Now, is there a way to show the equivalence of "omega" and "cast"?
I would like to do something like
  omega a = cast a
Since (T (f a)) and (T (g a)) are the different expressions of the same type, these values should be comparable. However, the equation does not type-check.
Moreover, I cannot unfold the "cast" function since it is defined with "Proof" and made opaque. Is it impossible to make this kind of comparison?

Regards,
Koki Ryu

On Mon, Sep 28, 2020 at 9:04 PM Maximilian Wuttke <mwuttke97 AT posteo.de> wrote:
You can indeed 'cast' a value from type `T (f a)` to type `T (g a)` if
you can prove `f a = g a`. To do that, you use the eliminator on `eq`:

```
eq_rect
: forall (A : Type) (x : A) (P : A -> Type), P x ->
  forall y : A, x = y -> P y
```

MWE:

```
Parameter A : Type.
Parameter f g : A -> A.
Parameter T : A -> Type.
Parameter omega : forall a : A, T (f a).

Parameter f_a_eq_g_a : forall (a : A), f a = g a.


Definition cast : forall a : A, T (g a).
Proof.
  intros a.
  elim (f_a_eq_g_a a).
  apply omega.
 *)
Defined.

Print cast.
(*
cast =
fun a : A => eq_rect (f a) (fun a0 : A => T a0) (omega a) (g a)
(f_a_eq_g_a a)
     : forall a : A, T (g a)
*)
```


On 28/09/2020 08:40, 劉弘毅 wrote:
> Hi,
> I defined a function about (A: Type), (f: A -> A),  and (T: A -> Type)
> as follows.
>
> Definition omega (a: A): T (f a)  := (* _expression_ *).
>
> I also took (g: A -> A) and proved the following lemma.
>
> Lemma f_a_eq_g_a : forall (a: A),  f a = g a.
>
> Now, I want to treat (omega a) as a value in (T (g a)). Is there any
> easy way to do this?
> Regards,
> Koki



Archive powered by MHonArc 2.6.19+.

Top of Page