A Math Mantra

There is not a standard definition of mantra, from my own (simplistic) view is a chant that has been performed collectively (e.g. Om, Om, Om,….) by humankind for so long (thousands of years), coupled with the fact that people tend to put positive intentions when praying or meditating, that somehow evolutionary-wise ended up embedded in our system as some sort of magic words that have the potential to unlock wellness. 

There is something about prime numbers that have caught the attention and curiosity of mathematicians for a very long time (thousands of years), it seems that in every culture someone has ended up captivated with curiosity about their governing rules.  Even at the present time, there are prizes set for solving theorems and finding patterns around them.

Following my line of thought about mantras, playing around with prime numbers is some sort of math-mantra.  (I’m putting all my positive intentions on getting an A in discrete math.)

Let’s math-mantra:

A prime number is simply defined as a number that is divisible only by 1 and itself (producing an integer result, of course).  For example: 14 can be formed 7 x 2, and 9 can be formed as 3 x 3, both 14 and 9 are non-prime numbers (a.k.a. composite numbers).  But how about 7? You can only use 7 x 1 to form it, you need 7 itself; how about 2, 3, or 15487469? Same thing.

What’s the big deal?

Any non-prime number can be reduced to a unique multiplication of primes.  This is so important that is called “The Fundamental Theorem of Arithmetic“. Therefore, primes are kind of unique particles (atoms) in the chemistry of numbers.

Is there a way to find primes?

Although some approximations have been developed, to be sure you need to try, one-by-one, looking for any potential divisor, and there are an infinite number of primes (this fact was proved by Euclid more than 2000 years ago). 

Taking the positive integer numbers one after the other, primes appear on a rather chaotic way (if you find a nice pattern maybe a prize awaits), sometimes they are spread apart and some other times they are just 2 numbers apart (e.g. 5 & 7, 11 & 13, or 15487469 & 15487471) on this particular case primes are called twin-primes, it is believed there are also an infinite number of them, although not proved yet.

The following Java code goes one by one tracing primes and twin primes, then prints out left-to-right, top-to-bottom a pattern with “_” for non-primes, “-” for primes, and “[_]” for twin primes.  Isn’t that mantra-beautiful?

public class TwinPrimes {
	public static void main(String[] args) {
		int newLine = 50;  //add a new line every 50 characters
		int maxLines = 30; //how many rows to print
		int lastPrime = 2;  //2 is the first prime
		int numbersToScan = maxLines * newLine;
		char[] output = new char[numbersToScan];
		for (int i = 1; i < numbersToScan; i++) {
			// This loop will go through every positive integer
			int testFactor = 2;
			while ( (i % testFactor != 0) && (testFactor <= i) ) {
				// This loop tests if testFactor is a factor of i 
				testFactor++;
			}
			if ( (testFactor < i) || (i == 1)) {
				// print something when i is not prime (has a factor > 1 and <i)
				output[i-1] = '_';  //array first index is 0 for integer number 1
			} 
			else {
				// print something else to flag a prime
				output[i-1] = '-';  //Standard prime 
				if (i - lastPrime == 2) {
					output[i-1] = ']';
					output[i-3] = '[';
				}
				lastPrime = i;  
			} 
		}			
		// Print characters, every newLine skip a line
		for (int i=0; i <= numbersToScan-1; i++) {
			if ( (i >= 1) && (i % newLine == 0) ) {
				System.out.print(" " + i + "\n");
			}
			System.out.print(output[i]);
		}
	}
}

Output:

_-[_[_]___[_]___[_]___-_____[_]_____-___[_]___-___ 50
__-_____[_]_____-___[_]_____-___-_____-_______-___ 100
[_]___[_]___-_____________-___-_____[_]_________[_ 150
]_____-_____-___-_____-_____[_]_________[_]___[_]_ 200
__________-___________-___[_]___-_____[_]_________ 250
-_____-_____-_____[_]_____-___[_]_________-_______ 300
______-___[_]___-_____________-_____-_________[_]_ 350
__-_____-_______-_____-_____-___-_____-_______-___ 400
-_______-_________[_]_________[_]_____-___-_____-_ 450
______-___[_]___-___________-_______-___-_______-_ 500
__-_____-___________[_]_________________-_____-___ 550
______-_____-_____[_]_____-_________-_____-_____[_ 600
]_____-_____-___[_]___________-_________[_]___-___ 650
__-_____[_]___________-___-_____-_______-_________ 700
-_______-_________-_______-_____-_____-___-_______ 750
-_____-___-_______-___-_____________-_________-___ 800
________[_]_________[_]___[_]_________-___________ 850
__-___[_]___-_____________-___[_]___-_____________ 900
______-___-_______-_________-_______-___-_____-___ 950
__-_____________-___-_____-_____-_______-_____-___ 1000
________-___-_____[_]_________[_]_____-_________[_ 1050
]_________[_]_____-_________________-___[_]___-___ 1100
__-_____-_______-_____-_____-_____________________ 1150
[_]_________-_______-_________-_____-_____-_______ 1200
-___________-___-_____-_____[_]_____-___________-_ 1250
________-_________________[_]___-_____[_]_____-___ 1300
[_]___-___________[_]_____-_______________________ 1350
__________-_____-_____-_______-_________________-_ 1400
________-_____________-___[_]___-_____-_______-___ 1450
[_]_____-___________-_________[_]___[_]___-_____-_ 1500

Math and Computer Science

Having to go through a discrete math class in the first semester of my Master’s degree in Computer Science (UPenn-MCIT) was intriguing at first, after all, this is a degree targeted for non-CS professionals, so what’s the deal on having to learn math proofs in the form “prove that if x is even then x*x is even” as our first approach into the field? As part of the introductory materials School’s Faculty went through this question explaining (in much better logic and language, of course):

“In order to make sure your program works on all possible inputs, you have to prove it.  No amount of testing gives you that certainty”. 

Sounds promising though hard to internalize.

First math homework asked us to find as a “further challenge question” a game outcome, a game of the style: “you have a bag of the following items, if you remove two items at a time and then add another item following some sort of rules, then what is the last item in the bag?”

When I noticed there was some form of randomness in this, my first approach was to think about it in probabilistic terms, and then I concluded: anything can happen (something in the Schrödinger’s cat paradox way of thinking) and I even write one and a half sheets of nice LaTeX-formatted arguments justifying my rationale which I spend the following days polishing. 

At breakfast my girlfriend asks: “how is your first week in grad school?” I go through all sorts of thoughts showing how happy I am, then I tell her about my math challenge question which I happen to have completely nailed.  She is an artist, one that I truly admire, and on her artistry curiosity, starts digging more to understand the problem, asking all sorts of questions I haven’t thought for sure. Then she says:

“I think you are so much into your own solution that are not even open for looking other possibilities”.  She is right, I’m not open because my answer is correct.  You are not open for other possibilities about 1+1=2.

I arrive home and take advantage of my rudimentary Python coding skills and build a simulation of the problem, after 10 iterations my answer of “anything is possible” is not showing up, only one outcome shows every single time.  Matter of probabilities, then after 50,000 iterations, I start realizing this is not what I expected.  And this is the time my girlfriend laughs, and also the time I take a blank piece of paper, starting to open for new possibilities (while letting an infinite loop of simulations that would only stop if a different outcome comes out, happen in the background, I’m not that easy).

Blank piece of paper, what the hell is going on?  Some hours (and a smaller scale exercise with coins in my desk) later, a proof comes out, showing a pattern in which indeed there is only one outcome possible.  Then I stop the simulation.

For me, this whole experience made the point of “why would you care about proofs?”.  And, of course why should I continue having breakfast conversations with an artist about CS.

A new journey in CS

I’m starting a very exiting journey, I enrolled on a master’s degree in computer science, I’m on week #1, last week was #0 (or minus 1, it’s complicated).  Coming back to school after graduating about 20 years ago from a relatively unrelated field and not being a student for more than 15 years, makes it exciting and at the same time challenging.  Is one of the things I’m doing just because I like it, for sure I have tons of professional aspirations coupled with this, but simply put, the main reason is:

“I’m doing it because I want to”. 

Let’s say that I would be doing this even without those sound professional goals.

The trill about being able to earn a degree online from an Ivy League University, while listening to my Discover-Weekly in Spotify, having video conferences and being able to handle my business remotely with a laptop and a smartphone is hard to explain to A.G. (after Google) generations.  Being forty one, means I saw IT evolution happen, or better said, explode in front of my eyes.  I saw things come to life such as:  3 ½” Floppy Disks, Cel phones (I mean it, not smartphones; I saw those too for sure… much later), Internet, messaging, email, PacMan, color computers, the list is long.  Studying CS was a growing itch that started long ago and I really had to start scratching it.

One evening, I saw this TED TaIk from Daphne Koller, founder of Coursera, there were several insights for me, first was Coursera itself, I really was not aware of the depth and breadth online education covered, but most importantly how to approach it, is not about adapting classroom learning to remote students, is about taking advantage of its unique characteristics for providing a better education experience.  Being a learner (nerdy) when joined Coursera, I felt like an unsupervised kid on a candy store.  This master’s degree, called Master of Computer and Information Technology (MCIT) from UPenn, was announced within the platform, and here I am! Starting the journey with a very interesting group of people.