reserve i,j,k,n for Nat;
reserve x,x1,x2,x3,y1,y2,y3 for set;

theorem
  Necklace 4, ComplRelStr Necklace 4 are_isomorphic
proof
  set g = (0,1) --> (1,3), h = (2,3) --> (0,2), f = g +* h;
  set S = Necklace 4, T = ComplRelStr Necklace 4;
A1: rng h = {0,2} by FUNCT_4:64;
A2: rng g = {1,3} by FUNCT_4:64;
A3: rng f c= the carrier of T
  proof
    let x be object;
    assume
A4: x in rng f;
A5: rng f c= rng g \/ rng h by FUNCT_4:17;
    rng g \/ rng h = {1,3,0,2} by A2,A1,ENUMSET1:5
      .= {0,1,2,3} by ENUMSET1:69;
    then x in 4 by A4,A5,CARD_1:52;
    then x in the carrier of S by Th19;
    hence thesis by Def8;
  end;
A6: dom f = dom (0,1) --> (1,3) \/ dom (2,3) --> (0,2) by FUNCT_4:def 1
    .= {0,1} \/ dom (2,3) --> (0,2) by FUNCT_4:62
    .= {0,1} \/ {2,3} by FUNCT_4:62
    .= {0,1,2,3} by ENUMSET1:5;
  then
A7: dom f = the carrier of S by Th19,CARD_1:52;
  then reconsider f as Function of S,T by A3,FUNCT_2:def 1,RELSET_1:4;
  take f;
  per cases;
  case that
    S is non empty and
    T is non empty;
    set A = the InternalRel of T;
A8: rng (0 .--> 1) misses rng (1 .--> 3)
    proof
      assume rng (0 .--> 1) meets rng (1 .--> 3);
      then consider x being object such that
A9:   x in rng (0 .--> 1) and
A10:  x in rng (1 .--> 3) by XBOOLE_0:3;
      rng (0 .--> 1) = {1} by FUNCOP_1:8;
      then rng (1 .--> 3) = {3} & x = 1 by A9,FUNCOP_1:8,TARSKI:def 1;
      hence contradiction by A10,TARSKI:def 1;
    end;
A11: rng g misses rng h
    proof
      assume rng g meets rng h;
      then consider x being object such that
A12:  x in rng g and
A13:  x in rng h by XBOOLE_0:3;
      x = 1 or x = 3 by A2,A12,TARSKI:def 2;
      hence contradiction by A1,A13,TARSKI:def 2;
    end;
    set B = {[1,3],[3,1],[0,2],[2,0],[0,3],[3,0]};
A14: rng (2 .--> 0) misses rng (3 .--> 2)
    proof
      assume rng (2 .--> 0) meets rng (3 .--> 2);
      then consider x being object such that
A15:  x in rng (2 .--> 0) and
A16:  x in rng (3 .--> 2) by XBOOLE_0:3;
      rng (2 .--> 0) = {0} by FUNCOP_1:8;
      then rng (3 .--> 2) = {2} & x = 0 by A15,FUNCOP_1:8,TARSKI:def 1;
      hence contradiction by A16,TARSKI:def 1;
    end;
    h = (2 .--> 0) +* (3 .-->2) by FUNCT_4:def 4;
    then
A17: h is one-to-one by A14,FUNCT_4:92;
A18: dom g misses dom h
    proof
      assume dom g meets dom h;
      then consider x being object such that
A19:  x in dom g and
A20:  x in dom h by XBOOLE_0:3;
      x = 0 or x = 1 by A19,TARSKI:def 2;
      hence contradiction by A20,TARSKI:def 2;
    end;
    then
A21: rng f = rng g \/ rng h by FRECHET:35,PARTFUN1:56
      .= {1,3,0,2} by A2,A1,ENUMSET1:5
      .= {0,1,2,3} by ENUMSET1:69
      .= the carrier of S by Th19,CARD_1:52
      .= the carrier of T by Def8;
    g = (0 .--> 1) +* (1 .-->3) by FUNCT_4:def 4;
    then
A22: g is one-to-one by A8,FUNCT_4:92;
    hence f is one-to-one by A17,A11,FUNCT_4:92;
    then reconsider F = f" as Function of T,S by A21,FUNCT_2:25;
A23: B c= A
    proof
      set C = the carrier of S;
      let x be object;
      assume x in B;
      then
A24:  x = [1,3] or x = [3,1] or x = [0,2] or x = [2,0] or x = [0,3] or x
      = [3,0] by ENUMSET1:def 4;
A25:  2 in C & 3 in C by A6,A7,ENUMSET1:def 2;
      0 in C & 1 in C by A6,A7,ENUMSET1:def 2;
      then reconsider x9=x as Element of [:C,C:] by A24,A25,ZFMISC_1:87;
      not x9 in the InternalRel of S
      proof
        assume x9 in the InternalRel of S;
        then consider i being Element of NAT such that
        i+1< 4 and
A26:    x9= [i,i+1] or x9= [i+1,i] by Th18;
        i=1 & i+1=3 or i=3 & i+1=1 or i=0 & i+1=2 or i=2 & i+1=0 or i=0 &
        i+1=3 or i=3 & i+1=0 by A24,A26,XTUPLE_0:1;
        hence contradiction;
      end;
      then
A27:  x9 in (the InternalRel of S)` by SUBSET_1:29;
      not x in id (the carrier of S) by A24,RELAT_1:def 10;
      then x in (the InternalRel of S)` \ id (the carrier of S) by A27,
XBOOLE_0:def 5;
      hence thesis by Def8;
    end;
    thus f is monotone
    proof
A28:  dom h = {2,3} by FUNCT_4:62;
      then 2 in dom h by TARSKI:def 2;
      then
A29:  f.2 = h.2 by FUNCT_4:13
        .= 0 by FUNCT_4:63;
      3 in dom h by A28,TARSKI:def 2;
      then
A30:  f.3 = h.3 by FUNCT_4:13
        .= 2 by FUNCT_4:63;
A31:  dom g = {0,1} by FUNCT_4:62;
      then 0 in dom g by TARSKI:def 2;
      then
A32:  f.0 = g.0 by A18,FUNCT_4:16
        .= 1 by FUNCT_4:63;
      1 in dom g by A31,TARSKI:def 2;
      then
A33:  f.1 = g.1 by A18,FUNCT_4:16
        .= 3 by FUNCT_4:63;
      let x,y being Element of S;
      assume x <= y;
      then
A34:  [x,y] in the InternalRel of S by ORDERS_2:def 5;
      the carrier of S = 4 by Th19;
      then x in Segm 4 & y in Segm 4;
      then reconsider i = x, j = y as Nat;
A35:  i = j + 1 or j = i + 1 by A34,Th23;
      let a,b being Element of T such that
A36:  a = f.x & b = f.y;
      per cases by A6,A7,ENUMSET1:def 2;
      suppose
        x = 0 & y = 0;
        hence thesis by A35;
      end;
      suppose
        x = 0 & y = 1;
        then [a,b] in B by A36,A32,A33,ENUMSET1:def 4;
        hence thesis by A23,ORDERS_2:def 5;
      end;
      suppose
        x = 0 & y = 2;
        hence thesis by A35;
      end;
      suppose
        x = 0 & y = 3;
        hence thesis by A35;
      end;
      suppose
        x = 1 & y = 0;
        then [a,b] in B by A36,A32,A33,ENUMSET1:def 4;
        hence thesis by A23,ORDERS_2:def 5;
      end;
      suppose
        x = 1 & y = 1;
        hence thesis by A35;
      end;
      suppose
        x = 1 & y = 2;
        then [a,b] in B by A36,A33,A29,ENUMSET1:def 4;
        hence thesis by A23,ORDERS_2:def 5;
      end;
      suppose
        x = 1 & y = 3;
        hence thesis by A35;
      end;
      suppose
        x = 2 & y = 0;
        hence thesis by A35;
      end;
      suppose
        x = 2 & y = 1;
        then [a,b] in B by A36,A33,A29,ENUMSET1:def 4;
        hence thesis by A23,ORDERS_2:def 5;
      end;
      suppose
        x = 2 & y = 2;
        hence thesis by A35;
      end;
      suppose
        x = 2 & y = 3;
        then [a,b] in B by A36,A29,A30,ENUMSET1:def 4;
        hence thesis by A23,ORDERS_2:def 5;
      end;
      suppose
        x = 3 & y = 0;
        hence thesis by A35;
      end;
      suppose
        x = 3 & y = 1;
        hence thesis by A35;
      end;
      suppose
        x = 3 & y = 2;
        then [a,b] in B by A36,A29,A30,ENUMSET1:def 4;
        hence thesis by A23,ORDERS_2:def 5;
      end;
      suppose
        x = 3 & y = 3;
        hence thesis by A35;
      end;
    end;
    take F;
    thus F = f";
    thus F is monotone
    proof
      let x,y being Element of T;
      assume x <= y;
      then [x,y] in the InternalRel of T by ORDERS_2:def 5;
      then
A37:  [x,y] in (the InternalRel of S)` \ id (the carrier of S) by Def8;
      then not [x,y] in id (the carrier of S) by XBOOLE_0:def 5;
      then
A38:  not x in (the carrier of S) or x <> y by RELAT_1:def 10;
      [x,y] in (the InternalRel of S)` implies not [x,y] in (the
      InternalRel of S) by XBOOLE_0:def 5;
      then
A39:  not [x,y] in ({[k,k+1] where k is Element of NAT:k+1 < 4} \/ {[l+1,
      l] where l is Element of NAT:l+1 < 4}) by A37,Th17,XBOOLE_0:def 5;
      then
A40:  not [x,y] in {[k+1,k] where k is Element of NAT:k+1 < 4} by
XBOOLE_0:def 3;
A41:  the carrier of T = the carrier of S by Def8
        .= Segm 4 by Th19;
      then x in Segm 4 & y in Segm 4;
      then x is natural & y is natural;
      then reconsider i = x, j = y as Element of NAT by ORDINAL1:def 12;
A42:  x in (the carrier of T);
A43:  not [x,y] in {[k,k+1] where k is Element of NAT:k+1 < 4} by A39,
XBOOLE_0:def 3;
A44:  i + 1 <> j & j + 1 <> i & i <> j
      proof
        hereby
          assume
A45:      i+1=j or j+1=i;
          per cases by A45;
          suppose
A46:        i+1 = j;
            then i+1 < 4 by A41,NAT_1:44;
            hence contradiction by A43,A46;
          end;
          suppose
A47:        j+1=i;
            then j+1 < 4 by A41,NAT_1:44;
            hence contradiction by A40,A47;
          end;
        end;
        thus thesis by A38,A42,Def8;
      end;
A48:  h" = (0,2) --> (2,3) by Th9;
      then
A49:  dom (h") = {0,2} by FUNCT_4:62;
      then
A50:  0 in dom (h") by TARSKI:def 2;
A51:  F.0 = (g" +* h").0 by A22,A17,A18,A11,Th6
        .= h".0 by A50,FUNCT_4:13
        .= 2 by A48,FUNCT_4:63;
A52:  g" = (1,3) --> (0,1) by Th9;
      then
A53:  dom (g") = {1,3} by FUNCT_4:62;
      then
A54:  1 in dom (g") by TARSKI:def 2;
A55:  dom (g") misses dom (h")
      proof
        assume dom (g") meets dom (h");
        then consider x being object such that
A56:    x in dom (g") and
A57:    x in dom (h") by XBOOLE_0:3;
        x = 1 or x = 3 by A53,A56,TARSKI:def 2;
        hence contradiction by A49,A57,TARSKI:def 2;
      end;
A58:  F.1 = (g" +* h").1 by A22,A17,A18,A11,Th6
        .= g".1 by A55,A54,FUNCT_4:16
        .= 0 by A52,FUNCT_4:63;
A59:  2 in dom (h") by A49,TARSKI:def 2;
A60:  F.2 = (g" +* h").2 by A22,A17,A18,A11,Th6
        .= h".2 by A59,FUNCT_4:13
        .= 3 by A48,FUNCT_4:63;
A61:  3 in dom (g") by A53,TARSKI:def 2;
A62:  F.3 = (g" +* h").3 by A22,A17,A18,A11,Th6
        .= g".3 by A55,A61,FUNCT_4:16
        .= 1 by A52,FUNCT_4:63;
      let a,b being Element of S such that
A63:  a = F.x and
A64:  b = F.y;
      per cases by A41,CARD_1:52,ENUMSET1:def 2;
      suppose
        x = 0 & y = 0;
        hence thesis by A44;
      end;
      suppose
        x = 0 & y = 1;
        hence thesis by A44;
      end;
      suppose
A65:    x = 0 & y = 2;
        then b = 2+1 by A64,A60;
        then [a,b] in the InternalRel of S by A63,A51,A65,Th24;
        hence thesis by ORDERS_2:def 5;
      end;
      suppose
A66:    x = 0 & y = 3;
        then a = 1+1 by A63,A51;
        then [a,b] in the InternalRel of S by A64,A62,A66,Th24;
        hence thesis by ORDERS_2:def 5;
      end;
      suppose
        x = 1 & y = 0;
        hence thesis by A44;
      end;
      suppose
        x = 1 & y = 1;
        hence thesis by A44;
      end;
      suppose
        x = 1 & y = 2;
        hence thesis by A44;
      end;
      suppose
A67:    x = 1 & y = 3;
        then b = 0+1 by A64,A62;
        then [a,b] in the InternalRel of S by A63,A58,A67,Th24;
        hence thesis by ORDERS_2:def 5;
      end;
      suppose
A68:    x = 2 & y = 0;
        then a = 2+1 by A63,A60;
        then [a,b] in the InternalRel of S by A64,A51,A68,Th24;
        hence thesis by ORDERS_2:def 5;
      end;
      suppose
        x = 2 & y = 1;
        hence thesis by A44;
      end;
      suppose
        x = 2 & y = 2;
        hence thesis by A44;
      end;
      suppose
        x = 2 & y = 3;
        hence thesis by A44;
      end;
      suppose
A69:    x = 3 & y = 0;
        then b = 1+1 by A64,A51;
        then [a,b] in the InternalRel of S by A63,A62,A69,Th24;
        hence thesis by ORDERS_2:def 5;
      end;
      suppose
A70:    x = 3 & y = 1;
        then a = 0+1 by A63,A62;
        then [a,b] in the InternalRel of S by A64,A58,A70,Th24;
        hence thesis by ORDERS_2:def 5;
      end;
      suppose
        x = 3 & y = 2;
        hence thesis by A44;
      end;
      suppose
        x = 3 & y = 3;
        hence thesis by A44;
      end;
    end;
  end;
  case
    S is empty or T is empty;
    hence thesis;
  end;
end;
