Interactive cells, GUIs, javascript, ...

8 views
Skip to first unread message

Hamptonio

unread,
Sep 14, 2007, 4:31:23 PM9/14/07
to sage-devel
Recently I started using Mathematica 6 in the computer labs of some
courses I teach, and I cannot help but be impressed. The new dynamic
commands such as Manipulate are very impressive, and are perfect for
teaching. Before seeing how powerful it is, I had hoped to switch
from using mathematica to sage in the fall of 2008. But now I am not
sure I can justisfy that switch or convince my colleagues it would
make sense. (As an aside: assume for the sake of argument that my
department gets mathematica for free, which is true in a certain
bureaucratic sense).

For some sense of what mathematica can now do, check out:
http://www.wolfram.com/products/mathematica/newin6/content/DynamicInteractivity/.
I actually think its more impressive in person.

While I would like to help remedy the gap between sage and mathematica/
matlab in this respect, I am not sure how it would be done. I am
learning a little about wxPython, but I don't think that would work
through the notebook at all, unless a program was created on the
server for download and byte-compilation by the client. Does anyone
have any ideas? If javascript is a possibility, can someone recommend
a good reference for learning to use it for such complicated
purposes? Or is java an option?

-Marshall

Fernando Perez

unread,
Sep 14, 2007, 4:40:14 PM9/14/07
to sage-...@googlegroups.com
On 9/14/07, Hamptonio <hamp...@gmail.com> wrote:
>
> Recently I started using Mathematica 6 in the computer labs of some
> courses I teach, and I cannot help but be impressed. The new dynamic
> commands such as Manipulate are very impressive, and are perfect for
> teaching. Before seeing how powerful it is, I had hoped to switch
> from using mathematica to sage in the fall of 2008. But now I am not
> sure I can justisfy that switch or convince my colleagues it would
> make sense. (As an aside: assume for the sake of argument that my
> department gets mathematica for free, which is true in a certain
> bureaucratic sense).
>
> For some sense of what mathematica can now do, check out:
> http://www.wolfram.com/products/mathematica/newin6/content/DynamicInteractivity/.
> I actually think its more impressive in person.

Good timing. Just yesterday I sent this to enthought-dev:

https://mail.enthought.com/pipermail/enthought-dev/2007-September/009023.html

Traits/TraitsUI is currently the closest python-side technology to
mathematica 6's stuff. In certain ways it's more generic, in others
not, and Mathematica's implementation is impressively elegant. I'd
also love to have this...

For more on traits:

http://code.enthought.com/traits/

This is a very nice mini-tutorial geared towards experimental scientists:

http://www.gael-varoquaux.info/computers/traits_tutorial/index.html


A word of caution: today, playing with Manipulate[], I found a truly
serious bug. On Linux at least (all I have tested on, Ubuntu Feisty),
if you leave a window that has Manipulate[] widgets open for a few
hours and go do something else, at some point those widgets go dead.
The notebook remains alive, you can run new code, etc. But both
existing Manipulate widgets and new ones you make become 100%
unresponsive to mouse input to drag their controls.

Something to be aware of before using this in front of an audience. I
hope they'll fix it soon.

Cheers,

f

William Stein

unread,
Sep 14, 2007, 4:46:37 PM9/14/07
to sage-...@googlegroups.com
On 9/14/07, Hamptonio <hamp...@gmail.com> wrote:

Isn't this exactly the sort of thing that javascript/AJAX is good at doing?
When you move an html control the server is contacted for the updated
output and it is displayed (by directly manipulating the DOM). I'm sure
it won't be as snappy as a purely local GUI (e.g., Mathematica), but it
will work from anywhere over a web browser, which counts for a lot
these days.

I've had some discussions with people about implementing things like
this (mostly with Robert Miller), but nobody has actually done it for
SAGE yet. Our complete rewrite of the notebook to use Twisted
as the underlying server technology I think makes doing something
like this easier.

-- William

Robert Bradshaw

unread,
Sep 14, 2007, 4:47:48 PM9/14/07
to sage-...@googlegroups.com, William Stein

Robert Bradshaw

unread,
Sep 14, 2007, 4:53:03 PM9/14/07
to sage-...@googlegroups.com
On Sep 14, 2007, at 1:46 PM, William Stein wrote:

That is really cool!

Generating, serving, and displaying pngs via javascript would be
really hard to do fast enough to make it smooth.

{{{
%time
for n in range(10):
plot(x^n).show()
}}}
CPU time: 2.44 s, Wall time: 2.93 s

A rough estimate of 4 frames/sec... maybe it's possible.

- Robert

Hamptonio

unread,
Sep 14, 2007, 5:48:29 PM9/14/07
to sage-devel
> Isn't this exactly the sort of thing that javascript/AJAX is good at doing?
> When you move an html control the server is contacted for the updated
> output and it is displayed (by directly manipulating the DOM). I'm sure
> it won't be as snappy as a purely local GUI (e.g., Mathematica), but it
> will work from anywhere over a web browser, which counts for a lot
> these days.

Well that's why I asked, I am ignorant about javascript/AJAX. Can you
suggest a good reference?

Ondrej Certik

unread,
Sep 14, 2007, 5:55:10 PM9/14/07
to sage-...@googlegroups.com
> https://mail.enthought.com/pipermail/enthought-dev/2007-September/009023.html
>
> Traits/TraitsUI is currently the closest python-side technology to
> mathematica 6's stuff. In certain ways it's more generic, in others
> not, and Mathematica's implementation is impressively elegant. I'd
> also love to have this...
>
> For more on traits:
>
> http://code.enthought.com/traits/
>
> This is a very nice mini-tutorial geared towards experimental scientists:
>
> http://www.gael-varoquaux.info/computers/traits_tutorial/index.html
>

While we are at it, if you use debian, you can use my preliminary
debian packages for tratis/traitsui, that will later get to debian
unstable. Put:

deb http://debian.wgdd.de/debian unstable main

into your /etc/apt/sources.list and

apt-get update
apt-get install python-ets-traits-ui

Please report any bugs,
Ondrej

William Stein

unread,
Sep 14, 2007, 6:11:03 PM9/14/07
to sage-...@googlegroups.com
On 9/14/07, Hamptonio <hamp...@gmail.com> wrote:
\> > Isn't this exactly the sort of thing that javascript/AJAX is good at doing?

No, unfortunately I can't, but hopefully someone else can. There are
a lot of bookstores in Barnes and Noble about "AJAX". It's also how programs
like Google Maps, etc., work.

It took me quite a while to get my head around AJAX programing. Basically
Alex Clemesha and Tom Boothby made a bunch of self-contained examples
and gave some takes, and after a while I just "got it". That was a while
ago and there are probably good books now.

William

-- William

Chris Chiasson

unread,
Sep 14, 2007, 6:50:49 PM9/14/07
to sage-devel
... wait until you actually start pushing Mathematica, it gets
sluggish on you, produces wrong results and/or crashes, and you
receive apathy and blame dodging instead of tech support and bug
fixing.

On Sep 14, 3:31 pm, Hamptonio <hampto...@gmail.com> wrote:
> Recently I started using Mathematica 6 in the computer labs of some
> courses I teach, and I cannot help but be impressed. The new dynamic
> commands such as Manipulate are very impressive, and are perfect for
> teaching. Before seeing how powerful it is, I had hoped to switch
> from using mathematica to sage in the fall of 2008. But now I am not
> sure I can justisfy that switch or convince my colleagues it would
> make sense. (As an aside: assume for the sake of argument that my
> department gets mathematica for free, which is true in a certain
> bureaucratic sense).
>

> For some sense of what mathematica can now do, check out:http://www.wolfram.com/products/mathematica/newin6/content/DynamicInt....

Hamptonio

unread,
Sep 14, 2007, 7:11:34 PM9/14/07
to sage-devel
Yeah, I have used mathematica for 17 years and I've pushed it very
hard at times. 6.0 seems much buggier than previous releases, but
they added and rewrote so much that I am not that surprised. I still
think its an amazing accomplishment, and for illustrating basic ideas
in calculus I don't think anything matches it.

I have submitted bugs to mathematica and gotten no response, so I know
what you mean there as well.

But I am committed to using and improving sage over the long haul,
don't get me wrong. I think the superiority of the development model
will win on most fronts eventually.

Cheers,
Marshall

Chris Chiasson

unread,
Sep 14, 2007, 7:21:58 PM9/14/07
to sage-devel
Also, for the benefit of the students you may possibly be
indoctrinating:

Please realize that WRI's marketing materials (aka documentation -
lol) make it seem like MMA can do anything (and so they might attempt
to use MMA in all their later courses - like me - which may not be
wise).

You could do much worse than teaching them SAGE, because then they
would learn the Python language and its libraries, which wouldn't be a
bad thing at all.

alex clemesha

unread,
Sep 14, 2007, 7:57:40 PM9/14/07
to sage-...@googlegroups.com

I just posted a cleaned-up example of AJAX-twisted.web2-SAGE here:

http://sage.math.washington.edu/home/agc/simple_ajax_twisted_sage.py

just getting your hands dirty by messing with examples is best, then
go to the books / google and learn about the details of the code.

The script above pretty much gives you the simplest possible example
of how to combine the technologies that make up the SAGE notebook.
There is a tiny README at the top of the file.

Good luck with it.

Alex
 

William

-- William

Ondrej Certik

unread,
Sep 14, 2007, 8:23:23 PM9/14/07
to sage-...@googlegroups.com
>
> I just posted a cleaned-up example of AJAX-twisted.web2-SAGE here:
>
> http://sage.math.washington.edu/home/agc/simple_ajax_twisted_sage.py
>
> just getting your hands dirty by messing with examples is best, then
> go to the books / google and learn about the details of the code.
>
> The script above pretty much gives you the simplest possible example
> of how to combine the technologies that make up the SAGE notebook.
> There is a tiny README at the top of the file.


Does anyone of you tried AJAX from pypy?

http://play1.codespeak.net/

You can write all of your code in Python (resp RPython) and you don't
have to mess up with javascript. Some of the demos look cool, but I
haven't seen much activity on pypy since March, I hope it's not dead.

Ondrej

alex clemesha

unread,
Sep 14, 2007, 8:39:43 PM9/14/07
to sage-...@googlegroups.com

I have not seen this before, but from a quick glance is looks like
it is like GWT (Google web toolkit), where you write code in Java
and it converts it to Javascript.   I'm slightly dubious that that is
a good way of going about producing Javascript ... but who knows.

Instead I think it is much better to use a good javascript library,
like the excellent Mochikit library (mochikit.com ).  Once you have
sufficient understanding of how to produce AJAX apps, then you
begin to realize the pain (DOM and Event issues, etc)
of making those apps work in all the main browsers ...
this is where a javascript library comes in.

The example I posted above is just for getting your head around
what is means to do 'AJAX'.  (with twisted.web2 and SAGE
thrown in for good measure ;)

Alex






Ondrej




Ondrej Certik

unread,
Sep 14, 2007, 8:47:34 PM9/14/07
to sage-...@googlegroups.com
> I have not seen this before, but from a quick glance is looks like
> it is like GWT (Google web toolkit), where you write code in Java
> and it converts it to Javascript. I'm slightly dubious that that is
> a good way of going about producing Javascript ... but who knows.

It's exactly like this, but not Java, but Python. :)

> Instead I think it is much better to use a good javascript library,
> like the excellent Mochikit library (mochikit.com ). Once you have
> sufficient understanding of how to produce AJAX apps, then you
> begin to realize the pain (DOM and Event issues, etc)
> of making those apps work in all the main browsers ...
> this is where a javascript library comes in.

I understand, that technically at this moment it's better to use
Mochikit or something. But in the long term I like to just write just
Python and don't care about some ugly technical details, like
javascript in browsers.

Ondrej

William Stein

unread,
Sep 14, 2007, 8:52:19 PM9/14/07
to sage-...@googlegroups.com
On 9/14/07, alex clemesha <clem...@gmail.com> wrote:
> I just posted a cleaned-up example of AJAX-twisted.web2-SAGE here:
>
> http://sage.math.washington.edu/home/agc/simple_ajax_twisted_sage.py
>
> just getting your hands dirty by messing with examples is best, then
> go to the books / google and learn about the details of the code.
>
> The script above pretty much gives you the simplest possible example
> of how to combine the technologies that make up the SAGE notebook.
> There is a tiny README at the top of the file.
>

Thanks! Great simple example.

For the total newbie, the way to use it is to download
simple_ajax_twisted_sage.py
to a file on your computer, then type
sage -python simple_ajax_twisted_sage.py
and follow the directions, i.e. open your browser to localhost:8000.

Make sure you aren't already running a sage notebook on that
port.

I'll put this in the SAGE_ROOT/examples directory so it comes with
future versions of SAGE.

William

Hamptonio

unread,
Sep 15, 2007, 9:49:35 AM9/15/07
to sage-devel
Yes, thanks, that example looks like it will help me a lot.

Btw, before reading William's instructions, I ran it without the -
python option and it seemed fine. Does the -python option just turn
off the preparser?

Cheers,
Marshall

On Sep 14, 7:52 pm, "William Stein" <wst...@gmail.com> wrote:

Ted Kosan

unread,
Sep 15, 2007, 11:51:26 AM9/15/07
to sage-...@googlegroups.com
Marshall wrote:

> Recently I started using Mathematica 6 in the computer labs of some
> courses I teach, and I cannot help but be impressed. The new dynamic
> commands such as Manipulate are very impressive, and are perfect for
> teaching.

I looked at Mathematica's new manipulate command and I am now
wondering if it calculates the rendering data on-the-fly when the
sliders are moved or does it precalculate the rendering data and then
the sliders are used to navigate through this data?

Ted

Hamptonio

unread,
Sep 15, 2007, 12:06:28 PM9/15/07
to sage-devel
My impression is that recalculates on the fly, but until you stop
(moving a slider for example) it tries to do quick-and-dirty
computations and rendering. This is pretty clear if you manipulate a
3D graph of a function f(x,y,a) with a the parameter - it doesn't even
draw the mesh until you let go of the slider.

-MH

Chris Chiasson

unread,
Sep 16, 2007, 10:33:48 PM9/16/07
to sage-devel
One last thing, I wanted to say that my earlier Mathematica comments
do not (usually) apply when dealing with the individual developers,
who are (usually) very helpful, especially on MathGroup. The thing I
am complaining about is the overall process of reporting and fixing
problems.

On Sep 14, 5:50 pm, Chris Chiasson <chris.chias...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages