:: GLIB_004 semantic presentation

theorem Th1: :: GLIB_004:1
for f, g being Function holds support (f +* g) c= (support f) \/ (support g)
proof end;

theorem Th2: :: GLIB_004:2
for f being Function
for x, y being set holds support (f +* (x .--> y)) c= (support f) \/ {x}
proof end;

theorem Th3: :: GLIB_004:3
for A, B being set
for b being Rbag of A
for b1 being Rbag of B
for b2 being Rbag of A \ B st b = b1 +* b2 holds
Sum b = (Sum b1) + (Sum b2)
proof end;

theorem Th4: :: GLIB_004:4
for X, x being set
for b being Rbag of X st dom b = {x} holds
Sum b = b . x
proof end;

theorem Th5: :: GLIB_004:5
for A being set
for b1, b2 being Rbag of A st ( for x being set st x in A holds
b1 . x <= b2 . x ) holds
Sum b1 <= Sum b2
proof end;

theorem :: GLIB_004:6
for A being set
for b1, b2 being Rbag of A st ( for x being set st x in A holds
b1 . x = b2 . x ) holds
Sum b1 = Sum b2
proof end;

theorem :: GLIB_004:7
for A1, A2 being set
for b1 being Rbag of A1
for b2 being Rbag of A2 st b1 = b2 holds
Sum b1 = Sum b2
proof end;

theorem Th8: :: GLIB_004:8
for X, x being set
for b being Rbag of X
for y being real number st b = (EmptyBag X) +* (x .--> y) holds
Sum b = y
proof end;

theorem :: GLIB_004:9
for X, x being set
for b1, b2 being Rbag of X
for y being real number st b2 = b1 +* (x .--> y) holds
Sum b2 = ((Sum b1) + y) - (b1 . x)
proof end;

definition
let G1 be real-weighted WGraph;
let G2 be WSubgraph of G1;
let v be set ;
pred G2 is_mincost_DTree_rooted_at v means :Def1: :: GLIB_004:def 1
( G2 is Tree-like & ( for x being Vertex of G2 ex W2 being DPath of G2 st
( W2 is_Walk_from v,x & ( for W1 being DPath of G1 st W1 is_Walk_from v,x holds
W2 .cost() <= W1 .cost() ) ) ) );
end;

:: deftheorem Def1 defines is_mincost_DTree_rooted_at GLIB_004:def 1 :
for G1 being real-weighted WGraph
for G2 being WSubgraph of G1
for v being set holds
( G2 is_mincost_DTree_rooted_at v iff ( G2 is Tree-like & ( for x being Vertex of G2 ex W2 being DPath of G2 st
( W2 is_Walk_from v,x & ( for W1 being DPath of G1 st W1 is_Walk_from v,x holds
W2 .cost() <= W1 .cost() ) ) ) ) );

definition
let G be real-weighted WGraph;
let W be DPath of G;
let x, y be set ;
pred W is_mincost_DPath_from x,y means :Def2: :: GLIB_004:def 2
( W is_Walk_from x,y & ( for W2 being DPath of G st W2 is_Walk_from x,y holds
W .cost() <= W2 .cost() ) );
end;

:: deftheorem Def2 defines is_mincost_DPath_from GLIB_004:def 2 :
for G being real-weighted WGraph
for W being DPath of G
for x, y being set holds
( W is_mincost_DPath_from x,y iff ( W is_Walk_from x,y & ( for W2 being DPath of G st W2 is_Walk_from x,y holds
W .cost() <= W2 .cost() ) ) );

definition
let G be finite real-weighted WGraph;
let x, y be set ;
func G .min_DPath_cost x,y -> Real means :Def3: :: GLIB_004:def 3
ex W being DPath of G st
( W is_mincost_DPath_from x,y & it = W .cost() ) if ex W being DWalk of G st W is_Walk_from x,y
otherwise it = 0 ;
existence
( ( ex W being DWalk of G st W is_Walk_from x,y implies ex b1 being Real ex W being DPath of G st
( W is_mincost_DPath_from x,y & b1 = W .cost() ) ) & ( ( for W being DWalk of G holds not W is_Walk_from x,y ) implies ex b1 being Real st b1 = 0 ) )
proof end;
uniqueness
for b1, b2 being Real holds
( ( ex W being DWalk of G st W is_Walk_from x,y & ex W being DPath of G st
( W is_mincost_DPath_from x,y & b1 = W .cost() ) & ex W being DPath of G st
( W is_mincost_DPath_from x,y & b2 = W .cost() ) implies b1 = b2 ) & ( ( for W being DWalk of G holds not W is_Walk_from x,y ) & b1 = 0 & b2 = 0 implies b1 = b2 ) )
proof end;
consistency
for b1 being Real holds verum
;
end;

:: deftheorem Def3 defines .min_DPath_cost GLIB_004:def 3 :
for G being finite real-weighted WGraph
for x, y being set
for b4 being Real holds
( ( ex W being DWalk of G st W is_Walk_from x,y implies ( b4 = G .min_DPath_cost x,y iff ex W being DPath of G st
( W is_mincost_DPath_from x,y & b4 = W .cost() ) ) ) & ( ( for W being DWalk of G holds not W is_Walk_from x,y ) implies ( b4 = G .min_DPath_cost x,y iff b4 = 0 ) ) );

definition
let G be real-WEV WEVGraph;
func DIJK:NextBestEdges G -> Subset of (the_Edges_of G) means :Def4: :: GLIB_004:def 4
for e1 being set holds
( e1 in it iff ( e1 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
((the_VLabel_of G) . ((the_Source_of G) . e1)) + ((the_Weight_of G) . e1) <= ((the_VLabel_of G) . ((the_Source_of G) . e2)) + ((the_Weight_of G) . e2) ) ) );
existence
ex b1 being Subset of (the_Edges_of G) st
for e1 being set holds
( e1 in b1 iff ( e1 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
((the_VLabel_of G) . ((the_Source_of G) . e1)) + ((the_Weight_of G) . e1) <= ((the_VLabel_of G) . ((the_Source_of G) . e2)) + ((the_Weight_of G) . e2) ) ) )
proof end;
uniqueness
for b1, b2 being Subset of (the_Edges_of G) st ( for e1 being set holds
( e1 in b1 iff ( e1 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
((the_VLabel_of G) . ((the_Source_of G) . e1)) + ((the_Weight_of G) . e1) <= ((the_VLabel_of G) . ((the_Source_of G) . e2)) + ((the_Weight_of G) . e2) ) ) ) ) & ( for e1 being set holds
( e1 in b2 iff ( e1 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
((the_VLabel_of G) . ((the_Source_of G) . e1)) + ((the_Weight_of G) . e1) <= ((the_VLabel_of G) . ((the_Source_of G) . e2)) + ((the_Weight_of G) . e2) ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def4 defines DIJK:NextBestEdges GLIB_004:def 4 :
for G being real-WEV WEVGraph
for b2 being Subset of (the_Edges_of G) holds
( b2 = DIJK:NextBestEdges G iff for e1 being set holds
( e1 in b2 iff ( e1 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 DSJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
((the_VLabel_of G) . ((the_Source_of G) . e1)) + ((the_Weight_of G) . e1) <= ((the_VLabel_of G) . ((the_Source_of G) . e2)) + ((the_Weight_of G) . e2) ) ) ) );

definition
let G be real-WEV WEVGraph;
func DIJK:Step G -> real-WEV WEVGraph equals :Def5: :: GLIB_004:def 5
G if DIJK:NextBestEdges G = {}
otherwise (G .labelEdge (choose (DIJK:NextBestEdges G)),1) .labelVertex ((the_Target_of G) . (choose (DIJK:NextBestEdges G))),(((the_VLabel_of G) . ((the_Source_of G) . (choose (DIJK:NextBestEdges G)))) + ((the_Weight_of G) . (choose (DIJK:NextBestEdges G))));
coherence
( ( DIJK:NextBestEdges G = {} implies G is real-WEV WEVGraph ) & ( not DIJK:NextBestEdges G = {} implies (G .labelEdge (choose (DIJK:NextBestEdges G)),1) .labelVertex ((the_Target_of G) . (choose (DIJK:NextBestEdges G))),(((the_VLabel_of G) . ((the_Source_of G) . (choose (DIJK:NextBestEdges G)))) + ((the_Weight_of G) . (choose (DIJK:NextBestEdges G)))) is real-WEV WEVGraph ) )
;
consistency
for b1 being real-WEV WEVGraph holds verum
;
end;

:: deftheorem Def5 defines DIJK:Step GLIB_004:def 5 :
for G being real-WEV WEVGraph holds
( ( DIJK:NextBestEdges G = {} implies DIJK:Step G = G ) & ( not DIJK:NextBestEdges G = {} implies DIJK:Step G = (G .labelEdge (choose (DIJK:NextBestEdges G)),1) .labelVertex ((the_Target_of G) . (choose (DIJK:NextBestEdges G))),(((the_VLabel_of G) . ((the_Source_of G) . (choose (DIJK:NextBestEdges G)))) + ((the_Weight_of G) . (choose (DIJK:NextBestEdges G)))) ) );

registration
let G be finite real-WEV WEVGraph;
cluster DIJK:Step G -> finite real-WEV ;
coherence
DIJK:Step G is finite
proof end;
end;

registration
let G be nonnegative-weighted real-WEV WEVGraph;
cluster DIJK:Step G -> nonnegative-weighted real-WEV ;
coherence
DIJK:Step G is nonnegative-weighted
proof end;
end;

definition
let G be real-weighted WGraph;
let src be Vertex of G;
func DIJK:Init G,src -> real-WEV WEVGraph equals :: GLIB_004:def 6
(G .set ELabelSelector ,{} ) .set VLabelSelector ,(src .--> 0 );
coherence
(G .set ELabelSelector ,{} ) .set VLabelSelector ,(src .--> 0 ) is real-WEV WEVGraph
proof end;
end;

:: deftheorem defines DIJK:Init GLIB_004:def 6 :
for G being real-weighted WGraph
for src being Vertex of G holds DIJK:Init G,src = (G .set ELabelSelector ,{} ) .set VLabelSelector ,(src .--> 0 );

definition
let s be WEVGraphSeq;
let n be Nat;
:: original: .
redefine func s . n -> WEVGraph;
coherence
s . n is WEVGraph
proof end;
end;

registration
let s be real-WEV WEVGraphSeq;
let n be Nat;
cluster s . n -> real-WEV WEVGraph;
coherence
s . n is real-WEV WEVGraph
by GLIB_003:def 31;
end;

definition
let G be real-weighted WGraph;
let src be Vertex of G;
func DIJK:CompSeq G,src -> real-WEV WEVGraphSeq means :Def7: :: GLIB_004:def 7
( it . 0 = DIJK:Init G,src & ( for n being Element of NAT holds it . (n + 1) = DIJK:Step (it . n) ) );
existence
ex b1 being real-WEV WEVGraphSeq st
( b1 . 0 = DIJK:Init G,src & ( for n being Element of NAT holds b1 . (n + 1) = DIJK:Step (b1 . n) ) )
proof end;
uniqueness
for b1, b2 being real-WEV WEVGraphSeq st b1 . 0 = DIJK:Init G,src & ( for n being Element of NAT holds b1 . (n + 1) = DIJK:Step (b1 . n) ) & b2 . 0 = DIJK:Init G,src & ( for n being Element of NAT holds b2 . (n + 1) = DIJK:Step (b2 . n) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def7 defines DIJK:CompSeq GLIB_004:def 7 :
for G being real-weighted WGraph
for src being Vertex of G
for b3 being real-WEV WEVGraphSeq holds
( b3 = DIJK:CompSeq G,src iff ( b3 . 0 = DIJK:Init G,src & ( for n being Element of NAT holds b3 . (n + 1) = DIJK:Step (b3 . n) ) ) );

registration
let G be finite real-weighted WGraph;
let src be Vertex of G;
cluster DIJK:CompSeq G,src -> finite real-WEV ;
coherence
DIJK:CompSeq G,src is finite
proof end;
end;

registration
let G be nonnegative-weighted WGraph;
let src be Vertex of G;
cluster DIJK:CompSeq G,src -> nonnegative-weighted real-WEV ;
coherence
DIJK:CompSeq G,src is nonnegative-weighted
proof end;
end;

definition
let G be real-weighted WGraph;
let src be Vertex of G;
func DIJK:SSSP G,src -> real-WEV WEVGraph equals :: GLIB_004:def 8
(DIJK:CompSeq G,src) .Result() ;
coherence
(DIJK:CompSeq G,src) .Result() is real-WEV WEVGraph
proof end;
end;

:: deftheorem defines DIJK:SSSP GLIB_004:def 8 :
for G being real-weighted WGraph
for src being Vertex of G holds DIJK:SSSP G,src = (DIJK:CompSeq G,src) .Result() ;

registration
let G be finite real-weighted WGraph;
let src be Vertex of G;
cluster DIJK:SSSP G,src -> finite real-WEV ;
coherence
DIJK:SSSP G,src is finite
proof end;
end;

theorem Th10: :: GLIB_004:10
for G being finite nonnegative-weighted WGraph
for W being DPath of G
for x, y being set
for m, n being Element of NAT st W is_mincost_DPath_from x,y holds
W .cut m,n is_mincost_DPath_from (W .cut m,n) .first() ,(W .cut m,n) .last()
proof end;

theorem Th11: :: GLIB_004:11
for G being finite real-weighted WGraph
for W1, W2 being DPath of G
for x, y being set st W1 is_mincost_DPath_from x,y & W2 is_mincost_DPath_from x,y holds
W1 .cost() = W2 .cost()
proof end;

theorem Th12: :: GLIB_004:12
for G being finite real-weighted WGraph
for W being DPath of G
for x, y being set st W is_mincost_DPath_from x,y holds
G .min_DPath_cost x,y = W .cost()
proof end;

theorem Th13: :: GLIB_004:13
for G being finite real-WEV WEVGraph holds
( ( card ((DIJK:Step G) .labeledV() ) = card (G .labeledV() ) implies DIJK:NextBestEdges G = {} ) & ( DIJK:NextBestEdges G = {} implies card ((DIJK:Step G) .labeledV() ) = card (G .labeledV() ) ) & ( card ((DIJK:Step G) .labeledV() ) = (card (G .labeledV() )) + 1 implies DIJK:NextBestEdges G <> {} ) & ( DIJK:NextBestEdges G <> {} implies card ((DIJK:Step G) .labeledV() ) = (card (G .labeledV() )) + 1 ) )
proof end;

theorem Th14: :: GLIB_004:14
for G being real-WEV WEVGraph holds
( G == DIJK:Step G & the_Weight_of G = the_Weight_of (DIJK:Step G) & G .labeledE() c= (DIJK:Step G) .labeledE() & G .labeledV() c= (DIJK:Step G) .labeledV() )
proof end;

theorem Th15: :: GLIB_004:15
for G being real-weighted WGraph
for src being Vertex of G holds (DIJK:Init G,src) .labeledV() = {src}
proof end;

theorem Th16: :: GLIB_004:16
for G being real-weighted WGraph
for src being Vertex of G
for i, j being Element of NAT st i <= j holds
( ((DIJK:CompSeq G,src) . i) .labeledV() c= ((DIJK:CompSeq G,src) . j) .labeledV() & ((DIJK:CompSeq G,src) . i) .labeledE() c= ((DIJK:CompSeq G,src) . j) .labeledE() )
proof end;

theorem Th17: :: GLIB_004:17
for G being real-weighted WGraph
for src being Vertex of G
for n being Element of NAT holds
( G == (DIJK:CompSeq G,src) . n & the_Weight_of G = the_Weight_of ((DIJK:CompSeq G,src) . n) )
proof end;

theorem Th18: :: GLIB_004:18
for G being finite real-weighted WGraph
for src being Vertex of G
for n being Element of NAT holds ((DIJK:CompSeq G,src) . n) .labeledV() c= G .reachableDFrom src
proof end;

registration
let s be finite WEVGraphSeq;
let n be Nat;
cluster s . n -> finite WEVGraph;
coherence
s . n is finite WEVGraph
by GLIB_000:def 60;
end;

theorem Th19: :: GLIB_004:19
for G being finite real-weighted WGraph
for src being Vertex of G
for n being Element of NAT holds
( DIJK:NextBestEdges ((DIJK:CompSeq G,src) . n) = {} iff ((DIJK:CompSeq G,src) . n) .labeledV() = G .reachableDFrom src )
proof end;

theorem Th20: :: GLIB_004:20
for G being finite real-weighted WGraph
for src being Vertex of G
for n being Element of NAT holds Card (((DIJK:CompSeq G,src) . n) .labeledV() ) = min (n + 1),(card (G .reachableDFrom src))
proof end;

theorem Th21: :: GLIB_004:21
for G being finite real-weighted WGraph
for src being Vertex of G
for n being Element of NAT holds ((DIJK:CompSeq G,src) . n) .labeledE() c= ((DIJK:CompSeq G,src) . n) .edgesBetween (((DIJK:CompSeq G,src) . n) .labeledV() )
proof end;

theorem Th22: :: GLIB_004:22
for G being finite nonnegative-weighted WGraph
for src being Vertex of G
for n being Element of NAT
for G2 being inducedWSubgraph of G,((DIJK:CompSeq G,src) . n) .labeledV() ,((DIJK:CompSeq G,src) . n) .labeledE() holds
( G2 is_mincost_DTree_rooted_at src & ( for v being Vertex of G st v in ((DIJK:CompSeq G,src) . n) .labeledV() holds
G .min_DPath_cost src,v = (the_VLabel_of ((DIJK:CompSeq G,src) . n)) . v ) )
proof end;

theorem Th23: :: GLIB_004:23
for G being finite real-weighted WGraph
for src being Vertex of G holds DIJK:CompSeq G,src is halting
proof end;

registration
let G be finite real-weighted WGraph;
let src be Vertex of G;
cluster DIJK:CompSeq G,src -> halting real-WEV ;
coherence
DIJK:CompSeq G,src is halting
by Th23;
end;

theorem Th24: :: GLIB_004:24
for G being finite real-weighted WGraph
for src being Vertex of G holds ((DIJK:CompSeq G,src) .Lifespan() ) + 1 = card (G .reachableDFrom src)
proof end;

theorem Th25: :: GLIB_004:25
for G being finite real-weighted WGraph
for src being Vertex of G holds (DIJK:SSSP G,src) .labeledV() = G .reachableDFrom src
proof end;

theorem :: GLIB_004:26
for G being finite nonnegative-weighted WGraph
for src being Vertex of G
for G2 being inducedWSubgraph of G,(DIJK:SSSP G,src) .labeledV() ,(DIJK:SSSP G,src) .labeledE() holds
( G2 is_mincost_DTree_rooted_at src & ( for v being Vertex of G st v in G .reachableDFrom src holds
( v in the_Vertices_of G2 & G .min_DPath_cost src,v = (the_VLabel_of (DIJK:SSSP G,src)) . v ) ) )
proof end;

definition
func WGraphSelectors -> non empty finite Subset of NAT equals :: GLIB_004:def 9
{VertexSelector ,EdgeSelector ,SourceSelector ,TargetSelector ,WeightSelector };
coherence
{VertexSelector ,EdgeSelector ,SourceSelector ,TargetSelector ,WeightSelector } is non empty finite Subset of NAT
;
end;

:: deftheorem defines WGraphSelectors GLIB_004:def 9 :
WGraphSelectors = {VertexSelector ,EdgeSelector ,SourceSelector ,TargetSelector ,WeightSelector };

Lm1: for G being WGraph holds WGraphSelectors c= dom G
proof end;

registration
let G be WGraph;
cluster G .strict WGraphSelectors -> [Graph-like] [Weighted] ;
coherence
( G .strict WGraphSelectors is [Graph-like] & G .strict WGraphSelectors is [Weighted] )
proof end;
end;

Lm2: for G being WGraph holds
( G == G .strict WGraphSelectors & the_Weight_of G = the_Weight_of (G .strict WGraphSelectors ) )
proof end;

Lm3: for G being WGraph holds dom (G .strict WGraphSelectors ) = WGraphSelectors
proof end;

definition
let G be WGraph;
func G .allWSubgraphs() -> non empty set means :Def10: :: GLIB_004:def 10
for x being set holds
( x in it iff ex G2 being WSubgraph of G st
( x = G2 & dom G2 = WGraphSelectors ) );
existence
ex b1 being non empty set st
for x being set holds
( x in b1 iff ex G2 being WSubgraph of G st
( x = G2 & dom G2 = WGraphSelectors ) )
proof end;
uniqueness
for b1, b2 being non empty set st ( for x being set holds
( x in b1 iff ex G2 being WSubgraph of G st
( x = G2 & dom G2 = WGraphSelectors ) ) ) & ( for x being set holds
( x in b2 iff ex G2 being WSubgraph of G st
( x = G2 & dom G2 = WGraphSelectors ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def10 defines .allWSubgraphs() GLIB_004:def 10 :
for G being WGraph
for b2 being non empty set holds
( b2 = G .allWSubgraphs() iff for x being set holds
( x in b2 iff ex G2 being WSubgraph of G st
( x = G2 & dom G2 = WGraphSelectors ) ) );

registration
let G be finite WGraph;
cluster G .allWSubgraphs() -> non empty finite ;
coherence
G .allWSubgraphs() is finite
proof end;
end;

definition
let G be WGraph;
let X be non empty Subset of (G .allWSubgraphs() );
:: original: Element
redefine mode Element of X -> WSubgraph of G;
coherence
for b1 being Element of X holds b1 is WSubgraph of G
proof end;
end;

definition
let G be finite real-weighted WGraph;
func G .cost() -> Real equals :: GLIB_004:def 11
Sum (the_Weight_of G);
coherence
Sum (the_Weight_of G) is Real
by XREAL_0:def 1;
end;

:: deftheorem defines .cost() GLIB_004:def 11 :
for G being finite real-weighted WGraph holds G .cost() = Sum (the_Weight_of G);

theorem :: GLIB_004:27
canceled;

theorem :: GLIB_004:28
for G being WGraph holds WGraphSelectors c= dom G by Lm1;

theorem :: GLIB_004:29
for G being WGraph holds
( G == G .strict WGraphSelectors & the_Weight_of G = the_Weight_of (G .strict WGraphSelectors ) ) by Lm2;

theorem :: GLIB_004:30
for G being WGraph holds dom (G .strict WGraphSelectors ) = WGraphSelectors by Lm3;

theorem :: GLIB_004:31
for G being finite real-weighted WGraph st the_Edges_of G = {} holds
G .cost() = 0
proof end;

theorem :: GLIB_004:32
for G1, G2 being finite real-weighted WGraph st the_Edges_of G1 = the_Edges_of G2 & the_Weight_of G1 = the_Weight_of G2 holds
G1 .cost() = G2 .cost() ;

theorem Th33: :: GLIB_004:33
for G1 being finite real-weighted WGraph
for e being set
for G2 being [Weighted] weight-inheriting removeEdge of G1,e st e in the_Edges_of G1 holds
G1 .cost() = (G2 .cost() ) + ((the_Weight_of G1) . e)
proof end;

theorem Th34: :: GLIB_004:34
for G being finite real-weighted WGraph
for V1 being non empty Subset of (the_Vertices_of G)
for E1 being Subset of (G .edgesBetween V1)
for G1 being inducedWSubgraph of G,V1,E1
for e being set
for G2 being inducedWSubgraph of G,V1,E1 \/ {e} st not e in E1 & e in G .edgesBetween V1 holds
(G1 .cost() ) + ((the_Weight_of G) . e) = G2 .cost()
proof end;

definition
let G be real-weighted WVGraph;
func PRIM:NextBestEdges G -> Subset of (the_Edges_of G) means :Def12: :: GLIB_004:def 12
for e1 being set holds
( e1 in it iff ( e1 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
(the_Weight_of G) . e1 <= (the_Weight_of G) . e2 ) ) );
existence
ex b1 being Subset of (the_Edges_of G) st
for e1 being set holds
( e1 in b1 iff ( e1 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
(the_Weight_of G) . e1 <= (the_Weight_of G) . e2 ) ) )
proof end;
uniqueness
for b1, b2 being Subset of (the_Edges_of G) st ( for e1 being set holds
( e1 in b1 iff ( e1 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
(the_Weight_of G) . e1 <= (the_Weight_of G) . e2 ) ) ) ) & ( for e1 being set holds
( e1 in b2 iff ( e1 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
(the_Weight_of G) . e1 <= (the_Weight_of G) . e2 ) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def12 defines PRIM:NextBestEdges GLIB_004:def 12 :
for G being real-weighted WVGraph
for b2 being Subset of (the_Edges_of G) holds
( b2 = PRIM:NextBestEdges G iff for e1 being set holds
( e1 in b2 iff ( e1 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G & ( for e2 being set st e2 SJoins G .labeledV() ,(the_Vertices_of G) \ (G .labeledV() ),G holds
(the_Weight_of G) . e1 <= (the_Weight_of G) . e2 ) ) ) );

definition
let G be real-weighted WGraph;
func PRIM:Init G -> real-WEV WEVGraph equals :: GLIB_004:def 13
(G .set VLabelSelector ,((choose (the_Vertices_of G)) .--> 1)) .set ELabelSelector ,{} ;
coherence
(G .set VLabelSelector ,((choose (the_Vertices_of G)) .--> 1)) .set ELabelSelector ,{} is real-WEV WEVGraph
;
end;

:: deftheorem defines PRIM:Init GLIB_004:def 13 :
for G being real-weighted WGraph holds PRIM:Init G = (G .set VLabelSelector ,((choose (the_Vertices_of G)) .--> 1)) .set ELabelSelector ,{} ;

definition
let G be real-WEV WEVGraph;
set e = choose (PRIM:NextBestEdges G);
func PRIM:Step G -> real-WEV WEVGraph equals :Def14: :: GLIB_004:def 14
G if PRIM:NextBestEdges G = {}
(G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex ((the_Target_of G) . (choose (PRIM:NextBestEdges G))),1 if ( PRIM:NextBestEdges G <> {} & (the_Source_of G) . (choose (PRIM:NextBestEdges G)) in G .labeledV() )
otherwise (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex ((the_Source_of G) . (choose (PRIM:NextBestEdges G))),1;
coherence
( ( PRIM:NextBestEdges G = {} implies G is real-WEV WEVGraph ) & ( PRIM:NextBestEdges G <> {} & (the_Source_of G) . (choose (PRIM:NextBestEdges G)) in G .labeledV() implies (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex ((the_Target_of G) . (choose (PRIM:NextBestEdges G))),1 is real-WEV WEVGraph ) & ( not PRIM:NextBestEdges G = {} & ( not PRIM:NextBestEdges G <> {} or not (the_Source_of G) . (choose (PRIM:NextBestEdges G)) in G .labeledV() ) implies (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex ((the_Source_of G) . (choose (PRIM:NextBestEdges G))),1 is real-WEV WEVGraph ) )
;
consistency
for b1 being real-WEV WEVGraph st PRIM:NextBestEdges G = {} & PRIM:NextBestEdges G <> {} & (the_Source_of G) . (choose (PRIM:NextBestEdges G)) in G .labeledV() holds
( b1 = G iff b1 = (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex ((the_Target_of G) . (choose (PRIM:NextBestEdges G))),1 )
;
end;

:: deftheorem Def14 defines PRIM:Step GLIB_004:def 14 :
for G being real-WEV WEVGraph holds
( ( PRIM:NextBestEdges G = {} implies PRIM:Step G = G ) & ( PRIM:NextBestEdges G <> {} & (the_Source_of G) . (choose (PRIM:NextBestEdges G)) in G .labeledV() implies PRIM:Step G = (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex ((the_Target_of G) . (choose (PRIM:NextBestEdges G))),1 ) & ( not PRIM:NextBestEdges G = {} & ( not PRIM:NextBestEdges G <> {} or not (the_Source_of G) . (choose (PRIM:NextBestEdges G)) in G .labeledV() ) implies PRIM:Step G = (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex ((the_Source_of G) . (choose (PRIM:NextBestEdges G))),1 ) );

definition
let G be real-weighted WGraph;
func PRIM:CompSeq G -> real-WEV WEVGraphSeq means :Def15: :: GLIB_004:def 15
( it . 0 = PRIM:Init G & ( for n being Element of NAT holds it . (n + 1) = PRIM:Step (it . n) ) );
existence
ex b1 being real-WEV WEVGraphSeq st
( b1 . 0 = PRIM:Init G & ( for n being Element of NAT holds b1 . (n + 1) = PRIM:Step (b1 . n) ) )
proof end;
uniqueness
for b1, b2 being real-WEV WEVGraphSeq st b1 . 0 = PRIM:Init G & ( for n being Element of NAT holds b1 . (n + 1) = PRIM:Step (b1 . n) ) & b2 . 0 = PRIM:Init G & ( for n being Element of NAT holds b2 . (n + 1) = PRIM:Step (b2 . n) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def15 defines PRIM:CompSeq GLIB_004:def 15 :
for G being real-weighted WGraph
for b2 being real-WEV WEVGraphSeq holds
( b2 = PRIM:CompSeq G iff ( b2 . 0 = PRIM:Init G & ( for n being Element of NAT holds b2 . (n + 1) = PRIM:Step (b2 . n) ) ) );

registration
let G be finite real-weighted WGraph;
cluster PRIM:CompSeq G -> finite real-WEV ;
coherence
PRIM:CompSeq G is finite
proof end;
end;

definition
let G be real-weighted WGraph;
func PRIM:MST G -> real-WEV WEVGraph equals :: GLIB_004:def 16
(PRIM:CompSeq G) .Result() ;
coherence
(PRIM:CompSeq G) .Result() is real-WEV WEVGraph
proof end;
end;

:: deftheorem defines PRIM:MST GLIB_004:def 16 :
for G being real-weighted WGraph holds PRIM:MST G = (PRIM:CompSeq G) .Result() ;

registration
let G be finite real-weighted WGraph;
cluster PRIM:MST G -> finite real-WEV ;
coherence
PRIM:MST G is finite
proof end;
end;

Lm4: for G being real-weighted WGraph holds
( G == PRIM:Init G & the_Weight_of G = the_Weight_of (PRIM:Init G) & the_ELabel_of (PRIM:Init G) = {} & the_VLabel_of (PRIM:Init G) = (choose (the_Vertices_of G)) .--> 1 )
proof end;

Lm5: for G being real-weighted WGraph holds
( (PRIM:Init G) .labeledV() = {(choose (the_Vertices_of G))} & (PRIM:Init G) .labeledE() = {} )
proof end;

Lm6: for G being real-WEV WEVGraph st PRIM:NextBestEdges G <> {} holds
ex v being Vertex of G st
( not v in G .labeledV() & PRIM:Step G = (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex v,1 )
proof end;

Lm7: for G being real-WEV WEVGraph holds
( G == PRIM:Step G & the_Weight_of G = the_Weight_of (PRIM:Step G) & G .labeledE() c= (PRIM:Step G) .labeledE() & G .labeledV() c= (PRIM:Step G) .labeledV() )
proof end;

Lm8: for G being finite real-weighted WGraph
for n being Element of NAT holds
( G == (PRIM:CompSeq G) . n & the_Weight_of ((PRIM:CompSeq G) . n) = the_Weight_of G )
proof end;

Lm9: for G being finite real-weighted WGraph
for n being Element of NAT holds
( ((PRIM:CompSeq G) . n) .labeledV() is non empty Subset of (the_Vertices_of G) & ((PRIM:CompSeq G) . n) .labeledE() c= G .edgesBetween (((PRIM:CompSeq G) . n) .labeledV() ) )
proof end;

Lm10: for G1 being finite real-weighted WGraph
for n being Element of NAT
for G2 being inducedSubgraph of G1,((PRIM:CompSeq G1) . n) .labeledV() ,((PRIM:CompSeq G1) . n) .labeledE() holds G2 is connected
proof end;

Lm11: for G1 being finite real-weighted WGraph
for n being Element of NAT
for G2 being inducedSubgraph of G1,(((PRIM:CompSeq G1) . n) .labeledV() ) holds G2 is connected
proof end;

registration
let G1 be finite real-weighted WGraph;
let n be Element of NAT ;
cluster -> connected inducedSubgraph of G1,((PRIM:CompSeq G1) . n) .labeledV() ,G1 .edgesBetween (((PRIM:CompSeq G1) . n) .labeledV() );
coherence
for b1 being inducedSubgraph of G1,(((PRIM:CompSeq G1) . n) .labeledV() ) holds b1 is connected
by Lm11;
end;

registration
let G1 be finite real-weighted WGraph;
let n be Element of NAT ;
cluster -> connected inducedSubgraph of G1,((PRIM:CompSeq G1) . n) .labeledV() ,((PRIM:CompSeq G1) . n) .labeledE() ;
coherence
for b1 being inducedSubgraph of G1,((PRIM:CompSeq G1) . n) .labeledV() ,((PRIM:CompSeq G1) . n) .labeledE() holds b1 is connected
by Lm10;
end;

Lm12: for G being finite real-weighted WGraph
for n being Element of NAT holds ((PRIM:CompSeq G) . n) .labeledV() c= G .reachableFrom (choose (the_Vertices_of G))
proof end;

Lm13: for G being finite real-weighted WGraph
for i, j being Nat st i <= j holds
( ((PRIM:CompSeq G) . i) .labeledV() c= ((PRIM:CompSeq G) . j) .labeledV() & ((PRIM:CompSeq G) . i) .labeledE() c= ((PRIM:CompSeq G) . j) .labeledE() )
proof end;

Lm14: for G being finite real-weighted WGraph
for n being Element of NAT holds
( PRIM:NextBestEdges ((PRIM:CompSeq G) . n) = {} iff ((PRIM:CompSeq G) . n) .labeledV() = G .reachableFrom (choose (the_Vertices_of G)) )
proof end;

Lm15: for G being finite real-weighted WGraph
for n being Element of NAT holds card (((PRIM:CompSeq G) . n) .labeledV() ) = min (n + 1),(card (G .reachableFrom (choose (the_Vertices_of G))))
proof end;

Lm16: for G being finite real-weighted WGraph holds
( PRIM:CompSeq G is halting & ((PRIM:CompSeq G) .Lifespan() ) + 1 = card (G .reachableFrom (choose (the_Vertices_of G))) )
proof end;

Lm17: for G1 being finite real-weighted WGraph
for n being Element of NAT
for G2 being inducedSubgraph of G1,((PRIM:CompSeq G1) . n) .labeledV() ,((PRIM:CompSeq G1) . n) .labeledE() holds G2 is Tree-like
proof end;

Lm18: for G being finite connected real-weighted WGraph holds (PRIM:MST G) .labeledV() = the_Vertices_of G
proof end;

registration
let G be finite connected real-weighted WGraph;
cluster spanning Tree-like Subgraph of G;
existence
ex b1 being WSubgraph of G st
( b1 is spanning & b1 is Tree-like )
proof end;
end;

definition
let G1 be finite connected real-weighted WGraph;
let G2 be spanning Tree-like WSubgraph of G1;
attr G2 is min-cost means :Def17: :: GLIB_004:def 17
for G3 being spanning Tree-like WSubgraph of G1 holds G2 .cost() <= G3 .cost() ;
end;

:: deftheorem Def17 defines min-cost GLIB_004:def 17 :
for G1 being finite connected real-weighted WGraph
for G2 being spanning Tree-like WSubgraph of G1 holds
( G2 is min-cost iff for G3 being spanning Tree-like WSubgraph of G1 holds G2 .cost() <= G3 .cost() );

registration
let G1 be finite connected real-weighted WGraph;
cluster spanning Tree-like min-cost Subgraph of G1;
existence
ex b1 being spanning Tree-like WSubgraph of G1 st b1 is min-cost
proof end;
end;

definition
let G be finite connected real-weighted WGraph;
mode minimumSpanningTree of G is spanning Tree-like min-cost WSubgraph of G;
end;

theorem :: GLIB_004:35
for G1, G2 being finite connected real-weighted WGraph
for G3 being WSubgraph of G1 st G3 is minimumSpanningTree of G1 & G1 == G2 & the_Weight_of G1 = the_Weight_of G2 holds
G3 is minimumSpanningTree of G2
proof end;

theorem Th36: :: GLIB_004:36
for G being finite connected real-weighted WGraph
for G1 being minimumSpanningTree of G
for G2 being WGraph st G1 == G2 & the_Weight_of G1 = the_Weight_of G2 holds
G2 is minimumSpanningTree of G
proof end;

theorem :: GLIB_004:37
for G being real-weighted WGraph holds
( G == PRIM:Init G & the_Weight_of G = the_Weight_of (PRIM:Init G) & the_ELabel_of (PRIM:Init G) = {} & the_VLabel_of (PRIM:Init G) = (choose (the_Vertices_of G)) .--> 1 ) by Lm4;

theorem :: GLIB_004:38
for G being real-weighted WGraph holds
( (PRIM:Init G) .labeledV() = {(choose (the_Vertices_of G))} & (PRIM:Init G) .labeledE() = {} ) by Lm5;

theorem :: GLIB_004:39
for G being real-WEV WEVGraph st PRIM:NextBestEdges G <> {} holds
ex v being Vertex of G st
( not v in G .labeledV() & PRIM:Step G = (G .labelEdge (choose (PRIM:NextBestEdges G)),1) .labelVertex v,1 ) by Lm6;

theorem :: GLIB_004:40
for G being real-WEV WEVGraph holds
( G == PRIM:Step G & the_Weight_of G = the_Weight_of (PRIM:Step G) & G .labeledE() c= (PRIM:Step G) .labeledE() & G .labeledV() c= (PRIM:Step G) .labeledV() ) by Lm7;

theorem :: GLIB_004:41
for G being finite real-weighted WGraph
for n being Element of NAT holds
( G == (PRIM:CompSeq G) . n & the_Weight_of ((PRIM:CompSeq G) . n) = the_Weight_of G ) by Lm8;

theorem :: GLIB_004:42
for G being finite real-weighted WGraph
for n being Element of NAT holds
( ((PRIM:CompSeq G) . n) .labeledV() is non empty Subset of (the_Vertices_of G) & ((PRIM:CompSeq G) . n) .labeledE() c= G .edgesBetween (((PRIM:CompSeq G) . n) .labeledV() ) ) by Lm9;

theorem :: GLIB_004:43
for G1 being finite real-weighted WGraph
for n being Element of NAT
for G2 being inducedSubgraph of G1,((PRIM:CompSeq G1) . n) .labeledV() ,((PRIM:CompSeq G1) . n) .labeledE() holds G2 is connected ;

theorem :: GLIB_004:44
for G1 being finite real-weighted WGraph
for n being Element of NAT
for G2 being inducedSubgraph of G1,(((PRIM:CompSeq G1) . n) .labeledV() ) holds G2 is connected ;

theorem :: GLIB_004:45
for G being finite real-weighted WGraph
for n being Element of NAT holds ((PRIM:CompSeq G) . n) .labeledV() c= G .reachableFrom (choose (the_Vertices_of G)) by Lm12;

theorem :: GLIB_004:46
for G being finite real-weighted WGraph
for i, j being Element of NAT st i <= j holds
( ((PRIM:CompSeq G) . i) .labeledV() c= ((PRIM:CompSeq G) . j) .labeledV() & ((PRIM:CompSeq G) . i) .labeledE() c= ((PRIM:CompSeq G) . j) .labeledE() ) by Lm13;

theorem :: GLIB_004:47
for G being finite real-weighted WGraph
for n being Element of NAT holds
( PRIM:NextBestEdges ((PRIM:CompSeq G) . n) = {} iff ((PRIM:CompSeq G) . n) .labeledV() = G .reachableFrom (choose (the_Vertices_of G)) ) by Lm14;

theorem :: GLIB_004:48
for G being finite real-weighted WGraph
for n being Element of NAT holds card (((PRIM:CompSeq G) . n) .labeledV() ) = min (n + 1),(card (G .reachableFrom (choose (the_Vertices_of G)))) by Lm15;

theorem :: GLIB_004:49
for G being finite real-weighted WGraph holds
( PRIM:CompSeq G is halting & ((PRIM:CompSeq G) .Lifespan() ) + 1 = card (G .reachableFrom (choose (the_Vertices_of G))) ) by Lm16;

theorem :: GLIB_004:50
for G1 being finite real-weighted WGraph
for n being Element of NAT
for G2 being inducedSubgraph of G1,((PRIM:CompSeq G1) . n) .labeledV() ,((PRIM:CompSeq G1) . n) .labeledE() holds G2 is Tree-like by Lm17;

theorem :: GLIB_004:51
for G being finite connected real-weighted WGraph holds (PRIM:MST G) .labeledV() = the_Vertices_of G by Lm18;

theorem Th52: :: GLIB_004:52
for G being finite connected real-weighted WGraph
for n being Nat holds ((PRIM:CompSeq G) . n) .labeledE() c= (PRIM:MST G) .labeledE()
proof end;

theorem :: GLIB_004:53
for G1 being finite connected real-weighted WGraph
for G2 being inducedWSubgraph of G1,(PRIM:MST G1) .labeledV() ,(PRIM:MST G1) .labeledE() holds G2 is minimumSpanningTree of G1
proof end;