Types 如何在agda中通过W型编码?
我试图在Agda中通过W-TYPE对列表进行编码,当我试图证明我的编码正确时,我得到了以下无法解决的目标Types 如何在agda中通过W型编码?,types,functional-programming,agda,induction,Types,Functional Programming,Agda,Induction,我试图在Agda中通过W-TYPE对列表进行编码,当我试图证明我的编码正确时,我得到了以下无法解决的目标 Goal: g (f (x a)) ≡ x a' Have: g (f (x a')) ≡ x a' ———————————————————————————————————————————————————————————— a' : A x : A → W (⊤ ⊔ A) Blist a : A A : Type 我假设在等价中定义正向函数时,f(sup(inra)x)=a∷ f(x
Goal: g (f (x a)) ≡ x a'
Have: g (f (x a')) ≡ x a'
————————————————————————————————————————————————————————————
a' : A
x : A → W (⊤ ⊔ A) Blist
a : A
A : Type
我假设在等价中定义正向函数时,f(sup(inra)x)=a∷ f(xa)
,需要以某种方式不仅仅将x应用于a,但我不知道如何做到这一点。否则,我定义的bx
是否错误,或者在向后函数g
中是否存在其他一些小错误?如何调试这一点?我可以提供所有使用的代码,但为了简洁起见,我希望错误可以被肉眼发现。另请注意,λ≡ 表示函数的可扩展性
data W (A : Type) (B : A → Type) : Type where
sup : (a : A) → ((b : B a) → W A B) → W A B
Blist : ∀ {A} → ⊤ ⊔ A → Type
Blist (inl x) = ⊥
Blist {A} (inr x) = A
List' : Type → Type
List' A = W (⊤ ⊔ A) Blist
data List (A : Type) : Type where
[] : List A
_∷_ : A → List A → List A
ListsEquiv : ∀ {A} → List' A ≃ List A
ListsEquiv {A} = equiv f g fg gf
where
f : List' A → List A
f (sup (inl top) x) = []
f (sup (inr a) x) = a ∷ f (x a)
g : List A → List' A
g [] = sup (inl tt) abort
g (a ∷ as) = sup (inr a) λ a' → g as
fg : (y : List A) → f (g y) ≡ y
fg [] = refl
fg (x ∷ y) = ap (λ - → x ∷ -) (fg y)
gf : (x : List' A) → g (f x) ≡ x
gf (sup (inl tt) x) = ap (λ - → sup (inl tt) -) (λ≡ (λ x₁ → abort x₁))
gf (sup (inr a) x) = ap (λ - → sup (inr a) -) (λ≡ (λ a' → {!gf (x a')!}))
正如@HTNW所指出的,arity索引类型的编码方式与自然数的编码方式相同,因此它只是用作索引数据的基类型。因此,下面的修改可以使证明顺利进行 很容易混淆数据应该如何编码到有序构造函数中,因此容易出现看似简单的错误
Blist : ∀ {A} → ⊤ ⊔ A → Type
Blist (inl x) = ⊥
Blist (inr x) = ⊤
List' : Type → Type
List' A = W (⊤ ⊔ A) Blist
ListsEquiv : ∀ {A} → List' A ≃ List A
ListsEquiv {A} = equiv f g fg gf
where
f : List' A → List A
f (sup (inl top) x) = []
f (sup (inr a) x) = a ∷ f (x tt)
g : List A → List' A
g [] = sup (inl tt) abort
g (a ∷ as) = sup (inr a) λ a' → g as
fg : (y : List A) → f (g y) ≡ y
fg [] = refl
fg (x ∷ y) = ap (λ - → x ∷ -) (fg y)
gf : (x : List' A) → g (f x) ≡ x
gf (sup (inl tt) x) = ap (λ - → sup (inl tt) -) (λ≡ (λ x₁ → abort x₁))
gf (sup (inr a) x) = ap (λ - → sup (inr a) -) (λ≡ (λ a' → gf (x a')))
嗯,我不知道Agda,但不应该
Blist(inrx)=⊤代码>?[]
构造函数具有零(⊥代码>)用于递归的插槽,以及每个_∷_ x
构造函数应该有一个(⊤代码>)插槽,而不是为A
的每个元素分配一个插槽。将Blist:Bool->Type;Blist b=如果是b,那么一个else\bot
也能正常工作吗?即,如果A
s存储在分支中,而不是形状中?