Sagebrush · Examples · Notebooks

Magma

Magma programs: sequences, functions and procedures, polynomials.

notebook · Magma · intro · by Sagebrush · MIT license

basicsprogramming

Download (ZIP)Source on GitHub

Preview

Magma

Magma programs, translated to Python in this page and run on Sagebrush's engines. Sequences are 1-based with value semantics, / is exact, and values print as Magma prints them (checked against Magma itself).

// Integers and sequences
Factorization(2^64 - 1);
[ p : p in [1..100] | IsPrime(p) and IsPrime(p + 2) ];
&+[ 1/n : n in [1..10] ];
[ <3, 1>, <5, 1>, <17, 1>, <257, 1>, <641, 1>, <65537, 1>, <6700417, 1> ]
[ 3, 5, 11, 17, 29, 41, 59, 71 ]
7381/2520
// Functions, procedures with reference arguments, recursion
fib := function(n) if n le 2 then return 1; end if; return $$(n-1) + $$(n-2); end function;
[ fib(n) : n in [1..20] ];
procedure Push(~L, x) Append(~L, x); end procedure;
L := [1, 2]; Push(~L, 3); L;
[ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 
4181, 6765 ]
[ 1, 2, 3 ]
// Polynomials over the integers and the rationals
R<x> := PolynomialRing(Integers());
Factorization(x^12 - 1);
Q<y> := PolynomialRing(Rationals());
Roots((y^2 - 1/4)*(3*y + 2));
[
    <x - 1, 1>,
    <x + 1, 1>,
    <x^2 - x + 1, 1>,
    <x^2 + 1, 1>,
    <x^2 + x + 1, 1>,
    <x^4 - x^2 + 1, 1>
]
[ <-2/3, 1>, <-1/2, 1>, <1/2, 1> ]
// Modular symbols and newforms (Sagebrush's Rust engine, in WebAssembly)
S := CuspidalSubspace(ModularSymbols(389, 2, 1));
S;
Factorization(HeckePolynomial(S, 2));
NewformDecomposition(NewSubspace(S));
Modular symbols space for Gamma_0(389) of weight 2 and dimension 32 over 
Rational Field
[
    <x + 2, 1>,
    <x^2 - 2, 1>,
    <x^3 - 4*x - 2, 1>,
    <x^6 + 3*x^5 - 2*x^4 - 8*x^3 + 2*x^2 + 4*x - 1, 1>,
    <x^20 - 3*x^19 - 29*x^18 + 91*x^17 + 338*x^16 - 1130*x^15 - 2023*x^14 + 
        7432*x^13 + 6558*x^12 - 28021*x^11 - 10909*x^10 + 61267*x^9 + 6954*x^8 -
        74752*x^7 + 1407*x^6 + 46330*x^5 - 1087*x^4 - 12558*x^3 - 942*x^2 + 
        960*x + 148, 1>
]
[
    Modular symbols space for Gamma_0(389) of weight 2 and dimension 1 over 
    Rational Field,
    Modular symbols space for Gamma_0(389) of weight 2 and dimension 2 over 
    Rational Field,
    Modular symbols space for Gamma_0(389) of weight 2 and dimension 3 over 
    Rational Field,
    Modular symbols space for Gamma_0(389) of weight 2 and dimension 6 over 
    Rational Field,
    Modular symbols space for Gamma_0(389) of weight 2 and dimension 20 over 
    Rational Field
]
// Elliptic curves
E := EllipticCurve("389a1");
E;
Rank(E), Conductor(E), TorsionSubgroup(E);
[ TraceOfFrobenius(E, p) : p in PrimesUpTo(50) ];
Elliptic Curve defined by y^2 + y = x^3 + x^2 - 2*x over Rational Field
2 389 
Abelian Group of order 1
[ -2, -2, -3, -5, -4, -3, -6, 5, -4, -6, 4, -8, -3, 12, -2 ]
Newforms(CuspForms(37, 2));
[* [*
    q - 2*q^2 - 3*q^3 + 2*q^4 - 2*q^5 + 6*q^6 - q^7 + 6*q^9 + 4*q^10 - 5*q^11 + 
    O(q^12)
*], [*
    q + q^3 - 2*q^4 - q^7 - 2*q^9 + 3*q^11 + O(q^12)
*] *]

Files

Open the ZIP's notebook in Sagebrush (File, Open) to run and change it.