<p>In programming say you have a boolean tree like this:</p>

<pre><code>a(
  b(c(), d(), 
    e(h(), i(j(), k(l()))), 
    f(m(), n(p(), q()), o()),
    g()
  ),
  r(),
  s(t(), u(), v(w(), x(y(z()))))
)
</code></pre>

<p>Each function is different, they all can accept arbitrary number of arguments, and they return $\rightarrow \{1,0\}$ a boolean value.</p>

<p>Then there is an algorithm that gets all the leaf nodes, so mathematically we can say:</p>

<p>$$
l = N \rightarrow L'
$$</p>

<p>where $l$ is a "leaf" function mapping all the nodes $N$ to a subset of nodes $L \subset N$.</p>

<p>Finally, there is a "calculate the final boolean value for the tree" function that starts at the leaf nodes and works its way up to the top.</p>

<p>What I'm wondering is how to define that last part mathematically.</p>

<ol>
<li>How to define the tree that can take into account arbitrary tree structures with arbitrary number of children at each node.</li>
<li>That iterates through the nodes starting from the leaf nodes, then to the parent nodes, then to the parents, until it gets back to the top.</li>
</ol>

<p>This is as far as I've gotten but don't think it's right.</p>

<p>$$
t = n + (t_0,\dotsc,t_i)?
$$</p>

<p>where $t$ is a tree and $n$ is a node, and $?$ means it's optional. Trying to capture the recursive nature of it.</p>

<p>Procedure:</p>

<p>$$
Start\ at\ leaf\ nodes\ l : N \rightarrow L
$$
$$
Calculate\ value\ v \in \{0,1\}
$$
$$
  Collect\ all\ the\ children\ to\ sum\ their\ value\ V
$$
$$
Repeat\ for\ the\ next\ parent
$$
$$
Finish\ when\ at\ top.
$$</p>

<p>I am new to algorithms and writing them mathematically, so this is probably a beginner question.</p>

CC BY-SA 3.0
2018-04-03T07:25:14.473Z
Why do you want to start at the leaf nodes, rather than the root? If you start at the root, the corresponding recursive algorithm is easy to write.
NietzscheanAI
CC BY-SA 3.0
2018-04-03T07:28:26.017Z
It looks to me like your concept of 'leaf' is not exactly as desired: the mapping l is probably intended to return the *child* nodes of a given node, which are not necessarily leaves of the entire tree.
NietzscheanAI
<ds.algorithms><co.combinatorics><notation>
How to represent boolean tree + algorithm as a mathematical formula
Lance Pollard
# How to represent boolean tree + algorithm as a mathematical formula

(Asked by: username_0 on 2018-03-29)

In programming say you have a boolean tree like this:
a(
  b(c(), d(), 
    e(h(), i(j(), k(l()))), 
    f(m(), n(p(), q()), o()),
    g()
  ),
  r(),
  s(t(), u(), v(w(), x(y(z()))))
)

Each function is different, they all can accept arbitrary number of arguments, and they return $\rightarrow \{1,0\}$ a boolean value.
Then there is an algorithm that gets all the leaf nodes, so mathematically we can say:
$$
l = N \rightarrow L'
$$
where $l$ is a "leaf" function mapping all the nodes $N$ to a subset of nodes $L \subset N$.
Finally, there is a "calculate the final boolean value for the tree" function that starts at the leaf nodes and works its way up to the top.
What I'm wondering is how to define that last part mathematically.

How to define the tree that can take into account arbitrary tree structures with arbitrary number of children at each node.
That iterates through the nodes starting from the leaf nodes, then to the parent nodes, then to the parents, until it gets back to the top.

This is as far as I've gotten but don't think it's right.
$$
t = n + (t_0,\dotsc,t_i)?
$$
where $t$ is a tree and $n$ is a node, and $?$ means it's optional. Trying to capture the recursive nature of it.
Procedure:
$$
Start\ at\ leaf\ nodes\ l : N \rightarrow L
$$
$$
Calculate\ value\ v \in \{0,1\}
$$
$$
  Collect\ all\ the\ children\ to\ sum\ their\ value\ V
$$
$$
Repeat\ for\ the\ next\ parent
$$
$$
Finish\ when\ at\ top.
$$
I am new to algorithms and writing them mathematically, so this is probably a beginner question.

**Tags:** ds.algorithms, co.combinatorics, notation

> **Comments:**
> **username_1**: Why do you want to start at the leaf nodes, rather than the root? If you start at the root, the corresponding recursive algorithm is easy to write.  
> **username_1**: It looks to me like your concept of 'leaf' is not exactly as desired: the mapping l is probably intended to return the *child* nodes of a given node, which are not necessarily leaves of the entire tree.  

---

## 0 answers

