reserve i,j,n,k,m for Nat,
     a,b,x,y,z for object,
     F,G for FinSequence-yielding FinSequence,
     f,g,p,q for FinSequence,
     X,Y for set,
     D for non empty set;

theorem Th5:
  for s be FinSequence st s"{y}<>{}
    ex p be Permutation of Seg (len s) st (s*p) . (len s) = y & p = p"
proof
  let s be FinSequence; assume s"{y}<>{};
  then consider x be object such that
A1: x in s"{y} by XBOOLE_0:def 1;
A2: x in dom s & s.x in {y} by A1,FUNCT_1:def 7;
  then
A3: s.x = y by TARSKI:def 1;
A4: dom s = Seg len s by FINSEQ_1:def 3;
  reconsider x as Nat by A2;
  per cases;
  suppose
A5:   x = len s;
    reconsider I=id Seg len s as Permutation of Seg (len s);
    take I;
    x in dom s /\ Seg len s by A1,FUNCT_1:def 7,A4;
    hence thesis by A5,A3,FUNCT_1:45,20;
  end;
  suppose
A6:   x <> len s;
    1 <= x <= len s by A2,FINSEQ_3:25;
    then
A7:   1 <= len s & x < len s by A6,XXREAL_0:1,2;
    then len s in dom s by FINSEQ_3:25;
    then consider tr be Element of Permutations (len s) such that
A8:   tr is being_transposition & tr.x = len s by A2,A4,A7,MATRIX11:16;
A9:   tr.(len s) =x & len s in dom tr by A7,A8,MATRIX11:8;
    reconsider tr as Permutation of Seg (len s) by MATRIX_1:def 12;
    take tr;
    thus thesis by A3,FUNCT_1:13,A9,A8,MATRIX11:20;
  end;
end;
