:: BAGORDER semantic presentation

theorem Th1: :: BAGORDER:1
for b1, b2, b3 being set st b3 in b1 & b3 in b2 holds
( b1 \ {b3} = b2 \ {b3} iff b1 = b2 )
proof end;

theorem Th2: :: BAGORDER:2
for b1, b2 being Nat holds
( b2 in Seg b1 iff ( b2 - 1 is Nat & b2 - 1 < b1 ) )
proof end;

registration
let c1 be natural-yielding Function;
let c2 be set ;
cluster a1 | a2 -> natural-yielding ;
coherence
c1 | c2 is natural-yielding
proof end;
end;

registration
let c1 be finite-support Function;
let c2 be set ;
cluster a1 | a2 -> finite-support ;
coherence
c1 | c2 is finite-support
proof end;
end;

theorem Th3: :: BAGORDER:3
for b1 being Function
for b2 being set st b2 in dom b1 holds
b1 * <*b2*> = <*(b1 . b2)*>
proof end;

theorem Th4: :: BAGORDER:4
for b1, b2, b3 being Function st dom b1 = dom b2 & rng b1 c= dom b3 & rng b2 c= dom b3 & b1,b2 are_fiberwise_equipotent holds
b3 * b1,b3 * b2 are_fiberwise_equipotent
proof end;

theorem Th5: :: BAGORDER:5
for b1 being FinSequence of NAT holds
( Sum b1 = 0 iff b1 = (len b1) |-> 0 )
proof end;

definition
let c1, c2, c3 be Nat;
let c4 be ManySortedSet of c1;
func c2,c3 -cut c4 -> ManySortedSet of a3 -' a2 means :Def1: :: BAGORDER:def 1
for b1 being Nat st b1 in a3 -' a2 holds
a5 . b1 = a4 . (a2 + b1);
existence
ex b1 being ManySortedSet of c3 -' c2 st
for b2 being Nat st b2 in c3 -' c2 holds
b1 . b2 = c4 . (c2 + b2)
proof end;
uniqueness
for b1, b2 being ManySortedSet of c3 -' c2 st ( for b3 being Nat st b3 in c3 -' c2 holds
b1 . b3 = c4 . (c2 + b3) ) & ( for b3 being Nat st b3 in c3 -' c2 holds
b2 . b3 = c4 . (c2 + b3) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def1 defines -cut BAGORDER:def 1 :
for b1, b2, b3 being Nat
for b4 being ManySortedSet of b1
for b5 being ManySortedSet of b3 -' b2 holds
( b5 = b2,b3 -cut b4 iff for b6 being Nat st b6 in b3 -' b2 holds
b5 . b6 = b4 . (b2 + b6) );

registration
let c1, c2, c3 be Nat;
let c4 be natural-yielding ManySortedSet of c1;
cluster a2,a3 -cut a4 -> natural-yielding ;
coherence
c2,c3 -cut c4 is natural-yielding
proof end;
end;

registration
let c1, c2, c3 be Nat;
let c4 be finite-support ManySortedSet of c1;
cluster a2,a3 -cut a4 -> finite-support ;
coherence
c2,c3 -cut c4 is finite-support
;
end;

theorem Th6: :: BAGORDER:6
for b1, b2 being Nat
for b3, b4 being ManySortedSet of b1 holds
( b3 = b4 iff ( 0,(b2 + 1) -cut b3 = 0,(b2 + 1) -cut b4 & (b2 + 1),b1 -cut b3 = (b2 + 1),b1 -cut b4 ) )
proof end;

definition
let c1 be non empty set ;
let c2 be non empty Nat;
func Fin c1,c2 -> set equals :: BAGORDER:def 2
{ b1 where B is Subset of a1 : ( b1 is finite & not b1 is empty & Card b1 <=` a2 ) } ;
coherence
{ b1 where B is Subset of c1 : ( b1 is finite & not b1 is empty & Card b1 <=` c2 ) } is set
;
end;

:: deftheorem Def2 defines Fin BAGORDER:def 2 :
for b1 being non empty set
for b2 being non empty Nat holds Fin b1,b2 = { b3 where B is Subset of b1 : ( b3 is finite & not b3 is empty & Card b3 <=` b2 ) } ;

registration
let c1 be non empty set ;
let c2 be non empty Nat;
cluster Fin a1,a2 -> non empty ;
coherence
not Fin c1,c2 is empty
proof end;
end;

theorem Th7: :: BAGORDER:7
for b1 being non empty transitive antisymmetric RelStr
for b2 being finite Subset of b1 st b2 <> {} holds
ex b3 being Element of b1 st
( b3 in b2 & b3 is_maximal_wrt b2,the InternalRel of b1 )
proof end;

theorem Th8: :: BAGORDER:8
for b1 being non empty transitive antisymmetric RelStr
for b2 being finite Subset of b1 st b2 <> {} holds
ex b3 being Element of b1 st
( b3 in b2 & b3 is_minimal_wrt b2,the InternalRel of b1 )
proof end;

theorem Th9: :: BAGORDER:9
for b1 being non empty transitive antisymmetric RelStr
for b2 being sequence of b1 st b2 is descending holds
for b3, b4 being Nat st b4 < b3 holds
( b2 . b4 <> b2 . b3 & [(b2 . b3),(b2 . b4)] in the InternalRel of b1 )
proof end;

definition
let c1 be non empty RelStr ;
let c2 be sequence of c1;
attr a2 is non-increasing means :Def3: :: BAGORDER:def 3
for b1 being Nat holds [(a2 . (b1 + 1)),(a2 . b1)] in the InternalRel of a1;
end;

:: deftheorem Def3 defines non-increasing BAGORDER:def 3 :
for b1 being non empty RelStr
for b2 being sequence of b1 holds
( b2 is non-increasing iff for b3 being Nat holds [(b2 . (b3 + 1)),(b2 . b3)] in the InternalRel of b1 );

theorem Th10: :: BAGORDER:10
for b1 being non empty transitive RelStr
for b2 being sequence of b1 st b2 is non-increasing holds
for b3, b4 being Nat st b4 < b3 holds
[(b2 . b3),(b2 . b4)] in the InternalRel of b1
proof end;

theorem Th11: :: BAGORDER:11
for b1 being non empty transitive RelStr
for b2 being sequence of b1 st b1 is well_founded & b2 is non-increasing holds
ex b3 being Nat st
for b4 being Nat st b3 <= b4 holds
b2 . b3 = b2 . b4
proof end;

theorem Th12: :: BAGORDER:12
for b1 being set
for b2 being Element of b1
for b3 being finite Subset of b1
for b4 being Order of b1 st b3 = {b2} & b4 linearly_orders b3 holds
SgmX b4,b3 = <*b2*>
proof end;

definition
let c1 be Ordinal;
let c2 be bag of c1;
func TotDegree c2 -> Nat means :Def4: :: BAGORDER:def 4
ex b1 being FinSequence of NAT st
( a3 = Sum b1 & b1 = a2 * (SgmX (RelIncl a1),(support a2)) );
existence
ex b1 being Natex b2 being FinSequence of NAT st
( b1 = Sum b2 & b2 = c2 * (SgmX (RelIncl c1),(support c2)) )
proof end;
uniqueness
for b1, b2 being Nat st ex b3 being FinSequence of NAT st
( b1 = Sum b3 & b3 = c2 * (SgmX (RelIncl c1),(support c2)) ) & ex b3 being FinSequence of NAT st
( b2 = Sum b3 & b3 = c2 * (SgmX (RelIncl c1),(support c2)) ) holds
b1 = b2
;
end;

:: deftheorem Def4 defines TotDegree BAGORDER:def 4 :
for b1 being Ordinal
for b2 being bag of b1
for b3 being Nat holds
( b3 = TotDegree b2 iff ex b4 being FinSequence of NAT st
( b3 = Sum b4 & b4 = b2 * (SgmX (RelIncl b1),(support b2)) ) );

theorem Th13: :: BAGORDER:13
for b1 being Ordinal
for b2 being bag of b1
for b3 being finite Subset of b1
for b4, b5 being FinSequence of NAT st b4 = b2 * (SgmX (RelIncl b1),(support b2)) & b5 = b2 * (SgmX (RelIncl b1),((support b2) \/ b3)) holds
Sum b4 = Sum b5
proof end;

theorem Th14: :: BAGORDER:14
for b1 being Ordinal
for b2, b3 being bag of b1 holds TotDegree (b2 + b3) = (TotDegree b2) + (TotDegree b3)
proof end;

theorem Th15: :: BAGORDER:15
for b1 being Ordinal
for b2, b3 being bag of b1 st b3 divides b2 holds
TotDegree (b2 -' b3) = (TotDegree b2) - (TotDegree b3)
proof end;

theorem Th16: :: BAGORDER:16
for b1 being Ordinal
for b2 being bag of b1 holds
( TotDegree b2 = 0 iff b2 = EmptyBag b1 )
proof end;

theorem Th17: :: BAGORDER:17
for b1, b2, b3 being Nat holds b1,b2 -cut (EmptyBag b3) = EmptyBag (b2 -' b1)
proof end;

theorem Th18: :: BAGORDER:18
for b1, b2, b3 being Nat
for b4, b5 being bag of b3 holds b1,b2 -cut (b4 + b5) = (b1,b2 -cut b4) + (b1,b2 -cut b5)
proof end;

theorem Th19: :: BAGORDER:19
for b1 being set holds support (EmptyBag b1) = {}
proof end;

theorem Th20: :: BAGORDER:20
for b1 being set
for b2 being bag of b1 st support b2 = {} holds
b2 = EmptyBag b1
proof end;

theorem Th21: :: BAGORDER:21
for b1, b2 being Ordinal
for b3 being bag of b1 st b2 in b1 holds
b3 | b2 is bag of b2
proof end;

theorem Th22: :: BAGORDER:22
for b1 being Ordinal
for b2, b3 being bag of b1 st b3 divides b2 holds
support b3 c= support b2
proof end;

definition
let c1 be set ;
mode TermOrder of a1 is Order of Bags a1;
end;

notation
let c1 be Ordinal;
synonym LexOrder c1 for BagOrder c1;
end;

definition
let c1 be Ordinal;
let c2 be TermOrder of c1;
canceled;
canceled;
attr a2 is admissible means :Def7: :: BAGORDER:def 7
( a2 is_strongly_connected_in Bags a1 & ( for b1 being bag of a1 holds [(EmptyBag a1),b1] in a2 ) & ( for b1, b2, b3 being bag of a1 st [b1,b2] in a2 holds
[(b1 + b3),(b2 + b3)] in a2 ) );
end;

:: deftheorem Def5 BAGORDER:def 5 :
canceled;

:: deftheorem Def6 BAGORDER:def 6 :
canceled;

:: deftheorem Def7 defines admissible BAGORDER:def 7 :
for b1 being Ordinal
for b2 being TermOrder of b1 holds
( b2 is admissible iff ( b2 is_strongly_connected_in Bags b1 & ( for b3 being bag of b1 holds [(EmptyBag b1),b3] in b2 ) & ( for b3, b4, b5 being bag of b1 st [b3,b4] in b2 holds
[(b3 + b5),(b4 + b5)] in b2 ) ) );

theorem Th23: :: BAGORDER:23
for b1 being Ordinal holds LexOrder b1 is admissible
proof end;

registration
let c1 be Ordinal;
cluster admissible Relation of Bags a1, Bags a1;
existence
ex b1 being TermOrder of c1 st b1 is admissible
proof end;
end;

registration
let c1 be Ordinal;
cluster LexOrder a1 -> admissible ;
coherence
LexOrder c1 is admissible
by Th23;
end;

theorem Th24: :: BAGORDER:24
for b1 being infinite Ordinal holds not LexOrder b1 is well-ordering
proof end;

definition
let c1 be Ordinal;
func InvLexOrder c1 -> TermOrder of a1 means :Def8: :: BAGORDER:def 8
for b1, b2 being bag of a1 holds
( [b1,b2] in a2 iff ( b1 = b2 or ex b3 being Ordinal st
( b3 in a1 & b1 . b3 < b2 . b3 & ( for b4 being Ordinal st b3 in b4 & b4 in a1 holds
b1 . b4 = b2 . b4 ) ) ) );
existence
ex b1 being TermOrder of c1 st
for b2, b3 being bag of c1 holds
( [b2,b3] in b1 iff ( b2 = b3 or ex b4 being Ordinal st
( b4 in c1 & b2 . b4 < b3 . b4 & ( for b5 being Ordinal st b4 in b5 & b5 in c1 holds
b2 . b5 = b3 . b5 ) ) ) )
proof end;
uniqueness
for b1, b2 being TermOrder of c1 st ( for b3, b4 being bag of c1 holds
( [b3,b4] in b1 iff ( b3 = b4 or ex b5 being Ordinal st
( b5 in c1 & b3 . b5 < b4 . b5 & ( for b6 being Ordinal st b5 in b6 & b6 in c1 holds
b3 . b6 = b4 . b6 ) ) ) ) ) & ( for b3, b4 being bag of c1 holds
( [b3,b4] in b2 iff ( b3 = b4 or ex b5 being Ordinal st
( b5 in c1 & b3 . b5 < b4 . b5 & ( for b6 being Ordinal st b5 in b6 & b6 in c1 holds
b3 . b6 = b4 . b6 ) ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def8 defines InvLexOrder BAGORDER:def 8 :
for b1 being Ordinal
for b2 being TermOrder of b1 holds
( b2 = InvLexOrder b1 iff for b3, b4 being bag of b1 holds
( [b3,b4] in b2 iff ( b3 = b4 or ex b5 being Ordinal st
( b5 in b1 & b3 . b5 < b4 . b5 & ( for b6 being Ordinal st b5 in b6 & b6 in b1 holds
b3 . b6 = b4 . b6 ) ) ) ) );

theorem Th25: :: BAGORDER:25
for b1 being Ordinal holds InvLexOrder b1 is admissible
proof end;

registration
let c1 be Ordinal;
cluster InvLexOrder a1 -> admissible ;
coherence
InvLexOrder c1 is admissible
by Th25;
end;

theorem Th26: :: BAGORDER:26
for b1 being Ordinal holds InvLexOrder b1 is well-ordering
proof end;

definition
let c1 be Ordinal;
let c2 be TermOrder of c1;
assume E26: for b1, b2, b3 being bag of c1 st [b1,b2] in c2 holds
[(b1 + b3),(b2 + b3)] in c2 ;
func Graded c2 -> TermOrder of a1 means :Def9: :: BAGORDER:def 9
for b1, b2 being bag of a1 holds
( [b1,b2] in a3 iff ( TotDegree b1 < TotDegree b2 or ( TotDegree b1 = TotDegree b2 & [b1,b2] in a2 ) ) );
existence
ex b1 being TermOrder of c1 st
for b2, b3 being bag of c1 holds
( [b2,b3] in b1 iff ( TotDegree b2 < TotDegree b3 or ( TotDegree b2 = TotDegree b3 & [b2,b3] in c2 ) ) )
proof end;
uniqueness
for b1, b2 being TermOrder of c1 st ( for b3, b4 being bag of c1 holds
( [b3,b4] in b1 iff ( TotDegree b3 < TotDegree b4 or ( TotDegree b3 = TotDegree b4 & [b3,b4] in c2 ) ) ) ) & ( for b3, b4 being bag of c1 holds
( [b3,b4] in b2 iff ( TotDegree b3 < TotDegree b4 or ( TotDegree b3 = TotDegree b4 & [b3,b4] in c2 ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def9 defines Graded BAGORDER:def 9 :
for b1 being Ordinal
for b2 being TermOrder of b1 st ( for b3, b4, b5 being bag of b1 st [b3,b4] in b2 holds
[(b3 + b5),(b4 + b5)] in b2 ) holds
for b3 being TermOrder of b1 holds
( b3 = Graded b2 iff for b4, b5 being bag of b1 holds
( [b4,b5] in b3 iff ( TotDegree b4 < TotDegree b5 or ( TotDegree b4 = TotDegree b5 & [b4,b5] in b2 ) ) ) );

theorem Th27: :: BAGORDER:27
for b1 being Ordinal
for b2 being TermOrder of b1 st ( for b3, b4, b5 being bag of b1 st [b3,b4] in b2 holds
[(b3 + b5),(b4 + b5)] in b2 ) & b2 is_strongly_connected_in Bags b1 holds
Graded b2 is admissible
proof end;

definition
let c1 be Ordinal;
func GrLexOrder c1 -> TermOrder of a1 equals :: BAGORDER:def 10
Graded (LexOrder a1);
coherence
Graded (LexOrder c1) is TermOrder of c1
;
func GrInvLexOrder c1 -> TermOrder of a1 equals :: BAGORDER:def 11
Graded (InvLexOrder a1);
coherence
Graded (InvLexOrder c1) is TermOrder of c1
;
end;

:: deftheorem Def10 defines GrLexOrder BAGORDER:def 10 :
for b1 being Ordinal holds GrLexOrder b1 = Graded (LexOrder b1);

:: deftheorem Def11 defines GrInvLexOrder BAGORDER:def 11 :
for b1 being Ordinal holds GrInvLexOrder b1 = Graded (InvLexOrder b1);

theorem Th28: :: BAGORDER:28
for b1 being Ordinal holds GrLexOrder b1 is admissible
proof end;

registration
let c1 be Ordinal;
cluster GrLexOrder a1 -> admissible ;
coherence
GrLexOrder c1 is admissible
by Th28;
end;

theorem Th29: :: BAGORDER:29
for b1 being infinite Ordinal holds not GrLexOrder b1 is well-ordering
proof end;

theorem Th30: :: BAGORDER:30
for b1 being Ordinal holds GrInvLexOrder b1 is admissible
proof end;

registration
let c1 be Ordinal;
cluster GrInvLexOrder a1 -> admissible ;
coherence
GrInvLexOrder c1 is admissible
by Th30;
end;

theorem Th31: :: BAGORDER:31
for b1 being Ordinal holds GrInvLexOrder b1 is well-ordering
proof end;

definition
let c1, c2 be Nat;
let c3 be TermOrder of (c1 + 1);
let c4 be TermOrder of (c2 -' (c1 + 1));
func BlockOrder c1,c2,c3,c4 -> TermOrder of a2 means :Def12: :: BAGORDER:def 12
for b1, b2 being bag of a2 holds
( [b1,b2] in a5 iff ( ( 0,(a1 + 1) -cut b1 <> 0,(a1 + 1) -cut b2 & [(0,(a1 + 1) -cut b1),(0,(a1 + 1) -cut b2)] in a3 ) or ( 0,(a1 + 1) -cut b1 = 0,(a1 + 1) -cut b2 & [((a1 + 1),a2 -cut b1),((a1 + 1),a2 -cut b2)] in a4 ) ) );
existence
ex b1 being TermOrder of c2 st
for b2, b3 being bag of c2 holds
( [b2,b3] in b1 iff ( ( 0,(c1 + 1) -cut b2 <> 0,(c1 + 1) -cut b3 & [(0,(c1 + 1) -cut b2),(0,(c1 + 1) -cut b3)] in c3 ) or ( 0,(c1 + 1) -cut b2 = 0,(c1 + 1) -cut b3 & [((c1 + 1),c2 -cut b2),((c1 + 1),c2 -cut b3)] in c4 ) ) )
proof end;
uniqueness
for b1, b2 being TermOrder of c2 st ( for b3, b4 being bag of c2 holds
( [b3,b4] in b1 iff ( ( 0,(c1 + 1) -cut b3 <> 0,(c1 + 1) -cut b4 & [(0,(c1 + 1) -cut b3),(0,(c1 + 1) -cut b4)] in c3 ) or ( 0,(c1 + 1) -cut b3 = 0,(c1 + 1) -cut b4 & [((c1 + 1),c2 -cut b3),((c1 + 1),c2 -cut b4)] in c4 ) ) ) ) & ( for b3, b4 being bag of c2 holds
( [b3,b4] in b2 iff ( ( 0,(c1 + 1) -cut b3 <> 0,(c1 + 1) -cut b4 & [(0,(c1 + 1) -cut b3),(0,(c1 + 1) -cut b4)] in c3 ) or ( 0,(c1 + 1) -cut b3 = 0,(c1 + 1) -cut b4 & [((c1 + 1),c2 -cut b3),((c1 + 1),c2 -cut b4)] in c4 ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def12 defines BlockOrder BAGORDER:def 12 :
for b1, b2 being Nat
for b3 being TermOrder of (b1 + 1)
for b4 being TermOrder of (b2 -' (b1 + 1))
for b5 being TermOrder of b2 holds
( b5 = BlockOrder b1,b2,b3,b4 iff for b6, b7 being bag of b2 holds
( [b6,b7] in b5 iff ( ( 0,(b1 + 1) -cut b6 <> 0,(b1 + 1) -cut b7 & [(0,(b1 + 1) -cut b6),(0,(b1 + 1) -cut b7)] in b3 ) or ( 0,(b1 + 1) -cut b6 = 0,(b1 + 1) -cut b7 & [((b1 + 1),b2 -cut b6),((b1 + 1),b2 -cut b7)] in b4 ) ) ) );

theorem Th32: :: BAGORDER:32
for b1, b2 being Nat
for b3 being TermOrder of (b1 + 1)
for b4 being TermOrder of (b2 -' (b1 + 1)) st b3 is admissible & b4 is admissible holds
BlockOrder b1,b2,b3,b4 is admissible
proof end;

definition
let c1 be Nat;
func NaivelyOrderedBags c1 -> strict RelStr means :Def13: :: BAGORDER:def 13
( the carrier of a2 = Bags a1 & ( for b1, b2 being bag of a1 holds
( [b1,b2] in the InternalRel of a2 iff b1 divides b2 ) ) );
existence
ex b1 being strict RelStr st
( the carrier of b1 = Bags c1 & ( for b2, b3 being bag of c1 holds
( [b2,b3] in the InternalRel of b1 iff b2 divides b3 ) ) )
proof end;
uniqueness
for b1, b2 being strict RelStr st the carrier of b1 = Bags c1 & ( for b3, b4 being bag of c1 holds
( [b3,b4] in the InternalRel of b1 iff b3 divides b4 ) ) & the carrier of b2 = Bags c1 & ( for b3, b4 being bag of c1 holds
( [b3,b4] in the InternalRel of b2 iff b3 divides b4 ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def13 defines NaivelyOrderedBags BAGORDER:def 13 :
for b1 being Nat
for b2 being strict RelStr holds
( b2 = NaivelyOrderedBags b1 iff ( the carrier of b2 = Bags b1 & ( for b3, b4 being bag of b1 holds
( [b3,b4] in the InternalRel of b2 iff b3 divides b4 ) ) ) );

theorem Th33: :: BAGORDER:33
for b1 being Nat holds the carrier of (product (b1 --> OrderedNAT )) = Bags b1
proof end;

theorem Th34: :: BAGORDER:34
for b1 being Nat holds NaivelyOrderedBags b1 = product (b1 --> OrderedNAT )
proof end;

theorem Th35: :: BAGORDER:35
for b1 being Nat
for b2 being TermOrder of b1 st b2 is admissible holds
( the InternalRel of (NaivelyOrderedBags b1) c= b2 & b2 is well-ordering )
proof end;

definition
let c1 be non empty connected Poset;
let c2 be Element of Fin the carrier of c1;
assume E34: not c2 is empty ;
func PosetMin c2 -> Element of a1 means :: BAGORDER:def 14
( a3 in a2 & a3 is_minimal_wrt a2,the InternalRel of a1 );
existence
ex b1 being Element of c1 st
( b1 in c2 & b1 is_minimal_wrt c2,the InternalRel of c1 )
proof end;
uniqueness
for b1, b2 being Element of c1 st b1 in c2 & b1 is_minimal_wrt c2,the InternalRel of c1 & b2 in c2 & b2 is_minimal_wrt c2,the InternalRel of c1 holds
b1 = b2
proof end;
func PosetMax c2 -> Element of a1 means :Def15: :: BAGORDER:def 15
( a3 in a2 & a3 is_maximal_wrt a2,the InternalRel of a1 );
existence
ex b1 being Element of c1 st
( b1 in c2 & b1 is_maximal_wrt c2,the InternalRel of c1 )
proof end;
uniqueness
for b1, b2 being Element of c1 st b1 in c2 & b1 is_maximal_wrt c2,the InternalRel of c1 & b2 in c2 & b2 is_maximal_wrt c2,the InternalRel of c1 holds
b1 = b2
proof end;
end;

:: deftheorem Def14 defines PosetMin BAGORDER:def 14 :
for b1 being non empty connected Poset
for b2 being Element of Fin the carrier of b1 st not b2 is empty holds
for b3 being Element of b1 holds
( b3 = PosetMin b2 iff ( b3 in b2 & b3 is_minimal_wrt b2,the InternalRel of b1 ) );

:: deftheorem Def15 defines PosetMax BAGORDER:def 15 :
for b1 being non empty connected Poset
for b2 being Element of Fin the carrier of b1 st not b2 is empty holds
for b3 being Element of b1 holds
( b3 = PosetMax b2 iff ( b3 in b2 & b3 is_maximal_wrt b2,the InternalRel of b1 ) );

definition
let c1 be non empty connected Poset;
func FinOrd-Approx c1 -> Function of NAT , bool [:(Fin the carrier of a1),(Fin the carrier of a1):] means :Def16: :: BAGORDER:def 16
( dom a2 = NAT & a2 . 0 = { [b1,b2] where B is Element of Fin the carrier of a1, B is Element of Fin the carrier of a1 : ( b1 = {} or ( b1 <> {} & b2 <> {} & PosetMax b1 <> PosetMax b2 & [(PosetMax b1),(PosetMax b2)] in the InternalRel of a1 ) ) } & ( for b1 being Element of NAT holds a2 . (b1 + 1) = { [b2,b3] where B is Element of Fin the carrier of a1, B is Element of Fin the carrier of a1 : ( b2 <> {} & b3 <> {} & PosetMax b2 = PosetMax b3 & [(b2 \ {(PosetMax b2)}),(b3 \ {(PosetMax b3)})] in a2 . b1 ) } ) );
existence
ex b1 being Function of NAT , bool [:(Fin the carrier of c1),(Fin the carrier of c1):] st
( dom b1 = NAT & b1 . 0 = { [b2,b3] where B is Element of Fin the carrier of c1, B is Element of Fin the carrier of c1 : ( b2 = {} or ( b2 <> {} & b3 <> {} & PosetMax b2 <> PosetMax b3 & [(PosetMax b2),(PosetMax b3)] in the InternalRel of c1 ) ) } & ( for b2 being Element of NAT holds b1 . (b2 + 1) = { [b3,b4] where B is Element of Fin the carrier of c1, B is Element of Fin the carrier of c1 : ( b3 <> {} & b4 <> {} & PosetMax b3 = PosetMax b4 & [(b3 \ {(PosetMax b3)}),(b4 \ {(PosetMax b4)})] in b1 . b2 ) } ) )
proof end;
uniqueness
for b1, b2 being Function of NAT , bool [:(Fin the carrier of c1),(Fin the carrier of c1):] st dom b1 = NAT & b1 . 0 = { [b3,b4] where B is Element of Fin the carrier of c1, B is Element of Fin the carrier of c1 : ( b3 = {} or ( b3 <> {} & b4 <> {} & PosetMax b3 <> PosetMax b4 & [(PosetMax b3),(PosetMax b4)] in the InternalRel of c1 ) ) } & ( for b3 being Element of NAT holds b1 . (b3 + 1) = { [b4,b5] where B is Element of Fin the carrier of c1, B is Element of Fin the carrier of c1 : ( b4 <> {} & b5 <> {} & PosetMax b4 = PosetMax b5 & [(b4 \ {(PosetMax b4)}),(b5 \ {(PosetMax b5)})] in b1 . b3 ) } ) & dom b2 = NAT & b2 . 0 = { [b3,b4] where B is Element of Fin the carrier of c1, B is Element of Fin the carrier of c1 : ( b3 = {} or ( b3 <> {} & b4 <> {} & PosetMax b3 <> PosetMax b4 & [(PosetMax b3),(PosetMax b4)] in the InternalRel of c1 ) ) } & ( for b3 being Element of NAT holds b2 . (b3 + 1) = { [b4,b5] where B is Element of Fin the carrier of c1, B is Element of Fin the carrier of c1 : ( b4 <> {} & b5 <> {} & PosetMax b4 = PosetMax b5 & [(b4 \ {(PosetMax b4)}),(b5 \ {(PosetMax b5)})] in b2 . b3 ) } ) holds
b1 = b2
proof end;
end;

:: deftheorem Def16 defines FinOrd-Approx BAGORDER:def 16 :
for b1 being non empty connected Poset
for b2 being Function of NAT , bool [:(Fin the carrier of b1),(Fin the carrier of b1):] holds
( b2 = FinOrd-Approx b1 iff ( dom b2 = NAT & b2 . 0 = { [b3,b4] where B is Element of Fin the carrier of b1, B is Element of Fin the carrier of b1 : ( b3 = {} or ( b3 <> {} & b4 <> {} & PosetMax b3 <> PosetMax b4 & [(PosetMax b3),(PosetMax b4)] in the InternalRel of b1 ) ) } & ( for b3 being Element of NAT holds b2 . (b3 + 1) = { [b4,b5] where B is Element of Fin the carrier of b1, B is Element of Fin the carrier of b1 : ( b4 <> {} & b5 <> {} & PosetMax b4 = PosetMax b5 & [(b4 \ {(PosetMax b4)}),(b5 \ {(PosetMax b5)})] in b2 . b3 ) } ) ) );

theorem Th36: :: BAGORDER:36
for b1 being non empty connected Poset
for b2, b3 being Element of Fin the carrier of b1 holds
( [b2,b3] in union (rng (FinOrd-Approx b1)) iff ( b2 = {} or ( b2 <> {} & b3 <> {} & PosetMax b2 <> PosetMax b3 & [(PosetMax b2),(PosetMax b3)] in the InternalRel of b1 ) or ( b2 <> {} & b3 <> {} & PosetMax b2 = PosetMax b3 & [(b2 \ {(PosetMax b2)}),(b3 \ {(PosetMax b3)})] in union (rng (FinOrd-Approx b1)) ) ) )
proof end;

theorem Th37: :: BAGORDER:37
for b1 being non empty connected Poset
for b2 being Element of Fin the carrier of b1 st b2 <> {} holds
not [b2,{} ] in union (rng (FinOrd-Approx b1))
proof end;

theorem Th38: :: BAGORDER:38
for b1 being non empty connected Poset
for b2 being Element of Fin the carrier of b1 holds b2 \ {(PosetMax b2)} is Element of Fin the carrier of b1
proof end;

Lemma39: for b1 being non empty connected Poset
for b2 being Nat
for b3 being Element of Fin the carrier of b1 st Card b3 = b2 + 1 holds
Card (b3 \ {(PosetMax b3)}) = b2
proof end;

theorem Th39: :: BAGORDER:39
for b1 being non empty connected Poset holds union (rng (FinOrd-Approx b1)) is Order of Fin the carrier of b1
proof end;

definition
let c1 be non empty connected Poset;
func FinOrd c1 -> Order of Fin the carrier of a1 equals :: BAGORDER:def 17
union (rng (FinOrd-Approx a1));
coherence
union (rng (FinOrd-Approx c1)) is Order of Fin the carrier of c1
by Th39;
end;

:: deftheorem Def17 defines FinOrd BAGORDER:def 17 :
for b1 being non empty connected Poset holds FinOrd b1 = union (rng (FinOrd-Approx b1));

definition
let c1 be non empty connected Poset;
func FinPoset c1 -> Poset equals :: BAGORDER:def 18
RelStr(# (Fin the carrier of a1),(FinOrd a1) #);
correctness
coherence
RelStr(# (Fin the carrier of c1),(FinOrd c1) #) is Poset
;
;
end;

:: deftheorem Def18 defines FinPoset BAGORDER:def 18 :
for b1 being non empty connected Poset holds FinPoset b1 = RelStr(# (Fin the carrier of b1),(FinOrd b1) #);

registration
let c1 be non empty connected Poset;
cluster FinPoset a1 -> non empty ;
correctness
coherence
not FinPoset c1 is empty
;
;
end;

theorem Th40: :: BAGORDER:40
for b1 being non empty connected Poset
for b2, b3 being Element of (FinPoset b1) holds
( [b2,b3] in the InternalRel of (FinPoset b1) iff ex b4, b5 being Element of Fin the carrier of b1 st
( b2 = b4 & b3 = b5 & ( b4 = {} or ( b4 <> {} & b5 <> {} & PosetMax b4 <> PosetMax b5 & [(PosetMax b4),(PosetMax b5)] in the InternalRel of b1 ) or ( b4 <> {} & b5 <> {} & PosetMax b4 = PosetMax b5 & [(b4 \ {(PosetMax b4)}),(b5 \ {(PosetMax b5)})] in FinOrd b1 ) ) ) )
proof end;

registration
let c1 be non empty connected Poset;
cluster FinPoset a1 -> non empty connected ;
correctness
coherence
FinPoset c1 is connected
;
proof end;
end;

definition
let c1 be non empty connected RelStr ;
let c2 be non empty set ;
assume that
E42: c1 is well_founded and
E43: c2 c= the carrier of c1 ;
func MinElement c2,c1 -> Element of a1 means :Def19: :: BAGORDER:def 19
( a3 in a2 & a3 is_minimal_wrt a2,the InternalRel of a1 );
existence
ex b1 being Element of c1 st
( b1 in c2 & b1 is_minimal_wrt c2,the InternalRel of c1 )
proof end;
uniqueness
for b1, b2 being Element of c1 st b1 in c2 & b1 is_minimal_wrt c2,the InternalRel of c1 & b2 in c2 & b2 is_minimal_wrt c2,the InternalRel of c1 holds
b1 = b2
proof end;
end;

:: deftheorem Def19 defines MinElement BAGORDER:def 19 :
for b1 being non empty connected RelStr
for b2 being non empty set st b1 is well_founded & b2 c= the carrier of b1 holds
for b3 being Element of b1 holds
( b3 = MinElement b2,b1 iff ( b3 in b2 & b3 is_minimal_wrt b2,the InternalRel of b1 ) );

definition
let c1 be non empty RelStr ;
let c2 be sequence of c1;
let c3 be Nat;
func SeqShift c2,c3 -> sequence of a1 means :Def20: :: BAGORDER:def 20
for b1 being Nat holds a4 . b1 = a2 . (b1 + a3);
existence
ex b1 being sequence of c1 st
for b2 being Nat holds b1 . b2 = c2 . (b2 + c3)
proof end;
uniqueness
for b1, b2 being sequence of c1 st ( for b3 being Nat holds b1 . b3 = c2 . (b3 + c3) ) & ( for b3 being Nat holds b2 . b3 = c2 . (b3 + c3) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def20 defines SeqShift BAGORDER:def 20 :
for b1 being non empty RelStr
for b2 being sequence of b1
for b3 being Nat
for b4 being sequence of b1 holds
( b4 = SeqShift b2,b3 iff for b5 being Nat holds b4 . b5 = b2 . (b5 + b3) );

theorem Th41: :: BAGORDER:41
for b1 being non empty RelStr
for b2 being sequence of b1
for b3 being Nat st b2 is descending holds
SeqShift b2,b3 is descending
proof end;

theorem Th42: :: BAGORDER:42
for b1 being non empty connected Poset st b1 is well_founded holds
FinPoset b1 is well_founded
proof end;