Notes for Magma users
There is no interface between Magma and OSCAR, so this page is only about translating what you know from Magma to OSCAR. Many of the number theoretic functions in OSCAR live in the package Hecke, whose function names often are the snake_case versions of the Magma names.
This page is a start. Please tell us what is missing, see Notes for users of other computer algebra systems.
Differences in syntax
Assignment is
:=in Magma and=in Julia. The comparison operatorseq,ne,lt,le,gt,geare==,!=,<,<=,>,>=in Julia, andand,or,notare&&,||,!.Every Magma statement ends with
;. In an interactive Julia session, a trailing;suppresses the output of the value, see Semicolons and output.Magma's
if ... then ... elif ... else ... end if;isif ... elseif ... else ... endin Julia, andfor x in L do ... end for;isfor x in L ... end. The same holds forwhileloops. There are nothenanddokeywords.Functions are defined with
function f(x) ... endin Julia; one-liners can be written asf(x) = .... Procedures that modify their arguments (~xin Magma) are ordinary functions in Julia, by convention their names end with!.The cardinality
#Sof a set, sequence, or group islength(S)for collections andorder(G)for groups.Sequence and set constructors translate to comprehensions:
[ f(x) : x in L | c(x) ]is[f(x) for x in L if c(x)], and{ ... }isSet(...)applied to a comprehension. The reductions&+Land&*Laresum(L)andprod(L),&cat Lisreduce(vcat, L).forall{ x : x in L | c(x) }andexists{ ... }areall(c, L)andany(c, L).Coercion
K!xisK(x)in OSCAR.Strings are concatenated with
*instead ofcat.Comments start with
#instead of//; multi-line comments are#= ... =#instead of/* ... */.time f(x);is@time f(x), andload "file";isinclude("file.jl").assigned xis@isdefined x.Magma's
?help syntax is available in Julia as?name.Many Magma constructors use angle brackets:
sub<G | a, b>,quo<G | N>,hom<G -> H | a, b, ... >,ideal<R | f, g>,R<x, y> := PolynomialRing(K, 2). The OSCAR counterparts are ordinary functions:sub(G, [a, b]),quo(G, N),hom(G, H, [a, b, ...]),ideal(R, [f, g]), andR, (x, y) = polynomial_ring(K, [:x, :y]).
Differences in semantics
Integer literals are machine integers. In Magma,
2^100is computed exactly and3/4is a rational number. In Julia,2^100evaluates to0and3/4to0.75. WriteZZ(2)^100instead, and3//4orQQ(3, 4)for the rational number; the former is a JuliaRational, the latter an OSCAR rational number, see Integers and rational numbers.Multiple return values are tuples. Both Magma and Julia allow functions to return several values, but in Julia these form a tuple that is printed as a whole, and there are no "optional" return values that are silently dropped. Where a Magma predicate returns a witness as a second value, OSCAR has a separate function whose name says so:
julia> is_square(ZZ(16)) true julia> is_square_with_sqrt(ZZ(16)) (true, 4)For example,
H, f := sub<G | ...>returns the subgroup together with its embedding, andH := sub<G | ...>silently drops the embedding. OSCAR'ssubalways returns both, see Many constructors return more than one object.The order of dihedral groups. Magma's
DihedralGroup(n)is the dihedral group of order $2n$, OSCAR'sdihedral_group(n)is the dihedral group of order $n$, following GAP.The default monomial ordering differs.
PolynomialRing(K, n)in Magma uses the lexicographical ordering, and Gröbner bases are computed w.r.t. it. In OSCAR,groebner_basiscomputes with respect to the degree reverse lexicographical ordering by default, the one returned bydefault_ordering(R), and takes the ordering as a keyword argument.julia> R, (x, y) = polynomial_ring(QQ, [:x, :y]); julia> I = ideal(R, [x^2 + y^2 - 1, x - y]); julia> groebner_basis(I; ordering = lex(R)) Gröbner basis with elements 1: 2*y^2 - 1 2: x - y with respect to the ordering lex([x, y])divrounds differently. Magma'sa div brounds towards $-\infty$, like Julia'sfld. Julia'sdivrounds towards zero, so it agrees with Magma'sdivonly when both operands have the same sign. Magma'sa mod band Julia'smod(a, b)do agree.Argument order of
ChangeRing. Magma'sChangeRing(M, R)ischange_base_ring(R, M)in OSCAR; the ring comes first, as inmatrix(R, ...).Types are not intrinsics. Magma's
Type(x)istypeof(x)in Julia,Parent(x)isparent(x). There is noCategory. The signatures of a functionfare listed bymethods(f).
Common Magma functions and their OSCAR counterparts
Sequences and sets
| Magma | OSCAR |
|---|---|
#L | length(L) |
[1..10], [1..10 by 2] | 1:10, 1:2:10 |
Append(~L, x) | push!(L, x) |
L cat M | vcat(L, M) |
Reverse(L), Sort(L) | reverse(L), sort(L) |
Position(L, x), Index(L, x) | findfirst(==(x), L) |
Max(L), Min(L) | maximum(L), minimum(L) |
IsEmpty(L) | isempty(L) |
Seqset(L), Setseq(S) | Set(L), collect(S) |
A join B, A meet B, A diff B | union(A, B), intersect(A, B), setdiff(A, B) |
Include(~S, x), Exclude(~S, x) | push!(S, x), delete!(S, x) |
x in S, x notin S | x in S, !(x in S) |
Universe(L) | eltype(L) |
ChangeUniverse(L, R) | R.(L) or map(R, L) |
Integers and rational numbers
| Magma | OSCAR |
|---|---|
Integers(), Rationals() | ZZ, QQ |
a div b, a mod b | fld(a, b), mod(a, b) |
Factorization(n) | factor(n) |
IsPrime(n), NextPrime(n) | is_prime(n), next_prime(n) |
Divisors(n), EulerPhi(n) | divisors(n), euler_phi(n) |
GCD(a, b), LCM(a, b) | gcd(a, b), lcm(a, b) |
Binomial(n, k), Factorial(n) | binomial(n, k), factorial(ZZ(n)) |
Numerator(q), Denominator(q) | numerator(q), denominator(q) |
Floor(q), Ceiling(q), Round(q) | floor(ZZRingElem, q), ceil(ZZRingElem, q), round(ZZRingElem, q) |
Isqrt(n), IsSquare(n) | isqrt(n), is_square(n), is_square_with_sqrt(n) |
Integers(n) | residue_ring(ZZ, n) |
RealField(30), ComplexField(30) | ArbField(100), AcbField(100) (precision in bits, not digits) |
Groups
| Magma | OSCAR |
|---|---|
Sym(n), Alt(n) | symmetric_group(n), alternating_group(n) |
CyclicGroup(n), DihedralGroup(n) | cyclic_group(n), dihedral_group(2n) |
AbelianGroup([2, 4]) | abelian_group([2, 4]) |
SmallGroup(n, i), IdentifyGroup(G) | small_group(n, i), small_group_identification(G) |
PermutationGroup<n | g, h> | permutation_group(n, [g, h]) |
Sym(n)!(1,2,3) | cperm(G, [1, 2, 3]) |
sub<G | a, b> | sub(G, [a, b]) |
quo<G | N> | quo(G, N) |
hom<G -> H | a :-> x, b :-> y> | hom(G, H, [a, b], [x, y]) |
f(x), x @ f | f(x) |
Kernel(f), Image(f) | kernel(f), image(f) |
#G, Order(G), Order(g) | order(G), order(g) |
Generators(G), G.1 | gens(G), G[1] or gen(G, 1) |
Random(G) | rand(G) |
Centre(G), DerivedSubgroup(G) | center(G), derived_subgroup(G) |
Centralizer(G, x), Normalizer(G, H) | centralizer(G, x), normalizer(G, H) |
Sylow(G, p) | sylow_subgroup(G, p) |
NormalSubgroups(G) | normal_subgroups(G) |
IsAbelian(G), IsSoluble(G), IsSimple(G) | is_abelian(G), is_solvable(G), is_simple(G) |
IsIsomorphic(G, H) | is_isomorphic(G, H), isomorphism(G, H) |
Classes(G), ConjugacyClasses(G) | conjugacy_classes(G) |
CharacterTable(G) | character_table(G) |
AutomorphismGroup(G) | automorphism_group(G) |
GroupName(G) | describe(G) |
Orbit(G, x), Stabilizer(G, x) | orbit(G, x), stabilizer(G, x) |
Polynomials and ideals
| Magma | OSCAR |
|---|---|
R<x, y> := PolynomialRing(K, 2) | R, (x, y) = polynomial_ring(K, [:x, :y]) |
P<t> := PolynomialRing(K) | P, t = polynomial_ring(K, :t) |
Evaluate(f, [1, 2]) | evaluate(f, [1, 2]) or f(1, 2) |
Degree(f), TotalDegree(f) | degree(f), total_degree(f) |
Derivative(f, x) | derivative(f, x) |
Coefficients(f), Monomials(f), Terms(f) | coefficients(f), monomials(f), terms(f) |
LeadingCoefficient(f), LeadingTerm(f) | leading_coefficient(f), leading_term(f) |
Factorization(f), IsIrreducible(f) | factor(f), is_irreducible(f) |
Roots(f) | roots(f) |
GCD(f, g), Resultant(f, g), Discriminant(f) | gcd(f, g), resultant(f, g), discriminant(f) |
ideal<R | f, g> | ideal(R, [f, g]) |
GroebnerBasis(I) | groebner_basis(I) |
Dimension(I), Radical(I) | dim(I), radical(I) |
PrimaryDecomposition(I) | primary_decomposition(I) |
EliminationIdeal(I, {x}) | eliminate(I, [x]) |
NormalForm(f, I), f in I | normal_form(f, I), f in I |
Variety(I) | rational_solutions(I) |
quo<R | I> | quo(R, I) |
Number fields
| Magma | OSCAR |
|---|---|
K<a> := NumberField(f) | K, a = number_field(f, "a") |
CyclotomicField(n), QuadraticField(d) | cyclotomic_field(n), quadratic_field(d) |
MaximalOrder(K), RingOfIntegers(K) | maximal_order(K) |
Discriminant(K), Degree(K) | discriminant(K), degree(K) |
MinimalPolynomial(a), Norm(a), Trace(a) | minpoly(a), norm(a), tr(a) |
ClassGroup(O), ClassNumber(K) | class_group(O), class_number(K) |
UnitGroup(O) | unit_group(O) |
Basis(O) | basis(O) |
ideal<O | 2> | ideal(O, 2) |
Factorization(I), IsPrime(I) | factor(I), is_prime(I) |
GaloisGroup(f) | galois_group(K) |
Matrices
| Magma | OSCAR |
|---|---|
Matrix(K, 2, 2, [1, 2, 3, 4]) | matrix(K, 2, 2, [1, 2, 3, 4]) or matrix(K, [1 2; 3 4]) |
IdentityMatrix(K, n), ZeroMatrix(K, m, n) | identity_matrix(K, n), zero_matrix(K, m, n) |
Nrows(M), Ncols(M) | nrows(M), ncols(M) |
M[i, j], M[i] | M[i, j], M[i, :] |
Determinant(M), Rank(M) | det(M), rank(M) |
Transpose(M), M^-1 | transpose(M), inv(M) or M^-1 |
ChangeRing(M, R) | change_base_ring(R, M) |
CharacteristicPolynomial(M), MinimalPolynomial(M) | charpoly(M), minpoly(M) |
Eigenvalues(M) | eigenvalues(M) |
Kernel(M), NullspaceMatrix(M) | kernel(M) |
Solution(M, v) | solve(M, v; side = :left) |
IsConsistent(M, v) | can_solve(M, v; side = :left), can_solve_with_solution(M, v; side = :left) |
EchelonForm(M) | rref(M) |
HermiteForm(M), SmithForm(M) | hnf(M), snf(M) |
Vector(K, [1, 2]) | K.([1, 2]) |