Do copies of Hamlet exist embedded in the digits of pi?

I know Vi Hart discussed it, but she may have not been the first to entertain the idea. Not sure. The question is do they digits of pi contain copies of hamlet?

Yes, yes they do. Not just copies of Hamlet, but actually copies of every book imaginable are contained within the digits of pi an infinite number of times.

Using software package pi and simple shell commands,

pastebin of shell commands

I found that any N digit sequence probably appears within the first 10^N digits of pi [1]; moreover, the sequence would appear about 10 times in the first 10^(N+1) digits of pi, 100 times in the first 10^(N+2) digits, etc.

For example, lets say our sequence is the last 4 digits of my phone number – 1345
That’s 4 digits, so if I scan the first 104 digits of pi, sure enough, my phone number occurs 1 time. If I scan 105 digits, it occurs 12 times. For 109 digits, it occures like 98 times. Its clockwork. See below.

```altoidnerd@HADRON:~\$ pi 10000|grep -o 1345|grep -c 1345 1 altoidnerd@HADRON:~\$ pi 100000|grep -o 1345|grep -c 1345 12 altoidnerd@HADRON:~\$ pi 1000000|grep -o 1345|grep -c 1345 114 altoidnerd@HADRON:~\$ pi 10000000|grep -o 1345|grep -c 1345 1020```

Anyway, so the question is how many digits of pi would we need to search through to likely find about 1 or 2 copies of hamlet in the sequence?

So I got hamlet in plaintext from 2 sources. I found that hamlet when compressed from plain text to a tar.gz archive, the average size was 69 KiB. Therefore, (I think?) that means to represent hamlet as just a binary integer, it would have 69 x 8 x 1024 digits = 565248 digits.

To get the number of digits in base 10, we multiply by log_10 (2) +~ .69 so the base ten hamlet would be like a sequence of about ~390,000 digitsm (0-9).

Ok so back to pi. How many digits of pi must we scan to probably find a string of length 390,000? That would be 10^390000 digits. That’s a lot of pi, but pi has got enough digits to spare. We should see approximately 1 copy of hamlet in the first 10^390000 digits of pi.

Even cooler is that if we just increase the power by 1, we should see 10 hamlets; increase the power by 2, and we should get 100 copies of hamlet. So quickly, we end up with infinite hamlets in the digits of pi. And not only hamlet … this argument should would for any book.

[1] This is not too surprising since pi is believed to be a normal number, though this is unproven.

Cigar box guitar amp with LM386 + JFET preamp guide with LTSpice optimization

Of all the circuits I’ve ever designed purely by guessing, this one has the highest performance/expectations ratio.  I took the LM386, basically combined two of the diagrams in the data sheet, and added a transistor preamp stage and some high quality capacitors.  And dude.  I like the way this thing sounds.  A lot.   First picture time, then full schematics.

The power amplifier section (left above) is nothing more than a combination of the first two schematics given in the LM386 data sheet.  And yeah yeah the sloppy soldering…  I told you it was on the fly.

The way the 386 works is not like a normal op amp.  If that is messing with your mind, it does with mine as well.  But this is life.  It is a cool chip anyway.  The way this works is that 10u cap AC shorts an internal 1.35k gain setting resistor.  So I added the cap, as well as a switch so I can go between high and low gain settings.

The switch you see there is from radio shack.  It is used to switch between the gain of 20 and gain of 200 settings; it is placed right in series with the 10u capacitor which amounts to an amp with two settings.  You either have decent clean-ish, or absolutely saturated, raunchy, but good distortion.  But it’s not because of the LM386 alone – the little preamp has a lot to do with the sound and overdrive in this design.  This 386 is seeing a well-groomed guitar signal.

That’s the preamp, on the near side.  The image below is a spice model of the transistor premap circuit. And if you don’t know what spice is PLEASE learn spice. You must learn spice.

This little preamp was adapted from some ideas I had seen online.  But I this combination of common source followed  by follower is a bit uncommon (a lot of times you see common base instead – this is called the cascode amp). I just like the way this one works for no particular reason, just many.  It is sometimes difficult to bias (as transistors can often be…) but I’ll show you how to take the guesswork out of it using LTSpice.

With JFET’s, my strategy is to set the drain currents the way I want them first, and for that I like to use spice.  It is a sensitive issue.  Here are some plots of the performance of this preamp driven with a 10k sine of 100 mV (if you want the spice files, just contact me).

The capacitors paired with resistors have RC time constants that determine the transfer curve or frequency response of this preamp.  Whenever you build one of these, you want to put some thought into those RC constants. Here’s how to obtain the desired transfer curve from RC elements in an amplifier like this, while making sure your transistors are in their safe operating regions.

Using DC sweep to set Id

Realize it is a common source amplifier followed by a common drain (source follower). So the second transistor is actually never going to give us a gain more than 1.  The first transistor’s gain is set by the size of R4, the drain resistor of J2.  Higher R4 means more gain in the common source stage.  So, because C4 looks like a short to high frequency, this gives us our high frequency rolloff:

The low frequency -3dB point is determined by the input capacitance.  You want a nice big cap to get that bass!  Audible tones are as low as 20 Hz, and tactile sense goes even lower.  Keep the bass…but you don’t want any DC.  So you get a pretty big cap, but just make sure it is not electrolytic.  Not for your signal path.  Metal film, ceramic disk, whatever.  Anything but electrolytic in the signal path.  And I don’t know if its mysticism or not, which there is a LOT of in audio as we all know…but I have noticed this input cap is a pretty big deal, so you may want to buy some nice ones.  These were \$10 on ebay for 8 of them.  I used two in the amplifier here.  Anyway, let’s see the gain now:

Not a crazy high gain.  I’d like there to be more.  Then I could use the LM386 as an output and not have to rail it to get some drive.  Hmmm.  The gain itself is set by the drain resistor of J2 (which I have stupidly labeled R4 ; sorry).  I want more gain, so I need to increase R4. But the most important part of this transistor design process is keeping an eye on your drain currents.  You can do this either with the data sheet and the equation

Id = Idss*(1-Vgs/Vp)^2

(I’ll write a more technical article later about how I optimized this by hand and with mathematica).  Or you can do this in spice with DC sweep and monitor the currents through R1, and R4.

Well they don’t look completely ideal, but as long as I don’t use too high of a supply voltage, I’ll stay in that linear region.  , but what you really want is the drain currents (shown above) to be in the flat region at the supply voltage you choose.  If you look at 9V there, I seem to be in the correct region of operation for my transistor.  But in the case of a guitar amp…you can certainly push the limits because hey – it’s just a little distortion.  Sounds fun, right?

Let’s increase the gain.  How do we do that?  We recall from the common source link, that drain resistor sets my gain.  Ok lets make it 850 ohm.  That won’t change much right?

Holy moly, we have a pretty distorted waveform and we can see why.  Look at my drain currents now.  Not only are they small, but they’re “much less linear.”

The big picture:  There are lots of ways to use spice.  One of those ways that is particularly good for discrete transistor design is DC sweep and checking out your transistors – make sure they’re in the correct operating range.  This waveform might be cool for some effect or something, but it will not give a good result if the idea is to reproduce exactly the waveform it sees.  I do like this amplifier anyway.  I plan next to make this thing with a variable supply voltage – controlling the gain that way is really cool.

Final design notes and summary:

Bypassing the supply (skip if not a noob)

This is one of those things that is basically automatic for this kind of circuit, yet if you’re a noobie, nobody really mentions it.  So I will.

• You must put 100 nF caps to ground as close as possible to the pins on your 8 pin op amps or anything similar.  If you’re still learning, think about what effect that would have.  What frequencies see a short to ground?  The idea is for your supply to be nice clean DC, because your supply will mess with your…well, everything, as we have seen.  We do not want it to fluctuate much, at any frequency.

• You want to place some big electrolytic caps between the node where you connect the battery to ground.  That is the very least you can do.  If you just pick big capacitors, you’re fine…I think I used 220uF here or something really high.  I was sloppy here because I could.  Sometimes, though, you’ll want to make a little RC network that charges up and take a little time.  This is especially true if you’re using CMOS.  JFETs can really take a beating, but not all transistors can handle a big impulse.

Connect the preamp to the LM386 schematic

• Feed the preamp into the LM386.  And see that I have a 10k resistor in my spice diagram?  That is not really in the final circuit – it’s just for the simulation, to act like the 386, which is (like an op amp or “op ampish thing” supposed to have a massive input impedance.

AC couple the output

• Put a capacitor at the output of the LM386 between your amplifier and your speaker.  Just experiment with different sizes.  Remember that caps block DC.  You don’t wanna hear any sudden DC in your speaker.  It’s nasty.  This is called AC coupling and is a great idea in many cases.

Don’t load it down too hard – its just a chip

• This little chip is awesome, and can drive a 3 ohm speaker.  But don’t push it.  It does start to oscillate driving 3 ohms, for one. And it’s not too big of a deal if you blow the chip because its cheap but you can start a fire perhaps if you let the battery get super hot or the chip starts on fire.  I find it unlikely, but yeah.  Stay above 4 ohms for the best sound anway.  I was really happy with a 6 ohm load in fact.

The one modification that would really make it nicer is increasing the supply rail from 9V to 12V, which is its max.  or better yet, use two LM386’s and an inverting buffer to get +-12V.  This should double the power output, which honestly, is surprisingly satisfying from 3/4 watt.  Try it out and let me know what variations you make!  This little thing screams.  Another cool mod would be varying the supply voltage.  I say this because we saw how much the circuit right there at the drain of J2 affects the overall waveform.  You could do some wonky stuff with this thing.

Have fun, be safe, ask any questions if you need help, and respect electronics! It’s not the safest hobby on earth.  Disclaimer disclaimer disclaimer!!

Altoidnerd

BTC: 13xdMqkaVKkHKT3ZZx5ikAvQUEkzqpDkDb

Donate Bitcoins