You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should the predicate be erasable in the subst rule (without-K) #5448
With Nisse and Andrea we discussed that the definitions below, erasing P, might not be compatible with univalence.
{-# OPTIONS --without-K #-}open importAgda.Builtin.Equalitysubst : {@0 A :Set} (@0 P : A →Set) {x y : A} (p : x ≡ y) → P x → P y
subst P refl z = z
subst' : {@0 A :Set} (@0 P : A →Set) {@0 x y : A} (p : x ≡ y) → P x → P y
subst' P refl z = z
Since foo and bar only differ in the P argument, this suggests that P is runtime relevant when univalence is around.
P is sort of the type-code that is recursed on to compute the "functorial action" that subst exhibits. Maybe to get a better intuition, could you complete here the definition of subst, @Saizan, with the additional reduction rules that are not visible in the surface syntax? The surface syntax only has the user-written clause
{-# OPTIONS --erased-cubical #-}open importAgda.Builtin.Boolusing (Bool; true; false)
open importAgda.Builtin.Equalityusing (_≡_; refl)
open importAgda.Builtin.Cubical.Pathusing () renaming (_≡_ to Path)
open importAgda.Builtin.Cubical.Glueusing (_≃_)
open importAgda.Builtin.IOusing (IO)
open importAgda.Builtin.Sigmausing (_,_; fst)
open importAgda.Builtin.Unitusing (⊤)
open importAgda.Primitiveusing (Level)
open importAgda.Primitive.Cubicalusing (primTransp; i0; primIMin; primINeg)
privatevariablea p : Level
A B :Set a
P : A →Set p
eq x y z : A
recordErased (@0 A :Set a) :Set a whereconstructor[_]field
@0 erased : A
[]-cong :
{@0 A :Set a} {@0 x y : A} →
@0 Path x y → Path [ x ] [ y ]
[]-cong eq =λ i → [ eq i ]
trans : x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
subst :
{@0 A :Set a} {@0 x y : A}
(@0 P : A →Set p) → x ≡ y → P x → P y
subst _ refl p = p
subst-Path :
{@0 A :Set a} {@0 x y : A}
(P : A →Set p) → Path x y → P x → P y
subst-Path P eq p = primTransp (λ i → P (eq i)) i0 p
Path→≡ : Path x y → x ≡ y
Path→≡ eq = subst-Path (_ ≡_) eq refl
postulate
@0 univ : A ≃ B → Path A B
@0 subst-Path-id-univ :
Path (subst-Path (λ A → A) (univ eq) x) (fst eq x)
J :
(P :∀ {y} → Path x y →Set p) →
P (λ _ → x) →
(eq : Path x y) → P eq
J P p eq = primTransp (λ i → P (λ j → eq (primIMin i j))) i0 p
subst-univ :
{@0 A B :Set a}
(@0 P :Set a →Set p) → @0 A ≃ B → P A → P B
subst-univ P eq p =
subst (λ ([ x ]) → P x) (Path→≡ ([]-cong (univ eq))) p
subst-Path→≡ :
{p : P x} →
subst P (Path→≡ eq) p ≡ subst-Path P eq p
subst-Path→≡ {P = P} {x = x} {p = p} = J
(λ eq → subst P (Path→≡ eq) p ≡ subst-Path P eq p)
(trans (Path→≡ λ i → subst P (primTransp (λ _ → x ≡ x) i refl) p)
(Path→≡ λ i → primTransp (λ _ → P x) (primINeg i) p))
_
@0 subst-univ-id :
subst-univ (λ A → A) eq x ≡ fst eq x
subst-univ-id = trans subst-Path→≡ (Path→≡ subst-Path-id-univ)
not : Bool → Bool
not true = false
not false = true
@0 swap : Bool ≃ Bool
swap = not , omitted
wherepostulateomitted : _
should-be-false : Bool
should-be-false = subst-univ (λ A → A) swap true
@0 is-false : should-be-false ≡ false
is-false = subst-univ-id
postulateprint : Bool → IO ⊤
{-# COMPILE GHC print = print #-}main : IO ⊤
main = print should-be-false
I postulated some things, but the only non-erased postulate is the one for print, and the remaining postulates should be non-controversial.
The result of running the resulting binary (with or without --ghc-strict) is incorrect:
Perhaps the problem will be fixed once (if?) proper support for inductive families is added to Cubical Agda (#3733), as discussed above.
It really depends on what we want --without-K to mean:
I think there should be some variant of Agda that is compatible with both --with-K and --cubical/--erased-cubical. This variant could perhaps use a more descriptive name than "without K", but for historical reasons I don't think we should remove the flag --without-K.
Commit e6404c3 checks the usability of the clause generated for the transpX constructor.
This raises a type error for subst and subst' defined with an erased P argument.
dataBox: @0 Set→Set₁where[_] :∀ {A} → A → Box A
unbox :∀ {@0 A} → Box A → A
unbox [ x ] = x
Unfortunately a benign definition like the following from the runtime irrelevance docs also triggers this error:
variablea b : Level
A :Set a
dataVec (A :Set a) : @0 Nat →Set a where[] : Vec A 0_∷_ :∀ {@0 n} → A → Vec A n → Vec A (suc n)
foldl : (B : Nat →Set b)
→ (f :∀ {@0 n} → B n → A → B (suc n))
→ (z : B 0)
→∀ {@0 n} → Vec A n → B n
foldl B f z [] = z
foldl B f z (x ∷ xs) = foldl (λ n → B (suc n)) (λ {n} → f {suc n}) (f z x) xs
However closed paths in Nat are constant, we might want to special case indexes like that.
The following is however fine, i.e. with B : @0 Nat -> Set b.
foldl' : (B : @0 Nat →Set b)
→ (f :∀ {@0 n} → B n → A → B (suc n))
→ (z : B 0)
→∀ {@0 n} → Vec A n → B n
foldl' B f z [] = z
foldl' B f z (x ∷ xs) = foldl' (λ n → B (suc n)) (λ {n} → f {suc n}) (f z x) xs
@plt-amy, did you say that you have some idea about how we can disallow problematic definitions like those discussed above without generating Cubical Agda code behind the scenes (by leveraging the current infrastructure for checking definitions by pattern matching)? That could be beneficial also to users of Cubical Agda, who might not have to see generated code in error messages.
Note that the current implementation checks things for several modalities, not just erasure. (However, irrelevance is ignored, see issue #5611.)
@nad Well I did have an idea before, but reflecting on it now, I think it's too complicated (and wouldn't work anyway)...
But an alternative dawned on me earlier today: if an acceptable fix for this issue is to reject all definitions that --cubical would reject when it generates the trX clauses, then it's enough to check that the target type of the RHS is usable at "its own" modality. That's essentially what the cubical check is doing anyway, which is why it rejects this:
{-# OPTIONS --cubical #-}moduleTest14whereopen importAgda.Builtin.Equalityopen importAgda.Builtin.Natopen importAgda.Primitivefakeout : {@0 A :Set} (@0 P : A →Set) {@0 α β : A} (p : α ≡ β) → P α → P α
fakeout {A} P {x} {y} refl a ={! !}
with the error
Agda.Primitive.Cubical.primTransp (λ i → P α) φ
(fakeout P refl
(Agda.Primitive.Cubical.primTransp (λ i → P α) φ
x)) is not usable at the required modality .
(side note: @ω probably shouldn't be printed blank for error messages..)
Activity
Saizan commentedon Jun 17, 2021
Let
ua : A ≃ B -> A ≡ Bbe the map we get from univalence, then with (a level polymorphic)substfrom above we can definewe can then prove that
foo ≡ falsewhilebar ≡ true.Since
fooandbaronly differ in thePargument, this suggests thatPis runtime relevant when univalence is around.andreasabel commentedon Jun 17, 2021
Pis sort of the type-code that is recursed on to compute the "functorial action" thatsubstexhibits. Maybe to get a better intuition, could you complete here the definition ofsubst, @Saizan, with the additional reduction rules that are not visible in the surface syntax? The surface syntax only has the user-written clausesubst P refl z = zwhich justifies the typing that Agda accepts.
Saizan commentedon Jun 18, 2021
If you mean in the
--cubicalcase, we would have e.g. this extra clause, where I added type annotations to some variables in the pattern for clarity.subst {A} {P} {x} {y} (transpX (p : Path y' y) (r : x ≡ y')) z = transp (\ i -> P (p i)) i0 (subst {A} {P} {x} {z} r z)jespercockx commentedon Jun 18, 2021
See also #5266. It really depends on what we want
--without-Kto mean:nad commentedon Jun 18, 2021
Note that this also affects
--erased-cubical:I postulated some things, but the only non-erased postulate is the one for
print, and the remaining postulates should be non-controversial.The result of running the resulting binary (with or without
--ghc-strict) is incorrect:nad commentedon Jun 18, 2021
Perhaps the problem will be fixed once (if?) proper support for inductive families is added to Cubical Agda (#3733), as discussed above.
I think there should be some variant of Agda that is compatible with both
--with-Kand--cubical/--erased-cubical. This variant could perhaps use a more descriptive name than "without K", but for historical reasons I don't think we should remove the flag--without-K.nad commentedon Jun 18, 2021
Doesn't it make sense to include the extra clauses also when
--without-Kis used? (This is related to issue #4527.)Saizan commentedon Jun 18, 2021
We already discussed this: looking at these generated clauses might be a good way to avoid definitions incompatible with --cubical.
[ re #5448 ] check usableAtModality of body of trX-con clause.
Saizan commentedon Aug 23, 2021
Commit e6404c3 checks the usability of the clause generated for the
transpXconstructor.This raises a type error for
substandsubst'defined with an erasedPargument.unboxfrom #5468 also triggers this error.Unfortunately a benign definition like the following from the runtime irrelevance docs also triggers this error:
However closed paths in Nat are constant, we might want to special case indexes like that.
Saizan commentedon Aug 24, 2021
The following is however fine, i.e. with
B : @0 Nat -> Set b.8 remaining items
Saizan commentedon Nov 25, 2021
Yes, looks good.
nad commentedon Sep 7, 2022
@plt-amy, did you say that you have some idea about how we can disallow problematic definitions like those discussed above without generating Cubical Agda code behind the scenes (by leveraging the current infrastructure for checking definitions by pattern matching)? That could be beneficial also to users of Cubical Agda, who might not have to see generated code in error messages.
Note that the current implementation checks things for several modalities, not just erasure. (However, irrelevance is ignored, see issue #5611.)
nad commentedon Oct 25, 2022
The examples in the OP are now again accepted when
--without-Kis used. @andreasabel, perhaps you want to rename this issue.plt-amy commentedon Oct 25, 2022
@nad Well I did have an idea before, but reflecting on it now, I think it's too complicated (and wouldn't work anyway)...
But an alternative dawned on me earlier today: if an acceptable fix for this issue is to reject all definitions that
--cubicalwould reject when it generates thetrXclauses, then it's enough to check that the target type of the RHS is usable at "its own" modality. That's essentially what the cubical check is doing anyway, which is why it rejects this:with the error
(side note:
@ωprobably shouldn't be printed blank for error messages..)nad commentedon Oct 25, 2022
What would the error message look like with that approach?
re #5448: check that clause target type is usable at modality
nad commentedon Oct 26, 2022
Given that @plt-amy has provided a proposed new implementation of the check I'm reopening this issue.
re #5448: check that clause target type is usable at modality
re #5448: check that clause target type is usable at modality
re #5448: check that clause target type is usable at modality (#6236)
andreasabel commentedon Oct 29, 2022
Please reopen with concrete TODOs.
nad commentedon Oct 30, 2022
The proposed new implementation has been completed and committed.