How I Got Started with Programming

I was going through my desk the other day when I came across something interesting...my old TI-83+ from middle school through college. I remembered that there were some old programs on there that I had written throughout the years, and I thought it might be fun to look at some of them. After a quick trip to the garage to grab some batteries she was up and running just like I remembered.

Quadratic Formula

Texas Instruments (TI) began support for their programming language TI-Basic with the release of the TI-81 calculator released in 1990, and have continued to support the language in every calculator model since. While most students have probably discovered the PRGM button on their calculator, and perhaps dabbled with it, few have discovered the computational power available to them, and fewer still have been able to utilize it to its full potential. I won't claim to be in the last group, but I did manage to write some useful functions with it that saved me a lot of time on tests.

Using TI-Basic was actually my first foray into the programming world. It started in middle school where I was told to copy down the instructions for a basic quadratic formula solver into the program memory by my algebra teacher. Unfortunately I didn't touch that feature again until the end of my sophomore year geometry class in high school, and didn't seriously utilize it until my senior year. Little did I know at the time that that little taste of programming would go on to become the foundation of my career.

Lets get to looking at one of the old programs that I wrote shall we? It only seems fitting to start with the one that started it all - QUAD. While I said before that QUAD started life as a copy and paste quadratic formula solver from middle school, it was later improved as I learned about complex numbers and determinants. Without further ado...QUAD:

ClrHome
Prompt A,B,C
(B²-4*A*C)→D
If D<0
Then
Output(4,1,B
Output(4,3,"+-i√("
Output(4,9,-D
Output(5,4,2*A
Else
-((B+√(D))/(2A))→E
-((B-√(D))/(2A))→F
Disp "Solutions",E,F
Output(5,1,"X="
Output(6,1,"X="
Quadratic Formula Solver

Breaking this down, the code it looks pretty straightforward.

First clear the screen and prompt for input to three variables A, B, and C.

ClrHome
Prompt A,B,C

Next calculate the determinant of the quadratic formula and assign it to a new variable D (→ is the assignment operator in TI-Basic). For those like myself that haven't taken high school math in quite a while, here is the quadratic formula:

\[ x_1, x_2 = \frac{-b \pm \sqrt{b^2 + 4ac}}{2a}\]

And in this context the "determinant" is just a fancy way of saying the "stuff inside of the square root ".

(B²-4*A*C)→D

Then check if the determinant is less than zero. If it is it will crash the square root function of the calculator and we don't want to do that It also means that the solution will be a pair of complex numbers and so we should output those accordingly.

If D<0
Then
Output(4,1,B
Output(4,3,"+-i√("
Output(4,9,-D
Output(5,4,2*A

Otherwise we should use the square root function of the calculator to come up with the two solutions to the equation.

Else
-((B+√(D))/(2A))→E
-((B-√(D))/(2A))→F
Disp "Solutions",E,F
Output(5,1,"X="
Output(6,1,"X="

The first thing that struck me when I read this was that none of the output statements had closing parenthesis on them. Obviously the program still works, so after some research I discovered that this is a common space saving optimization because TI-Basic doesn't require closing parenthesis at the end of a line. Big plus one to my past self for recognizing that, but unfortunately I didn't realize that I could have gone further and removed the end of line quotation marks as well.

The next thing I noticed was a distinct lack of indentation. I don't remember indentation being an option, but at the same time I probably just didn't realize that it was important. This is probably a good time to mention that none of my schools up until Iowa State offered any programming classes, and so I was entirely self taught. But I hope that any course that I would have taken would have emphasized good code cleanliness and indentation.

It is definitely on the simpler side, but it does exactly what it needs to do. If I were to write it again today I would probably make the code cleanliness changes that I mentioned before and try to add some logic so that it would output a simplified radical when the determinant is an integer. Currently, it will just return large floating point numbers that are harder to read than \(\sqrt{3}\). Overall I think the code isn't that bad for a first program, and I'm happy that it still works after all these years.

As I was researching this post, I found an old website that I remember using back when I was first learning how to write TI-Basic. I can tell that its the same site because it hasn't changed since I first discovered it over a decade ago. And the forums are surprisingly still active! Its somehow comforting to know that as much as the world has changed, that there is still a small community helping new programmers like I was to learn the ropes the same way that I did all those years ago.