Repository navigation
Description
- get the mrv() function finished that doesn't need the SubsSet (see my
gruntz2branch) - Implement missing ASR features (important: focus only on a clean ASR design, for now in the frontend support method calls, and maybe later we'll design a clean interface):
-
e.has(x)(ASR:SymbolicHasQ) -
e.func == Mul,e.func == Add,e.func == Pow -
e.func == log(e.func == expwill not be supported, since SymEngine doesn't have anexptype, onlyPow: Design question: shouldexp(x)be its own type/function? symengine/symengine#1984) -
e.func == sin -
y.args[0]andy.args[1](ASR:SymbolicGetArguments, Design of getargs() #2393), whereyis any expression -
exponent = int(e.args[1]) -
as_two_terms(e),as_independent(e, x)(ASR:SymbolicAsTwoTermsandSymbolicAsIndependent) - list[S]
- Set of symbolic expressions (
{exp(x)}), make sure printing and comparison works
-
- Compile
mrvusing LPython
The goal is to design a very small and clean ASR design. As few functions and ASR nodes as possible, the S type does not have methods, we have global ASR nodes (as few as possible) and IntrinsicFunctions (can be many) to operate on it. We want to keep this Symbolic API surface to be minimal and clean (no duplication).
Let's write a pure Python implementation of this Symbolic API, initially we'll just ship it with LPython. It will implement exactly this API in pure CPython, so we will ensure 100% compatibility (thus satisfying the LPython contract that if it works in LPython, it gives exactly the same result in CPython). SymPy itself will be about 95% compatible, so most tests will work in both and we will continue testing both, but in some corner cases (such as exp(x).func, and sin(pi/8) etc.) it will differ, so those tests will only test in our pure Python implementation (we will ensure that majority of tests work in SymPy). And then much later, we'll ensure that the symengine.py (Python wrappers to SymEngine) are a strict superset of our "lean Symbolic API", so that one can use symengine.py interchangeably with our pure Python implementation (and it will be faster, while still being in CPython). And we will carefully document all differences to SymPy. The contract will eventually be that if a symbolic code compiles and works with LPython, it will automatically work with our pure Python implementation as well as with symengine.py 100% of the time, and with SymPy only about 95%. And we'll offer our pure Python implementation (which will be slower than symengine.py, but faster than current SymPy) to SymPy itself, and using LPython SymPy can gradually move to this new core, we can start with limits.
Activity
anutosh491 commentedon Oct 4, 2023
Well if we plan on using
basic_get_argsfor implemntinge.expande.base(instead of what I was trying to do in symengine/symengine#1980), we would need a work around for theCVecBasictype just like we had one for thebasictype.If you remember, we introduced a workaround for declaring a basic variable as follows
Now what
basic_get_argsdoes is, it takes in a pointer toCVecBasicand then it populates the value ofargswith the arguments.Hence we might need to think about a workaround for implementing
CVecBasicin LPython.Here it is a bit different that the general procedure for a
basicvariable(which is to define it throughCPtrand then use thebasic_new_stackfunction )Here we have something like
certik commentedon Oct 4, 2023
You can also write an auxiliary C function that does this, if it simplifies things.
certik commentedon Oct 4, 2023
Regarding the
args, let's first implement the following:Where we obtain the whole vector of arguments from SymEngine, and we convert it to a Python tuple. Then we just deal with a tuple. For that, we should first get tuples of type
Sworking in LPython, that is, get this working first:And then once that works, let's get
args: list[S] = (x**2).argsworking. For that, I think we need some ASR function, let's saySymbolicGetArgumentsthat accepts an expression likex**2and returns atuple[S]with the arguments.I think after that, the following will also automatically start working:
However, for this to work, tuple would have to have a runtime size. Currently in LPython we have a compile time size, and in fact
tuple[S]is a tuple of just one element.tuple[S, S, S]is a tuple of 3 elements. We have two ways forward:args: list[S] = (x**2).args; print(args[0], args[1]).Once symengine gives us the
CVecBasic *args, then you can construct the following ASR code to construct alist[S], as an implementation ofSymbolicGetArguments, in Python:This has to be done in LPython using symengine's C API for handling the
CVecBasicstructure. So there is a function get gets you the length (len(args)) and there is another function to access ani-th element of the vector (args[i]).certik commentedon Nov 1, 2023
I would add a new integration test
test_gruntz.pyand in there I would start implementing themrvfunction, I would start small and then start adding things to it. Every time we discover something that does not work, I would isolate the bug, and add a dedicated separate testtest_symbolics_??.pyfor it. That way every single new feature will be tested. And then intest_gruntz.pyI would just keep improving the onemrvimplementation iteratively, whatever is there will be always working, and step by step we will get it to the point that it is equivalent (or almost equivalent) to SymPy's mrv: https://github.com/sympy/sympy/blob/b6e81e7c3f3860c7e826018e587531a8622fcc4e/sympy/series/gruntz.py#L248.