I've been bashing my head against this problem for a while: I have record types, with dependent fields, and I want to prove equalities on record transformations. I've tried to distill the crux of my problem into a small example. Consider the following record type Rec, which has dependency between the fields:
module Bar where
open import Data.Nat
open import Relation.Binary.PropositionalEquality as PE
open import Relation.Binary.HeterogeneousEquality as HE
record Rec : Set where
field val : ℕ
inc : {n : ℕ} -> ℕ
succ : inc {0} ≡ val
open Rec
The succ property states a relationship between the other two fields: that inc {0} returns val. The following function incR defines a Rec transformer that increments the value and the incrementor by a fixed value m, which preserves their interaction:
succPrf : {x : Rec} {m : ℕ} -> (inc x {0} + m) ≡ val x + m
succPrf {x} {m} rewrite (PE.cong (\x -> x + m) (succ x)) = refl
incR : Rec -> ℕ -> Rec
incR x m = record {
val = val x + m
; inc = λ{n} -> inc x {n} + m
; succ = succPrf {x} {m} }
Here succPrf gives the proof that the inc/val relationship holds.
Now, I want to prove the following:
incR0 : forall {x : Rec} -> incR x 0 ≡ x
incR0 {x} = {!!}
This turns out to be quite difficult however because of the dependency within the records.
I tried breaking it down into individual equalities on the fields, with the aim of using a congruence to put it back together: and it seems I can get fairly far:
postulate
ext : {A : Set} {B : Set}
{f g : {a : A} -> B} ->
(forall {n : A} -> f {n} ≡ g {n})
-> (λ {n : A} -> f {n}) ≡ (λ {n : A} -> g {n})
-- Trivial, but for tersity just postulated
runit : {n : ℕ} -> n + 0 ≡ n
incRVal : forall {x : Rec} -> val (incR x 0) ≡ val x
incRVal {x} rewrite runit {val x} = refl
incRinc : forall {x : Rec} -> (λ{n : ℕ} -> inc (incR x 0) {n}) ≡ (λ{n : ℕ} -> inc x {n})
incRinc {x} rewrite ext (λ{n : ℕ} -> runit {inc x {n}}) = refl
And on the succ field, we have to resort to heterogenous equality
succIncR : {x : Rec} -> (inc (incR x 0) {0} ≡ val (incR x 0) + 0)
≡ (inc x {0} ≡ val x)
succIncR {x} rewrite runit {inc x {0}} | runit {val x} | incRVal {x}
= refl
incRsucc : forall {x : Rec} -> succ (incR x 0) ≅ succ x
incRsucc {x} rewrite succIncR {x} | succ x | runit {val x}
= HE.reflexive refl
But I'm struggling to combine these together adequately. I really need some kind of congruence for Pi-types so that I can plug incRinc and incRsucc together in one go, but I've failed to build this. I'm at the point where I can't see the wood for the trees, so though I would see what SO thought. Am I missing some easy technique here?