整方根函數(英語:integer square root function),是指函數值為不大於自變量 a {\displaystyle a} 的算術平方根的最大整數,定義域為自然數,符號表示為 ⌊ a ⌋ {\displaystyle \lfloor {\sqrt {a}}\rfloor } 。[1]
整方根函數 ⌊ a ⌋ {\displaystyle \lfloor {\sqrt {a}}\rfloor } 用原始遞歸函數可定義為:[1]
{ ⌊ 0 ⌋ = 0 ⌊ S a ⌋ = ⌊ a ⌋ + N ( S a − ˙ ( S ⌊ a ⌋ ) 2 {\displaystyle {\begin{cases}\lfloor {\sqrt {0}}\rfloor =0\\\lfloor {\sqrt {Sa}}\rfloor =\lfloor {\sqrt {a}}\rfloor +N(Sa{\dot {-}}(S\lfloor {\sqrt {a}}\rfloor )^{2}\end{cases}}}
由牛頓法迭代公式 x n + 1 = x n − f ( x n ) f ′ ( x n + 1 ) {\displaystyle x_{n+1}=x_{n}-{\frac {f(x_{n})}{f'(x_{n+1})}}} ,欲計算 ⌊ a ⌋ {\displaystyle \lfloor {\sqrt {a}}\rfloor } ,可令
f ( x ) = x 2 − a {\displaystyle f(x)=x^{2}-a} ,由 x 2 − a = 0 {\displaystyle x^{2}-a=0} ,得
f ( x ) {\displaystyle f(x)} 與 x {\displaystyle x} 軸相交於 x = a {\displaystyle x={\sqrt {a}}} ,可計算平方根,於是
f ′ ( x ) = 2 x {\displaystyle f'(x)=2x} ,代入迭代公式可得
x n + 1 = x n − x n 2 − a 2 x n {\displaystyle x_{n+1}=x_{n}-{\frac {x_{n}^{2}-a}{2x_{n}}}} ,整理得
x n + 1 = x n 2 + a 2 x n {\displaystyle x_{n+1}={\frac {x_{n}}{2}}+{\frac {a}{2x_{n}}}} 。
算法結束條件為 Δ n = | x n + 1 − x n | = 0 {\displaystyle \Delta _{n}=\left\vert x_{n+1}-x_{n}\right\vert =0} ,即 x n + 1 = x n {\displaystyle x_{n+1}=x_{n}} 。[2]