
// Make newform 30.12.c.a in Magma, downloaded from the LMFDB on 03 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_30_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_30_c_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_30_12_c_a();".
// 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_30_12_c_a();".
// 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 := [79524, 0, 565, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 283, 0, 1], [132822, 753, 470, 1], [-199233, 988, -705, 1]];
    Rf_basisdens := [1, 282, 94, 141];
    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_30_c();"
function MakeCharacter_30_c()
    N := 30;
    order := 2;
    char_gens := [11, 7];
    v := [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_30_c_Hecke();"
function MakeCharacter_30_c_Hecke( : Kf := false)
    N := 30;
    order := 2;
    char_gens := [11, 7];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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 := 12;
    raw_aps := [[0, 32, 0, 0], [0, -243, 0, 0], [1205, -1820, 55, -10], [0, -13869, 23, 23], [-112892, 121, -121, 121], [0, 438273, -3519, -3519], [0, -1977349, -36729, -36729], [9089472, -5148, 5148, -5148], [0, 2113168, -124884, -124884], [63644238, -760617, 760617, -760617], [-76514324, -1326006, 1326006, -1326006], [0, 23438241, -2498263, -2498263], [219522406, 584914, -584914, 584914], [0, 384028308, -6829568, -6829568], [0, -1577082014, 667422, 667422], [0, 1565832903, 9864603, 9864603], [-3890738300, 27147415, -27147415, 27147415], [-65598982, 24739056, -24739056, 24739056], [0, -9864323874, -23000342, -23000342], [114355008, 8776386, -8776386, 8776386], [0, 9260874918, -95903234, -95903234], [-366791292, 109382778, -109382778, 109382778], [0, 35382136588, 81373464, 81373464], [-17218627270, -438921160, 438921160, -438921160], [0, 60723668736, -232833128, -232833128], [-83095080682, -692239009, 692239009, -692239009], [0, 13136230953, -6032083, -6032083], [0, 27091144056, 1029292596, 1029292596], [11915195930, 68893470, -68893470, 68893470], [0, -44866650177, 1416210651, 1416210651], [0, 161859573171, -363410281, -363410281], [-678315451308, 896310435, -896310435, 896310435], [0, -172143211059, 2657767761, 2657767761], [215886972176, -3162017214, 3162017214, -3162017214], [-462349993718, -1013998493, 1013998493, -1013998493], [-625759879292, -5437280394, 5437280394, -5437280394], [0, 814329054531, -2090729861, -2090729861], [0, -776222377902, -9685670386, -9685670386], [0, 16885842876, -15528165336, -15528165336], [0, -1948570878307, -9696861927, -9696861927], [1709862359332, 18168310327, -18168310327, 18168310327], [-4455020559250, 140151618, -140151618, 140151618], [-2892851626680, 22481117478, -22481117478, 22481117478], [0, 1194105495258, 22912165162, 22912165162], [0, 1065566344261, 9994144041, 9994144041], [5757007281060, 5614341210, -5614341210, 5614341210], [-1929611434368, -6011691930, 6011691930, -6011691930], [0, 2583411259293, -46229987375, -46229987375], [0, 4028018994596, -18579921120, -18579921120], [656971784254, -84280470426, 84280470426, -84280470426], [0, 10327066966013, 48459114081, 48459114081], [-13398615170968, -12734755258, 12734755258, -12734755258], [4842396661534, -116351488908, 116351488908, -116351488908], [10512728402124, -15879917553, 15879917553, -15879917553], [0, 7783978142181, 149968988937, 149968988937], [0, -7064432094752, 43900929468, 43900929468], [-31835823071598, -31145203143, 31145203143, -31145203143], [18141102513580, 171637298658, -171637298658, 171637298658], [0, 4802229474021, 44737600709, 44737600709], [16907497666902, -89856104580, 89856104580, -89856104580], [0, -38244855140262, -89860118170, -89860118170], [0, -99412076517, 127926717255, 127926717255], [0, 71554179315456, -117860663844, -117860663844], [83081487184392, 49743538230, -49743538230, 49743538230], [0, -85784786203302, 90113107498, 90113107498], [0, 62539355991551, -120389433669, -120389433669], [76583275144456, -59209725276, 59209725276, -59209725276], [0, 98311797829566, 105937422758, 105937422758], [0, 34059370862736, -583112457972, -583112457972], [3847146203414, -258346670436, 258346670436, -258346670436], [0, 41401386342653, -545500761903, -545500761903], [-35209836273864, 577652186076, -577652186076, 577652186076], [0, 17991658225251, 336651973511, 336651973511], [0, -59851344854907, 527164898589, 527164898589], [-71777310751544, 290382232626, -290382232626, 290382232626], [0, 79697126549438, 480586734810, 480586734810], [211252115391242, -407417329273, 407417329273, -407417329273], [0, 120689154078561, 1032779172905, 1032779172905], [-242287239156910, 187918038038, -187918038038, 187918038038], [30101231781622, 397912981662, -397912981662, 397912981662], [171938186729348, -956934443947, 956934443947, -956934443947], [-127032294399758, 878450703570, -878450703570, 878450703570], [-140385433280168, -438676206500, 438676206500, -438676206500], [0, -255114999443862, -1588946874566, -1588946874566], [102765183576804, 60723798714, -60723798714, 60723798714], [0, 412742328628008, -609937520076, -609937520076], [433031357440302, 950694142902, -950694142902, 950694142902], [0, 115651720725156, -3358438828708, -3358438828708], [-541654462716498, -1969085394135, 1969085394135, -1969085394135], [0, -608477020581177, 344156908251, 344156908251], [0, 300606596785776, 3448405586124, 3448405586124], [85453185374576, -2381593488454, 2381593488454, -2381593488454], [0, 426479973169041, -868958779899, -868958779899], [-550228795597212, 463058205771, -463058205771, 463058205771], [-153783220279080, -367324199280, 367324199280, -367324199280], [0, -28900561919622, 3250577162934, 3250577162934], [-124127210937954, 3797726912511, -3797726912511, 3797726912511], [104069890545962, 7793765753090, -7793765753090, 7793765753090], [0, -639339635831382, 2149883546102, 2149883546102], [570871849882630, -4681429334262, 4681429334262, -4681429334262], [0, 21665336565636, 1629607156976, 1629607156976], [0, -767965619707419, -1080512969103, -1080512969103], [0, 1945526309300048, -2638400151924, -2638400151924], [-42952382803402, -985250691322, 985250691322, -985250691322], [458382333996760, -5474810128212, 5474810128212, -5474810128212], [0, -593766514280304, -4301049189712, -4301049189712], [0, -1078339992227184, -4340973510180, -4340973510180], [0, 1638331079277783, -2088484192125, -2088484192125], [720999283012680, 1869331213380, -1869331213380, 1869331213380], [1395103424250422, -80221740030, 80221740030, -80221740030], [0, 799673361741981, 14812567755169, 14812567755169], [0, -979772329982277, -2580636368333, -2580636368333], [0, -977023542312949, -3123005769369, -3123005769369], [-670782458222480, 16876817583750, -16876817583750, 16876817583750], [2040729564516332, 12675212376750, -12675212376750, 12675212376750], [1395926293376206, 11867577150214, -11867577150214, 11867577150214], [0, -1481347846230642, 19005829498746, 19005829498746], [0, -2550262646617314, -6369636646710, -6369636646710], [0, -498501415633547, 13503459910329, 13503459910329], [-900339368913284, 6132640128781, -6132640128781, 6132640128781], [-522821951449102, -16457611568364, 16457611568364, -16457611568364], [0, 59944266636318, -21048986164962, -21048986164962], [0, 1792356723250871, 25757012746899, 25757012746899], [0, 174000662360188, -13693224937896, -13693224937896], [32749417359712, 21623862768120, -21623862768120, 21623862768120], [-1302994774909166, -32921739522743, 32921739522743, -32921739522743], [4523356940585118, -3516616559142, 3516616559142, -3516616559142], [-1169067192203224, -40052039136544, 40052039136544, -40052039136544], [0, -4040072106082479, -21126453585147, -21126453585147], [0, 1312094025180963, 45572985366611, 45572985366611], [2441943418793960, 41090054234220, -41090054234220, 41090054234220], [0, 3549803046318858, -3603187858554, -3603187858554], [-4071716113728436, 26205079879062, -26205079879062, 26205079879062], [0, -1620356108775219, 37777798795133, 37777798795133], [-10329297218745510, -9347442429522, 9347442429522, -9347442429522], [-7619073103677870, -21308731595190, 21308731595190, -21308731595190], [0, -1092674695439907, 34947403590321, 34947403590321], [0, -4005303639643134, 72659095115246, 72659095115246], [0, 255868356027611, 32475263694975, 32475263694975], [6554175572378634, 30667709074974, -30667709074974, 30667709074974], [-11001752845204712, 29124451222326, -29124451222326, 29124451222326], [-9013371457188550, 64851863919953, -64851863919953, 64851863919953], [0, 11143405759475943, 51415768671579, 51415768671579], [0, 10670692657712996, -51882140126160, -51882140126160], [-113057982696054, -52727624500734, 52727624500734, -52727624500734], [7758140879099560, 37873918601320, -37873918601320, 37873918601320], [0, 8743420645088103, -77717888656273, -77717888656273], [0, -851923508642769, -63680147896725, -63680147896725], [-2242021187624936, -99804777439446, 99804777439446, -99804777439446], [0, -6116718308529252, -48907678192920, -48907678192920], [0, 20256090023462571, 39782264349235, 39782264349235], [2857283281187262, 32733496471680, -32733496471680, 32733496471680], [0, 24051356115596838, 34119749889858, 34119749889858], [0, -1100717069518284, 13013154085680, 13013154085680], [0, -7709809755762144, -90756114920484, -90756114920484], [-16692429947868912, 6921132788976, -6921132788976, 6921132788976], [-8688248167329948, 89937271890882, -89937271890882, 89937271890882], [15622787692902510, 149089225079430, -149089225079430, 149089225079430], [0, 2794714426300716, -151007784418676, -151007784418676], [5426377000286494, 86919127101877, -86919127101877, 86919127101877], [0, -381404519671464, 67325845892148, 67325845892148], [0, -21929728357734997, -52003426304745, -52003426304745], [0, -2903749307987049, 234224735718379, 234224735718379], [-19794272252457204, -119203621179201, 119203621179201, -119203621179201], [0, 16133993906212071, 52439403415491, 52439403415491], [0, -6996265177655962, 210315525444450, 210315525444450], [24041489501778292, -27695404751850, 27695404751850, -27695404751850], [0, -19185630725481489, -49792834246521, -49792834246521]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_30_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_30_12_c_a();".
// 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_30_12_c_a(:prec:=4)
    chi := MakeCharacter_30_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_30_12_c_a();".
// 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_30_12_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_30_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<7,R![31477194981714496, 0, 414560372, 0, 1]>],Snew);
    return Vf;
end function;