:: TREES_4 semantic presentation

definition
let c1 be DecoratedTree;
mode Node of a1 is Element of dom a1;
end;

E1: now
let c1, c2 be set ;
let c3 be FinSequence of c1;
assume ( c2 in dom c3 or c2 in dom c3 ) ;
then ( c3 . c2 in rng c3 & rng c3 c= c1 ) by FINSEQ_1:def 4, FUNCT_1:def 5;
hence c3 . c2 in c1 ;
end;

definition
let c1, c2 be DecoratedTree;
redefine pred c1 = c2 means :: TREES_4:def 1
( dom a1 = dom a2 & ( for b1 being Node of a1 holds a1 . b1 = a2 . b1 ) );
compatibility
( c1 = c2 iff ( dom c1 = dom c2 & ( for b1 being Node of c1 holds c1 . b1 = c2 . b1 ) ) )
proof end;
end;

:: deftheorem Def1 defines = TREES_4:def 1 :
for b1, b2 being DecoratedTree holds
( b1 = b2 iff ( dom b1 = dom b2 & ( for b3 being Node of b1 holds b1 . b3 = b2 . b3 ) ) );

theorem Th1: :: TREES_4:1
for b1, b2 being Nat st elementary_tree b1 c= elementary_tree b2 holds
b1 <= b2
proof end;

theorem Th2: :: TREES_4:2
for b1, b2 being Nat st elementary_tree b1 = elementary_tree b2 holds
b1 = b2
proof end;

Lemma4: for b1 being Nat
for b2 being FinSequence st b1 < len b2 holds
( b1 + 1 in dom b2 & b2 . (b1 + 1) in rng b2 )
proof end;

E5: now
let c1 be Nat;
let c2 be set ;
let c3 be FinSequence of c2;
assume c1 < len c3 ;
then ( c3 . (c1 + 1) in rng c3 & rng c3 c= c2 ) by Lemma4, FINSEQ_1:def 4;
hence c3 . (c1 + 1) in c2 ;
end;

definition
let c1 be set ;
func root-tree c1 -> DecoratedTree equals :: TREES_4:def 2
(elementary_tree 0) --> a1;
correctness
coherence
(elementary_tree 0) --> c1 is DecoratedTree
;
;
end;

:: deftheorem Def2 defines root-tree TREES_4:def 2 :
for b1 being set holds root-tree b1 = (elementary_tree 0) --> b1;

definition
let c1 be non empty set ;
let c2 be Element of c1;
redefine func root-tree as root-tree c2 -> Element of FinTrees a1;
coherence
root-tree c2 is Element of FinTrees c1
proof end;
end;

theorem Th3: :: TREES_4:3
for b1 being set holds
( dom (root-tree b1) = elementary_tree 0 & (root-tree b1) . {} = b1 )
proof end;

theorem Th4: :: TREES_4:4
for b1, b2 being set st root-tree b1 = root-tree b2 holds
b1 = b2
proof end;

theorem Th5: :: TREES_4:5
for b1 being DecoratedTree st dom b1 = elementary_tree 0 holds
b1 = root-tree (b1 . {} )
proof end;

theorem Th6: :: TREES_4:6
for b1 being set holds root-tree b1 = {[{} ,b1]}
proof end;

definition
let c1 be set ;
let c2 be FinSequence;
func c1 -flat_tree c2 -> DecoratedTree means :Def3: :: TREES_4:def 3
( dom a3 = elementary_tree (len a2) & a3 . {} = a1 & ( for b1 being Nat st b1 < len a2 holds
a3 . <*b1*> = a2 . (b1 + 1) ) );
existence
ex b1 being DecoratedTree st
( dom b1 = elementary_tree (len c2) & b1 . {} = c1 & ( for b2 being Nat st b2 < len c2 holds
b1 . <*b2*> = c2 . (b2 + 1) ) )
proof end;
uniqueness
for b1, b2 being DecoratedTree st dom b1 = elementary_tree (len c2) & b1 . {} = c1 & ( for b3 being Nat st b3 < len c2 holds
b1 . <*b3*> = c2 . (b3 + 1) ) & dom b2 = elementary_tree (len c2) & b2 . {} = c1 & ( for b3 being Nat st b3 < len c2 holds
b2 . <*b3*> = c2 . (b3 + 1) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def3 defines -flat_tree TREES_4:def 3 :
for b1 being set
for b2 being FinSequence
for b3 being DecoratedTree holds
( b3 = b1 -flat_tree b2 iff ( dom b3 = elementary_tree (len b2) & b3 . {} = b1 & ( for b4 being Nat st b4 < len b2 holds
b3 . <*b4*> = b2 . (b4 + 1) ) ) );

theorem Th7: :: TREES_4:7
for b1, b2 being set
for b3, b4 being FinSequence st b1 -flat_tree b3 = b2 -flat_tree b4 holds
( b1 = b2 & b3 = b4 )
proof end;

theorem Th8: :: TREES_4:8
for b1, b2 being Nat st b1 < b2 holds
(elementary_tree b2) | <*b1*> = elementary_tree 0
proof end;

theorem Th9: :: TREES_4:9
for b1 being set
for b2 being Nat
for b3 being FinSequence st b2 < len b3 holds
(b1 -flat_tree b3) | <*b2*> = root-tree (b3 . (b2 + 1))
proof end;

definition
let c1 be set ;
let c2 be FinSequence;
assume E11: c2 is DTree-yielding ;
func c1 -tree c2 -> DecoratedTree means :Def4: :: TREES_4:def 4
( ex b1 being DTree-yielding FinSequence st
( a2 = b1 & dom a3 = tree (doms b1) ) & a3 . {} = a1 & ( for b1 being Nat st b1 < len a2 holds
a3 | <*b1*> = a2 . (b1 + 1) ) );
existence
ex b1 being DecoratedTree st
( ex b2 being DTree-yielding FinSequence st
( c2 = b2 & dom b1 = tree (doms b2) ) & b1 . {} = c1 & ( for b2 being Nat st b2 < len c2 holds
b1 | <*b2*> = c2 . (b2 + 1) ) )
proof end;
uniqueness
for b1, b2 being DecoratedTree st ex b3 being DTree-yielding FinSequence st
( c2 = b3 & dom b1 = tree (doms b3) ) & b1 . {} = c1 & ( for b3 being Nat st b3 < len c2 holds
b1 | <*b3*> = c2 . (b3 + 1) ) & ex b3 being DTree-yielding FinSequence st
( c2 = b3 & dom b2 = tree (doms b3) ) & b2 . {} = c1 & ( for b3 being Nat st b3 < len c2 holds
b2 | <*b3*> = c2 . (b3 + 1) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def4 defines -tree TREES_4:def 4 :
for b1 being set
for b2 being FinSequence st b2 is DTree-yielding holds
for b3 being DecoratedTree holds
( b3 = b1 -tree b2 iff ( ex b4 being DTree-yielding FinSequence st
( b2 = b4 & dom b3 = tree (doms b4) ) & b3 . {} = b1 & ( for b4 being Nat st b4 < len b2 holds
b3 | <*b4*> = b2 . (b4 + 1) ) ) );

definition
let c1 be set ;
let c2 be DecoratedTree;
func c1 -tree c2 -> DecoratedTree equals :: TREES_4:def 5
a1 -tree <*a2*>;
correctness
coherence
c1 -tree <*c2*> is DecoratedTree
;
;
end;

:: deftheorem Def5 defines -tree TREES_4:def 5 :
for b1 being set
for b2 being DecoratedTree holds b1 -tree b2 = b1 -tree <*b2*>;

definition
let c1 be set ;
let c2, c3 be DecoratedTree;
func c1 -tree c2,c3 -> DecoratedTree equals :: TREES_4:def 6
a1 -tree <*a2,a3*>;
correctness
coherence
c1 -tree <*c2,c3*> is DecoratedTree
;
;
end;

:: deftheorem Def6 defines -tree TREES_4:def 6 :
for b1 being set
for b2, b3 being DecoratedTree holds b1 -tree b2,b3 = b1 -tree <*b2,b3*>;

theorem Th10: :: TREES_4:10
for b1 being set
for b2 being DTree-yielding FinSequence holds dom (b1 -tree b2) = tree (doms b2)
proof end;

theorem Th11: :: TREES_4:11
for b1, b2 being set
for b3 being DTree-yielding FinSequence holds
( b1 in dom (b2 -tree b3) iff ( b1 = {} or ex b4 being Natex b5 being DecoratedTreeex b6 being Node of b5 st
( b4 < len b3 & b5 = b3 . (b4 + 1) & b1 = <*b4*> ^ b6 ) ) )
proof end;

theorem Th12: :: TREES_4:12
for b1 being set
for b2 being DTree-yielding FinSequence
for b3 being Nat
for b4 being DecoratedTree
for b5 being Node of b4 st b3 < len b2 & b4 = b2 . (b3 + 1) holds
(b1 -tree b2) . (<*b3*> ^ b5) = b4 . b5
proof end;

theorem Th13: :: TREES_4:13
for b1 being set
for b2 being DecoratedTree holds dom (b1 -tree b2) = ^ (dom b2)
proof end;

theorem Th14: :: TREES_4:14
for b1 being set
for b2, b3 being DecoratedTree holds dom (b1 -tree b2,b3) = tree (dom b2),(dom b3)
proof end;

theorem Th15: :: TREES_4:15
for b1, b2 being set
for b3, b4 being DTree-yielding FinSequence st b1 -tree b3 = b2 -tree b4 holds
( b1 = b2 & b3 = b4 )
proof end;

theorem Th16: :: TREES_4:16
for b1, b2 being set
for b3 being FinSequence st root-tree b1 = b2 -flat_tree b3 holds
( b1 = b2 & b3 = {} )
proof end;

theorem Th17: :: TREES_4:17
for b1, b2 being set
for b3 being FinSequence st root-tree b1 = b2 -tree b3 & b3 is DTree-yielding holds
( b1 = b2 & b3 = {} )
proof end;

theorem Th18: :: TREES_4:18
for b1, b2 being set
for b3, b4 being FinSequence st b1 -flat_tree b3 = b2 -tree b4 & b4 is DTree-yielding holds
( b1 = b2 & len b3 = len b4 & ( for b5 being Nat st b5 in dom b3 holds
b4 . b5 = root-tree (b3 . b5) ) )
proof end;

theorem Th19: :: TREES_4:19
for b1 being set
for b2 being DTree-yielding FinSequence
for b3 being Nat
for b4 being FinSequence st <*b3*> ^ b4 in dom (b1 -tree b2) holds
(b1 -tree b2) . (<*b3*> ^ b4) = b2 .. (b3 + 1),b4
proof end;

theorem Th20: :: TREES_4:20
for b1 being set holds
( b1 -flat_tree {} = root-tree b1 & b1 -tree {} = root-tree b1 )
proof end;

theorem Th21: :: TREES_4:21
for b1, b2 being set holds b1 -flat_tree <*b2*> = ((elementary_tree 1) --> b1) with-replacement <*0*>,(root-tree b2)
proof end;

theorem Th22: :: TREES_4:22
for b1 being set
for b2 being DecoratedTree holds b1 -tree <*b2*> = ((elementary_tree 1) --> b1) with-replacement <*0*>,b2
proof end;

definition
let c1 be non empty set ;
let c2 be Element of c1;
let c3 be FinSequence of c1;
redefine func -flat_tree as c2 -flat_tree c3 -> DecoratedTree of a1;
coherence
c2 -flat_tree c3 is DecoratedTree of c1
proof end;
end;

definition
let c1 be non empty set ;
let c2 be non empty DTree-set of c1;
let c3 be Element of c1;
let c4 be FinSequence of c2;
redefine func -tree as c3 -tree c4 -> DecoratedTree of a1;
coherence
c3 -tree c4 is DecoratedTree of c1
proof end;
end;

definition
let c1 be non empty set ;
let c2 be Element of c1;
let c3 be DecoratedTree of c1;
redefine func -tree as c2 -tree c3 -> DecoratedTree of a1;
coherence
c2 -tree c3 is DecoratedTree of c1
proof end;
end;

definition
let c1 be non empty set ;
let c2 be Element of c1;
let c3, c4 be DecoratedTree of c1;
redefine func -tree as c2 -tree c3,c4 -> DecoratedTree of a1;
coherence
c2 -tree c3,c4 is DecoratedTree of c1
proof end;
end;

definition
let c1 be non empty set ;
let c2 be FinSequence of FinTrees c1;
redefine func doms as doms c2 -> FinSequence of FinTrees ;
coherence
doms c2 is FinSequence of FinTrees
proof end;
end;

definition
let c1 be non empty set ;
let c2 be Element of c1;
let c3 be FinSequence of FinTrees c1;
redefine func -tree as c2 -tree c3 -> Element of FinTrees a1;
coherence
c2 -tree c3 is Element of FinTrees c1
proof end;
end;

definition
let c1 be non empty set ;
let c2 be Subset of c1;
redefine mode FinSequence as FinSequence of c2 -> FinSequence of a1;
coherence
for b1 being FinSequence of c2 holds b1 is FinSequence of c1
proof end;
end;

registration
let c1 be non empty constituted-DTrees set ;
let c2 be Subset of c1;
cluster -> DTree-yielding FinSequence of a2;
coherence
for b1 being FinSequence of c2 holds b1 is DTree-yielding
proof end;
end;

scheme :: TREES_4:sch 1
s1{ F1() -> Tree, F2() -> Tree, P1[ set ] } :
ex b1 being Tree st
for b2 being FinSequence holds
( b2 in b1 iff ( b2 in F1() or ex b3 being Element of F1()ex b4 being Element of F2() st
( P1[b3] & b2 = b3 ^ b4 ) ) )
proof end;

definition
let c1, c2 be DecoratedTree;
let c3 be set ;
func c1,c3 <- c2 -> DecoratedTree means :Def7: :: TREES_4:def 7
( ( for b1 being FinSequence holds
( b1 in dom a4 iff ( b1 in dom a1 or ex b2 being Node of a1ex b3 being Node of a2 st
( b2 in Leaves (dom a1) & a1 . b2 = a3 & b1 = b2 ^ b3 ) ) ) ) & ( for b1 being Node of a1 st ( not b1 in Leaves (dom a1) or a1 . b1 <> a3 ) holds
a4 . b1 = a1 . b1 ) & ( for b1 being Node of a1
for b2 being Node of a2 st b1 in Leaves (dom a1) & a1 . b1 = a3 holds
a4 . (b1 ^ b2) = a2 . b2 ) );
existence
ex b1 being DecoratedTree st
( ( for b2 being FinSequence holds
( b2 in dom b1 iff ( b2 in dom c1 or ex b3 being Node of c1ex b4 being Node of c2 st
( b3 in Leaves (dom c1) & c1 . b3 = c3 & b2 = b3 ^ b4 ) ) ) ) & ( for b2 being Node of c1 st ( not b2 in Leaves (dom c1) or c1 . b2 <> c3 ) holds
b1 . b2 = c1 . b2 ) & ( for b2 being Node of c1
for b3 being Node of c2 st b2 in Leaves (dom c1) & c1 . b2 = c3 holds
b1 . (b2 ^ b3) = c2 . b3 ) )
proof end;
uniqueness
for b1, b2 being DecoratedTree st ( for b3 being FinSequence holds
( b3 in dom b1 iff ( b3 in dom c1 or ex b4 being Node of c1ex b5 being Node of c2 st
( b4 in Leaves (dom c1) & c1 . b4 = c3 & b3 = b4 ^ b5 ) ) ) ) & ( for b3 being Node of c1 st ( not b3 in Leaves (dom c1) or c1 . b3 <> c3 ) holds
b1 . b3 = c1 . b3 ) & ( for b3 being Node of c1
for b4 being Node of c2 st b3 in Leaves (dom c1) & c1 . b3 = c3 holds
b1 . (b3 ^ b4) = c2 . b4 ) & ( for b3 being FinSequence holds
( b3 in dom b2 iff ( b3 in dom c1 or ex b4 being Node of c1ex b5 being Node of c2 st
( b4 in Leaves (dom c1) & c1 . b4 = c3 & b3 = b4 ^ b5 ) ) ) ) & ( for b3 being Node of c1 st ( not b3 in Leaves (dom c1) or c1 . b3 <> c3 ) holds
b2 . b3 = c1 . b3 ) & ( for b3 being Node of c1
for b4 being Node of c2 st b3 in Leaves (dom c1) & c1 . b3 = c3 holds
b2 . (b3 ^ b4) = c2 . b4 ) holds
b1 = b2
proof end;
end;

:: deftheorem Def7 defines <- TREES_4:def 7 :
for b1, b2 being DecoratedTree
for b3 being set
for b4 being DecoratedTree holds
( b4 = b1,b3 <- b2 iff ( ( for b5 being FinSequence holds
( b5 in dom b4 iff ( b5 in dom b1 or ex b6 being Node of b1ex b7 being Node of b2 st
( b6 in Leaves (dom b1) & b1 . b6 = b3 & b5 = b6 ^ b7 ) ) ) ) & ( for b5 being Node of b1 st ( not b5 in Leaves (dom b1) or b1 . b5 <> b3 ) holds
b4 . b5 = b1 . b5 ) & ( for b5 being Node of b1
for b6 being Node of b2 st b5 in Leaves (dom b1) & b1 . b5 = b3 holds
b4 . (b5 ^ b6) = b2 . b6 ) ) );

definition
let c1 be non empty set ;
let c2, c3 be DecoratedTree of c1;
let c4 be set ;
redefine func <- as c2,c4 <- c3 -> DecoratedTree of a1;
coherence
c2,c4 <- c3 is DecoratedTree of c1
proof end;
end;

theorem Th23: :: TREES_4:23
for b1, b2 being DecoratedTree
for b3 being set st ( not b3 in rng b1 or not b3 in Leaves b1 ) holds
b1,b3 <- b2 = b1
proof end;

theorem Th24: :: TREES_4:24
for b1, b2 being non empty set
for b3 being DecoratedTree of b1,b2 holds
( dom (b3 `1 ) = dom b3 & dom (b3 `2 ) = dom b3 )
proof end;

theorem Th25: :: TREES_4:25
for b1, b2 being non empty set
for b3 being Element of b1
for b4 being Element of b2 holds
( (root-tree [b3,b4]) `1 = root-tree b3 & (root-tree [b3,b4]) `2 = root-tree b4 )
proof end;

theorem Th26: :: TREES_4:26
for b1, b2 being set holds <:(root-tree b1),(root-tree b2):> = root-tree [b1,b2]
proof end;

theorem Th27: :: TREES_4:27
for b1, b2 being non empty set
for b3 being Element of b1
for b4 being Element of b2
for b5 being non empty DTree-set of b1,b2
for b6 being non empty DTree-set of b1
for b7 being FinSequence of b5
for b8 being FinSequence of b6 st dom b8 = dom b7 & ( for b9 being Nat st b9 in dom b7 holds
for b10 being DecoratedTree of b1,b2 st b10 = b7 . b9 holds
b8 . b9 = b10 `1 ) holds
([b3,b4] -tree b7) `1 = b3 -tree b8
proof end;

theorem Th28: :: TREES_4:28
for b1, b2 being non empty set
for b3 being Element of b1
for b4 being Element of b2
for b5 being non empty DTree-set of b1,b2
for b6 being non empty DTree-set of b2
for b7 being FinSequence of b5
for b8 being FinSequence of b6 st dom b8 = dom b7 & ( for b9 being Nat st b9 in dom b7 holds
for b10 being DecoratedTree of b1,b2 st b10 = b7 . b9 holds
b8 . b9 = b10 `2 ) holds
([b3,b4] -tree b7) `2 = b4 -tree b8
proof end;

theorem Th29: :: TREES_4:29
for b1, b2 being non empty set
for b3 being Element of b1
for b4 being Element of b2
for b5 being non empty DTree-set of b1,b2
for b6 being FinSequence of b5 ex b7 being FinSequence of Trees b1 st
( dom b7 = dom b6 & ( for b8 being Nat st b8 in dom b6 holds
ex b9 being Element of b5 st
( b9 = b6 . b8 & b7 . b8 = b9 `1 ) ) & ([b3,b4] -tree b6) `1 = b3 -tree b7 )
proof end;

theorem Th30: :: TREES_4:30
for b1, b2 being non empty set
for b3 being Element of b1
for b4 being Element of b2
for b5 being non empty DTree-set of b1,b2
for b6 being FinSequence of b5 ex b7 being FinSequence of Trees b2 st
( dom b7 = dom b6 & ( for b8 being Nat st b8 in dom b6 holds
ex b9 being Element of b5 st
( b9 = b6 . b8 & b7 . b8 = b9 `2 ) ) & ([b3,b4] -tree b6) `2 = b4 -tree b7 )
proof end;

theorem Th31: :: TREES_4:31
for b1, b2 being non empty set
for b3 being Element of b1
for b4 being Element of b2
for b5 being FinSequence of FinTrees [:b1,b2:] ex b6 being FinSequence of FinTrees b1 st
( dom b6 = dom b5 & ( for b7 being Nat st b7 in dom b5 holds
ex b8 being Element of FinTrees [:b1,b2:] st
( b8 = b5 . b7 & b6 . b7 = b8 `1 ) ) & ([b3,b4] -tree b5) `1 = b3 -tree b6 )
proof end;

theorem Th32: :: TREES_4:32
for b1, b2 being non empty set
for b3 being Element of b1
for b4 being Element of b2
for b5 being FinSequence of FinTrees [:b1,b2:] ex b6 being FinSequence of FinTrees b2 st
( dom b6 = dom b5 & ( for b7 being Nat st b7 in dom b5 holds
ex b8 being Element of FinTrees [:b1,b2:] st
( b8 = b5 . b7 & b6 . b7 = b8 `2 ) ) & ([b3,b4] -tree b5) `2 = b4 -tree b6 )
proof end;