#! /usr/local/bin/perl

use strict;
use warnings;
use Tie::RefHash;

sub compare {
    my $a = shift;
    my $b = shift;
    foreach my $sb ( @$b ) {  # First compare A with every subtree of B
	return -1 if compare($a,$sb)!=1;
    }
    foreach my $sa ( @$a ) {  # Then compare B with every subtree of A
	return 1 if compare($sa,$b)!=-1;
    }
    # Finally, do a lexicographic comparison of subtree lists
    return -1 if scalar(@$a) < scalar(@$b);
    return 1 if scalar(@$a) > scalar(@$b);
    for ( my $i=0 ; $i<scalar(@$a) ; $i++ ) {
	my $cmp = compare($$a[$i],$$b[$i]);
	return $cmp if $cmp;
    }
    return 0;
}

sub deep_copy {
    my $t = shift;
    my $tc = [];
    foreach my $st ( @$t ) {
	push (@$tc, deep_copy($st));
    }
    return $tc;
}

sub deep_reverse {
    my $t = shift;
    my $tc = [];
    foreach my $st ( @$t ) {
	unshift (@$tc, deep_reverse($st));
    }
    return $tc;
}

sub shallow_reverse {
    my $t = shift;
    my $tc = [];
    foreach my $st ( @$t ) {
	unshift (@$tc, deep_copy($st));
    }
    return $tc;
}

my @alltrees = ();

sub compute_alltrees {
    my $n = shift;
    $alltrees[$n] = [];
    my @l;
    my $subgen;
    $subgen = sub {
	my $k = shift;
	if ( $k == 1 ) {
	    push @{$alltrees[$n]}, deep_copy(\@l);
	}
	for ( my $i=1 ; $i<$k ; $i++ ) {
	    foreach my $st ( @{$alltrees[$i]} ) {
		push @l, $st;
		&{$subgen}($k-$i);
		pop @l;
	    }
	}
    };
    @l = ();
    &{$subgen}($n);
}

sub display {
    my $name = shift;
    my $t0 = shift;
    my %height;
    tie %height, 'Tie::RefHash';
    my $compute_height;
    $compute_height = sub {
	my $t = shift;
	my $b = shift;
	$height{$t} = $b;
	foreach my $st ( @$t ) {
	    &{$compute_height}($st,$b*0.866025);
	}
    };
    &{$compute_height}($t0,0.7);
    my %width;
    tie %width, 'Tie::RefHash';
    my $compute_width;
    $compute_width = sub {
	my $t = shift;
	my $w = 0.;
	$w += (scalar(@$t)-1)*$height{$t} unless scalar(@$t) < 1;
	foreach my $st ( @$t ) {
	    $w += &{$compute_width}($st);
	}
	$width{$t} = $w;
	return $w;
    };
    &{$compute_width}($t0);
    my (%x, %y, %nm);
    tie %x, 'Tie::RefHash';
    tie %y, 'Tie::RefHash';
    tie %nm, 'Tie::RefHash';
    my $cnt = 0;
    my $compute_pos;
    $compute_pos = sub {
	my $t = shift;
	my $bx = shift;
	my $by = shift;
	$x{$t} = $bx;
	$y{$t} = $by;
	$nm{$t} = sprintf("node%04d", $cnt++);
	my $ny = $by + $height{$t};
	my $nx = $bx - $width{$t}/2;
	my $vx = 0.;
	$vx = $height{$t};
	for (my $i=0 ; $i<scalar(@$t) ; $i++) {
	    my $st = $$t[$i];
	    &{$compute_pos}($st,$nx+$width{$st}/2,$ny);
	    $nx += $vx+$width{$st};
	}
    };
    &{$compute_pos}($t0,0.,0.);
    my $display_nodes;
    $display_nodes = sub {
	my $t = shift;
	printf "\\node (%s) at (%f,%f) [ordnode] {};\n", $nm{$t}, $x{$t}, $y{$t};
	foreach my $st ( @$t ) {
	    &{$display_nodes}($st);
	}
    };
    my $display_lines;
    $display_lines = sub {
	my $t = shift;
	foreach my $st ( @$t ) {
	    printf "\\draw (%s)--(%s) [ordline];\n", $nm{$t}, $nm{$st};
	    &{$display_lines}($st);
	}
    };
    print "\\begin{tikzpicture}\n";
    if ( defined($name) ) {
	printf "\\node at (0,%f) [ordtitle] {\\footnotesize\\strut\\smash{\$%s\$}};\n", -(12/72)*2.54, $name;
    } else {
	printf "\\node at (0,%f) [ordtitle] {\\footnotesize\\strut};\n", -(12/72)*2.54, $name;
    }
    &{$display_nodes}($t0);
    &{$display_lines}($t0);
    print "\\end{tikzpicture}\n";
}

my @ordinals = (
    { name => "0",
      tree => [] },
    { name => "1",
      tree => [[]] },
    { name => "2",
      tree => [[[]]] },
    { name => "3",
      tree => [[[[]]]] },
    { name => "4",
      tree => [[[[[]]]]] },
    { name => "5",
      tree => [[[[[[]]]]]] },
    { name => "6",
      tree => [[[[[[[]]]]]]] },
    { name => "\\omega",
      tree => [[],[]] },
    { name => "\\omega + 1",
      tree => [[[],[]]] },
    { name => "\\omega + 2",
      tree => [[[[],[]]]] },
    { name => "\\omega + 3",
      tree => [[[[[],[]]]]] },
    { name => "\\omega + 4",
      tree => [[[[[[],[]]]]]] },
    { name => "\\omega 2",
      tree => [[],[[]]] },
    { name => "\\omega 2 + 1",
      tree => [[[],[[]]]] },
    { name => "\\omega 2 + 2",
      tree => [[[[],[[]]]]] },
    { name => "\\omega 2 + 3",
      tree => [[[[[],[[]]]]]] },
    { name => "\\omega 3",
      tree => [[],[[[]]]] },
    { name => "\\omega 3 + 1",
      tree => [[[],[[[]]]]] },
    { name => "\\omega 3 + 2",
      tree => [[[[],[[[]]]]]] },
    { name => "\\omega 4",
      tree => [[],[[[[]]]]] },
    { name => "\\omega 4 + 1",
      tree => [[[],[[[[]]]]]] },
    { name => "\\omega 5",
      tree => [[],[[[[[]]]]]] },
    { name => "\\omega^2",
      tree => [[],[[],[]]] },
    { name => "\\omega^2 + 1",
      tree => [[[],[[],[]]]] },
    { name => "\\omega^2 + 2",
      tree => [[[[],[[],[]]]]] },
    { name => "\\omega^2 + \\omega",
      tree => [[],[[[],[]]]] },
    { name => "\\omega^2 + \\omega + 1",
      tree => [[[],[[[],[]]]]] },
    { name => "\\omega^2 + \\omega 2",
      tree => [[],[[[[],[]]]]] },
    { name => "\\omega^2 2",
      tree => [[],[[],[[]]]] },
    { name => "\\omega^2 2 + 1",
      tree => [[[],[[],[[]]]]] },
    { name => "\\omega^2 2 + \\omega",
      tree => [[],[[[],[[]]]]] },
    { name => "\\omega^2 3",
      tree => [[],[[],[[[]]]]] },
    { name => "\\omega^3",
      tree => [[],[[],[[],[]]]] },
    { name => "\\omega^3 + 1",
      tree => [[[],[[],[[],[]]]]] },
    { name => "\\omega^3 + \\omega",
      tree => [[],[[[],[[],[]]]]] },
    { name => "\\omega^3 + \\omega^2",
      tree => [[],[[],[[[],[]]]]] },
    { name => "\\omega^3 2",
      tree => [[],[[],[[],[[]]]]] },
    { name => "\\omega^4",
      tree => [[],[[],[[],[[],[]]]]] },
    { name => "\\omega^\\omega",
      tree => [[[]],[]] },
    { name => "\\omega^\\omega + 1",
      tree => [[[[]],[]]] },
    { name => "\\omega^\\omega + 2",
      tree => [[[[[]],[]]]] },
    { name => "\\omega^\\omega + 3",
      tree => [[[[[[]],[]]]]] },
    { name => "\\omega^\\omega + \\omega",
      tree => [[],[[[]],[]]] },
    { name => "\\omega^\\omega + \\omega + 1",
      tree => [[[],[[[]],[]]]] },
    { name => "\\omega^\\omega + \\omega 2",
      tree => [[],[[[[]],[]]]] },
    { name => "\\omega^\\omega + \\omega^2",
      tree => [[],[[],[[[]],[]]]] },
    { name => "\\omega^\\omega + \\omega^2 + \\omega",
      tree => [[],[[[],[[[]],[]]]]] },
    { name => "\\omega^\\omega + \\omega^2 2",
      tree => [[],[[],[[[[]],[]]]]] },
    { name => "\\omega^\\omega 2",
      tree => [[[]],[[]]] },
    { name => "\\omega^\\omega 2 + 1",
      tree => [[[[]],[[]]]] },
    { name => "\\omega^\\omega 2 + 2",
      tree => [[[[[]],[[]]]]] },
    { name => "\\omega^\\omega 2 + \\omega",
      tree => [[],[[[]],[[]]]] },
    { name => "\\omega^\\omega 2 + \\omega^2",
      tree => [[],[[],[[[]],[[]]]]] },
    { name => "\\omega^\\omega 3",
      tree => [[[]],[[[]]]] },
    { name => "\\omega^\\omega 3 + 1",
      tree => [[[[]],[[[]]]]] },
    { name => "\\omega^\\omega 4",
      tree => [[[]],[[[[]]]]] },
    { name => "\\omega^{\\omega + 1}",
      tree => [[[]],[[],[]]] },
    { name => "\\omega^{\\omega + 1} + 1",
      tree => [[[[]],[[],[]]]] },
    { name => "\\omega^{\\omega + 1} + \\omega",
      tree => [[],[[[]],[[],[]]]] },
    { name => "\\omega^{\\omega + 1} + \\omega^\\omega",
      tree => [[[]],[[[],[]]]] },
    { name => "\\omega^{\\omega + 1} + \\omega^\\omega 2",
      tree => [[[]],[[[[],[]]]]] },
    { name => "\\omega^{\\omega + 1} 2",
      tree => [[[]],[[],[[]]]] },
    { name => "\\omega^{\\omega + 1} 2 + \\omega^\\omega",
      tree => [[[]],[[[],[[]]]]] },
    { name => "\\omega^{\\omega + 2}",
      tree => [[[]],[[],[[],[]]]] },
    { name => "\\omega^{\\omega + 2} + \\omega^\\omega",
      tree => [[[]],[[[],[[],[]]]]] },
    { name => "\\omega^{\\omega + 2} + \\omega^{\\omega + 1}",
      tree => [[[]],[[],[[[],[]]]]] },
    { name => "\\omega^{\\omega + 2} 2",
      tree => [[[]],[[],[[],[[]]]]] },
    { name => "\\omega^{\\omega + 2} 2 + \\omega^\\omega",
      tree => [[[]],[[[],[[],[[]]]]]] },
    { name => "\\omega^{\\omega + 2} 2 + \\omega^{\\omega + 1}",
      tree => [[[]],[[],[[[],[[]]]]]] },
    { name => "\\omega^{\\omega 2}",
      tree => [[[]],[[[]],[]]] },
    { name => "\\omega^{\\omega 2} + \\omega",
      tree => [[],[[[]],[[[]],[]]]] },
    { name => "\\omega^{\\omega 2} + \\omega^\\omega",
      tree => [[[]],[[[[]],[]]]] },
    { name => "\\omega^{\\omega 2} + \\omega^{\\omega + 1}",
      tree => [[[]],[[],[[[]],[]]]] },
    { name => "\\omega^{\\omega 2} + \\omega^{\\omega + 1} + \\omega^\\omega",
      tree => [[[]],[[[],[[[]],[]]]]] },
    { name => "\\omega^{\\omega 2} + \\omega^{\\omega + 1} 2",
      tree => [[[]],[[],[[[[]],[]]]]] },
    { name => "\\omega^{\\omega 2} + \\omega^{\\omega + 2}",
      tree => [[[]],[[],[[],[[[]],[]]]]] },
    { name => "\\omega^{\\omega 2} 2",
      tree => [[[]],[[[]],[[]]]] },
    { name => "\\omega^{\\omega 2 + 1}",
      tree => [[[]],[[[]],[[],[]]]] },
    { name => "\\omega^{\\omega 3}",
      tree => [[[]],[[[]],[[[]],[]]]] },
    { name => "\\omega^{\\omega^2}",
      tree => [[[[]]],[]] },
    { name => "\\omega^{\\omega^2} + 1",
      tree => [[[[[]]],[]]] },
    { name => "\\omega^{\\omega^2} + 2",
      tree => [[[[[[]]],[]]]] },
    { name => "\\omega^{\\omega^2} + \\omega",
      tree => [[],[[[[]]],[]]] },
    { name => "\\omega^{\\omega^2} + \\omega^\\omega",
      tree => [[[]],[[[[]]],[]]] },
    { name => "\\omega^{\\omega^2} + \\omega^{\\omega + 1}",
      tree => [[[]],[[],[[[[]]],[]]]] },
    { name => "\\omega^{\\omega^2} + \\omega^{\\omega 2}",
      tree => [[[]],[[[]],[[[[]]],[]]]] },
    { name => "\\omega^{\\omega^2} 2",
      tree => [[[[]]],[[]]] },
    { name => "\\omega^{\\omega^2} 2 + 1",
      tree => [[[[[]]],[[]]]] },
    { name => "\\omega^{\\omega^2} 3",
      tree => [[[[]]],[[[]]]] },
    { name => "\\omega^{\\omega^2 + 1}",
      tree => [[[[]]],[[],[]]] },
    { name => "\\omega^{\\omega^2 + 1} 2",
      tree => [[[[]]],[[],[[]]]] },
    { name => "\\omega^{\\omega^2 + \\omega}",
      tree => [[[[]]],[[[]],[]]] },
    { name => "\\omega^{\\omega^2 2}",
      tree => [[[[]]],[[[[]]],[]]] },
    { name => "\\omega^{\\omega^3}",
      tree => [[[[[]]]],[]] },
    { name => "\\omega^{\\omega^3} + 1",
      tree => [[[[[[]]]],[]]] },
    { name => "\\omega^{\\omega^3} 2",
      tree => [[[[[]]]],[[]]] },
    { name => "\\omega^{\\omega^4}",
      tree => [[[[[[]]]]],[]] },
    { name => "\\omega^{\\omega^\\omega}",
      tree => [[[],[]],[]] },
    { name => "\\omega^{\\omega^\\omega} + 1",
      tree => [[[[],[]],[]]] },
    { name => "\\omega^{\\omega^\\omega} + 2",
      tree => [[[[[],[]],[]]]] },
    { name => "\\omega^{\\omega^\\omega} + \\omega",
      tree => [[],[[[],[]],[]]] },
    { name => "\\omega^{\\omega^\\omega} + \\omega^\\omega",
      tree => [[[]],[[[],[]],[]]] },
    { name => "\\omega^{\\omega^\\omega} 2",
      tree => [[[],[]],[[]]] },
    { name => "\\omega^{\\omega^\\omega} 2 + 1",
      tree => [[[[],[]],[[]]]] },
    { name => "\\omega^{\\omega^\\omega} 3",
      tree => [[[],[]],[[[]]]] },
    { name => "\\omega^{\\omega^\\omega + 1}",
      tree => [[[],[]],[[],[]]] },
    { name => "\\omega^{\\omega^\\omega + 1} 2",
      tree => [[[],[]],[[],[[]]]] },
    { name => "\\omega^{\\omega^\\omega + \\omega}",
      tree => [[[],[]],[[[]],[]]] },
    { name => "\\omega^{\\omega^\\omega 2}",
      tree => [[[],[]],[[[],[]],[]]] },
    { name => "\\omega^{\\omega^\\omega 3}",
      tree => [[[],[]],[[[],[]],[[[],[]],[]]]] },
    { name => "\\omega^{\\omega^{\\omega+1}}",
      tree => [[[[],[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega+1}} + 1",
      tree => [[[[[],[]]],[]]] },
    { name => "\\omega^{\\omega^{\\omega+1}} 2",
      tree => [[[[],[]]],[[]]] },
    { name => "\\omega^{\\omega^{\\omega+2}}",
      tree => [[[[[],[]]]],[]] },
    { name => "\\omega^{\\omega^{\\omega 2}}",
      tree => [[[],[[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega 2}} + 1",
      tree => [[[[],[[]]],[]]] },
    { name => "\\omega^{\\omega^{\\omega 2}} 2",
      tree => [[[],[[]]],[[]]] },
    { name => "\\omega^{\\omega^{\\omega 2}+1}",
      tree => [[[],[[]]],[[],[]]] },
    { name => "\\omega^{\\omega^{\\omega 2}+1} 2",
      tree => [[[],[[]]],[[],[[]]]] },
    { name => "\\omega^{\\omega^{\\omega 2}+\\omega}",
      tree => [[[],[[]]],[[[]],[]]] },
    { name => "\\omega^{\\omega^{\\omega 2} 2}",
      tree => [[[],[[]]],[[[],[[]]],[]]] },
    { name => "\\omega^{\\omega^{\\omega 2+1}}",
      tree => [[[[],[[]]]],[]] },
    { name => "\\omega^{\\omega^{\\omega 3}}",
      tree => [[[],[[[]]]],[]] },
    { name => "\\omega^{\\omega^{\\omega^2}}",
      tree => [[[],[[],[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega^2}+1}",
      tree => [[[],[[],[]]],[[],[]]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega}}",
      tree => [[[[]],[]],[]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega}} + 1",
      tree => [[[[[]],[]],[]]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega}} 2",
      tree => [[[[]],[]],[[]]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega} + 1}",
      tree => [[[[]],[]],[[],[]]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega} + \\omega}",
      tree => [[[[]],[]],[[[]],[]]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega} 2}",
      tree => [[[[]],[]],[[[[]],[]],[]]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega+1}}",
      tree => [[[[[]],[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega+\\omega}}",
      tree => [[[],[[[]],[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega^\\omega 2}}",
      tree => [[[[]],[[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega^{\\omega+1}}}",
      tree => [[[[]],[[],[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega^{\\omega 2}}}",
      tree => [[[[]],[[[]],[]]],[]] },
    { name => "\\omega^{\\omega^{\\omega^{\\omega^2}}}",
      tree => [[[[[]]],[]],[]] },
    { name => "\\omega^{\\omega^{\\omega^{\\omega^\\omega}}}",
      tree => [[[[],[]],[]],[]] },
    { name => "\\varepsilon_0 = \\phi_1(0) = \\psi(0)",
      tree => [[],[],[]] },
    { name => "\\varepsilon_0 + 1",
      tree => [[[],[],[]]] },
    { name => "\\varepsilon_0 + 2",
      tree => [[[[],[],[]]]] },
    { name => "\\varepsilon_0 + 3",
      tree => [[[[[],[],[]]]]] },
    { name => "\\varepsilon_0 + \\omega",
      tree => [[],[[],[],[]]] },
    { name => "\\varepsilon_0 + \\omega + 1",
      tree => [[[],[[],[],[]]]] },
    { name => "\\varepsilon_0 + \\omega 2",
      tree => [[],[[[],[],[]]]] },
    { name => "\\varepsilon_0 + \\omega 3",
      tree => [[],[[[[],[],[]]]]] },
    { name => "\\varepsilon_0 + \\omega^2",
      tree => [[],[[],[[],[],[]]]] },
    { name => "\\varepsilon_0 + \\omega^2 2",
      tree => [[],[[],[[[],[],[]]]]] },
    { name => "\\varepsilon_0 + \\omega^\\omega",
      tree => [[[]],[[],[],[]]] },
    { name => "\\varepsilon_0 + \\omega^{\\omega^\\omega}",
      tree => [[[],[]],[[],[],[]]] },
    { name => "\\varepsilon_0 + \\omega^{\\omega^{\\omega^\\omega}}",
      tree => [[[[]],[]],[[],[],[]]] },
    { name => "\\varepsilon_0 2",
      tree => [[[],[],[]],[]] },
    { name => "\\varepsilon_0 2 + 1",
      tree => [[[[],[],[]],[]]] },
    { name => "\\varepsilon_0 2 + \\omega",
      tree => [[],[[[],[],[]],[]]] },
    { name => "\\varepsilon_0 2 + \\omega^\\omega",
      tree => [[[]],[[[],[],[]],[]]] },
    { name => "\\varepsilon_0 3",
      tree => [[[],[],[]],[[]]] },
    { name => "\\varepsilon_0 \\omega = \\omega^{\\varepsilon_0+1}",
      tree => [[[],[],[]],[[],[]]] },
    { name => "\\varepsilon_0 (\\omega+1) = \\omega^{\\varepsilon_0+1} + \\varepsilon_0",
      tree => [[[],[],[]],[[[],[]]]] },
    { name => "\\varepsilon_0 \\omega 2 = \\omega^{\\varepsilon_0+1} 2",
      tree => [[[],[],[]],[[],[[]]]] },
    { name => "\\varepsilon_0 \\omega^\\omega = \\omega^{\\varepsilon_0+\\omega}",
      tree => [[[],[],[]],[[[]],[]]] },
    { name => "{\\varepsilon_0}^2 = \\omega^{\\varepsilon_0 2}",
      tree => [[[],[],[]],[[],[],[]]] },
    { name => "{\\varepsilon_0}^2 + \\omega",
      tree => [[],[[[],[],[]],[[],[],[]]]] },
    { name => "{\\varepsilon_0}^2 + \\varepsilon_0",
      tree => [[[],[],[]],[[[],[],[]]]] },
    { name => "{\\varepsilon_0}^2 + \\varepsilon_0 \\omega",
      tree => [[[],[],[]],[[],[[],[],[]]]] },
    { name => "{\\varepsilon_0}^2 2",
      tree => [[[],[],[]],[[[],[],[]],[]]] },
    { name => "{\\varepsilon_0}^2 \\omega = \\omega^{\\varepsilon_0 2+1}",
      tree => [[[],[],[]],[[[],[],[]],[[],[]]]] },
    { name => "{\\varepsilon_0}^3 = \\omega^{\\varepsilon_0 3}",
      tree => [[[],[],[]],[[[],[],[]],[[],[],[]]]] },
    { name => "{\\varepsilon_0}^\\omega = \\omega^{\\omega^{\\varepsilon_0+1}}",
      tree => [[[[],[],[]]],[]] },
    { name => "{\\varepsilon_0}^\\omega + \\varepsilon_0",
      tree => [[[],[],[]],[[[[],[],[]]],[]]] },
    { name => "{\\varepsilon_0}^\\omega 2",
      tree => [[[[],[],[]]],[[]]] },
    { name => "{\\varepsilon_0}^\\omega \\omega = \\omega^{\\omega^{\\varepsilon_0+1}+1}",
      tree => [[[[],[],[]]],[[],[]]] },
    { name => "{\\varepsilon_0}^{\\omega+1} = \\omega^{\\omega^{\\varepsilon_0+1}+\\varepsilon_0}",
      tree => [[[[],[],[]]],[[],[],[]]] },
    { name => "{\\varepsilon_0}^{\\omega+1} + {\\varepsilon_0}^\\omega",
      tree => [[[[],[],[]]],[[[],[],[]]]] },
    { name => "{\\varepsilon_0}^{\\omega+1} 2",
      tree => [[[[],[],[]]],[[[],[],[]],[]]] },
    { name => "{\\varepsilon_0}^{\\omega+1} \\omega = \\omega^{\\omega^{\\varepsilon_0+1}+\\varepsilon_0+1}",
      tree => [[[[],[],[]]],[[[],[],[]],[[],[]]]] },
    { name => "{\\varepsilon_0}^{\\omega+2} = \\omega^{\\omega^{\\varepsilon_0+1}+\\varepsilon_0 2}",
      tree => [[[[],[],[]]],[[[],[],[]],[[],[],[]]]] },
    { name => "{\\varepsilon_0}^{\\omega 2} = \\omega^{\\omega^{\\varepsilon_0+1}2}",
      tree => [[[[],[],[]]],[[[[],[],[]]],[]]] },
    { name => "{\\varepsilon_0}^{\\omega^2} = \\omega^{\\omega^{\\varepsilon_0+2}}",
      tree => [[[[[],[],[]]]],[]] },
    { name => "{\\varepsilon_0}^{\\omega^\\omega} = \\omega^{\\omega^{\\varepsilon_0+\\omega}}",
      tree => [[[],[[],[],[]]],[]] },
    { name => "{\\varepsilon_0}^{\\omega^\\omega+1} = \\omega^{\\omega^{\\varepsilon_0+\\omega}+\\varepsilon_0}",
      tree => [[[],[[],[],[]]],[[],[],[]]] },
    { name => "{\\varepsilon_0}^{\\omega^\\omega 2} = \\omega^{\\omega^{\\varepsilon_0+\\omega}2}",
      tree => [[[],[[],[],[]]],[[],[[],[],[]]]] },
    { name => "{\\varepsilon_0}^{\\omega^{\\omega+1}} = \\omega^{\\omega^{\\varepsilon_0+\\omega+1}}",
      tree => [[[[],[[],[],[]]]],[]] },
    { name => "{\\varepsilon_0}^{\\omega^{\\omega 2}} = \\omega^{\\omega^{\\varepsilon_0+\\omega 2}}",
      tree => [[[],[[[],[],[]]]],[]] },
    { name => "{\\varepsilon_0}^{\\omega^{\\omega^2}} = \\omega^{\\omega^{\\varepsilon_0+\\omega^2}}",
      tree => [[[],[[],[[],[],[]]]],[]] },
    { name => "{\\varepsilon_0}^{\\omega^{\\omega^\\omega}} = \\omega^{\\omega^{\\varepsilon_0+\\omega^\\omega}}",
      tree => [[[[]],[[],[],[]]],[]] },
    { name => "{\\varepsilon_0}^{\\varepsilon_0} = \\omega^{\\omega^{\\varepsilon_0 2}}",
      tree => [[[[],[],[]],[]],[]] },
    { name => "{\\varepsilon_0}^{{\\varepsilon_0}^2} = \\omega^{\\omega^{\\varepsilon_0 3}}",
      tree => [[[[],[],[]],[[]]],[]] },
    { name => "{\\varepsilon_0}^{{\\varepsilon_0}^\\omega} = \\omega^{\\omega^{\\omega^{\\varepsilon_0+1}}}",
      tree => [[[[],[],[]],[[],[]]],[]] },
    { name => "{\\varepsilon_0}^{{\\varepsilon_0}^{\\varepsilon_0}} = \\omega^{\\omega^{\\omega^{\\varepsilon_0 2}}}",
      tree => [[[[],[],[]],[[],[],[]]],[]] },
    { name => "{\\varepsilon_0}^{{\\varepsilon_0}^{{\\varepsilon_0}^\\omega}} = \\omega^{\\omega^{\\omega^{\\omega^{\\varepsilon_0+1}}}}",
      tree => [[[[[],[],[]]],[]],[]] },
    { name => "{\\varepsilon_0}^{{\\varepsilon_0}^{{\\varepsilon_0}^{\\varepsilon_0}}} = \\omega^{\\omega^{\\omega^{\\omega^{\\varepsilon_0 2}}}}",
      tree => [[[[[],[],[]],[[],[],[]]],[]],[]] },
    { name => "\\varepsilon_1 = \\phi_1(1) = \\psi(1)",
      tree => [[],[],[[]]] },
    { name => "\\varepsilon_1 + 1",
      tree => [[[],[],[[]]]] },
    { name => "\\varepsilon_1 + 2",
      tree => [[[[],[],[[]]]]] },
    { name => "\\varepsilon_1 + \\omega",
      tree => [[],[[],[],[[]]]] },
    { name => "\\varepsilon_1 + \\varepsilon_0",
      tree => [[[],[],[]],[[],[],[[]]]] },
    { name => "\\varepsilon_1 + \\varepsilon_0 2",
      tree => [[[],[],[]],[[[],[],[[]]]]] },
    { name => "\\varepsilon_1 + \\varepsilon_0 \\omega",
      tree => [[[],[],[]],[[],[[],[],[[]]]]] },
    { name => "\\varepsilon_1 + {\\varepsilon_0}^2",
      tree => [[[],[],[]],[[[],[],[]],[[],[],[[]]]]] },
    { name => "\\varepsilon_1 2",
      tree => [[[],[],[[]]],[]] },
    { name => "\\varepsilon_1 2 + \\varepsilon_0",
      tree => [[[],[],[]],[[[],[],[[]]],[]]] },
    { name => "\\varepsilon_1 \\omega = \\omega^{\\varepsilon_1 + 1}",
      tree => [[[],[],[[]]],[[],[]]] },
    { name => "\\varepsilon_1 \\varepsilon_0 = \\omega^{\\varepsilon_1 + \\varepsilon_0}",
      tree => [[[],[],[[]]],[[],[],[]]] },
    { name => "{\\varepsilon_1}^2 = \\omega^{\\varepsilon_1 2}",
      tree => [[[],[],[[]]],[[],[],[[]]]] },
    { name => "{\\varepsilon_1}^\\omega = \\omega^{\\omega^{\\varepsilon_1+1}}",
      tree => [[[[],[],[[]]]],[]] },
    { name => "{\\varepsilon_1}^{\\omega^\\omega} = \\omega^{\\omega^{\\varepsilon_1+\\omega}}",
      tree => [[[],[[],[],[[]]]],[]] },
    { name => "{\\varepsilon_1}^{\\varepsilon_0} = \\omega^{\\omega^{\\varepsilon_1+\\varepsilon_0}}",
      tree => [[[[],[],[]],[[],[],[[]]]],[]] },
    { name => "{\\varepsilon_1}^{{\\varepsilon_0}^{\\omega}} = \\omega^{\\omega^{\\varepsilon_1+\\omega^{\\varepsilon_0+1}}}",
      tree => [[[[],[],[]],[[],[[],[],[[]]]]],[]] },
    { name => "{\\varepsilon_1}^{{\\varepsilon_0}^{\\varepsilon_0}} = \\omega^{\\omega^{\\varepsilon_1+\\omega^{\\varepsilon_0 2}}}",
      tree => [[[[],[],[]],[[[],[],[]],[[],[],[[]]]]],[]] },
    { name => "{\\varepsilon_1}^{\\varepsilon_1} = \\omega^{\\omega^{\\varepsilon_1 2}}",
      tree => [[[[],[],[[]]],[]],[]] },
    { name => "{\\varepsilon_1}^{{\\varepsilon_1}^{\\omega}} = \\omega^{\\omega^{\\omega^{\\varepsilon_1+1}}}",
      tree => [[[[],[],[[]]],[[],[]]],[]] },
    { name => "{\\varepsilon_1}^{{\\varepsilon_1}^{\\varepsilon_0}} = \\omega^{\\omega^{\\omega^{\\varepsilon_1+\\varepsilon_0}}}",
      tree => [[[[],[],[[]]],[[],[],[]]],[]] },
    { name => "{\\varepsilon_1}^{{\\varepsilon_1}^{\\varepsilon_1}} = \\omega^{\\omega^{\\omega^{\\varepsilon_1 2}}}",
      tree => [[[[],[],[[]]],[[],[],[[]]]],[]] },
    { name => "\\varepsilon_2 = \\phi_1(2) = \\psi(2)",
      tree => [[],[],[[[]]]] },
    { name => "\\varepsilon_2 + 1",
      tree => [[[],[],[[[]]]]] },
    { name => "\\varepsilon_3 = \\phi_1(3) = \\psi(3)",
      tree => [[],[],[[[[]]]]] },
    { name => "\\varepsilon_\\omega = \\phi_1(\\omega) = \\psi(\\omega)",
      tree => [[],[],[[],[]]] },
    { name => "\\varepsilon_\\omega + 1",
      tree => [[[],[],[[],[]]]] },
    { name => "\\varepsilon_\\omega + \\omega",
      tree => [[],[[],[],[[],[]]]] },
    { name => "\\varepsilon_\\omega + \\varepsilon_0",
      tree => [[[],[],[]],[[],[],[[],[]]]] },
    { name => "\\varepsilon_\\omega + \\varepsilon_1",
      tree => [[[],[],[[]]],[[],[],[[],[]]]] },
    { name => "\\varepsilon_\\omega 2",
      tree => [[[],[],[[],[]]],[]] },
    { name => "{\\varepsilon_\\omega}^2",
      tree => [[[],[],[[],[]]],[[],[],[[],[]]]] },
    { name => "{\\varepsilon_\\omega}^{\\varepsilon_0} = \\phi_1(\\omega)^{\\phi_1(0)}",
      tree => [[[[],[],[]],[[],[],[[],[]]]],[]] },
    { name => "{\\varepsilon_\\omega}^{\\varepsilon_1} = \\phi_1(\\omega)^{\\phi_1(1)}",
      tree => [[[[],[],[[]]],[[],[],[[],[]]]],[]] },
    { name => "{\\varepsilon_\\omega}^{\\varepsilon_\\omega} = \\phi_1(\\omega)^{\\phi_1(\\omega)}",
      tree => [[[[],[],[[],[]]],[]],[]] },
    { name => "{\\varepsilon_\\omega}^{{\\varepsilon_\\omega}^{\\varepsilon_\\omega}} = \\phi_1(\\omega)^{\\phi_1(\\omega)^{\\phi_1(\\omega)}}",
      tree => [[[[],[],[[],[]]],[[],[],[[],[]]]],[]] },
    { name => "\\varepsilon_{\\omega+1} = \\phi_1(\\omega+1) = \\psi(\\omega+1)",
      tree => [[],[],[[[],[]]]] },
    { name => "\\varepsilon_{\\omega 2} = \\phi_1(\\omega 2) = \\psi(\\omega 2)",
      tree => [[],[],[[],[[]]]] },
    { name => "\\varepsilon_{\\omega^2} = \\phi_1(\\omega^2) = \\psi(\\omega^2)",
      tree => [[],[],[[],[[],[]]]] },
    { name => "\\varepsilon_{\\omega^\\omega} = \\phi_1(\\omega^\\omega) = \\psi(\\omega^\\omega)",
      tree => [[],[],[[[]],[]]] },
    { name => "\\varepsilon_{\\varepsilon_0} = \\phi_1(\\phi_1(0)) = \\psi(\\psi(0))",
      tree => [[],[],[[],[],[]]] },
    { name => "\\varepsilon_{\\varepsilon_0 2} = \\phi_1(\\phi_1(0)\\,2) = \\psi(\\psi(0)\\,2)",
      tree => [[],[],[[[],[],[]],[]]] },
    { name => "\\varepsilon_{{\\varepsilon_0}^{\\varepsilon_0}} = \\phi_1(\\phi_1(0)^{\\phi_1(0)}) = \\psi(\\psi(0)^{\\psi(0)})",
      tree => [[],[],[[[[],[],[]],[]],[]]] },
    { name => "\\varepsilon_{\\varepsilon_1} = \\phi_1(\\phi_1(1)) = \\psi(\\psi(1))",
      tree => [[],[],[[],[],[[]]]] },
    { name => "\\varepsilon_{\\varepsilon_{\\varepsilon_0}} = \\phi_1(\\phi_1(\\phi_1(0))) = \\psi(\\psi(\\psi(0)))",
      tree => [[],[],[[],[],[[],[],[]]]] },
    { name => "\\phi_2(0) = \\psi(\\Omega)",
      tree => [[],[[]],[]] },
    { name => "\\phi_2(0) + 1 = \\psi(\\Omega) + 1",
      tree => [[[],[[]],[]]] },
    { name => "\\phi_2(0) + 2 = \\psi(\\Omega) + 2",
      tree => [[[[],[[]],[]]]] },
    { name => "\\phi_2(0) + \\omega = \\psi(\\Omega) + \\omega",
      tree => [[],[[],[[]],[]]] },
    { name => "\\phi_2(0)\\,2 = \\psi(\\Omega)\\,2",
      tree => [[[],[[]],[]],[]] },
    { name => "\\phi_2(0)\\,\\omega = \\psi(\\Omega)\\,\\omega",
      tree => [[[],[[]],[]],[[],[]]] },
    { name => "\\phi_2(0)^\\omega = \\psi(\\Omega)^\\omega",
      tree => [[[[],[[]],[]]],[]] },
    { name => "\\phi_2(0)^{\\phi_2(0)} = \\psi(\\Omega)^{\\psi(\\Omega)}",
      tree => [[[[],[[]],[]],[]],[]] },
    { name => "\\phi_1(\\phi_2(0)+1) = \\psi(\\Omega+1)",
      tree => [[],[],[[],[[]],[]]] },
    { name => "\\phi_1(\\phi_2(0)+2) = \\psi(\\Omega+2)",
      tree => [[],[],[[[],[[]],[]]]] },
    { name => "\\phi_1(\\phi_2(0)+\\omega) = \\psi(\\Omega+\\omega)",
      tree => [[],[],[[],[[],[[]],[]]]] },
    { name => "\\phi_1(\\phi_2(0)\\,2) = \\psi(\\Omega+\\psi(\\Omega))",
      tree => [[],[],[[[],[[]],[]],[]]] },
    { name => "\\phi_1(\\phi_1(\\phi_2(0)+1)) = \\psi(\\Omega+\\psi(\\Omega+1))",
      tree => [[],[],[[],[],[[],[[]],[]]]] },
    { name => "\\phi_2(1) = \\psi(\\Omega 2)",
      tree => [[],[[]],[[]]] },
    { name => "\\phi_2(1) + 1 = \\psi(\\Omega 2) + 1",
      tree => [[[],[[]],[[]]]] },
    { name => "\\phi_2(1)\\,2 = \\psi(\\Omega 2)\\,2",
      tree => [[[],[[]],[[]]],[]] },
    { name => "\\phi_2(1)^{\\phi_2(1)} = \\psi(\\Omega 2)^{\\psi(\\Omega 2)}",
      tree => [[[[],[[]],[[]]],[]],[]] },
    { name => "\\phi_1(\\phi_2(1)+1) = \\psi(\\Omega 2+1)",
      tree => [[],[],[[],[[]],[[]]]] },
    { name => "\\phi_1(\\phi_1(\\phi_2(1)+1)) = \\psi(\\Omega 2+\\psi(\\Omega 2+1))",
      tree => [[],[],[[],[],[[],[[]],[[]]]]] },
    { name => "\\phi_2(2) = \\psi(\\Omega 3)",
      tree => [[],[[]],[[[]]]] },
    { name => "\\phi_2(\\omega) = \\psi(\\Omega\\omega)",
      tree => [[],[[]],[[],[]]] },
    { name => "\\phi_2(\\varepsilon_0) = \\phi_2(\\phi_1(0)) = \\psi(\\Omega\\psi(0))",
      tree => [[],[[]],[[],[],[]]] },
    { name => "\\phi_2(\\varepsilon_1) = \\phi_2(\\phi_1(1)) = \\psi(\\Omega\\psi(1))",
      tree => [[],[[]],[[],[],[[]]]] },
    { name => "\\phi_2(\\phi_1(\\phi_1(0))) = \\psi(\\Omega\\psi(\\psi(0)))",
      tree => [[],[[]],[[],[],[[],[],[]]]] },
    { name => "\\phi_2(\\phi_2(0)) = \\psi(\\Omega\\psi(\\Omega))",
      tree => [[],[[]],[[],[[]],[]]] },
    { name => "\\phi_1(\\phi_2(\\phi_2(0))+1) = \\psi(\\Omega\\psi(\\Omega)+1)",
      tree => [[],[],[[],[[]],[[],[[]],[]]]] },
    { name => "\\phi_2(\\phi_1(\\phi_2(0)+1)) = \\psi(\\Omega\\psi(\\Omega+1))",
      tree => [[],[[]],[[],[],[[],[[]],[]]]] },
    { name => "\\phi_2(\\phi_2(1)) = \\psi(\\Omega\\psi(\\Omega 2))",
      tree => [[],[[]],[[],[[]],[[]]]] },
    { name => "\\phi_2(\\phi_2(\\phi_2(0))) = \\psi(\\Omega\\psi(\\Omega\\psi(\\Omega)))",
      tree => [[],[[]],[[],[[]],[[],[[]],[]]]] },
    { name => "\\phi_3(0) = \\psi(\\Omega^2)",
      tree => [[],[[[]]],[]] },
    { name => "\\phi_3(0) + 1 = \\psi(\\Omega^2) + 1",
      tree => [[[],[[[]]],[]]] },
    { name => "\\phi_3(0)\\,2 = \\psi(\\Omega^2)\\,2",
      tree => [[[],[[[]]],[]],[]] },
    { name => "\\phi_3(0)^{\\phi_3(0)} = \\psi(\\Omega^2)^{\\psi(\\Omega^2)}",
      tree => [[[[],[[[]]],[]],[]],[]] },
    { name => "\\phi_1(\\phi_3(0)+1) = \\psi(\\Omega^2+1)",
      tree => [[],[],[[],[[[]]],[]]] },
    { name => "\\phi_1(\\phi_1(\\phi_3(0)+1)) = \\psi(\\Omega^2+\\psi(\\Omega^2+1))",
      tree => [[],[],[[],[],[[],[[[]]],[]]]] },
    { name => "\\phi_2(\\phi_3(0)+1) = \\psi(\\Omega^2+\\Omega)",
      tree => [[],[[]],[[],[[[]]],[]]] },
    { name => "\\phi_1(\\phi_2(\\phi_3(0)+1)+1) = \\psi(\\Omega^2+\\Omega+1)",
      tree => [[],[],[[],[[]],[[],[[[]]],[]]]] },
    { name => "\\phi_2(\\phi_2(\\phi_3(0)+1)) = \\psi(\\Omega^2+\\Omega\\psi(\\Omega^2))",
      tree => [[],[[]],[[],[[]],[[],[[[]]],[]]]] },
    { name => "\\phi_3(1) = \\psi(\\Omega^2 2)",
      tree => [[],[[[]]],[[]]] },
    { name => "\\phi_3(\\phi_3(0)) = \\psi(\\Omega^2 \\psi(\\Omega^2))",
      tree => [[],[[[]]],[[],[[[]]],[]]] },
    { name => "\\phi_4(0) = \\psi(\\Omega^3)",
      tree => [[],[[[[]]]],[]] },
    { name => "\\phi_\\omega(0) = \\psi(\\Omega^\\omega)",
      tree => [[],[[],[]],[]] },
    { name => "\\phi_\\omega(0) + 1 = \\psi(\\Omega^\\omega) + 1",
      tree => [[[],[[],[]],[]]] },
    { name => "\\phi_1(\\phi_\\omega(0)+1) = \\psi(\\Omega^\\omega + 1)",
      tree => [[],[],[[],[[],[]],[]]] },
    { name => "\\phi_2(\\phi_\\omega(0)+1) = \\psi(\\Omega^\\omega + \\Omega)",
      tree => [[],[[]],[[],[[],[]],[]]] },
    { name => "\\phi_3(\\phi_\\omega(0)+1) = \\psi(\\Omega^\\omega + \\Omega^2)",
      tree => [[],[[[]]],[[],[[],[]],[]]] },
    { name => "\\phi_\\omega(1) = \\psi(\\Omega^\\omega 2)",
      tree => [[],[[],[]],[[]]] },
    { name => "\\phi_\\omega(\\omega) = \\psi(\\Omega^\\omega \\omega)",
      tree => [[],[[],[]],[[],[]]] },
    { name => "\\phi_\\omega(\\phi_\\omega(0)) = \\psi(\\Omega^\\omega\\psi(\\Omega^\\omega))",
      tree => [[],[[],[]],[[],[[],[]],[]]] },
    { name => "\\phi_{\\omega+1}(0) = \\psi(\\Omega^{\\omega+1})",
      tree => [[],[[[],[]]],[]] },
    { name => "\\phi_{\\omega 2}(0) = \\psi(\\Omega^{\\omega 2})",
      tree => [[],[[],[[]]],[]] },
    { name => "\\phi_{\\omega}(\\phi_{\\omega 2}(0)+1) = \\psi(\\Omega^{\\omega 2}+\\Omega^\\omega)",
      tree => [[],[[],[]],[[],[[],[[]]],[]]] },
    { name => "\\phi_{\\omega+1}(\\phi_{\\omega 2}(0)+1) = \\psi(\\Omega^{\\omega 2}+\\Omega^{\\omega+1})",
      tree => [[],[[[],[]]],[[],[[],[[]]],[]]] },
    { name => "\\phi_{\\omega 2}(1) = \\psi(\\Omega^{\\omega 2} 2)",
      tree => [[],[[],[[]]],[[]]] },
    { name => "\\phi_{\\omega^\\omega}(0) = \\psi(\\Omega^{\\omega^\\omega})",
      tree => [[],[[[]],[]],[]] },
    { name => "\\phi_{\\varepsilon_0}(0) = \\phi_{\\phi_1(0)}(0) = \\psi(\\Omega^{\\psi(0)})",
      tree => [[],[[],[],[]],[]] },
    { name => "\\phi_{\\varepsilon_0}(1) = \\phi_{\\phi_1(0)}(1) = \\psi(\\Omega^{\\psi(0)}2)",
      tree => [[],[[],[],[]],[[]]] },
    { name => "\\phi_{\\varepsilon_0}(\\varepsilon_0) = \\phi_{\\phi_1(0)}(\\phi_1(0)) = \\psi(\\Omega^{\\psi(0)}\\psi(0))",
      tree => [[],[[],[],[]],[[],[],[]]] },
    { name => "\\phi_{\\phi_1(0)}(\\phi_{\\phi_1(0)}(0)) = \\psi(\\Omega^{\\psi(0)}\\psi(\\Omega^{\\psi(0)}))",
      tree => [[],[[],[],[]],[[],[[],[],[]],[]]] },
    { name => "\\phi_{\\varepsilon_0+1}(0) = \\phi_{\\phi_1(0)+1}(0) = \\psi(\\Omega^{\\psi(0)+1})",
      tree => [[],[[[],[],[]]],[]] },
    { name => "\\phi_{\\varepsilon_1}(0) = \\phi_{\\phi_1(1)}(0) = \\psi(\\Omega^{\\psi(1)})",
      tree => [[],[[],[],[[]]],[]] },
    { name => "\\phi_{\\varepsilon_{\\varepsilon_0}}(0) = \\phi_{\\phi_{\\phi_1(0)}(0)}(0) = \\psi(\\Omega^{\\psi(\\psi(0))})",
      tree => [[],[[],[],[[],[],[]]],[]] },
    { name => "\\phi_{\\phi_2(0)}(0) = \\psi(\\Omega^{\\psi(\\Omega)})",
      tree => [[],[[],[[]],[]],[]] },
    { name => "\\phi_{\\phi_{\\phi_1(0)}(0)}(0) = \\psi(\\Omega^{\\psi(\\Omega^{\\psi(0)})})",
      tree => [[],[[],[[],[],[]],[]],[]] },
    { name => "\\Gamma_0 = \\phi(1,0,0) = \\psi(\\Omega^\\Omega)",
      tree => [[[]],[],[]] },
    { name => "\\Gamma_0 + 1",
      tree => [[[[]],[],[]]] },
    { name => "\\Gamma_0 + 2",
      tree => [[[[[]],[],[]]]] },
    { name => "\\Gamma_0 + \\omega",
      tree => [[],[[[]],[],[]]] },
    { name => "\\Gamma_0 2",
      tree => [[[[]],[],[]],[]] },
    { name => "{\\Gamma_0}^2",
      tree => [[[[]],[],[]],[[[]],[],[]]] },
    { name => "{\\Gamma_0}^\\omega",
      tree => [[[[[]],[],[]]],[]] },
    { name => "{\\Gamma_0}^{\\Gamma_0}",
      tree => [[[[[]],[],[]],[[[]],[],[]]],[]] },
    { name => "\\varepsilon_{\\Gamma_0+1} = \\phi(1,\\phi(1,0,0)+1) = \\psi(\\Omega^\\Omega+1)",
      tree => [[],[],[[[]],[],[]]] },
    { name => "\\phi(\\phi_1(0),\\phi(1,0,0)+1) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(0)})",
      tree => [[],[[],[],[]],[[[]],[],[]]] },
    { name => "\\phi(\\phi_{\\phi_1(0)}(0),\\phi(1,0,0)+1) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\psi(0))})",
      tree => [[],[[],[[],[],[]],[]],[[[]],[],[]]] },
    { name => "\\phi(\\phi(1,0,0),1) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)})",
      tree => [[],[[[]],[],[]],[]] },
    { name => "\\phi(1,\\phi(\\phi(1,0,0),1)+1) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)}+1)",
      tree => [[],[],[[],[[[]],[],[]],[]]] },
    { name => "\\phi(\\phi_1(0),\\phi(\\phi(1,0,0),1)+1) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)}+\\Omega^{\\psi(0)})",
      tree => [[],[[],[],[]],[[],[[[]],[],[]],[]]] },
    { name => "\\phi(\\phi_{\\phi_1(0)}(0),\\phi(\\phi(1,0,0),1)+1) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)}+\\Omega^{\\psi(\\psi(0))})",
      tree => [[],[[],[[],[],[]],[]],[[],[[[]],[],[]],[]]] },
    { name => "\\phi(\\phi(1,0,0),2) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)} 2)",
      tree => [[],[[[]],[],[]],[[]]] },
    { name => "\\phi(\\phi(1,0,0),\\phi_1(0)) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)} \\psi(0))",
      tree => [[],[[[]],[],[]],[[],[],[]]] },
    { name => "\\phi(\\phi(1,0,0),\\phi(1,0,0)) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)} \\psi(\\Omega^\\Omega))",
      tree => [[],[[[]],[],[]],[[[]],[],[]]] },
    { name => "\\phi(\\phi(1,0,0),\\phi(\\phi(1,0,0),\\phi(1,0,0))) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)} \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)} \\psi(\\Omega^\\Omega)))",
      tree => [[],[[[]],[],[]],[[],[[[]],[],[]],[[[]],[],[]]]] },
    { name => "\\phi(\\phi(1,0,0)+1,0) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)+1})",
      tree => [[],[[[[]],[],[]]],[]] },
    { name => "\\phi(\\phi(\\phi(1,0,0),1),0) = \\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega+\\Omega^{\\psi(\\Omega^\\Omega)})})",
      tree => [[],[[],[[[]],[],[]],[]],[]] },
    { name => "\\Gamma_1 = \\phi(1,0,1) = \\psi(\\Omega^\\Omega 2)",
      tree => [[[]],[],[[]]] },
    { name => "\\Gamma_1 + 1",
      tree => [[[[]],[],[[]]]] },
    { name => "\\Gamma_2 = \\phi(1,0,2) = \\psi(\\Omega^\\Omega 3)",
      tree => [[[]],[],[[[]]]] },
    { name => "\\Gamma_\\omega = \\phi(1,0,\\omega) = \\psi(\\Omega^\\Omega \\omega)",
      tree => [[[]],[],[[],[]]] },
    { name => "\\Gamma_{\\Gamma_0} = \\phi(1,0,\\phi(1,0,0)) = \\psi(\\Omega^\\Omega \\psi(\\Omega^\\Omega))",
      tree => [[[]],[],[[[]],[],[]]] },
    { name => "\\Gamma_{\\Gamma_{\\Gamma_0}} = \\phi(1,0,\\phi(1,0,\\phi(1,0,0))) = \\psi(\\Omega^\\Omega \\psi(\\Omega^\\Omega \\psi(\\Omega^\\Omega)))",
      tree => [[[]],[],[[[]],[],[[[]],[],[]]]] },
    { name => "\\phi(1,1,0) = \\psi(\\Omega^{\\Omega+1})",
      tree => [[[]],[[]],[]] },
    { name => "\\phi(1,1,0) + 1",
      tree => [[[[]],[[]],[]]] },
    { name => "\\phi(1,0,\\phi(1,1,0)+1) = \\psi(\\Omega^{\\Omega+1}+\\Omega^\\Omega)",
      tree => [[[]],[],[[[]],[[]],[]]] },
    { name => "\\phi(1,1,1) = \\psi(\\Omega^{\\Omega+1} 2)",
      tree => [[[]],[[]],[[]]] },
    { name => "\\phi(1,2,0) = \\psi(\\Omega^{\\Omega+2})",
      tree => [[[]],[[[]]],[]] },
    { name => "\\phi(1,\\omega,0) = \\psi(\\Omega^{\\Omega+\\omega})",
      tree => [[[]],[[],[]],[]] },
    { name => "\\phi(1,\\phi(1,0,0),0) = \\psi(\\Omega^{\\Omega+\\psi(\\Omega^\\Omega)})",
      tree => [[[]],[[[]],[],[]],[]] },
    { name => "\\phi(2,0,0) = \\psi(\\Omega^{\\Omega 2})",
      tree => [[[[]]],[],[]] },
    { name => "\\phi(2,0,0) + 1",
      tree => [[[[[]]],[],[]]] },
    { name => "\\phi(2,0,1) = \\psi(\\Omega^{\\Omega 2} 2)",
      tree => [[[[]]],[],[[]]] },
    { name => "\\phi(2,1,0) = \\psi(\\Omega^{\\Omega 2+1})",
      tree => [[[[]]],[[]],[]] },
    { name => "\\phi(3,0,0) = \\psi(\\Omega^{\\Omega 3})",
      tree => [[[[[]]]],[],[]] },
    { name => "\\phi(\\omega,0,0) = \\psi(\\Omega^{\\Omega\\omega})",
      tree => [[[],[]],[],[]] },
    { name => "\\phi(\\omega,0,0) + 1",
      tree => [[[[],[]],[],[]]] },
    { name => "\\phi(\\omega,0,0)\\,2",
      tree => [[[[],[]],[],[]],[]] },
    { name => "\\phi(\\omega,0,0)^{\\phi(\\omega,0,0)}",
      tree => [[[[],[]],[],[]],[[[[],[]],[],[]]]] },
    { name => "\\phi(1,\\phi(\\omega,0,0)+1) = \\psi(\\Omega^{\\Omega\\omega}+1)",
      tree => [[],[],[[[],[]],[],[]]] },
    { name => "\\phi(2,\\phi(\\omega,0,0)+1) = \\psi(\\Omega^{\\Omega\\omega}+\\Omega)",
      tree => [[],[[]],[[[],[]],[],[]]] },
    { name => "\\phi(\\phi_1(0),\\phi(\\omega,0,0)+1) = \\psi(\\Omega^{\\Omega\\omega}+\\Omega^{\\psi(0)})",
      tree => [[],[[],[],[]],[[[],[]],[],[]]] },
    { name => "\\phi(\\phi(1,0,0),\\phi(\\omega,0,0)+1) = \\psi(\\Omega^{\\Omega\\omega}+\\Omega^{\\psi(\\Omega^\\Omega)})",
      tree => [[],[[[]],[],[]],[[[],[]],[],[]]] },
    { name => "\\phi(1,0,\\phi(\\omega,0,0)+1) = \\psi(\\Omega^{\\Omega\\omega}+\\Omega^\\Omega)",
      tree => [[[]],[],[[[],[]],[],[]]] },
    { name => "\\phi(2,0,\\phi(\\omega,0,0)+1) = \\psi(\\Omega^{\\Omega\\omega}+\\Omega^{\\Omega 2})",
      tree => [[[[]]],[],[[[],[]],[],[]]] },
    { name => "\\phi(\\omega,0,1) = \\psi(\\Omega^{\\Omega\\omega} 2)",
      tree => [[[],[]],[],[[]]] },
    { name => "\\phi(\\omega,0,\\phi(\\omega,0,0)) = \\psi(\\Omega^{\\Omega\\omega}\\psi(\\Omega^{\\Omega\\omega}))",
      tree => [[[],[]],[],[[[],[]],[],[]]] },
    { name => "\\phi(\\omega,1,0) = \\psi(\\Omega^{\\Omega\\omega+1})",
      tree => [[[],[]],[[]],[]] },
    { name => "\\phi(\\omega,\\phi(\\omega,0,0),0) = \\psi(\\Omega^{\\Omega\\omega+\\psi(\\Omega^{\\Omega\\omega})})",
      tree => [[[],[]],[[[],[]],[],[]],[]] },
    { name => "\\phi(\\omega+1,0,0) = \\psi(\\Omega^{\\Omega(\\omega+1)})",
      tree => [[[[],[]]],[],[]] },
    { name => "\\phi(\\omega 2,0,0) = \\psi(\\Omega^{\\Omega\\omega 2})",
      tree => [[[],[[]]],[],[]] },
    { name => "\\phi(\\omega^\\omega,0,0) = \\psi(\\Omega^{\\Omega\\omega^\\omega})",
      tree => [[[[]],[]],[],[]] },
    { name => "\\phi(\\phi_1(0),0,0) = \\psi(\\Omega^{\\Omega\\psi(0)})",
      tree => [[[],[],[]],[],[]] },
    { name => "\\phi(\\phi_1(0),0,0)\\,2",
      tree => [[[[],[],[]],[],[]],[]] },
    { name => "\\phi(\\phi_1(0),0,0)^{\\phi(\\phi_1(0),0,0)}",
      tree => [[[[[],[],[]],[],[]],[]],[]] },
    { name => "\\phi(1,\\phi(\\phi_1(0),0,0)+1) = \\psi(\\Omega^{\\Omega\\psi(0)} + 1)",
      tree => [[],[],[[[],[],[]],[],[]]] },
    { name => "\\phi(\\omega,\\phi(\\phi_1(0),0,0)+1) = \\psi(\\Omega^{\\Omega\\psi(0)} + \\Omega^\\omega)",
      tree => [[[],[]],[],[[[],[],[]],[],[]]] },
    { name => "\\phi(\\phi_1(0),0,1) = \\psi(\\Omega^{\\Omega\\psi(0)} 2)",
      tree => [[[],[],[]],[],[[]]] },
    { name => "\\phi(\\phi_1(0),0,\\phi_1(0)) = \\psi(\\Omega^{\\Omega\\psi(0)} \\psi(0))",
      tree => [[[],[],[]],[],[[],[],[]]] },
    { name => "\\phi(\\phi_1(0),0,\\phi(\\phi_1(0),0,0)) = \\psi(\\Omega^{\\Omega\\psi(0)} \\psi(\\Omega^{\\Omega\\psi(0)}))",
      tree => [[[],[],[]],[],[[[],[],[]],[],[]]] },
    { name => "\\phi(\\phi_1(0),1,0) = \\psi(\\Omega^{\\Omega\\psi(0)+1})",
      tree => [[[],[],[]],[[]],[]] },
    { name => "\\phi(\\phi_1(0),\\phi_1(0),0) = \\psi(\\Omega^{\\Omega\\psi(0)+\\psi(0)})",
      tree => [[[],[],[]],[[],[],[]],[]] },
    { name => "\\phi(\\phi_1(0),\\phi(\\phi_1(0),0,0),0) = \\psi(\\Omega^{\\Omega\\psi(0)+\\psi(\\Omega^{\\Omega\\psi(0)})})",
      tree => [[[],[],[]],[[[],[],[]],[],[]],[]] },
    { name => "\\phi(\\phi_1(0)+1,0,0) = \\psi(\\Omega^{\\Omega(\\psi(0)+1)})",
      tree => [[[[],[],[]]],[],[]] },
    { name => "\\phi(\\phi_1(1),0,0) = \\psi(\\Omega^{\\Omega\\psi(1)})",
      tree => [[[],[],[[]]],[],[]] },
    { name => "\\phi(\\phi_1(\\phi_1(0)),0,0) = \\psi(\\Omega^{\\Omega\\psi(\\psi(0))})",
      tree => [[[],[],[[],[],[]]],[],[]] },
    { name => "\\phi(\\phi_2(0),0,0) = \\psi(\\Omega^{\\Omega\\psi(\\Omega)})",
      tree => [[[],[[]],[]],[],[]] },
    { name => "\\phi(\\phi_{\\phi_1(0)}(0),0,0) = \\psi(\\Omega^{\\Omega\\psi(\\Omega^{\\psi(0)})})",
      tree => [[[],[[],[],[]],[]],[],[]] },
    { name => "\\phi(\\phi(1,0,0),0,0) = \\psi(\\Omega^{\\Omega\\psi(\\Omega^\\Omega)})",
      tree => [[[[]],[],[]],[],[]] },
    { name => "\\phi(\\phi(\\phi_1(0),0,0),0,0) = \\psi(\\Omega^{\\Omega\\psi(\\Omega^{\\Omega\\psi(0)})})",
      tree => [[[[],[],[]],[],[]],[],[]] },
    { name => "\\phi(1,0,0,0) = \\psi(\\Omega^{\\Omega^2})",
      tree => [[],[],[],[]] },
    { name => "\\phi(1,0,0,0) + 1",
      tree => [[[],[],[],[]]] },
    { name => "\\phi(1,0,0,0) + 2",
      tree => [[[[],[],[],[]]]] },
    { name => "\\phi(1,0,0,0) + \\omega",
      tree => [[],[[],[],[],[]]] },
    { name => "\\phi(1,0,0,0) 2",
      tree => [[[],[],[],[]],[]] },
    { name => "\\phi(1,0,\\phi(1,0,0,0)+1) = \\psi(\\Omega^{\\Omega^2}+\\Omega^\\Omega)",
      tree => [[[],[],[],[]],[],[]] },
    { name => "\\phi(1,0,0,1) = \\psi(\\Omega^{\\Omega^2} 2)",
      tree => [[],[],[],[[]]] },
    { name => "\\phi(1,0,0,1) + 1",
      tree => [[[],[],[],[[]]]] },
    { name => "\\phi(1,0,0,2) = \\psi(\\Omega^{\\Omega^2} 3)",
      tree => [[],[],[],[[[]]]] },
    { name => "\\phi(1,0,0,\\omega) = \\psi(\\Omega^{\\Omega^2} \\omega)",
      tree => [[],[],[],[[],[]]] },
    { name => "\\phi(1,0,1,0) = \\psi(\\Omega^{\\Omega^2+1})",
      tree => [[],[],[[]],[]] },
    { name => "\\phi(1,0,1,0) + 1",
      tree => [[[],[],[[]],[]]] },
    { name => "\\phi(1,0,1,1) = \\psi(\\Omega^{\\Omega^2+1} 2)",
      tree => [[],[],[[]],[[]]] },
    { name => "\\phi(1,0,2,0) = \\psi(\\Omega^{\\Omega^2+2})",
      tree => [[],[],[[[]]],[]] },
    { name => "\\phi(1,0,\\omega,0) = \\psi(\\Omega^{\\Omega^2+\\omega})",
      tree => [[],[],[[],[]],[]] },
    { name => "\\phi(1,1,0,0) = \\psi(\\Omega^{\\Omega^2+\\Omega})",
      tree => [[],[[]],[],[]] },
    { name => "\\phi(1,1,0,0) + 1",
      tree => [[[],[[]],[],[]]] },
    { name => "\\phi(1,1,0,1) = \\psi(\\Omega^{\\Omega^2+\\Omega} 2)",
      tree => [[],[[]],[],[[]]] },
    { name => "\\phi(1,1,1,0) = \\psi(\\Omega^{\\Omega^2+\\Omega+1})",
      tree => [[],[[]],[[]],[]] },
    { name => "\\phi(1,2,0,0) = \\psi(\\Omega^{\\Omega^2+\\Omega 2})",
      tree => [[],[[[]]],[],[]] },
    { name => "\\phi(1,\\omega,0,0) = \\psi(\\Omega^{\\Omega^2+\\Omega\\omega})",
      tree => [[],[[],[]],[],[]] },
    { name => "\\phi(2,0,0,0) = \\psi(\\Omega^{\\Omega^2 2})",
      tree => [[[]],[],[],[]] },
    { name => "\\phi(2,0,0,0) + 1",
      tree => [[[[]],[],[],[]]] },
    { name => "\\phi(2,0,0,1) = \\psi(\\Omega^{\\Omega^2 2} 2)",
      tree => [[[]],[],[],[[]]] },
    { name => "\\phi(2,0,1,0) = \\psi(\\Omega^{\\Omega^2 2+1})",
      tree => [[[]],[],[[]],[]] },
    { name => "\\phi(2,1,0,0) = \\psi(\\Omega^{\\Omega^2 2+\\Omega})",
      tree => [[[]],[[]],[],[]] },
    { name => "\\phi(3,0,0,0) = \\psi(\\Omega^{\\Omega^2 3})",
      tree => [[[[]]],[],[],[]] },
    { name => "\\phi(\\omega,0,0,0) = \\psi(\\Omega^{\\Omega^2\\omega})",
      tree => [[[],[]],[],[],[]] },
    { name => "\\phi(1,0,0,0,0) = \\psi(\\Omega^{\\Omega^3})",
      tree => [[],[],[],[],[]] },
    { name => "\\phi(1,0,0,0,0) + 1",
      tree => [[[],[],[],[],[]]] },
    { name => "\\phi(1,0,0,0,1) = \\psi(\\Omega^{\\Omega^3} 2)",
      tree => [[],[],[],[],[[]]] },
    { name => "\\phi(1,0,0,1,0) = \\psi(\\Omega^{\\Omega^3+1})",
      tree => [[],[],[],[[]],[]] },
    { name => "\\phi(1,0,1,0,0) = \\psi(\\Omega^{\\Omega^3+\\Omega})",
      tree => [[],[],[[]],[],[]] },
    { name => "\\phi(1,1,0,0,0) = \\psi(\\Omega^{\\Omega^3+\\Omega^2})",
      tree => [[],[[]],[],[],[]] },
    { name => "\\phi(2,0,0,0,0) = \\psi(\\Omega^{\\Omega^3 2})",
      tree => [[[]],[],[],[],[]] },
    { name => "\\phi(1,0,0,0,0,0) = \\psi(\\Omega^{\\Omega^4})",
      tree => [[],[],[],[],[],[]] },
);

for ( my $i=0 ; $i<scalar(@ordinals)-1 ; $i++ ) {
    if ( compare($ordinals[$i]{tree},$ordinals[$i+1]{tree}) != -1 ) {
	die (sprintf "Wrong order between %s and %s!\n", $ordinals[$i]{name}, $ordinals[$i+1]{name});
    }
}

my @ord_copy = @ordinals;

foreach my $o ( @ord_copy ) {
    use integer;
    my $t = $$o{tree};
    foreach my $st ( @$t ) {
	my $lbd = 0;
	my $ubd = scalar(@ordinals)+1;
	while ( 1 ) {
	    if ( $ubd == $lbd+1 ) {
		print STDERR "Inserting new ordinal at place $lbd\n";
		my $new_o = { tree => deep_copy($st) };
		splice @ordinals, $lbd, 0, $new_o;
		last;
	    }
	    my $idx = ($lbd+$ubd)/2;
	    my $cmp = compare($st,$ordinals[$idx-1]{tree});
	    if ( $cmp == 0 ) {
		last;
	    } elsif ( $cmp == -1 ) {
		$ubd = $idx;
	    } elsif ( $cmp == 1 ) {
		$lbd = $idx;
	    }
	}
    }
}

my $namcnt = 0;
foreach my $o ( @ordinals ) {
    $namcnt++ if defined($$o{name});
}
printf STDERR "%d ordinals in total, %d named\n", scalar(@ordinals), $namcnt;

print "\\documentclass{article}\n\\usepackage[a4paper,hmargin=1.5cm,vmargin=2cm,includeheadfoot]{geometry}\n";
print "\\usepackage{amssymb}\\usepackage{tikz}\n\\begin{document}\n";
print "\\tikzstyle ordnode=[shape=circle,draw,fill=black!50,minimum size=4pt,inner sep=0pt]\n";
print "\\tikzstyle ordline=[very thick]\n";
print "\\tikzstyle ordtitle=[]\n";
print "\\lineskip=2.5explus1fil\n";
print "\\par\\noindent\n";
my $is_first = 1;
foreach my $o ( @ordinals ) {
    printf "\\penalty500\\hskip.35cmplus1fil\\relax\n" unless $is_first;
    display $$o{name}, $$o{tree};
    $is_first = 0;
}
print << '__EOF__';
\hskip0ptplus1fill
\par\lineskip=\normallineskip\relax

\textbf{Conventions and notations:}
\begin{itemize}
\item The order on finite rooted trees is recursively defined as
follows: a tree $A$ is less than a tree $B$, written $A\prec B$, iff:
\begin{itemize}
\item \emph{either} there is some child (=immediate subtree) $B'$
of~$B$ such that $A \preceq B'$,
\item \emph{or} the following two conditions hold: every child $A'$
of~$A$ satisfies $A' \prec B$, \emph{and} the list of children
of~$A$ is lexicographically less than the list of children of~$B$ for
the order~$\prec$ (with the leftmost children having the most weight,
i.e., either $B$ has more children than $A$, or if $A'$ and $B'$ are
the leftmost children on which they differ then $A' \prec B'$).
\end{itemize}
This is a well-order.
\item $\omega$ is the smallest infinite ordinal.
\item Ordinal addition, multiplication and exponentiation are defined
as usual:
\begin{itemize}
\item[(i)] $\alpha+0 = \alpha$
\item[(ii)] $\alpha+1$ is the successor of~$\alpha$.
\item[(iii)] $\alpha+(\beta+1) = (\alpha+\beta)+1$
\item[(iv)] If $\delta$ is limit then $\alpha+\delta$ is the limit of
the $\alpha+\beta$ for~$\beta<\delta$.
\item[(v)] $\alpha\cdot 0 = 0$
\item[(vi)] $\alpha(\beta+1) = \alpha\beta + \alpha$
\item[(vii)] $\alpha^0 = 1$
\item[(viii)] $\alpha^{\beta+1} = \alpha^\beta \alpha$
\end{itemize}
\item $\phi_1(\alpha) = \varepsilon_\alpha$ is the $\alpha$-th fixed
point of $\xi \mapsto \omega^\xi$ (with $\varepsilon_0$ the smallest:
it is the limit of $\omega$, $\omega^\omega$,
$\omega^{\omega^\omega}$,~etc.).
\item \emph{The Veblen hierarchy:} For any $\beta>1$, let
$\phi_\beta(\alpha)$ be the $\alpha$-th common fixed point of
$\phi_\gamma$ for all~$0<\gamma<\beta$ (with $\phi_\beta(0)$ the
smallest).  Note:
\begin{itemize}
\item[(i)] $\phi_\beta(\alpha)$ is
continuous in $\alpha$ for all $\beta$ but it is \emph{not} continuous
in $\beta$ except for $\alpha=0$.
\item[(ii)] $\phi_{\beta+1}(0)$ is the limit of $\phi_\beta(0)$,
$\phi_\beta(\phi_\beta(0))$, $\phi_\beta(\phi_\beta(\phi_\beta(0)))$,
etc.
\item[(iii)] $\phi_{\beta+1}(\alpha+1)$ is the limit of
$\phi_{\beta+1}(\alpha)+1$, $\phi_\beta(\phi_{\beta+1}(\alpha)+1)$,
$\phi_\beta(\phi_\beta(\phi_{\beta+1}(\alpha)+1))$, etc.
\item[(iv)] If $\delta$ is limit (and $\beta$ is arbitrary) then
$\phi_\beta(\delta)$ is the limit of the $\phi_\beta(\xi)$
for~$\xi<\delta$.
\item[(v)] If $\delta$ is limit then $\phi_\delta(0)$ is the limit of
the $\phi_\gamma(0)$ for~$\gamma<\delta$.
\item[(vi)] If $\delta$ is limit then $\phi_\delta(\alpha+1)$ is the
limit of the $\phi_\gamma(\phi_\delta(\alpha)+1)$ for~$\gamma<\delta$.
\end{itemize}
\item $\phi(1,0,\alpha) = \Gamma_\alpha$ is the $\alpha$-th fixed
point of $\xi \mapsto \phi_\xi(0)$ (with $\Gamma_0$ the smallest: it
is the limit of $\phi_1(0)$, $\phi_{\phi_1(0)}(0)$
$\phi_{\phi_{\phi_1(0)}(0)}(0)$,~etc.; this is known as the
Feferman-Sch\"{u}tte ordinal).
\item More generally, let $\phi(\beta,\alpha) = \phi_\beta(\alpha)$
(we only use the notation with a subscript for values less
than~$\Gamma_0$) and define $\phi$ of finitely many variables by:
$\phi(\beta_n,\beta_{n-1},\ldots,\beta_r,0,0,\ldots,0,\alpha)$ is the
$\alpha$-th fixed point of all the $\xi\mapsto
\phi(\gamma_n,\gamma_{n-1},\ldots,\gamma_r,\xi,0,0,\ldots,0)$ for
$(\gamma_n,\ldots,\gamma_r)$ lexicographically less than
$(\beta_n,\ldots,\beta_r)$ (the leftmost variable having the most
weight), with the convention that $\phi(0,\beta_{n-1},\ldots,\beta_0)
= \phi(\beta_{n-1},\ldots,\beta_0)$.
\item $\Omega$ is the first uncountable ordinal.
\item \emph{A collapsing function:} $\psi(\alpha)$ is defined
inductively as the smallest ordinal not expressible from $0$, $1$,
$\omega$ and $\Omega$ using addition, multiplication, exponentiation,
and application of the function $\psi$ itself to ordinals less
than~$\alpha$.  Or, more rigorously:
\begin{itemize}
\item Assume $\psi$ has been defined for all ordinals $\beta<\alpha$.
\item Let $C(\alpha)$ be the set of ordinals constructed starting from
$0$, $1$, $\omega$ and $\Omega$ by recursively applying the following
functions: ordinal addition, multiplication and exponentiation and the
function $\psi{\upharpoonright}_\alpha$, i.e., the restriction of $\psi$
to ordinals $\beta<\alpha$.  Formally, we define $C(\alpha)_0 =
\{0,1,\omega,\Omega\}$ and inductively $C(\alpha)_{n+1} = C(\alpha)_n
\cup \{\beta_1+\beta_2,\;\beta_1\beta_2,\;{\beta_1}^{\beta_2}:\;
\beta_1,\beta_2\in C(\alpha)_n\} \cup \{\psi(\beta): \beta\in
C(\alpha)_n \,\land\, \beta<\alpha\}$ for all natural numbers~$n$, and we
let $C(\alpha)$ be the union of the $C(\alpha)_n$ for all~$n$.
\item Define $\psi(\alpha)$ as the smallest ordinal not
in~$C(\alpha)$.
\end{itemize}
It turns out that:
\begin{itemize}
\item[(i)] $\psi$ is continuous and non-decreasing.
\item[(ii)] The range of $\psi$ is precisely the set of
$\varepsilon$-numbers (i.e., fixed points of $\xi \mapsto \omega^\xi$)
up to the Bachmann-Howard ordinal.
\item[(iii)] $C(\alpha)$ consists exactly of those ordinals whose
iterated base $\Omega$ representation only has pieces less than
$\psi(\alpha)$; in particular, $C(\alpha) \cap \Omega = \alpha$.
\item[(iv)] $\psi(\alpha+1)$ is always equal either to the first
$\varepsilon$-number after $\psi(\alpha)$---this happens when
$\alpha \in C(\alpha)$---or else to $\psi(\alpha)$---which happens
when $\alpha \not\in C(\alpha)$.
\item[(v)] If $\delta$ is limit then $\psi(\delta)$ is the limit of
the $\psi(\xi)$ for~$\xi<\delta$.
\item[(vi)] $\psi(\alpha+\Omega)$ is the first fixed point of $\xi
\mapsto \psi(\alpha+\xi)$.
\item[(vii)] $\psi(\alpha\Omega)$ is the first fixed point of $\xi
\mapsto \psi(\alpha\xi)$.
\item[(viii)] $\psi(\alpha^\Omega)$ is the first fixed point of $\xi \mapsto
\psi(\alpha^\xi)$.
\item[(ix)] $\psi(\alpha^{\beta^\Omega})$ is the first fixed point of
$\xi \mapsto \psi(\alpha^{\beta^\xi})$.
\end{itemize}
\item Certain ordinals have special names:
\begin{itemize}
\item $\psi(\Omega^\Omega) = \phi(1,0,0) = \Gamma_0$ is the
``Feferman-Sch\"{u}tte ordinal'': it is the set of ordinals
constructed starting from $0$, $1$, $\omega$ by recursively applying
ordinal addition, multiplication and exponentiation and the Veblen
functions $\phi_\beta(\alpha)$ of two variables;
\item $\psi(\Omega^{\Omega^\omega})$ is the ``small'' Veblen ordinal:
it is the set of ordinals constructed starting from $0$, $1$, $\omega$
by recursively applying ordinal addition, multiplication and
exponentiation and the Veblen functions $\phi(\cdots)$ of finitely
many variables, and it is also the length of the ordering $\prec$ of
finite rooted trees;
\item $\psi(\Omega^{\Omega^\Omega})$ is the ``large'' Veblen ordinal
(it can be defined similarly to the ``small'' Veblen ordinal using a
generalization of $\phi(\cdots)$ to transfinitely many variables all
but finitely many of which are zero);
\item $\psi(\varepsilon_{\Omega+1})$ is the Bachmann-Howard ordinal.
\end{itemize}
\end{itemize}
\par
__EOF__

my $example = [[[[[[]]],[],[[[],[[]]],[]]],
		[[[],[],[[]]],[[],[]],[[],[[[],[]]]]]],
	       [[[[[[],[]]],[]],[[],[]],[[[]],[],[]]],
		[[[],[[[]],[]]],[],[[[]]]]]];

print "\\vfill\n\\begin{center}\n";
display "\\alpha_{\\textrm{example}}", $example;
print "\\[\n\\begin{array}{r\@{}l}\n";
print "\\alpha_{\\textrm{example}}\n";
print "\&= \\phi(\\phi_1(1),\\omega,\\omega^2+\\omega)\n"
    . "^{\\phi(2,0,\\omega^{\\omega^{\\omega 2}})}\\,\n"
    . "\\phi(\\omega^{\\omega^{\\omega+1}},\\omega,\\phi(1,0,0))\\,\n"
    . "\\phi(\\omega^\\omega+\\omega,0,2)\\\\\n";
print "\&= \\psi(\\Omega^{\\Omega\\psi(1)+\\omega}(\\omega^2+\\omega))\n"
    . "^{\\psi(\\Omega^{\\Omega 2}\\omega^{\\omega^{\\omega 2}})}\\,\n"
    . "\\psi(\\Omega^{\\Omega \\omega^{\\omega^{\\omega+1}}+\\omega}\\psi(\\Omega^\\Omega))\\,\n"
    . "\\psi(\\Omega^{\\Omega(\\omega^\\omega+\\omega)} 3)\\\\\n";
print "\\end{array}\\]\n\\par\n";
print "\\end{center}\n";

print "\\vfill\\end{document}\n";
