:: High Speed Adder Algorithm with Radix-$2^k$ SD_Sub Number
:: by Masaaki Niimura and Yasushi Fuwa
::
:: Copyright (c) 2003-2021 Association of Mizar Users

for k being Nat st 2 <= k holds
proof end;

Lm1: for k being Nat
for i1 being Integer st i1 in k -SD_Sub_S holds
( i1 >= - (Radix (k -' 1)) & i1 <= (Radix (k -' 1)) - 1 )

proof end;

Lm2: for n, m, k, i being Nat st i in Seg n holds
DigA ((DecSD (m,(n + 1),k)),i) = DigA ((DecSD (m,n,k)),i)

proof end;

Lm3: for k, x, n being Nat st n >= 1 holds
DigA ((DecSD ((x mod (() |^ n)),n,k)),n) = DigA ((DecSD (x,n,k)),n)

proof end;

for x, y being Integer
for k being Nat st 3 <= k holds
proof end;

for n, m, k being Nat st 2 <= k holds
DigA_SDSub ((SD2SDSub (DecSD (m,n,k))),(n + 1)) = SDSub_Add_Carry ((DigA ((DecSD (m,n,k)),n)),k)
proof end;

for m, k being Nat st 2 <= k & m is_represented_by 1,k holds
DigA_SDSub ((SD2SDSub (DecSD (m,1,k))),(1 + 1)) = SDSub_Add_Carry (m,k)
proof end;

for k, x, n being Nat st n >= 1 & k >= 3 & x is_represented_by n + 1,k holds
DigA_SDSub ((SD2SDSub (DecSD ((x mod (() |^ n)),n,k))),(n + 1)) = SDSub_Add_Carry ((DigA ((DecSD (x,n,k)),n)),k)
proof end;

for m, k being Nat st 2 <= k & m is_represented_by 1,k holds
DigA_SDSub ((SD2SDSub (DecSD (m,1,k))),1) = m - ((SDSub_Add_Carry (m,k)) * ())
proof end;

for k, x, n being Nat st k >= 2 holds
(() |^ n) * (DigA_SDSub ((SD2SDSub (DecSD (x,(n + 1),k))),(n + 1))) = (((() |^ n) * (DigA ((DecSD (x,(n + 1),k)),(n + 1)))) - ((() |^ (n + 1)) * (SDSub_Add_Carry ((DigA ((DecSD (x,(n + 1),k)),(n + 1))),k)))) + ((() |^ n) * (SDSub_Add_Carry ((DigA ((DecSD (x,(n + 1),k)),n)),k)))
proof end;

definition
let i, n, k be Nat;
let x, y be Tuple of n,k -SD_Sub ;
assume that
A1: i in Seg n and
A2: k >= 2 ;
func SDSubAddDigit (x,y,i,k) -> Element of k -SD_Sub equals :Def1: :: RADIX_4:def 1
(SDSub_Add_Data (((DigA_SDSub (x,i)) + (DigA_SDSub (y,i))),k)) + (SDSub_Add_Carry (((DigA_SDSub (x,(i -' 1))) + (DigA_SDSub (y,(i -' 1)))),k));
coherence
(SDSub_Add_Data (((DigA_SDSub (x,i)) + (DigA_SDSub (y,i))),k)) + (SDSub_Add_Carry (((DigA_SDSub (x,(i -' 1))) + (DigA_SDSub (y,(i -' 1)))),k)) is Element of k -SD_Sub
proof end;
end;

for i, n, k being Nat
for x, y being Tuple of n,k -SD_Sub st i in Seg n & k >= 2 holds
SDSubAddDigit (x,y,i,k) = (SDSub_Add_Data (((DigA_SDSub (x,i)) + (DigA_SDSub (y,i))),k)) + (SDSub_Add_Carry (((DigA_SDSub (x,(i -' 1))) + (DigA_SDSub (y,(i -' 1)))),k));

definition
let n, k be Nat;
let x, y be Tuple of n,k -SD_Sub ;
func x '+' y -> Tuple of n,k -SD_Sub means :Def2: :: RADIX_4:def 2
for i being Nat st i in Seg n holds
existence
ex b1 being Tuple of n,k -SD_Sub st
for i being Nat st i in Seg n holds
proof end;
uniqueness
for b1, b2 being Tuple of n,k -SD_Sub st ( for i being Nat st i in Seg n holds
DigA_SDSub (b1,i) = SDSubAddDigit (x,y,i,k) ) & ( for i being Nat st i in Seg n holds
DigA_SDSub (b2,i) = SDSubAddDigit (x,y,i,k) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines '+' RADIX_4:def 2 :
for n, k being Nat
for x, y, b5 being Tuple of n,k -SD_Sub holds
( b5 = x '+' y iff for i being Nat st i in Seg n holds
DigA_SDSub (b5,i) = SDSubAddDigit (x,y,i,k) );