## Walking Randomly Sage bounty hunt #1

Regular readers of Walking Randomly will know that I am a big fan of the Manipulate function in Mathematica. Manipulate allows you to easily create interactive mathematical demonstrations for teaching, research or just plain fun and is the basis of the incredibly popular Wolfram Demonstrations Project.

Sage, probably the best open source mathematics software available right now, has a similar function called interact and I have been playing with it a bit recently (see here and here) along with some other math bloggers. The Sage team have done a fantastic job with the interact function but it is missing a major piece of functionality in my humble opinion – a Locator control.

In Mathematica the default control for Manipulate is a slider:

Manipulate[Plot[Sin[n x], {x, -Pi, Pi}], {n, 1, 10}]

The slider is also the default control for Sage’s interact:

@interact def _(n=(1,10)): plt=plot(sin(n*x),(x,-pi,pi)) show(plt)

Both systems allow the user to use other controls such as text boxes, checkboxes and dropdown menus but Mathematica has a control called a Locator that Sage is missing. Locator controls allow you to directly interact with a plot or graphic. For example, the following Mathematica code (taken from its help system) draws a polygon and allows the user to click and drag the control points to change its shape.

Manipulate[Graphics[Polygon[pts], PlotRange -> 1], {{pts, {{0, 0}, {.5, 0}, {0, .5}}}, Locator}]

The Locator control has several useful options that allow you to customise your demonstration even further. For example, perhaps you want to allow the user to move the vertices of the polygon but you don’t want them to be able to actually see the control points. No problem, just add **Appearance -> None** to your code and you’ll get what you want.

Manipulate[Graphics[Polygon[pts], PlotRange -> 1], {{pts, {{0, 0}, {.5, 0}, {0, .5}}}, Locator, Appearance -> None}]

Another useful option is **LocatorAutoCreate -> True** which allows the user to create extra control points by holding down CTRL and ALT (or just ALT – it depends on your system it seems) as they click in the active area.

Manipulate[Graphics[Polygon[pts], PlotRange -> 1], {{pts, {{0, 0}, {.5, 0}, {0, .5}}}, Locator, LocatorAutoCreate -> True}]

When you add all of this functionality together you can do some very cool stuff with just a few lines of code. Theodore Gray’s curve fitting code on the Wolfram Demonstrations project is a perfect example.

All of these features are demonstrated in the video below

So, onto the bounty hunt. I am offering 25 pounds worth (about 40 American Dollars) of books from Amazon to anyone who writes the code to implement a Locator control for Sage’s interact function. To get the prize your code must fulfil the following spec

- Your code must be accepted into the Sage codebase and become part of the standard install. This should ensure that it is of reasonable quality.
- There should be an option like Mathematica’s
**LocatorAutoCreate -> True**to allow the user to create new locator points interactively by Alt-clicking (or via some other suitable method). - There should be an option to alter the appearance of the Locator control (e.g. equivalent to Mathematica’s
**Appearance -> x**option). As a minimum you should be able to do something like**Appearance->None** - You should provide demonstration code that implements everything shown in the video above.
- I have to be happy with it!

And the details of the prize:

- I only have one prize – 25 pounds worth of books (about 40 American dollars) from Amazon. If more than one person claims it then the prize will be split.
- The 25 pounds includes whatever it will cost for postage and packing.
- I won’t send you the voucher – I will send you the books of your choice as a ‘gift’. This will mean that you’ll have to send me your postal address. Don’t enter if this bothers you for some reason.
- I expect you to be sensible regarding the exact value of the prize. So if your books come to 24.50 then we’ll call it even. Similarly if they come to 25.50 then I won’t argue.
- I am not doing this on behalf of any organisation. It’s my personal money.
- My decision is final and I can withdraw this prize offer at any time without explanation. I hope you realise that I am just covering my back by saying this – I have every intention of giving the prize but whenever money is involved one always worries about the possibility of being ripped off.

Good luck!

**Update (29th December 2009):** The bounty hunt has only been going for a few days and the bounty has already doubled to 50 pounds which is around 80 American dollars. Thanks to David Jones for his generosity.

Wow! thanks for putting this out there Mike.

I’ve also missed this functionality in Sage, so I hope you get some good entries.

If Mike agrees, I will match his 25 with GBP 25 of my own.

@Simon Don’t thank me – thank the coder(s) who step up :)

@David Thank You! I definitely agree. I assume that you will be offering Amazon books too? I’ve sent you an email to make sure that it really is you who offered the extra 25 pounds and not an imposter. I won’t announce your offer in the main blog post until I hear back from you from the email address I know is yours (or from your twitter account).

Jason Grout did some preliminary work on exactly this. It really wouldn’t take a ton of effort from someone who understands javascript…

http://trac.sagemath.org/sage_trac/ticket/3866

-Marshall Hampton

There is a small discussion on sage-devel about this bounty:

http://groups.google.com/group/sage-devel/browse_thread/thread/4b52ee22e227370d

Here are my comments:

Let me just say that I wouldn’t claim any part of the prize if

someone finished that ticket. It would satisfying enough to me that we

had the feature, which I’ve wanted for a long time!

Note that there are a few things that are different about the code on

the ticket and the requirements on the blog. The code on the ticket

does not implement a locator control *inside* the picture. Instead, it

implements a 2d locator control in a square box in the controls section

of an interact (Mathematica also has something like this).

I see several things needing to be done to that ticket:

1. Figure out a way to have interact input in the *output* of the

interact. It seems like you’d need some way of saying “put a locator

control on *this* graphic that I’m printing out right here”.

2. For a locator control to be useful, it needs to return values in the

data coordinates of the plot (rather than pixels in the image). I think

it would be easy to return the pixel location in the image (once (1) is

solved). You’d probably use the transformation framework in matplotlib

to convert that to data coordinates.

3. I’m not sure how easily new controls can be easily created. That

would need to also be solved in order to meet the requirements.

Anyways, those are three main points that I would think need to be

addressed in the implementation of such a control. However, I’d love it

if someone did it some simpler way and proved me wrong! Those obstacles

are what prevented me from finishing up the ticket mentioned above—I

just didn’t have time to put towards it (and still don’t for the

foreseeable future).

All in all, I think having 2d interacts would not only give us a

valuable control, but would prove useful in refining the existing

interact infrastructure. So thanks for proposing a bounty! I’m excited

to see someone win it.

Hi Jason

Thanks for the extra information – yes Mathematica has something like the control in your original ticket and it’s called a Slider2D

http://reference.wolfram.com/mathematica/ref/Slider2D.html

I wouldn’t mind seeing that implemented in Sage as well to be honest although I can’t afford another bounty ;)

Cheers,

Mike

Hi Mike,

What ever happened to this bounty? Any progress?

Hi Simon

No progress that I’m aware of. The offer still stands though.

Cheers,

Mike