:: BINTREE2 semantic presentation

theorem Th1: :: BINTREE2:1
for b1 being set
for b2 being FinSequence
for b3 being Nat st b2 in b1 * holds
b2 | (Seg b3) in b1 *
proof end;

theorem Th2: :: BINTREE2:2
for b1 being binary Tree
for b2 being Element of b1 holds b2 is FinSequence of BOOLEAN
proof end;

definition
let c1 be binary Tree;
redefine mode Element as Element of c1 -> FinSequence of BOOLEAN ;
coherence
for b1 being Element of c1 holds b1 is FinSequence of BOOLEAN
by Th2;
end;

theorem Th3: :: BINTREE2:3
for b1 being Tree st b1 = {0,1} * holds
b1 is binary
proof end;

theorem Th4: :: BINTREE2:4
for b1 being Tree st b1 = {0,1} * holds
Leaves b1 = {}
proof end;

theorem Th5: :: BINTREE2:5
for b1 being binary Tree
for b2 being Nat
for b3 being Element of b1 st b3 in b1 -level b2 holds
b3 is Tuple of b2,BOOLEAN
proof end;

theorem Th6: :: BINTREE2:6
for b1 being Tree st ( for b2 being Element of b1 holds succ b2 = {(b2 ^ <*0*>),(b2 ^ <*1*>)} ) holds
Leaves b1 = {}
proof end;

theorem Th7: :: BINTREE2:7
for b1 being Tree st ( for b2 being Element of b1 holds succ b2 = {(b2 ^ <*0*>),(b2 ^ <*1*>)} ) holds
b1 is binary
proof end;

theorem Th8: :: BINTREE2:8
for b1 being Tree holds
( b1 = {0,1} * iff for b2 being Element of b1 holds succ b2 = {(b2 ^ <*0*>),(b2 ^ <*1*>)} )
proof end;

scheme :: BINTREE2:sch 1
s1{ F1() -> non empty set , F2() -> Element of F1(), P1[ set , set , set ] } :
ex b1 being binary DecoratedTree of F1() st
( dom b1 = {0,1} * & b1 . {} = F2() & ( for b2 being Node of b1 holds P1[b1 . b2,b1 . (b2 ^ <*0*>),b1 . (b2 ^ <*1*>)] ) )
provided
E7: for b1 being Element of F1() ex b2, b3 being Element of F1() st P1[b1,b2,b3]
proof end;

scheme :: BINTREE2:sch 2
s2{ F1() -> non empty set , F2() -> Element of F1(), P1[ set , set ], P2[ set , set ] } :
ex b1 being binary DecoratedTree of F1() st
( dom b1 = {0,1} * & b1 . {} = F2() & ( for b2 being Node of b1 holds
( P1[b1 . b2,b1 . (b2 ^ <*0*>)] & P2[b1 . b2,b1 . (b2 ^ <*1*>)] ) ) )
provided
E7: for b1 being Element of F1() ex b2 being Element of F1() st P1[b1,b2] and
E8: for b1 being Element of F1() ex b2 being Element of F1() st P2[b1,b2]
proof end;

Lemma7: for b1 being non empty set
for b2 being FinSequence of b1 holds Rev b2 is FinSequence of b1
;

definition
let c1 be binary Tree;
let c2 be non empty Nat;
func NumberOnLevel c2,c1 -> Function of a1 -level a2, NAT means :Def1: :: BINTREE2:def 1
for b1 being Element of a1 st b1 in a1 -level a2 holds
for b2 being Tuple of a2,BOOLEAN st b2 = Rev b1 holds
a3 . b1 = (Absval b2) + 1;
existence
ex b1 being Function of c1 -level c2, NAT st
for b2 being Element of c1 st b2 in c1 -level c2 holds
for b3 being Tuple of c2,BOOLEAN st b3 = Rev b2 holds
b1 . b2 = (Absval b3) + 1
proof end;
uniqueness
for b1, b2 being Function of c1 -level c2, NAT st ( for b3 being Element of c1 st b3 in c1 -level c2 holds
for b4 being Tuple of c2,BOOLEAN st b4 = Rev b3 holds
b1 . b3 = (Absval b4) + 1 ) & ( for b3 being Element of c1 st b3 in c1 -level c2 holds
for b4 being Tuple of c2,BOOLEAN st b4 = Rev b3 holds
b2 . b3 = (Absval b4) + 1 ) holds
b1 = b2
proof end;
end;

:: deftheorem Def1 defines NumberOnLevel BINTREE2:def 1 :
for b1 being binary Tree
for b2 being non empty Nat
for b3 being Function of b1 -level b2, NAT holds
( b3 = NumberOnLevel b2,b1 iff for b4 being Element of b1 st b4 in b1 -level b2 holds
for b5 being Tuple of b2,BOOLEAN st b5 = Rev b4 holds
b3 . b4 = (Absval b5) + 1 );

registration
let c1 be binary Tree;
let c2 be non empty Nat;
cluster NumberOnLevel a2,a1 -> one-to-one ;
coherence
NumberOnLevel c2,c1 is one-to-one
proof end;
end;

definition
let c1 be Tree;
attr a1 is full means :Def2: :: BINTREE2:def 2
a1 = {0,1} * ;
end;

:: deftheorem Def2 defines full BINTREE2:def 2 :
for b1 being Tree holds
( b1 is full iff b1 = {0,1} * );

theorem Th9: :: BINTREE2:9
{0,1} * is Tree
proof end;

theorem Th10: :: BINTREE2:10
for b1 being Tree st b1 = {0,1} * holds
for b2 being Nat holds 0* b2 in b1 -level b2
proof end;

theorem Th11: :: BINTREE2:11
for b1 being Tree st b1 = {0,1} * holds
for b2 being non empty Nat
for b3 being Tuple of b2,BOOLEAN holds b3 in b1 -level b2
proof end;

registration
let c1 be binary Tree;
let c2 be Nat;
cluster a1 -level a2 -> finite ;
coherence
c1 -level c2 is finite
by QC_LANG4:19;
end;

registration
cluster full -> binary set ;
coherence
for b1 being Tree st b1 is full holds
b1 is binary
proof end;
end;

registration
cluster binary full set ;
existence
ex b1 being Tree st b1 is full
proof end;
end;

theorem Th12: :: BINTREE2:12
for b1 being full Tree
for b2 being non empty Nat holds Seg (2 to_power b2) c= rng (NumberOnLevel b2,b1)
proof end;

definition
let c1 be full Tree;
let c2 be non empty Nat;
func FinSeqLevel c2,c1 -> FinSequence of a1 -level a2 equals :: BINTREE2:def 3
(NumberOnLevel a2,a1) " ;
coherence
(NumberOnLevel c2,c1) " is FinSequence of c1 -level c2
proof end;
end;

:: deftheorem Def3 defines FinSeqLevel BINTREE2:def 3 :
for b1 being full Tree
for b2 being non empty Nat holds FinSeqLevel b2,b1 = (NumberOnLevel b2,b1) " ;

registration
let c1 be full Tree;
let c2 be non empty Nat;
cluster FinSeqLevel a2,a1 -> one-to-one ;
coherence
FinSeqLevel c2,c1 is one-to-one
by FUNCT_1:62;
end;

theorem Th13: :: BINTREE2:13
for b1 being full Tree
for b2 being non empty Nat holds (NumberOnLevel b2,b1) . (0* b2) = 1
proof end;

theorem Th14: :: BINTREE2:14
for b1 being full Tree
for b2 being non empty Nat
for b3 being Tuple of b2,BOOLEAN st b3 = 0* b2 holds
(NumberOnLevel b2,b1) . ('not' b3) = 2 to_power b2
proof end;

theorem Th15: :: BINTREE2:15
for b1 being full Tree
for b2 being non empty Nat holds (FinSeqLevel b2,b1) . 1 = 0* b2
proof end;

theorem Th16: :: BINTREE2:16
for b1 being full Tree
for b2 being non empty Nat
for b3 being Tuple of b2,BOOLEAN st b3 = 0* b2 holds
(FinSeqLevel b2,b1) . (2 to_power b2) = 'not' b3
proof end;

theorem Th17: :: BINTREE2:17
for b1 being full Tree
for b2 being non empty Nat
for b3 being Nat st b3 in Seg (2 to_power b2) holds
(FinSeqLevel b2,b1) . b3 = Rev (b2 -BinarySequence (b3 -' 1))
proof end;

theorem Th18: :: BINTREE2:18
for b1 being full Tree
for b2 being Nat holds Card (b1 -level b2) = 2 to_power b2
proof end;

theorem Th19: :: BINTREE2:19
for b1 being full Tree
for b2 being non empty Nat holds len (FinSeqLevel b2,b1) = 2 to_power b2
proof end;

theorem Th20: :: BINTREE2:20
for b1 being full Tree
for b2 being non empty Nat holds dom (FinSeqLevel b2,b1) = Seg (2 to_power b2)
proof end;

theorem Th21: :: BINTREE2:21
for b1 being full Tree
for b2 being non empty Nat holds rng (FinSeqLevel b2,b1) = b1 -level b2
proof end;

theorem Th22: :: BINTREE2:22
for b1 being full Tree holds (FinSeqLevel 1,b1) . 1 = <*0*>
proof end;

theorem Th23: :: BINTREE2:23
for b1 being full Tree holds (FinSeqLevel 1,b1) . 2 = <*1*>
proof end;

theorem Th24: :: BINTREE2:24
for b1 being full Tree
for b2, b3 being non empty Nat st b3 <= 2 to_power (b2 + 1) holds
for b4 being Tuple of b2,BOOLEAN st b4 = (FinSeqLevel b2,b1) . ((b3 + 1) div 2) holds
(FinSeqLevel (b2 + 1),b1) . b3 = b4 ^ <*((b3 + 1) mod 2)*>
proof end;