Existence of cube terms in finite finitely generated clones

We study the problem of whether a given finite clone generated by finitely many operations contains a cube term and give both structural and algorithmic results. We show that if such a clone has a cube term then it has a cube term of dimension at most $N$, where the number $N$ depends on the arities of the generators of the clone and the size of the basic set. For idempotent clones we give a tight bound on $N$ that matches an earlier result of K. Kearnes and A. Szendrei. On the algorithmic side, we show that deciding the existence of cube terms is in P for idempotent clones and in EXPTIME in general. Since a clone contains a $k$-ary near unanimity operation if and only if it contains a cube term and a chain of Jonsson terms, our results can also be also used to decide whether a given finite algebra has a near unanimity operation.