% Detect inconsistencies
#define  poscontract (X) bel  (p (neg (X), Pn), p (X, Pp), Pn > Pp).
#define  negcontract (X) bel  (p (neg (X), Pn), p (X, Pp), Pn < Pp).
% Contract all least preferred positive beliefs
listall C <- poscontract (X) do  {
forall  just (Y, S), member (Z, C), member (Z, S) do delete  (just (Y, S)).
forall  just (Y, ), member (Y, C) do delete  (just (Y, _)).
forall  member (Y, C), just (Y, S) bel  (w (just (Y, S), Z)) do insert  (contract (Z)).
forall  member (Y, C) do delete  (Y).
}
% Contract all least preferred negative beliefs
listall C <- negcontract (X) do  {
forall  just (Y, S), member (Z, C), member (Z, S) do delete  (just (Y, s)).
forall  just (Y, ), member (Y, C) do delete  (just (Y, _)).
forall  member (Y, C), just (Y, S) bel  (w (just (Y, S), Z)) do insert  (contract (Z)).
forall  member (Y, C) do delete  (Y).
}
% Recursive contraction
listall C <- contract (X) do  {
forall  just (Y, S), member (Z, C), member (Z, S) do delete  (just (Y, S)).
forall  just (Y, ), member (Y, C) do delete  (just (Y, _)).
forall  member (Y, C), just (Y, S) bel  (w (just (Y, S), Z)) do insert  (contract (Z)).
forall  member (Y, C) do delete  (Y).
}
Algorithm 10