reserve f for Function;
reserve p,q for FinSequence;
reserve A,B,C for set,x,x1,x2,y,z for object;
reserve k,l,m,n for Nat;
reserve a for Nat;
reserve D for non empty set;
reserve d,d1,d2,d3 for Element of D;
reserve L,M for Element of NAT;

theorem Th54:
  p just_once_values x iff x in rng p & p - {x} = (p -| x) ^ (p |-- x)
proof
  set q = p - {x};
  set r = p -| x;
  set s = p |-- x;
  thus p just_once_values x implies x in rng p & p - {x} = (p -| x) ^ (p |-- x
  )
  proof
    assume
A1: p just_once_values x;
    hence
A2: x in rng p by Th5;
A3: now
      x..p <= len p by A2,Th21;
      then x..p - 1 <= len p - 1 by XREAL_1:9;
      then len r <= len p - 1 by A2,Th34;
      then len r <= len q by A1,Th30;
      then
A4:   Seg(len r) c= Seg(len q) by FINSEQ_1:5;
      let k be Nat;
A5:   Seg(len r) = dom r & Seg(len q) = dom q by FINSEQ_1:def 3;
      assume
A6:   k in dom r;
      then k in Seg(len r) by FINSEQ_1:def 3;
      then k <= len r by FINSEQ_1:1;
      then k <= x..p - 1 by A2,Th34;
      then
A7:   k + 1 <= x..p by XREAL_1:19;
      k < k + 1 by XREAL_1:29;
      then
A8:   k < x..p by A7,XXREAL_0:2;
      r.k = p.k by A2,A6,Th36;
      hence q.k = r.k by A1,A6,A4,A5,A8,Th31;
    end;
A9: now
      reconsider m = x..p - 1 as Element of NAT by A2,Th22;
      let k be Nat;
      set z = k + m;
      assume
A10:  k in dom s;
      then
A11:  s.k = p.(k + x..p) by A2,Def6;
A12:  dom s = Seg(len s) by FINSEQ_1:def 3;
      then
A13:  1 <= k by A10,FINSEQ_1:1;
      then x..p + 1 <= k + x..p by XREAL_1:7;
      then
A14:  x..p <= k + x..p - 1 by XREAL_1:19;
      k <= len s by A10,A12,FINSEQ_1:1;
      then k <= len p - x..p by A2,Def6;
      then k + x..p <= len p by XREAL_1:19;
      then k + x..p - 1 <= len p - 1 by XREAL_1:9;
      then
A15:  k + x..p - 1 <= len q by A1,Th30;
      1 <= x..p by A2,Th21;
      then 1 + 1 <= k + x..p by A13,XREAL_1:7;
      then
A16:  1 <= k + x..p - 1 by XREAL_1:19;
      dom q = Seg(len q) by FINSEQ_1:def 3;
      then z in dom q by A16,A15;
      then q.z = p.(z + 1) by A1,A14,Th31
        .= p.(k + x..p);
      hence q.(len r + k) = s.k by A2,A11,Th34;
    end;
    len r + len s = (x..p - 1) + len s by A2,Th34
      .= (x..p - 1) + (len p - x..p) by A2,Def6
      .= len p - 1
      .= len q by A1,Th30;
    then dom q = Seg(len r + len s) by FINSEQ_1:def 3;
    hence thesis by A3,A9,FINSEQ_1:def 7;
  end;
  assume
A17: x in rng p;
  assume
A18: p - {x} = (p -| x) ^ (p |-- x);
  now
    let k;
    assume that
A19: k in dom p and
A20: k <> x..p and
A21: p.k = x;
    {x..p,k} c= p " {x}
    proof
      let y be object;
      assume
A22:  y in {x..p,k};
A23:  x in {x} by TARSKI:def 1;
      x..p in dom p & p.(x..p) = x by A17,Th19,Th20;
      then
A24:  x..p in p " {x} by A23,FUNCT_1:def 7;
      k in p " {x} by A19,A21,A23,FUNCT_1:def 7;
      hence thesis by A22,A24,TARSKI:def 2;
    end;
    then card{x..p,k} <= card(p " {x}) by NAT_1:43;
    then
A25: 2 <= card(p " {x}) by A20,CARD_2:57;
A26: len q = len p - card(p " {x}) by FINSEQ_3:59
      .= len p + (- card(p " {x}));
    len q = len r + len s by A18,FINSEQ_1:22
      .= (x..p - 1) + len s by A17,Th34
      .= (x..p - 1) + (len p - x..p) by A17,Def6
      .= len p + (- 1);
    hence contradiction by A26,A25;
  end;
  hence thesis by A17,Th27;
end;
