lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.47k stars 157 forks source link

Discussion on supporting Pow instances for mrv function #2526

Open anutosh491 opened 5 months ago

anutosh491 commented 5 months ago

So the case overall from sympy's gruntz.py looks like

    elif e.is_Pow and e.base != S.Exp1:
        e1 = S.One
        while e.is_Pow:
            b1 = e.base
            e1 *= e.exp
            e = b1
        if b1 == 1:
            return SubsSet(), b1
        if e1.has(x):
            if limitinf(b1, x) is S.One:
                if limitinf(e1, x).is_infinite is False:
                    return mrv(exp(e1*(b1 - 1)), x)
            return mrv(exp(e1*log(b1)), x)
        else:
            s, expr = mrv(b1, x)
            return s, expr**e1

I think we have like to have

EDIT : Even for the first TODO we have the SymbolicInteger Intrinsic function node, so we can delay introducing S.One for a while

anutosh491 commented 5 months ago

So basically I see 2-3 conditional statements and we can address all except one

certik commented 5 months ago

Remove this:

            if limitinf(b1, x) is S.One:
                if limitinf(e1, x).is_infinite is False:
                    return mrv(exp(e1*(b1 - 1)), x)

or throw an exception.

certik commented 5 months ago

The last two TODO items thus don't apply.

As for S.One, we can support it and just do S(1), or we can rewrite the code to just do S(1). I would actually not support S.One at all, it seems hackish and I think the only advantage is that it is faster in SymPy, but in LPython there is no speed advantage, just duplicate syntax, so I would just stick to S(1).