
// Make newform 49.10.c.d in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_49_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_49_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_49_10_c_d();".
// 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_49_10_c_d();".
// 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 := [4064256, -858816, 183492, -3606, 427, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-18279850176, 356408640, -76149180, -1825733, -177205, 415], [30551662512, -387326016, 82754892, -4738111, 192577, -451], [-41319936, -785896236, 6865794, -1828841, 4283, -4331], [-934101504, -24361417764, 155211966, -41343799, -629099, -97909], [6773760, 97141857, -1125540, 299810, 4339, 710]];
    Rf_basisdens := [1, 464953608, 464953608, 3719628864, 1859814432, 12915378];
    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_49_c();"
function MakeCharacter_49_c()
    N := 49;
    order := 3;
    char_gens := [3];
    v := [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_49_c_Hecke();"
function MakeCharacter_49_c_Hecke(Kf)
    N := 49;
    order := 3;
    char_gens := [3];
    char_values := [[0, 0, 0, 1, 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 := 10;
    raw_aps := [[0, 0, 0, 7, 0, -1], [-28, 1, 1, -28, 1, 1], [0, 0, 0, 518, -13, 43], [0, 0, 0, 0, 0, 0], [1148, -650, -658, 1148, -658, -650], [-6594, 3017, -175, 0, 0, 0], [-338898, -3030, -1574, -338898, -1574, -3030], [0, 0, 0, 74284, 2437, -15371], [0, 0, 0, 628544, -3808, -24200], [1360606, 54866, 18914, 0, 0, 0], [-956480, -55698, 70302, -956480, 70302, -55698], [0, 0, 0, 465206, 60522, 209418], [-4806886, -163478, -131894, 0, 0, 0], [-20543724, 121982, 65366, 0, 0, 0], [0, 0, 0, -3456320, 83238, -534778], [-22500870, -1553376, 450352, -22500870, 450352, -1553376], [14196700, 2231195, 49659, 14196700, 49659, 2231195], [0, 0, 0, 63915614, -844773, 589107], [85058596, -3939816, -47712, 85058596, -47712, -3939816], [98838168, 3499356, -526260, 0, 0, 0], [-114737770, 9544844, -118516, -114737770, -118516, 9544844], [0, 0, 0, -320137552, 1679412, -7475532], [-366839060, -4479559, -1977367, 0, 0, 0], [0, 0, 0, 168938826, 1815976, -10612104], [-215832750, 33276782, -864850, 0, 0, 0], [-175124950, 9312157, -6270235, -175124950, -6270235, 9312157], [0, 0, 0, -517502104, 6873462, 17946342], [0, 0, 0, 608192004, 8208844, -39197964], [-10196606, -1462446, -6778926, -10196606, -6778926, -1462446], [1456992938, -25708886, 704914, 0, 0, 0], [646426440, -13198108, 12416012, 0, 0, 0], [0, 0, 0, 1109519516, -11460427, 54159589], [1163642102, 14101060, 40567268, 1163642102, 40567268, 14101060], [-5452351212, -56250397, 7278131, 0, 0, 0], [0, 0, 0, -1049208202, 20322260, 111063028], [2090928784, 180999876, -13591284, 2090928784, -13591284, 180999876], [7546938770, -37158337, 50001239, 7546938770, 50001239, -37158337], [0, 0, 0, 2809417100, 60027198, -216387354], [2370604376, 132391378, 92651314, 0, 0, 0], [0, 0, 0, 3556276318, -121594395, -192302851], [-4679521644, -79923444, 10041556, -4679521644, 10041556, -79923444], [-12182618602, 123030201, -84064911, 0, 0, 0], [0, 0, 0, 7564416496, -92650740, 358336124], [-4193166698, 296404746, 109446162, -4193166698, 109446162, 296404746], [-1044069738, 356422164, 146823012, 0, 0, 0], [-7775640488, 748413702, 35045046, -7775640488, 35045046, 748413702], [-5084983188, -255977680, 221074280, 0, 0, 0], [-8959631632, 220743684, 98663796, 0, 0, 0], [17290910084, 897007147, -89141989, 17290910084, -89141989, 897007147], [0, 0, 0, -13496753578, -458931171, 500018037], [0, 0, 0, 12893305194, 274790488, -1556666280], [5383177928, 1317170848, -517478024, 0, 0, 0], [-28492185218, -313800486, -431266758, -28492185218, -431266758, -313800486], [3118364004, 1838260347, -553785813, 0, 0, 0], [0, 0, 0, 96506412002, -134738008, -92049656], [-54233527768, 2039554756, -411736108, -54233527768, -411736108, 2039554756], [-14470203678, 1139234307, 481952059, -14470203678, 481952059, 1139234307], [0, 0, 0, -16445892064, -308601768, 556573704], [41701567978, 1295373696, -297000480, 41701567978, -297000480, 1295373696], [60731571994, 1493343152, -399991312, 0, 0, 0], [-2183767460, -435232461, -423882381, -2183767460, -423882381, -435232461], [29722533974, -1618396745, -509126513, 0, 0, 0], [40912279884, 706669061, 909882197, 0, 0, 0], [159254962216, -4287155032, -1022133048, 159254962216, -1022133048, -4287155032], [0, 0, 0, -12286108982, -1046029718, -969666326], [0, 0, 0, -168906803954, -735598668, 78171428], [0, 0, 0, -45968391308, -2765137466, 4251579310], [-13486829830, -5721254658, 220982454, 0, 0, 0], [-146836160996, 344698922, 1478583666, -146836160996, 1478583666, 344698922], [-99704829378, -1176007483, -983282083, 0, 0, 0], [-57347344306, -271332032, -3119021968, -57347344306, -3119021968, -271332032], [0, 0, 0, -105198692592, 1541162644, -8345003892], [-198570902656, -8002657228, 2574141956, -198570902656, 2574141956, -8002657228], [0, 0, 0, 118372717078, 1829708692, 10539003124], [149485441380, -40593070, 6653440010, 0, 0, 0], [0, 0, 0, -46217048080, -1284629338, -663388634], [419001589706, -2795739554, 1075626398, 419001589706, 1075626398, -2795739554], [0, 0, 0, 11488061102, -3815230467, -4648453851], [0, 0, 0, 92833081418, -2365592530, -2754036314], [-457847724698, 23895954762, 3641413434, -457847724698, 3641413434, 23895954762], [-305931218404, 22336510651, -1759027781, 0, 0, 0], [-229810690618, 2077218360, -4575621960, 0, 0, 0], [423893978760, -14253102408, 4944663472, 423893978760, 4944663472, -14253102408], [-395245203150, -4927649734, 2818804394, 0, 0, 0], [0, 0, 0, -100441021688, 4385700544, -12650593808], [0, 0, 0, -173884857020, -571445448, 17515090256], [351981434562, 12885001752, 9229258584, 0, 0, 0], [0, 0, 0, 1134555470258, 2326103934, 3643968390], [-724820539730, -9953581687, -3653043583, 0, 0, 0], [451768337120, 35034710256, -1921856832, 0, 0, 0], [0, 0, 0, -402370101588, -11341683191, -408629031], [1047626098400, 22024210510, 496857950, 1047626098400, 496857950, 22024210510], [-334461780688, 30240560120, 4844509712, -334461780688, 4844509712, 30240560120], [-286436335372, -55500291224, 8022145936, 0, 0, 0], [0, 0, 0, 148285775708, -20260808736, 21194911128], [-547398820920, 15469064436, -8065343580, 0, 0, 0], [0, 0, 0, 1444601390078, 6705267101, -13346869787], [-674777766474, -58917566322, 1725999262, -674777766474, 1725999262, -58917566322], [0, 0, 0, -1133563459084, 12865732713, 46758410217], [0, 0, 0, -1093628229890, 2382916060, 11593843708], [1848071315148, 18206633690, -3027219118, 0, 0, 0], [232168779906, 10225383204, -26046817580, 232168779906, -26046817580, 10225383204], [1764738857812, -31139926999, -10770612663, 1764738857812, -10770612663, -31139926999], [0, 0, 0, 2194098553906, -4462954314, -35149511314], [-781355582980, 83542406102, 26035063166, -781355582980, 26035063166, 83542406102], [-1151917665458, 12522515160, -37655286360, -1151917665458, -37655286360, 12522515160], [3393169481044, -15041451649, -3743843089, 0, 0, 0], [0, 0, 0, 189267720978, -19458573812, 4105755564], [-4139549865080, -25335368680, 6716733240, -4139549865080, 6716733240, -25335368680], [-2758512013782, -111209313544, 20119527176, 0, 0, 0], [0, 0, 0, 437824544416, 54712996864, -15504967232], [-440831618150, -79001940786, -6918491202, -440831618150, -6918491202, -79001940786], [-2937098052334, 26554812718, 10860815014, 0, 0, 0], [820805060908, 75721000083, 30860171763, 820805060908, 30860171763, 75721000083], [1624500571416, 115406775764, -21111739180, 0, 0, 0], [1593695109062, 36134967394, -10067049958, 1593695109062, -10067049958, 36134967394], [5415613098588, 20433816599, 9194964695, 0, 0, 0], [-586438102824, -13906398666, 43511047462, -586438102824, 43511047462, -13906398666], [0, 0, 0, 3616840291694, -29393672098, -39695691890], [-1816063341860, -94226963950, -9364390294, 0, 0, 0], [-2644906814662, 154405141745, -3237519655, -2644906814662, -3237519655, 154405141745], [-6803559030910, -6531973644, -14332938060, 0, 0, 0], [0, 0, 0, 2255203958182, 46655444361, -101680180111], [-1292190802308, -111992896224, 18118236136, -1292190802308, 18118236136, -111992896224], [0, 0, 0, -3118224539668, -60084064515, -17468934195], [589656379230, 161627368518, -1658129130, 0, 0, 0], [0, 0, 0, 3317663048630, -14828858814, 153560498370], [0, 0, 0, -5337579270240, -16365607670, 167240841930], [7661380614888, -198080967490, -30779337442, 0, 0, 0], [0, 0, 0, 7605507159614, 36844226595, 21403866555], [-2929981462604, 54065992506, -99955751070, -2929981462604, -99955751070, 54065992506], [-4065972133648, -48942306812, 67270736428, 0, 0, 0], [0, 0, 0, -2628718900136, -57646531040, 85083653752], [4584647698710, -178071369238, -31390670374, 0, 0, 0], [0, 0, 0, 4355095151498, -65605150834, 76738035886], [-5362997268622, -196718206062, 99030112818, 0, 0, 0], [-12265396652838, -16013359599, 19798346569, -12265396652838, 19798346569, -16013359599], [11131862131348, -131092607169, -48668472369, 11131862131348, -48668472369, -131092607169], [-3329293568818, 40976144629, 66374180509, 0, 0, 0], [4438334382510, -63591879630, 17232311866, 4438334382510, 17232311866, -63591879630], [-3110250381868, 45537036825, -116999818215, 0, 0, 0], [0, 0, 0, 10563188415094, 42805497672, -21656722648], [2225581331512, 414445754136, -63932745912, 2225581331512, -63932745912, 414445754136], [-1395606578700, 472112596452, 76927040988, 0, 0, 0], [1100070604514, -240205609531, 58761605981, 1100070604514, 58761605981, -240205609531], [-3214450380344, -82561983154, -78042202210, 0, 0, 0], [-3261979684474, -251727911883, -178191979875, 0, 0, 0], [-10194775973242, -150775920854, 56294497274, -10194775973242, 56294497274, -150775920854], [0, 0, 0, 9484371805412, 230001630363, -112654046133], [0, 0, 0, -3267820234896, -148496379164, -32972787660], [0, 0, 0, -4093668716578, 92045722986, 396080680554], [-9447184076862, 113617603596, 140545625724, 0, 0, 0], [11310986987036, 260641653132, 131545110900, 0, 0, 0], [0, 0, 0, -4810052367736, -140522951722, -284909683274], [4465912621996, -128034242076, -132916677348, 4465912621996, -132916677348, -128034242076], [-776274555320, 137163986708, 36364998572, 0, 0, 0], [0, 0, 0, 12197824958312, 6862701720, 356477315592], [0, 0, 0, -904370187518, -71014735938, -38683602418], [-5288787099414, 177982402388, 182921194484, 0, 0, 0], [19712465153122, 309744041069, -107365613067, 19712465153122, -107365613067, 309744041069], [0, 0, 0, 353912373052, 95781334530, -496514284246], [2667773776026, 470935834152, 35449375752, 0, 0, 0], [-13369332923952, -361890959920, -206353785064, 0, 0, 0], [0, 0, 0, -3944840249868, 167377757485, -98404661235], [-21643379653490, -391347106492, -113713391484, -21643379653490, -113713391484, -391347106492], [-4980874310104, 1065671717650, -202106619070, -4980874310104, -202106619070, 1065671717650], [9462695969440, 1362169007592, -170929805592, 9462695969440, -170929805592, 1362169007592], [13956742164442, 938287285545, -145091371263, 13956742164442, -145091371263, 938287285545]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_49_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_49_10_c_d();".
// 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_49_10_c_d(:prec:=6)
    chi := MakeCharacter_49_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_49_10_c_d();".
// 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_49_10_c_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_49_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![364046400, 25300080, 2158956, 10314, 1767, 21, 1]>,<3,R![9144576, 39299904, 169150032, -1085616, 20052, 84, 1]>],Snew);
    return Vf;
end function;