简体   繁体   English

一个人如何编写(和调试)一个依赖于两个参数的应用程序 apd2,并使用它来证明这种 ap 在 agda 中的功能性?

[英]How does one write (and debug) a two arguement dependent application, apd2, and use this to prove functoriality of such ap in agda?

I'm trying to prove the functoriality of ap under the dependent product type, analgous to Theorem 2.6.5 in the HoTT book, in Agda, and am stuck as to how to how to present the type for he functoriality condition in the presence of the dependent type, as it requires transport.我试图在依赖产品类型下证明 ap 的函数性,类似于在 Agda 的 HoTT 书中的定理 2.6.5,并且对于如何在存在的情况下如何呈现函数性条件的类型感到困惑依赖类型,因为它需要传输。 The book suggests this as an exercise at the end of section 2.7.本书在第 2.7 节的末尾建议将此作为练习。

functorDProdEq : {A A' : Set} {P : A → Set} {Q : A' → Set} (g : A → A')
                 (h : (a : A) →  P a → Q (g a))
                 → ((x1 , y1) (x2 , y2) : Σ A λ a → P a)
                 → (p : x1 ≡ x2) (q : p* {p = p} y1 ≡ y2)
                 → apf (λ - → fDprod g h -) (dpair= (p , q))
                 ≡ dpair= ((apf g p , {!apd (ap2 h ? ?)!} ))
functorDProdEq = {!!}

Above is the attempted definition, with a standalone file below from which the supporting material can be found.上面是尝试的定义,下面有一个独立的文件,可以从中找到支持材料。 The goal in the hole is:洞中的目标是:

Goal: p* (h (fst .patternInTele0) (snd .patternInTele0)) ≡
      h (fst .patternInTele1) (snd .patternInTele1)

In a context seen below.在下面看到的上下文中。 I don't understand the patternInTele* business, as I don't know where it would have been declared, and would greatly appreciate any elaboration.我不了解 patternInTele* 业务,因为我不知道它会在哪里声明,并且非常感谢任何详细说明。 Additionally, my thought to implement a dependent application function with two equalities, ap2d , the second equality induced by the transportation of the former.此外,我想实现一个依赖应用程序 function 有两个相等, ap2d ,前者的传输引起的第二个相等。

ap2d : {A : Set} {x x' : A}  {P : A → Set} {y : P x} {y' : P x'} {C : (x : A)
  → P x → Set} (f : (x : A) → (y : P x) → C x y )
  → (p : x ≡ x') → (q : (p *) y ≡ y') →
  p* {p = p} f x y ≡ {!!}
  -- p* {p = q} (p* {p = p} (f x)) y ≡ {!f x' y'!}
  -- (f x y ≡ f x' y')
ap2d = {!!}

However, I can't even get this to work.但是,我什至无法让它工作。 It seems that one would perform a double transport to get the desired result, but nothing I do on the lhs of the final equality seems to change the goal, which is always C xy instead of the desired C x' y' .似乎有人会执行双重传输以获得所需的结果,但我在最终相等的 lhs 上所做的任何事情似乎都不会改变目标,这始终是C xy而不是所需的C x' y' Is this the proper way to think about defining what I'm after, and does this help solve the original problem of producing a correct functorial theorem statement?这是思考定义我所追求的正确方法吗,这是否有助于解决产生正确函子定理陈述的原始问题? What is the correct way to implement both functorDProdEq and ap2d in this context such that they economize on space, as the type signatures tend to get hairy?在这种情况下实现functorDProdEqap2d以节省空间的正确方法是什么,因为类型签名往往会变得多毛?

--the context from above
y2 : P (fst .patternInTele1)
y2 = snd .patternInTele1
x2 : A
x2 = fst .patternInTele1
y1 : P (fst .patternInTele0)
y1 = snd .patternInTele0
x1 : A
x1 = fst .patternInTele0
q  : p* (snd .patternInTele0) ≡ snd .patternInTele1
p  : fst .patternInTele0 ≡ fst .patternInTele1
.patternInTele1
   : Σ A (λ a → P a)   (not in scope)
.patternInTele0
   : Σ A (λ a → P a)   (not in scope)
h  : (a : A) → P a → Q (g a)
g  : A → A'
Q  : A' → Set
P  : A → Set
A' : Set
A  : Set

And, finally, here's the code.最后,这是代码。

module question where

open import Agda.Builtin.Sigma public

data _≡_ {A : Set} (a : A) : A → Set where
  r : a ≡ a

infix 20 _≡_

J : {A : Set}
    → (D : (x y : A) → (x ≡ y) →  Set)
    -- → (d : (a : A) → (D a a r ))
    → ((a : A) → (D a a r ))
    → (x y : A)
    → (p : x ≡ y)
    ------------------------------------
    → D x y p
J D d x .x r = d x

-- ap\_
apf : {A B : Set} → {x y : A} → (f : A → B) → (x ≡ y) → f x ≡ f y
apf {A} {B} {x} {y} f p = J D d x y p
  where
    D : (x y : A) → x ≡ y → Set
    D x y p = {f : A → B} → f x ≡ f y
    d : (x : A) → D x x r
    d = λ x → r 

id : {A : Set} → A → A
id = λ z → z

transport : ∀ {A : Set} {P : A → Set} {x y : A} (p : x ≡ y)  → P x → P y
transport {A} {P} {x} {y} = J D d x y
  where
    D : (x y : A) → x ≡ y → Set
    D x y p =  P x → P y
    d : (x : A) → D x x r
    d = λ x → id

p* : {A : Set} {P : A → Set} {x : A} {y : A} {p : x ≡ y} → P x → P y
-- p* {P = P} {p = p} u = transport P p u
p* {P = P} {p = p} u = transport p u

_* : {A : Set} {P : A → Set} {x : A} {y : A} (p : x ≡ y) → P x → P y
(p *) u = transport p u
-- p * u = transport p u

apd : {A : Set} {P : A → Set} (f : (x : A) → P x) {x y : A} {p : x ≡ y}
  → p* {P = P} {p = p} (f x) ≡ f y
apd {A} {P} f {x} {y} {p} = J D d x y p
  where
    D : (x y : A) → x ≡ y → Set
    D x y p = p* {P = P} {p = p} (f x) ≡ f y
    d : (x : A) → D x x r
    d = λ x → r

_×_ : Set → Set → Set
A × B = Σ A (λ _ → B)

-- 2.6.1
fprodId : {A B : Set} {x y : A × B} → _≡_ {A × B} x y → ((fst x) ≡ (fst y)) × ((snd x) ≡ (snd y))
fprodId p = (apf fst p) , (apf snd p)
-- fprodId r = r , r

-- 2.6.4
-- alternative name consistent with book, A×B
×fam : {Z : Set} {A B : Z → Set} → (Z → Set)
×fam {A = A} {B = B} z = A z × B z

transport× : {Z : Set} {A B : Z → Set} {z w : Z} (p : z ≡ w) (x : ×fam {Z} {A} {B} z) → (transport p x ) ≡ (transport {Z} {A} p (fst x) , transport {Z} {B} p (snd x))
transport× r s = r

fprod : {A B A' B' : Set} (g : A → A') (h : B → B') → (A × B → A' × B')
fprod g h x = g (fst x) , h (snd x)

-- inverse of fprodId
pair= : {A B : Set} {x y : A × B} → (fst x ≡ fst y) × (snd x ≡ snd y) → x ≡ y
pair= (r , r) = r

-- 2.6.5
functorProdEq : {A B A' B' : Set} (g : A → A') (h : B → B')  (x y : A × B) (p : fst x ≡ fst y) (q : snd x ≡ snd y) →  apf (λ - → fprod g h -) (pair= (p , q)) ≡ pair= (apf g p , apf h q)
functorProdEq g h (a , b) (.a , .b) r r = r


  
-- 2.7.3
etaDprod : {A : Set} {P : A → Set} (z : Σ A (λ x → P x)) → z ≡ (fst z , snd z)
etaDprod z = r

-- 2.7.4
Σfam : {A : Set} {P : A → Set} (Q : Σ A (λ x → P x) → Set) → (A → Set)
Σfam {P = P} Q x = Σ (P x) λ u → Q (x , u) 

dpair= : {A : Set} {P : A → Set} {w1 w1' : A} {w2 : P w1 } {w2' : P w1'} →  (p : Σ (w1 ≡ w1') (λ p → p* {p = p} w2 ≡ w2')) → (w1 , w2) ≡ (w1' , w2')
dpair= (r  , r) = r

transportΣ : {A : Set} {P : A → Set} (Q : Σ A (λ x → P x) → Set) (x y : A) (p : x ≡ y) ((u , z) : Σfam Q x)
             →  _* {P = λ - → Σfam Q - } p (u , z) ≡ ((p *) u  , _* {P = λ - → Q ((fst -) , (snd -))} (dpair= (p , r)) z)
transportΣ Q x .x r (u , z) = r -- some agda bug here.  try ctrl-c ctrl-a

fDprod : {A A' : Set} {P : A → Set} {Q : A' → Set} (g : A → A') (h : (a : A) →  P a → Q (g a)) → (Σ A λ a → P a) → (Σ A' λ a' → Q a')
fDprod g h (a , pa) = g a , h a pa

ap2 : {A B C : Set} {x x' : A} {y y' : B} (f : A → B → C)
      → (x ≡ x') → (y ≡ y') → (f x y ≡ f x' y')
ap2 f r r = r

apd' : {A : Set} {P : A → Set} (f : (x : A) → P x) {x y : A} {p : x ≡ y}
  → p* {P = P} {p = p} (f x) ≡ {!f y!}
  -- →  (f x) ≡ {!!}
apd' = {!!}

ap2d : {A : Set} {x x' : A}  {P : A → Set} {y : P x} {y' : P x'} {C : (x : A)
  → P x → Set} (f : (x : A) → (y : P x) → C x y )
  → (p : x ≡ x') → (q : (p *) y ≡ y') →
  p* {p = p} f x y ≡ {!!}
  -- p* {p = q} (p* {p = p} (f x)) y ≡ {!f x' y'!}
  -- (f x y ≡ f x' y')
ap2d = {!!}

-- (.patternInTele0 .patternInTele1 : Σ A P)

functorDProdEq : {A A' : Set} {P : A → Set} {Q : A' → Set} (g : A → A') 
                 (h : (a : A) →  P a → Q (g a))
                 → ((x1 , y1) (x2 , y2) : Σ A λ a → P a)
                 → (p : x1 ≡ x2) (q : p* {p = p} y1 ≡ y2)
                 → apf (λ - → fDprod g h -) (dpair= (p , q))
                 ≡ dpair= ((apf g p , {!apd (ap2 h ? ?)!} ))
functorDProdEq = {!!}

As a partial answer, I was able to refactor with a new transportd function via Escardo's notes, which makes everything explicit.作为部分答案,我能够通过 Escardo 的注释使用新transportd的 function 进行重构,这使得一切都变得明确。 Nonetheless, I still find it a bit confusing what is actually happening.尽管如此,我仍然觉得实际发生的事情有点令人困惑。

transportd : {X : Set } (A : X → Set  ) (B : (x : X) → A x → Set )
  {x : X} ((a , b) : Σ (A x) λ a → B x a) {y : X} (p : x ≡ y)
  → B x a → B y (transport {P = A} p a)
transportd A B (a , b) r = id

ap2d : {A : Set} {x x' : A}  {P : A → Set} {y : P x} {y' : P x'} {C : (x : A)
  → P x → Set} (f : (x : A) → (y : P x) → C x y )
  → (p : x ≡ x') → (q : p* {P = P} {p = p} y ≡ y') → 
  p* {P = C x'} {p = q} (transportd P C (y , (f x y)) p (f x y)) ≡ f x' y'
ap2d f r r = r

Regarding the .patternInTele1 pattern, I was able to remediate this by not pattern matching in the type signature but instead calling the fst and snd constructors, so that the context now looks like关于.patternInTele1模式,我能够通过不在类型签名中进行模式匹配而是调用 fst 和 snd 构造函数来解决这个问题,因此上下文现在看起来像

Goal: p* (h (fst x) (snd x)) ≡ h (fst y) (snd y)
————————————————————————————————————————————————————————————
q  : p* (snd x) ≡ snd y
p  : fst x ≡ fst y
y  : Σ A (λ a → P a)
x  : Σ A (λ a → P a)
h  : (a : A) → P a → Q (g a)
g  : A → A'
Q  : A' → Set
P  : A → Set
A' : Set
A  : Set
———— Constraints ———————————————————————————————————————————
_2596 := (_ : _P_2595) y : _A_2583

where the new functorDProdEq is:其中新的functorDProdEq是:

functorDProdEq : {A A' : Set} {P : A → Set} {Q : A' → Set} (g : A → A') 
                 (h : (a : A) →  P a → Q (g a))
                 → (x y : Σ A λ a → P a)
                 → (p : fst x ≡ fst y) (q : p* {p = p} (snd x) ≡ snd y)
                 → apf (λ - → fDprod {P = P} {Q = Q} g h -) (dpair= (p , q))
                 ≡ dpair= (apf g p , ? )
functorDProdEq = {!!}

I'm still having problems, as it won't allow me to fill this final hole.我仍然有问题,因为它不允许我填补最后一个洞。 If I replace the question mark with ap2d hpq it highlights the last two lines yellow, and says如果我用ap2d hpq替换问号,它会突出显示最后两行黄色,并说

P (fst y) != A' of type Set
when checking that the expression ap2d h p q has type
p* (h (fst x) (snd x)) ≡ h (fst y) (snd y)

I still find the agda error messages unreadable, specifically the != * of type Set .我仍然发现 agda 错误消息不可读,特别是!= * of type Set Are there any resources to understand this?是否有任何资源可以理解这一点? If instead, I try to fill the hole in step by step, it wont let me pattern match either p or q, as in ap2d hp {!q!} gives相反,如果我尝试一步一步地填补这个洞,它不会让我模式匹配 p 或 q,如ap2d hp {!q!}给出

Goal: p* _y_2654 ≡ snd y
Have: p* (snd x) ≡ snd y

Which seems like it should be correct?哪个看起来应该是正确的? What am I missing?我错过了什么?

Additionally, is it advisable to never pattern match in a typing context if you are reasoning about the type youre building (I know its generally bad practice to try to define types you don't understand, but I'm doing so for the sake of this exercise.)此外,如果您正在推理您正在构建的类型,是否建议不要在类型上下文中进行模式匹配(我知道尝试定义您不理解的类型通常是不好的做法,但我这样做是为了这个练习。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM