My question is about closing sets under operations. First, I need a definition:

**Definition:** Let $A$ be a set and take a function $f : A^n \rightarrow A$ for $n \in \mathbb{N}_{\geq 0}$. For a set $S$, we define the closure of $S$ under $f$, $c_f (S)$, inductively as follows: define $S_0 = S$. For $i \in \mathbb{N}_{\geq 0}$, with $S_i$ defined, set 
$$S_{i+1} = S_i \cup \{ f ( a_1, ..., a_n ) : a_1, ..., a_n \in S_i \}$$
Define $c_f (S) = \bigcup_{i = 0}^{\infty} S_i$.

My question is this: let $A$ be a set. Take $n_1, ..., n_k \in \mathbb{N}_{\geq 0}$ and $f_i : A^{n_i} \rightarrow A$ for $1 \leq i \leq k$. Consider the set $S$. When is $c_{f_k} \circ c_{f_{k-1}} \circ \cdots \circ c_{f_1} (S)$ closed under $f_i$ for each $1 \leq i \leq k$? _I am asking for interesting properties one can put on $f_i$ to make this true._

This is equivalent to a seemingly simpler question: let $A$ be a set and take functions $f : A^n \rightarrow A$ and $g: A^m \rightarrow A$. Take a set $S$ which is closed under $g$. _What are some interesting properties we can put on $f$ and $g$ so that $c_f (S)$ closed under $g$?_

Here are some very familiar examples:

**Example:** Let $G$ be a group. For a subset $S \subset G$, we can form a subgroup of $G$ by adding $e$ (closing under the $0$-ary function that corresponds to the group identity), closing under inverses, and then closing under the group multiplication. The resulting set is then closed under all of these operations.

**Example:** Let $R$ be a ring. For a subset $S \subset R$, we can form a subring of $R$ by adding $0$ and $1$, (closing under the $0$-ary functions corresponding to $0$ and $1$), closing under products, and then closing under sums.

**Example:** Take a set $A$ and operations $\sigma : A^2 \rightarrow A$ and $\mu : A^2 \rightarrow A$. Suppose that $\mu(a, \sigma(b, c)) = \sigma(\mu(a, b) , \mu(a, c))$ and $\mu(\sigma(a, b), c) = \sigma(\mu(a, c), \mu(b, c))$ for each $a, b, c \in A$. Then, if $S \in A$ is closed under $\mu$, then $c_{\sigma}(S)$ is closed under $\mu$.