:: Free Order Sorted Universal Algebra
:: by Josef Urban
::
:: Received September 19, 2002
:: Copyright (c) 2002-2021 Association of Mizar Users

:: REVISE: should rather be attribute
:: changing to MSSubset and its OSCl, to make free algebras easier
:: no good way how to retypeOSCL into OSSubset now?
definition
let S be OrderSortedSign;
let U0 be OSAlgebra of S;
mode OSGeneratorSet of U0 -> MSSubset of U0 means :Def1: :: OSAFREE:def 1
for O being OSSubset of U0 st O = OSCl it holds
the Sorts of () = the Sorts of U0;
existence
ex b1 being MSSubset of U0 st
for O being OSSubset of U0 st O = OSCl b1 holds
the Sorts of () = the Sorts of U0
proof end;
end;

:: deftheorem Def1 defines OSGeneratorSet OSAFREE:def 1 :
for S being OrderSortedSign
for U0 being OSAlgebra of S
for b3 being MSSubset of U0 holds
( b3 is OSGeneratorSet of U0 iff for O being OSSubset of U0 st O = OSCl b3 holds
the Sorts of () = the Sorts of U0 );

theorem :: OSAFREE:1
for S being OrderSortedSign
for U0 being strict non-empty OSAlgebra of S
for A being MSSubset of U0 holds
( A is OSGeneratorSet of U0 iff for O being OSSubset of U0 st O = OSCl A holds
GenOSAlg O = U0 )
proof end;

:: renaming to osfree - if OSGeneratorSet and GeneratorSet become
:: attributes, Mizar would be puzzled
:: we do this for monotone osas only, though more general approach is possible
definition
let S be OrderSortedSign;
let U0 be monotone OSAlgebra of S;
let IT be OSGeneratorSet of U0;
attr IT is osfree means :: OSAFREE:def 2
for U1 being non-empty monotone OSAlgebra of 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 is order-sorted & h || IT = f );
end;

:: deftheorem defines osfree OSAFREE:def 2 :
for S being OrderSortedSign
for U0 being monotone OSAlgebra of S
for IT being OSGeneratorSet of U0 holds
( IT is osfree iff for U1 being non-empty monotone OSAlgebra of 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 is order-sorted & h || IT = f ) );

definition
let S be OrderSortedSign;
let IT be monotone OSAlgebra of S;
attr IT is osfree means :: OSAFREE:def 3
ex G being OSGeneratorSet of IT st G is osfree ;
end;

:: deftheorem defines osfree OSAFREE:def 3 :
for S being OrderSortedSign
for IT being monotone OSAlgebra of S holds
( IT is osfree iff ex G being OSGeneratorSet of IT st G is osfree );

::
:: Construction of Free Order Sorted Algebras for Given Signature
::
definition
let S be OrderSortedSign;
let X be ManySortedSet of S;
func OSREL X -> Relation of ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),(([: the carrier' of S,{ the carrier of S}:] \/ (Union ())) *) means :Def4: :: OSAFREE:def 4
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 ex i being Element of S st
( i <= () /. x & b . x in coprod (i,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 ex i being Element of S st
( i <= () /. x & b . x in coprod (i,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 ex i being Element of S st
( i <= () /. x & b . x in coprod (i,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 ex i being Element of S st
( i <= () /. x & b . x in coprod (i,X) ) ) ) ) ) ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def4 defines OSREL OSAFREE:def 4 :
for S being OrderSortedSign
for X being ManySortedSet 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 = OSREL 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 ex i being Element of S st
( i <= () /. x & b . x in coprod (i,X) ) ) ) ) ) ) ) ) );

theorem Th2: :: OSAFREE:2
for S being OrderSortedSign
for X being ManySortedSet 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 OSREL 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 ex i being Element of S st
( i <= () /. x & b . x in coprod (i,X) ) ) ) ) ) )
proof end;

definition
let S be OrderSortedSign;
let X be ManySortedSet of S;
func DTConOSA X -> DTConstrStr equals :: OSAFREE:def 5
DTConstrStr(# ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),() #);
correctness
coherence
DTConstrStr(# ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),() #) is DTConstrStr
;
;
end;

:: deftheorem defines DTConOSA OSAFREE:def 5 :
for S being OrderSortedSign
for X being ManySortedSet of S holds DTConOSA X = DTConstrStr(# ([: the carrier' of S,{ the carrier of S}:] \/ (Union ())),() #);

registration
let S be OrderSortedSign;
let X be ManySortedSet of S;
cluster DTConOSA X -> non empty strict ;
coherence
( DTConOSA X is strict & not DTConOSA X is empty )
;
end;

theorem Th3: :: OSAFREE:3
for S being OrderSortedSign
for X being V2() ManySortedSet of S holds
( NonTerminals () = [: the carrier' of S,{ the carrier of S}:] & Terminals () = Union () )
proof end;

registration
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
coherence
proof end;
end;

theorem Th4: :: OSAFREE:4
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for t being set holds
( t in Terminals () iff ex s being Element of S ex x being set st
( x in X . s & t = [x,s] ) )
proof end;

:: have to rename
definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let o be OperSymbol of S;
func OSSym (o,X) -> Symbol of () equals :: OSAFREE:def 6
[o, the carrier of S];
coherence
[o, the carrier of S] is Symbol of ()
proof end;
end;

:: deftheorem defines OSSym OSAFREE:def 6 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for o being OperSymbol of S holds OSSym (o,X) = [o, the carrier of S];

:: originally FreeSort, but it is not a good name in order-sorted context
definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let s be Element of S;
func ParsedTerms (X,s) -> Subset of (TS ()) equals :: OSAFREE:def 7
{ a where a is Element of TS () : ( ex s1 being Element of S ex x being object st
( s1 <= s & x in X . s1 & a = root-tree [x,s1] ) 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 s1 being Element of S ex x being object st
( s1 <= s & x in X . s1 & a = root-tree [x,s1] ) 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 ParsedTerms OSAFREE:def 7 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S holds ParsedTerms (X,s) = { a where a is Element of TS () : ( ex s1 being Element of S ex x being object st
( s1 <= s & x in X . s1 & a = root-tree [x,s1] ) or ex o being OperSymbol of S st
( [o, the carrier of S] = a . {} & the_result_sort_of o <= s ) )
}
;

registration
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let s be Element of S;
cluster ParsedTerms (X,s) -> non empty ;
coherence
not ParsedTerms (X,s) is empty
proof end;
end;

definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
func ParsedTerms X -> OrderSortedSet of S means :Def8: :: OSAFREE:def 8
for s being Element of S holds it . s = ParsedTerms (X,s);
existence
ex b1 being OrderSortedSet of S st
for s being Element of S holds b1 . s = ParsedTerms (X,s)
proof end;
uniqueness
for b1, b2 being OrderSortedSet of S st ( for s being Element of S holds b1 . s = ParsedTerms (X,s) ) & ( for s being Element of S holds b2 . s = ParsedTerms (X,s) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def8 defines ParsedTerms OSAFREE:def 8 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being OrderSortedSet of S holds
( b3 = ParsedTerms X iff for s being Element of S holds b3 . s = ParsedTerms (X,s) );

registration
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
cluster ParsedTerms X -> V2() ;
coherence
proof end;
end;

theorem Th5: :: OSAFREE:5
for S being OrderSortedSign
for X being V2() ManySortedSet 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 Th6: :: OSAFREE:6
for S being OrderSortedSign
for X being V2() ManySortedSet 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 ParsedTerms (X,(() /. n)) ) ) )
proof end;

theorem Th7: :: OSAFREE:7
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for o being OperSymbol of S
for p being FinSequence of TS () holds
( OSSym (o,X) ==> roots p iff p in ((() #) * the Arity of S) . o )
proof end;

theorem Th8: :: OSAFREE:8
for S being OrderSortedSign
for X being V2() ManySortedSet of S holds union (rng ()) = TS ()
proof end;

definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let o be OperSymbol of S;
func PTDenOp (o,X) -> Function of (((() #) * the Arity of S) . o),((() * the ResultSort of S) . o) means :Def9: :: OSAFREE:def 9
for p being FinSequence of TS () st OSSym (o,X) ==> roots p holds
it . p = (OSSym (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 OSSym (o,X) ==> roots p holds
b1 . p = (OSSym (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 OSSym (o,X) ==> roots p holds
b1 . p = (OSSym (o,X)) -tree p ) & ( for p being FinSequence of TS () st OSSym (o,X) ==> roots p holds
b2 . p = (OSSym (o,X)) -tree p ) holds
b1 = b2
proof end;
end;

:: deftheorem Def9 defines PTDenOp OSAFREE:def 9 :
for S being OrderSortedSign
for X being V2() ManySortedSet 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 = PTDenOp (o,X) iff for p being FinSequence of TS () st OSSym (o,X) ==> roots p holds
b4 . p = (OSSym (o,X)) -tree p );

definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
func PTOper X -> ManySortedFunction of (() #) * the Arity of S,() * the ResultSort of S means :Def10: :: OSAFREE:def 10
for o being OperSymbol of S holds it . o = PTDenOp (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 = PTDenOp (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 = PTDenOp (o,X) ) & ( for o being OperSymbol of S holds b2 . o = PTDenOp (o,X) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def10 defines PTOper OSAFREE:def 10 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being ManySortedFunction of (() #) * the Arity of S,() * the ResultSort of S holds
( b3 = PTOper X iff for o being OperSymbol of S holds b3 . o = PTDenOp (o,X) );

definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
func ParsedTermsOSA X -> OSAlgebra of S equals :: OSAFREE:def 11
MSAlgebra(# (),() #);
coherence
MSAlgebra(# (),() #) is OSAlgebra of S
by OSALG_1:17;
end;

:: deftheorem defines ParsedTermsOSA OSAFREE:def 11 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S holds ParsedTermsOSA X = MSAlgebra(# (),() #);

registration
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
coherence by MSUALG_1:def 3;
end;

definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let o be OperSymbol of S;
:: original: OSSym
redefine func OSSym (o,X) -> NonTerminal of ();
coherence
OSSym (o,X) is NonTerminal of ()
proof end;
end;

theorem Th9: :: OSAFREE:9
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S holds the Sorts of () . s = { a where a is Element of TS () : ( ex s1 being Element of S ex x being object st
( s1 <= s & x in X . s1 & a = root-tree [x,s1] ) or ex o being OperSymbol of S st
( [o, the carrier of S] = a . {} & the_result_sort_of o <= s ) )
}
proof end;

theorem Th10: :: OSAFREE:10
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for s, s1 being Element of S
for x being set st x in X . s holds
( root-tree [x,s] is Element of TS () & ( for z being set holds [z, the carrier of S] <> (root-tree [x,s]) . {} ) & ( root-tree [x,s] in the Sorts of () . s1 implies s <= s1 ) & ( s <= s1 implies root-tree [x,s] in the Sorts of () . s1 ) )
proof end;

theorem Th11: :: OSAFREE:11
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for t being Element of TS ()
for o being OperSymbol of S st t . {} = [o, the carrier of S] holds
( ex p being SubtreeSeq of OSSym (o,X) st
( t = (OSSym (o,X)) -tree p & OSSym (o,X) ==> roots p & p in Args (o,()) & t = (Den (o,())) . p ) & ( for s2 being Element of S
for x being set holds t <> root-tree [x,s2] ) & ( for s1 being Element of S holds
( t in the Sorts of () . s1 iff the_result_sort_of o <= s1 ) ) )
proof end;

theorem Th12: :: OSAFREE:12
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
( nt in NonTerminals () & nt -tree ts in TS () & ex o being OperSymbol of S st
( nt = [o, the carrier of S] & ts in Args (o,()) & nt -tree ts = (Den (o,())) . ts & ( for s1 being Element of S holds
( nt -tree ts in the Sorts of () . s1 iff the_result_sort_of o <= s1 ) ) ) )
proof end;

:: Element of Args is FinSequence (if clusters MSUALG_9)
theorem Th13: :: OSAFREE:13
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for o being OperSymbol of S
for x being FinSequence holds
( x in Args (o,()) iff ( x is FinSequence of TS () & OSSym (o,X) ==> roots x ) )
proof end;

:: this should be done more generally for leastsorted osas (and
:: then remove the LeastSorts func), however, it is better here
:: to have it defined for terms (and not Elements of osa)
definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let t be Element of TS ();
func LeastSort t -> SortSymbol of S means :Def12: :: OSAFREE:def 12
( t in the Sorts of () . it & ( for s1 being Element of S st t in the Sorts of () . s1 holds
it <= s1 ) );
existence
ex b1 being SortSymbol of S st
( t in the Sorts of () . b1 & ( for s1 being Element of S st t in the Sorts of () . s1 holds
b1 <= s1 ) )
proof end;
uniqueness
for b1, b2 being SortSymbol of S st t in the Sorts of () . b1 & ( for s1 being Element of S st t in the Sorts of () . s1 holds
b1 <= s1 ) & t in the Sorts of () . b2 & ( for s1 being Element of S st t in the Sorts of () . s1 holds
b2 <= s1 ) holds
b1 = b2
proof end;
end;

:: deftheorem Def12 defines LeastSort OSAFREE:def 12 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for t being Element of TS ()
for b4 being SortSymbol of S holds
( b4 = LeastSort t iff ( t in the Sorts of () . b4 & ( for s1 being Element of S st t in the Sorts of () . s1 holds
b4 <= s1 ) ) );

:: REVISE: the clusters needed to make the def from MSAFREE3 work
:: are too demanding, make it more easily accessible (or include
:: the clusters if it is too hard)
definition
let S be non empty non void ManySortedSign ;
let A be non-empty MSAlgebra over S;
mode Element of A is Element of Union the Sorts of A;
end;

theorem Th14: :: OSAFREE:14
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for x being set holds
( x is Element of () iff x is Element of TS () )
proof end;

theorem Th15: :: OSAFREE:15
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for x being set st x in the Sorts of () . s holds
x is Element of TS ()
proof end;

theorem :: OSAFREE:16
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for x being set st x in X . s holds
for t being Element of TS () st t = root-tree [x,s] holds
LeastSort t = s
proof end;

theorem Th17: :: OSAFREE:17
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for o being OperSymbol of S
for x being Element of Args (o,())
for t being Element of TS () st t = (Den (o,())) . x holds
LeastSort t = the_result_sort_of o
proof end;

:: WHY is this necessary??? bug?
registration
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let o2 be OperSymbol of S;
cluster Args (o2,()) -> non empty ;
coherence
not Args (o2,()) is empty
;
end;

:: REVISE: was probably needed for casting, but try if
:: LeastSort * x does the work and if so, remove this
definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let x be FinSequence of TS ();
func LeastSorts x -> Element of the carrier of S * means :Def13: :: OSAFREE:def 13
( dom it = dom x & ( for y being Nat st y in dom x holds
ex t being Element of TS () st
( t = x . y & it . y = LeastSort t ) ) );
existence
ex b1 being Element of the carrier of S * st
( dom b1 = dom x & ( for y being Nat st y in dom x holds
ex t being Element of TS () st
( t = x . y & b1 . y = LeastSort t ) ) )
proof end;
uniqueness
for b1, b2 being Element of the carrier of S * st dom b1 = dom x & ( for y being Nat st y in dom x holds
ex t being Element of TS () st
( t = x . y & b1 . y = LeastSort t ) ) & dom b2 = dom x & ( for y being Nat st y in dom x holds
ex t being Element of TS () st
( t = x . y & b2 . y = LeastSort t ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def13 defines LeastSorts OSAFREE:def 13 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for x being FinSequence of TS ()
for b4 being Element of the carrier of S * holds
( b4 = LeastSorts x iff ( dom b4 = dom x & ( for y being Nat st y in dom x holds
ex t being Element of TS () st
( t = x . y & b4 . y = LeastSort t ) ) ) );

:: all these should be generalized to any leastsorted osa
theorem Th18: :: OSAFREE:18
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for o being OperSymbol of S
for x being FinSequence of TS () holds
( LeastSorts x <= the_arity_of o iff x in Args (o,()) )
proof end;

registration
existence
ex b1 being monotone OrderSortedSign st
( b1 is locally_directed & b1 is regular )
proof end;
end;

:: just casting funcs necessary for the usage of schemes
definition
let S be monotone regular locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let o be OperSymbol of S;
let x be FinSequence of TS ();
assume A1: OSSym ((LBound (o,())),X) ==> roots x ;
func pi (o,x) -> Element of TS () equals :Def14: :: OSAFREE:def 14
(OSSym ((LBound (o,())),X)) -tree x;
correctness
coherence
(OSSym ((LBound (o,())),X)) -tree x is Element of TS ()
;
by ;
end;

:: deftheorem Def14 defines pi OSAFREE:def 14 :
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for o being OperSymbol of S
for x being FinSequence of TS () st OSSym ((LBound (o,())),X) ==> roots x holds
pi (o,x) = (OSSym ((LBound (o,())),X)) -tree x;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let t be Symbol of ();
assume A1: ex p being FinSequence st t ==> p ;
func @ (X,t) -> OperSymbol of S means :Def15: :: OSAFREE:def 15
[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 Def15 defines @ OSAFREE:def 15 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet 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 OrderSortedSign;
let X be V2() ManySortedSet of S;
let t be Symbol of ();
assume A1: t in Terminals () ;
func pi t -> Element of TS () equals :Def16: :: OSAFREE:def 16
root-tree t;
correctness
coherence
root-tree t is Element of TS ()
;
by ;
end;

:: deftheorem Def16 defines pi OSAFREE:def 16 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for t being Symbol of () st t in Terminals () holds
pi t = root-tree t;

:: the least monotone OSCongruence
definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func LCongruence X -> monotone OSCongruence of ParsedTermsOSA X means :Def17: :: OSAFREE:def 17
for R being monotone OSCongruence of ParsedTermsOSA X holds it c= R;
existence
ex b1 being monotone OSCongruence of ParsedTermsOSA X st
for R being monotone OSCongruence of ParsedTermsOSA X holds b1 c= R
proof end;
uniqueness
for b1, b2 being monotone OSCongruence of ParsedTermsOSA X st ( for R being monotone OSCongruence of ParsedTermsOSA X holds b1 c= R ) & ( for R being monotone OSCongruence of ParsedTermsOSA X holds b2 c= R ) holds
b1 = b2
proof end;
end;

:: deftheorem Def17 defines LCongruence OSAFREE:def 17 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being monotone OSCongruence of ParsedTermsOSA X holds
( b3 = LCongruence X iff for R being monotone OSCongruence of ParsedTermsOSA X holds b3 c= R );

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func FreeOSA X -> strict non-empty monotone OSAlgebra of S equals :: OSAFREE:def 18
QuotOSAlg ((),());
correctness
coherence
QuotOSAlg ((),()) is strict non-empty monotone OSAlgebra of S
;
;
end;

:: deftheorem defines FreeOSA OSAFREE:def 18 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds FreeOSA X = QuotOSAlg ((),());

:: now we need an explicit description of a sufficiently small
:: monotone OSCongruence on PTA; the PTCongruence turns out to
:: be LCongruence on regular signatures, and is also used to describe
:: minimal terms there
:: just casting funcs necessary for the usage of schemes,
:: remove when Frankel behaves better
definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let t be Symbol of ();
func @ t -> Subset of [:(TS ()), the carrier of S:] equals :: OSAFREE:def 19
{ [(),s1] where s1 is Element of S : ex s being Element of S ex x being set st
( x in X . s & t = [x,s] & s <= s1 )
}
;
correctness
coherence
{ [(),s1] where s1 is Element of S : ex s being Element of S ex x being set st
( x in X . s & t = [x,s] & s <= s1 )
}
is Subset of [:(TS ()), the carrier of S:]
;
proof end;
end;

:: deftheorem defines @ OSAFREE:def 19 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for t being Symbol of () holds @ t = { [(),s1] where s1 is Element of S : ex s being Element of S ex x being set st
( x in X . s & t = [x,s] & s <= s1 )
}
;

definition
let S be OrderSortedSign;
let X be V2() ManySortedSet of S;
let nt be Symbol of ();
let x be FinSequence of bool [:(TS ()), the carrier of S:];
func @ (nt,x) -> Subset of [:(TS ()), the carrier of S:] equals :: OSAFREE:def 20
{ [((Den (o2,())) . x2),s3] where o2 is OperSymbol of S, x2 is Element of Args (o2,()), s3 is Element of S : ( ex o1 being OperSymbol of S st
( nt = [o1, the carrier of S] & o1 ~= o2 & len () = len () & the_result_sort_of o1 <= s3 & the_result_sort_of o2 <= s3 ) & ex w3 being Element of the carrier of S * st
( dom w3 = dom x & ( for y being Nat st y in dom x holds
[(x2 . y),(w3 /. y)] in x . y ) ) )
}
;
correctness
coherence
{ [((Den (o2,())) . x2),s3] where o2 is OperSymbol of S, x2 is Element of Args (o2,()), s3 is Element of S : ( ex o1 being OperSymbol of S st
( nt = [o1, the carrier of S] & o1 ~= o2 & len () = len () & the_result_sort_of o1 <= s3 & the_result_sort_of o2 <= s3 ) & ex w3 being Element of the carrier of S * st
( dom w3 = dom x & ( for y being Nat st y in dom x holds
[(x2 . y),(w3 /. y)] in x . y ) ) )
}
is Subset of [:(TS ()), the carrier of S:]
;
proof end;
end;

:: deftheorem defines @ OSAFREE:def 20 :
for S being OrderSortedSign
for X being V2() ManySortedSet of S
for nt being Symbol of ()
for x being FinSequence of bool [:(TS ()), the carrier of S:] holds @ (nt,x) = { [((Den (o2,())) . x2),s3] where o2 is OperSymbol of S, x2 is Element of Args (o2,()), s3 is Element of S : ( ex o1 being OperSymbol of S st
( nt = [o1, the carrier of S] & o1 ~= o2 & len () = len () & the_result_sort_of o1 <= s3 & the_result_sort_of o2 <= s3 ) & ex w3 being Element of the carrier of S * st
( dom w3 = dom x & ( for y being Nat st y in dom x holds
[(x2 . y),(w3 /. y)] in x . y ) ) )
}
;

:: a bit technical, to create the PTCongruence
definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func PTClasses X -> Function of (TS ()),(bool [:(TS ()), the carrier of S:]) means :Def21: :: OSAFREE:def 21
( ( for t being Symbol of () st t in Terminals () holds
it . () = @ t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
it . (nt -tree ts) = @ (nt,(it * ts)) ) );
existence
ex b1 being Function of (TS ()),(bool [:(TS ()), the carrier of S:]) st
( ( for t being Symbol of () st t in Terminals () holds
b1 . () = @ t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b1 . (nt -tree ts) = @ (nt,(b1 * ts)) ) )
proof end;
uniqueness
for b1, b2 being Function of (TS ()),(bool [:(TS ()), the carrier of S:]) st ( for t being Symbol of () st t in Terminals () holds
b1 . () = @ t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b1 . (nt -tree ts) = @ (nt,(b1 * ts)) ) & ( for t being Symbol of () st t in Terminals () holds
b2 . () = @ t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b2 . (nt -tree ts) = @ (nt,(b2 * ts)) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def21 defines PTClasses OSAFREE:def 21 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being Function of (TS ()),(bool [:(TS ()), the carrier of S:]) holds
( b3 = PTClasses X iff ( ( for t being Symbol of () st t in Terminals () holds
b3 . () = @ t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b3 . (nt -tree ts) = @ (nt,(b3 * ts)) ) ) );

theorem Th19: :: OSAFREE:19
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for t being Element of TS () holds
( ( for s being Element of S holds
( t in the Sorts of () . s iff [t,s] in () . t ) ) & ( for s being Element of S
for y being Element of TS () st [y,s] in () . t holds
[t,s] in () . y ) )
proof end;

:: switched to have easier prooving
theorem Th20: :: OSAFREE:20
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for t being Element of TS ()
for s being Element of S st ex y being Element of TS () st [y,s] in () . t holds
[t,s] in () . t
proof end;

theorem Th21: :: OSAFREE:21
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for x, y being Element of TS ()
for s1, s2 being Element of S st s1 <= s2 & x in the Sorts of () . s1 & y in the Sorts of () . s1 holds
( [y,s1] in () . x iff [y,s2] in () . x )
proof end;

theorem Th22: :: OSAFREE:22
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for x, y, z being Element of TS ()
for s being Element of S st [y,s] in () . x & [z,s] in () . y holds
[x,s] in () . z
proof end;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func PTCongruence X -> MSEquivalence-like OrderSortedRelation of ParsedTermsOSA X means :Def22: :: OSAFREE:def 22
for i being set st i in the carrier of S holds
it . i = { [x,y] where x, y is Element of TS () : [x,i] in () . y } ;
existence
ex b1 being MSEquivalence-like OrderSortedRelation of ParsedTermsOSA X st
for i being set st i in the carrier of S holds
b1 . i = { [x,y] where x, y is Element of TS () : [x,i] in () . y }
proof end;
uniqueness
for b1, b2 being MSEquivalence-like OrderSortedRelation of ParsedTermsOSA X st ( for i being set st i in the carrier of S holds
b1 . i = { [x,y] where x, y is Element of TS () : [x,i] in () . y } ) & ( for i being set st i in the carrier of S holds
b2 . i = { [x,y] where x, y is Element of TS () : [x,i] in () . y } ) holds
b1 = b2
proof end;
end;

:: deftheorem Def22 defines PTCongruence OSAFREE:def 22 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being MSEquivalence-like OrderSortedRelation of ParsedTermsOSA X holds
( b3 = PTCongruence X iff for i being set st i in the carrier of S holds
b3 . i = { [x,y] where x, y is Element of TS () : [x,i] in () . y } );

theorem Th23: :: OSAFREE:23
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for x, y, s being object st [x,s] in () . y holds
( x in TS () & y in TS () & s in the carrier of S )
proof end;

theorem Th24: :: OSAFREE:24
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for C being Component of S
for x, y being object holds
( [x,y] in CompClass ((),C) iff ex s1 being Element of S st
( s1 in C & [x,s1] in () . y ) )
proof end;

theorem Th25: :: OSAFREE:25
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for x being Element of the Sorts of () . s holds OSClass ((),x) = proj1 (() . x)
proof end;

:: more explicit description of PTCongruence
theorem Th26: :: OSAFREE:26
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for R being ManySortedRelation of () holds
( R = PTCongruence X iff ( ( for s1, s2 being Element of S
for x being object st x in X . s1 holds
( ( s1 <= s2 implies [(root-tree [x,s1]),(root-tree [x,s1])] in R . s2 ) & ( for y being object st ( [(root-tree [x,s1]),y] in R . s2 or [y,(root-tree [x,s1])] in R . s2 ) holds
( s1 <= s2 & y = root-tree [x,s1] ) ) ) ) & ( for o1, o2 being OperSymbol of S
for x1 being Element of Args (o1,())
for x2 being Element of Args (o2,())
for s3 being Element of S holds
( [((Den (o1,())) . x1),((Den (o2,())) . x2)] in R . s3 iff ( o1 ~= o2 & len () = len () & the_result_sort_of o1 <= s3 & the_result_sort_of o2 <= s3 & ex w3 being Element of the carrier of S * st
( dom w3 = dom x1 & ( for y being Nat st y in dom w3 holds
[(x1 . y),(x2 . y)] in R . (w3 /. y) ) ) ) ) ) ) )
proof end;

:: the minimality for regular oss is done later
theorem Th27: :: OSAFREE:27
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds PTCongruence X is monotone
proof end;

:: MSCongruence-like is ensured by the OSALG_4 cluster
registration
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
coherence by Th27;
end;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let s be Element of S;
func PTVars (s,X) -> Subset of ( the Sorts of () . s) means :Def23: :: OSAFREE:def 23
for x being object holds
( x in it iff ex a being object st
( a in X . s & x = root-tree [a,s] ) );
existence
ex b1 being Subset of ( the Sorts of () . s) st
for x being object holds
( x in b1 iff ex a being object st
( a in X . s & x = root-tree [a,s] ) )
proof end;
uniqueness
for b1, b2 being Subset of ( the Sorts of () . s) st ( for x being object holds
( x in b1 iff ex a being object st
( a in X . s & x = root-tree [a,s] ) ) ) & ( for x being object holds
( x in b2 iff ex a being object st
( a in X . s & x = root-tree [a,s] ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def23 defines PTVars OSAFREE:def 23 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for b4 being Subset of ( the Sorts of () . s) holds
( b4 = PTVars (s,X) iff for x being object holds
( x in b4 iff ex a being object st
( a in X . s & x = root-tree [a,s] ) ) );

registration
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let s be Element of S;
cluster PTVars (s,X) -> non empty ;
coherence
not PTVars (s,X) is empty
proof end;
end;

theorem Th28: :: OSAFREE:28
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S holds PTVars (s,X) = { () where t is Symbol of () : ( t in Terminals () & t 2 = s ) }
proof end;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func PTVars X -> MSSubset of () means :Def24: :: OSAFREE:def 24
for s being Element of S holds it . s = PTVars (s,X);
existence
ex b1 being MSSubset of () st
for s being Element of S holds b1 . s = PTVars (s,X)
proof end;
uniqueness
for b1, b2 being MSSubset of () st ( for s being Element of S holds b1 . s = PTVars (s,X) ) & ( for s being Element of S holds b2 . s = PTVars (s,X) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def24 defines PTVars OSAFREE:def 24 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being MSSubset of () holds
( b3 = PTVars X iff for s being Element of S holds b3 . s = PTVars (s,X) );

theorem :: OSAFREE:29
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds PTVars X is V2()
proof end;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let s be Element of S;
func OSFreeGen (s,X) -> Subset of ( the Sorts of () . s) means :Def25: :: OSAFREE:def 25
for x being object holds
( x in it iff ex a being object st
( a in X . s & x = ((OSNat_Hom ((),())) . s) . (root-tree [a,s]) ) );
existence
ex b1 being Subset of ( the Sorts of () . s) st
for x being object holds
( x in b1 iff ex a being object st
( a in X . s & x = ((OSNat_Hom ((),())) . s) . (root-tree [a,s]) ) )
proof end;
uniqueness
for b1, b2 being Subset of ( the Sorts of () . s) st ( for x being object holds
( x in b1 iff ex a being object st
( a in X . s & x = ((OSNat_Hom ((),())) . s) . (root-tree [a,s]) ) ) ) & ( for x being object holds
( x in b2 iff ex a being object st
( a in X . s & x = ((OSNat_Hom ((),())) . s) . (root-tree [a,s]) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def25 defines OSFreeGen OSAFREE:def 25 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for b4 being Subset of ( the Sorts of () . s) holds
( b4 = OSFreeGen (s,X) iff for x being object holds
( x in b4 iff ex a being object st
( a in X . s & x = ((OSNat_Hom ((),())) . s) . (root-tree [a,s]) ) ) );

registration
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let s be Element of S;
cluster OSFreeGen (s,X) -> non empty ;
coherence
not OSFreeGen (s,X) is empty
proof end;
end;

theorem Th30: :: OSAFREE:30
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S holds OSFreeGen (s,X) = { (((OSNat_Hom ((),())) . s) . ()) where t is Symbol of () : ( t in Terminals () & t 2 = s ) }
proof end;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func OSFreeGen X -> OSGeneratorSet of FreeOSA X means :Def26: :: OSAFREE:def 26
for s being Element of S holds it . s = OSFreeGen (s,X);
existence
ex b1 being OSGeneratorSet of FreeOSA X st
for s being Element of S holds b1 . s = OSFreeGen (s,X)
proof end;
uniqueness
for b1, b2 being OSGeneratorSet of FreeOSA X st ( for s being Element of S holds b1 . s = OSFreeGen (s,X) ) & ( for s being Element of S holds b2 . s = OSFreeGen (s,X) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def26 defines OSFreeGen OSAFREE:def 26 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being OSGeneratorSet of FreeOSA X holds
( b3 = OSFreeGen X iff for s being Element of S holds b3 . s = OSFreeGen (s,X) );

theorem Th31: :: OSAFREE:31
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds OSFreeGen X is V2()
proof end;

registration
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
cluster OSFreeGen X -> V2() ;
coherence by Th31;
end;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let R be OSCongruence of ParsedTermsOSA X;
let t be Element of TS ();
func OSClass (R,t) -> Element of OSClass (R,()) means :Def27: :: OSAFREE:def 27
for s being Element of S
for x being Element of the Sorts of () . s st t = x holds
it = OSClass (R,x);
existence
ex b1 being Element of OSClass (R,()) st
for s being Element of S
for x being Element of the Sorts of () . s st t = x holds
b1 = OSClass (R,x)
proof end;
uniqueness
for b1, b2 being Element of OSClass (R,()) st ( for s being Element of S
for x being Element of the Sorts of () . s st t = x holds
b1 = OSClass (R,x) ) & ( for s being Element of S
for x being Element of the Sorts of () . s st t = x holds
b2 = OSClass (R,x) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def27 defines OSClass OSAFREE:def 27 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for R being OSCongruence of ParsedTermsOSA X
for t being Element of TS ()
for b5 being Element of OSClass (R,()) holds
( b5 = OSClass (R,t) iff for s being Element of S
for x being Element of the Sorts of () . s st t = x holds
b5 = OSClass (R,x) );

theorem Th32: :: OSAFREE:32
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for R being OSCongruence of ParsedTermsOSA X
for t being Element of TS () holds t in OSClass (R,t)
proof end;

theorem Th33: :: OSAFREE:33
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for t being Element of TS ()
for x, x1 being set st x in X . s & t = root-tree [x,s] holds
( x1 in OSClass ((),t) iff x1 = t )
proof end;

theorem Th34: :: OSAFREE:34
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for R being OSCongruence of ParsedTermsOSA X
for t1, t2 being Element of TS () holds
( t2 in OSClass (R,t1) iff OSClass (R,t1) = OSClass (R,t2) )
proof end;

theorem Th35: :: OSAFREE:35
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for R1, R2 being OSCongruence of ParsedTermsOSA X
for t being Element of TS () st R1 c= R2 holds
OSClass (R1,t) c= OSClass (R2,t)
proof end;

theorem Th36: :: OSAFREE:36
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for t being Element of TS ()
for x, x1 being set st x in X . s & t = root-tree [x,s] holds
( x1 in OSClass ((),t) iff x1 = t )
proof end;

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let A be V2() ManySortedSet of the carrier of S;
let F be ManySortedFunction of PTVars X,A;
let t be Symbol of ();
assume A1: t in Terminals () ;
func pi (F,A,t) -> Element of Union A means :Def28: :: OSAFREE:def 28
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 Def28 defines pi OSAFREE:def 28 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for A being V2() ManySortedSet of the carrier of S
for F being ManySortedFunction of PTVars 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 . () );

theorem Th37: :: OSAFREE:37
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for U1 being non-empty monotone OSAlgebra of S
for f being ManySortedFunction of PTVars X, the Sorts of U1 ex h being ManySortedFunction of (),U1 st
( h is_homomorphism ParsedTermsOSA X,U1 & h is order-sorted & h || () = f )
proof end;

:: NH stanbds for NatHom
definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
let s be Element of S;
func NHReverse (s,X) -> Function of (OSFreeGen (s,X)),(PTVars (s,X)) means :: OSAFREE:def 29
for t being Symbol of () st ((OSNat_Hom ((),())) . s) . () in OSFreeGen (s,X) holds
it . (((OSNat_Hom ((),())) . s) . ()) = root-tree t;
existence
ex b1 being Function of (OSFreeGen (s,X)),(PTVars (s,X)) st
for t being Symbol of () st ((OSNat_Hom ((),())) . s) . () in OSFreeGen (s,X) holds
b1 . (((OSNat_Hom ((),())) . s) . ()) = root-tree t
proof end;
uniqueness
for b1, b2 being Function of (OSFreeGen (s,X)),(PTVars (s,X)) st ( for t being Symbol of () st ((OSNat_Hom ((),())) . s) . () in OSFreeGen (s,X) holds
b1 . (((OSNat_Hom ((),())) . s) . ()) = root-tree t ) & ( for t being Symbol of () st ((OSNat_Hom ((),())) . s) . () in OSFreeGen (s,X) holds
b2 . (((OSNat_Hom ((),())) . s) . ()) = root-tree t ) holds
b1 = b2
proof end;
end;

:: deftheorem defines NHReverse OSAFREE:def 29 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for s being Element of S
for b4 being Function of (OSFreeGen (s,X)),(PTVars (s,X)) holds
( b4 = NHReverse (s,X) iff for t being Symbol of () st ((OSNat_Hom ((),())) . s) . () in OSFreeGen (s,X) holds
b4 . (((OSNat_Hom ((),())) . s) . ()) = root-tree t );

definition
let S be locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func NHReverse X -> ManySortedFunction of OSFreeGen X, PTVars X means :: OSAFREE:def 30
for s being Element of S holds it . s = NHReverse (s,X);
existence
ex b1 being ManySortedFunction of OSFreeGen X, PTVars X st
for s being Element of S holds b1 . s = NHReverse (s,X)
proof end;
uniqueness
for b1, b2 being ManySortedFunction of OSFreeGen X, PTVars X st ( for s being Element of S holds b1 . s = NHReverse (s,X) ) & ( for s being Element of S holds b2 . s = NHReverse (s,X) ) holds
b1 = b2
proof end;
end;

:: deftheorem defines NHReverse OSAFREE:def 30 :
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being ManySortedFunction of OSFreeGen X, PTVars X holds
( b3 = NHReverse X iff for s being Element of S holds b3 . s = NHReverse (s,X) );

theorem Th38: :: OSAFREE:38
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds OSFreeGen X is osfree
proof end;

theorem Th39: :: OSAFREE:39
for S being locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds FreeOSA X is osfree
proof end;

registration
let S be locally_directed OrderSortedSign;
existence
ex b1 being non-empty monotone OSAlgebra of S st
( b1 is osfree & b1 is strict )
proof end;
end;

:: PTMin ... minimality of PTCongruence on regular signatures
:: minimal terms
definition
let S be monotone regular locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func PTMin X -> Function of (TS ()),(TS ()) means :Def31: :: OSAFREE:def 31
( ( for t being Symbol of () st t in Terminals () holds
it . () = pi t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
it . (nt -tree ts) = pi ((@ (X,nt)),(it * ts)) ) );
existence
ex b1 being Function of (TS ()),(TS ()) st
( ( for t being Symbol of () st t in Terminals () holds
b1 . () = pi t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b1 . (nt -tree ts) = pi ((@ (X,nt)),(b1 * ts)) ) )
proof end;
uniqueness
for b1, b2 being Function of (TS ()),(TS ()) st ( for t being Symbol of () st t in Terminals () holds
b1 . () = pi t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b1 . (nt -tree ts) = pi ((@ (X,nt)),(b1 * ts)) ) & ( for t being Symbol of () st t in Terminals () holds
b2 . () = pi t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b2 . (nt -tree ts) = pi ((@ (X,nt)),(b2 * ts)) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def31 defines PTMin OSAFREE:def 31 :
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being Function of (TS ()),(TS ()) holds
( b3 = PTMin X iff ( ( for t being Symbol of () st t in Terminals () holds
b3 . () = pi t ) & ( for nt being Symbol of ()
for ts being FinSequence of TS () st nt ==> roots ts holds
b3 . (nt -tree ts) = pi ((@ (X,nt)),(b3 * ts)) ) ) );

theorem Th40: :: OSAFREE:40
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for t being Element of TS () holds
( () . t in OSClass ((),t) & LeastSort (() . t) <= LeastSort t & ( for s being Element of S
for x being set st x in X . s & t = root-tree [x,s] holds
() . t = t ) & ( for o being OperSymbol of S
for ts being FinSequence of TS () st OSSym (o,X) ==> roots ts & t = (OSSym (o,X)) -tree ts holds
( LeastSorts (() * ts) <= the_arity_of o & OSSym (o,X) ==> roots (() * ts) & OSSym ((LBound (o,(LeastSorts (() * ts)))),X) ==> roots (() * ts) & () . t = (OSSym ((LBound (o,(LeastSorts (() * ts)))),X)) -tree (() * ts) ) ) )
proof end;

theorem Th41: :: OSAFREE:41
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for t, t1 being Element of TS () st t1 in OSClass ((),t) holds
() . t1 = () . t
proof end;

theorem Th42: :: OSAFREE:42
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for t1, t2 being Element of TS () holds
( t2 in OSClass ((),t1) iff () . t2 = () . t1 )
proof end;

theorem Th43: :: OSAFREE:43
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for t1 being Element of TS () holds () . (() . t1) = () . t1
proof end;

theorem Th44: :: OSAFREE:44
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for R being MSEquivalence-like monotone OrderSortedRelation of ParsedTermsOSA X
for t being Element of TS () holds [t,(() . t)] in R . ()
proof end;

theorem Th45: :: OSAFREE:45
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for R being MSEquivalence-like monotone OrderSortedRelation of ParsedTermsOSA X holds PTCongruence X c= R
proof end;

:: minimality of PTCongruence
theorem :: OSAFREE:46
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds LCongruence X = PTCongruence X
proof end;

:: I would prefer attribute "minimal", but non-clusterable
definition
let S be monotone regular locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
mode MinTerm of S,X -> Element of TS () means :Def32: :: OSAFREE:def 32
() . it = it;
existence
ex b1 being Element of TS () st () . b1 = b1
proof end;
end;

:: deftheorem Def32 defines MinTerm OSAFREE:def 32 :
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for b3 being Element of TS () holds
( b3 is MinTerm of S,X iff () . b3 = b3 );

definition
let S be monotone regular locally_directed OrderSortedSign;
let X be V2() ManySortedSet of S;
func MinTerms X -> Subset of (TS ()) equals :: OSAFREE:def 33
rng ();
correctness
coherence
rng () is Subset of (TS ())
;
by RELAT_1:def 19;
end;

:: deftheorem defines MinTerms OSAFREE:def 33 :
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S holds MinTerms X = rng ();

theorem :: OSAFREE:47
for S being monotone regular locally_directed OrderSortedSign
for X being V2() ManySortedSet of S
for x being set holds
( x is MinTerm of S,X iff x in MinTerms X )
proof end;