applying functions to sets

64 views
Skip to first unread message

Paul Zinn-Justin

unread,
Jul 22, 2014, 6:20:59 AM7/22/14
to maca...@googlegroups.com
I'm not sure if this is a bug or a feature, but I find the following behavior odd.

if I try
apply(set {0,1,2},x->x+1)
then M2 complains
stdio:1:1:(3): error: expected argument 1 to be a list, sequence, or an integer
and rightly so.

but now if I try
(set {0,1,2})/(x->x+1)
then the answer is
set {1, 2, 3}
which is nice but unexpected. 

unfortunately things go wrong when we try
(set {0,1,2})/(x->x//2)
instead of producing set {0,1} as one might hope, the result is
stdio:2:14:(3): error: collision of keys in hash table
because 0//2 == 1//2.

any comments?

Daniel R. Grayson

unread,
Nov 17, 2014, 10:18:07 PM11/17/14
to maca...@googlegroups.com
The method for Tally/Function involves applying "applyKeys", which doesn't accommodate collisions of
keys, but the related functions "merge" and "combine" do.  Providing an optional third argument to applyKeys
to be called when collisions occur would allow desirable implementations of Tally/Function and Set/Function;
in the former case, the counts would be added, and in the latter case, the count would always be 1.  If that
feature is desired, make an issue for it on github.  (Does anyone want to implement it, and learn the "D" language?)

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

Paul Zinn-Justin

unread,
Nov 18, 2014, 9:47:47 PM11/18/14
to maca...@googlegroups.com
Thanks for your answer. I might just do that. Is there any reference / documention for the "D" language?

Daniel R. Grayson

unread,
Nov 19, 2014, 9:51:20 AM11/19/14
to maca...@googlegroups.com

Paul Zinn-Justin

unread,
Nov 20, 2014, 12:29:12 AM11/20/14
to maca...@googlegroups.com
all right, implemented as you suggested. it's already in my experimental branch (which contains many other features/improvements I'm not yet ready to share with the world), but I'll create an issue and move to my main branch as soon as we've settled the current pull request.
Reply all
Reply to author
Forward
0 new messages