表达关于幂等替换的定理

时间:2014-07-19 17:05:24

标签: agda

我在一个简单的库中工作,其中包含有关简单类型替换的定义和属性。我对类型使用以下编码:

data Ty (n : Nat) : Set where
   var : Fin n -> Ty n
   con : Ty n
   app : Ty n -> Ty n -> Ty n

所以,因为变量表示为有限集,所以替换只是向量:

Subst : Nat -> Nat -> Set 
Subst n m = Vec (Ty m) n

完整开发包含以下粘贴:http://lpaste.net/107751

使用这种编码,我已经定义了几个关于这种替换的引理,但我不知道如何定义一个定义指定替换是幂等的定理。我相信我必须使用弱化等属性来表达这一点,但我无法弄清楚如何。

有人可以提供任何指示或线索吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

在新变量上产生表达式的替换确实是幂等的。但是为了表达这个定理,你必须考虑将你的替换Subst n m作为联合变量集Subst (n + m) (n + m)的一个。以下是使用任意变量集AB而非Fin nFin m的变体。

open import Relation.Binary.PropositionalEquality using (_≡_; refl)

-- Disjoint union.

data _+_ (A B : Set) : Set where
  left  : A → A + B
  right : B → A + B

-- A set of variable names can be any type.

Names = Set

-- Simple expressions over a set of names.

data Tm (A : Names) : Set where
  var : A → Tm A
  app : Tm A → Tm A → Tm A

-- Substitute all variables from set A by terms over a name set B.

Subst : Names → Names → Set
Subst A B = A → Tm B

subst : ∀{A B} → Subst A B → Tm A → Tm B
subst σ (var x)   = σ x
subst σ (app t u) = app (subst σ t) (subst σ u)

-- Rename all variables from set A to names from set B.

Rename : Names → Names → Set
Rename A B = A → B

rename : ∀{A B} → Rename A B → Tm A → Tm B
rename σ (var x)   = var (σ x)
rename σ (app t u) = app (rename σ t) (rename σ u)

-- In order to speak about idempotency of substitutions whose domain A
-- is disjoint from the variable set B used in the range, we have to promote
-- them to work on the union A+B of variable sets.

-- The promoted substitution is the identity on B,
-- and the original substitution on A, but with the result transferred from B to A + B.

promote : ∀{A B} → Subst A B → Subst (A + B) (A + B)
promote σ (left  x) = rename right (σ x)
promote σ (right x) = var (right x)

module _ {A B : Set} (σ₀ : Subst A B) where

  -- Now assume a promoted substitution.

  σ = promote σ₀

  -- A promoted substitution has no effect on terms with variables only in B.

  lemma : ∀ t → subst σ (rename right t) ≡ rename right t
  lemma (var x) = refl
  lemma (app t u) rewrite lemma t | lemma u = refl

  -- Hence, it is idempotent.

  idempotency : ∀ x → subst σ (σ x) ≡ σ x
  idempotency (right x) = refl
  idempotency (left  x) = lemma (σ₀ x)
相关问题