UlfNorell / agda-test

Agda test
0 stars 0 forks source link

Higher order positivity #421

Open UlfNorell opened 10 years ago

UlfNorell commented 10 years ago

From dpip...@gmail.com on June 01, 2011 20:03:18

Using Agda version 2.2.10 on MacOSX 10.6.7

In the code below, μ₁ typechecks fine, but μ₂ gives me "μ₂ is not strictly positive, because it occurs in the third argument to ⟦_⟧ in the type of the constructor fix in the definition of μ₂."

module RegularTypes where

open import Data.Nat using (ℕ;zero;suc) open import Data.Fin using (Fin;zero;suc) open import Data.Vec open import Data.Empty open import Data.Product open import Data.Sum open import Data.Unit

Σ# : {n : ℕ} -> (Fin n -> Set) -> Set Σ# {zero} f = ⊥ Σ# {suc zero} f = f zero Σ# {suc n} f = f zero ⊎ Σ# {n} λ i -> f (suc i)

module Matrices {Ix : Set} {Σ : (Ix -> Set) -> Set} where

Matrix : Set1 Matrix = (i j : Ix) -> Set

<+> : Matrix -> Matrix -> Matrix m <+> n = λ i j -> m i j ⊎ n i j

<*> : Matrix -> Matrix -> Matrix m <*> n = λ i j -> Σ λ k -> m i k × n k j

data Poly {Coeffs : Set1} : Set1 where 0p 1p : Poly X : Poly + * : (D1 D2 : Poly {Coeffs}) -> Poly {Coeffs} K : Coeffs -> Poly

module Dim {n : ℕ} where open Matrices {Fin n} {Σ#}

⟦_⟧ : Poly {Vec (Vec Set n) n} -> Matrix -> Matrix ⟦ 0p ⟧ x i j = ⊥ ⟦ 1p ⟧ x i j = ⊤ ⟦ X ⟧ x i j = x i j ⟦ D1 + D2 ⟧ x i j = (⟦ D1 ⟧ x <+> ⟦ D2 ⟧ x) i j ⟦ D1 * D2 ⟧ x i j = (⟦ D1 ⟧ x <*> ⟦ D2 ⟧ x) i j ⟦ K S ⟧ x i j = lookup j (lookup i S)

⟪_⟫ : Poly {Set} -> Set → Set ⟪ 0p ⟫ x = ⊥ ⟪ 1p ⟫ x = ⊤ ⟪ X ⟫ x = x ⟪ D1 + D2 ⟫ x = (⟪ D1 ⟫ x ⊎ ⟪ D2 ⟫ x) ⟪ D1 * D2 ⟫ x = (⟪ D1 ⟫ x × ⟪ D2 ⟫ x) ⟪ K S ⟫ x = S

data μ₁ (p : Poly) : Set where fix : ⟪ p ⟫ (μ₁ p) -> μ₁ p

data μ₂ (p : Poly) (i j : Fin n) : Set where fix : ⟦ p ⟧ (μ₂ p) i j -> μ₂ p i j

Original issue: http://code.google.com/p/agda/issues/detail?id=421

UlfNorell commented 10 years ago

From nils.anders.danielsson on June 02, 2011 15:04:48

Strict positivity checking doesn't seem to play well with modules

I suspect that your code would be accepted if you inlined <+> and <*>. Is this what your summary refers to?

The positivity checker contains some magic which Ulf added because he wanted to support definitions like μ₁. Perhaps one could also support definitions like μ₂. Ulf?

Another option would be to include information about monotonicity etc. in types (as in MiniAgda, say).

Status: InfoNeeded
Owner: ulf.nor...@gmail.com

UlfNorell commented 10 years ago

From dpip...@google.com on June 02, 2011 15:29:17

Sorry, I didn't make that clear. Manually inlining <+> and <*> results in μ₂ typechecking fine but then I don't get the nice advantages of using modules.

UlfNorell commented 10 years ago

From nils.anders.danielsson on June 07, 2011 08:30:59

Summary: Make the positivity checker smarter to avoid having to inline code
Status: Accepted
Labels: Type-Enhancement

UlfNorell commented 10 years ago

From ulf.nor...@gmail.com on June 08, 2011 01:38:41

This is a bug with module instantiations not getting the proper positivity annotations. Here's a cut-down example:

module RegularTypes where

module Foo (_ : Set₁) where Id : Set → Set Id n = n

module FooApp = Foo Set

data ⊤ : Set where tt : ⊤

⟦_⟧ : ⊤ → Set → Set ⟦ tt ⟧ x = FooApp.Id x -- works: ⟦ tt ⟧ x = Foo.Id Set x

data μ x : Set where fix : ⟦ x ⟧ (μ x) -> μ x

Summary: Positivity checker doesn't work for instantiated parameterised modules
Labels: -Type-Enhancement Type-Defect Priority-High

UlfNorell commented 10 years ago

From ulf.nor...@gmail.com on June 16, 2011 13:12:47

Fixed.

Status: Fixed

UlfNorell commented 10 years ago

From dpip...@gmail.com on June 26, 2011 08:38:13

Using the latest version (I know nothing about darcs so I don't know how to precisely specify which version I'm using - just that I just used darcs just get to fetch it) I find that the cut-down example from comment 4 compiles fine. But my original example still produces the same error message as before.

UlfNorell commented 10 years ago

From ulf.nor...@gmail.com on June 27, 2011 07:16:35

Hm, odd. Reopening.

Status: Accepted

UlfNorell commented 10 years ago

From ulf.nor...@gmail.com on June 27, 2011 13:16:47

I found another bug, but your initial example still doesn't check. The reason for that is the Σ parameter. In the * case, x (which will be instantiated to μ₂ p) ends up in the argument of Σ in <*>. Since Σ is a variable, that occurrence will be marked as negative. In order to handle this we'd have to either check positivity once the arguments are known (which could get expensive) or do some kind of higher order positivity (which I don't know how it would work).

Labels: -Type-Defect -Priority-High Type-Enhancement Priority-Low

UlfNorell commented 10 years ago

From ulf.nor...@gmail.com on September 11, 2011 16:41:32

Summary: Higher order positivity