# Program ordinals and omega squared

## Python 2, 67 63 65 bytes

x=""
while 1:x="x=%r\nwhile 1:x='print%%r;'%%x;exec x;"%x;print x


Try it online!

Use the same strategy as @UnrelatedString's answer, be sure to check out and upvote his answer! Repeatedly print out programs with ordinal $$\0, \omega, \omega2, \omega3,\ldots \$$. The programs are separated by the string ";\n" (a semi-colon and a new line).

68 bytes to separate programs by a blank line.

### Explanation

A program with ordinal $$\n+1\$$ is created by adding a print statement around an $$\n\$$-ordinal program:

print <escaped string of ordinal-n program>


A program with ordinal $$\\omega(n+1)\$$ is created by repeatedly printing out programs with ordinal $$\\omega n, \omega n+1,\omega n+2,\ldots\$$

x = <string of omega*n program>
while 1:
x = 'print %r' % x
exec x


Note the use of %r, which escapes the given string x. This way, we don't have to worry about quote and new line characters.

Finally, a program with ordinal $$\\omega^2\$$ is created by repeatedly printing out programs with ordinal $$\0, \omega, \omega 2,\omega 3,\ldots\$$:

# string of program to go from omega*n to omega*(n+1)
s = "x=%r\nwhile 1:x='print%%r'%%x;exec x"
x = ""
while 1:
# create the omega*(n+1) program from omega*n
x = s % x
# print it out
print x


## Python 3, 85 bytes

s='def l(f,x):\n print(x+"\\n")\n l(f,"%s%r)"%(f,x))'
exec(s)
l(s+"\nl('print(',",'')


Try it online!

I... think this might be valid? This should print a sequence of programs, separated by blank lines, with ordinals ω, ω·2, ω·3, ω·4, ..., but the reasoning by which I arrived at those ordinals was pretty shaky and I've already forgotten what it even was, so I'd appreciate being shown that I'm completely wrong. The general idea of it is that one program with ordinal ω+ω = ω2 is one which prints a program with ordinal ω, then prints a program that prints that program (so that it has ordinal ω + 1), then prints a program that prints that, and so on... and the part I don't feel too solid about is doing that with the program with ordinal ω·2 to get to ω·3, and iterating to get ω2.