Skip to content

De Bruijn fail in Cubical (Was: Garbled boundary contexts & naming eta expansion.) #5900

Closed

Description

@anuyts

The following minimal example does not cause a problem:

{-# OPTIONS --cubical #-}

open import Agda.Builtin.Cubical.Path
open import Agda.Primitive.Cubical

record _×_ (A B : Set) : Set where
  constructor _,_
  field
    fst : A
    snd : B
open _×_

eta : ∀ {A B} (p q r : A × B) → p ≡ p
eta p q@(q1 , q2) r i = {!!}

so I will have to refer to my own code.

There are some holes at

The latter 2 goals (and originally the first one) give me garbled boundary contexts in the output:

t = algebraHom t j, carrierHom₁ = i0 ⊢ ...
t = algebraHom t j, carrierHom₁ = i1 ⊢ ...
t = algebraHom t j, strHom₁ = i0 ⊢ ...
t = algebraHom t j, strHom₁ = i1 ⊢ ...

The appearance of the names carrierHom₁ and strHom₁, which are the names of the constructors of AlgebraHom (with a ₁ appended), gave me the idea that this is a de Bruijn fail related to some but not all of the Algebra and AlgebraHom arguments being eta-expanded on the LHS in the code base. So for the first hole I changed the LHS from

ModelHom1Eq→IsTermAlgebraHom' m1EqA m1EqB@(algebra msetB β1 , respectsEqB) m1EqF sort (joinFQ-varF t j) i = ?

to

ModelHom1Eq→IsTermAlgebraHom'
  m1EqA@(algebra msetA α1 , respectsEqA)
  m1EqB@(algebra msetB β1 , respectsEqB)
  m1EqF@(algebraHom f f-isalg1) sort (joinFQ-varF t j) i = ?

and this actually solved the problem.

I am on Agda version 2.6.2-246a229.

Note: the linked repository contains a submodule and should be cloned with git clone --recurse-submodules.

Activity

  1. anuyts commented on May 12, 2022

    @anuyts
    ContributorAuthor

    Actually I cannot fill the hole using the boundaries obtained from the output:

    ModelHom1Eq→IsTermAlgebraHom'
      m1EqA@(algebra msetA α1 , respectsEqA)
      m1EqB@(algebra msetB β1 , respectsEqB)
      m1EqF@(algebraHom f f-isalg1) sort (joinFQ-varF t j) i =
      idfun
        (Square
          (λ j → f sort
             (Model1Eq→IsTermAlgebra (algebra msetA α1 , respectsEqA) sort t))
          (λ j → Model1Eq→IsTermAlgebra (algebra msetB β1 , respectsEqB)
             sort (mapTerm f sort t))
          (λ i → mapTermF-ModelHom1Eq→IsTermAlgebraHom'
             (algebra msetA α1 , respectsEqA) (algebra msetB β1 , respectsEqB)
             (algebraHom f f-isalg1) sort (varF t) {!i!})
          (λ i → ModelHom1Eq→IsTermAlgebraHom'
             (algebra msetA α1 , respectsEqA) (algebra msetB β1 , respectsEqB)
             (algebraHom f f-isalg1) sort t i)
        ) (toPathP (snd (msetB sort) _ _ _ _)) i j

    The remaining i is not accepted on the grounds of an ill-typed inequality

    algebraHom strHom₁ sort != sort
    

    where strHom is the name of the second field of AlgebraHom, so I have the impression that the de Bruijn fail persists.

    Also, why can't I use C-c C-s (or just type an underscore) to have the boundaries of my Square type filled in from the boundary constraints? This would make it MUCH easier to invoke h-levels, and I don't see any theoretical problem.

  2. changed the title [-]Garbled boundary contexts & naming eta expansion.[/-] [+]De Bruijn fail in Cubical (Was: Garbled boundary contexts & naming eta expansion.)[/+] on May 12, 2022
  3. added a commit that references this issue on May 15, 2022
  4. andreasabel commented on May 15, 2022

    @andreasabel
    Member

    @anuyts: Usually, when I tried to produce a minimal counterexample from my suspicion what the problem is, I could not reproduce the problem. In my experience, one has to go through the process of shrinking the original occurrence of the problem, and this typically takes 2 hours (however, this might take longer due to the slow response of Cubical Agda on this file when working interactively). The goal would be a MWE akin to #5838 (comment).

    I tried your development with Agda-2.6.3 and a later cubical library (that builds with 2.6.3), but this gives me scope errors.
    The version of cubical you pin to does not build with Agda-2.6.3. We usually only fix bugs in Agda master, so a MWE should be targeting Agda-2.6.3.

    I looked at the goal https://github.com/anuyts/ctx-alg/blob/15259093b0802315d7dc1d6b061540305680e1d7/src/Mat/Term.agda#L609 with Agda-2.6.2.2 and trying to give the solution, get type errors. Some can be fixed by replacing t (not a function) with f (a function). Then I saw that you fixed this in your second comment.

    Playing around a bit more, I found that explicitly matching on m1EqF in all clauses of ModelHom1Eq→IsTermAlgebraHom' fixes the problems you mention: garbled boundary context and failure to give i. Pushed to: andreasabel/anuyts-ctx-alg@07c84e3

    AFAIK, Agda does not eagerly split on eta-records on the LHS. So doing the split explicitly does put you in different execution paths of Agda.

  5. added
    type: bug
    eta
    cubical
    on May 15, 2022
  6. added this to the 2.6.3 milestone on May 15, 2022
  7. anuyts commented on May 17, 2022

    @anuyts
    ContributorAuthor

    I'll see what I can do.

    Meanwhile, I remain interested in a theoretical explanation of this:

    Also, why can't I use C-c C-s (or just type an underscore) to have the boundaries of my Square type filled in from the boundary constraints? This would make it MUCH easier to invoke h-levels, and I don't see any theoretical problem.

    I'm really quite puzzled that Agda's current metavariable solver cannot automatically do this; I've been manually copy-pasting terms from Agda's output.

  8. anuyts commented on May 17, 2022

    @anuyts
    ContributorAuthor

    Here I now get the following output:

    Failed to solve the following constraints:
      [$ i, $ i₁] ~~ [$ i, $ i₁] : x ≡ y (stuck)
      [$ i] ~~ [$ i]
        : joinFQ (mapTermF f sortOut (lhs axiom)) ≡
          joinFQ (mapTermF f sortOut (rhs axiom))
        (stuck)
      [$ i] ~~ [$ i]
        : joinFQ (astF t) ≡ ast (mapTerm1 (λ sort → joinFQ) sortOut t)
        (stuck)
      [$ i] ~~ [$ i] : joinFQ (varF x) ≡ x (stuck)
    

    I do not get it if I comment out the last uncommented line. (Line 90. Note: github syntax highlighting does not bother with well-nested comments.)
    I do not know how to interpret this output. What does it mean that agda is "stuck"?
    What is the meaning of something like [$ i, $ i₁] ~~ [$ i, $ i₁]?

    Also, the cubical library is giving me a lot of warnings in the lines of

    Could not generate equivalence when splitting on indexed family,
    the function will not compute on transports by a path.
      Reason: UnsupportedYet Injectivity
                               position:    0
                               type:        Agda.Builtin.Nat.Nat
                               datatype:    Agda.Builtin.Nat.Nat
                               parameters: 
                               indices:    
                               constructor: Agda.Builtin.Nat.Nat.suc
    when checking the definition of lookup
    

    I've merged a pretty recent version of the cubical master branch. Should I consider this normal?

    I'm currently on Agda version 2.6.3-9c6b052.

  9. andreasabel commented on May 20, 2022

    @andreasabel
    Member

    the cubical library is giving me a lot of warnings

    This is unfortunately the status quo atm, indexed inductive types are still not well-supported by Cubical Agda.

  10. added
    de-Bruijn
    on Aug 31, 2022
  11. jespercockx commented on Aug 31, 2022

    @jespercockx
    Member

    Might be fixed by #6053 ?

  12. plt-amy commented on Oct 23, 2022

    @plt-amy
    Contributor

    I'll keep working on it over the next week but sadly I'm not sure boundary-sensitive evaluation will be ready for review, let alone merge-able, in the coming 9 days. Bumping this to 2.6.4.

  13. modified the milestones: 2.6.3, 2.6.4 on Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cubicalde-Bruijnetatype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions