reserve S for non empty non void ManySortedSign;
reserve X for non-empty ManySortedSet of S;
reserve x,y,z for set, i,j for Nat;

theorem Th23:
  for I being set, A,B being ManySortedSet of I st A is_transformable_to B
  for f being ManySortedFunction of A,B st f is "onto"
  ex g being ManySortedFunction of B,A st f**g = id B
  proof
    let I be set;
    let A,B be ManySortedSet of I;
    assume A1: A is_transformable_to B;
    let f be ManySortedFunction of A,B;
    assume A2: f is "onto";
    deffunc F(object) = the rng-retract of f.$1;
    consider g being ManySortedSet of I such that
A3: for i being object st i in I holds g.i = F(i) from PBOOLE:sch 4;
    g is Function-yielding
    proof
      let x be object; assume x in dom g; then
      g.x = F(x) by A3;
      hence thesis;
    end; then
    reconsider g as ManySortedFunction of I;
    g is ManySortedFunction of B,A
    proof
      let x be object; assume
A4:   x in I; then
A5:   g.x = F(x) by A3; then
A6:   dom (g.x) = rng (f.x) & rng (f.x) = B.x
      by A2,A4,ALGSPEC1:def 2;
      A.x <> {} implies B.x <> {} by A4,A1,PZFMISC1:def 3; then
A7:   dom (f.x) = A.x by FUNCT_2:def 1;
A8:   (f.x)*(g.x) = id (B.x) & dom id (B.x) = B.x
      by A5,A6,ALGSPEC1:def 2;
      rng (g.x) c= dom (f.x)
      proof let y be object;
        assume y in rng (g.x); then
        consider z being object such that
A9:     z in dom (g.x) & y = (g.x).z by FUNCT_1:def 3;
        thus y in dom (f.x) by A6,A8,A9,FUNCT_1:11;
      end;
      hence thesis by A6,A7,FUNCT_2:2;
    end; then
    reconsider g as ManySortedFunction of B,A;
    take g;
    now let x be object;
      assume
A10:   x in I; then
      g.x = F(x) by A3; then
      (f.x)*(g.x) = id rng (f.x) & dom (g.x) = rng (f.x) & rng (f.x) = B.x
      by A2,A10,ALGSPEC1:def 2;
      hence (f**g).x = id (B.x) by A10,MSUALG_3:2
      .= (id B).x by A10,MSUALG_3:def 1;
    end;
    hence f**g = id B;
  end;
