94

This problem arose in a different context at work, but I have translated it to pizza.

Suppose you have a circular pizza of radius $R$. Upon this disc, $n$ pepperoni will be distributed completely randomly. All pepperoni have the same radius $r$.

A pepperoni is "free" if it does not overlap any other pepperoni.

You are free to choose $n$.

Suppose you choose a small $n$. The chance that any given pepperoni is free are very large. But $n$ is small so the total number of free pepperoni is small. Suppose you choose a large $n$. The chance that any given pepperoni is free are small. But there are a lot of them.

Clearly, for a given $R$ and $r$, there is some optimal $n$ that maximizes the expected number of free pepperoni. How to find this optimum?

Edit: picking the answer

So it looks like leonbloy's answer given the best approximation in the cases I've looked at:

 r/R          n* by simulation     n_free (sim)     (R/2r)^2
 0.1581       12                   4.5              10
 0.1          29                   10.4             25
 0.01         2550                 929.7            2500

(There's only a few hundred trials in the r=0.01 sim, so 2550 might not be super accurate.) So I'm going to pick it for the answer. I'd like to thank everyone for their contributions, this has been a great learning experience.

Here are a few pictures of a simulation for r/R = 0.1581, n=12: enter image description here

Edit after three answers posted:

I wrote a little simulation. I'll paste the code below so it can be checked (edit: it's been fixed to correctly pick points randomly on a unit disc). I've looked at two three cases so far. First case, r = 0.1581, R = 1, which is roughly p = 0.1 by mzp's notation. At these parameters I got n* = 12 (free pepperoni = 4.52). Arthur's expression did not appear to be maximized here. leonbloy's answer would give 10. I also did r = 0.1, R = 1. I got n* = 29 (free pepperoni = 10.38) in this case. Arthur's expression was not maximized here and leonbloy's answer would give 25. Finally for r = 0.01 I get roughly n*=2400 as shown here:enter image description here

Here's my (ugly) code, now edited to properly pick random points on a disc:

from __future__ import division
import numpy as np
# the radius of the pizza is fixed at 1
r = 0.1   # the radius of the pepperoni
n_to_try = [1,5,10,20,25,27,28,29,30,31,32,33,35]  # the number of pepperoni
trials = 10000# the number of trials (each trial randomly places n pepperoni)

def one_trial():
    # place the pepperoni
    pepperoni_coords = []
    for i in range(n):
        theta = np.random.rand()*np.pi*2 # a number between 0 and 2*pi
        a = np.random.rand()           # a number between 0 and 1
        coord_x = np.sqrt(a) * np.cos(theta) # see http://mathworld.wolfram.com/DiskPointPicking.html
        coord_y = np.sqrt(a) * np.sin(theta)
        pepperoni_coords.append((coord_x, coord_y))

    # how many pepperoni are free?
    num_free_pepperoni = 0
    for i in range(n): # for each pepperoni
        pepperoni_coords_copy = pepperoni_coords[:]  # copy the list so the orig is not changed
        this_pepperoni = pepperoni_coords_copy.pop(i) 
        coord_x_1 = this_pepperoni[0]
        coord_y_1 = this_pepperoni[1]
        this_pepperoni_free = True
        for pep in pepperoni_coords_copy: # check it against every other pepperoni
            coord_x_2 = pep[0]
            coord_y_2 = pep[1]
            distance = np.sqrt((coord_x_1 - coord_x_2)**2 + (coord_y_1 - coord_y_2)**2)
            if distance < 2*r:
                this_pepperoni_free = False
                break
        if this_pepperoni_free:
            num_free_pepperoni += 1

    return num_free_pepperoni

for n in n_to_try:
    results = []
    for i in range(trials):
        results.append(one_trial())
    x = np.average(results)
    print "For pizza radius 1, pepperoni radius", r, ", and number of pepperoni", n, ":"
    print "Over", trials, "trials, the average number of free pepperoni was", x
    print "Arthur's quantity:", x* ((((1-r)/1)**(x-1) - (r/1)) / ((1-r) / 1))
Ben S.
  • 475
  • 1
  • 5
  • 14
  • 4
    So if I get it, the pepperonis are "2D-balls" isn't? – Surb Dec 08 '15 at 16:38
  • 9
    By $n$ pepperoni will be distributed randomly, I presume you mean that they are distributed such that the center of each pepperoni is uniform random on an inner circle of the pizza that has the same center as the pizza but has radius $R-r/2$? That's to say that the pepperoni can't hang over the edge of the pizza. This is the type of problem that seems like it would be hard to do analytically but pretty easy to answer through simulation for a given $R, r$. Are you interested in simulated results, or do you want an analytical answer? – Shane Dec 08 '15 at 16:39
  • 6
    @Shane, I think you meant $R-r$, not $R-r/2$. – Barry Cipra Dec 08 '15 at 17:32
  • @BarryCipra Indeed, you're right. Thanks! – Shane Dec 08 '15 at 17:34
  • 1
    Back-of-the-envelope estimate: for large $n$ or small $r/R$, my money is on the optimal $n$ being the smallest $n$ such that the maximum number of free pepperoni is attainable, namely the sphere packing number, which is asymptotic to $\dfrac{\pi R^2}{2\sqrt 3r^2}$. – Mario Carneiro Dec 08 '15 at 18:03
  • 14
    Crowdsource it: Actually offer free pepperoni this way through a nationwide chain that delivers. Wait a week. Do a web search for "best number of pepperoni to order". – Todd Wilcox Dec 08 '15 at 18:23
  • @Shane Interested in analytical answer. I'm not sure how best to handle the edge...I'd say whatever makes the analysis easier. – Ben S. Dec 08 '15 at 18:48
  • 24
    I would recommend trying to solve this problem for a one-dimensional pizza first. – Jack M Dec 08 '15 at 19:50
  • 3
    The 1D version of this problem has previously been talked about in terms of random parked cars: http://mathworld.wolfram.com/RenyisParkingConstants.html – Ian Dec 08 '15 at 21:25
  • Are the pepperonies supposed to be non-overlapping, or not? – Danu Dec 08 '15 at 23:33
  • Your code is flawed: The generation of points in a circle is biased toward the center because you are choosing radius uniformly. Try using $r_n=R\sqrt{\rm{rand(0,1)}}$ instead. – Mario Carneiro Dec 09 '15 at 00:01
  • @Danu The pepperoni are overlapping, and the question is to find out how many on average happen to not be overlapping. – Mario Carneiro Dec 09 '15 at 00:04
  • @MarioCarneiro wow, massive misreading there on my part: thanks for the response. I'll be deleting these comments soon. – Danu Dec 09 '15 at 00:12
  • Oh, if sometimes they *do* overlap, then this is not quite the same as the parked cars problem. – Ian Dec 09 '15 at 00:36
  • Having worked in the pizza industry before, any chef who made a habit of placing the pepperonis *randomly* would be disciplined or fired. A quality pizza place should take some care to distribute the toppings evenly. – Darrel Hoffman Dec 09 '15 at 14:41
  • @ Mario. D'oh. Thanks. – Ben S. Dec 09 '15 at 15:44
  • By any chance is Buffon Needle problem relevant to this? – Narasimham Dec 09 '15 at 16:24
  • Looks like the beginning of the Monte Carlo method to measure relative areas? – DVD Dec 31 '15 at 00:40

4 Answers4

23

Updated: see below (Update 3)


Here's another approximation. Consider the center of the disks (pepperoni) as an homogeneous point process of density $\lambda = n/A$, where $A=\pi R^2$ is the pizza surface. Let $D$ be nearest neighbour distance from a given center. Then

$$P(D\le d) = 1- \exp(-\lambda \pi d^2)=1- \exp(-n \,d^2/R^2) \tag{1}$$

A pepperoni is free if $D > 2r$. Let $E$ be the expected number of free peperoni.

Then $$E= n\, P(D>2r) = n \exp (-n \,4 \, r^2/R^2) = n \exp(-n \, p)$$ where $p=(2r)^2/R^2$ (same notation as mzp's answer).

The maximum is attained for (ceil or floor of) $n^*=1/p=(R/2r)^2\tag{2}$

Update 1: Formula $(1)$ could be corrected for the border effects, the area near the border would be computed as the intersection of two circles. It looks quite cumbersome, though.

Update 2: In the above, I assumed that the center of the pepperoni could be placed anywhere inside the pizza circle. If that's not the case, if the pepperoni must be fully inside the pizza, then $R$ should be replaced by the "effective radius" $R' = R-r$


Update 3: The Poisson approach is really not necessary. Here's an exact solution

Let $$t = \frac{R}{2r}$$

(Equivalently, think of $t$ as the pizza radius, and assume a pepperoni of radius $1/2$). Assume $t>1$. Let $g(x)$ be the area of a unit circle, at a distance $x$ from the origin, intersected with the circle of radius $t$. Then

$$g(x)=\begin{cases}\pi & {\rm if}& 0\le x \le t-1\\ h(x) & {\rm if}& t-1<x \le t \\ 0 & {\rm elsewhere} \end{cases} \tag{3}$$ where $$h(x)=\cos^{-1}\left(\frac{x^2+1-t^2}{2x}\right)+t^2 \cos^{-1}\left(\frac{x^2+t^2-1}{2xt}\right) -\frac{1}{2}\sqrt{[(x+t)^2-1][1-(t-x)^2]} \tag{4}$$

Here's a graph of $g(x)/\pi$ for $t=5$ enter image description here

Let the random variable $e_i$ be $1$ if the $i$ pepperoni is free, $0$ otherwise. Then

$$E[e_i \mid x] = \left(1- \frac{g(x)}{\pi \, t^2}\right)^{n-1} \tag{5}$$ (remaining pepperoni fall in the free area). And

$$E[e_i] =E[E(e_i \mid x)]= \int_{0}^t \frac{2}{t^2} x \left(1- \frac{g(x)}{\pi \, t^2}\right)^{n-1} dx = \\ =\left(1- \frac{1}{t^2}\right)^{n-1} \left(1- \frac{1}{t}\right)^2 +\frac{2}{t^2} \int_{t-1}^t x \left(1- \frac{h(x)}{\pi\, t^2}\right)^{n-1} dx \tag{6}$$

The objective function (expected number of free pepperoni) is then given by:

$$J(n)=n E[e_i ] \tag{7} $$

This is exact... but (almost?) intractable. However, it can be evaluated numerically [**].

We can also take as approximation $$g(x)=\pi$$ for $0\le x < t$ (neglect border effects) and then it gets simple:

$$E[e_i ] =E[e_i \mid x]= \left(1- \frac{1}{t^2}\right)^{n-1}$$

$$J(n)= n \left(1- \frac{1}{t^2}\right)^{n-1} \tag{8}$$

To maximize, we can write $$\frac{J(n+1)}{J(n)}= \frac{n+1}{n} \left(1- \frac{1}{t^2}\right)=1 $$ which gives

$$ n^{*}= t^2-1 = \frac{R^2}{4 r^2}-1 \tag{9}$$ quite similar to $(2)$.

Notice that as $t \to \infty$, $J(n^{*})/n^{*} \to e^{-1}$, i.e. the proportion of free pepperoni (when using the optimal number) is around $36.7\%$. Also, the "total pepperoni area" is 1/4 of the pizza.

[**] Some Maxima code to evaluate (numerically) the exact solution $(7)$:

h(x,t) :=   acos((x^2+1-t^2)/(2*x))+t^2*acos((x^2-1+t^2)/(2*x*t))
  -sqrt(((x+t)^2-1)*(1-(t-x)^2))/2 $

j(n,t) := n * ( (1-1/t)^2*(1-1/t^2)^(n-1) 
  + (2/t^2) *  quad_qag(x * (1-h(x,t)/(%pi*t^2))^(n-1),x,t-1,t ,3)[1]) $

j0(n,t) := n *(1-1/t^2)^(n-1)$


tt : 1/(2*0.1581) $
j(11,tt);
4.521719308511862
j(12,tt);
4.522913706608645
j(13,tt);
4.494540361913981

tt : 1/(2*0.1) $
j(27,tt);
10.37509984083333
j(28,tt);
10.37692859747294
j(29,tt);
10.36601271146961

fpprintprec: 4$
nn : makelist(n, n, 2, round(tt^2*1.4))$
jnn : makelist(j(n,tt),n,nn) $ 
j0nn : makelist(j0(n,tt),n,nn) $

plot2d([[discrete,nn,jnn],[discrete,nn,j0nn]], 
    [legend,"exact","approx"],[style,[linespoints,1,2]],[xlabel,"n"],  [ylabel,"j(n)"],
[title,concat("t=",tt, "  r/R=",1/(2*tt))],[y,2,tt^2*0.5]);

The first result agrees with the OP simulation, the second is close: I got $n^{*}=28$ instead of $29$. For the third case, I get $n^{*}=2529$ ($j(n)=929.1865331$)

enter image description here

enter image description here

enter image description here

leonbloy
  • 56,395
  • 9
  • 64
  • 139
  • Looks promising. Going to do some simulation. – Ben S. Dec 08 '15 at 19:14
  • This looks pretty good for r = 0.01, R = 1 -- it predicts n* = 2500 which is what I'm getting with simulation, roughly. – Ben S. Dec 09 '15 at 21:04
  • I see you've replaced it, but do you mind explaining the Poisson approximation...how you go straight to $P(D – Ben S. Dec 10 '15 at 19:36
  • The Poisson model assumes, not a fixed number of points (pepperoni), but an average density (expected points per area=density). Then, the probability that $k$ points fall in some area is given by a Poisson distribution (with $\lambda=\rho A$) . The probabilty that $D>d$ equals the probality of zero ocurrences in a disk or radio $d$, which is given by $\exp(-\rho A)$. For more references, see https://en.wikipedia.org/wiki/Poisson_point_process – leonbloy Dec 10 '15 at 20:12
  • Can someone tell me how the 2/t^2 comes up in equation number 6? –  Feb 26 '17 at 07:03
  • @Einsteinthetroll : Let $f(x)$ be the probability (density funcion) of having a distance $x$ to the origin, for a point thrown at random inside a circle or radius $t$. Then $f(x)$ should be proportional to $x$, $f(x)=\alpha x$. From $\int_0^t f(x)=1$ we deduce $\alpha = 2/t^2$. Let me know if anything above is unclear for you. – leonbloy Feb 26 '17 at 14:38
  • I'm sorry, but I also fail to understand the use of the substitution t= R/2r. What is the significance of this? Also, how did you arrive at equation 4 using this substitution? –  Mar 09 '17 at 12:58
  • @Einsteinthetroll The fragment From "Let $g(x)$ be the area" .. to eq $(4)$ (graph included) can (should) be read alone, independently from the rest. Once you get that, the substitution t=R/2r is for simplicity (no need to have two variables) - I chose the 2 factor (you could use another) for more simplicity, so that the $g(x)$ above can be plugged directly into the calculation. – leonbloy Mar 09 '17 at 14:16
14

Let $a \equiv \pi (2r)^2$, $A \equiv \pi R^2$, and $p \equiv \frac{a}{A}$. Denote by $P_i^n$ the probability of having $i$ free pepperoni when $n$ are distributed randomly (according to a uniform distribution) over the pizza. Let $E_n$ denote the expected number of free pepperoni given $n$.

I will assume that the pepperoni can be placed on the pizza as long as their center lies inside it.

  • $n=1$:

    • $P_0^1 = 0$;
    • $P_1^1 = 1$;
    • $E_1= 0\cdot 0 +1\cdot 1 =1$.
  • $n=2$:

    • $P_0^2 = p$, that is, the probability of both pepperoni having their centers within a distance of less then $2r$, in which case they overlap;
    • $P_1^2 = 0$;
    • $P_2^2 = 1- p$;
    • $E_2=p\cdot 0 +0\cdot 1+(1-p)\cdot 2 = 2(1-p) $.
  • $n=3$:

    • $P_0^3 = p^2$;
    • $P_1^3 = C^3_2 p$, since there are $C^3_2$ combinations of how $2$ out of $3$ pepperoni could overlap;
    • $P_2^3 = 0$;
    • $P_3^3 = 1-p^2-C^3_2p$;
    • $E_3=p^2\cdot 0 +C^3_2 p\cdot 1+0\cdot 2 +(1-p^2-C^3_2p)\cdot 3 = 3(1-p^2)- 2C^3_2 p $.
  • $n=4$:

    • $P_0^4 = p^3$;
    • $P_1^4 = C^4_3 p^2$;
    • $P_2^4 = C^4_2 p$;
    • $P_3^4 = 0$;
    • $P_4^4 = 1-p^3-C^4_3p^2-C^4_2p$;
    • $E_4=p^3\cdot 0 +C^4_3 p^2\cdot 1+C^4_2 p \cdot 2+0\cdot 3 +(1-p^3-C^4_3p^2-C^4_2p)\cdot 4 \\ \;\;\;\;= 4(1-p^3)- 3C^4_3 p^2- 2C^4_2 p $.
  • By induction, for $n\ge 2$:

    • $E_n = n(1-p^{n-1})- \sum_{j=1}^{n-2} (n-j)C^n_{n-j}p^{n-1-j}$.

Hence the problem becomes that of solving

$$\max_{n \in\mathbb N} E_n$$

I was not able to solve this in general, but, for instance, if $p=0.1$ then

$$E_1 = 1, \; E_2 = 1.8, \; E_3 = 2.37, \; E_4 = 2.676, \; E_5 = 2.6795, \; E_6 = 2.3369, \; E_7 = 1.5991,\dots$$

So that the optimal number of pepperoni is $n^{*}=5$.

mzp
  • 1,897
  • 2
  • 16
  • 38
  • 1
    With an area ratio of $0.1$, that's either a small pizza or big pepperoni slices! – Brian Tung Dec 08 '15 at 18:45
  • @BrianTung $a$ is actually the area of $4$ pepperoni... – mzp Dec 08 '15 at 18:48
  • Right, gotcha. Still big, but not as big as I imagined. – Brian Tung Dec 08 '15 at 18:49
  • I like this, but I'm doing some simulation, and I'm getting n*=12 for r = 158, R=1000 which is p of about 0.1 – Ben S. Dec 08 '15 at 20:36
  • @BenS. How are you simulating it? – mzp Dec 08 '15 at 20:54
  • Sorry I meant n* = 14. With about 3.5 free pepperoni. – Ben S. Dec 08 '15 at 20:54
  • @ mzp I'll edit my question to include sim code for vetting. – Ben S. Dec 08 '15 at 20:55
  • 1
    You have a problem with the edge of the pizza. If a pepperoni is within $r$ of the edge, then part of the imaginary radius $2r$ circle around that pepperoni extends over the edge. In the case of $r=R$, you get $p=4$ and some of your probabilities are greater than one! – 2012rcampion Dec 08 '15 at 20:58
  • @2012rcampion You are right. This is hard to deal with though. I'm thinking about it, but if you have any suggestions they are welcome. – mzp Dec 08 '15 at 21:04
  • 8
    @2012rcampion This is easily dealt with: just interpret the $R$ used in this answer as $R-r$, that is, shrink the radius of the pizza before the analysis. Thus the variations where the pepperoni are required to lie entirely inside the pizza, just their centers inside the pizza, or simply non-disjoint from the pizza are all equivalent with a small parameter adjustment. – Mario Carneiro Dec 08 '15 at 23:26
  • 1
    $E_n = n \left( 2 - \frac{\left( 1 + \frac{1}{p} \right)^n p^n}{1+p} \right)$. Treating $n$ as a continuous variable and maximizing, we get $n = \frac{W(2 \mathrm{e}(p+1))-1}{\log(p+1)}$ where $W$ is the Lambert function (a.k.a. ProductLog : http://functions.wolfram.com/ElementaryFunctions/ProductLog/ ). So the maximum in the problem occurs at either the floor or ceiling of this number. – Eric Towers Dec 09 '15 at 15:06
  • People like this one, and I can't see what's wrong with it, but I (now) get n* = 12 for r/R = 0.1581 using my little simulation code. – Ben S. Dec 09 '15 at 16:51
  • Why is $P_0^3=p^2$? – A.S. Dec 09 '15 at 19:24
  • This answer is wrong for $n>2$ (apart from ignoring border effects). For example, for $n=3$, $P_0^3 \ne p^2$ : it's wrong to assume that for having no free pepperoni, the second and third must fall into the circle of influence of the first one. To try to compute the probabilities individually is hopeless, but this is not needed, with the linearity of the expectation we get the result (see my answer, which, with the notation used here and ignoring -as here- border effects gives $E_n= n(1-p)^{n-1}$) – leonbloy Dec 19 '15 at 23:42
8

Here is an approximation that uses only areas and no geometry. As long as the pepperonies are nice enough (circular, for instance) and the pizza is big and round enough that the edge doesn't matter, it is a good approximation.

Say there are $p$ pepperonies, they have area $a$. The pizza has area $1$. Then, right before you put down the last pepperoni, $(1-a)^{p-1}$ is the (expected) free area of pizza. The probability therefore that the last pepperoni is free is $\frac{(1-a)^{p-1}-a}{1-a}$.

Since all the pepperonies are equal, this probability is the same for all of them. Let $X_i$ be the random variable given by $1$ if pepperoni number $i$ is free, and $0$ if it is not. Then you want the $p$ that maximises $$ E(X_1+\cdots+X_p)=E(X_1)+\cdots +E(X_p)\\ =E(X_1)+\cdots +E(X_1)=pE(X_1)=p\frac{(1-a)^{p-1}-a}{1-a} $$ which can probably only be found numerically, but if you accept this approximation, then a little numerical analysis shouldn't be to bar.

Arthur
  • 187,016
  • 14
  • 158
  • 288
  • I like how in mathematics we interpret pepperonies as small line segments :D ,btw +1 – Mr. Y Dec 08 '15 at 17:01
  • 1
    This formula can't be right even in the 1d case. One easy way to see it: if $a\gt \frac12$, the probability that any pepperoni is free must be zero. – Steven Stadnicki Dec 08 '15 at 17:07
  • 1
    I don't buy this argument. What about "fragmentation" of the free area? Even if the pizza and pepperoni are line segments, the probability that a line segment of length $a$ fits freely between the others is the same as if the placed segment was a point and the others were line segments of twice the length, making the factor $(1-2a)^{p-1}$ instead of $(1-a)^{p-1}$, which is more than an edge effect. In 2D the pepperoni act as if they have 4 times the area since the radius doubles. – Mario Carneiro Dec 08 '15 at 17:16
  • @StevenStadnicki It should be better now. – Arthur Dec 08 '15 at 17:45
  • @Mario it does seem that for any given point, once $n$ pepperoni of area $a$ have been placed, the odds that it is in none of the pepperoni are $(1-a)^n$, since it's just the chance it's not in the first times the chance it's not in the second, and so on – Ben S. Dec 08 '15 at 19:03
  • @Arthur. This is very clever. – Ben S. Dec 08 '15 at 19:06
  • Ben: the problem with this argument is that it treats the piece being placed as a point rather than having any size itself. In the $n=2$ case, for instance, it suggests a probability of $1-a$ where the real value is $1-2a$ (as Mario notes). – Steven Stadnicki Dec 08 '15 at 19:57
  • @StevenStadnicki No, the problem is that it doesn't take fragmentation into account, e.g. the fact that the shape of the free area becomes very irregular after the first few pepperonies (so in a sense it is an edge problem). – Arthur Dec 08 '15 at 19:59
  • This approach will overestimate the probability of non-overlap, because it is quite possible to create a region of the pizza which is not covered but nevertheless no pepperonis can fit. I think that for large numbers of pepperonis the error will actually be quite considerable. There is a related 1D problem with cars parked randomly along a street where you have the same effect (cars parked less than a car length apart displace their own length as well as the length in between them). – Ian Dec 08 '15 at 21:17
  • @Ian As I said, it doesn't take edges /fragmentation into account, and by the time you've put down $1/5a$ pepperonies, say, the edge of the free area is quite complicated compared to what we started with. – Arthur Dec 08 '15 at 21:21
8

A First Approximation

Let $p$ be the probability that a pepperoni is not in conflict with one randomly placed pepperoni, and $P$ the probability that a pepperoni is free.

The exact expression for $p$ is the area suitable for another pepperoni over the total area where pepperoni can be placed :

$$ p = \frac{\pi (R-r)^2 - A}{\pi (R-r)^2} $$

Where $A$ is the area of the portion of a circle of radius $2r$ centered at the pepperoni center that is inside the area where pepperoni can be placed. I could not find an analytic formula for $A$ when the pepperoni is close to the border. Instead, I use the approximation that the pepperoni always covers the same area, regardless of where it is placed.

$$A \approx \pi (2r)^2$$

And we have :

$$ p = \frac{\pi (R-r)^2 - \pi (2r)^2}{\pi (R-r)^2} = \frac{(R-r)^2 - (2r)^2}{(R-r)^2} $$

This approximation is good when the radius of the pizza is large compared to the radius of a pepperoni.

Now, the probability that pepperoni $i$ is free when $n$ pepperoni are placed:

$$P = p^{n-1} $$

And the expected number of free pepperoni is :

$$E_n = n p^{n-1}$$

This function looks like this.

To obtain the maximum, we set the derivative equal to 0 :

$$p^{n-1} + np^{n-1} \ln(p) = 0 \implies n = \frac{-1}{ \ln(p)}$$

The maximum is either the ceiling or the floor of this value.

$$E_n = \max\left\{\left\lfloor \frac{-1}{ \ln(p)} \right\rfloor p^{\lfloor \frac{-1}{ \ln(p)} \rfloor - 1}, \left\lceil \frac{-1}{ \ln(p)} \right\rceil p^{\lceil \frac{-1}{ \ln(p)}\rceil - 1} \right\}$$

Now some numbers : If $R= 30$cm, $r=2$cm, we have $p\approx 0.98$. Then :

$$ E_{max} = \max\{48 \times 0.98^{48-1}, 49 \times 0.98^{49-1}\}\approx \max\{18.1678, 18.1669\} = \boxed{18.1678 }$$

Edit : A Better Approximation of A

I found a better way to approximate $A$, the average area in which another pepperoni cannot be placed. It is :

$$ A(r')= \left\{ \begin{array}{cc} \pi (2r)^2 & \mbox{ if } r' < R-3r \\ \frac{\pi (2r)^2}{2} & \mbox{ if } R-3r < r' < R-r \end{array} \right. $$

Where $r'$ is the distance between the center of the pizza and the center of the pepperoni. I think this formula desserves a bit of explaining. When the pepperoni is at distance less than $R-3r$ from the center of the pizza, all the points in a $2r$ radius are not suitable for a pepperoni. If the distance is larger than $R-3r$, some of the points in the circle of $2r$ radius are outside the zone where pepperoni can be placed (The circle of $R-r$ radius).When a pepperoni is inside that region, we consider that the area not suitable for another pepperoni is on average half the area of the circle. This correspond to making the approximation that the border of the pizza is flat. Again, for a large pizza, this approximation becomes more negligible.

Now, the average for $A$ becomes :

$$ \begin{align} A =& \frac{\int\limits_{0}^{2\pi} \int\limits_{0}^{R-r} A(r') r' dr' d\theta }{\int\limits_{0}^{2\pi} \int\limits_{0}^{R-r} r' dr' d\theta} \\ =& \frac{2\pi \left[\int\limits_{0}^{R-3r} \pi(2r)^2 r' dr' + \int\limits_{R-3r}^{R-r} \frac{\pi(2r)^2}{2} r' dr'\right]}{\pi (R-r)^2} \\ =& \frac{2\pi r^2}{(R-r)^2}\left[ (R-3r)^2 + (R-r)^2 \right] \end{align} $$

And the probability $p$ is :

$$ \begin{align} p =& \frac{\pi(R-r)^2 - \frac{2\pi r^2}{(R-r)^2}\left[ (R-3r)^2 + (R-r)^2 \right]}{\pi(R-r)^2} \\ =& 1-\frac{2r}{(R-r)^4}\left[ (R-3r)^2 + (R-r)^2 \right] \end{align} $$

And the rest of the equations stay unchanged.

Now, when $r/R = 0.1$, I get a total of 112 pepperoni placed, with an expected value of 31.74.

For $r/R = 0.01$, I get 2449 pepperoni placed, with an expected value of 901.58.

fredq
  • 920
  • 5
  • 8
  • I like this but in simulation I get $E_max$ of at least 22 when I set r = (1/15), R = 1 – Ben S. Dec 09 '15 at 17:11
  • I think it is because the formula for $p$ overestimate the actual probability. I would think as the ratio $r/R$ decreases,the method becomes more exact. – fredq Dec 09 '15 at 19:42
  • What do you get for R = 1, r = 0.01? I don't know what those L-shaped brackets mean. – Ben S. Dec 09 '15 at 20:09
  • @BenS. I get an expected value of 901.58. The L-shaped bracket are for the floor and ceiling functions. – fredq Dec 09 '15 at 20:29
  • Could someone please explain to me how to first formula for p was obtained? –  Jan 21 '17 at 04:27