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.
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 cong
s 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β)