text
stringlengths 2
132k
| source
dict |
|---|---|
from \( 1 \) to \( n + 1 - \left\lceil \frac{n+2}{3} \right\rceil \), each odd number up to the upper bound appears twice, and each even number up to the upper bound appears once. To show that this is indeed the minimum, note that each odd number can appear at most twice (once as an \( a_i \) and once as \( 2i-1 \)), and each even number can appear only once (as an \( a_i \)). Therefore, the minimum is achieved by greedily taking all the smaller numbers, i.e., two 1s, one 2, two 3s, and so on, which aligns with the described configuration. Thus, the minimum value of the sum is: \[ \sum_{i=1}^n \min \{ a_i, 2i-1 \}. \] The answer is: \boxed{\sum_{i=1}^n \min \{ n + 1 - i, 2i-1 \}}. | \sum_{i=1}^n \min \{ n + 1 - i, 2i-1 \} | china_team_selection_test | | [ "Mathematics -> Number Theory -> Prime Numbers" ] | 9 | Find all positive integers $a,b,c$ and prime $p$ satisfying that \[ 2^a p^b=(p+2)^c+1.\] | We need to find all positive integers \(a, b, c\) and a prime \(p\) that satisfy the equation: \[ 2^a p^b = (p+2)^c + 1. \] First, we note that \(p\) cannot be 2 because the left-hand side would be even, while the right-hand side would be odd. ### Case 1: \(a > 1\) Consider the equation modulo 4: \[ (p+2)^c + 1 \equiv 0 \pmod{4}. \] Since \(p\) is an odd prime, \(p+2\) is odd, and thus \((p+2)^c \equiv 3^c \pmod{4}\). For the equation to hold, \(c\) must be odd. Therefore, \(p+3\) must divide \(2^a p^b\). #### Subcase 1.1: \(p = 3\) If \(p = 3\), the equation becomes: \[ 2^a 3^b = 5^c + 1. \] Considering modulo 4, we get a
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
contradiction, so \(p \neq 3\). #### Subcase 1.2: \((p, p+3) = 1\) This implies \(p = 2^t - 3\). For both sides to match in terms of powers of 2, we analyze the \(v_2\) valuation: \[ v_2(2^a p^b) = a + b v_2(p). \] If \(a\) is even, there is no solution to \(x^2 = m^n + 1\) for positive integers \(x, m, n\) with \(m\) odd. If \(a\) is odd, we get: \[ 2^c + 1 \equiv 0 \pmod{p} \implies 2^{c+1} \equiv -2 \pmod{p}. \] This leads to a contradiction when considering the Legendre symbol \(\left(\frac{p}{3}\right) = 1\). ### Case 2: \(a = 1\) #### Subcase 2.1: \(p = 3\) The equation becomes: \[ 2 \cdot 3^b = 5^c + 1. \] If \(b \geq 2\), considering modulo 9, we get \(c = 6k + 3\), leading to \(7 \mid 2 \cdot 3^b\), a contradiction. Thus, \(b = 1\) and \(c = 1\), giving the solution: \[ (a, b, c, p) = (1, 1, 1, 3). \] #### Subcase 2.2: \(p \neq 3\) Considering modulo \(p+1\), we find that \(b\) is even. If \(c\) is odd, \(p+3 \mid 2p^b\), leading to a contradiction. Therefore, we are left with: \[ 2p^{2m} = (p+2)^{2n} + 1. \] After analyzing all cases, the only solution is: \[ (a, b, c, p) = (1, 1, 1, 3). \] The answer is: \boxed{(1, 1, 1, 3)}. | (1, 1, 1, 3) | china_team_selection_test | | [ "Mathematics -> Number Theory -> Congruences", "Mathematics -> Algebra -> Algebra -> Equations and Inequalities" ] | 7 | Find all pairs of positive integers $ (m,n)$ such that $ mn \minus{} 1$ divides $ (n^2 \minus{} n \plus{} 1)^2$. [i]Aaron Pixton.[/i] | To find all pairs of positive integers \((m, n)\) such that \(mn - 1\) divides
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\((n^2 - n + 1)^2\), we need to analyze the given condition and derive the solutions. First, let's denote \(d = mn - 1\). We need \(d\) to divide \((n^2 - n + 1)^2\). This implies: \[ d \mid (n^2 - n + 1)^2. \] We start by considering the trivial solution \((m, n) = (2, 2)\): \[ 2 \cdot 2 - 1 = 3 \quad \text{and} \quad (2^2 - 2 + 1)^2 = 3^2 = 9, \] which satisfies \(3 \mid 9\). Next, we explore other potential solutions. Suppose \((m, n)\) is a solution with \(2 < n < m\). We need to find \(k < n\) such that \((n, k)\) is also a solution. This requires: \[ (n^2 - n + 1)^2 \equiv -1 \pmod{n}. \] We analyze the inequalities: \[ n^2 - 1 \leq \frac{(n^2 - n + 1)^2}{mn - 1} \leq \frac{(n^2 - n + 1)^2}{n^2 - 1}. \] Simplifying, we get: \[ \frac{(n^2 - n + 1)^2}{n^2 - 1} \geq n^2 - 1 \implies n^2 - n + 1 \geq n^2 - 1 \implies n \leq 2. \] This implies that the solutions are limited to specific cases. By fixing initial values \(a_0\) and \(b_0\) with \(b_0 \leq 2\), we can generate all solutions using the recurrence relation: \[ (a_i, b_i)_{i=0}^{\infty} \quad \text{where} \quad a_i = b_{i+1}, \quad b_i = \frac{1}{b_{i+1}} \left[ \frac{(b_{i+1}^2 - b_{i+1} + 1)^2}{a_{i+1} b_{i+1} - 1} + 1 \right] \quad \forall \ i \in \mathbb{N}^*. \] By working through this recurrence, we find that the solutions are: \[ (m, n) = (2, 2) \quad \text{and} \quad (m, n) = (b_{\ell-1}, b_{\ell}), \ (b_{\ell}, b_{\ell+1}) \quad \forall \ \ell \in \mathbb{N}^*. \] Cleaning up the recurrence relation: \[ b_{i+2} = \frac{b_{i+1}^3 - 2b_{i+1}^2 + 3b_{i+1} + b_i - 2}{b_i b_{i+1} - 1}
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\quad \forall \ i \in \mathbb{N}^*, \quad b_0 = 2, \quad b_1 = 5, \] we get the sequence: \[ (b_i)_{i=0}^{\infty} = 2, 5, 10, 17, \ldots, \] which can be generalized as: \[ b_i = (i + 1)^2 + 1. \] Thus, the pairs \((m, n)\) that satisfy the condition are: \[ (m, n) = (2, 2) \quad \text{and} \quad (m, n) = ((i+1)^2 + 1, (i+2)^2 + 1) \quad \forall \ i \in \mathbb{N}. \] The answer is: \boxed{(2, 2) \text{ and } ((i+1)^2 + 1, (i+2)^2 + 1) \text{ for all } i \in \mathbb{N}}. | (2, 2) \text{ and } ((i+1)^2 + 1, (i+2)^2 + 1) \text{ for all } i \in \mathbb{N} | usa_team_selection_test | | [ "Mathematics -> Number Theory -> Factorization" ] | 9 | Given distinct positive integer $ a_1,a_2,…,a_{2020} $. For $ n \ge 2021 $, $a_n$ is the smallest number different from $a_1,a_2,…,a_{n-1}$ which doesn't divide $a_{n-2020}...a_{n-2}a_{n-1}$. Proof that every number large enough appears in the sequence. | Given distinct positive integers \( a_1, a_2, \ldots, a_{2020} \). For \( n \ge 2021 \), \( a_n \) is defined as the smallest number different from \( a_1, a_2, \ldots, a_{n-1} \) which does not divide \( a_{n-2020} \cdots a_{n-2} a_{n-1} \). We aim to prove that every sufficiently large number appears in the sequence. ### Proof: **Claim:** For sufficiently large \( n \), the least common multiple (LCM) of a set \( S \) of \( n \) natural numbers satisfies \( \text{lcm}(S) > n^{4040} \). This claim is intuitive and can be shown through detailed analysis, which is omitted here for brevity. **Claim:** The ratio \( \frac{a_n}{n} \) is bounded by a constant. **Proof:** Assume, for contradiction, that \( \frac{a_n}{n} \) is not bounded. Define a number \( t
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\) as "good" if \( \frac{a_t}{t} > \frac{a_s}{s} \) for all \( s ((r-1)t)^{4040} > (rt)^{2020} > a_{t-2020} a_{t-2019} \cdots a_{t-1} \). Since \( \text{lcm}(T) \nmid a_{t-2020} a_{t-2019} \cdots a_{t-1} \), there exists an element in \( T \) smaller than \( a_t \) that does not divide \( a_{t-2020} a_{t-2019} \cdots a_{t-1} \). This contradicts the definition of \( a_t \), as that element would have been chosen instead of \( a_t \). Therefore, \( \frac{a_n}{n} \) must be bounded by some constant \( c \). Now, assume for contradiction that there exists a sufficiently large number \( k \gg c \) that does not appear in the sequence. Let \( k \) have a sufficiently large prime power factor, say \( p^\alpha \gg c \). For all \( t > k \), since \( k \neq a_t \), \( p^\alpha \mid k \mid a_{t-2020} a_{t-2019} \cdots a_{t-1} \). This implies \( q = p^{\lceil \frac{\alpha}{2020} \rceil} \gg c \) divides one of the terms \( a_{t-2020}, a_{t-2019}, \ldots, a_{t-1} \). If \( a_t \) is divisible by \( q \), call \( t \) "friendly". For some \( n \gg k \), since at least \( n \) numbers in \( \{1, \ldots, k + 2020n\} \) are friendly, one of the numbers \( a_1, \ldots, a_{k + 2020n} \) is at least \( qn > kc + 2020cn \). This contradicts the claim that \( \frac{a_n}{n} \) is bounded by \( c \). Therefore, every sufficiently large number
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
must appear in the sequence. The answer is: \boxed{\text{Every sufficiently large number appears in the sequence}}. | \text{Every sufficiently large number appears in the sequence} | china_team_selection_test | | [ "Mathematics -> Number Theory -> Congruences", "Mathematics -> Applied Mathematics -> Statistics -> Probability -> Counting Methods -> Other" ] | 6.5 | Find the numbers of ordered array $(x_1,...,x_{100})$ that satisfies the following conditions: ($i$)$x_1,...,x_{100}\in\{1,2,..,2017\}$; ($ii$)$2017|x_1+...+x_{100}$; ($iii$)$2017|x_1^2+...+x_{100}^2$. | We are asked to find the number of ordered arrays \((x_1, x_2, \ldots, x_{100})\) that satisfy the following conditions: 1. \(x_1, x_2, \ldots, x_{100} \in \{1, 2, \ldots, 2017\}\), 2. \(2017 \mid (x_1 + x_2 + \cdots + x_{100})\), 3. \(2017 \mid (x_1^2 + x_2^2 + \cdots + x_{100}^2)\). To solve this problem, we generalize to an arbitrary prime \( p \) and use a classical roots of unity filter to count the number of such tuples. Let \(\omega = e^{\frac{2 \pi i }{p}}\) and \(N\) be the total number of such ordered tuples. The key observation is that: \[ \sum_{0 \leq a, b \leq p-1} \omega^{b(x_1 + x_2 + \cdots + x_{100}) + a (x_1^2 + x_2^2 + \cdots + x_{100}^2)} = \begin{cases} p^2 & \text{if } (x_1, x_2, \ldots, x_{100}) \text{ satisfies the conditions}, \\ 0 & \text{otherwise}. \end{cases} \] From this observation, we see that: \[ p^2 \cdot N = \sum_{(x_1, x_2, \ldots, x_{100})} \sum_{0 \leq a, b \leq p-1} \omega^{b(x_1 + x_2 + \cdots + x_{100}) + a (x_1^2 + x_2^2 + \cdots + x_{100}^2)}. \] Swapping the sums makes it easier to factor: \[ p^2 N = \sum_{0 \leq a, b \leq p-1} \left( \sum_{x=0}^{p-1} \omega^{ax^2 + bx} \right)^{100}. \] We deal with the edge case \(a = 0\) first. If \(b\) is nonzero, then \(1 + \omega^b + \omega^{2b} + \cdots + \omega^{(p-1)b} = 0\).
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
On the other hand, if \(b = 0\), then the sum evaluates to \(p\). Hence: \[ p^2 N = p^{100} + \sum_{\substack{1 \leq a \leq p-1 \\ 0 \leq b \leq p-1}} \left( \sum_{x=0}^{p-1} \omega^{ax^2 + bx} \right)^{100}. \] To relate the inner sums to Gauss sums, we complete the square: \[ p^2 N = \sum_{b=0}^{p-1} \sum_{a=1}^{p-1} \omega^{\frac{-b^2}{a}} \left( \sum_{x=0}^{p-1} \omega^{a(x + \frac{b}{2a})^2} \right)^{100}. \] Since \(\omega\) is a primitive \(p\)th root of unity, \[ \sum_{x=0}^{p-1} \omega^{a(x + \frac{b}{2a})^2} = \sum_{x=0}^{p-1} \omega^{ax^2}. \] For \(a\) not divisible by \(p\), define \(G(a) = \sum_{x=0}^{p-1} \omega^{ax^2}\) and denote \(G(1)\) by \(G\). We wish to compute \(G(a)\). Claim: \(G(a) = \left(\frac{a}{p}\right) G\). This follows from the properties of quadratic residues and non-residues. Since \(G(a)\) is raised to an even power, its sign does not matter. We need to evaluate \(G^{100}\). Claim: \(G^2 = (-1)^{\frac{p-1}{2}} p\). This follows from the properties of Gauss sums. Using Euler's Criterion, we conclude that \(G^2 = (-1)^{\frac{p-1}{2}} p\). Returning to our expression for \(N\): \[ p^2 N = p^{100} + \sum_{b=0}^{p-1} \sum_{a=1}^{p-1} \omega^{\frac{-b^2}{a}} G^{100}. \] Since the sum over \(a\) for fixed \(b\) evaluates to zero, we conclude: \[ N = p^{98}. \] Thus, for \(p = 2017\), the number of ordered arrays \((x_1, x_2, \ldots, x_{100})\) that satisfy the given conditions is: \[ \boxed{2017^{98}}. \] | 2017^{98} | china_team_selection_test | | [ "Mathematics -> Algebra -> Algebra -> Equations and Inequalities", "Mathematics -> Discrete Mathematics -> Combinatorics" ] | 7.5 | Let $n \ge 4$ be an integer. Find all functions $W : \{1, \dots, n\}^2 \to \mathbb R$ such that for every partition $[n] = A \cup B \cup C$ into disjoint sets, \[ \sum_{a \in A} \sum_{b \in B} \sum_{c \in C} W(a,b) W(b,c) = |A| |B| |C|. \] | Let \( n \ge 4
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\) be an integer. We need to find all functions \( W : \{1, \dots, n\}^2 \to \mathbb{R} \) such that for every partition \([n] = A \cup B \cup C\) into disjoint sets, the following condition holds: \[ \sum_{a \in A} \sum_{b \in B} \sum_{c \in C} W(a,b) W(b,c) = |A| |B| |C|. \] To solve this, we denote the function \( W \) by \( f \) for simplicity. We start by considering specific partitions of \([n]\). First, consider the partition \( P(\{1\}, \{2\}, \{3, 4, 5, \ldots\}) \): \[ f(1,2)f(2,4) + f(1,2)f(2,5) + \cdots + f(1,2)f(2,n) = (n-2) - f(1,2)f(2,3). \] Next, consider the partition \( P(\{1\}, \{3\}, \{2, 4, 5, \ldots\}) \): \[ f(1,3)f(3,4) + f(1,3)f(3,5) + \cdots + f(1,3)f(3,n) = (n-2) - f(1,3)f(3,2). \] Now, consider the partition \( P(\{1\}, \{2, 3\}, \{4, 5, \ldots\}) \): \[ f(1,2)f(2,4) + f(1,2)f(2,5) + \cdots + f(1,2)f(2,n) + f(1,3)f(3,4) + f(1,3)f(3,5) + \cdots + f(1,3)f(3,n) = 2(n-3). \] This simplifies to: \[ (n-2) - f(1,2)f(2,3) + (n-2) - f(1,3)f(3,2) = 2(n-3) \implies f(1,2)f(2,3) + f(1,3)f(3,2) = 2. \] Similarly, for any distinct \( a, b, c \): \[ f(a,b)f(b,c) + f(a,c)f(c,b) = 2. \] Considering \( P(\{3, 4, 5, \ldots\}, \{2\}, \{1\}) \), \( P(\{2, 4, 5, \ldots\}, \{3\}, \{1\}) \), and \( P(\{4, 5, \ldots\}, \{2, 3\}, \{1\}) \), we get: \[ f(3,2)f(2,1) + f(2,3)f(3,1) = 2, \] which generalizes to: \[ f(a,b)f(b,c) + f(b,a)f(a,c) = 2. \] Thus, we see that: \[ f(a,c)f(c,b) = f(b,a)f(a,c) \implies f(a,c) = 0 \quad \text{or} \quad f(c,b) = f(b,a). \] Suppose \( f(a,c) = 0 \) for some \( a \neq c \). Considering \( P(\{a\}, \{c\}, [n] - \{a,c\}) \), we get \( 0 = n-2 \), a contradiction. Hence, \( f(c,b) = f(b,a) \) for all distinct \(
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
a, b, c \). This implies that \( f(x,b) \) and \( f(b,x) \) are constants for each \( b \) and all \( x \neq b \). Consequently, \( f(x,y) \) is a constant \( k \) if \( x \neq y \). From the condition \( 2k^2 = 2 \), we find \( k = 1 \) or \( k = -1 \). Therefore, all solutions are of the form where \( W(a,a) \) can be any value, and for all distinct \( a, b \in [n] \), \( W(a,b) \) equals a constant \( k \), where \( k = 1 \) or \( k = -1 \). The answer is: \boxed{W(a,b) = k \text{ for all distinct } a, b \text{ and } k = 1 \text{ or } k = -1.} | W(a,b) = k \text{ for all distinct } a, b \text{ and } k = 1 \text{ or } k = -1. | usa_team_selection_test | | [ "Mathematics -> Algebra -> Abstract Algebra -> Field Theory" ] | 8.5 | Determine all $ f:R\rightarrow R $ such that $$ f(xf(y)+y^3)=yf(x)+f(y)^3 $$ | Determine all \( f: \mathbb{R} \rightarrow \mathbb{R} \) such that \[ f(xf(y) + y^3) = yf(x) + f(y)^3. \] Let \( P(x, y) \) denote the original proposition. First, we consider the constant solution. Clearly, the only constant solution is: \[ \boxed{f(x) = 0 \ \ \forall x \in \mathbb{R}}. \] Now, assume \( f \) is non-constant. From \( P(x, 0) \): \[ f(xf(0)) = f(0)^3 \quad \forall x \implies f(0) = 0 \text{ since } f \text{ is non-constant}. \] **Claim 1**: \( f(y^3) = f(y)^3 \) for all \( y \). **Proof**: From \( P(0, y) \): \[ f(y^3) = f(y)^3. \quad \blacksquare \] **Claim 2**: \( f
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\) is injective at 0. **Proof**: Suppose \( f(a) = 0 \) for some \( a \neq 0 \). Then from \( P(x, a) \): \[ af(x) = f(a^3) \implies f \text{ is constant, contradiction!} \quad \blacksquare \] **Claim 3**: \( f(1) = 1 \). **Proof**: From Claim 1, putting \( y = 1 \) gives \( f(1) = 0 \), \( -1 \), or \( 1 \). \( 0 \) can be ruled out by Claim 2. If \( f(1) = -1 \), then from \( P(x, 1) \): \[ f(1 - x) = f(x) - 1 \quad \forall x \implies f(x) = f(1 - (1 - x)) = f(1 - x) - 1 = f(x) - 2, \] which is absurd. Therefore, \( f(1) = 1 \). \(\quad \blacksquare \) **Claim 4**: \( f(x + 1) = f(x) + 1 \) for all \( x \). **Proof**: From \( P(x, 1) \). \(\quad \blacksquare \) Now, for any \( y, z \) with \( y \neq 0 \), we can choose an \( x \) such that \( z = xf(y) + y^3 \) by Claim 2. Then from \( P(x + 1, y) \): \[ \begin{align*} f(xf(y) + y^3 + f(y)) &= yf(x + 1) + f(y)^3 \\ \implies f(z + f(y)) &= yf(x) + f(y)^3 + y \ \ \dots \ \ \text{from Claim 4} \\ &= f(xf(y) + y^3) + y \ \ \dots \ \ \text{from } P(x, y) \\ \implies f(z + f(y)) &= f(z) + y. \end{align*} \] Clearly, the above holds when \( y = 0 \) as well, so call it \( Q(z, y) \). **Claim 5**: \( f(f(y)) = y \) for all \( y \). **Proof**: From \( Q(0, y) \). \(\quad \blacksquare \) Now, \( Q(z, f(y))
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\) along with Claim 5 implies: \[ f(y + z) = f(y) + f(z) \quad \forall y, z \implies f \text{ is additive}. \] Using the additivity in \( P(x, y) \), we get: \[ f(xf(y)) + f(y^3) = yf(x) + f(y)^3 \implies f(xf(y)) = yf(x), \] by Claim 1. Replacing \( y \) by \( f(y) \) in the above and using Claim 5, we get: \[ f(xy) = f(x)f(y) \quad \forall x, y \implies f \text{ is multiplicative as well}. \] It is well known that the only non-constant function which is both additive and multiplicative is: \[ \boxed{f(x) = x \ \ \forall x \in \mathbb{R}}. \] \(\quad \blacksquare\) | f(x) = 0 \ \ \forall x \in \mathbb{R} | china_team_selection_test | | [ "Mathematics -> Geometry -> Plane Geometry -> Other" ] | 7 | Find the smallest positive number $\lambda$, such that for any $12$ points on the plane $P_1,P_2,\ldots,P_{12}$(can overlap), if the distance between any two of them does not exceed $1$, then $\sum_{1\le i Discrete Mathematics -> Combinatorics" ] | 6 | There are $10$ birds on the ground. For any $5$ of them, there are at least $4$ birds on a circle. Determine the least possible number of birds on the circle with the most birds. | Given that there are 10 birds on the ground and for any 5 of them, there are at least 4 birds on a circle, we need to determine the least possible number of birds on the circle with the most birds. To solve this, consider the following steps: 1. **Initial Assumption**: Let \( n \) be the number of birds on the circle with the most birds. We need to find the minimum value of \( n \). 2. **Case Analysis**: - **Case \( n
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
= 10 \)**: All 10 birds are on the same circle. This trivially satisfies the condition. - **Case \( n = 9 \)**: Suppose 9 birds are on one circle and 1 bird is outside. For any 5 birds chosen, at least 4 must be on the circle. This condition is satisfied because any set of 5 birds will include at least 4 from the circle of 9. - **Case \( n Number Theory -> Factorization", "Mathematics -> Algebra -> Other" ] | 7 | Let $D_n$ be the set of divisors of $n$. Find all natural $n$ such that it is possible to split $D_n$ into two disjoint sets $A$ and $G$, both containing at least three elements each, such that the elements in $A$ form an arithmetic progression while the elements in $G$ form a geometric progression. | Let \( D_n \) be the set of divisors of \( n \). We need to find all natural numbers \( n \) such that it is possible to split \( D_n \) into two disjoint sets \( A \) and \( G \), both containing
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
at least three elements each, where the elements in \( A \) form an arithmetic progression and the elements in \( G \) form a geometric progression. We will analyze two main cases: ### Case 1: \( 1 \in A \) Suppose \( A = \{1, 1+k, 1+2k, \ldots, 1+mk\} \) for some integer \( k \). #### Subcase 1a: \( n \in A \) If \( n \in A \), then \( n = 1 + mk \) for some \( m \). However, this implies that \( n \) and \( 1 + (m-1)k \) are consecutive terms in the arithmetic progression, which leads to a contradiction because their greatest common divisor must be 1, but \( n \) is a multiple of \( k \). #### Subcase 1b: \( n \in G \) If \( G = \{s, sq, sq^2, \ldots, sq^z = n\} \), then the least common multiple of the elements in \( A \) must divide \( n \). If \( s = 1 \), then \( G \) contains \( 1 \), which contradicts the disjointness of \( A \) and \( G \). If \( s > 1 \), then \( q^{z-t} \) for \( t < z \) must belong to \( A \), but this leads to further contradictions regarding the divisibility and properties of the elements in \( A \) and \( G \). ### Case 2: \( 1 \in G \) Suppose \( G = \{1, q, q^2, \ldots, q^d\} \). #### Subcase 2a: \( n \in G \) If \( n = q^d \), then \( q \) must not be prime, as otherwise \( A \) and \( G \) would not be disjoint. Let \( t \) be the smallest divisor of \( q \)
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
greater than 1. Then \( A \) must contain \( t \) and other elements forming an arithmetic progression. However, this leads to contradictions regarding the divisibility and properties of the elements in \( A \) and \( G \). #### Subcase 2b: \( n \in A \) If \( n \in A \), then for some \( k \), \( n - k \in A \). This implies \( n - k \) divides \( n \), leading to \( n - k \leq k \), which implies \( |A| \leq 2 \), contradicting the requirement that \( A \) must contain at least three elements. After analyzing all possible cases, we conclude that there are no natural numbers \( n \) that satisfy the given conditions. The answer is: \boxed{\text{No such } n \text{ exists}}. | \text{No such } n \text{ exists} | china_national_olympiad | | [ "Mathematics -> Algebra -> Algebra -> Algebraic Expressions", "Mathematics -> Algebra -> Algebra -> Equations and Inequalities" ] | 8 | $x$, $y$ and $z$ are positive reals such that $x+y+z=xyz$. Find the minimum value of: \[ x^7(yz-1)+y^7(zx-1)+z^7(xy-1) \] | Given that \( x \), \( y \), and \( z \) are positive reals such that \( x + y + z = xyz \), we aim to find the minimum value of: \[ x^7(yz-1) + y^7(zx-1) + z^7(xy-1). \] First, we use the given condition \( x + y + z = xyz \). By the AM-GM inequality, we have: \[ xyz = x + y + z \geq 3\sqrt{xyz}, \] which implies: \[ xyz \geq 3\sqrt{3}. \] Now, consider the given expression: \[ x^7(yz-1) + y^7(zx-1) + z^7(xy-1). \] Rewriting it, we get: \[ x^7(yz-1) + y^7(zx-1) + z^7(xy-1) = x^6(xyz - x) + y^6(xyz - y) +
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
z^6(xyz - z). \] This simplifies to: \[ x^6(xyz) + y^6(xyz) + z^6(xyz) - (x^7 + y^7 + z^7). \] Factoring out \( xyz \) from the first part, we get: \[ (x^6 + y^6 + z^6)xyz - (x^7 + y^7 + z^7). \] Using the given \( xyz = x + y + z \), we can rewrite it as: \[ (x^6 + y^6 + z^6)(x + y + z) - (x^7 + y^7 + z^7). \] Expanding this, we have: \[ (x^7 + y^7 + z^7) + (x^6y + xy^6 + x^6z + xz^6 + y^6z + yz^6) - (x^7 + y^7 + z^7). \] This simplifies to: \[ x^6y + xy^6 + x^6z + xz^6 + y^6z + yz^6. \] By the AM-GM inequality, we know: \[ x^6y + xy^6 + x^6z + xz^6 + y^6z + yz^6 \geq 6\sqrt{(xyz)^{14}}. \] Given \( xyz \geq 3\sqrt{3} \), we have: \[ 6\sqrt{(3\sqrt{3})^{14}} = 6\sqrt{3^{21}} = 6 \cdot 3^{7/2} = 6 \cdot 27\sqrt{3} = 162\sqrt{3}. \] Therefore, the minimum value is: \[ \boxed{162\sqrt{3}}. \] This minimum is achieved when \( x = y = z = \sqrt{3} \). | 162\sqrt{3} | china_team_selection_test | | [ "Mathematics -> Algebra -> Algebra -> Polynomial Operations", "Mathematics -> Discrete Mathematics -> Combinatorics" ] | 7 | Determine whether or not there exist two different sets $A,B$, each consisting of at most $2011^2$ positive integers, such that every $x$ with $0 < x < 1$ satisfies the following inequality: \[\left| \sum_{a \in A} x^a - \sum_{b \in B} x^b \right| < (1-x)^{2011}.\] | We aim to determine whether there exist two different sets \( A \) and \( B \), each consisting of at most \( 2011^2 \) positive integers, such that for every \( x \) with \( 0 < x <
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
1 \), the following inequality holds: \[ \left| \sum_{a \in A} x^a - \sum_{b \in B} x^b \right| 2011^{4022} \prod_{k=1}^{2011} \binom{N}{k}. \] By the pigeonhole principle, there exist sets \( A \) and \( B \) satisfying the required conditions. Hence, such sets \( A
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\) and \( B \) do exist. The answer is: \boxed{\text{Yes}}. | \text{Yes} | usa_team_selection_test | | [ "Mathematics -> Algebra -> Intermediate Algebra -> Exponential Functions", "Mathematics -> Algebra -> Intermediate Algebra -> Other" ] | 7 | Determine whether $\sqrt{1001^2+1}+\sqrt{1002^2+1}+ \cdots + \sqrt{2000^2+1}$ be a rational number or not? | To determine whether the sum \(\sqrt{1001^2+1}+\sqrt{1002^2+1}+ \cdots + \sqrt{2000^2+1}\) is a rational number, we assume for the sake of contradiction that it is rational. Since \(\sqrt{k}\) is an algebraic integer for each positive integer \(k\) and algebraic integers are closed under addition, the given expression must be an algebraic integer. If we assume it is rational, it must be an integer. Consider the expression: \[ S = (\sqrt{1001^2 + 1} - 1001) + (\sqrt{1002^2+1}-1002) + \cdots + (\sqrt{2000^2+1} - 2000). \] Each term \(\sqrt{k^2+1} - k\) can be approximated as: \[ \sqrt{k^2+1} - k = \frac{1}{\sqrt{k^2+1} + k} Algebra -> Algebra -> Algebraic Expressions" ] | 7.5 | For each positive integer $ n$, let $ c(n)$ be the largest real number such that \[ c(n) \le \left| \frac {f(a) \minus{}
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
f(b)}{a \minus{} b}\right|\] for all triples $ (f, a, b)$ such that --$ f$ is a polynomial of degree $ n$ taking integers to integers, and --$ a, b$ are integers with $ f(a) \neq f(b)$. Find $ c(n)$. [i]Shaunak Kishore.[/i] | For each positive integer \( n \), let \( c(n) \) be the largest real number such that \[ c(n) \le \left| \frac{f(a) - f(b)}{a - b} \right| \] for all triples \( (f, a, b) \) such that: - \( f \) is a polynomial of degree \( n \) taking integers to integers, and - \( a, b \) are integers with \( f(a) \neq f(b) \). To find \( c(n) \), we claim that \( c(n) = \frac{1}{L_n} \), where \( L_n = \text{lcm}(1, 2, 3, \ldots, n) \). First, note that any polynomial \( f(X) \) that maps the integers to the integers can be represented as: \[ f(X) = c_0 + c_1 \binom{X}{1} + c_2 \binom{X}{2} + \cdots + c_n \binom{X}{n}. \] ### Lemma 1 \( L_n \cdot \frac{\binom{a}{n} - \binom{b}{n}}{a - b} \in \mathbb{Z} \). **Proof:** Consider the polynomial \( g(X) = \binom{X + b}{n} - \binom{b}{n} \). This polynomial can be written as: \[ g(X) = d_1 \binom{X}{1} + \cdots + d_n \binom{X}{n}. \] Using the identity \( \frac{1}{X} \binom{X}{n} = \frac{1}{n} \binom{X-1}{n-1} \), the denominator of \( \frac{g(X)}{X} \) must have size at most \( L_n \). Thus, \( L_n \cdot \frac{g(X)}{X} \in \mathbb{Z} \), proving the lemma. \( \blacksquare \) Now, consider: \[ T = \frac{f(a) - f(b)}{a - b} = \sum_{k=0}^n c_k \frac{\binom{a}{k} - \binom{b}{k}}{a - b}. \] In particular, for each prime \( p \), \[ v_p \left( c_k \frac{\binom{a}{k} - \binom{b}{k}}{a - b} \right) \ge -v_p(L_k) \ge -v_p(L_n), \] so \( v_p(T) \ge -v_p(L_n) \). Therefore,
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\( T \cdot L_n \in \mathbb{Z} \). If \( T \neq 0 \), then \( T \ge \frac{1}{L_n} \), establishing a lower bound on \( c(n) \). To show that this lower bound is attainable, consider a suitable choice of \( c_i \) such that: \[ \frac{f(N!) - f(0)}{N!} = \frac{1}{L_n} \] for large \( N \). Note that: \[ \frac{\binom{N!}{k} - \binom{0}{k}}{N! - 0} = \frac{\binom{N!}{k}}{N!} = \frac{\binom{N! - 1}{k - 1}}{k}. \] No prime less than or equal to \( k \) divides \( \binom{N! - 1}{k - 1} \), as the expression can be written as \( \prod_{i=1}^{k-1} \frac{N! - i}{i} \) and \( \gcd \left( \frac{N! - i}{i}, L_k \right) = 1 \) for large \( N \) and \( k \le n \). Therefore: \[ \frac{f(N!) - f(0)}{N! - 0} = \sum_{k=0}^n \frac{c_k t_k}{k} \] for \( \gcd(t_k, k) = 1 \) fixed and some \( c_k \). By Bézout's identity, we can choose suitable \( c_i \) such that the expression equals \( \frac{1}{L_n} \). Thus, we conclude that: \[ c(n) = \frac{1}{L_n}. \] The answer is: \boxed{\frac{1}{L_n}}. | \frac{1}{L_n} | usa_team_selection_test | | [ "Mathematics -> Number Theory -> Prime Numbers" ] | 7 | An integer partition, is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition. [quote]For example, 4 can be partitioned in five distinct ways: 4 3 + 1 2 + 2 2 + 1 + 1 1 + 1 + 1 + 1[/quote] The number of partitions of n is given by the partition function $p\left ( n \right )$. So $p\left ( 4 \right ) = 5$ . Determine all the positive integers so that $p\left ( n \right )+p\left
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
( n+4 \right )=p\left ( n+2 \right )+p\left ( n+3 \right )$. | We need to determine all positive integers \( n \) such that \[ p(n) + p(n+4) = p(n+2) + p(n+3), \] where \( p(n) \) denotes the partition function, which counts the number of ways \( n \) can be partitioned into positive integers. To solve this, we consider the equivalent equation by setting \( N = n + 4 \): \[ p(N) + p(N-4) = p(N-1) + p(N-2). \] We analyze the behavior of the partition function using coarse partitions. A partition of \( n \) is called coarse if all parts are at least three. Let \( q(n) \) denote the number of coarse partitions of \( n \). By generating functions, we derive the following identity for \( N \geq 5 \): \[ p(N) + p(N-4) - p(N-1) - p(N-2) = q(N) - q(N-3) - q(N-5) - q(N-7) - q(N-9) - \dots. \] We then examine the cases for odd and even \( N \): 1. **Odd \( N \geq 5 \)**: \[ q(N) \leq q(N-3) + q(N-5) + q(N-7) + \dots, \] with equality if and only if \( N = 5, 7, 9 \). 2. **Even \( N \)**: - For \( N \in \{6, 8, 10, 12\} \): \[ q(N) - 1 = q(N-3) + q(N-5) + q(N-7) + \dots. \] - For \( N \geq 14 \): \[ q(N) < q(N-3) + q(N-5) + q(N-7) + \dots. \] From the above analysis, we find that the only solutions to the equation are \( N = 5, 7, 9 \). Converting back to the original variable \( n \) using \( N = n + 4 \), we obtain the solutions: \[ n = 1, 3, 5. \] The answer is:
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
\boxed{1, 3, 5}. | 1, 3, 5 | china_team_selection_test | | [ "Mathematics -> Discrete Mathematics -> Combinatorics", "Mathematics -> Algebra -> Prealgebra -> Integers" ] | 6 | Given is an $n\times n$ board, with an integer written in each grid. For each move, I can choose any grid, and add $1$ to all $2n-1$ numbers in its row and column. Find the largest $N(n)$, such that for any initial choice of integers, I can make a finite number of moves so that there are at least $N(n)$ even numbers on the board. | Given an \( n \times n \) board, with an integer written in each grid, we aim to find the largest \( N(n) \) such that for any initial choice of integers, it is possible to make a finite number of moves so that there are at least \( N(n) \) even numbers on the board. Each move consists of choosing any grid and adding 1 to all \( 2n-1 \) numbers in its row and column. The answer is: \[ N(n) = \begin{cases} n^2 - n + 1 & \text{if } n \text{ is odd}, \\ n^2 & \text{if } n \text{ is even}. \end{cases} \] We will consider everything modulo 2. ### Case 1: \( n \) is odd Firstly, we show that if \( n \) is odd, then \( N(n) \leq n^2 - n + 1 \). Let \( r_1, r_2, \ldots, r_n \) and \( c_1, c_2, \ldots, c_n \) be the sums of numbers in the rows and columns, respectively. Notice that in each operation, all of these variables change from 0 to 1 or vice versa. Therefore, if the initial configuration is: \[ \begin{pmatrix} 0 & 1 & 1 & \cdots & 1 \\ 0 & 0 &
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
0 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & 0 \end{pmatrix} \] then we have \((r_1, \ldots, r_n, c_1, \ldots, c_n) = (0, \ldots, 0, 0, 1, \ldots, 1)\). After one operation, this vector becomes \((1, \ldots, 1, 1, 0, \ldots, 0)\), and \((0, \ldots, 0, 0, 1, \ldots, 1)\) after another operation. Hence, there are at least \( n-1 \) odd numbers every time. ### Case 2: \( n \) is even We will show that the claimed value of \( N(n) \) is attainable. **Claim:** It is possible to change the parity of one cell and fix all other numbers on the board. **Proof:** By symmetry, assume this cell is the top left corner. Notice that by applying the operation to any \( n \) cells, none of which lie in the same row or column, the parity of these \( n \) cells is changed while all other numbers on the board are fixed. Call this operation \( II \). Denote the cell in the \( i \)-th row and \( j \)-th column by \((i, j)\). Now, apply operation \( II \) to each of the following \( n \)-tuples: \[ (1,1), (i,1), (1,i), \ldots, (i-1,i-1), (i+1,i+1), \ldots, (n,n), \quad 2 \leq i \leq n. \] Then all the cells in the first column and first row except the bottom left corner are changed while the other cells are fixed. Apply the given operation to the bottom left corner, and we are done. \(\blacksquare\) Now, suppose \( n \) is odd. Apply the algorithm for even numbers to the bottom right \((n-1) \times (n-1)\) sub-board. If the first column and first row contain fewer than \( n-1 \) odd numbers, then
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
we are done. Otherwise, apply an operation to the top left corner, and we are done. The answer is: \(\boxed{\begin{cases} n^2 - n + 1 & \text{if } n \text{ is odd}, \\ n^2 & \text{if } n \text{ is even}. \end{cases}}\). | \begin{cases} n^2 - n + 1 & \text{if } n \text{ is odd}, \\ n^2 & \text{if } n \text{ is even}. \end{cases} | china_national_olympiad | | [ "Mathematics -> Discrete Mathematics -> Algorithms" ] | 7.5 | $101$ people, sitting at a round table in any order, had $1,2,... , 101$ cards, respectively. A transfer is someone give one card to one of the two people adjacent to him. Find the smallest positive integer $k$ such that there always can through no more than $ k $ times transfer, each person hold cards of the same number, regardless of the sitting order. | Given 101 people sitting at a round table, each holding a unique card numbered from 1 to 101, we need to determine the smallest positive integer \( k \) such that through no more than \( k \) transfers, each person can hold the same number of cards, regardless of the initial sitting order. To find the smallest \( k \), we consider the value \( S \) defined as: \[ S = \sum_{i=1}^{51} i a_i + \sum_{i=1}^{50} i b_i, \] where \( a_i \) represents the number of cards held by people in odd positions (1, 3, 5, ..., 101) and \( b_i \) represents the number of cards held by people in even positions (2, 4, 6, ..., 100). Initially, the value of \( S \) at the internal position is: \[ S = \sum_{i=1}^{51} i (2i-1) + \sum_{i=1}^{50} 2i^2. \] At the terminal position, where each person has the same
|
{
"page_id": null,
"source": 6821,
"title": "from dpo"
}
|
number of cards, the value of \( S \) is: \[ S = \sum_{i=1}^{51} 51i + \sum_{i=1}^{50} 51i. \] The change in \( S \), denoted as \( \Delta S \), is: \[ \Delta S = 42925. \] Since each transfer changes the value of \( S \) by at most 1 (either increasing or decreasing it by 1), it follows that at least 42925 steps are required to equalize the number of cards held by each person. Therefore, the smallest positive integer \( k \) such that each person can hold the same number of cards through no more than \( k \) transfers is: \ \boxed{42925}. | 42925 | china_team_selection_test | [ rightly along with it. Although FEs from !Image 1: $\mathbb{R}$: p^2+f(p) \mid pf(p)+p =>p^2+f(p) \mid pf(p) +p-pf(p)-p^3$]( !Image 5: $=> p^2+f(p) \mid p(p^2-1)$ \mid p^2-1$]( which is of course not possible. Thus !Image 9: $f(p)=kp$ ,(m,1)$: m^2+f(1) \mid mf(m)+1$]( (which also implies !Image 14: $m(f(m)-m) \geq f(1)-1$: 1+f(n) \mid f(1)+n$]( (which also implies !Image 16: $f(1)-1 \geq f(n)-n$$]( now gives us: !Image 18: $P(1,p): 1+kp \mid f(1)+p=>1+kp \mid kf(1)+kp$-1$]( Here we first glimpse of the true power of playing with primes- there are an infinite number of them! Speaking specifically, we can make them as large as we want, and thus- As we can make our !Image 20: $\text{LHS}$+p \geq kp+1$]( for arbitrarily large !Image 22: $p$-1 \geq (k-1)p =>f(1)=1$]( Now, as !Image 24: $f(1)-1 \geq f(n)-n =>n \geq f(n)$-m) \geq f(1)-1 =>f(m) \geq m => f(m)=m$]( for all !Image 26: $m$-n$]( is certainly not trivial to think of, but it can certainly be classified as semi-standard. No, there were exactly 2 tipping points: 1. Noticing how useful the !Image 28: $(p,p)$ harder problems). Ah, so this was quite a good problem,
|
{
"page_id": null,
"source": 6823,
"title": "from dpo"
}
|
but time to move on (to USAMO 2012 P4!): Remember how forcing something to be zero by using the infinite-ness of primes played out for us last time- this problem has a very similar feel to it, no? It doesn't turn out to be based on primes basically at all, but it hammers the second turning point for our N1 home: Let's start with the obvious- using !Image 29: $f(m!)=f(m)!$=1$]( or !Image 31: $2$=1/2$]( (from now on, I will use this to mean !Image 33: $1$!,1)$]( (which didn't turn out to be that useful as a general statement, unfortunately, but set us on the right track), giving us: !Image 36: $$P((p-2)!,1):(p-2)!-1 \mid f(p-2)!-1/2$$!-1/2=>f(p-2) \leq p-2$]( by Wilson's, which, unfortunately doesn't give up too much about the problem; but it never hurts to play around with what we've got, so let's see what happens when we put in small primes- well, !Image 38: $p=5$! -(1/2)$]( (here !Image 41: $1/2$$]( can either be !Image 45: $1$=1/2$]( our problem boils down instantly, as you might expect- If !Image 49: $f(3)=1/2$=f(n)!$]( and !Image 51: $1/2!=1/2$$]( for arbitrarily large !Image 53: $m_0$: m_0-n \mid f(n)-1/2$]( thus !Image 56: $f \equiv k$=3$]( Again, by =m_0$: m_0-n \mid m_0-f(n)=>m_0-n \mid f(n)-n$]( and !Image 66: $m_0$=n$]( for all !Image 68: $n$ \leq p-2$]( and substituted !Image 73: $p=5$$]( Another one, and the one which hammered home the importance of making something arbitrarily large while keeping a quantity either invariant or at least bounded, hence forcing our RHS to become zero. Well, till now we've only dealt with N1s and USAMO P4s- perhaps you aren't convinced, as there were other clean ways to attack these problems too: Watch as we take down a monster of an N6, purely by POP: ISL 2016 N6 wrote: It'd be quite hard to share the motivations for each step in an N6, so (try the problem first!, then) let's just follow along: First let's get over with the obvious substitutions- !Image 75: $P(m,m): 2f(m)-m^2 \mid 2mf(m) => 2f(m)-m^2 \mid m^3$-1 \mid 1 => f(1)=1$]( !Image 78: $P(m,1): f(m)-m+1 \mid m^2-m+1 -m(f(m)-m+1) =>f(m)-m+1 \mid m^2-m+1$ \leq m^2)$]( Time to spam our first technique of POP, eh? For !Image 80: $p$: 2f(p) -p^2 \mid p^3$]( Hey this seems pretty useful- it means !Image 82: $2f(p)-p^2$$](
|
{
"page_id": null,
"source": 6823,
"title": "from dpo"
}
|
Well, we've got nothing much else to do, and it pretty much seems like !Image 84: $f(x)=x^2$-m+1 \mid m^2-m+1$]( (and I promise it gets easier as you go through the cases) Case 1: !Image 86: $2f(p)-p^2=1 =>f(p)=\frac{p^2+1}{2}$-p^2 =-1 => f(p)=\frac{p^2-1}2$]( Thus !Image 89: $\frac{p^2-1}2 -p+1 \mid p^2-p+1 =>p^2-2p+1 \mid 2p^2-2p+1-2(p^2-2p+1) =>p^2-2p+1 \mid 2p-1 \neq$-p^2=p=>f(p)=\frac{p^2+p}2$]( Thus !Image 92: $\frac{p^2+p}2 -p+1 \mid p^2-p+1=>p^2-p+2 \mid 2p^2-2p+2 =>p^2-p+2 \mid 2 \neq$-p^2=-p =>f(p)=\frac{p^2-p}2$]( Thus !Image 94: $\frac{p^2-p}{2} -p+1 \mid p^2-p+1 =>p^2-3p+2 \mid 2p^2-2p+2 =>p^2-3p+2 \mid 4p-2 \neq$-p^2=-p^2 =>f(p)=0 \neq$]( possible. Case 6: !Image 97: $2f(p)-p^2 =+-p^3$-p^2=-p^3=>f(p)=\frac{p^2-p^3}2 f(m)-mp+p^2 \mid p^2-mp+m^2$-mp+p^2 \mid m^2-f(m)$]( Notice that we can choose arbitrarily large !Image 114: $p$$]( becomes
|
{
"page_id": null,
"source": 6823,
"title": "from dpo"
}
|
arbitrarily large while !Image 116: $m^2-f(m)$-m^2$]( must equal !Image 118: $0$=m^2$]( Thus the only solution is !Image 120: $f(m)=m^2$ using POP. And yes, I know this was long. Edit: Thanks to ShaftDraftKiller for informing me of ISL 2004 N3, which is almost a perfect example of both our points of POP, and is rather similar to ISL 2013 N1. Anyhow, here's the problem: ISL 2004 N3 wrote: Here's a (non-motivated) solution (hidden for length): POP solution This post has been edited 4 times. Last edited by ubermensch, Nov 2, 2019, 11:39 AM
|
{
"page_id": null,
"source": 6823,
"title": "from dpo"
}
|
Title: 15 Regular expressions – R for Data Science (2e) URL Source: Markdown Content: Introduction ------------ In Chapter 14. Next, we’ll talk about some of the other types of patterns that stringr functions can work with and the various “flags” that allow you to tweak the operation of regular expressions. We’ll finish with a survey of other places in the tidyverse and base R where you might use regexes. ### Prerequisites In this chapter, we’ll use regular expression functions from stringr and tidyr, both core members of the tidyverse, as well as data from the babynames package. Through this chapter, we’ll use a mix of very simple inline examples so you can get the basic idea, the baby names data, and three character vectors from stringr: * `fruit` contains the names of 80 fruits. * `words` contains 980 common English words. * `sentences` contains 720 short sentences. Pattern basics -------------- We’ll use `str_view()` to learn how regex patterns work. We used `str_view()` in the last chapter to better understand a string vs.its printed representation, and now we’ll use it with its second argument, a regular expression. When this is supplied, `str_view()` will show only the elements of the string vector that match, surrounding each match with `<>`,
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
and, where possible, highlighting the match in blue. The simplest patterns consist of letters and numbers which match those characters exactly: ``` str_view(fruit, "berry") #> │ bil #> │ black #> │ blue #> │ boysen #> │ cloud #> │ cran #> ... and 8 more ``` Letters and numbers match exactly and are called **literal characters**. Most punctuation characters, like `.`, `+`, `*`, `[`, `]`, and `?`, have special meanings2, "a.") #> │ #> │ #> │ e ``` Or we could find all the fruits that contain an “a”, followed by three letters, followed by an “e”: ``` str_view(fruit, "a...e") #> │ #> │ blrry #> │ mand #> │ nect #> │ pine #> │ pomegr #> ... and 2 more ``` **Quantifiers** control how many times a pattern can match: * `?` makes a pattern optional (i.e.it matches 0 or 1 times) * `+` lets a pattern repeat (i.e.it matches at least once) * `*` lets a pattern be optional or repeat (i.e.it matches any number of times, including 0). ``` # ab? matches an "a", optionally followed by a "b". str_view(c("a", "ab", "abb"), "ab?") #> │ #> │ #> │ b # ab+ matches an "a", followed by at least one "b". str_view(c("a", "ab", "abb"), "ab+") #> │ #> │ # ab* matches an "a", followed by any number of "b"s. str_view(c("a", "ab", "abb"), "ab*") #> │ #> │ #> │ ``` **Character classes** are defined by `[]`
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
and let you match a set of characters, e.g., `[abcd]` matches “a”, “b”, “c”, or “d”. You can also invert the match by starting with `^`: `[^abcd]` matches anything **except** “a”, “b”, “c”, or “d”. We can use this idea to find the words containing an “x” surrounded by vowels, or a “y” surrounded by consonants: ``` str_view(words, "[aeiou]x[aeiou]") #> │ ct #> │ mple #> │ rcise #> │ st str_view(words, "[^aeiou]y[^aeiou]") #> │ tem #> │ e ``` You can use **alternation**, `|`, to pick between one or more alternative patterns. For example, the following patterns look for fruits containing “apple”, “melon”, or “nut”, or a repeated vowel. ``` str_view(fruit, "apple|melon|nut") #> │ #> │ canary #> │ coco #> │ #> │ pine #> │ rock #> ... and 1 more str_view(fruit, "aa|ee|ii|oo|uu") #> │ bld orange #> │ gseberry #> │ lych #> │ purple mangostn ``` Regular expressions are very compact and use a lot of punctuation characters, so they can seem overwhelming and hard to read at first. Don’t worry; you’ll get better with practice, and simple patterns will soon become second nature. Let’s kick off that process by practicing with some useful stringr functions. Key functions ------------- Now that you’ve got the basics of regular expressions under your belt, let’s use them with some stringr and tidyr functions. In the following section, you’ll learn how to detect the presence or absence of a match, how to count the number of matches, how to replace a match with fixed text, and how to extract text using a pattern. ### Detect matches `str_detect()` returns a logical vector that is `TRUE` if the pattern matches an element of the character
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
vector and `FALSE` otherwise: ``` str_detect(c("a", "b", "c"), "[aeiou]") #> TRUE FALSE FALSE ``` Since `str_detect()` returns a logical vector of the same length as the initial vector, it pairs well with `filter()`. For example, this code finds all the most popular names containing a lower-case “x”: ``` babynames |> filter(str_detect(name, "x")) |> count(name, wt = n, sort = TRUE) #> # A tibble: 974 × 2 #> name n #> #> 1 Alexander 665492 #> 2 Alexis 399551 #> 3 Alex 278705 #> 4 Alexandra 232223 #> 5 Max 148787 #> 6 Alexa 123032 #> # ℹ 968 more rows ``` We can also use `str_detect()` with `summarize()` by pairing it with `sum()` or `mean()`: `sum(str_detect(x, pattern))` tells you the number of observations that match and `mean(str_detect(x, pattern))` tells you the proportion that match. For example, the following snippet computes and visualizes the proportion of baby names4`: `str_subset()` and `str_which()`. `str_subset()` returns a character vector containing only the strings that match. `str_which()` returns an integer vector giving the positions of the strings that match. ### Count matches The next step up in complexity from `str_detect()` is `str_count()`: rather than a true or false, it tells you how many matches there are in each string. ``` x 2 0 1 ``` Note that each match starts at the end of the previous match, i.e.regex
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
matches never overlap. For example, in `"abababa"`, how many times will the pattern `"aba"` match? Regular expressions say two, not three: It’s natural to use `str_count()` with `mutate()`. The following example uses `str_count()` with character classes to count the number of vowels and consonants in each name. ``` babynames |> count(name) |> mutate( vowels = str_count(name, "[aeiou]"), consonants = str_count(name, "[^aeiou]") ) #> # A tibble: 97,310 × 4 #> name n vowels consonants #> #> 1 Aaban 10 2 3 #> 2 Aabha 5 2 3 #> 3 Aabid 2 2 3 #> 4 Aabir 1 2 3 #> 5 Aabriella 5 4 5 #> 6 Aada 1 2 2 #> # ℹ 97,304 more rows ``` If you look closely, you’ll notice that there’s something off with our calculations: “Aaban” contains three “a”s, but our summary reports only two vowels. That’s because regular expressions are case sensitive. There are three ways we could fix this: * Add the upper case vowels to the character class: `str_count(name, "[aeiouAEIOU]")`. * Tell the regular expression to ignore case: `str_count(name, regex("[aeiou]", ignore_case = TRUE))`. We’ll talk about more in Section 15.5.1` to convert the names to lower case: `str_count(str_to_lower(name), "[aeiou]")`. This variety of approaches is pretty typical when working with strings — there are often multiple ways to reach your goal, either by making your pattern more complicated or by doing some preprocessing on your string. If you get stuck trying one approach, it can often be useful to switch gears and tackle the problem from a different perspective. In this case, since we’re applying two functions to the name, I think it’s easier to transform it first: ``` babynames |> count(name) |> mutate( name = str_to_lower(name), vowels = str_count(name, "[aeiou]"), consonants = str_count(name, "[^aeiou]") ) #> # A
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
tibble: 97,310 × 4 #> name n vowels consonants #> #> 1 aaban 10 3 2 #> 2 aabha 5 3 2 #> 3 aabid 2 3 2 #> 4 aabir 1 3 2 #> 5 aabriella 5 5 4 #> 6 aada 1 3 1 #> # ℹ 97,304 more rows ``` ### Replace values As well as detecting and counting matches, we can also modify them with `str_replace()` and `str_replace_all()`. `str_replace()` replaces the first match, and as the name suggests, `str_replace_all()` replaces all matches. ``` x "-ppl-" "p--r" "b-n-n-" ``` `str_remove()` and `str_remove_all()` are handy shortcuts for `str_replace(x, pattern, "")`: ``` x "ppl" "pr" "bnn" ``` These functions are naturally paired with `mutate()` when doing data cleaning, and you’ll often apply them repeatedly to peel off layers of inconsistent formatting. ### Exercises 1. What baby name has the most vowels? What name has the highest proportion of vowels? (Hint: what is the denominator?) 2. Replace all forward slashes in `"a/b/c/d/e"` with backslashes. What happens if you attempt to undo the transformation by replacing all backslashes with forward slashes? (We’ll discuss the problem very soon.) 3. Implement a simple version of `str_to_lower()` using `str_replace_all()`. 4. Create a regular expression that will match telephone numbers as commonly written in your country. Pattern details --------------- Now that you understand the basics of the pattern language and how to use it with some stringr and tidyr functions, it’s time to dig into more of the details. First, we’ll start with **escaping**, which allows you to match metacharacters that would otherwise be treated specially. Next, you’ll learn about **anchors** which allow you to match the start or end of the string. Then, you’ll learn more about
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
**character classes** and their shortcuts which allow you to match any character from a set. Next, you’ll learn the final details of **quantifiers** which control how many times a pattern can match. Then, we have to cover the important (but complex) topic of **operator precedence** and parentheses. And we’ll finish off with some details of **grouping** components of the pattern. The terms we use here are the technical names for each component. They’re not always the most evocative of their purpose, but it’s very helpful to know the correct terms if you later want to Google for more details. ### Escaping In order to match a literal `.`, you need an **escape** which tells the regular expression to match metacharacters6 #> │ \. # And this tells R to look for an explicit . str_view(c("abc", "a.c", "bef"), "a\\.c") #> │ ``` In this book, we’ll usually write regular expression without quotes, like `\.`. If we need to emphasize what you’ll actually type, we’ll surround it with quotes and add extra escapes, like `"\\."`. If `\` is used as an escape character in regular expressions, how do you match a literal `\`? Well, you need to escape it, creating the regular expression `\\`. To create that regular expression, you need to use a string,
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
which also needs to escape `\`. That means to match a literal `\` you need to write `"\\\\"` — you need four backslashes to match one! Alternatively, you might find it easier to use the raw strings you learned about in Section 14.2.2`, there’s an alternative to using a backslash escape: you can use a character class: `[.]`, `[$]`, `[|]`, … all match the literal values. ``` str_view(c("abc", "a.c", "a*c", "a c"), "a[.]c") #> │ str_view(c("abc", "a.c", "a*c", "a c"), ".[*]c") #> │ ``` ### Anchors By default, regular expressions will match any part of a string. If you want to match at the start or end you need to **anchor** the regular expression using `^` to match the start or `$` to match the end: ``` str_view(fruit, "^a") #> │ pple #> │ pricot #> │ vocado str_view(fruit, "a$") #> │ banan #> │ cherimoy #> │ feijo #> │ guav #> │ papay #> │ satsum ``` It’s tempting to think that `$` should match the start of a string, because that’s how we write dollar amounts, but that’s not what regular expressions want. To force a regular expression to match only the full string, anchor it with both `^` and `$`: ``` str_view(fruit, "apple") #> │ #> │ pine str_view(fruit, "^apple$") #> │ ``` You can also match the boundary between words (i.e.the start or end of a word) with `\b`. This can be particularly useful when using RStudio’s find and replace tool. For example, if to find all uses of `sum()`, you can search for `\bsum\b` to
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
avoid matching `summarize`, `summary`, `rowsum` and so on: ``` x │ mary(x) #> │ marize(df) #> │ row(x) #> │ (x) str_view(x, "\\bsum\\b") #> │ (x) ``` When used alone, anchors will produce a zero-width match: ``` str_view("abc", c("$", "^", "\\b")) #> │ abc<> #> │ <>abc #> │ <>abc<> ``` This helps you understand what happens when you replace a standalone anchor: ``` str_replace_all("abc", c("$", "^", "\\b"), "--") #> "abc--" "--abc" "--abc--" ``` ### Character classes A **character class**, or character **set**, allows you to match any character in a set. As we discussed above, you can construct your own sets with `[]`, where `[abc]` matches “a”, “b”, or “c” and `[^abc]` matches any character except “a”, “b”, or “c”. Apart from `^` there are two other characters that have special meaning inside of `[]:` * `-` defines a range, e.g., `[a-z]` matches any lower case letter and `[0-9]` matches any number. * `\` escapes special characters, so `[\^\-\]]` matches `^`, `-`, or `]`. Here are few examples: ``` x │ d ABCD 12345 -!@#%. str_view(x, "[a-z]+") #> │ ABCD 12345 -!@#%. str_view(x, "[^a-z0-9]+") #> │ abcd12345 # You need an escape to match characters that are otherwise # special inside of [] str_view("a-b-c", "[a-c]") #> │ -- str_view("a-b-c", "[a\\-c]") #> │ b ``` Some character classes are used so commonly that they get their own shortcut. You’ve already seen `.`, which matches any character apart from a newline. There are three other particularly useful pairs( * `\d` matches any digit; `\D` matches anything that isn’t a digit. * `\s` matches any whitespace (e.g., space, tab,
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
newline); `\S` matches anything that isn’t whitespace. * `\w` matches any “word” character, i.e.letters and numbers; `\W` matches any “non-word” character. The following code demonstrates the six shortcuts with a selection of letters, numbers, and punctuation characters. ``` x │ abcd ABCD -!@#%. str_view(x, "\\D+") #> │ 12345 str_view(x, "\\s+") #> │ abcdABCD12345-!@#%. str_view(x, "\\S+") #> │ str_view(x, "\\w+") #> │ -!@#%. str_view(x, "\\W+") #> │ abcdABCD12345 ``` ### Quantifiers **Quantifiers** control how many times a pattern matches. In Section 15.2, `+` (1 or more matches), and `*` (0 or more matches). For example, `colou?r` will match American or British spelling, `\d+` will match one or more digits, and `\s?` will optionally match a single item of whitespace. You can also specify the number of matches precisely with `{}`: * `{n}` matches exactly n times. * `{n,}` matches at least n times. * `{n,m}` matches between n and m times. ### Operator precedence and parentheses What does `ab+` match? Does it match “a” followed by one or more “b”s, or does it match “ab” repeated any number of times? What does `^a|b$` match? Does it match the complete string a or the complete string b, or does it match a string starting with a or a string ending with b? The answer to these questions is determined by operator precedence, similar to the PEMDAS or BEDMAS rules you might have learned in school. You know that `a + b * c` is equivalent to `a + (b * c)` not `(a + b) * c` because `*` has higher precedence and `+` has lower precedence: you compute
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
`*` before `+`. Similarly, regular expressions have their own precedence rules: quantifiers have high precedence and alternation has low precedence which means that `ab+` is equivalent to `a(b+)`, and `^a|b$` is equivalent to `(^a)|(b$)`. Just like with algebra, you can use parentheses to override the usual order. But unlike algebra you’re unlikely to remember the precedence rules for regexes, so feel free to use parentheses liberally. ### Grouping and capturing As well as overriding operator precedence, parentheses have another important effect: they create **capturing groups** that allow you to use sub-components of the match. The first way to use a capturing group is to refer back to it within a match with **back reference**: `\1` refers to the match contained in the first parenthesis, `\2` in the second parenthesis, and so on. For example, the following pattern finds all fruits that have a repeated pair of letters: ``` str_view(fruit, "(..)\\1") #> │ ba #> │ nut #> │ mber #> │ be #> │ ya #> │ s berry ``` And this one finds all words that start and end with the same pair of letters: ``` str_view(words, "^(..).*\\1$") #> │ #> │ #> │ #> │ #> │ ``` You can also use back references in `str_replace()`. For example, this code switches the order of the second and third words in `sentences`: ``` sentences |> str_replace("(\\w+) (\\w+) (\\w+)", "\\1 \\3 \\2") |> str_view() #> │ The canoe birch slid on the smooth planks. #> │ Glue sheet the to the dark blue background. #> │ It's to easy tell the depth of a well. #> │ These a days chicken leg is a rare dish. #> │ Rice often is served in round
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
bowls. #> │ The of juice lemons makes fine punch. #> ... and 714 more ``` If you want to extract the matches for each group you can use `str_match()`. But `str_match()` returns a matrix, so it’s not particularly easy to work with8 (\\w+)") |> head() #> [,1] [,2] [,3] #> [1,] "the smooth planks" "smooth" "planks" #> [2,] "the sheet to" "sheet" "to" #> [3,] "the depth of" "depth" "of" #> [4,] NA NA NA #> [5,] NA NA NA #> [6,] NA NA NA ``` You could convert to a tibble and name the columns: ``` sentences |> str_match("the (\\w+) (\\w+)") |> as_tibble(.name_repair = "minimal") |> set_names("match", "word1", "word2") #> # A tibble: 720 × 3 #> match word1 word2 #> #> 1 the smooth planks smooth planks #> 2 the sheet to sheet to #> 3 the depth of depth of #> 4 #> 5 #> 6 #> # ℹ 714 more rows ``` But then you’ve basically recreated your own version of `separate_wider_regex()`. Indeed, behind the scenes, `separate_wider_regex()` converts your vector of patterns to a single regex that uses grouping to capture the named components. Occasionally, you’ll want to use parentheses without creating matching groups. You can create a non-capturing group with `(?:)`. ``` x [,1] [,2] #> [1,] "gray" "a" #> [2,] "grey" "e" str_match(x, "gr(?:e|a)y") #> [,1] #> [1,] "gray" #> [2,] "grey" ``` ### Exercises 1. How would you match the literal string `"'\`? How about `"$^$"`? 2. Explain why each of these patterns don’t match a `\`: `"\"`, `"\\"`, `"\\\"`. 3. Given the corpus of common words in `stringr::words`, create regular expressions that find all words that: 1. Start with “y”. 2. Don’t start with “y”.
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
3. End with “x”. 4. Are exactly three letters long. (Don’t cheat by using `str_length()`!) 5. Have seven letters or more. 6. Contain a vowel-consonant pair. 7. Contain at least two vowel-consonant pairs in a row. 8. Only consist of repeated vowel-consonant pairs. 4. Create 11 regular expressions that match the British or American spellings for each of the following words: airplane/aeroplane, aluminum/aluminium, analog/analogue, ass/arse, center/centre, defense/defence, donut/doughnut, gray/grey, modeling/modelling, skeptic/sceptic, summarize/summarise. Try and make the shortest possible regex! 5. Switch the first and last letters in `words`. Which of those strings are still `words`? 6. Describe in words what these regular expressions match: (read carefully to see if each entry is a regular expression or a string that defines a regular expression.) 1. `^.*$` 2. `"\\{.+\\}"` 3. `\d{4}-\d{2}-\d{2}` 4. `"\\\\{4}"` 5. `\..\..\..` 6. `(.)\1\1` 7. `"(..)\\1"` 7. Solve the beginner regexp crosswords at [ Pattern control --------------- It’s possible to exercise extra control over the details of the match by using a pattern object instead of just a string. This allows you to control the so called regex flags and match various types of fixed strings, as described below. ### Regex flags There are a number of settings that can be used to control the details of the regexp. These settings are often called **flags** in other programming languages. In stringr, you can use these by wrapping the pattern in a call to `regex()`. The most useful flag is probably `ignore_case = TRUE` because it allows characters to match either their uppercase or lowercase forms: ``` bananas │ str_view(bananas, regex("banana", ignore_case = TRUE)) #> │ #> │ #> │ ``` If you’re doing a lot of work with multiline strings (i.e.strings that contain `\n`), `dotall`and `multiline` may also
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
be useful: * `dotall = TRUE` lets `.` match everything, including `\n`: ``` x │ Line 1 │ Line> 2 │ Line> 3 ``` * `multiline = TRUE` makes `^` and `$` match the start and end of each line rather than the start and end of the complete string: ``` x │ 1 #> │ Line 2 #> │ Line 3 str_view(x, regex("^Line", multiline = TRUE)) #> │ 1 #> │ 2 #> │ 3 ``` Finally, if you’re writing a complicated regular expression and you’re worried you might not understand it in the future, you might try `comments = TRUE`. It tweaks the pattern language to ignore spaces and new lines, as well as everything after `#`. This allows you to use comments and whitespace to make complex regular expressions more understandable9 # area code [)\-]? # optional closing parens or dash \ ? # optional space (\d{3}) # another three numbers [\ -]? # optional space or dash (\d{4}) # four more numbers )", comments = TRUE ) str_extract(c("514-791-8141", "(123) 456 7890", "123456"), phone) #> "514-791-8141" "(123) 456 7890" NA ``` If you’re using comments and want to match a space, newline, or `#`, you’ll need to escape it with `\`. ### Fixed matches You can opt-out of the regular expression rules by using `fixed()`: `fixed()` also gives you the ability to ignore case: If you’re working with non-English text, you will probably want `coll()` instead of `fixed()`, as it implements the full rules for capitalization as used by the `locale` you specify. See
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
Section 14.6) #> │ i ı I str_view("i İ ı I", coll("İ", ignore_case = TRUE, locale = "tr")) #> │ ı I ``` Practice -------- To put these ideas into practice we’ll solve a few semi-authentic problems next. We’ll discuss three general techniques: 1. checking your work by creating simple positive and negative controls 2. combining regular expressions with Boolean algebra 3. creating complex patterns using string manipulation ### Check your work First, let’s find all sentences that start with “The”. Using the `^` anchor alone is not enough: ``` str_view(sentences, "^The") #> │ birch canoe slid on the smooth planks. #> │ se days a chicken leg is a rare dish. #> │ juice of lemons makes fine punch. #> │ box was thrown beside the parked truck. #> │ hogs were fed chopped corn and garbage. #> │ boy was there when the sun rose. #> ... and 271 more ``` Because that pattern also matches sentences starting with words like `They` or `These`. We need to make sure that the “e” is the last letter in the word, which we can do by adding a word boundary: ``` str_view(sentences, "^The\\b") #> │ birch canoe slid on the smooth planks. #> │ juice of lemons makes fine punch. #> │ box was thrown beside the parked truck. #> │ hogs were fed chopped corn and garbage. #> │ boy was there when the sun rose. #> │ source of the huge river is the clear spring. #> ... and 250 more ``` What about finding all sentences that begin with a pronoun? ``` str_view(sentences, "^She|He|It|They\\b") #> │
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
's easy to tell the depth of a well. #> │ lp the woman get back to her feet. #> │ r purse was full of useless trash. #> │ snowed, rained, and hailed the same morning. #> │ ran half way to the hardware store. #> │ lay prone and hardly moved a limb. #> ... and 57 more ``` A quick inspection of the results shows that we’re getting some spurious matches. That’s because we’ve forgotten to use parentheses: ``` str_view(sentences, "^(She|He|It|They)\\b") #> │ 's easy to tell the depth of a well. #> │ snowed, rained, and hailed the same morning. #> │ ran half way to the hardware store. #> │ lay prone and hardly moved a limb. #> │ ordered peach pie with ice cream. #> │ caught its hind paw in a rusty trap. #> ... and 51 more ``` You might wonder how you might spot such a mistake if it didn’t occur in the first few matches. A good technique is to create a few positive and negative matches and use them to test that your pattern works as expected: ``` pos TRUE TRUE str_detect(neg, pattern) #> FALSE FALSE ``` It’s typically much easier to come up with good positive examples than negative examples, because it takes a while before you’re good enough with regular expressions to predict where your weaknesses are. Nevertheless, they’re still useful: as you work on the problem you can slowly accumulate a collection of your mistakes, ensuring that you never make the same mistake twice.
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
### Boolean operations Imagine we want to find words that only contain consonants. One technique is to create a character class that contains all letters except for the vowels (`[^aeiou]`), then allow that to match any number of letters (`[^aeiou]+`), then force it to match the whole string by anchoring to the beginning and the end (`^[^aeiou]+$`): ``` str_view(words, "^[^aeiou]+$") #> │ #> │ #> │ #> │ #> │ #> │ ``` But you can make this problem a bit easier by flipping the problem around. Instead of looking for words that contain only consonants, we could look for words that don’t contain any vowels: ``` str_view(words[!str_detect(words, "[aeiou]")]) #> │ by #> │ dry #> │ fly #> │ mrs #> │ try #> │ why ``` This is a useful technique whenever you’re dealing with logical combinations, particularly those involving “and” or “not”. For example, imagine if you want to find all words that contain “a” and “b”. There’s no “and” operator built in to regular expressions so we have to tackle it by looking for all words that contain an “a” followed by a “b”, or a “b” followed by an “a”: ``` str_view(words, "a.*b|b.*a") #> │ le #> │ out #> │ solute #> │ le #> │ by #> │ ck #> ... and 24 more ``` It’s simpler to combine the results of two calls to `str_detect()`: ``` words[str_detect(words, "a") & str_detect(words, "b")] #> "able" "about" "absolute" "available" "baby" "back" #> "bad" "bag" "balance" "ball" "bank" "bar" #> "base" "basis" "bear" "beat" "beauty" "because" #> "black" "board" "boat" "break" "brilliant" "britain" #> "debate" "husband" "labour" "maybe" "probable" "table" ``` What if
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
we wanted to see if there was a word that contains all vowels? If we did it with patterns we’d need to generate 5! (120) different patterns: It’s much simpler to combine five calls to `str_detect()`: In general, if you get stuck trying to create a single regexp that solves your problem, take a step back and think if you could break the problem down into smaller pieces, solving each challenge before moving onto the next one. ### Creating a pattern with code What if we wanted to find all `sentences` that mention a color? The basic idea is simple: we just combine alternation with word boundaries. ``` str_view(sentences, "\\b(red|green|blue)\\b") #> │ Glue the sheet to the dark background. #> │ Two fish swam in the tank. #> │ A wisp of cloud hung in the air. #> │ The spot on the blotter was made by ink. #> │ The sofa cushion is and of light weight. #> │ The sky that morning was clear and bright . #> ... and 20 more ``` But as the number of colors grows, it would quickly get tedious to construct this pattern by hand. Wouldn’t it be nice if we could store the colors in a vector? `rgb │ white #> │ aliceblue #> │ antiquewhite #> │ antiquewhite1 #> │ antiquewhite2 #> │ antiquewhite3 #> ... and 651 more ``` But
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
lets first eliminate the numbered variants: ``` cols │ white #> │ aliceblue #> │ antiquewhite #> │ aquamarine #> │ azure #> │ beige #> ... and 137 more ``` Then we can turn this into one giant pattern. We won’t show the pattern here because it’s huge, but you can see it working: ``` pattern │ Glue the sheet to the dark background. #> │ A rod is used to catch . #> │ Two fish swam in the tank. #> │ Cars and busses stalled in drifts. #> │ A wisp of cloud hung in the air. #> │ Leaves turn and in the fall. #> ... and 57 more ``` In this example, `cols` only contains numbers and letters so you don’t need to worry about metacharacters. But in general, whenever you create patterns from existing strings it’s wise to run them through `str_escape()` to ensure they match literally. ### Exercises 1. For each of the following challenges, try solving it by using both a single regular expression, and a combination of multiple `str_detect()` calls. 1. Find all `words` that start or end with `x`. 2. Find all `words` that start with a vowel and end with a consonant. 3. Are there any `words` that contain at least one of each different vowel? 2. Construct patterns to find evidence for and against the rule “i before e except after c”? 3. `colors()` contains a number of modifiers like “lightgray” and “darkblue”. How could you automatically identify these modifiers? (Think about how you might detect and then remove the colors that are modified). 4. Create a regular expression that
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
finds any base R dataset. You can get a list of these datasets via a special use of the `data()` function: `data(package = "datasets")$results[, "Item"]`. Note that a number of old datasets are individual vectors; these contain the name of the grouping “data frame” in parentheses, so you’ll need to strip those off. Regular expressions in other places ----------------------------------- Just like in the stringr and tidyr functions, there are many other places in R where you can use regular expressions. The following sections describe some other useful functions in the wider tidyverse and base R. ### tidyverse There are three other particularly useful places where you might want to use a regular expressions * `matches(pattern)` will select all variables whose name matches the supplied pattern. It’s a “tidyselect” function that you can use anywhere in any tidyverse function that selects variables (e.g., `select()`, `rename_with()` and `across()`). * `pivot_longer()'s``names_pattern` argument takes a vector of regular expressions, just like `separate_wider_regex()`. It’s useful when extracting data out of variable names with a complex structure * The `delim` argument in `separate_longer_delim()` and `separate_wider_delim()` usually matches a fixed string, but you can use `regex()` to make it match a pattern. This is useful, for example, if you want to match a comma that is optionally followed by a space, i.e.`regex(", ?")`. ### Base R `apropos(pattern)` searches all objects available from the global environment that match the given pattern. This is useful if you can’t quite remember the name of a function: ``` apropos("replace") #> "%+replace%" "replace" "replace_na" #> "setReplaceMethod" "str_replace" "str_replace_all" #> "str_replace_na" "theme_replace" ``` `list.files(path, pattern)` lists all files in `path` that match a regular expression `pattern`. For example, you can find all the R Markdown files in the current directory with: It’s worth noting that the pattern language used by
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
base R is very slightly different to that used by stringr. That’s because stringr is built on top of the stringi package` syntax. Summary ------- With every punctuation character potentially overloaded with meaning, regular expressions are one of the most compact languages out there. They’re definitely confusing at first but as you train your eyes to read them and your brain to understand them, you unlock a powerful skill that you can use in R and in many other places. In this chapter, you’ve started your journey to become a regular expression master by learning the most useful stringr functions and the most important components of the regular expression language. And there are plenty of resources to learn more. A good place to start is `vignette("regular-expressions", package = "stringr")`: it documents the full set of syntax supported by stringr. Another useful reference is [ It’s not R specific, but you can use it to learn about the most advanced features of regexes and how they work under the hood. It’s also good to know that stringr is implemented on top of the stringi package by Marek Gagolewski. If you’re struggling to find a function that does what you need in stringr, don’t be afraid to look in stringi. You’ll find stringi very
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
easy to pick up because it follows many of the the same conventions as stringr. In the next chapter, we’ll talk about a data structure closely related to strings: factors. Factors are used to represent categorical data in R, i.e.data with a fixed and known set of possible values identified by a vector of strings. * * * 1. You can pronounce it with either a hard-g (reg-x) or a soft-g (rej-x).↩︎`[↩︎]( 7. Remember, to create a regular expression containing `\d` or `\s`, you’ll need to escape the `\` for the string, so you’ll type `"\\d"` or `"\\s"`.[↩︎]( 8. Mostly because we never discuss matrices in this book The language { w ∈ Σ∗ | w ends with 00 } with three states. Answer: 1 2 3 0, 1 0 0 (b) The language { w ∈ Σ∗ | w contains the substring 0101 , i.e., w = x0101 y for some x, y ∈ Σ∗ } with five states. Answer: 1 2 3 4 5 0, 1 0 1 0 1 0, 1 (c) The language { w ∈ Σ∗ | w contains at least two 0s, or exactly two 1s } with six states. Answer: 1 2 5 3 4 60 ε 0, 1 0 1 0 0, 1 1 0 1 0 1(d) The language {ε} with one state. Answer: 1 (e) The language 0∗1∗0∗0 with three states. Answer: 1 2 3 0 ε 1 0 0 2. (a) Show by giving an example that, if M is an NFA that recognizes language C,swapping the accept and non-accept states in M doesn’t necessarily yield a new NFA that recognizes C. Answer: The NFA M below recognizes the language C = { w ∈ Σ∗ | w ends with 00 },where Σ = {0, 1}. 1 2 3 0, 1 0 0 Swapping the accept and non-accept states of M gives the following NFA M ′: 1 2 3 0, 1 0 0 Note that M ′ accepts the string 100 6 ∈ C = { w | w does not end with 00 }, so M ′ does not recognize the language C.(b) Is the class of languages recognized by
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
NFAs closed under complement? Explain your answer. Answer: The class of languages recognized by NFAs is closed under complement, which we 2can prove as follows. Suppose that C is a language recognized by some NFA M ,i.e., C = L(M ). Since every NFA has an equivalent DFA (Theorem 1.39), there is a DFA D such that L(D) = L(M ) = C. By problem 3 on Homework 2, we then know there is another DFA D that recognizes the language L(D). Since every DFA is also an NFA, this then shows that there is an NFA, in particular D,that recognizes the language C = L(D). Thus, the class of languages recognized by NFAs is closed under complement. 3. Use the construction given in Theorem 1.39 to convert the following NFA N into an equivalent DFA. 1 2 3 ε a a a, b b Answer: Let NFA N = ( Q, Σ, δ, 1, F ), where Q = {1, 2, 3}, Σ = {a, b }, 1 is the start state, F = {2}, and the transition function δ as in the diagram of N . Recall that for a subset R ⊆ Q of states, we define its ε-closure E(R) as E(R) = { q | q can be reached from R by travelling over 0 or more ε transitions }. To construct a DFA M = ( Q′, Σ, δ ′, q ′ > 0 , F ′) that is equivalent to NFA N , first we compute the ε-closure of every subset of Q = {1, 2, 3}. Subset R ⊆ Q ε-closure E(R) ∅ ∅ {1} {1, 2} {2} {2} {3} {3} {1, 2} {1, 2} {1, 3} {1, 2, 3} {2, 3} {2, 3} {1, 2, 3} {1, 2, 3} Then define Q′
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
as the power set P(Q), i.e., the set of all subsets of Q, so Q′ = { ∅ , {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3} } ; i.e., each state of the equivalent DFA M is a subset of states of the NFA N .3Recall that state 1 is the start state of the NFA N , so the start state of the equivalent DFA M is then E({1}) = {1, 2}. The set F ′ of accept states of M is F ′ = { { 2}, {1, 2}, {2, 3}, {1, 2, 3} } , i.e., each state in F ′ has at least one accept state of N .We define the transitions in the DFA M as in the following diagram: {1, 2} {2, 3} ∅ {1, 2, 3}a b a b a, b b a Note that we left out some of the states (e.g., {1}) in P(Q) from our diagram of the DFA M since they are not accessible from the start state {1, 2}. Also, we had to add an arc from state ∅ to itself labelled with “ a, b ” so that this state has an arc leaving it corresponding to each symbol in the alphabet Σ, which is a requirement for any DFA. The algorithm given in the notes and textbook will always correctly construct an equivalent DFA from a given NFA, but we don’t always have to go through all the steps of the algorithm to obtain an equivalent DFA. For example, on this problem, we begin by figuring out what states the NFA can be in without reading any symbols. In this case, this is E({1}) = {1, 2} since 1 is the starting state of the NFA, and the NFA can jump
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
from 1 to 2 without reading any symbols by taking the ε-transition. Thus, we first create a DFA state corresponding to the set {1, 2}: {1, 2} The state {1, 2} is the start state of the DFA since this is where the NFA can be without reading any symbols. The state {1, 2} is also an accepting state for the DFA since it contains 2, which is accepting for the NFA. Now for DFA state {1, 2}, determine where the NFA can go on an a from each NFA state within this DFA state, and where the NFA can go on a b from each NFA state 4within this DFA state. On an a, the NFA can go from state 1 to state 3; also, the NFA can go from state 2 to 1, and then it also can go further from 1 to 2 on the ε.So from NFA states 1 and 2 on an a, the NFA can end up in states 1, 2, and 3, so draw a transition in the DFA from state {1, 2} to a new state {1, 2, 3}, which is an accepting state since it contains 2 ∈ F : > {1,2}{1,2,3}a Similarly, to determine where the DFA moves on b from DFA state {1, 2}, determine all the possibilities of where the NFA can go from NFA states 1 and 2 on b. From state 1, the NFA can’t go anywhere on a b; also, the NFA can’t go anywhere from state 2 on b. Thus, the NFA can’t go anywhere from states 2 and 3 on a b, so we add a b-edge in the DFA from state {1, 2} to a new DFA state ∅, which is not accepting since it contains no accept states of the NFA:
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
> {1,2} > ∅ > {1,2,3}a > b Now every time we add a new DFA state, we have to determine all the possibilities of where the NFA can go on an a from each NFA state within that DFA state, and where the NFA can go on a b from each NFA state within that DFA state. For DFA state {1, 2, 3}, we next determine where the NFA can go on an a from each of the NFA states 1, 2 and 3. From NFA state 1, the NFA on an a can go to NFA state 3; from NFA state 2, the NFA on an a can go to NFA state 1, and then it can also further jump to 2 on ε; from NFA state 3, the NFA on an a can go to NFA state 2. Thus, if the NFA is in states 1, 2 and 3, it can go on an a to states 1, 2 and 3, so we add to the DFA an a-edge from {1, 2, 3} to {1, 2, 3}. > {1,2} > ∅ > {1,2,3}a > b > a Now we determine where the b-edge from DFA state {1, 2, 3} goes to. To do this, we examine what happens to the NFA from states 1, 2 and 3 on a b. If the NFA is 5in state 1, then there is nowhere to go on a b; if the NFA is in state 2, then there is nowhere to go on a b; if the NFA is in state 3, then the NFA can go to 2 or 3 on b.Hence, if the NFA is in states 1, 2 and 3, the NFA on b can end in states 2 and 3.Thus, in the DFA, draw an edge
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
from state {1, 2, 3} to a new state {2, 3}, which is accepting since it contains 2 ∈ F : > {1,2} > {2,3} > ∅ > {1,2,3}a > b > b > a Now do the same for DFA states {2, 3} and ∅. If any new DFA states arise, then we need to determine the a and b transitions out of those states as well. We stop once every DFA state has an a-transition and a b-transition out of it. Accepting states in the DFA are any DFA states that contain at least one accepting NFA state. We eventually end up with the DFA below as before: > {1,2} > {2,3} > ∅ > {1,2,3}a > b > ab > a, b > b > a For the DFA state ∅, there are no versions of the NFA currently active, i.e., all “threads” have “crashed,” so the NFA cannot proceed and the input string will not be accepted. 6However, according to the definition of a DFA, each state must have edges leaving it corresponding to each symbol in the alphabet Σ. Thus, we add a loop from the DFA state ∅ back to itself labeled with Σ, which in our case is a, b .4. Give regular expressions that generate each of the following languages. In all cases, the alphabet is Σ = {a, b }. Each regular language has infinitely many correct regular expressions, but you only need to give one. (a) The language { w ∈ Σ∗ | | w| is odd }. Answer: (a ∪ b)(( a ∪ b)( a ∪ b)) ∗ (b) The language { w ∈ Σ∗ | w has an odd number of a’s }. Answer: b∗a(ab ∗a ∪ b)∗ (c) The language { w | w contains at least
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
two a’s, or exactly two b’s }. Answer: b∗ab ∗a(a ∪ b)∗ ∪ a∗ba ∗ba ∗ (d) The language { w ∈ Σ∗ | w ends in a double letter }. (A string contains a double letter if it contains aa or bb as a substring.) Answer: (a ∪ b)∗(aa ∪ bb ) (e) The language { w ∈ Σ∗ | w does not end in a double letter }. Answer: ε ∪ a ∪ b ∪ (a ∪ b)∗(ab ∪ ba ) (f) The language { w ∈ Σ∗ | w contains exactly one double letter }. For example, baaba has exactly one double letter, but baaaba has two double letters. Answer: (ε ∪ b)( ab )∗aa (ba )∗(ε ∪ b) ∪ (ε ∪ a)( ba )∗bb (ab )∗(ε ∪ a) 5. Suppose we define a restricted version of the Java programming language in which variable names must satisfy all of the following conditions: > • A variable name can only use Roman letters (i.e., a, b, . . . , z, A, B, . . . , Z) or Arabic numerals (i.e., 0, 1, 2, . . . , 9); i.e., underscore and dollar sign are not allowed. > • A variable name must start with a Roman letter: a, b, . . . , z, A, B, . . . , Z > • The length of a variable name must be no greater than 8. > • A variable name cannot be a keyword (e.g., if). The set of keywords is finite. Let L be the set of all valid variable names in our restricted version of Java. 7(a) Let L0 be the set of strings satisfying the first 3 conditions above; i.e., we do not require the last condition. Give a regular expression for L0.
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
Answer: To simplify the regular expression, we define Σ1 = {a, b, . . . , z, A, B, . . . , Z} Σ2 = {0, 1, 2, . . . , 9}. Then a regular expression for L0 is Σ1 (Σ 1 ∪ Σ2 ∪ ε) · · · (Σ 1 ∪ Σ2 ∪ ε) # ︸ ︷︷ ︸ 7 times . Note that by including the ε in each of the last parts, we can generate strings that have length strictly less than 8. (b) Prove that L has a regular expression, where L is the set of strings satisfying all four conditions. Answer: We proved in Homework 1, problem 4(b), that L is finite. Thus, L is regular, so it has a regular expression (slide 1-95). Although the problem didn’t ask for it, we can write a regular expression for L by listing all of the finitely many strings in L and putting a ∪ in between each pair of consecutive strings. This works because L is finite. (We cannot use this approach for infinite languages because the resulting expression would then be infinitely long, which is not allowed for a regular expression.) (c) Give a DFA for the language L0 in part (a), where the alphabet Σ is the set of all printable characters on a computer keyboard (no control characters), except for parentheses to avoid confusion. Answer: Define Σ1 and Σ2 as in part (a), and let Σ3 = Σ − (Σ 1 ∪ Σ2) be all of the other characters on a computer keyboard except for parentheses. Then a DFA for L0 is as follows: > 12349 > 0 > Σ1 > Σ2∪Σ3 > Σ1∪Σ2 > Σ3 > Σ1∪Σ2 > Σ3 > • • • > Σ3 > Σ > Σ Note that
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
out of each state, there is exactly one edge leaving the state for any symbol from Σ, as required for a DFA. 86. Define L to be the set of strings that represent numbers in a modified version of Java. The goal in this problem is to define a regular expression and an NFA for L. To precisely define L, let the set of digits be Σ1 = { 0, 1, 2, . . . , 9 }, and define the set of signs to be Σ2 = { +, - }. Then L = L1 ∪ L2 ∪ L3, where > • L1 is the set of all strings that are decimal integer numbers. Specifically, L1 consists of strings that start with an optional sign, followed by one or more digits. Examples of strings in L1 are “ 02 ”, “ +9 ”, and “ -241 ”. > • L2 is the set of all strings that are floating-point numbers that are not in expo-nential notation. Specifically, L2 consists of strings that start with an optional sign, followed by zero or more digits, followed by a decimal point, and end with zero or more digits, where there must be at least one digit in the string. Examples of strings in L2 are “ 13.231 ”, “ -28. ” and “ .124 ”. All strings in L2 have exactly one decimal point. > • L3 is the set of all strings that are floating-point numbers in exponential notation. Specifically, L3 consists of strings that start with a string from L1 or L2, followed by “ E” or “ e”, and end with a string from L1. Examples of strings in L3 are “-80.1E-083 ”, “ +8.E5 ” and “ 1e+31 ”. Assume that there is no limit on the number
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
of digits in a string in L. Also, we do not allow for the suffixes L, l, F, f, D, d, at the end of numbers to denote types (long integers, floats, and doubles). Define Σ as the alphabet of all printable characters on a computer keyboard (no control characters), except for parentheses to avoid confusion. (a) Give a regular expression for L1. Also, give an NFA and a DFA for L1 over the alphabet Σ. Answer: A regular expression for L1 is R1 = ( + ∪ - ∪ ε ) Σ 1 Σ∗ > 1 where Σ1 = { 0, 1, 2, . . . , 9 } as previously defined. An NFA for L1 is > q1q2q3 > +,-, ε Σ1 > Σ1 Define Σ3 = Σ − (Σ 1 ∪ Σ2) with Σ2 = { -, + }, as before. Then a DFA for L1 is 91 2 > 3 > 4 > Σ2 > Σ1 > Σ1 > Σ−Σ1 > Σ−Σ1 > Σ1 > Σ3 > Σ Notice that the DFA has more states and transitions than the NFA. (b) Give a regular expression for L2. Also, give an NFA for L2 over the alphabet Σ. Answer: A regular expression for L2 is R2 = ( + ∪ - ∪ ε )(Σ 1 Σ∗ > 1 . Σ∗ > 1 ∪ . Σ1 Σ∗ > 1 ) Note that the regular expression ( + ∪ - ∪ ε ) Σ ∗ > 1 . Σ∗ > 1 is not correct since it can generate the strings “ .”, “ +. ” and “ -. ”, which are not valid floating-point numbers. An NFA for L2 is > r1r2 > r3 > r4 > r5 > +,-, ε > Σ1 > • > • > Σ1
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
> Σ1 > Σ1 (c) Give a regular expression for L3. Also, give an NFA for L3 over the alphabet Σ. Answer: A regular expression for L3 is R3 = ( R1 ∪ R2) ( E ∪ e) R1 where R1 and R2 are defined in the previous parts. An NFA for L3 is 10 s1 s2 s3 s4 s5 s6 s7 s8 +, -, ε Σ1 • Σ1 • Σ1 Σ1 Σ1 E, e +, -, ε Σ1 Σ1 (d) Give a regular expression for the language L. Also, give an NFA for L over the alphabet Σ. Answer: Note that L = L1 ∪ L2 ∪ L3, so a regular expression for L is R4 = R1 ∪ R2 ∪ R3 We can construct an NFA for L by taking the union of the NFA’s for L1, L2 and L3 using the approach on slides 1-59 to 1-61, as follows: q1 q2 q3 +, -, ε Σ1 Σ1 r1 r2 r3 r4 r5 +, -, ε Σ1 • • Σ1 Σ1 Σ1 s1 s2 s3 s4 s5 s6 s7 s8 +, -, ε Σ1 • Σ1 • Σ1 Σ1 Σ1 E, e +, -, ε Σ1 Σ1 q0 ε ε ε A simpler NFA for L is to take the NFA for L3 from the previous part and make s3 and s5 also accepting states in addition to s8.11
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
Title: Just a moment... URL Source: Warning: Target URL returned error 403: Forbidden Warning: This page maybe requiring CAPTCHA, please make sure you are authorized to access this page. Markdown Content: mathematica.stackexchange.com ----------------------------- Verify you are human by completing the action below. mathematica.stackexchange.com needs to review the security of your connection before proceeding.
|
{
"page_id": null,
"source": 6825,
"title": "from dpo"
}
|
Title: URL Source: Warning: Target URL returned error 403: Forbidden Markdown Content: You've been blocked by network security. To continue, log in to your Reddit account or use your developer token If you think you've been blocked by mistake, file a ticket below and we'll look into it. [Log in]( a ticket](
|
{
"page_id": null,
"source": 6827,
"title": "from dpo"
}
|
Title: I cannot understand how Irrational Numbers exist, please help me. : r/askmath URL Source: Markdown Content: I cannot understand how Irrational Numbers exist, please help me. : r/askmath =============== Skip to main content right triangle a vivid physical representation of sqrt(2)? Don't get hung up on the
|
{
"page_id": null,
"source": 6827,
"title": "from dpo"
}
|
digits, they are not important, they are just a side property Reply reply } Share Share [ is just as impossible for the same precision reasons ! Big difference between maths and physics there : maths are
|
{
"page_id": null,
"source": 6827,
"title": "from dpo"
}
|
an exact science. When we say this is equal to that, it has a precise meaning. It's exactly the same thing. In physics-or litterally anything in the real world tbf- people have to make approximations all the time ! And physicists, engineers, etc. deal with these approximations and make stuff work anyways. Reply reply } Share Share 2 more replies 2 more replies More replies. Reply reply } Share Share 10 more replies 10 more replies More replies You never get sqrt(2) kilos of grain from peasant, do you? This is why such numbers seems "IRrational", because we think about our day life as rational. Also: infinite rational numbers (like 1/3 which is 0.333...), do you seem them as absurd? You can think about 1/3 as 0.1 in base-3, and this seems much more logical. So, you better think of sqrt(2) not as 1.41.... but as side of
|
{
"page_id": null,
"source": 6827,
"title": "from dpo"
}
|
a square with size of 2, so essentially every sqrt(x) number is just a side of a square, but sometimes they match with our day-life numbers. I don't think this is a good explanation, but hope this helps. Reply reply } Share Share New to Reddit? Create your account and connect with a world of communities. Continue with Email Continue With Phone Number By continuing, you agree to ourUser Agreement. * * * 386K Members Online ### Pls explain irrational numbers.. * * * 386K Members Online [SPOILER ### Can someone please explain irrational/rational/ natural/ whole numbers?]( 72 upvotes ·43 comments * * * * Promoted  is irrational?]( 113 upvotes ·110 comments * * * * [Can someone explain to me how to find the answer]( 61: r/askmath icon]( r/askmath]( mo. ago  Ilya I. Bogdanov G´ eza K´ os Carlos Gustavo Tamm de Ara´ ujo Moreira (Gugu) Christian Reiher Shortlisted problems 3 # Problems # Algebra ## A1. Let n be a positive integer and let a1, . . . , a n´1 be arbitrary real numbers. Define the sequences u0, . . . , u n and v0, . . . , v n inductively by u0 “ u1 “ v0 “ v1 “ 1, and uk`1 “ uk ` akuk´1, vk`1 “ vk ` an´kvk´1 for k “ 1, . . . , n ´ 1. Prove that un “ vn. (France) ## A2. Prove that in any set of 2000 distinct real numbers there exist two pairs a ą b and c ą d with a ‰ c or b ‰ d, such that ˇˇˇˇ a ´ b c ´ d ´ 1 ˇˇˇˇ ă 1 100000 . (Lithuania) ## A3. Let Qą0 be the set of positive rational numbers. Let f : Qą0 Ñ R be a function satisfying the conditions f pxqf
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
pyq ě f pxy q and f px ` yq ě f pxq ` f pyq for all x, y P Qą0. Given that f paq “ a for some rational a ą 1, prove that f pxq “ x for all x P Qą0. (Bulgaria) ## A4. Let n be a positive integer, and consider a sequence a1, a 2, . . . , a n of positive integers. Extend it periodically to an infinite sequence a1, a 2, . . . by defining an`i “ ai for all i ě 1. If a1 ď a2 ď ¨ ¨ ¨ ď an ď a1 ` n and aai ď n ` i ´ 1 for i “ 1, 2, . . . , n, prove that a1 ` ¨ ¨ ¨ ` an ď n2. (Germany) ## A5. Let Zě0 be the set of all nonnegative integers. Find all the functions f : Zě0 Ñ Zě0 satisfying the relation f pf pf pnqqq “ f pn ` 1q ` 1for all n P Zě0. (Serbia) ## A6. Let m ‰ 0 be an integer. Find all polynomials P pxq with real coefficients such that px3 ´ mx 2 ` 1qP px ` 1q ` p x3 ` mx 2 ` 1qP px ´ 1q “ 2px3 ´ mx ` 1qP pxq for all real numbers x. (Serbia) 4 IMO 2013 Colombia # Combinatorics ## C1. Let n be a positive integer. Find the smallest integer k with the following property: Given any real numbers a1, . . . , a d such that a1 ` a2 ` ¨ ¨ ¨ ` ad “ n and 0 ď ai ď 1 for i “ 1, 2, . . . , d , it is possible to partition these numbers into
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
k groups (some of which may be empty) such that the sum of the numbers in each group is at most 1. (Poland) ## C2. In the plane, 2013 red points and 2014 blue points are marked so that no three of the marked points are collinear. One needs to draw k lines not passing through the marked points and dividing the plane into several regions. The goal is to do it in such a way that no region contains points of both colors. Find the minimal value of k such that the goal is attainable for every possible configuration of 4027 points. (Australia) ## C3. A crazy physicist discovered a new kind of particle which he called an imon , after some of them mysteriously appeared in his lab. Some pairs of imons in the lab can be entangled , and each imon can participate in many entanglement relations. The physicist has found a way to perform the following two kinds of operations with these particles, one operation at a time. piq If some imon is entangled with an odd number of other imons in the lab, then the physicist can destroy it. pii q At any moment, he may double the whole family of imons in his lab by creating a copy I1 of each imon I. During this procedure, the two copies I1 and J1 become entangled if and only if the original imons I and J are entangled, and each copy I1 becomes entangled with its original imon I; no other entanglements occur or disappear at this moment. Prove that the physicist may apply a sequence of such operations resulting in a family of imons, no two of which are entangled. (Japan) ## C4. Let n be a positive integer, and let A be a subset
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
of t1, . . . , n u. An A-partition of n into k parts is a representation of n as a sum n “ a1 ` ¨ ¨ ¨ ` ak, where the parts a1, . . . , a k belong to A and are not necessarily distinct. The number of different parts in such a partition is the number of (distinct) elements in the set ta1, a 2, . . . , a ku.We say that an A-partition of n into k parts is optimal if there is no A-partition of n into r parts with r ă k. Prove that any optimal A-partition of n contains at most 3 ?6n different parts. (Germany) ## C5. Let r be a positive integer, and let a0, a 1, . . . be an infinite sequence of real numbers. Assume that for all nonnegative integers m and s there exists a positive integer n P r m ` 1, m ` rs such that am ` am`1 ` ¨ ¨ ¨ ` am`s “ an ` an`1 ` ¨ ¨ ¨ ` an`s. Prove that the sequence is periodic, i. e. there exists some p ě 1 such that an`p “ an for all n ě 0. (India) Shortlisted problems 5 ## C6. In some country several pairs of cities are connected by direct two-way flights. It is possible to go from any city to any other by a sequence of flights. The distance between two cities is defined to be the least possible number of flights required to go from one of them to the other. It is known that for any city there are at most 100 cities at distance exactly three from it. Prove that there is no city such that more than 2550 other cities
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
have distance exactly four from it. (Russia) ## C7. Let n ě 2 be an integer. Consider all circular arrangements of the numbers 0 , 1, . . . , n ; the n ` 1 rotations of an arrangement are considered to be equal. A circular arrangement is called beautiful if, for any four distinct numbers 0 ď a, b, c, d ď n with a ` c “ b ` d, the chord joining numbers a and c does not intersect the chord joining numbers b and d.Let M be the number of beautiful arrangements of 0 , 1, . . . , n . Let N be the number of pairs px, y q of positive integers such that x ` y ď n and gcd px, y q “ 1. Prove that M “ N ` 1. (Russia) ## C8. Players A and B play a paintful game on the real line. Player A has a pot of paint with four units of black ink. A quantity p of this ink suffices to blacken a (closed) real interval of length p. In every round, player A picks some positive integer m and provides 1 {2m units of ink from the pot. Player B then picks an integer k and blackens the interval from k{2m to pk ` 1q{ 2m (some parts of this interval may have been blackened before). The goal of player A is to reach a situation where the pot is empty and the interval r0, 1s is not completely blackened. Decide whether there exists a strategy for player A to win in a finite number of moves. (Austria) 6 IMO 2013 Colombia # Geometry ## G1. Let ABC be an acute-angled triangle with orthocenter H, and let W be a point on side
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
BC . Denote by M and N the feet of the altitudes from B and C, respectively. Denote by ω1 the circumcircle of BW N , and let X be the point on ω1 which is diametrically opposite to W . Analogously, denote by ω2 the circumcircle of CW M , and let Y be the point on ω2 which is diametrically opposite to W . Prove that X, Y and H are collinear. (Thaliand) ## G2. Let ω be the circumcircle of a triangle ABC . Denote by M and N the midpoints of the sides AB and AC , respectively, and denote by T the midpoint of the arc BC of ω not containing A.The circumcircles of the triangles AMT and ANT intersect the perpendicular bisectors of AC and AB at points X and Y , respectively; assume that X and Y lie inside the triangle ABC . The lines MN and XY intersect at K. Prove that KA “ KT . (Iran) ## G3. In a triangle ABC , let D and E be the feet of the angle bisectors of angles A and B,respectively. A rhombus is inscribed into the quadrilateral AEDB (all vertices of the rhombus lie on different sides of AEDB ). Let ϕ be the non-obtuse angle of the rhombus. Prove that ϕ ď max t=BAC, =ABC u. (Serbia) ## G4. Let ABC be a triangle with =B ą =C. Let P and Q be two different points on line AC such that =P BA “ =QBA “ =ACB and A is located between P and C. Suppose that there exists an interior point D of segment BQ for which P D “ P B . Let the ray AD intersect the circle ABC at R ‰ A. Prove that QB “ QR
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
. (Georgia) ## G5. Let ABCDEF be a convex hexagon with AB “ DE , BC “ EF , CD “ F A , and =A ´ =D “ =C ´ =F “ =E ´ =B. Prove that the diagonals AD, BE, and CF are concurrent. (Ukraine) ## G6. Let the excircle of the triangle ABC lying opposite to A touch its side BC at the point A1.Define the points B1 and C1 analogously. Suppose that the circumcentre of the triangle A1B1C1 lies on the circumcircle of the triangle ABC . Prove that the triangle ABC is right-angled. (Russia) Shortlisted problems 7 # Number Theory ## N1. Let Zą0 be the set of positive integers. Find all functions f : Zą0 Ñ Zą0 such that m2 ` f pnq | mf pmq ` n for all positive integers m and n. (Malaysia) ## N2. Prove that for any pair of positive integers k and n there exist k positive integers m1, m 2, . . . , m k such that 1 ` 2k ´ 1 n “ ˆ 1 ` 1 m1 ˙ ˆ 1 ` 1 m2 ˙ ¨ ¨ ¨ ˆ 1 ` 1 mk ˙ . (Japan) ## N3. Prove that there exist infinitely many positive integers n such that the largest prime divisor of n4 ` n2 ` 1 is equal to the largest prime divisor of pn ` 1q4 ` p n ` 1q2 ` 1. (Belgium) ## N4. Determine whether there exists an infinite sequence of nonzero digits a1, a 2, a 3, . . . and a positive integer N such that for every integer k ą N, the number akak´1 . . . a 1 is a perfect square. (Iran) ## N5. Fix an integer k ě 2. Two players, called
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
Ana and Banana, play the following game of numbers : Initially, some integer n ě k gets written on the blackboard. Then they take moves in turn, with Ana beginning. A player making a move erases the number m just written on the blackboard and replaces it by some number m1 with k ď m1 ă m that is coprime to m. The first player who cannot move anymore loses. An integer n ě k is called good if Banana has a winning strategy when the initial number is n,and bad otherwise. Consider two integers n, n 1 ě k with the property that each prime number p ď k divides n if and only if it divides n1. Prove that either both n and n1 are good or both are bad. (Italy) ## N6. Determine all functions f : Q ÝÑ Z satisfying f ˆf pxq ` a b ˙ “ f ´x ` a b ¯ for all x P Q, a P Z, and b P Zą0. (Here, Zą0 denotes the set of positive integers.) (Israel) ## N7. Let ν be an irrational positive number, and let m be a positive integer. A pair pa, b q of positive integers is called good if arbν s ´ btaν u “ m. A good pair pa, b q is called excellent if neither of the pairs pa´b, b q and pa, b ´aq is good. (As usual, by txu and rxs we denote the integer numbers such that x ´ 1 ă txu ď x and x ď rxs ă x ` 1.) Prove that the number of excellent pairs is equal to the sum of the positive divisors of m. (U.S.A.) 8 IMO 2013 Colombia # Solutions # Algebra ## A1. Let n be a positive integer
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
and let a1, . . . , a n´1 be arbitrary real numbers. Define the sequences u0, . . . , u n and v0, . . . , v n inductively by u0 “ u1 “ v0 “ v1 “ 1, and uk`1 “ uk ` akuk´1, vk`1 “ vk ` an´kvk´1 for k “ 1, . . . , n ´ 1. Prove that un “ vn. (France) Solution 1. We prove by induction on k that uk “ ÿ > 0ăi1ă... ăităk, ij`1´ijě2 ai1 . . . a it . p1q Note that we have one trivial summand equal to 1 (which corresponds to t “ 0 and the empty sequence, whose product is 1). For k “ 0, 1 the sum on the right-hand side only contains the empty product, so (1) holds due to u0 “ u1 “ 1. For k ě 1, assuming the result is true for 0 , 1, . . . , k , we have uk`1 “ ÿ > 0ăi1ă... ăităk, ij`1´ijě2 ai1 . . . a it ` ÿ > 0ăi1ă... ăităk´1,ij`1´ijě2 ai1 . . . a it ¨ ak “ ÿ > 0ăi1ă... ăităk`1,ij`1´ijě2, > kRt i1,...,i tu ai1 . . . a it ` ÿ > 0ăi1ă... ăităk`1,ij`1´ijě2, > kPt i1,...,i tu ai1 . . . a it “ ÿ > 0ăi1ă... ăităk`1,ij`1´ijě2 ai1 . . . a it , as required. Applying (1) to the sequence b1, . . . , b n given by bk “ an´k for 1 ď k ď n, we get vk “ ÿ > 0ăi1ă... ăităk, ij`1´ijě2 bi1 . . . b it “ ÿ > nąi1ą... ąitąn´k, ij´ij`1ě2 ai1 . . . a it . p2q For k “ n the expressions (1) and (2) coincide, so indeed un
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
“ vn. Solution 2. Define recursively a sequence of multivariate polynomials by P0 “ P1 “ 1, Pk`1px1, . . . , x kq “ Pkpx1, . . . , x k´1q ` xkPk´1px1, . . . , x k´2q, so Pn is a polynomial in n ´ 1 variables for each n ě 1. Two easy inductive arguments show that un “ Pnpa1, . . . , a n´1q, vn “ Pnpan´1, . . . , a 1q,Shortlisted problems – solutions 9 so we need to prove Pnpx1, . . . , x n´1q “ Pnpxn´1, . . . , x 1q for every positive integer n. The cases n “ 1, 2 are trivial, and the cases n “ 3, 4 follow from P3px, y q “ 1 ` x ` y and P4px, y, z q “ 1 ` x ` y ` z ` xz .Now we proceed by induction, assuming that n ě 5 and the claim hold for all smaller cases. Using F pa, b q as an abbreviation for P|a´b|` 1pxa, . . . , x bq (where the indices a, . . . , b can be either in increasing or decreasing order), F pn, 1q “ F pn, 2q ` x1F pn, 3q “ F p2, n q ` x1F p3, n q“ p F p2, n ´ 1q ` xnF p2, n ´ 2qq ` x1pF p3, n ´ 1q ` xnF p3, n ´ 2qq “ p F pn ´ 1, 2q ` x1F pn ´ 1, 3qq ` xnpF pn ´ 2, 2q ` x1F pn ´ 2, 3qq “ F pn ´ 1, 1q ` xnF pn ´ 2, 1q “ F p1, n ´ 1q ` xnF p1, n ´ 2q“ F p1, n q, as
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
we wished to show. Solution 3. Using matrix notation, we can rewrite the recurrence relation as ˆ uk`1 uk`1 ´ uk ˙ “ ˆuk ` akuk´1 akuk´1 ˙ “ ˆ1 ` ak ´ak ak ´ak ˙ ˆ uk uk ´ uk´1 ˙ for 1 ď k ď n ´ 1, and similarly pvk`1; vk ´ vk`1q “ ´ vk ` an´kvk´1; ´an´kvk´1 ¯ “ p vk; vk´1 ´ vkq ˆ1 ` an´k ´an´k an´k ´an´k ˙ for 1 ď k ď n ´ 1. Hence, introducing the 2 ˆ 2 matrices Ak “ ˆ1 ` ak ´ak ak ´ak ˙ we have ˆ uk`1 uk`1 ´ uk ˙ “ Ak ˆ uk uk ´ uk´1 ˙ and pvk`1; vk ´ vk`1q “ p vk; vk´1 ´ vkqAn´k. for 1 ď k ď n ´ 1. Since ` u1 > u1´u0 ˘ “ `10 ˘ and pv1; v0 ´ v1q “ p 1; 0 q, we get ˆ un un ´ un´1 ˙ “ An´1An´2 ¨ ¨ ¨ A1 ¨ ˆ10 ˙ and pvn; vn´1 ´ vnq “ p 1; 0 q ¨ An´1An´2 ¨ ¨ ¨ A1. It follows that punq “ p 1; 0 q ˆ un un ´ un´1 ˙ “ p 1; 0 q ¨ An´1An´2 ¨ ¨ ¨ A1 ¨ ˆ10 ˙ “ p vn; vn´1 ´ vnq ˆ10 ˙ “ p vnq. Comment 1. These sequences are related to the Fibonacci sequence; when a1 “ ¨ ¨ ¨ “ an´1 “ 1, we have uk “ vk “ Fk`1, the pk ` 1qst Fibonacci number. Also, for every positive integer k, the polynomial Pkpx1, . . . , x k´1q from Solution 2 is the sum of Fk`1 monomials. Comment 2. One may notice that the condition is equivalent to uk`1 uk “ 1 `
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
ak 1 ` ak´1 1 ` . . . ` a2 1 ` a1 and vk`1 vk “ 1 ` an´k 1 ` an´k`1 1 ` . . . ` an´2 1 ` an´1 so the problem claims that the corresponding continued fractions for un{un´1 and vn{vn´1 have the same numerator. 10 IMO 2013 Colombia Comment 3. An alternative variant of the problem is the following. Let n be a positive integer and let a1, . . . , a n´1 be arbitrary real numbers. Define the sequences u0, . . . , u n and v0, . . . , v n inductively by u0 “ v0 “ 0, u1 “ v1 “ 1, and uk`1 “ akuk ` uk´1, vk`1 “ an´kvk ` vk´1 for k “ 1, . . . , n ´ 1. Prove that un “ vn. All three solutions above can be reformulated to prove this statement; one may prove un “ vn “ ÿ > 0“i0ăi1ă... ăit“n, ij`1´ijis odd ai1 . . . a it´1 for n ą 0or observe that ˆuk`1 uk ˙ “ ˆak 11 0 ˙ ˆ uk uk´1 ˙ and pvk`1; vkq “ p vk; vk´1q ˆak 11 0 ˙ . Here we have uk`1 uk “ ak ` 1 ak´1 ` 1 ak´2 ` . . . ` 1 a1 “ r ak; ak´1, . . . , a 1s and vk`1 vk “ an´k ` 1 an´k`1 ` 1 an´k`2 ` . . . ` 1 an´1 “ r an´k; an´k`1, . . . , a n´1s, so this alternative statement is equivalent to the known fact that the continued fractions ran´1; an´2, . . . , a 1s and ra1; a2, . . . , a n´1s have the same numerator. Shortlisted problems – solutions 11
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
## A2. Prove that in any set of 2000 distinct real numbers there exist two pairs a ą b and c ą d with a ‰ c or b ‰ d, such that ˇˇˇˇ a ´ b c ´ d ´ 1 ˇˇˇˇ ă 1 100000 . (Lithuania) Solution. For any set S of n “ 2000 distinct real numbers, let D1 ď D2 ď ¨ ¨ ¨ ď Dm be the distances between them, displayed with their multiplicities. Here m “ npn ´ 1q{ 2. By rescaling the numbers, we may assume that the smallest distance D1 between two elements of S is D1 “ 1. Let D1 “ 1 “ y ´ x for x, y P S. Evidently Dm “ v ´ u is the difference between the largest element v and the smallest element u of S.If Di`1{Di ă 1 ` 10 ´5 for some i “ 1, 2, . . . , m ´ 1 then the required inequality holds, because 0 ď Di`1{Di ´ 1 ă 10 ´5. Otherwise, the reverse inequality Di`1 Di ě 1 ` 1 10 5 holds for each i “ 1, 2, . . . , m ´ 1, and therefore v ´ u “ Dm “ Dm D1 “ Dm Dm´1 ¨ ¨ ¨ D3 D2 ¨ D2 D1 ě ˆ 1 ` 1 10 5 ˙m´1 . From m ´ 1 “ npn ´ 1q{ 2 ´ 1 “ 1000 ¨ 1999 ´ 1 ą 19 ¨ 10 5, together with the fact that for all n ě 1, `1 ` 1 > n ˘n ě 1 ` `n > 1 ˘ ¨ 1 > n “ 2, we get ˆ 1 ` 1 10 5 ˙19 ¨10 5 “ ˜ˆ 1 ` 1 10 5 ˙10
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
5 ¸19 ě 219 “ 29 ¨ 210 ą 500 ¨ 1000 ą 2 ¨ 10 5, and so v ´ u “ Dm ą 2 ¨ 10 5.Since the distance of x to at least one of the numbers u, v is at least pu ´ vq{ 2 ą 10 5, we have |x ´ z| ą 10 5. for some z P t u, v u. Since y ´ x “ 1, we have either z ą y ą x (if z “ v) or y ą x ą z (if z “ u). If z ą y ą x, selecting a “ z, b “ y, c “ z and d “ x (so that b ‰ d), we obtain ˇˇˇˇ a ´ b c ´ d ´ 1 ˇˇˇˇ “ ˇˇˇˇ z ´ y z ´ x ´ 1 ˇˇˇˇ “ ˇˇˇˇ x ´ y z ´ x ˇˇˇˇ “ 1 z ´ x ă 10 ´5. Otherwise, if y ą x ą z, we may choose a “ y, b “ z, c “ x and d “ z (so that a ‰ c), and obtain ˇˇˇˇ a ´ b c ´ d ´ 1 ˇˇˇˇ “ ˇˇˇˇ y ´ z x ´ z ´ 1 ˇˇˇˇ “ ˇˇˇˇ y ´ x x ´ z ˇˇˇˇ “ 1 x ´ z ă 10 ´5. The desired result follows. Comment. As the solution shows, the numbers 2000 and 1 > 100000 appearing in the statement of the problem may be replaced by any n P Zą0 and δ ą 0 satisfying δp1 ` δqnpn´1q{ 2´1 ą 2.12 IMO 2013 Colombia ## A3. Let Qą0 be the set of positive rational numbers. Let f : Qą0 Ñ R be a function satisfying the conditions f pxqf pyq
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
ě f pxy q, (1) f px ` yq ě f pxq ` f pyq (2) for all x, y P Qą0. Given that f paq “ a for some rational a ą 1, prove that f pxq “ x for all x P Qą0. (Bulgaria) Solution. Denote by Zą0 the set of positive integers. Plugging x “ 1, y “ a into (1) we get f p1q ě 1. Next, by an easy induction on n we get from (2) that f pnx q ě nf pxq for all n P Zą0 and x P Qą0. (3) In particular, we have f pnq ě nf p1q ě n for all n P Zą0. (4) From (1) again we have f pm{nqf pnq ě f pmq, so f pqq ą 0 for all q P Qą0.Now, (2) implies that f is strictly increasing; this fact together with (4) yields f pxq ě f ptxuq ě txu ą x ´ 1 for all x ě 1. By an easy induction we get from (1) that f pxqn ě f pxnq, so f pxqn ě f pxnq ą xn ´ 1 ùñ f pxq ě n ?xn ´ 1 for all x ą 1 and n P Zą0.This yields f pxq ě x for every x ą 1. (5) (Indeed, if x ą y ą 1 then xn ´ yn “ p x ´ yqp xn´1 ` xn´2y ` ¨ ¨ ¨ ` ynq ą npx ´ yq, so for a large n we have xn ´ 1 ą yn and thus f pxq ą y.) Now, (1) and (5) give an “ f paqn ě f panq ě an, so f panq “ an. Now, for x ą 1 let us choose n P Zą0 such that an ´ x ą
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
1. Then by (2) and (5) we get an “ f panq ě f pxq ` f pan ´ xq ě x ` p an ´ xq “ an and therefore f pxq “ x for x ą 1. Finally, for every x P Qą0 and every n P Zą0, from (1) and (3) we get nf pxq “ f pnqf pxq ě f pnx q ě nf pxq, which gives f pnx q “ nf pxq. Therefore f pm{nq “ f pmq{ n “ m{n for all m, n P Zą0. Comment. The condition f paq “ a ą 1 is essential. Indeed, for b ě 1 the function f pxq “ bx 2 satisfies (1) and (2) for all x, y P Qą0, and it has a unique fixed point 1 {b ď 1. Shortlisted problems – solutions 13 ## A4. Let n be a positive integer, and consider a sequence a1, a 2, . . . , a n of positive integers. Extend it periodically to an infinite sequence a1, a 2, . . . by defining an`i “ ai for all i ě 1. If a1 ď a2 ď ¨ ¨ ¨ ď an ď a1 ` n (1) and aai ď n ` i ´ 1 for i “ 1, 2, . . . , n, (2) prove that a1 ` ¨ ¨ ¨ ` an ď n2. (Germany) Solution 1. First, we claim that ai ď n ` i ´ 1 for i “ 1, 2, . . . , n. (3) Assume contrariwise that i is the smallest counterexample. From an ě an´1 ě ¨ ¨ ¨ ě ai ě n ` i and aai ď n ` i ´ 1, taking into account the periodicity of our sequence, it follows that ai
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
cannot be congruent to i, i ` 1, . . . , n ´ 1, or n pmod nq. (4) Thus our assumption that ai ě n ` i implies the stronger statement that ai ě 2n ` 1, which by a1 ` n ě an ě ai gives a1 ě n ` 1. The minimality of i then yields i “ 1, and ( 4) becomes contradictory. This establishes our first claim. In particular we now know that a1 ď n. If an ď n, then a1 ď ¨ ¨ ¨ ď ¨ ¨ ¨ an ď n and the desired inequality holds trivially. Otherwise, consider the number t with 1 ď t ď n ´ 1 such that a1 ď a2 ď . . . ď at ď n ă at`1 ď . . . ď an. (5) Since 1 ď a1 ď n and aa1 ď n by ( 2), we have a1 ď t and hence an ď n ` t. Therefore if for each positive integer i we let bi be the number of indices j P t t ` 1, . . . , n u satisfying aj ě n ` i, we have b1 ě b2 ě . . . ě bt ě bt`1 “ 0. Next we claim that ai ` bi ď n for 1 ď i ď t. Indeed, by n ` i ´ 1 ě aai and ai ď n, each j with aj ě n ` i (thus aj ą aai ) belongs to tai ` 1, . . . , n u, and for this reason bi ď n ´ ai.It follows from the definition of the bis and ( 5) that at`1 ` . . . ` an ď npn ´ tq ` b1 ` .
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
. . ` bt. Adding a1 ` . . . ` at to both sides and using that ai ` bi ď n for 1 ď i ď t, we get a1 ` a2 ` ¨ ¨ ¨ ` an ď npn ´ tq ` nt “ n2 as we wished to prove. 14 IMO 2013 Colombia Solution 2. In the first quadrant of an infinite grid, consider the increasing “staircase” obtained by shading in dark the bottom ai cells of the ith column for 1 ď i ď n. We will prove that there are at most n2 dark cells. To do it, consider the n ˆ n square S in the first quadrant with a vertex at the origin. Also consider the n ˆ n square directly to the left of S. Starting from its lower left corner, shade in light the leftmost aj cells of the jth row for 1 ď j ď n. Equivalently, the light shading is obtained by reflecting the dark shading across the line x “ y and translating it n units to the left. The figure below illustrates this construction for the sequence 6 , 6, 6, 7, 7, 7, 8, 12 , 12 , 14. > iai > n+i−1 > aai We claim that there is no cell in S which is both dark and light. Assume, contrariwise, that there is such a cell in column i. Consider the highest dark cell in column i which is inside S. Since it is above a light cell and inside S, it must be light as well. There are two cases: Case 1. ai ď n If ai ď n then this dark and light cell is pi, a iq, as highlighted in the figure. However, this is the pn ` iq-th cell
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
in row ai, and we only shaded aai ă n ` i light cells in that row, a contradiction. Case 2. ai ě n ` 1If ai ě n ` 1, this dark and light cell is pi, n q. This is the pn ` iq-th cell in row n and we shaded an ď a1 ` n light cells in this row, so we must have i ď a1. But a1 ď aa1 ď n by (1) and (2), so i ď a1 implies ai ď aa1 ď n, contradicting our assumption. We conclude that there are no cells in S which are both dark and light. It follows that the number of shaded cells in S is at most n2.Finally, observe that if we had a light cell to the right of S, then by symmetry we would have a dark cell above S, and then the cell pn, n q would be dark and light. It follows that the number of light cells in S equals the number of dark cells outside of S, and therefore the number of shaded cells in S equals a1 ` ¨ ¨ ¨ ` an. The desired result follows. Solution 3. As in Solution 1, we first establish that ai ď n ` i ´ 1 for 1 ď i ď n. Now define ci “ max pai, i q for 1 ď i ď n and extend the sequence c1, c 2, . . . periodically modulo n. We claim that this sequence also satisfies the conditions of the problem. For 1 ď i ă j ď n we have ai ď aj and i ă j, so ci ď cj . Also an ď a1 ` n and n ă 1 ` n imply cn ď c1 ` n.
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
Finally, the definitions imply that cci P t aai , a i, a i ´ n, i u so cci ď n ` i ´ 1 by ( 2) and (3). This establishes ( 1) and ( 2) for c1, c 2, . . . .Shortlisted problems – solutions 15 Our new sequence has the additional property that ci ě i for i “ 1, 2, . . . , n, (6) which allows us to construct the following visualization: Consider n equally spaced points on a circle, sequentially labelled 1 , 2, . . . , n pmod nq, so point k is also labelled n ` k. We draw arrows from vertex i to vertices i ` 1, . . . , c i for 1 ď i ď n, keeping in mind that ci ě i by ( 6). Since ci ď n ` i ´ 1 by ( 3), no arrow will be drawn twice, and there is no arrow from a vertex to itself. The total number of arrows is number of arrows “ > n ÿ > i“1 pci ´ iq “ > n ÿ > i“1 ci ´ ˆn ` 12 ˙ Now we show that we never draw both arrows i Ñ j and j Ñ i for 1 ď i ă j ď n. Assume contrariwise. This means, respectively, that i ă j ď ci and j ă n ` i ď cj . We have n ` i ď cj ď c1 ` n by ( 1), so i ď c1. Since c1 ď n by ( 3), this implies that ci ď cc1 ď n using ( 1) and ( 3). But then, using ( 1) again, j ď ci ď n implies cj ď cci , which combined
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
with n ` i ď cj gives us that n ` i ď cci . This contradicts ( 2). This means that the number of arrows is at most `n > 2 ˘, which implies that > n ÿ > i“1 ci ď ˆn 2 ˙ ` ˆn ` 12 ˙ “ n2. Recalling that ai ď ci for 1 ď i ď n, the desired inequality follows. Comment 1. We sketch an alternative proof by induction. Begin by verifying the initial case n “ 1 and the simple cases when a1 “ 1, a1 “ n, or an ď n. Then, as in Solution 1, consider the index t such that a1 ď ¨ ¨ ¨ ď at ď n ă at`1 ď ¨ ¨ ¨ ď an. Observe again that a1 ď t. Define the sequence d1, . . . , d n´1 by di “ # ai`1 ´ 1 if i ď t ´ 1 ai`1 ´ 2 if i ě t and extend it periodically modulo n ´ 1. One may verify that this sequence also satisfies the hypotheses of the problem. The induction hypothesis then gives d1 ` ¨ ¨ ¨ ` dn´1 ď p n ´ 1q2, which implies that > n ÿ > i“1 ai “ a1 ` > t ÿ > i“2 pdi´1 ` 1q ` > n ÿ > i“t`1 pdi´1 ` 2q ď t ` p t ´ 1q ` 2pn ´ tq ` p n ´ 1q2 “ n2. Comment 2. One unusual feature of this problem is that there are many different sequences for which equality holds. The discovery of such optimal sequences is not difficult, and it is useful in guiding the steps of a proof. In fact, Solution 2 gives a complete description of the optimal
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
sequences. Start with any lattice path P from the lower left to the upper right corner of the n ˆ n square S using only steps up and right, such that the total number of steps along the left and top edges of S is at least n. Shade the cells of S below P dark, and the cells of S above P light. Now reflect the light shape across the line x “ y and shift it up n units, and shade it dark. As Solution 2 shows, the dark region will then correspond to an optimal sequence, and every optimal sequence arises in this way. 16 IMO 2013 Colombia ## A5. Let Zě0 be the set of all nonnegative integers. Find all the functions f : Zě0 Ñ Zě0 satisfying the relation f pf pf pnqqq “ f pn ` 1q ` 1 p˚q for all n P Zě0. (Serbia) Answer. There are two such functions: f pnq “ n ` 1 for all n P Zě0, and f pnq “ $’&’% n ` 1, n ” 0 pmod 4 q or n ” 2 pmod 4 q,n ` 5, n ” 1 pmod 4 q,n ´ 3, n ” 3 pmod 4 q for all n P Zě0. (1) Throughout all the solutions, we write hkpxq to abbreviate the kth iteration of function h, so h0 is the identity function, and hkpxq “ hp. . . h loomoon > ktimes pxq . . . qq for k ě 1. Solution 1. To start, we get from p˚q that f 4pnq “ f pf 3pnqq “ f `f pn ` 1q ` 1˘ and f 4pn ` 1q “ f 3pf pn ` 1qq “ f `f pn ` 1q ` 1˘ ` 1, thus f 4pnq `
|
{
"page_id": null,
"source": 6828,
"title": "from dpo"
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.