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

Symbolics, numerical values #1907

Open
Tracked by #2262
certik opened this issue Jun 14, 2023 · 5 comments
Open
Tracked by #2262

Symbolics, numerical values #1907

certik opened this issue Jun 14, 2023 · 5 comments
Assignees
Labels

Comments

@certik
Copy link
Contributor

certik commented Jun 14, 2023

from sympy import Symbol, pi
from lpython import S

def main0():
    x: S = pi
    y: S = Symbol('y')
    z: S = S(45)*S(3)*x + S(45.5)*y
    e: S = S(45) # SymPy Integer
    print(z)

main0()
@certik
Copy link
Contributor Author

certik commented Jun 14, 2023

This is consistent with LPython:

from lpython import i32

x: i32 = i32(1.0)

@rebcabin
Copy link
Contributor

Very Nice!

@anutosh491
Copy link
Collaborator

I did give this a try and mostly everything works as I would expect . I've pasted relevant parts from the ASR and the C generated code below @certik , @rebcabin

(lf) anutosh491@spbhat68:~/lpython/lpython$ cat examples/expr2.py 
def main0():
    x: S = S(123)
    y: S = S(321)
    z: S = x + y
    print(z)

main0()

(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython --show-asr examples/expr2.py 
                                    [(=
                                        (Var 2 x)
                                        (Cast
                                            (IntegerConstant 123 (Integer 4))
                                            IntegerToSymbolicExpression
                                            (SymbolicExpression)
                                            (IntrinsicFunction
                                                SymbolicInteger
                                                [(IntegerConstant 123 (Integer 4))]
                                                0
                                                (SymbolicExpression)
                                                ()
                                            )
                                        )
                                        ()
                                    )
                                    (=
                                        (Var 2 y)
                                        (Cast
                                            (IntegerConstant 321 (Integer 4))
                                            IntegerToSymbolicExpression
                                            (SymbolicExpression)
                                            (IntrinsicFunction
                                                SymbolicInteger
                                                [(IntegerConstant 321 (Integer 4))]
                                                0
                                                (SymbolicExpression)
                                                ()
                                            )
                                        )
                                        ()
                                    )
                                    (=
                                        (Var 2 z)
                                        (IntrinsicFunction
                                            SymbolicAdd
                                            [(Var 2 x)
                                            (Var 2 y)]
                                            0
                                            (SymbolicExpression)
                                            ()
                                        )
                                        ()
                                    )
                                    (Print
                                        ()
                                        [(Var 2 z)]
                                        ()
                                        ()
                                    )]
(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython --show-c examples/expr2.py 

// Implementations
void main0()
{
    basic x;
    basic_new_stack(x);
    basic y;
    basic_new_stack(y);
    basic z;
    basic_new_stack(z);
    integer_set_si(x, 123);
    integer_set_si(y, 321);
    basic_add(z, x, y);
    printf("%s\n", basic_str(z));
}

void _lpython_main_program()
{
    main0();
}

(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython --backend=c --enable-symengine examples/expr2.py
444

@certik
Copy link
Contributor Author

certik commented Jun 17, 2023

Yes, we'll do all of this. But first let's finish #1846 without adding any new features, just polish it up and let's get it merged. Then you can send a new PR that implements the above.

@anutosh491
Copy link
Collaborator

Talking about numerics we are supporting the long signed and the long unsigned integer as of now . Adding support for floats & complex numbers also could be achieved . Maybe after that the issue could be closed .

@certik certik mentioned this issue Aug 9, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants