TITLE: What are retracts of polynomial rings?
QUESTION [27 upvotes]: Is there a known example of a ring endomorphism $f: \mathbb{Z}[x_1, \ldots, x_n] \to \mathbb{Z}[x_1, \ldots, x_n]$ such that $f \circ f = f$ but whose image is not isomorphic to a polynomial ring? 
My own interest in this has to do with better understanding the (categorical) Cauchy completions of Lawvere theories for some familiar types of algebraic objects; here we are dealing with the Lawvere theory of commutative rings. But apparently this type of problem is of interest to algebraists in the context of hard problems like the Jacobian conjecture and the cancellation problem, so there is a certain body of work out there already on related material. 
From the literature I've scanned so far (articles by Costa, Shpilrain, Picavet, Gupta, and others), a lot of attention is paid to retracts of polynomial algebras over fields, but I'm having quite a hard time finding a clear statement for the case of polynomial algebras over $\mathbb{Z}$. One tantalizing lead was a statement by Picavet here: "We were motivated by an unsolved conjecture: a projective algebra of finite type over a field $A$ is a polynomial ring. An example by Costa shows that the statement is false if $A$ is not a field." I couldn't find a statement by Costa which treated every non-field $A$ (including $\mathbb{Z}$ in particular); I suspect Picavet meant that there exist non-fields $A$ for which the statement is false. An interesting example of such $A$ can be extracted from Gupta's later negative solution to the cancellation problem, as mentioned by Jeremy Rickard here at the MO discussion Is a retract of a free object free?. (Actually, Gupta's constructions more significantly show that the statement is false for any field of positive characteristic, but this work can be used to derive some non-field examples as well.) 
Akhil Mathew asked essentially the same question at Math.SE here, and got pointers to literature from Mariano Suárez-Alvarez, but I'm hoping to get something more definitive now.

REPLY [13 votes]: Existence of such an example follows from the same result of Asanuma that is crucial for Gupta's work, see the article 
Teruo Asanuma, "Polynomial fibre rings of algebras over noetherian rings", Inventiones mathematicae 87 (1987), 101–127 (DOI link). 
It follows from Corollary 5.3 of that article that if
$$
A=\mathbb{Z}[x,y,z]/(-x^{p^e}+y+y^{sp}+pz),
 $$
where $p$ is a prime number and $e,s$ are positive integers such that $p^e\not\mid sp$, $sp\not\mid p^e$, then $A$ is not isomorphic to a polynomial ring, but $B=A[t]$ is isomorphic to a polynomial ring in three variables. Of course, $A$ is a retract of $B$ via the evaluation at $t=0$.
EDIT:
Moreover, consider 
 $$
A_n:=\mathbb{Z}[x,y,z,x_1,\ldots,x_n]/(-x^{p^e}+y+y^{sp}+px_1\cdots x_nz),
 $$
then the proof of the same Corollary 5.3 (in the case $R=\mathbb{Z}[x_1,\ldots,x_n]$) can be adapted to show that $A_n[t]$ is isomorphic to the polynomial ring in $n+3$ variables, but $A_n$ is not isomorphic to the polynomial ring in $n+2$ variables.