Ah, powerful notations and the Principia.  These are some of my favorite 
things. :-)

An excellent example of a difficult subject made easier by a wonderful tool is 
Mathematica. I think the Wolfram folks have done a really great job over the 
last 25 years with Mathematica.  You can directly use math notation but it is 
converted into the much more powerful internal representation of Mathematica 
terms.  Just think of Mathematica terms as s-expressions and you are close.  
Mathematica's math notation system is built on a general system that supports 
notations so that you could build a notation system that is what chemists would 
want.

The Mathematica Notebook is a wonderful system for exploration.  Notebooks let 
you build beautiful publishable documents that typically also contain live code 
for simulations and modeling.  Of course a Mathematica notebook is just a bunch 
of Mathematica terms.  I wish web browsers were as good as Mathematica 
notebooks.   They are like Smalltalk workspaces on steroids.  I wish there was 
an  open source Mathematica notebook like "read-canonicalize-evaluate-present" 
shell. 

At the bottom of Mathematica is the Mathematica language which is a very 
"Lispy" functional language with a gigantic library of primitives. There is no 
Type Religion in Mathematica's functional programming.  The documentation is 
extensive and made from Mathematica notebooks so that all examples are both 
beautiful and executable.  The learning curve is very very high because there 
is so much there but you can start simply just by evaluating 3+4 and grow.  
It's very open ended.

The Mathematica language is also great for meta programming.  Last year my son 
was working for the University of Colorado physics department building a model 
of the interaction of the solar wind with the interstellar medium.  His code 
made big use of meta programming to dramatically boost the performance.  He 
would partially evaluate his "code/ math" in the context of interesting 
boundary conditions  then use Simplify to reduce the code then run it through 
the low level Mathematica compiler.  He was able to get a 100x performance 
boost this way.  Mathematica was his first programming language and he has used 
it regularly for about 14 years .


To give you a taste let's implement the most beautiful Newton's forward 
difference algorithm  from the Principia.

see:
      http://mathworld.wolfram.com/FiniteDifference.html

for the background.
The code below (hopefully not too mangled by blind email systems) repeatedly 
takes differences
 until a zero is found resulting in a list of list of all differences.  The 
first elements are then harvested and the last zero dropped.
 Now just make some parallel lists for that will get passed to the difference 
term algorithm.  I could have written a loop
but APL and Mathematica has taught me that Transpose and Apply, and a level 
spec can write my loops for me without error.
Once you have all the terms in a list just join them with Plus.  Finally run 
the whole thing through Simplify.

The differenceTerm and fallingFactorial helper functions should look familiar 
to those who have played with modern functional programming.  Note I pass in a 
symbol and the Mathematica rule reducing system naturally does partial 
evaluation.  I realize I have left a lot of Mathematica details unexplained but 
I am just trying to give a taste.

Using the data from the mathworld web page you we can evaluate away

praiseNewton[{1, 19, 143, 607, 1789, 4211, 8539}, n]

   1+7 n+2 n^2+3 n^3+6 n^4

Without the Simplify we would have gotten:

1+18 n+53 (-1+n) n+39 (-2+n) (-1+n) n+6 (-3+n) (-2+n) (-1+n) n

I would never be able to do the Algebra right. :-)

if I want to define a function I can let my polynomial defining function do my 
work.

        fn[n_] = praiseNewton[{1, 19, 143, 607, 1789, 4211, 8539}, n]


--------
SetAttributes[praiseNewton, HoldRest];
praiseNewton[list_, sym_] := Module[{coefs, indexes, syms},
  coefs = 
   Drop[Map[First, NestWhileList[Differences, list, First[#] > 0 &]], -1];
  indexes = Range[0 , Length[coefs] - 1];
  syms = ConstantArray[sym, Length[indexes]];
  Simplify[
   Apply[Plus, Apply[differenceTerm, Transpose[{coefs, indexes, syms}], 1]]]];

differenceTerm[coef_, count_, sym_] := 1/count! * coef  * 
fallingFactorial[count, 0, sym];
fallingFactorial[0, indx_, sym_] := 1;
fallingFactorial[1, indx_, sym_] := (sym - indx);
fallingFactorial[count_, indx_, sym_] := (sym - indx) * fallingFactorial[count 
- 1, indx + 1, sym];

--------

What is much more interesting than the above code is the sequence of 
evaluations that lead to it.

It started with:

FixedPointList[Differences, {1, 19, 143, 607, 1789, 4211, 8539}]

{{1, 19, 143, 607, 1789, 4211, 8539}, {18, 124, 464, 1182, 2422, 4328}, {106, 
  340, 718, 1240, 1906}, {234, 378, 522, 666}, {144, 144, 144}, {0, 0}, {0}, 
{}, {}}

and just grew and grew by exploration, one experiment at a time.. :-)

I am sorry to have been so uncharacteristically wordy.  

-David Leibs

On Jul 28, 2011, at 9:57 AM, Alan Kay wrote:

> Well, we don't absolutely *need* music notation, but it really helps many 
> things. We don't *need* the various notations of mathematics (check out 
> Newton's use of English for complex mathematical relationships in the 
> Principia), but it really helps things.
> 
> I do think the hard problem is "design" and all that goes along with it (and 
> this is true in music and math too). But that is not the end of it, nor is 
> ignoring the design of visual representations that help grokking and thinking 
> a good idea.
> 
> I think you are confusing/convolving the fact of being able to do something 
> with the ease of it. This confusion is rampant in computer science ....
> 
> Cheers,
> 
> Alan
> 

_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to