GSoC 2017 Application Mohit Chandra: Implementation of Vector Integration in Higher Dimensions - sympy/sympy GitHub Wiki

Note: Important things to remember before reading

  • The term Higher Dimension means that it is valid for n-dimension where n is a positive integer.
  • Unless mentioned assume that I will use the dim_vector class (Which is a part of my proposal) for defining vectors and functions.
  • The term n-dimensional vector refers to a vector in n-dimensions where n is an positive integer.

Index



Personal Background


Details

Name: Mohit Chandra

Age: 20

University: International Institute of Information Technology, Hyderabad, India (IIIT-Hyderabad)

E-Mail: [email protected]

Github: mohit3011

IRC: mohit3011

Time-Zone: IST (UTC +5:30)

About Me

Hi, I am Mohit Chandra. I am currently in my second year and pursuing (B.Tech + M.S) in Computer Science and Engineering from International Institute of Information Technology, Hyderabad, India. I was interested in programming from a small age and was first introduced with Java in 8th standard. From then I have never looked back and have learned many technologies and languages.

I was introduced to python as part of the university curriculum and I liked the philosophy behind python so good that it has become my preferred choice of language.I have been working in python for almost 1 and a half year now and in the time being I have explored many libraries and worked on many projects. I had the opportunity to create:

  1. A Tetris Game (using pygame library)
  2. A blogging website like “Quora” (using Django web framework)
  3. Another quizzing web app (using web2py)
  4. Block Game on Open-Gl-3d
  5. Project on Fine-grained Data Visualisation

and many more.

My journey till now in my university has been really wonderful, I have learned a variety of things from designing OS system calls to creating Open-GL games and I definitely believe that there's much more to learn & explore.

I came to know about Sympy in around November 2016 when I was looking for libraries in python which could support me in mathematical works. The first thing which I found really interesting was that Sympy was based on symbolic mathematics and secondly it had a really well documented website with a live shell. This helped me to further explore Sympy and finally I started contributing to it in December 2016.

My favorite feature of Sympy

It would surely be the integration module of Sympy and in that too, the functionality of Fourier and Laplace transform as I use them quite often for my academic purposes (It saves quite a lot of effort and time when I deal with complex expressions).

>>> from sympy import fourier_transform, exp
>>> from sympy.abc import x, k
>>> fourier_transform(exp(-x**2), x, k)
sqrt(pi)*exp(-pi**2*k**2)

Platform Details

Operating System: MacOS X (El Capitan)

Text-Editor: Sublime Text 3 (because it improves my productivity)

Hardware: Intel Core i5 / 8 GB RAM

Contributions & Issues Raised

Contributions

Issues Raised

  • Simplifications in Dirac Delta function: In this issue, I suggested automation in the working of DiracDelta function due to its properties in Sympy. I also submitted a PR for this but, there came some problem during the automation process due to failing tests. After taking the suggestion from Kalevi Suominen I closed the issue.

  • Addition of the Laplacian Operator: In this issue, I suggested the addition of Laplacian operator, but this issue was reported earlier too. I also submitted a PR regarding this issue but due to the other issue being older I closed this issue.

  • Addition of Directional Derivative Function: In this issue, I suggested addition of Directional derivative function. I have submitted a PR regarding this issue and this PR is Merged.


Project Overview


Problem & Motivation

Vector Calculus plays an essential role when it comes to its implementation in various fields of mathematics & physics. Currently, Sympy lacks a well-structured support of a module related to vector integration and I think that a module related to vector integration is an essential need for a CAS.

Also, Sympy currently has the provision for 3-D dimensional vectors which is good but certainly not sufficient, currently the user cannot work with vectors in more 3 dimensions and therefore there is a need for a system which would provide the ability to create and work with vectors in n dimensions where n is a positive integer.

A solution to the above problems would be to create a structure/class for handling higher dimension vectors and this class would also help in the purpose of vector calculus (mainly vector integration). What I believe is that in future this class would replace the existing vector class which is limited to 3 dimensions.

Vector calculus (and Vector integration) is a very fundamental tool for analyzing vector fields and there lies its major applications electrical physics. In my proposal for vector integration in higher dimensions, I believe that focussing on the following would somewhat provide a solution to the existing problem in Sympy:

  1. Implementation of a structure/class for handling n-dimensional vectors and their methods.
  2. Implementation of Line Integrals (In n-dimensional differential 1-form).
  3. Work on implementation of Stokes Theorem.
  4. Implementation of Surface Integrals (In n-dimensional differential 2-form).
  5. Application of Line integration in 3-D.

My motivation for choosing this project was that as an undergraduate student of engineering (or even as a science student) I face many problems which require concepts of vector calculus and integration due to its immense applications in physics and mathematics. A successful implementation of the proposed project would mean that Sympy would provide its user the capability to handle problems related to vector fields which mostly require vector calculus.

Another reason for choosing this project was the fact that I really like vector mathematics due to its awesome applications and the ideas behind it. The real beauty of vector mathematics lies in the fact that how it relates physics to mathematics. Secondly, I like working in Python a lot because of its ease and efficient coding style and functionalities. So, through this project, I would be able to explore two of my favorite things (i.e mathematics and python) more.

Idea Behind The Project

The idea behind this project is to implement vector integration in Sympy which is possible for n-dimensions fields . But, to implement it correctly I would be needing a class which would provide the facilitly for creation and manipulation of n-dimensional vectors. For now, Sympy doesn't allow creation of vectors in dimension > 3 , therefore I have proposed a class which would help in this cause with some of its methods for manipulation.

I have further tried to cover fields in Line and Surface intergrals and have also included Stokes theorem for the relation between surface and Volume integrals.

Discussions

After choosing this project as a part of my proposal. I tried to get guidance & help through the discussion forum, where I was helped by Alan Bromborsky.

Alan, initially helped me by providing a Research Paper on The Fundamental Theorem of Geometric Calculus and Calculus on Manifolds by Michael Spivak. He also asked me to look through the generalised Stokes theorem as a reference.Meanwhile I also approached my professor at the university for help in vector calculus and he suggested me a book Vector Calculus by Susan Jane Colley for better understanding with examples.

Initially, I was a little bit confused and also misinterpreted the point of this project. But, thanks to Alan Bromborsky and Kalevi Suominen who corrected me and helped in shaping the idea. While working towards this proposal I was in constant touch with Kalevi Suominen through email and gitter. Through these conversations I cleared my various doubts & also discussed my ideas.

Link to email conversations with Kalevi Suominen

I further got my draft reviewed by Kalevi Suominen and modified my proposal after his feedback about the project.

How do I fit in?

  • I have been contributing in Sympy from last three months and the journey has been great, I have learned a lot from working in different modules and also got an opportunity to discover many mathematical ideas behind some modules.While contributing I have learned about techniques of development like modularity, test-driven approach etc and thus this project would provide me an excellent opportunity to apply the learned skills.

  • Vector Mathematics has been a subject of interest for me and fortunately, I have taken basic "Vector Mathematics" course at my university. While working on the idea for the project I was greatly helped by the Sympy community who recommended some research papers and books to me. Also, I took help from my Professor at IIIT Hyderabad regarding vector calculus. Thus, I am in a position where I can say that I have a clear idea of the topics and the subject involved.

I was recommended the following reading material by Mr. Alan Brombosky:

  1. Calculus on Manifolds by Michael Spivak
  2. Research Paper The Fundamental Theorem of Geometric Calculus

In addition to this, I also followed the book "Vector Calculus" by Susan Jane Colley (which referred by my Professor) for a better understanding of concepts.

  • I have worked on many projects having python as the main language and been exposed to many different libraries and technologies and thus I am quite familiar as well as confident with python.

  • I would be completing my second year this summer and I am planning to stay back at my college for my research work in Machine Learning. Apart from research work, I don't have anything else to work on and thus I would be able to devote 6-7 hours daily which fulfills the 40 hours requirement criteria.

  • Lastly, I am hardworking and sincere & would do my best to do justice with the assigned task.


Theory for Higher Dimension Vector Calculus


Theory for Differential k-form expressions

1. Basic (differential) k-form on is an expression of the form: where 1<= <= n for j = , .... ,k and '^' denotes the exterior derivative. Properties shown by the differential k-forms are:

  • = -
  • = 0

2. For calculation purpose of k-differential expression we have: () =

det

where det is the determinant and are vectors in n dimension.

3. A general (differential) k-form on is representated as

where F is a function defined on and is a k-differential expression evaluated at

Theory for Vector Integration in Higher Dimension

1. The general definition of vector integration for n-dimensional differential k-form requires a detailed analysis of the field/function and also of the n-dimensional vectors involved. Here, the concept of parameterization plays a major role as we can define the path/surface for integration in terms of these parameterized variables.

2. For a general vector integration over a bounded region , we can represent the co-ordinates in terms of n parametrization variables say . We further use these parametrized variables for differentiation of the Parametrized co-odinates (which are provided).

3. Vector integration for n-dimensional (differential k-form) expression with n-1 paramtrization variables would be:

where are the parametrization variables , represents the differentiated co-odinates w.r.t the parametrized variables and represents differential k-form expression.


Implementation


Approach

My approach for the implementation of the proposal,I have roughly divided my work into 5 subparts. The five submodules/subparts are:

  1. Creating a structure/class for n-dimensions (where n is a positive integer) vectors and methods related to it.
  2. Implementation of Line integrals (in n dimensions).
  3. Surface integrals in (in n-dimensions)
  4. Stokes Theorem related module.
  5. Module on 3-D application of Line integration.
  • My approach to tackling this issue would be based on phase evolutionary model of development, which means that I would be developing the modules in phases and first focussing on core functionalities in a module first. This would ensure that each module gets proper time and more time is spent on implementation & refinement of core functionalities.

  • Division of Phases

    • Phase-1: This phase would include the work on the class related to higher dimension vectors and their methods.
    • Phase-2: This phase would focus on the implementation of Line integrals (in n-dimensions).
    • Phase-3: This phase would be dedicated to the implementation of the Surface integral.
    • Phase-4: This phase would focus on the implementation of Stokes theorem.
    • Phase-5: This phase would be for dealing with bugs and errors and if time permits then I would work on the implementation of 3-D line integration.
  • While developing a module, I would focus on test-driven approach, which means that I would be writing tests first based on examples and conditions. This would ensure that errors are identified at the root level and it would save time & effort.

  • I would be keeping a buffer time at the last for any type of unforeseen errors and mistakes because when any new module/functionality is implemented then errors/failures are bound to come.


Class for Handling Higher Dimension Vectors

In this proposed subpart I would work on definition and usage of higher dimension vector (Dimension > 3). The idea here is to introduce a class structure which would be responsible for holding the coordinates of the vector (in n-dimensions where n is a positive integer) and using them for various methods related to vectors.

I would be using this class to create vectors and fields for line integration, surface integration.

Note:

  • When we consider cases beyond 3 dimensions then certain assumptions and conditions become really important. Like we have to assume that variables for defining various functions in n-dimensions are of the type {x_1, x_2, x_3, ...., x_n}. This convention would ensure that we maintain a common standard across dimensions. But, if the user wants to explicitly use different sets of variables then I have provided that functionality too.

  • The basis vectors in n-dimension are of the type {e_1, e_2, e_3, ...., e_n} . This is also for the standardization purposes.

  • In n-dimensions(n>3), we can represent a vector (say v1) as:

    v1 = c_1*e_1 + c_2*e_2 + .... + c_n*e_n
    

Here , {c_1, c_2, .... , c_n} representes the components toward respective basis vectors and can contain constant or variables in n-dimensions.

Functional Implementation

Parameters of Class (Adhoc Name dim_vector)

  • Component: This is a tuple which represents component along each basis vector. The tuple would be ordered for ease of working with vectors.

  • Dim: This represents the dimension in which we want to work (eg. 4 for 4th dimension).

  • Variable: This is a tuple representing the variables in the dimension (this can be defined the user).

Example for defining a vector:

# Assuming we have already defined varibales x_1,x_2,x_3,x_4
>>> v1 = dim_vector((2, x_2*x_3, 0, x_1), 4, (x_1, x_2, x_3, x_4))
>>> v1
(2*e_1, x_2*x_3*e_2, 0, x_1*e_4) 

Methods for the Vectors

Note: It is not possible to provide pseudocode for all listed methods as the proposal would become too long , therefore I would give example and provide pseudocode for some of the methods. Also , I have named the class dim_vector as an adhoc name.

  • Vector Addition: This method would be used for component-wise vector addition of the vectors. In case of two vectors being of different dimension then it would give an error.
Working Example: 

>>>v1 = dim_vector((2, x_2*x_3, 0, x_1), 4, (x_1, x_2, x_3, x_4))
>>>v2 = dim_vector((x_1, 0, 1, x_2), 4, (x_1, x_2, x_3, x_4))
>>>v1.Add(v2)
((2+x_1)*e_1, x_2*x_3*e_2, 1*e_3, (x_1+x_2)*e_4)

  • Vector Subtraction: This method would be used for component-wise vector subtraction of the vectors. In-case of two vectors being of different dimension then it would give an error.

  • Scalar Multiplication: This method would be used for scaling a vector by a constant or a symbol. In case that symbol is a part of variables that define the space.

pseudocode

def scalar_mul(self, expr) 
    #Assuming we get an expression which can be constant or made up of symbols

    free_symbols = expr.freesymbols
    dim = self.Dim
    basis_list = self.get_basis()
    for element in free_symbol:
        if element in basis_list:
             Raise Error
    for element in self.list:
        element = element*expr

    return self.list
  • Get Basis: This method would be used for getting the list of basis vectors for a vector.
Working Example:

>>>v1 = dim_vector((2, x_2*x_3, 0, x_1), 4, (x_1, x_2, x_3, x_4))
>>>v1.get_basis
(e_1, e_2, e_3, e_4)

  • Get Components: This method would be used for getting the list of components along the basis vectors for a given vector. Working would be similar to get_basis.

  • Dot Product: This method would be used for performing component-wise dot product of two vectors. Issue would be raised the vectors are not of same dimension.

Working Example:

>>>v1 = dim_vector((2, x_2*x_3, 0, x_1), 4, (x_1, x_2, x_3, x_4))
>>>v2 = dim_vector((x_1, 0, 1, x_2), 4, (x_1, x_2, x_3, x_4))
>>>v1.Dot(v2)
2*x_1 + x_1*x_2

  • Differentiation: This method would perform differentiation over each component wrt a variable. The variable should be a symbol(including those used in class).
Woking Example:

>>>v1 = dim_vector((2, x_2*x_3, 0, x_1), 4, (x_1, x_2, x_3, x_4))
>>>v1.diff(x_1)
(0, 0, 0, 1*e_4)

  • Restore_3D: This would be a special method for vectors which would have dimension=3. This method would convert the vectors from the new n-dimensional vector class to the existing vector class.
Working Example:

>>>v1 = dim_vector((2*x_1, x_2*x_3, 0), 3, (x_1, x_2, x_3))
>>>v2 = v1.restore_3d()
>>>v2
2*R.x*R.i + R.y*R.z*R.j      # R = CoordSysCartesian('R')


Line Integration

In this subpart, I would work on the implementation of Line integration of vector field over a given path in n dimensions. This would allow the user to perform Line integration in n-dimension using 1-form expressions.

  • Line Integration in higher dimensions: Let be a path in . If is a 1-form defined over an open set such as

where is a vector field.

&

Then, Line Integration is given by

Functional Implementation

  • The line_integral function would be defined as:

def line_integral(field , para_path , para_var , dim , *args):

Here

  • field: is the vector field in dimension = dim and represented as a tuple obtained from dim_vector.
  • para_path: is the path defined in terms of para_var and represented as a tuple.
  • para_var: is the variable for parametrization.
  • dim: is the dimension.
  • *args: is the tuple for upper and lower bound of para_var (if provided by user).

pseudocode (Adhoc Implementation and have to do more work after discussion)

Step 1). #Check for conditions whether:
         if len(field)==dim or not isinstance(Field, vector) or type(para_path)!='tuple':
            Raise Error
                                      

Step 2). for element in para_path:
            diff_path.append(diff(element,para_var)) #diff_path has each component of para_path differentiated by para_var

Step 3). for element in field:
            substitute para_var in element according to para_path  #Substituting values of variables in n-dimensions according to para_path

Step 4). i=0
         new_expr = S.Zero
         while i<dim:
               new_expr = new_expr + field[i]*diff_path[i]
               i = i+1
Step 5). if args:
           value = integrate(new_expr , (para_var , args[0] , args[1])) #Case of definite Line integration
           return value
         else:
           value = integrate(new_expr, para_var)    #Case of indefinite Line Integration
           return value

Working Example

#Assumming x_1, x_2, x_3, t are symbols
>>>line_integral((x_1, -x_2, x_1+x_2+x_3), (t, 3*t**2, 0), t, 3, (0,2))
-70 


Surface Integration

In this subpart, I would work on the surface integrations using the 2-form differential expressions. After having discussions with Kalevi Suominen, I realized that surface integration when considered beyond 3- dimensions would not represent the curl given by the pair of vectors/basis.

But, still, I have provided a solution for getting the surface integration for n-dimensions for scalar as well as vector fields.

  • Scalar Surface Integration For this type of integration we have a scalar Field in terms of variables in n-dimensions namely {x_1 , x_2, .... , x_n} then Scalar surface integration is given by

where x(t) represents the parametrized path in terms of parametrized variables , N represents the normal.

Note: The Function 'F' in the scalar surface integration can take nC2 combination of 2-form differential expression and thus it is valid in every case and is totally general.

  • Vector Surface Integration: Let D be a bounded connected region in & let . If . Then Vector surface integration is given by

where s & t are parametrized variables.

Example of different types of fields

               1.f(x,y,z) = 3*R.x - R.y + R.z [Case of Scalar surface integration]
               2.f(x,y,z) = 3*R.x*R.i - R.y*R.j + R.z*R.k [Case of Vector surface integration]
 
where R = CoordSysCartesian('R') (according to sympy conventions)

Functional Implementation

  • The surface_integral function would be defined as:

def surface_integral(field , omega, dim, para_path , para_var, str_type, *args):

Here

  • field is the field and represented as a tuple , obtained from dim_vector.
  • omega it is the 2-form expression in n-dimension (given as tuple of tuple).
  • dim represents the dimension (integer).
  • para_path is the path defined in terms of para_var and represented as a tuple.
  • para_var represents the variable for parametrization and represented as tuple.
  • str_type represents whether the intergration is scalar or vector.
  • *args it is a tuple of tuples which represent the lower and upper bounds for para_var (Optional can be provided by user).

pseudocode (Adhoc Implementation and have to do more work after discussion)

Step 1). Check for conditions whether: 1. the inputs are in required forms.

Step 2). for var in para_var:
           for element in para_path:
               diff_path.append(diff(element, var))

Step 3.1). if str_type=='scalar':
              if isinstance(field,vector):
                  Raise error
            
              else:
                  new_expr = S.Zero
                  for element in diff_path.append:
                     substitute the values in variables according to para_path
                  i = 1
                  j = 0
                  while j<=len(field):
                    while i<=n:
                         field[j] = field[j].subs(x_i,'expression acc. to para_path') #substituting value of each variable according to para_path in jth scalar field.
                         i = i+1
                    j = j+1
                  
                  i = 1
                  j = 0
                  while j<=len(field):         #For creating the final expression which is to be integrated
                      expr = expr + field[j]*det[diff(Ts, omega[j][0]) diff(Tt, omega[j][0])]  #I have simplified this
                                                [diff(Ts, omega[j][1]) diff(Tt, omega[j][1])]
                      j = j+1 
                  if args:   #Means if the bounds are given then do definite surface integration
                    result = integrate(integrate(new_expr , (para_var[0] , lower_b_1 , upper_b_1)),(para_var[1], lower_b_2, upper_b_2))

                  else:
                    result = integrate(integrate(new_expr , para_var[0]),para_var[1])


Step 3.2). if str_type=='vector':
             if not type(field)==tuple:
                Raise error
             else:
                new_expr = S.Zero
                for element in diff_path.append:
                    substitute the values in variables according to para_path
                i = 1
                j = 0
                while j<=len(field):
                    while i<=n:
                         field[j] = field[j].subs(x_i,'expression acc. to para_path') #substituting value of each variable according to para_path in jth scalar field.
                         i = i+1
                    j = j+1
                j = 0
                while j<=len(field):         #For creating the final expression which is to be integrated
                      expr = expr + field[j].dot(det[diff(Ts, omega[j][0]) diff(Tt, omega[j][0])])  #I have simplified this and taken dot product
                                                    [diff(Ts, omega[j][1]) diff(Tt, omega[j][1])]
                      j = j+1 
                
                if args:   #Means if the bounds are given then do definite surface integration
                   result = integrate(integrate(new_expr , (para_var[0] , args[0][0], args[0][1])),(para_var[1], args[1][0], args[1][1]))

                else:
                  result = integrate(integrate(new_expr , para_var[0]),para_var[1])



Step 4).  return result

Working Example

#For Scalar surface integral in 4 dimension (Assumming x_1, x_2, x_3, x_4, s, t, defined as symbol)

>>>surface_integral((x_2, -x_4) , ((x_1, x_3), (x_3, x_4)), 4, (s, s-t, 3-s+t*s, -3*t), (s,t), 'scalar', ((-sqrt(1-s**2), sqrt(1-s**2)), (-1,1)))
-2*pi

#For Vector surface integral

>>>surface_integral((x_1*e_1, x_2*e_2, x_3*e_3-2*x_2*e_3) , ((x_1, x_2), (x_2, x_3), (x_3, x_1)), 3, (s*cos(t), s*sin(t), t) , (s, t), 'vector', ((0, 1), (0, 2*pi))
pi**2

Generalised Stokes Theorem

In this module, I would be working on the implementation of Stokes' Theorem. Stokes' theorem is of immense importance as it can be used for relating Surface Integration with the Volume Integral when we consider differential 2-form expressions. I would be working on the implementation of 2-form in 3 Dimesions due to the constraint that when we consider higher dimensions then curl doesn't give the same answer as the dimension.

  • In-general Stokes' Theorem for differential k-form expressions is given by:

Where M represents the region for integration , represents the differential k-form expression & represents the differential k+1 -form expression.

Functional Implementation

Similar to my other modules this would also take vectors from the new vector class. The functions would be defined as:

def(omega, manifold, para_path, para_var, *args):

Here

  • omega: represents the differential 2-form expression provided as a tuple.
  • manifold: represents the 3 dimensional manifold (would be scalar).
  • var: represents the variables used for defining manifold, provided as (tuple) of length=3.
  • para_path: represents the parametrized path of the boundary provided as a tuple.
  • para_var: represents the variables used for parametrization provided as tuple of length=2.
  • *args: If the lower and upper bounds are given for para_var tuple. Would be given as Tuple.

pseudocode (Adhoc Implementation and have to do more work after discussion)


Step 1). if len(para_var)!=2 or len(para_path)!=3 or len(var)!=3 or type(omega)!='tuple':
           Raise error   #There are more checking condition but not written here for simplicity
         else:
           general_cood = (var[0], var[1], var[2], manifold)  #This represents co-ordinates in 4-D (tuple) and will be used in step 2

Step 2). #Checking whether the given `para_path` is valid for applying Stokes Theorem.

Step 2.1). norm_mod = sqrt(diff(manifold, var[0])**2 + diff(manifold, var[1])**2 + diff(manifold, var[2])**2 + 1)
           norm_comp = (diff(manifold, var[0])/norm_mod, diff(manifold, var[2])/norm_mod, diff(manifold, var[2])/norm_mod, -1/norm_mod)

Step 2.2) #Get partially diferentiated co-ordinates
          T_1 = diff each element of genral_cood wrt var[0]
          T_2 = diff each element of genral_cood wrt var[1]
          T_3 = diff each element of genral_cood wrt var[2]

Step 2.3) a_1 = substitute the values in T_1 according to para_path
          a_2 = substitute the values in T_2 according to para_path
          a_3 = substitute the values in T_3 according to para_path

Step 2.4) if det[norm_comp, a_1, a_2, a_3] >0: #This step takes the determinant of a 4X4 Matrix
             parametrization is valid
          else:
             Raise error

If parametrization is valid:
           
Step 4). if args:
            Perform Vector Triple Integration with bounds
         else:
            Perform Indefinite Triple Integration

Step 5). Return Result         

Note:

  • This is probably the hardest module and would require further analysis. What I have provided here is a pseudocode which would be needing some improvements.

  • But, conceptually this code is correct and would require good amount of time for its implementation.


Line integration in 3-D

In this submodule, I would be implementing line integration for the existing Co-ordinate & Vector system in Sympy. I have done this because most of the user would require to work in 3 dimensions and thus it would be tedious for the user to first define vector through the new proposed class and then perform line integration through the generalized n-dimensionsl) line integration.I plan to further subdivide line integration into two parts:

  • Scalar Line Integration.
  • Vector Line Integration.

I have done this because of the different field inputs as well as different orientation properties of the both integrations.

For Example:   1.f(x,y,z) = 3*R.x - R.y + R.z [Case of Scalar line integration]
               2.f(x,y,z) = 3*R.x*R.i - R.y*R.j + R.z*R.k [Case of Vector line integration]
 
where R = CoordSysCartesian('R') (according to sympy conventions)

**Note:** Here I would be using the existing vector class and co-ordinate system of Sympy and not the new proposed class.

Functional Implementation

I aim to apply this submodule in vector/functions.py as a function.

def line_integral_3d(field , para_path , para_var, str_type, *args):

Here

  • field:: The field (which can be scalar or vector).In case of Vector field type(field)=='tuple'.
  • para_var: Parametric variable.
  • para_path: Parametric Coordinates in terms of para_var (tuple of len==3).
  • str_type: String which defines the type (i.e either 'scalar' or 'vector').
  • *args: Represents the upper and lower bounds of para_var (if provided by the user).

pseudocode (Adhoc Implementation and have to do more work after discussion)

if not type(para_path)==tuple or not len(para_path)==3: 
  raise error
else:
  for element in para_path:
      diff_path.append(diff(element,para_var)) #diff_path has each component of para_path differentiated by para_var
  if str_type=='scalar':
    substitute values according to para_path in the field.
    expr = field*sqrt(diff_path[0]**2 + diff_path[1]**2 + diff_path[2])
    if args:
       result = integrate(expr, (para_var, args[0], args[1]))
    else:
       result = integrate(expr, para_var)
  else:
    if not len(field)==3:
       Raise error
    else:
       i=0
       expr = S.Zero
       while i<3:
          expr = expr + field[i]*diff_path[i]
           i = i+1
       if args:
           result = integrate(expr, (para_var, args[0], args[1]))
       else:
           result = integrate(expr, para_var)

return result

working

>>>R = CoordSysCartesian('R')
>>>Line_integral(3*R.x - R.y + R.z,(sin(t),cos(t),0),0,pi,'scalar')
6

Timeline


This project requires implementation of new definition of vector class (in n-dimensions) with vector integration. Thus , starting early would be the preferred way as the implementation of new modules/functionalities from root level require time, effort & planning.

Pre-GSoC Period

During the pre-GSoC period (1-30 April, 2017) , I would be busy with my academics curricullum as I would be having my end-emester exam as well as some project submissions. But, I would be able to solve some issues and explore further into the vector module in Sympy. Therefore, I would be in constant touch with the Sympy community , I would further discuss on my ideas and way of implementation.

GSoC Period

During this period I would be able to devote 6-7 Hours Daily which fulfills the requirement of minimum 40 hours of work per week. Apart from GSoC I would be doing researchin Machine Learning at my university but that work won't have affect on this project.

  • Community Bonding Period (5 - 30 May ,2017)

    • I consider bonding period to be an excellent time for discussion of new ideas and expansion of existing ones. Though this time is more than required as I am already familiar with the Sympy community and the way of working here.

    • During this period I would try to work on the refinement of my proposal in terms of the efficiency of code, the quality of tests. I would further try to explore alternative ideas for implementation so as to keep them as backups if something goes wrong in the further process.

  • Week 1,2 (31 May - 14 June ,2017)

    • In this period my prime focus would be on developing the class for defining n-dimensional vectors and its methods.
    • Methods to be implemented first would be: Vector Addition, Vector Subtraction, Scalar Multiplication, Get Basis, Get Components, Dot Product, Differentiation.
    • The development would include the tests written.
  • Week 3 (15 - 22 June, 2017)

    • In this week I would work on Restore_3D method of the new class. This work would also include the work for ensuring the backward compatibility of vectors in the existing system.
    • I'm devoting the whole week for compatibility issue as there may come problems while ensuring that vectors produced & handled by the new class can be handled by the existing class (in case of 3-D vectors only).
  • Week 4,5 (23 June - 7 July , 2017)

    • During week 4, my primary focus would be on implementation of line integrals along with its written tests.
    • During week 5, I would work on extra feature of indefinite line integrals and would start my work on Surface integral module
  • Week 6,7 (8 - 22 July , 2017)

    • During these two weeks, I will focus on Surface integrals and writing tests for it.
    • I would also work on adding the functionality of indefinite surface integration to this module with tests.
  • Week 8,9 (23 July - 6 August , 2017)

    • The work on Stokes Theorem is probably the hardest module and it would require time as well as effort for correct implementation.

    • I would work on linking the surface integral with volume integral using stokes theorem with written tests based on real life examples.

    • I have kept a buffer period of around 4-5 days in the week 9 for correcting errors.

  • Week 10 (7 - 14 August, 2017)

    • In week 10 I would work on the implementation of Line integrals in existing vector module of Sympy as I believe that mostly a user would prefer to use this function in case he/she is working in 3 dimensions.

    • The work would include writing tests for it.

  • Week 11,12 (15 - 29 August, 2017)

    • I would work on Documentation part and I have kept a buffer period for unforeseen errors.

Pull Requests

  • First PR: After the completion of Week 4. (Before Phase-1 evaluation)
  • Second PR: After the completion of Week 7. (Before Phase-2 evaluation)
  • Third PR: After completion of Week 12. (Before final evaluation)

Post-GSoC Period

  • After starting to contribute in Sympy, I have realized that my passion lies in open-source contribution and thus I would continue my journey with Sympy.I would like to work and explore other modules and try to work on them too.

  • I would like to become an active member of this organization and conduct events for Sympy and python at my college so that more people can be encouraged to contribute. I would also like to take part in conferences like PyCon , SciPy conference.


References