Loïc Grenié on Mon, 15 Jul 2024 22:35:23 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: vector of t_FRAC questions


Il lun 15 lug 2024 at 22:01, Hermann wrote:
I convert 3-dimensional vector or GMP mpq_t rational numbers from
CGAL function get_build_direction() to GP this way:

https://github.com/Hermann-SW/cgal4gp/blob/main/cgal4gp.cpp#L107-L123

extern "C"
GEN
get_build_direction() {
     assert(_simplex != NULL);
     _Vector_3 _dir = _simplex->get_build_direction();

     return mkvec3(
                mkfrac(
                    mpz2GEN(_dir[0].num.mpz()),
                    mpz2GEN(_dir[0].den.mpz())),
                mkfrac(
                    mpz2GEN(_dir[1].num.mpz()),
                    mpz2GEN(_dir[1].den.mpz())),
                mkfrac(
                    mpz2GEN(_dir[2].num.mpz()),
                    mpz2GEN(_dir[2].den.mpz())));
}

That works nicely, but I get denominators of 1:

$ gp -q tqf_width.gp
? G=[-67, -189, -200; 6, 17, 18; 1, 3, 3];
? Width([G*y~ | y<-SquaresRepresentations3(65)])
? d=get_build_direction()
[81920/1, 917504/1, -40960/1]
?


A) How to get conversion to t_INT in case of denominator 1?

     Try to use gdiv, or Qdivii.
 
B) Strange behavior of GP?

? simplify(d)
[81920/1, 917504/1, -40960/1]
? simplify([81920/1, 917504/1, -40960/1])
[81920, 917504, -40960]
?

     Obviously pari does not expect fractions with denominator 1 and
  does not even try to simplify them.
 
C) Why does division by 1 not work, while division by gcd does?

     Because this is not the same division, you create a fraction whose
  denominator is 1, you are not dividing by 1.
 
? gcd(81920,gcd(917504,40960))
8192
? d/8192
[10, 112, -5]
? d/1
[81920/1, 917504/1, -40960/1]
?

D) how to convert d to [10, 112, -5] in GP simpler?

        d/2*2, and maybe d*2/2, would probably have the expected
  effect. d*1 not...

           Hope this helps,

                Loïc