load(draw)$ 
set_draw_defaults( draw_realpart=false)$
 fpprintprec:5$ ratprint:false$kill(all)$

# Long-run Supply

## A Constant-Cost Industry

## A Variable Cost Industry

This section retains these parameter values from the previous section.

[lac0,x0,a0,b0,d0,e0]:[30,50,750,0.3,1000,1/250];

## An Industry with Non-identical Firms}

This section allows each firm to have a unique cost function. The firms are
ranked from least-cost (i = 1) to highest cost (i = n), where i is a counter and
n is the number of firms in the industry. 

The number of firms, imax, is the number that results in zero profits for the 
imax-th firm (i = imax), given the product price. Strictly speaking, we restrict
imax to integer values, so the marginal firm (i = imax) can earn a slight profit, 
but not enough to attract the higher-cost (imax+1)-th firm. 

declare(%alpha, integer)$ assume(p>0)$
a0*i^%alpha/x0+b0*i^%alpha*x0;solve(%=p,i)$ 
imax(p,%alpha):=''(floor(rhs(%[1])));

The next cell shows that p = 100 results in an industry that consists 
of 123 firm.

p0:100$   imax0: imax(p0, 0.25);

To extract a firm's supply curve, set its marginal cost equal to p.
Each firm's output is a function of p, i, alpha. Each firm's output 
differs from those of the other firms. These are long-run supply
curves.

x_i(p,i,%alpha):= ''(rhs(solve(2*b0*i^%alpha*x-p,x)[1]));

If p = p0 = 100, the least cost firm produces over three times as much
as the marginal (i = 123) firm.

[x_1:x_i(p0,1,0.25), x_imax0:x_i(p0,imax0,0.25)];

The graph below shows the average cost and marginal 
cost firms for Firm 1 and Firm 123. Each firm's supply 
curve is the segment of the marginal cost curve that lies
above its average cost curve.

wxdraw2d(dimensions=[480,480],
yrange = [0,  2*b0*imax0^0.25*(3*x0)],
xlabel = "Output Levels", ylabel = "$ per unit",
key="p0", explicit(p0, x, 0, 3*x0),
line_width = 2, key = "Average Cost Curves",
explicit(a0/x + b0*x, x, 0, 3*x0),key="",
explicit(a0*imax0^0.25/x+b0*imax0^0.25*x,x,0,3*x0),
color="red", key = "Marginal Cost Curves",
explicit(2*b0*x, x, 0, 3*x0), key = "",
explicit(2*b0*imax0^0.25*x, x, 0, 3*x0) )$

### Profits, Rents, and Shifting Cost Curves

All firms but Firm 123 in the industry depicted above earn positive profits. Whether
these profits accrue to the firms' owners or to owners of specialized resources 
used by the firm depends on the peculiarities of each firm's setting.

### Industry Supply

The cell below shows the number of firms in this industry at each of a 
set of prices. It also shows the industry output X. The average amount
produced by each firm is reported. The table could be amended to 
show the output for individual firms, say the lowest-cost firm and the
marginal firm.

pList: makelist(lac0*(1+(j-1)/10),j,1, 11)$
imaxList:imax(pList,0.25)$

X_list: makelist(
   sum(x_i(pList[j],i,0.25),i,1,imaxList[j]),
   j,1,11)$  

perfirmxList: X_list/imaxList$

numbers: transpose(matrix(pList,imaxList,X_list,
   perfirmxList))$  names:matrix(["Price","No. of Firms",
"Industry X","Avg. Firm x"])$  addrow(names,numbers);

For p = 42, p = 45 and p = 57, we compare the output of 
the median firm with the average x values above.

[x_i(42,2,0.25),x_i(45,3,0.25),x_i(57,7,0.25)];

The notes above say that the lowest-cost and highest-cost firms' outputs 
could be listed. These appear below. Except for the fact that we round the
number of firms, the marginal firm would always produce x_imax = 50. 

matrix(x_i(pList,1,0.25),
       x_i(pList,imaxList,0.25));

Each firm's supply curve exhibits unitary elasticity, so doubling the price should 
double the lowest-cost firm's output, from x = 50 to x = 100. The result below shows
that it does.  It also shows the output for Firm 8 and for Firm 16, the
highest-cost firm at the highest price.

matrix(["Firm1's x", "Firm8's x", "Firm16's x"],
[x_i(pList[11],1,0.25),x_i(pList[11],8,0.25),
x_i(pList[11],16,0.25)]);

The graph below shows the 11 points on the industry supply curve that 
appear in the table above.  Even though each firm's supply
curve has an elasticity of 1.0, the industry supply curve becomes quite
elastic as price increases. 

wxdraw2d(user_preamble="set key bottom",
 yrange=[0,1.5*pList[11]],
 ylabel="$ per unit",xlabel="Industry Quantity, X",
 line_width=2,key="Industry Supply Curve",
 points_joined=true,points(X_list,pList))$

### Least-cost Production in a Competitive Industry

The text argues that the condition for efficiency in the long-run is not that
each firm reach the minimum point on its lac. Rather the condition is two-fold:
Output is allocated among firms so that mc is the same in each firm, and
The average cost of the marginal firm is (approximately, due to integers) 
equal to the marginal cost of all other firms. 

In the special case reproduced below, in which all firms are identical, then
the two conditions above collapse into the single condition that every 
firm produces at the minimum point on its long-run total cost curve.

firmsupply: gr2d(user_preamble="set key bottom right",
yrange = [0, 2*lac0], xlabel="Firm Quantity",
ylabel = "$ per unit", key = "sac", 
title = "Firm",explicit(sac(x, d0, e0), x, 0, 2*x0),
line_width=2, key="lac",explicit(lac(x,a0,b0),x,0,2*x0),
color = gray, key="smc",explicit(smc(x,e0),x,0,2*x0),
color = black, key = "lmc", 
explicit(lmc(x,b0),x,x0,2*x0),line_type=dots, 
points_joined=true,points([ [0,lac0],[x0,lac0 ]]))$
industrysupply : gr2d(xlabel = "Industry Quantity", 
yrange=[0,2*lac0],ylabel="$ per unit",title="Industry",
key = "LR Supply", xtics={100*x0/2, 100*x0},
line_width = 2, explicit(lac0, x, 0, 100*x0) )$
wxdraw(firmsupply, industrysupply, columns = 2,
 dimensions=[540,400])$