function ret = thin_fun1 (A)
  
## stage 1 in thin algorithm

  x1 = A(2,3);
  x2 = A(1,3);
  x3 = A(1,2);
  x4 = A(1,1);
  x5 = A(2,1);
  x6 = A(3,1);
  x7 = A(3,2);
  x8 = A(3,3);
  p = A(2,2);
  
# condition 1
  b1 = (~x1) & (x2 | x3);
  b2 = (~x3) & (x4 | x5);
  b3 = (~x5) & (x6 | x7);
  b4 = (~x7) & (x8 | x1);
  xh = b1 + b2 + b3 + b4;
  
# condition 2  
  n1 = (x1 | x2) + (x3 | x4) + (x5 | x6) + (x7 | x8);
  n2 = (x2 | x3) + (x4 | x5) + (x6 | x7) + (x8 | x1);
  m = min(n1, n2);
 
# condition 3
  G3 = (x2 | x3 | (!x8)) & x1;  
  G3 = ~G3;
  
## point p is deleted iff all conditions are true  
  ret = p & (~((xh == 1) & (m == 2 | m == 3) & G3));
  
end
