Skip to content

Uninformative error when checking boundaries of functions defined on HITs #6017

Open

Description

@ncfavier

This code:

{-# OPTIONS --cubical #-}
open import Cubical.Foundations.Prelude

data T : Type where
  base : T
  p : base ≡ base
  surf : p ∙ p ≡ p

f : (x : T) → x ≡ x
f base = refl
f (p i) = refl
f (surf i j) = refl

produces this error:

(~ i ∨ i) ∨ ~ i₁ ∨ i₁ != ~ i ∨ i of type I
when checking the definition of f

on both Agda 2.6.2.2 and master (5d2d77a).

For context, I stumbled upon this error while trying to prove that the definition of the torus in terms of p ∙ q ≡ q ∙ p is equivalent to the one in the cubical library:
https://github.com/ncfavier/cubical-experiments/blob/f14da384b38cdea9eed82507cd12f6263a85969e/Torus.agda#L55-L57

cc. @mortberg @plt-amy @aljungstrom

Activity

  1. plt-amy commented on Aug 11, 2022

    @plt-amy
    Contributor

    As part of checking IApplyConfluence for the last clause, we encounter this conversion checking problem (I've cleaned up the debug output by hand since the conversion checker doesn't use prettyTCM):

    ~ i ∨ i ⊢ f (surf i j) = refl
    

    Why? Because the LHS of the clause must equal the RHS of the clause, even under "path reductions" (that's the "IApply" in IApplyConfluence). The face ~ i ∨ i is satisfied when i = i0 and when i= i1. Hence, we must check:

    f (surf i0 i) = refl : surf i0 i ≡ surf i0 i 
    

    and, cleaning this unification problem up a bit, we see that we have to compare

    ap f (p · p) = refl
    

    and that's what goes wrong! The error message is ridiculously uninformative, but f really doesn't commute with path applications. That's why, if you replace refl in the right-hand-side of the definition with a hole, the boundary when i = i0 is terrifying. That's (the normal form of) the hcomp clause for f, specialised for the case p · p. Keeping the CCHM comp instead of reducing it to hcomp + transp, we see that it is:

      module _ (i : I) where
        _ : f (hcomp (λ { j (i = i0) → base ; j (i = i1) → p j }) (p i))
          ≡ comp (λ j → hfill (λ { k (i = i0) → base ; k (i = i1) → p k }) (inS (p i)) j
                      ≡ hfill (λ { k (i = i0) → base ; k (i = i1) → p k }) (inS (p i)) j)
                 (λ { j (i = i0) → f base
                    ; j (i = i1) → f (p j)
                    })
                 (f (p i))
        _ = refl
    

    and.. that composite is definitely not definitionally refl. So Agda is correctly rejecting this program, but to understand why, you have to poke pretty deep into the implementation.

  2. plt-amy commented on Aug 11, 2022

    @plt-amy
    Contributor

    The (~ i ∨ i) ∨ ~ i₁ ∨ i₁ comes from the hfill in the hcomp clause for f.

  3. plt-amy commented on Aug 11, 2022

    @plt-amy
    Contributor

    I think that, basically everywhere that equalTermOnFace shows up, the resulting error message could use more context. Imagine if it were (this wouldn't even be hard to do; I've been in this part of the code):

    (~ i ∨ i) ∨ ~ i₁ ∨ i₁ != ~ i ∨ i of type I
    when comparing the terms
      f (surf i0 i)
    and
      refl
    which must be equal for this clause to commute with path applications.
    

    The use of "this clause" means that the error's Range would be set to the clause's LHS (we have this handy in IApplyConfluence). Now, annoyingly, it's hard to figure out why each specific interval variable was constrained, hence the generic "commute with path applications" wording. It might be possible to change iApplyVars to tag which variables appeared under a Con pattern; then we might be able to improve the wording to "to respect the (i = i0) face of constructor surf", or whatever.

  4. self-assigned this
    on Aug 14, 2022
  5. added
    type: bug
    ux: error reporting
    cubical
    on Aug 14, 2022
  6. changed the title [-][cubical] Weird error when checking boundaries of HITs with paths-between-hcomps constructors[/-] [+]Weird error when checking boundaries of HITs with paths-between-hcomps constructors[/+] on Aug 14, 2022
  7. changed the title [-]Weird error when checking boundaries of HITs with paths-between-hcomps constructors[/-] [+]Uninformative error when checking boundaries of functions defined on HITs[/+] on Aug 14, 2022
  8. ncfavier commented on Aug 18, 2022

    @ncfavier
    ContributorAuthor

    Found a similar error on code that doesn't involve HITs:

    {-# OPTIONS --cubical #-}
    open import Cubical.Foundations.Prelude
    
    variable
      ℓ : Level
      A : Type ℓ
    
    lUnit : {x y : A} (p : x ≡ y) → refl ∙ p ≡ p
    lUnit {x = x} p i j =
      hcomp (λ where k (i = i1) → p (j ∧ k)
                     k (j = i0) → x
                     k (j = i1) → p k)
            x
    
    rUnit : {x y : A} (p : x ≡ y) → p ∙ refl ≡ p
    rUnit {x = x} {y = y} p i j =
      hcomp (λ where k (i = i1) → p j
                     k (j = i0) → x
                     k (j = i1) → y)
            (p j)
    
    pre-EH : {x : A} (p q : refl {x = x} ≡ refl)
           → cong (λ x → x ∙ refl) p ∙ cong (λ x → refl ∙ x) q
           ≡ cong (λ x → refl ∙ x) q ∙ cong (λ x → x ∙ refl) p
    pre-EH {x = x} p q i = (λ j → p (j ∧ ~ i) ∙ q (j ∧ i))
                         ∙ (λ j → p (~ i ∨ j) ∙ q (i ∨ j))
    
    Eckmann-Hilton : {x : A} (p q : refl {x = x} ≡ refl) → p ∙ q ≡ q ∙ p
    Eckmann-Hilton {x = x} p q i j =
      hcomp (λ where k (i = i0) → (({- λ j → -} rUnit (p j) k) ∙ ({- λ j → -} lUnit (q j) k)) {- j -}
                     k (i = i1) → ((λ j → lUnit (q j) k) ∙ (λ j → rUnit (p j) k)) j
                     k (j = i0) → lUnit (λ _ → x) k
                     k (j = i1) → lUnit (λ _ → x) k)
            (pre-EH p q i j)
    i ∨ ~ i != i₁ ∨ ~ i ∨ i of type I
    when checking the definition of .extendedlambda2
    

    Uncommenting the lambdas fixes it.

  9. modified the milestones: icebox, later on Aug 23, 2022
  10. added 3 commits that reference this issue on Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cubicaltype: bugux: error reporting

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions