reserve X for RealUnitarySpace;
reserve x, y, y1, y2 for Point of X;
reserve xd for set;
reserve i, j, n for Nat;

theorem Th1:
  for D being set, p1, p2 being FinSequence of D holds
  p1 is one-to-one & p2 is one-to-one & rng p1 = rng p2 implies
  dom p1 = dom p2 & ex P being Permutation of dom p1 st
  p2 = p1*P & dom P = dom p1 & rng P = dom p1
proof
  let D be set, p1, p2 be FinSequence of D;
  assume that
A1: p1 is one-to-one and
A2: p2 is one-to-one and
A3: rng p1 = rng p2;
  set P = p1"*p2;
  len p1 = card rng p2 by A1,A3,FINSEQ_4:62
    .= len p2 by A2,FINSEQ_4:62;
  then
A4: dom p1 = Seg len p2 by FINSEQ_1:def 3
    .= dom p2 by FINSEQ_1:def 3;
A5: now
    let xd be object;
    dom (p1") = rng p1 by A1,FUNCT_1:33;
    then xd in dom p2 implies p2.xd in dom (p1") by A3,FUNCT_1:3;
    hence xd in dom P iff xd in dom p2 by FUNCT_1:11;
  end;
  then
A6: dom P = dom p2 by TARSKI:2;
A7: rng(p1") = dom p1 by A1,FUNCT_1:33;
A8: rng P c= dom p1
  by A7,FUNCT_1:14;
A9: dom p1 c= rng P
  proof
    let xd be object;
    assume xd in dom p1;
    then xd in rng(p1") by A1,FUNCT_1:33;
    then consider yd being object such that
A10: yd in dom (p1") and
A11: xd = (p1").yd by FUNCT_1:def 3;
    yd in rng p2 by A1,A3,A10,FUNCT_1:33;
    then consider z being object such that
A12: z in dom p2 and
A13: yd = p2.z by FUNCT_1:def 3;
    xd = P.z by A11,A12,A13,FUNCT_1:13;
    hence thesis by A6,A12,FUNCT_1:def 3;
  end;
A14: dom P = dom p1 by A4,A5,TARSKI:2;
A15: rng P = dom p1 by A8,A9,XBOOLE_0:def 10;
  then P is Function of dom p1, dom p1 by A14,FUNCT_2:1;
  then
A16: P is Permutation of dom p1 by A1,A2,A15,FUNCT_2:57;
  now
    let xd be object;
    xd in dom P implies P.xd in dom p1 by A15,FUNCT_1:3;
    hence xd in dom(p1*P) iff xd in dom p1 by A14,FUNCT_1:11;
  end;
  then
A17: dom p2 = dom (p1*P) by A4,TARSKI:2;
  for xd being object st xd in dom p2 holds p2.xd = (p1*P).xd
  proof
    let xd be object;
    assume
A18: xd in dom p2;
    then
A19: p2.xd in rng p1 by A3,FUNCT_1:3;
    (p1*P).xd = p1.((p1"*p2).xd) by A4,A14,A18,FUNCT_1:13
      .= p1.((p1").(p2.xd)) by A18,FUNCT_1:13
      .= p2.xd by A1,A19,FUNCT_1:35;
    hence thesis;
  end;
  hence thesis by A4,A14,A15,A16,A17,FUNCT_1:2;
end;
