Skip to main content
4 of 6
deleted 65 characters in body
user64494
  • 29.1k
  • 4
  • 29
  • 56

Since the feasible discrete set RealAbs[Sqrt[2] - x / y] < 0.0001 is infinite, this is a hard task for NMaximize. It can be done as follows. First, we find the maximum for x >= 100 && y >= 100 by

NMaximize[{Log[1/y, RealAbs[Sqrt[2] - x/y]], 
Element[{x, y}, Integers] && x >= 100 && y >= 100 && 
RealAbs[Sqrt[2] - x/y] < 0.0001}, {x, y},Method->{"DifferentialEvolution", "ScalingFactor" ->3}]

which produces {1.49309, {x -> 15043, y -> 10637}} and a warning

NMaximize::incst: NMaximize was unable to generate any initial points satisfying the inequality constraints {-0.0001+RealAbs[Sqrt[2]-Round[x]/Round[<<1>>]]<=0}. The initial region specified may not contain any feasible points. Changing the initial region or specifying explicit initial points may provide a better solution.

The above result is a feasible solution in view of

N[RealAbs[Sqrt[2] - x/y] /. {x -> 15043, y -> 10637}]

9.718*10^-7

Second, in order to be sure, we apply the known lower estimate for RealAbs[Sqrt[2] - x/y] (see the "Liouville numbers and transcendence" section in that Wiki article for info) $$\exists A>0\, \forall\{x,y\}\in\mathbb{N} \left| \sqrt{2}-\frac{x}{y}\right|> \frac A {y^2} $$. According to Lemma from this section, we may take $A=\frac 1 {2.9}$ ($M=2.9$). This inequality implies the inequality ForAll[{x,y},{x,y} \[Element] PositiveIntegers && y>1, Log[1/y, RealAbs[Sqrt[2] - x/y]] < Log[1/y, 1/2.9] + 2]. It is clear the maximum of Log[1/y, 1/2.9] + 2] for all integers y >=100 is attained at y==100 and is equal to N[Log[1/100, 1/2.9]]==0.231199.

Third, now we apply counting for x>=1&&x<=99&&y>=2&&y<=99

Do[If[RealAbs[Sqrt[2] - x/y] < 0.0001, Print[{x, y, N[Log[1/y, RealAbs[Sqrt[2] - x/y]]]}]],
 {x, 1, 99}, {y, 2, 99}]

{99,70,2.24473}

Summarizing the above, we draw the conclusion that the maximum under consideration is equal to 2.224473 at {x==99,y==70}.

user64494
  • 29.1k
  • 4
  • 29
  • 56