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 Th16:
  for T, T1 being finite Tree, p being Element of T holds
  card(T with-replacement (p,T1)) + card (T|p) = card T + card T1
proof
  let T, T1, p;
  defpred P1[Element of T] means not p is_a_prefix_of $1;
  defpred P2[Element of T] means p is_a_prefix_of $1;
  set A = { t : P1[t] };
  set B = { t : P2[t] };
  set C = the set of all  p^t1 ;
A1: A is Subset of T from DOMAIN_1:sch 7;
A2: B is Subset of T from DOMAIN_1:sch 7;
A3: T1,C are_equipotent
  proof
    deffunc F(Element of T1) = p^$1;
    consider f being Function such that
A4: dom f = T1 and
A5: for n being Element of T1 holds f.n = F(n) from FUNCT_1:sch 4;
    take f;
    thus f is one-to-one
    proof
      let x,y be object such that
A6:   x in dom f & y in dom f and
A7:   f.x = f.y;
      reconsider m = x, n = y as Element of T1 by A4,A6;
      p^m = f.n by A5,A7
        .= p^n by A5;
      hence thesis by FINSEQ_1:33;
    end;
    thus dom f = T1 by A4;
    thus rng f c= C
    proof
      let i be object;
      assume i in rng f;
      then consider n being object such that
A8:   n in dom f and
A9:   i = f.n by FUNCT_1:def 3;
      T1 c= NAT* by TREES_1:def 3;
      then reconsider n as Element of NAT* by A4,A8;
      f.n = p^n by A4,A5,A8;
      hence thesis by A4,A8,A9;
    end;
    let i be object;
    assume i in C;
    then consider n being Element of T1 such that
A10: i = p^n;
    i = f.n by A5,A10;
    hence thesis by A4,FUNCT_1:def 3;
  end;
  reconsider A,B as finite set by A1,A2;
  now
    let x be object;
    hereby
      assume x in T;
      then reconsider t = x as Element of T;
      p is_a_prefix_of t or not p is_a_prefix_of t;
      hence x in A or x in B;
    end;
    assume x in A or x in B;
    hence x in T by A1,A2;
  end;
  then
A11: T = A \/ B by XBOOLE_0:def 3;
A12: A misses C
  proof
    assume not thesis;
    then consider x being object such that
A13: x in A /\ C by XBOOLE_0:4;
    x in C by A13,XBOOLE_0:def 4;
    then
A14: ex t1 st x = p^t1;
    x in A by A13,XBOOLE_0:def 4;
    then ex t st x = t & not p is_a_prefix_of t;
    hence contradiction by A14,TREES_1:1;
  end;
A15: A misses B
  proof
    assume not thesis;
    then consider x being object such that
A16: x in A /\ B by XBOOLE_0:4;
    x in B by A16,XBOOLE_0:def 4;
    then
A17: ex t st x = t & p is_a_prefix_of t;
    x in A by A16,XBOOLE_0:def 4;
    then ex t st x = t & not p is_a_prefix_of t;
    hence contradiction by A17;
  end;
A18: T with-replacement (p,T1) = A \/ C by Th9;
  reconsider C as finite set by A3,CARD_1:38;
A19: card T1 = card C by A3,CARD_1:5;
  T|p,B are_equipotent by Th8;
  then card(T|p) = card B by CARD_1:5;
  hence
  card(T with-replacement (p,T1)) + card (T|p) = card A + card C + card B
  by A18,A12,CARD_2:40
    .= card A + card B + card C
    .= card T + card T1 by A11,A15,A19,CARD_2:40;
end;
