GSoC 2014 Application Rrubaa Panchendrarajan: Implementing Linear Transformation - sympy/sympy GitHub Wiki

AIM

Implement all the functionalities related to linear transformation.

Personal Information

Name: Rrubaa Panchendrarajan
University: Universiy of Moratuwa
Email: [email protected]
[email protected]
GitHub username: RubaP

I am a Computer Science and Engineering undergraduate from University of Moratuwa. Now I am in the end of my 2nd year.

As a programmer

I have more than 2 years of experience in programming especially in Java. I have a basic knowledge in Python. Only place where I used python was for the module called Object Oriented programming in my University. I am using PyCharm as my editor.

As I am a student from department of Computer Science and Engineering, I have good enough knowledge to learn new languages and technologies and solve problems. Feature that I admired in python is declaring variables without specifying its types. It will be easy for a programmer to implement the code quickly. But there are some other problems such as understanding the code. The person who is not implemented the code and go through it will feel hard to understand.

Best feature that I like in sympy is the symbolic expression. Finding the final value of an expression will not always be a need. Sometimes we may need only the way of solving. Symbolic expression will be a solution for that. For example:

>>> from sympy import MatMul, MatrixSymbol
>>> A = MatrixSymbol('A', 5, 4)
>>> B = MatrixSymbol('B', 4, 3)
>>> C = MatrixSymbol('C', 3, 6)
>>> MatMul(A, B, C)
A*B*C

Note: But I am suggesting improving this feature further more as it is not giving complete information

I have used Git as a version control system in so many projects for modules in my University. We were taught Git while we were entering to our department.

My Project

I am planning to implement all the functionalities of Linear Algebra. I am very much interested in mathematics and problem solving. Also I have enough knowledge in python. Mathematics and python, these two reasons were induced me to select sympy. I followed a module called Linear Algebra in semester four in my University. In that module I covered the sections such as vector space, linear transformations, inner product and so many other concepts. So once I saw the topic “Linear Algebra” I would like to go through the already available features.

While going through the implementation I got to know that only “rotation of a matrix” is implemented. So I planned to work in this area which is very much interesting to work.

Contribution to sympy

Currently I am working with the issue https://github.com/sympy/sympy/issues/6790 .
>>> A = MatrixSymbol('A', 3, 3)
>>> Determinant(A)
Determinant(A)

Here the determinant of a matrix print itself. I as realized that no point in having a functionality like this, I am suggesting to result the process of finding the determinant of a nxn matrix. Following result is I am expecting to get for any nxn matrix from my implementation.
>>>A=MatrixSymbol('A',1,1);
>>>Determinant(A);
A[0][0]

>>>B=MatrixSymbol('B',1,1);
>>>Determinant(A);
B[0][0]*B[1][1] - B[1][0]*B[0][1]

pull request :
https://github.com/sympy/sympy/pull/7311

Implementation

Defining a transformation
Linear transformation is a function that maps a vector space V into vector space W.

>>V=VectorSpace(x,y)
>>W=VectorSpace(x-y,x+2y)
>>T=Trasfomation(V,W)
>>v=Vector(-1,2)
(-1,2)
>>w=T.transform(v)
(-3,3)

Domain and codomain of T
V is called the domain of T and W is called the codomain of V.

>>T.domain()
V
>>T.codomain()
W

Image and preimage
w is called the image of v under the transformation T. The set of all images of vectors in V is called the range of T and the set of all v in V such that T(v)=w is called the preimage of w.

>>T.image(v)
(-1,2)
>>T.preimage(w)
(-3,3)

Supporting the property
The function is called a linear transformation of V into W if the following two properties are true for all v and u in V and for any scalar c.
T(u+v)=T(u)+T(v)
T(cu)=cT(u)

>>V.isTransform(W)
true
>>V=VectorSpace(x)
>>W=VectorSpcae(x^2)
>>V.istransform(W)
False

Linear Transformation defined by a matrix
Let A be a mxn matrix. The function T is defined by T(V)=AV is a linear transformation from Rn into Rm.

>>V=VectorSpace(x,y)
>>A=Matrix([3,0],[2,1],[-1,-2](/sympy/sympy/wiki/3,0],[2,1],[-1,-2))
>>T=Transformation(V,A)
>>v=Vector(2,-1)
(2,-1)
>> w=T.transform(v)
(6,3,0)

Transformation from matrix to matrix

>>A=Matrix()
>>T=Transformation(A,A.Transpose)
>>a=Matrix([1,2],[2,3](/sympy/sympy/wiki/1,2],[2,3))
>>T.transform(a)
Matrix([
[1,2],
[2,3]])

Differential operator as linear transformation
E.g. T: f --> f’ +2f
T(x2+5x) = 2x2+12x+5

Integration as linear transformation
E.g. T(p)= integration of p(x) from -1 to 1
T(x2)=2/3

Kernel of linear transformation
Let T: V --> W be a linear transformation. Then the set of all vectors v in V that satisfy T(v)=0 is called the kernel of and is denoted by ker(T)

>>V=VectorSpace(x,y)
>>W=VectorSpace(x-2y,0,-x)
>>T=Transformation(V,W)
>>T.ker()
={0}

Range of linear transformation
Range of T: V  W is the set of all vectors w in W that are images of vectors in V. That is range (T)={T(v) : v is in V}

Finding the basis for kernel, range

Finding the dimension
nullity(T) : dimension of kernel of T
rank(T) : dimension of range of T
dimension of the domain : rank + nullity

>>V=VectorSpace(x,y,z)
>>A= Matrix([1,0,-2],[0,1,1],[0,0,0](/sympy/sympy/wiki/1,0,-2],[0,1,1],[0,0,0))
>>T=Transformation(V,AV)
>>T.rank()
2
>>T.nullity()
1

Finding the standard matrix for a linear Transformation

>>V=VectorSpace(x,y,z)
>>W=VectorSpace(x-2y,2x+y)
>>T=Transformation(V,W)
>>T.transformMatrix()
Matrix([
[1,-2,0],
[2,1,0]
])

Composition of linear transformation
The composition of T, of T1 : Rn --> Rm with T2 : Rm --> Rk is defined by,
T(v) = T2(T1(v))

>>V=VectorSpace(x,y)
>>W=VectorSpace(x-y,x+y)
>>Y=VectorSpace(x/2,y/2)
>>T1=Transformation(V,W)
>>T2=Tranformation(V,Y)
>>T=T1.composite(T2)

>>v=(5,3)
>>T.transform(v)
(1,4)

Standard matrix for composition
Standard matrix for composition will be the multiplication of standard matrix of each

>>V=VectorSpace(x,y,z)
>>W=VectorSpace(2x+y,0,x+z)
>>Y=VectorSpace(x-y,,z,y)
>>T1=Transformation(V,W)
>>T2=Tranformation(V,Y)
>>T=T1.composite(T2)

>>A1=T1.transformMatrix()
Matrix([
[2,1,0],
[0,0,0],
[1,0,1]
])
>> A2=T2.transformMatrix()
Matrix([
[1,-1,0],
[0,0,1],
[0,1,0]
])
>>A=T.transformMatrix()
Matrix([
[2,-2,1],
[0,0,0],
[1,0,0]
])
>>A1*A2
Matrix([
[2,-2,1],
[0,0,0],
[1,0,0]
])

Inverse of a linear transformation
If the standard matrix A of a linear transformation T has inverse then T is also invertible

>>V=VectorSpace(x,y,z)
>>W=VectorSpace(2x+3y+z,3x+3y+z,2x+4y+z)
>>Y=Transformation(V,W)
>>Y.isinvertible()
True
>>A=Y.transformMatrix()
Matrix([
[2,3,1],
[3,3,1],
[2,4,1]
])
>>A**(-1)
Matrix([
[-1,1,0],
[-1,0,1],
[6,-2,-3]
])
>>Y1=Y.inverse()
>>Y1.transformMatrix()
Matrix([
[-1,1,0],
[-1,0,1],
[6,-2,-3]
])

Finding matrix relative to nonstandard basis
Defining a nonstandard basis for a vector space and Finding the transformation matrix.

>>B=Basis((1,2),(-1,1)))
>>B1= Basis((1,0),(0,1)))
>>V=VectorSpace(x,y,B)
>>W=VectorSpace(x+y,2x-y,B1)
>>T=Transformation(V,W)
>>T.tranformMatrix()
Matrix([
[3,0],
[0,-3]
])

Transition Matrix
Matrix for a linear transformation T: V  V depends on the basis of V. The matrix for T relative to a basis B is different from the matrix for T relative to another basis B’.
Transition matrix from B to B’: P
Transition matrix from B’ to B: P-1

>>B=Basis((-3,2),(4,-2))
>>B1=Basis((-1,2),(2,-2))
>>P=B.transitionMatrix(B1)
Matrix([
[3,-2],
[2,-1]
])
>>P1=B1.transitionMatrix(B)
Matrix([
[-1,2],
[-2,3]
])

Similar matrix
For square matrices A and A’ of order n, A’ is said to be similar to A if there exists an invertible matrix P such that A’ = P-1AP

>>A=Matrix([2,-2],[-1,3](/sympy/sympy/wiki/2,-2],[-1,3))
>>A1=Matrix([3,-2],[-1,2](/sympy/sympy/wiki/3,-2],[-1,2))
>>A.similar(A1)
Matrix([
[1,1],
[0,1]
])

Schedule

Before starting the project
Learn advanced features of python
Understand code of sympy
Practicing Git
Updating the schedule

Week 1 & 2
Implementing basic classes such Vector Spaces, Transformation and Bases Testing in implemented classes

Week 3
Implementing additional properties of transformation

Week 4
Transformation using matrix and Matrix to Matrix transformation

Week 5 & 6
Implementing available transformations such as Integration and Differentiation

Week 7
Testing all the implemented functions

Week 8
Implementing kernel, image and dimensions

Week 9
Finding Basis

Week 10
Finding standard matrix

Week 11
Composition in transformation and finding standard matrix for composition

Week 12
Inverse of a transition and finding matrix for non-standard basis

Week 13
Finding transition matrix and similar matrix

Week 14
Testing and final modifications

Reference

Elementary linear Algebra 6th Edition by Ron Larson
Chapter 6: Linear Transformations
http://www.jetbrains.com/pycharm/features/