简体   繁体   English

Agda:未能解决以下约束:P x <= _X_53(在 _X_53 上被阻止)

[英]Agda: Failed to solve the following constraints: P x <= _X_53 (blocked on _X_53)

I'm writing Agda code as I read the HoTT book.我在阅读HoTT书时正在编写 Agda 代码。 I'm stuck on Lemma 2.3.9:我被困在引理 2.3.9 上:

data _≡_ {X : Set} : X -> X -> Set where
  refl : {x : X} -> x ≡ x
infix 4 _≡_

-- Lemma 2.1.2
_·_ :  {A : Set} {x y z : A} -> x ≡ y -> y ≡ z -> x ≡ z
refl · refl = refl

-- Lemma 2.3.1
transp : {A : Set} {P : A -> Set} {x y : A} -> x ≡ y -> P x -> P y
transp refl f = f

lemma2'3'9 : {A : Set}{P : A -> Set}{x y z : A}{p : x ≡ y}{q : y ≡ z}{u : P x} -> 
             (transp q (transp p u)) ≡ (transp (p · q) u)
lemma2'3'9 {p = refl} {q = refl} = ?

Type-checking with Adga Emacs Mode gives me the following error:使用 Adga Emacs 模式进行类型检查会出现以下错误:

?0 : transp refl (transp refl u) ≡ transp (refl · refl) u
_X_53 : Set  [ at /home/user/prog/agda/sample.agda:12,38-39 ]

———— Errors ————————————————————————————————————————————————
Failed to solve the following constraints:
  P x =< _X_53 (blocked on _X_53)

Questions问题

  1. What is '_X_53', and why is it greater than or equal to (P x)?什么是'_X_53',为什么大于或等于(P x)?
  2. How can I get rid of this error?我怎样才能摆脱这个错误?

Note I wrote a working example of Lemma 2.3.9 in Coq, so I'm assuming it's possible in Agda.注意我在 Coq 中写了一个引理 2.3.9 的工作示例,所以我假设它在 Agda 中是可能的。

Inductive eq {X:Type} (x: X) : X -> Type :=
  | refl : eq x x.
Notation "x = y" := (eq x y)
                       (at level 70, no associativity)
                     : type_scope.

Definition eqInd{A} (C: forall x y: A, x = y -> Type) (c: forall x: A, C x x (refl x)) (x y: A): forall p: x = y, C x y p :=
  fun xy: x = y => match xy with
            | refl _ => c x
            end.

Definition dot'{A}{x y: A}: x = y -> forall z: A, y = z -> x = z :=
  let D := fun x y: A => fun p: x = y => forall z: A, forall q: y = z, x = z in
  let d: forall x, D x x (refl x) := let E: forall x z: A, forall q: x = z, Type := fun x z: A => fun q: x = z => x = z in
                                let e := fun x => refl x
                                in  fun x z => fun q => eqInd E e x z q
  in fun p: x = y => eqInd D d x y p.

(* Lemma 2.1.2 *)
Definition dot{A}{x y z: A}: x = y -> y = z -> x = z :=
  fun p: x = y => dot' p z.

Definition id {A} := fun a: A => a.

(* Lemma 2.3.1 *)
Definition transp{A} {P: A -> Type} {x y: A}: x = y -> P x -> P y :=
  fun p =>
  let D := fun x y: A => fun p: x = y => P x -> P y in
  let d: forall x, D x x (refl x) := fun x => id
  in  eqInd D d x y p.

Lemma L_2_3_9{A}{P: A -> Type}{x y z: A}{p: x = y}{q: y = z}{u: P x}:
  transp q (transp p u) = transp (dot p q) u.
Proof.
  unfold transp, dot, dot'.
  rewrite <- q.
  rewrite <- p.
  reflexivity.
  Qed.

_X_53 is a meta variable, ie, an unknown part of a term. _X_53是元变量,即术语的未知部分。 In order to figure out this unknown part of the term, Agda tries to resolve the meta variable.为了弄清楚术语的这个未知部分,Agda 尝试解析元变量。 She does so by looking at the context the meta variable appears in, deriving constraints from this context, and determining possible candidate solutions for the meta variable that meet the constraints.她通过查看元变量出现的上下文、从该上下文导出约束并确定满足约束的元变量的可能候选解决方案来做到这一点。

Among other things, Agda uses meta variables to implement implicit arguments.除此之外,Agda 使用元变量来实现隐式参数。 Each implicit argument is replaced with a meta variable, which Agda then tries to resolve within a context that includes the remaining arguments.每个隐式参数都被一个元变量替换,然后 Agda 尝试在包含剩余参数的上下文中解析该元变量。 This is how values for implicit arguments can be derived from the remaining arguments, for example.例如,这就是隐式参数的值可以从其余参数中导出的方式。

Sometimes Agda is unable to figure out an implicit argument, even though one would think that she should be able to.有时,Agda 无法找出隐含的论点,尽管人们认为她应该能够。 Ie, Agda is unable to resolve the implicit argument's meta variable.即,Agda 无法解析隐式参数的元变量。 This is when she needs a little assistance, ie, we have to explicitly specify one or more of the implicit arguments.这是她需要一点帮助的时候,即,我们必须明确指定一个或多个隐含参数。 Which is what @gallais suggests in the comment.这是@gallais 在评论中建议的。

=< compares two types. =<比较两种类型。 A =< B means that something of type A can be put where something of type B is required. A =< B意味着A类型的东西可以放在需要B类型的东西的地方。 So, if you have a function that takes a B , you can give it an A and it'll type check.所以,如果你有一个需要B的函数,你可以给它一个A并且它会输入检查。 I think that this is mostly used for Agda's sized types.我认为这主要用于 Agda 的大小类型。 In your case, I think, this can be read as type equality instead.我认为,在您的情况下,这可以理解为类型相等。

But back to the error message.但回到错误信息。 Agda fails to find a solution for _X_53 . Agda 找不到_X_53的解决方案。 The constraint that needs to be met is P x =< _X_53 .需要满足的约束是P x =< _X_53 If, in your case, =< is type equality, then why doesn't Agda simply set _X_53 to P x ?如果在您的情况下, =<是类型相等,那么为什么 Agda 不简单地将_X_53设置为P x

According to my very limited understanding, the reason is higher-order unification, which is a bit of a - to use a very technical term - capricious and finicky beast.根据我非常有限的理解,原因是高阶统一,这有点——用一个非常专业的术语来说——反复无常和挑剔的野兽。 _X_53 isn't the complete truth here. _X_53在这里并不是全部真相。 Meta variables can be functions and thus have arguments.元变量可以是函数,因此具有参数。 According to the Agda debug log, the actual unification problem at hand is to unify _X_53 AP xx and P x .根据 Agda 调试日志,手头的实际统一问题是统一_X_53 AP xxP x If I remember things correctly, then the two x s in the former are a problem.如果我没记错的话,那么前者中的两个x是有问题的。 Take this with a grain of salt, though.不过,把这个和一粒盐放在一起。 I'm not a type theorist.我不是类型理论家。

Long story short, sometimes Agda fails to figure out an implicit argument because unification fails and it's a bit hard to understand why exactly.长话短说,有时 Agda 无法找出隐含的论点,因为统一失败了,而且很难理解究竟是为什么。

Finally, something related: The following article talks a bit about best practices for using implicit arguments: Inference in Agda最后,一些相关的东西:下面的文章讨论了一些关于使用隐式参数的最佳实践: Inference in Agda

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

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