Physlib.Mathematics.DataStructures.FourTree.Basic
32 declarations
Leaf of type
#LeafThe type `Leaf` is an inductive structure parametrized by a type that contains a single value of type . It represents the terminal level of the hierarchical `FourTree` structure, which is designed to store nested data corresponding to the product type .
Decidability of equality for
#instDecidableEqLeafFor any type that has decidable equality, the equality relation for the type is also decidable. The structure is a wrapper containing a single value of type , representing the terminal level of the hierarchical `FourTree` structure.
Twig structure with data and leaves of type
#TwigGiven two types and , a `Twig` is a data structure that consists of a value of type and a multiset of elements of type `Leaf` .
Branch node of a `FourTree` containing and a multiset of Twigs
#BranchGiven types , , and , the `Branch` type represents a specific level within the `FourTree` hierarchical structure. An element of this type consists of a value of type and a multiset of objects of type `Twig \alpha_3 \alpha_4`.
Trunk node of a `FourTree` structure
#TrunkFor any types , and , a `Trunk` is a data structure that stores a value of type and a multiset of `Branch` objects (which are parameterized by , and ). It represents the highest specific level within the `FourTree` hierarchical structure.
Hierarchical `FourTree` structure over
#FourTreeGiven four types , and , a `FourTree` is an inductive data structure defined as a multiset of `Trunk` elements. It is designed to store values of the product type through a hierarchical tree structure: - A `Trunk` contains a value and a multiset of `Branch` elements. - A `Branch` contains a value and a multiset of `Twig` elements. - A `Twig` contains a value and a multiset of `Leaf` elements. - A `Leaf` contains a value .
String representation for `Leaf α_4`
#instReprLeafGiven a type that already has a defined string representation (an instance of the `Repr` class), this definition provides a string representation for the `Leaf` structure. For any leaf containing a value , its representation is the string "leaf " followed by the string representation of .
String representation for `Twig α_3 α_4`
#instReprTwigGiven types and that have defined string representations (instances of the `Repr` class), this definition provides a string representation for the `Twig` structure. For any twig containing a value and a multiset of leaves , its representation is the string "twig " followed by the string representation of and the string representation of .
String representation for `Branch α_2 α_3 α_4`
#instReprBranchGiven types , , and that have defined string representations, this definition provides a string representation for the `Branch` structure. For any branch consisting of a value and a multiset of twigs , its representation is the string "branch (" followed by the string representation of , a closing parenthesis, and the string representation of .
String representation for `Trunk α_1 α_2 α_3 α_4`
#instReprTrunkGiven types , and that possess string representations (instances of the `Repr` class), this definition provides a string representation for the `Trunk` structure. For any trunk node consisting of a value and a multiset of branches , its representation is the string "trunk (" followed by the string representation of , a closing parenthesis, and the string representation of .
String representation for `FourTree α_1 α_2 α_3 α_4`
#instReprFor types , and that have defined string representations (instances of the `Repr` class), this definition provides a string representation for the `FourTree` structure. For a `FourTree` consisting of a multiset of trunks , its representation is the string "root " followed by the string representation of the multiset .
Construction of a `FourTree` from a multiset of
#fromMultisetGiven four types , and with decidable equality, this function constructs a `FourTree` from a multiset of quadruples . The construction proceeds by hierarchically grouping and deduplicating the components of the tuples: 1. It identifies the set of unique values in to create the `Trunk` nodes. 2. For each , it identifies the set of unique values such that to create `Branch` nodes. 3. For each pair , it identifies the set of unique values such that to create `Twig` nodes. 4. For each triple , it identifies the set of unique values such that to create the terminal `Leaf` nodes. The resulting structure organizes the distinct quadruples present in the multiset into a nested hierarchy.
Conversion of a `FourTree` to a multiset of tuples in
#toMultisetFor types , and , the function maps a `FourTree` to a multiset of quadruples . The multiset is constructed by traversing the hierarchical structure of : for every value in a `Trunk`, every value in a `Branch` within that trunk, every value in a `Twig` within that branch, and every value in a `Leaf` within that twig, the tuple is collected into the resulting multiset.
Cardinality of a `Twig`
#cardGiven a `Twig` consisting of a value of type and a multiset of leaves of type , the cardinality of is defined as the number of elements in its multiset of leaves. If where and is a multiset of leaves, then the function returns .
Cardinality of a `Branch`
#cardGiven a `Branch` consisting of a value of type and a multiset of twigs of type `Twig \alpha_3 \alpha_4`, the cardinality of is defined as the sum of the cardinalities of all twigs in its multiset. If where and is the multiset of twigs, the function returns , which corresponds to the total number of leaves contained within the branch.
Cardinality of a `Trunk`
#cardGiven a `Trunk` consisting of a value of type and a multiset of branches (where each branch is of type `Branch α2 α3 α4`), the cardinality of is defined as the sum of the cardinalities of all branches in its multiset. If where and is the multiset of branches, the function returns . This sum corresponds to the total number of leaves contained within the hierarchical structure of the trunk.
Cardinality of a `FourTree`
#cardGiven a `FourTree` over types , and , which is defined as a multiset of trunks , the cardinality of is the sum of the cardinalities of all trunks in . Mathematically, . This value represents the total number of leaves contained within the entire hierarchical structure of the tree.
for a `FourTree`
#card_eq_toMultiset_cardFor any `FourTree` over types , and , the cardinality of the tree is equal to the cardinality of the multiset of tuples obtained by converting . That is, .
Membership of a Leaf
#memFor a leaf of type that stores an underlying value , an element is defined to be a member of if and only if .
Decidability of membership for a leaf
#instDecidableMemOfDecidableEqGiven a type with decidable equality, for any leaf storing a value and any element , the proposition (which is defined as ) is decidable.
Membership of in a Twig
#memLet be a `Twig` consisting of a value and a multiset of leaves . An element is defined to be a member of if and only if and there exists a leaf such that is a member of . In other words, membership requires the first component of the pair to match the Twig's data and the second component to be contained within one of its constituent leaves.
Decidability of membership for a twig
#instDecidableMemOfDecidableEq_1Given types and with decidable equality, for any twig (consisting of a value in and a multiset of leaves of type ) and any element , the proposition that is a member of is decidable. This is because the membership condition requires checking the equality of the first components and the existence of a leaf in the multiset containing the second component, both of which are decidable properties.
Membership of in a Branch
#memLet be a `Branch` node consisting of a value and a multiset of twigs . An element is defined to be a member of if and only if and there exists a twig such that the pair is a member of . In other words, membership requires the first component of the element to match the data stored in the branch and the remaining components to be contained within one of its constituent twigs.
Decidability of membership for a branch
#instDecidableMemOfDecidableEq_2Given types , and with decidable equality, for any branch (consisting of a value in and a multiset of twigs) and any element , the proposition that is a member of is decidable. This is because the membership condition requires checking the equality of the first component of with the data stored in the branch and determining the existence of a twig in the multiset for which the remaining components form a member, both of which are decidable properties.
Membership of in a `Trunk` node
#memLet be a `Trunk` node consisting of a value and a multiset of branches . An element is defined to be a member of if and only if and there exists a branch such that the triple is a member of (according to the membership criterion for branches). In other words, membership requires the first component of the quadruple to match the data stored in the trunk and the remaining components to be contained within one of its constituent branches.
Decidability of membership for a trunk
#instDecidableMemOfDecidableEq_3Given types , and with decidable equality, for any trunk (consisting of a value in and a multiset of branches) and any element , the proposition that is a member of is decidable. This decidability follows from the fact that checking if the first component of matches the trunk's data is decidable, and checking the existence of a branch in the multiset that contains the remaining components is also decidable.
Membership of in a `FourTree`
#memLet be a `FourTree` over types , and , which is structured as a multiset of `Trunk` elements. A quadruple is defined to be a member of if there exists a trunk in the multiset such that is a member of (according to the membership criterion for trunks).
Decidability of membership for a `FourTree`
#instDecidableMemOfDecidableEq_4For any types , and with decidable equality, given a `FourTree` and an element , the proposition that is a member of (denoted `T.mem x`) is decidable. Since a `FourTree` is a multiset of trunks, this decidability is established by checking the existence of a trunk such that is a member of , a property which is itself decidable.
Membership relation for `FourTree`
#instMembershipProdThis instance defines the membership relation for a `FourTree` . For a quadruple , the notation represents the proposition that is contained within the hierarchical structure of , which is composed of nested multisets of trunks, branches, twigs, and leaves.
Decidability of membership for a `FourTree`
#instDecidableMemProdOfDecidableEqFor any types with decidable equality, given a `FourTree` and an element , the proposition that is a member of (denoted ) is decidable.
Let be a `FourTree` defined over types , and , which hierarchically stores values of the product type . For any quadruple , is a member of () according to the recursive hierarchical membership criterion if and only if is an element of the multiset formed by collecting all tuples stored within the tree's trunks, branches, twigs, and leaves.
Hierarchical Path Components Imply Membership in a `FourTree`
#mem_of_partsLet be a `FourTree` over types , and . Let be a quadruple in . Suppose there exists: 1. a trunk in the multiset of trunks of , 2. a branch in the multiset of branches of , 3. a twig in the multiset of twigs of , and 4. a leaf in the multiset of leaves of . If , and are the data values stored within and respectively, then the quadruple is a member of the tree ().
