From ddca10c914bdf56e820fa77adecaf78fd5616abc Mon Sep 17 00:00:00 2001 From: thomassargent30 Date: Sun, 16 Jun 2024 17:21:17 +0800 Subject: [PATCH 01/11] Tom's June 16 edits of Greek square lecture --- lectures/greek_square.md | 54 ++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index db14f12b..2fd4377c 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -48,9 +48,12 @@ In this lecture, we'll describe this method. We'll also use invariant subspaces to describe variations on this method that are faster. -## Primer on second order linear difference equation +## Second order linear difference equations -Consider the following second-order linear difference equation +Before telling how the ancient Greeks computed square roots, we'll provide a quick introduction +to second order linear difference equations. + +We'll study the following second-order linear difference equation $$ y_t = a_1 y_{t-1} + a_2 y_{t-2}, \quad t \geq 0 @@ -58,7 +61,24 @@ $$ (eq:2diff1) where $(y_{-1}, y_{-2})$ is a pair of given initial conditions. -We want to find expressions for $y_t, t \geq 0$ as functions of the initial conditions $(y_{-1}, y_{-2})$: +Equation {eq}`eq:2diff1` is actually an infinite number of linear equations in the sequence +$\{y_t\}_{t=0}^\infty$. + +There is one equation each for $t = 0, 1, 2, \ldots$. + +We could follow an approach taken in this QuantEcon lecture {doc}`present values` and stack all of these equations into a single matrix equation that we would then solve by using matrix inversion. + +```{note} In the present instance, the matrix equation would have an infinite dimensional square matrix multiplying an infinite dimensional vector. With some qualifications, standard matrix multiplication and inversion tools can be applied to such a system. +``` + +But we won't pursue that approach here. + + +Instead, we'll seek to find a time-invariant function that *solves* our difference equation, meaning +thatit provides a formula for a $\{y_t\}_{t=0}^\infty$ sequence that satisfies +equation {eq}`eq:2diff1` for each $t \geq 0$. + +We seek an expression for $y_t, t \geq 0$ as functions of the initial conditions $(y_{-1}, y_{-2})$: $$ y_t = g((y_{-1}, y_{-2});t), \quad t \geq 0 @@ -137,8 +157,14 @@ If we choose $(y_{-1}, y_{-2})$ to set $(\eta_1, \eta_2) = (1, 0)$, then $y_t = If we choose $(y_{-1}, y_{-2})$ to set $(\eta_1, \eta_2) = (0, 1)$, then $y_t = \delta_2^t$ for all $t \geq 0$. +Soon we'll relate the preceding calculations to components an eigen decomposition of a transition +matrix that represents difference equation {eq}`eq:2diff1` in a very convenient way. -## Setup +We'll turn to that after we describe how Ancient Greeks figured out how to compute square roots of +positive integers that are not perfect squares. + + +## Algorithm of the Ancient Greeks Let $\sigma$ be a positive integer greater than $1$ @@ -173,7 +199,7 @@ $$ (eq:cha_eq0) +++ -(This is an instance of equation {eq}`eq:2diff6` above.) +(Notice how this is an instance of equation {eq}`eq:2diff6` above.) If we factor the right side of the equation {eq}`eq:cha_eq0`, we obtain @@ -280,7 +306,7 @@ In taking this second approach, we were in effect finding an **invariant subspa Here is what is going on. -For $ t \geq 0$ and for most pairs of initial conditions $(y_{-1}, y_{-2}) \in {\bf R}^2$ for equation {eq}`eq:second_order', $y_t$ can be expressed as a linear combination of $y_{t-1}$ and $y_{t-2}$. +For $ t \geq 0$ and for most pairs of initial conditions $(y_{-1}, y_{-2}) \in {\bf R}^2$ for equation {eq}`eq:second_order`, $y_t$ can be expressed as a linear combination of $y_{t-1}$ and $y_{t-2}$. But for some special initial conditions $(y_{-1}, y_{-2}) \in {\bf R}^2$, $y_t$ can be expressed as a linear function of $y_{t-1}$ only. @@ -500,7 +526,7 @@ $$ This can be achieved by setting $$ -x_{2,0} = -( V^{1,2})^{-1} V^{1,1} = V_{2,1} V_{1,1}^{-1} x_{1,0}. +x_{2,0} = -( V^{1,2})^{-1} V^{1,1} = V_{2,2} V_{1,2}^{-1} x_{1,0}. $$ (eq:deactivate1) To deactivate $\lambda_2$, we want to set @@ -515,6 +541,20 @@ $$ x_{2,0} = -(V^{2,2})^{-1} V^{2,1} = V_{2,1} V_{1,1}^{-1} x_{1,0} $$ (eq:deactivate2) +**Request for Humphrey**: + +Please compute the coefficients on $x_{1,0}$ in the two alternative settings for $x_{2,0}$ given by equations {eq}`eq:deactivate1` and {eq}`eq:deactivate2`. In +particular, please print out + + * $V_{2,2} V_{1,2}^{-1}$ + * $ V_{2,1} V_{1,1}^{-1}$ + +I want to compare them with the zeros of the characteristic polynomial that we computed above. +I'll explain why. + +**end of request for Humphrey** + + We shall encounter equations very similar to {eq}`eq:deactivate1` and {eq}`eq:deactivate2` in this QuantEcon lecture {doc}`money financed government deficits and inflation ` From 3df657817f5d949d587a5e7a5f67d3c8298cb39f Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 17 Jun 2024 14:40:38 +0800 Subject: [PATCH 02/11] update calculations of deactivations --- lectures/greek_square.md | 137 +++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 57 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index 2fd4377c..c8e86ac9 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -4,7 +4,7 @@ jupytext: extension: .md format_name: myst format_version: 0.13 - jupytext_version: 1.14.4 + jupytext_version: 1.16.2 kernelspec: display_name: Python 3 (ipykernel) language: python @@ -322,14 +322,10 @@ We now implement the above algorithm to compute the square root of $\sigma$. In this lecture, we use the following import: ```{code-cell} ipython3 -:tags: [] - import numpy as np ``` ```{code-cell} ipython3 -:tags: [] - def solve_λs(coefs): # Calculate the roots using numpy.roots λs = np.roots(coefs) @@ -385,16 +381,12 @@ print(f"sqrt({σ}) is approximately {sqrt_σ:.5f} (error: {dev:.5f})") Now we consider cases where $(\eta_1, \eta_2) = (0, 1)$ and $(\eta_1, \eta_2) = (1, 0)$ ```{code-cell} ipython3 -:tags: [] - # Compute λ_1, λ_2 λ_1, λ_2 = solve_λs(coefs) print(f'Roots for the characteristic equation are ({λ_1:.5f}, {λ_2:.5f}))') ``` ```{code-cell} ipython3 -:tags: [] - # Case 1: η_1, η_2 = (0, 1) ηs = (0, 1) @@ -406,8 +398,6 @@ print(f"For η_1, η_2 = (0, 1), sqrt_σ = {sqrt_σ:.5f}") ``` ```{code-cell} ipython3 -:tags: [] - # Case 2: η_1, η_2 = (0, 1) ηs = (1, 0) sqrt_σ = y(1, ηs) / y(0, ηs) - 1 @@ -459,6 +449,48 @@ $$ x_{t+1} = V \Lambda V^{-1} x_t $$ +Now we implement the algorithm above. + +First we write a function that iterates $M$ + +```{code-cell} ipython3 +def iterate_M(x_0, M, num_steps): + # Eigendecomposition of M + Λ, V_inv = np.linalg.eig(M) + V = np.linalg.inv(V_inv) + + print(f"eigenvalue:\n{Λ}") + print(f"eigenvector:\n{V}") + + # Initialize the array to store results + x = np.zeros((x_0.shape[0], num_steps)) + + # Perform the iterations + for t in range(num_steps): + x[:, t] = V @ np.diag(Λ**t) @ V_inv @ x_0 + + return x, Λ, V, V_inv + +# Define the state transition matrix M +M = np.array([[2, -(1 - σ)], + [1, 0]]) + +# Initial condition vector x_0 +x_0 = np.array([2, 2]) + +# Perform the iteration +xs, Λ, V, V_inv = iterate_M(x_0, M, num_steps=100) +``` + +Compare the eigenvector to the roots we obtained above + +```{code-cell} ipython3 +roots = solve_λs((1, -2, (1 - σ))) +print(f"roots: {np.round(roots, 8)}") +``` + +Hence we confirmed {eq}`eq:eigen_sqrt`. + Define $$ @@ -541,69 +573,60 @@ $$ x_{2,0} = -(V^{2,2})^{-1} V^{2,1} = V_{2,1} V_{1,1}^{-1} x_{1,0} $$ (eq:deactivate2) -**Request for Humphrey**: +Let's verify {eq}`eq:deactivate1` and {eq}`eq:deactivate2` below -Please compute the coefficients on $x_{1,0}$ in the two alternative settings for $x_{2,0}$ given by equations {eq}`eq:deactivate1` and {eq}`eq:deactivate2`. In -particular, please print out ++++ - * $V_{2,2} V_{1,2}^{-1}$ - * $ V_{2,1} V_{1,1}^{-1}$ +To deactivate $\lambda_1$ we use {eq}`eq:deactivate1` -I want to compare them with the zeros of the characteristic polynomial that we computed above. -I'll explain why. +```{code-cell} ipython3 +xd_1 = np.array((x_0[0], + V[1,1] * (1/V[0,1]) * x_0[0])) -**end of request for Humphrey** +# Compute x_{1,0}^* +np.round(V_inv @ xd_1, 8) +``` +We find $x_{1,0}^* = 0$. ++++ -We shall encounter equations very similar to {eq}`eq:deactivate1` and {eq}`eq:deactivate2` -in this QuantEcon lecture {doc}`money financed government deficits and inflation ` -and in many other places in dynamic economic theory. +Now we deactivate $\lambda_2$ using {eq}`eq:deactivate2` -### Implementation +```{code-cell} ipython3 +xd_2 = np.array((x_0[0], + V[1,0] * (1/V[0,0]) * x_0[0])) -Now we implement the algorithm above. +# Compute x_{2,0}^* +np.round(V_inv @ xd_2, 8) +``` -First we write a function that iterates $M$ +We find $x_{2,0}^* = 0$. + ++++ + +Here we compare $V_{2,2} V_{1,2}^{-1}$ and $V_{2,1} V_{1,1}^{-1}$ with the roots we computed above ```{code-cell} ipython3 -:tags: [] +np.round((V[1,1]*(1/V[0,1]), + V[1,0]*(1/V[0,0])), 8) +``` -def iterate_M(x_0, M, num_steps): - # Eigendecomposition of M - Λ, V = np.linalg.eig(M) - V_inv = np.linalg.inv(V) - - print(f"eigenvalue:\n{Λ}") - print(f"eigenvector:\n{V}") - - # Initialize the array to store results - x = np.zeros((x_0.shape[0], num_steps)) - - # Perform the iterations - for t in range(num_steps): - x[:, t] = V @ np.diag(Λ**t) @ V_inv @ x_0 - - return x +**Request for Humphrey**: -# Define the state transition matrix M -M = np.array([[2, -(1 - σ)], - [1, 0]]) +Please compute the coefficients on $x_{1,0}$ in the two alternative settings for $x_{2,0}$ given by equations {eq}`eq:deactivate1` and {eq}`eq:deactivate2`. In +particular, please print out -# Initial condition vector x_0 -x_0 = np.array([1, 0]) + * $V_{2,2} V_{1,2}^{-1}$ + * $V_{2,1} V_{1,1}^{-1}$ -# Perform the iteration -xs = iterate_M(x_0, M, num_steps=100) -``` +I want to compare them with the zeros of the characteristic polynomial that we computed above. +I'll explain why. -Compare the eigenvector to the roots we obtained above +**end of request for Humphrey** -```{code-cell} ipython3 -:tags: [] -roots = solve_λs((1, -2, (1 - σ))) -print(f"roots: {np.round(roots, 8)}") -``` -Hence we confirmed {eq}`eq:eigen_sqrt`. +We shall encounter equations very similar to {eq}`eq:deactivate1` and {eq}`eq:deactivate2` +in this QuantEcon lecture {doc}`money financed government deficits and inflation ` +and in many other places in dynamic economic theory. From daa229e79155c75899964ae8b897841b923381fa Mon Sep 17 00:00:00 2001 From: thomassargent30 Date: Fri, 21 Jun 2024 18:58:05 +0800 Subject: [PATCH 03/11] Tom's edit of Greeksquare lecture --- lectures/greek_square.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index c8e86ac9..7e997f59 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -18,6 +18,7 @@ kernelspec: ## Introduction + This lectures provides an example of **invariant subspace** methods for analyzing linear difference equations. These methods are applied throughout applied economic dynamics, for example, in this QuantEcon lecture {doc}`money financed government deficits and inflation ` @@ -459,8 +460,9 @@ def iterate_M(x_0, M, num_steps): Λ, V_inv = np.linalg.eig(M) V = np.linalg.inv(V_inv) - print(f"eigenvalue:\n{Λ}") - print(f"eigenvector:\n{V}") + print(f"eigenvalues:\n{Λ}") + print(f"eigenvectors:\n{V}") + print(f"inverse eigenvectors:\n{V_inv}") # Initialize the array to store results x = np.zeros((x_0.shape[0], num_steps)) @@ -482,7 +484,8 @@ x_0 = np.array([2, 2]) xs, Λ, V, V_inv = iterate_M(x_0, M, num_steps=100) ``` -Compare the eigenvector to the roots we obtained above +Let's compare the eigenvalues to the roots {eq}`eq:secretweapon` of equation +{eq}`eq:cha_eq0` that we obtained above. ```{code-cell} ipython3 roots = solve_λs((1, -2, (1 - σ))) @@ -558,7 +561,7 @@ $$ This can be achieved by setting $$ -x_{2,0} = -( V^{1,2})^{-1} V^{1,1} = V_{2,2} V_{1,2}^{-1} x_{1,0}. +x_{2,0} = -( V^{1,2})^{-1} V^{1,1} x_{1,0} = V_{2,2} V_{1,2}^{-1} x_{1,0}. $$ (eq:deactivate1) To deactivate $\lambda_2$, we want to set @@ -570,7 +573,7 @@ $$ This can be achieved by setting $$ -x_{2,0} = -(V^{2,2})^{-1} V^{2,1} = V_{2,1} V_{1,1}^{-1} x_{1,0} +x_{2,0} = -(V^{2,2})^{-1} V^{2,1} x_{1,0} = V_{2,1} V_{1,1}^{-1} x_{1,0} $$ (eq:deactivate2) Let's verify {eq}`eq:deactivate1` and {eq}`eq:deactivate2` below From 6ff01b51e39ce579bca010ba3b3531e4c9881df0 Mon Sep 17 00:00:00 2001 From: thomassargent30 Date: Mon, 24 Jun 2024 16:09:44 +0800 Subject: [PATCH 04/11] Tom's June 24 edits of greeksquare lecture --- lectures/greek_square.md | 97 +++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 27 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index 7e997f59..3c248b81 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -19,11 +19,18 @@ kernelspec: ## Introduction -This lectures provides an example of **invariant subspace** methods for analyzing linear difference equations. +This lecture can be viewed as a sequel to this QuantEcon lecture {doc}`eigenvalues and eigenvectors ` -These methods are applied throughout applied economic dynamics, for example, in this QuantEcon lecture {doc}`money financed government deficits and inflation ` +It provides an example of how eigen vectors isolate **invariant subspaces** that help construct and analyze solutions of linear difference equations. -Our approach in this lecture is to illustrate the method with an ancient example, one that ancient Greek mathematicians used to compute square roots of positive integers. +When vector $x_t$ starts in an invariant subspace, iterating the different equation keeps $x_{t+j}$ +in that subspace for all $j \geq 1$. + +Invariant subspace methods are used throughout applied economic dynamics, for example, in this QuantEcon lecture {doc}`money financed government deficits and inflation ` + +Our approach here is to illustrate the method with an ancient example, one that ancient Greek mathematicians used to compute square roots of positive integers. + +## Perfect Squares and Irrational Numbers An integer is called a **perfect square** if its square root is also an integer. @@ -69,7 +76,7 @@ There is one equation each for $t = 0, 1, 2, \ldots$. We could follow an approach taken in this QuantEcon lecture {doc}`present values` and stack all of these equations into a single matrix equation that we would then solve by using matrix inversion. -```{note} In the present instance, the matrix equation would have an infinite dimensional square matrix multiplying an infinite dimensional vector. With some qualifications, standard matrix multiplication and inversion tools can be applied to such a system. +```{note} In the present instance, the matrix equation would multiply a countably infinite dimensional square matrix by a countably infinite dimensional vector. With some qualifications, matrix multiplication and inversion tools apply to such an equation. ``` But we won't pursue that approach here. @@ -130,7 +137,11 @@ $$ y_t = \delta^t y_0 , \forall t \geq 0 $$ (eq:2diff8) -and $y_0 = a_1 y_{-1} + a_2 y_{-2}$ +provded that we set + +$$ +y_0 = \delta y_{-1} . +$$ The **general** solution of difference equation {eq}`eq:2diff1` takes the form @@ -202,7 +213,7 @@ $$ (eq:cha_eq0) (Notice how this is an instance of equation {eq}`eq:2diff6` above.) -If we factor the right side of the equation {eq}`eq:cha_eq0`, we obtain +Factoring the right side of equation {eq}`eq:cha_eq0`, we obtain $$ c(x)= (x - \lambda_1) (x-\lambda_2) = 0 @@ -227,8 +238,8 @@ $$ \lambda_1 = 1 + \sqrt{\sigma}, \quad \lambda_2 = 1 - \sqrt{\sigma} $$ (eq:secretweapon) -Formulas {eq}`eq:secretweapon` indicate that $\lambda_1$ and $\lambda_2$ are both simple functions -of a single variable, namely, $\sqrt{\sigma}$, the object that some Ancient Greeks wanted to compute. +Formulas {eq}`eq:secretweapon` indicate that $\lambda_1$ and $\lambda_2$ are each functions +of a single variable, namely, $\sqrt{\sigma}$, the object that we along with some Ancient Greeks want to compute. Ancient Greeks had an indirect way of exploiting this fact to compute square roots of a positive integer. @@ -241,7 +252,7 @@ $$ y_t = \lambda_1^t \eta_1 + \lambda_2^t \eta_2 $$ -where $\eta_1$ and $\eta_2$ are chosen to satisfy the prescribed initial conditions $y_{-1}, y_{-2}$: +where $\eta_1$ and $\eta_2$ are chosen to satisfy prescribed initial conditions $y_{-1}, y_{-2}$: $$ \begin{align} @@ -252,7 +263,7 @@ $$(eq:leq_sq) System {eq}`eq:leq_sq` of simultaneous linear equations will play a big role in the remainder of this lecture. -Since $\lambda_1 = 1 + \sqrt{\sigma} > 1 > \lambda_2 = 1 - \sqrt{\sigma} $ +Since $\lambda_1 = 1 + \sqrt{\sigma} > 1 > \lambda_2 = 1 - \sqrt{\sigma} $, it follows that for **almost all** (but not all) initial conditions $$ @@ -303,7 +314,7 @@ System {eq}`eq:leq_sq` of simultaneous linear equations can be used in various w Notice how we used the second approach above when we set $\eta_1, \eta_2$ either to $(0, 1)$, for example, or $(1, 0)$, for example. -In taking this second approach, we were in effect finding an **invariant subspace** of ${\bf R}^2$. +In taking this second approach, we constructed an **invariant subspace** of ${\bf R}^2$. Here is what is going on. @@ -313,7 +324,9 @@ But for some special initial conditions $(y_{-1}, y_{-2}) \in {\bf R}^2$, $y_t$ These special initial conditions require that $y_{-1}$ be a linear function of $y_{-2}$. -We'll study these special initial conditions soon. But first let's write some Python code to iterate on equation {eq}`eq:second_order` starting from an arbitrary $(y_{-1}, y_{-2}) \in {\bf R}^2$. +We'll study these special initial conditions soon. + +But first let's write some Python code to iterate on equation {eq}`eq:second_order` starting from an arbitrary $(y_{-1}, y_{-2}) \in {\bf R}^2$. ## Implementation @@ -410,7 +423,7 @@ We find that convergence is immediate. +++ -Let's represent the preceding analysis by vectorizing our second order difference equation {eq}`eq:second_order` and then using eigendecompositions of a state transition matrix. +Next, we'll represent the preceding analysis by first vectorizing our second order difference equation {eq}`eq:second_order` and then using eigendecompositions of an associated state transition matrix. ## Vectorizing the difference equation @@ -485,7 +498,7 @@ xs, Λ, V, V_inv = iterate_M(x_0, M, num_steps=100) ``` Let's compare the eigenvalues to the roots {eq}`eq:secretweapon` of equation -{eq}`eq:cha_eq0` that we obtained above. +{eq}`eq:cha_eq0` that we computed above. ```{code-cell} ipython3 roots = solve_λs((1, -2, (1 - σ))) @@ -494,13 +507,51 @@ print(f"roots: {np.round(roots, 8)}") Hence we confirmed {eq}`eq:eigen_sqrt`. -Define +**Request to Humphrey** +Please beautify the following description and code. + +Information about the square root we are after is also contained +in the two eigenvectors. + +Indeed, each eigenvector is just a two dimensional subspace of ${\bf R}^3$ pinned down +by dynamics of the form + +$$ +y_{t} = \delta_i y_{t-1}, \quad i = 1, 2 +$$ (eq:invariantsub101) + +that we encountered above in equation {eq}`eq:2diff8` above. + +In equation {eq}`eq:invariantsub101`, the $i$th $\delta_i$ equals the $V_{i, 0}/V_{i,1}$. + +The following code cell verifies this for our example. + + +```{code-cell} ipython3 +s1 = V[0,0] / V[0,1] +s2 = V[1,0] / V[1,1] +print ("(s1, s2) = ", s1, s2) +g1 = 1 + np.sqrt(2) +g2 = 1 - np.sqrt(2) +print("(g1, g2) = ", g1, g2) +``` + +**End of request to Humphrey** + +## Invariant Subspace Approach + +The preceding calculation indicates that we can use the eigenvectors $V$ to construct 2-dimensional **invariant subspaces**. + +We'll pursue that possibility now. + +Define the transformed variables + $$ x_t^* = V^{-1} x_t $$ -We can recover $x_t$ from $x_t^*$: +Evidently, we can recover $x_t$ from $x_t^*$: $$ x_t = V x_t^* @@ -615,20 +666,12 @@ np.round((V[1,1]*(1/V[0,1]), V[1,0]*(1/V[0,0])), 8) ``` -**Request for Humphrey**: - -Please compute the coefficients on $x_{1,0}$ in the two alternative settings for $x_{2,0}$ given by equations {eq}`eq:deactivate1` and {eq}`eq:deactivate2`. In -particular, please print out - - * $V_{2,2} V_{1,2}^{-1}$ - * $V_{2,1} V_{1,1}^{-1}$ - -I want to compare them with the zeros of the characteristic polynomial that we computed above. -I'll explain why. -**end of request for Humphrey** +## Concluding Remarks +This lecture sets the stage for many other applications of the **invariant subspace** methods. +All of these exploit very similar equations based on eigen decompositions. We shall encounter equations very similar to {eq}`eq:deactivate1` and {eq}`eq:deactivate2` in this QuantEcon lecture {doc}`money financed government deficits and inflation ` From ddeac3380ce0e817f2056abb88e32155f1132942 Mon Sep 17 00:00:00 2001 From: thomassargent30 Date: Tue, 25 Jun 2024 18:31:05 +0800 Subject: [PATCH 05/11] Tom's edit of french revolution June 25 --- lectures/french_rev.md | 257 +++++++++++++++++++++++++++-------------- 1 file changed, 169 insertions(+), 88 deletions(-) diff --git a/lectures/french_rev.md b/lectures/french_rev.md index 780f4317..359275f8 100644 --- a/lectures/french_rev.md +++ b/lectures/french_rev.md @@ -20,120 +20,78 @@ kernelspec: This lecture describes some monetary and fiscal features of the French Revolution described by {cite}`sargent_velde1995`. -We use matplotlib to replicate several of the graphs that they used to present salient patterns. +In order to finance public expenditures and service debts issued by earlier French governments, +successive French governments performed several policy experiments. +Authors of these experiments were guided by their having decided to put in place monetary-fiscal policies recommended by particular theories. +As a consequence, data on money growth and inflation from the period 1789 to 1787 at least temorarily illustrated outcomes predicted by these arrangements: -## Fiscal Situation and Response of National Assembly +* some *unpleasant monetarist arithmetic* like that described in this quanteon lecture XXXX +that governed French government debt dynamics in the decades preceding 1789 +* a *real bills* theory of the effects of government open market operations in which the government *backs* its issues of paper money with valuable real property or financial assets -In response to a motion by Catholic Bishop Talleyrand, -the National Assembly confiscated and nationalized Church lands. +* a classical **gold** or **silver** standard -But the National Assembly was dominated by free market advocates, not socialists. +* a classical inflation-tax theory of inflation in which Philip Cagan's demand for money studied +in this lecture XXXX is a key component -The National Assembly intended to use earnings from Church lands to service its national debt. +* a *legal restrictions* or *financial repression* theory of the demand for real balances -To do this, it began to implement a ''privatization plan'' that would let it service its debt while -not raising taxes. +We use matplotlib to replicate several of the graphs that they used to present salient patterns. -Their plan involved issuing paper notes called ''assignats'' that entitled bearers to use them to purchase state lands. +Certainly! Here's a 3-page summary of Thomas Sargent and Francois Velde's paper "Macroeconomic Features of the French Revolution" from the 1995 Journal of Political Economy: -These paper notes would be ''as good as silver coins'' in the sense that both were acceptable means of payment in exchange for those (formerly) church lands. +--- -Finance Minister Necker and the Constituants planned -to solve the privatization problem **and** the debt problem simultaneously -by creating a new currency. +### Introduction -They devised a scheme to raise revenues by auctioning -the confiscated lands, thereby withdrawing paper notes issued on the security of -the lands sold by the government. +Sargent and Velde's study delves into the macroeconomic implications of the French Revolution, focusing on the tumultuous period between 1789 and 1796. This era is marked by significant political upheaval, monetary instability, and economic transformation. The paper seeks to analyze the macroeconomic policies, particularly those related to the issuance of paper money (assignats), and their impact on the economy, including inflation, public finance, and economic activity. - This ''tax-backed money'' scheme propelled the National Assembly into the domain of monetary experimentation. - -Records of their debates show -how members of the Assembly marshaled theory and evidence to assess the likely -effects of their innovation. +### Historical Context and Monetary Policies -They quoted David Hume and Adam Smith and cited John -Law's System of 1720 and the American experiences with paper money fifteen years -earlier as examples of how paper money schemes can go awry. +**Pre-Revolutionary Fiscal Crisis:** +France entered the revolutionary period with a significant fiscal deficit, primarily due to extensive war expenditures and a cumbersome taxation system. The monarchy's inability to reform taxes and control expenditures led to escalating debts and the eventual fiscal crisis. +**Introduction of Assignats:** +In response to the financial crisis, the revolutionary government introduced assignats in 1789. Initially, these were land-backed paper money intended to be a temporary solution for fiscal shortages. Assignats were first issued as interest-bearing notes but soon became non-interest-bearing and were used as legal tender. -### Necker's plan and how it was tweaked +### Macroeconomic Consequences of Assignat Issuance -Necker's original plan embodied two components: a national bank and a new -financial instrument, the ''assignat''. +**Inflation Dynamics:** +The uncontrolled issuance of assignats led to severe inflation. Sargent and Velde highlight how the overproduction of these notes eroded their value, causing hyperinflation. The price level skyrocketed, creating widespread economic disarray and reducing the real value of debts and savings. +**Impact on Public Finance:** +The revolutionary government's reliance on assignats to finance its expenditures without corresponding fiscal reforms exacerbated the fiscal imbalance. While initially providing temporary relief, the overissuance undermined confidence in the currency, leading to a vicious cycle of devaluation and increasing monetary emissions. -Necker's national -bank was patterned after the Bank of England. He proposed to transform the *Caisse d'Escompte* into a national bank by granting it a monopoly on issuing -notes and marketing government debt. The *Caisse* was a -discount bank founded in 1776 whose main function was to discount commercial bills -and issue convertible notes. Although independent of the government in principle, -it had occasionally been used as a source of loans. Its notes had been declared -inconvertible in August 1788, and by the time of Necker's proposal, its reserves -were exhausted. Necker's plan placed the National Estates (as the Church lands -became known after the addition of the royal demesne) at the center of the financial -picture: a ''Bank of France'' would issue a $5\%$ security mortgaged on the prospective -receipts from the modest sale of some 400 millions' worth of National Estates in -the years 1791 to 1793. -```{note} - Only 170 million was to be used initially -to cover the deficits of 1789 and 1790. -``` +**Price Controls and Economic Distortions:** +In an attempt to control inflation, the government imposed price controls, notably the "Law of the Maximum." These measures, however, led to market distortions, shortages, and black markets. The disruption of traditional economic activities further aggravated the economic crisis. +### The Role of War and Political Instability -By mid-1790, members of the National Assembly had agreed to sell the National -Estates and to use the proceeds to service the debt in a ``tax-backed money'' scheme -```{note} -Debt service costs absorbed - over 60\% of French government expenditures. -``` +**War Financing:** +The Revolutionary Wars significantly influenced economic policy. The need to finance military expenditures drove the government to print more assignats, exacerbating inflationary pressures. The war effort also disrupted trade and agricultural production, further straining the economy. -The government would issue securities with which it would reimburse debt. +**Political Instability:** +The period was marked by rapid political changes, with various factions vying for control. This instability affected economic policy consistency and enforcement, contributing to the chaotic economic environment. The lack of a stable government made it challenging to implement long-term economic reforms. -The securities -were acceptable as payment for National Estates purchased at auctions; once received -in payment, they were to be burned. +### Consequences and Reforms -```{note} -The appendix to {cite}`sargent_velde1995` describes the -auction rules in detail. -``` -The Estates available for sale were thought to be worth about 2,400 -million, while the exactable debt (essentially fixed-term loans, unpaid arrears, -and liquidated offices) stood at about 2,000 million. The value of the land was -sufficient to let the Assembly retire all of the exactable debt and thereby eliminate -the interest payments on it. After lengthy debates, in August 1790, the Assembly set the denomination -and interest rate structure of the debt. +**Economic Collapse and Recovery Attempts:** +By 1796, the assignats had become nearly worthless, leading to a collapse of the monetary system. In response, the government introduced the mandats territoriaux, another form of land-backed currency, which also failed due to similar overissuance and loss of confidence. +**Fiscal and Monetary Reforms:** +The eventual stabilization of the French economy required substantial reforms. The Directory government initiated measures to restore fiscal discipline, including tax reforms and reducing the reliance on paper money. The establishment of the Banque de France in 1800 under Napoleon provided a more stable monetary system, which helped in the recovery. -```{note} Two distinct -aspects of monetary theory help in thinking about the assignat plan. First, a system -beginning with a commodity standard typically has room for a once-and-for-all emission -of (an unbacked) paper currency that can replace the commodity money without generating -inflation. \citet{Sargent/Wallace:1983} describe models with this property. That -commodity money systems are wasteful underlies Milton Friedman's (1960) TOM:ADD REFERENCE preference -for a fiat money regime over a commodity money. Second, in a small country on a -commodity money system that starts with restrictions on intermediation, those restrictions -can be relaxed by letting the government issue bank notes on the security of safe -private indebtedness, while leaving bank notes convertible into gold at par. See -Adam Smith and Sargent and Wallace (1982) for expressions of this idea. TOM: ADD REFERENCES HEREAND IN BIBTEX FILE. -``` +### Conclusion +Sargent and Velde's analysis illustrates the complex interplay between monetary policy, political stability, and economic performance during the French Revolution. The experience of the assignats serves as a cautionary tale about the dangers of excessive reliance on fiat money without adequate fiscal backing. The authors emphasize the importance of credible and consistent economic policies in maintaining monetary stability and fostering economic growth. + +--- + +This summary encapsulates the main points and findings of Sargent and Velde's paper, providing an overview of the macroeconomic challenges and policies during the French Revolution. -```{note} -The -National Assembly debated many now classic questions in monetary economics. Under -what conditions would money creation generate inflation, with what consequences -for business conditions? Distinctions were made between issue of money to pay off -debt, on one hand, and monetization of deficits, on the other. Would *assignats* be akin -to notes emitted under a real bills regime, and cause loss of specie, or would -they circulate alongside specie, thus increasing the money stock? Would inflation -affect real wages? How would it impact foreign trade, competitiveness of French -industry and agriculture, balance of trade, foreign exchange? -``` ## Data Sources @@ -194,7 +152,7 @@ plt.show() ``` -TO TEACH TOM: By staring at {numref}`fig1` carefully +TOM ADD MORE: By staring at {numref}`fig1` carefully ## Figure 2 @@ -239,6 +197,8 @@ plt.show() #plt.savefig('frfinfig2.pdf', dpi=600) ``` + +TOM ADD MORE: Figure {numref}`fig2` shows blah ## Figure 3 @@ -287,9 +247,15 @@ plt.show() ``` -TO TEACH TOM: By staring at {numref}`fr_fig3` carefully +TO TEACH TOM: Figure {numref}`fr_fig3` shows ```{code-cell} ipython3 +--- +mystnb: + figure: + caption: "Government Spending and Tax Revenues in France" + name: fr_fig3a +--- # Plot the data plt.figure() @@ -316,6 +282,7 @@ plt.show() #plt.savefig('frfinfig3_ignore_nan.jpg', dpi=600) ``` +TO TEACH TOM: Figure {numref}`fr_fig3a` shows ## Figure 4 @@ -1029,3 +996,117 @@ plt.show() ```{code-cell} ipython3 ``` + +STUFF FROM SV 1995 + + +## Fiscal Situation and Response of National Assembly + + +In response to a motion by Catholic Bishop Talleyrand, +the National Assembly confiscated and nationalized Church lands. + +But the National Assembly was dominated by free market advocates, not socialists. + +The National Assembly intended to use earnings from Church lands to service its national debt. + +To do this, it began to implement a ''privatization plan'' that would let it service its debt while +not raising taxes. + +Their plan involved issuing paper notes called ''assignats'' that entitled bearers to use them to purchase state lands. + +These paper notes would be ''as good as silver coins'' in the sense that both were acceptable means of payment in exchange for those (formerly) church lands. + +Finance Minister Necker and the Constituants planned +to solve the privatization problem **and** the debt problem simultaneously +by creating a new currency. + +They devised a scheme to raise revenues by auctioning +the confiscated lands, thereby withdrawing paper notes issued on the security of +the lands sold by the government. + + This ''tax-backed money'' scheme propelled the National Assembly into the domain of monetary experimentation. + +Records of their debates show +how members of the Assembly marshaled theory and evidence to assess the likely +effects of their innovation. + +They quoted David Hume and Adam Smith and cited John +Law's System of 1720 and the American experiences with paper money fifteen years +earlier as examples of how paper money schemes can go awry. + + +### Necker's plan and how it was tweaked + +Necker's original plan embodied two components: a national bank and a new +financial instrument, the ''assignat''. + + +Necker's national +bank was patterned after the Bank of England. He proposed to transform the *Caisse d'Escompte* into a national bank by granting it a monopoly on issuing +notes and marketing government debt. The *Caisse* was a +discount bank founded in 1776 whose main function was to discount commercial bills +and issue convertible notes. Although independent of the government in principle, +it had occasionally been used as a source of loans. Its notes had been declared +inconvertible in August 1788, and by the time of Necker's proposal, its reserves +were exhausted. Necker's plan placed the National Estates (as the Church lands +became known after the addition of the royal demesne) at the center of the financial +picture: a ''Bank of France'' would issue a $5\%$ security mortgaged on the prospective +receipts from the modest sale of some 400 millions' worth of National Estates in +the years 1791 to 1793. +```{note} + Only 170 million was to be used initially +to cover the deficits of 1789 and 1790. +``` + + +By mid-1790, members of the National Assembly had agreed to sell the National +Estates and to use the proceeds to service the debt in a ``tax-backed money'' scheme +```{note} +Debt service costs absorbed + over 60\% of French government expenditures. +``` + +The government would issue securities with which it would reimburse debt. + +The securities +were acceptable as payment for National Estates purchased at auctions; once received +in payment, they were to be burned. + +```{note} +The appendix to {cite}`sargent_velde1995` describes the +auction rules in detail. +``` +The Estates available for sale were thought to be worth about 2,400 +million, while the exactable debt (essentially fixed-term loans, unpaid arrears, +and liquidated offices) stood at about 2,000 million. The value of the land was +sufficient to let the Assembly retire all of the exactable debt and thereby eliminate +the interest payments on it. After lengthy debates, in August 1790, the Assembly set the denomination +and interest rate structure of the debt. + + +```{note} Two distinct +aspects of monetary theory help in thinking about the assignat plan. First, a system +beginning with a commodity standard typically has room for a once-and-for-all emission +of (an unbacked) paper currency that can replace the commodity money without generating +inflation. \citet{Sargent/Wallace:1983} describe models with this property. That +commodity money systems are wasteful underlies Milton Friedman's (1960) TOM:ADD REFERENCE preference +for a fiat money regime over a commodity money. Second, in a small country on a +commodity money system that starts with restrictions on intermediation, those restrictions +can be relaxed by letting the government issue bank notes on the security of safe +private indebtedness, while leaving bank notes convertible into gold at par. See +Adam Smith and Sargent and Wallace (1982) for expressions of this idea. TOM: ADD REFERENCES HEREAND IN BIBTEX FILE. +``` + + +```{note} +The +National Assembly debated many now classic questions in monetary economics. Under +what conditions would money creation generate inflation, with what consequences +for business conditions? Distinctions were made between issue of money to pay off +debt, on one hand, and monetization of deficits, on the other. Would *assignats* be akin +to notes emitted under a real bills regime, and cause loss of specie, or would +they circulate alongside specie, thus increasing the money stock? Would inflation +affect real wages? How would it impact foreign trade, competitiveness of French +industry and agriculture, balance of trade, foreign exchange? +``` \ No newline at end of file From 5edbb027f42ef5a04a65030ab662ce7bddc7e9e6 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Wed, 26 Jun 2024 09:52:33 +0800 Subject: [PATCH 06/11] update square root lecture --- lectures/greek_square.md | 128 +++++++++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 38 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index 3c248b81..88c79c77 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -337,6 +337,7 @@ In this lecture, we use the following import: ```{code-cell} ipython3 import numpy as np +import matplotlib.pyplot as plt ``` ```{code-cell} ipython3 @@ -412,7 +413,7 @@ print(f"For η_1, η_2 = (0, 1), sqrt_σ = {sqrt_σ:.5f}") ``` ```{code-cell} ipython3 -# Case 2: η_1, η_2 = (0, 1) +# Case 2: η_1, η_2 = (1, 0) ηs = (1, 0) sqrt_σ = y(1, ηs) / y(0, ηs) - 1 @@ -468,33 +469,37 @@ Now we implement the algorithm above. First we write a function that iterates $M$ ```{code-cell} ipython3 -def iterate_M(x_0, M, num_steps): - # Eigendecomposition of M - Λ, V_inv = np.linalg.eig(M) - V = np.linalg.inv(V_inv) +def iterate_M(x_0, M, num_steps, dtype=np.float64): - print(f"eigenvalues:\n{Λ}") - print(f"eigenvectors:\n{V}") - print(f"inverse eigenvectors:\n{V_inv}") + # Eigendecomposition of M + Λ, V = np.linalg.eig(M) + V_inv = np.linalg.inv(V) # Initialize the array to store results - x = np.zeros((x_0.shape[0], num_steps)) + xs = np.zeros((x_0.shape[0], + num_steps + 1)) # Perform the iterations + xs[:, 0] = x_0 for t in range(num_steps): - x[:, t] = V @ np.diag(Λ**t) @ V_inv @ x_0 + xs[:, t + 1] = M @ xs[:, t] - return x, Λ, V, V_inv + return xs, Λ, V, V_inv # Define the state transition matrix M -M = np.array([[2, -(1 - σ)], - [1, 0]]) +M = np.array([ + [2, -(1 - σ)], + [1, 0]]) # Initial condition vector x_0 x_0 = np.array([2, 2]) # Perform the iteration xs, Λ, V, V_inv = iterate_M(x_0, M, num_steps=100) + +print(f"eigenvalues:\n{Λ}") +print(f"eigenvectors:\n{V}") +print(f"inverse eigenvectors:\n{V_inv}") ``` Let's compare the eigenvalues to the roots {eq}`eq:secretweapon` of equation @@ -507,37 +512,48 @@ print(f"roots: {np.round(roots, 8)}") Hence we confirmed {eq}`eq:eigen_sqrt`. -**Request to Humphrey** -Please beautify the following description and code. - Information about the square root we are after is also contained in the two eigenvectors. -Indeed, each eigenvector is just a two dimensional subspace of ${\bf R}^3$ pinned down -by dynamics of the form +Indeed, each eigenvector is just a two-dimensional subspace of ${\mathbb R}^3$ pinned down by dynamics of the form $$ -y_{t} = \delta_i y_{t-1}, \quad i = 1, 2 +y_{t} = \lambda_i y_{t-1}, \quad i = 1, 2 $$ (eq:invariantsub101) that we encountered above in equation {eq}`eq:2diff8` above. -In equation {eq}`eq:invariantsub101`, the $i$th $\delta_i$ equals the $V_{i, 0}/V_{i,1}$. - -The following code cell verifies this for our example. +In equation {eq}`eq:invariantsub101`, the $i$th $\lambda_i$ equals the $V_{i, 1}/V_{i,2}$. +The following graph verifies this for our example. ```{code-cell} ipython3 -s1 = V[0,0] / V[0,1] -s2 = V[1,0] / V[1,1] -print ("(s1, s2) = ", s1, s2) -g1 = 1 + np.sqrt(2) -g2 = 1 - np.sqrt(2) -print("(g1, g2) = ", g1, g2) +# Plotting the eigenvectors +plt.figure(figsize=(8, 8)) + +plt.quiver(0, 0, V[0, 0], V[0, 1], angles='xy', scale_units='xy', + scale=1, color='C0', label=fr'$\lambda_1={np.round(Λ[0], 4)}$') +plt.quiver(0, 0, V[1, 0], V[1, 1], angles='xy', scale_units='xy', + scale=1, color='C1', label=fr'$\lambda_2={np.round(Λ[1], 4)}$') + +# Annotating the slopes +plt.text(V[0, 0]-0.5, V[0, 1]*1.2, + r'slope=$\frac{V_{1,1}}{V_{1,2}}=$'+f'{np.round(V[0, 0] / V[0, 1], 4)}', + fontsize=12, color='C0') +plt.text(V[1, 0]-0.5, V[1, 1]*1.2, + r'slope=$\frac{V_{2,1}}{V_{2,2}}=$'+f'{np.round(V[1, 0] / V[1, 1], 4)}', + fontsize=12, color='C1') + +# Adding labels +plt.axhline(0, color='grey', linewidth=0.5, alpha=0.4) +plt.axvline(0, color='grey', linewidth=0.5, alpha=0.4) +plt.legend() + +plt.xlim(-1.5, 1.5) +plt.ylim(-1.5, 1.5) +plt.show() ``` -**End of request to Humphrey** - ## Invariant Subspace Approach The preceding calculation indicates that we can use the eigenvectors $V$ to construct 2-dimensional **invariant subspaces**. @@ -565,9 +581,9 @@ Let $$ V = \begin{bmatrix} V_{1,1} & V_{1,2} \cr - V_{2,2} & V_{2,2} \end{bmatrix}, \quad + V_{2,1} & V_{2,2} \end{bmatrix}, \quad V^{-1} = \begin{bmatrix} V^{1,1} & V^{1,2} \cr - V^{2,2} & V^{2,2} \end{bmatrix} + V^{2,1} & V^{2,2} \end{bmatrix} $$ Notice that it follows from @@ -634,8 +650,11 @@ Let's verify {eq}`eq:deactivate1` and {eq}`eq:deactivate2` below To deactivate $\lambda_1$ we use {eq}`eq:deactivate1` ```{code-cell} ipython3 +Λ, V = np.linalg.eig(M) + xd_1 = np.array((x_0[0], - V[1,1] * (1/V[0,1]) * x_0[0])) + V[1,1]/V[0,1] * x_0[0]), + dtype=np.float64) # Compute x_{1,0}^* np.round(V_inv @ xd_1, 8) @@ -649,7 +668,8 @@ Now we deactivate $\lambda_2$ using {eq}`eq:deactivate2` ```{code-cell} ipython3 xd_2 = np.array((x_0[0], - V[1,0] * (1/V[0,0]) * x_0[0])) + V[1,0]/V[0,0] * x_0[0]), + dtype=np.float64) # Compute x_{2,0}^* np.round(V_inv @ xd_2, 8) @@ -657,16 +677,48 @@ np.round(V_inv @ xd_2, 8) We find $x_{2,0}^* = 0$. -+++ +```{code-cell} ipython3 +# Simulate the difference equation with muted λ1 +num_steps = 10 +xs_λ1, Λ, _, _ = iterate_M(xd_1, M, num_steps) + +# Simulate the difference equation with muted λ2 +xs_λ2, _, _, _ = iterate_M(xd_2, M, num_steps) + +# Compute ratios y_t / y_{t-1} with higher precision +ratios_λ1 = xs_λ1[1, 1:] / xs_λ1[1, :-1] # Adjusted to second component +ratios_λ2 = xs_λ2[1, 1:] / xs_λ2[1, :-1] # Adjusted to second component + +# Plot the ratios for y_t with higher precision +plt.figure(figsize=(14, 6)) + +plt.subplot(1, 2, 1) +plt.plot(np.round(ratios_λ1, 6), label='Ratios $y_t / y_{t-1}$ after muting $\lambda_1$', color='blue') +plt.axhline(y=Λ[1], color='red', linestyle='--', label='$\lambda_2$') +plt.xlabel('Time') +plt.ylabel('Ratio $y_t / y_{t-1}$') +plt.title('Ratios after Muting $\lambda_1$') +plt.legend() + +plt.subplot(1, 2, 2) +plt.plot(ratios_λ2, label='Ratios $y_t / y_{t-1}$ after muting $\lambda_2$', color='orange') +plt.axhline(y=Λ[0], color='green', linestyle='--', label='$\lambda_1$') +plt.xlabel('Time') +plt.ylabel('Ratio $y_t / y_{t-1}$') +plt.title('Ratios after Muting $\lambda_2$') +plt.legend() + +plt.tight_layout() +plt.show() +``` Here we compare $V_{2,2} V_{1,2}^{-1}$ and $V_{2,1} V_{1,1}^{-1}$ with the roots we computed above ```{code-cell} ipython3 -np.round((V[1,1]*(1/V[0,1]), - V[1,0]*(1/V[0,0])), 8) +np.round((V[1,1]/V[0,1], + V[1,0]/V[0,0]), 8) ``` - ## Concluding Remarks This lecture sets the stage for many other applications of the **invariant subspace** methods. From f3cb32aeaf1d31f5f24813270ab19347be251c9b Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Wed, 26 Jun 2024 10:28:49 +0800 Subject: [PATCH 07/11] update square root lecture --- lectures/greek_square.md | 73 +++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index 88c79c77..18d77da8 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -30,6 +30,8 @@ Invariant subspace methods are used throughout applied economic dynamics, for ex Our approach here is to illustrate the method with an ancient example, one that ancient Greek mathematicians used to compute square roots of positive integers. +In this lecture we assume that we have yet + ## Perfect Squares and Irrational Numbers An integer is called a **perfect square** if its square root is also an integer. @@ -528,20 +530,22 @@ In equation {eq}`eq:invariantsub101`, the $i$th $\lambda_i$ equals the $V_{i, 1 The following graph verifies this for our example. ```{code-cell} ipython3 +:tags: [hide-input] + # Plotting the eigenvectors plt.figure(figsize=(8, 8)) -plt.quiver(0, 0, V[0, 0], V[0, 1], angles='xy', scale_units='xy', +plt.quiver(0, 0, V[0, 0], V[1, 0], angles='xy', scale_units='xy', scale=1, color='C0', label=fr'$\lambda_1={np.round(Λ[0], 4)}$') -plt.quiver(0, 0, V[1, 0], V[1, 1], angles='xy', scale_units='xy', +plt.quiver(0, 0, V[0, 1], V[1, 1], angles='xy', scale_units='xy', scale=1, color='C1', label=fr'$\lambda_2={np.round(Λ[1], 4)}$') # Annotating the slopes -plt.text(V[0, 0]-0.5, V[0, 1]*1.2, - r'slope=$\frac{V_{1,1}}{V_{1,2}}=$'+f'{np.round(V[0, 0] / V[0, 1], 4)}', +plt.text(V[0, 0]-0.5, V[1, 0]*1.2, + r'slope=$\frac{V_{1,1}}{V_{1,2}}=$'+f'{np.round(V[0, 0] / V[1, 0], 4)}', fontsize=12, color='C0') -plt.text(V[1, 0]-0.5, V[1, 1]*1.2, - r'slope=$\frac{V_{2,1}}{V_{2,2}}=$'+f'{np.round(V[1, 0] / V[1, 1], 4)}', +plt.text(V[0, 1]-0.5, V[1, 1]*1.2, + r'slope=$\frac{V_{2,1}}{V_{2,2}}=$'+f'{np.round(V[0, 1] / V[1, 1], 4)}', fontsize=12, color='C1') # Adding labels @@ -590,8 +594,8 @@ Notice that it follows from $$ \begin{bmatrix} V^{1,1} & V^{1,2} \cr - V^{2,2} & V^{2,2} \end{bmatrix} \begin{bmatrix} V_{1,1} & V_{1,2} \cr - V_{2,2} & V_{2,2} \end{bmatrix} = \begin{bmatrix} 1 & 0 \cr 0 & 1 \end{bmatrix} + V^{2,1} & V^{2,2} \end{bmatrix} \begin{bmatrix} V_{1,1} & V_{1,2} \cr + V_{2,1} & V_{2,2} \end{bmatrix} = \begin{bmatrix} 1 & 0 \cr 0 & 1 \end{bmatrix} $$ that @@ -650,8 +654,6 @@ Let's verify {eq}`eq:deactivate1` and {eq}`eq:deactivate2` below To deactivate $\lambda_1$ we use {eq}`eq:deactivate1` ```{code-cell} ipython3 -Λ, V = np.linalg.eig(M) - xd_1 = np.array((x_0[0], V[1,1]/V[0,1] * x_0[0]), dtype=np.float64) @@ -678,47 +680,48 @@ np.round(V_inv @ xd_2, 8) We find $x_{2,0}^* = 0$. ```{code-cell} ipython3 -# Simulate the difference equation with muted λ1 +# Simulate with muted λ1 λ2. num_steps = 10 -xs_λ1, Λ, _, _ = iterate_M(xd_1, M, num_steps) +xs_λ1 = iterate_M(xd_1, M, num_steps)[0] +xs_λ2 = iterate_M(xd_2, M, num_steps)[0] -# Simulate the difference equation with muted λ2 -xs_λ2, _, _, _ = iterate_M(xd_2, M, num_steps) +# Compute ratios y_t / y_{t-1} +ratios_λ1 = xs_λ1[1, 1:] / xs_λ1[1, :-1] +ratios_λ2 = xs_λ2[1, 1:] / xs_λ2[1, :-1] +``` -# Compute ratios y_t / y_{t-1} with higher precision -ratios_λ1 = xs_λ1[1, 1:] / xs_λ1[1, :-1] # Adjusted to second component -ratios_λ2 = xs_λ2[1, 1:] / xs_λ2[1, :-1] # Adjusted to second component +```{code-cell} ipython3 +:tags: [hide-input] -# Plot the ratios for y_t with higher precision +# Plot the ratios for y_t plt.figure(figsize=(14, 6)) plt.subplot(1, 2, 1) -plt.plot(np.round(ratios_λ1, 6), label='Ratios $y_t / y_{t-1}$ after muting $\lambda_1$', color='blue') -plt.axhline(y=Λ[1], color='red', linestyle='--', label='$\lambda_2$') -plt.xlabel('Time') -plt.ylabel('Ratio $y_t / y_{t-1}$') -plt.title('Ratios after Muting $\lambda_1$') +plt.plot(np.round(ratios_λ1, 6), + label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3) +plt.axhline(y=Λ[1], color='red', + linestyle='--', label='$\lambda_2$', alpha=0.5) +plt.xlabel('t', size=18) +plt.ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) +plt.title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_1$', + size=13) plt.legend() plt.subplot(1, 2, 2) -plt.plot(ratios_λ2, label='Ratios $y_t / y_{t-1}$ after muting $\lambda_2$', color='orange') -plt.axhline(y=Λ[0], color='green', linestyle='--', label='$\lambda_1$') -plt.xlabel('Time') -plt.ylabel('Ratio $y_t / y_{t-1}$') -plt.title('Ratios after Muting $\lambda_2$') +plt.plot(ratios_λ2, + label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3) +plt.axhline(y=Λ[0], color='green', + linestyle='--', label='$\lambda_1$', alpha=0.5) +plt.xlabel('t', size=18) +plt.ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) +plt.title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_2$', + size=13) plt.legend() plt.tight_layout() plt.show() ``` -Here we compare $V_{2,2} V_{1,2}^{-1}$ and $V_{2,1} V_{1,1}^{-1}$ with the roots we computed above - -```{code-cell} ipython3 -np.round((V[1,1]/V[0,1], - V[1,0]/V[0,0]), 8) -``` - ## Concluding Remarks This lecture sets the stage for many other applications of the **invariant subspace** methods. From 3de16e16d6beec33794724fabe61a0d9f08b0f61 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Wed, 26 Jun 2024 10:30:26 +0800 Subject: [PATCH 08/11] Revert "Tom's edit of french revolution June 25" This reverts commit ddeac3380ce0e817f2056abb88e32155f1132942. --- lectures/french_rev.md | 257 ++++++++++++++--------------------------- 1 file changed, 88 insertions(+), 169 deletions(-) diff --git a/lectures/french_rev.md b/lectures/french_rev.md index 359275f8..780f4317 100644 --- a/lectures/french_rev.md +++ b/lectures/french_rev.md @@ -20,78 +20,120 @@ kernelspec: This lecture describes some monetary and fiscal features of the French Revolution described by {cite}`sargent_velde1995`. -In order to finance public expenditures and service debts issued by earlier French governments, -successive French governments performed several policy experiments. - -Authors of these experiments were guided by their having decided to put in place monetary-fiscal policies recommended by particular theories. - -As a consequence, data on money growth and inflation from the period 1789 to 1787 at least temorarily illustrated outcomes predicted by these arrangements: +We use matplotlib to replicate several of the graphs that they used to present salient patterns. -* some *unpleasant monetarist arithmetic* like that described in this quanteon lecture XXXX -that governed French government debt dynamics in the decades preceding 1789 -* a *real bills* theory of the effects of government open market operations in which the government *backs* its issues of paper money with valuable real property or financial assets -* a classical **gold** or **silver** standard +## Fiscal Situation and Response of National Assembly -* a classical inflation-tax theory of inflation in which Philip Cagan's demand for money studied -in this lecture XXXX is a key component -* a *legal restrictions* or *financial repression* theory of the demand for real balances +In response to a motion by Catholic Bishop Talleyrand, +the National Assembly confiscated and nationalized Church lands. -We use matplotlib to replicate several of the graphs that they used to present salient patterns. +But the National Assembly was dominated by free market advocates, not socialists. -Certainly! Here's a 3-page summary of Thomas Sargent and Francois Velde's paper "Macroeconomic Features of the French Revolution" from the 1995 Journal of Political Economy: +The National Assembly intended to use earnings from Church lands to service its national debt. ---- +To do this, it began to implement a ''privatization plan'' that would let it service its debt while +not raising taxes. -### Introduction +Their plan involved issuing paper notes called ''assignats'' that entitled bearers to use them to purchase state lands. -Sargent and Velde's study delves into the macroeconomic implications of the French Revolution, focusing on the tumultuous period between 1789 and 1796. This era is marked by significant political upheaval, monetary instability, and economic transformation. The paper seeks to analyze the macroeconomic policies, particularly those related to the issuance of paper money (assignats), and their impact on the economy, including inflation, public finance, and economic activity. +These paper notes would be ''as good as silver coins'' in the sense that both were acceptable means of payment in exchange for those (formerly) church lands. -### Historical Context and Monetary Policies +Finance Minister Necker and the Constituants planned +to solve the privatization problem **and** the debt problem simultaneously +by creating a new currency. -**Pre-Revolutionary Fiscal Crisis:** -France entered the revolutionary period with a significant fiscal deficit, primarily due to extensive war expenditures and a cumbersome taxation system. The monarchy's inability to reform taxes and control expenditures led to escalating debts and the eventual fiscal crisis. +They devised a scheme to raise revenues by auctioning +the confiscated lands, thereby withdrawing paper notes issued on the security of +the lands sold by the government. -**Introduction of Assignats:** -In response to the financial crisis, the revolutionary government introduced assignats in 1789. Initially, these were land-backed paper money intended to be a temporary solution for fiscal shortages. Assignats were first issued as interest-bearing notes but soon became non-interest-bearing and were used as legal tender. + This ''tax-backed money'' scheme propelled the National Assembly into the domain of monetary experimentation. + +Records of their debates show +how members of the Assembly marshaled theory and evidence to assess the likely +effects of their innovation. -### Macroeconomic Consequences of Assignat Issuance +They quoted David Hume and Adam Smith and cited John +Law's System of 1720 and the American experiences with paper money fifteen years +earlier as examples of how paper money schemes can go awry. -**Inflation Dynamics:** -The uncontrolled issuance of assignats led to severe inflation. Sargent and Velde highlight how the overproduction of these notes eroded their value, causing hyperinflation. The price level skyrocketed, creating widespread economic disarray and reducing the real value of debts and savings. -**Impact on Public Finance:** -The revolutionary government's reliance on assignats to finance its expenditures without corresponding fiscal reforms exacerbated the fiscal imbalance. While initially providing temporary relief, the overissuance undermined confidence in the currency, leading to a vicious cycle of devaluation and increasing monetary emissions. +### Necker's plan and how it was tweaked -**Price Controls and Economic Distortions:** -In an attempt to control inflation, the government imposed price controls, notably the "Law of the Maximum." These measures, however, led to market distortions, shortages, and black markets. The disruption of traditional economic activities further aggravated the economic crisis. +Necker's original plan embodied two components: a national bank and a new +financial instrument, the ''assignat''. -### The Role of War and Political Instability -**War Financing:** -The Revolutionary Wars significantly influenced economic policy. The need to finance military expenditures drove the government to print more assignats, exacerbating inflationary pressures. The war effort also disrupted trade and agricultural production, further straining the economy. +Necker's national +bank was patterned after the Bank of England. He proposed to transform the *Caisse d'Escompte* into a national bank by granting it a monopoly on issuing +notes and marketing government debt. The *Caisse* was a +discount bank founded in 1776 whose main function was to discount commercial bills +and issue convertible notes. Although independent of the government in principle, +it had occasionally been used as a source of loans. Its notes had been declared +inconvertible in August 1788, and by the time of Necker's proposal, its reserves +were exhausted. Necker's plan placed the National Estates (as the Church lands +became known after the addition of the royal demesne) at the center of the financial +picture: a ''Bank of France'' would issue a $5\%$ security mortgaged on the prospective +receipts from the modest sale of some 400 millions' worth of National Estates in +the years 1791 to 1793. +```{note} + Only 170 million was to be used initially +to cover the deficits of 1789 and 1790. +``` -**Political Instability:** -The period was marked by rapid political changes, with various factions vying for control. This instability affected economic policy consistency and enforcement, contributing to the chaotic economic environment. The lack of a stable government made it challenging to implement long-term economic reforms. -### Consequences and Reforms +By mid-1790, members of the National Assembly had agreed to sell the National +Estates and to use the proceeds to service the debt in a ``tax-backed money'' scheme +```{note} +Debt service costs absorbed + over 60\% of French government expenditures. +``` -**Economic Collapse and Recovery Attempts:** -By 1796, the assignats had become nearly worthless, leading to a collapse of the monetary system. In response, the government introduced the mandats territoriaux, another form of land-backed currency, which also failed due to similar overissuance and loss of confidence. +The government would issue securities with which it would reimburse debt. -**Fiscal and Monetary Reforms:** -The eventual stabilization of the French economy required substantial reforms. The Directory government initiated measures to restore fiscal discipline, including tax reforms and reducing the reliance on paper money. The establishment of the Banque de France in 1800 under Napoleon provided a more stable monetary system, which helped in the recovery. +The securities +were acceptable as payment for National Estates purchased at auctions; once received +in payment, they were to be burned. -### Conclusion +```{note} +The appendix to {cite}`sargent_velde1995` describes the +auction rules in detail. +``` +The Estates available for sale were thought to be worth about 2,400 +million, while the exactable debt (essentially fixed-term loans, unpaid arrears, +and liquidated offices) stood at about 2,000 million. The value of the land was +sufficient to let the Assembly retire all of the exactable debt and thereby eliminate +the interest payments on it. After lengthy debates, in August 1790, the Assembly set the denomination +and interest rate structure of the debt. -Sargent and Velde's analysis illustrates the complex interplay between monetary policy, political stability, and economic performance during the French Revolution. The experience of the assignats serves as a cautionary tale about the dangers of excessive reliance on fiat money without adequate fiscal backing. The authors emphasize the importance of credible and consistent economic policies in maintaining monetary stability and fostering economic growth. ---- +```{note} Two distinct +aspects of monetary theory help in thinking about the assignat plan. First, a system +beginning with a commodity standard typically has room for a once-and-for-all emission +of (an unbacked) paper currency that can replace the commodity money without generating +inflation. \citet{Sargent/Wallace:1983} describe models with this property. That +commodity money systems are wasteful underlies Milton Friedman's (1960) TOM:ADD REFERENCE preference +for a fiat money regime over a commodity money. Second, in a small country on a +commodity money system that starts with restrictions on intermediation, those restrictions +can be relaxed by letting the government issue bank notes on the security of safe +private indebtedness, while leaving bank notes convertible into gold at par. See +Adam Smith and Sargent and Wallace (1982) for expressions of this idea. TOM: ADD REFERENCES HEREAND IN BIBTEX FILE. +``` -This summary encapsulates the main points and findings of Sargent and Velde's paper, providing an overview of the macroeconomic challenges and policies during the French Revolution. +```{note} +The +National Assembly debated many now classic questions in monetary economics. Under +what conditions would money creation generate inflation, with what consequences +for business conditions? Distinctions were made between issue of money to pay off +debt, on one hand, and monetization of deficits, on the other. Would *assignats* be akin +to notes emitted under a real bills regime, and cause loss of specie, or would +they circulate alongside specie, thus increasing the money stock? Would inflation +affect real wages? How would it impact foreign trade, competitiveness of French +industry and agriculture, balance of trade, foreign exchange? +``` ## Data Sources @@ -152,7 +194,7 @@ plt.show() ``` -TOM ADD MORE: By staring at {numref}`fig1` carefully +TO TEACH TOM: By staring at {numref}`fig1` carefully ## Figure 2 @@ -197,8 +239,6 @@ plt.show() #plt.savefig('frfinfig2.pdf', dpi=600) ``` - -TOM ADD MORE: Figure {numref}`fig2` shows blah ## Figure 3 @@ -247,15 +287,9 @@ plt.show() ``` -TO TEACH TOM: Figure {numref}`fr_fig3` shows +TO TEACH TOM: By staring at {numref}`fr_fig3` carefully ```{code-cell} ipython3 ---- -mystnb: - figure: - caption: "Government Spending and Tax Revenues in France" - name: fr_fig3a ---- # Plot the data plt.figure() @@ -282,7 +316,6 @@ plt.show() #plt.savefig('frfinfig3_ignore_nan.jpg', dpi=600) ``` -TO TEACH TOM: Figure {numref}`fr_fig3a` shows ## Figure 4 @@ -996,117 +1029,3 @@ plt.show() ```{code-cell} ipython3 ``` - -STUFF FROM SV 1995 - - -## Fiscal Situation and Response of National Assembly - - -In response to a motion by Catholic Bishop Talleyrand, -the National Assembly confiscated and nationalized Church lands. - -But the National Assembly was dominated by free market advocates, not socialists. - -The National Assembly intended to use earnings from Church lands to service its national debt. - -To do this, it began to implement a ''privatization plan'' that would let it service its debt while -not raising taxes. - -Their plan involved issuing paper notes called ''assignats'' that entitled bearers to use them to purchase state lands. - -These paper notes would be ''as good as silver coins'' in the sense that both were acceptable means of payment in exchange for those (formerly) church lands. - -Finance Minister Necker and the Constituants planned -to solve the privatization problem **and** the debt problem simultaneously -by creating a new currency. - -They devised a scheme to raise revenues by auctioning -the confiscated lands, thereby withdrawing paper notes issued on the security of -the lands sold by the government. - - This ''tax-backed money'' scheme propelled the National Assembly into the domain of monetary experimentation. - -Records of their debates show -how members of the Assembly marshaled theory and evidence to assess the likely -effects of their innovation. - -They quoted David Hume and Adam Smith and cited John -Law's System of 1720 and the American experiences with paper money fifteen years -earlier as examples of how paper money schemes can go awry. - - -### Necker's plan and how it was tweaked - -Necker's original plan embodied two components: a national bank and a new -financial instrument, the ''assignat''. - - -Necker's national -bank was patterned after the Bank of England. He proposed to transform the *Caisse d'Escompte* into a national bank by granting it a monopoly on issuing -notes and marketing government debt. The *Caisse* was a -discount bank founded in 1776 whose main function was to discount commercial bills -and issue convertible notes. Although independent of the government in principle, -it had occasionally been used as a source of loans. Its notes had been declared -inconvertible in August 1788, and by the time of Necker's proposal, its reserves -were exhausted. Necker's plan placed the National Estates (as the Church lands -became known after the addition of the royal demesne) at the center of the financial -picture: a ''Bank of France'' would issue a $5\%$ security mortgaged on the prospective -receipts from the modest sale of some 400 millions' worth of National Estates in -the years 1791 to 1793. -```{note} - Only 170 million was to be used initially -to cover the deficits of 1789 and 1790. -``` - - -By mid-1790, members of the National Assembly had agreed to sell the National -Estates and to use the proceeds to service the debt in a ``tax-backed money'' scheme -```{note} -Debt service costs absorbed - over 60\% of French government expenditures. -``` - -The government would issue securities with which it would reimburse debt. - -The securities -were acceptable as payment for National Estates purchased at auctions; once received -in payment, they were to be burned. - -```{note} -The appendix to {cite}`sargent_velde1995` describes the -auction rules in detail. -``` -The Estates available for sale were thought to be worth about 2,400 -million, while the exactable debt (essentially fixed-term loans, unpaid arrears, -and liquidated offices) stood at about 2,000 million. The value of the land was -sufficient to let the Assembly retire all of the exactable debt and thereby eliminate -the interest payments on it. After lengthy debates, in August 1790, the Assembly set the denomination -and interest rate structure of the debt. - - -```{note} Two distinct -aspects of monetary theory help in thinking about the assignat plan. First, a system -beginning with a commodity standard typically has room for a once-and-for-all emission -of (an unbacked) paper currency that can replace the commodity money without generating -inflation. \citet{Sargent/Wallace:1983} describe models with this property. That -commodity money systems are wasteful underlies Milton Friedman's (1960) TOM:ADD REFERENCE preference -for a fiat money regime over a commodity money. Second, in a small country on a -commodity money system that starts with restrictions on intermediation, those restrictions -can be relaxed by letting the government issue bank notes on the security of safe -private indebtedness, while leaving bank notes convertible into gold at par. See -Adam Smith and Sargent and Wallace (1982) for expressions of this idea. TOM: ADD REFERENCES HEREAND IN BIBTEX FILE. -``` - - -```{note} -The -National Assembly debated many now classic questions in monetary economics. Under -what conditions would money creation generate inflation, with what consequences -for business conditions? Distinctions were made between issue of money to pay off -debt, on one hand, and monetization of deficits, on the other. Would *assignats* be akin -to notes emitted under a real bills regime, and cause loss of specie, or would -they circulate alongside specie, thus increasing the money stock? Would inflation -affect real wages? How would it impact foreign trade, competitiveness of French -industry and agriculture, balance of trade, foreign exchange? -``` \ No newline at end of file From 52d7eff9dd3d550122bb2201fd5d30ce88b605be Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 28 Jun 2024 08:45:18 +0800 Subject: [PATCH 09/11] update based on comments and fix typos --- lectures/greek_square.md | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index 18d77da8..764936d0 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -19,20 +19,20 @@ kernelspec: ## Introduction -This lecture can be viewed as a sequel to this QuantEcon lecture {doc}`eigenvalues and eigenvectors ` +This lecture can be viewed as a sequel to this QuantEcon lecture {doc}`eigen_I` -It provides an example of how eigen vectors isolate **invariant subspaces** that help construct and analyze solutions of linear difference equations. +It provides an example of how eigenvectors isolate *invariant subspaces* that help construct and analyze solutions of linear difference equations. When vector $x_t$ starts in an invariant subspace, iterating the different equation keeps $x_{t+j}$ in that subspace for all $j \geq 1$. -Invariant subspace methods are used throughout applied economic dynamics, for example, in this QuantEcon lecture {doc}`money financed government deficits and inflation ` +Invariant subspace methods are used throughout applied economic dynamics, for example, in this QuantEcon lecture {doc}`money_inflation` Our approach here is to illustrate the method with an ancient example, one that ancient Greek mathematicians used to compute square roots of positive integers. In this lecture we assume that we have yet -## Perfect Squares and Irrational Numbers +## Perfect squares and irrational numbers An integer is called a **perfect square** if its square root is also an integer. @@ -58,10 +58,10 @@ In this lecture, we'll describe this method. We'll also use invariant subspaces to describe variations on this method that are faster. -## Second order linear difference equations +## Second-order linear difference equations Before telling how the ancient Greeks computed square roots, we'll provide a quick introduction -to second order linear difference equations. +to second-order linear difference equations. We'll study the following second-order linear difference equation @@ -78,14 +78,15 @@ There is one equation each for $t = 0, 1, 2, \ldots$. We could follow an approach taken in this QuantEcon lecture {doc}`present values` and stack all of these equations into a single matrix equation that we would then solve by using matrix inversion. -```{note} In the present instance, the matrix equation would multiply a countably infinite dimensional square matrix by a countably infinite dimensional vector. With some qualifications, matrix multiplication and inversion tools apply to such an equation. +```{note} +In the present instance, the matrix equation would multiply a countably infinite dimensional square matrix by a countably infinite dimensional vector. With some qualifications, matrix multiplication and inversion tools apply to such an equation. ``` But we won't pursue that approach here. Instead, we'll seek to find a time-invariant function that *solves* our difference equation, meaning -thatit provides a formula for a $\{y_t\}_{t=0}^\infty$ sequence that satisfies +that it provides a formula for a $\{y_t\}_{t=0}^\infty$ sequence that satisfies equation {eq}`eq:2diff1` for each $t \geq 0$. We seek an expression for $y_t, t \geq 0$ as functions of the initial conditions $(y_{-1}, y_{-2})$: @@ -94,7 +95,7 @@ $$ y_t = g((y_{-1}, y_{-2});t), \quad t \geq 0 $$ (eq:2diff2) -We call such a function $g$ a **solution** of the difference equation {eq}`eq:2diff1`. +We call such a function $g$ a *solution* of the difference equation {eq}`eq:2diff1`. One way to discover a solution is to use a guess and verify method. @@ -120,7 +121,7 @@ $$ \left(a_1 + \frac{a_2}{\delta}\right) = \delta $$ (eq:2diff5) -which we can rewrite as the **characteristic equation** +which we can rewrite as the *characteristic equation* $$ \delta^2 - a_1 \delta - a_2 = 0 @@ -139,13 +140,13 @@ $$ y_t = \delta^t y_0 , \forall t \geq 0 $$ (eq:2diff8) -provded that we set +provided that we set $$ y_0 = \delta y_{-1} . $$ -The **general** solution of difference equation {eq}`eq:2diff1` takes the form +The *general* solution of difference equation {eq}`eq:2diff1` takes the form $$ y_t = \eta_1 \delta_1^t + \eta_2 \delta_2^t @@ -186,13 +187,13 @@ So $\sigma \in {\mathcal I} \equiv \{2, 3, \ldots \}$ We want an algorithm to compute the square root of $\sigma \in {\mathcal I}$. -If $\sqrt{\sigma} \in {\mathcal I}$, $\sigma $ is said to be a **perfect square**. +If $\sqrt{\sigma} \in {\mathcal I}$, $\sigma $ is said to be a *perfect square*. If $\sqrt{\sigma} \not\in {\mathcal I}$, it turns out that it is irrational. Ancient Greeks used a recursive algorithm to compute square roots of integers that are not perfect squares. -The algorithm iterates on a second order linear difference equation in the sequence $\{y_t\}_{t=0}^\infty$: +The algorithm iterates on a second-order linear difference equation in the sequence $\{y_t\}_{t=0}^\infty$: $$ y_{t} = 2 y_{t-1} - (1 - \sigma) y_{t-2}, \quad t \geq 0 @@ -200,7 +201,7 @@ $$ (eq:second_order) together with a pair of integers that are initial conditions for $y_{-1}, y_{-2}$. -First, we'll deploy some techniques for solving difference equations that are also deployed in this QuantEcon lecture about the multiplier-accelerator model: +First, we'll deploy some techniques for solving the difference equations that are also deployed in this QuantEcon lecture about the multiplier-accelerator model: @@ -257,16 +258,16 @@ $$ where $\eta_1$ and $\eta_2$ are chosen to satisfy prescribed initial conditions $y_{-1}, y_{-2}$: $$ -\begin{align} +\begin{aligned} \lambda_1^{-1} \eta_1 + \lambda_2^{-1} \eta_2 & = y_{-1} \cr \lambda_1^{-2} \eta_1 + \lambda_2^{-2} \eta_2 & = y_{-2} -\end{align} +\end{aligned} $$(eq:leq_sq) System {eq}`eq:leq_sq` of simultaneous linear equations will play a big role in the remainder of this lecture. Since $\lambda_1 = 1 + \sqrt{\sigma} > 1 > \lambda_2 = 1 - \sqrt{\sigma} $, -it follows that for **almost all** (but not all) initial conditions +it follows that for *almost all* (but not all) initial conditions $$ \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = 1 + \sqrt{\sigma} @@ -316,7 +317,7 @@ System {eq}`eq:leq_sq` of simultaneous linear equations can be used in various w Notice how we used the second approach above when we set $\eta_1, \eta_2$ either to $(0, 1)$, for example, or $(1, 0)$, for example. -In taking this second approach, we constructed an **invariant subspace** of ${\bf R}^2$. +In taking this second approach, we constructed an *invariant subspace* of ${\bf R}^2$. Here is what is going on. @@ -426,7 +427,7 @@ We find that convergence is immediate. +++ -Next, we'll represent the preceding analysis by first vectorizing our second order difference equation {eq}`eq:second_order` and then using eigendecompositions of an associated state transition matrix. +Next, we'll represent the preceding analysis by first vectorizing our second-order difference equation {eq}`eq:second_order` and then using eigendecompositions of an associated state transition matrix. ## Vectorizing the difference equation @@ -558,9 +559,9 @@ plt.ylim(-1.5, 1.5) plt.show() ``` -## Invariant Subspace Approach +## Invariant subspace approach -The preceding calculation indicates that we can use the eigenvectors $V$ to construct 2-dimensional **invariant subspaces**. +The preceding calculation indicates that we can use the eigenvectors $V$ to construct 2-dimensional *invariant subspaces*. We'll pursue that possibility now. @@ -722,12 +723,12 @@ plt.tight_layout() plt.show() ``` -## Concluding Remarks +## Concluding remarks -This lecture sets the stage for many other applications of the **invariant subspace** methods. +This lecture sets the stage for many other applications of the *invariant subspace* methods. All of these exploit very similar equations based on eigen decompositions. We shall encounter equations very similar to {eq}`eq:deactivate1` and {eq}`eq:deactivate2` -in this QuantEcon lecture {doc}`money financed government deficits and inflation ` +in this QuantEcon lecture {doc}`money_inflation` and in many other places in dynamic economic theory. From 38e6ed393999a4c8979449d0a40eb55ff802c02d Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 1 Jul 2024 13:31:25 +0800 Subject: [PATCH 10/11] update based on comments --- lectures/greek_square.md | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index 764936d0..d310e592 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -11,22 +11,20 @@ kernelspec: name: python3 --- -+++ {"user_expressions": []} - # Computing Square Roots ## Introduction -This lecture can be viewed as a sequel to this QuantEcon lecture {doc}`eigen_I` +This lecture can be viewed as a sequel to {doc}`eigen_I` It provides an example of how eigenvectors isolate *invariant subspaces* that help construct and analyze solutions of linear difference equations. When vector $x_t$ starts in an invariant subspace, iterating the different equation keeps $x_{t+j}$ in that subspace for all $j \geq 1$. -Invariant subspace methods are used throughout applied economic dynamics, for example, in this QuantEcon lecture {doc}`money_inflation` +Invariant subspace methods are used throughout applied economic dynamics, for example, in the lecture {doc}`money_inflation` Our approach here is to illustrate the method with an ancient example, one that ancient Greek mathematicians used to compute square roots of positive integers. @@ -76,7 +74,7 @@ $\{y_t\}_{t=0}^\infty$. There is one equation each for $t = 0, 1, 2, \ldots$. -We could follow an approach taken in this QuantEcon lecture {doc}`present values` and stack all of these equations into a single matrix equation that we would then solve by using matrix inversion. +We could follow an approach taken in the lecture on {doc}`present values` and stack all of these equations into a single matrix equation that we would then solve by using matrix inversion. ```{note} In the present instance, the matrix equation would multiply a countably infinite dimensional square matrix by a countably infinite dimensional vector. With some qualifications, matrix multiplication and inversion tools apply to such an equation. @@ -172,11 +170,9 @@ If we choose $(y_{-1}, y_{-2})$ to set $(\eta_1, \eta_2) = (1, 0)$, then $y_t = If we choose $(y_{-1}, y_{-2})$ to set $(\eta_1, \eta_2) = (0, 1)$, then $y_t = \delta_2^t$ for all $t \geq 0$. -Soon we'll relate the preceding calculations to components an eigen decomposition of a transition -matrix that represents difference equation {eq}`eq:2diff1` in a very convenient way. +Soon we'll relate the preceding calculations to components an eigen decomposition of a transition matrix that represents difference equation {eq}`eq:2diff1` in a very convenient way. -We'll turn to that after we describe how Ancient Greeks figured out how to compute square roots of -positive integers that are not perfect squares. +We'll turn to that after we describe how Ancient Greeks figured out how to compute square roots of positive integers that are not perfect squares. ## Algorithm of the Ancient Greeks @@ -201,8 +197,7 @@ $$ (eq:second_order) together with a pair of integers that are initial conditions for $y_{-1}, y_{-2}$. -First, we'll deploy some techniques for solving the difference equations that are also deployed in this QuantEcon lecture about the multiplier-accelerator model: - +First, we'll deploy some techniques for solving the difference equations that are also deployed in {doc}`dynam:samuelson` @@ -212,7 +207,7 @@ $$ c(x) \equiv x^2 - 2 x + (1 - \sigma) = 0 $$ (eq:cha_eq0) -+++ + (Notice how this is an instance of equation {eq}`eq:2diff6` above.) @@ -425,8 +420,6 @@ print(f"For η_1, η_2 = (1, 0), sqrt_σ = {sqrt_σ:.5f}") We find that convergence is immediate. -+++ - Next, we'll represent the preceding analysis by first vectorizing our second-order difference equation {eq}`eq:second_order` and then using eigendecompositions of an associated state transition matrix. ## Vectorizing the difference equation @@ -650,8 +643,6 @@ $$ (eq:deactivate2) Let's verify {eq}`eq:deactivate1` and {eq}`eq:deactivate2` below -+++ - To deactivate $\lambda_1$ we use {eq}`eq:deactivate1` ```{code-cell} ipython3 @@ -665,8 +656,6 @@ np.round(V_inv @ xd_1, 8) We find $x_{1,0}^* = 0$. -+++ - Now we deactivate $\lambda_2$ using {eq}`eq:deactivate2` ```{code-cell} ipython3 @@ -691,6 +680,10 @@ ratios_λ1 = xs_λ1[1, 1:] / xs_λ1[1, :-1] ratios_λ2 = xs_λ2[1, 1:] / xs_λ2[1, :-1] ``` +The following graph shows the ratios $y_t / y_{t-1}$ for the two cases. + +We find that the ratios converge to $\lambda_2$ in the first case and $\lambda_1$ in the second case. + ```{code-cell} ipython3 :tags: [hide-input] @@ -730,5 +723,4 @@ This lecture sets the stage for many other applications of the *invariant subsp All of these exploit very similar equations based on eigen decompositions. We shall encounter equations very similar to {eq}`eq:deactivate1` and {eq}`eq:deactivate2` -in this QuantEcon lecture {doc}`money_inflation` -and in many other places in dynamic economic theory. +in {doc}`money_inflation` and in many other places in dynamic economic theory. From d2554886821fffd22ea6b65762286863ebe62775 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Thu, 4 Jul 2024 11:01:34 +0800 Subject: [PATCH 11/11] update visualization and add full stops for some sentences\ --- lectures/greek_square.md | 103 ++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 56 deletions(-) diff --git a/lectures/greek_square.md b/lectures/greek_square.md index d310e592..3ae37d38 100644 --- a/lectures/greek_square.md +++ b/lectures/greek_square.md @@ -17,19 +17,17 @@ kernelspec: ## Introduction -This lecture can be viewed as a sequel to {doc}`eigen_I` +This lecture can be viewed as a sequel to {doc}`eigen_I`. It provides an example of how eigenvectors isolate *invariant subspaces* that help construct and analyze solutions of linear difference equations. When vector $x_t$ starts in an invariant subspace, iterating the different equation keeps $x_{t+j}$ in that subspace for all $j \geq 1$. -Invariant subspace methods are used throughout applied economic dynamics, for example, in the lecture {doc}`money_inflation` +Invariant subspace methods are used throughout applied economic dynamics, for example, in the lecture {doc}`money_inflation`. Our approach here is to illustrate the method with an ancient example, one that ancient Greek mathematicians used to compute square roots of positive integers. -In this lecture we assume that we have yet - ## Perfect squares and irrational numbers An integer is called a **perfect square** if its square root is also an integer. @@ -46,11 +44,11 @@ The ancient Greeks invented an algorithm to compute square roots of integers, in Their method involved - * computing a particular sequence of integers $\{y_t\}_{t=0}^\infty$ + * computing a particular sequence of integers $\{y_t\}_{t=0}^\infty$; - * computing $\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = \bar r$ + * computing $\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = \bar r$; - * deducing the desired square root from $\bar r$ + * deducing the desired square root from $\bar r$. In this lecture, we'll describe this method. @@ -90,7 +88,7 @@ equation {eq}`eq:2diff1` for each $t \geq 0$. We seek an expression for $y_t, t \geq 0$ as functions of the initial conditions $(y_{-1}, y_{-2})$: $$ -y_t = g((y_{-1}, y_{-2});t), \quad t \geq 0 +y_t = g((y_{-1}, y_{-2});t), \quad t \geq 0. $$ (eq:2diff2) We call such a function $g$ a *solution* of the difference equation {eq}`eq:2diff1`. @@ -110,7 +108,7 @@ For initial condition that satisfy {eq}`eq:2diff3` equation {eq}`eq:2diff1` impllies that $$ -y_0 = \left(a_1 + \frac{a_2}{\delta}\right) y_{-1} +y_0 = \left(a_1 + \frac{a_2}{\delta}\right) y_{-1}. $$ (eq:2diff4) We want @@ -122,13 +120,13 @@ $$ (eq:2diff5) which we can rewrite as the *characteristic equation* $$ -\delta^2 - a_1 \delta - a_2 = 0 +\delta^2 - a_1 \delta - a_2 = 0. $$ (eq:2diff6) Applying the quadratic formula to solve for the roots of {eq}`eq:2diff6` we find that $$ -\delta = \frac{ a_1 \pm \sqrt{a_1^2 + 4 a_2}}{2} +\delta = \frac{ a_1 \pm \sqrt{a_1^2 + 4 a_2}}{2}. $$ (eq:2diff7) For either of the two $\delta$'s that satisfy equation {eq}`eq:2diff7`, @@ -177,9 +175,9 @@ We'll turn to that after we describe how Ancient Greeks figured out how to compu ## Algorithm of the Ancient Greeks -Let $\sigma$ be a positive integer greater than $1$ +Let $\sigma$ be a positive integer greater than $1$. -So $\sigma \in {\mathcal I} \equiv \{2, 3, \ldots \}$ +So $\sigma \in {\mathcal I} \equiv \{2, 3, \ldots \}$. We want an algorithm to compute the square root of $\sigma \in {\mathcal I}$. @@ -195,11 +193,9 @@ $$ y_{t} = 2 y_{t-1} - (1 - \sigma) y_{t-2}, \quad t \geq 0 $$ (eq:second_order) -together with a pair of integers that are initial conditions for $y_{-1}, y_{-2}$. - -First, we'll deploy some techniques for solving the difference equations that are also deployed in {doc}`dynam:samuelson` - +together with a pair of integers that are initial conditions for $y_{-1}, y_{-2}$. +First, we'll deploy some techniques for solving the difference equations that are also deployed in {doc}`dynam:samuelson`. The characteristic equation associated with difference equation {eq}`eq:second_order` is @@ -207,8 +203,6 @@ $$ c(x) \equiv x^2 - 2 x + (1 - \sigma) = 0 $$ (eq:cha_eq0) - - (Notice how this is an instance of equation {eq}`eq:2diff6` above.) Factoring the right side of equation {eq}`eq:cha_eq0`, we obtain @@ -233,11 +227,11 @@ By applying the quadratic formula to solve for the roots the characteristic equ {eq}`eq:cha_eq0`, we find that $$ -\lambda_1 = 1 + \sqrt{\sigma}, \quad \lambda_2 = 1 - \sqrt{\sigma} +\lambda_1 = 1 + \sqrt{\sigma}, \quad \lambda_2 = 1 - \sqrt{\sigma}. $$ (eq:secretweapon) Formulas {eq}`eq:secretweapon` indicate that $\lambda_1$ and $\lambda_2$ are each functions -of a single variable, namely, $\sqrt{\sigma}$, the object that we along with some Ancient Greeks want to compute. +of a single variable, namely, $\sqrt{\sigma}$, the object that we along with some Ancient Greeks want to compute. Ancient Greeks had an indirect way of exploiting this fact to compute square roots of a positive integer. @@ -265,13 +259,13 @@ Since $\lambda_1 = 1 + \sqrt{\sigma} > 1 > \lambda_2 = 1 - \sqrt{\sigma} $, it follows that for *almost all* (but not all) initial conditions $$ -\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = 1 + \sqrt{\sigma} +\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = 1 + \sqrt{\sigma}. $$ Thus, $$ -\sqrt{\sigma} = \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) - 1 +\sqrt{\sigma} = \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) - 1. $$ However, notice that if $\eta_1 = 0$, then @@ -283,7 +277,7 @@ $$ so that $$ -\sqrt{\sigma} = 1 - \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) +\sqrt{\sigma} = 1 - \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right). $$ Actually, if $\eta_1 =0$, it follows that @@ -306,9 +300,9 @@ so again, convergence is immediate, and we have no need to compute a limit. System {eq}`eq:leq_sq` of simultaneous linear equations can be used in various ways. - * we can take $y_{-1}, y_{-2}$ as given initial conditions and solve for $\eta_1, \eta_2$ + * we can take $y_{-1}, y_{-2}$ as given initial conditions and solve for $\eta_1, \eta_2$; - * we can instead take $\eta_1, \eta_2$ as given and solve for initial conditions $y_{-1}, y_{-2}$ + * we can instead take $\eta_1, \eta_2$ as given and solve for initial conditions $y_{-1}, y_{-2}$. Notice how we used the second approach above when we set $\eta_1, \eta_2$ either to $(0, 1)$, for example, or $(1, 0)$, for example. @@ -330,7 +324,6 @@ But first let's write some Python code to iterate on equation {eq}`eq:second_ord We now implement the above algorithm to compute the square root of $\sigma$. - In this lecture, we use the following import: ```{code-cell} ipython3 @@ -594,8 +587,6 @@ $$ that - - $$ V^{2,1} V_{1,1} + V^{2,2} V_{2,1} = 0 $$ @@ -603,7 +594,7 @@ $$ and $$ -V^{1,1}V_{1,2} + V^{1,2} V_{2,2} = 0 +V^{1,1}V_{1,2} + V^{1,2} V_{2,2} = 0. $$ These equations will be very useful soon. @@ -619,7 +610,7 @@ $$ To deactivate $\lambda_1$ we want to set $$ -x_{1,0}^* = 0 +x_{1,0}^* = 0. $$ @@ -638,7 +629,7 @@ $$ This can be achieved by setting $$ -x_{2,0} = -(V^{2,2})^{-1} V^{2,1} x_{1,0} = V_{2,1} V_{1,1}^{-1} x_{1,0} +x_{2,0} = -(V^{2,2})^{-1} V^{2,1} x_{1,0} = V_{2,1} V_{1,1}^{-1} x_{1,0}. $$ (eq:deactivate2) Let's verify {eq}`eq:deactivate1` and {eq}`eq:deactivate2` below @@ -687,30 +678,30 @@ We find that the ratios converge to $\lambda_2$ in the first case and $\lambda_1 ```{code-cell} ipython3 :tags: [hide-input] -# Plot the ratios for y_t -plt.figure(figsize=(14, 6)) - -plt.subplot(1, 2, 1) -plt.plot(np.round(ratios_λ1, 6), - label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3) -plt.axhline(y=Λ[1], color='red', - linestyle='--', label='$\lambda_2$', alpha=0.5) -plt.xlabel('t', size=18) -plt.ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) -plt.title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_1$', - size=13) -plt.legend() - -plt.subplot(1, 2, 2) -plt.plot(ratios_λ2, - label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3) -plt.axhline(y=Λ[0], color='green', - linestyle='--', label='$\lambda_1$', alpha=0.5) -plt.xlabel('t', size=18) -plt.ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) -plt.title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_2$', - size=13) -plt.legend() +# Plot the ratios for y_t / y_{t-1} +fig, axs = plt.subplots(1, 2, figsize=(14, 6)) + +# First subplot +axs[0].plot(np.round(ratios_λ1, 6), + label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3) +axs[0].axhline(y=Λ[1], color='red', linestyle='--', + label='$\lambda_2$', alpha=0.5) +axs[0].set_xlabel('t', size=18) +axs[0].set_ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) +axs[0].set_title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_1$', + size=13) +axs[0].legend() + +# Second subplot +axs[1].plot(ratios_λ2, label=r'$\frac{y_t}{y_{t-1}}$', + linewidth=3) +axs[1].axhline(y=Λ[0], color='green', linestyle='--', + label='$\lambda_1$', alpha=0.5) +axs[1].set_xlabel('t', size=18) +axs[1].set_ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18) +axs[1].set_title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_2$', + size=13) +axs[1].legend() plt.tight_layout() plt.show()