reserve p,q,r for FinSequence;
reserve u,v,x,y,y1,y2,z for object, A,D,X,Y for set;
reserve i,j,k,l,m,n for Nat;

theorem Th40:
  X is included_in_Seg & Y is included_in_Seg implies
  ( (for m,n being Nat st m in X & n in Y holds m < n) iff
  Sgm(X \/ Y) = Sgm(X) ^ Sgm(Y) )
proof
  assume that
a1: X is included_in_Seg and
a2: Y is included_in_Seg;
    consider i such that
A1: X c= Seg i by a1,FINSEQ_1:def 13;
    consider j such that
A2: Y c= Seg j by a2,FINSEQ_1:def 13;
  set r = Sgm(X \/ Y);
  set q = Sgm Y;
  set p = Sgm X;
  Seg i, Seg j are_c=-comparable by Th19;
  then Seg i c= Seg j or Seg j c= Seg i;
  then
  X c= Seg j or Y c= Seg i by A1,A2;
  then
A4: X \/ Y c= Seg i or X \/ Y c= Seg j by A1,A2,XBOOLE_1:8;
    reconsider X1 = X, Y1 = Y as finite set by A1,A2;
bbb: X1 \/ Y1 is included_in_Seg by A4,FINSEQ_1:def 13;
  thus (for m,n being Nat st m in X & n in Y holds m < n) implies
  Sgm(X \/ Y) = Sgm(X) ^ Sgm(Y)
  proof
    defpred P[Nat] means $1 in dom p implies r.$1 = p.$1;
    assume
A5: for m,n being Nat st m in X & n in Y holds m < n;
    X /\ Y = {}
    proof
      set x = the Element of X /\ Y;
      X = rng p by a1,FINSEQ_1:def 14;
      then
A6:   X c= NAT;
      assume
A7:   not thesis;
      then x in X by XBOOLE_0:def 4;
      then reconsider m = x as Element of NAT by A6;
A8:   m in Y by A7,XBOOLE_0:def 4;
      m in X by A7,XBOOLE_0:def 4;
      hence thesis by A5,A8;
    end;
    then
A9: X misses Y;
A10: len r = card(X1 \/ Y1) by a1,a2,Th37
      .= card X1 + card Y1 by A9,CARD_2:40
      .= len p + card Y1 by a1,Th37
      .= len p + len q by a2,Th37;
A11: now
      let k be Nat;
      assume
A12:  P[k];
      thus P[k+1]
      proof
        assume
A13:    k + 1 in dom p;
        then
A14:    p.(k + 1) in rng p by FUNCT_1:def 3;
        then reconsider n = p.(k + 1) as Element of NAT;
A15:    n in X by a1,A14,FINSEQ_1:def 14;
        len p <= len r by A10,NAT_1:12;
        then Seg(len p) c= Seg(len r) by FINSEQ_1:5;
        then dom p c= Seg(len r) by FINSEQ_1:def 3;
        then
A16:    dom p c= dom r by FINSEQ_1:def 3;
        then
A17:    r.(k + 1) in rng r by A13,FUNCT_1:def 3;
        then reconsider m = r.(k + 1) as Element of NAT;
        rng r = X \/ Y by bbb,FINSEQ_1:def 14;
        then
A18:    m in X \/ Y by A17;
        assume
A19:    r.(k + 1) <> p.(k + 1);
A20:    k + 1 in dom r by A13,A16;
        now
          per cases;
          suppose
A21:        k in dom p;
            then p.k in rng p by FUNCT_1:def 3;
            then reconsider n1 = p.k as Element of NAT;
            r.k in rng r by A16,A21,FUNCT_1:def 3;
            then reconsider m1 = r.k as Element of NAT;
            now
              per cases by A19,XXREAL_0:1;
              suppose
A22:            m < n;
A23:            1 <= k + 1 by A13,Th25;
                not m in Y by A5,A15,A22;
                then m in X by A18,XBOOLE_0:def 3;
                then m in rng p by a1,FINSEQ_1:def 14;
                then consider x being object such that
A24:            x in dom p and
A25:            p.x = m by FUNCT_1:def 3;
                reconsider x as Element of NAT by A24;
                x <= len p by A24,Th25;
                then
A26:            x < k + 1 by a1,A22,A25,A23,Th39;
                k + 1 in Seg(len r) by A20,FINSEQ_1:def 3;
                then
A27:            k + 1 <= len r by FINSEQ_1:1;
                k in Seg(len p) by A21,FINSEQ_1:def 3;
                then
A28:            1 <= k by FINSEQ_1:1;
                k < k + 1 by XREAL_1:29;
                then
A29:            n1 < m by bbb,A12,A21,A28,A27,FINSEQ_1:def 14;
A30:            k <= len p by A21,Th25;
                1 <= x by A24,Th25;
                then k < x by a1,A25,A29,A30,Th39;
                hence contradiction by A26,NAT_1:13;
              end;
              suppose
A31:            n < m;
A32:            1 <= k + 1 by A13,Th25;
                n in X \/ Y by A15,XBOOLE_0:def 3;
                then n in rng r by bbb,FINSEQ_1:def 14;
                then consider x being object such that
A33:            x in dom r and
A34:            r.x = n by FUNCT_1:def 3;
                reconsider x as Element of NAT by A33;
                x <= len r by A33,Th25;
                then
A35:            x < k + 1 by bbb,A31,A34,A32,Th39;
A36:            k + 1 <= len p by A13,Th25;
A37:            k < k + 1 by XREAL_1:29;
                1 <= k by A21,Th25;
                then
A38:            m1 < n by a1,A12,A21,A37,A36,FINSEQ_1:def 14;
A39:            k <= len r by A16,A21,Th25;
                1 <= x by A33,Th25;
                then k < x by bbb,A34,A38,A39,Th39;
                hence contradiction by A35,NAT_1:13;
              end;
            end;
            hence contradiction;
          end;
          suppose
A40:        not k in dom p;
A41:        k < k + 1 by XREAL_1:29;
            k < 1 or len p < k by A40,Th25;
            then
A42:        k = 0 or len p < k + 1 & k + 1 <= len p by A13,A41,Th25,NAT_1:14
,XXREAL_0:2;
            now
              per cases by A19,XXREAL_0:1;
              suppose
A43:            m < n;
                then not m in Y by A5,A15;
                then m in X by A18,XBOOLE_0:def 3;
                then m in rng p by a1,FINSEQ_1:def 14;
                then consider x being object such that
A44:            x in dom p and
A45:            p.x = m by FUNCT_1:def 3;
A46:            1 <= k + 1 by A13,Th25;
                reconsider x as Element of NAT by A44;
                x <= len p by A44,Th25;
                then x < k + 1 by a1,A43,A45,A46,Th39;
                hence contradiction by A42,A44,Th24,NAT_1:14;
              end;
              suppose
A47:            n < m;
A48:            1 <= k + 1 by A13,Th25;
                n in X \/ Y by A15,XBOOLE_0:def 3;
                then n in rng r by bbb,FINSEQ_1:def 14;
                then consider x being object such that
A49:            x in dom r and
A50:            r.x = n by FUNCT_1:def 3;
                reconsider x as Element of NAT by A49;
                x <= len r by A49,Th25;
                then x < k + 1 by bbb,A47,A50,A48,Th39;
                hence contradiction by A42,A49,Th24,NAT_1:14;
              end;
            end;
            hence contradiction;
          end;
        end;
        hence contradiction;
      end;
    end;
A51: P[0] by Th24;
A52: for k being Nat holds P[k] from NAT_1:sch 2(A51,A11);
    defpred P[Nat] means $1 in dom q implies r.(len p + $1) = q.$1;
A53: now
      let k be Nat;
      assume
A54:  P[k];
      thus P[k+1]
      proof
        set a = len p + (k + 1);
        assume
A55:    k + 1 in dom q;
        then k + 1 <= len q by Th25;
        then
A56:    a <= len r by A10,XREAL_1:7;
A57:    1 <= k + 1 by NAT_1:12;
        then 1 <= a by NAT_1:12;
        then
A58:    a in dom r by A56,Th25;
        then
A59:    r.a in rng r by FUNCT_1:def 3;
        reconsider m = r.a as Element of NAT by A59;
A60:    now
          assume m in X;
          then m in rng p by a1,FINSEQ_1:def 14;
          then consider x being object such that
A61:      x in dom p and
A62:      p.x = m by FUNCT_1:def 3;
          reconsider x as Element of NAT by A61;
          x <= len p by A61,Th25;
          then
A63:      x <= len r by A10,NAT_1:12;
A64:      r is one-to-one by bbb;
          1 <= x by A61,Th25;
          then
A65:      x in dom r by A63,Th25;
          r.x = r.a by A52,A61,A62;
          then x = a by A58,A64,A65;
          then len p + (k + 1) <= len p + 0 by A61,Th25;
          hence contradiction by XREAL_1:29;
        end;
A66:    q.(k + 1) in rng q by A55,FUNCT_1:def 3;
        then reconsider n = q.(k + 1) as Element of NAT;
A67:    n in Y by a2,A66,FINSEQ_1:def 14;
        assume
A68:    r.(len p + (k + 1)) <> q.(k + 1);
A69:    m in X \/ Y by bbb,A59,FINSEQ_1:def 14;
        now
          per cases;
          suppose
A70:        k in dom q;
            then q.k in rng q by FUNCT_1:def 3;
            then reconsider n1 = q.k as Element of NAT;
            1 <= k by A70,Th25;
            then
A71:        1 <= len p + k by NAT_1:12;
A72:        k <= len q by A70,Th25;
            then len p + k <= len r by A10,XREAL_1:7;
            then len p + k in dom r by A71,Th25;
            then r.(len p + k) in rng r by FUNCT_1:def 3;
            then reconsider m1 = r.(len p + k) as Element of NAT;
            now
              per cases by A68,XXREAL_0:1;
              suppose
A73:            m < n;
A74:            1 <= k + 1 by A55,Th25;
                m in Y by A69,A60,XBOOLE_0:def 3;
                then m in rng q by a2,FINSEQ_1:def 14;
                then consider x being object such that
A75:            x in dom q and
A76:            q.x = m by FUNCT_1:def 3;
                reconsider x as Element of NAT by A75;
                x <= len q by A75,Th25;
                then
A77:            x < k + 1 by a2,A73,A76,A74,Th39;
                len p + k < len p + k + 1 by XREAL_1:29;
                then
A78:            n1 < m by bbb,A54,A56,A70,A71,FINSEQ_1:def 14;
A79:            k <= len q by A70,Th25;
                1 <= x by A75,Th25;
                then k < x by a2,A76,A78,A79,Th39;
                hence contradiction by A77,NAT_1:13;
              end;
              suppose
A80:            n < m;
A81:            1 <= a by A57,NAT_1:12;
                n in X \/ Y by A67,XBOOLE_0:def 3;
                then n in rng r by bbb,FINSEQ_1:def 14;
                then consider x being object such that
A82:            x in dom r and
A83:            r.x = n by FUNCT_1:def 3;
                reconsider x as Element of NAT by A82;
                x <= len r by A82,Th25;
                then
A84:            x < len p + k + 1
                by a1,a2,A80,A83,A81,Th39;
A85:            k + 1 <= len q by A55,Th25;
A86:            k < k + 1 by XREAL_1:29;
                1 <= k by A70,Th25;
                then
A87:            m1 < n by a2,A54,A70,A86,A85,FINSEQ_1:def 14;
A88:            len p + k <= len r by A10,A72,XREAL_1:7;
                1 <= x by A82,Th25;
                then len p + k < x
                by a1,a2,A83,A87,A88,Th39;
                hence contradiction by A84,NAT_1:13;
              end;
            end;
            hence contradiction;
          end;
          suppose
A89:        not k in dom q;
A90:        k < k + 1 by XREAL_1:29;
            k < 1 or len q < k by A89,Th25;
            then
A91:        k = 0 or len q < k + 1 & k + 1 <= len q by A55,A90,Th25,NAT_1:14
,XXREAL_0:2;
            now
              per cases by A68,XXREAL_0:1;
              suppose
A92:            m < n;
A93:            1 <= k + 1 by A55,Th25;
                m in Y by A69,A60,XBOOLE_0:def 3;
                then m in rng q by a2,FINSEQ_1:def 14;
                then consider x being object such that
A94:            x in dom q and
A95:            q.x = m by FUNCT_1:def 3;
                reconsider x as Element of NAT by A94;
                x <= len q by A94,Th25;
                then x < k + 1 by a2,A92,A95,A93,Th39;
                hence contradiction by A91,A94,Th24,NAT_1:14;
              end;
              suppose
A96:           n < m;
A97:           1 <= len p + 1 by NAT_1:12;
                n in X \/ Y by A67,XBOOLE_0:def 3;
                then n in rng r by bbb,FINSEQ_1:def 14;
                then consider x being object such that
A98:           x in dom r and
A99:           r.x = n by FUNCT_1:def 3;
                reconsider x as Element of NAT by A98;
                x <= len r by A98,Th25;
                then x < len p + 1
                by a1,a2,A91,A96,A99,A97,Th39;
                then
A100:           x <= len p by NAT_1:13;
                1 <= x by A98,Th25;
                then
A101:           x in dom p by A100,Th25;
                then
A102:           p.x in rng p by FUNCT_1:def 3;
                n = p.x by A52,A99,A101;
                then n in X by a1,A102,FINSEQ_1:def 14;
                hence contradiction by A5,A67;
              end;
            end;
            hence contradiction;
          end;
        end;
        hence contradiction;
      end;
    end;
A103: P[0] by Th24;
    for k being Nat holds P[k] from NAT_1:sch 2(A103,A53);
    hence thesis by A10,A52,Th36;
  end;
  assume
A104: Sgm(X \/ Y) = Sgm(X) ^ Sgm(Y);
  let m,n be Nat;
  assume that
A105: m in X and
A106: n in Y;
  n in rng q by a2,A106,FINSEQ_1:def 14;
  then consider y being object such that
A107: y in dom q and
A108: q.y = n by FUNCT_1:def 3;
  reconsider y as Element of NAT by A107;
A109: n = r.(len p + y) by A104,A107,A108,FINSEQ_1:def 7;
  y <= len q by A107,Th25;
  then len p + y <= len p + len q by XREAL_1:7;
  then
A110: len p + y <= len r by A104,FINSEQ_1:22;
  m in rng(Sgm X) by a1,A105,FINSEQ_1:def 14;
  then consider x being object such that
A111: x in dom p and
A112: p.x = m by FUNCT_1:def 3;
  reconsider x as Element of NAT by A111;
A113: x in Seg(len p) by A111,FINSEQ_1:def 3;
  then
A114: 1 <= x by FINSEQ_1:1;
A115: x <= len p by A113,FINSEQ_1:1;
  y <> 0 by A107,Th24;
  then
A116: x < len p + y by A115,NAT_1:16,XXREAL_0:2;
  m = r.x by A104,A111,A112,FINSEQ_1:def 7;
  hence thesis by bbb,A109,A114,A116,A110,FINSEQ_1:def 14;
end;
