reserve i,j,k,n,m for Nat,
  x,y,z,y1,y2 for object, X,Y,D for set,
  p,q for XFinSequence;
reserve k1,k2 for Nat;
reserve D for non empty set,
  F,G for XFinSequence of D,
  b for BinOp of D,
  d,d1,d2 for Element of D;

theorem Th40:  :: STIRL2_1:45
  b is having_a_unity or len F > 0 implies b "**" (F ^ <% d %>) =
  b.(b "**" F,d)
proof
  assume
A1: b is having_a_unity or len F > 0;
  now
    per cases;
    suppose
A2:   len F<zz+1;
      then
A3:     F={} by NAT_1:13;
A4:   b "**" (F ^<% d %>)=d by Th37,A3;
      len F=0 by A2,NAT_1:13;
      then b "**" F = the_unity_wrt b by A1,Def8;
      hence thesis by A1,A2,A4,NAT_1:13,SETWISEO:15;
    end;
    suppose
A5:   len F>=1;
      set G = F ^ <% d %>;
      reconsider lenF1=len F-1 as Element of NAT by A5,NAT_1:21;
A6:   G.(len F)=d by AFINSQ_1:36;
A7:   len G=len F+len <%d%> by AFINSQ_1:17
        .=len F+1 by AFINSQ_1:33;
      then 1 <= len G by NAT_1:12;
      then consider f1 be sequence of D such that
A8:   f1.0 = G.0 and
A9:   for n st n+1 < len G holds f1.(n+1)=b.(f1.n,G.(n+1)) and
A10:   b "**" G = f1.(len G-1) by Def8;
      consider f be sequence of D such that
A11:  f.0 = F.0 and
A12:  for n st n+1 < len F holds f.(n+1)=b.(f.n,F.(n+1)) and
A13:  b "**" F = f.(len F-1) by A5,Def8;
      defpred P[Nat] means $1+1 < len G implies f.$1 = f1.$1;
A14:   P[n] implies P[n + 1]
      proof
       assume
A15:    P[n];
        set n1=n+1;
        assume
A16:    n1+1<len G; then
A17:    f1.n1=b.(f1.n,G.(n+1)) by A9,NAT_1:13;
A18:    (n1+1)+(-1)<(len F+1)+(-1) by A7,A16,XREAL_1:8;
        then
A19:    n1 in len F by AFINSQ_1:86;
        f.n1=b.(f.n,F.n1) by A12,A18;
        hence thesis by A15,A16,A17,A19,AFINSQ_1:def 3,NAT_1:13;
      end;
      0 in len F by A5,AFINSQ_1:86;
      then
A20:  P[0] by A11,A8,AFINSQ_1:def 3;
A21:  for n holds P[n] from NAT_1:sch 2(A20,A14);
A22:  lenF1+1<len G by A7,NAT_1:13;
      then b "**" G = b.(f1.(lenF1),G.(lenF1+1)) by A7,A9,A10;
      hence thesis by A13,A21,A22,A6;
    end;
  end;
  hence thesis;
end;
