WOLFRAM

TreeRules[tree]

returns the rules associated with the Tree object tree.

Details

  • TreeRules returns the rules associated with a tree expression.
  • The inverse operation of TreeRules is performed by RulesTree.
  • If tree has a list of children, then TreeRules[tree] gives data{rule1,rule2,}, where data is the data in tree and rulei are the rules associated with its children.
  • TreeRules[Tree[data,<|key1tree1,key2tree2,|>]] gives data<|key1TreeRules[tree1],key2TreeRules[tree2],|>.
  • TreeRules[Tree[data,None]] for data of the form {}, <||> or None gives dataNone rather than data. »

Examples

open allclose all

Basic Examples  (3)Summary of the most common use cases

Get the rules associated with a tree with three leaves:

Out[2]=2

Get the rules for a tree with several levels:

Out[1]=1

Get the rules for a tree with named edges:

Out[1]=1

Scope  (4)Survey of the scope of standard use cases

Use TreeRules on a leaf with no child:

Out[2]=2

Use TreeRules on an inner node with no children:

Out[1]=1
Out[2]=2

Use TreeRules on a tree with a list of children:

Out[1]=1

Use TreeRules on a tree with an association of children:

Out[1]=1

Properties & Relations  (2)Properties of the function, and connections to other functions

RulesTree constructs a tree associated with the given rules:

Out[3]=3

Use TreeRules on the result to recover the original rules:

Out[4]=4

TreeRules[tree] is generally equivalent to TreeFold[{Rule,Identity},tree]:

Out[1]=1
Out[2]=2

Possible Issues  (1)Common pitfalls and unexpected behavior

TreeRules[Tree[data,None]] generally gives data:

Out[1]=1

However, TreeRules[Tree[expr{},None]] gives (expr{})None instead:

Out[2]=2
Wolfram Research (2021), TreeRules, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeRules.html (updated 2022).
Wolfram Research (2021), TreeRules, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeRules.html (updated 2022).

Text

Wolfram Research (2021), TreeRules, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeRules.html (updated 2022).

Wolfram Research (2021), TreeRules, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeRules.html (updated 2022).

CMS

Wolfram Language. 2021. "TreeRules." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/TreeRules.html.

Wolfram Language. 2021. "TreeRules." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/TreeRules.html.

APA

Wolfram Language. (2021). TreeRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeRules.html

Wolfram Language. (2021). TreeRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeRules.html

BibTeX

@misc{reference.wolfram_2025_treerules, author="Wolfram Research", title="{TreeRules}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeRules.html}", note=[Accessed: 19-June-2025 ]}

@misc{reference.wolfram_2025_treerules, author="Wolfram Research", title="{TreeRules}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeRules.html}", note=[Accessed: 19-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_treerules, organization={Wolfram Research}, title={TreeRules}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeRules.html}, note=[Accessed: 19-June-2025 ]}

@online{reference.wolfram_2025_treerules, organization={Wolfram Research}, title={TreeRules}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeRules.html}, note=[Accessed: 19-June-2025 ]}