PhyslibSearch

Physlib.Mathematics.DataStructures.FourTree.Basic

32 declarations

inductive

Leaf of type α4\alpha_4

#Leaf

The type `Leaf` is an inductive structure parametrized by a type α4\alpha_4 that contains a single value of type α4\alpha_4. It represents the terminal level of the hierarchical `FourTree` structure, which is designed to store nested data corresponding to the product type α1×α2×α3×α4\alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4.

instance

Decidability of equality for Leaf(α4)\text{Leaf}(\alpha_4)

#instDecidableEqLeaf

For any type α4\alpha_4 that has decidable equality, the equality relation for the type Leaf(α4)\text{Leaf}(\alpha_4) is also decidable. The Leaf(α4)\text{Leaf}(\alpha_4) structure is a wrapper containing a single value of type α4\alpha_4, representing the terminal level of the hierarchical `FourTree` structure.

inductive

Twig structure with data α3\alpha_3 and leaves of type α4\alpha_4

#Twig

Given two types α3\alpha_3 and α4\alpha_4, a `Twig` is a data structure that consists of a value of type α3\alpha_3 and a multiset of elements of type `Leaf` α4\alpha_4.

inductive

Branch node of a `FourTree` containing α2\alpha_2 and a multiset of Twigs

#Branch

Given types α2\alpha_2, α3\alpha_3, and α4\alpha_4, the `Branch` type represents a specific level within the `FourTree` hierarchical structure. An element of this type consists of a value of type α2\alpha_2 and a multiset of objects of type `Twig \alpha_3 \alpha_4`.

inductive

Trunk node of a `FourTree` structure

#Trunk

For any types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4, a `Trunk` is a data structure that stores a value of type α1\alpha_1 and a multiset of `Branch` objects (which are parameterized by α2,α3\alpha_2, \alpha_3, and α4\alpha_4). It represents the highest specific level within the `FourTree` hierarchical structure.

inductive

Hierarchical `FourTree` structure over α1,α2,α3,α4\alpha_1, \alpha_2, \alpha_3, \alpha_4

#FourTree

Given four types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4, a `FourTree` is an inductive data structure defined as a multiset of `Trunk` elements. It is designed to store values of the product type α1×α2×α3×α4\alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4 through a hierarchical tree structure: - A `Trunk` contains a value a1α1a_1 \in \alpha_1 and a multiset of `Branch` elements. - A `Branch` contains a value a2α2a_2 \in \alpha_2 and a multiset of `Twig` elements. - A `Twig` contains a value a3α3a_3 \in \alpha_3 and a multiset of `Leaf` elements. - A `Leaf` contains a value a4α4a_4 \in \alpha_4.

instance

String representation for `Leaf α_4`

#instReprLeaf

Given a type α4\alpha_4 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 vα4v \in \alpha_4, its representation is the string "leaf " followed by the string representation of vv.

instance

String representation for `Twig α_3 α_4`

#instReprTwig

Given types α3\alpha_3 and α4\alpha_4 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 vα3v \in \alpha_3 and a multiset of leaves MM, its representation is the string "twig " followed by the string representation of vv and the string representation of MM.

instance

String representation for `Branch α_2 α_3 α_4`

#instReprBranch

Given types α2\alpha_2, α3\alpha_3, and α4\alpha_4 that have defined string representations, this definition provides a string representation for the `Branch` structure. For any branch consisting of a value xα2x \in \alpha_2 and a multiset of twigs MM, its representation is the string "branch (" followed by the string representation of xx, a closing parenthesis, and the string representation of MM.

instance

String representation for `Trunk α_1 α_2 α_3 α_4`

#instReprTrunk

Given types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4 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 xα1x \in \alpha_1 and a multiset of branches MM, its representation is the string "trunk (" followed by the string representation of xx, a closing parenthesis, and the string representation of MM.

instance

String representation for `FourTree α_1 α_2 α_3 α_4`

#instRepr

For types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4 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 SS, its representation is the string "root " followed by the string representation of the multiset SS.

definition

Construction of a `FourTree` from a multiset of α1×α2×α3×α4\alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4

#fromMultiset

Given four types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4 with decidable equality, this function constructs a `FourTree` from a multiset LL of quadruples (a1,a2,a3,a4)α1×α2×α3×α4(a_1, a_2, a_3, a_4) \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4. The construction proceeds by hierarchically grouping and deduplicating the components of the tuples: 1. It identifies the set of unique values a1a_1 in LL to create the `Trunk` nodes. 2. For each a1a_1, it identifies the set of unique values a2a_2 such that (a1,a2,a3,a4)L(a_1, a_2, a_3, a_4) \in L to create `Branch` nodes. 3. For each pair (a1,a2)(a_1, a_2), it identifies the set of unique values a3a_3 such that (a1,a2,a3,a4)L(a_1, a_2, a_3, a_4) \in L to create `Twig` nodes. 4. For each triple (a1,a2,a3)(a_1, a_2, a_3), it identifies the set of unique values a4a_4 such that (a1,a2,a3,a4)L(a_1, a_2, a_3, a_4) \in L to create the terminal `Leaf` nodes. The resulting structure organizes the distinct quadruples present in the multiset into a nested hierarchy.

definition

Conversion of a `FourTree` to a multiset of tuples in α1×α2×α3×α4\alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4

#toMultiset

For types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4, the function maps a `FourTree` TT to a multiset of quadruples (a1,a2,a3,a4)α1×α2×α3×α4(a_1, a_2, a_3, a_4) \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4. The multiset is constructed by traversing the hierarchical structure of TT: for every value a1a_1 in a `Trunk`, every value a2a_2 in a `Branch` within that trunk, every value a3a_3 in a `Twig` within that branch, and every value a4a_4 in a `Leaf` within that twig, the tuple (a1,a2,a3,a4)(a_1, a_2, a_3, a_4) is collected into the resulting multiset.

definition

Cardinality of a `Twig` TT

#card

Given a `Twig` TT consisting of a value of type α3\alpha_3 and a multiset of leaves of type α4\alpha_4, the cardinality of TT is defined as the number of elements in its multiset of leaves. If T=(v,L)T = (v, L) where vα3v \in \alpha_3 and LL is a multiset of leaves, then the function returns L|L|.

definition

Cardinality of a `Branch` TT

#card

Given a `Branch` TT consisting of a value of type α2\alpha_2 and a multiset of twigs of type `Twig \alpha_3 \alpha_4`, the cardinality of TT is defined as the sum of the cardinalities of all twigs in its multiset. If T=(v,S)T = (v, S) where vα2v \in \alpha_2 and SS is the multiset of twigs, the function returns tScard(t)\sum_{t \in S} \text{card}(t), which corresponds to the total number of leaves contained within the branch.

definition

Cardinality of a `Trunk` TT

#card

Given a `Trunk` TT consisting of a value of type α1\alpha_1 and a multiset of branches BB (where each branch is of type `Branch α2 α3 α4`), the cardinality of TT is defined as the sum of the cardinalities of all branches in its multiset. If T=(v,B)T = (v, B) where vα1v \in \alpha_1 and BB is the multiset of branches, the function returns bBcard(b)\sum_{b \in B} \text{card}(b). This sum corresponds to the total number of leaves contained within the hierarchical structure of the trunk.

definition

Cardinality of a `FourTree` TT

#card

Given a `FourTree` TT over types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4, which is defined as a multiset of trunks SS, the cardinality of TT is the sum of the cardinalities of all trunks in SS. Mathematically, card(T)=tScard(t)\text{card}(T) = \sum_{t \in S} \text{card}(t). This value represents the total number of leaves contained within the entire hierarchical structure of the tree.

theorem

card(T)=card(toMultiset(T))\text{card}(T) = \text{card}(\text{toMultiset}(T)) for a `FourTree` TT

#card_eq_toMultiset_card

For any `FourTree` TT over types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4, the cardinality of the tree TT is equal to the cardinality of the multiset of tuples (a1,a2,a3,a4)α1×α2×α3×α4(a_1, a_2, a_3, a_4) \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4 obtained by converting TT. That is, card(T)=card(toMultiset(T))\text{card}(T) = \text{card}(\text{toMultiset}(T)).

definition

Membership of a Leaf TT

#mem

For a leaf TT of type α4\alpha_4 that stores an underlying value xsα4xs \in \alpha_4, an element xα4x \in \alpha_4 is defined to be a member of TT if and only if x=xsx = xs.

instance

Decidability of membership xTx \in T for a leaf TT

#instDecidableMemOfDecidableEq

Given a type α4\alpha_4 with decidable equality, for any leaf TT storing a value xsα4x_s \in \alpha_4 and any element xα4x \in \alpha_4, the proposition xTx \in T (which is defined as x=xsx = x_s) is decidable.

definition

Membership of xα3×α4x \in \alpha_3 \times \alpha_4 in a Twig TT

#mem

Let TT be a `Twig` consisting of a value xsα3x_s \in \alpha_3 and a multiset of leaves LL. An element x=(x1,x2)α3×α4x = (x_1, x_2) \in \alpha_3 \times \alpha_4 is defined to be a member of TT if and only if xs=x1x_s = x_1 and there exists a leaf lLl \in L such that x2x_2 is a member of ll. 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.

instance

Decidability of membership xTx \in T for a twig TT

#instDecidableMemOfDecidableEq_1

Given types α3\alpha_3 and α4\alpha_4 with decidable equality, for any twig TT (consisting of a value in α3\alpha_3 and a multiset of leaves of type α4\alpha_4) and any element xα3×α4x \in \alpha_3 \times \alpha_4, the proposition that xx is a member of TT is decidable. This is because the membership condition xTx \in T 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.

definition

Membership of xα2×α3×α4x \in \alpha_2 \times \alpha_3 \times \alpha_4 in a Branch TT

#mem

Let TT be a `Branch` node consisting of a value vα2v \in \alpha_2 and a multiset of twigs T\mathcal{T}. An element x=(x1,x2,x3)α2×α3×α4x = (x_1, x_2, x_3) \in \alpha_2 \times \alpha_3 \times \alpha_4 is defined to be a member of TT if and only if v=x1v = x_1 and there exists a twig tTt \in \mathcal{T} such that the pair (x2,x3)(x_2, x_3) is a member of tt. 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.

instance

Decidability of membership xTx \in T for a branch TT

#instDecidableMemOfDecidableEq_2

Given types α2,α3\alpha_2, \alpha_3, and α4\alpha_4 with decidable equality, for any branch TT (consisting of a value in α2\alpha_2 and a multiset of twigs) and any element xα2×α3×α4x \in \alpha_2 \times \alpha_3 \times \alpha_4, the proposition that xx is a member of TT is decidable. This is because the membership condition xTx \in T requires checking the equality of the first component of xx with the data stored in the branch and determining the existence of a twig in the multiset for which the remaining components (x2,x3)(x_2, x_3) form a member, both of which are decidable properties.

definition

Membership of xα1×α2×α3×α4x \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4 in a `Trunk` node TT

#mem

Let TT be a `Trunk` node consisting of a value vα1v \in \alpha_1 and a multiset of branches B\mathcal{B}. An element x=(x1,x2,x3,x4)α1×α2×α3×α4x = (x_1, x_2, x_3, x_4) \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4 is defined to be a member of TT if and only if v=x1v = x_1 and there exists a branch bBb \in \mathcal{B} such that the triple (x2,x3,x4)(x_2, x_3, x_4) is a member of bb (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.

instance

Decidability of membership xTx \in T for a trunk TT

#instDecidableMemOfDecidableEq_3

Given types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4 with decidable equality, for any trunk TT (consisting of a value in α1\alpha_1 and a multiset of branches) and any element xα1×α2×α3×α4x \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4, the proposition that xx is a member of TT is decidable. This decidability follows from the fact that checking if the first component of xx matches the trunk's data is decidable, and checking the existence of a branch in the multiset that contains the remaining components (x2,x3,x4)(x_2, x_3, x_4) is also decidable.

definition

Membership of xα1×α2×α3×α4x \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4 in a `FourTree` TT

#mem

Let TT be a `FourTree` over types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4, which is structured as a multiset of `Trunk` elements. A quadruple x=(x1,x2,x3,x4)α1×α2×α3×α4x = (x_1, x_2, x_3, x_4) \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4 is defined to be a member of TT if there exists a trunk tt in the multiset such that xx is a member of tt (according to the membership criterion for trunks).

instance

Decidability of membership xTx \in T for a `FourTree` TT

#instDecidableMemOfDecidableEq_4

For any types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4 with decidable equality, given a `FourTree` TT and an element xα1×α2×α3×α4x \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4, the proposition that xx is a member of TT (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 tTt \in T such that xx is a member of tt, a property which is itself decidable.

instance

Membership relation xTx \in T for `FourTree`

#instMembershipProd

This instance defines the membership relation \in for a `FourTree` TT. For a quadruple x=(x1,x2,x3,x4)α1×α2×α3×α4x = (x_1, x_2, x_3, x_4) \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4, the notation xTx \in T represents the proposition that xx is contained within the hierarchical structure of TT, which is composed of nested multisets of trunks, branches, twigs, and leaves.

instance

Decidability of membership xTx \in T for a `FourTree` TT

#instDecidableMemProdOfDecidableEq

For any types α1,α2,α3,α4\alpha_1, \alpha_2, \alpha_3, \alpha_4 with decidable equality, given a `FourTree` TT and an element xα1×α2×α3×α4x \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4, the proposition that xx is a member of TT (denoted xTx \in T) is decidable.

theorem

xT    xT.toMultisetx \in T \iff x \in T.\text{toMultiset}

#mem_iff_mem_toMultiset

Let TT be a `FourTree` defined over types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4, which hierarchically stores values of the product type α1×α2×α3×α4\alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4. For any quadruple xα1×α2×α3×α4x \in \alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4, xx is a member of TT (xTx \in T) according to the recursive hierarchical membership criterion if and only if xx is an element of the multiset T.toMultisetT.\text{toMultiset} formed by collecting all tuples (a1,a2,a3,a4)(a_1, a_2, a_3, a_4) stored within the tree's trunks, branches, twigs, and leaves.

theorem

Hierarchical Path Components Imply Membership in a `FourTree`

#mem_of_parts

Let TT be a `FourTree` over types α1,α2,α3\alpha_1, \alpha_2, \alpha_3, and α4\alpha_4. Let C=(a1,a2,a3,a4)C = (a_1, a_2, a_3, a_4) be a quadruple in α1×α2×α3×α4\alpha_1 \times \alpha_2 \times \alpha_3 \times \alpha_4. Suppose there exists: 1. a trunk tt in the multiset of trunks of TT, 2. a branch bb in the multiset of branches of tt, 3. a twig ww in the multiset of twigs of bb, and 4. a leaf ll in the multiset of leaves of ww. If a1,a2,a3a_1, a_2, a_3, and a4a_4 are the data values stored within t,b,w,t, b, w, and ll respectively, then the quadruple CC is a member of the tree TT (CTC \in T).