Congruence for heterogenous equality

时光毁灭记忆、已成空白 提交于 2020-01-03 15:18:11

问题


I'm trying to use heterogenous equality to prove statements involving this indexed datatype:

data Counter : ℕ → Set where
  cut : (i j : ℕ) → Counter (suc i + j)

I was able to write my proofs using Relation.Binary.HeterogenousEquality.≅-Reasoning, but only by assuming the following congruence property:

Counter-cong : ∀ {n n′} {k : Counter n} {k′ : Counter n′} →
               {A : ℕ → Set} → (f : ∀{n} → Counter n → A n) →
               k ≅ k′ → f k ≅ f k′
Counter-cong f k≅k′ = {!!}

However, I can't pattern match on k≅k′ being refl without getting the following error message from the type checker:

Refuse to solve heterogeneous constraint 
    k : Counter n =?= k′ : Counter n′

and if I try to do a case analysis on k≅k′ (i.e. by using C-c C-c from the Emacs frontend) to make sure all the implicit arguments are properly matched with respect to their constraints imposed by the refl, I get

Cannot decide whether there should be a case for the constructor
refl, since the unification gets stuck on unifying the 
inferred indices 
    [{.Level.zero}, {Counter n}, k] 
with the expected indices 
    [{.Level.zero}, {Counter n′}, k′]

(if you're interested, here are some non-relevant background: Eliminating subst to prove equality)


回答1:


What you can do is take an additional proof that the two indices are equal:

Counter-cong : ∀ {n n′} {k : Counter n} {k′ : Counter n′} →
               {A : ℕ → Set} → (f : ∀{n} → Counter n → A n) →
               n ≅ n′ → k ≅ k′ → f k ≅ f k′
Counter-cong f refl refl = refl

The original problem is that knowing Counter n ≅ Counter n′ doesn't imply n ≡ n′ because type constructors are not assumed to be injective (there's a flag --injective-type-constructors for this, which in fact makes the match go through, but it's known to be inconsistent with excluded middle), so while it can conclude that the two types are equal it won't rewrite n to n′ and so you get that error when it later checks if k and k′ are unifiable.

Since Counter n has exactly n elements, it's actually possible to prove Counter is injective using something like the pigeonhole principle (and maybe decidable equality for naturals), so you could do without the n ≅ n′ argument, though that'd be messy.

Edit: AFAICT the Het. equality behavior is still the same.



来源:https://stackoverflow.com/questions/9310520/congruence-for-heterogenous-equality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!