lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Discussion on supporting Pow instances for mrv function

Open anutosh491 opened this issue 1 year ago • 3 comments

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

  • [ ] e1 = S.One (which is basically introducing a constant 1, I think we have support through symengine for this) . The S.One constant is being used thrice so we would want that.
  • [ ] .is_infinite can also be supported through SymEngine
  • [ ] The only thing that I'm not sure how it should be supported is the limitinf function. We aren't supporting limits for now and not sure is SymEngine's C API has any kind of support for it.

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

anutosh491 avatar Feb 12 '24 04:02 anutosh491

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

anutosh491 avatar Feb 12 '24 04:02 anutosh491

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 avatar Feb 14 '24 18:02 certik

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).

certik avatar Feb 14 '24 18:02 certik