Require Import Relations Omega.
Require Import mathcomp.ssreflect.ssreflect.
Require Import Kstar_def demo hilbert_ref gen_def.
Set Implicit Arguments.
Import Prenex Implicits.
Implicit Types (S X Y H : {fset clause}) (C D E : clause).
Definition AXn C := [fset s in C | isDia s].
Definition Req C := [fset body s |` R C | s <- AXn C].
Require Import mathcomp.ssreflect.ssreflect.
Require Import Kstar_def demo hilbert_ref gen_def.
Set Implicit Arguments.
Import Prenex Implicits.
Implicit Types (S X Y H : {fset clause}) (C D E : clause).
Definition AXn C := [fset s in C | isDia s].
Definition Req C := [fset body s |` R C | s <- AXn C].
The argument order for fulfillAG differs from the paper version since we want
the induction principle where S0, S, and s remain constant during the
proofs.
Inductive fulfillAG S0 S s C : Prop :=
| fulfillAG1 D :
(forall E, E \in Req C -> suppS S E) ->
D \in S -> rtrans C D -> D |> s^- -> fulfillAG S0 S s C
| fulfillAGn D :
(forall E, E \in Req C -> suppS S E) ->
D \in S0 -> rtrans C D -> fulfillAG S0 S s D -> fulfillAG S0 S s C.
Section Decidability.
Variables (S0 S : {fset clause}).
To construct the pruning demo, we need to decide the fulfillment
relations. For this we again use a fixpoint computation
Definition fulfillAG_fun s X : {fset clause} :=
[fset C in S0 | [all D in Req C, suppS S D] &&
(suppS S (s^- |` R C) || [some D in S0, rtrans C D && (D \in X)])].
Lemma fulfillAG_fun_mono s : monotone (fulfillAG_fun s).
Lemma fulfillAG_fun_bounded s : bounded S0 (fulfillAG_fun s).
Definition fulfillAGb s := fset.lfp S0 (fulfillAG_fun s).
Lemma fulfillAGE s C :
(C \in fulfillAGb s) = (C \in fulfillAG_fun s (fulfillAGb s)).
Lemma fulfillAGP s C : reflect (C \in S0 /\ fulfillAG S0 S s C) (C \in fulfillAGb s).
End Decidability.
Lemma fulfillAG_Req S0 S s C : C \in fulfillAGb S0 S s -> (forall E, E \in Req C -> suppS S E).
Section Pruning.
Variables (F : clause).
Hypothesis sfc_F : sf_closed F.
Definition U := powerset F.
Definition S0 := [fset C in U | literalC C && lcons C].
Definition P1 C S := ~~ [all D in Req C, suppS S D].
Definition P2 C S := ~~ [all u in C, if u is fAX (fAG s)^- then C \in fulfillAGb S0 S s else true].
Definition pcond C S := P1 C S || P2 C S.
Pruning yields a demo
Definition S := prune pcond S0.
Let Fs := \bigcup_(C in S) C.
Definition T := [fset C in S0 | [all D in Req C, suppS S D]].
Lemma prune_D0 : D0 (S `|` T).
Lemma prune_D1_strong C s : fAX s^- \in C -> C \in S `|` T -> suppS S (s^- |` R C).
Lemma prune_D1 : D1 (S `|` T).
Lemma prune_S_aux C s : C \in S -> fAX (fAG s)^- \in C -> fulfillAG S0 S s C.
Lemma prune_D2_S C s : C \in S -> fAX (fAG s)^- \in C -> demo.fulfillAG (S `|` T) s C.
Lemma prune_D2 : D2 (S `|` T).
Definition DD := @Demo (S `|` T) prune_D0 prune_D1 prune_D2.
Definition coref (ref : clause -> Prop) S :=
forall C, C \in S0 `\` S -> ref C.
Inductive ref : clause -> Prop :=
| R1 S C : C \in U -> coref ref S -> ~~ suppS S C -> ref C
| R2 C s : ref (s^- |` R C) -> ref (fAX s^- |` C)
| R3 S C s : S `<=` S0 -> coref ref S ->
C \in S -> fAX (fAG s)^- \in C -> ~ fulfillAG S0 S s C -> ref C.
Lemma corefD1 S C : ref C -> coref ref S -> coref ref (S `\` [fset C]).
Lemma R1inU C s : C \in U -> fAX s^- \in C -> s^- |` R C \in U.
The pruning demo is corefutable
Section RefPred.
Variable (F : {fset sform}).
Hypothesis (sfc_F : sf_closed F).
Definition tref C := gen (C,aVoid).
Lemma lcons_gen C a : ~~ lcons C -> gen (C,a).
Ltac Lsupp1 := by rewrite /= ?fsubUset !fsub1 !inE // !ssub_refl.
Ltac Lsupp2 := rewrite /weight /= ?fsumU !fsum1 /= /sltype.f_weight /= -?(plusE,minusE); apply/leP; omega.
Ltac Lsupp3 := move => L; rewrite /= ?suppCU !suppC1 /=; by bcase.
Lemma tref_R0 C a : C \in U -> (forall D, D \in base S0 C -> gen (D,a)) -> gen (C,a).
Lemma tref_R1 S C : C \in U -> coref F tref S -> ~~ suppS S C -> tref C.
Lemma tref_R2 C s : tref (s^- |` R C) -> tref (fAX s^- |` C).
Ltac unfold_U := (repeat progress match goal with
| [H : context[U] |- _] => rewrite /U in H
end); rewrite /U.
Lemma tref_R3 S C s : S `<=` S0 -> coref F tref S -> C \in S ->
fAX (fAG s)^- \in C -> ~ fulfillAG S0 S s C -> tref C.
Lemma refpred_tref C : ref F C -> tref C.
End RefPred.
Lemma supp_S_sat (F : clause) (sfc_F : sf_closed F) C :
suppS (S F) C -> (exists M : fmodel, sat M C).
Lemma gen_completeness C : gen (C,aVoid) + (exists M : fmodel, sat M C).
Lemma gen_plain_sound C : gen (C, aVoid) -> ~ (exists M : cmodel, sat M C).
Corollary gen_correctness C : gen (C,aVoid) <-> ~ (exists M : cmodel, sat M C).