4

It seems that to prove that two items of a record type are equivalent, I need to write a helper that takes component wise proofs and applies them. An example:

postulate P : ℕ → Set

record Silly : Set (ℓsuc ℓ₀) where
 constructor _#_#_
 field
  n : ℕ
  pn : P n
  f : Set → ℕ

open Silly

SillyEq : ∀ s t → n s ≡ n t → pn s ≅ pn t → f s ≡ f t → s ≡ t
SillyEq (n # pn # f) (.n # .pn # .f) ≡-refl ≅-refl ≡-refl = ≡-refl

I feel like SillyEq should somehow be available to me, that I do not need to write it myself --or am I mistaken.

Also, I could not prove SillyEq without declaring a constructor and then pattern matching on it.

Thanks for your assistance!

Musa Al-hassy
  • 982
  • 1
  • 7
  • 12

1 Answers1

5

Having

SillyEq' : ∀ {n₁ n₂ pn₁ pn₂ f₁ f₂}
         → n₁ ≡ n₂ → pn₁ ≅ pn₂ → f₁ ≡ f₂ → (n₁ # pn₁ # f₁) ≡ (n₂ # pn₂ # f₂)

you can prove SillyEq as

SillyEq : ∀ s t → n s ≡ n t → pn s ≅ pn t → f s ≡ f t → s ≡ t
SillyEq _ _ = SillyEq'

due to the η-rule for Silly. So if you have an arity-generic version of cong, then you can prove SillyEq as (note the heterogeneous equality everywhere)

SillyEq : ∀ s t → n s ≅ n t → pn s ≅ pn t → f s ≅ f t → s ≅ t
SillyEq _ _ = gcong 3 _#_#_

I don't know whether gcong can be easily expressed via reflection, but I guess it can be written using the usual arity-generic programming stuff (like here), but the solution won't be short.

Here is an ad hoc proof:

cong₃ : ∀ {α β γ δ} {A : Set α} {B : A -> Set β} {C : ∀ {x} -> B x -> Set γ}
          {D : ∀ {x} {y : B x} -> C y -> Set δ} {x y v w s t}
      -> (f : ∀ x -> (y : B x) -> (z : C y) -> D z)
      -> x ≅ y -> v ≅ w -> s ≅ t -> f x v s ≅ f y w t
cong₃ f refl refl refl = refl

SillyEq : ∀ s t → n s ≅ n t → pn s ≅ pn t → f s ≅ f t → s ≅ t
SillyEq _ _ = cong₃ _#_#_

However, a mix of propositional and heterogeneous equalities like in your case complicates everything.

Community
  • 1
  • 1
effectfully
  • 12,325
  • 2
  • 17
  • 40
  • Perhaps the mix of the two forms of equalities is not the best, but what're the major downsides of using, say, heterogeneous equality exclusively? Also are you saying that, as far as you know, the only way to prove equalities of record types is to use variations of cong? – Musa Al-hassy Jan 07 '16 at 06:06
  • 3
    @Musa Al-hassy, it's OK to use just heterogeneous equality. When `x` and `y` in `x ≅ y` have the same type, `_≅_` acts like `_≡_` and there are no problems, you just need slightly more explicit types. But when `x : A i` and `y : A j` you lose the ability to use standard `cong`, `subst` and similar stuff on `x ≅ y`. I prefer to define a wrapper (similar to `PathOver` from [this](http://dlicata.web.wesleyan.edu/pubs/lb15cubicalsynth/lb15cubicalsynth.pdf) paper which contains `indeq : i ≡ j` and `valeq : x ≅ y` and define new `cong` and `subst` stuff over it. – effectfully Jan 07 '16 at 06:52
  • 1
    @Musa Al-hassy, some records are definitionally equal like with `all-eq : {x y : ⊤} -> x ≡ y` or `record R : Set where field .n : ℕ ; all-eq₂ : {r s : R} -> r ≡ s`, but others require proving. How would you know that two tuples are equal without knowing that their projections are equal? Or what do you want to hold? – effectfully Jan 07 '16 at 06:57
  • "(similar to PathOver from this paper)" — missed the parenthesis. – effectfully Jan 07 '16 at 07:00
  • 2
    @Musa Al-hassy, an [example](http://lpaste.net/148594) of what I'm talking about. Try to do the same with heterogeneous equality without proving that natural numbers addition is associative. – effectfully Jan 07 '16 at 07:28
  • Thanks for the paper-link, I've just begun it. Regarding your sample code, would you please shed some light on why making the type explicit alleviate problems. To me it seems almost the same as the agda-library definition, which leaves the type implicit. Thanks. – Musa Al-hassy Jan 18 '16 at 04:04
  • @Musa Al-hassy, I've elaborated in the answer to your new question. – effectfully Jan 18 '16 at 07:27