reserve i,j,n,k,m for Nat,
     a,b,x,y,z for object,
     F,G for FinSequence-yielding FinSequence,
     f,g,p,q for FinSequence,
     X,Y for set,
     D for non empty set;
reserve
  B,A,M for BinOp of D,
  F,G for D* -valued FinSequence,
  f for FinSequence of D,
  d,d1,d2 for Element of D;
reserve
  F,G for non-empty non empty FinSequence of D*,
  f for non empty FinSequence of D;

theorem
  M is commutative associative &
  A is commutative associative having_a_unity &
  M is_distributive_wrt A
implies
  M $$ ([#]dom F, A "**" F) = A $$ ([#]dom App F, M "**" App(F))
proof
  assume that
A1: M is commutative associative and
A2: A is commutative associative having_a_unity and
A3: M is_distributive_wrt A;
  defpred R[Nat] means
    for F be non-empty non empty FinSequence of D* st len F=$1 holds
      M $$ ([#]dom F, A "**" F) = A $$ ([#]dom App F, M "**" App(F));
A4: R[0];
A5: R[n] implies R[n+1]
  proof
    assume
A6:   R[n];
    per cases;
    suppose n=0;
      hence thesis by A1,A2,Th68;
    end;
    suppose
A7:     n>0;
      let F be non-empty non empty FinSequence of D* such that
A8:     len F=n+1;
      1<= n+1 by NAT_1:11;
      then len F in dom F by A8,FINSEQ_3:25;
      then reconsider FL=F.len F as non empty FinSequence of D;
      set FF=F|n,GG = <* FL *>;
A9:     len FF=n by NAT_1:11,FINSEQ_1:59,A8;
      reconsider FF as non-empty non empty FinSequence of D* by A7;
A10:    F = FF ^ GG by A8,FINSEQ_3:55;
      defpred P[object,object,object] means
        for f,g be FinSequence st f = $1 & g=$2
          for fg be FinSequence of D st fg= (App(F)).(f^g) holds $3 = M"**" fg;
A11:    for x,y st x in NAT* & y in NAT* ex z be object st z in D & P[x,y,z]
      proof
        let x,y;
        assume x in NAT* & y in NAT*;
        then reconsider x,y as FinSequence;
        reconsider fg=(App(F)).(x^y) as FinSequence of D;
        take M "**" fg;
        thus thesis;
      end;
      consider f being Function of [:NAT*,NAT*:],D such that
A12:    for x,y st x in NAT* & y in NAT* holds P[x,y,f.(x,y)]
        from BINOP_1:sch 1(A11);
      reconsider X=doms FF,Y=doms GG as Element of Fin (NAT*)
        by FINSUB_1:def 5;
      deffunc g(Element of NAT*) = A$$(X, (curry' f).$1);
      consider g be Function of NAT*,D such that
A13:    for e be Element of NAT* holds g.e=g(e) from FUNCT_2:sch 4;
A14:    dom f = [:NAT*,NAT*:] by FUNCT_2:def 1;
A15:    A$$(Y,g) = A$$([#]dom App F, M "**" App(F))
      proof
        set C=NAT-concatenation, s = C| [:X,Y:];
A16:      [:X,Y:] c= [:NAT*,NAT*:] =dom C by FUNCT_2:def 1,ZFMISC_1:96;
        then
A17:      dom s = [:X,Y:] by RELAT_1:62;
        C.:[:X,Y:] = doms (FF^GG) by Th54;
        then
A18:      rng s = doms (FF^GG) by RELAT_1:115;
        then
A19:      rng s = dom App F by A10,Def9;
A20:      s is one-to-one
        proof
          let x1,x2 be object such that
A21:        x1 in dom s & x2 in dom s & s.x1=s.x2;
          consider f1,g1 be object such that
A22:        f1 in X & g1 in Y & x1=[f1,g1] by A21,A17,ZFMISC_1:def 2;
          consider f2,g2 be object such that
A23:        f2 in X & g2 in Y & x2=[f2,g2] by A21,A17,ZFMISC_1:def 2;
          reconsider f1,f2,g1,g2 as NAT-valued FinSequence by A22,A23;
          len f1 = len FF & len f2 = len FF by A22,A23,Th47;
          then
A24:        f1 is (len FF)-element & f2 is (len FF)-element
            by CARD_1:def 7;
          s.x1 = C.x1 & s.x2 = C.x2 by A17,A21,FUNCT_1:49;
          then s.x1= C.(f1,g1) & s.x2= C.(f2,g2) by A22,A23,BINOP_1:def 1;
          then s.x1= f1^g1 & s.x2= f2^g2 by FOMODEL0:4;
          then f1=f2 & g1=g2 by A21,A24,FOMODEL0:41;
          hence thesis by A22,A23;
        end;
A25:      dom (f| [:X,Y:]) = [:X,Y:] by A14,ZFMISC_1:96,RELAT_1:62;
        dom (M "**" App(F)) = dom (App F) by FUNCT_2:def 1;
        then
A26:      dom (M "**" App(F)) = rng s by A10,A18,Def9;
        then
A27:      dom ((M "**" App(F))* s)=dom s by RELAT_1:27;
        for x st x in dom s holds (f| [:X,Y:]).x = ((M "**" App(F))* s).x
        proof
          let x;
          assume
A28:        x in dom s;
          then consider f1,g1 be object such that
A29:        f1 in X & g1 in Y & x=[f1,g1] by A17,ZFMISC_1:def 2;
          reconsider f1,g1 as NAT-valued FinSequence by A29;
          rng f1 c= NAT & rng g1 c= NAT;
          then f1 is FinSequence of NAT & g1 is FinSequence of NAT
            by FINSEQ_1:def 4;
          then
A30:        f1 in NAT* & g1 in NAT* by FINSEQ_1:def 11;
          (f1^g1) in doms (F) by A10,Th48,A29;
          then
A31:       (f1^g1) in dom App(F) by Def9;
          s.x = C.x by A17,A28,FUNCT_1:49;
          then s.x= C.(f1,g1) by A29,BINOP_1:def 1;
          then s.x= f1^g1 by FOMODEL0:4;
          then ((M "**" App(F))* s).x = (M "**" App(F)).(f1^g1)
            by FUNCT_1:12,A28,A27;
          then
A32:        ((M "**" App(F))* s).x = M "**" ((App(F)).(f1^g1)) by A31,Def10;
          (f| [:X,Y:]).x = f.x = f.(f1,g1)
            by FUNCT_1:47,A28,A25,A16,A29,BINOP_1:def 1;
          hence thesis by A32,A12,A30;
        end;
        then f| [:X,Y:] = (M "**" App(F)) * s by A25,A26,RELAT_1:27,A16;
        then A$$([:X,Y:],f) = A$$([#]dom App F, M "**" App(F))
          by A2,A17,A20,A19,SETWOP_2:5;
        hence thesis by A13,A2,MATRIX_3:32;
      end;
A33:    for h be FinSequence st h in Y holds
          g.h = M.( M $$ ([#]dom FF, A "**" FF), FL.(h  .1))
      proof
        let h be FinSequence;
        assume
A34:      h in Y;
        then h in { <*i*> where i is Element of NAT:i in dom FL} by Th55;
        then consider i be Element of NAT such that
A35:      h=<*i*> & i in dom FL;
        reconsider H=h as Element of NAT* by A35;
        FL.i in rng FL by A35,FUNCT_1:def 3;
        then reconsider FLi=FL.i as Element of D;
        set AFF=App(FF);
        defpred P[set] means $1<>{} & $1 c= X implies
          for BF be Element of Fin (dom AFF)
            for BN be Element of Fin (NAT*) st BF=$1 =BN holds
              M.(A $$ (BF, M "**" App(FF)), FL.i) = A$$(BN, (curry' f).H);
A36:      P [{}.(NAT*)];
A37:      for C being Element of Fin (NAT*), b being Element of NAT* holds
        P[C] & not b in C implies P[C \/ {b}]
        proof
          let C be Element of Fin (NAT*), b be Element of NAT* such that
A38:        P[C] & not b in C and
            C \/ {b} <>{} and
A39:        C \/ {b} c= X;
          let BF be Element of Fin (dom AFF), BN be Element of Fin (NAT*)
            such that
A40:        BF= C \/ {b} =BN;
          C c= C \/ {b} by XBOOLE_1:7;
          then
A41:        C c= X by A39;
          then C c= dom AFF by Def9;then
          reconsider CF = C as Element of Fin (dom AFF) by FINSUB_1:def 5;
          b in {b} by TARSKI:def 1;
          then
A42:        b in C \/ {b} by XBOOLE_0:def 3;
          reconsider bF = b as Element of dom AFF by A42,A39,Def9;
A43:        len (AFF.b) = len b & len b= len FF by Def9,Th47,A42,A39;
          [b,H] in dom f by A14;
          then
A44:        (curry' f).H.b=f.(b,H) by FUNCT_5:22;
          (App(GG)).H = <*FLi*> by Th60,A35;
          then
A45:        (App(F)).(b^H) = (AFF.b) ^ (<*FLi*>) by A42,A39,A34,Th61,A10;
A46:        M "**" ((AFF.b) ^ (<*FLi*>))=M.(M "**" (AFF.b),FLi)
            by A43,NAT_1:14,FINSOP_1:4;
          per cases;
          suppose
A47:          C={};
            hence M.(A $$ (BF, M "**" AFF), FL.i)
              = M.((M "**" AFF).bF, FLi) by A2,A40,SETWISEO:17
             .= M.(M "**" (AFF.b),FLi) by Def10
             .= (curry' f).H.b by A44,A12,A45,A46
             .= A$$(BN, (curry' f).H) by A47,A40,A2,SETWISEO:17;
          end;
          suppose
A48:          C<>{};
A49:          (M "**" AFF).bF = M "**" (AFF.b) by Def10;
            thus A$$(BN, (curry' f).H)
              = A.(A$$(C, (curry' f).H),((curry' f).H).b )
                by A2,A38,A40,SETWOP_2:2
             .= A.(M.(A $$ (CF, M "**" AFF), FLi),((curry' f).H).b )
                by A48,A41,A38
             .= A.(M.(A $$ (CF, M "**" AFF), FLi), M.(M "**" (AFF.b),FLi) )
                by A44,A12,A45,A46
             .= M.(A.(A $$ (CF, M "**" AFF),M "**" (AFF.b)),FLi)
                by A3,BINOP_1:11
             .= M.(A $$ (BF, M "**" AFF), FL.i) by A40,A49,A2,A38,SETWOP_2:2;
          end;
        end;
A50:      for B being Element of Fin (NAT*) holds P[B]
            from SETWISEO:sch 2(A36,A37);
        M.( A$$([#]dom App(FF), M "**" App(FF)), FL.i) = A$$(X, (curry' f).H)
          by A50,Def9;
        then M.( A$$([#]dom App(FF), M "**" App(FF)), FL.i) = g.h by A13;
        hence thesis by A35,A9,A6;
      end;
      defpred h[object,object] means for f be Function st f=$1 holds $2=f.1;
A51:    for x st x in Y ex y st y in dom FL & h[x,y]
      proof
        let x;
        assume x in Y;
        then x in { <*i*> where i is Element of NAT:i in dom FL} by Th55;
        then consider i be Element of NAT such that
A52:      x=<*i*> & i in dom FL;
        take i;
        thus thesis by A52;
      end;
      consider h be Function such that
A53:    dom h = Y & rng h c= dom FL & for x be object st
        x in Y holds h[x,h.x] from FUNCT_1:sch 6(A51);
      dom FL c= rng h
      proof
        let y such that
A54:      y in dom FL;
        <*y*> in { <*i*> where i is Element of NAT:i in dom FL} by A54;
        then <*y*> in Y by Th55;
        then h.<*y*> in rng h & h.<*y*> = <*y*>.1 by FUNCT_1:def 3,A53;
        hence thesis;
      end;
      then
A55:    rng h = dom FL by A53;
A56:    h is one-to-one
      proof
        let x1,x2 be object  such that
A57:      x1 in dom h & x2 in dom h & h.x1=h.x2;
        x1 in { <*i*> where i is Element of NAT:i in dom FL} by A53,A57,Th55;
        then consider i1 be Element of NAT such that
A58:      x1=<*i1*> & i1 in dom FL;
        x2 in { <*i*> where i is Element of NAT:i in dom FL} by A53,A57,Th55;
        then consider i2 be Element of NAT such that
A59:      x2=<*i2*> & i2 in dom FL;
        h.x1 = <*i1*>.1 & h.x2 = <*i2*>.1 by A58,A59,A57,A53;
        hence thesis by A58,A59,A57;
      end;
      deffunc fM(object) = M.( M$$ ([#]dom FF, A "**" FF), FL.$1);
A60:    x in dom FL implies fM(x) in D
      proof
        assume x in dom FL;
        then FL.x in rng FL c= D by FUNCT_1:def 3;
        then reconsider FLx =FL.x as Element of D;
        M.( M$$ ([#]dom FF, A "**" FF), FLx) in D;
        hence thesis;
      end;
      consider fM be Function of dom FL,D such that
A61:    x in dom FL implies fM.x = fM(x) from  FUNCT_2:sch 2(A60);
A62:    dom g = NAT* by FUNCT_2:def 1;
A63:    dom fM=dom FL by FUNCT_2:def 1;
      then
A64:    dom (fM * h) = Y by A53,RELAT_1:27;
      x in Y implies (g|Y).x = (fM * h).x
      proof
        assume
A65:      x in Y;
        then x in { <*i*> where i is Element of NAT:i in dom FL} by Th55;
        then consider i be Element of NAT such that
A66:      x=<*i*> & i in dom FL;
A67:      g.x = (g|Y).x by A65,FUNCT_1:49;
A68:      g.x = M.( M $$ ([#]dom FF, A "**" FF),FL.(<*i*>.1)) by A65,A66,A33;
        (fM * h).x = fM.(h.x) & h.x in dom fM & h.x = <*i*>.1
          by A65,FUNCT_1:11,13,A64,A66,A53;
        hence thesis by A68,A67,A61;
      end;
      then g|Y = fM * h by A62,A63,A53,RELAT_1:27;
      then A $$ ([#]dom FL, fM) = A$$(Y,g) by A53,A55,A56,A2,SETWOP_2:5;
      hence thesis by A10,A15,Th67,A61,A1,A2,A3,BINOP_1:def 11;
    end;
  end;
  R[n] from NAT_1:sch 2(A4,A5);
  hence thesis;
end;
