reserve n for Nat;

theorem Th11:
  for D be non empty set for f be FinSequence of D st f is
almost-one-to-one for p be Element of D holds Rotate(f,p) is almost-one-to-one
proof
  let D be non empty set;
  let f be FinSequence of D;
  assume
A1: f is almost-one-to-one;
  let p be Element of D;
  per cases;
  suppose
A2: p in rng f;
    then 0+1 <= p..f by FINSEQ_4:21;
    then
A3: p..f - 1 >= 0 by XREAL_1:19;
A4: len (f:-p) = len f - p..f + 1 by A2,FINSEQ_5:50;
    let i,j be Nat;
    assume that
A5: i in dom Rotate(f,p) and
A6: j in dom Rotate(f,p) and
A7: i <> 1 or j <> len Rotate(f,p) and
A8: i <> len Rotate(f,p) or j <> 1 and
A9: Rotate(f,p).i = Rotate(f,p).j;
A10: 0+1 <= i by A5,FINSEQ_3:25;
A11: dom Rotate(f,p) = dom f by FINSEQ_6:180;
    then
A12: i <= len f by A5,FINSEQ_3:25;
    then
A13: i - len f <= len f-len f by XREAL_1:9;
A14: j <= len f by A6,A11,FINSEQ_3:25;
    then
A15: j - len f <= len f-len f by XREAL_1:9;
A16: len Rotate(f,p) = len f by FINSEQ_6:179;
A17: 0+1 <= j by A6,FINSEQ_3:25;
    then
A18: j - 1 >= 0 by XREAL_1:19;
A19: now
      assume that
A20:  i -' 1 + p..f = len f and
A21:  j -' 1 + p..f = 1;
      j -' 1 + (p..f - 1) = 0 by A21;
      then
A22:  j -' 1 = 0 by A3;
      then j - 1 = 0 by A18,XREAL_0:def 2;
      hence contradiction by A8,A16,A10,A20,A21,A22,XREAL_1:235;
    end;
A23: p..f <= len f by A2,FINSEQ_4:21;
A24: i - 1 >= 0 by A10,XREAL_1:19;
A25: now
      assume that
A26:  i -' 1 + p..f = 1 and
A27:  j -' 1 + p..f = len f;
      i -' 1 + (p..f - 1) = 0 by A26;
      then
A28:  i -' 1 = 0 by A3;
      then i - 1 = 0 by A24,XREAL_0:def 2;
      hence contradiction by A7,A16,A17,A26,A27,A28,XREAL_1:235;
    end;
    now
      per cases;
      suppose
A29:    i <= len(f:-p);
        then i in dom(f:-p) by A10,FINSEQ_3:25;
        then i -' 1 + 1 in dom(f:-p) by A10,XREAL_1:235;
        then
A30:    i -' 1 + p..f in dom f by A2,FINSEQ_5:51;
        Rotate(f,p)/.i = f/.(i -' 1 + p..f) by A2,A10,A29,FINSEQ_6:174;
        then
A31:    Rotate(f,p).i = f/.(i -' 1 + p..f) by A5,PARTFUN1:def 6;
        now
          per cases;
          suppose
A32:        j <= len(f:-p);
            then j in dom(f:-p) by A17,FINSEQ_3:25;
            then j -' 1 + 1 in dom(f:-p) by A17,XREAL_1:235;
            then
A33:        j -' 1 + p..f in dom f by A2,FINSEQ_5:51;
            Rotate(f,p)/.j = f/.(j -' 1 + p..f) by A2,A17,A32,FINSEQ_6:174;
            then
A34:        f/.(i -' 1 + p..f) = f/.(j -' 1 + p..f) by A6,A9,A31,PARTFUN1:def 6
;
            f.(i -' 1 + p..f) = f/.(i -' 1 + p..f) by A30,PARTFUN1:def 6
              .= f.(j -' 1 + p..f) by A34,A33,PARTFUN1:def 6;
            then i -' 1 + p..f = j -' 1 + p..f by A1,A25,A19,A30,A33;
            hence thesis by A10,A17,XREAL_1:234;
          end;
          suppose
A35:        j > len(f:-p);
            then Rotate(f,p)/.j = f/.(j + p..f -' len f) by A2,A14,
              FINSEQ_6:177;
            then
A36:        f
/.(i -' 1 + p..f) = f/.(j + p..f -' len f) by A6,A9,A31,PARTFUN1:def 6;
A37:        j - (len f - p..f) > 1 by A4,A35,XREAL_1:20;
            then
A38:        j + p..f - len f > 1;
            then
A39:        j + p..f -' len f >= 1 by XREAL_0:def 2;
            j + p..f <= len f + len f by A23,A14,XREAL_1:7;
            then j + p..f - len f <= len f by XREAL_1:20;
            then j + p..f -' len f <= len f by A37,XREAL_0:def 2;
            then
A40:        j + p..f -' len f in dom f by A39,FINSEQ_3:25;
A41:        now
              assume that
A42:          i -' 1 + p..f = 1 and
A43:          j + p..f -' len f = len f;
              j + p..f - len f = len f by A37,A43,XREAL_0:def 2;
              then j + p..f = len f + len f;
              then
A44:          j >= len f by A23,XREAL_1:8;
              i -' 1 + (p..f - 1) = 0 by A42;
              then i -' 1 = 0 by A3;
              then i - 1 = 0 by A24,XREAL_0:def 2;
              hence contradiction by A7,A16,A14,A44,XXREAL_0:1;
            end;
A45:        i -' 1 + p..f <> len f or j + p..f -' len f <> 1 by A38,
XREAL_0:def 2;
            f.(i -' 1 + p..f) = f/.(i -' 1 + p..f) by A30,PARTFUN1:def 6
              .= f.(j + p..f -' len f) by A36,A40,PARTFUN1:def 6;
            then i -' 1 + p..f = j + p..f -' len f by A1,A30,A41,A45,A40;
            then
A46:        i -' 1 + p..f = j + p..f - len f by A37,XREAL_0:def 2;
            then
A47:        j - len f = 0 by A15;
            i - 1 = 0 by A24,A15,A46,XREAL_0:def 2;
            hence thesis by A7,A47,FINSEQ_6:179;
          end;
        end;
        hence thesis;
      end;
      suppose
A48:    i > len(f:-p);
        then
A49:    i - (len f - p..f) > 1 by A4,XREAL_1:20;
        i + p..f <= len f + len f by A23,A12,XREAL_1:7;
        then i + p..f - len f <= len f by XREAL_1:20;
        then
A50:    i + p..f -' len f <= len f by A49,XREAL_0:def 2;
A51:    i + p..f - len f > 1 by A49;
        then i + p..f -' len f >= 1 by XREAL_0:def 2;
        then
A52:    i + p..f -' len f in dom f by A50,FINSEQ_3:25;
A53:    Rotate(f,p)/.i = f/.(i+p..f -' len f) by A2,A12,A48,FINSEQ_6:177;
        now
          per cases;
          suppose
A54:        j <= len(f:-p);
A55:        now
              assume that
A56:          j -' 1 + p..f = 1 and
A57:          i + p..f -' len f = len f;
              i + p..f - len f = len f by A49,A57,XREAL_0:def 2;
              then i + p..f = len f + len f;
              then
A58:          i >= len f by A23,XREAL_1:8;
              j -' 1 + (p..f - 1) = 0 by A56;
              then j -' 1 = 0 by A3;
              then j - 1 = 0 by A18,XREAL_0:def 2;
              hence contradiction by A8,A16,A12,A58,XXREAL_0:1;
            end;
            Rotate(f,p)/.j = f/.(j -' 1 + p..f) by A2,A17,A54,FINSEQ_6:174;
            then Rotate(f,p).j = f/.(j -' 1 + p..f) by A6,PARTFUN1:def 6;
            then
A59:        f
/.(j -' 1 + p..f) = f/.(i + p..f -' len f) by A5,A9,A53,PARTFUN1:def 6;
A60:        j -' 1 + p..f <> len f or i + p..f -' len f <> 1 by A51,
XREAL_0:def 2;
            j in dom(f:-p) by A17,A54,FINSEQ_3:25;
            then j -' 1 + 1 in dom(f:-p) by A17,XREAL_1:235;
            then
A61:        j -' 1 + p..f in dom f by A2,FINSEQ_5:51;
            then f.(j -' 1 + p..f) = f/.(j -' 1 + p..f) by PARTFUN1:def 6
              .= f.(i + p..f -' len f) by A52,A59,PARTFUN1:def 6;
            then j -' 1 + p..f = i + p..f -' len f by A1,A52,A61,A55,A60;
            then
A62:        j -' 1 + p..f = i + p..f - len f by A49,XREAL_0:def 2;
            then
A63:        i - len f = 0 by A13;
            j - 1 = 0 by A18,A13,A62,XREAL_0:def 2;
            hence thesis by A8,A63,FINSEQ_6:179;
          end;
          suppose
A64:        j > len(f:-p);
            then Rotate(f,p)/.j = f/.(j + p..f -' len f) by A2,A14,
            FINSEQ_6:177;
            then Rotate(f,p).j = f/.(j + p..f -' len f) by A6,PARTFUN1:def 6;
            then
A65:        f/.(j + p..f -' len f) = f/.(i + p..f -' len f) by A5,A9,A53,
PARTFUN1:def 6;
A66:        i+p..f -' len f <> 1 or j + p..f -' len f <> len f by A51,
XREAL_0:def 2;
A67:        j - (len f - p..f) > 1 by A4,A64,XREAL_1:20;
            then
A68:        j + p..f - len f > 1;
            then
A69:        j + p..f -' len f >= 1 by XREAL_0:def 2;
            j + p..f <= len f + len f by A23,A14,XREAL_1:7;
            then j + p..f - len f <= len f by XREAL_1:20;
            then j + p..f -' len f <= len f by A67,XREAL_0:def 2;
            then
A70:        j + p..f -' len f in dom f by A69,FINSEQ_3:25;
A71:        i+p..f -' len f <> len f or j + p..f -' len f <> 1 by A68,
XREAL_0:def 2;
            f.(i + p..f -' len f) = f/.(i + p..f -' len f) by A52,
PARTFUN1:def 6
              .= f.(j + p..f -' len f) by A65,A70,PARTFUN1:def 6;
            then i + p..f -' len f = j + p..f -' len f by A1,A52,A70,A66,A71;
            then i + p..f - len f = j + p..f -' len f by A49,XREAL_0:def 2;
            then i + p..f - len f = j + p..f - len f by A67,XREAL_0:def 2;
            hence thesis;
          end;
        end;
        hence thesis;
      end;
    end;
    hence thesis;
  end;
  suppose
    not p in rng f;
    hence thesis by A1,FINSEQ_6:def 2;
  end;
end;
