reserve n,m,i,j,k for Nat,
  x,y,e,X,V,U for set,
  W,f,g for Function;
reserve p,q for FinSequence;
reserve G for Graph,
  pe,qe for FinSequence of the carrier' of G;
reserve v,v1,v2,v3 for Element of G;
reserve p,q for oriented Chain of G;
reserve G for finite Graph,
  ps for Simple oriented Chain of G,
  P,Q for oriented Chain of G,
  v1,v2,v3 for Element of G,
  pe,qe for FinSequence of the carrier' of G;

theorem
  for G being finite oriented Graph, P,Q,R being oriented Chain of G, v1
  ,v2,v3 being Element of G st e in the carrier' of G & W
is_weight>=0of G & len P >= 1 & P is_shortestpath_of v1,v2,V,W & v1 <> v2 & v1
<> v3 & R=P^<*e*> & Q is_shortestpath_of v1,v3,V,W & e orientedly_joins v2,v3 &
  P islongestInShortestpath V,v1,W holds (cost(Q,W) <= cost(R,W) implies Q
  is_shortestpath_of v1,v3,V \/{v2},W) & (cost(Q,W) >= cost(R,W) implies R
  is_shortestpath_of v1,v3,V \/{v2},W)
proof
  let G be finite oriented Graph, P,Q,R be oriented Chain of G, v1,v2,v3 be
  Element of G;
  assume that
A1: e in the carrier' of G and
A2: W is_weight>=0of G and
A3: len P >= 1 and
A4: P is_shortestpath_of v1,v2,V,W and
A5: v1 <> v2 and
A6: v1 <> v3 and
A7: R=P^<*e*> and
A8: Q is_shortestpath_of v1,v3,V,W and
A9: e orientedly_joins v2,v3 and
A10: P islongestInShortestpath V,v1,W;
A11: P is_orientedpath_of v1,v2,V by A4;
  then
A12: v1 in V by A5,Th29;
  set Eg=the carrier' of G;
  reconsider pe=<*e*> as FinSequence of Eg by A1,FINSEQ_1:74;
  set V9=V \/ {v2};
  Q is_orientedpath_of v1,v3,V by A8;
  then
A13: Q is_orientedpath_of v1,v3,V9 by Th30,XBOOLE_1:7;
A14: len pe = 1 & pe.1=e by FINSEQ_1:40;
  then consider s being Simple oriented Chain of G such that
A15: s is_shortestpath_of v1,v3,V9,W by A2,A3,A7,A9,A11,Th32,Th60;
A16: R is_orientedpath_of v1,v3,V9 by A3,A7,A9,A11,A14,Th32;
A17: now
    assume
A18: cost(Q,W) <= cost(s,W);
    hereby
      assume cost(Q,W)<= cost(R,W);
      now
        let u be oriented Chain of G;
        assume u is_orientedpath_of v1,v3,V9;
        then cost(s,W) <= cost(u,W) by A15;
        hence cost(Q,W) <= cost (u,W) by A18,XXREAL_0:2;
      end;
      hence Q is_shortestpath_of v1,v3,V9,W by A13;
    end;
    hereby
      assume
A19:  cost(Q,W)>= cost(R,W);
      now
        let u be oriented Chain of G;
        assume u is_orientedpath_of v1,v3,V9;
        then cost(s,W) <= cost(u,W) by A15;
        then cost(Q,W) <= cost (u,W) by A18,XXREAL_0:2;
        hence cost(R,W) <= cost (u,W) by A19,XXREAL_0:2;
      end;
      hence R is_shortestpath_of v1,v3,V9,W by A16;
    end;
  end;
  set FT=the Target of G, FS=the Source of G;
A20: FS.e=v2 & FT.e=v3 by A9,GRAPH_4:def 1;
A21: s is_orientedpath_of v1,v3,V9 by A15;
  then
A22: s is_orientedpath_of v1,v3;
  then
A23: FT.(s.len s)=v3;
  s <> {} by A22;
  then
A24: len s >= 1 by FINSEQ_1:20;
  per cases;
  suppose
    len s >= 2;
    then consider k being Nat such that
A25: len s = 1+1 + k by NAT_1:10;
A26: V9 \ {v2} = V \ {v2} by XBOOLE_1:40;
    reconsider k as Element of NAT by ORDINAL1:def 12;
A27: len s = 1 + (1+k) by A25;
    then consider s1,s2 being FinSequence such that
A28: len s1 = 1+k and
A29: len s2 = 1 and
A30: s = s1^s2 by FINSEQ_2:22;
    reconsider s1,s2 as Simple oriented Chain of G by A30,Th12;
A31: len s1 >= 1 by A28,NAT_1:12;
A32: FS.(s.1)=v1 by A22;
    then
A33: FS.(s1.1)=v1 by A30,A31,Lm1;
    len s2 = 1 by A29;
    then
A34: not v3 in vertices(s1) by A6,A23,A30,A31,A32,Th16;
A35: s2.1 = s.len s by A27,A28,A29,A30,Lm2;
    then
A36: vertices(s) \ {v3} = vertices(s1) \/ {v3} \ {v3} by A23,A28,A29,A30,Th25,
NAT_1:12
      .=vertices(s1) \ {v3} by XBOOLE_1:40
      .=vertices(s1) by A34,ZFMISC_1:57;
    then vertices(s1) c= V9 by A21;
    then vertices(s1) \ {v2} c= V9 \ {v2} by XBOOLE_1:33;
    then
A37: vertices(s1) \ {v2} c= V by A26,XBOOLE_1:1;
A38: len s1 < len s by A27,A28,NAT_1:13;
    then
A39: FS.(s.(len s1+1))=FT.(s.(len s1)) by A31,GRAPH_1:def 15;
A40: s1.len s1=s.len s1 by A30,A31,Lm1;
    then
A41: FS.(s2.1)=FT.(s1.(len s1)) by A27,A28,A35,A31,A38,GRAPH_1:def 15;
A42: cost(s,W) = cost(s1,W)+cost(s2,W) by A2,A30,Th44,Th52;
A43: not v1 in vertices(s2) by A6,A23,A29,A30,A31,A32,Th16;
    hereby
      per cases;
      suppose
        v2 in vertices(s1);
        then consider i such that
A44:    1<=i and
A45:    i <= len s1 and
A46:    v2 = FT.(s1.i) by A5,A33,Th26;
        s2/.1 in Eg by A1;
        then
A47:    s2.1 in Eg by A29,FINSEQ_4:15;
        hereby
          per cases;
          suppose
A48:        FS.(s2.1)=v2;
            s1 <> {} by A28;
            then s1 is_orientedpath_of v1,v2 by A33,A41,A48;
            then s1 is_orientedpath_of v1,v2,V by A37;
            then
A49:        cost(P,W) <= cost(s1,W) by A4;
            s2.1=e by A1,A23,A20,A35,A47,A48,GRAPH_1:def 7;
            then s2=pe by A29,FINSEQ_1:40;
            then cost(R,W) = cost(P,W)+cost(s2,W) by A2,A7,Th44,Th52;
            then
A50:        cost(R,W) <= cost(s,W) by A42,A49,XREAL_1:7;
            hereby
              assume cost(Q,W) <= cost(R,W);
              then
A51:          cost(Q,W) <= cost(s,W) by A50,XXREAL_0:2;
              now
                let u be oriented Chain of G;
                assume u is_orientedpath_of v1,v3,V9;
                then cost(s,W) <= cost(u,W) by A15;
                hence cost(Q,W) <= cost (u,W) by A51,XXREAL_0:2;
              end;
              hence Q is_shortestpath_of v1,v3,V9,W by A13;
            end;
            hereby
              assume cost(Q,W)>= cost(R,W);
              now
                let u be oriented Chain of G;
                assume u is_orientedpath_of v1,v3,V9;
                then cost(s,W) <= cost(u,W) by A15;
                hence cost(R,W) <= cost (u,W) by A50,XXREAL_0:2;
              end;
              hence R is_shortestpath_of v1,v3,V9,W by A16;
            end;
          end;
          suppose
A52:        FS.(s2.1)<>v2;
            len s1 in dom s1 by A31,FINSEQ_3:25;
            then reconsider vx=FT.(s1.len s1) as Vertex of G by FINSEQ_2:11
,FUNCT_2:5;
A53:        not vx in {v2} by A41,A52,TARSKI:def 1;
            len s1 in dom s1 by A31,FINSEQ_3:25;
            then
A54:        vx in vertices s1 by Th22;
            vertices s1 c= V9 by A21,A36;
            then
A55:        vx in V by A54,A53,XBOOLE_0:def 3;
            {vx} c= V
            by A55,TARSKI:def 1;
            then
A56:        V \/ {vx} c= V by XBOOLE_1:8;
            1 in dom s2 by A29,FINSEQ_3:25;
            then vx <> v1 by A25,A28,A35,A40,A43,A39,Th22;
            then consider q9 being oriented Chain of G such that
A57:        q9 is_shortestpath_of v1,vx,V,W and
A58:        cost(q9,W) <= cost(P,W) by A10,A55;
            consider j being Nat such that
A59:        len s1=i+j by A45,NAT_1:10;
A60:        q9 is_orientedpath_of v1,vx,V by A57;
            then
A61:        q9 is_orientedpath_of v1,vx;
            then q9<>{};
            then
A62:        len q9 >= 1 by FINSEQ_1:20;
            FT.(q9.len q9)=vx by A61;
            then reconsider
            qx=q9^s2 as oriented Chain of G by A25,A28,A35,A40,A39,Th10;
            len qx = len q9 + 1 by A29,FINSEQ_1:22;
            then
A63:        qx <> {} & FT.(qx.len qx)=v3 by A23,A29,A35,Lm2;
            FS.(q9.1)=v1 by A61;
            then FS.(qx.1)=v1 by A62,Lm1;
            then
A64:        qx is_orientedpath_of v1,v3 by A63;
            vertices(q9) \ {vx} c= V by A60;
            then vertices(q9) c= V \/ {vx} by XBOOLE_1:44;
            then vertices(q9) c= V by A56;
            then
A65:        vertices(q9) \ {v3} c= V \ {v3} by XBOOLE_1:33;
            vertices(qx)= vertices(q9) \/ {v3} by A23,A29,A35,A62,Th25;
            then vertices(qx) \ {v3} = vertices(q9) \ {v3} by XBOOLE_1:40;
            then vertices(qx) \ {v3} c= V by A65,XBOOLE_1:1;
            then qx is_orientedpath_of v1,v3,V by A64;
            then
A66:        cost(Q,W) <= cost(qx,W) by A8;
            reconsider j as Element of NAT by ORDINAL1:def 12;
            consider t1,t2 being FinSequence such that
A67:        len t1 = i and
            len t2 = j and
A68:        s1 = t1^t2 by A59,FINSEQ_2:22;
            reconsider t1,t2 as Simple oriented Chain of G by A68,Th12;
A69:        FT.(t1.len t1)=v2 by A44,A46,A67,A68,Lm1;
            vertices(t1) c= vertices(t1^t2) by Th24;
            then vertices(t1) \ {v2} c= vertices(s1) \ {v2} by A68,XBOOLE_1:33;
            then
A70:        vertices(t1) \ {v2} c= V by A37;
            t1 <> {} & FS.(t1.1)=v1 by A33,A44,A67,A68,Lm1;
            then t1 is_orientedpath_of v1,v2 by A69;
            then t1 is_orientedpath_of v1,v2,V by A70;
            then
A71:        cost(P,W) <= cost(t1,W) by A4;
A72:        cost(t2,W) >= 0 by A2,Th48;
            cost(s1,W)=cost(t1,W)+cost(t2,W) by A2,A68,Th44,Th52;
            then cost(t1,W) + (0 qua Nat) <= cost(s1,W) by A72,XREAL_1:7;
            then cost(P,W) <= cost(s1,W) by A71,XXREAL_0:2;
            then
A73:        cost(q9,W) <= cost(s1,W) by A58,XXREAL_0:2;
            cost(qx,W) = cost(q9,W)+cost(s2,W) by A2,Th44,Th52;
            then cost(qx,W) <= cost(s,W) by A42,A73,XREAL_1:7;
            then
A74:        cost(Q,W) <= cost(s,W) by A66,XXREAL_0:2;
            hereby
              assume cost(Q,W) <= cost(R,W);
              now
                let u be oriented Chain of G;
                assume u is_orientedpath_of v1,v3,V9;
                then cost(s,W) <= cost(u,W) by A15;
                hence cost(Q,W) <= cost (u,W) by A74,XXREAL_0:2;
              end;
              hence Q is_shortestpath_of v1,v3,V9,W by A13;
            end;
            hereby
              assume cost(Q,W)>= cost(R,W);
              then
A75:          cost(R,W) <= cost(s,W) by A74,XXREAL_0:2;
              now
                let u be oriented Chain of G;
                assume u is_orientedpath_of v1,v3,V9;
                then cost(s,W) <= cost(u,W) by A15;
                hence cost(R,W) <= cost (u,W) by A75,XXREAL_0:2;
              end;
              hence R is_shortestpath_of v1,v3,V9,W by A16;
            end;
          end;
        end;
      end;
      suppose
        not v2 in vertices(s1);
        then
A76:    vertices(s1) \ {v2} = vertices(s1) by ZFMISC_1:57;
        then vertices(s1) \ {v2} c= V9 by A21,A36;
        then vertices(s) \ {v3} c= V by A36,A76,XBOOLE_1:43;
        then s is_orientedpath_of v1,v3,V by A22;
        hence thesis by A8,A17;
      end;
    end;
  end;
  suppose
    len s < 1+1;
    then
A77: len s <= 1 by NAT_1:13;
    then
A78: len s=1 by A24,XXREAL_0:1;
A79: vertices s=vertices(s/.1) by A24,A77,Th23,XXREAL_0:1;
    vertices(s) \ {v3} c= V
    proof
      let x be object;
      assume
A80:  x in vertices(s) \ {v3};
      then
A81:  not x in {v3} by XBOOLE_0:def 5;
      x in vertices(s/.1) by A79,A80,XBOOLE_0:def 5;
      then
A82:  x=FS.(s/.1) or x=FT.(s/.1) by TARSKI:def 2;
A83:  s/.1=s.1 by A24,FINSEQ_4:15;
      v3=FT.(s.len s) by A22
        .=FT.(s/.1) by A78,FINSEQ_4:15;
      hence thesis by A22,A12,A81,A82,A83,TARSKI:def 1;
    end;
    then s is_orientedpath_of v1,v3,V by A22;
    hence thesis by A8,A17;
  end;
end;
