reserve A for non empty set,
  S for non void non empty ManySortedSign;
reserve x for set;
reserve o for OperSymbol of S;

theorem Th4:
  for U1,U2,U3 be feasible MSAlgebra over S,
      F be ManySortedFunction of U1,U2,
      G be ManySortedFunction of U2,U3,
      x be Element of Args(o,U1) st
     Args (o,U1) <> {} & the Sorts of U1 is_transformable_to the Sorts of U2 &
  the Sorts of U2 is_transformable_to the Sorts of U3
  ex GF be ManySortedFunction of U1,U3 st GF = G ** F & GF#x = G#(F#x)
proof
  let U1,U2,U3 be feasible MSAlgebra over S, F be ManySortedFunction of U1,U2,
  G be ManySortedFunction of U2,U3, x be Element of Args(o,U1);
  assume that
A1: Args (o,U1) <> {} and
A2: the Sorts of U1 is_transformable_to the Sorts of U2 and
A3: the Sorts of U2 is_transformable_to the Sorts of U3;
  x in Args (o,U1) by A1;
  then x in product ((the Sorts of U1)*(the_arity_of o)) by PRALG_2:3;
  then
A4: ex g be Function st x = g & dom g = dom ((the Sorts of U1 )*(the_arity_of
o)) & for x being object st x in dom ((the Sorts of U1)*(the_arity_of o))
holds g.x in ((the
  Sorts of U1)*(the_arity_of o)).x by CARD_3:def 5;
  then reconsider x9 = x as Function;
  reconsider Fr = (Frege (F*the_arity_of o)).x9 as Function;
  dom F = the carrier of S by PARTFUN1:def 2;
  then
A5: rng the_arity_of o c= dom F; then
A6: dom (F*the_arity_of o) = dom the_arity_of o by RELAT_1:27;
A7: dom doms (F*the_arity_of o) = dom (F*the_arity_of o) by FUNCT_6:59;
  then
A8: dom x9 = dom doms (F*the_arity_of o) by A1,A6,MSUALG_3:6;
  then reconsider
  x99 = x9 as ManySortedSet of dom (the_arity_of o) by A6,A7,PARTFUN1:def 2
,RELAT_1:def 18;
  dom G = the carrier of S by PARTFUN1:def 2;
  then rng the_arity_of o c= dom G;
  then
A9: dom (G*the_arity_of o) = dom the_arity_of o by RELAT_1:27;
  then reconsider Ga = (G*the_arity_of o), Fa = (F*the_arity_of o) as
  ManySortedFunction of dom (the_arity_of o) by A6,PARTFUN1:def 2
,RELAT_1:def 18;
A10: Args (o,U2) <> {} by A1,A2,Th3;
  dom (the Sorts of U1) = the carrier of S by PARTFUN1:def 2;
  then
A11: rng the_arity_of o c= dom the Sorts of U1;
  now
    let x be object;
    set ds = (the_arity_of o).x;
    assume x in dom doms (F*the_arity_of o); then
A12: x in dom (F*the_arity_of o) by FUNCT_6:59;
    then
A13: (doms (F*the_arity_of o)).x = dom ((F*the_arity_of o).x) by FUNCT_6:22;
A14: x in dom the_arity_of o by A5,A12,RELAT_1:27; then
A15: ds in rng the_arity_of o by FUNCT_1:def 3;
    then reconsider
    Ff = F.ds as Function of (the Sorts of U1).ds, (the Sorts of U2
    ).ds by PBOOLE:def 15;
    x in dom ((the Sorts of U1) * (the_arity_of o)) by A11,A14,RELAT_1:27;
    then
A16: x9.x in ((the Sorts of U1) * (the_arity_of o)).x by A1,MSUALG_3:6;
A17: (the Sorts of U1).ds = dom Ff
    proof
      per cases;
      suppose
        (the Sorts of U2).ds <> {};
        hence thesis by FUNCT_2:def 1;
      end;
      suppose
        (the Sorts of U2).ds = {};
        then (the Sorts of U1).ds = {} by A2,A15,PZFMISC1:def 3;
        hence thesis;
      end;
    end;
    ((F*the_arity_of o).x) = F.((the_arity_of o).x) by A14,FUNCT_1:13;
    hence x9.x in (doms (F*the_arity_of o)).x by A13,A14,A16,A17,FUNCT_1:13;
  end; then
A18: x9 in product doms (F*the_arity_of o) by A8,CARD_3:9; then
A19: Fr = (F*the_arity_of o)..x9 by PRALG_2:def 2;
A20: now
    let x be object;
    set ds = (the_arity_of o).x;
    assume
A21: x in dom doms (G*the_arity_of o); then
A22: x in dom (G*the_arity_of o) by FUNCT_6:59;
Z2: dom x9 = dom the_arity_of o by A1,MSUALG_3:6;
Z1: x in dom (F*the_arity_of o) by A9,A6,A21,FUNCT_6:59;
Z3: dom (F*the_arity_of o) = dom the_arity_of o by A6; then
 dom (F*the_arity_of o) /\ dom x9 = dom the_arity_of o by Z2; then
    x in dom (F*the_arity_of o) /\ dom x9 by Z1,Z3; then 
    x in dom ((F*the_arity_of o)..x9) by PRALG_1:def 19; then 
A23: Fr.x = ((F*the_arity_of o).x).(x9.x) by A19,PRALG_1:def 19;
A24: dom ((the Sorts of U1) * (the_arity_of o)) = dom (the_arity_of o) 
      by A11,RELAT_1:27;
A25: x in dom the_arity_of o by A9,A21,FUNCT_6:59; then
A26: ds in rng the_arity_of o by FUNCT_1:def 3;
    then reconsider
    Ff = F.ds as Function of (the Sorts of U1).ds, (the Sorts of U2).ds
       by PBOOLE:def 15;
A27: ((F*the_arity_of o).x) = Ff by A6,A25,FUNCT_1:12;
    reconsider Gds = G.ds as Function of (the Sorts of U2).ds, (the Sorts of
    U3).ds by A26,PBOOLE:def 15;
A28: dom Gds = (the Sorts of U2).ds
    proof
      per cases;
      suppose
        (the Sorts of U3).ds <> {};
        hence thesis by FUNCT_2:def 1;
      end;
      suppose
        (the Sorts of U3).ds = {};
        then (the Sorts of U2).ds = {} by A3,A26,PZFMISC1:def 3;
        hence thesis;
      end;
    end;
A29: (the Sorts of U1).ds = dom Ff
    proof
      per cases;
      suppose
        (the Sorts of U2).ds <> {};
        hence thesis by FUNCT_2:def 1;
      end;
      suppose
        (the Sorts of U2).ds = {};
        then (the Sorts of U1).ds = {} by A2,A26,PZFMISC1:def 3;
        hence thesis;
      end;
    end;
    ((the Sorts of U1) * (the_arity_of o)).x = (the Sorts of U1).((
    the_arity_of o).x) by A25,FUNCT_1:13;
    then (x9.x) in dom Ff by A1,A25,A24,A29,MSUALG_3:6; then
A30: ((F*the_arity_of o).x).(x9.x) in rng Ff by A27,FUNCT_1:def 3;
    ((G*the_arity_of o).x) = G.((the_arity_of o).x) by A25,FUNCT_1:13;
    then Fr.x in dom ((G*the_arity_of o).x) by A28,A30,A23;
    hence Fr.x in (doms (G*the_arity_of o)).x by A22,FUNCT_6:22;
  end;
  reconsider GF = G ** F as ManySortedFunction of U1,U3 by A2,ALTCAT_2:4;
  dom GF = the carrier of S by PARTFUN1:def 2;
  then rng the_arity_of o c= dom GF; then
A31: dom (GF*the_arity_of o) = dom the_arity_of o by RELAT_1:27;
A32: x99 in doms Fa
  proof
    let i be object;
    set ai = (the_arity_of o).i;
    assume
A33: i in dom the_arity_of o; then
A34: ai in rng the_arity_of o by FUNCT_1:def 3;
    Fa.i = F.((the_arity_of o).i) by A33,FUNCT_1:13;
    then reconsider
    Ew = Fa.i as Function of (the Sorts of U1).ai,(the Sorts of U2)
    .ai by A34,PBOOLE:def 15;
A35: dom Ew = (the Sorts of U1).ai
    proof
      per cases;
      suppose
        (the Sorts of U2).ai = {};
        then (the Sorts of U1).ai = {} by A2,A34,PZFMISC1:def 3;
        hence thesis;
      end;
      suppose
        (the Sorts of U2).ai <> {};
        hence thesis by FUNCT_2:def 1;
      end;
    end;
    i in dom ((the Sorts of U1)*(the_arity_of o)) by A33,PRALG_2:3;
    then x99.i in ((the Sorts of U1)*(the_arity_of o)).i by A4;
    then x99.i in dom (Fa.i) by A33,A35,FUNCT_1:13;
    hence thesis by A33,MSSUBFAM:14;
  end;
  take GF;
  thus GF = G ** F;
A36: (G*the_arity_of o)**(F*the_arity_of o) = GF*the_arity_of o by FUNCTOR0:12;
A37: the Sorts of U1 is_transformable_to the Sorts of U3 by A2,A3,AUTALG_1:10;
    set tao = the_arity_of o;
A38: now
    let x be object;
    set ds = tao.x;
    assume
A39: x in dom doms (GF*tao); then
A40: x in dom tao by A31,FUNCT_6:59; then
A41: ds in rng tao by FUNCT_1:def 3;
    then reconsider
    Gf = GF.ds as Function of (the Sorts of U1).ds, (the Sorts of U3).ds
      by PBOOLE:def 15;
    x in dom (GF*tao) by A39,FUNCT_6:59; then
A42: (doms (GF*tao)).x = dom ((GF*tao).x) by FUNCT_6:22;
A43: (the Sorts of U1).ds = dom Gf
    proof
      per cases;
      suppose
        (the Sorts of U3).ds <> {};
        hence thesis by FUNCT_2:def 1;
      end;
      suppose
        (the Sorts of U3).ds = {};
        then (the Sorts of U1).ds = {} by A37,A41,PZFMISC1:def 3;
        hence thesis;
      end;
    end;
    x in dom ((the Sorts of U1) * tao) by A11,A40,RELAT_1:27;
    then x9.x in ((the Sorts of U1) * tao).x by A1,MSUALG_3:6;
    then x9.x in dom (GF.ds) by A40,A43,FUNCT_1:13;
    hence x9.x in (doms (GF*tao)).x by A42,A40,FUNCT_1:13;
  end;
  dom doms (GF*tao) = dom (GF*tao) by FUNCT_6:59;
  then dom x9 = dom doms (GF*tao) by A1,A31,MSUALG_3:6; then
A44: x9 in product doms (GF*tao) by A38,CARD_3:9;
    rng tao c= dom F by A5; then
S2: dom (F*tao) = dom tao by RELAT_1:27;
S0: dom tao = dom x99 by A1,MSUALG_3:6;
  dom Fr = dom (F*tao) /\ dom x99 by A19,PRALG_1:def 19
    .= dom (G*tao) by A9,S0,S2;
  then dom Fr = dom doms (G*tao) by FUNCT_6:59;
  then Fr in product doms (G*tao) by A20,CARD_3:9; then
A45: (Frege (G*tao)).((Frege(F*tao)).x) = (G*tao)..((Frege(F*tao)).x)
        by PRALG_2:def 2
    .= Ga..(Fa..x99) by A18,PRALG_2:def 2
    .= (Ga**Fa)..x99 by A32,CLOSURE1:4;
A46: Args (o,U3) <> {} by A1,A2,A3,Th3,AUTALG_1:10;
  then GF#x = (Frege(GF*tao)).x by A1,MSUALG_3:def 5
    .= (Frege (G*tao)).((Frege(F*tao)).x)
      by A44,A45,A36,PRALG_2:def 2
    .= (Frege (G*tao)).(F#x) by A1,A10,MSUALG_3:def 5;
  hence thesis by A10,A46,MSUALG_3:def 5;
end;
