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

# Nonlinear Pricing: 
    Capturing Consumer Surplus

The workbook deals with "nonlinear pricing" -- pricing when the firm
can either charge different prices for different units of a good or 
can charge a fee in addition to the per-unit price.

## Review and Introduction

## First-degree Price Discrimination

The cell below shows willingness to pay for each of ten units of a good. 
The willingness to pay wtp function, wtp, exhibits constant elasticity. 

The text shows that a price of (slightly less than) $22.361 results in
maximum profit, with x = 5, if the firm must charge a single price for
each unit.

xlist: makelist(i,i,1,10)$  wtplist: 50.0/xlist^0.5$
trlist:xlist*wtplist$       tclist:7*xlist+0.5*xlist^2$
makelist(trlist[i]-trlist[i-1],i,2,10)$   mrlist: 
 append(["---"],%)$ makelist(tclist[i]-tclist[i-1],i,2,10)$   
mclist: append([tclist[1]],%)$  Plist: trlist-tclist$
names: matrix(["x","wtp","tr","tc","profit","mr","mc"])$
numbers: matrix(xlist,wtplist,trlist,tclist,Plist,mrlist,
 mclist)$  addrow(names, numbers);

From the producer's viewpoint the solution above leaves two
possible source of gain: Consumer Surplus and DWL. A more
complex pricing scheme might allow appropriation of one or both
of these.

P0 : (wtplist[5]*5 - tclist[5])$
cs0: sum(wtplist[i] - wtplist[5], i, 1, 5)$
dwl0 : sum(wtplist[i] - mclist[i], i, 6, 9)$ 
matrix(["Profit, single price","Consumer Surplus","DWL"],
  [P0,cs0,dwl0]);

If the seller can charge wtp for each unit, then its marginal
revenue equals the marginal price. Therefore, the firm produces
the quantity at which the price of the marginal unit equals 
mc. In the case above p > mc for all but the 10th unit, so 
x = 9 yields maximum profit. Also, it is the efficient unit,
so DWL = 0. The output below shows that the firm's profit now
equals the sum of its profit under the single-price regime, 
Consumer Surplus, and Deadweight Loss.

[P1:sum((wtplist[i]-mclist[i]),i,1,9),P0+cs0+dwl0];

One alternative to selling each unit to a seller at a different price is to use a 
"two-part tariff," with which the buyer is charged one price for the privilege of 
buying the product and may choose how many units to buy at a seller-determined p. 

In the illustration above, the profit-maximizing seller would set p = $16.667, 
approximately the marginal cost of the ninth unit. The next cell shows, the entry fee, 
A0, is $85.239, and the profit level is $131.74, as above.

A0: sum(wtplist[i] - wtplist[9], i, 1, 9)$
P2 : A0 + sum(wtplist[9] - mclist[i], i, 1, 9)$
matrix(["Entry Fee", "Profit"], [A0, P2]);

### A Special Case: Identical Buyers

Suppose a seller's product faces the demand curves of twelve
identical buyers. The next cell shows the market for buyers whose 
demand curves exhibit a constant elasticity of -2.0.  Each buyer's 
quantity is x, and total quantity is X = 12*x.  

kill(x,X,pd,mr,mc,X0,p0,Xe0,pe0)$ x:1000*p^-2.0$ X:12*x$
matrix(["Individual Demand","Market Demand"],[x,X]);

The next cell contains expressions for inverse market demand
and marginal revenue, along with an expression for a linear
marginal cost curve. Applying find_root( ) determines the 
profit-maximizing quantity given that a single price applies, X0, 
the efficient quantity, Xe0, and the corresponding prices.

pd:(Xs/12000)^-0.5$   mr:.5*pd$  mc:2+0.5*Xs$
X0: find_root(mr - mc, Xs, 0.01, 200)$
p0 : subst(Xs = X0,pd)$  Xe0:find_root(pd-mc,Xs,0.01,200)$
pe0 : subst(Xs = Xe0,pd)$      matrix(["Demand","mr","mc",
"X0","p0","Xe0","pe0"],[pd,mr,mc,X0,p0,Xe0,pe0]);

The graph below shows the market demand curve,
mr, and mc,along with an individual demand curve.  

wxdraw2d( yrange=[0,1.5*p0],xlabel="Quantity",
 ytics = {p0,pe0},
 ylabel ="$ per unit",line_type=dots,points_joined=true,
 points([[0,pe0],[Xe0,pe0], [Xe0,0]]),
 points([[X0,0],[X0,p0],[0,p0]]),line_type=solid,
 line_width=2,key= "Market Demand",
 explicit(pd, Xs, 0.01, 1.1*Xe0),key = "mr",
 color=black,explicit(mr,Xs,0.01,1.1*Xe0), 
 color=red, key="mc",
 explicit(mc,Xs,0.01,1.1*Xe0), color=gray,
 key="Individual Demand",
 explicit((xd/1000)^-0.5,xd,0.01,1.1*Xe0),
 dimensions=[640,480])$

If p = p0, then each consumer's surplus is the area between the individual 
demand curve and p0, over the range from x = 0 to the x = X0/12 = 1.6924.
Each individual can be charged an entry fee equal to that area.

With two-part pricing, p = p0 will no longer yield maximum profits. In 
fact, with identical buyers, the firm maximizes profits by charging 
p = pe0 = $18.8629.

The cell below shows the profits given the two prices above. 

P0:float(integrate(mr-mc,Xs,10^-20,X0))$
A0:float(integrate((xd/1000)^-0.5-pe0,xd,10^-20,Xe0/12))$
P1:float(12*A0 + integrate(pe0 - mc, Xs, 10^-20, X0))$
matrix(["P0", "Fee", "P1"], [P0, A0, P1]);

### Heterogeneous Buyers and Pricing Schedules

The next cell extends the analysis to a case in which two types
of buyers inhabit the market. For simplicity, we use linear 
demand curves. The fraction of the buyers of Type A is m; 1 - m
is the fraction of buyers that are of Type B.

kill(all)$  [xa(pa,a):=a-pa, pa(xa,a) := a-xa, 
mra(xa,a):=a-2*xa];[xb(pb,b):=b-pb,pb(xb,b):=b-xb,
  mrb(xb,b):=b-2*xb];      mc : 1$  P(xa,xb,A,m,a,b):=
  m*(pa(xa,a)-mc)*xa +(1-m)*(pb(xb,b)-mc)*xb+A ;

The two demand curves appear below.

[a0,b0]:[10,20]$  wxdraw2d(yrange=[0,1+b0],xlabel="x",
 ylabel="$ per unit", line_width=2,
 key="Demand, A",explicit(pa(xa,a0),xa,0,b0+1),
 color=black,key="Demand,B", explicit(pb(xb,b0),xb,0,b0+1),
 color=red, key="mc",explicit(mc,x,0,b0+1)  )$

If the seller could separate consumers into two markets and charge a 
single price in each market, the profit-maximizing prices would be $4.5 and 
$9.5. with associated quantities of $5.5*m and $10.5*(1 - m) units.  
The profit levels in the two markets would be $20.25*m and $90.25*(1-m). 
For the moment, however, we assume that these markets are not separable. 

matrix([ ["pa0","pb0"] ,["xa0","xb0"],"Profit"],
[[xa0, xb0]:[find_root(mra(xa,a0)-mc,xa,0,a0),find_root(
  mrb(xb, b0)-mc,xb,0,b0)],    [pa0, pb0]:
  [pa(qa0,a0),pb(qb0,b0)], P0:P(xa0,xb0,0.0,m,a0,b0)]);

If the seller can both separate the markets and charge the profit-maximizing
entry fee in each, then it would appropriate the consumers' surplus by setting 
the price at p = $1 and charging entry fees of $40.5 and $180.5, so that its 
profit is $40.5*m + $180.5*(1-m). Again, no deadweight loss would occur.

40.5*m + 180.5*(1-m);

More likely, the firm cannot separate its markets, but can engage
in two-part pricing. Suppose that it sets an entry fee and a price. 

Consider two extremes. If p = mc and the entry fee equals Type A consumers'
surplus, the firm gets $(40.5*m + 40.5*(1-m)) = $40.5 in profits. At the other
extreme setting the entry fee equal to the consumer surplus for Type B consumers
results in a profit of $180.5*(1-m), because the Type A consumers buy nothing.

The next cell confirms that for m < 0.776, the second option is the better
of the two.

[xae, xbe] : [xa(mc, a0), xb(mc, b0)]$
A0: float(integrate(pa(xa, a0)-mc, xa, 0, xae))$
B0: float(integrate(pb(xb, b0) -mc, xb, 0, xbe))$
m0: find_root(A0 - (1-m)*B0, m, 0, 1)$
matrix(["Quantities","Per-unit profits and Critical m"],
[ [xae,xbe],[A0,B0,m0]]);

When it serves both types of buyers, the firm must take into account
the effect of the price on the entry fee. We determine the price by expressing
the entry fee A in terms of the price. This expression is A2.

Inserting expression A2 into the P( ) function and evaluating that functions
derivative with respect to p yield the 2nd and third output items. If m = 0.776,
then p = 3.24 and A = 22.849 yield maximum profits. Higher m values dictate lower
prices and higher entry fees. In the limiting case, m = 1, p = mc = 1, and A = 40.5.

A2:integrate(pa(xa,a0)-p2,xa,0,10-p2);
P(xa(p2,a0),xb(p2,b0),A2,m,a0,b0);  diff(%,p2);
subst(0.776,m,solve(%, p2));  p2max:rhs(%[1])$  
A2min:subst(p2max,p2, A2);

Quantity Discounts

We continue with the same demand functions as above, but the profit 
function now changes. The firm will set a small-quantity price that is 
the only price that Type A buyers pay. Type B buyers pay the initial 
price for part of the units that they buy and a lower price per additional unit. 

Solving this maximization problem involves taking partial derivatives
of the profit function with respect to the the price. The result is
a pair of linear equations in terms of p1, p2, and m. The firm controls 
the two prices.

P2p : (p1 - mc)*(m*xa(p1, a0) + (1 -m)*xb(p1, b0)) + 
        (p2 - mc)*(1 - m)*(xb(p2,b0) - xb(p1, b0));
[dP2p1,dP2p2]: [ratsimp(diff(P2p, p1)),
ratsimp(diff(P2p, p2))];

The next cell's first output line, generated by the first input 
line, shows the solutions for p1 and p2. These two prices are 
assigned the names phigh and plow. The third command defines
the profit function.

Next m = m1 = 0.8 is specified, defining the two prices
and the resulting quantities and the profit level.

soln: ratsimp(solve([dP2p1, dP2p2],[p1, p2]));
[phigh, plow] : [rhs(soln[1][1]), rhs(soln[1][2])]$

P2pmax:ratsimp(phigh*(m*xa(phigh,a0)+(1-m)*xb(phigh,b0))+ 
     (1-m)*plow*(xb(plow,b0)-xb(phigh,b0))-
     mc*(xb(plow,b0)));             

m1: 0.8$
[ph1, pl1,xa1,xbhigh1,xblow1]:subst(m = m1,[phigh, plow,
  xa(phigh,a0),xb(phigh,b0),xb(plow,b0)-xb(phigh,b0)])$
numbers: subst(m=m1,[phigh, plow,P2pmax,xa1,xbhigh1,xblow1])$
matrix(["phigh","plow","maximum P","xa","xbhigh","xblow"],
numbers);

The graph below shows the pair of prices that generates maximum
profit. The upper dashed line shows the price for lower quantities. The
lower, broader dashed line shows the price for quantities above 13.211 units.

wxdraw2d( yrange = [0,1+b0],xlabel="x",ylabel="$ per unit",
 ytics={numbers[1],numbers[2]},
 key="mc",explicit(mc,x,0,b0+1),line_width=2,
 key="Type A Demand",explicit(pa(xa,a0),xa,0,b0+1),
 color=black,key="Type B Demand",
 explicit(pb(xb,b0),xb,0,b0+1),
 line_type=dots, points_joined=true,    
 key="High Price", points([[0,ph1],[xbhigh1,ph1]]),
 color=red, point_type=3, key="Low Price",
 points([[xbhigh1,pl1],[xb(pl1,b0),pl1]]) )$