I found the following result and decided to try proving it.
Let $A$ be a set and $n \geq 2$ a natural number. Show that all $n$-ary operations (i.e. functions defined on $A^n$ with values in $A$, or elements of $A^{A^n}$) can be expressed by finite compositions of binary operations.
Let's first analyze a simpler case where $A$ has two elements and $n=2$. WLOG, assume $A=2=\{0, 1\}$. This can be interpreted as the fact that all logical operators can be expressed in terms of negation and conjunction. I will show my thought process in this context.
Assume there is some logical operator f, for which we write the truth table
\begin{array} {|r|r|}\hline x_1 & x_2 & f \\ \hline 0 & 0 & a \\ \hline 0 & 1 & b \\ \hline 1 & 0 & c \\ \hline 1 & 1 & d \\ \hline \end{array}
where $a, b, c, d$ are elements of $A$.
My first approach was to think of this formula $$( (\neg x_1 \land \neg x_2) \to a) \land ( (\neg x_1 \land x_2) \to b) \land ( (x_1 \land \neg x_2) \to c) \land ( (x_1 \land x_2) \to d)$$
where $\land$ is the logical and, $\neg$ is the logical negation and $\to$ is the logical implication. If either $a, b, c$ or $d$ is $0$ substitute it for $x_1 \land \neg x_2$ and $x_1 \lor \neg x_2$ if they are $1$.
Basically, I form $4$ units that have $1$ in the output except one place where there is $a, b, c$ or $d$. Then we unify them via conjunction, because $1 \land a \iff a$.
We could also define units that have $0$ in the output except one place which is some value defined by $f$ and then disjunct them.
We can interpret the logical operators as functions, like $a \land b$ is just $\land(a, b)$.
Therefore $f(x_1, x_2)$ is just $$ (\neg x_1 \land \neg x_2 \land a) \lor (\neg x_1 \land x_2 \land b) \lor (x_1 \land \neg x_2 \land c) \lor (x_1 \land x_2 \land d)$$ or $$\lor(\lor(\lor( \land( \land(\neg(x_1), \neg(x_2) ), a) , \land( \land(\neg(x_1), x_2), ) b), \land( \land(x_1, \neg(x_2)), c) ), \land( \land(x_1, x_2), d) )$$
For the sake of simplicity, I will write $a \lor b$ instead of $\lor(a, b)$ and $\bigvee_{b \in B}(b)$ mean the disjunction of all the elements in $B$. Analogously, $\bigwedge_{b \in B}(b)$.
I will also introduce a new function, namely $\leftrightarrow$, where $\leftrightarrow(x, y)$ or $x \leftrightarrow y$ is $1$ if and only if $x=y$, otherwise $0$.
We can rewrite $f(x_1, x_2)$ as $$( (0 \leftrightarrow x_1) \land (0 \leftrightarrow x_2) \land a) \lor ((0 \leftrightarrow x_1) \land (1 \leftrightarrow x_2) \land b) \lor ((1 \leftrightarrow x_1) \land (0 \leftrightarrow x_2) \land c) \lor ((1 \leftrightarrow x_1) \land (1 \leftrightarrow x_2) \land d)$$
or condensed
$$ \bigvee_{(a_1, a_2) \in A^2}( \bigwedge_{i=1}^n(a_i \leftrightarrow x_i) \land f(a_1, a_2) ) $$.
However, this generalizes nicely even when $n$ is bigger than $2$. We can check by induction that this formula works for any natural $n$.
Now we want to write all of $x \land y$ and $\neg x$ and $x \lor y$ and $x \leftrightarrow y$ in terms of one function. Let's call assume that such function exists and call it $g$.
Now $g(0, 0)$ has to be $1$. If it were $0$, we couldn't have composed $g$ with itself to get some function such that it maps $(0, 0)$ to $1$. Analogously, $g(1, 1)=0$. Now $g(0, 1)$ has to be equal to $g(1, 0)$, otherwise $g(x, y)$ would be equivalent to $\neg x$ or $\neg y$, a one variable function, which can't get us anywhere.
And indeed, the two functions,
$g_1(x, y)=0$ when $(x, y)=1$ and $1$ otherwise
and
$g_2(x, y)=1$ when $(x, y)=0$ and $0$ otherwise
can be used to create $\lor, \land$ and $\leftrightarrow$.
Assume $g(x, y) = \neg (x \land y)$. Then $x \land y = g(g(x, x), g(y, y))$, $\neg(x) = g(x, x)$, $\lor(x, y) = \neg (x \land y)$ and $x \leftrightarrow y = (x \land y) \lor (\neg x \land \neg y)$, so everything works, for $A=\{0, 1 \}$
Now, assume $A$ is some finite set. Again, WLOG, assume $A = \{ 0, 1, 2, ..., m-1\}$.
Now let's define the following functions:
$\bullet$ $x \leftrightarrow y = \leftrightarrow(x, y)$ is $1$ only when $x=y$ and $0$ othwerwise.
$\bullet$ $x \land y = \land(x, y)$ has to respect the following rules $0 \land a = 0$ and $1 \land a = a$ and values such as $2 \land 2$ can be fixed arbitrarily.
$\bullet$ $x \lor y = \lor(x, y)$ has to respect the following rules $0 \lor a = a$ and $1 \lor a = 1$ and values such as $2 \lor 2$ can be fixed arbitrarily.
By the same argument, an arbitrary function $f$ defined on $A^n$ taking values in $A$ can be expressed as
$$f(x_1, x_2, ..., x_n) = \bigvee_{(a_1, a_2, ..., a_n) \in A^n}(\bigwedge_{i=1}^n(a_i \leftrightarrow x_i) \land f(a_1, a_2, ..., a_n))$$
Now my intuition says that there is some binary function $g$ such that $\land, \lor$ and $\leftrightarrow$ can all be expressed in terms of $g$, however I did not seem to find an algorithm to restrict those functions, like I could when $A$ had $2$ elements.
Regarding the work I have done above I have a few questions:
$\bullet$ The first question:
How can I phrase my original question "Let $A$ be a set and $n \geq 2$ a natural number. Show that all $n$-ary operations can be expressed by finite compositions of binary operations." in mathematical terms. Like I just proved for the case that $A$ is finite that any $n$-ary function can be written in terms of finite compositions, but how do I express that in rigurous mathematical terms (I think the words I am looking for are first order logic in set theory).
Firstly, let's define $\text{function}(f, A, B) \iff ( f \subseteq A \times B \land \forall x \in A \colon \exists ! y \in B \colon (x, y) \in f )$.
Now, how do i say "any $n$-ary function can be written in terms of finite compositions"?I think i should write something like $\forall f (\text{function}(f, A^n, A) \implies \exists ...)$ I don't know what to write after the existential quantifier.
$\bullet$ The second question:
Consider $A=\{ 0, 1, ..., m-1 \}$ As I have stated in my proof above, how can I find all the functions $g$ such that $\lor, \land$ and $\leftrightarrow$ can be written only in terms of $g$. I haven't found any good algorithm so the only option I think it is left is that I have to try out almost all functions from $A^2$ to $A$.
$\bullet$ The third question:
The formula
$$f(x_1, x_2, ..., x_n) = \bigvee_{(a_1, a_2, ..., a_n) \in A^n}(\bigwedge_{i=1}^n(a_i \leftrightarrow x_i) \land f(a_1, a_2, ..., a_n)) $$
that I found looks extremly closely related to Lagrange interpolation polynomials. Is there any connection/intuition between them? (I think the answer is yes, I can answer myself like 70%, but I just wanna share the beauty of math and the connection of multiple areas of mathematics).
$\bullet$ The fourth question:
How can I go about proving this in the case that $A$ is not finite. The same method does not work since I get an inifnite "composition" of functions. I am also wondering if $1$ binary function would be sufficient to express all the $n$-ary functions or we would need more binary functions. I assume I need to use the fact that if $A$ is an infinite cardinal then $A^n=A$. How can I prove my problem when $A$ is infinite.
$\bullet$ The fifth question:
Is this the reason why in abstract algebra we don't talk about ternary or $n$-ary operations on sets? Because we can reduce them to binary operations?
$\bullet$ The last question:
Can I draw some conclusion from the problem if instead of letting $n$ be a natural number we let $n$ be any ordinal? I do not have any ideea on how to even approach such a problem, since I didn't study $\infty$-ary operations before.
I am not necessarily looking for a proof for what I have written, but for the answers with some resources to find the proofs to my questions, although proofs written here would be gladly appreciated and would save me a lot of time.
Thank you!
Edit: I have looked this concept up and found out it is called currying, but I still didn't find any answer to my questions.