Source code on Github{-# OPTIONS --allow-unsolved-metas #-}
open import Prelude.Init hiding ([_]); open SetAsType
open L.Mem
open import Prelude.General
open import Prelude.DecEq
open import Prelude.InfEnumerable
open import Prelude.Setoid
open import Prelude.InferenceRules
module ULC.Substitution (Atom : Type) ⦃ _ : DecEq Atom ⦄ ⦃ _ : Enumerable∞ Atom ⦄ where
open import ULC.Base Atom ⦃ it ⦄
open import ULC.Measure Atom ⦃ it ⦄ ⦃ it ⦄
open import ULC.Alpha Atom ⦃ it ⦄ ⦃ it ⦄
open import Nominal Atom
open import Nominal.Product Atom
{-# TERMINATING #-}
barendregt : Op₁ Term
barendregt = go []
where
go : List Atom → Op₁ Term
go xs = λ where
(` x) → ` x
(l · r) → go xs l · go xs r
(ƛ x ⇒ t) → let x′ = freshAtom (xs ++ supp t)
in ƛ x′ ⇒ go (x ∷ xs) (swap x′ x t)
infix 6 _[_/_]
{-# TERMINATING #-}
_[_/_] : Term → Atom → Term → Term
(` x) [ 𝕒 / N ] = if x == 𝕒 then N else ` x
(L · M) [ 𝕒 / N ] =
let L′ = L [ 𝕒 / N ]
M′ = M [ 𝕒 / N ]
in L′ · M′
(ƛ t̂) [ 𝕒 / N ] =
let y = freshAtom (𝕒 ∷ supp t̂ ++ supp N)
in ƛ y ⇒ conc t̂ y [ 𝕒 / N ]
infix 6 _[_]
_[_] : Abs Term → Term → Term
(abs x t) [ s ] = (ƛ x ⇒ t) [ x / s ]
infix 6 _[_/_]↑
_[_/_]↑ : Abs Term → Atom → Term → Abs Term
(abs 𝕒 t) [ x / N ]↑ = unƛ $ (ƛ 𝕒 ⇒ t) [ x / N ]
postulate swap-subst : Equivariant _[_/_]
subst-commute : N [ x / L ] [ y / M [ x / L ] ] ≈ N [ y / M ] [ x / L ]
subst-commute {` n} {x} {L} {y} {M}
with n ≟ x | n ≟ y
... | yes refl | yes refl
= {!subst-commute !}
... | yes refl | no n≠y
rewrite ≟-refl n
= {!!}
... | no n≠x | yes refl
rewrite ≟-refl n
= ≈-refl
... | no n≠x | no n≠y
rewrite dec-no (n ≟ x) n≠x .proj₂
| dec-no (n ≟ y) n≠y .proj₂
= ≈-refl
subst-commute {Nˡ · Nʳ} {x} {L} {y} {M}
= ξ≡ (subst-commute {Nˡ}) (subst-commute {Nʳ})
subst-commute {ƛ t̂} {x} {L} {y} {M}
with xˡ ← freshAtom (x ∷ supp t̂ ++ supp L)
with yˡ ← freshAtom (y ∷ supp (abs xˡ $ conc t̂ xˡ [ x / L ]) ++ supp (M [ x / L ]))
with yʳ ← freshAtom (y ∷ supp t̂ ++ supp M)
with xʳ ← freshAtom (x ∷ supp (abs yʳ $ conc t̂ yʳ [ y / M ]) ++ supp L)
= ζ≡ ({!!} , (λ z z∉ → {!!}))
postulate cong-subst : t ≈ t′ → t [ x / M ] ≈ t′ [ x / M ]
swap∘subst : swap y x N [ y / M ] ≈ N [ x / M ]
swap∘subst {y} {x} {` n} {M}
with n ≟ x | n ≟ y
... | yes refl | yes refl
rewrite ≟-refl y
= ≈-refl
... | yes refl | no n≠y
rewrite ≟-refl y
= ≈-refl
... | no n≠x | yes refl
rewrite dec-no (x ≟ y) (≢-sym n≠x) .proj₂
= {!!}
... | no n≠x | no n≠y
rewrite dec-no (n ≟ y) n≠y .proj₂
= ≈-refl
swap∘subst {y} {x} {L · R} {M}
= ξ≡ (swap∘subst {N = L}) (swap∘subst {N = R})
swap∘subst {y} {x} {ƛ t̂} {M}
= ζ≡ ({!!} , λ w w∉ → {!!})