A city's bakeries sell sourdough loaves. At a price of P dollars per loaf, buyers want Q_d = a - b \cdot P loaves a day and bakeries offer Q_s = c + d \cdot P (with b > 0, d > 0; c may be negative).
Two things happen at once:
- Incomes rise, and at every price buyers now want
extra_demandmore loaves a day: the demand line becomes Q_d = (a + \text{extra\_demand}) - b \cdot P. A negativeextra_demandmeans they want fewer. - Flour gets dearer by
cost_risedollars per loaf. A bakery now needscost_risedollars more per loaf than before to offer the same number of loaves: the supply line becomes Q_s = c + d \cdot (P - \text{cost\_rise}). A negativecost_risemeans flour got cheaper.
Either change can be 0. Write shift_effect(a, b, c, d, extra_demand, cost_rise) that returns the tuple (new_price, new_quantity, price_move, quantity_move): the equilibrium after the changes (the price where the new lines cross, and the quantity there), and how each compares with the equilibrium before them, as "up", "down" or "none". A move is "none" when the change is at most 1e-9 in size.
Both before and after, the lines cross at a price and quantity of at least 0 (the inputs promise it).
Examples
Input: a = 500, b = 20, c = -100, d = 30, extra_demand = 50, cost_rise = 0
Output: (13.0, 290.0, 'up', 'up')
Explanation: before, the market clears at 12 dollars and 260 loaves.
Input: a = 500, b = 20, c = -100, d = 30, extra_demand = 0, cost_rise = 2
Output: (13.2, 236.0, 'up', 'down')
Input: a = 500, b = 20, c = -100, d = 30, extra_demand = 40, cost_rise = 2
Output: (14.0, 260.0, 'up', 'none')
Explanation: the two changes push the quantity in opposite directions, and here they cancel.
Constraints
- prices and quantities are compared with a tolerance of
1e-6
Goals
- Turn a story (higher incomes, a costlier input) into new parameters of the lines
- Find the equilibrium before and after a change
- Report the direction of the change in price and quantity, including no change