17 views

Skip to first unread message

Mar 15, 2023, 6:53:49 AMMar 15

to syme...@googlegroups.com

Hi,

I am using SymEngine.jl with julia1.5.2 on a linux machine and am trying to

parse a string that contains the names of built-in and user defined functions.

The following approach seems to works for some built-in functions:

julia> x1,x2,x3 = symbols("x1,x2,x3")

(x1, x2, x3)

julia> y1 = sin(PI/3)+cos(PI/3) + cos(x1)*sin(x1) + cos(x2) + sin(x3)

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2)

julia> y1_s = Basic(string(y1))

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2)

If I include the user defined function my_xpn()

function my_xpn(x,n)

return(x^n)

end

I get the following:

julia> y2 = y1 + my_xpn(x1,2) + my_xpn(x2,3)

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + x1^2 + x2^3 + sin(x3) + cos(x2)

julia> y3v = join([string(y1), "+ my_xpn(x1,2) + my_xpn(x2,3)"])

"1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2)+

my_xpn(x1,2) + my_xpn(x2,3)"

julia> y3v_s = Basic(y3v)

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2) + my_xpn(x1,

2) + my_xpn(x2, 3)

What method/s should be applied to "evaluate" the calls to the

user-defined function

my_xpn() in the string y3v? Using Basic() does not work in this case.

Any help with the above would be appreciated.

Thank you.

Constantinos

I am using SymEngine.jl with julia1.5.2 on a linux machine and am trying to

parse a string that contains the names of built-in and user defined functions.

The following approach seems to works for some built-in functions:

julia> x1,x2,x3 = symbols("x1,x2,x3")

(x1, x2, x3)

julia> y1 = sin(PI/3)+cos(PI/3) + cos(x1)*sin(x1) + cos(x2) + sin(x3)

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2)

julia> y1_s = Basic(string(y1))

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2)

If I include the user defined function my_xpn()

function my_xpn(x,n)

return(x^n)

end

I get the following:

julia> y2 = y1 + my_xpn(x1,2) + my_xpn(x2,3)

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + x1^2 + x2^3 + sin(x3) + cos(x2)

julia> y3v = join([string(y1), "+ my_xpn(x1,2) + my_xpn(x2,3)"])

"1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2)+

my_xpn(x1,2) + my_xpn(x2,3)"

julia> y3v_s = Basic(y3v)

1/2 + sin(x1)*cos(x1) + (1/2)*sqrt(3) + sin(x3) + cos(x2) + my_xpn(x1,

2) + my_xpn(x2, 3)

What method/s should be applied to "evaluate" the calls to the

user-defined function

my_xpn() in the string y3v? Using Basic() does not work in this case.

Any help with the above would be appreciated.

Thank you.

Constantinos

Mar 16, 2023, 11:04:07 PMMar 16

to syme...@googlegroups.com

Hi Constantinos,

Thanks for your question. I think in Python we allow a user defined function to be defined in Python, and used from C++. So I think exactly the same mechanism could be used in the Julia wrappers. If I am not mistaken, here is the implementation:

https://github.com/symengine/symengine.py/blob/560bafb9eb4623800f8caa4df72033ecb6f6b21a/symengine/lib/symengine_wrapper.pyx#L2818

If you want to contribute it to the Julia wrappers, that would be great. It might be already implemented right here: https://github.com/symengine/SymEngine.jl/blob/3734b04aff57da6fa7f45081b26d7b525091771c/src/customfuncs.jl.

Ondrej

https://github.com/symengine/symengine.py/blob/560bafb9eb4623800f8caa4df72033ecb6f6b21a/symengine/lib/symengine_wrapper.pyx#L2818

If you want to contribute it to the Julia wrappers, that would be great. It might be already implemented right here: https://github.com/symengine/SymEngine.jl/blob/3734b04aff57da6fa7f45081b26d7b525091771c/src/customfuncs.jl.

Ondrej

Mar 17, 2023, 7:16:57 AMMar 17

to syme...@googlegroups.com

Hi Ondřej,

Thank you for the response and two links.

The second link points to the Julia file customfuncs.jl located in the Julia

SymEngine installation.

I noticed that in the file SymEngine.jl there is no statement

include("customfuncs.jl")

in order to include this file. So, it was not possible to directly use

the functions

defined in customfuncs.jl in order to try and solve the problem described in my

original email.

I tried the command include("/path.../customfuncs.jl") from the Julia command

line but got an error message.

I think that it would be best if you could forward my inquiry to the

developer/s of

the package SymEngine.jl for advice on how to proceed further.

Thank you very much for your assistance.

Constantinos

> --

> You received this message because you are subscribed to the Google Groups

> "symengine" group.

> To unsubscribe from this group and stop receiving emails from it, send an

> email to symengine+...@googlegroups.com.

> To view this discussion on the web visit

> https://groups.google.com/d/msgid/symengine/4ec9fbb5-1ef3-4e54-9518-6bc093c6c965%40app.fastmail.com.

>

Thank you for the response and two links.

The second link points to the Julia file customfuncs.jl located in the Julia

SymEngine installation.

I noticed that in the file SymEngine.jl there is no statement

include("customfuncs.jl")

in order to include this file. So, it was not possible to directly use

the functions

defined in customfuncs.jl in order to try and solve the problem described in my

original email.

I tried the command include("/path.../customfuncs.jl") from the Julia command

line but got an error message.

I think that it would be best if you could forward my inquiry to the

developer/s of

the package SymEngine.jl for advice on how to proceed further.

Thank you very much for your assistance.

Constantinos

> You received this message because you are subscribed to the Google Groups

> "symengine" group.

> To unsubscribe from this group and stop receiving emails from it, send an

> email to symengine+...@googlegroups.com.

> To view this discussion on the web visit

> https://groups.google.com/d/msgid/symengine/4ec9fbb5-1ef3-4e54-9518-6bc093c6c965%40app.fastmail.com.

>

Mar 17, 2023, 2:43:59 PMMar 17

to syme...@googlegroups.com

Hi Constantinos,

We don't have dedicated developers for SymEngine.jl. The best way to proceed is to report it as an issue in the SymEngine.jl repository, and then if you have time, try to fix it in the code, and submit a pull request with the fix. That would be very helpful. It looks like that the code is not included, as you said, so you can try to include it, see if it works, if not, see where it breaks, etc. If you get stuck, please ask questions.

Thanks,

Ondrej

> https://groups.google.com/d/msgid/symengine/CALfNWAnxEK2o7AtYLDWEz3XBKOgMAB%3D7dXFnGd%3DXihkERzPF8A%40mail.gmail.com.

We don't have dedicated developers for SymEngine.jl. The best way to proceed is to report it as an issue in the SymEngine.jl repository, and then if you have time, try to fix it in the code, and submit a pull request with the fix. That would be very helpful. It looks like that the code is not included, as you said, so you can try to include it, see if it works, if not, see where it breaks, etc. If you get stuck, please ask questions.

Thanks,

Ondrej

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu