
// Make newform 700.4.a.p in Magma, downloaded from the LMFDB on 05 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_700_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_700_4_a_p();".
// 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_700_4_a_p();".
// 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 := [-6, 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_700_a();"
function MakeCharacter_700_a()
    N := 700;
    order := 1;
    char_gens := [351, 477, 101];
    v := [1, 1, 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_700_a_Hecke(Kf)
    return MakeCharacter_700_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]];
    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 := 4;
    raw_aps := [[0, 0], [0, 1], [0, 0], [-7, 0], [24, 14], [14, 23], [14, -24], [-44, 7], [-14, -2], [-70, -14], [52, -14], [182, 48], [90, 154], [196, -94], [28, 70], [462, 50], [284, 161], [-234, -161], [112, 288], [-486, -14], [658, -98], [482, -350], [336, -287], [-826, 168], [714, 20], [582, -329], [1736, 94], [1456, -192], [170, 322], [406, 524], [1274, 530], [236, -329], [-616, -812], [52, -497], [366, -980], [-768, -728], [-1974, 745], [-924, -914], [1680, -286], [42, -1075], [-1076, -28], [-3310, 35], [670, 1302], [322, -616], [-742, 1342], [1452, 490], [-1932, 1344], [-1036, -456], [2352, 189], [4366, 385], [-2548, 860], [-1408, -1372], [1878, -966], [716, -1169], [378, -450], [-2016, 1388], [-190, -217], [2220, 0], [-4270, 1538], [-162, -1008], [-5936, -643], [-3990, -965], [-1064, -1723], [8412, 840], [-7070, 536], [-3514, -422], [1844, -3654], [-8470, -104], [7392, 1582], [762, 847], [-4242, 1654], [3544, 2408], [5264, 1368], [2926, -762], [-2600, -2058], [-756, -3914], [1626, 350], [-2086, 1125], [5424, -3276], [2410, -3934], [956, 3017], [-8246, -3052], [-6568, 4396], [-3430, 1364], [-1672, 3276], [12936, -2212], [-7786, 3360], [-10682, -2504], [-4886, -861], [-4480, -872], [9128, -1057], [14856, -1638], [1862, -3990], [-11976, 1624], [-1256, 2380], [10724, -1152], [-2146, -6895], [21618, -546], [9296, 5359], [13982, 1288], [11564, -4938], [8890, -2070], [5992, -1719], [1416, 1316], [-9256, -6734], [-854, 610], [10976, 6593], [294, 410], [-402, -2702], [-10906, 924], [-5012, 492], [14826, -380], [-602, -3560], [-1484, -8239], [-6354, 8134], [-22592, -2044], [56, 2009], [15036, -2338], [-1386, -7972], [4980, -3374], [23218, -3955], [1960, -6332], [12194, 3553], [13832, -1832], [15124, -6769], [-21550, -3990], [2622, -4942], [836, -938], [-1624, -5382], [19138, -761], [-14300, 6650], [4494, 4086], [17392, 1036], [-11214, -3980], [10822, 3850], [13846, -9702], [20118, 5133], [-10752, -11089], [24374, -7885], [-17684, 280], [660, 13531], [9018, 11452], [1344, 12160], [13972, -11368], [11662, 7679], [-11008, 5194], [-28574, -3539], [-12530, 2944], [-4260, 10801], [-21280, 5532], [2786, -996], [4722, 12460], [-32200, -2012], [-5124, -9270], [-48104, -572], [-25600, 2408], [5258, -10738], [18390, 1778], [2366, 18910], [39386, 2849], [23352, 3726], [-26796, 2932], [-2030, 5534], [-3948, -1519], [16128, -468], [18956, -7590], [-20978, -1974], [11774, 3357], [21652, 3472], [-6874, 4267], [37500, 6076], [-9522, 2149], [21490, 378], [13412, -19604], [44788, 1722], [21078, 4760], [-31864, 1008], [24862, 12838], [-24948, -348], [-1102, 2737], [-35938, 13106], [-26476, -1099], [7742, -4272], [43218, -4942], [-38234, -4938], [-7326, -5061], [-12894, -15182], [-29176, 877], [6406, 8988], [26424, -6818], [-26642, -8366], [6804, -16668], [29860, -11340], [6546, -8309], [-15428, -17796], [-19978, 12970], [-25876, -19040], [42630, 13332], [-3626, -15046], [-3752, 16028], [-23162, -20076], [-45320, 1358], [2982, -21019], [-9702, -16968], [-17652, -3437], [54586, -10697], [-15036, -7714], [54068, 4458], [10992, 2016], [-13564, 22995], [-2506, 14192], [15826, -22911], [1806, 17814], [13104, 19181], [27088, 9660], [19442, 6202], [-4872, 30248], [-48678, -4326], [17136, -28080], [34286, -13008], [11290, -4046], [-4360, 3472], [-42654, -5376], [26838, -28510], [21448, 11901], [42678, -20174], [4914, -20586], [11480, -29820], [34748, -18288], [-52908, 3766], [50470, -6452], [-26028, -26425], [3650, -34538], [-15678, 20048], [4424, -16967], [-56196, 6584], [60742, -2366], [75138, -2678], [-14568, 23912], [68220, -840], [41748, 10146], [-24236, -9947], [28336, 28656], [-55818, 19152], [-8022, 11978], [-6420, -16786], [9548, -23112], [-6372, 32025], [13080, 26866], [69720, -13544], [97762, 862], [39678, -6440], [32816, -21612], [-27814, -420], [-4326, -21513], [-80312, -17780], [12110, -20482], [11032, -9111], [-42042, -4991], [-72170, -10500], [-46354, 522], [31836, 9562], [-57158, -21119], [40894, 23609], [-490, -21964], [-109412, -5593], [91146, 2772], [37210, 3948], [0, -2216], [35490, 3964], [26050, -35497], [-51576, -25150], [-85414, -282], [55256, -23240], [13818, -12758], [-35784, 3840], [13440, 13014], [-52226, 13104], [-20560, 10752], [-81996, -11683], [83076, 14552], [85714, 27118], [40124, 39870], [38822, 17395], [12880, 1407], [-40848, 43288], [13636, 32788], [-39942, -2162], [21740, 39830], [42558, 7056], [-20658, 10724], [-78288, 14983], [-141246, 4880], [19700, 11277], [31234, -534], [-24782, 5271], [-92504, 7308], [5726, -65665], [-94308, 24577], [32872, 15009], [41818, 43788], [16114, -10348], [118686, 11018], [-36456, 22778], [-101216, 2702], [23576, -30428], [-89656, -7718], [-61078, -22043], [26760, -29876], [-117586, -19662], [-24976, 6552], [-6642, -3262], [-29970, 30100], [98616, -14498], [-39648, -30708], [-47842, 51212], [101460, -26901], [57466, -1946], [-128002, 12710], [-22782, -34944], [-123620, 8057], [3248, -30396], [18230, -8505], [-13328, 4164], [-156982, 5768], [52370, -35546], [61708, 11326], [-27664, -25439], [-20286, 28042], [-113582, 12340], [24622, 39312], [-60018, 35708], [-79736, 1134], [16632, -37627], [122800, -23044], [81592, -45151], [56466, 14686], [-43694, 51486], [-69470, -40656], [-3164, 83442], [66794, 48858], [-64414, -9208], [57858, -16821], [20818, -23142], [57162, -20912], [-81632, -27230], [-112366, -301], [83916, 26878], [20784, -24640], [-120890, 6429], [-99108, 8827], [4844, -3204], [103742, -31360], [126336, -19650], [-26122, -31136], [-132118, -30054], [-124388, -28826], [-95964, -34097], [-68460, 43556], [102858, -26994], [8862, -346], [-100938, 5516], [124922, -38110], [-32332, 13552], [100352, 51997], [107310, -8432], [-139258, -14453], [-143066, -8414], [-72948, -29848], [108996, -36232], [-25180, -21777], [73416, -13968], [44478, -20272], [-119468, 35028], [-70966, -20746], [-13660, 3857], [167400, 26908], [61866, -71086], [101170, -43974], [45206, 66752], [-38490, 64953], [131474, 50688], [59808, -33040], [-172704, 760], [-23260, 90741], [11508, 93960], [-27278, 76650], [6454, 13809], [181636, -3888], [-34860, 18706], [124484, -3696], [-87570, 28609], [41908, 24332], [-29176, -55741], [53928, -38528], [-18648, -60900], [-88016, -27678], [121486, 35210], [59708, 3976], [95306, -8470], [156822, 32487], [13636, 7716], [-57456, -77912], [-15078, -45364], [-71466, 23849], [-50800, 52570], [92442, -73678], [-71148, -23016], [-74144, 68157], [-185628, 7357], [18774, -31618], [-143262, -29928], [67396, 79930], [-42984, -60956], [-144788, 38204], [71454, 58205], [-31974, 18522], [15316, -35318], [21798, 32108], [-59052, -78660], [59202, 15022], [85498, -23621], [-28616, 29616], [20972, -83573], [26586, 19084], [-111846, 51683], [40712, -98014], [15126, 69440], [51732, -2205], [152308, 11914]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_700_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_700_4_a_p();".
// 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_700_4_a_p(:prec:=2)
    chi := MakeCharacter_700_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_700_4_a_p();".
// 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_700_4_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_700_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-6, 0, 1]>,<11,R![-600, -48, 1]>,<13,R![-2978, -28, 1]>],Snew);
    return Vf;
end function;