Using Baby Math

While Baby TeX is useful for communicating elegant yet abstract formulae, we also need to have our feet on the ground. High school students. Engineers. Tutors. Lawyers. Accountants. Teachers. Composers. Chefs. What do they have in common? They all own and use some kind of calculator. iStorm provides a pretty powerful calculator with two modes just like the Baby TeX. It allows users to define their own variables initially up to 1000 instances. If the slot is exhausted, it will dynamically allocates more slots (each allowing 500 variables at a time) up to 100 times! That is, you will have practically unlimited number of variables to define. It is important to understand what it does not do: it will do most numerical operations using standard double precision mostly on the built-in standard functions of math library in C. It will not do calculations with an arbitrary precision as Mathematica does. It will not do matrices. It will not do 2D or 3D plots. It will not do symbolic mathematics. What it does is simple numerical evaluation of mathematical formula using predefined constants and user-defined variables. It also does fairly complete unit conversion to SI system. In the Appendix of the pdf version of this document, you will find the list of built-in functions and the syntax. Concise summary is also available in the Baby Math module window.

Inline Substitution Mode

Just like TeX equations were enclosed by $ ... $ or $$ ... $$ pairs, Baby Math expressions are enclosed by # ... # or ## ... ## pairs. #...# expression will be replaced by the result, while ##...## expression will remain intact, with the numerical value appended. Just as in the inline TeX Mode, the intelligent substitution may break down if you have several suspect #...# zones near the current cursor location. Baby Math follows a heuristic rule: if it finds more than one possible pair of # . . . #, it prefers the one on the left side of current cursor position. When in doubt, manually select the target block and then issue the Baby Math command. Several math statements may be combined in a single expression separated by semi-colons ; . For example, let us evaluate how much equivalent energy there is in joule for a mass of 70 kg using the famous Einstein's formula : Energy = Mass * (speed of light)^2. It is impressive if you know the speed of light already, but Baby Math knows it too as @c.

Therefore, you can simply type
# M = 70.0 ; E = M * @c^2; E #
and press Command-= . You will see the whole expression being selected and replaced by the result as shown in below.


If you do not think you really weigh 70 kg, you can double click on the small symbol to bring up the code and revise the formula either in the Baby Math module or by replacing the result with the code in line.


If you are experienced with variables and calculators, you may now wonder about the persistence of the variable M and E. They will remain until you redefine them later. If you doubt, try a mile away from the original block of code, processing #E # simply to see what value it has. You may therefore build up a series of calculations, using many variables scattered all over your document. It is perfectly reasonable to define Mass and what not in a paragraph and carry out the numerical evaluation of some formula using those variables in another paragraph.

Caution regarding variables in a group collaboration

Reading the following section may induce a headache for those of you who were happy with the silly calculator Apple provided in the last century. If "persistence of variables" does not ring anything, skip ahead.

However, there is one note of caution following this observation. While the values you define persist in each variable until you redefine it, it may lead to some error as the piecemeal expressions get exchanged and modified on different machines. Remember that the variables in Baby Math are not shared among group members.

To illustrate this further:
Suppose Jan processed # M = 70 # on page 10 of their paper, and then used # E = M * @c^2 # in page 14 to get the number 6.2912e+18. Without knowing this, Jane takes the control of the document, and decides to re-evaluate # E = M * @c^2 #. To complicate the situation, she had her own definition # M = 55 # in page 12, which Jan didn't notice. Now, having evaluated earlier #M = 55# on her machine, she re-evaluates # E = M * @c^2# to get an answer different from what Jan got.

The implications of two NASA engineers making this error on a Mars landing project is pretty chilling.

Given this potential confusion, it is generally safe to define all variables inside a single #...# block. That is, if you use Baby Math in a group collaboration, do not ever trust a variable defined somewhere outside the current block being evaluated. As we mentioned at the beginning, Baby Math is very generous with how many variables you can define and use! So do not recycle them outside each block unless you are absolutely sure.

If you still need to have variable assignments scattered all over document, one possible precaution to minimize risk is to follow a strict convention in naming them, so that other people understand that the variable named Jan_M refers to Jan's Mass and was introduced and assigned a value on Jan's Baby Math. If anyone else need to use it in other part of the document, he can make sure of its value by printing Jan_M and other suspect variables as in the first line of the following code:
# 
Jan_M ;  
Jane_M;
.....
Jan_E = Jan_M * @c^2; Jan_E
#

Baby Math Module

You can bring out the separate Baby Math module by pressing Command-Shift-M or choosing Baby Math in the Tools Menu. You don't need the #...# symbols for typing in the expressions to be evaluated here. On the right side, one can look up the list of functions and predefined constants.
If you check "Do not attach source" option, the source code will not be attached to the result. Generally it is a good idea to keep the source code attached so that you or other collaborators may examine or modify them later.
Reset button is to clear Baby Math when an expression with bad syntax caused it to hang.

If you are having these problems/questions:

If I assign a value of 10 to a variable a_1 in a document, can I use the a_1 in another document? Will it have a value of 10 in another document or is it treated as a separate variable?
The variables of Baby Math are shared by all open documents in iStorm on a given machine. However, only the expressions are shared over network. If Jan processes #a_1 = 10 # in Document_1, and uses it in Document_2, he may assume a_1 to be 10 in both documents until he redefines it. However, on Jane's machine, even if they are collaborating on Document_1, a_1 will not have 10 unless she process the assignment herself on her Baby Math.
Will iStorm have fancy graphing tool someday?
We want to keep many possibilities open, but given limited resource, we do not want to spread too thin. Instead we would like to focus on a few things and get them done superbly. Therefore, do not keep your hopes too high on this. Yes, it is still tempting....