A quine is a computer program which takes no input and produces a copy of its own source code as its only output. There are many trivial quines in Mathematica:
In[1]:= "Hello world"
Out[1]= "Hello world"
In[2]:= 3.14
Out[2]= 3.14
In[3]:= f[x]
Out[3]= f[x]
where f and x are undefined symbols; and some more
In[4]:= Hold[N[\[Pi]]]
Out[4]= Hold[N[\[Pi]]]
These are all trivial. I was thinking that perhaps a more interesting challenge for Mathematica was a multiquine. This is a program A that outputs another program B, distinct from A, such that when B is executed, the output is A. Multiple levels of depth are also allowed: Thus one might have a program that when executed outputs a distinct program that when executed outputs another program distinct from the first two ... that when executed outputs the original program.
There are also multiquines that output a distinct program in a different language, such that when this program is executed, the output is the original program.
QUESTION (Though more of a challenge): Can you come up with a multiquine for Mathematica?




Print[ToString[#0][]] & [], the output is"Print[ToString[#0][]] & "[], which doesn't equal the original expression. Then if you execute"Print[ToString[#0][]] & "[], you get"Print[ToString[#0][]] & "[]. Therefore the program"Print[ToString[#0][]] & "[]is a quine. However,Print[ToString[#0][]] & []is neither a quine nor a multiquine. – a06e May 28 '12 at 18:05"anything"[]as input equals the output, which is NOT"anything"[]but its displayed form (quotes omitted). So what the quine must equal? TheInputFormor theOutputForm? – István Zachar May 28 '12 at 18:21InputFormshould equal the original quine source code (or the output of the output ... for a multiquine), but I am open to suggestions. As far as I know a established definition of what a quine is in the particular case of Mathematica doesn't exist, and as your comment exemplifies, there are subtleties that distinguish Mathematica from other languages. Part of the knowledge I expect to gain from this question is a definition of Mathematica quine that makes the problem non-trivial and interesting. – a06e May 28 '12 at 18:50