reserve x for set,
  C for Ordinal,
  L0 for Sequence;
reserve O1,O2 for Ordinal;

theorem Th32:
  for L be lower-bounded modular LATTICE for S being ExtensionSeq2
of the carrier of L, BasicDF(L) for FS being non empty set st FS = union the
set of all  (S.i
)`1 where i is Element of NAT holds union the set of all  (S.i)`2 where i
  is Element of NAT is distance_function of FS,L
proof
  let L be lower-bounded modular LATTICE;
  let S be ExtensionSeq2 of the carrier of L, BasicDF(L);
  let FS be non empty set;
  assume
A1: FS = union the set of all  (S.i)`1 where i is Element of NAT;
  reconsider FS as non empty set;
  set A = the carrier of L;
  set FD = union the set of all  (S.i)`2 where i is Element of NAT;
  now
    let x,y be set;
    assume that
A2: x in the set of all  (S.i)`2 where i is Element of NAT and
A3: y in the set of all  (S.i)`2 where i is Element of NAT;
    consider k being Element of NAT such that
A4: x = (S.k)`2 by A2;
    consider l being Element of NAT such that
A5: y = (S.l)`2 by A3;
    k <= l or l <= k;
    then x c= y or y c= x by A4,A5,Th31;
    hence x,y are_c=-comparable;
  end;
  then
A6: the set of all  (S.i)`2 where i is Element of NAT is c=-linear;
  the set of all  (S.i)`2 where i is Element of NAT c= PFuncs([:FS,
  FS:],A)
  proof
    let z be object;
    assume z in the set of all  (S.i)`2 where i is Element of NAT;
    then consider j being Element of NAT such that
A7: z = (S.j)`2;
    consider A9 being non empty set, d9 being distance_function of A9,L, Aq
    being non empty set, dq being distance_function of Aq,L such that
    Aq, dq is_extension2_of A9,d9 and
A8: S.j = [A9,d9] and
    S.(j+1) = [Aq,dq] by Def11;
A9:  A9 = [A9,d9]`1;
    A9 in the set of all  (S.i)`1 where i is Element of NAT
       by A9,A8;
    then dom d9 = [:A9,A9:] & A9 c= FS by A1,FUNCT_2:def 1,ZFMISC_1:74;
    then
A10: rng d9 c= A & dom d9 c= [:FS,FS:] by ZFMISC_1:96;
    z = d9 by A7,A8;
    hence thesis by A10,PARTFUN1:def 3;
  end;
  then FD in PFuncs([:FS,FS:],A) by A6,TREES_2:40;
  then
A11: ex g being Function st FD = g & dom g c= [:FS,FS:] & rng g c= A by
PARTFUN1:def 3;
  (S.0)`1 in the set of all  (S.i)`1 where i is Element of NAT;
  then reconsider
  X = the set of all  (S.i)`1 where i is Element of NAT as
  non empty set;
  set LL = { [:I,I:] where I is Element of X : I in X }, PP = the set of all
 [:(S.i)`1,(S.i
  )`1:] where i is Element of NAT;
  defpred X[object,object] means $2 = (S.$1)`2;
A12: LL = PP
  proof
    thus LL c= PP
    proof
      let x be object;
      assume x in LL;
      then consider J being Element of X such that
A13:  x = [:J,J:] and
A14:  J in X;
      ex j being Element of NAT st J = (S.j)`1 by A14;
      hence thesis by A13;
    end;
    let x be object;
    assume x in PP;
    then consider j being Element of NAT such that
A15: x = [:(S.j)`1,(S.j)`1:];
    (S.j)`1 in X;
    hence thesis by A15;
  end;
  reconsider FD as Function by A11;
A16: for x being object st x in NAT ex y being object st X[x,y];
  consider F being Function such that
A17: dom F = NAT and
A18: for x being object st x in NAT holds X[x,F.x] from CLASSES1:sch 1(A16);
A19: rng F = the set of all  (S.i)`2 where i is Element of NAT
  proof
    thus rng F c= the set of all  (S.i)`2 where i is Element of NAT
    proof
      let x be object;
      assume x in rng F;
      then consider j being object such that
A20:  j in dom F and
A21:  F.j = x by FUNCT_1:def 3;
      reconsider j as Element of NAT by A17,A20;
      x = (S.j)`2 by A18,A21;
      hence thesis;
    end;
    let x be object;
    assume x in the set of all  (S.i)`2 where i is Element of NAT;
    then consider j being Element of NAT such that
A22: x = (S.j)`2;
    x = F.j by A18,A22;
    hence thesis by A17,FUNCT_1:def 3;
  end;
  F is Function-yielding
  proof
    let x be object;
    assume x in dom F;
    then reconsider j = x as Element of NAT by A17;
    consider A1 being non empty set, d1 being distance_function of A1,L, Aq1
    being non empty set, dq1 being distance_function of Aq1,L such that
    Aq1, dq1 is_extension2_of A1,d1 and
A23: S.j = [A1,d1] and
    S.(j+1) = [Aq1,dq1] by Def11;
    [A1,d1]`2 = d1;
    hence thesis by A18,A23;
  end;
  then reconsider F as Function-yielding Function;
A24: rng doms F = PP
  proof
    thus rng doms F c= PP
    proof
      let x be object;
      assume x in rng doms F;
      then consider j being object such that
A25:  j in dom doms F and
A26:  x = (doms F).j by FUNCT_1:def 3;
A27:  j in dom F by A25,FUNCT_6:59;
      reconsider j as Element of NAT by A17,A25,FUNCT_6:59;
      consider A1 being non empty set, d1 being distance_function of A1,L, Aq1
      being non empty set, dq1 being distance_function of Aq1,L such that
      Aq1, dq1 is_extension2_of A1,d1 and
A28:  S.j = [A1,d1] and
      S.(j+1) = [Aq1,dq1] by Def11;
A29:  [A1,d1]`2 = d1;
      x = dom (F.j) by A26,A27,FUNCT_6:22
        .= dom d1 by A18,A29,A28
        .= [:(S.j)`1,(S.j)`1:] by A28,FUNCT_2:def 1;
      hence thesis;
    end;
    let x be object;
    assume x in PP;
    then consider j being Element of NAT such that
A30: x = [:(S.j)`1,(S.j)`1:];
    consider A1 being non empty set, d1 being distance_function of A1,L, Aq1
    being non empty set, dq1 being distance_function of Aq1,L such that
    Aq1, dq1 is_extension2_of A1,d1 and
A31: S.j = [A1,d1] and
    S.(j+1) = [Aq1,dq1] by Def11;
A32: [A1,d1]`2 = d1;
    j in NAT;
    then
A33: j in dom doms F by A17,FUNCT_6:59;
    x = dom d1 by A30,A31,FUNCT_2:def 1
      .= dom (F.j) by A18,A32,A31
      .= (doms F).j by A17,FUNCT_6:22;
    hence thesis by A33,FUNCT_1:def 3;
  end;
  now
    let x,y be set;
    assume that
A34: x in X and
A35: y in X;
    consider k being Element of NAT such that
A36: x = (S.k)`1 by A34;
    consider l being Element of NAT such that
A37: y = (S.l)`1 by A35;
    k <= l or l <= k;
    then x c= y or y c= x by A36,A37,Th30;
    hence x,y are_c=-comparable;
  end;
  then X is c=-linear;
  then [:FS,FS:] = union rng doms F by A1,A24,A12,LATTICE5:3
    .= dom FD by A19,LATTICE5:1;
  then reconsider FD as BiFunction of FS,L by A11,FUNCT_2:def 1,RELSET_1:4;
A38: FD is symmetric
  proof
    let x,y be Element of FS;
    consider x1 being set such that
A39: x in x1 and
A40: x1 in X by A1,TARSKI:def 4;
    consider k being Element of NAT such that
A41: x1 = (S.k)`1 by A40;
    consider A1 being non empty set, d1 being distance_function of A1,L, Aq1
    being non empty set, dq1 being distance_function of Aq1,L such that
    Aq1, dq1 is_extension2_of A1,d1 and
A42: S.k = [A1,d1] and
    S.(k+1) = [Aq1,dq1] by Def11;
A43: [A1,d1]`1 = A1;
A44: x in A1 by A39,A41,A42;
 [A1,d1]`2 = d1;
    then d1 in the set of all  (S.i)`2 where i is Element of NAT by A42;
    then
A45: d1 c= FD by ZFMISC_1:74;
    consider y1 being set such that
A46: y in y1 and
A47: y1 in X by A1,TARSKI:def 4;
    consider l being Element of NAT such that
A48: y1 = (S.l)`1 by A47;
    consider A2 being non empty set, d2 being distance_function of A2,L, Aq2
    being non empty set, dq2 being distance_function of Aq2,L such that
    Aq2, dq2 is_extension2_of A2,d2 and
A49: S.l = [A2,d2] and
    S.(l+1) = [Aq2,dq2] by Def11;
A50: [A2,d2]`1 = A2;
A51: y in A2 by A46,A48,A49;
 [A2,d2]`2 = d2;
    then d2 in the set of all  (S.i)`2 where i is Element of NAT by A49;
    then
A52: d2 c= FD by ZFMISC_1:74;
    per cases;
    suppose
      k <= l;
      then A1 c= A2 by A43,A50,Th30,A42,A49;
      then reconsider x9=x,y9=y as Element of A2 by A44,A46,A48,A49;
A53:  dom d2 = [:A2,A2:] by FUNCT_2:def 1;
      hence FD.(x,y) = d2.[x9,y9] by A52,GRFUNC_1:2
        .= d2.(x9,y9)
        .= d2.(y9,x9) by LATTICE5:def 5
        .= FD.[y9,x9] by A52,A53,GRFUNC_1:2
        .= FD.(y,x);
    end;
    suppose
      l <= k;
      then A2 c= A1 by A43,A50,Th30,A42,A49;
      then reconsider x9=x,y9=y as Element of A1
           by A39,A41,A42,A51;
A54:  dom d1 = [:A1,A1:] by FUNCT_2:def 1;
      hence FD.(x,y) = d1.[x9,y9] by A45,GRFUNC_1:2
        .= d1.(x9,y9)
        .= d1.(y9,x9) by LATTICE5:def 5
        .= FD.[y9,x9] by A45,A54,GRFUNC_1:2
        .= FD.(y,x);
    end;
  end;
A55: FD is u.t.i.
  proof
    let x,y,z be Element of FS;
    consider x1 being set such that
A56: x in x1 and
A57: x1 in X by A1,TARSKI:def 4;
    consider k being Element of NAT such that
A58: x1 = (S.k)`1 by A57;
    consider A1 being non empty set, d1 being distance_function of A1,L, Aq1
    being non empty set, dq1 being distance_function of Aq1,L such that
    Aq1, dq1 is_extension2_of A1,d1 and
A59: S.k = [A1,d1] and
    S.(k+1) = [Aq1,dq1] by Def11;
A60: [A1,d1]`1 = A1;
A61: x in A1 by A56,A58,A59;
  [A1,d1]`2 = d1;
    then d1 in the set of all  (S.i)`2 where i is Element of NAT by A59;
    then
A62: d1 c= FD by ZFMISC_1:74;
A63: dom d1 = [:A1,A1:] by FUNCT_2:def 1;
    consider y1 being set such that
A64: y in y1 and
A65: y1 in X by A1,TARSKI:def 4;
    consider l being Element of NAT such that
A66: y1 = (S.l)`1 by A65;
    consider A2 being non empty set, d2 being distance_function of A2,L, Aq2
    being non empty set, dq2 being distance_function of Aq2,L such that
    Aq2, dq2 is_extension2_of A2,d2 and
A67: S.l = [A2,d2] and
    S.(l+1) = [Aq2,dq2] by Def11;
A68: [A2,d2]`1 = A2;
A69: y in A2 by A64,A66,A67;
  [A2,d2]`2 = d2;
    then d2 in the set of all  (S.i)`2 where i is Element of NAT by A67;
    then
A70: d2 c= FD by ZFMISC_1:74;
A71: dom d2 = [:A2,A2:] by FUNCT_2:def 1;
    consider z1 being set such that
A72: z in z1 and
A73: z1 in X by A1,TARSKI:def 4;
    consider n being Element of NAT such that
A74: z1 = (S.n)`1 by A73;
    consider A3 being non empty set, d3 being distance_function of A3,L, Aq3
    being non empty set, dq3 being distance_function of Aq3,L such that
    Aq3, dq3 is_extension2_of A3,d3 and
A75: S.n = [A3,d3] and
    S.(n+1) = [Aq3,dq3] by Def11;
A76: [A3,d3]`1 = A3;
A77: z in A3 by A72,A74,A75;
  [A3,d3]`2 = d3;
    then d3 in the set of all  (S.i)`2 where i is Element of NAT by A75;
    then
A78: d3 c= FD by ZFMISC_1:74;
A79: dom d3 = [:A3,A3:] by FUNCT_2:def 1;
    per cases;
    suppose
      k <= l;
      then
A80:  A1 c= A2 by A60,A68,Th30,A59,A67;
      thus FD.(x,y) "\/" FD.(y,z) >= FD.(x,z)
      proof
        per cases;
        suppose
          l <= n;
          then
A81:      A2 c= A3 by A68,A76,Th30,A67,A75;
          then A1 c= A3 by A80;
          then reconsider
          x9 = x, y9 = y, z9 = z as Element of A3
      by A61,A69,A72,A74,A75,A81;
A82:      FD.(y,z) = d3.[y9,z9] by A78,A79,GRFUNC_1:2
            .= d3.(y9,z9);
A83:      FD.(x,z) = d3.[x9,z9] by A78,A79,GRFUNC_1:2
            .= d3.(x9,z9);
          FD.(x,y) = d3.[x9,y9] by A78,A79,GRFUNC_1:2
            .= d3.(x9,y9);
          hence thesis by A82,A83,LATTICE5:def 7;
        end;
        suppose
          n <= l;
          then A3 c= A2 by A68,A76,Th30,A67,A75;
          then reconsider
          x9 = x, y9 = y, z9 = z as Element of A2
       by A61,A64,A66,A67,A77,A80;
A84:      FD.(y,z) = d2.[y9,z9] by A70,A71,GRFUNC_1:2
            .= d2.(y9,z9);
A85:      FD.(x,z) = d2.[x9,z9] by A70,A71,GRFUNC_1:2
            .= d2.(x9,z9);
          FD.(x,y) = d2.[x9,y9] by A70,A71,GRFUNC_1:2
            .= d2.(x9,y9);
          hence thesis by A84,A85,LATTICE5:def 7;
        end;
      end;
    end;
    suppose
      l <= k;
      then
A86:  A2 c= A1 by A60,A68,Th30,A59,A67;
      thus FD.(x,y) "\/" FD.(y,z) >= FD.(x,z)
      proof
        per cases;
        suppose
          k <= n;
          then
A87:      A1 c= A3 by A60,A76,Th30,A59,A75;
          then A2 c= A3 by A86;
          then reconsider
          x9 = x, y9 = y, z9 = z as Element of A3
    by A61,A69,A72,A74,A75,A87;
A88:      FD.(y,z) = d3.[y9,z9] by A78,A79,GRFUNC_1:2
            .= d3.(y9,z9);
A89:      FD.(x,z) = d3.[x9,z9] by A78,A79,GRFUNC_1:2
            .= d3.(x9,z9);
          FD.(x,y) = d3.[x9,y9] by A78,A79,GRFUNC_1:2
            .= d3.(x9,y9);
          hence thesis by A88,A89,LATTICE5:def 7;
        end;
        suppose
          n <= k;
          then A3 c= A1 by A60,A76,Th30,A59,A75;
          then reconsider
          x9 = x, y9 = y, z9 = z as Element of A1
   by A56,A58,A59,A69,A77,A86;
A90:      FD.(y,z) = d1.[y9,z9] by A62,A63,GRFUNC_1:2
            .= d1.(y9,z9);
A91:      FD.(x,z) = d1.[x9,z9] by A62,A63,GRFUNC_1:2
            .= d1.(x9,z9);
          FD.(x,y) = d1.[x9,y9] by A62,A63,GRFUNC_1:2
            .= d1.(x9,y9);
          hence thesis by A90,A91,LATTICE5:def 7;
        end;
      end;
    end;
  end;
  FD is zeroed
  proof
    let x be Element of FS;
    consider y being set such that
A92: x in y and
A93: y in X by A1,TARSKI:def 4;
    consider j being Element of NAT such that
A94: y = (S.j)`1 by A93;
    consider A1 being non empty set, d1 being distance_function of A1,L, Aq1
    being non empty set, dq1 being distance_function of Aq1,L such that
    Aq1, dq1 is_extension2_of A1,d1 and
A95: S.j = [A1,d1] and
    S.(j+1) = [Aq1,dq1] by Def11;
 [A1,d1]`2 = d1;
    then d1 in the set of all  (S.i)`2 where i is Element of NAT by A95;
    then
A96: d1 c= FD by ZFMISC_1:74;
    reconsider x9 = x as Element of A1 by A92,A94,A95;
    dom d1 = [:A1,A1:] by FUNCT_2:def 1;
    hence FD.(x,x) = d1.[x9,x9] by A96,GRFUNC_1:2
      .= d1.(x9,x9)
      .= Bottom L by LATTICE5:def 6;
  end;
  hence thesis by A38,A55;
end;
