GSoC Week 7

by on under jekyll
1 minute read

In the initial parts of this week, I was working to debug 2 more issues - sympy/sympy#18363 and sympy/sympy#21598.

For the first issue, the thing to observe is that real_root returns a piecewise -

In [1]: (real_root(x - 6, 3) + 2)/(x + 2)
Out[1]:
⎛⎧3 _________                           ⎞
⎜⎪╲╱ │x - 6│ ⋅sign(x - 6)  for im(x) = 0⎟
⎜⎨                                      ⎟ + 2
⎜⎪       3 _______                      ⎟
⎝⎩       ╲╱ x - 6            otherwise  ⎠
─────────────────────────────────────────────
                    x + 2

So, the issue involved some incorrect operation on piecewise functions. I found that Add._eval_as_leading_term must perform piecewise_fold to fix this issue. An interesting thing is that I had encountered a similar need in an older PR - sympy/sympy#20754, so it was relatively quick to debug.

Regarding the second issue, the problem was that the expression, which is symbolically 0, was not returning 0. To fix this, the first step of changing log._eval_as_leading_term was already done last week, so this week I just had to add some simplification. I found that expand_log fitted my needs best, but Kalevi suggested that the full call may not be needed - and could potentially be expensive. So, I just used expand with some specific flags which represent the last statement of expand_log.

A PR was opened combining these two weeks - sympy/sympy#21775.It was also reviewed and merged within a day!

Next week, I would be looking into some improvements to mrv_leadterm.

gsoc, SymPy