
// Make newform 7.10.a.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_7_10_a_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_7_10_a_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 := [2016, -426, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [276, 25, -1], [-288, 11, 1]];
    Rf_basisdens := [1, 6, 6];
    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_7_a();"
function MakeCharacter_7_a()
    N := 7;
    order := 1;
    char_gens := [3];
    v := [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;

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


// To make the newform (type ModFrm), type "MakeNewformModFrm_7_10_a_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_7_10_a_b(:prec:=3)
    chi := MakeCharacter_7_a();
    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_7_10_a_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_7_10_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![19080, -1326, -21, 1]>],Snew);
    return Vf;
end function;