Documentation

Linglib.Core.Tree

Trees #

Unified tree type parameterized by node labels (C) and terminal content (W).

Tree C W — The Y-Model Tree #

N-ary branching with categories on every node. Supports both:

Parameterized by category type C (UD tags, CCG categories, feature bundles, Unit for unlabeled, ...) and terminal type W.

Instantiations #

Cat — Default Category System #

Grounded in Universal Dependencies UPOS. Word-level categories via head : UPOS → Cat, phrasal via proj : UPOS → Cat, plus S and CP.

TreePath and Tree.toTreeOrder #

A TreePath is a list of child indices identifying a subtree position. The forgetful map Tree.toTreeOrder extracts the dominance partial order from any Tree C W as a Core.Order.TreeOrder TreePath, making the B&P command-relation library (Linglib.Core.Order.Command) applicable to concrete trees regardless of category type.

inductive Core.Tree.Cat :

Default syntactic category system grounded in Universal Dependencies UPOS (@cite{de-marneffe-zeman-2021}).

  • head pos — word-level (terminal): wraps a UPOS tag directly
  • proj pos — maximal X-bar projection of a UPOS head
  • S — sentence/clause (not a projection of a single lexical head)
  • CP — complementizer phrase

Phrasal categories are derived systematically: NP = proj .NOUN, VP = proj .VERB, DP = proj .DET, ConjP = proj .CCONJ, etc.

This is one possible instantiation of Tree's C parameter. Framework-specific category systems (CCG functors, Minimalist feature bundles, etc.) can be used instead.

Instances For
    def Core.Tree.instDecidableEqCat.decEq (x✝ x✝¹ : Cat) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      def Core.Tree.instReprCat.repr :
      CatStd.Format
      Equations
      Instances For
        @[implicit_reducible]
        instance Core.Tree.instReprCat :
        Repr Cat
        Equations
        @[implicit_reducible]
        instance Core.Tree.instInhabitedCat :
        Inhabited Cat
        Equations
        @[implicit_reducible]
        Equations
        @[reducible, match_pattern, inline]
        Equations
        Instances For
          @[reducible, match_pattern, inline]
          Equations
          Instances For
            @[reducible, match_pattern, inline]
            Equations
            Instances For
              @[reducible, match_pattern, inline]
              Equations
              Instances For
                @[reducible, match_pattern, inline]
                Equations
                Instances For
                  @[reducible, match_pattern, inline]
                  Equations
                  Instances For
                    @[reducible, match_pattern, inline]
                    Equations
                    Instances For
                      @[reducible, match_pattern, inline]
                      Equations
                      Instances For
                        @[reducible, match_pattern, inline]
                        Equations
                        Instances For
                          @[reducible, match_pattern, inline]
                          Equations
                          Instances For
                            @[reducible, match_pattern, inline]
                            Equations
                            Instances For
                              @[reducible, match_pattern, inline]
                              Equations
                              Instances For
                                @[reducible, match_pattern, inline]
                                Equations
                                Instances For
                                  @[reducible, match_pattern, inline]
                                  Equations
                                  Instances For
                                    @[reducible, match_pattern, inline]
                                    Equations
                                    Instances For
                                      @[reducible, match_pattern, inline]
                                      Equations
                                      Instances For
                                        @[reducible, match_pattern, inline]
                                        Equations
                                        Instances For
                                          @[reducible, match_pattern, inline]
                                          Equations
                                          Instances For
                                            @[reducible, match_pattern, inline]
                                            Equations
                                            Instances For
                                              @[reducible, match_pattern, inline]
                                              Equations
                                              Instances For
                                                @[reducible, match_pattern, inline]
                                                Equations
                                                Instances For
                                                  inductive Core.Tree.Tree (C W : Type) :

                                                  Framework-neutral tree, parameterized by node label type C and terminal word type W.

                                                  • terminal c w — leaf carrying category c and word w
                                                  • node c cs — internal node with category c and children cs
                                                  • trace n c — movement trace with index n and category c
                                                  • bind n c body — λ-abstraction with index n, category c, scope body

                                                  The node constructor takes a List of children, subsuming both binary branching (for Heim & Kratzer composition) and n-ary structure (for Katzir's deletion operation). Binary nodes are node c [l, r].

                                                  trace and bind support Quantifier Raising and variable binding. Frameworks without movement (CCG, HPSG) simply never construct these.

                                                  For category-free trees (C = Unit), use the convenience constructors leaf, bin, un, tr, binder which hide the Unit parameter.

                                                  Instances For
                                                    @[implicit_reducible]
                                                    instance Core.Tree.instReprTree {C✝ W✝ : Type} [Repr C✝] [Repr W✝] :
                                                    Repr (Tree C✝ W✝)
                                                    Equations
                                                    partial def Core.Tree.instReprTree.repr {C✝ W✝ : Type} [Repr C✝] [Repr W✝] :
                                                    Tree C✝ W✝Std.Format
                                                    @[reducible, match_pattern, inline]
                                                    abbrev Core.Tree.Tree.leaf {W : Type} (w : W) :
                                                    Tree Unit W
                                                    Equations
                                                    Instances For
                                                      @[reducible, match_pattern, inline]
                                                      abbrev Core.Tree.Tree.un {W : Type} (t : Tree Unit W) :
                                                      Tree Unit W
                                                      Equations
                                                      Instances For
                                                        @[reducible, match_pattern, inline]
                                                        abbrev Core.Tree.Tree.bin {W : Type} (t1 t2 : Tree Unit W) :
                                                        Tree Unit W
                                                        Equations
                                                        Instances For
                                                          @[reducible, match_pattern, inline]
                                                          abbrev Core.Tree.Tree.tr {W : Type} (n : ) :
                                                          Tree Unit W
                                                          Equations
                                                          Instances For
                                                            @[reducible, match_pattern, inline]
                                                            abbrev Core.Tree.Tree.binder {W : Type} (n : ) (body : Tree Unit W) :
                                                            Tree Unit W
                                                            Equations
                                                            Instances For
                                                              def Core.Tree.Tree.cat {C W : Type} :
                                                              Tree C WC

                                                              Category label of the root node. Total: every constructor carries a category (including bind, where it labels the result of PA).

                                                              Equations
                                                              Instances For
                                                                def Core.Tree.Tree.beq {C W : Type} [BEq C] [BEq W] :
                                                                Tree C WTree C WBool

                                                                Structural equality for trees (mutual recursion through List).

                                                                Equations
                                                                Instances For
                                                                  def Core.Tree.Tree.beq.beqList {C W : Type} [BEq C] [BEq W] :
                                                                  List (Tree C W)List (Tree C W)Bool
                                                                  Equations
                                                                  Instances For
                                                                    @[implicit_reducible]
                                                                    instance Core.Tree.Tree.instBEq {C W : Type} [BEq C] [BEq W] :
                                                                    BEq (Tree C W)
                                                                    Equations
                                                                    def Core.Tree.Tree.decEq {C W : Type} [DecidableEq C] [DecidableEq W] (a b : Tree C W) :
                                                                    Decidable (a = b)

                                                                    Decidable equality on Tree C W, mutually recursive with the list-of-trees case. Required because deriving DecidableEq does not handle the nested List (Tree C W) in node.

                                                                    Equations
                                                                    Instances For
                                                                      def Core.Tree.Tree.decEqList {C W : Type} [DecidableEq C] [DecidableEq W] (as bs : List (Tree C W)) :
                                                                      Decidable (as = bs)

                                                                      Helper: decidable equality for list of trees.

                                                                      Equations
                                                                      Instances For
                                                                        @[implicit_reducible]
                                                                        instance Core.Tree.Tree.instDecidableEq {C W : Type} [DecidableEq C] [DecidableEq W] :
                                                                        DecidableEq (Tree C W)
                                                                        Equations
                                                                        def Core.Tree.Tree.size {C W : Type} :
                                                                        Tree C W

                                                                        Number of nodes in the tree.

                                                                        Equations
                                                                        Instances For
                                                                          def Core.Tree.Tree.leafCount {C W : Type} :
                                                                          Tree C W

                                                                          Number of word-bearing terminals (leaves) in the tree. Traces and binders contribute 0; internal nodes recurse.

                                                                          Equations
                                                                          Instances For
                                                                            @[irreducible]
                                                                            def Core.Tree.Tree.binRec {W : Type} {motive : Tree Unit WSort u_1} (term : (w : W) → motive (terminal () w)) (binNode : (l r : Tree Unit W) → motive lmotive rmotive (node () [l, r])) (tr : (n : ) → motive (trace n ())) (bd : (n : ) → (body : Tree Unit W) → motive bodymotive (bind n () body)) (nilNode : motive (node () [])) (singletonNode : (c : Tree Unit W) → motive (node () [c])) (manyNode : (c1 c2 c3 : Tree Unit W) → (cs : List (Tree Unit W)) → motive (node () (c1 :: c2 :: c3 :: cs))) (t : Tree Unit W) :
                                                                            motive t

                                                                            Custom recursor for binary trees over Tree Unit W. The default induction tactic refuses nested inductives like Tree; this recursor expands the node-case enumeration so each non-binary arity (0, 1, ≥3 children) gets its own branch, separate from the binary binNode case that carries inductive hypotheses. With @[elab_as_elim], used as induction t using Tree.binRec with | term … | binNode … | tr … | bd … | nilNode | singletonNode … | manyNode ….

                                                                            Equations
                                                                            Instances For
                                                                              def Core.Tree.Tree.subtrees {C W : Type} :
                                                                              Tree C WList (Tree C W)

                                                                              All subtrees including self (pre-order traversal).

                                                                              Equations
                                                                              Instances For
                                                                                def Core.Tree.Tree.containsCat {C W : Type} [BEq C] (target : C) :
                                                                                Tree C WBool

                                                                                Whether a category appears anywhere in the tree.

                                                                                Equations
                                                                                Instances For
                                                                                  def Core.Tree.Tree.containsCat.containsCatList {C W : Type} [BEq C] (target : C) :
                                                                                  List (Tree C W)Bool
                                                                                  Equations
                                                                                  Instances For
                                                                                    def Core.Tree.Tree.leafSubst {C W : Type} [BEq C] [BEq W] (target replacement : W) (c : C) :
                                                                                    Tree C WTree C W

                                                                                    Substitute all terminals of category c carrying word target with replacement. This is the most common structural operation: replacing one scalar item with another of the same category.

                                                                                    Equations
                                                                                    Instances For
                                                                                      def Core.Tree.Tree.leafSubst.leafSubstList {C W : Type} [BEq C] [BEq W] (target replacement : W) (c : C) :
                                                                                      List (Tree C W)List (Tree C W)
                                                                                      Equations
                                                                                      Instances For

                                                                                        A path from the root of a tree, encoded as a list of child indices.

                                                                                        Each element is the index in the parent's child list (or 0 for the unique child of a bind). The empty path identifies the root.

                                                                                        • toList : List

                                                                                          The underlying list of child indices.

                                                                                        Instances For
                                                                                          @[implicit_reducible]

                                                                                          Dominance order: p ≤ q iff p is a prefix of q.

                                                                                          Equations
                                                                                          @[implicit_reducible]
                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          theorem Core.Tree.TreePath.prefix_or_prefix {p q r : TreePath} (hp : p r) (hq : q r) :
                                                                                          p q q p

                                                                                          Two prefixes of the same list are comparable. This is the Connected Ancestor Condition (CAC) for the prefix order.

                                                                                          def Core.Tree.Tree.subtreeAt {C W : Type} :
                                                                                          Tree C WList Option (Tree C W)

                                                                                          Subtree at the given path; none if the path leaves the tree.

                                                                                          For node c cs, the next index i selects child cs[i]?; for bind, only index 0 is valid (binders have a single body).

                                                                                          Equations
                                                                                          Instances For
                                                                                            def Core.Tree.Tree.validPaths {C W : Type} (t : Tree C W) :

                                                                                            Set of valid paths in the tree (paths that resolve to a subtree).

                                                                                            Equations
                                                                                            Instances For
                                                                                              theorem Core.Tree.Tree.nil_validPath {C W : Type} (t : Tree C W) :
                                                                                              { toList := [] } t.validPaths

                                                                                              Forgetful map from a Tree C W to its dominance order as a TreeOrder TreePath. This makes the framework-agnostic command- relation library (@cite{barker-pullum-1990}, B&P) directly applicable to any concrete tree, regardless of category or word type.

                                                                                              Equations
                                                                                              • t.toTreeOrder = { nodes := t.validPaths, root := { toList := [] }, root_in_nodes := , root_le_all := , ancestor_connected := }
                                                                                              Instances For
                                                                                                def FreeMagma.toTree {α : Type} :
                                                                                                FreeMagma αCore.Tree.Tree Unit α

                                                                                                Forgetful map from a free magma to a binary Core.Tree.Tree Unit α.

                                                                                                The image lives in a strict subset of Tree Unit α: only .terminal () (from .of) and the binary .node () [_, _] (from .mul) are produced; the n-ary .node, .trace, and .bind constructors are never used.

                                                                                                By composition with Core.Tree.Tree.toTreeOrder, every FreeMagma α inherits a Core.Order.TreeOrder Core.Tree.TreePath, making B&P's framework-agnostic command-relation library (Linglib.Core.Order.Command) directly applicable.

                                                                                                Universe note: capped at α : Type because Core.Tree.Tree is monomorphic in Type 0; sufficient for LIToken-indexed SyntacticObject.

                                                                                                Equations
                                                                                                Instances For