Skip to content

Proper support for inductive families in Cubical Agda #3733

Open

Description

@nad

It would be nice with proper support for inductive families in Cubical Agda. If I have understood correctly this is a non-trivial research problem, so I have put this issue in the icebox for now.

What is the current status of inductive families in Cubical Agda? I seem to recall @Saizan mentioning that they can break canonicity. What about consistency?

Activity

  1. added
    type: enhancement
    cubical
    on Apr 30, 2019
  2. added this to the icebox milestone on Apr 30, 2019
  3. self-assigned this
    on Apr 30, 2019
  4. Saizan commented on Apr 30, 2019

    @Saizan
    Collaborator

    Inductive families shouldn't break consistency, as ``--without-K``` makes sure pattern matching is consistent with the indexing being up to a weak enough equality.

    They indeed break canonicity as transp/hcomp do not compute for them, and pattern matching definitions will get stuck on those elements.

    I've recently started working on this btw, so hopefully we get a full implementation not too late from now.

  5. WorldSEnder commented on Jun 12, 2019

    @WorldSEnder

    Any updates on this?

  6. WorldSEnder commented on Jun 13, 2019

    @WorldSEnder

    In my rather naive eyes, the following should define an equivalence, but currently does not due to getting stuck.

    module _ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) where
      open import Level
      open import Cubical.Foundations.Everything
    
      data Indexed : B → Set (ℓ Level.⊔ ℓ') where
        ⌜_⌝ : ∀ a → Indexed (f a)
    
      fiber→Indexed : ∀ {b} → fiber f b → Indexed b
      fiber→Indexed (a , fa≡b) = transport (λ i → Indexed (fa≡b i)) ⌜ a ⌝
      Indexed→fiber : ∀ {b} → Indexed b → fiber f b
      Indexed→fiber ⌜ a ⌝ = a , refl
    

    I am wondering, is this understanding correct?

  7. Saizan commented on Sep 13, 2019

    @Saizan
    Collaborator

    It's still provably an equivalence, by path induction/contractibility of singletons:

    {-# OPTIONS --cubical #-}
    module _ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) where
      open import Level
      open import Cubical.Foundations.Everything
      open import Cubical.Data.Sigma
    
      data Indexed : B → Set (ℓ Level.⊔ ℓ') where
        ⌜_⌝ : ∀ a → Indexed (f a)
    
      fiber→Indexed : ∀ {b} → fiber f b → Indexed b
      fiber→Indexed (a , fa≡b) = transport (λ i → Indexed (fa≡b i)) ⌜ a ⌝
      Indexed→fiber : ∀ {b} → Indexed b → fiber f b
      Indexed→fiber ⌜ a ⌝ = a , refl
    
      fwd-bwd : ∀ {b} x → fiber→Indexed (Indexed→fiber {b} x) ≡ x
      fwd-bwd ⌜ a ⌝ = transportRefl ⌜ a ⌝
    
      bwd-fwd-refl : ∀ x → Indexed→fiber {f x} (fiber→Indexed (_ , refl)) ≡ (_ , refl)
      bwd-fwd-refl x = cong Indexed→fiber (transportRefl ⌜ x ⌝)
    
      bwd-fwd : ∀ {b} x → Indexed→fiber {b} (fiber→Indexed x) ≡ x
      bwd-fwd x = subst (\ (bx : Σ _ (fiber f)) → Indexed→fiber {fst bx} (fiber→Indexed (snd bx)) ≡ snd bx)
                        (ΣPathP (x .snd , \ i → fst x , (\ j → snd x (j ∧ i)))) -- contractibility of singletons
                        (bwd-fwd-refl (x .fst))
  8. added 4 commits that reference this issue on May 6, 2020
  9. added a commit that references this issue on May 25, 2020
  10. Saizan commented on Mar 25, 2021

    @Saizan
    Collaborator

    Yeah, that's it

  11. 7 remaining items

  12. added 2 commits that reference this issue on Aug 20, 2021
  13. Saizan commented on Aug 23, 2021

    @Saizan
    Collaborator

    Status Update: Merged partial support for inductive families into master.

    Missing features and caveats:

    1. Definitions relying on injectivity of data constructors are not yet supported.
    2. The generated clauses are excluded when checking termination, positivity, or injectivity checking.
    3. The generated clauses are not looked at for other purposes that might benefit, like matching in the presence of @0.
    1. is mostly a matter of writing out the implementation.

    2. is more problematic, because while it could lead to replacing the "masking" introduced in the fix to Coinduction incompatible with univalence [WAS: Structural termination order incompatible with univalence] #1023 it also seems to introduce its own distinct class of false positives, at least if applied naively.
      However it also means that there's some false-proving definitions that will get accepted, like --without-K inconsistent with UA + LEM #4966 with UA and propositional LEM. Most likely others as well!

    The flag -vtc.def.fun.clauses:15 can be used to print out the final clauses for a function definition. And the flag -vtc.transpix.type:15 can be used to print out the type of generated constructor for transport on indexes.

    1. Here we could just checkInternal the generated clauses, similarly to the type for with, or introduce more specific checks.
  14. nad commented on Sep 28, 2021

    @nad
    CollaboratorAuthor

    It seems to me as if it would not make sense to make the generated transpX constructors erased. Does it still make sense to erase them, and the generated clauses, when compiling using --erased-cubical?

  15. Saizan commented on Sep 28, 2021

    @Saizan
    Collaborator

    We should have |transpX p φ u| = |u|. The realizability lemma should go like the one for hcomp constructors of HITs.

  16. nad commented on Oct 13, 2021

    @nad
    CollaboratorAuthor

    The flag -vtc.def.fun.clauses:15 can be used to print out the final clauses for a function definition. And the flag -vtc.transpix.type:15 can be used to print out the type of generated constructor for transport on indexes.

    The second flag should be -vtc.transpx.type:15.

  17. nad commented on Nov 25, 2021

    @nad
    CollaboratorAuthor
    1. The generated clauses are not looked at for other purposes that might benefit, like matching in the presence of @0.

    Do you mean that we could accept more definitions? Currently we do not allow matching on erased arguments if the type is an inductive family (unless --with-K is active), so my guess is that the answer is "yes".

    1. is more problematic, because while it could lead to replacing the "masking" introduced in the fix to Coinduction incompatible with univalence [WAS: Structural termination order incompatible with univalence] #1023 it also seems to introduce its own distinct class of false positives, at least if applied naively.
      However it also means that there's some false-proving definitions that will get accepted, like --without-K inconsistent with UA + LEM #4966 with UA and propositional LEM. Most likely others as well!

    I don't follow this part. In the discussion of issue #4966 you wrote that "This kind of definition would be disallowed by the positivity checker once the extra clauses for issue #3733 get generated". Did you mean that there are "some false-proving definitions that will get rejected"?

  18. Saizan commented on Nov 25, 2021

    @Saizan
    Collaborator

    Regarding 3., I meant what we later did for the fix of #5448.

    The "However it also means ..." paragraph is talking about the current situation where the generated clauses are ignored.

    Btw, as of commit ff2e436 the injectivity check has actually been handled.

  19. added 2 commits that reference this issue on Dec 31, 2021
  20. ice1000 commented on Apr 11, 2022

    @ice1000
    Member

    @Saizan is there any update on the cubicalagda2.pdf thing? Is it published now or is there an updated version?

  21. andreasabel commented on Dec 7, 2024

    @andreasabel
    Member

    The feature was merged in 621894f. This commit introduced regression

  22. added 2 commits that reference this issue on Jul 5, 2026
    3fe173e
    ef99d9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cubicaltype: enhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions