These are chat archives for symengine/symengine

27th
Jul 2017
Shikhar Jaiswal
@ShikharJ
Jul 27 2017 07:10
@isuruf While porting up SymEngine in Physics module, at certain places I was unable to use sqrt and exp because hbar constant was being passed to them. Should I implement the same in SymEngine?
Isuru Fernando
@isuruf
Jul 27 2017 07:13
what's the hbar constant?
Shikhar Jaiswal
@ShikharJ
Jul 27 2017 08:38
Planck's constant over 2*pi.
Isuru Fernando
@isuruf
Jul 27 2017 09:03
You can declare in symengine.py as hbar = PyFunction(sympy.hbar, (), sympy.hbar.func, sympy_module)
printing needs to be fixed, but other than that, it works fine
drakei
@drakei
Jul 27 2017 18:06
Hi, I am new to SymEngine and had a question. Is there / will there be support for multivariate Piranha polynomials in SymEngine? I am looking to use SymEngine and Piranha to do integrations of large multivariate polynomials within SymPy code (SymPy is too slow for the large cases). By the way I am not sure if this is the place to ask this so let me know if that is the case.
Isuru Fernando
@isuruf
Jul 27 2017 18:08
There will be, but they are not complete yet. Have you looked at python bindings pyranha?
drakei
@drakei
Jul 27 2017 18:21
I have seen pyranha, but do not have much experience with it. Does it support easy conversion to/from SymPy polynomials? In the long term though I think eventually I want to port completely over to SymEngine in C++.
Isuru Fernando
@isuruf
Jul 27 2017 18:22
I've no idea. @bluescarni ?
In SymEngine C++, there are methods to convert to pyranha polynomials and back. they need to be exposed in the python wrappers though
drakei
@drakei
Jul 27 2017 18:24
Does that include multivariate ones as well?
Isuru Fernando
@isuruf
Jul 27 2017 18:24
yes
wait, let me check
Only the univariate polys, but that can be easily extended to multivariate ones
drakei
@drakei
Jul 27 2017 18:32
Thanks for checking. As part of a temporary solution involving converting SymPy polynomials to dictionaries and transferring those to C++ Piranha, I wrote something like the container_from_dict function in uintpoly_piranha.h for multivariate polynomials that accomplishes the SymPy --> Piranha conversion. What would be the analog to convert the other way?
drakei
@drakei
Jul 27 2017 18:57
Ah, thank you. There when you iterate through the polynomial, it looks like you get pairs of (exponent, coefficient) and the logic operates off of that. When one iterates through a piranha::polynomial, one gets pairs of (coefficient, piranha::polynomial) where the second elements are the monomials. Do you know if there is a simple way to convert the piranha::polynomials in those pairs to their corresponding collection of exponents? SymEngine must be doing it somewhere but I am not sure where.
Here we have this custom iterator
since it's for univariate, it uses ptr_->m_key.begin() to get the power of the variable
drakei
@drakei
Jul 27 2017 19:31
Oh I see. I'm not sure I understand how m_key accesses the Piranha exponents though. If I have piranha::polynomial poly it seems I cannot call something like poly._container().m_key. Sorry for all the questions.
Isuru Fernando
@isuruf
Jul 27 2017 19:33
It's just poly.m_key
Oops. poly._container().m_key is correct
drakei
@drakei
Jul 27 2017 19:37
I get error: no member named 'm_key' in 'piranha::polynomial
Isuru Fernando
@isuruf
Jul 27 2017 19:38
Should have been poly._container().begin().m_key
poly._container().begin() gives an iterator with m_key and m_cf for the monomial and the coefficient
drakei
@drakei
Jul 27 2017 19:41
ah thank you that makes sense
Isuru Fernando
@isuruf
Jul 27 2017 19:42
m_key.begin() is an iterator to iterate m_key
drakei
@drakei
Jul 27 2017 19:57
Looks like poly._container().begin()->m_key.begin()
*Looks like poly._container().begin()->m_key.begin() should do it. Thanks!
Isuru Fernando
@isuruf
Jul 27 2017 19:59
yes, you need to iterate from it = poly._container().begin(); it != poly._container().end(); it++ and then from it2=it->m_key.begin(); it2!= it->m_key.end(); it2++
drakei
@drakei
Jul 27 2017 20:03
Ah so that should let me avoid iterating directly through the polynomial to begin with and avoid the std::pairs.
Francesco Biscani
@bluescarni
Jul 27 2017 20:15
@drakei there's no explicit support for converting piranha polys to/from sympy. In the past I've sometimes converted piranha polys to string form and parsed them back with sympy, but of course it's not gonna be efficient for large polys
poly._container().begin() gives you access directly to the piranha::term objects contained in a piranha poly. Each term in turn contains two members, m_cf and m_key
poly.begin() gives you back a "fat" iterator, I'd recommend avoiding it for performance reasons
it's for use mostly by the python bindings
drakei
@drakei
Jul 27 2017 21:50
Oh okay. I considered converting via strings and sympify, but yeah the conversion takes too long with that approach. Thanks for the clarification with iterating through terms - that's what I was looking for. Do you think using SymPy's as_dict() and from_dict() along with iterating through poly._container() will give good performance for he conversion or do you have a better way in mind? I was thinking of linking the Python and C++ with ctypes, though Cython, pybind11, and boost could be options too.
Francesco Biscani
@bluescarni
Jul 27 2017 21:52
poly._container() gives you directly access to the internal hash table used to store the individual terms, so it's the fastest way to access the terms
I have zero experience with ctypes, but I am fairly well acquainted with boost python (and a bit of pybind11). I am planning eventually an overhaul of the python bindings probably switching from boost.python to pybind11, but it's still some way down the road
so probably that would be a good occasion to think about symengine/sympy integration (and possibly integration with other python libraries)
most of piranha development in these last few months has been focused on mppp https://github.com/bluescarni/mppp, which is basically piranha's multiprecision bits taken out from it in a separate library and with various improvements, fixes and performance tweakings