
theorem Th17:
  for G being _finite natural-weighted WGraph,source,sink being
  Vertex of G st source <> sink holds FF:CompSeq(G,source,sink) is halting
proof
  let G be _finite natural-weighted WGraph, source, sink be Vertex of G;
  set CS = FF:CompSeq(G,source,sink);
  assume
A1: source <> sink;
  now
    set V = {source};
    defpred P[Nat] means
$1 <= (CS.$1).flow(source,sink) & (CS.$1)
    .flow(source,sink) is Element of NAT;
A2: source in V by TARSKI:def 1;
    set W1 = (the_Weight_of G)|G.edgesDBetween(V,the_Vertices_of G \ V);
    degree W1 = Sum W1;
    then reconsider N = Sum W1 as Element of NAT;
    set Gn1 = CS.(N+1);
    assume
A3: for n being Nat holds CS.n <> CS.(n+1);
    now
      let n be Nat;
      set Gn = CS.n, Gn1 = CS.(n+1);
      assume that
A4:   n <= Gn.flow(source,sink) and
A5:   Gn.flow(source,sink) is Element of NAT;
      reconsider GnF = Gn.flow(source,sink) as Element of NAT by A5;
      set P = AP:GetAugPath(Gn,source,sink);
A6:   Gn1 = FF:Step(Gn, source,sink) by Def20;
A7:   now
        assume not sink in dom AP:FindAugPath(Gn,source);
        then Gn1 = Gn by A6,Def18;
        hence contradiction by A3;
      end;
      then
A8:   P is_augmenting_wrt Gn by Def14;
A9:   P is_Walk_from source,sink by A7,Def14;
      then
A10:  P.last() = sink by GLIB_001:def 23;
      Gn1 = FF:PushFlow(Gn,AP:GetAugPath(Gn,source,sink)) by A6,A7,Def18;
      then
A11:  GnF + P.tolerance(Gn) = Gn1.flow(source,sink) by A1,A8,A9,Th15;
      then reconsider Gn1F = Gn1.flow(source,sink) as Element of NAT
              by ORDINAL1:def 12;
      P.first() = source by A9,GLIB_001:def 23;
      then 0 < P.tolerance(Gn) by A1,A8,A10,Th13,GLIB_001:127;
      then GnF + P.tolerance(Gn)-P.tolerance(Gn) < Gn1F-0 by A11,XREAL_1:15;
      then n < Gn1F by A4,XXREAL_0:2;
      hence n+1 <= Gn1.flow(source,sink) by NAT_1:13;
      thus Gn1.flow(source,sink) is Element of NAT by A11,ORDINAL1:def 12;
    end;
    then
A12: for n being Nat st P[n] holds P[n+1];
    now
      set B1 = EmptyBag G.edgesInto({sink}),B2 = EmptyBag G.edgesOutOf({sink});
      set G0 = CS.0;
      set E1 = G0 | G.edgesInto({sink}), E2 = G0 | G.edgesOutOf({sink});
A13:  G0 = the_Edges_of G --> 0 by Def20;
      now
        let e be set;
        assume
A14:    e in G.edgesInto({sink});
        hence E1.e = G0.e by FUNCT_1:49
          .= 0 by A13,A14,FUNCOP_1:7
          .= B1.e by PBOOLE:5;
      end;
      then
A15:  Sum E1 = Sum B1 by GLIB_004:6
        .= 0 by UPROOTS:11;
      now
        let e be set;
        assume
A16:    e in G.edgesOutOf({sink});
        hence E2.e = G0.e by FUNCT_1:49
          .= 0 by A13,A16,FUNCOP_1:7
          .= B2.e by PBOOLE:5;
      end;
      then
A17:  Sum E2 = Sum B2 by GLIB_004:6
        .= 0 by UPROOTS:11;
      hence G0.flow(source,sink) = 0 qua Nat - 0 by A15;
      thus G0.flow(source,sink) is Element of NAT by A15,A17;
    end;
    then
A18: P[ 0 ];
A19: for n being Nat holds P[n] from NAT_1:sch 2(A18,A12);
    then reconsider Gn1F = Gn1.flow(source,sink) as Element of NAT;
    Sum W1 + 1 <= Gn1F by A19;
    then
A20: Sum W1 < Gn1.flow(source,sink) by NAT_1:13;
    not sink in V by A1,TARSKI:def 1;
    hence contradiction by A2,A20,Th12,Th16;
  end;
  hence thesis;
end;
