brain

tamnd's digital brain — notes, problems, research

41641 notes

TAOCP 4.2.1 Exercise 8

We consider floating point arithmetic in the context of base-$b$ digits with normalized representation, following Section 4.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.2.1 Exercise 7

**Problem.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.2.1 Exercise 6

The answer is determined by the normalization routine used by FADD.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.2.1 Exercise 5

Let f_e=b^{p-2}F_e, where $F_e$ is an integer.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.2.1 Exercise 3

The proposed solution does **not** address the exercise that was asked.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.2.1 Exercise 4

We are asked to compute the result of Algorithm A for the given pairs of floating-point numbers in base $b=10$ with precision $p=8$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.2.1 Exercise 2

We are asked to determine the largest and smallest positive values representable in a base-$b$, excess-$q$, $p$-digit floating point system, both in general and under the _normalized_ constraint.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.1 Exercise 34

Let n=\sum_{i\ge0} a_i2^i, \qquad a_i\in\{-1,0,1\}.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.2.1 Exercise 1

In MIX floating point with byte size $100$, a number is represented as (\text{sign})\,(e,b_1,b_2,b_3,b_4), where

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.1 Exercise 31

Let u=(\ldots u_3u_2u_1u_0.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.1 Exercise 32

Let A=\left\{\sum_{i\ge 0}\varepsilon_i3^i:\varepsilon_i\in\{0,1\}\right\}, \qquad B=\left\{\sum_{j\ge 0}\delta_j5^j:\delta_j\in\{0,1\}\right\}.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.1 Exercise 33

Let S_n=\left\{\sum_{i=0}^{n-1} a_i3^i : a_i\in D=\{-1,0,3\}\right\}, and let

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.1 Exercise 29

Let ${T_0, T_1, T_2, \ldots}$ be a collection of sets of nonnegative integers that satisfies **Property B**; that is, every nonnegative integer $n$ can be written uniquely as n = t_0 + t_1 + t_2 + \cd...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.1 Exercise 30

Let b_0,b_1,b_2,\ldots be a binary basis, that is, every integer has a unique representation

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 4.1 Exercise 27

Let $n$ be a nonzero integer.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 28

Let $z = a + bi$ be a nonzero Gaussian integer, where $a, b \in \mathbb{Z}$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 26

A skater moves on horizontal ice with both skate blades in contact with the surface.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.1 Exercise 24

Let D_t=\{0,1,2,3,4,5,6,7,8,10+t\}, \qquad t=0,1,2,\ldots We shall prove that every $D_t$ satisfies conditions (i), (ii), and (iii).

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.1 Exercise 25

Let x=\frac{u}{v}, where $b\ge2$, $u>0$, $v>0$, and

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 21

Let the digit set be D=\left\{-\frac{9}{2},-\frac{7}{2},-\frac{5}{2},-\frac{3}{2},-\frac{1}{2},\frac{1}{2},\frac{3}{2},\frac{5}{2},\frac{7}{2},\frac{9}{2}\right\}.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 23

Let $D={d_1,\dots,d_b}\subset \mathbb{R}$ be a finite digit set with the property that every positive real number admits at least one representation of the form x=\sum_{k\le n} a_k b^k,\qquad a_k\in D...

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.1 Exercise 22

**Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.1 Exercise 20

**Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.1 Exercise 19

Let $D$ be a set of $b$ integers such that for each residue $j$ modulo $b$, there exists exactly one element $a \in D$ with a \equiv j \pmod{b}, \quad 0 \le j < b.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.1 Exercise 16

Let (a_n a_{n-1} \ldots a_1 a_0)_{i-1} = \sum_{j=0}^{n} a_j (i-1)^j be a number in the $(i-1)$-ary system, where each digit satisfies

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 18

Let $B = i - 1$ denote the base of the number system under consideration.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 4.1 Exercise 17

Let $\beta = i + 1$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.1 Exercise 14

Let the base be $2i$, as in the quater-imaginary system.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.1 Exercise 15

We correct the missing justification by giving a fully constructive expansion algorithm for the negative decimal system and then completing the standard argument for the quater-imaginary system.

taocpmathematicsalgorithmsvolume-1math-medium
CF 104664E - Riddle Me This (Easy Version)

We are given an even number of arrays, each array is a permutation of numbers from 1 to some common length $n$. The key operation allowed on any array is a cyclic rotation, where the last element moves to the front.

codeforcescompetitive-programming
TAOCP 4.1 Exercise 11

Let $(a_n \ldots a_1 a_0)_{-2}$ and $(b_n \ldots b_1 b_0)_{-2}$ be given, where each digit $a_i, b_i \in {0,1}$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.1 Exercise 13

Let the negadecimal base be $\beta = -10$ and digits be $0,1,\dots,9$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 12

A signed magnitude binary number $\pm(a_n \ldots a_1 a_0)_2$ represents an integer $N$ obtained by first forming the binary value A = \sum_{i=0}^{n} a_i 2^i and then setting $N = A$ if the sign is $+$...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.1 Exercise 10

Let a number be represented in _mixed-radix_ notation, that is, by a sequence of digits $(d_0, d_1, \ldots, d_{n-1})$ associated with radices $(b_0, b_1, \ldots, b_{n-1})$, where each $d_i$ satisfies...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 9

To convert an octal number to hexadecimal, we first expand each octal digit into a 3-bit binary block, concatenate all the blocks, and then regroup the resulting binary string into 4-bit blocks to obt...

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.1 Exercise 7

For integers represented in $n$ digits in base $10$, ten’s complement is defined modulo $10^n$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.1 Exercise 8

Let $F(x)$ be a distribution function as defined in Section 4.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 4.1 Exercise 6

Let $p$ denote the total number of bits.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.1 Exercise 5

Let $x$ be a nonnegative integer written with $n$ decimal digits.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.1 Exercise 4

We are asked to determine the position of the radix point in registers A and X after executing two sequences of MIX instructions, given that the operands in memory locations A and B have the radix poi...

taocpmathematicsalgorithmsvolume-1simple
TAOCP 4.1 Exercise 2

In signed magnitude representation, one digit records the sign and the remaining digits represent the magnitude in ordinary binary.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.1 Exercise 3

**Exercise 4.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 4.1 Exercise 1

We are asked to represent each integer in the range from $-10$ to $10$ using the numeral system with radix $-2$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.6 Exercise 14

Let X_n=(X_{n-37}+X_{n-100})\bmod 2 and define

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.6 Exercise 15

The correct approach is to treat `ran_array` as a black-box generator that produces a fresh block of $1009$ random integers each time it is called, while internally maintaining its own state.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.6 Exercise 12

The machine performs integer arithmetic only in the range $[-32768,.,.,32767]$, which corresponds to a word size of $2^{16}$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.6 Exercise 13

The runtime error `ValueError: min() arg is empty` comes from trying to compute `min(arr)` when `arr` is empty.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.6 Exercise 9

The previous solution failed because it replaced the actual structure of **run_array** with an unmotivated generic LFSR model.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.6 Exercise 10

The failure in the previous solution is that it reconstructs a plausible subtractive generator, but it does not faithfully translate the _actual control structure of the C `run_start`_, in particular...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.6 Exercise 11

Let $S = 2^{-30} = 1/m$, where $m = 2^{30} = \text{MM}$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.6 Exercise 7

Let X_{n+1} \equiv aX_n + c \pmod{2^{35}}, \qquad 0 \le X_n < 2^{35}, and the observed data be

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.6 Exercise 8

The original proposal correctly identified a sensible three-layer testing strategy, but it relied on an incorrect and oversimplified description of LCG period behavior.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.6 Exercise 6

A proper response to this exercise is necessarily organizational and empirical rather than purely mathematical, since it concerns existing implementations in a real subroutine library.

taocpmathematicsalgorithmsvolume-1project
TAOCP 3.6 Exercise 4

The exercise requires a concrete implementation that plays **two games**, uses a **specific random number generator**, shuffles a deck of cards, and prints all results in the indicated form.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.6 Exercise 5

This exercise is intentionally open-ended.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 3.6 Exercise 2

Lady Lovelace's statement is correct in the limited sense that a machine executes rules supplied by its designer.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.6 Exercise 3

We simulate the game commonly known as _craps_.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.5 Exercise 43

We are given a set of boxes, each containing some number of candies.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 3.6 Exercise 1

Method (1) of Section 3.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.5 Exercise 44

The runtime error in the previous testing framework occurs because the `solve()` function is defined in the global scope, but the `run()` helper function tries to call it inside a new `io.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.5 Exercise 41

\textbf{Let }p_j=P(A,H_j)\qquad(0\le j\le N), where $H_j$ is the hybrid source whose first $j$ bits come from $S$ and whose remaining $N-j$ bits are independent unbiased bits.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.5 Exercise 42

Let $X_1, \ldots, X_n$ be random variables with \mu = \mathrm{E}X_j, \qquad \sigma^2 = \mathrm{E}X_j^2 - (\mathrm{E}X_j)^2 \quad (1 \le j \le n), and assume that for $i \ne j$,

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.5 Exercise 40

We are asked to simulate a dynamic seating scenario.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.5 Exercise 39

Let $(X_n)$ be a binary sequence that is random according to Definition R6.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.5 Exercise 38

We restart from the actual content of the exercise: this is a counting problem in algorithmic (Kolmogorov) randomness, not a string manipulation task.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 3.5 Exercise 37

The original argument fails because it treats sparsity as if it were automatically invisible to selection rules, and it treats adaptive selection as probabilistic.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.5 Exercise 36

Let $(X_n)$ be a binary sequence that is random according to Definition R6.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 34

Exercise 31 shows that Definition R5 does not imply Definition R1.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.5 Exercise 33

Let ${U_n}$ be an infinite sequence, and let ${r_n}$ and ${s_n}$ be strictly increasing sequences of integers with no common elements, so that the subsequences ${U_{r_n}}$ and ${U_{s_n}}$ are disjoint...

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 35

We are asked to construct arrays called beautiful arrays.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 32

Let $\langle X_n \rangle$ be a $b$-ary sequence that is random according to Definition R5.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.5 Exercise 28

The failure of the previous solution comes from trying to _infer 3-distribution from digitwise uniformity of a single sequence_.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 29

Let $X_0, X_1, X_2, \ldots$ be a $(2k)$-distributed binary sequence.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 26

The proposed solution does address the actual exercise and identifies the key idea: each pair $(U_{2n-1},U_{2n})$ is transformed by either keeping it unchanged or swapping coordinates, depending on wh...

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 27

Let $B_n$ be the indicator of the event $V_n \ge \tfrac12$.

taocpmathematicsalgorithmsvolume-2
TAOCP 3.5 Exercise 25

Let $(U_n)$ be a $\{0,1\}$-valued sequence that is equidistributed in $[0,1)$.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 23

Let $(U_n)$ be a $[0,1)$ sequence.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.5 Exercise 24

Part (a) asks for a characterization of equidistribution in terms of the difference sequences $V_n^{(k)}=(U_{n+k}-U_n)\bmod 1,\qquad k>0.$ The statement to be proved is that $(U_n)$ is equidistributed...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.5 Exercise 22

Let $Y_n = (U_n, U_{n+1}, \ldots, U_{n+k-1}) \in [0,1)^k.$ By Definition B in Section 3.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 20

Let l_n^{(1)} \ge l_n^{(2)} \ge \cdots \ge l_n^{(n)} denote the lengths of the $n$ subintervals determined by the first $n$ points

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.5 Exercise 19

Let $U_0, U_1, \ldots$ be an infinite sequence of real numbers in $[0,1)$.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 18

Let V_n=\frac{\lfloor nU_n\rfloor}{n}.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 17

Let U_n = r^n \bmod 1, \qquad n \ge 0, where $r$ is a rational number.

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 3.5 Exercise 16

**Solution to Exercise 3.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.5 Exercise 15

Let Y_i=X_{f(n-1)+i}\qquad (i\ge 1).

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 14

Let $\langle U_n \rangle$ be an $\infty$-distributed sequence.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 13

Let $A_n=\{\alpha \le U_n < \beta\},\qquad p=\beta-\alpha.$ Since $(U_n)$ is $\infty$-distributed, it is $k$-distributed for every positive integer $k$.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 11

**Solution to Exercise 3.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.5 Exercise 12

Let $(U_n)$ be a $k$-distributed sequence.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 9

Lemma E states that if \lim_{n\to\infty}\frac1n\sum_{j=1}^n y_{jn}=a, \qquad \lim_{n\to\infty}\frac1n\sum_{j=1}^n y_{jn}^2=a^2,

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 10

The proof of Theorem C uses the hypothesis \(m \mid q\) at the point where one must show that the residue classes \[ 0,\; m,\; 2m,\; \ldots,\; \left(\frac{q}{m}-1\right)m \] are distinct modulo \(q\).

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 7

The answer is **No**.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.5 Exercise 8

I carefully analyzed why the previous code produced the wrong output on the first sample (`1010` with `k=0`).

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.5 Exercise 5

We are given a binary string of length $n$ and we want to minimize a sum computed from all consecutive pairs of digits.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 6

I analyzed the original solution carefully and identified the root cause of the wrong output.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.5 Exercise 4

Let A(n) = S(n) \land T(n), \qquad B(n) = S(n) \lor T(n), and, for $N \ge 1$, let

taocpmathematicsalgorithmsvolume-1hm-simple
TAOCP 3.5 Exercise 3

Let the ternary sequence be periodic with period $P$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.5 Exercise 2

Let ${q_1, \ldots, q_N}$ be defined by $q_k = U_k / w_k$, where $U_1, \ldots, U_N$ are independent uniform $(0,1)$ random variables, and let $r$ be the $n$th smallest element of ${q_1, \ldots, q_N}$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.5 Exercise 1

No.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.4.2 Exercise 19

Let a file of $N$ items be given, with positive weights $w_1, \ldots, w_N$.

taocpmathematicsalgorithmsvolume-1math-hard