:: Free Many Sorted Universal Algebra
:: by Beata Perkowska
::
:: Copyright (c) 1994-2018 Association of Mizar Users

::
:: Preliminaries
::
theorem Th1: :: MSAFREE:1
for I being set
for J being non empty set
for f being Function of I,(J *)
for X being ManySortedSet of J
for p being Element of J *
for x being set st x in I & p = f . x holds
((X #) * f) . x = product (X * p)
proof end;

definition
let I be set ;
let A, B be ManySortedSet of I;
let C be ManySortedSubset of A;
let F be ManySortedFunction of A,B;
func F || C -> ManySortedFunction of C,B means :Def1: :: MSAFREE:def 1
for i being set st i in I holds
it . i = (F . i) | (C . i);
existence
ex b1 being ManySortedFunction of C,B st
for i being set st i in I holds
b1 . i = (F . i) | (C . i)
proof end;
uniqueness
for b1, b2 being ManySortedFunction of C,B st ( for i being set st i in I holds
b1 . i = (F . i) | (C . i) ) & ( for i being set st i in I holds
b2 . i = (F . i) | (C . i) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def1 defines || MSAFREE:def 1 :
for I being set
for A, B being ManySortedSet of I
for C being ManySortedSubset of A
for F being ManySortedFunction of A,B
for b6 being ManySortedFunction of C,B holds
( b6 = F || C iff for i being set st i in I holds
b6 . i = (F . i) | (C . i) );

definition
let I be set ;
let X be ManySortedSet of I;
let i be object ;
assume A1: i in I ;
func coprod (i,X) -> set means :Def2: :: MSAFREE:def 2
for x being set holds
( x in it iff ex a being set st
( a in X . i & x = [a,i] ) );
existence
ex b1 being set st
for x being set holds
( x in b1 iff ex a being set st
( a in X . i & x = [a,i] ) )
proof end;
uniqueness
for b1, b2 being set st ( for x being set holds
( x in b1 iff ex a being set st
( a in X . i & x = [a,i] ) ) ) & ( for x being set holds
( x in b2 iff ex a being set st
( a in X . i & x = [a,i] ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines coprod MSAFREE:def 2 :
for I being set
for X being ManySortedSet of I
for i being object st i in I holds
for b4 being set holds
( b4 = coprod (i,X) iff for x being set holds
( x in b4 iff ex a being set st
( a in X . i & x = [a,i] ) ) );

notation
let I be set ;
let X be ManySortedSet of I;
synonym coprod X for disjoin I;
end;

registration
let I be set ;
let X be ManySortedSet of I;
coherence
proof end;
end;

registration
let I be set ;
let X be ManySortedSet of I;
coherence
proof end;
end;

definition
let I be set ;
let X be ManySortedSet of I;
:: original: coprod
redefine func coprod X -> set means :Def3: :: MSAFREE:def 3
( dom it = I & ( for i being set st i in I holds
it . i = coprod (i,X) ) );
compatibility
for b1 being set holds
( b1 = coprod iff ( dom b1 = I & ( for i being set st i in I holds
b1 . i = coprod (i,X) ) ) )
proof end;
end;

:: deftheorem Def3 defines coprod MSAFREE:def 3 :
for I being set
for X being ManySortedSet of I
for b3 being set holds
( b3 = coprod X iff ( dom b3 = I & ( for i being set st i in I holds
b3 . i = coprod (i,X) ) ) );

registration
let I be set ;
let X be V5() ManySortedSet of I;
cluster K153(X) -> V5() ;
coherence
proof end;
end;

registration
let I be non empty set ;
let X be V5() ManySortedSet of I;
cluster Union X -> non empty ;
coherence
not Union X is empty
proof end;
end;

theorem :: MSAFREE:2
for I being set
for X being ManySortedSet of I
for i being set st i in I holds
( X . i <> {} iff () . i <> {} )
proof end;

definition
let S be non empty non void ManySortedSign ;
let U0 be MSAlgebra over S;
mode GeneratorSet of U0 -> MSSubset of U0 means :Def4: :: MSAFREE:def 4
the Sorts of (GenMSAlg it) = the Sorts of U0;
existence
ex b1 being MSSubset of U0 st the Sorts of (GenMSAlg b1) = the Sorts of U0
proof end;
end;

:: deftheorem Def4 defines GeneratorSet MSAFREE:def 4 :
for S being non empty non void ManySortedSign
for U0 being MSAlgebra over S
for b3 being MSSubset of U0 holds
( b3 is GeneratorSet of U0 iff the Sorts of (GenMSAlg b3) = the Sorts of U0 );

theorem :: MSAFREE:3
for S being non empty non void ManySortedSign
for U0 being strict non-empty MSAlgebra over S
for A being MSSubset of U0 holds
( A is GeneratorSet of U0 iff GenMSAlg A = U0 )
proof end;

definition
let S be non empty non void ManySortedSign ;
let U0 be MSAlgebra over S;
let IT be GeneratorSet of U0;
attr IT is free means :: MSAFREE:def 5
for U1 being non-empty MSAlgebra over S
for f being ManySortedFunction of IT, the Sorts of U1 ex h being ManySortedFunction of U0,U1 st
( h is_homomorphism U0,U1 & h || IT = f );
end;

:: deftheorem defines free MSAFREE:def 5 :
for S being non empty non void ManySortedSign
for U0 being MSAlgebra over S
for IT being GeneratorSet of U0 holds
( IT is free iff for U1 being non-empty MSAlgebra over S
for f being ManySortedFunction of IT, the Sorts of U1 ex h being ManySortedFunction of U0,U1 st
( h is_homomorphism U0,U1 & h || IT = f ) );

definition
let S be non empty non void ManySortedSign ;
let IT be MSAlgebra over S;
attr IT is free means :Def6: :: MSAFREE:def 6
ex G being GeneratorSet of IT st G is free ;
end;

:: deftheorem Def6 defines free MSAFREE:def 6 :
for S being non empty non void ManySortedSign
for IT being MSAlgebra over S holds
( IT is free iff ex G being GeneratorSet of IT st G is free );

theorem Th4: :: MSAFREE:4
for S being non empty non void ManySortedSign
for X being ManySortedSet of the carrier of S holds Union () misses [: the carrier' of S,{ the carrier of S}:]
proof end;

::
:: Construction of Free Many Sorted Algebras for Given Signature
::
definition
let S be non empty non void ManySortedSign ;
let X be ManySortedSet of the carrier of S;
func REL X -> Relation of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) *) means :Def7: :: MSAFREE:def 7
for a being Element of [: the carrier' of S,{ the carrier of S}:] \/ (Union ())
for b being Element of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) * holds
( [a,b] in it iff ( a in [: the carrier' of S,{ the carrier of S}:] & ( for o being OperSymbol of S st [o, the carrier of S] = a holds
( len b = len () & ( for x being set st x in dom b holds
( ( b . x in [: the carrier' of S,{ the carrier of S}:] implies for o1 being OperSymbol of S st [o1, the carrier of S] = b . x holds
the_result_sort_of o1 = () . x ) & ( b . x in Union () implies b . x in coprod ((() . x),X) ) ) ) ) ) ) );
existence
ex b1 being Relation of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) *) st
for a being Element of [: the carrier' of S,{ the carrier of S}:] \/ (Union ())
for b being Element of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) * holds
( [a,b] in b1 iff ( a in [: the carrier' of S,{ the carrier of S}:] & ( for o being OperSymbol of S st [o, the carrier of S] = a holds
( len b = len () & ( for x being set st x in dom b holds
( ( b . x in [: the carrier' of S,{ the carrier of S}:] implies for o1 being OperSymbol of S st [o1, the carrier of S] = b . x holds
the_result_sort_of o1 = () . x ) & ( b . x in Union () implies b . x in coprod ((() . x),X) ) ) ) ) ) ) )
proof end;
uniqueness
for b1, b2 being Relation of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) *) st ( for a being Element of [: the carrier' of S,{ the carrier of S}:] \/ (Union ())
for b being Element of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) * holds
( [a,b] in b1 iff ( a in [: the carrier' of S,{ the carrier of S}:] & ( for o being OperSymbol of S st [o, the carrier of S] = a holds
( len b = len () & ( for x being set st x in dom b holds
( ( b . x in [: the carrier' of S,{ the carrier of S}:] implies for o1 being OperSymbol of S st [o1, the carrier of S] = b . x holds
the_result_sort_of o1 = () . x ) & ( b . x in Union () implies b . x in coprod ((() . x),X) ) ) ) ) ) ) ) ) & ( for a being Element of [: the carrier' of S,{ the carrier of S}:] \/ (Union ())
for b being Element of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) * holds
( [a,b] in b2 iff ( a in [: the carrier' of S,{ the carrier of S}:] & ( for o being OperSymbol of S st [o, the carrier of S] = a holds
( len b = len () & ( for x being set st x in dom b holds
( ( b . x in [: the carrier' of S,{ the carrier of S}:] implies for o1 being OperSymbol of S st [o1, the carrier of S] = b . x holds
the_result_sort_of o1 = () . x ) & ( b . x in Union () implies b . x in coprod ((() . x),X) ) ) ) ) ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def7 defines REL MSAFREE:def 7 :
for S being non empty non void ManySortedSign
for X being ManySortedSet of the carrier of S
for b3 being Relation of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) *) holds
( b3 = REL X iff for a being Element of [: the carrier' of S,{ the carrier of S}:] \/ (Union ())
for b being Element of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) * holds
( [a,b] in b3 iff ( a in [: the carrier' of S,{ the carrier of S}:] & ( for o being OperSymbol of S st [o, the carrier of S] = a holds
( len b = len () & ( for x being set st x in dom b holds
( ( b . x in [: the carrier' of S,{ the carrier of S}:] implies for o1 being OperSymbol of S st [o1, the carrier of S] = b . x holds
the_result_sort_of o1 = () . x ) & ( b . x in Union () implies b . x in coprod ((() . x),X) ) ) ) ) ) ) ) );

theorem Th5: :: MSAFREE:5
for S being non empty non void ManySortedSign
for X being ManySortedSet of the carrier of S
for o being OperSymbol of S
for b being Element of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) * holds
( [[o, the carrier of S],b] in REL X iff ( len b = len () & ( for x being set st x in dom b holds
( ( b . x in [: the carrier' of S,{ the carrier of S}:] implies for o1 being OperSymbol of S st [o1, the carrier of S] = b . x holds
the_result_sort_of o1 = () . x ) & ( b . x in Union () implies b . x in coprod ((() . x),X) ) ) ) ) )
proof end;

definition
let S be non empty non void ManySortedSign ;
let X be ManySortedSet of the carrier of S;
func DTConMSA X -> DTConstrStr equals :: MSAFREE:def 8
DTConstrStr(# ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(REL X) #);
correctness
coherence
DTConstrStr(# ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(REL X) #) is DTConstrStr
;
;
end;

:: deftheorem defines DTConMSA MSAFREE:def 8 :
for S being non empty non void ManySortedSign
for X being ManySortedSet of the carrier of S holds DTConMSA X = DTConstrStr(# ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(REL X) #);

registration
let S be non empty non void ManySortedSign ;
let X be ManySortedSet of the carrier of S;
cluster DTConMSA X -> non empty strict ;
coherence
( DTConMSA X is strict & not DTConMSA X is empty )
;
end;

theorem Th6: :: MSAFREE:6
for S being non empty non void ManySortedSign
for X being ManySortedSet of the carrier of S holds
( NonTerminals () c= [: the carrier' of S,{ the carrier of S}:] & Union () c= Terminals () & ( X is V5() implies ( NonTerminals () = [: the carrier' of S,{ the carrier of S}:] & Terminals () = Union () ) ) )
proof end;

registration
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
coherence
proof end;
end;

theorem Th7: :: MSAFREE:7
for S being non empty non void ManySortedSign
for X being ManySortedSet of the carrier of S
for t being set holds
( ( t in Terminals () & X is V5() implies ex s being SortSymbol of S ex x being set st
( x in X . s & t = [x,s] ) ) & ( for s being SortSymbol of S
for x being set st x in X . s holds
[x,s] in Terminals () ) )
proof end;

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let o be OperSymbol of S;
func Sym (o,X) -> Symbol of () equals :: MSAFREE:def 9
[o, the carrier of S];
coherence
[o, the carrier of S] is Symbol of ()
proof end;
end;

:: deftheorem defines Sym MSAFREE:def 9 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for o being OperSymbol of S holds Sym (o,X) = [o, the carrier of S];

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let s be SortSymbol of S;
func FreeSort (X,s) -> Subset of (TS ()) equals :: MSAFREE:def 10
{ a where a is Element of TS () : ( ex x being set st
( x in X . s & a = root-tree [x,s] ) or ex o being OperSymbol of S st
( [o, the carrier of S] = a . {} & the_result_sort_of o = s ) )
}
;
coherence
{ a where a is Element of TS () : ( ex x being set st
( x in X . s & a = root-tree [x,s] ) or ex o being OperSymbol of S st
( [o, the carrier of S] = a . {} & the_result_sort_of o = s ) )
}
is Subset of (TS ())
proof end;
end;

:: deftheorem defines FreeSort MSAFREE:def 10 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for s being SortSymbol of S holds FreeSort (X,s) = { a where a is Element of TS () : ( ex x being set st
( x in X . s & a = root-tree [x,s] ) or ex o being OperSymbol of S st
( [o, the carrier of S] = a . {} & the_result_sort_of o = s ) )
}
;

registration
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let s be SortSymbol of S;
cluster FreeSort (X,s) -> non empty ;
coherence
not FreeSort (X,s) is empty
proof end;
end;

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
func FreeSort X -> ManySortedSet of the carrier of S means :Def11: :: MSAFREE:def 11
for s being SortSymbol of S holds it . s = FreeSort (X,s);
existence
ex b1 being ManySortedSet of the carrier of S st
for s being SortSymbol of S holds b1 . s = FreeSort (X,s)
proof end;
uniqueness
for b1, b2 being ManySortedSet of the carrier of S st ( for s being SortSymbol of S holds b1 . s = FreeSort (X,s) ) & ( for s being SortSymbol of S holds b2 . s = FreeSort (X,s) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def11 defines FreeSort MSAFREE:def 11 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for b3 being ManySortedSet of the carrier of S holds
( b3 = FreeSort X iff for s being SortSymbol of S holds b3 . s = FreeSort (X,s) );

registration
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
cluster FreeSort X -> V5() ;
coherence
proof end;
end;

theorem Th8: :: MSAFREE:8
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for o being OperSymbol of S
for x being set st x in ((() #) * the Arity of S) . o holds
x is FinSequence of TS ()
proof end;

theorem Th9: :: MSAFREE:9
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for o being OperSymbol of S
for p being FinSequence of TS () holds
( p in ((() #) * the Arity of S) . o iff ( dom p = dom () & ( for n being Nat st n in dom p holds
p . n in FreeSort (X,(() /. n)) ) ) )
proof end;

theorem Th10: :: MSAFREE:10
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for o being OperSymbol of S
for p being FinSequence of TS () holds
( Sym (o,X) ==> roots p iff p in ((() #) * the Arity of S) . o )
proof end;

theorem Th11: :: MSAFREE:11
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S holds union (rng ()) = TS ()
proof end;

theorem Th12: :: MSAFREE:12
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for s1, s2 being SortSymbol of S st s1 <> s2 holds
() . s1 misses () . s2
proof end;

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let o be OperSymbol of S;
func DenOp (o,X) -> Function of (((() #) * the Arity of S) . o),((() * the ResultSort of S) . o) means :Def12: :: MSAFREE:def 12
for p being FinSequence of TS () st Sym (o,X) ==> roots p holds
it . p = (Sym (o,X)) -tree p;
existence
ex b1 being Function of (((() #) * the Arity of S) . o),((() * the ResultSort of S) . o) st
for p being FinSequence of TS () st Sym (o,X) ==> roots p holds
b1 . p = (Sym (o,X)) -tree p
proof end;
uniqueness
for b1, b2 being Function of (((() #) * the Arity of S) . o),((() * the ResultSort of S) . o) st ( for p being FinSequence of TS () st Sym (o,X) ==> roots p holds
b1 . p = (Sym (o,X)) -tree p ) & ( for p being FinSequence of TS () st Sym (o,X) ==> roots p holds
b2 . p = (Sym (o,X)) -tree p ) holds
b1 = b2
proof end;
end;

:: deftheorem Def12 defines DenOp MSAFREE:def 12 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for o being OperSymbol of S
for b4 being Function of (((() #) * the Arity of S) . o),((() * the ResultSort of S) . o) holds
( b4 = DenOp (o,X) iff for p being FinSequence of TS () st Sym (o,X) ==> roots p holds
b4 . p = (Sym (o,X)) -tree p );

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
func FreeOper X -> ManySortedFunction of (() #) * the Arity of S,() * the ResultSort of S means :Def13: :: MSAFREE:def 13
for o being OperSymbol of S holds it . o = DenOp (o,X);
existence
ex b1 being ManySortedFunction of (() #) * the Arity of S,() * the ResultSort of S st
for o being OperSymbol of S holds b1 . o = DenOp (o,X)
proof end;
uniqueness
for b1, b2 being ManySortedFunction of (() #) * the Arity of S,() * the ResultSort of S st ( for o being OperSymbol of S holds b1 . o = DenOp (o,X) ) & ( for o being OperSymbol of S holds b2 . o = DenOp (o,X) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def13 defines FreeOper MSAFREE:def 13 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for b3 being ManySortedFunction of (() #) * the Arity of S,() * the ResultSort of S holds
( b3 = FreeOper X iff for o being OperSymbol of S holds b3 . o = DenOp (o,X) );

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
func FreeMSA X -> MSAlgebra over S equals :: MSAFREE:def 14
MSAlgebra(# (),() #);
coherence
MSAlgebra(# (),() #) is MSAlgebra over S
;
end;

:: deftheorem defines FreeMSA MSAFREE:def 14 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S holds FreeMSA X = MSAlgebra(# (),() #);

registration
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
coherence
( FreeMSA X is strict & FreeMSA X is non-empty )
by MSUALG_1:def 3;
end;

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let s be SortSymbol of S;
func FreeGen (s,X) -> Subset of (() . s) means :Def15: :: MSAFREE:def 15
for x being set holds
( x in it iff ex a being set st
( a in X . s & x = root-tree [a,s] ) );
existence
ex b1 being Subset of (() . s) st
for x being set holds
( x in b1 iff ex a being set st
( a in X . s & x = root-tree [a,s] ) )
proof end;
uniqueness
for b1, b2 being Subset of (() . s) st ( for x being set holds
( x in b1 iff ex a being set st
( a in X . s & x = root-tree [a,s] ) ) ) & ( for x being set holds
( x in b2 iff ex a being set st
( a in X . s & x = root-tree [a,s] ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def15 defines FreeGen MSAFREE:def 15 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for s being SortSymbol of S
for b4 being Subset of (() . s) holds
( b4 = FreeGen (s,X) iff for x being set holds
( x in b4 iff ex a being set st
( a in X . s & x = root-tree [a,s] ) ) );

registration
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let s be SortSymbol of S;
cluster FreeGen (s,X) -> non empty ;
coherence
not FreeGen (s,X) is empty
proof end;
end;

theorem Th13: :: MSAFREE:13
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for s being SortSymbol of S holds FreeGen (s,X) = { () where t is Symbol of () : ( t in Terminals () & t 2 = s ) }
proof end;

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
func FreeGen X -> GeneratorSet of FreeMSA X means :Def16: :: MSAFREE:def 16
for s being SortSymbol of S holds it . s = FreeGen (s,X);
existence
ex b1 being GeneratorSet of FreeMSA X st
for s being SortSymbol of S holds b1 . s = FreeGen (s,X)
proof end;
uniqueness
for b1, b2 being GeneratorSet of FreeMSA X st ( for s being SortSymbol of S holds b1 . s = FreeGen (s,X) ) & ( for s being SortSymbol of S holds b2 . s = FreeGen (s,X) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def16 defines FreeGen MSAFREE:def 16 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for b3 being GeneratorSet of FreeMSA X holds
( b3 = FreeGen X iff for s being SortSymbol of S holds b3 . s = FreeGen (s,X) );

theorem :: MSAFREE:14
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S holds FreeGen X is V5()
proof end;

theorem :: MSAFREE:15
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S holds union (rng ()) = { () where t is Symbol of () : t in Terminals () }
proof end;

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let s be SortSymbol of S;
func Reverse (s,X) -> Function of (FreeGen (s,X)),(X . s) means :Def17: :: MSAFREE:def 17
for t being Symbol of () st root-tree t in FreeGen (s,X) holds
it . () = t 1 ;
existence
ex b1 being Function of (FreeGen (s,X)),(X . s) st
for t being Symbol of () st root-tree t in FreeGen (s,X) holds
b1 . () = t 1
proof end;
uniqueness
for b1, b2 being Function of (FreeGen (s,X)),(X . s) st ( for t being Symbol of () st root-tree t in FreeGen (s,X) holds
b1 . () = t 1 ) & ( for t being Symbol of () st root-tree t in FreeGen (s,X) holds
b2 . () = t 1 ) holds
b1 = b2
proof end;
end;

:: deftheorem Def17 defines Reverse MSAFREE:def 17 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for s being SortSymbol of S
for b4 being Function of (FreeGen (s,X)),(X . s) holds
( b4 = Reverse (s,X) iff for t being Symbol of () st root-tree t in FreeGen (s,X) holds
b4 . () = t 1 );

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
func Reverse X -> ManySortedFunction of FreeGen X,X means :Def18: :: MSAFREE:def 18
for s being SortSymbol of S holds it . s = Reverse (s,X);
existence
ex b1 being ManySortedFunction of FreeGen X,X st
for s being SortSymbol of S holds b1 . s = Reverse (s,X)
proof end;
uniqueness
for b1, b2 being ManySortedFunction of FreeGen X,X st ( for s being SortSymbol of S holds b1 . s = Reverse (s,X) ) & ( for s being SortSymbol of S holds b2 . s = Reverse (s,X) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def18 defines Reverse MSAFREE:def 18 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for b3 being ManySortedFunction of FreeGen X,X holds
( b3 = Reverse X iff for s being SortSymbol of S holds b3 . s = Reverse (s,X) );

definition
let S be non empty non void ManySortedSign ;
let X, A be V5() ManySortedSet of the carrier of S;
let F be ManySortedFunction of FreeGen X,A;
let t be Symbol of ();
assume A1: t in Terminals () ;
func pi (F,A,t) -> Element of Union A means :Def19: :: MSAFREE:def 19
for f being Function st f = F . (t 2) holds
it = f . ();
existence
ex b1 being Element of Union A st
for f being Function st f = F . (t 2) holds
b1 = f . ()
proof end;
uniqueness
for b1, b2 being Element of Union A st ( for f being Function st f = F . (t 2) holds
b1 = f . () ) & ( for f being Function st f = F . (t 2) holds
b2 = f . () ) holds
b1 = b2
proof end;
end;

:: deftheorem Def19 defines pi MSAFREE:def 19 :
for S being non empty non void ManySortedSign
for X, A being V5() ManySortedSet of the carrier of S
for F being ManySortedFunction of FreeGen X,A
for t being Symbol of () st t in Terminals () holds
for b6 being Element of Union A holds
( b6 = pi (F,A,t) iff for f being Function st f = F . (t `2) holds
b6 = f . () );

definition
let S be non empty non void ManySortedSign ;
let X be V5() ManySortedSet of the carrier of S;
let t be Symbol of ();
assume A1: ex p being FinSequence st t ==> p ;
func @ (X,t) -> OperSymbol of S means :Def20: :: MSAFREE:def 20
[it, the carrier of S] = t;
existence
ex b1 being OperSymbol of S st [b1, the carrier of S] = t
proof end;
uniqueness
for b1, b2 being OperSymbol of S st [b1, the carrier of S] = t & [b2, the carrier of S] = t holds
b1 = b2
by XTUPLE_0:1;
end;

:: deftheorem Def20 defines @ MSAFREE:def 20 :
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S
for t being Symbol of () st ex p being FinSequence st t ==> p holds
for b4 being OperSymbol of S holds
( b4 = @ (X,t) iff [b4, the carrier of S] = t );

definition
let S be non empty non void ManySortedSign ;
let U0 be non-empty MSAlgebra over S;
let o be OperSymbol of S;
let p be FinSequence;
assume A1: p in Args (o,U0) ;
func pi (o,U0,p) -> Element of Union the Sorts of U0 equals :Def21: :: MSAFREE:def 21
(Den (o,U0)) . p;
coherence
(Den (o,U0)) . p is Element of Union the Sorts of U0
proof end;
end;

:: deftheorem Def21 defines pi MSAFREE:def 21 :
for S being non empty non void ManySortedSign
for U0 being non-empty MSAlgebra over S
for o being OperSymbol of S
for p being FinSequence st p in Args (o,U0) holds
pi (o,U0,p) = (Den (o,U0)) . p;

theorem Th16: :: MSAFREE:16
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S holds FreeGen X is free
proof end;

theorem Th17: :: MSAFREE:17
for S being non empty non void ManySortedSign
for X being V5() ManySortedSet of the carrier of S holds FreeMSA X is free
proof end;

registration
let S be non empty non void ManySortedSign ;
cluster strict non-empty free for MSAlgebra over S;
existence
ex b1 being non-empty MSAlgebra over S st
( b1 is free & b1 is strict )
proof end;
end;

registration
let S be non empty non void ManySortedSign ;
let U0 be free MSAlgebra over S;
existence
ex b1 being GeneratorSet of U0 st b1 is free
by Def6;
end;

theorem Th18: :: MSAFREE:18
for S being non empty non void ManySortedSign
for U1 being non-empty MSAlgebra over S ex U0 being strict non-empty free MSAlgebra over S ex F being ManySortedFunction of U0,U1 st F is_epimorphism U0,U1
proof end;

theorem :: MSAFREE:19
for S being non empty non void ManySortedSign
for U1 being strict non-empty MSAlgebra over S ex U0 being strict non-empty free MSAlgebra over S ex F being ManySortedFunction of U0,U1 st
( F is_epimorphism U0,U1 & Image F = U1 )
proof end;