More than 100% pregnant
May 9, 2024 at 11:21 PM by Dr. Drang
Kieran Healy tweeted out a gem earlier this evening:
Yes, Professor Huberman, a probability of 120% is indeed “a different thing altogether.”1
While I find it fascinating that someone can run through an argument that clearly proves they are wrong and continue along as if they hadn’t, I don’t have any expertise in psychology, so I won’t try to explain it.
I do, however, have some expertise in probability, and Huberman is dancing around the edge of one of my favorite problems: If there’s a 1 in n chance of something happening in one try, what’s the probability of it happening in n tries?
Remarkably, the answer is not
It’s
The term in the parentheses is the probability of it not happening in a single trial. That term raised to the nth power is the probability of it not happening in n trials (assuming independence between trials). And subtracting that from 1 gives us the probability of it happening (at least once) in n trials.
What’s great about this problem is that you can make a pretty decent estimate of the answer without doing any calculations. The reason is
and so
Now, in the Huberman problem n is 5, which is not especially close to infinity, but luckily the convergence to the limit is pretty rapid.
I would have guessed the answer for was about 0.65; it’s actually 0.67. Not super accurate, but better than 1.
Update 10 May 2024 12:21 PM
John D. Cook also saw the Huberman clip and wrote a nice post this morning about how adding probabilities is a reasonably close approximation if both
- the base probability for a single trial is small; and
- the number of trials is small.
Absolutely true, but not as much fun as a solution that ends up with Euler’s constant popping up out of nowhere.
A nice, safe cup of tea
May 8, 2024 at 11:00 AM by Dr. Drang
As I was making tea this morning, I was reminded that many people on the internet think I’m an idiot. I’d like to defend myself.
I heat the water I use for brewing tea in a microwave oven. This is, according to the internet, a terribly dangerous practice, as I could very easily end up with superheated water that will suddenly boil over and scald me. That I’ve never had such an accident in maybe 20 years of making tea this way is a strong hint that I’m doing it safely, but it isn’t proof. Maybe I’ve just been lucky the roughly 6,000 times I’ve done it.
So let’s do some calculations. The thermal mug I currently drink from has a 20-oz capacity, so I heat up about 600 ml of water in a Pyrex measuring cup. I put the measuring cup in a 1200-watt microwave and set the timer for 3:10. That works out to
of energy being put into the water (J = joules). This is an overestimate, as it doesn’t account for the heating of the glass cup.
The water coming out of my kitchen faucet tends to be 50–55°F. Let’s call it 12°C, so bringing this water to the boiling point requires
The energy I’m putting into the system is, at most, about what it takes to bring the water to a boil. So I’m not creating superheated water.
What about hot spots? If I’m not heating the water uniformly, I could still be superheating some portion of it, right? I suppose, but like all microwave ovens, mine has a turntable, so no part of the measuring cup stays in the same place. Not even the center, because I don’t put the cup in the middle of the turntable.
Now, I don’t want to be irresponsible here and suggest you all go out and start microwaving water with no concern for the risks. But there is a way to do it safely, and I’d like to be given some credit for knowing how.
Perplexity and beam bending
May 7, 2024 at 10:07 AM by Dr. Drang
David Sparks tested out the Perplexity AI-driven search engine and was moderately impressed, even though he disagreed with one of its answers. I decided to give Perplexity my own test, a structural engineering problem similar to one I gave ChatGPT last year.
My first question was this:
A cantilever beam of length L has a concentrated load P at midspan. What is the deflection at the free end?
This is not the most clearly worded question in the world, but I thought most structural engineers would interpret it as this problem,
I would have been satisfied if Perplexity had answered “Listen, dumbass, the concept of ‘midspan’ is questionable when it comes to cantilever beams because they don’t have supports at both ends.” Instead, Perplexity gave basically the same wrong answer as ChatGPT did:
For a cantilever beam of length L with a concentrated load P at midspan, the deflection at the free end is given by:
δ_max = PL^3 / (3EI)
Where:
δ_max is the maximum deflection at the free end
P is the concentrated load applied at midspan
L is the length of the cantilever beam
E is the modulus of elasticity of the beam material
I is the moment of inertia of the beam cross-sectionThe key points are:
- The deflection is maximum at the free end of the cantilever beam.
- The deflection varies with the cube of the beam length L, making longer beams much more susceptible to deflection.
- The deflection is inversely proportional to the flexural rigidity EI of the beam, which depends on the material and cross-sectional geometry.
So in summary, to calculate the free end deflection of a cantilever beam with a midspan concentrated load, simply substitute the given values of P, L, E and I into the formula δ_max = PL^3 / (3EI).
Like ChatGPT, Perplexity treated the question as this problem,
which is perhaps the most common cantilever beam configuration in example problems you’d find on the internet, but it’s not what I asked about.
(Also, “the maximum deflection at the free end” makes less sense than “midspan of a cantilever beam.” But we’ll let that one go.)
I followed up with a clarification and asked Perplexity to try again:
This answer is for the load applied at the free end. I want the deflection at the free end when the load is applied halfway between the fixed end and the free end.
I hoped this was a more explicit description of where the load was applied. Here’s Perplexity’s answer:
For a cantilever beam of length L with a concentrated load P applied at the midspan (L/2 from the fixed end), the deflection at the free end is given by:
δ_max = PL^3 / (8EI)
Where:
δ_max is the maximum deflection at the free end
P is the concentrated load applied at midspan
L is the length of the cantilever beam
E is the modulus of elasticity of the beam material
I is the moment of inertia of the beam cross-sectionThe key points are:
- The maximum deflection occurs at the free end of the cantilever.
- The deflection varies with the cube of the beam length L.
- The deflection is inversely proportional to the flexural rigidity EI.
- For a midspan load, the deflection is 27% higher than for a load at the free end.
So to calculate the free end deflection for a midspan concentrated load on a cantilever beam, substitute the given values of P, L, E and I into the formula: δ_max = PL^3 / (8EI)
It was nice that Perplexity understood where the load was applied and that the formula for deflection had to be different from what it gave me before. However:
The deflection at the free end, as we determined last year, is
not
as Perplexity said.
- The deflection is not “27% higher than for a load at the free end.” Even if we use Perplexity’s answer, one-eighth isn’t 27% higher than one-third. In fact, it’s quite a bit lower (as is the correct answer). So that last bullet point in Perplexity’s answer isn’t just wrong, it’s internally inconsistent.
Every teacher has seen students come up with internally inconsistent answers and not recognize them as such, so in that way Perplexity is mimicking human behavior. But we wouldn’t call it intelligence.
Weekdays of future passed
May 2, 2024 at 10:01 PM by Dr. Drang
Some time ago, I wrote a little shell script called next
, which used the date
command to output the date some number of weekdays after the current date. So if I ran it today (Thursday, May 2, 2024) with this invocation,
next tue
it would return
2024-05-07
which is the Tuesday of next week. If I ran it with this invocation,
next tue 2
it would return
2024-05-14
which is the Tuesday after that, i.e., two Tuesdays after today.
This worked out pretty well, except that I had to run it in the Terminal1 and then copy the output if I wanted it to go into some document. The switching to the Terminal and back made next
a lot less convenient than it should have been.
So I rewrote it as a Keyboard Maestro macro that I can run from anywhere and get the output onto the clipboard immediately. I call the macro download it (you may need to right-click on that link).
, and you canWhen
is invoked, typically by ⌃⌘W, this window appears:You choose the day of the week from the popup menu (the default is Monday) and enter the number of those weekdays after today in the text field (the default is 1).
Assuming I choose two Tuesdays from today, as in the second next
example above, the output is this:
As you can see, it tells me what the date is and gives me the option to put it on the clipboard in either of two formats:
yyyy-mm-dd
, which is what I’d typically use if I were making notes for myself.- Month Day, Year, which is what I’d use in an email or text to someone else (probably deleting the year).
Or I can just
the macro if all I want is to see the date.Because next
, it’s more complicated, but it still uses date
to do most of the work. Here’s the code:
The key is the shell script in the second step:
weeks=$(( $KMVAR_Local_Number - 1 ))
date -v+${weeks}w -v+1d -v+$KMVAR_Local_Chosen_Weekday '+%Y-%m-%d'
The first line subtracts 1 from the number of weekdays the user asks for and puts that into the variable $weeks
. The second line does the work. The first two -v
options tell date
to move forward $weeks
weeks and one day. The third -v
option tells it to move to the weekday chosen by the user. The final argument is the output format.
If I asked for the second Tuesday after today, as in the example, date
would be called like this:
date -v+1w -v+1d -v+Tuesday '+%Y-%m-%d'
which returns 2024-05-14
. The -v
option is pretty complicated, and I frankly don’t trust myself to give you a complete explanation of how it works. I suggest you RTFM and play around with it, possibly using the command above as your starting point.
OK, so that’s where we get the yyyy-mm-dd
form of the date. It’s stored in the Local Next Weekday
variable. The next shell script converts it to the long format through
date -jf '%Y-%m-%d' $KMVAR_Local_Next_Weekday +'%B %-e, %Y'
The -jf
combination of options is the common way to convert dates from one format to another. The -f
part has an argument that specifies the input format, and the -j
part says that the input date should not be used to set the computer’s date and time.
Yes, date
can be used to set the date, which sounds insane, but only the superuser can do that. Option letters usually have some relationship to what they do, but -j
has always seemed to me like a weird choice to turn off the date-setting feature. I’ve decided it stands for Jesus, don’t try to change the date!
The third script in the macro is a Python script to turn the cardinal number (1, 2, 3, etc.) stored in Local Number
into the ordinal number (1st, 2nd, 3rd, etc.) that’s used in the prompt of output window. This is an unnecessary bit of flair that I added to the macro because I already had the code to do it.
python:
#!/usr/bin/env python
import os
n = int(os.environ['KMVAR_Local_Number'])
s = ('th', 'st', 'nd', 'rd') + ('th',)*10
v = n%100
if v > 13:
print(f'{n}{s[v%10]}')
else:
print(f'{n}{s[v]}')
The last two steps of the macro are pretty straightforward. They display the output window and handle whatever button the user presses.
One last thing. If you think I misspelled “past” in the title of this post, you need to clear the X-Men out of your head. There’s a reason the examples get the dates of Tuesday afternoons.