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;
reserve f,g for FinSequence of D,
        a,b,c for set,
        F,F1,F2 for finite set;

theorem Th127:
  A is commutative associative having_a_unity having_an_inverseOp &
  M is associative commutative having_a_unity &
  M is_distributive_wrt A
implies
  for E1 be Enumeration of F1 st union F1 c= Seg (1+m)
    for Ee be Enumeration of Ext(F1,1+m,2+m) st
        Ee = Ext(E1,1+m,2+m)
    ex S be Subset of doms(m+2,card F1) st
      S = (len E1)-tuples_on {1+m,2+m} &
      for CFe be non-empty non empty FinSequence of D*,f,d1,d2 st
        len f=m &
        CFe = SignGenOp(f^<*d1*>^<*d2*>,A,Ext(F1,1+len f,2+len f) ) * Ee
      for Sd be Element of Fin dom App CFe st Sd = S holds
      (M "**" App (SignGenOp(f^<*A .(d1,d2)*>,A,F1)*E1)).(len E1|->(1+ len f))
        = A$$(Sd,M"**"App CFe)
proof
  set I=the_inverseOp_wrt A;
  assume that
A1: A is commutative associative having_a_unity
    having_an_inverseOp and
A2:M is associative commutative having_a_unity and
A3: M is_distributive_wrt A;
  defpred P[Nat] means
    for F1 for E1 be Enumeration of F1 st union F1 c= Seg (1+m) & len E1=$1
    for Ee be Enumeration of Ext(F1,1+m,2+m) st
    Ee = Ext(E1,1+m,2+m)
    ex S be Subset of doms(m+2,card F1) st
    S = (len E1)-tuples_on {1+m,2+m} &
    for CFe be non-empty non empty FinSequence of D*,f,d1,d2 st len f=m &
    CFe = SignGenOp(f^<*d1*>^<*d2*>,A, Ext(F1,1+len f,2+len f) ) * Ee
    for Sd be Element of Fin dom App CFe st Sd=S holds
     (M "**" App (SignGenOp(f^<*A . (d1,d2)*>,A,F1) * E1)).(len E1|->(1+len f))
       = A$$(Sd,M"**"App CFe);
A4: P[0]
  proof
    let F1;
    let E1 be Enumeration of F1 such that
A5:   union F1 c= Seg (1+m) & len E1=0;
    set Fe=Ext(F1,1+m,2+m);
    let Ee be Enumeration of Fe such that
    Ee = Ext(E1,1+m,2+m);
A6:   len E1=card F1 by CARD_1:def 7;
    then doms(m+2,card F1) = {<*>Seg (m+2)} by A5,FINSEQ_2:94;
    then reconsider S= {<*>{1+m,2+m}} as Subset of doms(m+2,card F1);
    take S;
    thus S = (len E1)-tuples_on {1+m,2+m} by A5,FINSEQ_2:94;
    let CFe be non-empty non empty FinSequence of D*,f,d1,d2 such that
A7:   len f=m and
A8: CFe = SignGenOp(f^<*d1*>^<*d2*>,A, Ext(F1,1+len f,2+len f) ) * Ee;
    1+len f < 1+len f+1 by NAT_1:13;
    then not 2+len f in union F1 by A7,A5,FINSEQ_1:1;
    then card F1 = card Fe =len Ee by A7,Th10,CARD_1:def 7;
    hence thesis by A6,A5,A8;
  end;
A9:P[n] implies P[n+1]
  proof
    set n1=n+1;
    assume
A10: P[n];
    let F1;
    let E1 be Enumeration of F1 such that
A11:union F1 c= Seg (1+m) & len E1=n1;
    set Fe=Ext(F1,1+m,2+m);
    let Ee be Enumeration of Fe such that
A12:Ee = Ext(E1,1+m,2+m);
    set sij=(len E1)-tuples_on {1+m,2+m};
A13: len E1=card F1 by CARD_1:def 7;
A14: Seg (1+m+1) = Seg (1+m)\/{1+m+1} by FINSEQ_1:9;
    1+m in Seg (m+2) & 1+m+1 in Seg (m+2) by FINSEQ_1:4,A14,ZFMISC_1:136;
    then {1+m,2+m} c= Seg (m+2) by ZFMISC_1:32;
    then reconsider sij as Subset of doms(m+2,card F1) by A13,SRINGS_5:5;
    take sij;
    thus sij = (len E1)-tuples_on {1+m,2+m};
    let CFe be non-empty non empty FinSequence of D*,f,d1,d2 such that
A15:len f=m and
A16:CFe = SignGenOp(f^<*d1*>^<*d2*>,A, Ext(F1,1+len f,2+len f) ) * Ee;
    set fD=f^<*A.(d1,d2)*>,fDD=f^<*d1*>^<*d2*>;
    let Sd be Element of Fin dom App CFe such that
A17: Sd=sij;
    set CE= (SignGenOp(fD,A,F1) * E1);
A18: len fD=len f+1 >=1 by FINSEQ_2:16,NAT_1:11;
    1+len f < 1+len f+1 by NAT_1:13;
    then
A19: not 2+len f in union F1 by A15,A11,FINSEQ_1:1;
A20: len fDD = 1 + len (f^<*d1*>) by FINSEQ_2:16
    .= 1+(1 + len f) by FINSEQ_2:16
    .= 2+len f;
A21:  1+len f <= 2+len f & 1+0 <= 2+len f by XREAL_1:8;
    then
A22:1+len f in dom fDD & 2+len f in dom fDD by A18,A20,FINSEQ_3:25;
    dom <*d1,d2*>={1,2} by FINSEQ_1:92;
    then
A23: 1 in dom <*d1,d2*> & 2 in dom <*d1,d2*> by TARSKI:def 2;
    fDD = f^<*d1,d2*> by FINSEQ_1:32;
    then
A24: fDD.(1+len f) = <*d1,d2*>.1 =d1 &
    fDD.(2+len f) = <*d1,d2*>.2 =d2 by A23,FINSEQ_1:def 7;
    set F1n=F1\{E1.n1};
    reconsider E1n= E1|n as Enumeration of F1n by Th96,A11;
    reconsider En= <*E1.n1*> as Enumeration of {E1.n1} by Th96,A11;
    set CEn=SignGenOp(fD,A,F1n) * E1n;
A25: n< n1 by NAT_1:13;
    then
A26: len E1n = n by A11,FINSEQ_1:59;
A27:len fD in dom fD by A18,FINSEQ_3:25;
    then
A28:n |-> (len fD) in doms CEn by A26,Th102;
    len En = 1 by FINSEQ_1:40;
    then
A29: 1 |-> (len fD) in doms(SignGenOp(fD,A,{E1.n1}) * En)
      by A27,Th102;
    n1 |-> (len fD) in doms CE by A27,A11,Th102;
    then
A30: n1 |-> (len fD) in dom App CE by Def9;
A31: n1 |-> (len fD) = (n |-> (len fD))^(1 |-> (len fD))
      by FINSEQ_2:123;
A32: F1 = F1n\/ {E1.n1} by Th96,A11;
    then
A33: union F1n c= union F1 & union {E1.n1} c= union F1
      by ZFMISC_1:77,XBOOLE_1:7;
    then
A34:  not 2+len f in union F1n & not 2+len f in union {E1.n1}  by A19;
    reconsider EE1n = Ext(E1n,1+len f,2+len f) as Enumeration of
    Ext(F1n,1+len f,2+len f) by A33,A19,Th28;
    reconsider EEn = Ext(En,1+len f,2+len f) as Enumeration of
    Ext({E1.n1},1+len f,2+len f) by A33,A19,Th28;
    set CEE1n=(SignGenOp(fDD,A, Ext(F1n,1+len f,2+len f) ) * EE1n),
    CEEn = (SignGenOp(fDD,A, Ext({E1.n1},1+len f,2+len f) ) * EEn);
A35:E1 = E1n ^ En by A11,FINSEQ_3:55;
    then CE = (SignGenOp(fD,A,F1n) * E1n)^
    (SignGenOp(fD,A,{E1.n1}) * En) by Th81,A32;
    then
A36: (App CE).(n1 |-> (len fD)) =
    (( App CEn ).(n |-> (len fD)))^
    (( App (SignGenOp(fD,A,{E1.n1}) * En)).(1 |-> (len fD)))
    by A28,A31,A29,Th61;
A37: (M "**" App CE).(len E1|-> (1+ len f))
    = M "**" ((App CE).(n1|-> (len fD))) by A18,Def10,A11,A30
    .= M. (M"**"( App CEn).(n |-> (len fD)),
    M"**"( App (SignGenOp(fD,A,{E1.n1}) * En)).(1 |-> (len fD)))
    by FINSOP_1:5,A2,A36;
A38: Fe = Ext(F1n,1+len f,2+len f)\/ Ext({E1.n1},1+len f,2+len f)
    by A15,Th16,A32;
    Ee = EE1n^EEn by A15,A12,A35,Th19;
    then
A39: CFe = CEE1n^CEEn by A15,A16,A38,Th81;
A40: for x st x in dom CEEn holds CEEn.x is non empty
    proof
      let x;
      assume x in dom CEEn;
      then CEEn.x = SignGen(fDD,A,EEn.x) by Th80;
      hence thesis;
    end;
    rng CEEn c= D*;
    then reconsider CEEn as non-empty non empty FinSequence of D*
    by A40,FINSEQ_1:def 4,FUNCT_1:def 9;
A41: len fD in dom fD = dom SignGen(fD,A,E1.n1) by Def11,A18,FINSEQ_3:25;
    then SignGen(fD,A,E1.n1).(len fD) in rng SignGen(fD,A,E1.n1)
      by FUNCT_1:def 3;
    then
    reconsider temp= SignGen(fD,A,E1.n1).(len fD) as Element of D;
A42:  SignGenOp(fD,A,{E1.n1}) * En = <* SignGen(fD,A,E1.n1) *> by Th78;
A43: M"**"(( App (<* SignGen(fD,A,E1.n1) *>)).(1 |-> (len fD)))=
    M"**"( App (<* SignGen(fD,A,E1.n1) *>)).<*len fD*> by FINSEQ_2:59
    .= M"**" <* temp *> by A41,Th60
    .= SignGen(fD,A,E1.n1).(len fD) by FINSOP_1:11;
    1<=n1 by NAT_1:11;
    then
A44: n1 in dom E1 by A11,FINSEQ_3:25;
A45: Ext({E1.n1},1+len f,2+len f) = {Ee.n1} by A15,A12,A44,Th37;
A46: CEEn= <* SignGen(fDD,A,Ee.n1) *> by A45,Th78;
A47: dom SignGen(fDD,A,Ee.n1) = dom fDD by Def11;
A48: len <* 1+len f *> = 1 & len <* 2+len f *> = 1 by FINSEQ_1:40;
    <* 1+len f *>.1 in dom fDD & <* 2+len f *>.1 in dom fDD
    by A21,A18,A20,FINSEQ_3:25;
    then <* 1+len f *> in doms CEEn & <* 2+len f *> in doms CEEn
    by A47,A48,A46,Th51;
    then reconsider II=<* 1+len f *>,JJ= <* 2+len f *>
    as Element of dom App CEEn by Def9;
A49: rng <* 1+len f *> = { 1+len f} &
     rng <* 2+len f *> = { 2+len f} by FINSEQ_1:39;
A50:SignGen(fD,A,E1.n1).(len fD) = A$$({.II,JJ.},M"**"App CEEn)
    proof
      SignGen(fDD,A,Ee.n1).(1+len f) in rng SignGen(fDD,A,Ee.n1)
      by A22,A47,FUNCT_1:def 3;
      then reconsider t1=SignGen(fDD,A,Ee.n1).(1+len f) as Element of D;
      SignGen(fDD,A,Ee.n1).(2+len f) in rng SignGen(fDD,A,Ee.n1)
        by A22,A47,FUNCT_1:def 3;
      then reconsider t2=SignGen(fDD,A,Ee.n1).(2+len f) as Element of D;
      (App CEEn).II = <* t1 *> &
      (App CEEn).JJ = <* t2 *> by Th60,A46,A47,A21,A18,A20,FINSEQ_3:25;
      then
A51:  M"**"((App CEEn).II) = t1 & M"**"((App CEEn).JJ) = t2
      by FINSOP_1:11;
      II.1 =len f +1 & JJ.1=len f+2;
      then II <>JJ;
      then
A52:  A$$({.II,JJ.},M"**"App CEEn) =
      A.( (M"**"App CEEn).II,(M"**"App CEEn).JJ) by SETWOP_2:1,A1
      .= A.( M"**"((App CEEn).II),(M"**"App CEEn).JJ) by Def10
      .= A. (SignGen(fDD,A,Ee.n1).(1+len f), SignGen(fDD,A,Ee.n1).(2+len f))
        by Def10,A51;
A53:  fD.(len fD) = A.(d1,d2) by A18;
      per cases;
      suppose
A54:    len fD in E1.n1;
        then
A55:    SignGen(fD,A,E1.n1).(len fD) = I. (A.(d1,d2))
          by A41,Def11,A53;
        {E1.n1 \/{2+len f}} = Ext({E1.n1},1+len f,2+len f) by A18,A54,Th29;
        then Ee.n1 = E1.n1 \/{2+len f} by A45,ZFMISC_1:18;
        then 1+len f in Ee.n1 & 2+len f in Ee.n1 by A54,A18,ZFMISC_1:136;
        then SignGen(fDD,A,Ee.n1).(1+len f) = I.d1 &
        SignGen(fDD,A,Ee.n1).(2+len f) = I.d2 by A24,A47,A22,Def11;
        hence thesis by A1,Th103,A55,A52;
      end;
      suppose
A56:    not len fD in E1.n1;
        {E1.n1} = Ext({E1.n1},1+len f,2+len f) by A18,A56,Th30;
        then not 1+len f in Ee.n1 & not 2+len f in Ee.n1
          by A56,A18,ZFMISC_1:25,A34,A45,ZFMISC_1:18;
        then SignGen(fDD,A,Ee.n1).(1+len f) = d1 &
        SignGen(fDD,A,Ee.n1).(2+len f) = d2 by A24,A47,A22,Def11;
        hence thesis by A56,A41,Def11,A53,A52;
      end;
    end;
    per cases;
    suppose
A57: n<>0;
A58: for x st x in dom CEE1n holds CEE1n.x is non empty
      proof
        let x;
        assume x in dom CEE1n;
        then CEE1n.x = SignGen(fDD,A,EE1n.x) by Th80;
        hence thesis;
      end;
      rng CEE1n c= D*;
      then reconsider CEE1n as non-empty non empty FinSequence of D*
        by A58,FINSEQ_1:def 4,FUNCT_1:def 9,A26,A57;
      union F1n c= Seg (1+len f) by A15,A33,A11;
      then consider S be Subset of doms(m+2,card F1n) such that
A59:  S = (len E1n)-tuples_on {1+m,2+m} and
A60:  for CFe be non-empty non empty FinSequence of D*,f,d1,d2 st
      len f=m &
      CFe = SignGenOp(f^<*d1*>^<*d2*>,A, Ext(F1n,1+len f,2+len f) ) * EE1n
      for Sd be Element of Fin dom App CFe st Sd=S
      holds
      (M "**" App (SignGenOp(f^<*A . (d1,d2)*>,A,F1n) * E1n)).
      (len E1n|-> (1+ len f)) = A$$(Sd,M"**"App CFe)
        by A15,A10,A25,A11,FINSEQ_1:59;
      len EE1n = len E1n =card F1n by CARD_1:def 7;
      then dom App CEE1n = doms(m+2,card F1n) by A20,A15,Lm3;
      then reconsider S1=S as Element of Fin dom App CEE1n by FINSUB_1:def 5;
      S1 c= dom App CEE1n & {.II,JJ.} c= dom App CEEn by FINSUB_1:def 5;
      then S1 c= doms CEE1n & {.II,JJ.} c= doms CEEn by Def9;
      then S1^{.II,JJ.} c= doms CFe by A39,Th49;
      then S1^{.II,JJ.} c= dom App CFe by Def9;
      then reconsider SIJ=S1^{.II,JJ.} as Element of Fin dom App CFe
      by FINSUB_1:def 5;
A61:  n |-> (len fD) in dom App CEn by A28,Def9;
A62:  SIJ = (len E1)-tuples_on {1+len f,2+len f}
      proof
        thus SIJ c= (len E1)-tuples_on {1+len f,2+len f}
        proof
          let y such that
A63:      y in SIJ;
          consider s,ij be FinSequence such that
A64:      y=s^ij & s in S & ij in {.II,JJ.} by A63,POLNOT_1:def 2;
          reconsider s as Element of (len E1n)-tuples_on {1+len f,2+len f}
          by A15,A64,A59;
A65:      ij=II or ij=JJ by A64,TARSKI:def 2;
          then reconsider ij as FinSequence of {1+len f,2+len f}
          by A49,ZFMISC_1:7,FINSEQ_1:def 4;
          len (s^ij) = len E1 by A11,A26,A65,CARD_1:def 7;
          hence thesis by A64;
        end;
        let y such that
A66:    y in (len E1)-tuples_on {1+len f,2+len f};
        reconsider y as Element of (len E1)-tuples_on {1+len f,2+len f} by A66;
A67:    len y = len E1=1+len E1n by A11,A25,FINSEQ_1:59,CARD_1:def 7;
        then
A68:    y = (y|(len E1n))^<*y.(1+len E1n)*> by FINSEQ_3:55;
        len (y|(len E1n)) = len E1n by A11,A26,CARD_1:def 7;
        then
A69:    y|(len E1n) is Element of
        (len E1n)-tuples_on {1+len f,2+len f} by FINSEQ_2:92;
        1<= 1+len E1n by NAT_1:11;
        then (1+len E1n) in dom y by A67,FINSEQ_3:25;
        then y.(1+len E1n) in rng y by FUNCT_1:def 3;
        then y.(1+len E1n) = 1+len f or y.(1+len E1n) = 2+len f
          by TARSKI:def 2;
        then <*y.(1+len E1n)*> in {.II,JJ.} by TARSKI:def 2;
        hence thesis by A68,A15,A69,A59,POLNOT_1:def 2;
      end;
      thus A$$(Sd,M"**"App CFe) =
      M.(A $$ (S1,M "**" App CEE1n),SignGen(fD,A,E1.n1).(len fD))
        by A50,A39,Th93,A1,A2,A3,A15,A62,A17
      .= M.( (M "**" App (CEn)).(len E1n|-> (1+ len f)),
        M"**"(( App (<* SignGen(fD,A,E1.n1) *>)).(1 |-> (len fD))))
        by A15,A60,A43
      .= M.((M "**" App (CEn)).( n |-> (len fD)),
        M"**"(( App (<* SignGen(fD,A,E1.n1) *>)).(1 |-> (len fD))))
        by A25,A11,FINSEQ_1:59,A18
      .= (M "**" App CE).(len E1|-> (1+ len f)) by A37,A42,Def10,A61;
    end;
    suppose
A70:  n=0;
      then
A71:  E1n= {};
      then
A72:  E1=En & F1n={} by A35;
A73:  CEE1n={} by A71;
      reconsider SIJ={.II,JJ.} as Element of Fin dom App CFe by A39,A73;
A74:  SIJ = (len E1)-tuples_on {1+len f,2+len f}
      proof
        thus SIJ c= (len E1)-tuples_on {1+len f,2+len f}
        proof
          let y be object;
          assume y in SIJ;
          then
A75:      y=II or y=JJ by TARSKI:def 2;
          then reconsider y as FinSequence of {1+len f,2+len f}
            by A49,ZFMISC_1:7,FINSEQ_1:def 4;
          y is Element of (len E1)-tuples_on {1+len f,2+len f}
            by A11,A70,A75,A48,FINSEQ_2:92;
          hence thesis;
        end;
        let y be object;
        assume y in (len E1)-tuples_on {1+len f,2+len f};
        then reconsider y as Element of (len E1)-tuples_on {1+len f,2+len f};
        len y = 1 by A70,A11,CARD_1:def 7;
        then 1 in dom y by FINSEQ_3:25;
        then y.1 in rng y c= {1+len f,2+len f} by FUNCT_1:def 3;
        then y.1 = 1+len f or y.1 = 2+len f by TARSKI:def 2;
        then y =II or y = JJ by A70,A11,CARD_1:def 7,FINSEQ_1:40;
        hence thesis by TARSKI:def 2;
      end;
      thus (M "**" App CE).(len E1|-> (1+ len f)) = A$$(Sd, M"**"App CFe)
      by A15,A73,A39,A74,A17,Def10,A18,A30,A50,A43,A72,A32,A42,A70,A11;
    end;
  end;
  P[n] from NAT_1:sch 2(A4,A9);
  hence thesis;
end;
