brain

tamnd's digital brain — notes, problems, research

41641 notes

TAOCP 4.5.3 Exercise 3

Let M_n = \begin{pmatrix} x_1 & 1 & 0 & \cdots & 0 \\ -1 & x_2 & 1 & & \vdots \\

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 2

We are asked to compute the product of the 2×2 matrices M_0 \cdot M_1 \cdot M_2 \cdots M_n, where

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.3 Exercise 1

First we verify that the proposed program is correct.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.2 Exercise 41

Let $m$ and $n$ be nonnegative integers.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 42

Let $n$ be a positive integer.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 38

Exercise 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 40

Let M=\max(|u|,|v|) at the moment Algorithm K begins.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 39

**Problem.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 37

**Solution.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 4.5.2 Exercise 36

The previous solution must be discarded.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 33

Let $H(a,b)$ denote the number of iterations of Harris's algorithm.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.5.2 Exercise 34

Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 4.5.2 Exercise 31

**Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 4.5.2 Exercise 32

Let $G$ be a continuous function on $[0,1]$ satisfying equations (36) and (37).

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.5.2 Exercise 30

We are asked to determine $G_2(x)$, the cumulative distribution function of the ratio r_2 = \frac{\min(u_2,v_2)}{\max(u_2,v_2)} after the second subtract-and-shift cycle of Algorithm B, continuing fro...

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.2 Exercise 29

Let R=\frac{\min(u,v)}{\max(u,v)}\in[0,1].

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 4.5.2 Exercise 28

Exercise 27 established equation (58), expressing $\psi_n$ in terms of Bernoulli numbers.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.2 Exercise 27

The proposed solution correctly identifies the probability requested: the probability that a single subtract-and-shift cycle produces an odd value $w$ in the range $[2^n,2^{n+1})$ while the other argu...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 26

Let \Delta(x)=2G(x)-5G(2x)+2G(4x).

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 24

We restart from the correct probabilistic model and explicitly connect the “next time step B6 is encountered” to Brent’s limiting distribution.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 25

Equation (46) in the text gives a relation between the series 1 + \rho_1 t + \rho_2 t^2 + O(t^3) and the exponential factor with a quadratic correction:

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 23

Solution to TAOCP 4.5.2 Exercise 23.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 21

Let Algorithm B denote the binary greatest common divisor algorithm (Stein’s algorithm) as described in Section 4.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.5.2 Exercise 22

Let $N$ be a positive integer.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 18

Algorithm L, as presented in Section 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 20

Let M=2^{n'}, \qquad \Omega=\{x:\; M\le x<2M,\; x\ \text{odd}\}.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.5.2 Exercise 19

The system is $3x + 7y + 11z = 1,$ $5x - 7y - 3z = 3.$ Eliminating $y$ by adding the two equations gives $8x + 8z = 4,$ hence

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.2 Exercise 17

We are asked to compute an integer $u'$ such that $u u' \equiv 1 \pmod{2^e},$ given that $u$ is odd, i.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 16

We are asked to find an integer $w$ satisfying u \equiv v w \pmod{m}, \quad 0 \le w < m, given positive integers $u$, $v$, $m$, with $v \perp m$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 15

The key correction is that Algorithm X never introduces a “reset” or “nullification” of its working variables at termination.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 14

Let $u$ and $v$ be random positive integers.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.2 Exercise 13

Let P=\Pr(\gcd(u,v)=1), where $u$ and $v$ are chosen uniformly from the odd positive integers.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.2 Exercise 12

Let $u$ and $v$ range uniformly over the integers $1 \le u, v \le n$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 9

We are asked to compute $\gcd(31408, 2718)$ using Algorithm B and then to find integers $m$ and $n$ such that $31408 \, m + 2718 \, n = \gcd(31408, 2718)$ using Algorithm X.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.5.2 Exercise 11

We correct both parts, and in particular replace the unjustified interchange of limit and infinite sum by a derivation that keeps all sums finite until the final asymptotic step.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 10

Let $q_n$ denote the number of ordered pairs $(u,v)$ with $1 \le u,v \le n$ and $\gcd(u,v)=1$.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.5.2 Exercise 8

Program B in Section 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 7

The exercise statement as given is incomplete.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 4

Let $u$ and $v$ be positive integers, with canonical prime factorizations u = \prod_{p \text{ prime}} p^{u_p}, \qquad v = \prod_{p \text{ prime}} p^{v_p}, where all but finitely many of the exponents...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 5

Let's carefully analyze the previous Python solution.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.2 Exercise 6

Let $u$ and $v$ be independent random positive integers chosen with uniform density over the positive integers.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 2

Assume first that $u=0$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 3

Let n = \prod_{p} p^{a_p} be the canonical prime factorization of $n$, where each $a_p \ge 0$ and all but finitely many $a_p$ are zero.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.1 Exercise 9

Suppose $1 \le u' < 2^k$ and $1 \le v' < 2^k$, and assume that $\lfloor 2^{2k} u/u' \rfloor = \lfloor 2^{2k} v/v' \rfloor.$ Let $x = 2^{2k} u/u'$ and $y = 2^{2k} v/v'$.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.2 Exercise 1

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.1 Exercise 8

Representing $(1/0)$ and $(-1/0)$ as $\infty$ and $-\infty$ corresponds to adjoining two signed points at infinity to the set of rational numbers.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.1 Exercise 6

**Solution.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.1 Exercise 7

**Exercise 4.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.1 Exercise 5

The recommended division method is the direct fraction-division algorithm.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.1 Exercise 4

Let \frac{u}{u'} \div \frac{v}{v'}, where $u \perp u'$ and $v \perp v'$.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.1 Exercise 1

The previous solution does not address the exercise at all.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.5.1 Exercise 3

Let a=\gcd(u,v'), \qquad b=\gcd(u',v).

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.1 Exercise 2

Let d=\gcd(u,v), and define

taocpmathematicsalgorithmsvolume-1
TAOCP 4.4 Exercise 18

Let $b$ and $B$ be the bases as in the problem statement.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.4 Exercise 19

Let $u = (u_7 \ldots u_1 u_0)_{10}$ be a decimal number, and let $U = (u_7 \ldots u_1 u_0)_{16}$ denote its binary-coded decimal (BCD) representation.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.4 Exercise 16

Let u=(u_m u_{m-1}\ldots u_1u_0)_{10} be the decimal number to be converted into binary notation.

taocpmathematicsalgorithmsvolume-1project
TAOCP 4.4 Exercise 15

Exercise 4.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.4 Exercise 17

The error in the previous code is actually two-fold: first, the test harness had a syntax error (a dangling comma in the last `assert`).

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.4 Exercise 13

The error in the previous code is actually two-fold: first, the test harness had a syntax error (a dangling comma in the last `assert`).

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 14

Let the input be an $n$-digit decimal integer N=\sum_{i=0}^{n-1} a_i 10^i, \qquad 0\le a_i\le 9.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.4 Exercise 10

Let $u$ be a nonnegative integer represented in binary-coded decimal (BCD) form as $u = u_{n-1} u_{n-2} \ldots u_1 u_0,$ where each $u_j$ occupies four bits and satisfies $0 \le u_j \le 9$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 11

**Exercise 4.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 12

Method 1b already provides the key idea.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 9

Define v_0(u)=3\lfloor u/2\rfloor+3, and

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.4 Exercise 8

Equation (5) shows how to replace division by $10$ with multiplication by an approximation to $\frac1{10}$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 7

Let \delta=r-\alpha .

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.4 Exercise 6

Methods 1a, 1b, 2a, and 2b are stated for positive radices $b$ and $B$.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.4 Exercise 3

The statement uses the symbol $\epsilon$ but the data are $u$ and $v$; the intended meaning is that $v$ is the allowed error bound.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 4

**Exercise 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.4 Exercise 5

A radix conversion routine transforms a nonnegative integer written in one base into its representation in another base.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.4 Exercise 1

Method 1b evaluates u=a_m b_{m-1}\cdots b_0+\cdots+a_1 b_0+a_0 by Horner's rule,

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 2

Let the mixed-radix system have radices r_0,r_1,\ldots,r_{n-1}, so that a number is represented in the form

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.3 Exercise 17

Let K_1=1,\qquad K_{2n}=3K_n,\qquad K_{2n+1}=2K_{n+1}+K_n \qquad (n\ge1).

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.3 Exercise 19

There is actually **no algorithmic bug** in the output you showed.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.3 Exercise 18

The error message is very explicit: `NameError: name 'math' is not defined`.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.3 Exercise 16

Start with the DFT \hat{u}_t=\sum_{s=0}^{K-1} u_s \,\omega^{st}, \quad \omega=e^{-2\pi i/K}.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.3 Exercise 15

We restart from a clean formulation and give a model-independent analysis of what “fastest online multiplication” means in each automaton class.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.3.3 Exercise 14

**Exercise 4.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 4.3.3 Exercise 12

**Solution (Corrected)** We are asked to implement the Fourier-transform multiplication method efficiently on a pointer machine and show that $m$-bit multiplication can be done in $O(m)$ steps.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.3.3 Exercise 11

Let the two $n$-bit numbers be A = \sum_{i=0}^{n-1} a_i 2^i, \quad B = \sum_{j=0}^{n-1} b_j 2^j.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.3 Exercise 10

**Corrected Solution** We want to show that all complex numbers $A^{(j)}$ computed during the third Fourier transform (the computation of $\tilde{w}_s$) satisfy $|A^{(j)}| < 1$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.3 Exercise 8

The statement is **false**.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.3 Exercise 7

Let $U(x)$ and $V(x)$ be polynomials of degree $r$ with integer coefficients, and let $W(x) = U(x)V(x),$ so $W(x)$ has degree at most $2r$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.3 Exercise 9

**Corrected Solution to Exercise 4.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 4.3.3 Exercise 6

We are asked to track a frog moving along a one-dimensional axis starting at position 0.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.3 Exercise 5

Let $\ell(n)$ denote the binary length of $n$, i.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.3.3 Exercise 4

**Exercise 4.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.3.3 Exercise 3

This is no longer a Codeforces 1535C input issue.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.3 Exercise 2

**Corrected Solution for Exercise 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 33

Let $x$ be an $n$-digit automorph, so the last $n$ digits of $x^2$ equal $x$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.3 Exercise 1

Thank you, now the issue is fully clear.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.2 Exercise 14

We are asked to compute w = (uv) \bmod (2^q - 1) for two $q$-bit integers $u$ and $v$ given in the mixed-radix representation

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 4.3.2 Exercise 12

The claimed output `10` for `"0?

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 4.3.2 Exercise 11

Let $m_1, m_2, \ldots, m_r$ be odd integers, and let $u = (u_1, \ldots, u_r)$ satisfy $0 \le u < m$, where $m = m_1 m_2 \cdots m_r$, and suppose that $u$ is even.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 10

Suppose an integer $u$ lies in the symmetrical range $-\frac{m}{2} < u < \frac{m}{2}, \qquad m = m_1 m_2 \cdots m_r, \eqno(10)$ and we seek numbers $u_1, \ldots, u_r$ such that $u \equiv u_j \pmod{m_j...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 9

From the construction of mixed-radix digits in (25), the integer $u$ is represented in the form u \equiv v_1 + m_1 v_2 + m_1 m_2 v_3 + \cdots + m_1 m_2 \cdots m_{r-1} v_r \pmod{m}, and for each $j$ th...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 7

Equation (24) in _The Art of Computer Programming_, Volume 2, Section 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.2 Exercise 8

The reviewer is correct that the previous submission is unrelated to the stated TAOCP exercise.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.2 Exercise 6

Edit Let m=2^g-1.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 5

The solution does not correctly determine the outcome of the greedy procedure in part (a).

taocpmathematicsalgorithmsvolume-1math-medium