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

Leave a comment

Your email address will not be published. Required fields are marked *