brain

tamnd's digital brain — notes, problems, research

41301 notes

TAOCP 4.5.2 Exercise 5

Let's carefully analyze the previous Python solution.

taocpmathematicsalgorithmsvolume-1math-hard
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 7

**Exercise 4.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.5.1 Exercise 6

**Solution.

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 3

Let a=\gcd(u,v'), \qquad b=\gcd(u',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 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 11

**Exercise 4.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.4 Exercise 12

Method 1b already provides the key idea.

taocpmathematicsalgorithmsvolume-1medium
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 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 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 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 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 19

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

taocpmathematicsalgorithmsvolume-1math-medium
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 18

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

taocpmathematicsalgorithmsvolume-1math-hard
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 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 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 14

**Exercise 4.

taocpmathematicsalgorithmsvolume-1math-simple
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 2

**Corrected Solution for Exercise 4.

taocpmathematicsalgorithmsvolume-1math-medium
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 1

Thank you, now the issue is fully clear.

taocpmathematicsalgorithmsvolume-1medium
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.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 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 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 8

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

taocpmathematicsalgorithmsvolume-1math-hard
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 5

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

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 6

Edit Let m=2^g-1.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 4

Equation (13) is obtained by the rule stated immediately before it.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.3.2 Exercise 3

Let m=\operatorname{lcm}(m_1,m_2,\ldots,m_r).

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.2 Exercise 2

We are asked whether Theorem C from _The Art of Computer Programming_ would still hold if the variables $a$, $u_1, u_2, \dots, u_r$, and $u$ were allowed to be arbitrary real numbers instead of intege...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.2 Exercise 1

Find all integers $u$ satisfying u \equiv 1 \pmod 7, \qquad u \equiv 0 \pmod{11}, \qquad

taocpmathematicsalgorithmsvolume-1project
TAOCP 4.3.1 Exercise 43

The desired value of $w$ is the nearest integer to $uv/255$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 40

Let $u$ be a $2n$-place number and $v$ an $n$-place number in base $b$, with $0 \le u < b^{2n}$, $0 \le v < b^n$, and assume $u = vq$ so the remainder is zero.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 42

Let u_i=(u_{i,n-1}\cdots u_{i,1}u_{i,0})_b, \qquad 0\le u_i<b^n, and let

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.3.1 Exercise 41

We are given a directed graph whose vertices are cities and whose root is city 1, the capital.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.1 Exercise 39

The solution attempts to prove the lower bound on the true remainder when the trial quotient $\hat q$ underestimates the true quotient $q$ by 1.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 38

Let $x = uv$, where $0 \le u,v < 2^n$.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.3.1 Exercise 36

Let \(\phi\) be given to \(n\) digits of precision in a fixed radix \(b\).

taocpmathematicsalgorithmsvolume-1
TAOCP 4.3.1 Exercise 37

In Algorithm D, step D1 multiplies both the dividend and the divisor by the same power of $b$ so that the leading digit of the divisor satisfies $v_{n-1} \ge \lfloor b/2 \rfloor$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 35

A correct design must first remove the ambiguity about what “word-level scaling” means and then express every operation in terms of explicit operations on fixed-size word arrays.

taocpmathematicsalgorithmsvolume-1project
TAOCP 4.3.1 Exercise 34

A correct solution must design algorithms, not analyze radix transformations.

taocpmathematicsalgorithmsvolume-1project
TAOCP 4.3.1 Exercise 32

**Solution to Exercise 4.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.3.1 Exercise 31

Assume first that $v \ne 0$.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.3.1 Exercise 30

In Algorithm A, each digit $w_j$ is computed from the expression $u_j + v_j + k$, where $k$ is the carry from the previous position.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 29

The claim is: > At the beginning of step D3 of Algorithm D, we always have $u_{j+n} = 0$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.3.1 Exercise 27

**Solution to Exercise 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 28

Let $v = (.v_{n-1}\,v_{n-2}\,\ldots v_1\,v_0)_b$ with $v_{n-1} \ne 0$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.1 Exercise 26

Step D8 in Program D performs the correction after an over-subtraction in the trial quotient step of the division algorithm.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 25

**Corrected Solution to Exercise 4.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.3.1 Exercise 24

Section 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 23

Let $b,v\in\mathbb{Z}$ with $1\le v<b$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 22

Let the dividend be $(u_3 u_2 u_1 u_0)_{10} = (8500)_{10}$ and the divisor be $(v_2 v_1 v_0)_{10} = (101)_{10}$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 20

**Solution to Exercise 4.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 21

Let $u$ and $v$ be positive integers with $n$ digits in base $b$, written in the notation of Exercises 19 and 20: u = u_{n-1} b^{\,n-1} + u_{n-2} b^{\,n-2} + \cdots + u_0, \qquad v = v_{n-1} b^{\,n-1}...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 19

In the setting of Fig.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 16

**Solution to Exercise 4.

taocpmathematicsalgorithmsvolume-1project
TAOCP 4.3.1 Exercise 18

The solution correctly addresses the exercise.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.1 Exercise 15

The solution correctly addresses the exercise.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 14

We prove the validity of Algorithm M by induction on the outer loop variable $j$, using the method of inductive assertions from Section 1.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 13

Let the multiplicand be stored in memory as U=(u_{n-1}\ldots u_1u_0)_b, with one digit per word, and let $v$ be a single precision number,

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 12

Exercise 4.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 9

Exercise 4.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 10

Program S represents the quantity $1+k$ in register A.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.3.1 Exercise 11

Compare the digits beginning with the most significant position.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.3.1 Exercise 7

Exercise 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.1 Exercise 8

Exercise 5 of section 4.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.3.1 Exercise 6

We are asked to design an algorithm that adds two numbers digit by digit from **most significant to least significant**, producing each output digit only when it cannot possibly be affected by future...

taocpmathematicsalgorithmsvolume-1medium