reserve x,y,z for object, X,Y for set,
  i,k,n for Nat,
  p,q,r,s for FinSequence,
  w for FinSequence of NAT,
  f for Function;

theorem Th55:
  for T being Tree, p being Tree-yielding FinSequence holds
  tree(p^<*T*>) = (tree(p) \/ elementary_tree (len p + 1))
  with-replacement (<*len p*>, T)
proof
  let T be Tree, p be Tree-yielding FinSequence;
  set W1 = elementary_tree (len p + 1), W2 = tree(p) \/ W1,
  W = W2 with-replacement (<*len p*>, T);
  len <*T*> = 1 by FINSEQ_1:40;
  then
A1: len (p^<*T*>) = len p + 1 by FINSEQ_1:22;
  len p < len p+1 by NAT_1:13;
  then <*len p*> in W1 by TREES_1:28;
  then
A2: <*len p*> in W2 by XBOOLE_0:def 3;
  let q be FinSequence of NAT;
  thus q in tree(p^<*T*>) implies q in W
  proof
    assume q in tree(p^<*T*>);
    then
A3: q = {} or ex n,r st n < len (p^<*T*>) & r in (p^<*T*>).(n+1) &
    q = <*n*>^r by Def15;
    now
      given n, r such that
A4:   n < len (p^<*T*>) and
A5:   r in (p^<*T*>).(n+1) and
A6:   q = <*n*>^r;
      reconsider r as FinSequence of NAT by A6,FINSEQ_1:36;
A7:   n <= len p by A1,A4,NAT_1:13;
A8:   now
        assume
A9:     n < len p;
        then n+1 in dom p by Lm3;
        then (p^<*T*>).(n+1) = p.(n+1) by FINSEQ_1:def 7;
        then q in tree(p) by A5,A6,A9,Def15;
        then
A10:    q in W2 by XBOOLE_0:def 3;
        not <*len p*> is_a_prefix_of <*n*>^r by A9,TREES_1:50;
        then not <*len p*> is_a_proper_prefix_of <*n*>^r;
        hence thesis by A2,A6,A10,TREES_1:def 9;
      end;
      now
        assume
A11:    n = len p;
        then
A12:    (p^<*T*>).(n+1) = T by FINSEQ_1:42;
        r = r;
        hence thesis by A2,A5,A6,A11,A12,TREES_1:def 9;
      end;
      hence thesis by A7,A8,XXREAL_0:1;
    end;
    hence thesis by A3,TREES_1:22;
  end;
  assume
A13: q in W;
  assume
A14: not thesis;
A15: now
    given r being FinSequence of NAT such that
A16: r in T and
A17: q = <*len p*>^r;
A18: len p < len p+1 by NAT_1:13;
    (p^<*T*>).(len p+1) = T by FINSEQ_1:42;
    hence thesis by A1,A14,A16,A17,A18,Def15;
  end;
  now
    assume q in W2;
    then
A19: q in tree(p) or q in W1 by XBOOLE_0:def 3;
A20: now
      assume q in tree(p);
      then q = {} & {} in tree(p^<*T*>) or
      ex n,r st n < len p & r in p.(n+1) & q = <*n*>^r by Def15;
      then consider n,r such that
A21:  n < len p and
A22:  r in p.(n+1) and
A23:  q = <*n*>^r by A14;
      n+1 in dom p by A21,Lm3;
      then
A24:  p.(n+1) = (p^<*T*>).(n+1) by FINSEQ_1:def 7;
      n < len (p^<*T*>) by A1,A21,NAT_1:13;
      hence thesis by A14,A22,A23,A24,Def15;
    end;
    now
      assume
A25:  not q in tree(p);
      then q = {} or ex n st n < len p+1 & q = <*n*> by A19,TREES_1:30;
      then consider n such that
A26:  n < len p+1 and
A27:  q = <*n*> by A14,TREES_1:22;
A28:  now
        assume n < len p;
        then
A29:    p.(n+1) in rng p by Lm3;
        rng p is constituted-Trees by Def9;
        hence {} in p.(n+1) by A29,TREES_1:22;
      end;
A30:  q = <*n*>^{} by A27,FINSEQ_1:34;
      then
A31:  n >= len p by A25,A28,Def15;
      n <= len p by A26,NAT_1:13;
      then
A32:  len p = n by A31,XXREAL_0:1;
A33:  n < n+1 by NAT_1:13;
A34:  (p^<*T*>).(len p+1) = T by FINSEQ_1:42;
      {} in T by TREES_1:22;
      hence thesis by A1,A14,A30,A32,A33,A34,Def15;
    end;
    hence thesis by A20;
  end;
  hence thesis by A2,A13,A15,TREES_1:def 9;
end;
