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 Th51:
  x in rng p implies p = (p -| x) ^ <* x *> ^ (p |-- x)
proof
  set q1 = p -| x;
  set q2 = p |-- x;
  set r = q1 ^ <* x *>;
  assume
A1: x in rng p;
A2: now
    let k be Nat;
    assume k in dom q2;
    then q2.k = p.(x..p - 1 + 1 + k) by A1,Def6
      .= p.(len q1 + 1 + k) by A1,Th34
      .= p.(len q1 + len<* x *> + k) by FINSEQ_1:40
      .= p.(len r + k) by FINSEQ_1:22;
    hence p.(len r + k) = q2.k;
  end;
A3: now
    let k be Nat;
    assume
A4: k in dom r;
    now
      per cases by A4,FINSEQ_1:25;
      suppose
A5:     k in dom q1;
        hence r.k = q1.k by FINSEQ_1:def 7
          .= p.k by A1,A5,Th36;
      end;
      suppose
        ex n be Nat st n in dom<* x *> & k = len q1 + n;
        then consider n be Nat such that
A6:     n in dom <* x *> and
A7:     k = len q1 + n;
        n in {1} by A6,FINSEQ_1:2,def 8;
        then
A8:     n = 1 by TARSKI:def 1;
        hence r.k = <* x *>.1 by A6,A7,FINSEQ_1:def 7
          .= x
          .= p.(x..p - 1 + 1) by A1,Th19
          .= p.k by A1,A7,A8,Th34;
      end;
    end;
    hence p.k = r.k;
  end;
  len p = len p - x..p + x..p .= x..p - 1 + 1 + len q2 by A1,Def6
    .= len q1 + 1 + len q2 by A1,Th34
    .= len q1 + len<* x *> + len q2 by FINSEQ_1:40
    .= len r + len q2 by FINSEQ_1:22;
  hence thesis by A3,A2,FINSEQ_3:38;
end;
