Dyck words and proper binary trees #
Formalizes the grammar, tree encoding, graded correspondence, and Catalan
cardinality in Lem:optimal_dyck (main.tex:337–342).
The Dyck language (main.tex:337) #
Proper binary tree shapes = L_full_BT (main.tex:318–327) #
Equations
- Nock.instReprBTree = { reprPrec := Nock.instReprBTree.repr }
Equations
- One or more equations did not get rendered due to their size.
- Nock.instReprBTree.repr Nock.BTree.leaf prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "Nock.BTree.leaf")).group prec✝
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Nock.instDecidableEqBTree.decEq Nock.BTree.leaf Nock.BTree.leaf = isTrue ⋯
- Nock.instDecidableEqBTree.decEq Nock.BTree.leaf (a.node a_1) = isFalse ⋯
- Nock.instDecidableEqBTree.decEq (a.node a_1) Nock.BTree.leaf = isFalse ⋯
Instances For
Equations
- Nock.instInhabitedBTree = { default := Nock.instInhabitedBTree.default }
A greedy parser, to pin down injectivity of encode #
`decode fuel w` parses exactly one tree off the front of `w`, returning the tree and the
unconsumed suffix. A leading `0` (`false`) starts a `node`; anything else (a leading `1`
or the empty word) is a `leaf` consuming nothing. This is the algorithmic inverse of
`encode`; `decode_encode` proves the round-trip, which yields injectivity.
Parse one binary tree from a Dyck prefix, returning the tree and unconsumed suffix.
Equations
- One or more equations did not get rendered due to their size.
- Nock.BTree.decode 0 x✝ = none
- Nock.BTree.decode n.succ x✝ = some (Nock.BTree.leaf, x✝)
Instances For
The greedy parser recovers the encoded tree and returns the untouched suffix, provided
the fuel covers the tree's size and the suffix is not "open"-led (which is exactly the
invariant maintained by the recursion: a left subtree is followed by its closing 1, a
right subtree by the parent's suffix).
Lem:optimal_dyck (main.tex:340–342) #
The shape of a noun: erase the leaf data, leaving a proper binary tree (L_full_BT).
The paper's noun (t, dt) pairs this shape (encoded as the Dyck word t) with the leaf
array dt; the Dyck bijection above governs the t component.
Equations
- (Nock.Noun.atom a).shape = Nock.BTree.leaf
- (l.cell r).shape = l.shape.node r.shape
Instances For
The shape preserves leaf and node counts (Noun.size = BTree.size ∘ shape).
The Dyck word of a noun: the encoding of its shape. By Lem:pbt_size (main.tex:333) a
noun with λ leaves has size 2λ − 1, so its Dyck word has length 2λ − 2 = 2(λ−1),
matching the paper's L^{2(λ−1)}_dk component of a noun (main.tex:1164).
Instances For
Leaf array + Def "noun" uniqueness (main.tex:347) #
A noun is `(t, dt)` = Dyck shape + DFS leaf array. These live here (not in NPR) so the
Pure Nock language closure can talk about uniqueness without importing Field/Goldilocks.
Reconstruction. If two nouns have the same shape (Dyck word) and the same leaf array, they are the same noun: the shape fixes the tree structure and the leaf list fills the leaves in DFS order, leaving no ambiguity.
Def "noun" uniqueness (main.tex:347). The map sending a noun to its Dyck word +
leaf array, n ↦ (n.dyckWord, n.leafList), is injective. This is the paper's claim
that the tuple (t, dt) "corresponds to a unique noun" (main.tex:345,347).
Catalan cardinality |L^{2λ}_dk| = C_λ (Lem:optimal_dyck, main.tex:341) #
The shape isomorphism to Mathlib's BinaryTree: a proper-binary-tree leaf is Mathlib's
empty leaf nil; a node is a Mathlib node carrying the unit value.
Equations
- Nock.BTree.leaf.toBin = BinaryTree.nil
- (l.node r).toBin = BinaryTree.node () l.toBin r.toBin
Instances For
Under the shape isomorphism, BTree.size is 2·numNodes + 1: a proper binary tree with
λ internal (Mathlib) nodes has 2λ+1 total nodes (Lem:pbt_size, main.tex:333).
A word lies in dyckWordsOfLen λ iff it is a Dyck word of length 2λ — i.e. this finset is
exactly the paper's L^{2λ}_dk.
Lem:optimal_dyck (main.tex:340–342).
|L^{2λ}_dk| = C_λ.