Re: Some thougts on cartesian products

2006-01-25 Thread Fredrik Lundh
Terry Reedy wrote: > You might so define, but Bryan and others might not. The > philosophical/methodological idea that 'everything is a set' has been very > fruitful but it is not a fact. Alternative ideas are 'everything is a > function' and 'everything is defined by axioms'. according to goog

Re: Some thougts on cartesian products

2006-01-25 Thread Terry Reedy
"Christoph Zwerschke" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Bryan Olson wrote: >> The claim "everything is a set" falls into the category of >> 'not even wrong'. > > No, it falls into the category of the most fundamental Mathematical > concepts. You actually *define* tuple

Re: Some thougts on cartesian products

2006-01-24 Thread Christoph Zwerschke
I think this has been discussed thoroughgoing enough. All I wanted to say is that this proposal of building "Cartesian products" of strings is well-defined, in line with the mathematical concept of Cartesian products, and can be *sometimes* useful. I hope we agree on this, but if not we don't n

Re: Some thougts on cartesian products

2006-01-24 Thread Bryan Olson
Christoph Zwerschke wrote: > Bryan Olson wrote: > >> The claim "everything is a set" falls into the category of >> 'not even wrong'. > > No, it falls into the category of the most fundamental Mathematical > concepts. You actually *define* tuples as sets, or functions as sets or > relations as s

Re: Some thougts on cartesian products

2006-01-24 Thread Christoph Zwerschke
Bryan Olson wrote: > The claim "everything is a set" falls into the category of > 'not even wrong'. No, it falls into the category of the most fundamental Mathematical concepts. You actually *define* tuples as sets, or functions as sets or relations as sets, or even all kinds of numbers and ot

Re: Some thougts on cartesian products

2006-01-24 Thread Christoph Zwerschke
Bryan Olson wrote: > The claim "everything is a set" falls into the category of > 'not even wrong'. No, it falls into the category of the most fundamental Mathematical concepts. You actually *define* tuples as sets, or functions as sets or relations as sets, or even all kinds of numbers and othe

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Christoph Zwerschke wrote: > Bryan Olson schrieb: > >>> Still think there is no such thing? >> >> >> Uh, yes. >> >>The Cartesian product of two sets A and B (also called the >>product set, set direct product, or cross product) is defined to >>be the set of [...] >> >> All sets, no stri

Re: Some thougts on cartesian products

2006-01-23 Thread Kay Schluehr
Christoph Zwerschke wrote: > Now as I'm thinking about it, wouldn't it be nice to have the cartesian > products on Python sets? Maybe also a method that returns the power set > of a set (the set of all subsets), or the set of all subsets with a > given length. For defining powersets it might suf

Re: Some thougts on cartesian products

2006-01-23 Thread val bykoski
Christoph Zwerschke wrote: > Bryan Olson schrieb: > >>> Still think there is no such thing? >> >> >> Uh, yes. >> >>The Cartesian product of two sets A and B (also called the >>product set, set direct product, or cross product) is defined to >>be the set of [...] >> >> All sets, no stri

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Kay Schluehr wrote: > Bryan Olson wrote: > > >>There's no such thing; you'd have to define it first. Are duplicates >>significant? Order? > > > That's all trivial isn't it? A string is a set of pairs (i,c) where i > is an integer number, the index, with 0<=i (i,c), (j,d) in string and c is a ch

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Steven D'Aprano wrote: > On Mon, 23 Jan 2006 18:17:08 +, Bryan Olson wrote: > > >>Steven D'Aprano wrote: >> >>>Bryan Olson wrote: >>> >>[Christoph Zwerschke had written:] >> >What I expect as the result is the "cartesian product" of the strings. There's no such thing; you'd have

Re: Some thougts on cartesian products

2006-01-23 Thread Christoph Zwerschke
Bryan Olson schrieb: >> Still think there is no such thing? > > Uh, yes. > >The Cartesian product of two sets A and B (also called the >product set, set direct product, or cross product) is defined to >be the set of [...] > > All sets, no strings. What were you looking at? Not only

Re: Some thougts on cartesian products

2006-01-23 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > On Mon, 23 Jan 2006 18:17:08 +, Bryan Olson wrote: > > > Steven D'Aprano wrote: > >> Bryan Olson wrote: > >> > >> > > [Christoph Zwerschke had written:] > What I expect as the result is the "cartesian product" of the strings. > >>> > >>>There's no such thing; you'd

Re: Some thougts on cartesian products

2006-01-23 Thread Steven D'Aprano
On Mon, 23 Jan 2006 18:17:08 +, Bryan Olson wrote: > Steven D'Aprano wrote: >> Bryan Olson wrote: >> >> > [Christoph Zwerschke had written:] What I expect as the result is the "cartesian product" of the strings. >>> >>>There's no such thing; you'd have to define it first. Are duplicates

Re: Some thougts on cartesian products

2006-01-23 Thread Kay Schluehr
Bryan Olson wrote: > There's no such thing; you'd have to define it first. Are duplicates > significant? Order? That's all trivial isn't it? A string is a set of pairs (i,c) where i is an integer number, the index, with 0<=ihttp://mail.python.org/mailman/listinfo/python-list

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Steven D'Aprano wrote: > Bryan Olson wrote: > > [Christoph Zwerschke had written:] >>>What I expect as the result is the "cartesian product" of the strings. >> >>There's no such thing; you'd have to define it first. Are duplicates >>significant? Order? > > > Google "cartesian product" and hit "

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Steven D'Aprano wrote: > Bryan Olson wrote: >>Christoph Zwerschke wrote: >>[...] >> >>>That may be the main problem to decide whether the cartesian product >>>should return a generator or a list. >> >>The Cartesion product is a set. > > And the generalization of mathematical sets in Python can be

Re: Some thougts on cartesian products

2006-01-23 Thread Christoph Zwerschke
Bryan Olson schrieb: > Christoph Zwerschke wrote: > [...] >> That may be the main problem to decide whether the cartesian product >> should return a generator or a list. > > The Cartesion product is a set. Of course it is a set. But if the factors of the product have a total order (as in the ca

Re: Some thougts on cartesian products

2006-01-23 Thread Erik Max Francis
Bryan Olson wrote: > Christoph Zwerschke wrote: > [...] >> That may be the main problem to decide whether the cartesian product >> should return a generator or a list. > > The Cartesion product is a set. Sets are iterable, so that isn't an answer. If it's a set, then it should either be a gen

Re: Some thougts on cartesian products

2006-01-23 Thread Steven D'Aprano
On Mon, 23 Jan 2006 10:36:55 +, Bryan Olson wrote: > Christoph Zwerschke wrote: > [...] >> That may be the main problem to decide whether the cartesian product >> should return a generator or a list. > > The Cartesion product is a set. And the generalization of mathematical sets in Python c

Re: Some thougts on cartesian products

2006-01-23 Thread Steven D'Aprano
On Mon, 23 Jan 2006 01:25:36 +, Bryan Olson wrote: >> Sometimes I was missing such a feature. >> What I expect as the result is the "cartesian product" of the strings. > > There's no such thing; you'd have to define it first. Are duplicates > significant? Order? Google "cartesian product" an

Re: Some thougts on cartesian products

2006-01-23 Thread Bryan Olson
Christoph Zwerschke wrote: [...] > That may be the main problem to decide whether the cartesian product > should return a generator or a list. The Cartesion product is a set. [...] > That's the other problem. The uses cases (like the password cracker > example) are very limited and in these cas

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Jean-Paul Calderone wrote: > Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >> >> BTW: What is the shortest way to get the binary representation of a >> number in Python? Is there really not something like itoa() anywhere in >> the standard libs? > > I'm somewhat partial to this implementation: >

Re: Some thougts on cartesian products

2006-01-22 Thread Jean-Paul Calderone
On Mon, 23 Jan 2006 03:21:59 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: > >BTW: What is the shortest way to get the binary representation of a >number in Python? Is there really not something like itoa() anywhere in >the standard libs? I'm somewhat partial to this implementation: bina

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Bryan Olson wrote: > What you seem to want is easy enough: > [a + b for a in 'hello' for b in 'world'] Yes, but 'hello'*'world' is easier. And how would you write '01'**8 ? This should give you all bytes in binary code. > And maybe you want the result to be a generator: > (a + b for a in

Re: Some thougts on cartesian products

2006-01-22 Thread Bryan Olson
Christoph Zwerschke wrote: > In Python, it is possible to multiply a string with a number: > > >>> "hello"*3 > 'hellohellohello' Which is really useful. > However, you can't multiply a string with another string: > > >>> 'hello'*'world' > Traceback (most recent call last): > File "", line 1

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Steven D'Aprano wrote: > If you are happy to always return a list of tuples regardless of what the > two operands are, generators make it so easy it is shameful. Even if you > want a special case of two string arguments returning a string, it is > hardly any more difficult: > > def cartprod(A, B):

Re: Some thougts on cartesian products

2006-01-22 Thread Steven D'Aprano
On Sun, 22 Jan 2006 19:12:49 +0100, Christoph Zwerschke wrote: > Steven D'Aprano wrote: >> On Sun, 22 Jan 2006 18:29:45 +0100, Christoph Zwerschke wrote: >>> For doing such things I would use a vector subtype of list. >> >> Not everything needs to be a separate class! Why create a magic class for

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Steven D'Aprano wrote: > I beg to differ: Python *allows* people to create classes if they're keen > on the syntax (and I can sympathise with that like), but Python > *encourages* by example generic tools that operate on as many different > types as makes sense. But these generic tools (say the "p

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Alex Martelli schrieb: >> s = set(range(49)).powerset(6) >> for x in range(10): >> print s.pop() > > This is very systematic, not random;-). Still, using random.sample on s > would indeed produce 12 random different tips!-) Right, that would be systematic. What I wanted to write was: s = s

Re: Some thougts on cartesian products

2006-01-22 Thread Steven D'Aprano
On Sun, 22 Jan 2006 10:41:39 -0800, Alex Martelli wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >... >> What advantage is there to creating a "list with cartesian product" >> subclass of list? > > Essentially, syntax sugar -- for some people, being able to code a*b > rather than product

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Generally, if you could multiply strings in the above fashion, you could spare one more more sub loops, as in this example: for f in ('index', 'default')*('.html', '.htm', '.shtml'): if exists(f): break In this case, it would be not really be better than that: for f in '

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Christoph Zwerschke <[EMAIL PROTECTED]> wrote: > Alex Martelli schrieb: > > Christoph Zwerschke <[EMAIL PROTECTED]> wrote: > >... > >> given length. You could get a 6/49 lotto tip with something like: > >> > >> choice(set(range(49)).powerset(6)) > > > And that would be better than the current

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote: ... > What advantage is there to creating a "list with cartesian product" > subclass of list? Essentially, syntax sugar -- for some people, being able to code a*b rather than product(a,b) takes on a huge significance; Python chooses to support this syn

Re: Some thougts on cartesian products

2006-01-22 Thread Paul Rubin
Christoph Zwerschke <[EMAIL PROTECTED]> writes: > No, the elements of the powerset would be sets with 6 elements each, > not tuples. So technically, it would be correct. Just horribly > inefficient. Oh I see, not the Cartesian product. Yeah, it would be silly in practice. -- http://mail.python.o

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Paul Rubin schrieb: > [EMAIL PROTECTED] (Alex Martelli) writes: >>> given length. You could get a 6/49 lotto tip with something like: >>> choice(set(range(49)).powerset(6)) >> And that would be better than the current random.sample(range(49),6) in >> WHAT ways, exactly...? > > I think the first on

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Steven D'Aprano wrote: > On Sun, 22 Jan 2006 18:29:45 +0100, Christoph Zwerschke wrote: >> For doing such things I would use a vector subtype of list. > > Not everything needs to be a separate class! Why create a magic class for > every piece of functionality you want? Just create functions that o

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Alex Martelli schrieb: > Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >... >> given length. You could get a 6/49 lotto tip with something like: >> >> choice(set(range(49)).powerset(6)) > And that would be better than the current random.sample(range(49),6) in > WHAT ways, exactly...? You're

Re: Some thougts on cartesian products

2006-01-22 Thread Steven D'Aprano
On Sun, 22 Jan 2006 18:29:45 +0100, Christoph Zwerschke wrote: > Alex Martelli wrote: >> Kay Schluehr <[EMAIL PROTECTED]> wrote: >>> range(3)**2 >>> But why isn't this interpreted as [0, 1, 4] like it is in Mathematica? >> >> Since range(3)*2 is [0, 1, 2, 0, 1, 2], it would be horribly, painfully

Re: Some thougts on cartesian products

2006-01-22 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes: > > given length. You could get a 6/49 lotto tip with something like: > > choice(set(range(49)).powerset(6)) > > And that would be better than the current random.sample(range(49),6) in > WHAT ways, exactly...? I think the first one would be incorrect sinc

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Christoph Zwerschke <[EMAIL PROTECTED]> wrote: ... > given length. You could get a 6/49 lotto tip with something like: > > choice(set(range(49)).powerset(6)) And that would be better than the current random.sample(range(49),6) in WHAT ways, exactly...? Alex -- http://mail.python.org/mailman

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Alex Martelli wrote: > Kay Schluehr <[EMAIL PROTECTED]> wrote: >> range(3)**2 >> But why isn't this interpreted as [0, 1, 4] like it is in Mathematica? > > Since range(3)*2 is [0, 1, 2, 0, 1, 2], it would be horribly, painfully > inconsistent if **2 was interpreted as "square each item". Yes. Pyt

Re: Some thougts on cartesian products

2006-01-22 Thread Christoph Zwerschke
Kay Schluehr schrieb: > But why isn't this interpreted as [0, 1, 4] like it is in Mathematica? Because we are thinking of a cartesian product. If you have lists of numbers, then there are mane more ways to define a product: tensor product, vector product, scalar product, componentwise product...

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Kay Schluehr <[EMAIL PROTECTED]> wrote: ... > > >> range(3)**2 > > [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)] ... > But why isn't this interpreted as [0, 1, 4] like it is in Mathematica? Since range(3)*2 is [0, 1, 2, 0, 1, 2], it would be horribly, painfully inconsistent

Re: Some thougts on cartesian products

2006-01-22 Thread Kay Schluehr
Giovanni Bajo wrote: > Christoph Zwerschke wrote: > > > Sometimes I was missing such a feature. > > What I expect as the result is the "cartesian product" of the strings. > > I've been thinking of it as well. I'd like it for lists too: > > >> range(3)**2 > [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2)

Re: Some thougts on cartesian products

2006-01-22 Thread Giovanni Bajo
Christoph Zwerschke wrote: > Sometimes I was missing such a feature. > What I expect as the result is the "cartesian product" of the strings. I've been thinking of it as well. I'd like it for lists too: >> range(3)**2 [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)] -- Giovanni

Some thougts on cartesian products

2006-01-21 Thread Christoph Zwerschke
In Python, it is possible to multiply a string with a number: >>> "hello"*3 'hellohellohello' However, you can't multiply a string with another string: >>> 'hello'*'world' Traceback (most recent call last): File "", line 1, in ? TypeError: can't multiply sequence by non-int Sometimes I was