LeafIndexingTree¶
tree.spad line 639 [edit on github]
LeafIndexingTree is a tree where the children of each node are totally ordered from left to right, smaller means left. The root node has an arbitrary label (= value). Each other node has as label the number of leaves in the subtree of its parent node y, consisting of all the childrens left to the edge x-y. These edges are labeled from left to right by 1,2,… Assume that there are exactly l leaves. This setting determines a bijection between {0,1,…,l-1} and the leaves, respectively the paths given as list of edge numbers from the root node to the leaves: rank and unrank. Output is inherited from Tree(NNI) and implemented in the package TreeOutput. See its documentation for more details.
- #: % -> NonNegativeInteger
from Aggregate
- any?: (NonNegativeInteger -> Boolean, %) -> Boolean
- childrenValues: % -> List NonNegativeInteger
childrenValues(t)considers thekchildrent(0), ..,t(k-1) and returns the partial sumsv(t0)+..+v(t(i-1)) for 1<=i<=k.
- coerce: % -> OutputForm
from CoercibleTo OutputForm
- coerce: % -> Tree NonNegativeInteger
- count: (NonNegativeInteger -> Boolean, %) -> NonNegativeInteger
- count: (NonNegativeInteger, %) -> NonNegativeInteger
- depth: % -> NonNegativeInteger
depth(t)returns the length of the longest path from root to a leaf. Should be moved toRecursiveAggregate.
- elt: (%, PositiveInteger) -> %
from Eltable(PositiveInteger, %)
- elt: (%, value) -> NonNegativeInteger
- enumerate: % -> List List NonNegativeInteger
enumerate(t)constructs all paths from the root oftto its leaves. If a node hascchildren, then its edges to these children are labelled by 1..v. To get the corresponding combinatorial objects, one has to apply the appropriatepathTo...function.
- eval: (%, Equation NonNegativeInteger) -> % if NonNegativeInteger has Evalable NonNegativeInteger
- eval: (%, List Equation NonNegativeInteger) -> % if NonNegativeInteger has Evalable NonNegativeInteger
- eval: (%, List NonNegativeInteger, List NonNegativeInteger) -> % if NonNegativeInteger has Evalable NonNegativeInteger
- eval: (%, NonNegativeInteger, NonNegativeInteger) -> % if NonNegativeInteger has Evalable NonNegativeInteger
- every?: (NonNegativeInteger -> Boolean, %) -> Boolean
- grtr: (List List NonNegativeInteger, List List NonNegativeInteger) -> Boolean
grtr(path1, path2)is used to sort lists of unordered set partitions. First, according to the lexicographical order of the lengths of the subsets, then according to the entries in descending order.
- hash: % -> SingleInteger
from Hashable
- hashUpdate!: (HashState, %) -> HashState
from Hashable
- isLeafIndexingTree?: Tree NonNegativeInteger -> Boolean
isLeafIndexingTree?(t)checks, if the given tree is a leaf indexing tree. This has to be checked by inspecting all nodesy, whether either the node is a leaf or if each value of a childxis the number of leaves which can be reached starting from the node via the edges left to the the edgey-x. The value of the root does not play a role, so it can be abitrary.
- isPathToLeaf?: (%, List NonNegativeInteger) -> Boolean
isPathToLeaf?(t, ln)checks whetherlnis a path fromtto a leave oft, in particular two neighboured entries must satisfy a parent-child relationship. Note, that themleaves are in 1-1-correspondence with such paths, as the graph is a tree. And also with the set {0,..m-1} the ranks.
- latex: % -> String
from SetCategory
- leafIndexingTree: (NonNegativeInteger, List %) -> %
leafIndexingTree(v, lt)considersltas the list of children and adds a parent node with valuevto create a new tree with this root. Before it changes the values of the child trees value(lt(1)) = 0, value(lt(2)) = #leaves(lt(1)), value(lt(3))= #leaves(lt(1)) + #leaves(lt(2)) and so on.
- leafIndexingTree: List % -> %
leafIndexingTree(lt)considersltas the list of children and adds a parent node with value 0 to create a new tree with this root. Before it changes the values of the child trees value(lt(1)) = 0, value(lt(2)) = #leaves(lt(1)), value(lt(3))= #leaves(lt(1)) + #leaves(lt(2)) and so on.
- leafIndexingTree: NonNegativeInteger -> %
leafIndexingTree(v)creates a leaf indexing tree with valuev, and no children.
- leafIndexingTree: Tree NonNegativeInteger -> %
leafIndexingTree(t)modifiestto become a leaf indexing tree by setting the values for the required counting.
- less?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- logicFunctionTree: (NonNegativeInteger, NonNegativeInteger) -> %
logicFunctionTree(n,k)constructs the tree of all logic functions innvariables and exactlykminterms. Use with care as there arebinomial(2^n,k)of them.
- logicFunctionTree: NonNegativeInteger -> %
logicFunctionTree(n)constructs the tree with depth 2 for all logic function innvariables, represented in canonocialDNF-form as a sum of (s-1) of the 2^n minterms for 1<=s<=2^n+1 (children). For each (s-1) at the next level we choose the (t-1)-th (s-1)-subset of the 2^n minterms, for 1<=t<=binomial(2^n,s). The path from the root to such a leaf is [s,t]. Note, a conversion functionpathToLogicFunctionis still missing as we needp-restricted integer and a domainLogicFunctionnot yet in the system. Use with care as there are2^(2^n)of them.
- map!: (NonNegativeInteger -> NonNegativeInteger, %) -> %
- map: (NonNegativeInteger -> NonNegativeInteger, %) -> %
- max: % -> NonNegativeInteger
- max: ((NonNegativeInteger, NonNegativeInteger) -> Boolean, %) -> NonNegativeInteger
- more?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- nextEdge: (NonNegativeInteger, List NonNegativeInteger) -> NonNegativeInteger
nextEdge(r: NNI, lvs: List NNI)returns the largestisuch thatlvs(i)<=r. It is required, but unchecked, that the entries oflvsare strictly increasing from left to right. The labelling of the edges starts with 1.
- numberOfChildren: % -> NonNegativeInteger
numberOfChildren(t)returns the number of children of the root of treet.
- numberOfLeaves: % -> NonNegativeInteger
numberOfLeaves(t)counts the number of leaves oft.
- numberOfNodes: (%, NonNegativeInteger) -> NonNegativeInteger
numberOfNode(
t,d) counts the number of nodes oftwith depthdincluding leaves with smaller depth.
- P: (NonNegativeInteger, NonNegativeInteger) -> NonNegativeInteger
P(n,k)returns the number of unorderedk- number partitions ofn, e.g.P(7,3) = 4 = #{[5,1,1],[4,2,1],[3,3,1],[3,2,2]}
- pathToPermutationCycles: (NonNegativeInteger, NonNegativeInteger, List NonNegativeInteger) -> List List NonNegativeInteger
pathToPermutationCycles(n,k,lp)constructs the permutation of {1,..,n} withkcycles, represented by the path from the root of its tree to a leave.
- pathToSubset: (NonNegativeInteger, NonNegativeInteger, List NonNegativeInteger) -> List Integer
pathToSubset(n, k, lp)constructs ak-subset of {1,…,n} which corresponds to a leaf of subsetTree(n,k). Elements are in descending Order
- pathToUnorderedNumberPartition: (NonNegativeInteger, NonNegativeInteger, List NonNegativeInteger) -> List NonNegativeInteger
pathToUnorderedNumberPartition(n,k,lp)constructs the unordered number partition ofnwithkcomponents, represented by the path from the root of its tree to a leave.
- pathToUnorderedSetPartition: (NonNegativeInteger, NonNegativeInteger, List NonNegativeInteger) -> List List NonNegativeInteger
pathToUnorderedSetPartition(n,k,lp)constructs the unordered set partition ofninknon-empty subsets, represented by the path from the root of its tree to a leave.
- permutationCyclesTree: (NonNegativeInteger, NonNegativeInteger) -> %
permutationCyclesTree(n, k), abbreviated by [n,k] gives the tree for the permutations of {1,2,..,n} with exactlykcycles. Their number isstirling1(n,k). The constructing recursion is [n,k] = [n-k,k] + (n-1)[n-1,k-1], termination is [n,n] = [(1),(2),..,(n)], [2,1] = [(1,2)] first edge drop cycle (n), if possible, next (n-1) edges: dropnout of the cycle, whereiis mapped ton, 1<=i<=n-1. Bijections: [n-1,k-1]->[n,k], c1*c2*..*c(k-1) +-> c1*c2*..*c(k-1)*(n) case 1<=i<=n-1 : [n-1,k]->[n,k], c1*c2*..*ck+-> _ c1*c2*..*cj'*..*clwherecj=(…i,n,l,,,) is the cycle whereiis mapped tonwhilecj'=(…i,l,,,) is the cycle wherenis cancelled.
- randomPath: % -> List NonNegativeInteger
randomPath(t)constructs path from the root oftto one leaf. Each leaf has equal chance to be selected by random.
- rank: (%, List NonNegativeInteger) -> NonNegativeInteger
rank(t, path)returns the rank of the leaf at the end of the path. This is the number starting with 0 from left to right in the natural ordering of the leaves given by the ordering of the children at each node.
- retractIfCan: Tree NonNegativeInteger -> Union(%, failed)
- setchildren!: (%, List %) -> %
- setCountingValues: List % -> List %
setCountingValues(lt)sets all values to satisfy the counting conditions of a leaf indexing tree.
- setelt!: (%, value, NonNegativeInteger) -> NonNegativeInteger
- setValue: (%, NonNegativeInteger) -> %
setValue(t, v)setsvas the new value of treet.
- size?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- subsetTree: (NonNegativeInteger, NonNegativeInteger) -> %
subsetTree(n, k)constructs the tree with depthkfor allk-subsets of ann-element set as {1,2,..,n}. Its elements are sorted in decreasing order. A path (p1,p2,..,pk) from root to a leave represents the subset {s1:=n-p1+1,s2:=s1-p2+1, …}.
- unorderedNumberPartitionTree: (NonNegativeInteger, NonNegativeInteger) -> %
unorderedNumberPartitionTree(n,k), abbreviated byP(n,k), gives the tree forthe unordered number partitions ofnin exactlyksummands > 0. Therr number can be computed byP(n,k). Recursion isP(n,k) =P(n-k,k) +P(n-1,k-1), Termination isP(n,n) = {[1,1,..,1]},P(n,1) = {[n]}. First edge -[1,1,,1], if smallest element>=2, otherwise second edge drop: ..,1]. Bijections:P(n,k,>1)->P(n-k,k),p+->p-[1,1,..,1]P(n,k,1)->P(n-1,k-1),p= [p1,p2,..,.p(k-1),1] +-> [p1,p2,..,.p(k-1)]
- unorderedSetPartitionTree: (NonNegativeInteger, NonNegativeInteger) -> %
unorderedSetPartitionTree(n,k), abbreviated by {n,k}, gives the tree for the unordered set partitions ofnin exactlyknon-empty subsets, ak-clustering. Recursion is {n,k} = {n-1,k-1} +k{n-1,k}, termination is {n,n} = {{1},{2},..,{n}}, {n,1} = {{1,2,..,n}} First edge drop 1-element set {n}, nextkedges 2<=i<=k+1: dropnfrom thei-th subset where it is included, bijections: {n-1,k-1}->{n,k},c= {c1,c2, …,c(k-1)} +-> {c1,c2, …,c(k-1), {n}} case i: {n-1,k)->{n,k},c= {c1,c2, …,ck} +-> {c1,c2, …,c(i-1),ciunion {n},c(i+1),..,ck}
- unrank: (%, NonNegativeInteger) -> List NonNegativeInteger
unrank(t, r)returns the path from top node oftto the leaf, numbered byr. Argumentrmust satisfy 0<=r< numberOfLeaves(t).
CoercibleTo Tree NonNegativeInteger
Evalable NonNegativeInteger if NonNegativeInteger has Evalable NonNegativeInteger
HomogeneousAggregate NonNegativeInteger
InnerEvalable(NonNegativeInteger, NonNegativeInteger) if NonNegativeInteger has Evalable NonNegativeInteger
RecursiveAggregate NonNegativeInteger