
theorem Th6:
  for f, g being FinSequence, i being Nat
  st i <= len f & mid(f,i,i-'1+len g) = g
  holds i-'1+len g <= len f
proof
  let f, g be FinSequence, i be Nat;
  set j = i-'1+len g;
  assume that
    A1: i <= len f and
    A2: mid(f,i,j) = g;
  per cases;
  suppose A3: i <= j;
    then A4: mid(f,i,j) = (f/^(i-'1))|(j-'i+1) by FINSEQ_6:def 3;
    A5: i-'1 <= len f -' 1 by A1, NAT_D:42;
    len f -' 1 <= len f by NAT_D:35;
    then i-'1 <= len f by A5, XXREAL_0:2;
    then A6: len (f/^(i-'1)) = len f - (i-'1) by RFINSEQ:def 1;
    per cases;
    suppose i > 0;
      then A8: i-'1 = i-1 by NAT_1:14, XREAL_1:233;
      per cases;
      suppose len g >= 1;
        then A10: len g - 1 = len g -' 1 by XREAL_1:233;
        A11: (-1+len g)+i-'i = -1+len g by A10, NAT_D:34;
        A12: j-'i+1 = len g by A8, A11;
        per cases;
        suppose len g <= len f - (i-'1);
          then j+1-'i <= len f - (i-1) by A3, A12, A8, NAT_D:38;
          then j+1-i <= len f - (i-1) by A3, NAT_D:37;
          then j-(i-1) <= len f - (i-1);
          hence thesis by XREAL_1:9;
        end;
        suppose len g > len f - (i-'1);
          then (f/^(i-'1))|(j-'i+1) = (f/^(i-'1)) by A6, A12, FINSEQ_1:58;
          hence thesis by A2, A4,A6;
        end;
      end;
      suppose len g < 1;
        then len g = 0 by NAT_1:14;
        then j <= i by NAT_D:35;
        hence thesis by A1, XXREAL_0:2;
      end;
    end;
    suppose A14: i = 0;
      0-'1 <= 0 by NAT_D:35;
      then A15: i-'1 = 0 by A14;
      A16: j-'i+1 = len g + 1 by A14, A15, NAT_D:40;
      per cases;
      suppose len g + 1 <= len f - (i-'1);
        then A17: j+1 <= len f by A15;
        j+0 <= j+1 by XREAL_1:6;
        hence thesis by A17, XXREAL_0:2;
      end;
      suppose len g + 1 > len f - (i-'1);
        then (f/^(i-'1))|(j-'i+1) = (f/^(i-'1)) by A6, A16, FINSEQ_1:58;
        hence thesis by A2, A4, A6;
      end;
    end;
  end;
  suppose i > j;
    then A20: len g = 0 by Th3;
    i-'1 <= i by NAT_D:35;
    hence thesis by A1, A20, XXREAL_0:2;
  end;
end;
