text:
############################################################################
##
##  loadfp.gi                     IRREDSOL                  Burkhard Höfling
##
##  Copyright © 2003–2016 Burkhard Höfling
##

IRREDSOL_DATA.FP := [];
IRREDSOL_DATA.FP_INDEX := [];
IRREDSOL_DATA.FP_LOADED := [];

############################################################################
##
#F  IsAvailableAbsolutelyIrreducibleSolubleGroupFingerprintIndex(<n>, <q>)
##
InstallGlobalFunction(IsAvailableAbsolutelyIrreducibleSolubleGroupFingerprintIndex,
    function(n, q)

        if not IsPosInt(n) or not IsPosInt(q) or not IsPPowerInt(q)  then
            Error("n and q must be positive integers and q must be a prime power");
        fi;

        return TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintIndex(n, q);

    end);

############################################################################
##
#F  TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintIndex(<n>, <q>)
##
InstallGlobalFunction(TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintIndex,
    function(n, q)

        local pathname;

        if not IsPosInt(n) or not IsPosInt(q) or not IsPPowerInt(q)  then
            Error("n and q must be positive integers and q must be a prime power");
        fi;

        if n = 1 then
            return true;
        fi;

        if not IsBound(IRREDSOL_DATA.FP_INDEX[n]) then
            IRREDSOL_DATA.FP_INDEX[n] := [];
        fi;

        if not IsBound(IRREDSOL_DATA.FP_INDEX[n][q]) then
            pathname := Concatenation("fp/gl_", String(n), "_",String(q),".idx");

            Info(InfoIrredsol, 2, "Reading data file ", pathname);

            if not ReadPackage("irredsol", pathname) then
                return false;
            fi;

            if not IsBound(IRREDSOL_DATA.FP_INDEX[n][q]) then
                Error("Panic: reading data file didn't define required data");
            fi;
            MakeImmutable(IRREDSOL_DATA.FP_INDEX[n][q]);

        fi;
        return true;
    end);

###########################################################################
##
#F  LoadAbsolutelyIrreducibleSolubleGroupFingerprintIndex(<n>, <q>)
##
InstallGlobalFunction(LoadAbsolutelyIrreducibleSolubleGroupFingerprintIndex,
    function(n, q)

        if not IsPosInt(n) or not IsPosInt(q) or not IsPPowerInt(q)  then
            Error("n and q must be positive integers and q must be a prime power");
        fi;

        if not TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintIndex(n, q) then
            Error("Panic: missing fingerprint index file for GL(",n,", ", q, ")");
        fi;
    end);

############################################################################
##
#F  IsAvailableAbsolutelyIrreducibleSolubleGroupFingerprintData(<n>, <q>, <index>)
##
InstallGlobalFunction(IsAvailableAbsolutelyIrreducibleSolubleGroupFingerprintData,

    function(n, q, index)
        if not IsPosInt(n) or not IsPosInt(q) or not IsPPowerInt(q)
            or not IsPosInt(index) then
                Error("n, q, and index must be positive integers",
                    ", and q must be a prime power");
        fi;

        return TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintData(n, q, index);
    end);

###########################################################################
##
#F  TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintData(<n>, <q>, <index>)
##
InstallGlobalFunction(TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintData,
    function(n, q, index)

        local pathname, i;

        if not IsPosInt(n) or not IsPosInt(q) or not IsPPowerInt(q) or not IsPosInt(index) then
            Error("n and q must be positive integers, q must be a prime power, and pos must be a positive integer");
        fi;

        if n = 1 then
            return; # group is unique, up to conjugacy - no information stored
        fi;

        if not IsBound(IRREDSOL_DATA.FP[n]) then
            IRREDSOL_DATA.FP[n] := [];
        fi;

        if not IsBound(IRREDSOL_DATA.FP[n][q]) then
            IRREDSOL_DATA.FP[n][q] := [];
        fi;

        if not IsBound(IRREDSOL_DATA.FP_LOADED[n]) then
            IRREDSOL_DATA.FP_LOADED[n] := [];
        fi;

        if not IsBound(IRREDSOL_DATA.FP_LOADED[n][q]) then
            IRREDSOL_DATA.FP_LOADED[n][q] := [];
        fi;

        if not IsBound(IRREDSOL_DATA.FP_LOADED[n][q][index]) then

            Unbind(IRREDSOL_DATA.FP_LOADED[n][q][index]); # if anything fails during loading
                # we won't have inconsistencies

            pathname := Concatenation("fp/gl_", String(n), "_",String(q),"_", String(index),".fp");

            Info(InfoIrredsol, 2, "Reading fingerprint file ", pathname);
            if not ReadPackage("irredsol", pathname) then
                return false;
            fi;

            for i in [1..Length(IRREDSOL_DATA.FP_INDEX[n][q][2])] do
                if IRREDSOL_DATA.FP_INDEX[n][q][2][i] = index then
                    MakeImmutable(IRREDSOL_DATA.FP[n][q][i]);
                fi;
            od;
            IRREDSOL_DATA.FP_LOADED[n][q][index] := true;

        fi;
        return true;
    end);

###########################################################################
##
#F  LoadAbsolutelyIrreducibleSolubleGroupFingerprintData(<n>, <q>, <index>)
##
InstallGlobalFunction(LoadAbsolutelyIrreducibleSolubleGroupFingerprintData,
    function(n, q, index)

        if not IsPosInt(n) or not IsPosInt(q) or not IsPPowerInt(q) or not IsPosInt(index) then
            Error("n and q must be positive integers, q must be a prime power, and pos must be a positive integer");
        fi;
        if not TryLoadAbsolutelyIrreducibleSolubleGroupFingerprintData(n, q, index) then
            Error("Panic: ", index, "-th fingerprint file for GL(",n,", ", q, ") is missing");
        fi;
    end);

###########################################################################
##
#F  LoadAbsolutelyIrreducibleSolubleGroupFingerprints(<n>, <q>)
##
##  see IRREDSOL documentation
##
InstallGlobalFunction(LoadAbsolutelyIrreducibleSolubleGroupFingerprints,
    function(n, q)

        local i;

        if not IsPosInt(n) or not IsPosInt(q) or not IsPPowerInt(q) then
            Error("n and q must be positive integers, and q must be a prime power");
        fi;

        LoadAbsolutelyIrreducibleSolubleGroupFingerprintIndex(n, q);
        for i in Set(IRREDSOL_DATA.FP_INDEX[n][q][2]) do
            LoadAbsolutelyIrreducibleSolubleGroupFingerprintData(n, q, i);
        od;
    end);

###########################################################################
##
#F  UnloadAbsolutelyIrreducibleSolubleGroupFingerprints(<arg>)
##
##  see IRREDSOL documentation
##
InstallGlobalFunction(UnloadAbsolutelyIrreducibleSolubleGroupFingerprints,
    function(arg)

        local UnbindIfBound;

        UnbindIfBound := function(arg)
            local data, i;

            data := arg[1];
            i := 2;
            while i < Length(arg)  do
                if not IsBound(data[arg[i]]) then
                    return false;
                fi;
                data := data[arg[i]];
                i := i + 1;
            od;
            if IsBound(data[arg[i]]) then
                Unbind(data[arg[i]]);
                return true;
            else
                return false;
            fi;
        end;

        if Length(arg) = 0 then
            IRREDSOL_DATA.FP := [];
            IRREDSOL_DATA.FP_INDEX := [];
            IRREDSOL_DATA.FP_LOADED := [];
        elif IsPosInt(arg[1]) and Length(arg) = 1 then
            if arg[1] > 1 then
                UnbindIfBound(IRREDSOL_DATA.FP, arg[1]);
                UnbindIfBound(IRREDSOL_DATA.FP_INDEX, arg[1]);
                UnbindIfBound(IRREDSOL_DATA.FP_LOADED, arg[1]);
            fi;
        elif Length(arg) = 2 and IsPosInt(arg[1]) and IsPPowerInt(arg[2]) and arg[2] <> 1 then
            if arg[1] > 1 then
                UnbindIfBound(IRREDSOL_DATA.FP, arg[1], arg[2]);
                UnbindIfBound(IRREDSOL_DATA.FP_INDEX, arg[1], arg[2]);
                UnbindIfBound(IRREDSOL_DATA.FP_LOADED, arg[1], arg[2]);
            fi;
        else
            Error("Usage: `UnloadAbsolutelyIrreducibleSolubleGroupFingerprints( [n [, q]] )'");
        fi;
    end);

############################################################################
##
#F  LoadedAbsolutelyIrreducibleSolubleGroupFingerprints()
##
##  see IRREDSOL documentation
##
InstallGlobalFunction(LoadedAbsolutelyIrreducibleSolubleGroupFingerprints,
    function()

        local n, p, data, fields;

        data := [];
        for n in [1..Length(IRREDSOL_DATA.FP)] do
            if IsBound(IRREDSOL_DATA.FP[n]) then
                fields := [];
                for p in [1..Length(IRREDSOL_DATA.FP[n])] do
                    if IsBound(IRREDSOL_DATA.FP[n][p]) then
                        Add(fields, p);
                    fi;
                od;
                if not IsEmpty(fields) then
                    Add(data, [n, fields]);
                fi;
            fi;
        od;
        return data;
    end);

###########################################################################
##
#E
##

ext: gi

max_stars_repo_name: fingolfin/irredsol

max_issues_repo_name: fingolfin/irredsol

max_forks_repo_name: fingolfin/irredsol


text:
Balanced := function(L)
    local c, r;
    r := 0;
    for c in L do
        if c = ']' then
            r := r - 1;
            if r < 0 then
                return false;
            fi;
        elif c = '[' then
            r := r + 1;
        fi;
    od;
    return r = 0;
end;

Balanced("");
# true

Balanced("[");
# false

Balanced("]");
# false

Balanced("[]");
# true

Balanced("][");
# false

Balanced("[[][]]");
# true

Balanced("[[[]][]]]");
# false

ext: gap

max_issues_repo_name: seanwallawalla-forks/RosettaCodeData

max_forks_repo_name: seanwallawalla-forks/RosettaCodeData


text:
# Displays the preimages of all the subgroups of the quotient isomorphic to a given group.
# INPUT:
# > G - a finite group which is the domain of the quotient map
# > N - a normal subgroup of G with respect to we take the quotient G/N
# > H - a group which is supposed to be isomorphic to a subgroup of G/N
# OUTPUT:
# > displays the preimages grouped in the corresponding conjugacy classes of subgroups of G
InstallGlobalFunction( AMPreImagesQuotientSubgroup, function( G, N, H )

end );

max_stars_repo_name: piotrmizerka/math-work-tools

max_issues_repo_name: piotrmizerka/math-work-tools

max_forks_repo_name: piotrmizerka/math-work-tools


text:
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details

#F RDFT(<size>) -  Discrete Fourier Transform of a real sequence, non-terminal
#F This is an obsolete real DFT, please use PRDFT
#F
#F Definition: (n x n)-matrix
#F              [ cos(2*pi*k*l/n) | k = 0...Int(n/2), l = 0...n-1 ]
#F              [-sin(2*pi*k*l/n) | k = Int(n/2)+1...n, l = 0...n-1 ]
#F              k and l are row and column indices, respectively.
#F Note:      RDFT is obtained using symmetry of  DFT on a real-valued input
#F Example:   RDFT(8)
Class(RDFT, NonTerminal, rec(
    abbrevs := [ N -> Checked(IsInt(N), N > 1, [N]) ],
    terminate := self >> When(self.params[1]=2, F(2),
	Mat(ApplyFunc(Global.RDFT, self.params))),
    isReal := True,
    dims := self >> [self.params[1], self.params[1]],
    SmallRandom := () -> Random([2, 3, 4, 6, 8, 12, 16, 24, 32])
));

RulesFor(RDFT, rec(
    #F RuleRDFT_Base: RDFT_2 = F_2
    #F
    RDFT_Base := rec (
	info             := "RDFT_2 -> F_2",
	isApplicable     := L -> L[1] = 2,
	allChildren      := L -> [ [ ] ],
	rule            := (L, C) -> F(2)
    ),

    #F RDFT_Trigonometric: 1984
    #F
    #F   RDFT_n = (DCT1_(n/2+1) dirsum DST1_(n/2-1)) * blocks
    #F
    #F   Wang:
    #F     Fast Algorithms for the Discrete W Transform and the
    #F     Discrete Fourier Transform.
    #F     IEEE Trans. on ASSP, 1984, pp. 803--814
    #F   Britanak/Rao:
    #F     The fast generalized discrete Fourier transforms: A unified
    #F     approach to the discrete sinusoidal transforms computation.
    #F     Signal Processing 79, 1999, pp. 135--150
    #F
    RDFT_Trigonometric := rec (
	info             := "RDFT_n -> DCT1_(n/2+1), DST1_(n/2-1)",
        # 3 can occur only once
	isApplicable     := L -> L[1] >= 4 and
	    (Is2Power(L[1]) or (L[1] mod 3 = 0 and Is2Power(L[1]/3))),

        allChildren := L -> [[ DCT1(L[1]/2 + 1), DST1(L[1]/2 - 1) ]],

	rule := (L, C) -> let(N := L[1], exp := 1,
	   DirectSum(C[1], exp * C[2] ^ J(N/2 - 1)) *
	   DirectSum(I(1), blocks1(N - 1)))
    ),

    #F RDFT_CT_Radix2  : Cooley-Tukey Radix-2
    #F
    #F   RDFT_n = M * (F_2 tensor)' * (I_n/2 dirsum rots^(L^n/2_n/4)) *
    #F            (I_2 tensor RDFT_n/2) * L^n_2
    #F
    #F   derived by hand; the prime denotes that one F_2 is missing in the
    #F   tensor product.
    #F
    RDFT_CT_Radix2 := rec (
	info             := "RDFT_n -> RDFT_n/2",
	isApplicable     := L -> let(N := L[1], exp := 1,
	    N mod 4 = 0 and exp = 1 and
	    (IsPrimePowerInt(N) or       # 3 or 5 can occur only once
		(N mod 3 = 0 and IsPrimePowerInt(N/3)) or
		(N mod 5 = 0 and IsPrimePowerInt(N/5)))),

	allChildren := L -> [[ RDFT(L[1]/2) ]],

	rule := (P, C) -> let(N := P[1], i := Ind(N/4-1),
	    When(N=4,
		Conjugate(DirectSum(F(2),I(2)), L(4, 2)) *
		Tensor(I(2), C[1]) * L(4, 2),

		monomial1(N) *
		DirectSum(Tensor(I(N/4), F(2)), I(2), Tensor(I(N/4 - 1), F(2))) ^ L(N, N/2) *
		DirectSum(
		    I(N/2),
		    DirectSum(I(1), IterDirectSum(i, Rot(fdiv(i+1, N/2))), I(1)*(-1)^(N/2))
		       ^ M(N/2,N/4)) *
		Tensor(I(2), C[1]) * L(N, 2)))
    ),

    #F RDFT_toDCT2: 1989
    #F
    #F   RDFT_n = M * DCT2_n * P,   n odd
    #F
    #F   Chan/Ho: Efficient Index-Mapping for Computing the Discrete Cosine Transform
    #F     Electronics Letters, 1989
    #F   see also:
    #F   Heideman: Computation of an Odd-Length DCT from a Real-Valued DFT of
    #F     the same Length, IEEE Trans. Sig. Proc. 40(1), 1992
    #F
    RDFT_toDCT2 := rec(
	info             := "RDFT_n -> DCT2_n",
	switch           := false,
	isApplicable     := L ->
            # we block odd sizes larger than 3 for now
	    L[1] mod 2 = 1 and L[1] >= 3,

        allChildren := L ->  [[ DCT2(L[1]) ]],

	rule := (L, C) -> let(N := L[1],
	    Diag(LambdaList([0..N-1], i -> (-1)^i)) *
	    OS(N, 2) *
	    C[1] *
	    perm7(N))
    )
));