
// Make newform 63.15.m.a in Magma, downloaded from the LMFDB on 04 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_63_m();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_63_m_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_63_15_m_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_63_15_m_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, -1, 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_63_m();"
function MakeCharacter_63_m()
    N := 63;
    order := 6;
    char_gens := [29, 10];
    v := [6, 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_63_m_Hecke();"
function MakeCharacter_63_m_Hecke(Kf)
    N := 63;
    order := 6;
    char_gens := [29, 10];
    char_values := [[1, 0], [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 := 15;
    raw_aps := [[0, 0], [0, 0], [0, 0], [-511048, -438987], [0, 0], [18227657, -36455314], [0, 0], [-962292282, 481146141], [0, 0], [0, 0], [-2921176405, -2921176405], [0, -77194104697], [0, 0], [375951067189, 0], [0, 0], [0, 0], [0, 0], [-1086939977872, 543469988936], [-7623508989083, 7623508989083], [0, 0], [4663928820033, 4663928820033], [0, 17998954613629], [0, 0], [0, 0], [-93054982142192, 186109964284384], [0, 0], [-277369541296694, 138684770648347], [0, 0], [-267167157500809, 267167157500809], [0, 0], [-104016445742557, 0], [0, 0], [0, 0], [-1019969206761869, 2039938413523738], [0, 0], [2355113278757954, -2355113278757954], [-2450802702230232, -2450802702230232], [0, -1518633172942442], [0, 0], [0, 0], [0, 0], [3796797015058215, -7593594030116430], [0, 0], [19934613462490511, -19934613462490511], [0, 0], [-14104942672700936, -14104942672700936], [-11416039276365194, 0], [-30576776767454568, 61153553534909136], [0, 0], [9584866574206322, -4792433287103161], [0, 0], [0, 0], [14322122385480224, 14322122385480224], [0, 0], [0, 0], [0, 0], [0, 0], [-246707389252266320, 123353694626133160], [-121527305869906343, 121527305869906343], [0, 0], [34569112010031277, 34569112010031277], [0, 0], [189428773907547755, -378857547815095510], [0, 0], [598879723768391730, -299439861884195865], [0, 0], [0, -806948574492421021], [-330843006620733959, 0], [0, 0], [573182597538598040, -1146365195077196080], [0, 0], [0, 0], [-419435436042178605, -419435436042178605], [0, 187031830761188353], [619030991645833429, 0], [0, 0], [0, 0], [-2300975036559239810, 1150487518279619905], [0, 0], [-1435036830733921121, -1435036830733921121], [0, 0], [-4208909144182404961, 0], [0, 0], [-3258486593798633015, 6516973187597266030], [-5305487564045016432, 2652743782022508216], [0, 0], [0, 0], [0, -5281136561470258177], [0, 0], [364971237305658587, 0], [0, 0], [0, 0], [7081100467975359659, -7081100467975359659], [0, 0], [0, -11724742312997476549], [0, 0], [0, 0], [0, 0], [-8868601274927349130, 4434300637463674565], [0, -27127535167605468719], [6517486797482829674, 0], [0, 0], [0, 0], [0, 0], [-35525150806465003139, 35525150806465003139], [22338731452327682455, 22338731452327682455], [0, 0], [0, 0], [0, 0], [-15525448986469312849, 31050897972938625698], [-69821842730900983926, 34910921365450491963], [-62245750687098751466, 62245750687098751466], [0, 0], [25671626134663247165, 25671626134663247165], [57270498816431628674, 0], [0, 0], [-48965479113066627587, 97930958226133255174], [0, 0], [0, 0], [0, 0], [58629394351349180919, 58629394351349180919], [14924548336372614553, 0], [0, 0], [0, 0], [-154139778587736460442, 77069889293868230221], [0, 0], [0, -170916357885542484694], [0, 0], [-30993010931949569867, 61986021863899139734], [-254773164306247790546, 127386582153123895273], [240730296854142413989, -240730296854142413989], [0, 0], [0, -199975187456626883941], [234099107758614585142, 0], [0, 0], [-94764802237493694495, 189529604474987388990], [0, 0], [164324805352118270608, 164324805352118270608], [0, 0], [0, 0], [-144398894127219819696, 288797788254439639392], [0, 0], [-503723684507178662402, 503723684507178662402], [0, 0], [307868984239089153111, 307868984239089153111], [0, 0], [-158151426765622749585, 316302853531245499170], [0, 0], [-694427894946577470560, 347213947473288735280], [0, 0], [0, -517897041519948447578], [0, 0], [819681513662255962093, 0], [0, 0], [-963559920326221087477, 963559920326221087477], [0, 0], [0, -1077841982796373956997], [0, 0], [575710422235128770695, -1151420844470257541390], [0, 0], [0, 0], [0, 0], [-1459688801815531953517, 0], [0, 0], [0, 0], [0, 0], [1452578409583457834987, -1452578409583457834987], [148701213032783142697, 148701213032783142697]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_63_m_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_63_15_m_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_63_15_m_a(:prec:=2)
    chi := MakeCharacter_63_m();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 15));
    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_63_15_m_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_63_15_m_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_63_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,15,sign)));
    Vf := Kernel([<2,R![0, 1]>],Snew);
    return Vf;
end function;