Week 7

Hello y’all, I am super happy to announce that I was successfully able to finish the first part of my GSoC project this week. So week 7 was a good week overall. Talking about the progress I made, I had to cover 2 tasks before moving to the next half of the project and those were

  • Adding support for symbolic Expand & Differentiation - The only catch here being sympy supports symbolic operations and attributes on symbolic expressions and as functions too which accept symbolic expressions. Hence I raised a pull request #2077 for supporting this.
  • Adding support for symbolic elementary functions like sin, exp, abs & others - Here I had to create a macro create_symbolic_unary_macro to add support all elementary functions. I raised a pull request #2094 for supporting this.

Through these Pr’s now we could support the following programs

(lf) anutosh491@spbhat68:~/lpython/lpython$ cat examples/expr2.py 
from sympy import Symbol, expand

def main0():
    x: S = Symbol('x')
    y: S = Symbol('y')
    z: S = (x + y)**S(3)
    print(z.expand())
    print(expand((x + y)**S(4)))

main0()

(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython --backend=c --enable-symengine examples/expr2.py 
3*x*y**2 + 3*x**2*y + x**3 + y**3
4*x*y**3 + 6*x**2*y**2 + 4*x**3*y + x**4 + y**4
(lf) anutosh491@spbhat68:~/lpython/lpython$ cat examples/expr2.py 
from sympy import Symbol, Abs, sin, pi, log, exp
def main0():
    x: S = Symbol('x')
    y: S = Symbol('y')
    z: S = exp(x**S(2) + pi)
    print(z)
    print(sin(z))
    print(log(z + Abs(S(-10))))

main0()

(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython --backend=c --enable-symengine examples/expr2.py 
exp(x**2 + pi)
sin(exp(x**2 + pi))
log(10 + exp(x**2 + pi))

I got these PR’s reviewed by Ondřej and once they were merged, I could say that the first part of my project was now complete. Moving onto the next half. So during our weekly meet, we discussed that the next half of the project should be aimed towards supporting symbolic expressions and operations for all backends. We decided to frame a new ASR to ASR pass that would consolidate all the symbolic support into just one file (the ASR pass) and it would make it work with any backend, including C and LLVM.

We would essentially be making use of the bindC functionality available in Lpython and whenever we encounter a symbolic function like basic_add or basic_new_stack we would end up making C calls to symengine’s C wrapper header file where all these functions have been defined. I am still currently figuring how I could get this working and positively I aim to have something concrete in place by end of week 8

Talking about my plans for the next week.

  • Discuss out the new implementation plan with my mentors.
  • Start framing the ASR pass.

Thank You for going through the blog. I hope you like it. Stick around for what’s next to come. Moving into Week 8!

Address

Mumbai, Maharashtra, India