Value and Policy Iteration

A robot must reach its dock along a cliff edge. One rule finds the worth of every square and the best move from it. On a slippery floor, policy iteration needs 5 rounds where value iteration needs 18 sweeps, and both give the same answer.

Learn the return, V and Q, the two Bellman equations, and the two algorithms that solve them exactly when you know the world.

Press Solve. Then drag Slip to 10% and solve again: the route moves away from the cliff. Then switch to Policy iteration. Then we build each piece: the return, V and Q, the Bellman equations, policy evaluation, why it converges, policy improvement, and both algorithms.

You need the MDP words from Lecture 1 (state, action, reward, policy) and a little Python. We build the rest from zero.

Based on Lecture 7 of CMU 16-831, Introduction to Robot Learning, taught by Guanya Shi. Every idea is re-taught here in our own words and toys. It follows Lecture 6, Imitation Learning II and leads to Lecture 8, Q-Learning.

Solve the cliff walk

0%

Illustrative 6 by 4 grid, gamma 0.9. Every move costs 1. The dock ends the episode with value 0; a cliff square ends it with value −20. With slip s, a move goes sideways with chance s, half to each side. Value iteration stops when no value changes by more than 0.001. Policy iteration starts from “always up” and scores each policy exactly.

Chapter 0

How Good Is This Square?

Ask two questions about a robot in a corridor, and see one rule answer both

A robot stands in a corridor of four squares: A, B, C and D. D is its charging dock. Each move costs a little battery, so each move pays a reward of −1. Reaching the dock ends the episode. The robot can move left or right, and it knows exactly where each move lands.

It still has two questions. How good is each square, as a number? And which move is best from each square? Both answers depend on the whole future, not on the square alone.

Here is the rule that answers both. A square is worth the reward of the next move, plus a discounted worth of the square where that move lands. That sentence is the Bellman equation. Apply it to every square, over and over, and watch what happens.

Sweep the corridor

Every square starts at 0. Each sweep applies the rule once to every square. Press Sweep and watch which squares change.

Illustrative corridor. Gamma is 0.9, every move from A, B or C pays −1, and the dock is worth 0. A grey dot means the two moves tie.

Two things happened. The dock's pull moved back one square per sweep, because each sweep looks only one move ahead. And when the numbers stopped, every arrow pointed right. The best move came out of the values.

This lesson builds that rule and two algorithms on it. Policy iteration scores a fixed plan, then improves it, and repeats. Value iteration folds the improvement into each sweep. Both reach the same answer, and both are sure to get there.

  1. The return: one number for a whole future, and why rewards far away count less.
  2. V and Q: the worth of a square, and the worth of a square plus a first move.
  3. The Bellman equations: an average for a fixed plan, a max for the best plan.
  4. Policy evaluation: score a plan by sweeping until the values stop.
  5. Why it converges: each sweep shrinks every error by gamma.
  6. Policy improvement: pick the best move by the old plan's own scores.
  7. Policy iteration: evaluate, improve, repeat. The hero's second button.
  8. Value iteration: one sweep with a max. The hero's first button.
  9. The field guide: terms, numbers, code, links and the credit.
Why does square A need three sweeps to reach its final value, while C needs one?

Chapter 1

The Return Scores a Whole Future

Add up every reward that follows, and shrink each one by how late it comes

The robot walks right from A: three moves, three rewards of −1, then the dock. What is that whole future worth as one number? Call the time now t. Call the reward of the next move rt+1, the one after rt+2, and so on. Call the discount γ (gamma), a number between 0 and 1 that shrinks each later reward once more. The total is the return, Gt.

Say it aloud

G-t equals r-t-plus-1, plus gamma times r-t-plus-2, plus gamma squared times r-t-plus-3, and so on.

Gt
G-t the return: what the future from time t is worth as one number.
rt+1
r-t-plus-1 the reward of the next move. Here −1 for a move, 0 once docked.
γ
gamma the discount, between 0 and 1. Here 0.9.
γ2
gamma squared gamma times gamma: 0.81. The third reward counts at 81%.
…
and so on one more term per step, each with one more factor of gamma.
In plain words

Take the next reward r-t-plus-1 at full worth. Multiply the one after by gamma, the next by gamma twice, and so on. Add them all. The total is G-t.

With numbers

From A, always right: rewards −1, −1, −1, then 0. With gamma 0.9: G = −1 − 0.9 − 0.81 = −2.71.

Why shrink later rewards? First, it keeps the sum finite. A robot that pays −1 forever has a return of −1/(1 − γ), which is −10 at gamma 0.9. Second, a reward now is worth more than the same reward later. Gamma near 1 makes a patient robot. Gamma near 0 makes a robot that sees one move ahead.

Turn the discount

Each bar is the weight gamma to the k of the reward k steps after the first. Drag gamma and watch the far bars.

0.90

The return shown is the corridor's: A, always right, rewards −1, −1, −1, then 0.

Peel the first reward off the return. What is left is the return from the next step, shrunk once by gamma. This one line powers the whole lesson.

Say it aloud

G-t equals r-t-plus-1 plus gamma times G-t-plus-1.

Gt
G-t the return from now.
rt+1
r-t-plus-1 the reward of the next move.
γ
gamma the discount, 0.9.
Gt+1
G-t-plus-1 the return from the next step on.
In plain words

The return from here is the next reward r-t-plus-1, plus gamma times the return G-t-plus-1 from where you land.

With numbers

From B, always right, the return is −1.9. So the return from A is G = −1 + 0.9 × (−1.9) = −2.71, the same as the long sum.

The failure. Set gamma to 1 and score the plan “always left”. The robot never docks, so the return is −1 − 1 − 1 with no end. The symptom: the values drop by 1 on every sweep. Measure the largest change per sweep; it never shrinks. The fix: use gamma below 1, or make sure every plan you score ends.

Gamma is 0.5. The fourth reward, rt+4, is +8. How much does it add to Gt?

Chapter 2

Two Kinds of Worth: V and Q

Average the return over every future a square can have, with or without a chosen first move

On a slippery floor, the same plan from A gives different futures. So a square's worth is an average return. Call the plan the policy π (pi): it says which move to make in each square. Call the square s. The state value Vπ(s) is the average return if you start in s and follow π.

Say it aloud

V-pi of s equals the expected value under pi of G-t, given that s-t is s.

Vπ(s)
V-pi of s the worth of square s under policy pi.
Eπ
the expected value under pi the average over many runs that follow pi.
Gt
G-t the return of one run, from Chapter 1.
| st = s
given that s-t is s every run starts in square s.
In plain words

Start in square s many times. Follow pi each time. Average the returns G-t. That average is V-pi of s.

With numbers

With made-up numbers: from A, 8 of 10 runs return −2.71 and 2 runs return −3.44. V = 0.8 × (−2.71) + 0.2 × (−3.44) = −2.856.

The action value Qπ(s, a) asks more: take move a first, then follow π. Call the chance that move a in square s lands in square s′ p(s′|s, a), and the move's reward r(s, a). One move ahead, you can build Q from V.

Say it aloud

Q-pi of s and a equals the sum over s-prime of p of s-prime given s and a, times the quantity r of s and a plus gamma V-pi of s-prime.

Qπ(s, a)
Q-pi of s and a the worth of making move a in square s, then following pi.
Σs′ p(s′|s, a)
the sum over s-prime of p of s-prime given s and a an average over the squares the move can land in, weighted by their chances.
r(s, a)
r of s and a the move's reward: −1.
γ
gamma the discount, 0.9.
Vπ(s′)
V-pi of s-prime the worth of the landing square.
In plain words

For each landing square s-prime, add the reward r of s and a to gamma times V-pi of s-prime. Average those by the chances p. That is Q-pi of s and a.

With numbers

No slip, so each p is 1. Under the best plan, V(A) = −2.71 and V(B) = −1.9. Q(A, right) = −1 + 0.9 × (−1.9) = −2.71. Q(A, left) = −1 + 0.9 × (−2.71) = −3.439. Right wins.

The best policy gets a star: V* and Q*. A square's best worth is its best move's worth, V*(s) = maxa Q*(s, a). The best move is the one that reaches that max. So Q* hands you the policy with no model. V* does not: to rank moves from V*, you need p to see where each move lands.

Compare the two moves

The squares show V* at gamma 0.9. Pick a square: the bars show Q* for left and for right. The longer bar loses, because values are costs.

Illustrative corridor, no slip. Left from A bumps the wall and stays in A.

The failure. You stored V and threw the model away. The symptom: you cannot rank the moves, because each Q needs p. Measure it by writing the argmax; it asks for p. The fix: store Q in place of V. Lecture 8 learns Q from experience for this reason.

Why does Q*(s, a) give the best policy with no model, while V*(s) does not?

Chapter 3

The Two Bellman Equations

Average the one-step recursion for a fixed policy, or take a max for the best one

Put the return recursion Gt = rt+1 + γ Gt+1 inside the average V. Two choices are random. The policy picks move a with chance π(a|s). Then the world picks the landing square s′ with chance p(s′|s, a). Average over both.

Say it aloud

V-pi of s equals the sum over a of pi of a given s, times the sum over s-prime of p of s-prime given s and a, times r of s and a plus gamma V-pi of s-prime.

Vπ(s)
V-pi of s the worth of square s under policy pi. It is on both sides.
Σa π(a|s)
the sum over a of pi of a given s an average over the moves, weighted by the policy's chances.
Σs′ p(s′|s, a)
the sum over s-prime of p of s-prime given s and a an average over landing squares, weighted by the world's chances.
r(s, a)
r of s and a the reward of the move, −1.
γ
gamma the discount, 0.9.
Vπ(s′)
V-pi of s-prime the worth of the landing square.
In plain words

For each move a, average r of s and a plus gamma times V-pi of s-prime over the landing squares, using p. Then average those move scores using pi of a given s.

With numbers

With made-up numbers: square C, slip 20%, the policy always goes right, and the current guess for B is −1.9. Right lands on the dock with chance 0.8 and on B with 0.2. V(C) = −1 + 0.9 × (0.8 × 0 + 0.2 × (−1.9)) = −1.342.

This is the Bellman expectation equation. It describes one fixed policy. To describe the best policy, take the best move in place of the policy's average. The principle of optimality says why this works: a best plan must stay best from every square it reaches.

Say it aloud

V-star of s equals the max over a of the sum over s-prime of p of s-prime given s and a, times r of s and a plus gamma V-star of s-prime.

V*(s)
V-star of s the best worth any policy can get from square s.
maxa
the max over a keep the move whose score is largest.
Σs′ p(s′|s, a)
the sum over s-prime of p of s-prime given s and a the world still picks the landing square.
r(s, a)
r of s and a the reward of the move, −1.
γ
gamma the discount, 0.9.
V*(s′)
V-star of s-prime the best worth of the landing square.
In plain words

Score each move a the same way as before, with V-star in place of V-pi. Keep the largest score. That is V-star of s.

With numbers

Square C, no slip, V*(B) = −1.9, the dock is 0. V*(C) = max(−1 + 0.9 × 0, −1 + 0.9 × (−1.9)) = max(−1, −2.71) = −1.

Build one backup

Purple lines are the policy's moves. Pink lines are the model's landings. Switch between average and max, pick a square, and drag the slip.

20%

Illustrative. The current guess is V = (−2.71, −1.9, −1, 0) for A, B, C and the dock. With slip s, a move goes the other way with chance s.

EquationCombines moves byShapeHow to solve
Expectationthe policy's averagelinear in Vexactly, or by sweeps
Optimalitythe maxnot linearby sweeps

The failure. You plan with no slip, but the floor slips 20% of the time. You predict V(A) = −2.71 for “always right”; the true value is −3.61. The symptom: the robot takes longer than its values promise. Measure the average return of real runs against V. The fix: estimate p from data.

What is the one change from the Bellman expectation equation to the optimality equation, and why does it matter?

Chapter 4

Policy Evaluation Scores a Fixed Plan

Turn the expectation equation into an update and sweep it until the values stop moving

You have a plan, maybe a bad one. What is it worth in every square? Policy evaluation answers with Vπ. There are two routes.

Route 1: solve it. The expectation equation is one linear equation per square. Stack the values in a vector V and the rewards in a vector r. Call T the table of chances to move from each square to each square under π, and I the identity matrix. Then:

V = r + γ T V,  so  V = (I − γ T)−1 r

This is exact, but the cost grows with the cube of the number of squares.

Route 2: sweep it. Start with every value at 0. Call the values after k sweeps Vk. Compute new values from the old ones with the equation, for every square at once:

Vk+1(s) ← Σa π(a|s) Σs′ p(s′|s, a) [ r(s, a) + γ Vk(s′) ]

The arrow means “becomes”. In the corridor with “always right”, the sweeps go like this:

SweepV(A)V(B)V(C)V(D)
00000
1−1.00−1.00−1.000
2−1.90−1.90−1.000
3−2.71−1.90−1.000
4, no change−2.71−1.90−1.000

Sweep 3 for A: V3(A) = −1 + 0.9 × V2(B) = −1 + 0.9 × (−1.9) = −2.71. The same −2.71 as the return in Chapter 1.

Score your own plan

Tap a square's button to flip its move. Then sweep. The lower plot is the largest change in each sweep, on a log scale.

Plan:

Illustrative corridor, gamma 0.9, no slip. “Run to the end” stops when the largest change falls below 0.0001.

The failure. You stop after a fixed 3 sweeps. For “always left” every square then reads −2.71, but the true value is −10: the robot never docks. The symptom: a bad plan looks fine. Measure the largest change in the last sweep: 0.81, far from 0. The fix: sweep until that change is tiny. Getting within 0.01 of −10 takes 66 sweeps.

Now write the update yourself. The lab gives you the corridor; you write the one line that is the backup.

In the lab's starter, the placeholder sets Vnew = r in place of r + gamma*(P @ V). What goes wrong?

Chapter 5

Why the Sweeps Settle

Run one sweep on two different guesses and measure how much closer they get

Why should sweeping settle at all, and on one answer? Take two guesses, x and y. Call one full sweep F: it takes a list of values and returns a new list. Call ‖x − y‖ the max-norm of the gap: the largest difference between the two lists over all squares.

Say it aloud

The largest gap between F of x and F of y is at most gamma times the largest gap between x and y.

‖F(x) − F(y)‖
the largest gap between F of x and F of y how far apart the two guesses are after one sweep.
≤
is at most smaller than or equal to.
γ
gamma the discount, 0.9: the shrink factor of each sweep.
‖x − y‖
the largest gap between x and y how far apart the two guesses were before.
In plain words

Sweep both guesses x and y once. The rewards are the same in both, so they cancel. What is left is gamma times an average of the old gaps, and an average is never above the largest gap.

With numbers

Square A under “always left”: one sweep maps a guess v to −1 + 0.9v. Guesses 0 and −20 become −1 and −19. The gap goes from 20 to 18, which is 0.9 × 20.

An update with this property is a contraction. The Banach fixed-point theorem then gives three facts:

  1. There is exactly one list of values that a sweep leaves unchanged: Vπ.
  2. Sweeps from any start reach it.
  3. After k sweeps, the error is at most γk times the first error.

Squeeze two guesses together

Two guesses for square A, 0 and −20, swept 30 times. Drag gamma and watch how fast the gap closes.

0.90

Illustrative: square A under “always left”, so a sweep maps v to −1 + gamma × v. The fixed point is −1/(1 − gamma).

After 10 sweeps at gamma 0.9 the gap is 20 × 0.910 = 6.97. To cut any error 100 times takes 44 sweeps at gamma 0.9, but 459 at gamma 0.99. The gamma that makes a robot patient also makes the sweeps slow. The full proof, with the max, is in Deep RL, Chapter 1; the optimality sweep is a contraction too.

The failure. You set gamma to 0.999 for a long task. The symptom: thousands of sweeps and values still moving. Measure the ratio of two changes in a row; it sits near gamma. The fix: score each plan exactly (Route 1) and use policy iteration, or use the smallest gamma the task allows.

The Bellman update is a gamma-contraction in the max-norm. What does that promise?

Chapter 6

Policy Improvement Picks the Best Move

Score every move with the old plan's values, and switch to the best one

You scored a plan π. Now make a better one. In each square, compute Qπ(s, a) for every move from the old values. Then switch to the move with the largest Q. Call the new plan π′ (pi-prime).

Say it aloud

Pi-prime of s equals the argmax over a of Q-pi of s and a.

π′(s)
pi-prime of s the new plan's move in square s.
argmaxa
the argmax over a the move that makes the score largest. On a tie, keep the old move.
Qπ(s, a)
Q-pi of s and a the old plan's worth of move a in square s, from Chapter 2.
In plain words

In each square s, compute Q-pi of s and a for every move a. Pick the move with the largest Q. If two moves tie, keep the move the old plan used.

With numbers

The old plan is “always left”, so V = −10 in A, B and C. At C: Q(C, right) = −1 + 0.9 × 0 = −1, and Q(C, left) = −1 + 0.9 × (−10) = −10. C switches to right. At B both moves give −10, a tie, so B keeps left.

The policy improvement theorem says Vπ′(s) ≥ Vπ(s) in every square. The reason: the first move is at least as good as the old one. The same holds again at the next square, and the next.

Improve a plan

Pick the old plan. Under each square, two bars show Q for left and right from the old values. Purple marks the new move; a grey “tie” keeps the old one.

Illustrative corridor, gamma 0.9, no slip. The device scores each old plan exactly before the greedy step.

When does improvement stop? When the greedy step gives back the same plan. Then Vπ(s) = maxa Qπ(s, a) in every square. That is the optimality equation from Chapter 3. So a plan that improvement cannot change is a best plan.

The failure. You break ties at random. Two moves with the same Q swap back and forth, so the plan changes on every round and the stop test never fires. Measure the number of switches where the Q gain is 0. The fix: switch only on a strict gain.

When does policy improvement stop changing the plan?

Chapter 7

Policy Iteration: Evaluate, Improve, Repeat

Alternate the two halves until the plan stops changing

You have both halves. Policy iteration runs them in a loop:

  1. Pick any plan π.
  2. Evaluate it: find Vπ (Chapter 4).
  3. Improve it: make the greedy plan from Qπ (Chapter 6).
  4. If the plan changed, go to step 2. If not, stop: it is a best plan.

Why must it stop? The corridor has 23 = 8 plans. Each round gives a plan at least as good as the last, and with strict-gain switches it never returns to an old plan. So it runs out of plans to try, and the only place it can stop is a best plan.

Run it from the worst plan, “always left”:

RoundPlan (A, B, C)V(A)V(B)V(C)Switches
1L, L, L−10−10−10C to R
2L, L, R−10−10−1B to R
3L, R, R−10−1.9−1A to R
4R, R, R−2.71−1.9−1none: stop

Round 3 at A: Q(A, right) = −1 + 0.9 × (−1.9) = −2.71 beats Q(A, left) = −10. Four evaluations, three improvements. The ties at A and B keep them on left until the dock's worth reaches them.

Run the loop by hand

Set a start plan with the buttons, then press Next step. It alternates evaluate and improve. Add slip and run it again.

Start plan:
0%

Illustrative corridor, gamma 0.9. Each evaluation is exact. With slip s, a move goes the other way with chance s.

You need not evaluate to the end before improving. Any mix of partial evaluation and improvement still climbs to the best plan. Sutton and Barto call this generalized policy iteration, and most RL methods have this shape.

The failure. Exact evaluation solves one linear equation per state, and its cost grows with the cube of the count. A 100 by 100 grid has 10,000 states: about 1012 steps per round. Measure the time per round. The fix: evaluate with a few sweeps only, then improve.

Why is policy iteration sure to stop at a best plan?

Chapter 8

Value Iteration Folds Improvement Into Each Sweep

Sweep the optimality equation directly, and read the best move off at the end

Policy iteration scores each plan fully before it improves once. That is many sweeps for a plan you will throw away. Value iteration skips the inner loop. It sweeps the optimality equation from Chapter 3 as an update:

Vk+1(s) ← maxa Σs′ p(s′|s, a) [ r(s, a) + γ Vk(s′) ]

The only change from policy evaluation is the max in front. Each sweep picks the best move on the fly, so it stores values only. The optimality sweep is also a gamma-contraction, so it settles on V* from any start.

SweepV(A)V(B)V(C)V(D)
1−1.00−1.00−1.000
2−1.90−1.90−1.000
3−2.71−1.90−1.000
4, no change−2.71−1.90−1.000

Sweep 2 at C: max(−1 + 0.9 × 0, −1 + 0.9 × (−1)) = max(−1, −1.9) = −1. At the end, read the best move: at C, Q(right) = −1 beats Q(left) = −2.71. The plan is “always right”, as policy iteration found.

When do you stop? Stop when the largest change in a sweep falls below a small number ε (epsilon). Then the error is at most ε × γ/(1 − γ). The plan is often right many sweeps before the values settle.

Watch the plan settle before the values

The yellow line is the largest change per sweep. The purple line marks the last sweep that changed the greedy plan. Drag slip and gamma.

20%
0.90

Illustrative corridor of five squares and a dock. Values start at 0; ties keep the move “left”. The run stops when the largest change falls below 0.001.

Policy iterationValue iteration
One roundfull evaluation, then a greedy stepone sweep with a max
Cost of a roundhighlow
Rounds neededfew (5 on the hero at 10% slip)many (18 sweeps there)
Keeps a plan during the runyesno, read it off at the end
AnswerV* and π*the same V* and π*

The failure. You stop when the change is below 0.01, with gamma 0.99. The symptom: the values look settled but are still off. Measure with the bound: the error can be up to 0.01 × 0.99/0.01 = 0.99. The fix: set ε from the error you can accept, ε = error × (1 − γ)/γ.

What is the one difference between the value iteration update and the policy evaluation update?

Chapter 9

The Field Guide

Keep the terms, the numbers, the code and the next steps in one place

A square is worth its next reward plus gamma times the worth of where it lands. Averaged over a fixed plan, that rule scores the plan. With a max, it describes the best plan. Policy iteration and value iteration both solve it, and both settle because each sweep shrinks every error by gamma.

TermWhat it isNumber on this page
Return Gtthe sum of rewards, each shrunk by gamma once per step of delay−2.71 from A, always right
Vπ(s)the average return from s under plan pi−10 everywhere under always left
Qπ(s, a)the average return after move a, then piQ*(A, left) = −3.439
Bellman expectationV as an average of reward plus gamma times next VV(C) = −1.342 at 20% slip
Bellman optimalitythe same with a max over movesV*(C) = max(−1, −2.71)
Contractioneach sweep shrinks the largest gap by gamma44 sweeps per 100 times at 0.9; 459 at 0.99
Policy iterationevaluate, improve, repeat until the plan stops4 rounds from always left
Value iterationsweep the optimality equation, read the plan at the end3 sweeps, plus 1 to confirm
Stopping ruleerror at most ε × gamma/(1 − gamma)0.99 for ε = 0.01, gamma 0.99

Checklist

The core, in code

pythonimport numpy as np
# P[a, s, s2] = chance that move a in state s lands in s2;  R[s, a] = reward
def q_values(V, P, R, gamma):
    return R + gamma * np.einsum('asn,n->sa', P, V)       # Q[s, a], shape (S, A)

def evaluate(pi, P, R, gamma, tol=1e-8):
    V = np.zeros(P.shape[1])
    while True:
        Vn = q_values(V, P, R, gamma)[np.arange(len(V)), pi]   # follow the plan
        if np.max(np.abs(Vn - V)) < tol: return Vn
        V = Vn

def policy_iteration(P, R, gamma):
    pi = np.zeros(P.shape[1], dtype=int)
    while True:
        V = evaluate(pi, P, R, gamma)
        Q = q_values(V, P, R, gamma)
        best = Q.argmax(1)
        keep = Q[np.arange(len(V)), best] <= Q[np.arange(len(V)), pi] + 1e-12
        new = np.where(keep, pi, best)                          # switch only on a strict gain
        if np.array_equal(new, pi): return pi, V
        pi = new

def value_iteration(P, R, gamma, eps=1e-3):
    V = np.zeros(P.shape[1])
    while True:
        Vn = q_values(V, P, R, gamma).max(1)                   # the optimality backup
        if np.max(np.abs(Vn - V)) < eps: return q_values(Vn, P, R, gamma).argmax(1), Vn
        V = Vn

What this page assumed

Keep going

Credit: Lecture 7 of CMU 16-831, Introduction to Robot Learning, taught by Guanya Shi. This page re-teaches the lecture's ideas in its own words, numbers and toys; it does not copy the slides.

The takeaway. A square is worth its next reward plus gamma times the worth of where it lands. Everything else on this page is a way to solve that sentence.

Now teach it back: open Present or Teach and derive the optimality equation, one policy iteration run and one value iteration sweep on the corridor. Then go back to the cliff walk and predict the route at 15% slip before you press Solve.

Value iteration stops when the largest change is below 0.001, with gamma 0.9. What is the most its values can still be off?
Introduction to Robot Learning · CMU 16-831 · Lecture 7
Lecture 6 · Lecture 8 · Back to Gleams