PROBLEM : In a list of vectors, I want to know if there is a pair of equal vectors.
I have two solutions. The first to create an empty list L and append the vectors one per one. If a vector is already in L before adding it, then I found a pair of equal vectors. But looking if a vector belongs to a list is apparently very slow on my computer : sage: v = vector((1, SR(0))) sage: w = vector((1, sqrt(2))) sage: time v in [v,v,v,v,v,v,v,v,v] CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s Wall time: 0.00 s True sage: time w in [v] CPU times: user 0.92 s, sys: 0.20 s, total: 1.12 s Wall time: 5.17 s False sage: time w in [v,v] CPU times: user 1.86 s, sys: 0.46 s, total: 2.32 s Wall time: 12.32 s False sage: time w in [v,v,v,v] CPU times: user 4.83 s, sys: 1.14 s, total: 5.97 s Wall time: 32.42 s False My second solution is to put them in a set. But since vectors are not hashable, I first convert them into tuples. But I then get two equal vectors having distinct hash values: sage: z = vector((1,sqrt(2)-sqrt(2))); z (1, 0) sage: v = vector((1, SR(0))) ; v (1, 0) sage: z == v True sage: tuple(z) == tuple(v) True sage: hash(tuple(z)) -1374268819 sage: hash(tuple(v)) 1302034650 sage: map(type, z) [<class 'sage.calculus.calculus.SymbolicConstant'>, <class 'sage.calculus.calculus.SymbolicArithmetic'>] sage: map(type, v) [<class 'sage.calculus.calculus.SymbolicConstant'>, <class 'sage.calculus.calculus.SymbolicConstant'>] Anybody has a better idea? Thank you Sébastien Labbé --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---