Hi list,
I've a very confusing problem with some simple algorithm:
following setting: a matrix sing:
sage: sing
[ 3 0 1]
[-2 -1 -2]
[ 0 1 0]
sage: l = sings.column(2);l
(1, -2, 0)
#my algorithem, code see below:
sage: extgcd(l)
#some printoutput for debugging:
l: (1, -2, 0)
tlist: (-2, 0)
#this should not be, d = gcd(tlist)
d: 1
l: [1, 1]
[u, v]: [0, 1]
l: (-2, 0)
[u, v]: [1, 0]
res: [0, 1, 0]
#the result:
[0, 1, 0]
#now the same but i construct the vector on my own:
sage: l = vector([1,-2,0]);l
(1, -2, 0)
sage: extgcd(l)
l: (1, -2, 0)
tlist: (-2, 0)
#here it works fine
d: 2
l: [1, 2]
[u, v]: [1, 0]
l: (-2, 0)
[u, v]: [1, 0]
res: [1, 0, 0]
#getting the expected result:
[1, 0, 0]
the code of my algorithm:
def extgcd(l):
print "l: " + str(l)
assert len(l) > 1
if len(l) == 2:
#calculated ext euclidean for two values
a = l[0]
b = l[1]
u=t=1
v=s=0
while b>0:
q=a//b
a, b = b, a-q*b
u, s = s, u-q*s
v, t = t, v-q*t
print "[u, v]: " + str([u, v])
return [u, v]
else:
#this is the part where it does not work!
tlist = l[1:]
print "tlist: " + str(tlist)
d = gcd(tlist)
print "d: " + str(gcd(tlist))
#calculate part decomp
u, v = extgcd([l[0],d])
#calculate rest
ttlist = extgcd(tlist)
res = [u]
#combine results
res.extend([v * item for item in ttlist])
print "res: " + str(res)
return res
I hope somebody can help me.
greatz Johannes
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org