24.11 Test Recursive Structures

643test Recursive 643  (626)  644
testRecursive1(): () == {
        macro {
                E == EmptySetSpecies;
                X == SingletonSpecies;
                + == Plus;
                * == Times;
        }

        A(L: LabelType): CombinatorialSpecies L == (E + X*A*A)(L) add;
        check(
            A,
            [1, 1, 4, 30, 336, 5040],
            [1, 1, 2, 5, 14, 42],
            [1, 1, 2, 5, 14, 42]
        );
}

Uses CombinatorialSpecies 71, EmptySetSpecies 83, LabelType 62, Plus 166a, SingletonSpecies 84, and Times 175a.
644test Recursive 643+   (626)  643  645
testRecursive1b(): () == {
        macro {
                X == SingletonSpecies;
                + == Plus;
                * == Times;
        }

        A(L: LabelType): CombinatorialSpecies L == (X + A*A)(L) add;
        check(
            A,
            [0, 1, 2, 12, 120, 1680, 30240],
            [0, 1, 1, 2, 5, 14, 42],
            [0, 1, 1, 2, 5, 14, 42]
        );
        import from String, List String;
        import from Integer, List Integer, SetSpecies Integer;
        assertEquals(List String,
            ["(1, (2, 3))", "(1, (3, 2))", "(2, (1, 3))", "(2, (3, 1))",
                "((1, 2), 3)", "((2, 1), 3)", "(3, (1, 2))", "(3, (2, 1))",
                "((1, 3), 2)", "((3, 1), 2)", "((2, 3), 1)", "((3, 2), 1)"],
            [(s: StringBuffer := new();
                    tw := s::TextWriter;
                    (tw << e)$A(Integer);
                    string s) for e in structures(set [1,2,3])$A(Integer)]);

        assertEquals(List String,
            ["(1, (2, 3))", "((1, 2), 3)"],
            [(s: StringBuffer := new();
              tw := s::TextWriter;
              (tw << e)$A(Integer);
              string s) for e in isomorphismTypes(set [1,2,3])$A(Integer)]);
}

Uses CombinatorialSpecies 71, Integer 66, LabelType 62, Plus 166a, SetSpecies 117, SingletonSpecies 84, String 65, and Times 175a.

For the following test can be compared with the output of the following Mathematica commands.

rhxSolve[eqs_] :=  
  Module[{L, X, Sol, S, s, sc}, L = {0, 1, 2, 3, 4, 5, 6, 7, 8};  
    X = {x, 0, 8}; Sol = Solve[eqs, {A[x], B[x]}];  
    S[i_] := Sol[[1, i, 2]];  
    s[i_] := Series[S[i], X];  
    sc[i_, n_] := SeriesCoefficient[s[i], n];  
    ME[i_] := Map[#!*sc[i, #] &, L];  
    MO[i_] := Map[sc[i, #] &, L];  
    {SE1[ME[1]], SO1[MO[1]], SE2[ME[2]], SO2[MO[2]]}  
  ]  
testRecursive2 = rhxSolve[{A[x] == 1 + x*B[x]^3, B[x] == 1 + x*A[x]^2}]  
testRecursive2b = rhxSolve[{A[x] == x + B[x]^3, B[x] == x + A[x]^2}]

645test Recursive 643+   (626)  644  646
testRecursive2(): () == {
        macro {
                E == EmptySetSpecies;
                X == SingletonSpecies;
                + == Plus;
                * == Times;
        }

        A(L: LabelType): CombinatorialSpecies L == (E + X*B*B*B)(L) add;
        B(L: LabelType): CombinatorialSpecies L == (E + X*A*A)(L) add;

        check(
            A,
            [1, 1, 6, 54, 816, 15840, 393120, 11728080, 410901120],
            [1, 1, 3, 9, 34, 132, 546, 2327, 10191],
            [1, 1, 3, 9, 34, 132, 546, 2327, 10191]
        );
        check(
            B,
            [1, 1, 4, 42, 576, 11400, 277920, 8270640, 288288000],
            [1, 1, 2, 7, 24, 95, 386, 1641, 7150],
            [1, 1, 2, 7, 24, 95, 386, 1641, 7150]
        );
}

Uses CombinatorialSpecies 71, EmptySetSpecies 83, LabelType 62, Plus 166a, SingletonSpecies 84, and Times 175a.
646test Recursive 643+   (626)  645  647
testRecursive2b(): () == {
        macro {
                X == SingletonSpecies;
                + == Plus;
                * == Times;
        }

        A(L: LabelType): CombinatorialSpecies L == (X + B*B*B)(L) add;
        B(L: LabelType): CombinatorialSpecies L == (X + A*A)(L) add;

        check(
            A,
            [0, 1, 0, 6, 72, 360, 5040, 151200, 2540160],
            [0, 1, 0, 1, 3, 3, 7, 30, 63],
            [0, 1, 0, 1, 3, 3, 7, 30, 63]
        );
        check(
            B,
            [0, 1, 2, 0, 48, 720, 5040, 100800, 3024000],
            [0, 1, 1, 0, 2, 6, 7, 20, 75],
            [0, 1, 1, 0, 2, 6, 7, 20, 75]
        );
}

Uses CombinatorialSpecies 71, LabelType 62, Plus 166a, SingletonSpecies 84, and Times 175a.

Look for fiWords on http://mupad-combinat.sourceforge.net/doc/en/index/guidedTour-predefinedCombinatorialClasses.html.

647test Recursive 643+   (626)  646  648
testRecursive3(): () == {
        macro {
                E == EmptySetSpecies;
                X == SingletonSpecies;
                + == Plus;
                * == Times;
        }

        F(L: LabelType): CombinatorialSpecies L == (E+X+F*X+F*X*X)(L) add;

        check(
            F,
            [1, 2, 6, 30, 192, 1560, 15120, 171360, 2217600],
            [1, 2, 3, 5, 8, 13, 21, 34, 55],
            [1, 2, 3, 5, 8, 13, 21, 34, 55]
        );
}

Uses CombinatorialSpecies 71, EmptySetSpecies 83, LabelType 62, Plus 166a, SingletonSpecies 84, and Times 175a.

Solving the order equations for the generating series of the following system gives the orders (5,4,2) for (A,B,C).

648test Recursive 643+   (626)  647
testRecursive4(): () == {
        macro {
                X == SingletonSpecies;
                X2 == X*X;
                X5 == X2*X2*X;
                + == Plus;
                * == Times;
        }

        import from Integer, Array Integer;
        A(L: LabelType): CombinatorialSpecies L == (X5 + B*B)(L) add;
        B(L: LabelType): CombinatorialSpecies L == (X5 + C*C)(L) add;
        C(L: LabelType): CombinatorialSpecies L == (X2 + C*C + A*A)(L) add;

        check(
            A,
            [0, 0, 0, 0, 0, 120, 0, 0, 40320, 725760, 18144000],
            [0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 5],
            [0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 5]
        );
        check(
            B,
            [0, 0, 0, 0, 24, 120, 1440, 0, 201600, 0, 50803200],
            [0, 0, 0, 0, 1, 1, 2, 0, 5, 0, 14],
            [0, 0, 0, 0, 1, 1, 2, 0, 5, 0, 14]
        );
        check(
            C,
            [0, 0, 2, 0, 24, 0, 1440, 0, 201600, 0, 54432000],
            [0, 0, 1, 0, 1, 0, 2, 0, 5, 0, 15],
            [0, 0, 1, 0, 1, 0, 2, 0, 5, 0, 15]
        );
}

Uses Array 599, CombinatorialSpecies 71, Integer 66, LabelType 62, Plus 166a, SingletonSpecies 84, and Times 175a.