My name is Abdullah Javed Nesar, I am an undergraduate student at Indian Institute of Technology, Kharagpur.

**About the Project**

A **Ru**le **b**ased **i**ntegrator nicknamed **Rubi** is an entirely new module in SymPy, Integrals. It is an implementation of more than 10,000 rules to cover a wide variety of indefinite integration. Currently SymPy uses algorithms for indefinite integration which are too slow and presents results which are not simplified. Rubi utilizes a set of well defined rules which makes it smart to present the results in a more symmetric and simplified manner.

**The Plan**

The plan earlier was to implement a completely new pattern matcher with multiple functionalities which was as efficient as Mathematica’s pattern matcher. As the pattern matcher would be the back bone of Rubi. But later we came across matchpy and we planned to implement it in our module. But because it is implemented in Python3.6 Rubi isn’t capable to support Python version less then 3.6.

**Work Done**

- Utility functions: We have managed to cover majority of the utility functions. Our job was to re-write functions from mathematica to Python.
- Added rules into SymPy using Python parser.
- Added tests cases. But unfortunately we could not include all the tests due to performance issue in Python. Tests was taking too long so we decided to include only a few of them.

**Future Work**

- Although we have implemented all the rules, but we could not work much on the performance and so it takes too long for Python to compute results. Because of this issue we could not add all the test cases.
- Working on left out Utility functions. Few of the utility functions were a bit tricky like
`Dist`

,`FixRhsIntRule`

etc are yet to be implemented. - Extending rules set for a smarter computation and better results.
- Replacing the SymPy’s pattern matcher with matchpy in utility functions.

**Conclusion**

I would like to thank my mentor Ondřej Čertík for this project idea and helping me understand the project, I am also thankful to Francesco Bonazzi and Aaron Meurer for helping me from the very beginning at every stage whenever I needed help.

**References**

- Link to pull request: https://github.com/sympy/sympy/pull/12978
- Weekly blog link: https://nesar2017.wordpress.com/

`PowerVariableDegree`

I’ve fixed those.
]]>`Rt()`

which could only handle numeric value the new definition can handle even expressions. This week I was a bit engaged with my pending academic works so I was a bit inactive. I’ll be committing my changes soon. These are few tests for `Rt()`

.
```
def test_Rt():
assert Rt(x**2, 2) == x
assert Rt(S(2 + 3*I), S(8)) == (2 + 3*I)**(1/8)
assert Rt(x**2 + 4 + 4*x, 2) == x + 2
assert Rt(S(8), S(3)) == 2
assert Rt(S(16807), S(5)) == 7
```

]]>

`TrigReduce()`

is an inbuilt function in Mathematica, following is its code in Python.

def TrigReduce(i): if SumQ(i): t = 0 for k in i.args: t += TrigReduce(k) return t if ProductQ(i): if any(PowerQ(k) for k in i.args): if (i.rewrite(sin, exp).rewrite(cos, exp).expand().rewrite(exp, sin)).has(I): return i.rewrite(sin, exp).rewrite(cos, exp).expand().rewrite(exp, sin).simplify() else: return i.rewrite(sin, exp).rewrite(cos, exp).expand().rewrite(exp, sin) else: a = Wild('a') b = Wild('b') v = Wild('v') Match = i.match(v*sin(a)*cos(b)) if Match: a = Match[a] b = Match[b] v = Match[v] # 2 sin A cos B = sin(A + B) + sin(A − B) return i.subs(v*sin(a)*cos(b), v*S(1)/2*(sin(a + b) + sin(a - b))) Match = i.match(v*sin(a)*sin(b)) if Match: a = Match[a] b = Match[b] v = Match[v] # 2 sin A sin B = cos(A − B) − cos(A + B) return i.subs(v*sin(a)*sin(b), v*S(1)/2*cos(a - b) - cos(a + b)) Match = i.match(v*cos(a)*cos(b)) if Match: a = Match[a] b = Match[b] v = Match[v] # 2 cos A cos B = cos(A + B) + cos(A − B) return i.subs(v*cos(a)*cos(b), v*S(1)/2*cos(a + b) + cos(a - b)) if PowerQ(i): if i.has(sin): if (i.rewrite(sin, exp).expand().rewrite(exp, sin)).has(I): return i.rewrite(sin, exp).expand().rewrite(exp, sin).simplify() else: return i.rewrite(sin, exp).expand().rewrite(exp, sin) if i.has(cos): if (i.rewrite(cos, exp).expand().rewrite(exp, cos)).has(I): return i.rewrite(cos, exp).expand().rewrite(exp, cos).simplify() else: return i.rewrite(cos, exp).expand().rewrite(exp, cos) else: return i

Some tests for `TrigReduce()`

assert TrigReduce(cos(x)**2) == cos(2*x)/2 + 1/2 assert TrigReduce(cos(x)**2*sin(x)) == sin(x)/4 + sin(3*x)/4 assert TrigReduce(cos(x)**2+sin(x)) == sin(x) + cos(2*x)/2 + 1/2 assert TrigReduce(cos(x)**2*sin(x)**5) == 5*sin(x)/64 + sin(3*x)/64 - 3*sin(5*x)/64 + sin(7*x)/64 assert TrigReduce(2*sin(x)*cos(x) + 2*cos(x)**2) == sin(2*x) + cos(2*x) + 1

I have taken some help from a reply in stackoverflow and may be now we can answer that question much better.

My next week’s target would be to complete all the utility functions and fix bugs as much as possible.

]]>Currently I’m work on implementation of **Normalization functions**, although I have implemented `NormalizeIntegrandFactorBase`

using SymPy’s pattern matcher but that needs a bit improvisation. After that I’ll complete implementation of `SimpHelp`

.

May be a couple of weeks more and we’ll be done with the implementation of all the Utility Functions.

]]>

Arihant and I have made a good progress on implementation of Utility functions and have successfully implemented almost half of it. Till now we have worked on it in sets with each containing 7 to 15 functions along with tests which takes approximately 3-5 days for complete implementation. Some of the functions used are predefined in Mathematica and to define those in SymPy we need to look into its definitions and examples. Thanks to Francesco for helping whenever I got stuck. Recently I have changed the format of all Linear products\Algebraic test suit and sympified the numbers using Regex. Hopefully we’ll be completing all the functions to support Linear products\Algebraic rules soon.

]]>After adding Algebraic\Linear Product rules and tests Arihant and I are working on implementations of Utility Functions, there is a huge set Utility Functions that needs to be implemented before we proceed ahead with next set of rules. Once we are done with the entire set of utility functions implementing rules and adding tests would be an easy task. Understanding the Mathematica codes and analyzing its dependent functions and converting it into Python syntax is a major task.

We started with implementation of only those functions which were necessary to support **Algebraic rules\Linear Products** but because they were dependent on the previous functions we had to start off from the very beginning of the Pdf. So far we have implemented more that 100 utility functions. Our priority is to implement all Utility functions capable to support Algebraic Rules as soon as possible.

The first week comes to an end and we (Arihant and me) have partially implemented Algebraic functions\ Linear products.

**THE PROGRESS**

Most of my task was to translate Algebraic Integration tests from Maple Syntax to Python, write Utility Functions and writing tests for Utility Functions. I have already implemented 1 Algebraic functions\1 Linear products\1.2 (a+b x)**m (c+d x)**n, here. And test sets for 1 Algebraic functions\1 Linear products\1.3 (a+b x)**m (c+d x)**n (e+f x)**p and 1 Algebraic functions\1 Linear products\1.4 (a+b x)^m (c+d x)^n (e+f x)^p (g+h x)^q are almost ready here along with most of the Utility Functions we require till now, after this we will be successfully covering the Algebraic\ Linear products portion.

Next what’s delaying our progress is Utility Functions, I have been taking help from this pdf on Integration Utility Functions and looking for their definitions in Mathematica website but the major problem is the definitions provided are not very clear or no definition at all. Meanwhile Arihant was implementing RUBI rules, default values for variables and working on constraints .

]]>Community bonding period is officially over, I have been taking help from my mentors and ex-gsocer friends. This would be my first experience on working on parsing so I am very excited. I have taken help from Francesco to get a better idea about my work and we have even discussed it with Ondrej. The work is divided between us (me and Arihant) .

- 1st person: translates the code of MatchPy.
- 2nd person: creates a translator for the RUBI rules (first to MatchPy, then to the new code that person 1 will develop).

I have taken second persons work preparing a translator to transform downvalues of the RUBI rules to MatchPy.

I have been reading more on regular expressions in python and now I have sufficient knowledge to head start. Francesco had provided a basic parser I will be trying to extend that and translate rules in small bits.