:: Partially Ordered Sets
:: by Wojciech A. Trybulec
::
:: Copyright (c) 1990-2021 Association of Mizar Users

Lm1: for Y being set holds
( ex X being set st
( X <> {} & X in Y ) iff union Y <> {} )

proof end;

::
:: Choice function.
::
definition
let f be Function;
mode Choice of f -> Function means :Def1: :: ORDERS_1:def 1
( dom it = dom f & ( for x being object st x in dom f holds
it . x = the Element of f . x ) );
existence
ex b1 being Function st
( dom b1 = dom f & ( for x being object st x in dom f holds
b1 . x = the Element of f . x ) )
proof end;
end;

:: deftheorem Def1 defines Choice ORDERS_1:def 1 :
for f, b2 being Function holds
( b2 is Choice of f iff ( dom b2 = dom f & ( for x being object st x in dom f holds
b2 . x = the Element of f . x ) ) );

definition
let I be set ;
let M be ManySortedSet of I;
:: original: Choice
redefine mode Choice of M -> ManySortedSet of I means :Def2: :: ORDERS_1:def 2
for x being object st x in I holds
it . x = the Element of M . x;
coherence
for b1 being Choice of M holds b1 is ManySortedSet of I
proof end;
compatibility
for b1 being ManySortedSet of I holds
( b1 is Choice of M iff for x being object st x in I holds
b1 . x = the Element of M . x )
proof end;
end;

:: deftheorem Def2 defines Choice ORDERS_1:def 2 :
for I being set
for M, b3 being ManySortedSet of I holds
( b3 is Choice of M iff for x being object st x in I holds
b3 . x = the Element of M . x );

definition
let A be set ;
mode Choice_Function of A is Choice of id A;
end;

Lm2: for M being non empty set st not {} in M holds
for Ch being Choice_Function of M
for X being set st X in M holds
Ch . X in X

proof end;

Lm3: for M being non empty set st not {} in M holds
for Ch being Choice_Function of M holds Ch is Function of M,()

proof end;

definition
let D be set ;
func BOOL D -> set equals :: ORDERS_1:def 3
(bool D) \ ;
coherence
(bool D) \ is set
;
end;

:: deftheorem defines BOOL ORDERS_1:def 3 :
for D being set holds BOOL D = (bool D) \ ;

registration
let D be non empty set ;
cluster BOOL D -> non empty ;
coherence
not BOOL D is empty
proof end;
end;

theorem :: ORDERS_1:1
for D being non empty set holds not {} in BOOL D
proof end;

theorem :: ORDERS_1:2
for X being set
for D being non empty set holds
( D c= X iff D in BOOL X )
proof end;

::
:: Orders.
::
definition end;

Lm4: for X being set
for R being total Relation of X holds field R = X

proof end;

theorem Th3: :: ORDERS_1:3
for X, x being set
for O being Order of X st x in X holds
[x,x] in O
proof end;

theorem :: ORDERS_1:4
for X, x, y being set
for O being Order of X st x in X & y in X & [x,y] in O & [y,x] in O holds
x = y
proof end;

theorem :: ORDERS_1:5
for X, x, y, z being set
for O being Order of X st x in X & y in X & z in X & [x,y] in O & [y,z] in O holds
[x,z] in O
proof end;

theorem :: ORDERS_1:6
for Y being set holds
( ex X being set st
( X <> {} & X in Y ) iff union Y <> {} ) by Lm1;

theorem :: ORDERS_1:7
for X being set
for P being Relation holds
( P is_strongly_connected_in X iff ( P is_reflexive_in X & P is_connected_in X ) )
proof end;

theorem :: ORDERS_1:8
for X, Y being set
for P being Relation st P is_reflexive_in X & Y c= X holds
P is_reflexive_in Y ;

theorem :: ORDERS_1:9
for X, Y being set
for P being Relation st P is_antisymmetric_in X & Y c= X holds
P is_antisymmetric_in Y ;

theorem :: ORDERS_1:10
for X, Y being set
for P being Relation st P is_transitive_in X & Y c= X holds
P is_transitive_in Y ;

theorem :: ORDERS_1:11
for X, Y being set
for P being Relation st P is_strongly_connected_in X & Y c= X holds
P is_strongly_connected_in Y ;

theorem :: ORDERS_1:12
for X being set
for R being total Relation of X holds field R = X by Lm4;

theorem Th13: :: ORDERS_1:13
for A being set
for R being Relation of A st R is_reflexive_in A holds
( dom R = A & field R = A )
proof end;

::
:: Orders.
::
theorem Th14: :: ORDERS_1:14
for X being set
for O being Order of X holds
( dom O = X & rng O = X )
proof end;

theorem :: ORDERS_1:15
for X being set
for O being Order of X holds field O = X
proof end;

definition
let R be Relation;
attr R is being_quasi-order means :: ORDERS_1:def 4
( R is reflexive & R is transitive );
attr R is being_partial-order means :: ORDERS_1:def 5
( R is reflexive & R is transitive & R is antisymmetric );
attr R is being_linear-order means :: ORDERS_1:def 6
( R is reflexive & R is transitive & R is antisymmetric & R is connected );
end;

:: deftheorem defines being_quasi-order ORDERS_1:def 4 :
for R being Relation holds
( R is being_quasi-order iff ( R is reflexive & R is transitive ) );

:: deftheorem defines being_partial-order ORDERS_1:def 5 :
for R being Relation holds
( R is being_partial-order iff ( R is reflexive & R is transitive & R is antisymmetric ) );

:: deftheorem defines being_linear-order ORDERS_1:def 6 :
for R being Relation holds
( R is being_linear-order iff ( R is reflexive & R is transitive & R is antisymmetric & R is connected ) );

theorem :: ORDERS_1:16
for R being Relation st R is being_quasi-order holds
R ~ is being_quasi-order ;

theorem :: ORDERS_1:17
for R being Relation st R is being_partial-order holds
R ~ is being_partial-order ;

Lm5: for R being Relation st R is connected holds
R ~ is connected

proof end;

theorem Th18: :: ORDERS_1:18
for R being Relation st R is being_linear-order holds
R ~ is being_linear-order by Lm5;

theorem :: ORDERS_1:19
for R being Relation st R is well-ordering holds
( R is being_quasi-order & R is being_partial-order & R is being_linear-order ) ;

theorem :: ORDERS_1:20
for R being Relation st R is being_linear-order holds
( R is being_quasi-order & R is being_partial-order ) ;

theorem :: ORDERS_1:21
for R being Relation st R is being_partial-order holds
R is being_quasi-order ;

theorem :: ORDERS_1:22
for X being set
for O being Order of X holds O is being_partial-order ;

theorem :: ORDERS_1:23
for X being set
for O being Order of X holds O is being_quasi-order ;

theorem :: ORDERS_1:24
for X being set
for O being Order of X st O is connected holds
O is being_linear-order ;

Lm6: for R being Relation holds R c= [:(),():]
proof end;

Lm7: for R being Relation
for X being set st R is reflexive & X c= field R holds
field (R |_2 X) = X

proof end;

theorem :: ORDERS_1:25
for R being Relation
for X being set st R is being_quasi-order holds
R |_2 X is being_quasi-order by ;

theorem :: ORDERS_1:26
for R being Relation
for X being set st R is being_partial-order holds
R |_2 X is being_partial-order by ;

theorem :: ORDERS_1:27
for R being Relation
for X being set st R is being_linear-order holds
R |_2 X is being_linear-order by ;

registration
let R be empty Relation;
coherence
field R is empty
;
end;

registration
coherence
for b1 being Relation st b1 is empty holds
( b1 is being_quasi-order & b1 is being_partial-order & b1 is being_linear-order & b1 is well-ordering )
proof end;
end;

registration
let X be set ;
coherence ;
end;

definition
let R be Relation;
let X be set ;
end;

:: deftheorem defines quasi_orders ORDERS_1:def 7 :
for R being Relation
for X being set holds
( R quasi_orders X iff ( R is_reflexive_in X & R is_transitive_in X ) );

:: deftheorem defines partially_orders ORDERS_1:def 8 :
for R being Relation
for X being set holds
( R partially_orders X iff ( R is_reflexive_in X & R is_transitive_in X & R is_antisymmetric_in X ) );

:: deftheorem defines linearly_orders ORDERS_1:def 9 :
for R being Relation
for X being set holds
( R linearly_orders X iff ( R is_reflexive_in X & R is_transitive_in X & R is_antisymmetric_in X & R is_connected_in X ) );

theorem Th28: :: ORDERS_1:28
for R being Relation
for X being set st R well_orders X holds
( R quasi_orders X & R partially_orders X & R linearly_orders X ) ;

theorem Th29: :: ORDERS_1:29
for R being Relation
for X being set st R linearly_orders X holds
( R quasi_orders X & R partially_orders X ) ;

theorem :: ORDERS_1:30
for R being Relation
for X being set st R partially_orders X holds
R quasi_orders X ;

theorem Th31: :: ORDERS_1:31
for R being Relation st R is being_quasi-order holds
R quasi_orders field R
proof end;

theorem :: ORDERS_1:32
for R being Relation
for X, Y being set st R quasi_orders Y & X c= Y holds
R quasi_orders X
proof end;

Lm8: for R being Relation
for X being set st R is_reflexive_in X holds
R |_2 X is reflexive

proof end;

Lm9: for R being Relation
for X being set st R is_transitive_in X holds
R |_2 X is transitive

proof end;

Lm10: for R being Relation
for X being set st R is_antisymmetric_in X holds
R |_2 X is antisymmetric

proof end;

Lm11: for R being Relation
for X being set st R is_connected_in X holds
R |_2 X is connected

proof end;

theorem :: ORDERS_1:33
for R being Relation
for X being set st R quasi_orders X holds
R |_2 X is being_quasi-order by ;

theorem Th34: :: ORDERS_1:34
for R being Relation st R is being_partial-order holds
R partially_orders field R
proof end;

theorem :: ORDERS_1:35
for R being Relation
for X, Y being set st R partially_orders Y & X c= Y holds
R partially_orders X
proof end;

theorem :: ORDERS_1:36
for R being Relation
for X being set st R partially_orders X holds
R |_2 X is being_partial-order by ;

theorem :: ORDERS_1:37
for R being Relation st R is being_linear-order holds
R linearly_orders field R
proof end;

theorem :: ORDERS_1:38
for R being Relation
for X, Y being set st R linearly_orders Y & X c= Y holds
R linearly_orders X
proof end;

theorem :: ORDERS_1:39
for R being Relation
for X being set st R linearly_orders X holds
R |_2 X is being_linear-order by ;

Lm12: for R being Relation
for X being set st R is_reflexive_in X holds
R ~ is_reflexive_in X

proof end;

Lm13: for R being Relation
for X being set st R is_transitive_in X holds
R ~ is_transitive_in X

proof end;

Lm14: for R being Relation
for X being set st R is_antisymmetric_in X holds
R ~ is_antisymmetric_in X

proof end;

Lm15: for R being Relation
for X being set st R is_connected_in X holds
R ~ is_connected_in X

proof end;

theorem :: ORDERS_1:40
for R being Relation
for X being set st R quasi_orders X holds
R ~ quasi_orders X by ;

theorem Th41: :: ORDERS_1:41
for R being Relation
for X being set st R partially_orders X holds
R ~ partially_orders X by ;

theorem :: ORDERS_1:42
for R being Relation
for X being set st R linearly_orders X holds
R ~ linearly_orders X by ;

theorem :: ORDERS_1:43
for X being set
for O being Order of X holds O quasi_orders X
proof end;

theorem :: ORDERS_1:44
for X being set
for O being Order of X holds O partially_orders X
proof end;

theorem Th45: :: ORDERS_1:45
for R being Relation
for X being set st R partially_orders X holds
R |_2 X is Order of X
proof end;

theorem :: ORDERS_1:46
for R being Relation
for X being set st R linearly_orders X holds
R |_2 X is Order of X by ;

theorem :: ORDERS_1:47
for R being Relation
for X being set st R well_orders X holds
R |_2 X is Order of X by ;

theorem :: ORDERS_1:48
for X being set holds
( id X quasi_orders X & id X partially_orders X )
proof end;

definition
let R be Relation;
let X be set ;
pred X has_upper_Zorn_property_wrt R means :: ORDERS_1:def 10
for Y being set st Y c= X & R |_2 Y is being_linear-order holds
ex x being set st
( x in X & ( for y being set st y in Y holds
[y,x] in R ) );
pred X has_lower_Zorn_property_wrt R means :: ORDERS_1:def 11
for Y being set st Y c= X & R |_2 Y is being_linear-order holds
ex x being set st
( x in X & ( for y being set st y in Y holds
[x,y] in R ) );
end;

:: deftheorem defines has_upper_Zorn_property_wrt ORDERS_1:def 10 :
for R being Relation
for X being set holds
( X has_upper_Zorn_property_wrt R iff for Y being set st Y c= X & R |_2 Y is being_linear-order holds
ex x being set st
( x in X & ( for y being set st y in Y holds
[y,x] in R ) ) );

:: deftheorem defines has_lower_Zorn_property_wrt ORDERS_1:def 11 :
for R being Relation
for X being set holds
( X has_lower_Zorn_property_wrt R iff for Y being set st Y c= X & R |_2 Y is being_linear-order holds
ex x being set st
( x in X & ( for y being set st y in Y holds
[x,y] in R ) ) );

Lm16: for R being Relation
for X being set holds (R |_2 X) ~ = (R ~) |_2 X

proof end;

Lm17: now :: thesis: for R being Relation holds R |_2 {} = {}
let R be Relation; :: thesis:
thus R |_2 {} = ({} |` R) | {} by WELLORD1:10
.= {} ; :: thesis: verum
end;

theorem Th49: :: ORDERS_1:49
for R being Relation
for X being set st X has_upper_Zorn_property_wrt R holds
X <> {}
proof end;

theorem :: ORDERS_1:50
for R being Relation
for X being set st X has_lower_Zorn_property_wrt R holds
X <> {}
proof end;

theorem Th51: :: ORDERS_1:51
for R being Relation
for X being set holds
( X has_upper_Zorn_property_wrt R iff X has_lower_Zorn_property_wrt R ~ )
proof end;

theorem :: ORDERS_1:52
for R being Relation
for X being set holds
( X has_upper_Zorn_property_wrt R ~ iff X has_lower_Zorn_property_wrt R )
proof end;

definition
let R be Relation;
let x be set ;
pred x is_maximal_in R means :: ORDERS_1:def 12
( x in field R & ( for y being set holds
( not y in field R or not y <> x or not [x,y] in R ) ) );
pred x is_minimal_in R means :: ORDERS_1:def 13
( x in field R & ( for y being set holds
( not y in field R or not y <> x or not [y,x] in R ) ) );
pred x is_superior_of R means :: ORDERS_1:def 14
( x in field R & ( for y being set st y in field R & y <> x holds
[y,x] in R ) );
pred x is_inferior_of R means :: ORDERS_1:def 15
( x in field R & ( for y being set st y in field R & y <> x holds
[x,y] in R ) );
end;

:: deftheorem defines is_maximal_in ORDERS_1:def 12 :
for R being Relation
for x being set holds
( x is_maximal_in R iff ( x in field R & ( for y being set holds
( not y in field R or not y <> x or not [x,y] in R ) ) ) );

:: deftheorem defines is_minimal_in ORDERS_1:def 13 :
for R being Relation
for x being set holds
( x is_minimal_in R iff ( x in field R & ( for y being set holds
( not y in field R or not y <> x or not [y,x] in R ) ) ) );

:: deftheorem defines is_superior_of ORDERS_1:def 14 :
for R being Relation
for x being set holds
( x is_superior_of R iff ( x in field R & ( for y being set st y in field R & y <> x holds
[y,x] in R ) ) );

:: deftheorem defines is_inferior_of ORDERS_1:def 15 :
for R being Relation
for x being set holds
( x is_inferior_of R iff ( x in field R & ( for y being set st y in field R & y <> x holds
[x,y] in R ) ) );

theorem :: ORDERS_1:53
for R being Relation
for x being set st x is_inferior_of R & R is antisymmetric holds
x is_minimal_in R
proof end;

theorem :: ORDERS_1:54
for R being Relation
for x being set st x is_superior_of R & R is antisymmetric holds
x is_maximal_in R
proof end;

theorem :: ORDERS_1:55
for R being Relation
for x being set st x is_minimal_in R & R is connected holds
x is_inferior_of R
proof end;

theorem :: ORDERS_1:56
for R being Relation
for x being set st x is_maximal_in R & R is connected holds
x is_superior_of R
proof end;

theorem :: ORDERS_1:57
for R being Relation
for X, x being set st x in X & x is_superior_of R & X c= field R & R is reflexive holds
X has_upper_Zorn_property_wrt R
proof end;

theorem :: ORDERS_1:58
for R being Relation
for X, x being set st x in X & x is_inferior_of R & X c= field R & R is reflexive holds
X has_lower_Zorn_property_wrt R
proof end;

theorem Th59: :: ORDERS_1:59
for R being Relation
for x being set holds
( x is_minimal_in R iff x is_maximal_in R ~ )
proof end;

theorem :: ORDERS_1:60
for R being Relation
for x being set holds
( x is_minimal_in R ~ iff x is_maximal_in R )
proof end;

theorem :: ORDERS_1:61
for R being Relation
for x being set holds
( x is_inferior_of R iff x is_superior_of R ~ )
proof end;

theorem :: ORDERS_1:62
for R being Relation
for x being set holds
( x is_inferior_of R ~ iff x is_superior_of R )
proof end;

Lm18: for R being Relation
for X, Y being set st R well_orders X & Y c= X holds
R well_orders Y

proof end;

theorem Th63: :: ORDERS_1:63
for R being Relation
for X being set st R partially_orders X & field R = X & X has_upper_Zorn_property_wrt R holds
ex x being set st x is_maximal_in R
proof end;

theorem Th64: :: ORDERS_1:64
for R being Relation
for X being set st R partially_orders X & field R = X & X has_lower_Zorn_property_wrt R holds
ex x being set st x is_minimal_in R
proof end;

:: Kuratowski-Zorn Lemma
:: Zorn Lemma
theorem Th65: :: ORDERS_1:65
for X being set st X <> {} & ( for Z being set st Z c= X & Z is c=-linear holds
ex Y being set st
( Y in X & ( for X1 being set st X1 in Z holds
X1 c= Y ) ) ) holds
ex Y being set st
( Y in X & ( for Z being set st Z in X & Z <> Y holds
not Y c= Z ) )
proof end;

theorem Th66: :: ORDERS_1:66
for X being set st X <> {} & ( for Z being set st Z c= X & Z is c=-linear holds
ex Y being set st
( Y in X & ( for X1 being set st X1 in Z holds
Y c= X1 ) ) ) holds
ex Y being set st
( Y in X & ( for Z being set st Z in X & Z <> Y holds
not Z c= Y ) )
proof end;

theorem Th67: :: ORDERS_1:67
for X being set st X <> {} & ( for Z being set st Z <> {} & Z c= X & Z is c=-linear holds
union Z in X ) holds
ex Y being set st
( Y in X & ( for Z being set st Z in X & Z <> Y holds
not Y c= Z ) )
proof end;

theorem :: ORDERS_1:68
for X being set st X <> {} & ( for Z being set st Z <> {} & Z c= X & Z is c=-linear holds
meet Z in X ) holds
ex Y being set st
( Y in X & ( for Z being set st Z in X & Z <> Y holds
not Z c= Y ) )
proof end;

scheme :: ORDERS_1:sch 1
ZornMax{ F1() -> non empty set , P1[ set , set ] } :
ex x being Element of F1() st
for y being Element of F1() st x <> y holds
not P1[x,y]
provided
A1: for x being Element of F1() holds P1[x,x] and
A2: for x, y being Element of F1() st P1[x,y] & P1[y,x] holds
x = y and
A3: for x, y, z being Element of F1() st P1[x,y] & P1[y,z] holds
P1[x,z] and
A4: for X being set st X c= F1() & ( for x, y being Element of F1() st x in X & y in X & P1[x,y] holds
P1[y,x] ) holds
ex y being Element of F1() st
for x being Element of F1() st x in X holds
P1[x,y]
proof end;

scheme :: ORDERS_1:sch 2
ZornMin{ F1() -> non empty set , P1[ set , set ] } :
ex x being Element of F1() st
for y being Element of F1() st x <> y holds
not P1[y,x]
provided
A1: for x being Element of F1() holds P1[x,x] and
A2: for x, y being Element of F1() st P1[x,y] & P1[y,x] holds
x = y and
A3: for x, y, z being Element of F1() st P1[x,y] & P1[y,z] holds
P1[x,z] and
A4: for X being set st X c= F1() & ( for x, y being Element of F1() st x in X & y in X & P1[x,y] holds
P1[y,x] ) holds
ex y being Element of F1() st
for x being Element of F1() st x in X holds
P1[y,x]
proof end;

::
:: Orders - continuation.
::
theorem :: ORDERS_1:69
for R being Relation
for X being set st R partially_orders X & field R = X holds
ex P being Relation st
( R c= P & P linearly_orders X & field P = X )
proof end;

::
:: Auxiliary theorems.
::
theorem :: ORDERS_1:70
for R being Relation holds R c= [:(),():] by Lm6;

theorem :: ORDERS_1:71
for R being Relation
for X being set st R is reflexive & X c= field R holds
field (R |_2 X) = X by Lm7;

theorem :: ORDERS_1:72
for R being Relation
for X being set st R is_reflexive_in X holds
R |_2 X is reflexive by Lm8;

theorem :: ORDERS_1:73
for R being Relation
for X being set st R is_transitive_in X holds
R |_2 X is transitive by Lm9;

theorem :: ORDERS_1:74
for R being Relation
for X being set st R is_antisymmetric_in X holds
R |_2 X is antisymmetric by Lm10;

theorem :: ORDERS_1:75
for R being Relation
for X being set st R is_connected_in X holds
R |_2 X is connected by Lm11;

theorem :: ORDERS_1:76
for R being Relation
for X, Y being set st R is_connected_in X & Y c= X holds
R is_connected_in Y ;

theorem :: ORDERS_1:77
for R being Relation
for X, Y being set st R well_orders X & Y c= X holds
R well_orders Y by Lm18;

theorem :: ORDERS_1:78
for R being Relation st R is connected holds
R ~ is connected by Lm5;

theorem :: ORDERS_1:79
for R being Relation
for X being set st R is_reflexive_in X holds
R ~ is_reflexive_in X by Lm12;

theorem :: ORDERS_1:80
for R being Relation
for X being set st R is_transitive_in X holds
R ~ is_transitive_in X by Lm13;

theorem :: ORDERS_1:81
for R being Relation
for X being set st R is_antisymmetric_in X holds
R ~ is_antisymmetric_in X by Lm14;

theorem :: ORDERS_1:82
for R being Relation
for X being set st R is_connected_in X holds
R ~ is_connected_in X by Lm15;

theorem :: ORDERS_1:83
for R being Relation
for X being set holds (R |_2 X) ~ = (R ~) |_2 X by Lm16;

theorem :: ORDERS_1:84
for R being Relation holds R |_2 {} = {} by Lm17;

:: from COMPTS_1
theorem :: ORDERS_1:85
for f being Function
for Z being set st Z is finite & Z c= rng f holds
ex Y being set st
( Y c= dom f & Y is finite & f .: Y = Z )
proof end;

:: from AMISTD_3, 2006.03.26, A.T.
theorem Th86: :: ORDERS_1:86
for R being Relation st field R is finite holds
R is finite
proof end;

theorem :: ORDERS_1:87
for R being Relation st dom R is finite & rng R is finite holds
R is finite
proof end;

:: from AMISTD_3, 2010.01.10, A.T
registration
coherence
proof end;
end;

theorem :: ORDERS_1:88
for O being Ordinal holds order_type_of () = O
proof end;

definition
let X be set ;
:: original: RelIncl
redefine func RelIncl X -> Order of X;
coherence
RelIncl X is Order of X
proof end;
end;

theorem :: ORDERS_1:89
for M being non empty set st not {} in M holds
for Ch being Choice_Function of M
for X being set st X in M holds
Ch . X in X by Lm2;

theorem :: ORDERS_1:90
for M being non empty set st not {} in M holds
for Ch being Choice_Function of M holds Ch is Function of M,() by Lm3;