On Monday, June 9, 2014 3:50:06 PM UTC-7, Volker Braun wrote:
>
> This seems like it would be a good solution in Sage, namely provide 
> associative containers that participate in coercion and ensure that all 
> elements have the same type. E.g.
>
> sage: s = SageSet([3, 8]); s     # universe = ZZ
> {3, 8}
>

sage: s.add(GF(5)(3));  z          # coercion to universe = GF(5)
> {3}
> sage: s.add(QQ(5))
> TypeError: no common canonical parent
>
> This would be consistent with our type model of always applying coercion 
> if necessary, for example:
>
> sage: GF(5)(3) + 1
> 4
> sage: GF(5)(3) + QQ(1)
> TypeError: unsupported operand parent(s) for '+': 'Finite Field of size 5' 
> and 'Rational Field'
>
>  
We're supposed to have that already (minus the universe changing) except 
that it doesn't really work:

sage: C=Subsets(GF(5))
sage: v=C([1,2,9])
sage: [parent(a) for a in v]
[Integer Ring, Integer Ring, Integer Ring]
sage: v.category()
Category of sets
sage: v
{1, 2, 9}
sage: v in C # ?? is this a bug ??
True

Also, if we'd actually have the category as "Category of subsets of GF(5)" 
we would probably end up with the memory leaks that parametrized categories 
tend to cause. Still, it may be worth investigating how such containers 
should interact with the category framework. Do we want/need a category of 
"Dictionaries with keys in ..."?


>  The "coercing set" / "coercing dict" could then replace the standard 
> Python set/dict when used on the command line. 
>
>
I'd have to see a prototype, but I'd probably be -1 on that being the 
default. The behaviour of these sets/dicts would be much more noticeably 
different from pythons than the Integer/int differences. I also expect that 
their performance will be significantly worse, because of the parent 
coercion/checking overhead on any occasion. It would also put pressure on 
sage library functions to only return these "coercing" versions, since 
otherwise the normal python sets/dicts would still be leaking into user 
sessions. That would be a waste internally, since for most programming 
problems, you tend to end up with uniform key universes automatically, so 
they don't have to be imposed artificially.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to