These are chat archives for symengine/symengine

16th
Jun 2016
Rajith Vidanaarachchi
@rajithv
Jun 16 2016 06:59

Hi,
I've been testing the eval function which I was writing earlier, and came across the following error:

Consider the following code segment:

basic_const_pi(s);
integer_set_ui(t, 1963319607);
basic_mul(s, s, t);
integer_set_ui(t, 6167950454);
basic_sub(r, s, t);
//r = pi*1963319607 - 6167950454
// This is equivalent to: 1.497342914414639737573531356935588060199405738165573... × 10^-10

real_double_get_d(r) gives 0
but, basic_eval(eval2, r, 53, 1); and then real_double_get_d(eval2) gives 4294967296.000000

I have tried giving a RealDouble of value 0.0 directly to eval, and that gives 0.0

I suspect this is because of the internals of multiple precision numbers, but am having a hard time trying to pinpoint where the trouble is happening.

@isuruf @abinashmeher999

Isuru Fernando
@isuruf
Jun 16 2016 09:09
Are you using a 32-bit OS?
Rajith Vidanaarachchi
@rajithv
Jun 16 2016 09:09
@isuruf yes
Isuru Fernando
@isuruf
Jun 16 2016 09:10
6167950454 >= 2**32
Rajith Vidanaarachchi
@rajithv
Jun 16 2016 09:14
@isuruf okay. thanks :)
Isuru Fernando
@isuruf
Jun 16 2016 09:24

@srajangarg, I don't understand this comment,

but gcd/lcm are done using a modified euclidean algorithm. As the integer ring is not euclidean we cannot implement these yet.

Srajan Garg
@srajangarg
Jun 16 2016 09:26
@isuruf I'm really not sure. I have to read more about this. What I thought is that for trivial gcd, we use euclidean division algorithm. The same that we use for taking gcd of two integers.
That makes sense only if your division is euclidean (ie proper).
For just int polynomials, proper division is not defined.
I will confirm, and get back to you
Kalevi Suominen
@jksuom
Jun 16 2016 09:29
The ring of integers is euclidean. (In fact, the first example, presented by Euclid himself.) Univariate polynomial rings over a field of coefficients are also euclidean. But the combination ZZ[t] is not euclidean.
Srajan Garg
@srajangarg
Jun 16 2016 09:31
ZZ[t] being Univariate polynomials over integer coefficients?
Kalevi Suominen
@jksuom
Jun 16 2016 09:31
Yes.
Isuru Fernando
@isuruf
Jun 16 2016 09:32
Yes, but the gcd of two univariate polynomials over integer coefficients is of the same type right?
Srajan Garg
@srajangarg
Jun 16 2016 09:33
Yes it is. But I haven't been able to think of a trivial algorithm which is able to do so. The simple euclidean algorithm will make use of polynomials of rationals in intermediate stages I think.
Isuru Fernando
@isuruf
Jun 16 2016 09:34
I can think of a simple algorithm for calculating gcd without resorting to rationals
Kalevi Suominen
@jksuom
Jun 16 2016 09:34
Yes. The ring ZZ[t] is a unique factorization domain (UFD) even if it is not euclidean. It has gcd and lcm, but there is no euclidean algorithm for them.
Srajan Garg
@srajangarg
Jun 16 2016 09:36
What do you have in mind @isuruf, or can I read up from somewhere? The simplest one I read about was the euclidean one.
Isuru Fernando
@isuruf
Jun 16 2016 09:36
This uses the fact that gcd(a, b) = gcd(b, a*x + b*y) if gcd(x, b) = 1
Kalevi Suominen
@jksuom
Jun 16 2016 09:38
The standard procedure for finding gcd and lcm is to first find the prime factors. In ZZ[t] there are two types of prime factors, irreducible polynomials whose integer coefficients have no common factor and then prime numbers.
Srajan Garg
@srajangarg
Jun 16 2016 09:39
Isn't finding the factors a much larger problem than finding the gcd
Kalevi Suominen
@jksuom
Jun 16 2016 09:40
It is, in general. In the case of ZZ[t] there are shortcuts.
First one can find the gcd in QQ[t] and then clear off the denominators.
Srajan Garg
@srajangarg
Jun 16 2016 16:59
@isuruf there's a lot of places (especially in tests) where the auto keyword can be used. Do you think I should make the change?
I think the change is alright for tests
Isuru Fernando
@isuruf
Jun 16 2016 17:00
Doesn't matter if auto is used or not
Srajan Garg
@srajangarg
Jun 16 2016 17:00
I know, just for readability sake
Isuru Fernando
@isuruf
Jun 16 2016 17:00
One advantage of not using auto is that it documents the return types
Srajan Garg
@srajangarg
Jun 16 2016 17:01
But sometimes, it's not needed like auto a = UIntPoly::from_dict(..)
Well, that's only sometimes so I guess it's not all that necessary