:: TREES_3 semantic presentation

Lemma1: for b1 being Nat
for b2, b3 being FinSequence st 1 <= b1 & b1 <= len b2 holds
(b2 ^ b3) . b1 = b2 . b1
proof end;

definition
func Trees -> set means :Def1: :: TREES_3:def 1
for b1 being set holds
( b1 in a1 iff b1 is Tree );
existence
ex b1 being set st
for b2 being set holds
( b2 in b1 iff b2 is Tree )
proof end;
uniqueness
for b1, b2 being set st ( for b3 being set holds
( b3 in b1 iff b3 is Tree ) ) & ( for b3 being set holds
( b3 in b2 iff b3 is Tree ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def1 defines Trees TREES_3:def 1 :
for b1 being set holds
( b1 = Trees iff for b2 being set holds
( b2 in b1 iff b2 is Tree ) );

registration
cluster Trees -> non empty ;
coherence
not Trees is empty
proof end;
end;

definition
func FinTrees -> Subset of Trees means :Def2: :: TREES_3:def 2
for b1 being set holds
( b1 in a1 iff b1 is finite Tree );
existence
ex b1 being Subset of Trees st
for b2 being set holds
( b2 in b1 iff b2 is finite Tree )
proof end;
uniqueness
for b1, b2 being Subset of Trees st ( for b3 being set holds
( b3 in b1 iff b3 is finite Tree ) ) & ( for b3 being set holds
( b3 in b2 iff b3 is finite Tree ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines FinTrees TREES_3:def 2 :
for b1 being Subset of Trees holds
( b1 = FinTrees iff for b2 being set holds
( b2 in b1 iff b2 is finite Tree ) );

registration
cluster FinTrees -> non empty ;
coherence
not FinTrees is empty
proof end;
end;

definition
let c1 be set ;
attr a1 is constituted-Trees means :Def3: :: TREES_3:def 3
for b1 being set st b1 in a1 holds
b1 is Tree;
attr a1 is constituted-FinTrees means :Def4: :: TREES_3:def 4
for b1 being set st b1 in a1 holds
b1 is finite Tree;
attr a1 is constituted-DTrees means :Def5: :: TREES_3:def 5
for b1 being set st b1 in a1 holds
b1 is DecoratedTree;
end;

:: deftheorem Def3 defines constituted-Trees TREES_3:def 3 :
for b1 being set holds
( b1 is constituted-Trees iff for b2 being set st b2 in b1 holds
b2 is Tree );

:: deftheorem Def4 defines constituted-FinTrees TREES_3:def 4 :
for b1 being set holds
( b1 is constituted-FinTrees iff for b2 being set st b2 in b1 holds
b2 is finite Tree );

:: deftheorem Def5 defines constituted-DTrees TREES_3:def 5 :
for b1 being set holds
( b1 is constituted-DTrees iff for b2 being set st b2 in b1 holds
b2 is DecoratedTree );

theorem Th1: :: TREES_3:1
for b1 being set holds
( b1 is constituted-Trees iff b1 c= Trees )
proof end;

theorem Th2: :: TREES_3:2
for b1 being set holds
( b1 is constituted-FinTrees iff b1 c= FinTrees )
proof end;

theorem Th3: :: TREES_3:3
for b1, b2 being set holds
( ( b1 is constituted-Trees & b2 is constituted-Trees ) iff b1 \/ b2 is constituted-Trees )
proof end;

theorem Th4: :: TREES_3:4
for b1, b2 being set st b1 is constituted-Trees & b2 is constituted-Trees holds
b1 \+\ b2 is constituted-Trees
proof end;

theorem Th5: :: TREES_3:5
for b1, b2 being set st b1 is constituted-Trees holds
( b1 /\ b2 is constituted-Trees & b2 /\ b1 is constituted-Trees & b1 \ b2 is constituted-Trees )
proof end;

theorem Th6: :: TREES_3:6
for b1, b2 being set holds
( ( b1 is constituted-FinTrees & b2 is constituted-FinTrees ) iff b1 \/ b2 is constituted-FinTrees )
proof end;

theorem Th7: :: TREES_3:7
for b1, b2 being set st b1 is constituted-FinTrees & b2 is constituted-FinTrees holds
b1 \+\ b2 is constituted-FinTrees
proof end;

theorem Th8: :: TREES_3:8
for b1, b2 being set st b1 is constituted-FinTrees holds
( b1 /\ b2 is constituted-FinTrees & b2 /\ b1 is constituted-FinTrees & b1 \ b2 is constituted-FinTrees )
proof end;

theorem Th9: :: TREES_3:9
for b1, b2 being set holds
( ( b1 is constituted-DTrees & b2 is constituted-DTrees ) iff b1 \/ b2 is constituted-DTrees )
proof end;

theorem Th10: :: TREES_3:10
for b1, b2 being set st b1 is constituted-DTrees & b2 is constituted-DTrees holds
b1 \+\ b2 is constituted-DTrees
proof end;

theorem Th11: :: TREES_3:11
for b1, b2 being set st b1 is constituted-DTrees holds
( b1 /\ b2 is constituted-DTrees & b2 /\ b1 is constituted-DTrees & b1 \ b2 is constituted-DTrees )
proof end;

theorem Th12: :: TREES_3:12
( {} is constituted-Trees & {} is constituted-FinTrees & {} is constituted-DTrees )
proof end;

theorem Th13: :: TREES_3:13
for b1 being set holds
( {b1} is constituted-Trees iff b1 is Tree )
proof end;

theorem Th14: :: TREES_3:14
for b1 being set holds
( {b1} is constituted-FinTrees iff b1 is finite Tree )
proof end;

theorem Th15: :: TREES_3:15
for b1 being set holds
( {b1} is constituted-DTrees iff b1 is DecoratedTree )
proof end;

theorem Th16: :: TREES_3:16
for b1, b2 being set holds
( {b1,b2} is constituted-Trees iff ( b1 is Tree & b2 is Tree ) )
proof end;

theorem Th17: :: TREES_3:17
for b1, b2 being set holds
( {b1,b2} is constituted-FinTrees iff ( b1 is finite Tree & b2 is finite Tree ) )
proof end;

theorem Th18: :: TREES_3:18
for b1, b2 being set holds
( {b1,b2} is constituted-DTrees iff ( b1 is DecoratedTree & b2 is DecoratedTree ) )
proof end;

theorem Th19: :: TREES_3:19
for b1, b2 being set st b1 is constituted-Trees & b2 c= b1 holds
b2 is constituted-Trees
proof end;

theorem Th20: :: TREES_3:20
for b1, b2 being set st b1 is constituted-FinTrees & b2 c= b1 holds
b2 is constituted-FinTrees
proof end;

theorem Th21: :: TREES_3:21
for b1, b2 being set st b1 is constituted-DTrees & b2 c= b1 holds
b2 is constituted-DTrees
proof end;

registration
cluster non empty finite constituted-Trees constituted-FinTrees set ;
existence
ex b1 being set st
( b1 is finite & b1 is constituted-Trees & b1 is constituted-FinTrees & not b1 is empty )
proof end;
cluster non empty finite constituted-DTrees set ;
existence
ex b1 being set st
( b1 is finite & b1 is constituted-DTrees & not b1 is empty )
proof end;
end;

registration
cluster constituted-FinTrees -> constituted-Trees set ;
coherence
for b1 being set st b1 is constituted-FinTrees holds
b1 is constituted-Trees
proof end;
end;

registration
let c1 be constituted-Trees set ;
cluster -> constituted-Trees Element of bool a1;
coherence
for b1 being Subset of c1 holds b1 is constituted-Trees
proof end;
end;

registration
let c1 be constituted-FinTrees set ;
cluster -> constituted-Trees constituted-FinTrees Element of bool a1;
coherence
for b1 being Subset of c1 holds b1 is constituted-FinTrees
proof end;
end;

registration
let c1 be constituted-DTrees set ;
cluster -> constituted-DTrees Element of bool a1;
coherence
for b1 being Subset of c1 holds b1 is constituted-DTrees
proof end;
end;

definition
let c1 be non empty constituted-Trees set ;
redefine mode Element as Element of c1 -> Tree;
coherence
for b1 being Element of c1 holds b1 is Tree
by Def3;
end;

definition
let c1 be non empty constituted-FinTrees set ;
redefine mode Element as Element of c1 -> finite Tree;
coherence
for b1 being Element of c1 holds b1 is finite Tree
by Def4;
end;

definition
let c1 be non empty constituted-DTrees set ;
redefine mode Element as Element of c1 -> DecoratedTree;
coherence
for b1 being Element of c1 holds b1 is DecoratedTree
by Def5;
end;

registration
cluster Trees -> non empty constituted-Trees ;
coherence
Trees is constituted-Trees
proof end;
end;

registration
cluster non empty constituted-Trees constituted-FinTrees Element of bool Trees ;
existence
ex b1 being Subset of Trees st
( b1 is constituted-FinTrees & not b1 is empty )
proof end;
end;

registration
cluster FinTrees -> non empty constituted-Trees constituted-FinTrees ;
coherence
FinTrees is constituted-FinTrees
proof end;
end;

definition
let c1 be non empty set ;
mode DTree-set of c1 -> set means :Def6: :: TREES_3:def 6
for b1 being set st b1 in a2 holds
b1 is DecoratedTree of a1;
existence
ex b1 being set st
for b2 being set st b2 in b1 holds
b2 is DecoratedTree of c1
proof end;
end;

:: deftheorem Def6 defines DTree-set TREES_3:def 6 :
for b1 being non empty set
for b2 being set holds
( b2 is DTree-set of b1 iff for b3 being set st b3 in b2 holds
b3 is DecoratedTree of b1 );

registration
let c1 be non empty set ;
cluster -> constituted-DTrees DTree-set of a1;
coherence
for b1 being DTree-set of c1 holds b1 is constituted-DTrees
proof end;
end;

registration
let c1 be non empty set ;
cluster non empty finite constituted-DTrees DTree-set of a1;
existence
ex b1 being DTree-set of c1 st
( b1 is finite & not b1 is empty )
proof end;
end;

definition
let c1 be non empty set ;
let c2 be non empty DTree-set of c1;
redefine mode Element as Element of c2 -> DecoratedTree of a1;
coherence
for b1 being Element of c2 holds b1 is DecoratedTree of c1
by Def6;
end;

definition
let c1 be Tree;
let c2 be non empty set ;
redefine func Funcs as Funcs c1,c2 -> non empty DTree-set of a2;
coherence
Funcs c1,c2 is non empty DTree-set of c2
proof end;
redefine mode Relation as Relation of c1,c2 -> ParametrizedSubset of a2;
coherence
for b1 being Relation of c1,c2 holds b1 is ParametrizedSubset of c2
proof end;
end;

registration
let c1 be Tree;
let c2 be non empty set ;
cluster -> DecoratedTree-like Relation of a1,a2;
coherence
for b1 being Function of c1,c2 holds b1 is DecoratedTree-like
proof end;
end;

definition
let c1 be non empty set ;
func Trees c1 -> DTree-set of a1 means :Def7: :: TREES_3:def 7
for b1 being DecoratedTree of a1 holds b1 in a2;
existence
ex b1 being DTree-set of c1 st
for b2 being DecoratedTree of c1 holds b2 in b1
proof end;
uniqueness
for b1, b2 being DTree-set of c1 st ( for b3 being DecoratedTree of c1 holds b3 in b1 ) & ( for b3 being DecoratedTree of c1 holds b3 in b2 ) holds
b1 = b2
proof end;
end;

:: deftheorem Def7 defines Trees TREES_3:def 7 :
for b1 being non empty set
for b2 being DTree-set of b1 holds
( b2 = Trees b1 iff for b3 being DecoratedTree of b1 holds b3 in b2 );

registration
let c1 be non empty set ;
cluster Trees a1 -> non empty constituted-DTrees ;
coherence
not Trees c1 is empty
by Def7;
end;

definition
let c1 be non empty set ;
func FinTrees c1 -> DTree-set of a1 means :Def8: :: TREES_3:def 8
for b1 being DecoratedTree of a1 holds
( dom b1 is finite iff b1 in a2 );
existence
ex b1 being DTree-set of c1 st
for b2 being DecoratedTree of c1 holds
( dom b2 is finite iff b2 in b1 )
proof end;
uniqueness
for b1, b2 being DTree-set of c1 st ( for b3 being DecoratedTree of c1 holds
( dom b3 is finite iff b3 in b1 ) ) & ( for b3 being DecoratedTree of c1 holds
( dom b3 is finite iff b3 in b2 ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def8 defines FinTrees TREES_3:def 8 :
for b1 being non empty set
for b2 being DTree-set of b1 holds
( b2 = FinTrees b1 iff for b3 being DecoratedTree of b1 holds
( dom b3 is finite iff b3 in b2 ) );

registration
let c1 be non empty set ;
cluster FinTrees a1 -> non empty constituted-DTrees ;
coherence
not FinTrees c1 is empty
proof end;
end;

theorem Th22: :: TREES_3:22
for b1 being non empty set holds FinTrees b1 c= Trees b1
proof end;

definition
let c1 be Function;
attr a1 is Tree-yielding means :Def9: :: TREES_3:def 9
rng a1 is constituted-Trees;
attr a1 is FinTree-yielding means :Def10: :: TREES_3:def 10
rng a1 is constituted-FinTrees;
attr a1 is DTree-yielding means :Def11: :: TREES_3:def 11
rng a1 is constituted-DTrees;
end;

:: deftheorem Def9 defines Tree-yielding TREES_3:def 9 :
for b1 being Function holds
( b1 is Tree-yielding iff rng b1 is constituted-Trees );

:: deftheorem Def10 defines FinTree-yielding TREES_3:def 10 :
for b1 being Function holds
( b1 is FinTree-yielding iff rng b1 is constituted-FinTrees );

:: deftheorem Def11 defines DTree-yielding TREES_3:def 11 :
for b1 being Function holds
( b1 is DTree-yielding iff rng b1 is constituted-DTrees );

theorem Th23: :: TREES_3:23
( {} is Tree-yielding & {} is FinTree-yielding & {} is DTree-yielding )
proof end;

theorem Th24: :: TREES_3:24
for b1 being Function holds
( b1 is Tree-yielding iff for b2 being set st b2 in dom b1 holds
b1 . b2 is Tree )
proof end;

theorem Th25: :: TREES_3:25
for b1 being Function holds
( b1 is FinTree-yielding iff for b2 being set st b2 in dom b1 holds
b1 . b2 is finite Tree )
proof end;

theorem Th26: :: TREES_3:26
for b1 being Function holds
( b1 is DTree-yielding iff for b2 being set st b2 in dom b1 holds
b1 . b2 is DecoratedTree )
proof end;

theorem Th27: :: TREES_3:27
for b1, b2 being FinSequence holds
( ( b1 is Tree-yielding & b2 is Tree-yielding ) iff b1 ^ b2 is Tree-yielding )
proof end;

theorem Th28: :: TREES_3:28
for b1, b2 being FinSequence holds
( ( b1 is FinTree-yielding & b2 is FinTree-yielding ) iff b1 ^ b2 is FinTree-yielding )
proof end;

theorem Th29: :: TREES_3:29
for b1, b2 being FinSequence holds
( ( b1 is DTree-yielding & b2 is DTree-yielding ) iff b1 ^ b2 is DTree-yielding )
proof end;

theorem Th30: :: TREES_3:30
for b1 being set holds
( <*b1*> is Tree-yielding iff b1 is Tree )
proof end;

theorem Th31: :: TREES_3:31
for b1 being set holds
( <*b1*> is FinTree-yielding iff b1 is finite Tree )
proof end;

theorem Th32: :: TREES_3:32
for b1 being set holds
( <*b1*> is DTree-yielding iff b1 is DecoratedTree )
proof end;

theorem Th33: :: TREES_3:33
for b1, b2 being set holds
( <*b1,b2*> is Tree-yielding iff ( b1 is Tree & b2 is Tree ) )
proof end;

theorem Th34: :: TREES_3:34
for b1, b2 being set holds
( <*b1,b2*> is FinTree-yielding iff ( b1 is finite Tree & b2 is finite Tree ) )
proof end;

theorem Th35: :: TREES_3:35
for b1, b2 being set holds
( <*b1,b2*> is DTree-yielding iff ( b1 is DecoratedTree & b2 is DecoratedTree ) )
proof end;

theorem Th36: :: TREES_3:36
for b1 being set
for b2 being Nat st b2 <> 0 holds
( b2 |-> b1 is Tree-yielding iff b1 is Tree )
proof end;

theorem Th37: :: TREES_3:37
for b1 being set
for b2 being Nat st b2 <> 0 holds
( b2 |-> b1 is FinTree-yielding iff b1 is finite Tree )
proof end;

theorem Th38: :: TREES_3:38
for b1 being set
for b2 being Nat st b2 <> 0 holds
( b2 |-> b1 is DTree-yielding iff b1 is DecoratedTree )
proof end;

registration
cluster non empty Tree-yielding FinTree-yielding set ;
existence
ex b1 being FinSequence st
( b1 is Tree-yielding & b1 is FinTree-yielding & not b1 is empty )
proof end;
cluster non empty DTree-yielding set ;
existence
ex b1 being FinSequence st
( b1 is DTree-yielding & not b1 is empty )
proof end;
end;

registration
cluster non empty Tree-yielding FinTree-yielding set ;
existence
ex b1 being Function st
( b1 is Tree-yielding & b1 is FinTree-yielding & not b1 is empty )
proof end;
cluster non empty DTree-yielding set ;
existence
ex b1 being Function st
( b1 is DTree-yielding & not b1 is empty )
proof end;
end;

registration
cluster FinTree-yielding -> Tree-yielding set ;
coherence
for b1 being Function st b1 is FinTree-yielding holds
b1 is Tree-yielding
proof end;
end;

registration
let c1 be non empty constituted-Trees set ;
cluster -> Tree-yielding FinSequence of a1;
coherence
for b1 being FinSequence of c1 holds b1 is Tree-yielding
proof end;
end;

registration
let c1, c2 be Tree-yielding FinSequence;
cluster a1 ^ a2 -> Tree-yielding ;
coherence
c1 ^ c2 is Tree-yielding
by Th27;
end;

registration
let c1 be non empty constituted-FinTrees set ;
cluster -> Tree-yielding FinTree-yielding FinSequence of a1;
coherence
for b1 being FinSequence of c1 holds b1 is FinTree-yielding
proof end;
end;

registration
let c1, c2 be FinTree-yielding FinSequence;
cluster a1 ^ a2 -> Tree-yielding FinTree-yielding ;
coherence
c1 ^ c2 is FinTree-yielding
by Th28;
end;

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

registration
let c1, c2 be DTree-yielding FinSequence;
cluster a1 ^ a2 -> DTree-yielding ;
coherence
c1 ^ c2 is DTree-yielding
by Th29;
end;

Lemma38: for b1, b2 being set holds
( not <*b1*> is empty & not <*b1,b2*> is empty )
proof end;

registration
let c1 be Tree;
cluster <*a1*> -> non empty Tree-yielding ;
coherence
( <*c1*> is Tree-yielding & not <*c1*> is empty )
by Th30;
let c2 be Tree;
cluster <*a1,a2*> -> non empty Tree-yielding ;
coherence
( <*c1,c2*> is Tree-yielding & not <*c1,c2*> is empty )
by Lemma38, Th33;
end;

registration
let c1 be Nat;
let c2 be Tree;
cluster a1 |-> a2 -> Tree-yielding ;
coherence
c1 |-> c2 is Tree-yielding
proof end;
end;

registration
let c1 be finite Tree;
cluster <*a1*> -> Tree-yielding FinTree-yielding ;
coherence
<*c1*> is FinTree-yielding
by Th31;
let c2 be finite Tree;
cluster <*a1,a2*> -> non empty Tree-yielding FinTree-yielding ;
coherence
<*c1,c2*> is FinTree-yielding
by Th34;
end;

registration
let c1 be Nat;
let c2 be finite Tree;
cluster a1 |-> a2 -> Tree-yielding FinTree-yielding ;
coherence
c1 |-> c2 is FinTree-yielding
proof end;
end;

registration
let c1 be DecoratedTree;
cluster <*a1*> -> non empty DTree-yielding ;
coherence
( <*c1*> is DTree-yielding & not <*c1*> is empty )
by Th32;
let c2 be DecoratedTree;
cluster <*a1,a2*> -> non empty DTree-yielding ;
coherence
( <*c1,c2*> is DTree-yielding & not <*c1,c2*> is empty )
by Lemma38, Th35;
end;

registration
let c1 be Nat;
let c2 be DecoratedTree;
cluster a1 |-> a2 -> DTree-yielding ;
coherence
c1 |-> c2 is DTree-yielding
proof end;
end;

theorem Th39: :: TREES_3:39
for b1 being DTree-yielding Function holds
( dom (doms b1) = dom b1 & doms b1 is Tree-yielding )
proof end;

registration
let c1 be DTree-yielding FinSequence;
cluster doms a1 -> FinSequence-like Tree-yielding ;
coherence
( doms c1 is Tree-yielding & doms c1 is FinSequence-like )
proof end;
end;

theorem Th40: :: TREES_3:40
for b1 being DTree-yielding FinSequence holds len (doms b1) = len b1
proof end;

Lemma40: for b1 being non empty set
for b2 being DecoratedTree of b1 holds b2 is Function of dom b2,b1
proof end;

definition
let c1, c2 be non empty set ;
mode DecoratedTree of a1,a2 is DecoratedTree of [:a1,a2:];
mode DTree-set of a1,a2 is DTree-set of [:a1,a2:];
end;

registration
let c1, c2 be DecoratedTree;
cluster <:a1,a2:> -> DecoratedTree-like ;
coherence
<:c1,c2:> is DecoratedTree-like
proof end;
end;

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

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

definition
let c1, c2 be non empty set ;
redefine func pr1 as pr1 c1,c2 -> Function of [:a1,a2:],a1;
coherence
pr1 c1,c2 is Function of [:c1,c2:],c1
proof end;
redefine func pr2 as pr2 c1,c2 -> Function of [:a1,a2:],a2;
coherence
pr2 c1,c2 is Function of [:c1,c2:],c2
proof end;
end;

definition
let c1, c2 be non empty set ;
let c3 be DecoratedTree of c1,c2;
func c3 `1 -> DecoratedTree of a1 equals :: TREES_3:def 12
(pr1 a1,a2) * a3;
correctness
coherence
(pr1 c1,c2) * c3 is DecoratedTree of c1
;
;
func c3 `2 -> DecoratedTree of a2 equals :: TREES_3:def 13
(pr2 a1,a2) * a3;
correctness
coherence
(pr2 c1,c2) * c3 is DecoratedTree of c2
;
;
end;

:: deftheorem Def12 defines `1 TREES_3:def 12 :
for b1, b2 being non empty set
for b3 being DecoratedTree of b1,b2 holds b3 `1 = (pr1 b1,b2) * b3;

:: deftheorem Def13 defines `2 TREES_3:def 13 :
for b1, b2 being non empty set
for b3 being DecoratedTree of b1,b2 holds b3 `2 = (pr2 b1,b2) * b3;

theorem Th41: :: TREES_3:41
for b1, b2 being non empty set
for b3 being DecoratedTree of b1,b2
for b4 being Element of dom b3 holds
( (b3 . b4) `1 = (b3 `1 ) . b4 & (b3 `2 ) . b4 = (b3 . b4) `2 )
proof end;

theorem Th42: :: TREES_3:42
for b1, b2 being non empty set
for b3 being DecoratedTree of b1,b2 holds <:(b3 `1 ),(b3 `2 ):> = b3
proof end;

registration
let c1 be finite Tree;
cluster Leaves a1 -> non empty finite ;
coherence
( Leaves c1 is finite & not Leaves c1 is empty )
proof end;
end;

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

definition
let c1 be finite Tree;
redefine mode Leaf as Leaf of c1 -> Element of Leaves a1;
coherence
for b1 being Leaf of c1 holds b1 is Element of Leaves c1
by TREES_1:def 10;
end;

definition
let c1 be finite Tree;
mode T-Substitution of c1 -> Tree means :Def14: :: TREES_3:def 14
for b1 being Element of a2 holds
( b1 in a1 or ex b2 being Leaf of a1 st b2 is_a_proper_prefix_of b1 );
existence
ex b1 being Tree st
for b2 being Element of b1 holds
( b2 in c1 or ex b3 being Leaf of c1 st b3 is_a_proper_prefix_of b2 )
proof end;
end;

:: deftheorem Def14 defines T-Substitution TREES_3:def 14 :
for b1 being finite Tree
for b2 being Tree holds
( b2 is T-Substitution of b1 iff for b3 being Element of b2 holds
( b3 in b1 or ex b4 being Leaf of b1 st b4 is_a_proper_prefix_of b3 ) );

definition
let c1 be finite Tree;
let c2 be Leaf of c1;
let c3 be Tree;
redefine func with-replacement as c1 with-replacement c2,c3 -> T-Substitution of a1;
coherence
c1 with-replacement c2,c3 is T-Substitution of c1
proof end;
end;

registration
let c1 be finite Tree;
cluster finite T-Substitution of a1;
existence
ex b1 being T-Substitution of c1 st b1 is finite
proof end;
end;

definition
let c1 be Nat;
mode T-Substitution of a1 is T-Substitution of elementary_tree a1;
end;

theorem Th43: :: TREES_3:43
for b1 being Tree holds b1 is T-Substitution of 0
proof end;

theorem Th44: :: TREES_3:44
for b1, b2 being Tree st b1 -level 1 c= b2 -level 1 & ( for b3 being Nat st <*b3*> in b1 holds
b1 | <*b3*> = b2 | <*b3*> ) holds
b1 c= b2
proof end;

Lemma43: 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;

theorem Th45: :: TREES_3:45
canceled;

theorem Th46: :: TREES_3:46
for b1, b2 being Tree
for b3 being FinSequence of NAT st b3 in Leaves b1 holds
b1 c= b1 with-replacement b3,b2
proof end;

theorem Th47: :: TREES_3:47
for b1, b2 being DecoratedTree
for b3 being Element of dom b1 holds (b1 with-replacement b3,b2) . b3 = b2 . {}
proof end;

theorem Th48: :: TREES_3:48
for b1, b2 being DecoratedTree
for b3, b4 being Element of dom b1 st not b3 is_a_prefix_of b4 holds
(b1 with-replacement b3,b2) . b4 = b1 . b4
proof end;

theorem Th49: :: TREES_3:49
for b1, b2 being DecoratedTree
for b3 being Element of dom b1
for b4 being Element of dom b2 holds (b1 with-replacement b3,b2) . (b3 ^ b4) = b2 . b4
proof end;

registration
let c1, c2 be Tree;
cluster a1 \/ a2 -> non empty Tree-like ;
coherence
( not c1 \/ c2 is empty & c1 \/ c2 is Tree-like )
by TREES_1:49;
end;

theorem Th50: :: TREES_3:50
for b1, b2 being Tree
for b3 being Element of b1 \/ b2 holds
( ( b3 in b1 & b3 in b2 implies (b1 \/ b2) | b3 = (b1 | b3) \/ (b2 | b3) ) & ( not b3 in b1 implies (b1 \/ b2) | b3 = b2 | b3 ) & ( not b3 in b2 implies (b1 \/ b2) | b3 = b1 | b3 ) )
proof end;

definition
let c1 be FinSequence;
assume E45: c1 is Tree-yielding ;
func tree c1 -> Tree means :Def15: :: TREES_3:def 15
for b1 being set holds
( b1 in a2 iff ( b1 = {} or ex b2 being Natex b3 being FinSequence st
( b2 < len a1 & b3 in a1 . (b2 + 1) & b1 = <*b2*> ^ b3 ) ) );
existence
ex b1 being Tree st
for b2 being set holds
( b2 in b1 iff ( b2 = {} or ex b3 being Natex b4 being FinSequence st
( b3 < len c1 & b4 in c1 . (b3 + 1) & b2 = <*b3*> ^ b4 ) ) )
proof end;
uniqueness
for b1, b2 being Tree st ( for b3 being set holds
( b3 in b1 iff ( b3 = {} or ex b4 being Natex b5 being FinSequence st
( b4 < len c1 & b5 in c1 . (b4 + 1) & b3 = <*b4*> ^ b5 ) ) ) ) & ( for b3 being set holds
( b3 in b2 iff ( b3 = {} or ex b4 being Natex b5 being FinSequence st
( b4 < len c1 & b5 in c1 . (b4 + 1) & b3 = <*b4*> ^ b5 ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def15 defines tree TREES_3:def 15 :
for b1 being FinSequence st b1 is Tree-yielding holds
for b2 being Tree holds
( b2 = tree b1 iff for b3 being set holds
( b3 in b2 iff ( b3 = {} or ex b4 being Natex b5 being FinSequence st
( b4 < len b1 & b5 in b1 . (b4 + 1) & b3 = <*b4*> ^ b5 ) ) ) );

definition
let c1 be Tree;
func ^ c1 -> Tree equals :: TREES_3:def 16
tree <*a1*>;
correctness
coherence
tree <*c1*> is Tree
;
;
end;

:: deftheorem Def16 defines ^ TREES_3:def 16 :
for b1 being Tree holds ^ b1 = tree <*b1*>;

definition
let c1, c2 be Tree;
func tree c1,c2 -> Tree equals :: TREES_3:def 17
tree <*a1,a2*>;
correctness
coherence
tree <*c1,c2*> is Tree
;
;
end;

:: deftheorem Def17 defines tree TREES_3:def 17 :
for b1, b2 being Tree holds tree b1,b2 = tree <*b1,b2*>;

theorem Th51: :: TREES_3:51
for b1 being Nat
for b2, b3 being FinSequence st b2 is Tree-yielding holds
( <*b1*> ^ b3 in tree b2 iff ( b1 < len b2 & b3 in b2 . (b1 + 1) ) )
proof end;

theorem Th52: :: TREES_3:52
for b1 being FinSequence st b1 is Tree-yielding holds
( (tree b1) -level 1 = { <*b2*> where B is Nat : b2 < len b1 } & ( for b2 being Nat st b2 < len b1 holds
(tree b1) | <*b2*> = b1 . (b2 + 1) ) )
proof end;

theorem Th53: :: TREES_3:53
for b1, b2 being Tree-yielding FinSequence st tree b1 = tree b2 holds
b1 = b2
proof end;

theorem Th54: :: TREES_3:54
for b1 being FinSequence
for b2, b3 being Tree-yielding FinSequence
for b4 being Tree holds
( b1 in b4 iff <*(len b2)*> ^ b1 in tree ((b2 ^ <*b4*>) ^ b3) )
proof end;

theorem Th55: :: TREES_3:55
tree {} = elementary_tree 0
proof end;

theorem Th56: :: TREES_3:56
for b1 being FinSequence st b1 is Tree-yielding holds
elementary_tree (len b1) c= tree b1
proof end;

theorem Th57: :: TREES_3:57
for b1 being Nat holds elementary_tree b1 = tree (b1 |-> (elementary_tree 0))
proof end;

theorem Th58: :: TREES_3:58
for b1 being Tree
for b2 being Tree-yielding FinSequence holds tree (b2 ^ <*b1*>) = ((tree b2) \/ (elementary_tree ((len b2) + 1))) with-replacement <*(len b2)*>,b1
proof end;

theorem Th59: :: TREES_3:59
for b1 being Tree-yielding FinSequence holds tree (b1 ^ <*(elementary_tree 0)*>) = (tree b1) \/ (elementary_tree ((len b1) + 1))
proof end;

theorem Th60: :: TREES_3:60
for b1, b2 being Tree-yielding FinSequence
for b3, b4 being Tree holds tree ((b1 ^ <*b3*>) ^ b2) = (tree ((b1 ^ <*b4*>) ^ b2)) with-replacement <*(len b1)*>,b3
proof end;

theorem Th61: :: TREES_3:61
for b1 being Tree holds ^ b1 = (elementary_tree 1) with-replacement <*0*>,b1
proof end;

theorem Th62: :: TREES_3:62
for b1, b2 being Tree holds tree b1,b2 = ((elementary_tree 2) with-replacement <*0*>,b1) with-replacement <*1*>,b2
proof end;

registration
let c1 be FinTree-yielding FinSequence;
cluster tree a1 -> finite ;
coherence
tree c1 is finite
proof end;
end;

registration
let c1 be finite Tree;
cluster ^ a1 -> finite ;
coherence
^ c1 is finite
;
end;

registration
let c1, c2 be finite Tree;
cluster tree a1,a2 -> finite ;
coherence
tree c1,c2 is finite
;
end;

theorem Th63: :: TREES_3:63
for b1 being Tree
for b2 being set holds
( b2 in ^ b1 iff ( b2 = {} or ex b3 being FinSequence st
( b3 in b1 & b2 = <*0*> ^ b3 ) ) )
proof end;

theorem Th64: :: TREES_3:64
for b1 being Tree
for b2 being FinSequence holds
( b2 in b1 iff <*0*> ^ b2 in ^ b1 )
proof end;

theorem Th65: :: TREES_3:65
for b1 being Tree holds elementary_tree 1 c= ^ b1
proof end;

theorem Th66: :: TREES_3:66
for b1, b2 being Tree st b1 c= b2 holds
^ b1 c= ^ b2
proof end;

theorem Th67: :: TREES_3:67
for b1, b2 being Tree st ^ b1 = ^ b2 holds
b1 = b2
proof end;

theorem Th68: :: TREES_3:68
for b1 being Tree holds (^ b1) | <*0*> = b1
proof end;

theorem Th69: :: TREES_3:69
for b1, b2 being Tree holds (^ b1) with-replacement <*0*>,b2 = ^ b2
proof end;

theorem Th70: :: TREES_3:70
^ (elementary_tree 0) = elementary_tree 1
proof end;

theorem Th71: :: TREES_3:71
for b1, b2 being Tree
for b3 being set holds
( b3 in tree b1,b2 iff ( b3 = {} or ex b4 being FinSequence st
( ( b4 in b1 & b3 = <*0*> ^ b4 ) or ( b4 in b2 & b3 = <*1*> ^ b4 ) ) ) )
proof end;

theorem Th72: :: TREES_3:72
for b1, b2 being Tree
for b3 being FinSequence holds
( b3 in b1 iff <*0*> ^ b3 in tree b1,b2 )
proof end;

theorem Th73: :: TREES_3:73
for b1, b2 being Tree
for b3 being FinSequence holds
( b3 in b2 iff <*1*> ^ b3 in tree b1,b2 )
proof end;

theorem Th74: :: TREES_3:74
for b1, b2 being Tree holds elementary_tree 2 c= tree b1,b2
proof end;

theorem Th75: :: TREES_3:75
for b1, b2, b3, b4 being Tree st b1 c= b3 & b2 c= b4 holds
tree b1,b2 c= tree b3,b4
proof end;

theorem Th76: :: TREES_3:76
for b1, b2, b3, b4 being Tree st tree b1,b2 = tree b3,b4 holds
( b1 = b3 & b2 = b4 )
proof end;

theorem Th77: :: TREES_3:77
for b1, b2 being Tree holds
( (tree b1,b2) | <*0*> = b1 & (tree b1,b2) | <*1*> = b2 )
proof end;

theorem Th78: :: TREES_3:78
for b1, b2, b3 being Tree holds
( (tree b2,b3) with-replacement <*0*>,b1 = tree b1,b3 & (tree b2,b3) with-replacement <*1*>,b1 = tree b2,b1 )
proof end;

theorem Th79: :: TREES_3:79
tree (elementary_tree 0),(elementary_tree 0) = elementary_tree 2
proof end;

theorem Th80: :: TREES_3:80
for b1 being Nat
for b2 being FinTree-yielding FinSequence st ( for b3 being finite Tree st b3 in rng b2 holds
height b3 <= b1 ) holds
height (tree b2) <= b1 + 1
proof end;

theorem Th81: :: TREES_3:81
for b1 being FinTree-yielding FinSequence
for b2 being finite Tree st b2 in rng b1 holds
height (tree b1) > height b2
proof end;

theorem Th82: :: TREES_3:82
for b1 being FinTree-yielding FinSequence
for b2 being finite Tree st b2 in rng b1 & ( for b3 being finite Tree st b3 in rng b1 holds
height b3 <= height b2 ) holds
height (tree b1) = (height b2) + 1
proof end;

theorem Th83: :: TREES_3:83
for b1 being finite Tree holds height (^ b1) = (height b1) + 1
proof end;

theorem Th84: :: TREES_3:84
for b1, b2 being finite Tree holds height (tree b1,b2) = (max (height b1),(height b2)) + 1
proof end;

registration
let c1 be non empty set ;
let c2 be Element of FinTrees c1;
cluster dom a2 -> finite ;
coherence
dom c2 is finite
by Def8;
end;

definition
let c1 be FinSequence;
assume E61: c1 is DTree-yielding ;
defpred S1[ Nat, set ] means ex b1 being DecoratedTree st
( b1 = c1 . a1 & a2 = b1 . {} );
func roots c1 -> FinSequence means :: TREES_3:def 18
( dom a2 = dom a1 & ( for b1 being Nat st b1 in dom a1 holds
ex b2 being DecoratedTree st
( b2 = a1 . b1 & a2 . b1 = b2 . {} ) ) );
existence
ex b1 being FinSequence st
( dom b1 = dom c1 & ( for b2 being Nat st b2 in dom c1 holds
ex b3 being DecoratedTree st
( b3 = c1 . b2 & b1 . b2 = b3 . {} ) ) )
proof end;
uniqueness
for b1, b2 being FinSequence st dom b1 = dom c1 & ( for b3 being Nat st b3 in dom c1 holds
ex b4 being DecoratedTree st
( b4 = c1 . b3 & b1 . b3 = b4 . {} ) ) & dom b2 = dom c1 & ( for b3 being Nat st b3 in dom c1 holds
ex b4 being DecoratedTree st
( b4 = c1 . b3 & b2 . b3 = b4 . {} ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def18 defines roots TREES_3:def 18 :
for b1 being FinSequence st b1 is DTree-yielding holds
for b2 being FinSequence holds
( b2 = roots b1 iff ( dom b2 = dom b1 & ( for b3 being Nat st b3 in dom b1 holds
ex b4 being DecoratedTree st
( b4 = b1 . b3 & b2 . b3 = b4 . {} ) ) ) );