Menu

#4231 Greatest common divisor wrong result

None
not-a-bug
nobody
9
2023-12-30
2023-12-28
Rayon340
No

Dear everyone, hi. I have tried to calculate the greatest common divisor of the three following monomials:

12a^3b^2c^2, 6a^2b^3c^3, 3a^2b^2c^3.

In order to do this I have written:

gcd(12a^3b^2c^2, 6a^2b^3c^3, 3a^2b^2*c^3);

but Maxima gives me the result "6a^2b^2c^2" instead of "3a^2b^2c^2". What is the point?

Related

Bugs: #4231

Discussion

  • Raymond Toy

    Raymond Toy - 2023-12-28

    I think you're using gcd wrong. The manual for gcd (via "? gcd") says:

    -- Function: gcd (<p_1>, <p_2>, <x_1>, ...)
    Returns the greatest common divisor of <p_1> and <p_2>. The flag</p_2></p_1></x_1></p_2></p_1>

    so it only takes two polynomials. It doesn't describe what x_1 is, though and I don't really know either.

     
  • Stavros Macrakis

    As Ray says, gcdtakes two polynomials. Arguments x_1, x_2, etc. specify the variable ordering (cf. ratvars and divide, which also takes x_n arguments). I agree that the doc should be explicit about this.

    For the gcd of more than two polynomials, here's an easy approach:

    xreduce('gcd,[12*a^3*b^2*c^2, 6*a^2*b^3*c^3,3*a^2*b^2*c^3]);
         => 3*a^2*b^2*c^2
    
     
  • Stavros Macrakis

    • status: open --> not-a-bug
     
  • Rayon340

    Rayon340 - 2023-12-28

    Ok, many thanks to both of you. So I can either use nested gcd calls

    gcd(12a^3b^2c^2, gcd(6a^2b^3c^3, 3a^2b^2c^3))

    or use the xreduce function with gcd. I think it could be more intuitive to let gcd function to take more than two polynomials.

    Best regards.

     
    • Stavros Macrakis

      I understand your point. But that leaves the question of how to specify
      variable order.

      Fateman, can you supply an example where the result is non-trivially
      different with different variable order? (not just x-y vs y-x).

      On Thu, Dec 28, 2023 at 12:41 PM Emanuele Giusti via Maxima-bugs maxima-bugs@lists.sourceforge.net wrote:

      Ok, many thanks to both of you. So I can either use nested gcd calls

      gcd(12a^3b^2c^2, gcd(6a^2b^3c^3, 3a^2b^2c^3))

      or use the xreduce function with gcd. I think it could be more intuitive
      to let gcd function to take more than two polynomials.

      Best regards.

      [bugs:#4231] https://sourceforge.net/p/maxima/bugs/4231/ Greatest
      common divisor wrong result

      Status: not-a-bug
      Group: None
      Labels: greatest common divisor gcd
      Created: Thu Dec 28, 2023 05:10 PM UTC by Emanuele Giusti
      Last Updated: Thu Dec 28, 2023 05:34 PM UTC
      Owner: nobody

      Dear everyone, hi. I have tried to calculate the greatest common divisor
      of the three following monomials:

      12a^3b^2c^2, 6a^2b^3c^3, 3a^2b^2c^3.

      In order to do this I have written:

      gcd(12a^3b^2c^2, 6a^2b^3c^3, 3a^2b^2*c^3);

      but Maxima gives me the result "6a^2b^2c^2" instead of "3a^2b^2
      c^2". What is the point?


      Sent from sourceforge.net because maxima-bugs@lists.sourceforge.net is
      subscribed to https://sourceforge.net/p/maxima/bugs/

      To unsubscribe from further messages, a project admin can change settings
      at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a
      mailing list, you can unsubscribe from the mailing list.


      Maxima-bugs mailing list
      Maxima-bugs@lists.sourceforge.net
      https://lists.sourceforge.net/lists/listinfo/maxima-bugs

       

      Related

      Bugs: #4231

      • Rayon340

        Rayon340 - 2023-12-28

        Hi. I do not understand what you mean and I do not understand the meaning of the word "Fateman". I am not an english native speaker. The dictionary does not provide any translation for that word. I am a new Maxima user. I do not want to make a controversy. Of course Maxima has an algorithm to calculate the gcd of two polynomials; maybe it could be possible to extend the funtionality of that algorithm to deal with more than two polynomials. For me it is fine to use the two solutions you have provided to me, what I have said is only a suggestion.

         
        • Raymond Toy

          Raymond Toy - 2023-12-29

          I think what Stavros is saying is that if you change gcd to have more then two polynomials then how do you know what the last polynomial is and where the x_1 argument begins. That is, gcd has no way of knowing if you want gcd(p1,p2,p3, x1) to do 3 polynomials or if p3 is another ratvar polynomial for ordering.

          "Fateman" is a reference to Richard Fateman, one of the original Macsyma authors who still contributes to Maxima.

           
    • Stavros Macrakis

      You can also package the functionality so that it's easy to use:

      gcdn([l]) := xreduce('gcd, l)$

      It is rare that you'll need to specify the main variable -- which as far as
      I can tell only determines whether there is a factor of -1:

      makelist( gcd (x^2-y^2, x-y,x),
      gcd,'[ez,subres,red,spmod]);
      => [x - y, x - y, x - y, x - y]

      makelist( gcd (x^2-y^2, x-y,y),
      gcd,'[ez,subres,red,spmod]);
      => [y - x, y - x, y - x, y - x]

      and the exact form of the result:

      qq;
      2 2 2 2 2 2
      y z - x z - y z + x z + x y - x y
      rr;
      (y - z) (z - x)

      gcd(qq,rr,x,y,z);
      2
      z + ((- y) - x) z + x y
      gcd(qq,rr,x,z,y);
      2
      (- z ) + y (z - x) + x z
      gcd(qq,rr,y,x,z);
      2
      z + ((- y) - x) z + x y
      gcd(qq,rr,y,z,x);
      2
      (- z ) + x (z - y) + y z
      gcd(qq,rr,z,x,y);
      2
      z - x z + y (x - z)
      gcd(qq,rr,z,y,x);
      2
      z - y z + x (y - z)

      On Thu, Dec 28, 2023 at 12:41 PM Emanuele Giusti rayon340@users.sourceforge.net wrote:

      Ok, many thanks to both of you. So I can either use nested gcd calls

      gcd(12a^3b^2c^2, gcd(6a^2b^3c^3, 3a^2b^2c^3))

      or use the xreduce function with gcd. I think it could be more intuitive
      to let gcd function to take more than two polynomials.

      Best regards.

      [bugs:#4231] https://sourceforge.net/p/maxima/bugs/4231/ Greatest
      common divisor wrong result

      Status: not-a-bug
      Group: None
      Labels: greatest common divisor gcd
      Created: Thu Dec 28, 2023 05:10 PM UTC by Emanuele Giusti
      Last Updated: Thu Dec 28, 2023 05:34 PM UTC
      Owner: nobody

      Dear everyone, hi. I have tried to calculate the greatest common divisor
      of the three following monomials:

      12a^3b^2c^2, 6a^2b^3c^3, 3a^2b^2c^3.

      In order to do this I have written:

      gcd(12a^3b^2c^2, 6a^2b^3c^3, 3a^2b^2*c^3);

      but Maxima gives me the result "6a^2b^2c^2" instead of "3a^2b^2
      c^2". What is the point?


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/maxima/bugs/4231/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #4231

  • Richard Fateman

    Richard Fateman - 2023-12-29

    see gcd ( (x+y+1)^2, (x+y+1)^3,x,y);
    vs
    gcd((x+y+1)^2,(x+y+1)^3, y,x);
    to see what the extra arguments do.
    Richard Fateman ;)

     

    Last edit: Richard Fateman 2023-12-30
  • Stavros Macrakis

    Here is a minimum example of the sign of the result being different because of variable ordering:

    gcd(x-y,y-x,x) => x - y
    gcd(x-y,y-x,y) => y - x
    
     

Log in to post a comment.