Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in pynac's numeric::gcd method #31477

Open
DaveWitteMorris opened this issue Mar 10, 2021 · 11 comments
Open

Error in pynac's numeric::gcd method #31477

DaveWitteMorris opened this issue Mar 10, 2021 · 11 comments

Comments

@DaveWitteMorris
Copy link
Member

Functions in pynac expect the gcd of two rational numbers p and q to be the largest number d, such that p/d and q/d are integers (except that gcd(0,0) = 0). But pynac's numeric::gcd method says that gcd(p,1) = 1 for all p, which does not have to be true when p is not an integer.

Related ticket: #24880

Component: symbolics

Keywords: gcd, pynac

Author: Dave Morris

Branch/Commit: public/31477 @ 77bf8ce

Issue created by migration from https://trac.sagemath.org/ticket/31477

@DaveWitteMorris
Copy link
Member Author

Branch: public/31477

@DaveWitteMorris
Copy link
Member Author

comment:2

This is part of metaticket #31478.


New commits:

bf1ab79trac 31477 fix pynac gcd(p,1)

@DaveWitteMorris
Copy link
Member Author

Commit: bf1ab79

@tscrim
Copy link
Collaborator

tscrim commented Apr 19, 2021

comment:3

Wouldn't it make sense to check that if a.is_one() you return the denominator of b (and vice versa) so you don't completely loose the special case optimizations?

@mkoeppe
Copy link
Member

mkoeppe commented May 10, 2021

comment:4

Moving to 9.4, as 9.3 has been released.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 May 10, 2021
@DaveWitteMorris
Copy link
Member Author

comment:5

Replying to @tscrim:

Wouldn't it make sense to check that if a.is_one() you return the denominator of b (and vice versa) so you don't completely loose the special case optimizations?

That seems reasonable, but needs some thought, because it will change the value of the function in some cases. Without the change you suggest, I think 1.gcd(b) will return 1 whenever b is a PyObject (such as a complex number), even if the denominator of b is not 1 (for example, if b is a rational multiple of I).

I think your change is probably correct (so the rest of the numeric::gcd code should be modified to match this), but this should be verified by looking at the uses of the gcd function to see what behaviour is expected.

Related ticket: #31884.

PS. Once the correct behaviour has been implemented, the description of the gcd(const numeric &a, const numeric &b) function (in this same file) should be corrected. It currently says "return The GCD of two numbers if both are integer, a numerical 1 if they are not."

@mkoeppe
Copy link
Member

mkoeppe commented Aug 16, 2021

comment:6

With #32386, the new patch can just be applied to the merged-in sources

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Aug 22, 2021
@mkoeppe
Copy link
Member

mkoeppe commented Sep 4, 2021

comment:8

... by doing (cd src/sage/symbolic && patch -p1) < build/pkgs/pynac/patches/gcd1.patch

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 26, 2021

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

77bf8cefix pynac gcd(p,1)

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 26, 2021

Changed commit from bf1ab79 to 77bf8ce

@mkoeppe
Copy link
Member

mkoeppe commented Sep 26, 2021

comment:10

9.5.beta2 has merged #32386, so I have applied your patch as indicated in comment:8

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 21, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants