## Boolean expressions on the TI-84 for Piecewise functions

Here I will try to explain boolean expressions. Boolean expressions are expressions that evaluate to “true” or “false”. “True” is like a value of 1 and “false” is like a value of 0 (zero).

Suppose you have $(x>-1.0881)$ as your boolean for Y1. If X is greater than $-1.0881$, the expression can be replaced with a “1”. In turn, $1 \times (1.5x + 3) = 1.5x + 3$, so a value of true causes Y1 to plot.

If X is equal to or less than $-1.0881$, this same expression can be replaced with a 0. $Y_1$ does not plot in that case. But since $X \leq -1.088$ falls in the domain of Y2, then it is Y2 that will plot instead.

Suppose now I have two functions on my graphing calculator:

$Y_1 = (1.5x + 3)(x < -1.0881)$
$Y_2 = (2x^2 - 1)(x \geq -1.0881)$

I have written the two booleans in such a way that only one of the statements can be true at a time. Notice that if the boolean for Y1 us true, then the one for Y2 is not. That means for X values less than $-1.0881$, only Y1 will plot. For all other values, only Y2 will plot, because its boolean will now be true and Y1‘s false. Ultimately, we obtain the graph:

This is produced by a piecewise function which can be expressed using the following standard notation:

Others have used different techniques for piecewise functions. One which seems to possess certain advantages would have been to place all details on to $Y_1$ as the sum of both “pieces” where each “piece” is multiplied by the boolean of the restriction, as follows:

$Y_1 = (1.5x + 3)(x < -1.0881) + (2x^2 - 1)(x \geq -1.0881)$

While being slightly unwieldy (being sure to run past the end of the display), it saves the user from having to flip between $Y_1$ and $Y_2$ using the $\uparrow$ key.

There was also a useful idea where you could disable plotting for Y1 and Y2; and, for a new function Y3, enter: Y1 + Y2 using the VARS key to obtain the Y variables. The result is a single function that does not require flipping between functions with the $\uparrow$ or $\downarrow$, and proving continuity is much easier. And, the function is more like a piecewise function rather than two separate functions.

## VIII: The Programmatic Side of Mathematica: Sampling With Replacement

Arrays. I can declare an array and return an arbitrary element from it:

S := {2,4,6,8,10}
S[[3]]
6

I can also do the same things for an anonymous array:

{2,4,6,8,10}[[3]]
6

In both cases, I request the third element of the array in double square brackets, and Mathematica returns with the number 6. I can request a random element as was shown in previour posts, but it would be better to name the array:

S[[Random[Integer,{1,Length[S]}]]]

The above statement returns a random element from an array without needing to know the length of the array. I could include it in my bag of tricks, since it would resemble sampling, especially if I sample a certain number of times.

Sampling with replacement means picking an element e from a set S without removing it. With sets, that amounts to just choosing elements from a set while allowing repetition. We don’t even need numbers. What about letters? Let’s re-define the set S thusly:

S:={a,b,c,d,e,f,g,h,i,j,k,l}

Now, let’s define a function called “pick[n]” which chooses some quantity of letters from S by passing the number of choices to it as “n”:

pick[n_]:=Table[S[[Random[Integer,{1,Length[S]}]]],{n}]

That’s a lot of nested brackets. But recall that the Table[] function generated a set of size n by executing the function in the first parameter n times, and returning the result as an array. But here, the function is passed into the Random[] function, which determines the array index of the element chosen from S. So, two calls to pick returned these for me:

pick[4]
{b,e,a,d}
pick[4]
{h,g,h,d}

So, as you can see, we have repetition.

## Quote of the day

Every programming language has some kind of way of doing numbers and math. Do not worry, programmers lie frequently about being math geniuses when they really aren’t. If they were math geniuses, they would be doing math, not writing ads and social network games to steal people’s money.

— Zed Shaw (2012), Learn Python the Hard Way

## Doing math without “technology”

Math is a mental process. Basic math techniques should be, for those that are learning basic math, of the variety that you should either be able to do in your head, writing your thoughts on paper; or learn how to do so if you can’t yet. It is essentially a human skill. We acquire new math skills by building upon a foundation of what we have previously learned. In my opinion, there is nothing that modern computers can do to change this, although it might help us learn different things.

Math is a means of pure intellectual inquiry. How would you investigate the following:

A is 100 m to the north of B. A moves to the east at 3 m/s, while B moves to the west at 3 m/s. Show that the midpoint of the line AB is fixed under these conditions regardless of the position of A or B.

There are a number of ways to show this to yourself. I didn’t want to say “prove”, since I am avoiding a rigorous proof here. Just say that one rainy day, you simply asked yourself that question. You weren’t trying to be rigorous, just curious. There is no teacher in the room; no critical parents. Just you, a pencil and some paper. And maybe a ruler. And an eraser. How would you tackle it?

Some people would draw a diagram moving A and B apart in regular invervals, with $\overline{AB}$ lines drawn between them. Others would show that the areas of the two triangles described by the initial vertical line $\overline{AB}$ at time zero and their present position are the same area, which implies their hypoteneuses are equal. You can also show that the midpoint of the line $\overline{AB}$ at any time > 0 is the same midpoint as exists between the initial $\overline{AB}$ at time = 0.

## A used calculus textbook

I have advocated Mathematica and other technologies in previous posts, but I think it is high time to advocate for doing math with the absence of technology other than an pencil and paper.

I like this rather old text I acquired from a used dealer: “Calculus With Analytic Geometry: A First Course” by UC Berkeley professors Murray H. Protter and Charles B. Morrey, published way back in 1963, about 49 years ago.

There is something to be said about a math text that isn’t full of distracting bull regarding applications of “technology” in aiding the completion of math problems. A real math text should be one where, if you were out on a desert island with nothing more than a pencil and paper (read: no calculator, internet or PC), you could try the examples and exercises and learn the ins and outs of math for yourself. Using technology trivializes math, while the use of serious thought makes the learning stick.

Related rates, which is a dying question type in Calculus (covered more in university these days), when they appear in modern texts, seem to require the use of a calculator. A book made like Protter and Morrey — written before the days of calculators — will often compensate by having questions you can do with a little thought and some scribbling of side calculations, making the calculator un-necessary. In doing their Related Rates problems, I haven’t felt the need for even a slide rule, which would have been the “technology” current with the text.

Sometimes going “desert island style” means you need to do long division, and at other times, you will need to be handy with dealing with radicals. And a book like this would be written with the expectation that you rarely need decimal answers, so an answer like $5\sqrt{10}$ is just left that way. No need to calculate further.

Here is an example:

A point moves along the curve $y = \sqrt{x^2 + 1}$ in such a way that $dx/dt = 4$. Find $dy/dt$ when $x = 3$.

In this day and age, I would almost be made to feel like an inventor who had discovered the art of solving related rates problems by hand all by myself. Of course, far from being a trailblazer and breaker of new ground, I am really treading on paths that are well-worn by every first-year math student in the past several decades. This is by no means magical and neither you nor I would not be the first ones to master it. But that doesn’t take away from the joy of discovery and “getting it right”, at least not for me.

My solution, scribbled in ink on a blank, unruled sheet of paper, was thus:

$\frac{dy}{dt} = \frac{1}{2\sqrt{x^2 + 1}}\cdot 2x \frac{dx}{dt} \\ .\;\;\; = \frac{6(4)}{2\sqrt{10}} = \frac{12}{\sqrt{10}} = \frac{6\sqrt{10}}{5}$

I found writing an answer this way to be liberating. Over the past 30 years or so, we have come to expect to see all numbers in decimal form. Decimals are almost never exact, since not many rational numbers are nicely convertable into base 10. Base-10 is also not intuitive to computers, which thinks only in base-2, and require an arithmetic logic unit to make the conversions. Today’s faster processors and “textbook-style” calculators make this problem less visible, but it is always there, and will likely be there for some time to come.

Over the past 30 years, we have come to expect that all numbers are integers followed by decimals. Why should we be locked into this expectation? $\frac{6\sqrt{10}}{5}$ is also a number. And it is better than a decimal representation such as 3.795, because it is exact, no rounding necessary.

## The programmatic side of Mathematica I

I have been playing with Mathematica 5, and have a big thick book on it from Wolfram and even a Schaum’s Outline on the program. All of these books touch on all of the functions of the program as though that was all there was to know.

But of course you can make your own user-defined functions, but material on that is harder to find. I managed to get my hands on a book published in the early 90s by Gaylord, Kamin, and Wellin, entitled Introduction to Programming with Mathematica. It does not appear that any specific version number for this program is mentioned in the text. But the publication date of 1993 would suggest that the intended version would be 2.1 or 2.2. I have version 5.2, but so far in the first few pages, I haven’t run into any trouble.

In the old days when an operating system was nothing more than a BASIC command interpreter (anyone old enough to remember the Commodore 64? or the TRS-80?), you are by default placed into an immediate mode where you can issue commands, test out command syntax or run programs written in the same language as understood by your interpreter (for the Commodore or TRS-80, that language would be BASIC). In Mathematica, that is what is happening. You are in a sort of “immediate mode” where you can issue commands or run pre-defined functions or programs, load your own functions, and so on.

The Mathematica kernel seems to allow you to enter similar commands as in this discussion without the need to press “shift-enter” to execute it as you do in the so-called “Notebook” interface. Just the “enter” key will suffice. I needed to open the kernel from the Start menu of Windows. Then I tried to test it out:

In[1]:= 39/7

39
Out[1]= --
7

OK, the interpreter works, and it works the way it seems to in the “Notebook” interface. You can also get help from a command by placing a question mark before it:

In[2]:= ?Plot
Plot[f, {x, xmin, xmax}] generates a plot of f as a function of x from xmin to xmax.
Plot[{f1, f2, ... }, {x, xmin, xmax}] plots several functions fi.

But the plotting of graphs  in kernel mode is a little … uh … different:

In[15]:= Plot[Sin[x], {x,0,2Pi}]

#               ####
1#            ####  #####
#          ###         ###
#        ###             ###
#       ##                 ##
#     ###                   ##
0.5#    ##                      ##
#   ##                        ##
#  ##                          ###
# ##                             ##
###                               ##
### #  # # #  # # # #  # # #  # # ###  # # #  # # # #  # # #  # # # #  ###
############################################################################
#          1           2          3  ##       4          5           6##
#                                     ##                             ##
#                                      ##                          ###
#                                       ##                        ##
#                                        ##                      ##
-0.5#                                         ###                   ##
#                                           ##                ###
#                                            ###             ##
#                                              ###         ###
#                                                ####  #####
-1#                                                   ####

So, it’s probably better to use the Notebook mode for graphs…

Being a math program, you can create your own lists or generate new lists from Mathematica’s “Range” function:

Range[min,max,increment]

A “List” function can generate arbitrary lists:

In[16]:= List[1,2,3,-4,dog, cat, Sin, "Hello World!", {a, b}, Pi, {}]

Out[16]= {1, 2, 3, -4, dog, cat, Sin, Hello World!, {a, b}, Pi, {}}

In[17]:= Range[-12,15,7]

Out[17]= {-12, -5, 2, 9}

Notice the last output was for a Range command I inputted. The command asked for every 7th number between -12 and 15, including -12.

It doesn’t have loops in the pascal sense, but it has iterators, which are more compact. Here, I generate 50 random numbers:

In[18]:= Table[Random[],{50}]

Out[18]= {0.384617, 0.0481281, 0.278996, 0.161237, 0.880606, 0.587204, 0.996814, 0.0335705, 0.367147, 0.730021,

>    0.195816, 0.707583, 0.316029, 0.030375, 0.971311, 0.607889, 0.172245, 0.461959, 0.511372, 0.001557, 0.830695,

>    0.517233, 0.716287, 0.984279, 0.446078, 0.469105, 0.437292, 0.823042, 0.565472, 0.881901, 0.440478, 0.789472,

>    0.198325, 0.151881, 0.244661, 0.0818886, 0.882296, 0.121506, 0.27335, 0.474, 0.71005, 0.659546, 0.761978,

>    0.472443, 0.879355, 0.142313, 0.0456913, 0.488163, 0.433277, 0.673208}

{50} refers to the number of times the Random[] command must be repeated. Trouble is, the output looks a bit messy. You can clean this up by dividing the {50} into two dimensions, then tacking on a //TableForm modifier to the end of the whole command:

In[20]:= Table[Random[],{10},{5}]//TableForm
Out[20]//TableForm= 0.503921    0.225364   0.462814   0.985969   0.276704
0.613243    0.320156   0.961345   0.836671   0.519041
0.827408    0.256483   0.473772   0.283214   0.222593
0.39894     0.308651   0.763449   0.460018   0.900552
0.908033    0.286537   0.931285   0.096198   0.404112
0.0611721   0.468471   0.110229   0.127408   0.447929
0.148315    0.148884   0.290737   0.928888   0.320907
0.8924      0.816965   0.645673   0.098314   0.493461
0.508314    0.882225   0.638296   0.592909   0.600281
0.595688    0.707011   0.496711   0.196169   0.534516

This looks a bit better. {10},{5} specifies 10 rows and 5 columns. But of course you can have counters:

In[25]:= Table[i*j, {i, 1, 8}, {j, i, 8}]//TableForm
Out[25]//TableForm= 1    2    3    4    5    6    7    8
4    6    8    10   12   14   16
9    12   15   18   21   24
16   20   24   28   32
25   30   35   40
36   42   48
49   56
64

Here are the equivalent of two nested loops. You can think of “i” as the outer loop, and “j” as the inner loop, and I think the whole thing will make sense. And the loop syntax will accept a fourth parameter for loop increment:

In[35]:= Table[i*j, {i, 1, 8}, {j, i, 8, 2}]//TableForm
Out[35]//TableForm= 1    3    5    7
4    8    12   16
9    15   21
16   24   32
25   35
36   48
49
64

This one causes j to go to every second number. Note the change in the output. With a few more number operations, I can have 100 dice rolls in table format:

In[57]:= Table[IntegerPart[Random[]*6]+1, {10},{10}]//TableForm
Out[57]//TableForm= 6   3   6   6   4   4   5   2   5   1
5   5   3   2   3   1   2   1   5   6
2   2   6   1   2   5   6   2   4   2
2   1   6   1   3   2   3   5   6   2
1   5   2   2   6   4   3   1   5   5
3   6   1   3   1   6   1   3   4   4
5   4   4   3   4   6   3   2   4   3
6   1   6   4   4   2   6   1   3   3
5   5   6   6   6   1   2   3   3   2
6   2   5   6   6   1   5   2   2   5

IntegerPart[] takes the place of Trunc[] in many languages, returning the integer part of a number containing decimals. The chopping, or truncation of decimals is necessary to guarantee a dice roll between 1 and 6. Round[] is also available if you wish to experiment with it. It will round, but you will be rolling some zeroes as a result.