
// Make newform 1200.3.l.u in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1200_l();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_l_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_3_l_u();".
// 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_3_l_u();".
// 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 := [9, 0, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -1, 0, 1], [-2, 2, 1, 0], [2, 1, -1, 0]];
    Rf_basisdens := [1, 1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_l();"
function MakeCharacter_1200_l()
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    v := [2, 2, 1, 2];
    // 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_l_Hecke();"
function MakeCharacter_1200_l_Hecke(Kf)
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 0], [1, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 0, 0], [1, 0, 0, 1], [0, 0, 0, 0], [2, 1, -2, -2], [0, 2, 0, 0], [10, 0, 0, 0], [0, -4, -2, 4], [-8, 2, -4, -4], [0, 1, -2, 4], [0, 0, 4, -8], [-8, 0, 0, 0], [22, 4, -8, -8], [0, -8, -2, 4], [14, 3, -6, -6], [0, 5, -10, 20], [0, -4, -2, 4], [0, -12, 4, -8], [-16, 4, -8, -8], [-82, 3, -6, -6], [0, 10, -4, 8], [-50, 4, -8, -8], [28, -2, 4, 4], [0, -3, -2, 4], [0, -8, -4, 8], [-74, -4, 8, 8], [0, 24, -8, 16], [74, -7, 14, 14], [0, 7, 2, -4], [20, -12, 24, 24], [0, 24, -14, 28], [-106, 3, -6, -6], [0, -14, -24, 48], [0, 32, -6, 12], [-56, -14, 28, 28], [0, 24, 26, -52], [-56, -4, 8, 8], [10, 12, -24, -24], [74, 9, -18, -18], [0, -31, -18, 36], [0, -32, 22, -44], [0, 28, -28, 56], [38, 24, -48, -48], [0, -6, 20, -40], [130, -4, 8, 8], [0, 12, 18, -36], [-92, -6, 12, 12], [172, 12, -24, -24], [14, -9, 18, 18], [0, 29, 14, -28], [98, -24, 48, 48], [0, -28, 10, -20], [0, -84, -8, 16], [104, -36, 72, 72], [0, -18, -24, 48], [0, -72, -2, 4], [0, 37, -18, 36], [0, -96, -18, 36], [400, -8, 16, 16], [-302, -12, 24, 24], [0, -48, 34, -68], [170, -3, 6, 6], [0, 80, 26, -52], [74, 9, -18, -18], [0, 78, 28, -56], [274, 24, -48, -48], [0, -44, 22, -44], [28, -44, 88, 88], [-98, 24, -48, -48], [0, -47, 22, -44], [206, 32, -64, -64], [0, 8, -90, 180], [0, 52, 8, -16], [-22, -51, 102, 102], [454, -4, 8, 8], [88, -18, 36, 36], [0, -101, -14, 28], [0, 8, 86, -172], [214, 0, 0, 0], [0, -32, 88, -176], [-460, 12, -24, -24], [0, -80, 36, -72], [224, -52, 104, 104], [0, -126, 36, -72], [-146, 36, -72, -72], [-428, -18, 36, 36], [0, -9, -38, 76], [0, -40, -62, 124], [130, -72, 144, 144], [0, 80, 32, -64], [110, 59, -118, -118], [0, -61, 34, -68], [0, 148, 16, -32], [-178, -9, 18, 18], [0, 22, 120, -240], [-80, 6, -12, -12], [0, -57, -30, 60], [0, -32, 52, -104], [0, 64, -40, 80], [350, -65, 130, 130], [-262, -8, 16, 16], [-262, 5, -10, -10], [0, -80, 50, -100], [0, 65, -66, 132], [0, -40, 2, -4], [220, 8, -16, -16], [226, 80, -160, -160], [0, -67, 14, -28], [0, 72, 6, -12], [0, -128, -24, 48], [680, 36, -72, -72], [-826, -1, 2, 2], [-302, -56, 112, 112], [0, 180, 46, -92], [-128, -22, 44, 44], [304, 84, -168, -168], [0, -32, 30, -60], [-514, -9, 18, 18], [0, -49, -38, 76], [0, 116, -10, 20], [0, -100, 36, -72], [-520, -4, 8, 8], [-602, -44, 88, 88], [0, -52, -126, 252], [0, 31, 98, -196], [-932, 0, 0, 0], [0, -88, -146, 292], [110, 40, -80, -80], [0, -76, -32, 64], [-634, 51, -102, -102], [334, 36, -72, -72], [880, 6, -12, -12], [0, -53, 34, -68], [-920, 28, -56, -56], [370, -52, 104, 104], [0, -8, -80, 160], [-514, 24, -48, -48], [0, -188, 26, -52], [914, 61, -122, -122], [0, -76, -34, 68], [0, 64, -124, 248], [124, -12, 24, 24], [0, -32, 30, -60], [-190, -75, 150, 150], [0, 179, 34, -68], [68, -28, 56, 56], [0, -96, 80, -160], [58, 120, -240, -240], [0, -232, 42, -84], [376, 10, -20, -20], [0, 83, 10, -20], [-662, 44, -88, -88], [0, -72, -66, 132], [386, 133, -266, -266], [0, 59, 114, -228], [926, -61, 122, 122], [0, 154, 52, -104], [268, -54, 108, 108], [0, 8, 158, -316], [370, -4, 8, 8], [0, 272, -72, 144], [0, -47, -210, 420], [0, 224, -38, 76], [-1438, -43, 86, 86], [0, -262, -8, 16], [0, 28, -126, 252], [0, 175, 42, -84], [280, -160, 320, 320], [-446, 48, -96, -96], [350, 88, -176, -176], [0, -332, -54, 108], [0, -172, -84, 168], [242, 0, 0, 0], [0, -102, -164, 328], [502, -52, 104, 104], [-1340, 54, -108, -108], [0, -272, 100, -200], [436, 108, -216, -216], [0, -24, 96, -192], [-970, -9, 18, 18], [-76, 60, -120, -120], [1022, 15, -30, -30], [0, -146, -56, 112], [-602, 0, 0, 0], [0, 244, 26, -52], [0, 57, 110, -220], [0, -136, -52, 104], [70, -84, 168, 168], [-1174, -3, 6, 6], [-580, -116, 232, 232], [0, -70, 292, -584], [-854, 104, -208, -208], [0, -131, -114, 228], [-1556, 68, -136, -136], [0, -168, -62, 124], [0, -185, 98, -196], [0, -252, 58, -116], [-736, -76, 152, 152], [-674, 88, -176, -176], [0, 24, 26, -52], [0, -59, 86, -172], [0, -56, -164, 328], [136, 4, -8, -8], [-110, -8, 16, 16], [-910, -112, 224, 224], [0, -392, 20, -40], [0, -184, -98, 196], [-1412, -10, 20, 20], [0, 243, -46, 92], [0, 176, -148, 296], [100, -228, 456, 456], [1762, -36, 72, 72], [0, -152, 178, -356], [-778, -21, 42, 42], [0, -49, 218, -436], [0, 380, -88, 176], [296, 92, -184, -184], [-910, -39, 78, 78], [0, 112, 96, -192], [0, -165, -246, 492], [0, -236, -102, 204], [392, -164, 328, 328], [-1412, -6, 12, 12], [0, -280, 228, -456], [578, -135, 270, 270], [0, 53, -282, 564], [-292, 156, -312, -312], [0, -180, 182, -364], [0, -252, -48, 96], [-922, 111, -222, -222], [0, 310, 88, -176], [-1022, 32, -64, -64], [592, 18, -36, -36], [-296, -168, 336, 336], [0, -112, -174, 348], [-478, -19, 38, 38], [0, -231, 262, -524], [1316, -100, 200, 200], [0, 100, -298, 596], [0, -24, -188, 376], [0, 46, -4, 8], [0, 7, 234, -468], [2284, -72, 144, 144], [14, 55, -110, -110], [-610, -96, 192, 192], [0, -40, 110, -220], [0, -216, -40, 80], [-190, -191, 382, 382], [0, -98, 24, -48], [-872, 174, -348, -348], [0, -313, -158, 316], [-530, -72, 144, 144], [0, -312, -96, 192], [0, 453, 158, -316], [1724, -84, 168, 168], [0, -152, 118, -236], [0, 200, 52, -104], [2078, 64, -128, -128], [1490, 105, -210, -210], [0, -272, 38, -76], [-182, -144, 288, 288], [722, 157, -314, -314], [0, 423, 202, -404], [-1582, 104, -208, -208], [-710, 68, -136, -136], [0, 404, 38, -76], [1696, -18, 36, 36], [0, 416, -68, 136], [0, -456, -152, 304], [134, -45, 90, 90], [0, 288, 178, -356], [-1786, -56, 112, 112], [1238, 131, -262, -262], [346, -36, 72, 72], [-764, 42, -84, -84], [-2150, -144, 288, 288], [638, 175, -350, -350], [0, -133, -6, 12], [1166, -24, 48, 48], [560, -132, 264, 264], [0, -78, -400, 800], [0, 225, 110, -220], [-1088, 84, -168, -168], [0, -99, -266, 532], [-382, -96, 192, 192], [-118, -315, 630, 630], [0, 42, 228, -456], [2050, -108, 216, 216], [0, -52, -94, 188], [-44, 10, -20, -20], [0, 40, 218, -436], [0, 592, -30, 60], [0, -241, -110, 220], [0, -20, -114, 228], [0, 378, 16, -32], [-698, 228, -456, -456], [0, -136, -138, 276], [1168, 128, -256, -256], [0, -104, -62, 124], [0, -88, -44, 88], [-334, 89, -178, -178], [646, -8, 16, 16], [0, 432, -282, 564], [844, -186, 372, 372]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1200_l_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_3_l_u();".
// 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_3_l_u(:prec:=4)
    chi := MakeCharacter_1200_l();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_l_u();".
// 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_3_l_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1200_l();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![-86, -4, 1]>,<11,R![72, 0, 1]>,<13,R![-10, 1]>],Snew);
    return Vf;
end function;