agda - Nested dependent pattern-matching produces errors -
agda - Nested dependent pattern-matching produces errors -
some imports , definitions first:
open import relation.binary.heterogeneousequality open import relation.binary.propositionalequality open import data.nat open import algebra open import data.nat.properties module ℕcs = commutativesemiring commutativesemiring info bin : ℕ → set 0 : bin 0 2*n : ∀ {n} → bin n → bin (n + n) 2*n+1 : ∀ {n} → bin n → bin (suc (n + n)) inc : ∀ {n} → bin n → bin (suc n) inc 0 = 2*n+1 0 inc (2*n b) = 2*n+1 b inc (2*n+1 {n} b) n + suc n | ℕcs.+-comm n (suc n) | 2*n (inc b) ... | ._ | refl | b' = b' nat2bin : (n : ℕ) → bin n nat2bin 0 = 0 nat2bin (suc n) = inc (nat2bin n)
now want prove lemma:
lem : ∀ n → 2*n+1 (inc (nat2bin n)) ≅ inc (inc (2*n+1 (nat2bin n))) lem 0 = refl lem (suc n) = {!!}
the next code produces error:
lem : ∀ n → 2*n+1 (inc (nat2bin n)) ≅ inc (inc (2*n+1 (nat2bin n))) lem 0 = refl lem (suc n) suc (n + suc (suc n)) | ℕcs.+-comm (suc n) (suc (suc n)) ... | ._ | refl = ?
here is:
suc (n + suc (suc n)) != w of type ℕ when checking type (n w : ℕ) (w₁ : w ≡ suc (suc (n + suc n))) → 2*n+1 (inc (inc (nat2bin n))) ≅ inc (inc (2*n+1 (inc (nat2bin n))) | w | w₁ | 2*n (inc (inc (nat2bin n)))) of generated function well-formed
while code typechecks perfectly:
postulate foo : ℕ -> set foo : (m n : ℕ) -> foo (m + n) -> foo (n + m) foo m n x n + m | ℕcs.+-comm n m ... | ._ | refl = x bar : (m n : ℕ) (x : foo (m + n)) -> foo m n x ≅ x bar m n x n + m | ℕcs.+-comm n m ... | ._ | refl = refl
and doesn't typecheck too:
qux : (n m : ℕ) -> (x : foo (n + m)) -> foo m n (foo n m x) ≅ x qux n m x n + m | ℕcs.+-comm n m ... | ._ | refl = ?
the error:
n + m != w of type ℕ when checking type (n m w : ℕ) (w₁ : w ≡ m + n) (x : foo w) → (foo m n (foo n m x | w | w₁) | m + n | .data.nat.properties.simple.+-comm m n) ≅ x of generated function well-formed
what's going wrong?
this not reply specific question but: definitions quite complicated. don't need involved.
inc : ∀ {n} → bin n → bin (suc n) inc 0 = 2*n+1 0 inc (2*n b) = 2*n+1 b inc (2*n+1 {n} b) rewrite ℕcs.+-comm (suc n) n = 2*n (inc b) lem : ∀ n → 2*n+1 (inc (nat2bin n)) ≅ inc (inc (2*n+1 (nat2bin n))) lem n rewrite ℕcs.+-comm (suc n) n = refl
pattern-matching agda
Comments
Post a Comment