ProductSet implementation

32 views
Skip to first unread message

Amit Saha

unread,
Mar 26, 2014, 9:18:41 AM3/26/14
to sy...@googlegroups.com
Hello,

I was going through how ProductSet is implemented and couple of things
struck me as odd. First, the string/repr representation:

>>> s = FiniteSet(1, 2)
>>> t = FiniteSet(2, 3)
>>> p = ProductSet(s, t)
>>> p
{1, 2} x {2, 3}

IMO, a product set is a set (at least Wikipedia tells me so). So,
shouldn't it rather be the following?

{(1,2), (1,3), (2,2), (2,3)}

Again going by the same idea, I also feel, the len() function should
return the cardinatlity and not raise a TypeError:

>>> len(p)
Traceback (most recent call last):
File "<pyshell#166>", line 1, in <module>
len(p)
TypeError: object of type 'ProductSet' has no len()

Best,
Amit.


--
http://echorand.me

Sergey Kirpichev

unread,
Mar 26, 2014, 9:59:29 AM3/26/14
to sy...@googlegroups.com

On Wednesday, March 26, 2014 5:18:41 PM UTC+4, Amit Saha wrote:
IMO, a product set is a set (at least Wikipedia tells me so). So,
shouldn't it rather be the following?

{(1,2), (1,3), (2,2), (2,3)}

1) It *is* a set:
In [8]: isinstance(p, Set)
Out[8]: True

2) Yes, maybe for FiniteSet - we should evaluate ProductSet.
 
Again going by the same idea, I also feel, the len() function should
return the cardinatlity and not raise a TypeError:

Maybe.

Amit Saha

unread,
Mar 26, 2014, 10:01:28 AM3/26/14
to sy...@googlegroups.com
On Wed, Mar 26, 2014 at 11:59 PM, Sergey Kirpichev <skirp...@gmail.com> wrote:
>
> On Wednesday, March 26, 2014 5:18:41 PM UTC+4, Amit Saha wrote:
>>
>> IMO, a product set is a set (at least Wikipedia tells me so). So,
>> shouldn't it rather be the following?
>>
>> {(1,2), (1,3), (2,2), (2,3)}
>
>
> 1) It *is* a set:
> In [8]: isinstance(p, Set)
> Out[8]: True

Yes, I realized that. My comment is regarding how it is presented to the user.



--
http://echorand.me

Aaron Meurer

unread,
Mar 26, 2014, 3:13:07 PM3/26/14
to sy...@googlegroups.com
If the set itself is unevaluated as a product, then it should print that way.

The main concern with evaluating such sets automatically would be that
they can get quite large compared to the size of the original sets.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CANODV3kUJ%2B_a_tOCpTtRiYLqfoXC6z274aqMYEG5SuypRD-cVQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Matthew Rocklin

unread,
Mar 26, 2014, 5:02:47 PM3/26/14
to sy...@googlegroups.com
If you want the fully evaluated FiniteSet of pairs then call FiniteSeton the ProductSet.  This works because ProductSets iterate through all of the elements.

>>> s = FiniteSet(1, 2)
>>> t = FiniteSet(2, 3)
>>> p = ProductSet(s, t)
>>> FiniteSet(p)
{(1, 2), (1, 3), (2, 2), (2, 3)}



Reply all
Reply to author
Forward
0 new messages