Sierpinksi's Monster Made Palette-able

Buttons and palettes simplify the work of writing with Mathematica 3.0.

by David Fowler and Robert Dickau

In Writing Mathematics Well, Leonard Gillman [Gillman 1987] presents the following example of terrible mathematical notation:

\(TraditionalForm
    \`t\_\(n\_κ\%\(ξ\_κ\%α\)\)\%\(ξ\_κ\%α\)\)

This symbol is the work of the great Polish topologist Wacław Sierpi(Overscript[n, ‵])′ski, (*Joe, can't find the correct Polish symbol*) perhaps better known to readers of this journal for the Sierpinski triangle (*Footnote: The underlined term is a hyperlink, which takes readers of the electronic version of this article to a section at the end showing Mathematica 3.0 code for generating a version of the triangle. Hyperlinks and advanced notebook programming will be covered in future issues of Mathematica in Education and Research. *). 

In an appendix showing how to simplify the notation, Gillman remarks "Sierpinski had a pixyish quality and may have done all this partly because it was so much fun." [Gillman 1987, page 38].

In the spirit of fun, then, but also to demonstrate the power of Mathematica 3.0's new palette feature, we show that this "monster," as Gillman labels it, presents no problems for the Mathematica 3.0 user.

We list the exact set of clicks and keystrokes needed to create the expression. The reader who does not wish to verify each stroke will still appreciate the ease with which the expression can be created.

Creating a Sierpinski monster with the BasicTypesetting palette

This simple tutorial uses the BasicTypesetting palette, located under 
File: Palettes⊳

Begin by typing the character "t" into a text cell. Now select the character and click the subsuperscript button  on the BasicTypesetting palette (see illustration). Mathematica will add placeholders for subscript and superscript characters, leaving the cursor within the subscript placeholder (Subscript[t, ◼]^□). Notice that Mathematica also italicizes the letter t. A second click on the subsuperscript button adds two additional placeholders to the subscript placeholder: \(TraditionalForm
      \`t\_\(◼\_□\%□\)\%□\). The cursor is still located within the original subscript placeholder. Pressing the ⇥ key moves the cursor into different placeholder boxes.The sequence of moves progresses in a pattern such that pressing ⇥ twice will relocate the cursor to the superscript attached to the original subscript.  Another click on the subsuperscript button adds a new set of placeholders: \(TraditionalForm
      \`t\_\(□\_□\%\(□\_□\%□\)\)\%□\). Three more presses of the ⇥ key and a final click on the sub-superscript button gives us the template we were seeking: \(TraditionalForm
      \`t\_\(□\_□\%\(□\_□\%□\)\)\%\(□\_□\%□\)\).

To fill the boxes with the appropriate characters, position the cursor in the bottom-left box and enter the character "n". The remaining characters can be entered by combining ⇥ keystrokes to relocate the cursor and clicking the appropriate Greek character on the BasicTypesetting palette. The keystroke sequence is  ⇥ -κ-⇥ -ξ-⇥ -κ-⇥ -α-⇥ -ξ-⇥ -κ-⇥ -α. Behold the monster! 

When the cursor is positioned over a Greek character on the palette, an alternate keystroke combination is shown at the base of the palette. For example, instead of clicking on the α button, the keystroke combination EscaEsc can be used. Expression of the corresponding keystroke combination will be left to the reader.

It is simple to create a button to give at one stroke a template for the Sierpinski monster.

(Subscript[t, (Subscript[\[Placeholder], \[Placeholder]]^((Subscript[\[Placeholder], \[Placeholder]]^\[Placeholder])))]^((Subscript[\[Placeholder], \[Placeholder]]^\[Placeholder])))

Create an empty button by choosing Input ⊳ Create Button ⊳ Paste, and then paste the template for the Sierpinski monster into the button’s placeholder. To activate the button, select the entire button, and then choose File ⊳ Generate Palette from Selection.

Creating a useful button

We now show how to create a button that would be useful in a mathematical discussion on sequences. The idea is inspired by Gillman's "deconstruction" of the Sierpinski notation—a topic to which we will return at the conclusion of this article.

The button we have in mind will insert in a line of text the string
"{(Subscript[□, 1]), (Subscript[□, 2]), ...}" with the selection boxes filled with a symbol of the writer's choice. Thus a writer wishing to compare the sequences
{(Subscript[a, 1]), (Subscript[a, 2]), ...} and {(Subscript[b, 1]), (Subscript[b, 2]), ...}, could simply select this button once for each sequence. Furthermore, we will configure this button so that the writer need only type the initial letter in a sequence, select it and click the button. The button will then add a second instance of the letter, italicize both characters and insert subscripts, ellipses and braces. In other words: "consider the sequence z " becomes "consider the sequence {(Subscript[z, 1]),(Subscript[z, 2]),…}" with a selection motion and a click.

The key to creating a button that performs sophisticated actions on any currently selected text is use of the notebook-manipulation commands NotebookRead and NotebookWrite. NotebookRead[notebook] returns an expression that represents the current selection in notebook, and NotebookWrite[notebook, data] writes data into notebook at the current insertion point, writing over anything currently selected.

To determine what sort of data to write into a notebook, it is instructive to create the desired expression by hand, and then display the expression form of the expression by choosing Show Expression from the Format menu. For example, here is a text cell that contains an expression similar to the one we wish our button to create.

{(Subscript[a, 1]), (Subscript[a, 2]), …}

Here is the expression form of the cell containing the expression, found by selecting the cell containing the expression and choosing Format ⊳ Show Expression.

Cell[TextData[Cell[BoxData[
    FormBox[
      RowBox[{"{", 
        RowBox[{
          SubscriptBox["a", "1"], ",", 
          SubscriptBox["a", "2"], ",", "\[Ellipsis]"}], 
        "}"}], TraditionalForm]]]], "Text"]

Here is a function that reads in any currently selected text, and then writes back the desired list.

\(Sequencify := 
      Module[{inputnb = InputNotebook[], sel}, sel = NotebookRead[inputnb]; 
        NotebookWrite[inputnb, 
			
          Cell[BoxData[
					
              FormBox[RowBox[{"{", 
								
                    RowBox[{
										
                        SubscriptBox[
											
                          StyleBox[sel, FontSlant -> "Italic"], 
                          "1"], ",", 
                        SubscriptBox[
                          StyleBox[sel, FontSlant -> "Italic"], 
                          "2"], ",", "…"}], "}"}], 
                TradionalForm]], "Output"]
		]]\)

To create a button that executes the function Sequencify, we create a new button by choosing Input ⊳ Create Button ⊳ Custom…. In the Edit Button dialog box that appears, we type Sequencify into the Button Function text field, and choose Local from the Button Evaluator pop-up menu. (*Joe, some questions about typsetting format*)

(*Joe, should probably shrink this graphic*)

After clicking OK, we create the button contents by typing any desired text into the button’s placeholder. In this case, we enter the expression \(TraditionalForm
      \`{■\_1, ■\_2, …}\), where ■ is the character \[FilledSquare] and not the character \[SelectionPlaceholder] usually used in palettes. The result is the following.

{(Subscript[■, 1]), (Subscript[■, 2]), …}

To activate the button, we select the button and choose File ⊳ Generate Palette from Selection.

To use the button, we create a text cell containing the following text.

We consider the sequences a and b.

Next we select the letter “a” and click on the Sequencify button. The following is the result.

We consider the sequences {(Subscript[a, 1]),(Subscript[a, 2]),…} and b.

Selecting the letter “b” and clicking the button again produces the desired result.

We consider the sequences {(Subscript[a, 1]),(Subscript[a, 2]),…} and {(Subscript[b, 1]),(Subscript[b, 2]),…}.

Note that the button works properly only in text cells, section cells, and title cells. Note also that the button can be made faster using commands evaluated directly in the front end, such as FrontEndExecute.

Conclusion: Writing Mathematica well

We have only hinted at the power of Mathematica 3.0's palette and button features. In particular, we have shown the typsetting side of the new features. Buttons can be programmed to perform evaluations of any expression defined by the user. Of course, these new tools should be used with established common sense to create understandable and simplified mathematics, rather than to bring new typographical monsters into the world.

Gillman provides three excellent steps to take toward simplifying mathematical notation [Gillman 1987, page 37]:
I. Use an uncomplicated symbol in place of an elaborate one.
II. Discard any symbol that is just plain unnecessary.
III. Simplify the mathematical argument itself.

Applying his own rules in a fine example of mathematical writing, Gillman simultaneously shows how to simplify the Sierpinski notation and outlines the proof in which this notation is used. Under Gillman's rewriting, the monstor becomes 

(Subscript[(Subscript[t, κ]^α), i]).

The Triangle

As a final example of programming in a button, here is the button code for generating the Sierpinski triangle. The reader is invited to experiment with the character "ξ" and to replace the number 5 with the desired depth of calculation.

Nest[SubsuperscriptBox[#, #, #]&, "ξ", 5] // DisplayForm // 
      TraditionalForm

References

Gillman, L., Writing Mathematics Well. Mathematical Association of America Press. 1987.

Stewart, I. Four encounters with Sierpinski's Gasket. The Mathematical Intelligencer, 17, 1, (1995), 52-64

About the authors

Electronic subscriptions

Included in the distribution for each electronic subscription is the file Monster.nb containing Mathematica code for the material described in this article.