MathPiper Lesson 2: MathPiperIDE worksheets, and a preview of expression trees

35 views
Skip to first unread message

Ted Kosan

unread,
Apr 18, 2016, 5:41:12 AM4/18/16
to mathf...@googlegroups.com
My main project for this past week was to add speech synthesis
capabilities to the automated video demonstration system I am
creating. Here is a video that contains a synthesized speech
description of how to use MathPiperIDE worksheets:

https://youtu.be/eGldEkSczs4


ASSIGNMENT 2

1) Watch the above video.

2) Download version .149 of the “Introduction to Programming with
MathPiper and MathPiperIDE” book:

http://patternmatics.org/mathpiper/developer_releases/

3) Read section 8.4.1 “Rectangular Selection Mode” that starts on line 883.

4) Read section 9. Create a new .mpw worksheet file named
“section_9_examples.mpw” and save it. Copy some of the example folds
this section contains into the new worksheet, and evaluate them by
placing the cursor inside each fold and pressing <shift><enter>.

5) After you have evaluated some folds, notice that a file named
“section_9_examples.mpwlog” has been created in the same directory
that “section_9_examples.mpw” is in. Open this log file inside of
MathPiperIDE and look at it. A copy of the code that is in a fold when
it is evaluated is placed into this log file each time a fold is
evaluated.

6) Copy the following fold into the bottom of the worksheet and evaluate it:

%mathpiper

ViewList('(5 + 6*21/7 - 2^3));

Show(TreeView('(5 + 6*21/7 - 2^3)));

UnparseLisp('(5 + 6*21/7 - 2^3));

%/mathpiper

Two windows will be displayed, one directly over the top of the other.
Move the top window to the side. Compare the diagrams that these two
windows contain with each other and with the code that was returned as
the fold’s side effect output.

Both of the diagrams contain equivalent and completely unambiguous
representations of the relationships that exist between all of the
operators and operands in the given mathematical expression . If you
were ever curious about the programming language Lisp, the diagram
produced by ViewList and the code displayed in the side effect output
will give you some clues about its nature.

7) Enable the “Show Positions” checkbox that is at the bottom of the
tree diagram. The positions that are shown are used to navigate to
different nodes in the tree starting from the root node (which is the
topmost node). For example, the / operator is at position “122”, and
the 3 is at position “22”. Can you see how these positions can also be
used to navigate the list diagram of the expression?

8) Copy the following fold into the bottom of the worksheet, and evaluate it:

%mathpiper

code := ''{
a := 1;
Echo(a);
b := 2;
Echo(b);
c := 3;
Echo(c);
};

ViewList(code);

Show(TreeView(code));

code;

%/mathpiper

The '' operator is called the “freeze” operator. It is similar to the
' “hold” operator, but the hold operator only holds its operand for
one evaluation while the freeze operator holds its operand
indefinitely.

Separate the two windows that are shown, and compare their contents
with each other and with the diagrams that were produced for the
mathematical expression by the previous fold. You should notice that
mathematical expressions and programming code expressions are
represented using the same tree/list mechanism. I think students of
all ages would think this information is very interesting.

9) One last example fold just for fun :-)

%mathpiper,output="flowchart"
{
a := 1;
Echo(a);
b := 2;
Echo(b);
c := 3;
Echo(c);
};
%/mathpiper


If you have any questions, comments, or bug reports, please submit
them to the Math Future group.

Ted

kirby urner

unread,
Apr 18, 2016, 3:24:39 PM4/18/16
to mathf...@googlegroups.com

Hello Ted.

If I get to <guild /> tonight, which is the current plan, I'll plan
to get as far as possible with exactly the assignments you give
us below. 

I'll hook up MathPiper to a second monitor (the school has a
lot of monitors just sitting around) and if anyone asks (as they're
encouraged to), I'll dive in to some kind of explanation, a good
way to expand awareness of MathPiper. 

Maybe I'll just be reading documentation (the stuff you assign). 
That's role modeling what it's like to be in boot camp (these
meetups are one more intake valve).  Staring at documentation
is something we do.

I went to this same "Monday Night Python Circus" last week and
did all of the above except last week I was tackling the

%clojure
S and E modules computations [1], using tetrahedron volume
formula based solely on lengths of six edges
%/clojure

issue and someone asked me about Vagrant, sending me on a
reverie / tangent chronicled here:

http://worldgame.blogspot.com/2016/04/a-code-school-evening.html

Peter, if you're listening in...

I clued Margaux with CERM Academy that you'd be another
person to interview about your curriculum writing.  She's looking
into the whole Python for Kids arena, doing market research for
Greg.  You're a pioneer in that area.

She's only 16, but suave around adults thanks to her atypical
"home school" training, meaning learning trig etc. in StarBucks
from her engineer dad.  Her mom runs a business too. 

She and her dad (Greg) joined me at <guild /> last Monday and
helped me scope it out and brainstorm some generic gift shop
ideas [2].

Here's a picture of Margaux & Greg @ PDX Code Guild:
https://flic.kr/p/GceeyX
(I write for Greg's mailing list / blog sometimes)

And here's one of me when I was closer to her age:
https://flic.kr/p/4VKFbP  (just for kicks -- from when I was a
high school math teacher)

The idea is we're building a stash of code school stuff behind
a paywall and it's not yet clear to me how much K-8 or even
9-12 (as in grade school) will be a focus. 

Our clientele is aged 21-49 on average. 

However that does NOT mean that:

(A) we'll ignore all the Turtle and Minecraft stuff or
(B) we can't learn by writing curriculum

On the contrary, writing curriculum for K-8 and 9-12 is a
great way for 2nd-3rd-career-hunting 30-somethings to
rekindle their love of STEM, programming in particular.
"Learn by Teaching" [tm] right?

For some there's no "rekindle" as they've never loved
programming ever (nor hated it either -- no strong emotions
need apply). 

So they dive in with JavaScript, move to a LISPish functional
language for Lambda Calc (likely not part of high school --
that's only just starting to happen), then come up for air inside
our Python bubble, with Jupyter Notebooks and all that
(Haskell serves well as a Jupyter engine right?).

It's not that our placements all end up as Pythonistas on the
job.  The JavaScript component is stressed all the way through.
We aim for "polyglot" as the norm though.  As programmers
have long recognized "knowing just one language" is almost
a contradiction in terms.  Once you know that much JavaScript,
Clojure and Python, learning Java, C-Sharp or even Erlang
should not be that difficult.  You'll be over the hump.

Kirby

PS:  newer version of "Nonsense Numbers":
http://coffeeshopsnet.blogspot.com/2016/04/nonsense-numbers.html

[1]  E-module is tetrahedral sliver (wedge of a "spherical pizza"),
120 of which (half right handed) assemble to give rhombic triacontahedron
scaled down 1/phi from what Koski and I call "super RT" (the one in
which icosahedron of t.v. 18.51... is inscribed).  S-modules are even
more obscure if you can believe it.  I'll post something right after this to
help clear up the nomenclature for anyone interested.

[2]  people go to code schools to learn how to write
eCommerce software, like an on-line gift shop, so it stands
to reason any code school worth its salt (A) has a gift shop
and (B) runs software it wrote or co-wrote in-house.





Ted

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

Peter Farrell

unread,
Apr 18, 2016, 3:56:59 PM4/18/16
to MathFuture
Thanks, Kirby,

I'd be interested to help any way I can. Currently looking for ways to help and get paid at the same time.

I agree Jupyter notebooks are the wave of the future. Maybe someday they'll even do MathPiper!

Peter

Ted Kosan

unread,
Apr 18, 2016, 4:39:33 PM4/18/16
to mathf...@googlegroups.com
Peter wrote:

> I agree Jupyter notebooks are the wave of the future. Maybe someday they'll
> even do MathPiper!

Last month I studied the Jupyter notebook source code to determine
what would need to be done to add MathPiper as a kernel. It did not
seem like it would be very difficult.

Ted

kirby urner

unread,
Apr 18, 2016, 4:50:51 PM4/18/16
to mathf...@googlegroups.com
I've not studied Jupyter from a source code angle but know it's intended much like JEdit as able to work with a lot of kernels (or we could say servers to this common front end or client). 

Jupyter is a client that also allows editing such that what one creates is a Notebook with runnable code patches, handed off to a native interpreter.

That's what publishing to the cloud means these days:  a combination of reading and interactivity.  That's why the big publisher math textbooks won't be in the pipeline for much longer (hey, nothing wrong with recycling). 

Wood pulp textbooks don't have "runnable code patches". :-D

Kirby

kirby urner

unread,
Apr 19, 2016, 12:16:26 AM4/19/16
to mathf...@googlegroups.com
On Mon, Apr 18, 2016 at 12:24 PM, kirby urner <kirby...@gmail.com> wrote:

Hello Ted.

If I get to <guild /> tonight, which is the current plan, I'll plan
to get as far as possible with exactly the assignments you give
us below. 

All going according to plan, but what's Alt \ on a Mac?  I'm having
trouble toggling that Rectangular Select on and off.

Oh wait, I just figured it out:  control

I'm taking more pictures, and I did get an opportunity to talk
about MathPiper to the Swiss bioinformatician who sat next
to me.

My last name Urner is Swiss and we joked about how the
canton Uri, from which it derives, is little more than a lake,
and a very steep mountain.

I also explained what I was attempting to accomplish in
Clojure, since that's the code that originally came up on
the MathPiper screen.  The volume of S and E modules
in tetravolumes (I explained tetravolumes).

You'll see new slides scattered in this Album.

https://www.flickr.com/photos/kirbyurner/albums/72157664766721643

This one for example:  https://flic.kr/p/GijnMv

Great stuff.  I finished my homework except for the video
which I've saved for later.

Kirby



Joseph Austin

unread,
May 2, 2016, 9:23:36 PM5/2/16
to mathf...@googlegroups.com
Ted,
Working my way thru MathPiper Lesson 2.

Re rectangular selection:
Intro version .150
888 On Mac, for <Alt> use <control>; 
896 for <CTRL> use <command> 

Line 791: it's a nit, but for:
 
For example, in the expression 2 + 3, the addition operator +
tells MathPiper to add the integer 2 to the integer 3 and return the result.

I would assume this would be evaluated the other way around: 

For example, in the expression 2 + 3, the addition operator +
tells MathPiper to add the integer 3 to the integer 2 and return the result.

This is consistent with the treatment of non-commutative operators
and post-order evaluation.

Joe Austin

On Apr 18, 2016, at 5:41 AM, Ted Kosan <ted....@gmail.com> wrote:

Ted Kosan

unread,
May 2, 2016, 10:47:26 PM5/2/16
to mathf...@googlegroups.com
Joe wrote:

> Re rectangular selection:
> Intro version .150
> 888 On Mac, for <Alt> use <control>;
> 896 for <CTRL> use <command>

Fixed in version .151.



> Line 791: it's a nit, but for:
>
> For example, in the expression 2 + 3, the addition operator +
> tells MathPiper to add the integer 2 to the integer 3 and return the result.
>
> I would assume this would be evaluated the other way around:
>
> For example, in the expression 2 + 3, the addition operator +
> tells MathPiper to add the integer 3 to the integer 2 and return the result.
>
> This is consistent with the treatment of non-commutative operators
> and post-order evaluation.

Good point (fixed in version .151).

The "Evaluate" mode of the following expression structure app I wrote
has support for visualizing both PEMDAS and Post-Order evaluation:

http://patternmatics.org/test/expression_structure.html

At some point I think it would be helpful to add more expression tree
visualizations to this book to show explicitly how the CAS is working.

Thanks for the feedback, and feel free to point out any problems in
the book that you notice no matter how small they are.

Ted

Joseph Austin

unread,
May 3, 2016, 1:20:21 PM5/3/16
to mathf...@googlegroups.com
On May 2, 2016, at 10:47 PM, Ted Kosan <ted....@gmail.com> wrote:

Thanks for the feedback, and feel free to point out any problems in
the book that you notice no matter how small they are.


You may regret that solicitation :-) JA

I'm still on version .150

  1. 1222  The NewLine() procedure simply prints a blank line in the side effects output.

    Actually it doesn't necessarily add a blank line, just starts a new line.

    E.g.  

    %mathpiper
    a:=1;Write(a);
    b:=2;Write(b);NewLine();
    c:=3;Write(c);NewLine();
    %/mathpiper

        %output,sequence="13",timestamp="2016-05-03 11:08:34.582",preserve="false"
          Result: True
          
          Side Effects:
          12
          3
          
    .   %/output
    ===========
    1280 A code sequence ...

    At this point there is no motivation for "code sequence".
    Consider moving the thought in 1330 up: e.g.
    In later sections we will see powerful reasons for grouping a sequence of expressions together.  We call this a code sequence, which...

    1. 1486  Exception: String index out of range: 8 


    The text in the book does not match the actual error message.
    I'd assume this would all be cleaned up in a final edit.
    One trick we've used is to create an error message file,
    and reference all the text by key (message number), 
    so any change in text would be reflected everywhere.

    Example 1: mpw:
    %mathpiper,title=""
    a := "Hello, I am a string."; 

    Echo(a[22]);

    %/mathpiper

        %error,sequence="18",timestamp="2016-05-03 11:53:14.257",preserve="false"
          Result:  Error: String indexes must between 1 and the length of the string (inclusive).  Error on or before line 79 starting at index 5.
    .   %/error

    Example 2: Console:

    In> a[0]
    Result: Exception
    Exception:  Error:  String indexes must between 1 and the length of the string (inclusive).   Starting at index 0.

    ---
    Finally finished lesson 2.  
    I think the various expression diagrams are powerful learning tools.

    On to lesson 3.
    Joe Austin

Reply all
Reply to author
Forward
0 new messages