# Usage of Mathematica in Two Places in my Book

Mathematica is a commercially available program that can solve math problems, and it has its own general-purpose programming language that is not limited to just math.

In June 2017, while working on the 12th edition of my book A Soliton and its owned Bions (Awareness and Mind), I had occasion to use Mathematica to help me with a specific math problem I had in my gravity algorithm. And in July 2017 I used Mathematica to write a program that tests my sphere-filling message-sending algorithm that is detailed in the pass_this_message_along() routine in subsection 3.8.5 in my book.

In total, I created three different Notebooks (Mathematica’s terminology). A Notebook filename is suffixed with “.nb”, and this file is a large, bulky text file. However, Mathematica has an option to save a Notebook in other formats, including “Plain Text (*.txt)”, and I used this option to create the following three .txt files which I hereby place in the public domain:

1. mathematica-for-footnote-23-gmr-vectors.txt : See the First Use of Mathematica in my Book section below, for a detailed explanation of this text file.

2. mathematica-for-footnote-23-compute-test-cases.txt : This allows one to give arbitrary values for (x1, y1, z1), (x2, y2, z2), and L, and then verify that the vector’s head-point (x3, y3, z3) was computed correctly. In effect, this tests whether or not Mathematica’s solution of the Solve[] in mathematica-for-footnote-23-gmr-vectors.txt is correct, and that I had written the rules for setting add_or_subtract correctly. After trying many different values for (x1, y1, z1), (x2, y2, z2), and L, my conclusion is that Mathematica’s solution is correct and I had written the rules for setting add_or_subtract correctly. See the First Use of Mathematica in my Book section below for an explanation of add_or_subtract.

3. mathematica-test-sphere-filling-messaging-algorithm.txt : As said above, this tests my sphere-filling message-sending algorithm that is detailed in the pass_this_message_along() routine in subsection 3.8.5 in my book. More specifically, this tests the selection code in that routine. The selection code determines which adjacent computing element(s), if any, to give the message to, based on two pieces of data: the message sender’s XYZ coordinate and the XYZ coordinate of the computing element that has the message and is running the pass_this_message_along() routine.

If you have Mathematica, you can copy the text in any of the three above Mathematica .txt files into an empty Notebook and then evaluate it and see the results. Do the following (these instructions are correct for version 11.1.1.0 Home Edition of Mathematica which is the version that I had when I wrote these instructions in August 2017):

1. On Mathematica’s menu, select: File: New: Notebook

Result: A blank Notebook page opens up.

2. Copy the entire text from one of the three above .txt files into that blank Notebook page.

3. At this point the copied text is now in that Notebook page. To evaluate that copied text, select on Mathematica’s menu: Evaluation: Evaluate Notebook

In the case of copying the text from mathematica-test-sphere-filling-messaging-algorithm.txt into the blank Notebook page: You will have to scroll down to the end of that copied text, if not already there, to see the result of that evaluation. Also, the only input variable for this test program is cubeWidth which is near the top of the copied text. In the .txt file it is set to a value of 31, which should take about a second to evaluate. If you change cubeWidth’s value to a substantially higher odd-number value, note that substantially more execution time will be needed (read the two comments—each comment is bracketed by (* and *)—immediately above the cubeWidth = 31; line in the .txt file).

## First Use of Mathematica in my Book

In June 2017, while working on the gravity algorithm that is in my book, I wanted to know how to compute the head-point of a 3D vector when I knew three things about that vector (denote the XYZ coordinate of this vector’s head-point as (x3, y3, z3)):

• The tail-point of the vector (denote as (x1, y1, z1)).

• The length of the vector (denote as L).

• The vector lies on a line defined by two different points: the tail-point of the vector which is (x1, y1, z1), and another point (x2, y2, z2) which can be anywhere in 3D space as long as it’s not the vector’s tail-point (x1, y1, z1)).

The first thing I tried to do, given the above three knowns, is find the solution on the internet. However, I wasn’t sure how to construct my search query, and after about an hour of search effort, I gave up and decided to try solving the problem of computing the vector’s head-point myself. I knew it was an algebra problem, described in my book as:

Note that the computed value of (x3, y3, z3) must satisfy two different equations. The first equation is the equation of a line when two different points on that line—in this case, (x1, y1, z1) and (x2, y2, z2)—are known: ((x3 − x1) ÷ (x2 − x1)) = ((y3 − y1) ÷ (y2 − y1)) = ((z3 − z1) ÷ (z2 − z1)). The other equation is the distance formula: L = square_root_of((x3 − x1)2 + (y3 − y1)2 + (z3 − z1)2).

The text file mathematica-for-footnote-23-compute-test-cases.txt is my Mathematica code for computing the values of x3, y3, and z3—the coordinates of the wanted head-point (x3, y3, z3)—in terms of the known values (x1, y1, z1), (x2, y2, z2), and L. Note: any text that begins with “(*” and ends with “*)” is a comment.