reserve x,y,z for set;
reserve f,f1,f2,f3 for FinSequence,
  p,p1,p2,p3 for set,
  i,k for Nat;
reserve D for non empty set,
  p,p1,p2,p3 for Element of D,
  f,f1,f2 for FinSequence of D;
reserve D for non empty set;
reserve p, q for FinSequence,
  X, Y, x, y for set,
  D for non empty set,
  i, j, k, l, m, n, r for Nat;
reserve a, a1, a2 for TwoValued Alternating FinSequence;

theorem
  for f being FinSubsequence, g, h, fg, fh, fgh being FinSequence
  st rng g c= dom f & rng h c= dom f & fg=f*g & fh=f*h & fgh=f*(g^h) holds
  fgh = fg^fh
proof
  let f be FinSubsequence, g, h, fg, fh, fgh be FinSequence;
  assume that
A1: rng g c= dom f and
A2: rng h c= dom f and
A3: fg=f*g and
A4: fh=f*h and
A5: fgh=f*(g^h);
  now
    rng (g^h) = rng g \/ rng h by FINSEQ_1:31;
    hence len fgh = len (g^h) by A1,A2,A5,FINSEQ_2:29,XBOOLE_1:8
      .= len g + len h by FINSEQ_1:22;
    then
A6: dom fgh = Seg (len g +len h) by FINSEQ_1:def 3;
A7: dom fh = dom h by A2,A4,RELAT_1:27;
A8: dom fg = dom g by A1,A3,RELAT_1:27;
A9: len fg = len g by A1,A3,FINSEQ_2:29;
    len fh = len h by A2,A4,FINSEQ_2:29;
    hence len (fg^fh) = len g + len h by A9,FINSEQ_1:22;
    let j be Nat;
    assume
A10: j in dom fgh;
    then
A11: 1<=j by A6,FINSEQ_1:1;
A12: j<=len g + len h by A6,A10,FINSEQ_1:1;
    per cases;
    suppose
      j<=len g;
      then
A13:  j in dom g by A11,FINSEQ_3:25;
      thus fgh.j = f.((g^h).j) by A5,A10,FUNCT_1:12
        .= f.(g.j) by A13,FINSEQ_1:def 7
        .= fg.j by A3,A13,FUNCT_1:13
        .= (fg^fh).j by A8,A13,FINSEQ_1:def 7;
    end;
    suppose
      len g < j;
      then len g +1 <=j by NAT_1:13;
      then
A14:  1<=j-len g by XREAL_1:19;
      then j-'len g = j-len g by XREAL_0:def 2;
      then reconsider j9 = j-len g as Element of NAT;
A15:  j = len g + j9;
      then j9<=len h by A12,XREAL_1:6;
      then
A16:  j9 in dom h by A14,FINSEQ_3:25;
      thus fgh.j = f.((g^h).j) by A5,A10,FUNCT_1:12
        .= f.(h.j9) by A15,A16,FINSEQ_1:def 7
        .= fh.j9 by A4,A16,FUNCT_1:13
        .= (fg^fh).j by A9,A7,A15,A16,FINSEQ_1:def 7;
    end;
  end;
  hence thesis by FINSEQ_2:9;
end;
