reserve V for Universe,
  a,b,x,y,z,x9,y9 for Element of V,
  X for Subclass of V,
  o,p,q,r,s,t,u,a1,a2,a3,A,B,C,D for set,
  K,L,M for Ordinal,
  n for Element of omega,
  fs for finite Subset of omega,
  e,g,h for Function,
  E for non empty set,
  f for Function of VAR,E,
  k,k1 for Element of NAT,
  v1,v2,v3 for Element of VAR,
  H,H9 for ZF-formula;

theorem Th18:
  X is closed_wrt_A1-A7 & E in X implies for v1,v2 holds Diagram(
  v1 '=' v2,E) in X & Diagram(v1 'in' v2,E) in X
proof
  assume that
A1: X is closed_wrt_A1-A7 and
A2: E in X;
A3: X is closed_wrt_A4 by A1;
A4: X is closed_wrt_A1 by A1;
A5: omega c= X by A1,Th7;
  reconsider m=E as Element of V by A2;
  let v1,v2;
  set H=v1 '=' v2;
  set H9=v1 'in' v2;
A6: Free(H)={v1,v2} by ZF_LANG1:58;
  then
A7: v1 in Free H by TARSKI:def 2;
A8: v2 in Free H by A6,TARSKI:def 2;
A9: Free(H9)={v1,v2} by ZF_LANG1:59;
  then
A10: v1 in Free H9 by TARSKI:def 2;
A11: v2 in Free H9 by A9,TARSKI:def 2;
  per cases;
  suppose
A12: v1=v2;
    set a=code Free(H);
    set Z={{[z,y]} where z,y: z in a & y in m};
A13: Free(H)={v1} by A6,A12,ENUMSET1:29;
A14: x".v1 in X by A5;
A15: Z=Diagram(H,E)
    proof
      thus Z c= Diagram(H,E)
      proof
        let p be object;
A16:    H is being_equality by ZF_LANG:5;
        assume p in Z;
        then consider z,y such that
A17:    p={[z,y]} and
A18:    z in a and
A19:    y in m;
        reconsider f =VAR --> y as Function of VAR,E by A19,FUNCOP_1:45;
        z in { x".v1} by A13,A18,Lm6;
        then
A20:    z= x".v1 by TARSKI:def 1;
        dom((f*decode)|code Free(H))=code Free H by Lm3
          .={z} by A13,A20,Lm6;
        then
((f*decode)|code Free H)={[z,((f*decode)|code Free(H)).z]} by GRFUNC_1:7;
        then (f*decode)|code Free H={[z,f.v1]} by A7,A20,Lm9;
        then
A21:    (f*decode)|code Free H=p by A17,FUNCOP_1:7;
        f.(Var1 H)=f.v2 by A12,ZF_LANG1:1
          .=f.(Var2 H) by ZF_LANG1:1;
        then f in St(H,E) by A16,ZF_MODEL:7;
        hence thesis by A21,Def4;
      end;
      reconsider z= x".v1 as Element of V by A14;
      let p be object;
      assume p in Diagram(H,E);
      then consider f such that
A22:  p=(f*decode)|code Free(H) and
      f in St(H,E) by Def4;
      reconsider y=f.v1 as Element of V by A2,Th1;
      dom((f*decode)|code Free H)=code Free H by Lm3
        .={z} by A13,Lm6;
      then ((f*decode)|code Free H)={[z,((f*decode)|code Free(H)).z]} by
GRFUNC_1:7;
      then
A23:  p={[z,y]} by A7,A22,Lm9;
      z in {z} by TARSKI:def 1;
      then z in a by A13,Lm6;
      hence thesis by A23;
    end;
    {x".v1} in X by A1,A14,Th2;
    then code Free(H) in X by A13,Lm6;
    hence Diagram(H,E) in X by A2,A3,A15;
    Diagram(H9,E)={}
    proof
      set p = the Element of Diagram(H9,E);
      assume not thesis;
      then consider f being Function of VAR,E such that
      p=(f*decode)|code Free(H9) and
A24:  f in St(H9,E) by Def4;
      H9 is being_membership by ZF_LANG:5;
      then f.(Var1 H9) in f.(Var2 H9) by A24,ZF_MODEL:8;
      then f.v1 in f.(Var2 H9) by ZF_LANG1:2;
      then f.v1 in f.v2 by ZF_LANG1:2;
      hence contradiction by A12;
    end;
    hence thesis by A1,Th3;
  end;
  suppose
A25: v1<>v2;
    x".v2 in X & 1-element_of(V) in X by A5;
    then
A26: [ x".v2,1-element_of(V)] in X by A1,Th6;
    x".v1 in X & 0-element_of(V) in X by A1,A5,Lm13;
    then [ x".v1,0-element_of(V)] in X by A1,Th6;
    then ({[ x".v1,0-element_of(V)],[ x".v2,1-element_of(V)]}) in X by A1,A26
,Th6;
    then reconsider d={[ x".v1,0-element_of(V)],[ x".v2,1-element_of(V)]} as
    Element of V;
    set fs=code Free H;
A27: fs={ x".v1, x".v2} by A6,Lm7;
A28: now
      assume x".v1= x".v2;
      then v1=x.(x".v2) by Def2
        .=v2 by Def2;
      hence contradiction by A25;
    end;
A29: d in Funcs(fs,omega)
    proof
      reconsider g={[x".v1,0-element_of(V)]}, h={[x".v2,1-element_of(V)]} as
      Function;
      reconsider e=d as Function by A28,GRFUNC_1:8;
A30:  0-element_of(V) in omega by ORDINAL1:def 11;
A31:  e=g \/ h by ENUMSET1:1;
      then rng e=rng g \/ rng h by RELAT_1:12
        .={0-element_of(V)} \/ rng h by RELAT_1:9
        .={0-element_of(V)} \/ {1-element_of(V)} by RELAT_1:9
        .={0-element_of(V),1-element_of(V)} by ENUMSET1:1;
      then
A32:  rng e c= omega by A30,ZFMISC_1:32;
      dom e=dom g \/ dom h by A31,XTUPLE_0:23
        .={ x".v1} \/ dom h by RELAT_1:9
        .={ x".v1} \/ { x".v2} by RELAT_1:9
        .=fs by A27,ENUMSET1:1;
      hence thesis by A32,FUNCT_2:def 2;
    end;
    set a={{[0-element_of(V),x],[1-element_of(V),x]}: x in m};
    a in X by A1,A2,Th17;
    then reconsider a as Element of V;
    set b={{[0-element_of(V),x],[1-element_of(V),y]}: x in y & x in m & y in m
    };
    set Y={d(#)x: x in a};
A33: b in X by A2,A4;
    then reconsider b as Element of V;
    set Z={d(#)x: x in b};
    Y=Diagram(H,E)
    proof
      thus Y c= Diagram(H,E)
      proof
        let p be object;
        assume p in Y;
        then consider x such that
A34:    p=d(#)x and
A35:    x in a;
        consider y such that
A36:    x={[0-element_of(V),y],[1-element_of(V),y]} and
A37:    y in m by A35;
        reconsider f=VAR --> y as Function of VAR,E by A37,FUNCOP_1:45;
A38:    f.(Var1 H)=y by FUNCOP_1:7
          .=f.(Var2 H) by FUNCOP_1:7;
        H is being_equality by ZF_LANG:5;
        then
A39:    f in St(H,E) by A38,ZF_MODEL:7;
A40:    ((f*decode)|code Free H).( x".v2)=f.v2 by A8,Lm9
          .=y by FUNCOP_1:7;
A41:    ((f*decode)|code Free H).( x".v1)=f.v1 by A7,Lm9
          .=y by FUNCOP_1:7;
A42:    dom((f*decode)|code Free(H))={ x".v1, x".v2} by A27,Lm3;
        p={[ x".v1,y],[ x".v2,y]} by A34,A36,Lm15;
        then (f*decode)|code Free(H)=p by A42,A41,A40,Lm16;
        hence thesis by A39,Def4;
      end;
      let p be object;
      assume p in Diagram(H,E);
      then consider f such that
A43:  p=(f*decode)|code Free(H) and
A44:  f in St(H,E) by Def4;
      reconsider y=f.v1 as Element of V by A2,Th1;
      H is being_equality by ZF_LANG:5;
      then f.(Var1 H)=f.(Var2 H) by A44,ZF_MODEL:7;
      then f.v1=f.(Var2 H) by ZF_LANG1:1
        .=f.v2 by ZF_LANG1:1;
      then
A45:  ((f*decode)|code Free H).( x".v2)=y by A8,Lm9;
      reconsider x={[0-element_of(V),y],[1-element_of(V),y]} as Element of V;
      dom((f*decode)|code Free(H))={ x".v1, x".v2} & ((f*decode)|code
      Free H).( x".v1)=y by A7,A27,Lm3,Lm9;
      then p={[ x".v1,y],[ x".v2,y]} by A43,A45,Lm16;
      then ({[0-element_of(V),y],[1-element_of(V),y]}) in a & p=d(#)x by Lm15;
      hence thesis;
    end;
    hence Diagram(H,E) in X by A1,A2,A29,Th10,Th17;
    Z=Diagram(H9,E)
    proof
      thus Z c= Diagram(H9,E)
      proof
        reconsider a1=v1 as Element of VAR;
        let p be object;
        assume p in Z;
        then consider x such that
A46:    p=d(#)x and
A47:    x in b;
        consider y,z such that
A48:    x={[0-element_of(V),y],[1-element_of(V),z]} and
A49:    y in z and
A50:    y in m & z in m by A47;
A51:    p={[ x".v1,y],[ x".v2,z]} by A46,A48,Lm15;
        reconsider y9=y, z9=z as Element of E by A50;
        deffunc F(set) = z9;
        consider f being Function of VAR,E such that
A52:    f.a1=y9 & for v3 being Element of VAR st v3<>a1 holds f.v3=F
        (v3) from FUNCT_2:sch 6;
A53:    ((f*decode)|code Free H9).( x".v2)=f.v2 by A11,Lm9
          .=z by A25,A52;
A54:    ((f*decode)|code Free H9).( x".v1)=y by A10,A52,Lm9;
        f.v1 in f.v2 by A25,A49,A52;
        then f.(Var1 H9) in f.v2 by ZF_LANG1:2;
        then H9 is being_membership & f.(Var1 H9) in f.(Var2 H9) by ZF_LANG:5
,ZF_LANG1:2;
        then
A55:    f in St(H9,E) by ZF_MODEL:8;
        dom((f*decode)|code Free H9)={ x".v1, x".v2} by A6,A9,A27,Lm3;
        then p=(f*decode)|code Free(H9) by A51,A54,A53,Lm16;
        hence thesis by A55,Def4;
      end;
      let p be object;
      assume p in Diagram(H9,E);
      then consider f being Function of VAR,E such that
A56:  p=(f*decode)|code Free(H9) and
A57:  f in St(H9,E) by Def4;
      reconsider z=f.v2 as Element of V by A2,Th1;
      reconsider y=f.v1 as Element of V by A2,Th1;
      H9 is being_membership by ZF_LANG:5;
      then f.(Var1 H9) in f.(Var2 H9) by A57,ZF_MODEL:8;
      then f.v1 in f.(Var2 H9) by ZF_LANG1:2;
      then y in z by ZF_LANG1:2;
      then
A58:  ({[0-element_of(V),y],[1-element_of(V),z]}) in b;
      reconsider x={[0-element_of(V),y],[1-element_of(V),z]} as Element of V;
A59:  ((f*decode)|code Free H9).( x".v2)=f.v2 by A11,Lm9;
      dom((f*decode)|code Free(H9))={ x".v1, x".v2} & ((f*decode)|code
      Free H9).( x".v1)=f.v1 by A6,A9,A10,A27,Lm3,Lm9;
      then p={[ x".v1,y],[ x".v2,z]} by A56,A59,Lm16;
      then p=d(#)x by Lm15;
      hence thesis by A58;
    end;
    hence thesis by A1,A33,A29,Th10;
  end;
end;
