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

# Long-run Supply

The short run the supply curve for an industry of price-taking 
firms is the horizontal sum of a fixed number of firms' supply 
curves. 

In contrast, the number of firms can vary with the price in the long 
run, and the number of firms must be determined. We begin analysis
of the long run by assuming that all firms are identical and the firms' 
common cost curves do not depend on the number of firms in the 
industry. Both assumptions are relaxed as we proceed. 

## A Constant-Cost Industry

This section develops the supply curve for a "constant-cost"
industry that consists of identical firms. The term "constant-cost" 
means that no firm's cost curve is affected by the number
or size of other firms in the industry. 

The first cell establishes the parameters of the long-run
cost curve for each firm in this industry, ltc = a + b*x^2. We specify 
a minimum long-run average cost, lac0, and a quantity, x0, at 
which that average cost is realized.

[ltc:a+b*x^2, lmc:diff(ltc,x)]; [lac0,x0]:[30,50];

For this simple function, the marginal cost, 2*b*x, equals the lac,
at the minimum lac value, lac0. Thus, b0 = lac0/(2*x0). Once b0 is 
determined, a0 can be calculated from the fact that, at x = x0, 
ltc = x0*lac0. Equivalently, as below, Maxima can solve for the 
values of a and b simultaneously.

solve([(a+b*x0^2)/x0=lac0,2*b*x0=lac0],[a,b])$
[a0,b0]:[rhs(%[1][1]), rhs(%[1][2]) ]$
matrix(["a0 =",a0],["b0 =",b0]);

Tracing the move between long-run equilibrium requires looking at 
the short-run adjustment, which requires a short-run cost function.
We a cubic function to illustrate the effects of a change. 

[stc:d+e*x^3, smc:diff(stc,x)];

In full equilibrium, each firm operates at the minimum point on
its ltc, so it has chosen the optimal short-run size. This implies
that the lac = sac, given the right size. Also, the ltc and stc 
 curves have the same slope, which equals lac0. First solve
for e using 3*e*x^2 =lac0. Then solve for d0. (Or solve for 
the two simultaneously).  

[e0 :lac0/(3*x0^2), d0:lac0*x0-e0*x0^3]$
matrix(["d0","e0"],[d0,e0]);

We now have expressions for the four relevant per-unit cost curves.

[lac(x,a0,b0):=''(a0/x+b0*x),lmc(x,b0):=''(2*b0*x)];
[sac(x,d0,e0):=''(d0/x+e0*x^2), smc(x,e0):=''(3*e0*x^2)];

### Firm Supply

The next cell creates long-run and short-run supply curves for
the firm represented above. The "if then else" statement accounts
for the fact that for p < lac0, the firm would exit in the long run.
In the short-run a firm would have to cover variable costs, but for
the function used here, average variable cost (e0*x^2) is always
less than marginal cost (3*e0*x^2). This firm would never shut 
down in the short run (this, of course, is not generally true).

xl(p):=''(if p < lac0 then 0 else p/(2*b0))$
xs(p):=''(sqrt(p/(3*e0)))$  plist:makelist(10*i,i,0,8)$ 
xslist:float(xs(plist))$    xllist:float(map(xl,plist))$
names:matrix(["p, dollars/unit)","x,short run", 
"x, long run"])$   numbers:transpose(
matrix(plist,xslist,xllist))$    addrow(names,numbers);

The figure below shows these two supply curves. 

wxdraw2d(user_preamble="set key bottom",
yrange=[0, 2*lac0],xlabel="x",ylabel="$ per unit", 
key="sac",explicit(sac(x,d0,e0),x,0,2*x0),line_width=2,
key="lac",explicit(lac(x,a0,b0),x,0,2*x0),color=gray40,
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]]) )$

### Long-run Equilibrium

The graph below shows why the long-run equilibrium price
must be 30. Any other price would induce either entry or exit
of firms. Thus, the height of the supply curve is lac0 = 30 for
all values of industry output. 

firmsupply:gr2d(user_preamble="set key bottom",
 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,
 line_width=3, key=  "relevant lmc",explicit(lmc(x,b0),x,x0,2*x0),
 line_type=dots, points_joined=true,key="",points([[0,lac0 ], [x0,lac0] ]))$
industrysupply : gr2d(xlabel="Industry Quantity",ylabel=
"$ per unit",yrange=[0, 2*lac0], title = "Industry",xtics=2000,
 key="LR Supply",line_width=2, explicit(lac0, x, 0, 100*x0) )$
 wxdraw(firmsupply,industrysupply,columns = 2,
  dimensions=[540,400])$

### Long-run and Short-run Equilibria

Given the two conditions that unlie this analysis, the development of
the logic of the movement from one long-run equilibrium to another
requires that a market demand curve be added to the model. For the 
other cases, developed below, we can develop the supply relationships
without reference to demand.

The next cell begins at full equilibrium. In addition to specifying a 
number of firms and thereby a supply curve, it specifies a demand
curve consistent with p = lac0 at X = n0*x0, where X is the 
industry quantity.

The last output line, produced by the last three commands, 
calculates n0, given the equilibrium condition. The calculated
value equals the stipulated value, as a check of the reasoning
that generated the equilibrium condition.

n0:200$    Xeq0:n0*x0$  
Xs(p,n):=''(n*xs(p));  
Xl(p,n):=''(n*xl(p));   
Xd(p,Xeq,T):=Xeq+T-(5000/lac0)*p;

solve(Xd(lac0,Xeq0,5000)-Xs(lac0,n),n)$  
n0calc:float(rhs(%[1]))$  
matrix(["Check: n0calc = ",float(n0calc)]);

Changing T from 5000 to 15000 shifts the demand curve rightward.
To trace the effects of this demand increase, we first determine 
the new price, p1, in the short run. The price rises to 63.031,
and the quantity increases from 10000 to 14495 units. 
This is a short-run equilibrium because firms cannot enter. 

To find the new long-run equilibrium number of firms, 
set demand equal to the post-entry short-run supply with 
the price constrained to lac0, but with n unknown. 

In this special case, and only in this special case}, the long-run 
supply curve determines the price, and the demand curve 
determines the quantity.

p1:find_root(Xd(p,Xeq0,15000)-Xs(p,n0),p,lac0,10*lac0);
solve(Xd(lac0,Xeq0,15000)-Xs(lac0,n),n)$  n1:float(rhs(%[1]));

matrix(["No. Firms", "Price", "Xs", "Xd"],
[n0,lac0,float(Xs(lac0, n0)),Xd(lac0,Xeq0,5000)],   
[n0,p1,float(Xs(p1,n0)),Xd(p1,Xeq0,15000)],
[n1,lac0,float(Xs(lac0,n1)),Xd(lac0,Xeq0,15000)]);

To draw a graph of the demand and supply curves, we 
we express the demand price  in terms of X. 

solve(Xd(p,Xeq,T)-X,p)$ p(X,Xeq,T):=''(rhs(%[1]));

In the next graph, the initial demand curve intersects 
the long-run supply curve at X = 10000, as does the initial 
short-run supply curve. The demand shift raises the price and 
quantity.  At p = 63.031, each firm produces 14495/200 = 72.475
units.

Profit leads to the entry of 200 additional firms, so the 
short-run supply curve shifts rightward. Once again each firm produces 
x = 50. The values in the points( ) commands are from above.

wxdraw2d( yrange=[0,2*p(0,Xeq0,1500)],
 xlabel="Industry Quantity", ylabel="$ per unit",
 line_width = 2, key="Initial Short-run Supply",
 explicit(smc(X/n0,e0),X,0,25000), color=red,
 key="New Short-run Supply",
 explicit(smc(X/n1,e0),X,0,25000),
 line_width=2, color= black,key="Initial Demand",
 explicit(p(X, Xeq0,5000),X,0,25000),
 key="New Demand",color=green,
 explicit(p(X, Xeq0,15000),X,0,25000),line_width=3,
 color=brown,key="Long-run supply curve",
 explicit(lac0,x,0,25000), points_joined=true,key="",
 line_type=dots,color=black,line_width=1,
 points([Xeq0,Xeq0],[0,lac0]),
 points([0,Xs(p1,n0)],[p1,p1]),
 points([Xs(p1,n0),Xs(p1,n0)],[0,p1]),
 points([Xs(lac0,n1),Xs(lac0,n1)],[0,lac0]),
 dimensions=[480,480])$