
// Make newform 10.11.c.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_10_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_10_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_10_11_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_10_11_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 := [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_10_c();"
function MakeCharacter_10_c()
    N := 10;
    order := 4;
    char_gens := [7];
    v := [3];
    // 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_10_c_Hecke();"
function MakeCharacter_10_c_Hecke(Kf)
    N := 10;
    order := 4;
    char_gens := [7];
    char_values := [[0, 1]];
    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 := 11;
    raw_aps := [[16, 16], [-183, 183], [-1875, -2500], [-8407, -8407], [-173398, 0], [-232623, 232623], [1880033, 1880033], [0, -1101560], [-5228263, 5228263], [0, -24790840], [-10065998, 0], [56387913, 56387913], [-153003598, 0], [59372457, -59372457], [172339353, 172339353], [196385617, -196385617], [0, 694068920], [906185802, 0], [-962073967, -962073967], [-3120877598, 0], [-636339263, 636339263], [0, -1967996640], [-5183822103, 5183822103], [0, 7771383280], [-640361247, -640361247], [2024343802, 0], [-1502524583, 1502524583], [1418116193, 1418116193], [0, -6212959480], [-17951089823, 17951089823], [13062106073, 13062106073], [-52022190598, 0], [-16381452687, -16381452687], [0, -26148958120], [0, 4313626200], [113868406402, 0], [10442780793, 10442780793], [47830549577, -47830549577], [-11828130167, -11828130167], [-116377366063, 116377366063], [0, -181010928440], [133000325402, 0], [131043806002, 0], [212792488257, -212792488257], [79024621353, 79024621353], [0, 452657290800], [137994639002, 0], [-126053692263, 126053692263], [115268207473, 115268207473], [0, -329124036840], [-99794809503, 99794809503], [0, -39562237920], [-814270609598, 0], [453171013002, 0], [1335788872993, 1335788872993], [-912065175623, 912065175623], [0, 1043476578440], [719444957202, 0], [-862576489527, -862576489527], [-789299999598, 0], [-660245134903, 660245134903], [179236397457, -179236397457], [-1101553373007, -1101553373007], [5311384908802, 0], [-840078380223, 840078380223], [-1166347782567, -1166347782567], [-4820422072598, 0], [-3685497774687, -3685497774687], [-5384498447647, -5384498447647], [0, 8126579105800], [5492737385217, -5492737385217], [0, -5913045067280], [1753598840633, 1753598840633], [4257172389937, -4257172389937], [0, -7209991060040], [-6938318326503, 6938318326503], [0, 11251772045880], [-7946276374247, -7946276374247], [8810722856802, 0], [0, -10016009696880], [0, 14824395641640], [-4685003428198, 0], [23912644242002, 0], [-741822675103, 741822675103], [0, 20970445584080], [-23890926418743, 23890926418743], [0, -20453537970400], [6885206622993, 6885206622993], [-17203850090998, 0], [-467191847623, 467191847623], [16276805236433, 16276805236433], [0, -32675924919040], [3916166452713, 3916166452713], [-1669454762198, 0], [0, 26911278389000], [23550122149017, -23550122149017], [0, -8636213892280], [-62732628945198, 0], [1489512083337, -1489512083337], [-89711512202198, 0], [33995478931953, 33995478931953], [9519145028793, 9519145028793], [36365147631177, -36365147631177], [0, -28285933224560], [2192009421002, 0], [-29757859348127, -29757859348127], [46033254317313, 46033254317313], [-6177137322943, 6177137322943], [0, -58030996850800], [124750357414802, 0], [-93418378294407, -93418378294407], [14280173155377, -14280173155377], [-4177403266767, -4177403266767], [0, 40797747527640], [80355572220802, 0], [94347712104802, 0], [19892461882857, -19892461882857], [59728871309353, 59728871309353], [-98707248211983, 98707248211983], [0, 58068882437320], [-153137463592198, 0], [-87535971111263, 87535971111263], [1594524311273, 1594524311273], [-56579574527703, 56579574527703], [4985576867802, 0], [-180303257628598, 0], [0, -311542786085480], [0, -165068133312160], [215313966939273, 215313966939273], [-278786616982703, 278786616982703], [0, -205170755975320], [159047209676857, -159047209676857], [-140007869581998, 0], [70788089995593, 70788089995593], [-284952799093198, 0], [0, -359991010845760], [140031716617137, -140031716617137], [299888126528113, 299888126528113], [-214433006126247, -214433006126247], [0, 371569006907920], [425888727868202, 0], [473944086862202, 0], [-393378088647463, 393378088647463], [-232821673186527, -232821673186527], [0, -97333684556440], [0, 382848375860080], [425917526760817, -425917526760817], [-358496526204207, -358496526204207], [0, -730888426844680], [148513147065977, -148513147065977], [-38560860981927, -38560860981927], [-411263967729598, 0], [-634115560920503, 634115560920503], [715240745272713, 715240745272713], [462742823901793, 462742823901793], [-241311535745198, 0], [0, -374681845717360], [0, 447350621276960], [-234215056777487, -234215056777487], [-38052568047798, 0], [12656670587953, 12656670587953], [-773543568285183, 773543568285183], [-557903577968567, -557903577968567], [101087413375402, 0], [-713366306105727, -713366306105727], [-514730602885703, 514730602885703], [1133562513594802, 0], [655684564697353, 655684564697353]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_10_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_10_11_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_10_11_c_a(:prec:=2)
    chi := MakeCharacter_10_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 11));
    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_10_11_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_10_11_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([<3,R![66978, 366, 1]>],Snew);
    return Vf;
end function;