Search code examples
agdadependent-typecommutativity

Agda: cannot instantiate metavariable


I'm fairly new to Agda and I'm trying to construct the Interval's lattice. So far I've defined the Lattice datatype as follows:

data 𝕀 : Set where
  ⊀ : 𝕀
  βŠ₯ : 𝕀
  -∞ : β„€ β†’ 𝕀
  _+∞ : β„€ β†’ 𝕀
  I : (l : β„€) β†’ (u : β„€) β†’ {l ≀ u} β†’ 𝕀

and the _βŠ”π•€_ operator as:

_βŠ”π•€_ : Opβ‚‚ 𝕀
⊀ βŠ”π•€ y = ⊀
βŠ₯ βŠ”π•€ y = y
-∞ x βŠ”π•€ ⊀ = ⊀
-∞ x βŠ”π•€ βŠ₯ = -∞ x
-∞ x βŠ”π•€ -∞ y = -∞ (x βŠ” y)
-∞ x βŠ”π•€ (y +∞) = ⊀
-∞ x βŠ”π•€ I l u = -∞ (x βŠ” u)
(x +∞) βŠ”π•€ ⊀ = ⊀
(x +∞) βŠ”π•€ βŠ₯ = x +∞
(x +∞) βŠ”π•€ -∞ y = ⊀
(x +∞) βŠ”π•€ (y +∞) = (x βŠ“ y) +∞
(x +∞) βŠ”π•€ I l u = (x βŠ“ l) +∞
I l u βŠ”π•€ ⊀ = ⊀
I l u {l≀u} βŠ”π•€ βŠ₯ = I l u {l≀u}
I l u βŠ”π•€ -∞ x = -∞ (u βŠ” x)
I l u βŠ”π•€ (x +∞) = (l βŠ“ x) +∞
I l₁ u₁ {l₁≀u₁} βŠ”π•€ I lβ‚‚ uβ‚‚ {l₂≀uβ‚‚} = I (l₁ βŠ“ lβ‚‚) (u₁ βŠ” uβ‚‚) {≀-trans (≀-trans (iβŠ“j≀i l₁ lβ‚‚) l₁≀u₁) ((i≀iβŠ”j u₁ uβ‚‚))}

but when trying to prove commutativity of the operator in the case

βŠ”π•€-comm (I l₁ u₁ {l₁≀u₁}) (I lβ‚‚ uβ‚‚ {l₂≀uβ‚‚}) = {!congβ‚‚ I (βŠ“-comm l₁ lβ‚‚) (βŠ”-comm u₁ uβ‚‚)!}

I get the error

Cannot instantiate the metavariable _C_171 to solution
({_ : l ≀ u} β†’ 𝕀) since it contains the variable l
which is not in scope of the metavariable
when checking that the expression I has type β„€ β†’ β„€ β†’ _C_171

which, if I understand correctly, is related to the fact that the I constructor has an implicit argument, nevertheless I have no idea on how to solve the issue.


Solution

  • Indeed the problem is that I's type (l : β„€) β†’ (u : β„€) β†’ {l ≀ u} β†’ 𝕀 does not match the type of the first argument to congβ‚‚, A β†’ B β†’ C, because in this case C depends on the first two arguments. You can use one of the dependent congs like dcongβ‚‚ instead:

    open import Data.Product
    open import Data.Product.Properties
    
    βŠ”π•€-comm : βˆ€ x y β†’ x βŠ”π•€ y ≑ y βŠ”π•€ x
    βŠ”π•€-comm (I l₁ u₁ {l₁≀u₁}) (I lβ‚‚ uβ‚‚ {l₂≀uβ‚‚}) = dcongβ‚‚
      (Ξ» (l , u) p β†’ I l u {p})
      (Γ—-≑,≑→≑ (βŠ“-comm l₁ lβ‚‚ , βŠ”-comm u₁ uβ‚‚))
      (≀-irrelevant _ _)
    

    Or you could prove a helper lemma for this purpose:

    cong-I : βˆ€ {l l' u u' p p'} β†’ l ≑ l' β†’ u ≑ u' β†’ I l u {p} ≑ I l' u' {p'}
    cong-I {p = p} {p'} refl refl with ≀-irrelevant p p'
    ... | refl = refl
    
    βŠ”π•€-comm : βˆ€ x y β†’ x βŠ”π•€ y ≑ y βŠ”π•€ x
    βŠ”π•€-comm (I l₁ u₁) (I lβ‚‚ uβ‚‚) = cong-I (βŠ“-comm l₁ lβ‚‚) (βŠ”-comm u₁ uβ‚‚)