我在鍛鍊。這似乎是一個簡單的事情(簡化,以顯示該問題顯然是在名單分裂):如何證明列表拆分有效?
infixr 4 _::_ _++_ _==_
data _==_ {A : Set} : (x : A) -> (y : A) -> Set where
refl : (x : A) -> x == x
data List (A : Set) : Set where
nil : List A
_::_ : A -> List A -> List A
_++_ : forall {A} -> List A -> List A -> List A
nil ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
data Permutation {A : Set} : List A -> List A -> Set where
pnil : Permutation nil nil
p:: : forall {xs} -> (x : A) ->
(zs : List A) -> (y : A) -> (ys : List A) ->
x == y -> Permutation xs (zs ++ ys) ->
Permutation (x :: xs) (zs ++ (y :: ys))
lemma-ripTop : forall {A} -> (xs : List A) ->
(y : A) -> (ys : List A) ->
Permutation xs (y :: ys) ->
Permutation xs (y :: ys)
lemma-ripTop nil y ys()
lemma-ripTop (x :: xs) y ys (p:: .x zs y1 ys1 x==y1 ps) =
p:: x zs y1 ys1 x==y1 ps
長期和短期的它,我宣佈一個可如果他們可以定義兩個列表的置換,提供具有一對相等元件x
和y
的較小列表的Permutation
,並且y
的插入位置由zs
和ys
確定。
然後lemma-ripTop
(是爲了做一些完全不同的,但在這裏它只是id
上Permutation
)需要證明的東西給出一個列表(y :: ys
)一個Permutation
。
我不明白爲什麼阿格達需要看到
zs ++ (y1 :: ys1) == y :: ys
(這是我的錯誤) - 我認爲這應該是從類型聲明,構造清楚了嗎?即由於Permutation xs (y :: ys)
是在輸入時給出的,因此在構造函數p::
中作爲見證提供的分割應該已經添加到y :: ys
。如何說服Agda這個分割的列表是有效的?
錯誤消息:
zs ++ y1 :: ys1 != y :: ys of type List A
when checking that the pattern p:: .x zs y1 ys1 x==y1 ps has type
Permutation (x :: xs) (y :: ys)
太好了!我也在想Sigmas,看起來相當難看。 insert_into _ == _看起來好多了。我會嘗試的。 –