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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With