Monday, May 30, 2022

Is 2 taken to the power of one million minus 1 a prime number? NO! and I didn't have to calculate it to find out......I used some LSD

 Mersenne prime numbers are ones that have the form 2^N - 1.  Not all (actually relatively few) prime numbers have this relationship, and of course not all numbers that can be calculated using that formula are prime.  For a simple example, 2^4 = 16.  16 - 1 = 15, which is divisible by 3 and 5 -- so it's not a prime number.

You will have to read on to learn about the LSD.

Prime numbers are important when it comes to generating highly secure encryption codes, so they have been of interest for a long while.

For some reason, perhaps yet another sleepless night, I started thinking about powers of two, in terms of their digits.  More specifically, if the least-significant digit of them has any kind of pattern to it.  Some simple mental arithmetic revealed the answer, and it should become obvious when I write down the first few powers of 2, starting with N = 1:   2, 4, 8, 16, 32, 64,128, 256....and so on.  Looking at the Least-Significant Digit (the LSD, gotcha!!!) of this series we see:  2 4 8 6 2 4 8 6 .... so we have a sequence of 4 digits that endlessly repeats:  2 4 8 6 .... A little more mental gyrations and I came up with a way to predict what the first digit of any power of 2 is.  It does take a little more math, requiring the use of the Residue function.  Residues are calculted by getting the remainder of long division.  It's easier to show by example, like this:  take a look at 10/4.  Long division gives us a quotient of 2 because 4*2 is the nearest multiple of 4 that is closest (but not larger than) 10.  10 - (4*2) gives us the remainder, 2.  That is what the Residue function produces -- the remainder.  So if we examine the Remainder of (any whole number)/4, we find they can only be either zero, one, two or three.

Now let's create an array with the values [6,2,4,8] in it.  The array entries are a little different than what you might expect since the indices into the array are 0, 1, 2 and 3....4 isn't possible because its residue is zero.

Now let's determine what the LSD of 2 taken to the one-millionth power must be.  Some simple math says that the remainder of 1,000,000/4 is 0 (this will be true for any power of 10 greater than 1).  The first entry in the array is a 6, so we know that the LSD of 2 to the millionth power is a 6.

Recall that Mersenne primes have the form 2^n - 1.  If we subtract 1 from 6, we get 5, and all numbers ending in 5 are divisible by 5.  Therefore, it is NOT a prime number.

For the same reason, we also can say that any number calculated by evaluating 2^(10^n) -1 also are NOT primes, as long as n is greater than 1.

It so happens that we can use a similar but slightly more complicated scheme to determine what the next-most-least-significant digit (NMLSD) of a power of 2 is.  I won't go into much of it here except to say that the sequence has a length of 20.  The NMLSD of 2^1,000,000 is a seven.

After that the sequences become ever-longer so the approach becomes less and less viable.  If nothing else, it becomes necessary to accurately calculate some pretty large numbers, just to examine their smallest parts.

Friday, May 13, 2022

Touch Sensor Update

In some ways it's been a rough year, what with Covid and a rental-rehab project we found ourselves saddled with.  Supply-chain and contractor issues caused problems; and in many cases we found that the most expedient way to move forward with the project was to do the work ourselves.  We did a lot of research before embarking on any of the major projects we had to do.  Anyway, all that delayed work on my touch sensor -- but now that we've got the rental fixed up (and rented), I've had time to work on some long-delayed personal projects.  That includes the touch sensor that I designed a PCB for.  I did have time to order the PCB and assemble one, but that's about as far as it got until recently.  I finally was able to hook up my 4-point sensor connectors and test the thing:  and, what a surprise -- it worked, right off the bat.  

The wires connecting the modified battery-charger clips to the circuits are a mess, since I used individual wires but I have some cable management stuff I can wrap around them to make it all a little less like an octopus waiting to snare me when I pass by.

Now I'm working on a really sad antique dresser we bought a few years back.  When we bought it we didn't realize what bad shape it was in, so it needs some work -- to put it mildly.  I think a child may have used some of the drawers as a ladder and stepped through the bottoms.  The dovetails on the lowermost drawers were loose, and the rabbets on several of the side pieces (the ones that hold the bottom piece in place) were split or just plain broken off.  I also had to reinforce the sides for a couple of them.  It has water damage, too -- the oak veneer on one side of the case has delaminated.  I'm not going to try to repair that for now -- it basically was purchased to put in a guest room so visitors should just appreciate having a dresser, however it looks (as long as it is usable, anyway).  The feet are a mess, too -- three have the remnants of some sort of steel foot, and there's nothing at all on one of them.  The steel will be pretty bad for scratching our wood floors so there's some work to do there before the dresser is put into service.  I learned a lot during our rental rehab w/regard to doing stuff like trim work so that will come in handy for this project.

Friday, May 6, 2022

Oxygen, the master vampire element

 As a preface to this entry, I'm going to write about my first real experience with what I now call the master vampire element, oxygen.  At the time, I was working on a different approach to etching gold.  Since gold is a relatively inert element, it takes some doing to etch it -- basically, turning the metal into a salt of some kind.  I was thinking about gold chloride.  Aqua Regia is a commonly-used etchant for gold, made by mixing nitric acid and hydrochloric acid.  Thing is, the mixture is unstable because the two acids react to form something called Nitrosyl Chloride -- and it quickly decomposes.  It also takes some time for NOCl (its chemical formula) to form so you're running a race between getting the etchant working and then using it before it decomposes.  There also are a number of different ratios given for the ingredients, probably because they come in a number of different concentrations.  So I had some interest in coming up with something that was more stable and more reproducible.  I had concentrated hydrochloric acid available, the same with 30% hydrogen peroxide, so I had the thought of combining the two to see how that would work.  The idea was that the peroxide would oxidize the gold and then the acid would react with the oxide to form its chloride.

Well, my new etchant sort of worked but it turned out to be even more unstable than aqua regia.  The REALLY interesting part was that my mixture quickly decomposed by releasing a green-yellow gas:  chlorine.  Well now, what was that about?  It didn't take long for me to realize that the hydrogen peroxide had done it, using its extra oxygen atom to grab two hydrogen atoms from two molecules of hydrochloric acid (HCl), forming one molecule of water and one molecule of Cl2.  Up to that point, I had thought that chlorine was a pretty strong oxidizer and was pretty safe from being affected by oxygen:  but my little experiment blew that notion right out of the water.  BTW I performed my experiment with just a small quantity of the two materials, under a fume hood so no harm done.

Now I want to talk a little about the idea of "valence".  Fundamentally, it means how many electrons an element in a compound has either gained or lost:  or wants to gain or lose.  Many reactions are all about electrons.  For instance, in the water molecule we have two atoms of hydrogen and one atom of oxygen.  Oxygen has a valence of 2, because it "wants" two additional electrons to fill its outer shell (and each hydrogen atom only has one to provide, so it takes two to form a stable molecule).  And oxygen REALLY wants those electrons, as shown by my little experiment.

It gets even more interesting though.  Looking at chlorine (Cl), it has a valence of 1 when it combines with things like sodium to form sodium chloride, table salt.  In that case chlorine is the oxidizer and sodium is the reducing agent.  But oxygen is such a powerful oxidizer that it can actually wrest electrons _away_ from chlorine, which in itself is no slouch as an oxidizer.  In fact, oxygen is so powerful that it can abduct SEVEN electrons from chlorine, forming perchlorate compounds.  They are used to make explosives in fireworks.  Perchlorate compounds themselves are extremely powerful oxidizing agents, so if mixed with things like charcoal and sulfur they are more than ready to go boom.  Perchlorates are not the only ones that are infected by the bite of oxygen.  Chromium trioxide (CrO3) is notable because it is in a +6 oxidiation state (3 * oxygen's valence-of-2 = 6).  Squirting acetone on a pile of dry chromium trioxide powder will instantly cause the acetone to burst into flame because it's just ripped apart by the combination of hexavalent chromium and oxygen.  Another good one:  the permanganate ion.  In that one, manganese is in a +7 oxidiation state.  By now it  shouldn't be much of a surprise that it also is an extremely powerful oxidizer.   It will react with a sugar solution at room temperature and turn it into black sludge in very short time.  When bitten by oxygen nitrogen suffers a similar fate and as a result becomes usable for things like explosives (think nitroglycerine) and rocket fuel.

In these instances, the base elements -- chlorine, chromium and manganese -- range from being a fairly powerful oxidizer to "not in my wheelhouse" -- but oxygen bites 'em and they turn into vampires themselves.  That's why I call oxygen the master vampire, because it can affect otherwise innocent elements and turn them into monsters, too.