While running the Rubi test suit I found that matching was getting slower as the test progressed. Manuel suggested to analyze the code using snakeviz.

Two functions which were taking significant amount of time were `ExpandIntegrand`(a utility function) and MatchPy’s pattern matching. Here is the sunburst chart for 100 integrands(pink coloured arc corresponds to time taken by `ExpandIntegrand`): `ExpandIntegrand` expands the expression into sums of smaller terms. And then each of those terms gets integrated again. This can be very time consuming if the expression is of the form `(1 + x)**10/x`. I should try to optimize `ExpandIntegrand` and use SymPy’s `.expand()` function whenever possible. Manuel made some improvements to MatchPy which prevents redundant work in the matcher.

#### Test Suit

Rubi test suit we have gives us the optimal antiderivative, for some of the integrands, SymPy gives correct output but the answers does not match because the answer cannot be matched. Example:

``````>>> r1 = -sqrt(a + b*x)/x - b*sqrt(a + b*x)*atanh(sqrt(1 + b*x/a))/(a*sqrt(1 + b*x/a)) # Rubi Output
>>> r2 = - b*atanh(sqrt(a + b*x)/sqrt(a))/sqrt(a) - sqrt(a + b*x)/x # Optimal answer
>>> r1 == r2
False
``````

In the above example both `r1` and `r2` are same(they render same graphs).

#### Utility Functions

Mathematica has functionality of matching functions such as:

``````ExpandIntegrand[u_*(a_.+b_.*F_[c_.+d_.*x_])^n_,x_Symbol] :=
ExpandLinearProduct[(a+b*F[c+d*x])^n,u,c,d,x] /;
FreeQ[{a,b,c,d,n},x] && PolynomialQ[u,x] && MemberQ[{ArcSin,ArcCos,ArcSinh,ArcCosh},F]
``````

In the above example, `F_[ ]` can match functions. SymPy only has single `Wild` which can match a single node. So, in order to match the above pattern(`u_*(a_.+b_.*F_[c_.+d_.*x_])^n_`), I need to do `.match()` twice in order to match the expression with the pattern.

Francesco suggested to generate test suit for utility functions by exporting I/O of functions in Mathematica. I am trying it for functions which are very large such as `ExpandIntegrand` and `FixSimplify`.

I and Abdullah are about to complete 50% of utility functions. I will continue working on utility functions and try my best to complete it by next weekend.