{
  "index": "2008-B-5",
  "type": "ANA",
  "tag": [
    "ANA",
    "NT"
  ],
  "difficulty": "",
  "question": "Find all continuously differentiable functions $f: \\mathbb{R} \\to \\mathbb{R}$\nsuch that for every rational number $q$, the number $f(q)$ is rational\nand has the same denominator as $q$. (The denominator of a rational number\n$q$ is the unique positive integer $b$ such that $q = a/b$\nfor some integer $a$ with $\\mathrm{gcd}(a,b) = 1$.)\n(Note: gcd means greatest common\ndivisor.)",
  "solution": "The functions $f(x) = x+n$ and $f(x)=-x+n$ for any integer $n$ clearly satisfy the condition of the problem; we claim that these are the only possible $f$.\n\nLet $q=a/b$ be any rational number with $\\gcd(a,b)=1$ and $b>0$. For $n$ any positive integer, we have\n\\[\n\\frac{f(\\frac{an+1}{bn}) - f(\\frac{a}{b})}{\\frac{1}{bn}}\n= bn f\\left(\\frac{an+1}{bn}\\right) - nb f\\left(\\frac{a}{b}\\right)\n\\]\nis an integer by the property of $f$. Since $f$ is differentiable at $a/b$, the left hand side has a limit. It follows that for sufficiently large $n$, both sides must be equal to some integer $c=f'(\\frac{a}{b})$: $f(\\frac{an+1}{bn}) = f(\\frac{a}{b})+\\frac{c}{bn}$. Now $c$ cannot be $0$, since otherwise $f(\\frac{an+1}{bn}) = f(\\frac{a}{b})$ for sufficiently large $n$ has denominator $b$ rather than $bn$. Similarly, $|c|$ cannot be greater than $1$: otherwise\nif we take $n=k|c|$ for $k$ a sufficiently large positive integer,\nthen $f(\\frac{a}{b})+\\frac{c}{bn}$ has denominator $bk$, contradicting the fact that $f(\\frac{an+1}{bn})$ has denominator $bn$. It follows that $c = f'(\\frac{a}{b}) = \\pm 1$.\n\nThus the derivative of $f$ at any rational number is $\\pm 1$. Since $f$ is continuously differentiable, we conclude that $f'(x) = 1$ for all real $x$ or $f'(x) = -1$ for all real $x$. Since $f(0)$ must be an integer (a rational number with denominator $1$), $f(x)=x+n$ or $f(x)=-x+n$ for some integer $n$.\n\n\\textbf{Remark:}\nAfter showing that $f'(q)$ is an integer for each $q$, one can instead\nargue that $f'$ is a continuous function from the rationals to the integers,\nso must be constant. One can then write $f(x) = ax+b$ and check that\n$b \\in \\ZZ$ by evaluation at $a=0$, and that $a= \\pm 1$ by evaluation at\n$x=1/a$.",
  "vars": [
    "x",
    "q",
    "a",
    "b"
  ],
  "params": [
    "n",
    "c",
    "k"
  ],
  "sci_consts": [],
  "variants": {
    "descriptive_long": {
      "map": {
        "x": "realvar",
        "q": "ratnum",
        "a": "numerat",
        "b": "denomi",
        "n": "posint",
        "c": "derico",
        "k": "multfac"
      },
      "question": "Find all continuously differentiable functions $f: \\mathbb{R} \\to \\mathbb{R}$ such that for every rational number $ratnum$, the number $f(ratnum)$ is rational and has the same denominator as $ratnum$. (The denominator of a rational number $ratnum$ is the unique positive integer $denomi$ such that $ratnum = numerat/denomi$ for some integer $numerat$ with $\\mathrm{gcd}(numerat,denomi) = 1$.) (Note: gcd means greatest common divisor.)",
      "solution": "The functions $f(realvar)=realvar+posint$ and $f(realvar)=-realvar+posint$ for any integer $posint$ clearly satisfy the condition of the problem; we claim that these are the only possible $f$.\n\nLet $ratnum=numerat/denomi$ be any rational number with $\\gcd(numerat,denomi)=1$ and $denomi>0$. For $posint$ any positive integer, we have\n\\[\n\\frac{f\\!\\left(\\frac{numerat\\,posint+1}{denomiposint}\\right)-f\\!\\left(\\frac{numerat}{denomi}\\right)}{\\frac{1}{denomiposint}}\n=denomiposint\\,f\\!\\left(\\frac{numerat\\,posint+1}{denomiposint}\\right)-posint denomi\\,f\\!\\left(\\frac{numerat}{denomi}\\right)\n\\]\nis an integer by the property of $f$. Since $f$ is differentiable at $numerat/denomi$, the left–hand side has a limit. It follows that for sufficiently large $posint$, both sides must equal some integer $derico=f'\\!\\left(\\tfrac{numerat}{denomi}\\right)$:\n\\[\nf\\!\\left(\\frac{numerat\\,posint+1}{denomiposint}\\right)=f\\!\\left(\\frac{numerat}{denomi}\\right)+\\frac{derico}{denomiposint} .\n\\]\nNow $derico$ cannot be $0$, for otherwise $f\\!\\left(\\frac{numerat\\,posint+1}{denomiposint}\\right)=f\\!\\left(\\frac{numerat}{denomi}\\right)$ for sufficiently large $posint$, which has denominator $denomi$ rather than $denomiposint$. Similarly, $|derico|$ cannot exceed $1$: otherwise, taking $posint=multfac|derico|$ for a sufficiently large positive integer $multfac$, the quantity $f\\!\\left(\\frac{numerat}{denomi}\\right)+\\frac{derico}{denomiposint}$ would have denominator $denomi multfac$, contradicting the fact that $f\\!\\left(\\frac{numerat\\,posint+1}{denomiposint}\\right)$ has denominator $denomiposint$. It follows that $derico=f'\\!\\left(\\tfrac{numerat}{denomi}\\right)=\\pm1$.\n\nThus the derivative of $f$ at every rational number is $\\pm1$. Because $f$ is continuously differentiable, we must have either $f'(realvar)=1$ for all real $realvar$ or $f'(realvar)=-1$ for all real $realvar$. Since $f(0)$ must be an integer (a rational number with denominator $1$), we conclude that $f(realvar)=realvar+posint$ or $f(realvar)=-realvar+posint$ for some integer $posint$.\n\n\\textbf{Remark:} After establishing that $f'(ratnum)$ is an integer for each rational $ratnum$, one can instead observe that $f'$ is a continuous function from the rationals to the integers and hence is constant. Writing $f(realvar)=numerat\\,realvar+denomi$, one checks that $denomi\\in\\mathbb{Z}$ by evaluating at $numerat=0$, and that $numerat=\\pm1$ by evaluating at $realvar=1/numerat$. Hence the same two families of solutions are obtained."
    },
    "descriptive_long_confusing": {
      "map": {
        "x": "landscape",
        "q": "melodyline",
        "a": "gemstone",
        "b": "raincloud",
        "n": "bookshelf",
        "c": "fingertip",
        "k": "snowflake"
      },
      "question": "Find all continuously differentiable functions $f: \\mathbb{R} \\to \\mathbb{R}$ such that for every rational number $melodyline$, the number $f(melodyline)$ is rational and has the same denominator as $melodyline$. (The denominator of a rational number $melodyline$ is the unique positive integer $raincloud$ such that $melodyline = gemstone/raincloud$ for some integer $gemstone$ with $\\mathrm{gcd}(gemstone,raincloud) = 1$.) (Note: gcd means greatest common divisor.)",
      "solution": "The functions $f(landscape) = landscape+bookshelf$ and $f(landscape)=-landscape+bookshelf$ for any integer $bookshelf$ clearly satisfy the condition of the problem; we claim that these are the only possible $f$.\n\nLet $melodyline=gemstone/raincloud$ be any rational number with $\\gcd(gemstone,raincloud)=1$ and $raincloud>0$. For $bookshelf$ any positive integer, we have\n\\[\n\\frac{f(\\frac{gemstonebookshelf+1}{raincloudbookshelf}) - f(\\frac{gemstone}{raincloud})}{\\frac{1}{raincloudbookshelf}}\n= raincloudbookshelf\\, f\\left(\\frac{gemstonebookshelf+1}{raincloudbookshelf}\\right) - bookshelfraincloud\\, f\\left(\\frac{gemstone}{raincloud}\\right)\n\\]\nis an integer by the property of $f$. Since $f$ is differentiable at $gemstone/raincloud$, the left hand side has a limit. It follows that for sufficiently large $bookshelf$, both sides must be equal to some integer $fingertip=f'(\\frac{gemstone}{raincloud})$: $f(\\frac{gemstonebookshelf+1}{raincloudbookshelf}) = f(\\frac{gemstone}{raincloud})+\\frac{fingertip}{raincloudbookshelf}$. Now $fingertip$ cannot be $0$, since otherwise $f(\\frac{gemstonebookshelf+1}{raincloudbookshelf}) = f(\\frac{gemstone}{raincloud})$ for sufficiently large $bookshelf$ has denominator $raincloud$ rather than $raincloudbookshelf$. Similarly, $|fingertip|$ cannot be greater than $1$: otherwise if we take $bookshelf=snowflake|fingertip|$ for $snowflake$ a sufficiently large positive integer, then $f(\\frac{gemstone}{raincloud})+\\frac{fingertip}{raincloudbookshelf}$ has denominator $raincloudsnowflake$, contradicting the fact that $f(\\frac{gemstonebookshelf+1}{raincloudbookshelf})$ has denominator $raincloudbookshelf$. It follows that $fingertip = f'(\\frac{gemstone}{raincloud}) = \\pm 1$.\n\nThus the derivative of $f$ at any rational number is $\\pm 1$. Since $f$ is continuously differentiable, we conclude that $f'(landscape) = 1$ for all real $landscape$ or $f'(landscape) = -1$ for all real $landscape$. Since $f(0)$ must be an integer (a rational number with denominator $1$), $f(landscape)=landscape+bookshelf$ or $f(landscape)=-landscape+bookshelf$ for some integer $bookshelf$.\n\n\\textbf{Remark:} After showing that $f'(melodyline)$ is an integer for each $melodyline$, one can instead argue that $f'$ is a continuous function from the rationals to the integers, so must be constant. One can then write $f(landscape) = gemstone\\,landscape+raincloud$ and check that $raincloud \\in \\ZZ$ by evaluation at $gemstone=0$, and that $gemstone = \\pm 1$ by evaluation at $landscape = 1/gemstone$.}",
      "confidence": "0.07"
    },
    "descriptive_long_misleading": {
      "map": {
        "x": "knownval",
        "q": "irrational",
        "a": "denominator",
        "b": "numerator",
        "n": "fractional",
        "c": "variable",
        "k": "noninteger"
      },
      "question": "Find all continuously differentiable functions $f: \\mathbb{R} \\to \\mathbb{R}$\nsuch that for every rational number $irrational$, the number $f(irrational)$ is rational\nand has the same denominator as $irrational$. (The denominator of a rational number\n$irrational$ is the unique positive integer $numerator$ such that $irrational = denominator/numerator$\nfor some integer $denominator$ with $\\mathrm{gcd}(denominator,numerator) = 1$.)\n(Note: gcd means greatest common\ndivisor.)",
      "solution": "The functions $f(knownval) = knownval+fractional$ and $f(knownval)=-knownval+fractional$ for any integer $fractional$ clearly satisfy the condition of the problem; we claim that these are the only possible $f$.\n\nLet $irrational=denominator/numerator$ be any rational number with $\\gcd(denominator,numerator)=1$ and $numerator>0$. For $fractional$ any positive integer, we have\n\\[\n\\frac{f(\\frac{denominator fractional+1}{numerator fractional}) - f(\\frac{denominator}{numerator})}{\\frac{1}{numerator fractional}}\n= numerator fractional f\\left(\\frac{denominator fractional+1}{numerator fractional}\\right) - fractional numerator f\\left(\\frac{denominator}{numerator}\\right)\n\\]\nis an integer by the property of $f$. Since $f$ is differentiable at $denominator/numerator$, the left hand side has a limit. It follows that for sufficiently large $fractional$, both sides must be equal to some integer $variable=f'(\\frac{denominator}{numerator})$: $f(\\frac{denominator fractional+1}{numerator fractional}) = f(\\frac{denominator}{numerator})+\\frac{variable}{numerator fractional}$. Now $variable$ cannot be $0$, since otherwise $f(\\frac{denominator fractional+1}{numerator fractional}) = f(\\frac{denominator}{numerator})$ for sufficiently large $fractional$ has denominator $numerator$ rather than $numerator fractional$. Similarly, $|variable|$ cannot be greater than $1$: otherwise\nif we take $fractional=noninteger|variable|$ for $noninteger$ a sufficiently large positive integer,\nthen $f(\\frac{denominator}{numerator})+\\frac{variable}{numerator fractional}$ has denominator $numerator noninteger$, contradicting the fact that $f(\\frac{denominator fractional+1}{numerator fractional})$ has denominator $numerator fractional$. It follows that $variable = f'(\\frac{denominator}{numerator}) = \\pm 1$.\n\nThus the derivative of $f$ at any rational number is $\\pm 1$. Since $f$ is continuously differentiable, we conclude that $f'(knownval) = 1$ for all real $knownval$ or $f'(knownval) = -1$ for all real $knownval$. Since $f(0)$ must be an integer (a rational number with denominator $1$), $f(knownval)=knownval+fractional$ or $f(knownval)=-knownval+fractional$ for some integer $fractional$.\n\n\\textbf{Remark:}\nAfter showing that $f'(irrational)$ is an integer for each $irrational$, one can instead\nargue that $f'$ is a continuous function from the rationals to the integers,\nso must be constant. One can then write $f(knownval) = denominator knownval+fractional$ and check that\n$fractional \\in \\ZZ$ by evaluation at $denominator=0$, and that $denominator= \\pm 1$ by evaluation at\n$knownval=1/denominator$.}",
      "confidence": "0.11"
    },
    "garbled_string": {
      "map": {
        "x": "qzxwvtnp",
        "q": "hjgrksla",
        "a": "plzxyqmn",
        "b": "rctvbkse",
        "n": "uidsawer",
        "c": "mfeqldop",
        "k": "tuvxpsar"
      },
      "question": "Find all continuously differentiable functions $f: \\mathbb{R} \\to \\mathbb{R}$\nsuch that for every rational number $hjgrksla$, the number $f(hjgrksla)$ is rational\nand has the same denominator as $hjgrksla$. (The denominator of a rational number\n$hjgrksla$ is the unique positive integer $rctvbkse$ such that $hjgrksla = plzxyqmn/rctvbkse$\nfor some integer $plzxyqmn$ with $\\mathrm{gcd}(plzxyqmn,rctvbkse) = 1$.)\n(Note: gcd means greatest common\ndivisor.)",
      "solution": "The functions $f(qzxwvtnp) = qzxwvtnp+uidsawer$ and $f(qzxwvtnp)=-qzxwvtnp+uidsawer$ for any integer $uidsawer$ clearly satisfy the condition of the problem; we claim that these are the only possible $f$.\n\nLet $hjgrksla=plzxyqmn/rctvbkse$ be any rational number with $\\gcd(plzxyqmn,rctvbkse)=1$ and $rctvbkse>0$. For $uidsawer$ any positive integer, we have\n\\[\n\\frac{f(\\frac{plzxyqmn uidsawer+1}{rctvbkse uidsawer}) - f(\\frac{plzxyqmn}{rctvbkse})}{\\frac{1}{rctvbkse uidsawer}}\n= rctvbkse uidsawer\\, f\\left(\\frac{plzxyqmn uidsawer+1}{rctvbkse uidsawer}\\right) - uidsawer rctvbkse\\, f\\left(\\frac{plzxyqmn}{rctvbkse}\\right)\n\\]\nis an integer by the property of $f$. Since $f$ is differentiable at $plzxyqmn/rctvbkse$, the left hand side has a limit. It follows that for sufficiently large $uidsawer$, both sides must be equal to some integer $mfeqldop=f'(\\frac{plzxyqmn}{rctvbkse})$: $f(\\frac{plzxyqmn uidsawer+1}{rctvbkse uidsawer}) = f(\\frac{plzxyqmn}{rctvbkse})+\\frac{mfeqldop}{rctvbkse uidsawer}$. Now $mfeqldop$ cannot be $0$, since otherwise $f(\\frac{plzxyqmn uidsawer+1}{rctvbkse uidsawer}) = f(\\frac{plzxyqmn}{rctvbkse})$ for sufficiently large $uidsawer$ has denominator $rctvbkse$ rather than $rctvbkse uidsawer$. Similarly, $|mfeqldop|$ cannot be greater than $1$: otherwise\nif we take $uidsawer=tuvxpsar|mfeqldop|$ for $tuvxpsar$ a sufficiently large positive integer,\nthen $f(\\frac{plzxyqmn}{rctvbkse})+\\frac{mfeqldop}{rctvbkse uidsawer}$ has denominator $rctvbkse tuvxpsar$, contradicting the fact that $f(\\frac{plzxyqmn uidsawer+1}{rctvbkse uidsawer})$ has denominator $rctvbkse uidsawer$. It follows that $mfeqldop = f'(\\frac{plzxyqmn}{rctvbkse}) = \\pm 1$.\n\nThus the derivative of $f$ at any rational number is $\\pm 1$. Since $f$ is continuously differentiable, we conclude that $f'(qzxwvtnp) = 1$ for all real $qzxwvtnp$ or $f'(qzxwvtnp) = -1$ for all real $qzxwvtnp$. Since $f(0)$ must be an integer (a rational number with denominator $1$), $f(qzxwvtnp)=qzxwvtnp+uidsawer$ or $f(qzxwvtnp)=-qzxwvtnp+uidsawer$ for some integer $uidsawer$.\n\n\\textbf{Remark:}\nAfter showing that $f'(hjgrksla)$ is an integer for each $hjgrksla$, one can instead\nargue that $f'$ is a continuous function from the rationals to the integers,\nso must be constant. One can then write $f(qzxwvtnp) = plzxyqmn qzxwvtnp+\\beta$ and check that\n$\\beta \\in \\ZZ$ by evaluation at $plzxyqmn=0$, and that $plzxyqmn= \\pm 1$ by evaluation at\n$qzxwvtnp=1/plzxyqmn$. "
    },
    "kernel_variant": {
      "question": "Let f : ℝ → ℝ be a continuously differentiable function that satisfies the following condition.  \nFor every rational number that is written in lowest terms as\n                   q = a / b   ( b > 0 ),\n the value f(q) is again rational and, when it is written in lowest terms, it has exactly the same denominator b.\nDetermine all such functions f.",
      "solution": "Throughout we write a rational number in lowest terms as q = a / b with b > 0 and gcd(a, b) = 1.\n\nStep 1 – An integer‐valued difference quotient.\nFix q = a / b and for n = 1, 2, … define \n     q_n := (a n + 1)/(b n).\nBecause |q_n – q| = 1/(b n) → 0, we have q_n → q.  \n\nIf q_n is written in lowest terms, its denominator divides b n, hence b n · f(q_n) is an integer.  Likewise b · f(q) is an integer; therefore b n · f(q) is an integer as well.  Consequently\n     D_n := (f(q_n) − f(q))/(q_n − q) = b n (f(q_n) − f(q))            (1)\nis an integer for every n.  Since f is differentiable at q, D_n → f′(q), so\n     f′(q) ∈ ℤ                                            (2)\nfor every rational q.\n\nStep 2 – Infinitely many indices whose denominator is exactly b n and that are divisible by a prescribed integer.\nLet t ≥ 1 be any fixed integer (later we shall take t = |f′(q)|).  We show that there are infinitely many positive integers n satisfying simultaneously\n     (i)  n ≡ 0  (mod t),\n     (ii) gcd(a n + 1, b) = 1.                            (3)\n\nWrite b = p_1 p_2 … p_r for its distinct prime divisors.  For each prime p_i ∤ t we choose a residue class c_i (mod p_i) with a c_i + 1 ≠ 0 (mod p_i).  Because the map n ↦ a n + 1 is surjective modulo p_i, there is at most one forbidden residue class, so such a choice is possible.  If p_i | t, we simply take the congruence n ≡ 0 (mod p_i); then a n + 1 ≡ 1 (mod p_i) and (ii) still holds.\n\nThus we have the system of congruences\n     n ≡ 0    (mod t),\n     n ≡ c_i  (mod p_i)  for every prime p_i ∤ t.          (4)\nBecause each modulus in (4) divides L := lcm(t, p_1, …, p_r) and the residue classes are pairwise compatible, the Chinese Remainder Theorem yields an arithmetic progression\n     n ≡ C   (mod L)                                       (5)\nall of whose elements satisfy both (i) and (ii).  In particular, for every such n we have\n     denom(q_n) = b n.                                     (6)\nSince (5) is infinite, there are infinitely many indices n for which (6) holds and which are multiples of the arbitrary integer t.\n\nStep 3 – Excluding the possibilities f′(q) = 0 and |f′(q)| ≥ 2.\n(a)  Assume f′(q) = 0.  Because D_n → 0 and every D_n is integral, choose N such that n ≥ N ⇒ |D_n| < 1/2.  Then D_n = 0 for all n ≥ N, so f(q_n) = f(q).  But for such n the denominator of q_n is b n → ∞ whereas that of f(q) is b, contradicting (6).  Hence f′(q) ≠ 0.\n\n(b)  Assume |f′(q)| ≥ 2 and put ℓ := f′(q).  Using (2) we know ℓ ∈ ℤ.  Apply Step 2 with the choice t = |ℓ|.  This gives infinitely many indices n that are divisible by |ℓ| and satisfy (6).  Because D_n → ℓ, pick one of those n large enough that |D_n − ℓ| < 1/2; then D_n = ℓ.  Consequently\n        f(q_n) = f(q) + ℓ/(b n) = f(q) + 1 /(b n / |ℓ|).\nHere b n / |ℓ| is a proper divisor of b n, contradicting (6).  Thus |f′(q)| ≥ 2 is impossible.\n\nCombining (a) and (b) we obtain\n        f′(q) = ±1   for every rational q.                (7)\n\nStep 4 – f′ is constant on ℝ.\nThe function f′ is continuous, and by (7) it takes only the two values {−1, 1} on the dense set ℚ.  Hence f′ is constant on ℝ, so\n        f′(x) ≡  1   or   f′(x) ≡ −1.                     (8)\n\nStep 5 – Integrate and determine the constant term.\nIntegrating (8) gives\n        f(x) =  x + c   or   f(x) = −x + c,   with c ∈ ℝ.\nBecause f(1) is a rational with denominator 1, we have f(1) ∈ ℤ, hence c ∈ ℤ.\n\nVerification.\nFor any integer n and any q = a / b,\n   (x + n)(q)  = a/b + n  = (a + n b)/b,      denom = b,\n   (−x + n)(q) = −a/b + n = (−a + n b)/b,     denom = b.\nThus both families fulfil the required property.\n\nConclusion.\nThe only continuously differentiable functions satisfying the stated condition are\n        f(x) =  x + n   and   f(x) = −x + n,        n ∈ ℤ.",
      "_meta": {
        "core_steps": [
          "For q = a/b (gcd(a,b)=1) choose rationals q_n = (an±1)/(bn) → q, so that q_n − q = ±1/(bn).",
          "Because f(q) has denominator b and f(q_n) denominator bn, the quantity bn f(q_n) − nb f(q) is an integer, hence the difference–quotient (f(q_n)−f(q))/(q_n−q) is an integer; taking n→∞ gives f'(q) ∈ ℤ for every rational q.",
          "A denominator–counting argument shows that f'(q) cannot be 0 or |f'(q)|>1; therefore f'(q)=±1 for all rational q.",
          "Continuity of f' forces f'(x) to be the same constant ±1 on all real x.",
          "Integrating and using that f takes integers to integers yields the only possibilities f(x)=x+n or f(x)=−x+n with n∈ℤ."
        ],
        "mutable_slots": {
          "slot1": {
            "description": "The ±1 added to the numerator when constructing the approximating rationals (an±1)/(bn).  Any choice of +1 or −1 keeps |q_n−q| = 1/(bn) and the proof identical.",
            "original": "+1"
          },
          "slot2": {
            "description": "The specific integer where f is evaluated to fix the vertical shift.  Replacing x=0 by any integer m (denominator 1) still forces the shift to be an integer.",
            "original": "x = 0"
          }
        }
      }
    }
  },
  "checked": true,
  "problem_type": "proof",
  "iteratively_fixed": true
}