reserve k, l, m, n, i, j for Nat,
  K, N for non empty Subset of NAT,
  Ke, Ne, Me for Subset of NAT,
  X,Y for set;
reserve f for Function of Segm n,Segm k;
reserve x,y for set;

theorem Th40:
  for f be Function of Segm n,Segm k,
      g be Function of Segm(n+1),Segm(k+1) st f is onto
  "increasing & f=g|Segm n & g.n = k
  holds g is onto "increasing & g"{g.n}={n}
proof
  let f be Function of Segm n,Segm k,
      g be Function of Segm(n+1),Segm(k+1) such that
A1: f is onto "increasing and
A2: f=g|Segm n and
A3: g.n = k;
  Segm(k+1) c= rng g
  proof
    let x9 be object such that
A4: x9 in Segm(k+1);
    reconsider x=x9 as Element of NAT by A4;
    x<k+1 by A4,NAT_1:44;
    then
A5: x<=k by NAT_1:13;
    now
      per cases by A5,XXREAL_0:1;
      suppose
A6:     x<k;
A7:     rng f=k by A1,FUNCT_2:def 3;
        x in Segm k by A6,NAT_1:44;
        then consider y be object such that
A8:     y in dom f and
A9:     f.y =x by A7,FUNCT_1:def 3;
A10:    dom g = n+1 by FUNCT_2:def 1;
        n=0 iff k=0 by A1;
        then
A11:    dom f = n by FUNCT_2:def 1;
        n<=n+1 by NAT_1:11;
        then
A12:    Segm n c= Segm(n+1) by NAT_1:39;
        f.y=g.y by A2,A8,FUNCT_1:47;
        hence thesis by A8,A9,A11,A12,A10,FUNCT_1:def 3;
      end;
      suppose
A13:    x=k;
        n<n+1 by NAT_1:13;
        then
A14:    n in Segm(n+1) by NAT_1:44;
        dom g =n+1 by FUNCT_2:def 1;
        hence thesis by A3,A13,A14,FUNCT_1:def 3;
      end;
    end;
    hence thesis;
  end;
  then k+1=rng g;
  hence g is onto by FUNCT_2:def 3;
  for i,j st i in rng g & j in rng g & i<j holds min* g"{i} < min* g"{j}
  by A1,A2,Th39;
  hence g is "increasing;
  thus g"{g.n}={n}
  proof
    assume g"{g.n}<>{n};
    then consider m such that
A15: m in g"{g.n} and
A16: m<>n by Th35;
    g.m in {g.n} by A15,FUNCT_1:def 7;
    then
A17: g.m=k by A3,TARSKI:def 1;
    m in dom g by A15,FUNCT_1:def 7;
    then m<n+1 by NAT_1:44;
    then m<=n by NAT_1:13;
    then
A18: m<n by A16,XXREAL_0:1;
    n=0 iff k=0 by A1;
    then dom f=n by FUNCT_2:def 1;
    then
A19: m in dom f by A18,NAT_1:44;
    then
A20: f.m in rng f by FUNCT_1:def 3;
    f.m=g.m by A2,A19,FUNCT_1:47;
    hence contradiction by A20,A17,NAT_1:44;
  end;
end;
