reserve X for non empty set;
reserve e,e1,e2,e19,e29 for Equivalence_Relation of X,
  x,y,x9,y9 for set;
reserve A for non empty set,
  L for lower-bounded LATTICE;
reserve T,L1 for Sequence,
  O,O1,O2,O3,C for Ordinal;

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