Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for symbolic Expand & Differentiation #2077

Merged
merged 3 commits into from
Jul 2, 2023

Conversation

anutosh491
Copy link
Collaborator

Symbolic operations in SymPy can be used as both attributes

>>> from sympy import Symbol, S
>>> x = Symbol('x')
>>> y = Symbol('y')
>>> ((x + y)**S(3)).expand()
x**3 + 3*x**2*y + 3*x*y**2 + y**3

OR can be imported and can be called as function

>>> from sympy import Symbol, S, expand
>>> x = Symbol('x')
>>> y = Symbol('y')
>>> expand((x + y)**S(3))
x**3 + 3*x**2*y + 3*x*y**2 + y**3

Hence I have added support for both

(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

The diff operation has been dealt similarly

@anutosh491 anutosh491 requested a review from certik July 2, 2023 09:21
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks great!

@certik certik merged commit e8f63b0 into lcompilers:main Jul 2, 2023
8 checks passed
@anutosh491
Copy link
Collaborator Author

Thanks a lot for the review @certik

@anutosh491 anutosh491 deleted the GSoC_PR5 branch July 2, 2023 18:14
@certik
Copy link
Contributor

certik commented Jul 2, 2023

Thanks for this. The backend is starting to look pretty cool!

@anutosh491 anutosh491 mentioned this pull request Jul 3, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants