
// Make newform 1200.3.l.q in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1200_l();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_l_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_1200_3_l_q();".
// 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_1200_3_l_q();".
// 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 := [5, 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_1200_l();"
function MakeCharacter_1200_l()
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    v := [2, 2, 1, 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_1200_l_Hecke();"
function MakeCharacter_1200_l_Hecke(Kf)
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    char_values := [[1, 0], [1, 0], [-1, 0], [1, 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 := [[0, 0], [2, -1], [0, 0], [-8, 0], [0, 4], [12, 0], [0, 14], [-6, 0], [0, -2], [0, 12], [-34, 0], [44, 0], [0, 8], [28, 0], [0, 2], [0, 18], [0, 44], [74, 0], [92, 0], [0, -24], [56, 0], [-78, 0], [0, 46], [0, 8], [-32, 0], [0, -68], [104, 0], [0, 66], [-74, 0], [0, 18], [16, 0], [0, -36], [0, 78], [-118, 0], [0, -44], [-34, 0], [-92, 0], [68, 0], [0, -30], [0, 34], [0, 116], [-166, 0], [0, 96], [32, 0], [0, -2], [114, 0], [6, 0], [-272, 0], [0, -110], [-154, 0], [0, 82], [0, -80], [-206, 0], [0, -12], [0, -18], [0, 94], [0, 60], [398, 0], [-292, 0], [0, 24], [-52, 0], [0, -174], [492, 0], [0, 216], [-568, 0], [0, -274], [-202, 0], [368, 0], [0, 114], [118, 0], [0, -14], [0, 24], [352, 0], [132, 0], [394, 0], [0, -34], [0, -124], [-652, 0], [0, -80], [206, 0], [0, -92], [-38, 0], [0, -272], [272, 0], [-366, 0], [0, -258], [0, 192], [104, 0], [0, 228], [-96, 0], [0, 66], [0, 256], [-648, 0], [0, -60], [-486, 0], [0, -354], [0, 12], [0, -440], [-292, 0], [-86, 0], [-164, 0], [0, -162], [0, 446], [0, -280], [-394, 0], [608, 0], [0, -318], [0, -270], [0, -24], [434, 0], [656, 0], [-844, 0], [0, 206], [-1046, 0], [46, 0], [0, 512], [804, 0], [0, 258], [0, 482], [0, -364], [1082, 0], [1056, 0], [0, -274], [0, 142], [-922, 0], [0, 212], [966, 0], [0, 496], [-408, 0], [-164, 0], [1082, 0], [0, 510], [958, 0], [-772, 0], [0, 504], [1326, 0], [0, 66], [1132, 0], [0, -274], [0, -552], [-874, 0], [0, -116], [1368, 0], [0, -206], [-1002, 0], [0, -136], [772, 0], [0, -402], [-278, 0], [0, -258], [628, 0], [0, -240], [948, 0], [0, -126], [516, 0], [0, 144], [1314, 0], [0, 672], [1288, 0], [0, 164], [0, -750], [0, 370], [536, 0], [0, -60], [0, 78], [0, 830], [1646, 0], [1164, 0], [-34, 0], [0, -318], [0, -84], [-246, 0], [0, -632], [-488, 0], [1394, 0], [0, -312], [406, 0], [0, -420], [-632, 0], [1046, 0], [-368, 0], [0, 956], [532, 0], [0, -690], [0, -898], [0, 468], [-412, 0], [1988, 0], [-514, 0], [0, -928], [-1728, 0], [0, -194], [326, 0], [0, 276], [0, 834], [0, -654], [882, 0], [1116, 0], [0, -210], [0, 350], [0, -324], [-642, 0], [-516, 0], [958, 0], [0, 28], [0, 30], [1554, 0], [0, -578], [0, 472], [566, 0], [-2192, 0], [0, 108], [248, 0], [0, 114], [0, -328], [-1598, 0], [-1888, 0], [0, -656], [0, 98], [0, -46], [1914, 0], [-46, 0], [0, -288], [-1696, 0], [0, -126], [-1434, 0], [0, -622], [0, -352], [152, 0], [0, -188], [-788, 0], [-2278, 0], [1966, 0], [0, -120], [-2276, 0], [0, -62], [-162, 0], [0, 658], [0, 108], [0, 648], [0, 894], [-1994, 0], [-632, 0], [406, 0], [0, -814], [0, 1032], [-48, 0], [0, -1284], [-86, 0], [0, -482], [2724, 0], [0, -448], [0, -1054], [1966, 0], [0, 850], [0, -1068], [-326, 0], [116, 0], [0, 574], [1624, 0], [-432, 0], [0, 850], [-122, 0], [412, 0], [0, -114], [922, 0], [0, -612], [0, 1112], [364, 0], [0, 450], [2954, 0], [716, 0], [-824, 0], [914, 0], [-3472, 0], [1688, 0], [0, 818], [-874, 0], [-2686, 0], [0, -1428], [0, 1470], [1918, 0], [0, 194], [-1286, 0], [1412, 0], [0, 1264], [2832, 0], [0, 238], [82, 0], [0, -1216], [0, -1084], [0, -126], [0, 690], [0, -156], [2732, 0], [0, 684], [606, 0], [0, 450], [0, -1460], [636, 0], [-584, 0], [0, -1170], [-3326, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1200_l_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_3_l_q();".
// 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_1200_3_l_q(:prec:=2)
    chi := MakeCharacter_1200_l();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1200_3_l_q();".
// 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_1200_3_l_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1200_l();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![8, 1]>,<11,R![80, 0, 1]>,<13,R![-12, 1]>],Snew);
    return Vf;
end function;