Function Repository Resource:

TreeCounts

Source Notebook

Create a tree of the counts of the distinct data of each subtree

Contributed by: Ian Ford (Wolfram Research)

ResourceFunction["TreeCounts"][tree]

replaces the data of each subtree of tree with an association whose keys are the distinct data of that subtree and whose values give the number of times those data appear in that subtree.

Examples

Basic Examples (1) 

Give a tree of the counts of the distinct data of each subtree:

In[1]:=
ResourceFunction["TreeCounts"][\!\(\*
GraphicsBox[
NamespaceBox["Trees",
DynamicModuleBox[{Typeset`tree = HoldComplete[
Tree[$CellContext`b, {
Tree[$CellContext`c, {
Tree[$CellContext`c, None]}], 
Tree[$CellContext`a, {
Tree[$CellContext`c, None]}], 
Tree[$CellContext`c, {
Tree[$CellContext`d, None], 
Tree[$CellContext`d, {
Tree[$CellContext`d, None]}]}], 
Tree[$CellContext`a, None]}]]}, 
NamespaceBox[{
{Hue[0.6, 0.7, 0.5], Opacity[0.7], Arrowheads[Medium], 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.2827791657412049`, 2.216869224641865}, {0., 1.4779128164279103`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.2827791657412049`, 2.216869224641865}, {
           0.7330166661378313, 1.4779128164279103`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.2827791657412049`, 2.216869224641865}, {
           1.8325416653445783`, 1.4779128164279103`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.2827791657412049`, 2.216869224641865}, {
           2.5655583314824097`, 1.4779128164279103`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0., 1.4779128164279103`}, {0., 0.7389564082139551}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.7330166661378313, 1.4779128164279103`}, {
           0.7330166661378313, 0.7389564082139551}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.8325416653445783`, 1.4779128164279103`}, {
           1.4660333322756627`, 0.7389564082139551}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.8325416653445783`, 1.4779128164279103`}, {
           2.199049998413494, 0.7389564082139551}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{2.199049998413494, 0.7389564082139551}, {
           2.199049998413494, 0.}}]}}, 
{Hue[0.6, 0.2, 0.8], EdgeForm[{GrayLevel[0], Opacity[0.7]}], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.2827791657412049, 2.216869224641865}],
"DynamicName",
BoxID -> "VertexID$1"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0., 1.4779128164279103}],
"DynamicName",
BoxID -> "VertexID$2"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0., 0.7389564082139551}],
"DynamicName",
BoxID -> "VertexID$3"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.7330166661378313, 1.4779128164279103}],
"DynamicName",
BoxID -> "VertexID$4"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0.7330166661378313, 0.7389564082139551}],
"DynamicName",
BoxID -> "VertexID$5"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.8325416653445783, 1.4779128164279103}],
"DynamicName",
BoxID -> "VertexID$6"], 
TagBox[InsetBox[
FrameBox["d",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.4660333322756627, 0.7389564082139551}],
"DynamicName",
BoxID -> "VertexID$7"], 
TagBox[InsetBox[
FrameBox["d",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {2.199049998413494, 0.7389564082139551}],
"DynamicName",
BoxID -> "VertexID$8"], 
TagBox[InsetBox[
FrameBox["d",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2.199049998413494, 0.}],
"DynamicName",
BoxID -> "VertexID$9"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2.5655583314824097, 1.4779128164279103}],
"DynamicName",
BoxID -> "VertexID$10"]}}]]],
AlignmentPoint->Center,
Axes->False,
AxesLabel->None,
AxesOrigin->Automatic,
AxesStyle->{},
Background->None,
BaseStyle->{},
BaselinePosition->Automatic,
ContentSelectable->Automatic,
DefaultBaseStyle->"TreeGraphics",
Epilog->{},
FormatType->StandardForm,
Frame->False,
FrameLabel->FormBox["False", StandardForm],
FrameStyle->{},
FrameTicks->None,
FrameTicksStyle->{},
GridLines->None,
GridLinesStyle->{},
ImageMargins->0.,
ImagePadding->All,
ImageSize->{108.75, Automatic},
LabelStyle->{},
PlotLabel->None,
PlotRange->All,
PlotRangeClipping->False,
PlotRangePadding->Automatic,
PlotRegion->Automatic,
Prolog->{},
RotateLabel->True,
Ticks->Automatic,
TicksStyle->{}]\)]
Out[1]=

Properties and Relations (3) 

Counts gives an Association of the counts of the distinct elements of a list:

In[2]:=
Counts[{a, b, c, a}]
Out[2]=

TreeCounts gives an Association of the counts of the distinct data of each subtree at each node of a tree:

In[3]:=
ResourceFunction["TreeCounts"][\!\(\*
GraphicsBox[
NamespaceBox["Trees",
DynamicModuleBox[{Typeset`tree = HoldComplete[
Tree[$CellContext`d, {
Tree[$CellContext`a, None], 
Tree[$CellContext`b, None], 
Tree[$CellContext`c, None], 
Tree[$CellContext`a, None]}]]}, 
NamespaceBox[{
{Hue[0.6, 0.7, 0.5], Opacity[0.7], Arrowheads[Medium], 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1., 0.7451027094363127}, {0., 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1., 0.7451027094363127}, {0.6666666666666666, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1., 0.7451027094363127}, {1.3333333333333333`, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1., 0.7451027094363127}, {2., 0.}}]}}, 
{Hue[0.6, 0.2, 0.8], EdgeForm[{GrayLevel[0], Opacity[0.7]}], 
TagBox[InsetBox[
FrameBox["d",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1., 0.7451027094363127}],
"DynamicName",
BoxID -> "VertexID$1"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0., 0.}],
"DynamicName",
BoxID -> "VertexID$2"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0.6666666666666666, 0.}],
"DynamicName",
BoxID -> "VertexID$3"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.3333333333333333, 0.}],
"DynamicName",
BoxID -> "VertexID$4"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2., 0.}],
"DynamicName",
BoxID -> "VertexID$5"]}}]]],
AlignmentPoint->Center,
Axes->False,
AxesLabel->None,
AxesOrigin->Automatic,
AxesStyle->{},
Background->None,
BaseStyle->{},
BaselinePosition->Automatic,
ContentSelectable->Automatic,
DefaultBaseStyle->"TreeGraphics",
Epilog->{},
FormatType->StandardForm,
Frame->False,
FrameLabel->FormBox["False", StandardForm],
FrameStyle->{},
FrameTicks->None,
FrameTicksStyle->{},
GridLines->None,
GridLinesStyle->{},
ImageMargins->0.,
ImagePadding->All,
ImageSize->Automatic,
LabelStyle->{},
PlotLabel->None,
PlotRange->All,
PlotRangeClipping->False,
PlotRangePadding->Automatic,
PlotRegion->Automatic,
Prolog->{},
RotateLabel->True,
Ticks->Automatic,
TicksStyle->{}]\)]
Out[3]=

Use Merge to merge two associations, using Total to combine elements with the same key:

In[4]:=
Merge[{<|a -> 1, b -> 4|>, <|a -> 3, b -> 2|>}, Total]
Out[4]=

TreeCounts automatically merges the counts from sibling branches:

In[5]:=
ResourceFunction["TreeCounts"][\!\(\*
GraphicsBox[
NamespaceBox["Trees",
DynamicModuleBox[{Typeset`tree = HoldComplete[
Tree[$CellContext`c, {
Tree[$CellContext`a, {
Tree[$CellContext`b, None], 
Tree[$CellContext`b, {
Tree[$CellContext`b, None], 
Tree[$CellContext`b, None]}]}], 
Tree[$CellContext`a, {
Tree[$CellContext`a, {
Tree[$CellContext`b, None], 
Tree[$CellContext`b, None]}], 
Tree[$CellContext`a, None]}]}]]}, 
NamespaceBox[{
{Hue[0.6, 0.7, 0.5], Opacity[0.7], Arrowheads[Medium], 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.556997888323046, 2.3762676699247125`}, {
           0.3892494720807615, 1.5841784466164748`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.556997888323046, 2.3762676699247125`}, {
           2.7247463045653304`, 1.5841784466164748`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.3892494720807615, 1.5841784466164748`}, {0., 0.7920892233082374}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.3892494720807615, 1.5841784466164748`}, {
           0.778498944161523, 0.7920892233082374}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.778498944161523, 0.7920892233082374}, {
           0.3892494720807615, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.778498944161523, 0.7920892233082374}, {
           1.1677484162422844`, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{2.7247463045653304`, 1.5841784466164748`}, {
           2.335496832484569, 0.7920892233082374}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{2.7247463045653304`, 1.5841784466164748`}, {
           3.113995776646092, 0.7920892233082374}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{2.335496832484569, 0.7920892233082374}, {
           1.9462473604038075`, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{2.335496832484569, 0.7920892233082374}, {
           2.7247463045653304`, 0.}}]}}, 
{Hue[0.6, 0.2, 0.8], EdgeForm[{GrayLevel[0], Opacity[0.7]}], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.556997888323046, 2.3762676699247125}],
"DynamicName",
BoxID -> "VertexID$1"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.3892494720807615, 1.5841784466164748}],
"DynamicName",
BoxID -> "VertexID$2"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0., 0.7920892233082374}],
"DynamicName",
BoxID -> "VertexID$3"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.778498944161523, 0.7920892233082374}],
"DynamicName",
BoxID -> "VertexID$4"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0.3892494720807615, 0.}],
"DynamicName",
BoxID -> "VertexID$5"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.1677484162422844, 0.}],
"DynamicName",
BoxID -> "VertexID$6"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {2.7247463045653304, 1.5841784466164748}],
"DynamicName",
BoxID -> "VertexID$7"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {2.335496832484569, 0.7920892233082374}],
"DynamicName",
BoxID -> "VertexID$8"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.9462473604038075, 0.}],
"DynamicName",
BoxID -> "VertexID$9"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2.7247463045653304, 0.}],
"DynamicName",
BoxID -> "VertexID$10"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {3.113995776646092, 0.7920892233082374}],
"DynamicName",
BoxID -> "VertexID$11"]}}]]],
AlignmentPoint->Center,
Axes->False,
AxesLabel->None,
AxesOrigin->Automatic,
AxesStyle->{},
Background->None,
BaseStyle->{},
BaselinePosition->Automatic,
ContentSelectable->Automatic,
DefaultBaseStyle->"TreeGraphics",
Epilog->{},
FormatType->StandardForm,
Frame->False,
FrameLabel->FormBox["False", StandardForm],
FrameStyle->{},
FrameTicks->None,
FrameTicksStyle->{},
GridLines->None,
GridLinesStyle->{},
ImageMargins->0.,
ImagePadding->All,
ImageSize->Automatic,
LabelStyle->{},
PlotLabel->None,
PlotRange->All,
PlotRangeClipping->False,
PlotRangePadding->Automatic,
PlotRegion->Automatic,
Prolog->{},
RotateLabel->True,
Ticks->Automatic,
TicksStyle->{}]\)]
Out[5]=

TreeCount gives the total number of times a pattern matches the data in a tree:

In[6]:=
TreeCount[\!\(\*
GraphicsBox[
NamespaceBox["Trees",
DynamicModuleBox[{Typeset`tree = HoldComplete[
Tree[$CellContext`b, {
Tree[$CellContext`a, {
Tree[$CellContext`b, {
Tree[$CellContext`a, None]}], 
Tree[$CellContext`b, {
Tree[$CellContext`b, None]}], 
Tree[$CellContext`c, {
Tree[$CellContext`a, None]}]}], 
Tree[$CellContext`c, {
Tree[$CellContext`a, None]}]}]]}, 
NamespaceBox[{
{Hue[0.6, 0.7, 0.5], Opacity[0.7], Arrowheads[Medium], 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.6641005886756874`, 2.4921570416007084`}, {
           0.8320502943378437, 1.6614380277338057`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.6641005886756874`, 2.4921570416007084`}, {
           2.496150883013531, 1.6614380277338057`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 1.6614380277338057`}, {0., 0.8307190138669026}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 1.6614380277338057`}, {
           0.8320502943378437, 0.8307190138669026}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 1.6614380277338057`}, {
           1.6641005886756874`, 0.8307190138669026}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0., 0.8307190138669026}, {0., 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 0.8307190138669026}, {
           0.8320502943378437, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.6641005886756874`, 0.8307190138669026}, {
           1.6641005886756874`, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{2.496150883013531, 1.6614380277338057`}, {
           2.496150883013531, 0.8307190138669026}}]}}, 
{Hue[0.6, 0.2, 0.8], EdgeForm[{GrayLevel[0], Opacity[0.7]}], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.6641005886756874, 2.4921570416007084}],
"DynamicName",
BoxID -> "VertexID$1"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.8320502943378437, 1.6614380277338057}],
"DynamicName",
BoxID -> "VertexID$2"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0., 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$3"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0., 0.}],
"DynamicName",
BoxID -> "VertexID$4"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.8320502943378437, 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$5"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0.8320502943378437, 0.}],
"DynamicName",
BoxID -> "VertexID$6"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.6641005886756874, 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$7"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.6641005886756874, 0.}],
"DynamicName",
BoxID -> "VertexID$8"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {2.496150883013531, 1.6614380277338057}],
"DynamicName",
BoxID -> "VertexID$9"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2.496150883013531, 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$10"]}}]]],
AlignmentPoint->Center,
Axes->False,
AxesLabel->None,
AxesOrigin->Automatic,
AxesStyle->{},
Background->None,
BaseStyle->{},
BaselinePosition->Automatic,
ContentSelectable->Automatic,
DefaultBaseStyle->"TreeGraphics",
Epilog->{},
FormatType->StandardForm,
Frame->False,
FrameLabel->FormBox["False", StandardForm],
FrameStyle->{},
FrameTicks->None,
FrameTicksStyle->{},
GridLines->None,
GridLinesStyle->{},
ImageMargins->0.,
ImagePadding->All,
ImageSize->{87., Automatic},
LabelStyle->{},
PlotLabel->None,
PlotRange->All,
PlotRangeClipping->False,
PlotRangePadding->Automatic,
PlotRegion->Automatic,
Prolog->{},
RotateLabel->True,
Ticks->Automatic,
TicksStyle->{}]\), b]
Out[6]=

TreeCounts gives the counts of the distinct data for each branch of a tree:

In[7]:=
ResourceFunction["TreeCounts"][\!\(\*
GraphicsBox[
NamespaceBox["Trees",
DynamicModuleBox[{Typeset`tree = HoldComplete[
Tree[$CellContext`b, {
Tree[$CellContext`a, {
Tree[$CellContext`b, {
Tree[$CellContext`a, None]}], 
Tree[$CellContext`b, {
Tree[$CellContext`b, None]}], 
Tree[$CellContext`c, {
Tree[$CellContext`a, None]}]}], 
Tree[$CellContext`c, {
Tree[$CellContext`a, None]}]}]]}, 
NamespaceBox[{
{Hue[0.6, 0.7, 0.5], Opacity[0.7], Arrowheads[Medium], 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.6641005886756874`, 2.4921570416007084`}, {
           0.8320502943378437, 1.6614380277338057`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.6641005886756874`, 2.4921570416007084`}, {
           2.496150883013531, 1.6614380277338057`}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 1.6614380277338057`}, {0., 0.8307190138669026}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 1.6614380277338057`}, {
           0.8320502943378437, 0.8307190138669026}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 1.6614380277338057`}, {
           1.6641005886756874`, 0.8307190138669026}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0., 0.8307190138669026}, {0., 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{0.8320502943378437, 0.8307190138669026}, {
           0.8320502943378437, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{1.6641005886756874`, 0.8307190138669026}, {
           1.6641005886756874`, 0.}}]}, 
{RGBColor[0.6, 0.5882352941176471, 0.5529411764705883], AbsoluteThickness[1], LineBox[{{2.496150883013531, 1.6614380277338057`}, {
           2.496150883013531, 0.8307190138669026}}]}}, 
{Hue[0.6, 0.2, 0.8], EdgeForm[{GrayLevel[0], Opacity[0.7]}], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.6641005886756874, 2.4921570416007084}],
"DynamicName",
BoxID -> "VertexID$1"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.8320502943378437, 1.6614380277338057}],
"DynamicName",
BoxID -> "VertexID$2"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0., 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$3"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0., 0.}],
"DynamicName",
BoxID -> "VertexID$4"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.8320502943378437, 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$5"], 
TagBox[InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0.8320502943378437, 0.}],
"DynamicName",
BoxID -> "VertexID$6"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.6641005886756874, 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$7"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.6641005886756874, 0.}],
"DynamicName",
BoxID -> "VertexID$8"], 
TagBox[InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {2.496150883013531, 1.6614380277338057}],
"DynamicName",
BoxID -> "VertexID$9"], 
TagBox[InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.9607843137254902, 0.9882352941176471, 0.9764705882352941]],
            
BaseStyle->GrayLevel[0],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.4196078431372549, 0.6313725490196078, 0.4196078431372549], AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2.496150883013531, 0.8307190138669026}],
"DynamicName",
BoxID -> "VertexID$10"]}}]]],
AlignmentPoint->Center,
Axes->False,
AxesLabel->None,
AxesOrigin->Automatic,
AxesStyle->{},
Background->None,
BaseStyle->{},
BaselinePosition->Automatic,
ContentSelectable->Automatic,
DefaultBaseStyle->"TreeGraphics",
Epilog->{},
FormatType->StandardForm,
Frame->False,
FrameLabel->FormBox["False", StandardForm],
FrameStyle->{},
FrameTicks->None,
FrameTicksStyle->{},
GridLines->None,
GridLinesStyle->{},
ImageMargins->0.,
ImagePadding->All,
ImageSize->{87., Automatic},
LabelStyle->{},
PlotLabel->None,
PlotRange->All,
PlotRangeClipping->False,
PlotRangePadding->Automatic,
PlotRegion->Automatic,
Prolog->{},
RotateLabel->True,
Ticks->Automatic,
TicksStyle->{}]\)]
Out[7]=

Version History

  • 1.0.0 – 19 May 2023

Related Resources

License Information