# Chapter 4 - Polynomials¶

## Page 121 Example 4.3¶

In [1]:
from numpy import array,identity
from sympy import Symbol
print 'C is the field of complex numbers'
x = Symbol("x")
def f(x):
ff= x**2 + 2
return ff
print 'f = ',f(x)
#part a
print 'if a = C and z belongs to C, then f(z) = z**2 + 2'
print 'f(2) = ',f(2)

print 'f(1+1J/1-1J) = ',f((1+1J)/(1-1J))
print '----------------------------------------'

#part b
print 'If a is the algebra of all 2*2 matrices over C and'
B = array([[1 ,0],[-1, 2]])
print 'B = \n',B
print 2*identity(2) + B**2,'then, f(B) = '
print '----------------------------------------'

#part c
print 'If a is algebra of all linear operators on C**3'
print 'And T is element of a as:'
print 'T(c1,c2,c3) = (i*2**1/2*c1,c2,i*2**1/2*c3)'
print 'Then, f(T)(c1,c2,c3) = (0,3*c2,0)'
print '----------------------------------------'
#part d
print 'If a is the algebra of all polynomials over C'
def g(x):
gg= x**4 + 3*1J
return gg
print 'And, g = ',g(x)
print 'Then f(g) = ',g(2)

C is the field of complex numbers
f =  x**2 + 2
if a = C and z belongs to C, then f(z) = z**2 + 2
f(2) =  6
f(1+1J/1-1J) =  (1+0j)
----------------------------------------
If a is the algebra of all 2*2 matrices over C and
B =
[[ 1  0]
[-1  2]]
[[ 3.  0.]
[ 1.  6.]] then, f(B) =
----------------------------------------
If a is algebra of all linear operators on C**3
And T is element of a as:
T(c1,c2,c3) = (i*2**1/2*c1,c2,i*2**1/2*c3)
Then, f(T)(c1,c2,c3) = (0,3*c2,0)
----------------------------------------
If a is the algebra of all polynomials over C
And, g =  x**4 + 3.0*I
Then f(g) =  (16+3j)


## Page 131 Example 4.7¶

In [2]:
from sympy import Symbol
x = Symbol('x')
p1 = x + 2#
p2 = x**2 + 8*x + 16#
print 'M = (x+2)F[x] + (x**2 + 8x + 16)F[x]'
print 'We assert, M = F[x]'
print 'M contains:',
t = p2 - x*p1#
print t
print 'And hence M contains:',
print t - 6*p1
print 'Thus the scalar polynomial 1 belongs to M as well all its multiples.'

M = (x+2)F[x] + (x**2 + 8x + 16)F[x]
We assert, M = F[x]
M contains: x**2 - x*(x + 2) + 8*x + 16
And hence M contains: x**2 - x*(x + 2) + 2*x + 4
Thus the scalar polynomial 1 belongs to M as well all its multiples.


## Page 133 Example 4.8¶

In [3]:
from sympy import Symbol
x = Symbol('x')

#part a
p1 = x + 2#
p2 = x**2 + 8*x + 16#
print 'p1 = ',p1
print 'p2 = ',p2
print 'M = (x+2)F[x] + (x**2 + 8x + 16)F[x]'
print 'We assert, M = F[x]'
print 'M contains:',
t = p2 - x*p1#
print t
print 'And hence M contains:',
print t - 6*p1
print 'Thus the scalar polynomial 1 belongs to M as well all its multiples'
print 'So, gcd(p1,p2) = 1'
print '----------------------------------------------'
#part b
p1 = (x - 2)**2*(x+1J)#
p2 = (x-2)*(x**2 + 1)#
print 'p1 = ',p1
print 'p2 = ',p2
print 'M = (x - 2)**2*(x+1J)F[x] + (x-2)*(x**2 + 1'
print 'The ideal M contains p1 - p2 i.e.,',
print p1 - p2
print 'Hence it contains (x-2)(x+i), which is monic and divides both,'
print 'So, gcd(p1,p2) = (x-2)(x+i)'
print '----------------------------------------------'

p1 =  x + 2
p2 =  x**2 + 8*x + 16
M = (x+2)F[x] + (x**2 + 8x + 16)F[x]
We assert, M = F[x]
M contains: x**2 - x*(x + 2) + 8*x + 16
And hence M contains: x**2 - x*(x + 2) + 2*x + 4
Thus the scalar polynomial 1 belongs to M as well all its multiples
So, gcd(p1,p2) = 1
----------------------------------------------
p1 =  (x - 2)**2*(x + 1.0*I)
p2 =  (x - 2)*(x**2 + 1)
M = (x - 2)**2*(x+1J)F[x] + (x-2)*(x**2 + 1
The ideal M contains p1 - p2 i.e., (x - 2)**2*(x + 1.0*I) - (x - 2)*(x**2 + 1)
Hence it contains (x-2)(x+i), which is monic and divides both,
So, gcd(p1,p2) = (x-2)(x+i)
----------------------------------------------


## Page 133 Example 4.9¶

In [4]:
from sympy import Symbol
x = Symbol('x')

print 'M is the ideal in F[x] generated by:'
print '(x-1)*(x+2)**2'
print '(x+2)**2*(x+3)'
print '(x-3)','and'
p1 = (x-1)*(x+2)**2#
p2 = (x+2)**2*(x-3)#
p3 = (x-3)#
print 'M = (x-1)*(x+2)**2 F[x] + (x+2)**2*(x-3) + (x-3)'
print 'Then M contains:',
t = 1/2*(x+2)**2*((x-1) - (x-3))#
print t
print 'i.e., M contains (x+2)**2'
print 'and since, (x+2)**2 = (x-3)(x-7) - 17'
print 'So M contains the scalar polynomial 1.'
print 'So, M = F[x] and given polynomials are relatively prime.'

M is the ideal in F[x] generated by:
(x-1)*(x+2)**2
(x+2)**2*(x+3)
(x-3) and
M = (x-1)*(x+2)**2 F[x] + (x+2)**2*(x-3) + (x-3)
Then M contains: 0
i.e., M contains (x+2)**2
and since, (x+2)**2 = (x-3)(x-7) - 17
So M contains the scalar polynomial 1.
So, M = F[x] and given polynomials are relatively prime.


## Page 135 Example 4.10¶

In [5]:
from sympy import Symbol
x = Symbol('x')
P = x**2 + 1#
print P,'P = '
print 'P is reducible over complex numbers as: ',
print '=',P
print '(x-i)(x+i)'
print 'Whereas, P is irreducible over real numbers as:',
print '=',P
print '(ax + b)(a''x + b'')'
print 'For, a,a'',b,b'' to be in R,'
print 'aa'' = 1'
print 'ab'' + ba'' = 0'
print 'bb'' = 1'
print '=> a**2 + b**2 = 0'
print '=> a = b = 0'

x**2 + 1 P =
P is reducible over complex numbers as:  = x**2 + 1
(x-i)(x+i)
Whereas, P is irreducible over real numbers as: = x**2 + 1
(ax + b)(ax + b)
For, a,a,b,b to be in R,
aa = 1
ab + ba = 0
bb = 1
=> a**2 + b**2 = 0
=> a = b = 0