I don’t like nuts. I really don’t like them in brownies. What I want is a way to tell if a particular brownie has nuts in it just by looking at it. That’s what this post is all about.

If you see that all four of the cut sides of a brownie don’t show any nuts, what is the probability that there are no nuts inside? To get to that question, first I wanted to find what the relationship was between the percentage of the side area with nuts and the percentage of the volume with nuts. The latter you can basically get from recipes. The former is the evidence you have at the snack table.

**Theoretical argument**

I asked some math buddies of mine this question and here’s one of the answers I got.

Assume that the density of nuts is uniform throughout the brownie. Let that density be . Then the volume that the nuts take up is given by:

So what would the area of nut-like-substance be on a particular slice, say in the x-z plane:

The whole brownie volume would be the same integrals without alpha (ie, a density of one).

From this you can see that since is in each integral in the same way, the ratio of the percentages that I’m interested in is one. In other words, if you see 20% of the surface covered with nuts, then 20% of the interior is filled with nuts.

**Brute force attempt **

First I should give a hat tip to my friend, John Burk. I asked the original question on twitter and he challenged me to find a solution using a brute force probability answer in Mathematica. I’ve obliged.

Ok, here’s my brownie:

Here’s the Mathematica command to determine the random locations and sizes:

nuts = Table[{RandomReal[{-1, 1}, {3}], RandomReal[{0.01, .2}]}, {10}];

The first RandomReal determines the location and the second one the size. I came to those numbers because they made my brownie seem realistic. They’re easy to change, of course.

Next comes figuring out how to do the calculations for a slice. Basically I made a function that took a point on the blade and a vector normal to the blade. I ended up only choosing normals that were in the x- or y-direction because it made things easy but also because, since the nuts were placed randomly, I don’t need further randomness in my cuts (please let me know if I’m wrong about that).

With the plane of the cut defined, I needed a function that figured if any of the nuts were cut and what area they would represent on the slice. This took a little geometry but I finally came up with this:

bladehit[{loc_, r_}, {norm_, x_}] := (vec = x - loc; dist = norm.vec/Sqrt[norm.norm]; If[Abs[dist] < r, \[Pi] (r^2 - dist^2), 0])

(it looks much better in Mathematica, by the way). The first vec variable holds the vector that goes from the center of the nut to the given point on a plane. The dist variable then finds the distance from the plane to the center of the nut by using the dot product. Essentially the normal vector dotted into vec should give the length of vec that is parallel to norm and hence the distance (note that I make sure to normalize the norm vector). Finally I find whether that distance is less than the radius and find the area of the circle you get when slicing the nut at that location.

With those tools in place, I’m ready to do a bunch of slicing and counting. For each brownie, I sliced it 200 times. For each slice, I found the ratio of (the % of the slice that’s made up of nut) to (the volume of the brownie that’s made up of nuts). I then averaged those 200 slices to get an average for that brownie. Then I did it for 1000 brownies and made this histogram:

You can see that the most popular result was that the ratio is one, or that if you get, say, 20% of the surface with a nut, you’ve got 20% of the volume made up of nuts. It’s interesting that this particular way of averaging the slices of a brownie and then averaging those averages over 1000 brownies yields a one-sided histogram.

**But what about the probability?**

Now I’m in a position to see what the chances are that, if you see no nuts, there aren’t any inside. To do this, I did the same 200 slices into 1000 brownies and tabulated the chances that a slice saw no nuts. It came out to be just over 30%. In other words, if you have a brownie with this distribution of nuts in it, a single slice with not nuts showing will happen ~1/3 of the time. That doesn’t seem very helpful, as I was hoping that if you don’t see nuts, there’s a good chance, as opposed to this somewhat decent chance, that there’s no nuts inside.

Ah, but wait, there’s more! When you examine a brownie, you can usually see 4 sliced sides. So I should be able to take that 30% number and raise it to the fourth power for a decent estimate of the chances of finding a brownie with no nuts showing that still has nuts inside. If you do that, you get an answer around 1%. That’s not bad, I’ll take my chances with that.

As usual, I’m sure there are better ways to do this. I’m happy to take suggestions below. Let me just end by saying, once again, that the brute force way is fun, and doable way to answer questions like these.

I love nuts in brownies. I also love this problem.

I haven’t had time to read this in detail yet, but I am looking forward to it. I love that you are putting up these problems on your blog.

Bret