reserve i,j,x,y for object,
  f,g for Function;
reserve T,T1 for finite Tree,
  t,p for Element of T,
  t1 for Element of T1;

theorem Th13:
  for p,q being Tree-yielding FinSequence, k being Element of NAT st
    len p = len q & k+1 in dom p & for i being Nat st i in dom p &
  i <> k+1 holds p.i = q.i
  for t being Tree st q.(k+1) = t holds
    tree(q) = tree(p) with-replacement (<*k*>, t)
proof
  let p,q be Tree-yielding FinSequence, k be Element of NAT such that
A1: len p = len q and
A2: k+1 in dom p and
A3: for i being Nat st i in dom p & i <> k+1 holds p.i = q.i;
  let t be Tree;
  set o = <*k*>;
  k+1 <= len p by A2,FINSEQ_3:25;
  then
A4: k < len p by NAT_1:13;
  assume
A5: q.(k+1) = t;
A6: now
    let s be FinSequence of NAT;
    hereby
      assume
A7:   s in tree(q);
      per cases by A7,TREES_3:def 15;
      suppose
        s = {};
        hence s in tree(p) & not o is_a_proper_prefix_of s or ex r being
        FinSequence of NAT st r in t & s = o^r by TREES_1:22;
      end;
      suppose
        ex n being Nat, r being FinSequence st n < len q &
        r in q.(n+1) & s = <*n*>^r;
        then consider n being Nat, r being FinSequence such that
A8:     n < len q and
A9:     r in q.(n+1) and
A10:    s = <*n*>^r;
        now
          per cases;
          case
A11:        n = k;
            reconsider r as FinSequence of NAT by A10,FINSEQ_1:36;
            take r;
            thus r in t & s = o^r by A5,A9,A10,A11;
          end;
          case
A12:        n <> k;
            1 <= n+1 & n+1 <= len p by A1,A8,NAT_1:11,13;
            then n+1 in dom p by FINSEQ_3:25;
            then q.(n+1) = p.(n+1) by A3,A12,XCMPLX_1:2;
            hence s in tree(p) by A1,A8,A9,A10,TREES_3:def 15;
            assume o is_a_proper_prefix_of s;
            then o is_a_prefix_of s;
            then ex s1 being FinSequence st s = o^s1 by TREES_1:1;
            then k = s.1 by FINSEQ_1:41
              .= n by A10,FINSEQ_1:41;
            hence contradiction by A12;
          end;
        end;
        hence s in tree(p) & not o is_a_proper_prefix_of s or ex r being
        FinSequence of NAT st r in t & s = o^r;
      end;
    end;
    assume
A13: s in tree(p) & not o is_a_proper_prefix_of s or ex r being
    FinSequence of NAT st r in t & s = o^r;
    per cases by A13;
    suppose that
A14:  s in tree(p) and
A15:  not o is_a_proper_prefix_of s;
      now
        per cases by A14,TREES_3:def 15;
        suppose
          s = {};
          hence s in tree(q) by TREES_1:22;
        end;
        suppose
          ex n being Nat, r being FinSequence st n < len p
          & r in p.(n+1) & s = <*n*>^r;
          then consider n being Nat, r being FinSequence such that
A16:      n < len p and
A17:      r in p.(n+1) and
A18:      s = <*n*>^r;
          now
            per cases;
            suppose
A19:          r = {};
              1 <= n+1 & n+1 <= len q by A1,A16,NAT_1:11,13;
              then n+1 in dom q by FINSEQ_3:25;
              then q.(n+1) is Tree by TREES_3:22;
              then r in q.(n+1) by A19,TREES_1:22;
              hence s in tree(q) by A1,A16,A18,TREES_3:def 15;
            end;
            suppose r <> {};
              then
A20:          n <> k by A15,A18,FINSEQ_1:87,TREES_1:1;
              1 <= n+1 & n+1 <= len p by A16,NAT_1:11,13;
              then n+1 in dom p by FINSEQ_3:25;
              then q.(n+1) = p.(n+1) by A3,A20,XCMPLX_1:2;
              hence s in tree(q) by A1,A16,A17,A18,TREES_3:def 15;
            end;
          end;
          hence s in tree(q);
        end;
      end;
      hence s in tree(q);
    end;
    suppose
      ex r being FinSequence of NAT st r in t & s = o^r;
      hence s in tree(q) by A1,A4,A5,TREES_3:def 15;
    end;
  end;
  p.(k+1) is Tree by A2,TREES_3:22;
  then
A21: {} in p.(k+1) by TREES_1:22;
  o = o^{} by FINSEQ_1:34;
  then o in tree(p) by A4,A21,TREES_3:def 15;
  hence thesis by A6,TREES_1:def 9;
end;
