Why Does the Fixed Point Theorem Apply to Quines? 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&lt;4; i++){",
"            System.out.println(code[i]);",
"        }",
"        for(int i=0; i&lt;code.length; i++){",
"            System.out.println(quote + code[i] + quote + ',');",
"        }",
"        for(int i=4; i&lt;code.length; i++){",
"            System.out.println(code[i]);",
"        }",
"    }",
"}",
        };
        for(int i=0; i&lt;4; i++){
            System.out.println(code[i]);
        }
        for(int i=0; i&lt;code.length; i++){
            System.out.println(quote + code[i] + quote + ',');
        }
        for(int i=4; i&lt;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?
As Discrete Lizard points out, there exist more than one "fixed point theorem." The one you're mentioning makes sense in terms of topology and geometry, but you're right to realize that it does not apply to programming languages.

It turns out, though, that a more general notion of continuity, called Scott Continuity, can give you something that is applicable, namely the Kleene fixed-point theorem:


  Any Scott-continuous function over a directed-complete partial order has a least fixed point.


An earlier, and easier to understand, version of this is given by Knaster-Tarski:


  Any monotone function over a complete lattice has a fixed-point. In fact, the fixed points of such a function form a complete lattice.