Module Terminate. Section Terminate.
Variable (clause: finType)
(entails: {set clause} -> clause -> bool)
(redund: {set clause} -> clause -> bool)
(Trans: TRANS.Sig entails redund).
Notation redundU := (TRANS.redundU Trans).
Notation redundU2 := (TRANS.redundU2 Trans).
Notation redundD := (TRANS.redundD Trans).
(*Notation clauseset := ({set clause}).*)
Definition clauseset := set_finType clause.
(* set of clauses addable to s *)
Definition add (s: clauseset) : clauseset :=
[set c | [&& ~~redund s c &
[exists s0: clauseset, [&& s0 \subset s & entails s0 c]]]].
(* set of clauses removable from s *)
Definition rem (s: clauseset) : clauseset := [set c | redund s c].
(* the transition relation, expressed as a function to bool *)
Definition trans (s s': clauseset) :=
[exists c: clause,
if [&& c \in add s & c \notin s] then s' == c |: s
else if [&& c \in rem s & c \in s] then s' == s :\ c
else false].
(* a derivation is the graph induced by the refl. transitive closure of trans *)
Notation deriv := (connect trans).
(* predicate a is closed under "edge" relation e *)
Definition closed {T: finType} (e: rel T) (a: pred T) :=
forall x y : T, e x y -> a x -> a y.
Definition removed (c: clause) {s s'': clauseset} (step: trans s s'') :=
(c \in s) && (c \notin s'').
Definition added (c: clause) {s s'': clauseset} (step: trans s s'') :=
(c \notin s) && (c \in s'').
Definition adds (c: clause) (s s': clauseset) (trace: deriv s s') :=
[&& c \notin s & c \in s'].
Definition removes (c: clause) (s s': clauseset) (trace: deriv s s') :=
[&& c \in s & c \notin s'].
(* here's a different characterization based on sequences of states *)

Lemma last_take {T: finType} (e: rel T) (x y: T) (p p1 p2: seq T) :
x \in p -> last y (take ((index x p).+1) p) = x.