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

# Demand Theory: Constraints 
               and Optimization

This chapter introduces the budget constraint and 
combines the budget constraint with the preferences developed in the 
preceding chapter to provide a model of rational consumer
choice. 

## Budgets and Budget Constraints

The consumer's budget constraint is  px*x + py*y = m. The function
below expresses the constraint as px*x+py*y-m, with "= 0" being 
implicit. This is different from, but equivalent to, the phrasing
used in the text.

budget(x,y,px,py,m):=px*x+py*y-m;

This budget line appears below.

[px0,py0,m0]:[50,12,1200]$  
wxdraw2d(xlabel="x",ylabel="y",key="Initial Budget Line",
 implicit(budget(x,y,px0,py0,m0),x,0,1.1*m0/px0,y,0,1.1*m0/py0))$

In the analysis that follows, x is the consumer's decision variable,
so we rephrase the budget line with BL being the quantity of y, given
x. The function is y = (m - px*x)/py.

### Nominal vs. Relative Values

This statement of the expression reveals that real money income and r
elativeprices matter, not nominal values.

BL(x,m,px,py):=''(rhs(solve(budget(x,y,px,py,m),y)[1]));

The next cell confirms that the budget line is homogeneous,
degree zero in its parameters (m, px, and py).

solve(budget(x,y,k*px,k*py,k*m),y);
/* or */  ratsimp( BL(x,k*m,k*px,k*py)/BL(x,m,px,py));

### Budget Lines with Rationing and with Subsidies

Quota

The budget line now consists of a line that is a segment 
of the initial budget line, with a maximum quantity established.

That quantity is x = 15 in the illustration.

x1:15$  xmax:1.1*m0/px0$  
wxdraw2d(xlabel="Good x", xrange=[0, xmax],ylabel="Good y",
 yrange=[0,(m0/py0)*1.1],  key="Initial Budget Line",
 explicit(BL(x,m0,px0,py0),x,0,m0/px0 ),
 line_width=3,key="Budget Line, Rationing",
 explicit(BL(x,m0,px0,py0),x,0,x1 ) )$

Ad valorem subsidy

In the illustration the subsidy rate is 40% for the first 15 units and 
zero thereafter.

s:0.40$ xmax:(m0+(px0*s*x1))/px0$
wxdraw2d(xrange=[0,xmax],xlabel="x",yrange=[0,1.1*m0/py0],
 ylabel="y",key="Initial Budget Line",
 explicit(BL(x,m0,px0,py0),x,0,xmax),   line_width=3,
 key=concat("New Budget Line Segment, x < ",string(x1)),
/*   y-intercept no affected, slope is 60% of the initial
      slope. To the consumer, the net price is 0.6*px0.      */
 explicit(BL(x,m0,px0*(1-s),py0),x,0,x1),
 color=red,key=
 concat("New Budget Line Segment, x >= ",string(x1)),
/*        The budget line shifts upward by 0.4*px0*15        */     
 explicit(BL(x,m0+s*px0*x1,px0,py0),x,x1,xmax)    )$

Fixed-quantity subsidy

For some subsidies like food stamps, a fixed quantity is provided
and the consumer can buy additional units. Such a subsidy shifts
the budget line to the right, with the segment above the initial
income level truncated. In the illustration, the fixed quantity is 5.
The consumer can now consume any quantity between 5 and 30. The
unit price for units greater than 5 is px0.

FS:5$ xmax:FS+m0/px0$    
wxdraw2d(xrange=  [0,1.1*xmax], xlabel="x",yrange=[0,1.1*m0/py0],
 ylabel="y", key="Initial Budget Line",
 explicit(BL(x,m0,px0,py0),x,0,m0/px0),
 color=green,line_width=2,points_joined=true, 
  key="Fixed Subsidy Budget Line",points([[0,m0/py0],
  [FS,m0/py0]]),key="",points([[FS,m0/py0],[xmax,0]]))$

## Indifference Curves and Choice

The budget lines shown above relate y to x, indicating the 
quantity of y that a consumer can have for any quantity of x.

The indifference curves developed earlier show a separate
relationship between x and y. Combining the two provides a 
model of choice, in which the consumer selects the point
on the budget line that yields maximum utility.

The cell below repeats four functions from Chapter 3 and 
the explicit expression of the budget line derived in the 
previous section.

u(x,y,a,b):=(a*x^-b+(1-a)*y^-b)^-(1/b);
mux(x,y,a,b) :=a*((u(x, y, a, b))/x)^(1+b);
muy(x,y,a,b) :=(1-a)*(u(x,y,a,b)/y)^(1+b);
ic(x,a,b,u0) :=u0*((1-a)*x^b/(x^b-a*u0^b))^(1/b);
BL(x,m,px,py):=m/py-(px/py)*x;

The next cell recalls parameter values that have been used
so far. It also specifies that we will focus on three 
utility levels -- 20, 30, and 40 -- for illustrations below.

We recall the xmin expression that specifies the minimum
number of x units that the consumer must have in order to
achieve a given utility level. Recall that this requirement
derives from our use of a relatively small value of s, the 
elasticity of substitution.

[a0,b0]:[1/3,4/5]$ 
[px0,py0,m0]:[50,12,1200]$
xmin(a,b,u):=a^(1/b)*u; [u1,u2,u3]:[20,30,40]$
[xmin1,xmin2,xmin3]:float([xmin(a0,b0,u1),  
xmin(a0, b0, u2), xmin(a0, b0, u3)]);

### Optimization: Choosing the Best Combination

Before combining budget lines and indifference curves graphically
we explore the implications of setting the slope of an indifference
curve (the rate at which the consumer is willing to trade y for x)
equal to the slope of the budget line (the rate at which the 
consumer is able to trade y for x).

It is useful to develop a functional expression for the slope of
the consumer's indifference curves. 
The icslope(x,u0) states the number of units of y required for the
slope of the indifference curve for u = u0 for each specified value 
of x. The next cell considers three values of u0 -- u01, u02, and u03.

The money income, m, values below indicate the amount of money that 
would be required for the x, y values that are determined to be 
available. Later, we take the money income level as exognenous.

[u01,u02,u03]:[20,30,40]$
icslope(x,u0):= ''(radcan(diff(ic(x,a0,b0,u0),x)));   
/*  Set the slope of this function equal to the price ratio. The find_root
    command provides a numerical value directly and is easier to used than
    solve( ) */
[x1,x2,x3]:
 [find_root(icslope(x,u01)=-px0/py0,x,xmin1+0.1,50),
 find_root(icslope(x,u02)= -px0/py0,x,xmin2+0.1,50),
 find_root(icslope(x,u03)= -px0/py0,x,xmin3+0.1,50)]$
/*   Place the values of x above into the icslope(x,u0), 
     along with the values of u0, to determine the y 
     values that result in the indicated slope                 */
[y1,y2,y3]: float([ic(x1,a0,b0,u01),ic(x2,a0,b0,u02), 
      ic(x3, a0,b0,u03)])$        
/*       Determine the implied income levels, given 
         the prices and the x and y values determined above.     */
[m1,m2,m3]: 
   [x1*px0+y1*py0, x2*px0+y2*py0, x3*px0+y3*py0]$
matrix(["x","y","m"],[x1,y1,m1],[x2,y2,m2],[x3,y3,m3]);

The next cell confirms that the mrs = px0/py0 at each of the points
determined above.
It also defines the mrs(x,y,a,b) function for use here and below.

mrs(x,y,a,b) := (a/(1-a)) * (y/x)^(1 + b);
numbers: float([mrs(x1,y1,a0,b0), mrs(x2,y2,a0,b0), 
mrs(x3, y3, a0, b0), px0/py0])$   names: 
  ["mrs1","mrs2","mrs3","px/py"]$  matrix(names,numbers);

The Income Consumption Curve

Given the CES utility function and fixed prices, we can express
the relationship between y and x that generalizes the solutions
above. First, derive the relationship between x and y that 
mrs( ) = px/py implies.

declare(b,noninteger)$   
assume(a>0,a<1,x>0,y>0,px>0,py>0)$  
soln:radcan(solve(mrs(x,y,a,b)=px/py,y));

The cell below simplifies the solution above and writes y 
as an explicit function of x, the prices, and the parameters
of the utility function.

yicc(x,px,py,a,b) := x*((px/py)*(1-a)/a)^(1/(1+b));

The graph below contains the three indifference curves defined
above. It also shows the budget lines that must pertain if these
utility levels are to be attained, given px and py. 
Finally, it shows the income-consumption curve, which passes
through the points of tangency of the indifference curves and the 
budget lines.

wxdraw2d(title="Indifference Curves and Budget Lines",
 xlabel="x",ylabel="y",xrange=[0,m3/px0],yrange=[0,m3/py0],
 
 line_width=2,key="IC and BL, u0 = u01",
 explicit(ic(x,a0,b0,u01),x,1,m3/px0),  
 key = "", /*This turns off the key. No space between " and " */ 
 explicit(BL(x,m1,px0,py0), x, 0, m1/px0), 
 
 color=red, key="IC and BL, u0 = u02",
 explicit(ic(x,a0,b0,u02),x,xmin1+1,m3/px0),
 key = "",  explicit(BL(x,m2,px0,py0), x, 0, m2/px0),
 
 color=black, key="IC and BL, u0 = u03",
 explicit(ic(x,a0,b0,u03),x,xmin1+0.1,m3/px0) , 
 key="",explicit(BL(x,m3,px0,py0),x,0,m3/px0) ,
 
 line_width=1,key="ICC",color=black,
 explicit(yicc(x,px0,py0,a0,b0),x,0,m3/px0),
 dimensions=[640,480] )$

Elasticity of Substitution Revisited

The graph shows that, for px=px0 and py=py0, the ratio of y to x that
results in a specific mrs (mrs = px0/py0) is the same for all utility
levels.

The first expression rephrases the relationship developed above in 
terms of the ratio y/x. The second command generates the specific 
value implied by the values used above.
A function with this characteristic is called a homothetic function.

[a0,b0]:[1/3,4/5]$  expr1:y/x=((px/py)*(1-a)/a)^(1/(1+b));
float((subst([a=a0,b=b0,px=px0,py=py0], expr1)));