Local rewrite matches and smart with#15
Conversation
c53ad84 to
dde18de
Compare
dde18de to
db1c2ea
Compare
ac72da6 to
639e49d
Compare
|
While working on the normalisation proof (trying to figure out how to encode pi-typed values), I thought of a counter-example to my neutral LHS and no overlaps condition: {-# OPTIONS --smart-with #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
foo : (f : Nat → Nat → Nat) (x : Nat) → f x ≡ (λ y → f y y) → f x x ≡ 42
foo f x p rewrite p = reflI think this demonstrates that allowing closures on the RHS of rewrites doesn't really work. Not exactly sure how I want to encode the restriction (or how it will look when translated to Agda), but in principle we could inspect the normal form of the RHS, looking for any occurrence of In the NbE proof, this would mean that pi-typed values would only need to quantify over variable-thinnings (i.e. we can introduce new variables into the context, but not new convertibility assumptions). |
338968b to
50e6fdd
Compare
|
I have now implemented the above-described check (currently |
|
Ouch, there is a similar counter-example which I don't yet prevent, using copatterns: {-# OPTIONS --smart-with #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
record Weird : Set where
no-eta-equality
constructor mk
field
app : Nat → Nat
open Weird
wah : (f : Nat → Weird) → Weird
wah f .app x = f x .app x
foo : (f : Nat → Weird) (x : Nat) → f x ≡ wah f → f x .app x ≡ 42
foo f x p rewrite p = reflI am not immediately sure what the fix here should be. I need to think about how copatterns should work in NbE. EDIT: I think it makes sense to reject this example because all underapplied applications (in this case {-# OPTIONS --smart-with #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
data Unit : Set where
⟨⟩ : Unit
wah : (Nat → Unit → Nat → Nat) → Unit → Nat → Nat
wah f ⟨⟩ y = f y ⟨⟩ y
foo : (f : Nat → Unit → Nat → Nat) (x : Nat) → f x ≡ wah f → f x ⟨⟩ x ≡ 42
foo f x p rewrite p = refl |
|
Yet another counter-example: {-# OPTIONS --smart-with #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
open import Agda.Builtin.Nat
data ⊥ : Set where
data Branch : Set where
branch : (Nat → Branch) → Branch
rec : Branch → ⊥
rec (branch f) = rec (f 0)
foo : (f : Nat → Branch) (bad : ⊥) → f 0 ≡ branch f → rec (f 0) ≡ bad
foo f bad p rewrite p = reflI think this demonstrates that all pi-typed terms should be considered closures (which is perhaps not so surprising). It's interesting to consider that this example is still problematic without eta for functions though. If we try to apply the NbE proof to a type theory with rewriting but without eta for functions, we find that we can no longer interpret Luckily, Agda has eta for functions, so the much more obvious route is to just consider |
loop block t (rew:rews) es
| let n = rewArity rew, length es >= n = do
...
| otherwise = loop (block `mappend` NotBlocked Underapplied ()) t rews esThis is... not ideal |
|
Btw, for |
We should cherry pick this...
We already reject it!
Reduce is not good enough!
LHSs must be fully stuck neutrals RHSs must not contain unguarded lambdas
To fix this, we need to ensure Underapplied is prioritised in the NotBlocked monoid. First, I need to understand why this wasn't the case originally...
This case still seems somewhat suspicious, but I think we only ever hit it during confluence checking.
6fdffbc to
850b226
Compare
|
Another edge case..... {-# OPTIONS --smart-with #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
data ⊥ : Set where
data Foo : Set
record Bar : Set
data Foo where
b : Bar → Foo
record Bar where
inductive
no-eta-equality
field
app : Nat → Foo
open Bar
rec : Foo → ⊥
rec (b f) = rec (f .app 0)
ohNo : (x : Bar) → x .app 0 ≡ b x → Nat
ohNo x p rewrite p = {!!}Projections are considered size-preserving... My current thinking:
|
Relax closure check New subterm check --smart-with is no longer infective (not convinced this is a good idea though, mostly for experimentation)
We need to check for closures on the RHS under the current rewrite rule
|
Ok I think there is a much simpler strategy actually. |
WORK IN PROGRESS!
Todos:
--smart-with,--without-Kmore (we reject the examples I have come up with so far, but it wouldn't surprise me if there are ways to get around this...)with ... in eq) as--smart-withmakes it redundant