Hi all and sorry for the bad English!
I'm implementing Bombelli's algorithm for a big-integer library, and for optimization I'd need to prove some details regarding the values that certain variables can assume or not.
First of all, here is my algorithm formalization attempt:
What I should prove (or even disprove) is:
a) [imath]a_i[/imath] has at most one more digit than [imath]2bR_{i-1} \ [/imath];
b) for [imath]r_i \neq 0[/imath] the difference [imath]a_i-c_i[/imath] has at most the same number of digits as [imath]c_i \ [/imath];
c) for [imath]i>1[/imath] when [imath]a_i[/imath] has one more digit than [imath]2bR_{i-1} \ [/imath], let [imath]A[/imath] be the number consisting of the first two digits of [imath]a_i[/imath] and [imath]B[/imath] be the number consisting of the first digit of [imath]2bR_{i-1} \ [/imath], then [imath]\frac{A}{B+1}<b \ [/imath].
About a), the numerical example above demonstrates that [imath]a_i[/imath] can have one more digit than [imath]2bR_{i-1} \ [/imath], so now we need to show that it cannot have [imath]2[/imath] (or more) more. Assuming that [imath]a_i[/imath] has [imath]2[/imath] more digits than [imath]2bR_{i-1} \ [/imath], we can set [imath]a_i \geq b^{k+1}[/imath] and [imath]2bR_{i-1} \leq b^k-b[/imath], that is, [imath]a_i[/imath] is greater than or equal to the smallest number of [imath]k+2[/imath] digits and [imath]2bR_{i-1}[/imath] is less than or equal to the largest number of [imath]k[/imath] digits ending in [imath]0[/imath]; in this case 4) would also be verified for [imath]r_i=b \ [/imath], in fact [math]c_i=r_i(2bR_{i-1}+r_i) \leq b(b^k-b+b)=b^{k+1} \leq a_i[/math] but since it must be [imath]r_i<b \ [/imath], we can conclude that [imath]a_1[/imath] will have at most one more digit than [imath]2bR_{i-1} \ [/imath].
About b), obviously the problem only arises when [imath]a_i[/imath] has more digits than [imath]c_i \ [/imath]. I would have thought of distinguishing the case [imath]i=1[/imath] from the case i>1, but in any case I would only be able to prove the first case.
About c), to maximize [imath]\frac{A}{B+1}[/imath] we set [imath]B=1[/imath] (we can obtain it for example for [imath]r_1 \geq \Bigl \lceil \frac{b}{2} \Bigr \rceil[/imath]), then we get that [imath]\frac{A}{1+1}<b \Rightarrow A<2b \ [/imath] , that is, the first digit of [imath]A[/imath] should be [imath]1[/imath], but i don't know how to prove it.
So in the end I ask whether my proof of a) is correct and whether it can be done better, and how to prove (or even disprove) b) and c).
I'm implementing Bombelli's algorithm for a big-integer library, and for optimization I'd need to prove some details regarding the values that certain variables can assume or not.
First of all, here is my algorithm formalization attempt:
[math]\Bigl \lfloor \sqrt{N} \Bigr \rfloor = \Bigl \lfloor \sqrt{n_1 | n_2| ... | n_i | ... | n_m} \Bigr \rfloor = r_1 | r_2 | ... | r_i | ... | r_m = R_m[/math]
Let [imath]b[/imath] be the numeric base used, [imath]r_i<b[/imath] is the [imath]i[/imath]-th digit of the result, [imath]R_i[/imath] is the partial result at the [imath]i[/imath]-th step, while [imath]n_i[/imath] is obtained by dividing [imath]N[/imath] into groups of two digit starting from the right. Given that
1) [imath]a_0=c_0=R_0=0[/imath]
algorithm steps for [imath]i=1,2,...,m[/imath] are:
2) [imath]a_i=b^2(a_{i-1}-c_{i-1})+n_i[/imath]
3) [imath]c_i=r_i(2bR_{i-1}+r_i)[/imath]
4) [imath]c_i \leq a_i[/imath]
5) [imath]R_i=bR_{i-1}+r_i[/imath]
Where 4) constitues an inequality in the unknown [imath]r_i[/imath] to be solved in the set [imath]ℕ[/imath], i.e. [imath]r_i[/imath] represents the maximum natural number that satisfies 4).
What I should prove (or even disprove) is:
a) [imath]a_i[/imath] has at most one more digit than [imath]2bR_{i-1} \ [/imath];
b) for [imath]r_i \neq 0[/imath] the difference [imath]a_i-c_i[/imath] has at most the same number of digits as [imath]c_i \ [/imath];
c) for [imath]i>1[/imath] when [imath]a_i[/imath] has one more digit than [imath]2bR_{i-1} \ [/imath], let [imath]A[/imath] be the number consisting of the first two digits of [imath]a_i[/imath] and [imath]B[/imath] be the number consisting of the first digit of [imath]2bR_{i-1} \ [/imath], then [imath]\frac{A}{B+1}<b \ [/imath].
About a), the numerical example above demonstrates that [imath]a_i[/imath] can have one more digit than [imath]2bR_{i-1} \ [/imath], so now we need to show that it cannot have [imath]2[/imath] (or more) more. Assuming that [imath]a_i[/imath] has [imath]2[/imath] more digits than [imath]2bR_{i-1} \ [/imath], we can set [imath]a_i \geq b^{k+1}[/imath] and [imath]2bR_{i-1} \leq b^k-b[/imath], that is, [imath]a_i[/imath] is greater than or equal to the smallest number of [imath]k+2[/imath] digits and [imath]2bR_{i-1}[/imath] is less than or equal to the largest number of [imath]k[/imath] digits ending in [imath]0[/imath]; in this case 4) would also be verified for [imath]r_i=b \ [/imath], in fact [math]c_i=r_i(2bR_{i-1}+r_i) \leq b(b^k-b+b)=b^{k+1} \leq a_i[/math] but since it must be [imath]r_i<b \ [/imath], we can conclude that [imath]a_1[/imath] will have at most one more digit than [imath]2bR_{i-1} \ [/imath].
About b), obviously the problem only arises when [imath]a_i[/imath] has more digits than [imath]c_i \ [/imath]. I would have thought of distinguishing the case [imath]i=1[/imath] from the case i>1, but in any case I would only be able to prove the first case.
About c), to maximize [imath]\frac{A}{B+1}[/imath] we set [imath]B=1[/imath] (we can obtain it for example for [imath]r_1 \geq \Bigl \lceil \frac{b}{2} \Bigr \rceil[/imath]), then we get that [imath]\frac{A}{1+1}<b \Rightarrow A<2b \ [/imath] , that is, the first digit of [imath]A[/imath] should be [imath]1[/imath], but i don't know how to prove it.
So in the end I ask whether my proof of a) is correct and whether it can be done better, and how to prove (or even disprove) b) and c).
