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 Th39:
  for S being stack of X/== st S = Class(==_X, s) & not emp s holds
  pop s in pop S & Class(==_X, pop s) = pop S
  proof set p = the s_pop of X;
    set i = id the s_empty of X;
    let S be stack of X/==;
    assume
A1: S = Class(==_X, s);
    assume
A2: not emp s;
A3: s in S by A1,EQREL_1:20;
A4: S in Class(==_X) by A1,EQREL_1:def 3;
A5: dom i = the s_empty of X;
A6: p+*i is UnOp of the carrier' of X, ==_X
    proof
      let y1,y2 be stack of X;
      assume
A7:   [y1,y2] in ==_X; then
A8:   y1 == y2 by Def16;
      per cases;
      suppose
A9:     not emp y1; then
        not emp y2 by A8,Th14; then
        y1 nin the s_empty of X & y2 nin the s_empty of X by A9; then
A10:     (p+*i).y1 = p.y1 & (p+*i).y2 = p.y2 by A5,FUNCT_4:11;
        pop y1 == pop y2 by A8,A9,Th17;
        hence [(p+*i).y1,(p+*i).y2] in ==_X by A10,Def16;
      end;
      suppose
A11:     emp y1; then
        emp y2 by A8,Th14; then
        y1 in the s_empty of X & y2 in the s_empty of X by A11; then
        (p+*i).y1 = i.y1 & i.y1 = y1 & (p+*i).y2 = i.y2 & i.y2 = y2
        by A5,FUNCT_1:18,FUNCT_4:13;
        hence thesis by A7;
      end;
    end;
A12: s nin the s_empty of X by A2;
    pop S = ((p+*i)/\/==_X).S by Def20
    .= Class(==_X, (p+*i).s) by A3,A4,A6,FILTER_1:def 3
    .= Class(==_X, pop s) by A5,A12,FUNCT_4:11;
    hence thesis by EQREL_1:20;
  end;
