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;
reserve
  A0 for (X,S)-terms non-empty MSAlgebra over S,
  A1 for all_vars_including (X,S)-terms MSAlgebra over S,
  A2 for all_vars_including inheriting_operations (X,S)-terms MSAlgebra over S,
  A for all_vars_including inheriting_operations free_in_itself
  (X,S)-terms MSAlgebra over S;
reserve X0 for non-empty countable ManySortedSet of S;
reserve A0 for all_vars_including inheriting_operations free_in_itself
  (X0,S)-terms MSAlgebra over S;

theorem Th85:
  for R being terminating with_UN_property invariant stable
  ManySortedRelation of Free(S,X)
  for g being ManySortedFunction of Free(S,X),Free(S,X)
  st g is_homomorphism Free(S,X),Free(S,X)
  for h being ManySortedFunction of NFAlgebra R, NFAlgebra R
  st for s being SortSymbol of S, x being Element of NFAlgebra R,s holds
     h.s.x = nf(g.s.x,R.s)
  for s being SortSymbol of S
  for o being OperSymbol of S st s = the_result_sort_of o
  for x being Element of Args(o,NFAlgebra R)
  for y being Element of Args(o,Free(S,X)) st x = y holds
  nf(Den(o,NFAlgebra R).(h#x),R.s) = nf(Den(o,Free(S,X)).(g#y),R.s)
  proof
    let R be terminating with_UN_property invariant stable
    ManySortedRelation of Free(S,X);
    let g be ManySortedFunction of Free(S,X),Free(S,X);
    assume g is_homomorphism Free(S,X),Free(S,X);
    let h be ManySortedFunction of NFAlgebra R, NFAlgebra R;
    assume
A1: for s being SortSymbol of S, x being Element of NFAlgebra R,s holds
    h.s.x = nf(g.s.x,R.s);
    let s be SortSymbol of S;
    let o be OperSymbol of S such that
A2: s = the_result_sort_of o;
    let x be Element of Args(o,NFAlgebra R);
    let y be Element of Args(o,Free(S,X)) such that
A3: x = y;
    defpred P[Nat] means $1 <= len the_arity_of o implies
    nf(Den(o,Free(S,X)).(((g#y)|$1)^((h#x)/^$1)),R.s)
    = nf(Den(o,NFAlgebra R).(h#x),R.s);
    dom(h#x) = dom the_arity_of o & dom(g#y) = dom the_arity_of o
    by MSUALG_3:6;
    then
A4: len(h#x) = len the_arity_of o & len(g#y) = len the_arity_of o
    by FINSEQ_3:29;
    (g#y)|0 = {} & (h#x)/^0 = h#x by Th81;
    then
A5: ((g#y)|0)^((h#x)/^0) = h#x by FINSEQ_1:34;
A6: Args(o,NFAlgebra R) c= Args(o, Free(S,X)) & h#x in Args(o,NFAlgebra R)
    by Lm3;
    then reconsider hx = h#x as Element of Args(o,Free(S,X));
    NForms R c= the Sorts of Free(S,X) & the Sorts of NFAlgebra R = NForms R
    by Def20,PBOOLE:def 18;
    then Result(o,Free(S,X)) = (the Sorts of Free(S,X)).s &
    Result(o,NFAlgebra R) = (the Sorts of NFAlgebra R).s &
    (the Sorts of NFAlgebra R).s c= (the Sorts of Free(S,X)).s &
    Den(o,NFAlgebra R).(h#x) in Result(o,NFAlgebra R)
    by A2,FUNCT_2:15;
    then
    reconsider Dx = Den(o,Free(S,X)).hx, Dnx = Den(o,NFAlgebra R).(h#x) as
    Element of Free(S,X),s;
    nf(nf(Dx,R.s),R.s) = nf(Dnx,R.s) by A2,Def20;
    then
A7: P[0] by A5,Th18;
A8: now let i be Nat;
      assume
A9:   P[i];
      thus P[i+1]
      proof assume
A10:     i+1 <= len the_arity_of o;
        then
A11:     i < len the_arity_of o by NAT_1:13;
A12:     len ((h#x)|i) = i & len ((g#y)|i) = i by A4,A11,FINSEQ_1:59;
A13:     (g#y)|(i+1) = ((g#y)|i)^<*(g#y).(i+1)*> by A4,A10,Th83;
A14:     (h#x)/^i = <*(h#x).(i+1)*>^((h#x)/^(i+1)) by A4,A10,Th84;
A15:     i+1 in dom the_arity_of o & dom ((the Sorts of NFAlgebra R)
        *the_arity_of o) = dom the_arity_of o
        by A10,NAT_1:11,FINSEQ_3:25,PRALG_2:3;
A16:     x .(i+1) in ((the Sorts of NFAlgebra R)*the_arity_of o).(i+1) &
        (the_arity_of o)/.(i+1) = (the_arity_of o).(i+1)
        by A15,PARTFUN1:def 6,MSUALG_3:6;
        then
        reconsider xi1 = x .(i+1) as Element of
        NFAlgebra R,(the_arity_of o)/.(i+1) by A15,FUNCT_1:13;
        dom x = dom the_arity_of o by MSUALG_3:6;
        then (h#x).(i+1) = h.((the_arity_of o)/.(i+1)).xi1 by A15
,MSUALG_3:def 6
        .= nf(g.((the_arity_of o)/.(i+1)).xi1,R.((the_arity_of o)/.(i+1)))
        by A1;
        then hx.(i+1) is_a_normal_form_of g.((the_arity_of o)/.(i+1)).xi1,
        R.((the_arity_of o)/.(i+1)) by REWRITE1:54;
        then
A17:     R.((the_arity_of o)/.(i+1)) reduces g.((the_arity_of o)/.(i+1)).xi1,
        hx.(i+1);
A18:     dom(h#x) = dom the_arity_of o by MSUALG_3:6;
        then
A19:     len (h#x) = len the_arity_of o by FINSEQ_3:29;
        defpred Q[set] means
        nf((Den(o,Free(S,X)).(((g#y)|i)^<*$1*>^((h#x)/^(i+1)))),R.s)
        = nf((Den(o,NFAlgebra R).(h#x)),R.s);
A20:     Q[hx.(i+1)] by A9,A10,NAT_1:13,A14,FINSEQ_1:32;
A21:     for a,b being set st [a,b] in R.((the_arity_of o)/.(i+1)) & Q[b]
        holds Q[a]
        proof
          let a,b be set;
          assume A22: [a,b] in R.((the_arity_of o)/.(i+1));
          then reconsider c = a, d = b as Element of (the Sorts of Free(S,X))
          .((the_arity_of o)/.(i+1)) by ZFMISC_1:87;
          reconsider j = i+1 as Element of NAT by ORDINAL1:def 12;
          set f = transl(o,j,((g#y)|i)^<*d*>^((h#x)/^(i+1)),Free(S,X));
          now
A23:         len(((g#y)|i)^<*d*>) = i+len<*d*> by A12,FINSEQ_1:22
            .= i+1 by FINSEQ_1:40;
            thus
A24:         dom (((the Sorts of Free(S,X))*the_arity_of o))
            = dom the_arity_of o by PRALG_2:3;
            len (((g#y)|i)^<*d*>^((h#x)/^(i+1))) = len(((g#y)|i)^<*d*>)+
            len((h#x)/^(i+1)) by FINSEQ_1:22
            .= i+1+(len (h#x) - (i+1)) by A10,A19,A23,RFINSEQ:def 1
            .= len the_arity_of o by A18,FINSEQ_3:29;
            hence dom (((the Sorts of Free(S,X))*the_arity_of o))
            = dom (((g#y)|i)^<*d*>^((h#x)/^(i+1))) by A24,FINSEQ_3:29;
            let a be object;
            assume
A25:         a in dom the_arity_of o;
            then reconsider b = a as Nat;
A26:         b <= len the_arity_of o & b >= 1 by A25,FINSEQ_3:25;
            per cases by NAT_1:8;
            suppose
A27:           b <= i;
              then
A28:           b in dom((g#y)|i) & dom((g#y)|i) c= dom(((g#y)|i)^<*d*>) &
              b in Seg i by A26,A12,FINSEQ_3:25,FINSEQ_1:26;
              then (((g#y)|i)^<*d*>^((h#x)/^(i+1))).a = (((g#y)|i)^<*d*>).a
              by FINSEQ_1:def 7 .= ((g#y)|i).a by A28,FINSEQ_1:def 7
              .= (g#y).a by A27,A26,FINSEQ_1:1,FUNCT_1:49;
              hence (((g#y)|i)^<*d*>^((h#x)/^(i+1))).a
              in ((the Sorts of Free(S,X))*the_arity_of o).a
              by A24,A25,MSUALG_3:6;
            end;
            suppose
A29:           b = i+1;
              then b in dom(((g#y)|i)^<*d*>) by A26,A23,FINSEQ_3:25;
              then (((g#y)|i)^<*d*>^((h#x)/^(i+1))).a = (((g#y)|i)^<*d*>).a
              by FINSEQ_1:def 7 .= d by A12,A29,FINSEQ_1:42;
              then (((g#y)|i)^<*d*>^((h#x)/^(i+1))).a
              in (the Sorts of Free(S,X)).((the_arity_of o)/.(i+1));
              hence (((g#y)|i)^<*d*>^((h#x)/^(i+1))).a
              in ((the Sorts of Free(S,X))*the_arity_of o).a
              by A16,A25,A29,FUNCT_1:13;
            end;
            suppose
A30:           b > i+1;
              then consider k being Nat such that
A31:           b = i+1+k by NAT_1:10;
              i+1+k > i+1+0 by A30,A31;
              then k > 0 & b-(i+1) <= (len the_arity_of o)-(i+1)
              by A26,XREAL_1:9,6;
              then k >= 0+1 & k <= len((h#x)/^(i+1))
              by A10,A19,RFINSEQ:def 1,A31,NAT_1:13;
              then
A32:           k in dom((h#x)/^(i+1)) by FINSEQ_3:25;
              then (((g#y)|i)^<*d*>^((h#x)/^(i+1))).a = ((h#x)/^(i+1)).k
              by A23,A31,FINSEQ_1:def 7 .= (h#x).a by A31,A19,A32,A10
,RFINSEQ:def 1;
              hence (((g#y)|i)^<*d*>^((h#x)/^(i+1))).a
              in ((the Sorts of Free(S,X))*the_arity_of o).a
              by A24,A25,A6,MSUALG_3:6;
            end;
          end;
          then
A33:       ((g#y)|i)^<*d*>^((h#x)/^(i+1))
          in product ((the Sorts of Free(S,X))*the_arity_of o) by CARD_3:9;
          then
          ((g#y)|i)^<*d*>^((h#x)/^(i+1)) in Args(o,Free(S,X)) by PRALG_2:3;
          then
A34:       [f.c,f.d] in R.s by A2,A15,A22,MSUALG_6:def 5,def 8;
          reconsider ad = ((g#y)|i)^<*d*>^((h#x)/^(i+1)) as Element of
          Args(o,Free(S,X)) by A33,PRALG_2:3;
          reconsider Dd = Den(o,Free(S,X)).ad as Element of Free(S,X),s
          by A2,FUNCT_2:15;
A35:       f.c = Den(o,Free(S,X)).((((g#y)|i)^<*d*>^((h#x)/^(i+1)))+*(j,c))
          by MSUALG_6:def 4
          .= Den(o,Free(S,X)).(((g#y)|i)^<*c*>^((h#x)/^(i+1))) by A12,Th82;
          f.d = Den(o,Free(S,X)).((((g#y)|i)^<*d*>^((h#x)/^(i+1)))+*(j,d))
          by MSUALG_6:def 4
          .= Den(o,Free(S,X)).(((g#y)|i)^<*d*>^((h#x)/^(i+1))) by A12,Th82;
          then
A36:       (Den(o,Free(S,X)).(((g#y)|i)^<*c*>^((h#x)/^(i+1)))),
          (Den(o,Free(S,X)).(((g#y)|i)^<*d*>^((h#x)/^(i+1))))
          are_convertible_wrt R.s by A34,A35,REWRITE1:29;
          assume Q[b];
          hence Q[a] by A36,REWRITE1:55;
        end;
A37:     Q[g.((the_arity_of o)/.(i+1)).xi1] from B(A20,A17,A21);
        dom y = dom the_arity_of o by MSUALG_3:6;
        hence
        nf((Den(o,Free(S,X)).(((g#y)|(i+1))^((h#x)/^(i+1)))),R.s)
        = nf((Den(o,NFAlgebra R).(h#x)),R.s) by A13,A3,A15,A37,MSUALG_3:def 6;
      end;
    end;
    for i being Nat holds P[i] from NAT_1:sch 2(A7,A8);
    then
A38: nf(Den(o,Free(S,X)).(((g#y)|len the_arity_of o)^
    ((h#x)/^len the_arity_of o)),R.s)
    = nf(Den(o,NFAlgebra R).(h#x),R.s);
    (g#y)|len the_arity_of o = g#y & (h#x)/^len the_arity_of o = {}
    by A4,FINSEQ_1:58,Th81;
    hence thesis by A38,FINSEQ_1:34;
  end;
