Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 1

This is the first chapter of the book.

I’m putting some stuff here to test the rebuild process.

This is another sample paragraph to verify that the production site is updating as expected.

Chapter 2

This is the second chapter.

Here’s a test image:

Chapter 3

A third chapter that tests syntax highlighting.

Here’s some code

type Mat = list[list[int]]

def mat_reduce(m: Mat, q: int) -> Mat:
  '''return matrix in reduced-row eschelon form'''
  for i in range(len(m)):
    if m[i][i] != 1:
      # reduce row
      inv = pow(m[i][i], q - 2, q) # get inverse
      m[i] = [(v * inv) % q for (j, v) in enumerate(m[i])] # reduce

    for j in range(len(m)):
      if i != j:
        f = m[j][i]
        m[j] = [(m[j][k] - f * m[i][k]) % q for k in range(len(m[j]))]

  return m

def test_mat_reduce() -> None:
  '''test mat_reduce()'''
  tests: list[tuple] = [(
    [[1, 2, 3], [3, 4, 1]], # mat
    5, # q
    [[1, 0, 0], [0, 1, 4]], # exp
  ), (
    [[3, 4, 1], [1, 2, 3]], # mat
    5, # q
    [[1, 0, 0], [0, 1, 4]], # exp
  )]

  for (i, t) in enumerate(tests):
    val, q, exp = t
    assert mat_reduce(val, q) == exp, f'test {i} failed: {val=}, {exp=}'