:: GLIB_004 semantic presentation

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

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

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

theorem Th4: :: GLIB_004:4
for b1, b2 being set
for b3 being Rbag of b1 st dom b3 = {b2} holds
Sum b3 = b3 . b2
proof end;

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

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

theorem Th7: :: GLIB_004:7
for b1, b2 being set
for b3 being Rbag of b1
for b4 being Rbag of b2 st b3 = b4 holds
Sum b3 = Sum b4
proof end;

theorem Th8: :: GLIB_004:8
for b1, b2 being set
for b3 being Rbag of b1
for b4 being real number st b3 = (EmptyBag b1) +* (b2 .--> b4) holds
Sum b3 = b4
proof end;

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

definition
let c1 be real-weighted WGraph;
let c2 be WSubgraph of c1;
let c3 be set ;
pred c2 is_mincost_DTree_rooted_at c3 means :Def1: :: GLIB_004:def 1
( a2 is Tree-like & ( for b1 being Vertex of a2 ex b2 being DPath of a2 st
( b2 is_Walk_from a3,b1 & ( for b3 being DPath of a1 st b3 is_Walk_from a3,b1 holds
b2 .cost() <= b3 .cost() ) ) ) );
end;

:: deftheorem Def1 defines is_mincost_DTree_rooted_at GLIB_004:def 1 :
for b1 being real-weighted WGraph
for b2 being WSubgraph of b1
for b3 being set holds
( b2 is_mincost_DTree_rooted_at b3 iff ( b2 is Tree-like & ( for b4 being Vertex of b2 ex b5 being DPath of b2 st
( b5 is_Walk_from b3,b4 & ( for b6 being DPath of b1 st b6 is_Walk_from b3,b4 holds
b5 .cost() <= b6 .cost() ) ) ) ) );

definition
let c1 be real-weighted WGraph;
let c2 be DPath of c1;
let c3, c4 be set ;
pred c2 is_mincost_DPath_from c3,c4 means :Def2: :: GLIB_004:def 2
( a2 is_Walk_from a3,a4 & ( for b1 being DPath of a1 st b1 is_Walk_from a3,a4 holds
a2 .cost() <= b1 .cost() ) );
end;

:: deftheorem Def2 defines is_mincost_DPath_from GLIB_004:def 2 :
for b1 being real-weighted WGraph
for b2 being DPath of b1
for b3, b4 being set holds
( b2 is_mincost_DPath_from b3,b4 iff ( b2 is_Walk_from b3,b4 & ( for b5 being DPath of b1 st b5 is_Walk_from b3,b4 holds
b2 .cost() <= b5 .cost() ) ) );

definition
let c1 be finite real-weighted WGraph;
let c2, c3 be set ;
func c1 .min_DPath_cost c2,c3 -> Real means :Def3: :: GLIB_004:def 3
ex b1 being DPath of a1 st
( b1 is_mincost_DPath_from a2,a3 & a4 = b1 .cost() ) if ex b1 being DWalk of a1 st b1 is_Walk_from a2,a3
otherwise a4 = 0;
existence
( ( ex b1 being DWalk of c1 st b1 is_Walk_from c2,c3 implies ex b1 being Realex b2 being DPath of c1 st
( b2 is_mincost_DPath_from c2,c3 & b1 = b2 .cost() ) ) & ( ( for b1 being DWalk of c1 holds not b1 is_Walk_from c2,c3 ) implies ex b1 being Real st b1 = 0 ) )
proof end;
uniqueness
for b1, b2 being Real holds
( ( ex b3 being DWalk of c1 st b3 is_Walk_from c2,c3 & ex b3 being DPath of c1 st
( b3 is_mincost_DPath_from c2,c3 & b1 = b3 .cost() ) & ex b3 being DPath of c1 st
( b3 is_mincost_DPath_from c2,c3 & b2 = b3 .cost() ) implies b1 = b2 ) & ( ( for b3 being DWalk of c1 holds not b3 is_Walk_from c2,c3 ) & 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 b1 being finite real-weighted WGraph
for b2, b3 being set
for b4 being Real holds
( ( ex b5 being DWalk of b1 st b5 is_Walk_from b2,b3 implies ( b4 = b1 .min_DPath_cost b2,b3 iff ex b5 being DPath of b1 st
( b5 is_mincost_DPath_from b2,b3 & b4 = b5 .cost() ) ) ) & ( ( for b5 being DWalk of b1 holds not b5 is_Walk_from b2,b3 ) implies ( b4 = b1 .min_DPath_cost b2,b3 iff b4 = 0 ) ) );

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

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

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

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

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

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

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

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

definition
let c1 be real-weighted WGraph;
let c2 be Vertex of c1;
func DIJK:CompSeq c1,c2 -> real-WEV WEVGraphSeq means :Def7: :: GLIB_004:def 7
( a3 .-> 0 = DIJK:Init a1,a2 & ( for b1 being Nat holds a3 .-> (b1 + 1) = DIJK:Step (a3 .-> b1) ) );
existence
ex b1 being real-WEV WEVGraphSeq st
( b1 .-> 0 = DIJK:Init c1,c2 & ( for b2 being Nat holds b1 .-> (b2 + 1) = DIJK:Step (b1 .-> b2) ) )
proof end;
uniqueness
for b1, b2 being real-WEV WEVGraphSeq st b1 .-> 0 = DIJK:Init c1,c2 & ( for b3 being Nat holds b1 .-> (b3 + 1) = DIJK:Step (b1 .-> b3) ) & b2 .-> 0 = DIJK:Init c1,c2 & ( for b3 being Nat holds b2 .-> (b3 + 1) = DIJK:Step (b2 .-> b3) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def7 defines DIJK:CompSeq GLIB_004:def 7 :
for b1 being real-weighted WGraph
for b2 being Vertex of b1
for b3 being real-WEV WEVGraphSeq holds
( b3 = DIJK:CompSeq b1,b2 iff ( b3 .-> 0 = DIJK:Init b1,b2 & ( for b4 being Nat holds b3 .-> (b4 + 1) = DIJK:Step (b3 .-> b4) ) ) );

registration
let c1 be finite real-weighted WGraph;
let c2 be Vertex of c1;
cluster DIJK:CompSeq a1,a2 -> finite real-WEV ;
coherence
DIJK:CompSeq c1,c2 is finite
proof end;
end;

registration
let c1 be nonnegative-weighted WGraph;
let c2 be Vertex of c1;
cluster DIJK:CompSeq a1,a2 -> nonnegative-weighted real-WEV ;
coherence
DIJK:CompSeq c1,c2 is nonnegative-weighted
proof end;
end;

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

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

registration
let c1 be finite real-weighted WGraph;
let c2 be Vertex of c1;
cluster DIJK:SSSP a1,a2 -> finite real-WEV ;
coherence
DIJK:SSSP c1,c2 is finite
proof end;
end;

theorem Th10: :: GLIB_004:10
for b1 being finite nonnegative-weighted WGraph
for b2 being DPath of b1
for b3, b4 being set
for b5, b6 being Nat st b2 is_mincost_DPath_from b3,b4 holds
b2 .cut b5,b6 is_mincost_DPath_from (b2 .cut b5,b6) .first() ,(b2 .cut b5,b6) .last()
proof end;

theorem Th11: :: GLIB_004:11
for b1 being finite real-weighted WGraph
for b2, b3 being DPath of b1
for b4, b5 being set st b2 is_mincost_DPath_from b4,b5 & b3 is_mincost_DPath_from b4,b5 holds
b2 .cost() = b3 .cost()
proof end;

theorem Th12: :: GLIB_004:12
for b1 being finite real-weighted WGraph
for b2 being DPath of b1
for b3, b4 being set st b2 is_mincost_DPath_from b3,b4 holds
b1 .min_DPath_cost b3,b4 = b2 .cost()
proof end;

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

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

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

theorem Th16: :: GLIB_004:16
for b1 being real-weighted WGraph
for b2 being Vertex of b1
for b3, b4 being Nat st b3 <= b4 holds
( ((DIJK:CompSeq b1,b2) .-> b3) .labeledV() c= ((DIJK:CompSeq b1,b2) .-> b4) .labeledV() & ((DIJK:CompSeq b1,b2) .-> b3) .labeledE() c= ((DIJK:CompSeq b1,b2) .-> b4) .labeledE() )
proof end;

theorem Th17: :: GLIB_004:17
for b1 being real-weighted WGraph
for b2 being Vertex of b1
for b3 being Nat holds
( b1 == (DIJK:CompSeq b1,b2) .-> b3 & the_Weight_of b1 = the_Weight_of ((DIJK:CompSeq b1,b2) .-> b3) )
proof end;

theorem Th18: :: GLIB_004:18
for b1 being finite real-weighted WGraph
for b2 being Vertex of b1
for b3 being Nat holds ((DIJK:CompSeq b1,b2) .-> b3) .labeledV() c= b1 .reachableDFrom b2
proof end;

theorem Th19: :: GLIB_004:19
for b1 being finite real-weighted WGraph
for b2 being Vertex of b1
for b3 being Nat holds
( DIJK:NextBestEdges ((DIJK:CompSeq b1,b2) .-> b3) = {} iff ((DIJK:CompSeq b1,b2) .-> b3) .labeledV() = b1 .reachableDFrom b2 )
proof end;

theorem Th20: :: GLIB_004:20
for b1 being finite real-weighted WGraph
for b2 being Vertex of b1
for b3 being Nat holds Card (((DIJK:CompSeq b1,b2) .-> b3) .labeledV() ) = min (b3 + 1),(card (b1 .reachableDFrom b2))
proof end;

theorem Th21: :: GLIB_004:21
for b1 being finite real-weighted WGraph
for b2 being Vertex of b1
for b3 being Nat holds ((DIJK:CompSeq b1,b2) .-> b3) .labeledE() c= ((DIJK:CompSeq b1,b2) .-> b3) .edgesBetween (((DIJK:CompSeq b1,b2) .-> b3) .labeledV() )
proof end;

theorem Th22: :: GLIB_004:22
for b1 being finite nonnegative-weighted WGraph
for b2 being Vertex of b1
for b3 being Nat
for b4 being inducedWSubgraph of b1,((DIJK:CompSeq b1,b2) .-> b3) .labeledV() ,((DIJK:CompSeq b1,b2) .-> b3) .labeledE() holds
( b4 is_mincost_DTree_rooted_at b2 & ( for b5 being Vertex of b1 st b5 in ((DIJK:CompSeq b1,b2) .-> b3) .labeledV() holds
b1 .min_DPath_cost b2,b5 = (the_VLabel_of ((DIJK:CompSeq b1,b2) .-> b3)) . b5 ) )
proof end;

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

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

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

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

theorem Th26: :: GLIB_004:26
for b1 being finite nonnegative-weighted WGraph
for b2 being Vertex of b1
for b3 being inducedWSubgraph of b1,(DIJK:SSSP b1,b2) .labeledV() ,(DIJK:SSSP b1,b2) .labeledE() holds
( b3 is_mincost_DTree_rooted_at b2 & ( for b4 being Vertex of b1 st b4 in b1 .reachableDFrom b2 holds
( b4 in the_Vertices_of b3 & b1 .min_DPath_cost b2,b4 = (the_VLabel_of (DIJK:SSSP b1,b2)) . b4 ) ) )
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
by ENUMSET1:def 3;
end;

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

Lemma29: for b1 being WGraph holds WGraphSelectors c= dom b1
proof end;

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

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

Lemma31: for b1 being WGraph holds dom (b1 .strict WGraphSelectors ) = WGraphSelectors
proof end;

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

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

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

definition
let c1 be WGraph;
let c2 be non empty Subset of (c1 .allWSubgraphs() );
redefine mode Element as Element of c2 -> WSubgraph of a1;
coherence
for b1 being Element of c2 holds b1 is WSubgraph of c1
proof end;
end;

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

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

theorem Th27: :: GLIB_004:27
for b1 being set holds
( b1 in WGraphSelectors iff ( b1 = VertexSelector or b1 = EdgeSelector or b1 = SourceSelector or b1 = TargetSelector or b1 = WeightSelector ) ) by ENUMSET1:def 3;

theorem Th28: :: GLIB_004:28
for b1 being WGraph holds WGraphSelectors c= dom b1 by Lemma29;

theorem Th29: :: GLIB_004:29
for b1 being WGraph holds
( b1 == b1 .strict WGraphSelectors & the_Weight_of b1 = the_Weight_of (b1 .strict WGraphSelectors ) ) by Lemma30;

theorem Th30: :: GLIB_004:30
for b1 being WGraph holds dom (b1 .strict WGraphSelectors ) = WGraphSelectors by Lemma31;

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

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

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

theorem Th34: :: GLIB_004:34
for b1 being finite real-weighted WGraph
for b2 being non empty Subset of (the_Vertices_of b1)
for b3 being Subset of (b1 .edgesBetween b2)
for b4 being inducedWSubgraph of b1,b2,b3
for b5 being set
for b6 being inducedWSubgraph of b1,b2,b3 \/ {b5} st not b5 in b3 & b5 in b1 .edgesBetween b2 holds
(b4 .cost() ) + ((the_Weight_of b1) . b5) = b6 .cost()
proof end;

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

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

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

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

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

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

definition
let c1 be real-weighted WGraph;
func PRIM:CompSeq c1 -> real-WEV WEVGraphSeq means :Def15: :: GLIB_004:def 15
( a2 .-> 0 = PRIM:Init a1 & ( for b1 being Nat holds a2 .-> (b1 + 1) = PRIM:Step (a2 .-> b1) ) );
existence
ex b1 being real-WEV WEVGraphSeq st
( b1 .-> 0 = PRIM:Init c1 & ( for b2 being Nat holds b1 .-> (b2 + 1) = PRIM:Step (b1 .-> b2) ) )
proof end;
uniqueness
for b1, b2 being real-WEV WEVGraphSeq st b1 .-> 0 = PRIM:Init c1 & ( for b3 being Nat holds b1 .-> (b3 + 1) = PRIM:Step (b1 .-> b3) ) & b2 .-> 0 = PRIM:Init c1 & ( for b3 being Nat holds b2 .-> (b3 + 1) = PRIM:Step (b2 .-> b3) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def15 defines PRIM:CompSeq GLIB_004:def 15 :
for b1 being real-weighted WGraph
for b2 being real-WEV WEVGraphSeq holds
( b2 = PRIM:CompSeq b1 iff ( b2 .-> 0 = PRIM:Init b1 & ( for b3 being Nat holds b2 .-> (b3 + 1) = PRIM:Step (b2 .-> b3) ) ) );

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

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

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

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

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

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

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

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

Lemma42: for b1 being finite real-weighted WGraph
for b2 being Nat holds
( b1 == (PRIM:CompSeq b1) .-> b2 & the_Weight_of ((PRIM:CompSeq b1) .-> b2) = the_Weight_of b1 )
proof end;

Lemma43: for b1 being finite real-weighted WGraph
for b2 being Nat holds
( ((PRIM:CompSeq b1) .-> b2) .labeledV() is non empty Subset of (the_Vertices_of b1) & ((PRIM:CompSeq b1) .-> b2) .labeledE() c= b1 .edgesBetween (((PRIM:CompSeq b1) .-> b2) .labeledV() ) )
proof end;

Lemma44: for b1 being finite real-weighted WGraph
for b2 being Nat
for b3 being inducedSubgraph of b1,((PRIM:CompSeq b1) .-> b2) .labeledV() ,((PRIM:CompSeq b1) .-> b2) .labeledE() holds b3 is connected
proof end;

Lemma45: for b1 being finite real-weighted WGraph
for b2 being Nat
for b3 being inducedSubgraph of b1,(((PRIM:CompSeq b1) .-> b2) .labeledV() ) holds b3 is connected
proof end;

registration
let c1 be finite real-weighted WGraph;
let c2 be Nat;
cluster -> connected inducedSubgraph of a1,((PRIM:CompSeq a1) .-> a2) .labeledV() ,a1 .edgesBetween (((PRIM:CompSeq a1) .-> a2) .labeledV() );
coherence
for b1 being inducedSubgraph of c1,(((PRIM:CompSeq c1) .-> c2) .labeledV() ) holds b1 is connected
by Lemma45;
end;

registration
let c1 be finite real-weighted WGraph;
let c2 be Nat;
cluster -> connected inducedSubgraph of a1,((PRIM:CompSeq a1) .-> a2) .labeledV() ,((PRIM:CompSeq a1) .-> a2) .labeledE() ;
coherence
for b1 being inducedSubgraph of c1,((PRIM:CompSeq c1) .-> c2) .labeledV() ,((PRIM:CompSeq c1) .-> c2) .labeledE() holds b1 is connected
by Lemma44;
end;

Lemma46: for b1 being finite real-weighted WGraph
for b2 being Nat holds ((PRIM:CompSeq b1) .-> b2) .labeledV() c= b1 .reachableFrom (choose (the_Vertices_of b1))
proof end;

Lemma47: for b1 being finite real-weighted WGraph
for b2, b3 being Nat st b2 <= b3 holds
( ((PRIM:CompSeq b1) .-> b2) .labeledV() c= ((PRIM:CompSeq b1) .-> b3) .labeledV() & ((PRIM:CompSeq b1) .-> b2) .labeledE() c= ((PRIM:CompSeq b1) .-> b3) .labeledE() )
proof end;

Lemma48: for b1 being finite real-weighted WGraph
for b2 being Nat holds
( PRIM:NextBestEdges ((PRIM:CompSeq b1) .-> b2) = {} iff ((PRIM:CompSeq b1) .-> b2) .labeledV() = b1 .reachableFrom (choose (the_Vertices_of b1)) )
proof end;

Lemma49: for b1 being finite real-weighted WGraph
for b2 being Nat holds card (((PRIM:CompSeq b1) .-> b2) .labeledV() ) = min (b2 + 1),(card (b1 .reachableFrom (choose (the_Vertices_of b1))))
proof end;

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

Lemma51: for b1 being finite real-weighted WGraph
for b2 being Nat
for b3 being inducedSubgraph of b1,((PRIM:CompSeq b1) .-> b2) .labeledV() ,((PRIM:CompSeq b1) .-> b2) .labeledE() holds b3 is Tree-like
proof end;

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

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

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

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

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

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

theorem Th35: :: GLIB_004:35
for b1, b2 being finite connected real-weighted WGraph
for b3 being WSubgraph of b1 st b3 is minimumSpanningTree of b1 & b1 == b2 & the_Weight_of b1 = the_Weight_of b2 holds
b3 is minimumSpanningTree of b2
proof end;

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

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

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

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

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

theorem Th41: :: GLIB_004:41
for b1 being finite real-weighted WGraph
for b2 being Nat holds
( b1 == (PRIM:CompSeq b1) .-> b2 & the_Weight_of ((PRIM:CompSeq b1) .-> b2) = the_Weight_of b1 ) by Lemma42;

theorem Th42: :: GLIB_004:42
for b1 being finite real-weighted WGraph
for b2 being Nat holds
( ((PRIM:CompSeq b1) .-> b2) .labeledV() is non empty Subset of (the_Vertices_of b1) & ((PRIM:CompSeq b1) .-> b2) .labeledE() c= b1 .edgesBetween (((PRIM:CompSeq b1) .-> b2) .labeledV() ) ) by Lemma43;

theorem Th43: :: GLIB_004:43
for b1 being finite real-weighted WGraph
for b2 being Nat
for b3 being inducedSubgraph of b1,((PRIM:CompSeq b1) .-> b2) .labeledV() ,((PRIM:CompSeq b1) .-> b2) .labeledE() holds b3 is connected ;

theorem Th44: :: GLIB_004:44
for b1 being finite real-weighted WGraph
for b2 being Nat
for b3 being inducedSubgraph of b1,(((PRIM:CompSeq b1) .-> b2) .labeledV() ) holds b3 is connected ;

theorem Th45: :: GLIB_004:45
for b1 being finite real-weighted WGraph
for b2 being Nat holds ((PRIM:CompSeq b1) .-> b2) .labeledV() c= b1 .reachableFrom (choose (the_Vertices_of b1)) by Lemma46;

theorem Th46: :: GLIB_004:46
for b1 being finite real-weighted WGraph
for b2, b3 being Nat st b2 <= b3 holds
( ((PRIM:CompSeq b1) .-> b2) .labeledV() c= ((PRIM:CompSeq b1) .-> b3) .labeledV() & ((PRIM:CompSeq b1) .-> b2) .labeledE() c= ((PRIM:CompSeq b1) .-> b3) .labeledE() ) by Lemma47;

theorem Th47: :: GLIB_004:47
for b1 being finite real-weighted WGraph
for b2 being Nat holds
( PRIM:NextBestEdges ((PRIM:CompSeq b1) .-> b2) = {} iff ((PRIM:CompSeq b1) .-> b2) .labeledV() = b1 .reachableFrom (choose (the_Vertices_of b1)) ) by Lemma48;

theorem Th48: :: GLIB_004:48
for b1 being finite real-weighted WGraph
for b2 being Nat holds card (((PRIM:CompSeq b1) .-> b2) .labeledV() ) = min (b2 + 1),(card (b1 .reachableFrom (choose (the_Vertices_of b1)))) by Lemma49;

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

theorem Th50: :: GLIB_004:50
for b1 being finite real-weighted WGraph
for b2 being Nat
for b3 being inducedSubgraph of b1,((PRIM:CompSeq b1) .-> b2) .labeledV() ,((PRIM:CompSeq b1) .-> b2) .labeledE() holds b3 is Tree-like by Lemma51;

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

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

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