Rings


In [1]:
RRing = Rings()

In [2]:
[method for method in dir(RRing) if method[0] is not r'_']


Out[2]:
['AdditiveAssociative',
 'AdditiveCommutative',
 'AdditiveInverse',
 'AdditiveUnital',
 'Algebras',
 'Associative',
 'CartesianProducts',
 'Commutative',
 'Distributive',
 'Division',
 'ElementMethods',
 'Endsets',
 'Facade',
 'Facades',
 'Finite',
 'FinitelyGenerated',
 'FinitelyGeneratedAsMagma',
 'Homsets',
 'Infinite',
 'Inverse',
 'IsomorphicObjects',
 'Metric',
 'NoZeroDivisors',
 'ParentMethods',
 'Quotients',
 'Realizations',
 'SubcategoryMethods',
 'Subobjects',
 'Subquotients',
 'Topological',
 'Unital',
 'WithRealizations',
 'additional_structure',
 'all_super_categories',
 'an_instance',
 'axioms',
 'base_category',
 'category',
 'category_graph',
 'db',
 'dump',
 'dumps',
 'element_class',
 'example',
 'extra_super_categories',
 'full_super_categories',
 'hom_category',
 'is_abelian',
 'is_full_subcategory',
 'is_subcategory',
 'join',
 'meet',
 'morphism_class',
 'or_subcategory',
 'parent',
 'parent_class',
 'rename',
 'required_methods',
 'reset_name',
 'save',
 'structure',
 'subcategory_class',
 'super_categories',
 'version']

In [3]:
RRing.axioms()


Out[3]:
frozenset({'AdditiveAssociative',
           'AdditiveCommutative',
           'AdditiveInverse',
           'AdditiveUnital',
           'Associative',
           'Distributive',
           'Unital'})

In [4]:
RCommutRing = CommutativeRing( RR ) # a "base" ring for input is needed

In [5]:
RCommutRing.is_commutative()


Out[5]:
True

In [6]:
ZZRing = ZZ()
RRRing = RR()
CCRing = CC()
QQRing = QQ() # Rational numbers

$\mathbb{Z}_n$, integers mod $n$:


In [7]:
Z_2Ring = Integers(2)
Z_16Ring = Integers(16)

Quadratic Field is the the field formed by combining the rationals with a solution to polynomial equation $x^2-n=0$, $\equiv \mathbb{Q}[\sqrt{n}]$


In [8]:
QuadField2Ring = QuadraticField(2)

In [9]:
[method for method in dir(ZZRing) if method[0] is not '_']


Out[9]:
['N',
 'abs',
 'additive_order',
 'base_extend',
 'base_ring',
 'binary',
 'binomial',
 'bits',
 'cartesian_product',
 'category',
 'ceil',
 'class_number',
 'conjugate',
 'coprime_integers',
 'crt',
 'db',
 'degree',
 'denominator',
 'digits',
 'dist',
 'divide_knowing_divisible_by',
 'divides',
 'divisors',
 'dump',
 'dumps',
 'euclidean_degree',
 'exact_log',
 'exp',
 'factor',
 'factorial',
 'floor',
 'gamma',
 'gcd',
 'global_height',
 'imag',
 'inverse_mod',
 'inverse_of_unit',
 'is_idempotent',
 'is_integer',
 'is_integral',
 'is_irreducible',
 'is_nilpotent',
 'is_norm',
 'is_one',
 'is_perfect_power',
 'is_power_of',
 'is_prime',
 'is_prime_power',
 'is_pseudoprime',
 'is_pseudoprime_power',
 'is_square',
 'is_squarefree',
 'is_unit',
 'is_zero',
 'isqrt',
 'jacobi',
 'kronecker',
 'lcm',
 'leading_coefficient',
 'list',
 'log',
 'mod',
 'multifactorial',
 'multiplicative_order',
 'n',
 'nbits',
 'ndigits',
 'next_prime',
 'next_prime_power',
 'next_probable_prime',
 'nth_root',
 'numerator',
 'numerical_approx',
 'odd_part',
 'ord',
 'order',
 'ordinal_str',
 'parent',
 'perfect_power',
 'popcount',
 'powermod',
 'powermodm_ui',
 'powers',
 'previous_prime',
 'previous_prime_power',
 'prime_divisors',
 'prime_factors',
 'prime_to_m_part',
 'quo_rem',
 'radical',
 'rank',
 'rational_reconstruction',
 'real',
 'rename',
 'reset_name',
 'save',
 'sign',
 'sqrt',
 'sqrtrem',
 'squarefree_part',
 'str',
 'subs',
 'substitute',
 'support',
 'test_bit',
 'trailing_zero_bits',
 'trial_division',
 'val_unit',
 'valuation',
 'version',
 'xgcd']

In [10]:
ZZRing.rank()


Out[10]:
0

ring of Gaussian integers, $\mathbb{I}_m \equiv \mathbb{Z}/m\mathbb{Z}$


In [1]:
ZZ[I]


Out[1]:
Order in Number Field in I with defining polynomial x^2 + 1

In [3]:
ZZ[I].is_integral_domain()


Out[3]:
True

In [4]:
ZZ[I].zero()


Out[4]:
0

In [5]:
ZZ[I].one()


Out[5]:
1

In [11]:
ZZ[I].is_ring()


Out[11]:
True

Polynomials

For reading - cf. Sec. 3.4 Greatest Common Divisors, of Joseph Rotman's Advanced Modern Algebra

For the Sage Math exercises - cf. in Abstract Algebra - Theory and Applications by Thomas W. Judson, 17 Polynomials, 17.6 Sage

\begin{gathered} \mathbb{I}_8 \equiv \mathbb{Z}/8\mathbb{Z} \text{ is the (commutative) ring } \\ \mathbb{Z}/8\mathbb{Z}[x] \text{ is the polynomial ring over } \mathbb{Z}/8\mathbb{Z} \end{gathered}

In [12]:
R.<x> = Integers(8)[]; R


Out[12]:
Univariate Polynomial Ring in x over Ring of integers modulo 8

In [19]:
R1.<x> = PolynomialRing(ZZ.quo(8*ZZ)); R1


Out[19]:
Univariate Polynomial Ring in x over Ring of integers modulo 8

In [20]:
R1 == R


Out[20]:
True

In [21]:
S.<y> = ZZ[]; S


Out[21]:
Univariate Polynomial Ring in y over Integer Ring

In [22]:
T.<z> = QQ[]; T


Out[22]:
Univariate Polynomial Ring in z over Rational Field

In [23]:
R.is_finite()


Out[23]:
False

In [25]:
R.is_integral_domain()


Out[25]:
False

In [26]:
S.is_integral_domain()


Out[26]:
True

In [27]:
T.is_field()


Out[27]:
False

In [28]:
R.characteristic()


Out[28]:
8

In [29]:
T.characteristic()


Out[29]:
0

In [31]:
print(y in S)
x in S


True
Out[31]:
False

In [32]:
q = (3/2) + (5/4)*z^2 
q in T


Out[32]:
True

In [34]:
print(3 in S)
r = 3
print( r.parent() )
s = 3*y^0
s.parent()


True
Integer Ring
Out[34]:
Univariate Polynomial Ring in y over Integer Ring

Polynomials can be evaluated like they are functions


In [35]:
p = 3 + 5*x + 2*x^2
print( p.parent() )
p(1)


Univariate Polynomial Ring in x over Ring of integers modulo 8
Out[35]:
2

In [36]:
[p(t) for t in Integers(8)]


Out[36]:
[3, 2, 5, 4, 7, 6, 1, 0]

In [38]:
g = 4*x^2 + 4*x
[g(t) for t in Integers(8)]


Out[38]:
[0, 0, 0, 0, 0, 0, 0, 0]

In [39]:
M.<s,t> = QQ[]; M


Out[39]:
Multivariate Polynomial Ring in s, t over Rational Field

Irreducible Polynomials


In [40]:
R.<x> = QQ[]
p = 1/4*x^4 - x^3 + x^2 - x - 1/2
p.is_irreducible()


Out[40]:
True

In [41]:
p.factor()


Out[41]:
(1/4) * (x^4 - 4*x^3 + 4*x^2 - 4*x - 2)

In [42]:
q = 2*x^5 + 5/2*x^4 + 3/4*x^3 - 25/24*x^2 - x - 1/2
q.is_irreducible()


Out[42]:
False

In [43]:
q.factor()


Out[43]:
(2) * (x^2 + 3/2*x + 3/4) * (x^3 - 1/4*x^2 - 1/3)

In [51]:
F.<a> = FiniteField(5^2)
S.<y> = F[]
p = 2*y^5 + 2*y^4 + 4*y^3 + 2*y^2 + 3*y + 1
p.is_irreducible()


Out[51]:
True

In [52]:
p.factor()


Out[52]:
(2) * (y^5 + y^4 + 2*y^3 + y^2 + 4*y + 3)

In [54]:
q = 3*y^4+2*y^3-y+4; print( q.is_irreducible() )
q.factor()


False
Out[54]:
(3) * (y^2 + (a + 4)*y + 2*a + 3) * (y^2 + 4*a*y + 3*a)

In [55]:
r = y^4 + 2*y^3 + 3*y^2+4; r.factor()


Out[55]:
(y + 4) * (y^3 + 3*y^2 + y + 1)

In [57]:
s = 3*y^4+2*y^3-y+3; s.factor()


Out[57]:
(3) * (y + 1) * (y + 3) * (y + 2*a + 4) * (y + 3*a + 1)

In [58]:
F.modulus()


Out[58]:
x^2 + 4*x + 2

In [60]:
F.modulus().is_irreducible()


Out[60]:
True

Polynomials over Fields

If $F$ is a field, then every ideal of $F[x]$ is principal. cf. (http://abstract.ups.edu/aata/poly-sage.html)


In [61]:
W.<w> = QQ[]
r = -w^5 + 5*w^4 - 4*w^3 + 14*w^2 - 67*w + 17
s = 3*w^5 - 14*w^4 + 12*w^3 - 6*w^2 + w
S = W.ideal(r, s)
S


Out[61]:
Principal ideal (w^2 - 4*w + 1) of Univariate Polynomial Ring in w over Rational Field

In [62]:
(w^2)*r + (3*w-6)*s in S


Out[62]:
True

In [63]:
F = Integers(7)
R.<x> = F[]
p = x^5 + x + 4
p.is_irreducible()


Out[63]:
True

In [64]:
_.<x> = PolynomialRing(ZZ)
f = x^4 + 2*x^2 + 1
print( f.coefficients() )
f.coefficients(sparse=False)


[1, 2, 1]
Out[64]:
[1, 0, 2, 0, 1]

In [65]:
f.degree()


Out[65]:
4

Take derivatives of polynomials

$\begin{gathered} f'(x) \\ f''(x) \end{gathered}$


In [66]:
print( f.derivative(x) )
print( f.derivative(x,x) )
f.derivative(x,2)


4*x^3 + 4*x
12*x^2 + 4
Out[66]:
12*x^2 + 4

cf. J. Rotman, Advanced Modern Algebra, Exercise 3.28


In [89]:
ZZ5_x_polys.<x> = PolynomialRing( Integers(5) )

In [92]:
( Integers(5)(1)*x**3-Integers(5)(7)*x+Integers(5)(6) ).gcd( Integers(5)(1)*x**2-Integers(5)(1)*x-Integers(5)(2) )
(x^3-7*x+6).gcd(x^2-x-2)


Out[92]:
x + 3

In [95]:
print( (x^2-x-2).factor() )
(x^3-7*x+6).factor()
factor( x^3-7*x+6)


(x + 1) * (x + 3)
Out[95]:
(x + 4) * (x + 3)^2

In [93]:
print( (x+1)*(x+3) )


x^2 + 4*x + 3

In [96]:
p0328 = x^2 - x - 2
q0328 = x^3 - 7*x+6
print( p0328.parent() )
q0328.parent()


Univariate Polynomial Ring in x over Ring of integers modulo 5
Out[96]:
Univariate Polynomial Ring in x over Ring of integers modulo 5

At this point, this helped to check what's going on: cf. Ring Z/nZ of integers modulo n


In [94]:
print( Integers(5).0 )
print( Integers(5)(0) + Integers(5)(3) )
print( Integers(5)(0) + Integers(5)(6) )
print( Integers(5)(0)*Integers(5)(2) )
print( Integers(5)(1)*Integers(5)(3) ) 

print( 0 )
print( 0 + 3 )
print( 0 + 6 )
print( 0 * 2 )
print( 1 * 3 )


1
3
1
0
3
0
3
6
0
3

cf. J. Rotman, Advanced Modern Algebra, Exercise 3.30


In [97]:
ZZ3_x_polys.<x> = PolynomialRing( Integers(3) )

In [98]:
f0330 = x^2 + 1
g0330 = x^3 + x + 1

In [99]:
f0330.gcd( g0330 )


Out[99]:
1

In [101]:
print( factor( f0330 ) )
factor( g0330 )


x^2 + 1
Out[101]:
(x + 2) * (x^2 + x + 2)

Modules


In [ ]:


In [ ]:


In [11]:
%display latex

In [12]:
RingModule = Modules(Rings())

In [13]:
[method for method in dir(RingModule) if method[0] is not '_']


Out[13]:

In [14]:
RingModule.category_graph()


Out[14]:

In [15]:
RingModule.axioms()


Out[15]:

In [16]:
ZZmodule = Modules(ZZ)

In [17]:
ZZmodule.AdditiveInverse(), ZZmodule.AdditiveUnital(), ZZmodule.an_instance()


Out[17]:

In [18]:
ZZmodule.category_graph()


Out[18]:

cf. Chapter 7 Modules and Categories, 7.1 Modules of Rotman, Advanced Modern Algebra, pp. 423, Example 7.1


In [19]:
n = var('n',domain="integer")
RRmoduleVecSpace = VectorSpace(RR,3)

In [20]:
[method for method in dir(RRmoduleVecSpace) if method[0] is not '_']


Out[20]:

In [21]:
RRmoduleVecSpace.basis(), RRmoduleVecSpace.basis_matrix(), RRmoduleVecSpace.gens()


Out[21]:

In [22]:
RRmoduleVecSpace.gens_dict()


Out[22]:

In [ ]: