def sqrt_next
import bend-collections-laws-math@1.0.0.0/src/math/natural.bend as Naturalimport Base
213# the largest r with r * r <= n, by Heron's (Newton's) iteration as in Lean 4
214# Mathlib's Nat.sqrt: g := (g + n / g) / 2 while that decreases g. Started
215# from 2^(b/2 + 1) >= sqrt(n) (n < 2^b, b = bit_length(n)) it converges in
216# O(log b) steps; the fuel g bounds the (strictly decreasing) steps.
217def sqrt_next(+n: Nat, +g: Nat) -> Nat:
218 Nat.div(Nat.add(g, Nat.div(n, g)), 2n)
Uses (3)
Used by (9)
- bend-collections-laws-math@1.0.0.0/src/math/natural:sqrt_iter
- bend-collections-laws-math@1.0.0.0/proofs/math/natural/sqrtn:isqrt_le
- bend-collections-laws-math@1.0.0.0/proofs/math/natural/sqrtn:lt_succ_isqrt
- bend-collections-laws-math@1.0.0.0/proofs/math/natural/sqrtn:iter_lt
- bend-collections-laws-math@1.0.0.0/proofs/math/natural/sqrtn:iter_sq
- …