reserve i,j for Nat;
reserve x,y for set;
reserve A for non empty set;
reserve c for Element of StandardStackSystem A;
reserve m for stack of StandardStackSystem A;
reserve X for non empty non void StackSystem;
reserve s,s1,s2 for stack of X;
reserve e,e1,e2 for Element of X;
reserve X for StackAlgebra;
reserve s,s1,s2,s3 for stack of X;
reserve e,e1,e2,e3 for Element of X;

theorem Th40:
  for S being stack of X/== st S = Class(==_X, s) & not emp s holds
  top S = top s
  proof set t = the s_top of X;
    set A = the s_empty of X;
    set e = the Element of the carrier of X;
    let S be stack of X/==;
    assume
A1: S = Class(==_X, s);
    assume
A2: not emp s; then
    not emp S by A1,Th36; then
A3: S <> A by Th37;
    set f = the Choice_Function of Class(==_X);
A4: S in Class(==_X) & {} nin Class(==_X)
    by A1,EQREL_1:def 3; then
A5: f.S in S by ORDERS_1:89; then
    reconsider x = f.S as stack of X by A1;
    [s,x] in ==_X by A1,A5,EQREL_1:18; then
A6: s == x by Def16;
A7: dom f = Class(==_X) by A4,RLVECT_3:28;
    the s_top of X/== = (t*f)+*(A,e) by Def20;
    hence top S = (t*f).S by A3,FUNCT_7:32
    .= top x by A4,A7,FUNCT_1:13
    .= top s by A6,A2,Th18;
  end;
