Week 1

Published: 06/01/2023

As I had discussed with Ondřej, my goal for the first couple of weeks would be to get a basic assignment and print statement working for a`SymbolicExpression` for instance the `Symbol` class from SymPy. So I had to support something like the following

from lpython import S
from sympy import Symbol

def main0():
   x: S = Symbol('x')



This task would comprise of the following few steps

  * Supporting imports from `SymPy` for `CPython`

  * Introducing the `SymbolicExpression` ttype

  * Introducing `SymbolicSymbol` as an intrinsic function

  * Adding support in `visit_print` and `visit_assignment` to handle symbolic expressions

I managed to raise a pull request 1846 and address the first 3 steps and I am halfway through with the 4th step. Hence we currently have a decent Abstract Semantic Representation (ASR) of our program above. It goes as follows:

    (Var 2 x)
            (Character 1 1 () [])
    [(Var 2 x)]

Well as of now, I can't claim that I have cracked the solution for the 4th step. As discussed in my weekly meeting with Ondřej, we are still not fully sure as to how we could support the above program in the backend. We are still exploring the most probable and easily achievable approaches . While framing my GSoC proposal, we were more inclined towards framing a pass which would make function calls to `SymEngine's C interface`. But as we were brainstorming during our meet we realized some potential downsides to this approach and hence we tried framing a somewhat newer approach for the same, which goes as follows:

  * Skip implementing `instantiate_SymbolicSymbol` and the pass to replace the intrinsic function node.

  * Take inspiration from how assignment statements work for the `Complex` ttype in LPython and try extending the `visit_assignment` function for symbolic expressions accordingly.

  * Introduce `symengine_str` function similar to how `print_f` for handling print statements.

I am halway through this approach and I feel this would be the correct way to go. I will try to resolve these in the 2nd week of my coding period.Finally, I would like to point out some tasks which need to be addressed in Week 2 or the upcoming weeks

  * Finish `generate_SymbolicSymbol` function implementation (kept as TODO for now)

  * Finish `SymbolicSymbol::verify_args` function implementation (kept as TODO for now)

  * Finish `eval_SymbolicSymbol` function implementation (kept as TODO for now)

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