On Sun, Dec 19, 2010 at 9:04 AM, Francois Maltey fmal...@nerim.fr wrote:
Hello,
I try to work with all the subsets of a cartesian product.
So I begin with
S = Set([1..4])
P = CartesianProduct (S)
Subsets (S) # is right
Subsets (P) # fails
Am I wrong ? (CartesianProduct isn't a Set) or is it a bug in Sage ?
Not a bug. If you type CartesianProduct? you will see it is an
interator, designed to be used in a for-loop. These are much faster
than set constructors. Here is an example:
sage: cp = CartesianProduct([1,2], [3,4]); cp
Cartesian product of [1, 2], [3, 4]
sage: cp.list()
[[1, 3], [1, 4], [2, 3], [2, 4]]
sage: cp.list()
[[1, 3], [1, 4], [2, 3], [2, 4]]
sage: for x in cp:
if 1 in x:
print x
:
[1, 3]
[1, 4]
Many thanks for your tips.
Francois
--
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
URL: http://www.sagemath.org
--
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
URL: http://www.sagemath.org