This is because c in your loop below is a rational number, and the  
GCD of any set of rational numbers (not all 0) is 1 (because  
everything is a unit). Write

>                                                       c = ZZ((d - r*s*t 
> +a*r*r + b*s*s)/(4*a*b - t*t))


On Jun 7, 2009, at 10:58 AM, salte...@gmail.com wrote:

> I am running into problems using the gcd function in sage. (version
> 3.4.2)
>
> Specifically, I am iterating over a set of integers [a,b,c,r,s,t]
> which I want to be coprime. I check this using gcd([a,b,c,r,s,t]). The
> problem is that it returns 1 for tuples that should not have gcd = 1.
> For example, for [a,b,c,r,s,t]=[2,2,2,0,0,0], it passes gcd
> ([a,b,c,r,s,t]) == 1. When I check this directly (by evaluating gcd
> ([2,2,2,0,0,0]) it evaluates correctly. This is driving me insane -
> any help would be greatly appreciated. Here is the pertinent code: (If
> you want to run into the [2,2,2,0,0,0] case, try d = 32 and N = 8)
>
> def MakeTernaryQF(d,N):
>
>       ## Make the list##
>       #r,s,t <= 0
>       QFlist = []
>       for a in range(1, 1+ceil((d/2)^(1/3))):
>               for b in range(a, floor(sqrt(d / (2*a)))+1):
>                       for r in range(-b, 1):
>                               for s in range(-a,1):
>                                       for t in range(-a,1):
>                                               if (d - r*s*t +a*r*r + 
> b*s*s)%(4*a*b - t*t) == 0:
>                                                       c = (d - r*s*t +a*r*r + 
> b*s*s)/(4*a*b - t*t)
>                                                       if gcd([a,b,c,r,s,t]) 
> == 1 and a+b+c+r+s+t >= 0:
>                                                               #print 'This 
> dumb thing thinks gcd('+str(a)+','+str(b)+','+str
> (c)+','+str(r)+','+str(s)+','+str(t)+') = '+str(gcd([a,b,c,r,s,t]))
>                                                               
> QFlist.append([a,b,c,r,s,t])
>
>       #r,s,t > 0
>       for a in range(1, 1+ceil((d/2)^(1/3))):
>               for b in range(a, floor(sqrt(d / (2*a)))+1):
>                       for r in range(1, b+1):
>                               for s in range(1,a+1):
>                                       for t in range(1,a+1):
>                                               if (d - r*s*t +a*r*r + 
> b*s*s)%(4*a*b - t*t) == 0:
>                                                       c = (d - r*s*t +a*r*r + 
> b*s*s)/(4*a*b - t*t)
>                                                       if gcd([a,b,c,r,s,t]) 
> == 1 and a+b+c+r+s+t >= 0:
>                                                                       #print 
> 'This dumb thing thinks gcd('+str(a)+','+str(b) 
> +','+str
> (c)+','+str(r)+','+str(s)+','+str(t)+') = '+str(gcd([a,b,c,r,s,t]))
>                                                                       
> QFlist.append([a,b,c,r,s,t])
>
>       return QFlist
>
> >


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to