
// Make newform 63.3.j.a in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_63_j();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_63_j_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_3_j_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_3_j_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 := [9, 33, 118, 17, 12, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [2241, -66, -236, 288, -24, 2], [36, 5310, 604, 540, -45, 44], [99, 354, 16, 36, -3, 2], [5337, 9819, 2281, 843, -30, 83], [-1335, 3130, 249, 422, -62, 32]];
    Rf_basisdens := [1, 1449, 1449, 63, 1449, 483];
    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_63_j();"
function MakeCharacter_63_j()
    N := 63;
    order := 6;
    char_gens := [29, 10];
    v := [1, 4];
    // 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_j_Hecke();"
function MakeCharacter_63_j_Hecke(Kf)
    N := 63;
    order := 6;
    char_gens := [29, 10];
    char_values := [[1, 0, 1, 0, 0, 0], [-1, 0, -1, 0, 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 := 3;
    raw_aps := [[-1, 0, 0, 0, -1, -1], [3, 0, 0, 0, 0, 0], [-4, 0, -2, 0, -1, 0], [0, 0, 1, 1, 1, -1], [0, 2, 2, -1, 0, 2], [6, 0, 5, -1, 2, 1], [10, 2, 5, 2, 6, 0], [-7, 0, -7, 2, 0, 0], [2, -1, 1, -1, -3, 0], [-12, 0, -6, 0, -1, 0], [-14, -4, 0, 0, 2, -2], [-10, 0, -3, -5, -14, -7], [5, -8, 5, 4, 0, 10], [8, 3, 38, -3, 4, 8], [6, -2, -24, 4, 18, 18], [2, -3, 1, -3, -15, 0], [-23, 3, -34, -6, -6, -6], [10, -8, 0, 0, 6, -6], [-35, 7, 0, 0, -6, 6], [10, -2, 32, 4, -6, -6], [-36, 7, 18, -7, -18, -36], [31, -3, 0, 0, -2, 2], [16, 9, 8, 9, 0, 0], [-20, -10, 28, 5, 0, 8], [-24, 1, 42, -1, -12, -24], [-17, -16, 12, 8, 0, -5], [-14, 12, -94, -12, -7, -14], [28, 2, -38, -1, 0, -10], [-22, -8, -108, 8, -11, -22], [28, -26, -44, 13, 0, -16], [0, 2, 0, 0, -24, 24], [4, 11, 2, 11, 32, 0], [-22, 26, 4, -13, 0, -18], [-14, 0, -36, 7, 44, 22], [-90, 9, -45, 9, -69, 0], [-45, 0, -50, 30, 10, 5], [-84, -2, 0, 0, 4, -4], [43, 0, 17, 8, 52, 26], [-27, 24, 38, -12, 0, 11], [30, 10, 92, -20, -16, -16], [28, -11, 14, -11, 46, 0], [-47, -5, 0, 0, -30, 30], [-68, -4, -216, 8, 40, 40], [11, -15, 0, 0, -18, 18], [-76, 20, -40, -40, -56, -56], [-46, -2, 132, 2, -23, -46], [210, 0, 206, 23, 8, 4], [22, -13, 133, 13, 11, 22], [84, 18, -12, -9, 0, 72], [-70, -21, 65, 21, -35, -70], [129, -16, -99, 8, 0, 30], [-59, 8, -40, -4, 0, -99], [-9, 0, 1, -30, -20, -10], [71, 5, 158, -10, -8, -8], [-226, 22, -113, 22, -20, 0], [-106, 34, 105, -17, 0, -1], [80, -12, 40, -12, 45, 0], [-72, 0, -49, 23, -46, -23], [120, 0, 101, -43, 38, 19], [-156, 19, -78, 19, 70, 0], [-63, 7, 0, 0, -8, 8], [151, -24, -120, 12, 0, 31], [-87, -41, 0, 0, 16, -16], [93, 23, 66, -46, 60, 60], [-351, 27, 0, 0, -4, 4], [6, -2, -24, 4, 18, 18], [21, -21, 0, 0, -94, 94], [-290, 0, -244, -7, -92, -46], [-187, -5, -186, 10, -94, -94], [-170, 53, -143, -53, -85, -170], [107, 28, -129, -14, 0, -22], [14, 98, -37, -49, 0, -23], [88, 0, 21, 67, 134, 67], [-106, 0, 194, 0, -53, -106], [-225, -67, 0, 0, -36, 36], [224, -40, 112, -40, -21, 0], [-90, -90, 111, 45, 0, 21], [-245, 0, -246, -20, 2, 1], [412, 1, 206, 1, 0, 0], [413, 15, 0, 0, 0, 0], [6, -50, -72, 25, 0, -66], [-2, 3, -361, -3, -1, -2], [240, 4, 120, 4, 27, 0], [-351, 67, 0, 0, 10, -10], [147, 89, 0, 0, -6, 6], [-61, -39, 22, 78, -72, -72], [285, -21, 462, 42, 54, 54], [462, -32, 0, 0, -56, 56], [188, 18, 94, 18, 37, 0], [284, 0, 287, -1, -6, -3], [266, -50, -134, 25, 0, 132], [83, -60, -190, 30, 0, -107], [246, -76, 100, 76, 123, 246], [-73, 16, 5, -8, 0, -68], [-68, 62, 349, -62, -34, -68], [360, 0, 336, 0, 192, 192], [82, 15, 41, 15, -65, 0], [454, 14, 227, 14, -84, 0], [280, 0, 218, -67, 124, 62], [526, 0, 505, 27, 42, 21], [-160, -31, 100, 31, -80, -160], [-264, -10, -132, -10, -49, 0], [-73, 25, 146, -50, -146, -146], [-332, 56, -504, -112, -80, -80], [271, -51, 0, 0, 106, -106], [-248, -34, -179, 34, -124, -248], [594, 18, 297, 18, -88, 0], [-203, -72, 353, 36, 0, 150], [-10, 22, -128, -44, 54, 54], [160, -134, 513, 134, 80, 160], [166, -72, 200, 72, 83, 166], [154, -70, 10, 70, 77, 154], [316, 86, -352, -43, 0, -36], [283, 0, 191, -64, 184, 92], [444, 78, 0, 0, 14, -14], [-343, 80, 187, -40, 0, -156], [-171, 0, -137, 18, -68, -34], [198, 75, 99, 75, 31, 0], [-154, 5, -77, 5, 123, 0], [-98, -36, -49, -36, -312, 0], [530, 16, 0, 0, -46, 46], [136, -4, 115, 4, 68, 136], [-202, 54, -248, -108, -78, -78], [710, 36, 355, 36, -12, 0], [21, -81, 0, 0, 146, -146], [368, -16, 508, 32, 114, 114], [-211, -97, 0, 0, -50, 50], [47, 148, -128, -74, 0, -81], [126, -36, 380, 36, 63, 126], [194, -50, -186, 50, 97, 194], [-132, 166, -219, -166, -66, -132], [348, -74, -69, 37, 0, 279], [14, -88, 436, 88, 7, 14], [-56, -102, 0, 0, 40, -40], [-1040, 7, -520, 7, 72, 0], [99, 0, 49, -6, 100, 50], [278, -67, 139, -67, -53, 0], [-779, 19, 0, 0, -120, 120], [17, 92, -150, -46, 0, -133], [-744, -47, -372, -47, -42, 0], [638, 108, 0, 0, 84, -84], [183, 1, 110, -2, 128, 128], [236, 86, 0, 0, -2, 2], [373, -17, -22, 34, 384, 384], [218, 123, 245, -123, 109, 218], [-368, -92, -184, -92, -157, 0], [30, -60, -562, 60, 15, 30], [-217, -20, 21, 10, 0, -196], [-32, 114, -469, -114, -16, -32], [-165, 68, 132, -34, 0, -33], [58, 5, 175, -5, 29, 58], [-5, 1, 110, -2, -60, -60], [-203, 75, 0, 0, 280, -280], [1066, 3, 533, 3, -203, 0], [-202, 0, -212, 15, 20, 10], [226, -63, 113, -63, 39, 0], [-217, 0, -308, 54, 182, 91], [-731, -25, -986, 50, -238, -238], [239, 17, 0, 0, -182, 182], [-264, -40, -592, 80, 32, 32], [556, -88, 736, 176, 188, 188], [-289, 53, 6, -106, -292, -292], [219, 0, 314, -58, -190, -95], [-193, 88, 175, -44, 0, -18], [161, 67, 118, -134, 102, 102], [-225, 60, -180, -30, 0, -405], [414, -138, 50, 138, 207, 414], [496, 0, 413, 137, 166, 83]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_63_j_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_63_3_j_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_3_j_a(:prec:=6)
    chi := MakeCharacter_63_j();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_j_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_3_j_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_63_j();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![147, 0, 163, 0, 25, 0, 1]>],Snew);
    return Vf;
end function;