RIS.words: words, binding monoid and alpha-equivalence.

Set Implicit Arguments.

Require Export tools atoms.

Section s.

Preliminary definitions

Parameters


  Class Alphabet {a : Set} (A : Atom a) (X : Set) :=
    {
      dec_X :> decidable_set X;
      support_X :> Support A X;
      action_X :> Action A X;
      nom_X :> Nominal A X
    }.

Type of atoms
  Context {atom : Set}{𝐀 : Atom atom}.

We take an alphabet Nom.
  Context {X : Set} {𝐗 : Alphabet 𝐀 X}.

Letters

Letters are generated by the grammar open a | close a | var x where a ranges over atom and x ranges over X.
  Inductive letter {𝐀 : Atom atom} {Nom : Alphabet 𝐀 X}:=
  | open : atom β†’ letter
  | close : atom β†’ letter
  | var : X β†’ letter.
  Notation " ⟨ a " := (open a) (at level 0).
  Notation " a ⟩ " := (close a) (at level 0).


The type letter is decidable.
  Definition eq_letter l1 l2 :=
    match (l1,l2) with
    | (⟨a, ⟨b) | (a⟩,b⟩) β‡’ a=?= b
    | (var x,var y) β‡’ x =?= y
    | _ β‡’ false
    end.

  Lemma eq_letter_correct : βˆ€ x y : letter, reflect (x = y) (eq_letter x y).

  Global Instance dec_letter : decidable_set letter :=
    Build_decidable_set eq_letter_correct.

We canonically get a nominal structure over letters from the nominal structures of Atom and Nom.
  Definition supp_letter (l : letter) : list atom :=
    match l with
    | ⟨a | a⟩ β‡’ ⌊aβŒ‹
    | var x β‡’ ⌊xβŒ‹
    end.

  Global Instance support_letter : Support 𝐀 letter := supp_letter.

  Definition letter_map Ο€ l :=
    match l with
    | open b β‡’ open (Ο€βˆ™b)
    | close b β‡’ close (Ο€βˆ™b)
    | var x β‡’ var (Ο€βˆ™x)
    end.

  Global Instance action_letter : Action 𝐀 letter := letter_map.

  Global Instance group_action_letter : Nominal 𝐀 letter.

A word is a list of letters. It is therefore equipped with a nominal structure, following Nominal_list.
  Definition word {𝐀 X} := list (@letter 𝐀 X).

Binding monoid

The elements of the binding monoid are triples (m,n,p), where m and p are natural numbers and p is a boolean.
  Definition 𝖑 := (nat Γ— boolΓ— nat)%type.
The product (m,n,p)β‹…(m',n',p') is defined as follows:
  • if p < m' then (m+m'-p,n',p');
  • if m' < p then (m,n,p'+p-m');
  • if p = m' then (m,n||n',p').
  Definition prod_binding (a b:𝖑) : 𝖑 :=
    match (a,b) with
    | ((m,n,p),(m',n',p')) β‡’
      if Nat.ltb p m'
      then (m+m'-p,n',p')
      else
        if Nat.ltb m' p
        then (m,n,p'+p-m')
        else (m,n||n',p')
    end.
  Infix " β‹… " := prod_binding (at level 50).

The unit of this product is the element (0,false,0).
  Definition Ξ΅ := (0,false,0).
  Hint Transparent Ξ΅.
  Lemma prod_unit_r a : a β‹… Ξ΅ = a.
  Lemma prod_unit_l a : Ξ΅ β‹… a = a.

The product in 𝖑 is associative.
We will need sometimes to consider the first or last projection of elements from the binding monoid.
  Definition c_binding : 𝖑 β†’ nat := snd.
  Definition d_binding (x : 𝖑) : nat := fst(fst x).

  Lemma c_binding_prod x y :
    c_binding (xβ‹…y) = c_binding y + (c_binding x - d_binding y).

  Lemma d_binding_prod x y :
    d_binding (xβ‹…y) = d_binding x + (d_binding y - c_binding x).


The size of an element (n,m,p) is the sum n+m+p, where the boolean true is identified with 1 and false with 0.

Binding power

The binding power of a letter l relative to a name a, written 𝗳 a l, is an element of the binding monoid defined as follows:
  Definition 𝗳 a l : 𝖑 :=
    match l with
    | open b β‡’ if a =?= b then (0,false,1) else Ξ΅
    | close b β‡’ if a =?= b then (1,false,0) else Ξ΅
    | var x β‡’ (0,inb a ⌊xβŒ‹,0)
    end.

The binding power of a word w relative to a name a, written 𝗙 a w, is obtained by extending 𝗳 a as a monoid homomorphism from word to 𝖑.
  Definition 𝗙 a (w : word) := fold_right prod_binding Ξ΅ (map (𝗳 a) w).

The following trivial simplification lemmas hold.

Balance properties

a is open-balanced in w, written a β–· w, if the last component of 𝗙 a w is 0.
  Definition open_balanced a w := c_binding (𝗙 a w) = 0.
  Infix " β–· " := open_balanced (at level 20).

a is close-balanced in w, written a ◁ w, if the first component of 𝗙 a w is 0.
  Definition close_balanced a w := d_binding (𝗙 a w) = 0.
  Infix " ◁ " := close_balanced (at level 20).

a is balanced in w, written a β‹„ w, if it is both open- and close-balanced.
  Definition balanced a w := c_binding (𝗙 a w) = 0 ∧ d_binding (𝗙 a w) = 0.
  Infix " β‹„ " := balanced (at level 20).

a is Ξ±-fresh for w, written a #Ξ± w, if 𝗙 a w=Ξ΅.
  Definition fresh__Ξ± a w := 𝗙 a w = (0,false,0).
  Infix " #Ξ± " := fresh__Ξ± (at level 30).

The predicate a β–· is preserved by taking suffixes.
The predicate a β–· is preserved by taking prefixes.
The balance properties commute with the action of permutations.
For letters, freshness and Ξ±-freshness are equivalent.
  Lemma Ξ±fresh_letter a l : a # l ↔ 𝗳 a l = Ξ΅.

If a is fresh for u, then it is Ξ±-fresh. Note however that the converse is not true: a is Ξ±-fresh for [⟨a;a⟩], and yet a∈⌊[⟨a;a⟩]βŒ‹=[a].

Decomposition properties

If a is not open-balanced in u, then there is an unmatched ⟨a in u, and therefore a last unmatched ⟨a. This means that u may be factorised as u1++⟨a::u2, with a being balanced in u2.
Similarly, for closing brackets.
This decomposition is unique.

Alpha-equivalence

We write ≑ for the relation defined as follows:
  • ≑ is transitive, and []≑[];
  • if u≑v, then x::u≑x::v and u++[x]≑v++[x];
  • if b is Ξ±-fresh in u and a is balanced in u, then ⟨a::u++[a⟩] is equivalent to ⟨b::([(a,b)]βˆ™u)++[b⟩].
This is an equivalence relation.
  Global Instance Ξ±equiv_equivalence : Equivalence equiv.

This relation is a congruence.
  Lemma Ξ±equiv_app_left u v w : u ≑ v β†’ w++u≑w++v.
  Lemma Ξ±equiv_app_right (u v w : word) : u ≑ v β†’ u++w≑v++w.

  Global Instance Ξ±equiv_app :
    Proper (equiv ==> equiv ==> equiv) (@app letter).

Equivalent words have the same length.
Equivalent words have the same binding power.
  Lemma Ξ±equiv_binding u v : u ≑ v β†’ βˆ€ a, 𝗙 a u = 𝗙 a v.

This relation commutes with the action of permutations.
  Lemma Ξ±equiv_perm u v Ο€ : u ≑ v β†’ Ο€ βˆ™ u ≑ Ο€ βˆ™ v.

End s.
Hint Transparent Ξ΅.

Notation " ⟨ a " := (open a) (at level 0).
Notation " a ⟩ " := (close a) (at level 0).
Infix " β‹… " := prod_binding (at level 50).
Infix " #Ξ± " := fresh__Ξ± (at level 30).
Infix " β‹„ " := balanced (at level 20).
Infix " ◁ " := close_balanced (at level 20).
Infix " β–· " := open_balanced (at level 20).