English
Define ratSqrt(x, prec) as a rational approximation to sqrt(x) with accuracy 1/prec: ratSqrt(x, prec) = sqrt(x · prec^2) / prec.
Русский
Определим приближённое рациональное значение квадратного корня: ratSqrt(x, prec) = sqrt(x · prec^2) / prec, приближённое значение sqrt(x) с точностью 1/prec.
LaTeX
$$$ \operatorname{ratSqrt}(x, \operatorname{prec}) = \dfrac{\sqrt{x \cdot \operatorname{prec}^2}}{\operatorname{prec}} $$$
Lean4
/-- Approximate the square root of a natural number as a rational number, to within `1 / prec`.
-/
def ratSqrt (x : ℕ) (prec : ℕ) : ℚ :=
((x * prec ^ 2).sqrt : ℚ) / prec