reserve X,Y,Z for set, x,y,z for object;
reserve i,j for Nat;
reserve A,B,C for Subset of X;
reserve R,R1,R2 for Relation of X;
reserve AX for Subset of [:X,X:];
reserve SFXX for Subset-Family of [:X,X:];
reserve EqR,EqR1,EqR2,EqR3 for Equivalence_Relation of X;

theorem
  x in X implies ([x,y] in EqR1 "\/" EqR2 iff ex f being FinSequence st
1 <= len f & x = f.1 & y = f.(len f) & for i st 1 <= i & i < len f holds [f.i,f
  .(i+1)] in EqR1 \/ EqR2)
proof
  assume
A1: x in X;
  thus [x,y] in EqR1 "\/" EqR2 implies ex f being FinSequence st 1 <= len f &
  x = f.1 & y = f.(len f) & for i st 1 <= i & i < len f holds [f.i,f.(i+1)] in
  EqR1 \/ EqR2
  proof
    defpred P[object,object] means
ex f being FinSequence st (1 <= len f & $1 = f.1
& $2 = f.(len f) & for i st 1 <= i & i < len f holds [f.i,f.(i+1)] in EqR1 \/
    EqR2);
    consider Y being Relation of X,X such that
A2: for x,y holds [x,y] in Y iff x in X & y in X & P[x,y] from
    RELSET_1:sch 1;
A3: Y is_transitive_in X
    proof
      let x,y,z;
      assume that
A4:   x in X and
A5:   y in X and
A6:   z in X and
A7:   [x,y] in Y and
A8:   [y,z] in Y;
      consider g being FinSequence such that
A9:   1 <= len g and
A10:  y = g.1 and
A11:  z = g.(len g) and
A12:  for i st 1 <= i & i < len g holds [g.i,g.(i+1)] in EqR1 \/ EqR2 by A2,A8;
      consider f being FinSequence such that
A13:  1 <= len f and
A14:  x = f.1 and
A15:  y = f.(len f) and
A16:  for i st 1 <= i & i < len f holds [f.i,f.(i+1)] in EqR1 \/ EqR2 by A2,A7;
      set h = f^g;
A17:  len h = len f + len g by FINSEQ_1:22;
A18:  len f + 1 <= len f + len g by A9,XREAL_1:7;
      then
A19:  h.(len h) = g.(len g + len f - len f) by A17,FINSEQ_1:23
        .= g.(len g);
A20:  for i st 1 <= i & i < len h holds [h.i,h.(i+1)] in EqR1 \/ EqR2
      proof
        let i;
        assume that
A21:    1 <= i and
A22:    i < len h;
A23:    1 <= i & i < len f or i = len f or len f < i by A21,XXREAL_0:1;
        now
          per cases by A22,A23,NAT_1:13;
          suppose
A24:        1 <= i & i < len f;
            then 1 <= i + 1 & i + 1 <= len f by NAT_1:13;
            then i + 1 in Seg len f by FINSEQ_1:1;
            then i + 1 in dom f by FINSEQ_1:def 3;
            then
A25:        h.(i + 1) = f.(i + 1) by FINSEQ_1:def 7;
            i in Seg(len f) by A24,FINSEQ_1:1;
            then i in dom f by FINSEQ_1:def 3;
            then h.i = f.i by FINSEQ_1:def 7;
            hence thesis by A16,A24,A25;
          end;
          suppose
A26:        i = len f;
            len f in Seg len f by A13,FINSEQ_1:1;
            then len f in dom f by FINSEQ_1:def 3;
            then
A27:        h.i = y by A15,A26,FINSEQ_1:def 7;
A28:        [y,y] in EqR1 by A5,Th5;
            h.(i + 1) = g.(1 + len f - len f) by A18,A26,FINSEQ_1:23
              .= y by A10;
            hence thesis by A27,A28,XBOOLE_0:def 3;
          end;
          suppose
A29:        len f + 1 <= i & i < len h;
            then len f < i by NAT_1:13;
            then reconsider k = i - len f as Element of NAT by NAT_1:21;
            i < len f + len g by A29,FINSEQ_1:22;
            then
A30:        i - len f < len g by XREAL_1:19;
            len f + 1 <= i + 1 & i + 1 <= len f + len g by A17,A29,NAT_1:13;
            then
A31:        h.(i + 1) = g.(1 + i - len f) by FINSEQ_1:23
              .= g.((i - len f) + 1);
            1 + len f - len f <= i - len f by A29,XREAL_1:9;
            then [g.k,g.(k + 1)] in EqR1 \/ EqR2 by A12,A30;
            hence thesis by A17,A29,A31,FINSEQ_1:23;
          end;
        end;
        hence thesis;
      end;
      1 in Seg(len f) by A13,FINSEQ_1:1;
      then 1 in dom f by FINSEQ_1:def 3;
      then
A32:  x = h.1 by A14,FINSEQ_1:def 7;
      1 <= len h by A13,A17,NAT_1:12;
      hence thesis by A2,A4,A6,A11,A32,A19,A20;
    end;
A33: Y is_symmetric_in X
    proof
      let x,y;
      assume that
A34:  x in X & y in X and
A35:  [x,y] in Y;
      consider f being FinSequence such that
A36:  1 <= len f and
A37:  x = f.1 and
A38:  y = f.(len f) and
A39:  for i st 1 <= i & i < len f holds [f.i,f.(i+1)] in EqR1 \/ EqR2
      by A2,A35;
      defpred P[Nat,object] means $2 = f.(1 + (len f) - $1);
A40:  for k be Nat st k in Seg(len f) ex z being object st P[k,z];
      consider g being FinSequence such that
A41:  dom g = Seg(len f) & for k being Nat st k in Seg(len f) holds P
      [k,g.k] from FINSEQ_1:sch 1(A40);
A42:  len f = len g by A41,FINSEQ_1:def 3;
A43:  for j st 1 <= j & j < len g holds [g.j,g.(j+1)] in EqR1 \/ EqR2
      proof
        let j;
        assume that
A44:    1 <= j and
A45:    j < len g;
        reconsider k = (len f) - j as Element of NAT by A42,A45,NAT_1:21;
        j - (len f) < (len f) - (len f) by A42,A45,XREAL_1:9;
        then - ((len f) - j) < - 0;
        then 0 < k;
        then
A46:    0 + 1 <= k by NAT_1:13;
        - j < -0 by A44,XREAL_1:24;
        then (len f) + -j < 0 + (len f) by XREAL_1:6;
        then
A47:    [f.k,f.(k + 1)] in EqR1 \/ EqR2 by A39,A46;
A48:    now
          per cases by A47,XBOOLE_0:def 3;
          suppose
            [f.k,f.(k + 1)] in EqR1;
            then [f.(k + 1),f.k] in EqR1 by Th6;
            hence [f.(k + 1),f.k] in EqR1 \/ EqR2 by XBOOLE_0:def 3;
          end;
          suppose
            [f.k,f.(k + 1)] in EqR2;
            then [f.(k + 1),f.k] in EqR2 by Th6;
            hence [f.(k + 1),f.k] in EqR1 \/ EqR2 by XBOOLE_0:def 3;
          end;
        end;
        1 <= (j + 1) & (j + 1) <= len f by A42,A45,NAT_1:12,13;
        then (j + 1) in Seg(len f) by FINSEQ_1:1;
        then
A49:    g.(j + 1) = f.((len f) + 1 - (1 + j)) by A41
          .= f.((len f) - j);
        j in Seg(len f) by A42,A44,A45,FINSEQ_1:1;
        then g.j = f.(1 + (len f) - j) by A41
          .= f.(((len f) - j) + 1);
        hence thesis by A49,A48;
      end;
      len f in Seg(len f) by A36,FINSEQ_1:1;
      then g.(len f) = f.(1 + (len f) - len f) by A41
        .= f.(1 + 0);
      then
A50:  x = g.(len g) by A37,A41,FINSEQ_1:def 3;
      1 in Seg(len f) by A36,FINSEQ_1:1;
      then
A51:  g.1 = f.((len f) + 1 - 1) by A41
        .= f.(len f);
      1 <= len g by A36,A41,FINSEQ_1:def 3;
      hence thesis by A2,A34,A38,A51,A50,A43;
    end;
    Y is_reflexive_in X
    proof
      let x such that
A52:  x in X;
      set g = <*x*>;
A53:  for i st 1 <= i & i < len g holds [g.i,g.(i+1)] in EqR1 \/ EqR2 by
FINSEQ_1:40;
      len g = 1 & g.1 = x by FINSEQ_1:40;
      hence thesis by A2,A52,A53;
    end;
    then field Y = X & dom Y = X by ORDERS_1:13;
    then reconsider R1 = Y as Equivalence_Relation of X by A33,A3,
PARTFUN1:def 2,RELAT_2:def 11,def 16;
    for x,y being object holds [x,y] in EqR1 \/ EqR2 implies [x,y] in R1
    proof
      let x,y be object;
      assume
A54:  [x,y] in EqR1 \/ EqR2;
      set g = <*x,y*>;
A55:  len g = 1 + 1 by FINSEQ_1:44;
A57:  for i st 1 <= i & i < len g holds [g.i,g.(i+1)] in EqR1 \/ EqR2
      proof
        let i;
        assume that
A58:    1 <= i and
A59:    i < len g;
        i <= 1 by A55,A59,NAT_1:13;
        then 1 = i by A58,XXREAL_0:1;
        hence thesis by A54;
      end;
      len g = 2 by FINSEQ_1:44;
      then
A60:  g.1 = x & g.(len g) = y;
      x in X & y in X by A54,Lm1;
      hence thesis by A2,A55,A60,A57;
    end;
    then EqR1 \/ EqR2 c= R1;
    then
A61: EqR1 "\/" EqR2 c= R1 by Def2;
    assume [x,y] in EqR1 "\/" EqR2;
    then consider f being FinSequence such that
A62: 1 <= len f & x = f.1 &( y = f.(len f) & for i st 1 <= i & i <
    len f holds [f.i,f.(i+1)] in EqR1 \/ EqR2 ) by A2,A61;
    take f;
    thus thesis by A62;
  end;
  given f being FinSequence such that
A63: 1 <= len f and
A64: x = f.1 and
A65: y = f.(len f) and
A66: for i st 1 <= i & i < len f holds [f.i,f.(i+1)] in EqR1 \/ EqR2;
  defpred P[Nat] means 1 <= $1 & $1 <= len f implies [f.1,f.$1] in
  EqR1 "\/" EqR2;
A67: now
    let i;
    assume
A68: P[i];
    thus P[i+1]
    proof
      assume that
A69:  1 <= i + 1 and
A70:  i + 1 <= len f;
A71:  1 <= i or 1 = i + 1 by A69,NAT_1:8;
A72:  EqR1 \/ EqR2 c= EqR1 "\/" EqR2 by Def2;
A73:  i < len f by A70,NAT_1:13;
      now
        per cases by A71;
        suppose
A74:      1 <= i;
          then [f.i,f.(i+1)] in EqR1 \/ EqR2 by A66,A73;
          hence thesis by A68,A70,A72,A74,Th7,NAT_1:13;
        end;
        suppose
A75:      0 = i;
          [f.1,f.1] in EqR1 by A1,A64,Th5;
          then [f.1,f.1] in EqR1 \/ EqR2 by XBOOLE_0:def 3;
          hence thesis by A72,A75;
        end;
      end;
      hence thesis;
    end;
  end;
A76: P[0];
  for i holds P[i] from NAT_1:sch 2(A76,A67);
  hence thesis by A63,A64,A65;
end;
