GSOC 2019 Linear algebra:Tensor core on Sympy - sympy/sympy GitHub Wiki

Sympy:-Linear algebra:Tensor core Google summer of code 2019

Rahul
New Delhi,India Email:- [email protected] Github Username:-Raarav Gitter Username:-@Raarav

About Me:-

Currently, I am in 3rd year undergraduate student at “Ch. Brahm Prakash Government Engineering College(affiliated by GGSIPU)” pursuing course Information Technology(IT).At the school time. I have lot of interest in programming and development.I love to reading and solving problem of mathematics like:- algebra,statistics,probability etc. I have also good command in Data structure and algorithms. I also regularly participate in hackathon. I also take participate in college level competitions But, Recently my interest is boostup towards python and data science. Because python is faster and easy to learn and apply and I got chance to contribute into open source development by Gsoc 2019.

Programming Background :-

I have 5 year experience in C/C++ as well as 3 year in Python.I love to working on data science,ML,Deep Learning and how to implement and use in realistic things and I have skill like:-Python,C,C++,java, android. C++ is not most widely used in data science and Machine learning as well as not java.but most suitable use python. And By python and make code smaller and faster than other so i choice python and i love to mathematics so it is more good to me that i can apply python.

Work and Experience:-

I have been worked on following libraries. 1.)Numpy, 2.)Pandas, 3.)Opencv 4.)math 5.)matplotlib 6.)tensorflow etc.

And now i am trying to apply sympy contributing on sympy organisation with mathematical concepts in linear algebra,series expansion,graphics etc.

The Project:- Introduction-

Linear algebra is the branch of mathematics concerning linear equations such as a1x1+a2x2+…………+anxn=b linear functions such as (x1,.........,xn)->a1x1+............+anxn, and their representations through matrices and vector spaces.

Linear algebra topics Mathematical operations with matrices (addition, multiplication) Matrix inverses and determinants Solving systems of equations with matrices Euclidean vector spaces Eigenvalues and eigenvectors Orthogonal matrices Positive definite matrices Linear transformations Projections Linear dependence and independence Singular value decomposition Phase :-1 Mathematical operations with matrices (addition, multiplication) Addition of Matrices :-Denote the sum of two matrices A and B (of the same dimensions) by C = A + B.. The sum is defined by adding entries with the same indices over all i and j. Example:

Subtraction of Matrices:- Subtraction is performed in analogous way. Example:

Scalar multiplication:- To multiply a matrix with a real number, we multiply each element with this number. Example:

Multiplication of a row vector by a column vector This multiplication is only possible if the row vector and the column vector have the same number of elements. To multiply the row by the column, one multiplies corresponding elements, then adds the results. Example:

If the row vector and the column vector are not of the same length, their product is not defined. Example:

The Product of a Row Vector and Matrix:- When the number of elements in row vector is the same as the number of rows in the second matrix then this matrix multiplication can be performed. Example:

If the number of elements in row vector is NOT the same as the number of rows in the second matrix then their product is not defined. Example:

Matrix inverses and determinants Finding the inverse of a matrix is very important in many areas of science. For example, decrypting a coded message uses the inverse of a matrix. Determinant may be used to answer this problem. Indeed, let A be a square matrix. We know that A is invertible if and only if . Also if A has order n, then the cofactor Ai,j is defined as the determinant of the square matrix of order (n-1) obtained from A by removing the row number i and the column number j multiplied by (-1)i+j. Recall

for any fixed i, and

for any fixed j. Define the adjoint of A, denoted adj(A), to be the transpose of the matrix whose ijth entry is Aij. Example. Let

We have

Let us evaluate . We have

Note that . Therefore, we have

Is this formula only true for this matrix, or does a similar formula exist for any square matrix? In fact, we do have a similar formula. Theorem. For any square matrix A of order n, we have

In particular, if , then

For a square matrix of order 2, we have

which gives

Code:- Matrix object: Run code block in SymPy Live

from sympy.interactive.printing import init_printing

init_printing(use_unicode=False, wrap_line=False)

from sympy.matrices import Matrix, eye, zeros, ones, diag, GramSchmidt

M = Matrix([1,0,0], 0,0,0); M

[1 0 0]

[ ]

[0 0 0]

Matrix([M, (0, 0, -1)])

[1 0 0 ]

[ ]

[0 0 0 ]

[ ]

[0 0 -1]

Matrix(1, 2, 3)

[1 2 3]

Matrix([1, 2, 3])

[1]

[ ]

[2]

[ ]

[3] Linear Transformation:- Also, a linear transformation always maps lines to lines (or to zero). When and are finite dimensional, a general linear transformation can be written as a matrix multiplication only after specifying a vector.

as_coeff_Mul(rational=False) Efficiently extract the coefficient of a product. def as_coeff_Mul(self, rational=False): """Efficiently extract the coefficient of a product. """ return S.One, self

as_explicit() Returns a dense Matrix with elements represented explicitly Returns an object of type ImmutableDenseMatrix. def as_explicit(self): """ Returns a dense Matrix with elements represented explicitly

    Returns an object of type ImmutableDenseMatrix.

    Examples
    ========

    >>> from sympy import Identity
    >>> I = Identity(3)
    >>> I
    I
    >>> I.as_explicit()
    Matrix([
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]])

    See Also
    ========
    as_mutable: returns mutable Matrix type

    """
    from sympy.matrices.immutable import ImmutableDenseMatrix
    return ImmutableDenseMatrix([[    self[i, j]
                        for j in range(self.cols)]
                        for i in range(self.rows)])

Projection in linear algebra:- In linear algebra and functional analysis, a projection is a linear transformation from a vector space to itself such that . That is, whenever is applied twice to any value, it gives the same result as if it were applied once. Here , is small intro about math i will implement all about of linear algebra subtopic related in this idea. Phase:-2 Milestones

1.Bonding Time Fix exiting error help merging pending PRs and close issues and create milestones on github projects Discuss with mentors and org admins about roadmap and finalise the plan actions. Week 1-2 Studying about idea and analysing it form it’s github documentation and its website https://www.sympy.org/en/index.html create pull and push for PRs. as well as search it’s required tools. For implementation interface use for developing :- Jupyter lab

Weak 3-4 After analysing idea, creating algorithms using mathematics and data structure and try to implement I will use python and i will relate it by numpy, TensorFlow. a.) I will create algorithm for sparse Matrix and vector. b.)i will improve to faster to response as well as possible. c.) i will use all matrices techniques for solving linear algebra problem.

Weak 5-7 These three weaks will be used on a large set of work and try to implement created algorithms i will implement by discussion mentor and check arised issues resolve during doing it. I will make symbolic representation which is given to solve me. I will apply this subtopics in sparse array for better accuracy. Mathematical operations with matrices (addition, multiplication) Matrix inverses and determinants Solving systems of equations with matrices Euclidean vector spaces Eigenvalues and eigenvectors Orthogonal matrices Positive definite matrices

Weak 8-9

Remaining topics like :- Linear transformations Projections Linear dependence and independence Singular value decomposition I will implement and check issues and take mentor advice.

Weak 10-11 In this Weak After having ported i will consider some extra work which is given in this idea
Implement some well known tensor math - i.e. (relativity, electromagnetism, fluids). Unify the various SymPy modules using custom matrices and array implementations.

Weak 12 Will wrap up the project by now and will help with documenting the project. Basically in this week if there’s any small small trailing work left I would finish it.

I will check my implenemation is reponse well or not.

Contributions to sympy:-

#16615 adding comment for future module. #16615 making global variable in test_iterative() method. #16615 comment-adding link about matrix for berief intro.

Contribution:-And last year i had also participated in grande finale of Smart india hackathon 2018 In this hackathon we worked android app which is based on career counselling app which is conducted by sih2018 here is github link :-https://github.com/Raarav/Career_Counselling_app

Now I have no more PR for on Sympy becasue I heared late about Gsoc 2019. Sorry for that if i got heared 4 or 5 month before about 2019. Than i will have more PRs on Sympy and more contributions.

I promise that if i got chance i will more hard on this in summar.

Availability:-

I would be able to devote approx 60 hours every week to GSOC. During. 1th may to 20th may I will have my end-sessional examinations and time devoted would be around 1 hour per day for that time. I have no obligations after May, and would be devoting all my time to GSOC.

I have been part of developer group and open source meetups in Delhi.

I would strive to be regulr, and sincere with my scrum and daily updates.

Platform Used:- I have dual booted system a.)Window 10 and b.)Ubuntu 17 version. I will prefer window 10 which easy to handle for me. But some specific i may use ubuntu.i will use jupyter lab or spyder framework.

I can implement code any interface like pycharm,python idle etc. For specific if recommended.

References:- https://docs.sympy.org/latest/modules/matrices/matrices.html https://docs.sympy.org/latest/modules/matrices/index.html https://stackoverflow.com/questions/48479317/what-exactly-are-indexed-objects-in-sympy https://github.com/Raarav/sympy/blob/master/sympy/tensor https://www.mathportal.org/linear-algebra/matrices/matrix-operations.php https://en.wikipedia.org/wiki/Linear_algebra https://en.wikipedia.org/wiki/Projection_(linear_algebra) https://docs.sympy.org/latest/modules/tensor/indexed.html https://www.coursera.org/learn/machine-learning/home/welcome https://www.coursera.org/learn/algorithmic-toolbox/home/welcome https://docs.sympy.org/1.0/_modules/sympy/tensor/tensor.html https://docs.sympy.org/latest/tutorial/matrices.html