Hi,

I think the most basic consideration is this: if you want to ever pass your data structures around in sympy, then they should inherit from Basic, and then using existing sympy implementations is almost always less trouble. Thus the only reason ever not to use sympy data structures (in my opinion) is if they are completely internal to your algorithms, and of temporary nature. Anything else will likely cause trouble, when various parts of sympy make assumptions on how your objects can be treated. As you observe, you will get many things, like hashing or subs, essentially for free.

Best,
Tom

On 05.06.2012 14:59, Sergiu Ivanov wrote:
Hello,

I have a class Diagram, which is a collection of objects and morphisms
(arrows) between them.  Another class, Category, should contain a
collection of diagrams which are known to possess a certain property.
Obviously, I don't want repetitions in this collection, so I am
considering choosing between Python's built-in sets and
sympy.core.sets.FiniteSet.  Which one would be the recommended way?

I reason in the following way.  From what I can see in the
implementation of FiniteSet, it is based on Python's built-in sets and
it adds proper interaction with other kinds of sets implemented in
SymPy (like Interval, Union, etc.).  Since I don't really need that
functionality, my choice should be Python's built-in sets.  Is this
right?

An one more on-topic question.  Diagram will contain at least one
collection of morphisms which I expect to implement using one of the
set container types I mentioned above (because, apparently, I don't
want duplicate morphisms).  To be able to store Diagram in sets, I'll
have to make it hashable.  Python's built-in set is unhashable, while
FiniteSet is, but I think it's Basic's __hash__ that gets called.  So,
is it OK if I rely on Basic to do the hashing, or should I write the
hash function myself?  If I should write it myself, is there a
recommended, SymPy-specific way to achieve that?

Sergiu


--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
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/sympy?hl=en.

Reply via email to