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