Documentation

Linglib.Core.Data.RoseTree.Perm

Permutation of rose trees #

RoseTree.Perm t s says the trees agree up to reordering the children of every vertex — the n-ary tree analogue of List.Perm, and the identity criterion of the unordered quotient (Nonplanar, built downstream). Mirroring List.Perm, transitivity is a constructor while reflexivity and symmetry are theorems, and the list-level companion PermList (List.Perm with elements compared by Perm instead of Eq) is mutually inductive with it, in the fold/foldList pattern.

Main declarations #

Main results #

inductive RoseTree.Perm {α : Type u_1} :
RoseTree αRoseTree αProp

Two rose trees are equal up to reordering the children of every vertex. Transitivity is a constructor (as in List.Perm); reflexivity and symmetry are theorems.

Instances For
    inductive RoseTree.PermList {α : Type u_1} :
    List (RoseTree α)List (RoseTree α)Prop

    List.Perm with corresponding elements related by Perm instead of Eq.

    Instances For
      def RoseTree.«term_~_» :
      Lean.TrailingParserDescr

      Two rose trees are equal up to reordering the children of every vertex. Transitivity is a constructor (as in List.Perm); reflexivity and symmetry are theorems.

      Equations
      • RoseTree.«term_~_» = Lean.ParserDescr.trailingNode `RoseTree.«term_~_» 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ~ ") (Lean.ParserDescr.cat `term 51))
      Instances For

        Equivalence #

        theorem RoseTree.Perm.refl {α : Type u_1} (t : RoseTree α) :
        t.Perm t
        theorem RoseTree.PermList.refl {α : Type u_1} (cs : List (RoseTree α)) :
        PermList cs cs
        theorem RoseTree.Perm.symm {α : Type u_1} {t s : RoseTree α} :
        t.Perm ss.Perm t
        theorem RoseTree.PermList.symm {α : Type u_1} {cs ds : List (RoseTree α)} :
        PermList cs dsPermList ds cs
        @[implicit_reducible]
        instance RoseTree.instTransPerm {α : Type u_1} :
        Trans Perm Perm Perm
        Equations
        @[implicit_reducible]
        Equations
        theorem RoseTree.Perm.eqv {α : Type u_1} :
        Equivalence Perm
        @[implicit_reducible]
        instance RoseTree.isSetoid {α : Type u_1} :
        Setoid (RoseTree α)

        The setoid of rose trees up to child reordering; the nonplanar quotient is taken over it.

        Equations

        Constructors from list-level data #

        theorem RoseTree.PermList.of_forall₂ {α : Type u_1} {cs ds : List (RoseTree α)} (h : List.Forall₂ Perm cs ds) :
        PermList cs ds

        Componentwise-related children give related nodes.

        theorem RoseTree.PermList.of_perm {α : Type u_1} {cs ds : List (RoseTree α)} (h : cs.Perm ds) :
        PermList cs ds

        A plain List.Perm of children gives related nodes.

        theorem RoseTree.PermList.of_rel {α : Type u_1} {cs ds : List (RoseTree α)} (h : Multiset.Rel Perm cs ds) :
        PermList cs ds

        Multiset.Rel Perm between coerced children lists gives PermList: the bridge feeding fold_rel at S := Perm.

        theorem RoseTree.Perm.node_of_perm {α : Type u_1} {a : α} {cs ds : List (RoseTree α)} (h : cs.Perm ds) :

        A plain List.Perm of the children relates the nodes.

        theorem RoseTree.Perm.node_of_forall₂ {α : Type u_1} {a : α} {cs ds : List (RoseTree α)} (h : List.Forall₂ Perm cs ds) :

        Componentwise-related children relate the nodes.

        theorem RoseTree.Perm.congr_child {α : Type u_1} {a : α} (pre post : List (RoseTree α)) {old new : RoseTree α} (h : old.Perm new) :
        (RoseTree.node a (pre ++ old :: post)).Perm (RoseTree.node a (pre ++ new :: post))

        Rewriting a single child by a Perm-related tree relates the nodes.

        The Multiset.Rel characterization #

        theorem RoseTree.permList_iff_rel {α : Type u_1} {cs ds : List (RoseTree α)} :
        PermList cs ds Multiset.Rel Perm cs ds

        PermList is Multiset.Rel Perm in list clothing: its theory is inherited from the Multiset.Rel API.

        theorem RoseTree.perm_node_iff {α : Type u_1} {a b : α} {cs ds : List (RoseTree α)} :
        (node a cs).Perm (node b ds) a = b Multiset.Rel Perm cs ds

        Node inversion: related trees have equal labels and Multiset.Rel-related children.

        theorem RoseTree.Perm.value_eq {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :
        t.value = s.value

        The label is a Perm-invariant.

        theorem RoseTree.Perm.children_rel {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :
        Multiset.Rel Perm t.children s.children

        The children, up to Multiset.Rel Perm, are a Perm-invariant.

        theorem RoseTree.Perm.cons_child {α : Type u_1} (x : RoseTree α) {a : α} {cs ds : List (RoseTree α)} (h : (RoseTree.node a cs).Perm (RoseTree.node a ds)) :
        (RoseTree.node a (x :: cs)).Perm (RoseTree.node a (x :: ds))

        Prepending a shared child preserves relatedness of nodes.

        theorem RoseTree.PermList.length_eq {α : Type u_1} {cs ds : List (RoseTree α)} (h : PermList cs ds) :
        cs.length = ds.length

        PermList-related lists have equal length.

        theorem RoseTree.PermList.singleton_inv {α : Type u_1} {c d : RoseTree α} (h : PermList [c] [d]) :
        c.Perm d

        Inversion at singletons: PermList [c] [d] is just Perm c d.

        Functoriality #

        theorem RoseTree.Perm.map {α : Type u_1} {β : Type u_2} (f : αβ) {t s : RoseTree α} :
        t.Perm s(RoseTree.map f t).Perm (RoseTree.map f s)

        RoseTree.map preserves Perm (cf. List.Perm.map).

        theorem RoseTree.PermList.map {α : Type u_1} {β : Type u_2} (f : αβ) {cs ds : List (RoseTree α)} :
        PermList cs dsPermList (List.map (RoseTree.map f) cs) (List.map (RoseTree.map f) ds)

        List.mapRoseTree.map preserves PermList.

        Fold invariance #

        A fold whose algebra is congruent along Multiset.Rel S of the folded children carries Perm to S (fold_rel): the generic dissolver of per-function invariance inductions, relational so that tree-valued folds descend too. fold_perm is the S := Eq case; the counts below are such folds.

        theorem RoseTree.fold_rel {α : Type u_1} {β : Type u_3} {S : ββProp} {g : αList ββ} (hrefl : ∀ (b : β), S b b) (htrans : ∀ {b₁ b₂ b₃ : β}, S b₁ b₂S b₂ b₃S b₁ b₃) (hg : ∀ (a : α) {l₁ l₂ : List β}, Multiset.Rel S l₁ l₂S (g a l₁) (g a l₂)) {t s : RoseTree α} :
        t.Perm sS (fold g t) (fold g s)

        A fold whose algebra is congruent along Multiset.Rel S carries Perm to any reflexive transitive S.

        theorem RoseTree.foldList_rel {α : Type u_1} {β : Type u_3} {S : ββProp} {g : αList ββ} (hrefl : ∀ (b : β), S b b) (htrans : ∀ {b₁ b₂ b₃ : β}, S b₁ b₂S b₂ b₃S b₁ b₃) (hg : ∀ (a : α) {l₁ l₂ : List β}, Multiset.Rel S l₁ l₂S (g a l₁) (g a l₂)) {cs ds : List (RoseTree α)} :
        PermList cs dsMultiset.Rel S (List.map (fold g) cs) (List.map (fold g) ds)

        Folded children of PermList-related lists are Multiset.Rel S-related.

        theorem RoseTree.fold_perm {α : Type u_1} {β : Type u_3} {g : αList ββ} (hg : ∀ (a : α) (l₁ l₂ : List β), l₁.Perm l₂g a l₁ = g a l₂) {t s : RoseTree α} :
        t.Perm sfold g t = fold g s

        A fold with a permutation-invariant algebra is Perm-invariant.

        theorem RoseTree.numNodes_perm {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :

        numNodes is a Perm-invariant (List.Perm.sum_eq).

        theorem RoseTree.numLeaves_perm {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :

        numLeaves is a Perm-invariant.

        theorem RoseTree.depth_perm {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :
        t.depth = s.depth

        depth is a Perm-invariant (List.Perm.foldr_eq, max being commutative).

        theorem RoseTree.arity_perm {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :
        t.arity = s.arity

        Arity (root child count) is a Perm-invariant.

        theorem RoseTree.isLeaf_perm {α : Type u_1} {t s : RoseTree α} (h : t.Perm s) :

        Leaf-ness is a Perm-invariant.