
// Make newform 1200.4.f.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1200_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_f_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_4_f_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1200_4_f_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1200_f();"
function MakeCharacter_1200_f()
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    v := [2, 2, 2, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_f_Hecke();"
function MakeCharacter_1200_f_Hecke(Kf)
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    char_values := [[1, 0], [1, 0], [1, 0], [-1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 4;
    raw_aps := [[0, 0], [0, 3], [0, 0], [0, 24], [-52, 0], [0, -22], [0, -14], [-20, 0], [0, -168], [-230, 0], [288, 0], [0, -34], [122, 0], [0, -188], [0, -256], [0, 338], [100, 0], [742, 0], [0, 84], [328, 0], [0, 38], [-240, 0], [0, 1212], [-330, 0], [0, 866], [-1218, 0], [0, -88], [0, -36], [970, 0], [0, -1042], [0, -1936], [-732, 0], [0, -2214], [20, 0], [1330, 0], [1208, 0], [0, -3514], [0, -2068], [0, 24], [0, 618], [3340, 0], [-178, 0], [1888, 0], [0, -1922], [0, 2526], [-1160, 0], [4468, 0], [0, 6032], [0, -2636], [-4830, 0], [0, -2682], [2320, 0], [2002, 0], [-132, 0], [0, -7614], [0, -4888], [-1270, 0], [-1072, 0], [0, -5394], [2442, 0], [0, 2772], [0, -4542], [0, -5116], [2808, 0], [0, 7318], [0, 2246], [-1332, 0], [0, -11534], [0, -11956], [-4870, 0], [0, -10722], [120, 0], [0, -3936], [0, -3022], [-13340, 0], [0, -1008], [-9630, 0], [0, 7126], [-8718, 0], [10870, 0], [-9700, 0], [862, 0], [-15792, 0], [0, -11602], [-440, 0], [0, -10188], [13310, 0], [0, 3226], [6582, 0], [0, 15072], [0, -476], [-19680, 0], [0, 5944], [-10772, 0], [8140, 0], [0, -13768], [-22150, 0], [1562, 0], [0, -668], [-6138, 0], [0, 10484], [0, 3606], [0, 12252], [14550, 0], [25468, 0], [0, 12866], [0, 14844], [0, -20402], [10760, 0], [14282, 0], [0, -11056], [0, 16418], [0, -10374], [-5260, 0], [-21352, 0], [-29118, 0], [0, 5772], [0, 14264], [0, -6902], [20140, 0], [-3218, 0], [0, 7518], [0, -18114], [0, -23868], [-172, 0], [-22138, 0], [-3070, 0], [15600, 0], [0, -20696], [0, 30778], [11740, 0], [0, 2632], [20528, 0], [0, 21646], [18282, 0], [24190, 0], [0, 25698], [0, -33436], [0, -37594], [-4730, 0], [8748, 0], [44142, 0], [0, 3992], [0, 14444], [-42150, 0], [13400, 0], [0, 8658], [0, 42826], [-35900, 0], [0, -3088], [0, -35274], [25042, 0], [0, 12572], [0, 21864], [0, -31236], [-8272, 0], [20200, 0], [-31010, 0], [0, -39174], [-4138, 0], [0, -23676], [0, -18922], [0, -39656], [33228, 0], [0, -974], [0, -13608], [-13472, 0], [0, -3234], [13870, 0], [0, 1618], [-37020, 0], [-54938, 0], [16008, 0], [0, 36198], [2320, 0], [40950, 0], [-38052, 0], [23742, 0], [0, -5848], [26570, 0], [0, 2224], [59428, 0], [0, 25538], [0, -17254], [0, 50112], [-9550, 0], [0, -60474], [0, -52628], [39430, 0], [-5152, 0], [0, 50558], [0, -10268], [-28812, 0], [56422, 0], [0, -46476], [0, 37318], [12562, 0], [0, -24102], [0, -16254], [0, 58472], [44490, 0], [13968, 0], [0, -3474], [-49570, 0], [25140, 0], [0, 50886], [-39520, 0], [0, -30068], [-15450, 0], [8908, 0], [0, 21746], [-52018, 0], [0, -19848], [0, 524], [53880, 0], [-43078, 0], [0, 58784], [38322, 0], [0, -95096], [0, 21018], [17182, 0], [-47800, 0], [60990, 0], [0, -82208], [0, 27364], [-59630, 0], [0, -56202], [-76000, 0], [0, -76936], [-55572, 0], [0, -86262], [-16820, 0], [-62912, 0], [39322, 0], [0, -1948], [0, 105504], [-41970, 0], [0, -68942], [9540, 0], [-38232, 0], [0, 68892], [-75012, 0], [0, -54968], [97770, 0], [0, 110478], [113800, 0], [0, -25136], [118148, 0], [-7180, 0], [0, 122272], [0, 2086], [-11198, 0], [0, -22536], [-112410, 0], [0, -38582], [-84180, 0], [-27218, 0], [0, 24844], [0, -1794], [0, 86186], [0, -123728], [0, -65516], [-81470, 0], [0, 32058], [0, 88866], [5980, 0], [-67030, 0], [-61078, 0], [0, 75572], [0, -12382], [-50218, 0], [0, -98716], [0, 61558], [42240, 0], [0, -17454], [0, 122072], [0, 65964], [98970, 0], [66522, 0], [-3852, 0], [0, 62192], [1928, 0], [0, 108904], [60222, 0], [0, 73404], [-87312, 0], [0, -4402], [0, -77874], [96680, 0], [-20130, 0], [-15658, 0], [0, -67196], [0, 55638], [-100212, 0], [0, 110698], [-66150, 0], [26848, 0], [0, 122898], [-102300, 0], [0, -49196], [0, -92442], [0, 96886], [-9200, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1200_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_4_f_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_1200_4_f_b(:prec:=2)
    chi := MakeCharacter_1200_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1200_4_f_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_1200_4_f_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1200_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![576, 0, 1]>,<11,R![52, 1]>],Snew);
    return Vf;
end function;