These are chat archives for symengine/symengine

3rd
Nov 2015
Ondřej Čertík
@certik
Nov 03 2015 03:23
Yeah, pyranha is using way too many templates.
I don't want to mix any kind of Python into the C++, as it brings a host of other issues to worry about. I doubt pyranha + ring_series.py can be faster than a native C++ implementation that uses Piranha itself. And as such, if speed is not an issue, one can just use ring_series.py directly from SymPy. If speed is an issue, then one should implement the fastest possible way.
the ring_series.py implements Puiseux series I think.
Isuru Fernando
@isuruf
Nov 03 2015 03:28
@certik, gmpxx is almost a header only library with only io operators being not defined. If we are careful not to use the operators << and >> then we don't have to link to libgmpxx
Ondřej Čertík
@certik
Nov 03 2015 03:28
@isuruf as to the idea of using gmpxx without linking, it feels like a hack to me, since we are not using it as it is intended by the GMP developers. And we still would require the gmpxx to be present. By writing our own C++ wrapper over the raw C GMP functionality as discussed in #478 has the advantage that it is much simpler, doesn't require the gmpxx at all and it is equally performing.
And consistent with our other similar wrappers of C libraries like Arb.
Isuru Fernando
@isuruf
Nov 03 2015 03:30
Yes, it feels like a hack, but I am okay with it because we'll be duplicating most of the stuff in gmpxx.h in our wrapper. Arithmetic operators, relational operators etc.
Ondřej Čertík
@certik
Nov 03 2015 03:34
Didn't we write a similar C++ wrapper for mpfr, arb, mpc and others? I can't find it at the moment.
Isuru Fernando
@isuruf
Nov 03 2015 03:35
Ondřej Čertík
@certik
Nov 03 2015 03:37
As @bluescarni explained in https://github.com/symengine/symengine/issues/478#issuecomment-153180587, if you do x=y*z using the C++ gmp expression templates, there is still a little overhead.
So I think given the complexity of it, that's why we didn't implement any arithmetic operators and just call the C functions directly.
As summarized in https://github.com/symengine/symengine/issues/478#issuecomment-153188107, we can do the same with GMP if we want.
As I see it, I would either depend on the whole C++ library, including linking, or implement our own simple version that only needs the C library.
Isuru Fernando
@isuruf
Nov 03 2015 03:58
I agree with avoiding temporaries where possible. How do we handle statements like if (N % 5 == 0) ? Temporaries are useful in this case.
Ondřej Čertík
@certik
Nov 03 2015 04:00
why couldn't you call a function that tests if N % 5 is zero? No need for temporaries.
I assume that's what the expression templates do, but I think it's always good if things are explicit and simpler, since you can reason more easily about what is happening under the hood.
Isuru Fernando
@isuruf
Nov 03 2015 04:03
I could do
mpz_class a;
mpz_mod_ui(a.get_mpz_t(), N.get_mpz_t(), 5); 
if (mpz_cmp_ui(a.get_mpz_t(), 0) == 0) {

}
Ondřej Čertík
@certik
Nov 03 2015 04:11
So you need a temporary anyway.
In that case, if (N % 5 == 0) is much more readable.
I don't know what the best way is in the GMP case, since it is used quite a lot. For things like MPFR or ARB, the approach that we use (i.e. a simple C++ wrapper and calling the C functions) seem to be a good solution.
Isuru Fernando
@isuruf
Nov 03 2015 04:17
Yes, I agree
Ralf Stephan
@rwst
Nov 03 2015 05:55
@certik , the size of Pyranha is also because it includes Poisson and divisor series.