A quine is a program that outputs its own source code without taking in any input. An example would be this (taken from here)
public class Quine {
public static void main(String[] args) {
char quote = 34;
String[] code = {
"public class Quine {",
" public static void main(String[] args) {",
" char quote = 34;",
" String[] code = {",
" };",
" for(int i=0; i<4; i++){",
" System.out.println(code[i]);",
" }",
" for(int i=0; i<code.length; i++){",
" System.out.println(quote + code[i] + quote + ',');",
" }",
" for(int i=4; i<code.length; i++){",
" System.out.println(code[i]);",
" }",
" }",
"}",
};
for(int i=0; i<4; i++){
System.out.println(code[i]);
}
for(int i=0; i<code.length; i++){
System.out.println(quote + code[i] + quote + ',');
}
for(int i=4; i<code.length; i++){
System.out.println(code[i]);
}
}
}
Running this produces exactly the same output as the source code. I've heard that the fixed point theorem applies, meaning that any turing-complete programming language will contain a quine. However, the more I thought about this the less it made sense.
The rules for the fixed point theorem in mathematics are that it must be continuous, bounded surface with no holes or 'cutting and gluing'. This seems to make no sense in terms of programming languages.
The first rule can be broken by the nature of characters as not continuous, for example there is no inbetween 'a' and 'b' in terms of ASCII encoding.
The second rule can be broken by stating that there can be infinitely many programs all equally valid, for example you could have System.out.println("");
, System.out.println("a");
, System.out.println("aa");
...System.out.println("aaaaaaaaaaaaaaaaaaaaa");
.
The third rule can be broken by saying that not all programs are valid, for example abstract System out.println(23");"
is not valid, however the build output could be used as the output, ie
Main.java:2: error: class, interface, or enum expected
public static void main(String[] args) {abstract System out.println(23");"
^
Main.java:2: error: ')' expected
public static void main(String[] args) {abstract System out.println(23");"
^
2 errors
If all but one of the rules are broken, then why does the fixed point theorem still apply?