← 输入框|github.com|刷新
Skip to content

Symbolics, numerical values #1907

Open
Open

Description

@certik
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()

Activity

  1. certik commented on Jun 14, 2023

    @certik
    ContributorAuthor

    This is consistent with LPython:

    from lpython import i32
    
    x: i32 = i32(1.0)
    
  2. rebcabin commented on Jun 14, 2023

    @rebcabin
    Contributor

    Very Nice!

  3. anutosh491 commented on Jun 17, 2023

    @anutosh491
    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
    
  4. certik commented on Jun 17, 2023

    @certik
    ContributorAuthor

    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.

  5. self-assigned this
    on Jun 21, 2023
  6. anutosh491 commented on Aug 9, 2023

    @anutosh491
    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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions