Natural.sqrt_next: def of bend-collections-laws-crypto@1.0.0.0 Import: import bend-collections-laws-crypto@1.0.0.0/src/math/natural.bend as Natural Lines 213-218 of bend-collections-laws-crypto@1.0.0.0/src/math/natural.bend: https://jend.leeeet.dev/read.txt?path=bend-collections-laws-crypto@1.0.0.0/src/math/natural.bend&start_line=213&end_line=218 import Base # the largest r with r * r <= n, by Heron's (Newton's) iteration as in Lean 4 # Mathlib's Nat.sqrt: g := (g + n / g) / 2 while that decreases g. Started # from 2^(b/2 + 1) >= sqrt(n) (n < 2^b, b = bit_length(n)) it converges in # O(log b) steps; the fuel g bounds the (strictly decreasing) steps. def sqrt_next(+n: Nat, +g: Nat) -> Nat: Nat.div(Nat.add(g, Nat.div(n, g)), 2n) Uses (3): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.div