-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should the predicate be erasable in the subst rule (without-K) #5448
Comments
Let foo = subst (\ X -> X) (ua notEquiv) true
bar = subst (\ X -> Bool) (ua notEquiv) true we can then prove that Since |
subst P refl z = z which justifies the typing that Agda accepts. |
If you mean in the 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) |
See also #5266. It really depends on what we want
|
Note that this also affects {-# OPTIONS --erased-cubical #-}
open import Agda.Builtin.Bool using (Bool; true; false)
open import Agda.Builtin.Equality using (_≡_; refl)
open import Agda.Builtin.Cubical.Path using () renaming (_≡_ to Path)
open import Agda.Builtin.Cubical.Glue using (_≃_)
open import Agda.Builtin.IO using (IO)
open import Agda.Builtin.Sigma using (_,_; fst)
open import Agda.Builtin.Unit using (⊤)
open import Agda.Primitive using (Level)
open import Agda.Primitive.Cubical
using (primTransp; i0; primIMin; primINeg)
private
variable
a p : Level
A B : Set a
P : A → Set p
eq x y z : A
record Erased (@0 A : Set a) : Set a where
constructor [_]
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
where
postulate
omitted : _
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
postulate
print : 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 The result of running the resulting binary (with or without
|
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 |
Doesn't it make sense to include the extra clauses also when |
We already discussed this: looking at these generated clauses might be a good way to avoid definitions incompatible with --cubical. |
Commit e6404c3 checks the usability of the clause generated for the
data Box : @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: variable
a b : Level
A : Set a
data Vec (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 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 |
Can you explain in more detail what happens? Is the problem that |
We get a generated clause of the form foldl B f z (transpX-Vec x φ []) = transp (λ i → B (x i)) φ (foldl B f z []) where {a : Level} {A : Set a} (@0 x : I → Nat) (φ : I) → Vec A (x i0) → Vec A (x i1) so |
@Saizan, can this issue be closed now (after some test cases have been added)? Enhancements could be discussed in a separate issue. |
@Saizan, can this issue be closed now? |
Yes, looks good. |
@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.) |
The examples in the OP are now again accepted when |
@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 {-# OPTIONS --cubical #-}
module Test14 where
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
open import Agda.Primitive
fakeout : {@0 A : Set} (@0 P : A → Set) {@0 α β : A} (p : α ≡ β) → P α → P α
fakeout {A} P {x} {y} refl a = {! !} with the error
(side note: |
What would the error message look like with that approach? |
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 * fixup: tweak error message for --cubical-compatible slightly * fixup: update error messages w/ --cubical-compatible wording * fixup: finish comment, always print @ω in errors * fixup: test --without-K error message, too * fixup: reword --without-K justification * Print modalities in error messages verbosely ... so that the irrelevance modality isn't confusable for punctuation anymore. Also fixes up punctuation in the error message * fixup: remove justification when --without-K
Please reopen with concrete TODOs. |
The proposed new implementation has been completed and committed. |
With Nisse and Andrea we discussed that the definitions below, erasing
P
, might not be compatible with univalence.Cf. #4784
The text was updated successfully, but these errors were encountered: