A valley's firewood market: at a price of P dollars per cubic metre, households want a - b \cdot P cubic metres a month and woodcutters offer c + d \cdot P (with b > 0, d > 0). Neither side can want or offer less than nothing, so each of these is taken as 0 when the formula gives a negative number. Without rules, the market clears at the equilibrium price P^* where the two lines cross (the inputs promise P^* > 0 and a positive quantity there).
The valley council sets one price rule:
- a ceiling (
kind = "ceiling"): wood may not sell aboveleveldollars; - a floor (
kind = "floor"): wood may not sell belowleveldollars.
A rule binds if it forbids the equilibrium price: a ceiling below P^*, or a floor above it. A rule exactly at P^* does not bind. A rule that does not bind changes nothing. A binding rule fixes the price at level; no one can be made to trade more than they want, so the quantity traded is the smaller of the amounts wanted and offered at that price. The gap between the two is a shortage (under a ceiling, more is wanted than offered) or an excess supply (under a floor).
Write price_control(a, b, c, d, kind, level) that returns (binds, price, quantity_traded, gap), where gap is the shortage or the excess supply as a number of at least 0 (0 when the rule does not bind).
Examples
Input: a = 900, b = 10, c = -100, d = 15, kind = "ceiling", level = 30
Output: (True, 30, 350, 250)
Explanation: the market would clear at 40 dollars and 500 cubic metres. At 30 dollars
households want 600 but woodcutters offer only 350: 350 is traded, 250 is missing.
Input: a = 900, b = 10, c = -100, d = 15, kind = "floor", level = 50
Output: (True, 50, 400, 250)
Input: a = 900, b = 10, c = -100, d = 15, kind = "ceiling", level = 45
Output: (False, 40.0, 500.0, 0)
Constraints
- numbers are compared with a tolerance of
1e-6
Goals
- Decide whether a price ceiling or floor binds by comparing it with the equilibrium price
- Find the quantity traded under a binding control: the short side of the market
- Measure the shortage or the excess supply the control creates