├── .loadpath ├── _CoqProject ├── .gitattributes ├── QuantifierLogic ├── DeepEmbedded │ ├── FirstOrderLanguage.v │ └── FirstOrderLogic.v ├── ShallowEmbedded │ ├── PredicateAsBLang.v │ └── PredicateQuantifierLogic.v ├── ProofTheory │ ├── QuantifierLogic.v │ └── IntuitionisticDerivedRules.v └── Syntax.v ├── .gitignore ├── ModalLogic ├── Model │ ├── KripkeModel.v │ └── OrderedKripkeModel.v ├── Syntax.v ├── Semantics │ ├── Kripke.v │ └── Flat.v ├── ShallowEmbedded │ ├── PredicateModalLogic.v │ └── MonoPredicateModalLogic.v ├── ProofTheory │ ├── RewriteClass.v │ └── ClassicalDerivedRules.v └── Sound │ ├── Sound_Kripke.v │ └── Sound_Flat.v ├── MinimumLogic ├── Syntax.v ├── Semantics │ ├── Trivial.v │ ├── SemanticEquiv.v │ └── Kripke.v ├── Complete │ ├── ContextProperty_Kripke.v │ ├── Lindenbaum_Kripke.v │ └── Truth_Kripke.v ├── Sound │ ├── Sound_Classical_Trivial.v │ └── Sound_Kripke.v ├── DeepEmbedded │ ├── MinimumLogic.v │ ├── Soundness.v │ ├── KripkeSemantics.v │ └── MinimumLanguage.v └── ProofTheory │ ├── TheoryOfSequentCalculus.v │ └── ExtensionTactic.v ├── LogicGenerator ├── Makefile └── demo │ ├── configuration_2.v │ ├── configuration_3.v │ ├── implementation_2a.v │ ├── configuration_1.v │ ├── implementation_2b.v │ ├── implementation_3.v │ └── implementation_1.v ├── logic_gen.sh ├── SeparationLogic ├── Model │ ├── SeparationAlgebra.v │ ├── UpwardsClosure.v │ └── DownwardsClosure.v ├── DeepEmbedded │ ├── Parameter.v │ └── SeparationLanguage.v ├── Semantics │ ├── SemanticsExtension.v │ ├── DownUpSemantics_Fail.v │ ├── StrongSemantics.v │ ├── Down2Flat.v │ ├── Up2Flat.v │ ├── FlatSemantics.v │ ├── DownwardsSemantics.v │ └── UpwardsSemantics.v ├── Syntax.v ├── ProofTheory │ ├── SeparationLogicExtension.v │ ├── WandFrame.v │ └── RewriteClass.v └── Sound │ └── Sound_DownUp_Fail.v ├── Extensions ├── Syntax_CoreTransit.v └── ProofTheory │ ├── Stable.v │ └── ModalSeparation.v ├── lib ├── StrongInduction.v ├── SublistT.v ├── register_typeclass.v ├── Bisimulation.v ├── Countable.v ├── Stream │ └── StreamSplit.v ├── EnsemblesProperties.v └── Equivalence_ext.v ├── GeneralLogic ├── ShallowEmbedded │ ├── PredicateAsLang.v │ └── MonoPredicateAsLang.v ├── Semantics │ └── Kripke.v ├── Complete │ ├── README │ ├── ContextProperty.v │ ├── Lindenbaum_Kripke.v │ ├── ContextProperty_Trivial.v │ ├── Canonical_Kripke.v │ └── Complete_Kripke.v ├── HenkinCompleteness.v └── ProofTheory │ └── BasicSequentCalculus.v ├── HoareLogic ├── SimpleSmallStepSemantics.v ├── OperationalSemanticsGenerator.v ├── ConcurrentSemantics_Angelic.v ├── GuardedHoareTriple_TraceSemantics.v ├── GuardedHoareLogic.v ├── HoareTriple_BigStepSemantics.v ├── GuardedHoareTriple_Angelic.v ├── ImperativeLanguage.v ├── HoareLogic.v └── Sound_Frame.v ├── PropositionalLogic ├── Syntax.v ├── DeepEmbedded │ ├── TrivialSemantics.v │ ├── Deep.v │ └── KripkeSemantics.v ├── Semantics │ └── Trivial.v ├── Sound │ └── Sound_Classical_Trivial.v ├── ProofTheory │ ├── DeMorgan.v │ └── GodelDummett.v └── Complete │ ├── Lindenbaum_Trivial.v │ ├── Truth_Kripke.v │ └── Complete_Trivial.v ├── .travis.yml ├── README ├── unused_files ├── Wf.v └── trivial.v └── examples └── Imp.v /.loadpath: -------------------------------------------------------------------------------- 1 | -R . Logic 2 | -------------------------------------------------------------------------------- /_CoqProject: -------------------------------------------------------------------------------- 1 | -R . Logic 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.v text eol=lf 2 | 3 | -------------------------------------------------------------------------------- /QuantifierLogic/DeepEmbedded/FirstOrderLanguage.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | -------------------------------------------------------------------------------- /QuantifierLogic/DeepEmbedded/FirstOrderLogic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | -------------------------------------------------------------------------------- /QuantifierLogic/ShallowEmbedded/PredicateAsBLang.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | -------------------------------------------------------------------------------- /QuantifierLogic/ShallowEmbedded/PredicateQuantifierLogic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.vo 2 | *.glob 3 | *.v.d 4 | *.aux 5 | .depend 6 | CONFIGURE 7 | LogicGenerator/Config.v 8 | LogicGenerator/Generated.v 9 | LogicGenerator/demo/interface*.v 10 | -------------------------------------------------------------------------------- /ModalLogic/Model/KripkeModel.v: -------------------------------------------------------------------------------- 1 | Module KM. 2 | 3 | Class Relation (worlds: Type): Type := 4 | Krelation: worlds -> worlds -> Prop. 5 | 6 | End KM. 7 | 8 | Export KM. 9 | 10 | 11 | -------------------------------------------------------------------------------- /MinimumLogic/Syntax.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | 3 | Class MinimumLanguage (L: Language): Type := { 4 | impp: expr -> expr -> expr 5 | }. 6 | 7 | Declare Scope syntax. 8 | 9 | Notation "x --> y" := (impp x y) (at level 55, right associativity) : syntax. 10 | -------------------------------------------------------------------------------- /LogicGenerator/Makefile: -------------------------------------------------------------------------------- 1 | COQBIN= 2 | -include ../CONFIGURE 3 | unifysl_dir := .. 4 | coq_exe := $(COQBIN)coqc 5 | coq_flags := -R $(unifysl_dir) Logic 6 | src := Generate.v 7 | dst := Generated.v 8 | 9 | .PHONY: all clean 10 | 11 | all: $(dst) 12 | 13 | Config.vo: Config.v 14 | $(coq_exe) $(coq_flags) Config.v 15 | 16 | $(dst): $(src) Config.vo 17 | $(coq_exe) $(coq_flags) $(src) > $@ 18 | 19 | clean: 20 | @rm -rf *.vo *.glob .*.aux $(dst) 2>/dev/null 21 | -------------------------------------------------------------------------------- /logic_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ $# -eq 0 ] 3 | then 4 | src=LogicGenerator/Config.v 5 | else 6 | src=$1 7 | echo "cp ${src} LogicGenerator/Config.v" 8 | cp ${src} LogicGenerator/Config.v 9 | fi 10 | make -j7; cd LogicGenerator; rm Config.vo; make; cd .. 11 | if [ $# -le 1 ] 12 | then 13 | dst=LogicGenerator/Generated.v 14 | else 15 | dst=$2 16 | echo "cp LogicGenerator/demo/Generated.v ${dst}" 17 | cp LogicGenerator/Generated.v ${dst} 18 | fi 19 | -------------------------------------------------------------------------------- /LogicGenerator/demo/configuration_2.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Lists.List. 2 | Require Import Logic.LogicGenerator.Utils. 3 | Require Import Logic.LogicGenerator.ConfigLang. 4 | 5 | Import ListNotations. 6 | 7 | Definition how_connectives := 8 | [primitive_connective impp 9 | ;FROM_impp_TO_multi_imp 10 | ]. 11 | 12 | Definition how_judgements := 13 | [primitive_judgement provable 14 | ]. 15 | 16 | Definition transparent_names := 17 | [expr:parameter]. 18 | 19 | Definition primitive_rule_classes := 20 | [ provability_OF_impp 21 | ]. 22 | -------------------------------------------------------------------------------- /SeparationLogic/Model/SeparationAlgebra.v: -------------------------------------------------------------------------------- 1 | Class Join (worlds: Type): Type := join: worlds -> worlds -> worlds -> Prop. 2 | 3 | Class SeparationAlgebra (worlds: Type) {SA: Join worlds}: Type := 4 | { 5 | join_comm: forall m1 m2 m: worlds, 6 | join m1 m2 m -> 7 | join m2 m1 m; 8 | join_assoc: forall mx my mz mxy mxyz: worlds, 9 | join mx my mxy -> 10 | join mxy mz mxyz -> 11 | exists myz, join my mz myz /\ join mx myz mxyz 12 | }. 13 | 14 | Definition unit_element {worlds: Type} {J: Join worlds}: worlds -> Prop := 15 | fun e => forall n n', join e n n' -> n = n'. 16 | -------------------------------------------------------------------------------- /SeparationLogic/DeepEmbedded/Parameter.v: -------------------------------------------------------------------------------- 1 | Class SL_Parameter: Type := { 2 | EM: bool; 3 | IC: bool; 4 | WEM: bool; 5 | SCE: bool; 6 | ESE: bool; 7 | ED: bool 8 | }. 9 | 10 | Class SA_Parameter: Type := { 11 | ID: bool; 12 | NB: bool; 13 | BJ: bool; 14 | INCR: bool; 15 | ISS: bool; 16 | IJS: bool 17 | }. 18 | 19 | Inductive Parameter_coincide (SLP: SL_Parameter) (SAP: SA_Parameter) : Prop := 20 | Build_Parameter_coincide: 21 | EM = ID -> 22 | IC = NB -> 23 | WEM = BJ -> 24 | SCE = INCR -> 25 | ESE = ISS -> 26 | ED = IJS -> 27 | Parameter_coincide SLP SAP. 28 | -------------------------------------------------------------------------------- /ModalLogic/Syntax.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.MinimumLogic.Syntax. 3 | Require Import Logic.PropositionalLogic.Syntax. 4 | 5 | Class ModalLanguage (L: Language): Type := { 6 | boxp : expr -> expr 7 | }. 8 | 9 | Definition diamondp {L: Language} {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {mL: ModalLanguage L}: expr -> expr := 10 | fun x => negp (boxp (negp x)). 11 | 12 | Module ModalLanguageNotation. 13 | 14 | Notation "□ x" := (boxp x) (at level 35) : syntax. (* Unicode 25a1 *) 15 | Notation "◇ x" := (diamondp x) (at level 35) : syntax. (* Unicode 25c7 *) 16 | 17 | End ModalLanguageNotation. 18 | 19 | -------------------------------------------------------------------------------- /Extensions/Syntax_CoreTransit.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.MinimumLogic.Syntax. 3 | Require Import Logic.PropositionalLogic.Syntax. 4 | Require Import Logic.ModalLogic.Syntax. 5 | Require Import Logic.SeparationLogic.Syntax. 6 | 7 | Class CoreTransitSeparationLanguage (L: Language): Type := { 8 | core_tr: expr -> expr 9 | }. 10 | 11 | Definition ct_mL (L: Language) {CtsGamma: CoreTransitSeparationLanguage L} : ModalLanguage L := @Build_ModalLanguage L core_tr. 12 | 13 | Module CoreTransitNotation. 14 | 15 | Notation "□ x" := (core_tr x) (at level 35) : syntax. (* Unicode 25a1 *) 16 | 17 | End CoreTransitNotation. 18 | 19 | -------------------------------------------------------------------------------- /lib/StrongInduction.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.omega.Omega. 2 | 3 | Lemma strong_induction {P: nat -> Prop}: 4 | (forall n, (forall m, m < n -> P m) -> P n) -> 5 | (forall n, P n). 6 | Proof. 7 | intros ?. 8 | assert (forall n, (forall m, m < n -> P m)). 9 | + intro n; induction n. 10 | - intros; omega. 11 | - intros. 12 | destruct (lt_dec m n). 13 | * apply IHn; auto. 14 | * assert (m = n) by omega; subst m. 15 | apply H; auto. 16 | + intros. 17 | apply (H0 (S n)). 18 | constructor. 19 | Qed. 20 | 21 | Ltac strong_induction n := 22 | revert dependent n; 23 | intro n; 24 | pattern n; 25 | revert n; 26 | apply strong_induction; 27 | intros ?n ?IH. 28 | -------------------------------------------------------------------------------- /GeneralLogic/ShallowEmbedded/PredicateAsLang.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.ProofIrrelevance. 2 | Require Import Coq.omega.Omega. 3 | Require Import Logic.lib.Bijection. 4 | Require Import Logic.lib.Countable. 5 | Require Import Logic.GeneralLogic.Base. 6 | 7 | Instance Pred_L (A: Type) : Language := Build_Language (A -> Prop). 8 | 9 | Instance Pred_strongGammaP (A: Type): Provable (Pred_L A) := 10 | Build_Provable (Pred_L A) (fun x => forall a, x a). 11 | 12 | Instance Pred_strongGammaD (A: Type): Derivable (Pred_L A) := 13 | Build_Derivable 14 | (Pred_L A) (fun Phi x => forall a, (forall y, Phi y -> y a) -> x a). 15 | 16 | Instance Pred_SM (A: Type): Semantics (Pred_L A) (Build_Model A) := 17 | Build_Semantics (Pred_L A) (Build_Model A) (fun x => x). 18 | -------------------------------------------------------------------------------- /HoareLogic/SimpleSmallStepSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.KripkeModel. 2 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 3 | Require Import Logic.HoareLogic.ImperativeLanguage. 4 | Require Import Logic.HoareLogic.ProgramState. 5 | 6 | Class SimpleSmallStepSemantics (P: ProgrammingLanguage) (state: Type): Type := { 7 | simple_step: cmd * state -> cmd * state -> Prop 8 | }. 9 | 10 | Definition step {P: ProgrammingLanguage} {state: Type} {SSSS: SimpleSmallStepSemantics P state} (final_state: cmd * state -> Prop) (cs: cmd * state) (mcs: MetaState (cmd * state)) := 11 | match mcs with 12 | | Terminating cs0 => simple_step cs cs0 13 | | NonTerminating => False 14 | | Error => ~ final_state cs /\ forall cs0, ~ simple_step cs cs0 15 | end. 16 | -------------------------------------------------------------------------------- /lib/SublistT.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Lists.List. 2 | 3 | Inductive sublistT {A: Type}: list A -> list A -> Type := 4 | | sublistT_nil_nil: sublistT nil nil 5 | | sublistT_cons: forall a {l1 l2}, sublistT l1 l2 -> sublistT l1 (a :: l2) 6 | | sublistT_cons_cons: forall a {l1 l2}, sublistT l1 l2 -> sublistT (a :: l1) (a :: l2). 7 | 8 | Definition sublistT_refl {A: Type}: forall (l: list A), sublistT l l := 9 | fix sublistT_refl l := 10 | match l with 11 | | nil => sublistT_nil_nil 12 | | a :: l' => sublistT_cons_cons a (sublistT_refl l') 13 | end. 14 | 15 | (* 16 | Definition sublistT_trans {A: Type}: 17 | forall (l1 l2 l3: list A), sublistT l1 l2 -> sublistT l2 l3 -> sublistT l1 l3 := 18 | fix sublistT_trans l1 l2 l3 g12 g23 := 19 | match g23 with 20 | | 21 | *) -------------------------------------------------------------------------------- /LogicGenerator/demo/configuration_3.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Lists.List. 2 | Require Import Logic.LogicGenerator.Utils. 3 | Require Import Logic.LogicGenerator.ConfigLang. 4 | 5 | Import ListNotations. 6 | 7 | Definition how_connectives := 8 | [primitive_connective impp 9 | ;primitive_connective andp 10 | ;primitive_connective orp 11 | ;primitive_connective falsep 12 | ;FROM_andp_impp_TO_iffp 13 | ;FROM_falsep_impp_TO_negp 14 | ;FROM_falsep_impp_TO_truep 15 | ;FROM_impp_TO_multi_imp 16 | ;FROM_empty_set_TO_empty_context 17 | ]. 18 | 19 | Definition how_judgements := 20 | [primitive_judgement derivable 21 | ;FROM_derivable_TO_provable 22 | ]. 23 | 24 | Definition transparent_names: list parameter := 25 | []. 26 | 27 | Definition primitive_rule_classes := 28 | [ derivitive_OF_basic_setting 29 | ; derivitive_OF_impp 30 | ; derivitive_OF_propositional_connectives 31 | ; GEN_provable_FROM_derivable 32 | ]. 33 | -------------------------------------------------------------------------------- /lib/register_typeclass.v: -------------------------------------------------------------------------------- 1 | Class RegisterClass (Kind: Type) {A: Type} (a: A) (n: nat): Type := {}. 2 | 3 | Ltac rec_from_n n tac := 4 | try (tac n; rec_from_n (S n) tac). 5 | 6 | Ltac get_nth' K n := 7 | let A := fresh "A" in 8 | evar (A: Type); 9 | let a := fresh "a" in 10 | evar (a: A); 11 | let H := fresh "H" in 12 | assert (RegisterClass K a n) as H by (unfold a, A; once (typeclasses eauto)); 13 | match type of H with 14 | | RegisterClass _ ?a _ => exact a 15 | end. 16 | 17 | Ltac get_nth K n := 18 | let a := eval cbv beta zeta in ltac:(get_nth' K n) in a. 19 | 20 | Goal RegisterClass unit 0 0 -> RegisterClass unit true 1 -> False. 21 | intros. 22 | let a := get_nth unit 1 in pose a. 23 | Abort. 24 | 25 | Ltac pose_proof_instance_as F name:= 26 | idtac; 27 | first [ let G := eval cbv beta in (F ltac:(typeclasses eauto)) in 28 | pose_proof_instance_as G name 29 | | pose proof F as name]. 30 | -------------------------------------------------------------------------------- /MinimumLogic/Semantics/Trivial.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.MinimumLogic.Syntax. 3 | 4 | Local Open Scope logic_base. 5 | Local Open Scope syntax. 6 | 7 | Module Semantics. 8 | 9 | Definition impp {model: Type} (X: Ensemble model) (Y: Ensemble model): Ensemble model := 10 | fun m => X m -> Y m. 11 | 12 | End Semantics. 13 | 14 | Class TrivialMinimumSemantics (L: Language) {minL: MinimumLanguage L} (MD: Model) (SM: Semantics L MD): Type := { 15 | denote_impp: forall x y, Same_set _ (denotation (x --> y)) (Semantics.impp (denotation x) (denotation y)) 16 | }. 17 | 18 | Lemma sat_impp {L: Language} {minL: MinimumLanguage L} {MD: Model} {SM: Semantics L MD} {tminSM: TrivialMinimumSemantics L MD SM}: forall m x y, m |= x --> y <-> (m |= x -> m |= y). 19 | Proof. 20 | intros; simpl. 21 | unfold satisfies. 22 | destruct (denote_impp x y). 23 | split; auto; [apply H | apply H0]. 24 | Qed. 25 | 26 | -------------------------------------------------------------------------------- /GeneralLogic/ShallowEmbedded/MonoPredicateAsLang.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.ProofIrrelevance. 2 | Require Import Coq.omega.Omega. 3 | Require Import Logic.lib.Bijection. 4 | Require Import Logic.lib.Countable. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | 8 | Instance MonoPred_L (A: Type) {R: Relation A} : Language 9 | := Build_Language (MonoEnsemble A). 10 | 11 | Instance MonoPred_strongGammaP (A: Type) {R: Relation A}: 12 | Provable (MonoPred_L A) := 13 | Build_Provable (MonoPred_L A) (fun x => forall a, proj1_sig x a). 14 | 15 | Instance MonoPred_strongGammaD (A: Type) {R: Relation A}: 16 | Derivable (MonoPred_L A) := 17 | Build_Derivable (MonoPred_L A) 18 | (fun Phi x => forall a, (forall y, Phi y -> proj1_sig y a) -> proj1_sig x a). 19 | 20 | Instance MonoPred_SM (A: Type) {R: Relation A}: Semantics (MonoPred_L A) (Build_Model A) := Build_Semantics (MonoPred_L A) (Build_Model A) (fun x => proj1_sig x). 21 | -------------------------------------------------------------------------------- /LogicGenerator/demo/implementation_2a.v: -------------------------------------------------------------------------------- 1 | Require Import ZArith. 2 | 3 | Module NaiveLang. 4 | Definition expr := (nat -> Z) -> Prop. 5 | Definition impp (e1 e2 : expr) : expr := fun st => e1 st -> e2 st. 6 | 7 | Definition provable (e : expr) : Prop := forall st, e st. 8 | End NaiveLang. 9 | 10 | Require Import interface_2. 11 | 12 | Module NaiveRule. 13 | Import NaiveLang. 14 | Include DerivedNames (NaiveLang). 15 | Lemma modus_ponens : 16 | forall x y : expr, provable (impp x y) -> provable x -> provable y. 17 | Proof. unfold provable, impp. auto. Qed. 18 | 19 | Lemma axiom1 : forall x y : expr, provable (impp x (impp y x)). 20 | Proof. unfold provable, impp. auto. Qed. 21 | 22 | Lemma axiom2 : forall x y z : expr, 23 | provable (impp (impp x (impp y z)) (impp (impp x y) (impp x z))). 24 | Proof. unfold provable, impp. auto. Qed. 25 | 26 | End NaiveRule. 27 | 28 | Module T := LogicTheorem NaiveLang NaiveRule. 29 | Module Solver := IPSolver NaiveLang. 30 | Import T. 31 | Import Solver. 32 | 33 | 34 | -------------------------------------------------------------------------------- /MinimumLogic/Complete/ContextProperty_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.EnsemblesProperties. 2 | Require Import Logic.GeneralLogic.Base. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 5 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 6 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 7 | 8 | Local Open Scope logic_base. 9 | 10 | Section ContextProperty. 11 | 12 | Context {L: Language} 13 | {minL: MinimumLanguage L} 14 | {Gamma: Derivable L} 15 | {fwSC: FiniteWitnessedSequentCalculus L Gamma}. 16 | 17 | Lemma can_derive_finite_witnessed: forall x, 18 | finite_witnessed (can_derive x). 19 | Proof. 20 | intros; hnf; intros. 21 | apply derivable_finite_witnessed; auto. 22 | Qed. 23 | 24 | Lemma cannot_derive_finite_captured: forall x, 25 | finite_captured (cannot_derive x). 26 | Proof. 27 | intros. 28 | apply (not_finite_witnessed_finite_captured _ (can_derive_finite_witnessed x)). 29 | Qed. 30 | 31 | End ContextProperty. 32 | -------------------------------------------------------------------------------- /PropositionalLogic/Syntax.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.MinimumLogic.Syntax. 3 | 4 | Class PropositionalLanguage (L: Language): Type := { 5 | andp : expr -> expr -> expr; 6 | orp : expr -> expr -> expr; 7 | falsep: expr 8 | }. 9 | 10 | Definition negp {L: Language} {MinL: MinimumLanguage L} {pL: PropositionalLanguage L} (x: expr): expr := impp x falsep. 11 | Definition iffp {L: Language} {MinL: MinimumLanguage L} {pL: PropositionalLanguage L} (x y: expr): expr := andp (impp x y) (impp y x). 12 | Definition truep {L: Language} {MinL: MinimumLanguage L} {pL: PropositionalLanguage L}: expr := impp falsep falsep. 13 | 14 | Module PropositionalLanguageNotation. 15 | 16 | Notation "x && y" := (andp x y) (at level 40, left associativity) : syntax. 17 | Notation "x || y" := (orp x y) (at level 50, left associativity) : syntax. 18 | Notation "x <--> y" := (iffp x y) (at level 60, no associativity) : syntax. 19 | Notation "~~ x" := (negp x) (at level 35) : syntax. 20 | Notation "'FF'" := falsep : syntax. 21 | Notation "'TT'" := truep : syntax. 22 | 23 | End PropositionalLanguageNotation. 24 | 25 | -------------------------------------------------------------------------------- /GeneralLogic/Semantics/Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.RelationClasses. 2 | Require Import Coq.Relations.Relation_Definitions. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | 6 | Local Open Scope logic_base. 7 | Local Open Scope kripke_model. 8 | Import KripkeModelFamilyNotation. 9 | Import KripkeModelNotation_Intuitionistic. 10 | 11 | (* TODO: This should be reformulated. Add a typeclass called kiMD: KripkeIntuitionisticModel, so that on every model, a preorder relation is defined. *) 12 | Class KripkeIntuitionisticSemantics (L: Language) (MD: Model) {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} (SM: Semantics L MD) : Type := { 13 | denote_closed: forall x, upwards_closed_Kdenote (Kdenotation M x) 14 | }. 15 | 16 | Lemma sat_mono {L: Language} {MD: Model} {kMD: KripkeModel MD} {M: Kmodel} {R: Relation (Kworlds M)} {SM: Semantics L MD} {kiSM: KripkeIntuitionisticSemantics L MD M SM}: forall m n x, m <= n -> KRIPKE: M , m |= x -> KRIPKE: M , n |= x. 17 | Proof. 18 | intros ? ? ? ?. 19 | unfold satisfies. 20 | apply (denote_closed x); auto. 21 | Qed. 22 | 23 | -------------------------------------------------------------------------------- /MinimumLogic/Sound/Sound_Classical_Trivial.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Ensembles_ext. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.MinimumLogic.Semantics.Trivial. 6 | 7 | Local Open Scope logic_base. 8 | Local Open Scope syntax. 9 | 10 | Section Sound. 11 | 12 | Context {L: Language} 13 | {minL: MinimumLanguage L} 14 | {MD: Model} 15 | {SM: Semantics L MD} 16 | {tminSM: TrivialMinimumSemantics L MD SM}. 17 | 18 | Lemma sound_modus_ponens: 19 | forall x y m, 20 | m |= (x --> y) -> m |= x -> m |= y. 21 | Proof. 22 | intros. 23 | rewrite sat_impp in H. 24 | apply H; auto. 25 | Qed. 26 | 27 | Lemma sound_axiom1: 28 | forall x y m, 29 | m |= x --> y --> x. 30 | Proof. 31 | intros. 32 | rewrite !sat_impp. 33 | intros ? ?; auto. 34 | Qed. 35 | 36 | Lemma sound_axiom2: 37 | forall x y z m, 38 | m |= (x --> y --> z) --> (x --> y) --> (x --> z). 39 | Proof. 40 | intros. 41 | rewrite !sat_impp. 42 | intros ? ? ?. 43 | specialize (H H1). 44 | specialize (H0 H1). 45 | auto. 46 | Qed. 47 | 48 | End Sound. 49 | -------------------------------------------------------------------------------- /lib/Bisimulation.v: -------------------------------------------------------------------------------- 1 | Require Export Coq.Relations.Relations. 2 | Require Import Coq.Classes.Morphisms. 3 | Require Export Coq.Classes.Equivalence. 4 | Require Import Logic.lib.Relation_ext. 5 | 6 | Definition bisimulation {A: Type} (bis: relation A) (R: relation A): Prop := 7 | forall m n, bis m n -> 8 | (forall m', R m m' -> exists n', R n n' /\ bis m' n') /\ 9 | (forall n', R n n' -> exists m', R m m' /\ bis m' n'). 10 | 11 | Class Bisimulation {A: Type} (bis: relation A) (R: relation A): Prop := { 12 | bis_l: forall m n, bis m n -> 13 | forall m', R m m' -> exists n', R n n' /\ bis m' n'; 14 | bis_r: forall m n, bis m n -> 15 | forall n', R n n' -> exists m', R m m' /\ bis m' n' 16 | }. 17 | 18 | Lemma eq_bis {A: Type} (R: relation A): Bisimulation eq R. 19 | Proof. 20 | constructor; intros. 21 | + exists m'; subst; auto. 22 | + exists n'; subst; auto. 23 | Qed. 24 | 25 | Lemma full_bis {A: Type} (R: relation A) {_: Serial R}: Bisimulation full_relation R. 26 | Proof. 27 | constructor; intros. 28 | + destruct (seriality n) as [n' ?]; exists n'. 29 | auto. 30 | + destruct (seriality m) as [m' ?]; exists m'. 31 | auto. 32 | Qed. 33 | 34 | -------------------------------------------------------------------------------- /LogicGenerator/demo/configuration_1.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Lists.List. 2 | Require Import Logic.LogicGenerator.Utils. 3 | Require Import Logic.LogicGenerator.ConfigLang. 4 | 5 | Import ListNotations. 6 | 7 | Definition how_connectives := 8 | [primitive_connective impp 9 | ;primitive_connective andp 10 | ;primitive_connective orp 11 | ;primitive_connective falsep 12 | ;primitive_connective sepcon 13 | ;primitive_connective emp 14 | ;FROM_andp_impp_TO_iffp 15 | ;FROM_falsep_impp_TO_negp 16 | ;FROM_falsep_impp_TO_truep 17 | ;FROM_impp_TO_multi_imp 18 | ;FROM_empty_set_TO_empty_context 19 | ;FROM_sepcon_TO_iter_sepcon 20 | ]. 21 | 22 | Definition how_judgements := 23 | [primitive_judgement provable 24 | ;FROM_provable_TO_derivable 25 | ]. 26 | 27 | Definition transparent_names := 28 | [expr:parameter]. 29 | 30 | Definition primitive_rule_classes := 31 | [ provability_OF_impp 32 | ; provability_OF_propositional_connectives 33 | ; provability_OF_classical_logic 34 | ; provability_OF_sepcon_rule_AS_weak_iffp 35 | ; provability_OF_sepcon_rule_AS_mono 36 | ; provability_OF_sepcon_orp_rule 37 | ; provability_OF_sepcon_falsep_rule 38 | ; provability_OF_emp_rule_AS_iffp 39 | ]. 40 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/SemanticsExtension.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Sets.Ensembles. 2 | Require Import Logic.GeneralLogic.KripkeModel. 3 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 4 | 5 | Local Open Scope kripke_model. 6 | Import KripkeModelNotation_Intuitionistic. 7 | 8 | Definition cut {worlds: Type} {J: Join worlds} (m: worlds) (P: worlds -> Prop) (n: worlds) : Prop := 9 | exists m', join m' n m /\ P m'. 10 | 11 | Definition greatest_cut {worlds: Type} {R: Relation worlds} {J: Join worlds} (m: worlds) (P: worlds -> Prop) (n: worlds) : Prop := 12 | cut m P n /\ (forall n', cut m P n' -> n' <= n). 13 | 14 | Definition Kdenote_precise {worlds: Type} {R: Relation worlds} {J: Join worlds} (P: Ensemble worlds): Prop := 15 | forall m n, cut m P n -> 16 | exists n, greatest_cut m P n. 17 | 18 | Require Import Logic.GeneralLogic.Base. 19 | 20 | Local Open Scope logic_base. 21 | Import KripkeModelFamilyNotation. 22 | 23 | Definition sem_precise 24 | {L: Language} 25 | {MD: Model} 26 | {kMD: KripkeModel MD} 27 | {M: Kmodel} 28 | {R: Relation (Kworlds M)} 29 | {J: Join (Kworlds M)} 30 | {SM: Semantics L MD} 31 | (x: expr): Prop := 32 | Kdenote_precise (Kdenotation M x). 33 | -------------------------------------------------------------------------------- /GeneralLogic/Complete/README: -------------------------------------------------------------------------------- 1 | Completeness 2 | | 3 | | 4 | | 5 | |--------------|-------------| 6 | | | | 7 | | | | 8 | | | | 9 | Canonical | | 10 | ( Model Has ) Truth | 11 | (Corresponding) | | 12 | ( Properties ) | | 13 | | | 14 | | | 15 | | | 16 | |------|------| 17 | | 18 | | 19 | | 20 | | 21 | | 22 | Lindenbaum 23 | | 24 | | 25 | | 26 | | 27 | | 28 | |------|------| 29 | | | 30 | | | 31 | | | 32 | | | 33 | Lindenabum Lindenabum 34 | Preserve Ensure -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | matrix: 4 | include: 5 | - os: linux 6 | services: 7 | - docker 8 | script: 9 | - | 10 | bash -c "while true; do echo \$(date) - travis building ...; sleep 540; done" & 11 | export PING_LOOP_PID=$! 12 | - | 13 | cat <<-EOF | docker run -i ocaml/opam:ubuntu-16.04_ocaml-4.05.0 bash - 14 | set -e 15 | opam install -y coq=8.6.1 16 | git clone https://github.com/QinxiangCao/UnifySL 17 | cd UnifySL 18 | make depend 19 | make -j 2 20 | EOF 21 | after_script: 22 | - kill -9 $PING_LOOP_PID 23 | 24 | - os: osx 25 | before_script: 26 | - | 27 | bash -c "while true; do echo \$(date) - travis building ...; sleep 540; done" & 28 | - git clone https://github.com/asdf-vm/asdf.git 29 | - . asdf/asdf.sh 30 | - asdf plugin-add ocaml https://github.com/vic/asdf-ocaml.git 31 | - asdf install ocaml 4.05.0 32 | - asdf global ocaml 4.05.0 33 | - opam install -y coq=8.6.1 34 | - asdf reshim ocaml 35 | script: 36 | - git clone https://github.com/QinxiangCao/UnifySL 37 | - cd UnifySL 38 | - make depend 39 | - make -j 2 40 | after_script: 41 | - kill -9 $PING_LOOP_PID 42 | -------------------------------------------------------------------------------- /HoareLogic/OperationalSemanticsGenerator.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.omega.Omega. 2 | Require Import Coq.Relations.Relation_Operators. 3 | Require Import Coq.Relations.Operators_Properties. 4 | Require Import Coq.Logic.Classical_Prop. 5 | Require Import Coq.Logic.Classical_Pred_Type. 6 | Require Import Logic.lib.Coqlib. 7 | Require Import Logic.lib.NatChoice. 8 | Require Import Logic.lib.Stream.SigStream. 9 | Require Import Logic.lib.Stream.StreamFunctions. 10 | Require Import Logic.lib.Stream.StreamSplit. 11 | Require Import Logic.GeneralLogic.Base. 12 | Require Import Logic.GeneralLogic.KripkeModel. 13 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 14 | Require Import Logic.HoareLogic.ImperativeLanguage. 15 | Require Import Logic.HoareLogic.ProgramState. 16 | Require Import Logic.HoareLogic.Trace. 17 | Require Import Logic.HoareLogic.SimpleSmallStepSemantics. 18 | Require Import Logic.HoareLogic.SmallStepSemantics. 19 | Require Import Logic.HoareLogic.BigStepSemantics. 20 | 21 | Module SSS_SimpleSSS. 22 | 23 | Instance SSS_SimpleSSS 24 | {P: ProgrammingLanguage} 25 | {state: Type} 26 | (SSSS: SimpleSmallStepSemantics P state) 27 | (final_state: cmd * state -> Prop): 28 | SmallStepSemantics P state := 29 | Build_SmallStepSemantics _ _ (SimpleSmallStepSemantics.step final_state). 30 | 31 | End SSS_SimpleSSS. 32 | 33 | -------------------------------------------------------------------------------- /HoareLogic/ConcurrentSemantics_Angelic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.GeneralLogic.KripkeModel. 3 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 4 | Require Import Logic.HoareLogic.ImperativeLanguage. 5 | Require Import Logic.HoareLogic.ProgramState. 6 | Require Import Logic.HoareLogic.BigStepSemantics. 7 | 8 | Definition DecorateProgram (P: ProgrammingLanguage) (hint: cmd -> Type): ProgrammingLanguage := 9 | Build_ProgrammingLanguage (sigT hint). 10 | 11 | Class ThreadLocalBigStepSemantics (P: ProgrammingLanguage) (state: Type) (guard: Type): Type := { 12 | hint: guard -> cmd -> Type; 13 | guarded_BSS: forall g: guard, BigStepSemantics (DecorateProgram P (hint g)) state 14 | }. 15 | 16 | Definition tl_access 17 | {P: ProgrammingLanguage} 18 | {state: Type} 19 | {guard: Type} 20 | {TLBSS: ThreadLocalBigStepSemantics P state guard}: 21 | forall (g: guard), state -> sigT (hint g) -> MetaState state -> Prop := 22 | fun g => @access _ _ (guarded_BSS g). 23 | 24 | Definition lift_tl_access 25 | {P: ProgrammingLanguage} 26 | {state: Type} 27 | {guard: Type} 28 | {TLBSS: ThreadLocalBigStepSemantics P state guard}: 29 | forall g: guard, MetaState state -> sigT (hint g) -> MetaState state -> Prop := 30 | fun g => @lift_access _ _ (guarded_BSS g). 31 | -------------------------------------------------------------------------------- /ModalLogic/Semantics/Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.ModalLogic.Model.KripkeModel. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.PropositionalLogic.Syntax. 5 | Require Import Logic.ModalLogic.Syntax. 6 | 7 | Local Open Scope logic_base. 8 | Local Open Scope syntax. 9 | Local Open Scope kripke_model. 10 | Import PropositionalLanguageNotation. 11 | Import ModalLanguageNotation. 12 | Import KripkeModelFamilyNotation. 13 | 14 | Module Semantics. 15 | 16 | Definition boxp {worlds: Type} {R: KM.Relation worlds} (X: Ensemble worlds): Ensemble worlds := 17 | fun m => forall n, Krelation m n -> X n. 18 | 19 | End Semantics. 20 | 21 | Class KripkeModalSemantics (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} (MD: Model) {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} (SM: Semantics L MD): Type := { 22 | denote_boxp: forall x: expr, Same_set _ (Kdenotation M (boxp x)) (Semantics.boxp (Kdenotation M x)) 23 | }. 24 | 25 | Lemma sat_boxp {L: Language} {minL: MinimumLanguage L} {mL: ModalLanguage L} {MD: Model} {kMD: KripkeModel MD} {M: Kmodel} {R: Relation (Kworlds M)} {SM: Semantics L MD} {kmSM: KripkeModalSemantics L MD M SM}: forall m x, KRIPKE: M , m |= boxp x <-> (forall n, KM.Krelation m n -> KRIPKE: M , n |= x). 26 | Proof. 27 | intros; simpl. 28 | unfold satisfies. 29 | destruct (denote_boxp x). 30 | split; [apply H | apply H0]. 31 | Qed. 32 | 33 | -------------------------------------------------------------------------------- /LogicGenerator/demo/implementation_2b.v: -------------------------------------------------------------------------------- 1 | Require Import ZArith. 2 | 3 | Definition var := nat. 4 | 5 | Inductive expr: Type := 6 | | impp : expr -> expr -> expr 7 | | varp : var -> expr. 8 | 9 | Declare Scope syntax. 10 | Notation "x --> y" := (impp x y) (at level 55, right associativity) : syntax. 11 | Local Open Scope syntax. 12 | 13 | Inductive provable: expr -> Prop := 14 | | modus_ponens: forall x y, provable (x --> y) -> provable x -> provable y 15 | | axiom1: forall x y, provable (x --> (y --> x)) 16 | | axiom2: forall x y z, provable ((x --> y --> z) --> (x --> y) --> (x --> z)). 17 | 18 | Module NaiveLang. 19 | Definition expr := expr. 20 | Definition impp := impp. 21 | Definition provable := provable. 22 | End NaiveLang. 23 | 24 | Require Import interface_2. 25 | 26 | Module NaiveRule. 27 | Import NaiveLang. 28 | Include DerivedNames (NaiveLang). 29 | Lemma modus_ponens : 30 | forall x y : expr, provable (impp x y) -> provable x -> provable y. 31 | Proof. intros. eapply modus_ponens; eauto. Qed. 32 | 33 | Lemma axiom1 : forall x y : expr, provable (impp x (impp y x)). 34 | Proof. exact axiom1. Qed. 35 | 36 | Lemma axiom2 : forall x y z : expr, 37 | provable (impp (impp x (impp y z)) (impp (impp x y) (impp x z))). 38 | Proof. exact axiom2. Qed. 39 | 40 | End NaiveRule. 41 | 42 | Module T := LogicTheorem NaiveLang NaiveRule. 43 | Module Solver := IPSolver NaiveLang. 44 | Import T. 45 | Import Solver. 46 | 47 | -------------------------------------------------------------------------------- /lib/Countable.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Bijection. 2 | 3 | Definition Countable (A: Type): Type := injection A nat. 4 | 5 | Definition injection_Countable {A B} (R: injection A B) (CB: Countable B): Countable A := injection_trans R CB. 6 | 7 | Definition bijection_Countable {A B} (R: bijection A B) (CB: Countable B): Countable A := injection_Countable (bijection_injection R) CB. 8 | 9 | Definition sum_Countable {A B} (CA: Countable A) (CB: Countable B): Countable (sum A B) := 10 | injection_trans (sum_injection CA CB) (bijection_injection nat2_nat_bijection). 11 | 12 | Definition prod_Countable {A B} (CA: Countable A) (CB: Countable B): Countable (prod A B) := 13 | injection_trans (prod_injection CA CB) (bijection_injection natnat_nat_bijection). 14 | 15 | Definition nCountable_Countable {A: nat -> Type} (CA: forall n, Countable (A n)): Countable (sigT A) := 16 | injection_trans (sigT_injection _ _ _ CA) (bijection_injection natnat_nat_bijection). 17 | 18 | Definition unit_Countable: Countable unit. 19 | apply (FBuild_injection _ _ (fun _ => 0)). 20 | hnf; intros. 21 | destruct a1, a2; auto. 22 | Qed. 23 | 24 | Ltac solve_Countable := 25 | match goal with 26 | | |- Countable (sum _ _) => apply sum_Countable; solve_Countable 27 | | |- Countable (prod _ _) => apply prod_Countable; solve_Countable 28 | | |- Countable (sigT _) => try (apply nCountable_Countable; intro; solve_Countable) 29 | | |- Countable unit => apply unit_Countable 30 | | _ => try assumption 31 | end. 32 | 33 | 34 | -------------------------------------------------------------------------------- /SeparationLogic/DeepEmbedded/SeparationLanguage.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.ProofIrrelevance. 2 | Require Import Coq.omega.Omega. 3 | Require Import Logic.lib.Bijection. 4 | Require Import Logic.lib.Countable. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | Require Import Logic.PropositionalLogic.Syntax. 8 | Require Import Logic.SeparationLogic.Syntax. 9 | 10 | Local Open Scope logic_base. 11 | Local Open Scope syntax. 12 | Import PropositionalLanguageNotation. 13 | Import SeparationLogicNotation. 14 | 15 | Class PropositionalVariables: Type := { 16 | Var: Type 17 | }. 18 | 19 | Inductive expr {Sigma: PropositionalVariables}: Type := 20 | | andp : expr -> expr -> expr 21 | | orp : expr -> expr -> expr 22 | | impp : expr -> expr -> expr 23 | | falsep : expr 24 | | sepcon : expr -> expr -> expr 25 | | wand : expr -> expr -> expr 26 | | varp : Var -> expr. 27 | 28 | Arguments expr: clear implicits. 29 | 30 | Instance L {Sigma: PropositionalVariables}: Language := 31 | Build_Language (expr Sigma). 32 | 33 | Instance minL {Sigma: PropositionalVariables}: MinimumLanguage L := 34 | Build_MinimumLanguage L impp. 35 | 36 | Instance pL {Sigma: PropositionalVariables}: PropositionalLanguage L := 37 | Build_PropositionalLanguage L andp orp falsep. 38 | 39 | Instance sepconL {Sigma: PropositionalVariables}: SepconLanguage L := 40 | Build_SepconLanguage L sepcon. 41 | 42 | Instance wandL {Sigma: PropositionalVariables}: WandLanguage L := 43 | Build_WandLanguage L wand. 44 | -------------------------------------------------------------------------------- /HoareLogic/GuardedHoareTriple_TraceSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.PropositionalLogic.Syntax. 3 | Require Import Logic.SeparationLogic.Syntax. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 6 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 7 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 8 | Require Import Logic.HoareLogic.ImperativeLanguage. 9 | Require Import Logic.HoareLogic.BigStepSemantics. 10 | Require Import Logic.HoareLogic.TraceSemantics. 11 | Require Import Logic.HoareLogic.HoareTriple_BigStepSemantics. 12 | 13 | Local Open Scope logic_base. 14 | Local Open Scope syntax. 15 | Local Open Scope kripke_model. 16 | Import PropositionalLanguageNotation. 17 | Import SeparationLogicNotation. 18 | Import KripkeModelSingleNotation. 19 | Import KripkeModelNotation_Intuitionistic. 20 | 21 | Definition guarded_triple_partial_valid 22 | {L: Language} 23 | {P: ProgrammingLanguage} 24 | {MD: Model} 25 | {J: Join model} 26 | {R: Relation model} 27 | {Res: Resource} 28 | {Ac: Action} 29 | {Acr: Action_resource Ac Res} 30 | {TS: TraceSemantics P (resources * model) Ac} 31 | {SM: Semantics L MD} 32 | (Inv: (resource * (model -> Prop)) -> Prop) 33 | (Pre: expr) 34 | (c: cmd) 35 | (Post: expr): 36 | Prop := 37 | @triple_partial_valid L _ MD (ThreadLocal_BSS TS Inv) SM Pre c Post. 38 | -------------------------------------------------------------------------------- /MinimumLogic/Semantics/SemanticEquiv.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Logic.lib.Ensembles_ext. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | Require Import Logic.MinimumLogic.Syntax. 8 | Require Logic.MinimumLogic.Semantics.Kripke. 9 | Require Logic.MinimumLogic.Semantics.Trivial. 10 | 11 | Local Open Scope logic_base. 12 | Local Open Scope syntax. 13 | Local Open Scope kripke_model. 14 | Import KripkeModelFamilyNotation. 15 | Import KripkeModelNotation_Intuitionistic. 16 | 17 | Section SemanticEquiv. 18 | 19 | Context {L: Language} 20 | {minL: MinimumLanguage L} 21 | {MD: Model} 22 | {SM: Semantics L MD}. 23 | 24 | Lemma eqR_KripkeIntuitionistic: @Kripke.KripkeIntuitionisticSemantics L MD (unit_kMD _) tt eq SM. 25 | Proof. 26 | constructor. 27 | intros; hnf; intros. 28 | hnf in H; subst. 29 | auto. 30 | Qed. 31 | 32 | Lemma Trivial2Kripke {tpSM: Trivial.TrivialMinimumSemantics L MD SM}: 33 | @Kripke.KripkeMinimumSemantics L minL MD (unit_kMD _) tt eq SM. 34 | Proof. 35 | constructor. 36 | + intros. 37 | change (@Kdenotation L MD (unit_kMD _) tt SM) with denotation. 38 | rewrite Trivial.denote_impp. 39 | split; unfold Included, Ensembles.In; intros. 40 | - hnf; intros. 41 | hnf in H0; subst. 42 | apply H, H1. 43 | - hnf; intros; apply (H x0); auto. 44 | reflexivity. 45 | Qed. 46 | 47 | End SemanticEquiv. 48 | -------------------------------------------------------------------------------- /PropositionalLogic/DeepEmbedded/TrivialSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Ensembles_ext. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.MinimumLogic.Semantics.Trivial. 6 | Require Import Logic.PropositionalLogic.Syntax. 7 | Require Import Logic.PropositionalLogic.Semantics.Trivial. 8 | Require Import Logic.PropositionalLogic.DeepEmbedded.PropositionalLanguage. 9 | 10 | Section TrivialSemantics. 11 | 12 | Context {Sigma: PropositionalVariables}. 13 | 14 | Existing Instances L minL pL. 15 | 16 | Definition model: Type := Var -> Prop. 17 | 18 | Fixpoint denotation (x: expr Sigma): Ensemble model := 19 | match x with 20 | | andp y z => Semantics.andp (denotation y) (denotation z) 21 | | orp y z => Semantics.orp (denotation y) (denotation z) 22 | | impp y z => Semantics.impp (denotation y) (denotation z) 23 | | falsep => Semantics.falsep 24 | | varp p => fun m => m p 25 | end. 26 | 27 | Instance MD: Model := 28 | Build_Model model. 29 | 30 | Instance SM: Semantics L MD := 31 | Build_Semantics L MD denotation. 32 | 33 | Instance tminSM: TrivialMinimumSemantics L MD SM. 34 | Proof. 35 | constructor. 36 | simpl; intros. 37 | apply Same_set_refl. 38 | Qed. 39 | 40 | Instance tpSM: TrivialPropositionalSemantics L MD SM. 41 | Proof. 42 | constructor. 43 | + simpl; intros. 44 | apply Same_set_refl. 45 | + simpl; intros. 46 | apply Same_set_refl. 47 | + simpl; intros. 48 | apply Same_set_refl. 49 | Qed. 50 | 51 | End TrivialSemantics. 52 | -------------------------------------------------------------------------------- /ModalLogic/Model/OrderedKripkeModel.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.KripkeModel. 2 | Require Import Logic.ModalLogic.Model.KripkeModel. 3 | 4 | Local Open Scope kripke_model. 5 | Import KripkeModelNotation_Intuitionistic. 6 | 7 | Class UpwardsClosedOrderedKripkeModel (worlds: Type) {R1: KI.Relation worlds} {R2: KM.Relation worlds} := { 8 | KM_relation_up: forall m m' n', m <= m' -> KM.Krelation m' n' -> exists n, n <= n' /\ KM.Krelation m n 9 | }. 10 | 11 | (* Generator *) 12 | 13 | Instance prod_ukmM {A B: Type} (RA1: KI.Relation A) (RB1: KI.Relation B) (RA2: KM.Relation A) (RB2: KM.Relation B) {ukmM_A: UpwardsClosedOrderedKripkeModel A} {ukmM_B: UpwardsClosedOrderedKripkeModel B}: @UpwardsClosedOrderedKripkeModel (A * B) (RelProd RA1 RB1) (RelProd RA2 RB2). 14 | Proof. 15 | constructor. 16 | intros [m1 m2] [m1' m2'] [n1 n2] [? ?] [? ?]. 17 | hnf in H, H0, H1, H2; simpl in *. 18 | destruct (KM_relation_up _ _ _ H H1) as [n1' [? ?]]. 19 | destruct (KM_relation_up _ _ _ H0 H2) as [n2' [? ?]]. 20 | exists (n1', n2'). 21 | split; split; auto. 22 | Qed. 23 | 24 | Instance eq1_ukmM (worlds: Type) {R: KM.Relation worlds}: @UpwardsClosedOrderedKripkeModel worlds eq R. 25 | Proof. 26 | constructor; intros. 27 | exists n'; simpl in *. 28 | split. 29 | + reflexivity. 30 | + hnf in H; subst; auto. 31 | Qed. 32 | 33 | Instance eq2_ukmM (worlds: Type) {R: KI.Relation worlds}: @UpwardsClosedOrderedKripkeModel worlds R eq. 34 | Proof. 35 | constructor; intros. 36 | exists m; simpl in *. 37 | split. 38 | + hnf in H0; subst; auto. 39 | + reflexivity. 40 | Qed. 41 | -------------------------------------------------------------------------------- /MinimumLogic/DeepEmbedded/MinimumLogic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 5 | Require Logic.MinimumLogic.DeepEmbedded.MinimumLanguage. 6 | 7 | Local Open Scope logic_base. 8 | Local Open Scope syntax. 9 | 10 | Section MinimumLogic. 11 | 12 | Context (Var: Type). 13 | 14 | Instance L: Language := MinimumLanguage.L Var. 15 | Instance minL: MinimumLanguage L := MinimumLanguage.minL Var. 16 | 17 | Inductive provable: expr -> Prop := 18 | | modus_ponens: forall x y, provable (x --> y) -> provable x -> provable y 19 | | axiom1: forall x y, provable (x --> (y --> x)) 20 | | axiom2: forall x y z, provable ((x --> y --> z) --> (x --> y) --> (x --> z)). 21 | 22 | Instance GP: Provable L := Build_Provable L provable. 23 | 24 | Instance GD: Derivable L := Provable2Derivable. 25 | 26 | Instance AX: NormalAxiomatization L GP GD := Provable2Derivable_Normal. 27 | 28 | Instance minAX: MinimumAxiomatization L GP. 29 | Proof. 30 | constructor. 31 | + apply modus_ponens. 32 | + apply axiom1. 33 | + apply axiom2. 34 | Qed. 35 | 36 | Instance SC: NormalSequentCalculus L GP GD := Axiomatization2SequentCalculus_SC. 37 | 38 | Instance bSC: BasicSequentCalculus L GD := Axiomatization2SequentCalculus_bSC. 39 | 40 | Instance fwSC: FiniteWitnessedSequentCalculus L GD := Axiomatization2SequentCalculus_fwSC. 41 | 42 | Instance minSC: MinimumSequentCalculus L GD := Axiomatization2SequentCalculus_minSC. 43 | 44 | End MinimumLogic. 45 | -------------------------------------------------------------------------------- /ModalLogic/ShallowEmbedded/PredicateModalLogic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Ensembles_ext. 2 | Require Import Logic.GeneralLogic.Base. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.PropositionalLogic.Syntax. 5 | Require Import Logic.ModalLogic.Syntax. 6 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 7 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 8 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 9 | Require Import Logic.ModalLogic.ProofTheory.ModalLogic. 10 | Require Import Logic.ModalLogic.Model.KripkeModel. 11 | Require Import Logic.ModalLogic.Semantics.Kripke. 12 | Require Import Logic.ModalLogic.Sound.Sound_Kripke. 13 | Require Import Logic.GeneralLogic.ShallowEmbedded.PredicateAsLang. 14 | Require Import Logic.PropositionalLogic.ShallowEmbedded.PredicatePropositionalLogic. 15 | 16 | Instance Pred_mL (A: Type) {R: KM.Relation A}: ModalLanguage (Pred_L A) := 17 | Build_ModalLanguage (Pred_L A) Semantics.boxp. 18 | 19 | Instance Pred_kmSM (A: Type) {R: KM.Relation A}: @KripkeModalSemantics (Pred_L A) (Pred_minL A) (Pred_mL A) (Build_Model A) (unit_kMD _) tt R (Pred_SM A). 20 | Proof. 21 | constructor. 22 | intros; apply Same_set_refl. 23 | Qed. 24 | 25 | Instance Pred_KmGamma (A: Type) {R: KM.Relation A}: SystemK (Pred_L A) (Pred_Gamma A). 26 | Proof. 27 | constructor. 28 | + intros x y. 29 | exact (@sound_axiom_K (Pred_L A) _ _ (Build_Model A) (unit_kMD _) tt R (Pred_SM A) (Pred_tminSM A) (Pred_kmSM A) x y). 30 | + intros x. 31 | exact (@sound_rule_N (Pred_L A) _ _ (Build_Model A) (unit_kMD _) tt R (Pred_SM A) (Pred_kmSM A) x). 32 | Qed. 33 | -------------------------------------------------------------------------------- /GeneralLogic/Complete/ContextProperty.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Coqlib. 3 | Require Import Logic.GeneralLogic.Base. 4 | 5 | Local Open Scope logic_base. 6 | 7 | Section ContextProperty. 8 | 9 | Context {L: Language}. 10 | 11 | Definition at_least (P cP: context -> Prop): Prop := 12 | forall (Phi: context), cP Phi -> P Phi. 13 | 14 | Lemma at_least_self: forall P, at_least P P. 15 | Proof. 16 | intros. 17 | hnf; intros. 18 | auto. 19 | Qed. 20 | 21 | Lemma at_least_left: forall P cP1 cP2, at_least P cP1 -> at_least P (Intersection _ cP1 cP2). 22 | Proof. 23 | intros. 24 | hnf in H |- *; intros. 25 | destruct H0; auto. 26 | Qed. 27 | 28 | Lemma at_least_right: forall P cP1 cP2, at_least P cP2 -> at_least P (Intersection _ cP1 cP2). 29 | Proof. 30 | intros. 31 | hnf in H |- *; intros. 32 | destruct H0; auto. 33 | Qed. 34 | 35 | Definition maximal (P: context -> Prop): context -> Prop := 36 | fun Phi => P Phi /\ forall Psi, P Psi -> Included _ Phi Psi -> Included _ Psi Phi. 37 | 38 | Lemma sig_context_ext: forall (cP: context -> Prop) (Phi Psi: sig cP), 39 | (forall x, proj1_sig Phi x <-> proj1_sig Psi x) -> Phi = Psi. 40 | Proof. 41 | intros. 42 | pose proof Extensionality_Ensembles _ _ _ (conj (fun x => proj1 (H x)) (fun x => proj2 (H x))). 43 | destruct Psi as [Psi ?], Phi as [Phi ?]. 44 | simpl in H0; subst. 45 | pose proof proof_irrelevance _ c c0. 46 | subst. 47 | auto. 48 | Qed. 49 | 50 | End ContextProperty. 51 | 52 | Ltac solve_at_least := 53 | solve [apply at_least_self | auto | apply at_least_left; solve_at_least | apply at_least_right; solve_at_least]. 54 | 55 | -------------------------------------------------------------------------------- /HoareLogic/GuardedHoareLogic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.PropositionalLogic.Syntax. 3 | Require Import Logic.SeparationLogic.Syntax. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 6 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 7 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 8 | Require Import Logic.HoareLogic.ImperativeLanguage. 9 | Require Import Logic.HoareLogic.BigStepSemantics. 10 | Require Import Logic.HoareLogic.ConcurrentSemantics_Angelic. 11 | Require Import Logic.HoareLogic.HoareLogic. 12 | 13 | (***************************************) 14 | (* Type Classes *) 15 | (***************************************) 16 | 17 | Class GuardedHoareTriple 18 | (L: Language) 19 | (P: ProgrammingLanguage) 20 | (HLan: Language): Type := 21 | { 22 | Assertion := @expr L; 23 | guard: Type; 24 | triple: guard -> 25 | Assertion -> 26 | cmd -> 27 | Assertion -> 28 | @expr HLan 29 | }. 30 | 31 | Definition triple_valid 32 | {L: Language} 33 | {P: ProgrammingLanguage} 34 | {HLan: Language} 35 | {TI: Semantics HLan unit_MD} 36 | (t: @expr HLan): Prop := 37 | @satisfies _ _ TI tt t. 38 | 39 | (* 40 | Notation "|== x" := (triple_valid x) (at level 71, no associativity) : hoare_logic. 41 | (* This notation has been used. *) 42 | *) 43 | Declare Scope guarded_hoare_logic. 44 | Notation "{{ Inv }} {{ P }} c {{ Q }}" := (triple Inv P c Q) (at level 80, no associativity) : guarded_hoare_logic. 45 | 46 | 47 | -------------------------------------------------------------------------------- /HoareLogic/HoareTriple_BigStepSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.PropositionalLogic.Syntax. 3 | Require Import Logic.SeparationLogic.Syntax. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 6 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 7 | Require Import Logic.HoareLogic.ImperativeLanguage. 8 | Require Import Logic.HoareLogic.ProgramState. 9 | Require Import Logic.HoareLogic.BigStepSemantics. 10 | 11 | Local Open Scope logic_base. 12 | Local Open Scope syntax. 13 | Local Open Scope kripke_model. 14 | Import PropositionalLanguageNotation. 15 | Import SeparationLogicNotation. 16 | Import KripkeModelSingleNotation. 17 | Import KripkeModelNotation_Intuitionistic. 18 | 19 | Definition triple_partial_valid {L: Language} {P: ProgrammingLanguage} {MD: Model} {BSS: BigStepSemantics P (model)} {SM: Semantics L MD} (Pre: expr) (c: cmd) (Post: expr): Prop := 20 | forall (s_pre: model) (ms_post: MetaState model), 21 | KRIPKE: s_pre |= Pre -> 22 | access s_pre c ms_post -> 23 | match ms_post with 24 | | Error => False 25 | | NonTerminating => True 26 | | Terminating s_post => KRIPKE: s_post |= Post 27 | end. 28 | 29 | Definition triple_total_valid {L: Language} {P: ProgrammingLanguage} {MD: Model} {BSS: BigStepSemantics P (model)} {SM: Semantics L MD} (Pre: expr) (c: cmd) (Post: expr): Prop := 30 | forall (s_pre: model) (ms_post: MetaState model), 31 | KRIPKE: s_pre |= Pre -> 32 | access s_pre c ms_post -> 33 | match ms_post with 34 | | Error => False 35 | | NonTerminating => False 36 | | Terminating s_post => KRIPKE: s_post |= Post 37 | end. 38 | -------------------------------------------------------------------------------- /QuantifierLogic/ProofTheory/QuantifierLogic.v: -------------------------------------------------------------------------------- 1 | (* 2 | Require Import Logic.lib.Coqlib. 3 | Require Import Logic.lib.SublistT. 4 | Require Import Logic.GeneralLogic.Base. 5 | Require Import Logic.MinimumLogic.Syntax. 6 | Require Import Logic.QuantifierLogic.Syntax. 7 | Require Import Logic.MinimumLogic.ProofTheory.Normal. 8 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 9 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 10 | 11 | Local Open Scope logic_base. 12 | Local Open Scope syntax. 13 | 14 | Class BindedProofTheory (BL: BinderLanguage): Type := { 15 | binded_Gamma:> forall ts, ProofTheory (binded_L ts) 16 | }. 17 | 18 | Class QuantifierLogic 19 | (BL: BinderLanguage) 20 | {nL: forall ts, NormalLanguage (binded_L ts)} 21 | {qL: QuantifierLanguage BL} 22 | (BGamma: BindedProofTheory BL) 23 | {nGamma: forall ts, NormalProofTheory (binded_L ts) (binded_Gamma ts)} 24 | {mpGamma: forall ts, MinimumPropositionalLogic (binded_L ts) (binded_Gamma ts)} := 25 | { 26 | allp_elim: forall (t: type) (ts: list type) (x: binded_expr (t :: ts)) (e: binded_term ts t), 27 | |-- allp x --> ins_expr x e; 28 | allp_gen: forall (t: type) (ts: list type) (x: binded_expr ts) (y: binded_expr (t :: ts)), 29 | |-- lift_expr (sublistT_cons t (sublistT_refl ts)) x --> y -> 30 | |-- x --> allp y; 31 | exp_intros: forall (t: type) (ts: list type) (x: binded_expr (t :: ts)) (e: binded_term ts t), 32 | |-- ins_expr x e --> exp x; 33 | exp_gen: forall (t: type) (ts: list type) (x: binded_expr (t :: ts)) (y: binded_expr ts), 34 | |-- x --> lift_expr (sublistT_cons t (sublistT_refl ts)) y -> 35 | |-- exp x --> y 36 | }. 37 | 38 | *) 39 | -------------------------------------------------------------------------------- /GeneralLogic/Complete/Lindenbaum_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Sets.Ensembles. 3 | Require Export Coq.Lists.List. 4 | Require Import Coq.omega.Omega. 5 | Require Import Coq.Classes.Morphisms. 6 | Require Import Coq.Classes.RelationClasses. 7 | Require Import Logic.lib.Bijection. 8 | Require Import Logic.lib.Countable. 9 | Require Import Logic.lib.Ensembles_ext. 10 | Require Import Logic.lib.EnsemblesProperties. 11 | 12 | Require Import Logic.GeneralLogic.Base. 13 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 14 | Require Import Logic.GeneralLogic.Complete.Lindenbaum. 15 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 16 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 17 | 18 | Local Open Scope logic_base. 19 | 20 | Section Lindenbaum. 21 | 22 | Context {L: Language} 23 | {Gamma: Derivable L} 24 | {bSC: BasicSequentCalculus L Gamma}. 25 | 26 | Lemma Lindenbaum_for_derivable_closed: forall P, 27 | Lindenbaum_preserves P -> 28 | derivable_subset_preserved P -> 29 | Lindenbaum_ensures P derivable_closed. 30 | Proof. 31 | intros; hnf; intros; hnf; intros. 32 | pose proof H CA _ H1. 33 | destruct (im_inj _ _ CA x) as [n ?]. 34 | rewrite <- Lindenbaum_pointwise_finite_decided by eauto. 35 | simpl; right; split; auto. 36 | eapply H0; [| exact H3]. 37 | unfold Included, Ensembles.In; intros. 38 | eapply deduction_subst; eauto. 39 | eapply deduction_weaken; eauto. 40 | rewrite Union_Included; split. 41 | + eapply Included_trans; [| apply left_Included_Union]. 42 | apply Lindenbaum_included_n_omega. 43 | + eapply Included_trans; [| apply right_Included_Union]. 44 | intros ? ?. 45 | inversion H6; subst; auto. 46 | Qed. 47 | 48 | End Lindenbaum. 49 | -------------------------------------------------------------------------------- /MinimumLogic/Complete/Lindenbaum_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.FunctionalExtensionality. 2 | Require Import Coq.Logic.Classical_Prop. 3 | Require Import Coq.Logic.Classical_Pred_Type. 4 | Require Import Logic.lib.Bijection. 5 | Require Import Logic.lib.Countable. 6 | Require Import Logic.GeneralLogic.Base. 7 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 8 | Require Import Logic.GeneralLogic.Complete.Lindenbaum. 9 | Require Import Logic.GeneralLogic.Complete.Lindenbaum_Kripke. 10 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 11 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 12 | Require Import Logic.MinimumLogic.Syntax. 13 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 14 | Require Import Logic.MinimumLogic.Complete.ContextProperty_Kripke. 15 | 16 | Local Open Scope logic_base. 17 | Local Open Scope kripke_model. 18 | Import KripkeModelFamilyNotation. 19 | 20 | Section Lindenbaum_Kripke. 21 | 22 | Context {L: Language} 23 | {minL: MinimumLanguage L} 24 | {Gamma: Derivable L} 25 | {bSC: BasicSequentCalculus L Gamma} 26 | {fwSC: FiniteWitnessedSequentCalculus L Gamma}. 27 | 28 | Lemma Lindenbaum_preserves_cannot_derive: forall x, Lindenbaum_preserves (cannot_derive x). 29 | Proof. 30 | intros. 31 | apply Lindenbaum_preserves_by_finiteness. 32 | - apply cannot_derive_finite_captured. 33 | - apply cannot_derive_subset_preserved. 34 | Qed. 35 | 36 | Lemma Lindenbaum_cannot_derive_ensures_derivable_closed: forall x, Lindenbaum_ensures (cannot_derive x) derivable_closed. 37 | Proof. 38 | intros. 39 | apply Lindenbaum_for_derivable_closed. 40 | - apply Lindenbaum_preserves_cannot_derive. 41 | - apply cannot_derive_derivable_subset_preserved. 42 | Qed. 43 | 44 | End Lindenbaum_Kripke. 45 | -------------------------------------------------------------------------------- /HoareLogic/GuardedHoareTriple_Angelic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.PropositionalLogic.Syntax. 3 | Require Import Logic.SeparationLogic.Syntax. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 6 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 7 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 8 | Require Import Logic.HoareLogic.ImperativeLanguage. 9 | Require Import Logic.HoareLogic.BigStepSemantics. 10 | Require Import Logic.HoareLogic.ConcurrentSemantics_Angelic. 11 | Require Import Logic.HoareLogic.HoareTriple_BigStepSemantics. 12 | 13 | Local Open Scope logic_base. 14 | Local Open Scope syntax. 15 | Local Open Scope kripke_model. 16 | Import PropositionalLanguageNotation. 17 | Import SeparationLogicNotation. 18 | Import KripkeModelSingleNotation. 19 | Import KripkeModelNotation_Intuitionistic. 20 | 21 | Definition guarded_triple_partial_valid 22 | {L: Language} 23 | {P: ProgrammingLanguage} 24 | {MD: Model} 25 | {guard: Type} 26 | {TLBSS: ThreadLocalBigStepSemantics P (model) guard} 27 | {SM: Semantics L MD} 28 | (Inv: guard) 29 | (Pre: expr) 30 | (c: cmd) 31 | (Post: expr): 32 | Prop := 33 | exists h, 34 | @triple_partial_valid L _ MD (guarded_BSS Inv) SM Pre (existT _ c h) Post. 35 | 36 | Definition guarded_triple_total_valid 37 | {L: Language} 38 | {P: ProgrammingLanguage} 39 | {MD: Model} 40 | {guard: Type} 41 | {TLBSS: ThreadLocalBigStepSemantics P (model) guard} 42 | {SM: Semantics L MD} 43 | (Inv: guard) 44 | (Pre: expr) 45 | (c: cmd) 46 | (Post: expr): 47 | Prop := 48 | exists h, 49 | @triple_total_valid L _ MD (guarded_BSS Inv) SM Pre (existT _ c h) Post. 50 | -------------------------------------------------------------------------------- /HoareLogic/ImperativeLanguage.v: -------------------------------------------------------------------------------- 1 | Class ProgrammingLanguage: Type := { 2 | cmd: Type 3 | }. 4 | 5 | Class ImperativeProgrammingLanguage (P: ProgrammingLanguage): Type := { 6 | bool_expr: Type; 7 | Ssequence: cmd -> cmd -> cmd; 8 | Sifthenelse: bool_expr -> cmd -> cmd -> cmd; 9 | Swhile: bool_expr -> cmd -> cmd; 10 | Sskip: cmd 11 | }. 12 | 13 | Class ConcurrentProgrammingLanguage_Sparallel (P: ProgrammingLanguage): Type := { 14 | Sparallel: cmd -> cmd -> cmd 15 | }. 16 | 17 | Class Resource: Type := { 18 | resource: Type; 19 | resources := resource -> Prop 20 | }. 21 | 22 | Class ConcurrentProgrammingLanguage_Sresource (P: ProgrammingLanguage) (Res: Resource): Type := { 23 | Sresource: resource -> cmd -> cmd 24 | }. 25 | 26 | Class ConcurrentProgrammingLanguage_AcqRel_resource (P: ProgrammingLanguage) (Res: Resource): Type := { 27 | Sacquire_res: resource -> cmd; 28 | Srelease_res: resource -> cmd 29 | }. 30 | 31 | Class ConcurrentProgrammingLanguage_lock (P: ProgrammingLanguage): Type := { 32 | lock_expr: Type 33 | }. 34 | 35 | Class ConcurrentProgrammingLanguage_AcqRel_lock (P: ProgrammingLanguage) {CPl: ConcurrentProgrammingLanguage_lock P}: Type := { 36 | Sacquire_lock: lock_expr -> cmd; 37 | Srelease_lock: lock_expr -> cmd 38 | }. 39 | 40 | Class NormalImperativeProgrammingLanguage (P: ProgrammingLanguage) {iP: ImperativeProgrammingLanguage P}: Type := { 41 | Ssequence_inv: forall c1 c2 c1' c2', Ssequence c1 c2 = Ssequence c1' c2' -> c1 = c1' /\ c2 = c2'; 42 | Ssequence_Sskip: forall c1 c2, Ssequence c1 c2 <> Sskip; 43 | Sifthenelse_inv: forall b c1 c2 b' c1' c2', Sifthenelse b c1 c2 = Sifthenelse b' c1' c2' -> b = b' /\ c1 = c1' /\ c2 = c2'; 44 | Sifthenelse_Sskip: forall b c1 c2, Sifthenelse b c1 c2 <> Sskip; 45 | Swhile_inv: forall b c b' c', Swhile b c = Swhile b' c' -> b = b' /\ c = c'; 46 | Swhile_Sskip: forall b c, Swhile b c <> Sskip; 47 | Ssequence_Swhile: forall c1 c2 b c, Ssequence c1 c2 <> Swhile b c 48 | }. 49 | 50 | 51 | -------------------------------------------------------------------------------- /HoareLogic/HoareLogic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.PropositionalLogic.Syntax. 3 | Require Import Logic.SeparationLogic.Syntax. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 6 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 7 | Require Import Logic.HoareLogic.ImperativeLanguage. 8 | Require Import Logic.HoareLogic.ProgramState. 9 | Require Import Logic.HoareLogic.BigStepSemantics. 10 | 11 | (***************************************) 12 | (* Type Classes *) 13 | (***************************************) 14 | 15 | Class HoareTriple (L: Language) (P: ProgrammingLanguage) (HLan: Language): Type := { 16 | Assertion := @expr L; 17 | triple: Assertion -> cmd -> Assertion -> @expr HLan 18 | }. 19 | 20 | Definition triple_valid {L: Language} {P: ProgrammingLanguage} {HLan: Language} {TI: Semantics HLan unit_MD} (t: @expr HLan): Prop := @satisfies _ _ TI tt t. 21 | 22 | Declare Scope hoare_logic. 23 | 24 | Notation "|== x" := (triple_valid x) (at level 71, no associativity) : hoare_logic. 25 | Notation "{{ P }} c {{ Q }}" := (triple P c Q) (at level 80, no associativity) : hoare_logic. 26 | 27 | Local Open Scope hoare_logic. 28 | (* 29 | Class TripleInterpretation_Partial (L: Language) (P: ProgrammingLanguage) (HLan: Language) {HT: HoareTriple L P HLan} (MD: Model) (BSS: BigStepSemantics P model) (SM: Semantics L MD) (TI: Semantics HLan unit_MD) : Type := { 30 | partial_valid_spec: forall (P: Assertion) (c: cmd) (Q: Assertion), 31 | (|== {{ P }} c {{ Q }}) <-> 32 | triple_partial_valid P c Q 33 | }. 34 | 35 | Class TripleInterpretation_Total (L: Language) (P: ProgrammingLanguage) (HLan: Language) {HT: HoareTriple L P HLan} (MD: Model) (BSS: BigStepSemantics P model) (SM: Semantics L MD) (TI: Semantics HLan unit_MD) : Type := { 36 | total_valid_spec: forall (P: Assertion) (c: cmd) (Q: Assertion), 37 | (|== {{ P }} c {{ Q }}) <-> 38 | triple_total_valid P c Q 39 | }. 40 | *) 41 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This library contains three parts: logics, a logic generator and Hoare logics. 2 | 3 | ============================================ 4 | 5 | Logics. 6 | 7 | You can find basic logic settings, propositional logics and separation logics 8 | in the following folders: 9 | GeneralLogic 10 | MinimumLogic 11 | PropositionalLogic 12 | SeparationLogic 13 | You can find formalized proof theories, semantic definitions, soundness 14 | proofs and completeness proofs. The library is built-up in an extensible 15 | style, using Coq's typeclasses and higher-order features. But at the same 16 | time, we also provide several concrete examples, containing both shallow 17 | embeddings and deep embeddings. 18 | 19 | ============================================ 20 | 21 | Logic Generator. 22 | 23 | The folder "LogicGenerator" contains our development about this 24 | generator. It requires users to provide a configuration file. Then a command 25 | line can be used to generate an interface file: 26 | ./logic_gen CONFIGURATION_FILE INTERFACE_FILE 27 | The configuration file should specify involved connectives and primary proof 28 | rules. The interface file will contain a Module Type (where these connectives 29 | and proof rules are specified) and a Module functor which generate many many 30 | derived rules from primary ones. See LogicGenerator/demo for more information. 31 | 32 | ============================================ 33 | 34 | Hoare Logics. 35 | 36 | This part is not quite complete. It contains some elementary results about Hoare 37 | logic soundness, especially those about concurrent separation logic. 38 | 39 | ============================================ 40 | 41 | Dependency: Coq 8.10 42 | 43 | ============================================ 44 | 45 | How to install. 46 | 47 | Run "make" or "make -j7" for parallel in your command line. A CONFIGURE file 48 | may be needed for setting up COQBIN. 49 | 50 | ============================================ 51 | 52 | Open Source. 53 | 54 | This library is NOT open sourced for now. 55 | 56 | -------------------------------------------------------------------------------- /PropositionalLogic/Semantics/Trivial.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.MinimumLogic.Syntax. 3 | Require Import Logic.MinimumLogic.Semantics.Trivial. 4 | Require Import Logic.PropositionalLogic.Syntax. 5 | 6 | Local Open Scope logic_base. 7 | Local Open Scope syntax. 8 | Import PropositionalLanguageNotation. 9 | 10 | Module Semantics. 11 | 12 | Definition andp {model: Type} (X: Ensemble model) (Y: Ensemble model): Ensemble model := 13 | fun m => X m /\ Y m. 14 | 15 | Definition orp {model: Type} (X: Ensemble model) (Y: Ensemble model): Ensemble model := 16 | fun m => X m \/ Y m. 17 | 18 | Definition falsep {model: Type}: Ensemble model := fun m => False. 19 | 20 | End Semantics. 21 | 22 | Class TrivialPropositionalSemantics (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} (MD: Model) (SM: Semantics L MD): Type := { 23 | denote_andp: forall x y, Same_set _ (denotation (x && y)) (Semantics.andp (denotation x) (denotation y)); 24 | denote_orp: forall x y, Same_set _ (denotation (x || y)) (Semantics.orp (denotation x) (denotation y)); 25 | denote_falsep: Same_set _ (denotation FF) Semantics.falsep 26 | }. 27 | 28 | Section Trivial. 29 | 30 | Context {L: Language} 31 | {minL: MinimumLanguage L} 32 | {pL: PropositionalLanguage L} 33 | {MD: Model} 34 | {SM: Semantics L MD} 35 | {tpSM: TrivialPropositionalSemantics L MD SM}. 36 | 37 | Lemma sat_andp: forall m x y, m |= x && y <-> (m |= x /\ m |= y). 38 | Proof. 39 | intros; simpl. 40 | unfold satisfies. 41 | destruct (denote_andp x y). 42 | split; auto; [apply H | apply H0]. 43 | Qed. 44 | 45 | Lemma sat_orp: forall m x y, m |= x || y <-> (m |= x \/ m |= y). 46 | Proof. 47 | intros; simpl. 48 | unfold satisfies. 49 | destruct (denote_orp x y). 50 | split; auto; [apply H | apply H0]. 51 | Qed. 52 | 53 | Lemma sat_falsep: forall m, m |= FF <-> False. 54 | Proof. 55 | intros; simpl. 56 | unfold satisfies. 57 | destruct denote_falsep. 58 | split; auto; [apply H | apply H0]. 59 | Qed. 60 | 61 | End Trivial. 62 | -------------------------------------------------------------------------------- /lib/Stream/StreamSplit.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.omega.Omega. 2 | Require Import Coq.Lists.List. 3 | Require Import Coq.Arith.Wf_nat. 4 | Require Import Logic.lib.Coqlib. 5 | Require Import Logic.lib.Stream.SigStream. 6 | Require Import Logic.lib.Stream.SigStream. 7 | Require Import Logic.lib.Stream.StreamFunctions. 8 | 9 | Lemma cut2_exists {A: Type}: forall (h: stream A) (P: A -> Prop), 10 | (exists h1 h2, 11 | is_fin_stream h1 /\ 12 | h = stream_app h1 h2 /\ 13 | (forall n a, h1 n = Some a -> ~ P a) /\ 14 | (exists a, h2 0 = Some a /\ P a)) \/ 15 | (forall n a, h n = Some a -> ~ P a). 16 | Proof. 17 | intros. 18 | destruct (classic (exists n a, h n = Some a /\ P a)). 19 | + left. 20 | apply (dec_inh_nat_subset_has_unique_least_element 21 | _ (fun n => classic _)) in H. 22 | destruct H as [n [[? ?] _]]. 23 | destruct H as [a [? ?]]. 24 | exists (fstn_stream n h), (skipn_stream n h). 25 | split; [| split; [| split]]. 26 | - apply fstn_stream_is_fin_stream. 27 | - symmetry; apply stream_app_fstn_skipn. 28 | - clear H H1 a. 29 | intros; intro. 30 | destruct (lt_dec n0 n); 31 | [| rewrite fstn_stream_None in H by omega; congruence]. 32 | rewrite fstn_stream_Some in H by auto. 33 | specialize (H0 n0 (ex_intro _ a (conj H H1))). 34 | omega. 35 | - exists a; split; auto. 36 | + right. 37 | firstorder. 38 | Qed. 39 | 40 | Lemma cut_omega_exists {A: Type}: forall (h: stream A) (P: A -> Prop), 41 | (exists a, h 0 = Some a /\ P a) -> 42 | (exists hs, 43 | (forall n, is_fin_stream (hs n)) /\ 44 | h = stream_capp hs /\ 45 | (forall m n a, hs m (S n) = Some a -> ~ P a) /\ 46 | (forall n, exists a, hs n 0 = Some a /\ P a)) \/ 47 | (exists hs: list (stream A), 48 | (Forall is_fin_stream hs) /\ 49 | h = fold_right stream_app empty_stream hs /\ 50 | (Forall (fun h0: stream A => forall n a, h0 (S n) = Some a -> ~ P a) hs) /\ 51 | (Forall (fun h0: stream A => exists a, h0 0 = Some a /\ P a) hs)). 52 | Proof. 53 | intros. 54 | Abort. 55 | 56 | 57 | -------------------------------------------------------------------------------- /GeneralLogic/Complete/ContextProperty_Trivial.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Coqlib. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 5 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 6 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 7 | 8 | Local Open Scope logic_base. 9 | 10 | Section ContextProperty. 11 | 12 | Context {L: Language} 13 | {Gamma: Derivable L} 14 | {bSC: BasicSequentCalculus L Gamma}. 15 | 16 | Lemma maximal_consistent_spec : 17 | forall Phi, maximal consistent Phi <-> consistent Phi /\ forall x, consistent (Union _ Phi (Singleton _ x)) -> Phi x. 18 | Proof. 19 | intros. 20 | split; intros [? ?]; split; auto. 21 | + intros. 22 | specialize (H0 _ H1). 23 | specialize (H0 (fun x H => Union_introl _ _ _ _ H)). 24 | specialize (H0 x). 25 | apply H0; right; constructor. 26 | + intros. 27 | hnf; intros. 28 | apply H0. 29 | unfold consistent in*. 30 | destruct H1 as [y ?]. 31 | exists y. 32 | intro; apply H1. 33 | eapply deduction_weaken; [| exact H4]. 34 | intros ? [? | ?]; auto. 35 | destruct H5; auto. 36 | Qed. 37 | 38 | Lemma maximal_consistent_derivable_closed: 39 | forall (Phi: context), 40 | maximal consistent Phi -> 41 | derivable_closed Phi. 42 | Proof. 43 | intros. 44 | hnf; intros. 45 | assert (consistent (Union _ Phi (Singleton _ x))). 46 | { 47 | destruct H as [[y ?] _]. 48 | exists y. 49 | intro. 50 | pose proof deduction_subst1 _ _ _ H0 H1. 51 | auto. 52 | } 53 | destruct H. 54 | specialize (H2 _ H1). 55 | specialize (H2 (fun x H => Union_introl _ _ _ x H)). 56 | apply H2. 57 | right; constructor. 58 | Qed. 59 | 60 | Lemma MCS_element_derivable: 61 | forall(Phi: context), 62 | maximal consistent Phi -> 63 | (forall x: expr, Phi x <-> Phi |-- x). 64 | Proof. 65 | intros. 66 | apply derivable_closed_element_derivable, maximal_consistent_derivable_closed. 67 | auto. 68 | Qed. 69 | 70 | End ContextProperty. 71 | -------------------------------------------------------------------------------- /MinimumLogic/ProofTheory/TheoryOfSequentCalculus.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.Morphisms. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Logic.lib.Ensembles_ext. 4 | Require Import Logic.GeneralLogic.Base. 5 | Require Import Logic.GeneralLogic.ProofTheory.TheoryOfSequentCalculus. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | 8 | Local Open Scope logic_base. 9 | Local Open Scope syntax. 10 | 11 | Section PropertiesOfSequentCalculus. 12 | 13 | Context (L: Language) 14 | (Gamma: Derivable L) 15 | {minL: MinimumLanguage L}. 16 | 17 | Definition DeductionMP: Prop := 18 | forall (Phi: context) (x y: expr), Phi |-- x -> Phi |-- x --> y -> Phi |-- y. 19 | 20 | Definition DeductionImpIntro: Prop := 21 | forall (Phi: context) (x y: expr), Phi;; x |-- y -> Phi |-- x --> y. 22 | 23 | Definition DeductionImpElim: Prop := 24 | forall (Phi: context) (x y: expr), Phi |-- x --> y -> Phi;; x |-- y. 25 | 26 | End PropertiesOfSequentCalculus. 27 | 28 | Section TheoryOfSequentCalculus. 29 | 30 | Context {L: Language} 31 | {Gamma: Derivable L} 32 | {minL: MinimumLanguage L}. 33 | 34 | Lemma DeductionMP_DerivableAssu_DeductionWeaken_2_DeductionImpElim: 35 | DeductionMP L Gamma -> 36 | DerivableAssu L Gamma -> 37 | DeductionWeaken L Gamma -> 38 | DeductionImpElim L Gamma. 39 | Proof. 40 | intros. 41 | intros ? ? ? ?. 42 | eapply H. 43 | + apply H0. 44 | right. 45 | constructor. 46 | + eapply H1; [| exact H2]. 47 | intros ? ?. 48 | left. 49 | auto. 50 | Qed. 51 | 52 | Lemma DeductionImpIntro_DeductionMP_2_DeductionSubst1: 53 | DeductionImpIntro L Gamma -> 54 | DeductionMP L Gamma -> 55 | DeductionSubst1 L Gamma. 56 | Proof. 57 | intros. 58 | intros ? ? ? ? ?. 59 | apply H in H2. 60 | revert H1 H2; apply H0. 61 | Qed. 62 | 63 | Lemma DeductionImpElim_DeductionSubst1_2_DeductionMP: 64 | DeductionImpElim L Gamma -> 65 | DeductionSubst1 L Gamma -> 66 | DeductionMP L Gamma. 67 | Proof. 68 | intros. 69 | intros ? ? ? ? ?. 70 | apply H in H2. 71 | revert H1 H2; apply H0. 72 | Qed. 73 | 74 | End TheoryOfSequentCalculus. 75 | -------------------------------------------------------------------------------- /MinimumLogic/Sound/Sound_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Logic.Classical_Pred_Type. 3 | Require Import Coq.Classes.RelationClasses. 4 | Require Import Coq.Relations.Relation_Definitions. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | Require Import Logic.GeneralLogic.Semantics.Kripke. 8 | Require Import Logic.MinimumLogic.Syntax. 9 | Require Import Logic.MinimumLogic.Semantics.Kripke. 10 | 11 | Local Open Scope logic_base. 12 | Local Open Scope syntax. 13 | Local Open Scope kripke_model. 14 | Import KripkeModelFamilyNotation. 15 | Import KripkeModelNotation_Intuitionistic. 16 | 17 | Section Sound_Kripke. 18 | 19 | Context {L: Language} 20 | {minL: MinimumLanguage L} 21 | {MD: Model} 22 | {kMD: KripkeModel MD} 23 | {M: Kmodel} 24 | {R: Relation (Kworlds M)} 25 | {po_R: PreOrder Krelation} 26 | {SM: Semantics L MD} 27 | {kiSM: KripkeIntuitionisticSemantics L MD M SM} 28 | {kminSM: KripkeMinimumSemantics L MD M SM}. 29 | 30 | Lemma sound_modus_ponens: 31 | forall x y: expr, 32 | forall m, 33 | KRIPKE: M, m |= (x --> y) -> KRIPKE: M, m |= x -> KRIPKE: M, m |= y. 34 | Proof. 35 | intros. 36 | rewrite sat_impp in H. 37 | specialize (H m). 38 | apply H; auto. 39 | reflexivity. 40 | Qed. 41 | 42 | Lemma sound_axiom1: 43 | forall x y: expr, 44 | forall m, 45 | KRIPKE: M, m |= x --> y --> x. 46 | Proof. 47 | intros. 48 | rewrite sat_impp; intros. 49 | rewrite sat_impp; intros. 50 | eapply sat_mono; eauto. 51 | Qed. 52 | 53 | Lemma sound_axiom2: 54 | forall x y z: expr, 55 | forall m, 56 | KRIPKE: M, m |= (x --> y --> z) --> (x --> y) --> (x --> z). 57 | Proof. 58 | intros. 59 | rewrite sat_impp; intros. 60 | rewrite sat_impp; intros. 61 | rewrite sat_impp; intros. 62 | assert (n <= n1) by (etransitivity; eauto). 63 | 64 | rewrite sat_impp in H0. 65 | specialize (H0 n1 H5 H4). 66 | rewrite sat_impp in H2. 67 | specialize (H2 n1 H3 H4). 68 | 69 | rewrite sat_impp in H0. 70 | specialize (H0 n1 ltac:(reflexivity) H2). 71 | auto. 72 | Qed. 73 | 74 | End Sound_Kripke. 75 | -------------------------------------------------------------------------------- /lib/EnsemblesProperties.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Sets.Ensembles. 2 | Require Import Coq.Classes.Morphisms. 3 | Require Import Coq.Lists.List. 4 | Require Import Logic.lib.Ensembles_ext. 5 | 6 | Section Properties. 7 | 8 | Context {A: Type}. 9 | 10 | Definition finite_captured (P: Ensemble A -> Prop): Prop := 11 | forall (Phi: Ensemble A), 12 | (forall xs: list A, Forall Phi xs -> P (fun x => In x xs)) -> 13 | P Phi. 14 | 15 | Definition finite_witnessed (P: Ensemble A -> Prop): Prop := 16 | forall (Phi: Ensemble A), P Phi -> 17 | exists xs: list A, Forall Phi xs /\ P (fun x => In x xs). 18 | 19 | Definition subset_preserved (P: Ensemble A -> Prop): Prop := 20 | forall (Phi Psi: Ensemble A), 21 | Included _ Phi Psi -> P Psi -> P Phi. 22 | 23 | Definition superset_preserved (P: Ensemble A -> Prop): Prop := 24 | forall (Phi Psi: Ensemble A), 25 | Included _ Phi Psi -> P Phi -> P Psi. 26 | 27 | Lemma not_finite_witnessed_finite_captured: forall P, 28 | finite_witnessed P -> 29 | finite_captured (fun X => ~ P X). 30 | Proof. 31 | intros. 32 | hnf in H |- *. 33 | intros. 34 | intro. 35 | specialize (H Phi H1). 36 | firstorder. 37 | Qed. 38 | 39 | Lemma not_superset_preserved_subset_preserved: forall P, 40 | superset_preserved P -> 41 | subset_preserved (fun X => ~ P X). 42 | Proof. 43 | intros. 44 | hnf in H |- *. 45 | firstorder. 46 | Qed. 47 | 48 | Lemma superset_preserved_same_set_preserved: forall P, 49 | superset_preserved P -> 50 | Proper (Same_set _ ==> iff) P. 51 | Proof. 52 | intros. 53 | hnf; intros. 54 | rewrite Same_set_spec in H0. 55 | split; apply H. 56 | + unfold Included, Ensembles.In. 57 | hnf in H0. 58 | firstorder. 59 | + unfold Included, Ensembles.In. 60 | hnf in H0. 61 | firstorder. 62 | Qed. 63 | 64 | Lemma subset_preserved_same_set_preserved: forall P, 65 | subset_preserved P -> 66 | Proper (Same_set _ ==> iff) P. 67 | Proof. 68 | intros. 69 | hnf; intros. 70 | rewrite Same_set_spec in H0. 71 | split; apply H. 72 | + unfold Included, Ensembles.In. 73 | hnf in H0. 74 | firstorder. 75 | + unfold Included, Ensembles.In. 76 | hnf in H0. 77 | firstorder. 78 | Qed. 79 | 80 | End Properties. 81 | -------------------------------------------------------------------------------- /MinimumLogic/Semantics/Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.RelationClasses. 2 | Require Import Coq.Relations.Relation_Definitions. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.GeneralLogic.Semantics.Kripke. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | 8 | Local Open Scope logic_base. 9 | Local Open Scope syntax. 10 | Local Open Scope kripke_model. 11 | Import KripkeModelFamilyNotation. 12 | Import KripkeModelNotation_Intuitionistic. 13 | 14 | Module Semantics. 15 | 16 | Definition impp {worlds: Type} {R: Relation worlds} (X: Ensemble worlds) (Y: Ensemble worlds): Ensemble worlds := 17 | fun m => forall n, m <= n -> X n -> Y n. 18 | 19 | Lemma impp_closed {worlds: Type} {R: Relation worlds} {po_R: PreOrder Krelation}: 20 | forall (X: Ensemble worlds) (Y: Ensemble worlds), 21 | upwards_closed_Kdenote X -> 22 | upwards_closed_Kdenote Y -> 23 | upwards_closed_Kdenote (impp X Y). 24 | Proof. 25 | intros. 26 | hnf; intros. 27 | hnf in H2 |- *. 28 | intros ? ?; apply H2. 29 | etransitivity; eauto. 30 | Qed. 31 | 32 | End Semantics. 33 | 34 | Module SemanticsMono. 35 | 36 | Program Definition impp {worlds: Type} {R: Relation worlds} {po_R: PreOrder Krelation} (X Y: MonoEnsemble worlds): MonoEnsemble worlds := 37 | Semantics.impp X Y. 38 | Next Obligation. 39 | apply (@Semantics.impp_closed worlds R po_R); 40 | apply (proj2_sig _). 41 | Defined. 42 | 43 | End SemanticsMono. 44 | 45 | Class KripkeMinimumSemantics (L: Language) {minL: MinimumLanguage L} (MD: Model) {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} (SM: Semantics L MD) : Type := { 46 | denote_impp: forall x y, Same_set _ (Kdenotation M (x --> y)) (Semantics.impp (Kdenotation M x) (Kdenotation M y)) 47 | }. 48 | 49 | Lemma sat_impp {L: Language} {minL: MinimumLanguage L} {MD: Model} {kMD: KripkeModel MD} {M: Kmodel} {R: Relation (Kworlds M)} {SM: Semantics L MD} {kminSM: KripkeMinimumSemantics L MD M SM}: forall m x y, KRIPKE: M , m |= x --> y <-> (forall n, m <= n -> KRIPKE: M , n |= x -> KRIPKE: M , n |= y). 50 | Proof. 51 | intros; simpl. 52 | unfold satisfies. 53 | destruct (denote_impp x y). 54 | split; [apply H | apply H0]. 55 | Qed. 56 | 57 | -------------------------------------------------------------------------------- /unused_files/Wf.v: -------------------------------------------------------------------------------- 1 | (************************************************************************) 2 | (* v * The Coq Proof Assistant / The Coq Development Team *) 3 | (* A -> Prop. 27 | 28 | Hypothesis Rwf : well_founded R. 29 | 30 | Section FixPoint. 31 | 32 | Variable P : A -> Type. 33 | Variable F : forall x:A, (forall y:A, R y x -> P y) -> P x. 34 | 35 | (** Proof that [well_founded_induction] satisfies the fixpoint equation. 36 | It requires an extra property of the functional *) 37 | 38 | Variable EQ : forall a, P a -> P a -> Prop. 39 | Variable Equiv: forall a: A, Equivalence (@EQ a). 40 | 41 | Hypothesis 42 | F_ext : 43 | forall (x:A) (f g:forall y:A, R y x -> P y), 44 | (forall (y:A) (p:R y x), EQ (f y p) (g y p)) -> EQ (F f) (F g). 45 | 46 | Lemma Fix_F_inv : forall (x:A) (r s:Acc R x), EQ (Fix_F P F r) (Fix_F P F s). 47 | Proof. 48 | intro x; induction (Rwf x); intros. 49 | rewrite <- (Fix_F_eq P F r); rewrite <- (Fix_F_eq P F s); intros. 50 | apply F_ext; auto. 51 | Qed. 52 | 53 | Lemma Fix_eq : forall x:A, EQ (Fix Rwf P F x) (F (fun (y:A) (p:R y x) => Fix Rwf P F y)). 54 | Proof. 55 | intro x; unfold Fix. 56 | rewrite <- Fix_F_eq. 57 | apply F_ext; intros. 58 | apply Fix_F_inv. 59 | Qed. 60 | 61 | End FixPoint. 62 | 63 | End Well_founded. 64 | -------------------------------------------------------------------------------- /PropositionalLogic/Sound/Sound_Classical_Trivial.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Ensembles_ext. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.MinimumLogic.Semantics.Trivial. 6 | Require Import Logic.PropositionalLogic.Syntax. 7 | Require Import Logic.PropositionalLogic.Semantics.Trivial. 8 | 9 | Local Open Scope logic_base. 10 | Local Open Scope syntax. 11 | Import PropositionalLanguageNotation. 12 | 13 | Section Sound. 14 | 15 | Context {L: Language} 16 | {minL: MinimumLanguage L} 17 | {pL: PropositionalLanguage L} 18 | {MD: Model} 19 | {SM: Semantics L MD} 20 | {tminSM: TrivialMinimumSemantics L MD SM} 21 | {tpSM: TrivialPropositionalSemantics L MD SM}. 22 | 23 | Lemma sound_andp_intros: 24 | forall x y m, 25 | m |= x --> y --> x && y. 26 | Proof. 27 | intros. 28 | rewrite !sat_impp, sat_andp. 29 | simpl; intros ? ?. 30 | auto. 31 | Qed. 32 | 33 | Lemma sound_andp_elim1: 34 | forall x y m, 35 | m |= x && y --> x. 36 | Proof. 37 | intros. 38 | rewrite !sat_impp, sat_andp. 39 | intros [? ?]. 40 | auto. 41 | Qed. 42 | 43 | Lemma sound_andp_elim2: 44 | forall x y m, 45 | m |= x && y --> y. 46 | Proof. 47 | intros. 48 | rewrite !sat_impp, sat_andp. 49 | intros [? ?]. 50 | auto. 51 | Qed. 52 | 53 | Lemma sound_orp_intros1: 54 | forall x y m, 55 | m |= x --> x || y. 56 | Proof. 57 | intros. 58 | rewrite !sat_impp, sat_orp. 59 | auto. 60 | Qed. 61 | 62 | Lemma sound_orp_intros2: 63 | forall x y m, 64 | m |= y --> x || y. 65 | Proof. 66 | intros. 67 | rewrite !sat_impp, sat_orp. 68 | auto. 69 | Qed. 70 | 71 | Lemma sound_orp_elim: 72 | forall x y z m, 73 | m |= (x --> z) --> (y --> z) --> (x || y --> z). 74 | Proof. 75 | intros. 76 | rewrite !sat_impp, sat_orp. 77 | tauto. 78 | Qed. 79 | 80 | Lemma sound_falsep_elim: 81 | forall x m, 82 | m |= FF --> x. 83 | Proof. 84 | intros. 85 | rewrite sat_impp, sat_falsep. 86 | intros []. 87 | Qed. 88 | 89 | Lemma sound_excluded_middle: 90 | forall x m, 91 | m |= x || (x --> FF). 92 | Proof. 93 | intros. 94 | rewrite sat_orp, sat_impp, sat_falsep. 95 | tauto. 96 | Qed. 97 | 98 | End Sound. 99 | -------------------------------------------------------------------------------- /SeparationLogic/Syntax.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | 3 | Class SepconLanguage (L: Language): Type := { 4 | sepcon : expr -> expr -> expr 5 | }. 6 | 7 | Class WandLanguage (L: Language): Type := { 8 | wand : expr -> expr -> expr 9 | }. 10 | 11 | Class EmpLanguage (L: Language): Type := { 12 | emp: expr 13 | }. 14 | 15 | Module SeparationLogicNotation. 16 | 17 | Notation "x * y" := (sepcon x y) (at level 40, left associativity) : syntax. 18 | Notation "x -* y" := (wand x y) (at level 55, right associativity) : syntax. 19 | 20 | End SeparationLogicNotation. 21 | 22 | Class IterSepconLanguage (L: Language): Type := { 23 | iter_sepcon : list expr -> expr 24 | }. 25 | 26 | Class IterWandLanguage (L: Language): Type := { 27 | iter_wand : list expr -> expr -> expr 28 | }. 29 | 30 | Class NormalIterSepcon 31 | (L: Language) 32 | {sepconL: SepconLanguage L} 33 | {empL: EmpLanguage L} 34 | {iter_sepcon_L: IterSepconLanguage L}: Prop := { 35 | iter_sepcon_def: forall xs, 36 | iter_sepcon xs = fold_left sepcon xs emp 37 | }. 38 | 39 | Class NormalIterWand 40 | (L: Language) 41 | {wandL: WandLanguage L} 42 | {iter_wand_L: IterWandLanguage L}: Prop := { 43 | iter_wand_def: forall xs y, 44 | iter_wand xs y = fold_right wand y xs 45 | }. 46 | 47 | Definition Sepcon2IterSepcon 48 | {L: Language} 49 | {sepconL: SepconLanguage L} 50 | {empL: EmpLanguage L}: IterSepconLanguage L := 51 | Build_IterSepconLanguage L (fun xs => fold_left sepcon xs emp). 52 | 53 | Definition Wand2IterWand 54 | {L: Language} 55 | {wandL: WandLanguage L}: IterWandLanguage L := 56 | Build_IterWandLanguage L (fun xs y => fold_right wand y xs). 57 | 58 | Lemma Sepcon2IterSepcon_Normal 59 | {L: Language} 60 | {sepconL: SepconLanguage L} 61 | {empL: EmpLanguage L}: 62 | @NormalIterSepcon L _ _ Sepcon2IterSepcon. 63 | Proof. 64 | intros. 65 | constructor. 66 | intros; reflexivity. 67 | Qed. 68 | 69 | Lemma Wand2IterWand_Normal 70 | {L: Language} 71 | {wandL: WandLanguage L}: 72 | @NormalIterWand L _ Wand2IterWand. 73 | Proof. 74 | intros. 75 | constructor. 76 | intros; reflexivity. 77 | Qed. 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /PropositionalLogic/ProofTheory/DeMorgan.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 5 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 6 | Require Import Logic.MinimumLogic.ProofTheory.ExtensionTactic. 7 | Require Import Logic.PropositionalLogic.Syntax. 8 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 9 | 10 | Local Open Scope logic_base. 11 | Local Open Scope syntax. 12 | Import PropositionalLanguageNotation. 13 | 14 | Class DeMorganPropositionalLogic (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} (Gamma: Provable L) {minAX: MinimumAxiomatization L Gamma} {ipAX: IntuitionisticPropositionalLogic L Gamma} := { 15 | weak_excluded_middle: forall x, |-- ~~ x || ~~ ~~ x 16 | }. 17 | 18 | Section DeMorgan. 19 | 20 | Context {L: Language} 21 | {minL: MinimumLanguage L} 22 | {pL: PropositionalLanguage L} 23 | {Gamma: Provable L} 24 | {minAX: MinimumAxiomatization L Gamma} 25 | {ipAX: IntuitionisticPropositionalLogic L Gamma} 26 | {dmpAX: DeMorganPropositionalLogic L Gamma}. 27 | 28 | Lemma demorgan_negp_andp: forall (x y: expr), 29 | |-- ~~ (x && y) <--> (~~ x || ~~ y). 30 | Proof. 31 | AddSequentCalculus. 32 | intros. 33 | rewrite provable_derivable. 34 | apply deduction_andp_intros; [| rewrite <- provable_derivable; apply demorgan_orp_negp]. 35 | rewrite <- deduction_theorem. 36 | apply (deduction_modus_ponens _ (~~ x || ~~ ~~ x)); [apply deduction_weaken0, weak_excluded_middle |]. 37 | apply deduction_orp_elim'. 38 | + apply deduction_weaken0. 39 | apply orp_intros1. 40 | + rewrite <- deduction_theorem. 41 | apply deduction_orp_intros2. 42 | unfold negp at 4. 43 | rewrite <- deduction_theorem. 44 | apply (deduction_modus_ponens _ (x --> FF)). 45 | - rewrite <- deduction_theorem. 46 | apply (deduction_modus_ponens _ (x && y)). 47 | * apply deduction_andp_intros; [| apply deduction_weaken1]; apply derivable_assum1. 48 | * do 3 apply deduction_weaken1; apply derivable_assum1. 49 | - apply deduction_weaken1; apply derivable_assum1. 50 | Qed. 51 | 52 | End DeMorgan. 53 | -------------------------------------------------------------------------------- /GeneralLogic/Complete/Canonical_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.FunctionalExtensionality. 2 | Require Import Coq.Logic.Classical_Prop. 3 | Require Import Coq.Logic.Classical_Pred_Type. 4 | Require Import Logic.lib.Bijection. 5 | Require Import Logic.lib.Countable. 6 | Require Import Logic.GeneralLogic.Base. 7 | Require Import Logic.GeneralLogic.KripkeModel. 8 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 9 | Require Import Logic.GeneralLogic.Semantics.Kripke. 10 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 11 | 12 | Local Open Scope logic_base. 13 | Local Open Scope kripke_model. 14 | Import KripkeModelFamilyNotation. 15 | Import KripkeModelNotation_Intuitionistic. 16 | 17 | Section Canonical. 18 | 19 | Context {L: Language} 20 | {Gamma: Derivable L} 21 | {bSC: BasicSequentCalculus L Gamma} 22 | {MD: Model} 23 | {kMD: KripkeModel MD} 24 | {M: Kmodel} 25 | {R: Relation (Kworlds M)} 26 | {SM: Semantics L MD}. 27 | 28 | Context (cP: context -> Prop) 29 | (rel: bijection (Kworlds M) (sig cP)). 30 | 31 | Hypothesis H_R: forall m n Phi Psi, rel m Phi -> rel n Psi -> (m <= n <-> Included _ (proj1_sig Phi) (proj1_sig Psi)). 32 | 33 | Lemma denote_monotonic (x: expr): 34 | (forall m Phi, rel m Phi -> (KRIPKE: M, m |= x <-> proj1_sig Phi x)) -> 35 | upwards_closed_Kdenote (Kdenotation M x). 36 | Proof. 37 | intros. 38 | hnf; intros. 39 | change (KRIPKE: M, m |= x). 40 | change (KRIPKE: M, n |= x) in H1. 41 | destruct (im_bij _ _ rel n) as [Phi ?]. 42 | destruct (im_bij _ _ rel m) as [Psi ?]. 43 | erewrite H in H1 |- * by eauto. 44 | eapply H_R in H0; eauto. 45 | apply H0; auto. 46 | Qed. 47 | 48 | Instance po_R: PreOrder (@KI.Krelation _ R). 49 | Proof. 50 | constructor. 51 | + hnf; intros m. 52 | destruct (im_bij _ _ rel m) as [Phi ?]. 53 | apply (H_R _ _ _ _ H H). 54 | hnf; intros; auto. 55 | + hnf; intros m1 m2 m3. 56 | destruct (im_bij _ _ rel m1) as [Phi1 ?]. 57 | destruct (im_bij _ _ rel m2) as [Phi2 ?]. 58 | destruct (im_bij _ _ rel m3) as [Phi3 ?]. 59 | rewrite (H_R _ _ _ _ H H0). 60 | rewrite (H_R _ _ _ _ H0 H1). 61 | rewrite (H_R _ _ _ _ H H1). 62 | clear; unfold Included, Ensembles.In; firstorder. 63 | Qed. 64 | 65 | End Canonical. 66 | -------------------------------------------------------------------------------- /GeneralLogic/Complete/Complete_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.FunctionalExtensionality. 2 | Require Import Coq.Logic.Classical_Prop. 3 | Require Import Coq.Logic.Classical_Pred_Type. 4 | Require Import Logic.lib.Bijection. 5 | Require Import Logic.lib.Countable. 6 | Require Import Logic.GeneralLogic.Base. 7 | Require Import Logic.GeneralLogic.KripkeModel. 8 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 9 | Require Import Logic.GeneralLogic.Complete.Lindenbaum. 10 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 11 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 12 | 13 | Local Open Scope logic_base. 14 | Local Open Scope kripke_model. 15 | Import KripkeModelFamilyNotation. 16 | Import KripkeModelNotation_Intuitionistic. 17 | 18 | Section Completeness. 19 | 20 | Context {L: Language} 21 | {Gamma: Derivable L} 22 | {bSC: BasicSequentCalculus L Gamma} 23 | {MD: Model} 24 | {kMD: KripkeModel MD} 25 | {M: Kmodel} 26 | {R: Relation (Kworlds M)} 27 | {SM: Semantics L MD} 28 | {kMC: Kmodel -> Prop}. 29 | 30 | Context (cP: context -> Prop) 31 | (rel: bijection (Kworlds M) (sig cP)). 32 | 33 | Hypothesis LIN_CD: forall x: expr, Lindenbaum_constructable (cannot_derive x) cP. 34 | Hypothesis TRUTH: forall x: expr, forall m Phi, rel m Phi -> (KRIPKE: M, m |= x <-> proj1_sig Phi x). 35 | Hypothesis CANON: kMC M. 36 | 37 | Lemma general_completeness: strongly_complete Gamma SM (KripkeModelClass _ kMC). 38 | Proof. 39 | intros. 40 | assert (forall Phi x, ~ Phi |-- x -> ~ consequence (KripkeModelClass _ kMC) Phi x). 41 | 2: { 42 | hnf; intros. 43 | apply Classical_Prop.NNPP; intro; revert H0. 44 | apply H; auto. 45 | } 46 | 47 | intros. 48 | destruct (LIN_CD x _ H) as [Psi [? ?]]. 49 | destruct (su_bij _ _ rel Psi) as [n HH]. 50 | specialize (fun x => TRUTH x _ _ HH); clear HH. 51 | assert ((forall x, Phi x -> KRIPKE: M, n |= x) /\ ~ KRIPKE: M, n |= x). 52 | 2: { 53 | intro. 54 | specialize (H3 (KRIPKE: M, n) ltac:(constructor; apply CANON)). 55 | tauto. 56 | } 57 | 58 | split. 59 | + intros. 60 | rewrite TRUTH. 61 | apply H0; auto. 62 | + rewrite TRUTH. 63 | intro; apply H1; clear H1. 64 | apply derivable_assum; auto. 65 | Qed. 66 | 67 | End Completeness. 68 | -------------------------------------------------------------------------------- /SeparationLogic/ProofTheory/SeparationLogicExtension.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Coqlib. 2 | Require Import Logic.GeneralLogic.Base. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.PropositionalLogic.Syntax. 5 | Require Import Logic.SeparationLogic.Syntax. 6 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 7 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 8 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 9 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 10 | Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett. 11 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 12 | Require Import Logic.PropositionalLogic.ProofTheory.RewriteClass. 13 | Require Import Logic.SeparationLogic.ProofTheory.SeparationLogic. 14 | 15 | Local Open Scope logic_base. 16 | Local Open Scope syntax. 17 | Import PropositionalLanguageNotation. 18 | Import SeparationLogicNotation. 19 | 20 | Class SeparationLogic_Precise 21 | (L: Language) 22 | {minL: MinimumLanguage L} 23 | {pL: PropositionalLanguage L} 24 | {sepconL: SepconLanguage L} 25 | (Gamma: Provable L) := { 26 | precise: expr -> Prop; 27 | precise_sepcon: forall x y, precise x -> precise y -> precise (x * y) 28 | }. 29 | 30 | (* 31 | This rule is not sound for garbage collect SL 32 | precise_impp: forall x y, |-- x --> y -> precise y -> precise x 33 | 34 | The following is not sound e.g. when x := a = 0 && emp, y := a = 1, z := a = 0 35 | sepcon_cancel: forall x y z, |-- (x * z) --> (y * z) -> precise z -> |-- (x --> y) 36 | *) 37 | 38 | Class SeparationLogic_PureFact 39 | (L: Language) 40 | {minL: MinimumLanguage L} 41 | {pL: PropositionalLanguage L} 42 | {sepconL: SepconLanguage L} 43 | {wandL: WandLanguage L} 44 | (Gamma: Provable L) := { 45 | pure_fact: expr -> Prop; 46 | pure_falsep: pure_fact FF; 47 | pure_andp: forall x y, pure_fact x -> pure_fact y -> pure_fact (x && y); 48 | pure_orp: forall x y, pure_fact x -> pure_fact y -> pure_fact (x || y); 49 | pure_impp: forall x y, pure_fact x -> pure_fact y -> pure_fact (x --> y); 50 | pure_specon: forall x y, pure_fact x -> pure_fact y -> pure_fact (x * y); 51 | pure_wand: forall x y, pure_fact x -> pure_fact y -> pure_fact (x -* y); 52 | andp_sepcon: forall x y z, pure_fact x -> |-- (x && (y * z)) <--> ((x && y) * z) 53 | }. 54 | 55 | -------------------------------------------------------------------------------- /SeparationLogic/ProofTheory/WandFrame.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Coqlib. 2 | Require Import Logic.GeneralLogic.Base. 3 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 6 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 7 | Require Import Logic.PropositionalLogic.Syntax. 8 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 9 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 10 | Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett. 11 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 12 | Require Import Logic.PropositionalLogic.ProofTheory.RewriteClass. 13 | Require Import Logic.SeparationLogic.Syntax. 14 | Require Import Logic.SeparationLogic.ProofTheory.SeparationLogic. 15 | Require Import Logic.SeparationLogic.ProofTheory.RewriteClass. 16 | 17 | Local Open Scope logic_base. 18 | Local Open Scope syntax. 19 | Import PropositionalLanguageNotation. 20 | Import SeparationLogicNotation. 21 | 22 | Section WandFrame. 23 | 24 | Context {L: Language} 25 | {minL: MinimumLanguage L} 26 | {sepconL: SepconLanguage L} 27 | {wandL: WandLanguage L} 28 | {Gamma: Provable L} 29 | {minAX: MinimumAxiomatization L Gamma} 30 | {sepconAX: SepconAxiomatization L Gamma} 31 | {wandAX: WandAxiomatization L Gamma}. 32 | 33 | Lemma wand_frame_intros: forall (x y: expr), 34 | |-- x --> (y -* x * y). 35 | Proof. 36 | intros. 37 | apply wand_sepcon_adjoint. 38 | apply provable_impp_refl. 39 | Qed. 40 | 41 | Lemma wand_frame_elim: forall (x y: expr), 42 | |-- x * (x -* y) --> y. 43 | Proof. 44 | intros. 45 | apply provable_wand_sepcon_modus_ponens2. 46 | Qed. 47 | 48 | Lemma wand_frame_ver: forall (x y z: expr), 49 | |-- (x -* y) * (y -* z) --> (x -* z). 50 | Proof. 51 | intros. 52 | rewrite <- wand_sepcon_adjoint. 53 | rewrite sepcon_comm_impp, sepcon_assoc1. 54 | rewrite !wand_frame_elim. 55 | apply provable_impp_refl. 56 | Qed. 57 | 58 | Lemma wand_frame_hor: forall (x1 y1 x2 y2: expr), 59 | |-- (x1 -* y1) * (x2 -* y2) --> (x1 * x2 -* y1 * y2). 60 | Proof. 61 | intros. 62 | rewrite <- wand_sepcon_adjoint. 63 | rewrite sepcon_assoc1, (sepcon_comm_impp _ x1), sepcon_assoc1. 64 | rewrite wand_frame_elim. 65 | rewrite sepcon_assoc2, (sepcon_comm_impp _ x2). 66 | rewrite wand_frame_elim. 67 | apply provable_impp_refl. 68 | Qed. 69 | 70 | End WandFrame. 71 | -------------------------------------------------------------------------------- /ModalLogic/ProofTheory/RewriteClass.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.Morphisms. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 5 | Require Import Logic.MinimumLogic.Syntax. 6 | Require Import Logic.ModalLogic.Syntax. 7 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 8 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 9 | Require Import Logic.PropositionalLogic.Syntax. 10 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 11 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 12 | Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett. 13 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 14 | Require Import Logic.PropositionalLogic.ProofTheory.RewriteClass. 15 | Require Import Logic.ModalLogic.ProofTheory.ModalLogic. 16 | 17 | Local Open Scope logic_base. 18 | Local Open Scope syntax. 19 | Import PropositionalLanguageNotation. 20 | Import ModalLanguageNotation. 21 | 22 | Section RewriteClass. 23 | 24 | Context {L: Language} 25 | {minL: MinimumLanguage L} 26 | {pL: PropositionalLanguage L} 27 | {mL: ModalLanguage L} 28 | {Gamma: Provable L} 29 | {minAX: MinimumAxiomatization L Gamma} 30 | {ipAX: IntuitionisticPropositionalLogic L Gamma} 31 | {KmAX: SystemK L Gamma}. 32 | 33 | Instance boxp_proper_impp: Proper ((fun x y => |-- impp x y) ==> (fun x y => |-- impp x y)) boxp. 34 | Proof. 35 | hnf; intros x y ?. 36 | apply rule_N in H. 37 | eapply modus_ponens; eauto. 38 | apply axiom_K. 39 | Qed. 40 | 41 | Instance boxp_proper_iffp: Proper ((fun x y => |-- iffp x y) ==> (fun x y => |-- iffp x y)) boxp. 42 | Proof. 43 | hnf; intros x y ?. 44 | apply solve_andp_intros; apply boxp_proper_impp. 45 | + eapply solve_andp_elim1; eauto. 46 | + eapply solve_andp_elim2; eauto. 47 | Qed. 48 | 49 | Instance diamondp_proper_impp: Proper ((fun x y => |-- impp x y) ==> (fun x y => |-- impp x y)) diamondp. 50 | Proof. 51 | hnf; intros x y ?. 52 | unfold diamondp. 53 | rewrite H. 54 | apply provable_impp_refl. 55 | Qed. 56 | 57 | Instance diamondp_proper_iffp: Proper ((fun x y => |-- iffp x y) ==> (fun x y => |-- iffp x y)) diamondp. 58 | Proof. 59 | hnf; intros x y ?. 60 | unfold diamondp. 61 | rewrite H. 62 | apply provable_iffp_refl. 63 | Qed. 64 | 65 | End RewriteClass. 66 | 67 | Existing Instances boxp_proper_impp boxp_proper_iffp diamondp_proper_impp diamondp_proper_iffp. 68 | -------------------------------------------------------------------------------- /ModalLogic/ShallowEmbedded/MonoPredicateModalLogic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Ensembles_ext. 2 | Require Import Logic.GeneralLogic.Base. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.PropositionalLogic.Syntax. 5 | Require Import Logic.ModalLogic.Syntax. 6 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 7 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 8 | Require Import Logic.ModalLogic.ProofTheory.ModalLogic. 9 | Require Import Logic.GeneralLogic.KripkeModel. 10 | Require Import Logic.ModalLogic.Model.KripkeModel. 11 | Require Import Logic.ModalLogic.Model.OrderedKripkeModel. 12 | Require Import Logic.ModalLogic.Semantics.Flat. 13 | Require Import Logic.ModalLogic.Sound.Sound_Flat. 14 | Require Import Logic.GeneralLogic.ShallowEmbedded.MonoPredicateAsLang. 15 | Require Import Logic.PropositionalLogic.ShallowEmbedded.MonoPredicatePropositionalLogic. 16 | 17 | Instance MonoPred_mL (A: Type) {R1: KI.Relation A} {po_R1: PreOrder KI.Krelation} {R2: KM.Relation A} {uR2: UpwardsClosedOrderedKripkeModel A} : ModalLanguage (MonoPred_L A) := 18 | Build_ModalLanguage (MonoPred_L A) SemanticsMono.boxp. 19 | 20 | Instance MonoPred_fmSM (A: Type) {R1: KI.Relation A} {po_R1: PreOrder KI.Krelation} {R2: KM.Relation A} {uR2: UpwardsClosedOrderedKripkeModel A} : @FlatModalSemantics (MonoPred_L A) (MonoPred_minL A) (MonoPred_mL A) (Build_Model A) (unit_kMD _) tt R1 R2 (MonoPred_SM A). 21 | Proof. 22 | constructor. 23 | intros; apply Same_set_refl. 24 | Qed. 25 | 26 | Instance MonoPred_KmGamma (A: Type) {R1: KI.Relation A} {po_R1: PreOrder KI.Krelation} {R2: KM.Relation A} {uR2: UpwardsClosedOrderedKripkeModel A}: SystemK (MonoPred_L A) (MonoPred_Gamma A). 27 | Proof. 28 | constructor. 29 | + intros x y. 30 | exact (@sound_axiom_K (MonoPred_L A) _ _ (Build_Model A) (unit_kMD _) tt R1 R2 _ (MonoPred_SM A) (MonoPred_kminSM A) (MonoPred_fmSM A) x y). 31 | + intros x. 32 | exact (@sound_rule_N (MonoPred_L A) _ _ (Build_Model A) (unit_kMD _) tt R1 R2 (MonoPred_SM A) (MonoPred_fmSM A) x). 33 | Qed. 34 | 35 | Instance MonoPred_pmGamma (A: Type) {R1: KI.Relation A} {po_R1: PreOrder KI.Krelation} {R2: KM.Relation A} {uR2: UpwardsClosedOrderedKripkeModel A} {pf_R2: PartialFunctional KM.Krelation}: PropositionalTransparentModality (MonoPred_L A) (MonoPred_Gamma A). 36 | Proof. 37 | constructor. 38 | intros x y. 39 | exact (@sound_boxp_orp (MonoPred_L A) _ _ _ (Build_Model A) (unit_kMD _) tt R1 R2 (MonoPred_SM A) (MonoPred_kminSM A) (MonoPred_kpSM A) (MonoPred_fmSM A) pf_R2 x y). 40 | Qed. 41 | -------------------------------------------------------------------------------- /QuantifierLogic/Syntax.v: -------------------------------------------------------------------------------- 1 | (* 2 | (* Require Import Logic.lib.SublistT.*) 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.PropositionalLogic.Syntax. 6 | 7 | Local Open Scope logic_base. 8 | Local Open Scope syntax. 9 | Import PropositionalLanguageNotation. 10 | 11 | 12 | Class SimpleTypedLambdaCalculus (TC: TermCalculus) : Type := { 13 | arrow_type: type -> type -> type; 14 | term_abs: forall a t_var t_term, term (args_cons t_var a) t_term -> term a (arrow_type t_var t_term); 15 | term_app: forall a t_var t_term, term a (arrow_type t_var t_term) -> term a t_var -> term a t_term; 16 | beta_red: forall a t_var t_term (func: term (args_cons t_var a) t_term) arg, term_app _ _ _ (term_abs _ _ _ func) arg = term_ins _ _ _ func arg 17 | }. 18 | 19 | Class BinderLanguage: Type := { 20 | (* parameter *) 21 | type: Type; 22 | args: Type; 23 | args_cons: type -> args -> args; 24 | binded_L :> list type -> Language; 25 | binded_expr := fun ts => @expr (binded_L ts) 26 | }. 27 | 28 | Arguments binded_expr {_} _. 29 | Arguments ins_expr {_} {_} {_} _ _. 30 | Arguments lift_expr {_} {_} {_} _ _. 31 | 32 | Class QuantifierLanguage (BL: BinderLanguage): Type := { 33 | allp: forall t ts, binded_expr (t :: ts) -> binded_expr ts; 34 | exp: forall t ts, binded_expr (t :: ts) -> binded_expr ts; 35 | lift_allp: forall t ts1 ts2 (g: sublistT ts1 ts2) (x: binded_expr (t :: ts1)), lift_expr g (allp t ts1 x) = allp t ts2 (lift_expr (sublistT_cons_cons t g) x); 36 | lift_exp: forall t ts1 ts2 (g: sublistT ts1 ts2) (x: binded_expr (t :: ts1)), lift_expr g (exp t ts1 x) = exp t ts2 (lift_expr (sublistT_cons_cons t g) x) 37 | }. 38 | 39 | Arguments allp {_} {_} {_} {_} _. 40 | Arguments exp {_} {_} {_} {_} _. 41 | 42 | Class NormalBinderLanguage (BL: BinderLanguage): Type := { 43 | binded_nL:> forall ts, NormalLanguage (binded_L ts); 44 | lift_impp: 45 | forall ts1 ts2 (g: sublistT ts1 ts2) (x y: binded_expr ts1), 46 | lift_expr g (x --> y) = lift_expr g x --> lift_expr g y 47 | }. 48 | 49 | Class PropositionalBinderLanguage (BL: BinderLanguage) {nBL: NormalBinderLanguage BL}: Type := { 50 | binded_pL:> forall ts, PropositionalLanguage (binded_L ts); 51 | lift_andp: 52 | forall ts1 ts2 (g: sublistT ts1 ts2) (x y: binded_expr ts1), 53 | lift_expr g (x && y) = lift_expr g x && lift_expr g y; 54 | lift_orp: 55 | forall ts1 ts2 (g: sublistT ts1 ts2) (x y: binded_expr ts1), 56 | lift_expr g (x || y) = lift_expr g x || lift_expr g y 57 | }. 58 | *) 59 | -------------------------------------------------------------------------------- /lib/Equivalence_ext.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.Morphisms. 2 | Require Import Coq.Lists.List. 3 | Require Export Logic.lib.Relation_ext. 4 | 5 | Instance list_Reflexive {A R} {EqA: @Equivalence A R}: Reflexive (Forall2 (@equiv A _ _)). 6 | Proof. 7 | hnf; intros. 8 | induction x; constructor. 9 | + reflexivity. 10 | + auto. 11 | Qed. 12 | 13 | Instance list_Symmetric {A R} {EqA: @Equivalence A R}: Symmetric (Forall2 (@equiv A _ _)). 14 | Proof. 15 | hnf; intros. 16 | revert y H; induction x; intros; destruct y; try solve [inversion H]; constructor. 17 | + inversion H; subst. symmetry. auto. 18 | + inversion H; subst. apply IHx; auto. 19 | Qed. 20 | 21 | Instance list_Transitive {A R} {EqA: @Equivalence A R}: Transitive (Forall2 (@equiv A _ _)). 22 | Proof. 23 | hnf; intros. 24 | revert y z H H0; induction x; intros; destruct y, z; try solve [inversion H; subst; inversion H0]; constructor. 25 | + inversion H; inversion H0; subst. etransitivity; eauto. 26 | + inversion H; inversion H0; subst. eapply IHx; eauto. 27 | Qed. 28 | 29 | Instance list_Equivalence {A R} {EqA: @Equivalence A R}: Equivalence (Forall2 (@equiv A _ _)). 30 | Proof. 31 | split. 32 | apply list_Reflexive. 33 | apply list_Symmetric. 34 | apply list_Transitive. 35 | Qed. 36 | 37 | (* The Instances-Searching for type classes are type oriented. 38 | As resp_Equivalence is a (Equvalence B), it should not be involved 39 | in Instances-Searching. Or else, searching engine will apply this 40 | Instance, and do never terminate. *) 41 | 42 | Lemma resp_Reflexive {A B} (f: A -> B) (R: relation B) {RR: Reflexive R}: Reflexive (respectful_relation f R). 43 | Proof. 44 | intros. 45 | hnf; intros. 46 | unfold respectful_relation. 47 | reflexivity. 48 | Qed. 49 | 50 | Lemma resp_Symmetric {A B} (f: A -> B) (R: relation B) {SR: Symmetric R}: Symmetric (respectful_relation f R). 51 | Proof. 52 | intros. 53 | hnf; intros. 54 | unfold respectful_relation. 55 | symmetry. 56 | auto. 57 | Qed. 58 | 59 | Lemma resp_Transitive {A B} (f: A -> B) (R: relation B) {TR: Transitive R}: Transitive (respectful_relation f R). 60 | Proof. 61 | intros. 62 | hnf; intros. 63 | unfold respectful_relation. 64 | transitivity (f y); auto. 65 | Qed. 66 | 67 | Lemma resp_Equivalence {A B} (f: A -> B) (R: relation B) {ER: Equivalence R}: Equivalence (respectful_relation f R). 68 | Proof. 69 | destruct ER. 70 | split. 71 | + apply resp_Reflexive; auto. 72 | + apply resp_Symmetric; auto. 73 | + apply resp_Transitive; auto. 74 | Qed. 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /QuantifierLogic/ProofTheory/IntuitionisticDerivedRules.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Coqlib. 2 | Require Import Logic.lib.SublistT. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.PropositionalLogic.Syntax. 6 | Require Import Logic.QuantifierLogic.Syntax. 7 | Require Import Logic.MinimumLogic.ProofTheory.Normal. 8 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 9 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 10 | Require Import Logic.MinimumLogic.ProofTheory.ContextProperty. 11 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 12 | Require Import Logic.PropositionalLogic.ProofTheory.RewriteClass. 13 | Require Import Logic.QuantifierLogic.ProofTheory.QuantifierLogic. 14 | 15 | Local Open Scope logic_base. 16 | Local Open Scope syntax. 17 | Import PropositionalLanguageNotation. 18 | 19 | Lemma allp_K 20 | (BL: BinderLanguage) 21 | {nBL: NormalBinderLanguage BL} 22 | {pBL: PropositionalBinderLanguage BL} 23 | {qL: QuantifierLanguage BL} 24 | (BGamma: BindedProofTheory BL) 25 | {nGamma: forall ts, NormalProofTheory (binded_L ts) (binded_Gamma ts)} 26 | {mpGamma: forall ts, MinimumPropositionalLogic (binded_L ts) (binded_Gamma ts)} 27 | {ipGamma: forall ts, IntuitionisticPropositionalLogic (binded_L ts) (binded_Gamma ts)} 28 | {qGamma: QuantifierLogic BL BGamma}: 29 | forall (t: type) (ts: list type) (x y: binded_expr (t :: ts)), 30 | |-- allp (x --> y) --> (allp x --> allp y). 31 | Proof. 32 | intros. 33 | rewrite provable_derivable. 34 | rewrite <- !deduction_theorem. 35 | eapply deduction_modus_ponens. 36 | + apply deduction_andp_intros. 37 | - apply derivable_assum1. 38 | - apply deduction_weaken1. 39 | apply derivable_assum1. 40 | + apply deduction_weaken0. 41 | eapply allp_gen. 42 | rewrite lift_andp, !lift_allp. 43 | rewrite !(allp_elim _ _ _ var_term). 44 | Abort. 45 | 46 | Lemma allp_intros 47 | (BL: BinderLanguage) 48 | {nL: forall ts, NormalLanguage (binded_L ts)} 49 | {qL: QuantifierLanguage BL} 50 | (BGamma: BindedProofTheory BL) 51 | {nGamma: forall ts, NormalProofTheory (binded_L ts) (binded_Gamma ts)} 52 | {mpGamma: forall ts, MinimumPropositionalLogic (binded_L ts) (binded_Gamma ts)} 53 | {qGamma: QuantifierLogic BL BGamma}: 54 | forall (t: type) (ts: list type) (x: binded_expr ts) (y: binded_expr (t :: ts)), 55 | |-- allp (lift t x --> y) --> (x --> allp y). 56 | Proof. 57 | intros. 58 | Abort. 59 | -------------------------------------------------------------------------------- /LogicGenerator/demo/implementation_3.v: -------------------------------------------------------------------------------- 1 | Require Import ZArith. 2 | Require Import Ensembles. 3 | 4 | Module NaiveLang. 5 | Definition expr := (nat -> Z) -> Prop. 6 | Definition context := expr -> Prop. 7 | Definition impp (e1 e2 : expr) : expr := fun st => e1 st -> e2 st. 8 | Definition andp (e1 e2 : expr) : expr := fun st => e1 st /\ e2 st. 9 | Definition orp (e1 e2 : expr) : expr := fun st => e1 st \/ e2 st. 10 | Definition falsep : expr := fun st => False. 11 | 12 | Definition derivable (Phi: context) (e : expr) : Prop := forall st, (forall e0, Phi e0 -> e0 st) -> e st. 13 | End NaiveLang. 14 | 15 | Require Import interface_3. 16 | 17 | Module NaiveRule. 18 | Import NaiveLang. 19 | Include DerivedNames (NaiveLang). 20 | Axiom deduction_andp_intros : (forall (Phi : context) (x y : expr), derivable Phi x -> derivable Phi y -> derivable Phi (andp x y)) . 21 | Axiom deduction_andp_elim1 : (forall (Phi : context) (x y : expr), derivable Phi (andp x y) -> derivable Phi x) . 22 | Axiom deduction_andp_elim2 : (forall (Phi : context) (x y : expr), derivable Phi (andp x y) -> derivable Phi y) . 23 | Axiom deduction_orp_intros1 : (forall (Phi : context) (x y : expr), derivable Phi x -> derivable Phi (orp x y)) . 24 | Axiom deduction_orp_intros2 : (forall (Phi : context) (x y : expr), derivable Phi y -> derivable Phi (orp x y)) . 25 | Axiom deduction_orp_elim : (forall (Phi : Ensemble expr) (x y z : expr), derivable (Union expr Phi (Singleton expr x)) z -> derivable (Union expr Phi (Singleton expr y)) z -> derivable (Union expr Phi (Singleton expr (orp x y))) z) . 26 | Axiom deduction_falsep_elim : (forall (Phi : context) (x : expr), derivable Phi falsep -> derivable Phi x) . 27 | Axiom deduction_modus_ponens : (forall (Phi : context) (x y : expr), derivable Phi x -> derivable Phi (impp x y) -> derivable Phi y) . 28 | Axiom deduction_impp_intros : (forall (Phi : Ensemble expr) (x y : expr), derivable (Union expr Phi (Singleton expr x)) y -> derivable Phi (impp x y)) . 29 | Axiom deduction_weaken : (forall (Phi Psi : Ensemble expr) (x : expr), Included expr Phi Psi -> derivable Phi x -> derivable Psi x) . 30 | Axiom derivable_assum : (forall (Phi : Ensemble expr) (x : expr), In expr Phi x -> derivable Phi x) . 31 | Axiom deduction_subst : (forall (Phi Psi : context) (y : expr), (forall x : expr, Psi x -> derivable Phi x) -> derivable (Union expr Phi Psi) y -> derivable Phi y) . 32 | End NaiveRule. 33 | 34 | Module T := LogicTheorem NaiveLang NaiveRule. 35 | Module Solver := IPSolver NaiveLang. 36 | Import T. 37 | Import Solver. 38 | 39 | 40 | -------------------------------------------------------------------------------- /MinimumLogic/DeepEmbedded/Soundness.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Ensembles_ext. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.GeneralLogic.Semantics.Kripke. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 8 | Require Import Logic.MinimumLogic.Semantics.Kripke. 9 | Require Logic.MinimumLogic.Sound.Sound_Kripke. 10 | Require Logic.MinimumLogic.DeepEmbedded.MinimumLanguage. 11 | Require Logic.MinimumLogic.DeepEmbedded.MinimumLogic. 12 | Require Logic.MinimumLogic.DeepEmbedded.KripkeSemantics. 13 | 14 | Local Open Scope logic_base. 15 | Local Open Scope syntax. 16 | Local Open Scope kripke_model. 17 | Local Open Scope kripke_model_class. 18 | Import KripkeModelFamilyNotation. 19 | Import KripkeModelNotation_Intuitionistic. 20 | Import KripkeModelClass. 21 | 22 | (* TODO: soundness about trivial semantics is not yet added. *) 23 | 24 | Section Sound. 25 | 26 | Context (Var: Type). 27 | 28 | Instance L: Language := MinimumLanguage.L Var. 29 | Instance minL: MinimumLanguage L := MinimumLanguage.minL Var. 30 | 31 | Instance GP: Provable L := MinimumLogic.GP Var. 32 | Instance GD: Derivable L := MinimumLogic.GD Var. 33 | Instance AX: NormalAxiomatization L GP GD := MinimumLogic.AX Var. 34 | Instance minAX: MinimumAxiomatization L GP := MinimumLogic.minAX Var. 35 | 36 | Instance Kripke_MD: Model := KripkeSemantics.MD Var. 37 | Instance Kripke_kMD: KripkeModel Kripke_MD := KripkeSemantics.kMD Var. 38 | Instance Kripke_R (M: Kmodel): Relation (Kworlds M) := KripkeSemantics.R Var M. 39 | Instance Kripke_SM: Semantics L Kripke_MD := KripkeSemantics.SM Var. 40 | Instance Kripke_kminSM (M: Kmodel): KripkeMinimumSemantics L Kripke_MD M Kripke_SM := KripkeSemantics.kminSM Var M. 41 | 42 | Section Sound_Kripke. 43 | 44 | Import Logic.MinimumLogic.Sound.Sound_Kripke. 45 | Import Logic.MinimumLogic.DeepEmbedded.KripkeSemantics. 46 | 47 | Theorem sound_intuitionistic_Kripke_all: 48 | provable_sound GP Kripke_SM (KripkeModelClass _ (Kmodel_Monotonic + Kmodel_PreOrder)). 49 | Proof. 50 | hnf; intros. 51 | intros _ [M m [mono po_R]]. 52 | pose proof (@KripkeSemantics.kiSM Var M mono po_R) as kiSM. 53 | hnf in mono, po_R. 54 | change (Kmodel Var) in M. 55 | change (Kworlds M) in m. 56 | change (KRIPKE: M, m |= x). 57 | induction H. 58 | + pose proof sound_modus_ponens x y m. 59 | exact (H1 IHprovable1 IHprovable2). 60 | + apply sound_axiom1. 61 | + apply sound_axiom2. 62 | Qed. 63 | 64 | End Sound_Kripke. 65 | 66 | End Sound. 67 | -------------------------------------------------------------------------------- /Extensions/ProofTheory/Stable.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.Morphisms. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.PropositionalLogic.Syntax. 6 | Require Import Logic.ModalLogic.Syntax. 7 | Require Import Logic.SeparationLogic.Syntax. 8 | 9 | Local Open Scope logic_base. 10 | Local Open Scope syntax. 11 | Import PropositionalLanguageNotation. 12 | Import ModalLanguageNotation. 13 | Import SeparationLogicNotation. 14 | 15 | Class PropositionalStable (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} (Gamma: Provable L) (stable: expr -> Prop) := { 16 | impp_stable: forall x y, stable x -> stable y -> stable (x --> y); 17 | andp_stable: forall x y, stable x -> stable y -> stable (x && y); 18 | orp_stable: forall x y, stable x -> stable y -> stable (x || y); 19 | falsep_stable: stable FF; 20 | stable_proper_iffp :> Proper ((fun x y => |-- x <--> y) ==> iff) stable 21 | }. 22 | 23 | Class ModalStable (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} (Gamma: Provable L) (stable: expr -> Prop) := { 24 | boxp_stable: forall x, stable x -> stable (boxp x) 25 | }. 26 | 27 | Class ModalAbsorbStable (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} (Gamma: Provable L) (stable: expr -> Prop) := { 28 | boxp_absorb_stable: forall x, stable x -> |-- x --> boxp x 29 | }. 30 | 31 | Class SeparationStable (L: Language) {minL: MinimumLanguage L} {sepconL: SepconLanguage L} {wandL: WandLanguage L} (Gamma: Provable L) (stable: expr -> Prop) := { 32 | sepcon_stable: forall x y, stable x -> stable y -> stable (x * y); 33 | wand_stable: forall x y, stable x -> stable y -> stable (x -* y) 34 | }. 35 | 36 | Class SeparationAbsorbStable (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {sepconL: SepconLanguage L} {wandL: WandLanguage L} (Gamma: Provable L) (stable: expr -> Prop) := { 37 | stable_andp_sepcon1: forall x y z, stable x -> |-- (x && y) * z <--> x && (y * z) 38 | }. 39 | 40 | Lemma iffp_stable {L: Language} {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {Gamma: Provable L} {stable: expr -> Prop} {pstable: PropositionalStable L Gamma stable}: 41 | forall x y, stable x -> stable y -> stable (x <--> y). 42 | Proof. 43 | intros. 44 | apply andp_stable; apply impp_stable; auto. 45 | Qed. 46 | 47 | Lemma truep_stable {L: Language} {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {Gamma: Provable L} {stable: expr -> Prop} {pstable: PropositionalStable L Gamma stable}: 48 | stable TT. 49 | Proof. 50 | apply impp_stable; apply falsep_stable. 51 | Qed. 52 | 53 | -------------------------------------------------------------------------------- /SeparationLogic/Sound/Sound_DownUp_Fail.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Coqlib. 2 | Require Import Logic.GeneralLogic.Base. 3 | Require Import Logic.GeneralLogic.KripkeModel. 4 | Require Import Logic.GeneralLogic.Semantics.Kripke. 5 | Require Import Logic.MinimumLogic.Syntax. 6 | Require Import Logic.MinimumLogic.Semantics.Kripke. 7 | Require Import Logic.PropositionalLogic.Syntax. 8 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 9 | Require Import Logic.SeparationLogic.Syntax. 10 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 11 | Require Import Logic.SeparationLogic.Model.OrderedSA. 12 | Require Import Logic.SeparationLogic.Semantics.DownUpSemantics_Fail. 13 | 14 | Local Open Scope logic_base. 15 | Local Open Scope syntax. 16 | Local Open Scope kripke_model. 17 | Import PropositionalLanguageNotation. 18 | Import SeparationLogicNotation. 19 | Import KripkeModelFamilyNotation. 20 | Import KripkeModelNotation_Intuitionistic. 21 | 22 | Lemma sound_sepcon_comm {L: Language} {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {sepconL: SepconLanguage L} {wandL: WandLanguage L} {MD: Model} {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} {po_R: PreOrder Krelation} {J: Join (Kworlds M)} {SA: SeparationAlgebra (Kworlds M)} {SM: Semantics L MD} {kiSM: KripkeIntuitionisticSemantics L MD M SM} {kminSM: KripkeMinimumSemantics L MD M SM} {kpSM: KripkePropositionalSemantics L MD M SM} {dusSM: DownUpSemantics_Fail.SeparatingSemantics L MD M SM}: 23 | forall x y: expr, 24 | forall m, 25 | KRIPKE: M, m |= x * y --> y * x. 26 | Proof. 27 | intros. 28 | rewrite sat_impp; intros. 29 | rewrite sat_sepcon in H0 |- *; intros. 30 | destruct H0 as [m0 [m1 [m2 [? [? [? ?]]]]]]. 31 | exists m0, m2, m1. 32 | split; [| split; [| split]]; auto. 33 | apply join_comm; auto. 34 | Qed. 35 | 36 | Lemma sound_sepcon_assoc {L: Language} {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {sepconL: SepconLanguage L} {wandL: WandLanguage L} {MD: Model} {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} {po_R: PreOrder Krelation} {J: Join (Kworlds M)} {SA: SeparationAlgebra (Kworlds M)} {SM: Semantics L MD} {kiSM: KripkeIntuitionisticSemantics L MD M SM} {kminSM: KripkeMinimumSemantics L MD M SM} {kpSM: KripkePropositionalSemantics L MD M SM} {dusSM: DownUpSemantics_Fail.SeparatingSemantics L MD M SM}: 37 | forall x y z: expr, 38 | forall m, 39 | KRIPKE: M, m |= x * (y * z) <--> (x * y) * z. 40 | Proof. 41 | intros. 42 | unfold iffp. 43 | rewrite sat_andp. 44 | split; intros. 45 | + rewrite sat_impp; intros. 46 | rewrite sat_sepcon in H0. 47 | destruct H0 as [m0 [m1 [m2 [? [? [? ?]]]]]]. 48 | (* fail *) 49 | Abort. 50 | -------------------------------------------------------------------------------- /GeneralLogic/HenkinCompleteness.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Sets.Ensembles. 3 | Require Export Coq.Lists.List. 4 | Require Import Coq.omega.Omega. 5 | 6 | Definition LindenbaumChain {A: Type} (step: nat -> Ensemble A -> Ensemble A) (init: Ensemble A): nat -> Ensemble A := 7 | fix l (n: nat): Ensemble A := 8 | match n with 9 | | 0 => init 10 | | S n => step n (l n) 11 | end. 12 | 13 | Definition LindenbaumConstruction {A: Type} (step: nat -> Ensemble A -> Ensemble A) (init: Ensemble A): Ensemble A := 14 | fun a => exists n, LindenbaumChain step init n a. 15 | 16 | Definition Lindenbaum_spec_included {A: Type}: forall (step: nat -> Ensemble A -> Ensemble A) (init: Ensemble A) n , 17 | Included _ (LindenbaumChain step init n) (LindenbaumConstruction step init). 18 | Proof. 19 | intros. 20 | intros ? ?. 21 | exists n; auto. 22 | Qed. 23 | 24 | Definition Lindenbaum_spec_pos {A: Type}: forall (step: nat -> Ensemble A -> Ensemble A) (init: Ensemble A) (Pl: list A -> Prop) (Ps: Ensemble A -> Prop), 25 | (forall S, Ps S <-> exists l, Forall S l /\ Pl l) -> 26 | (forall n S, Included _ S (step n S)) -> 27 | ~ Ps init -> 28 | (forall n S, ~ Ps S -> ~ Ps (step n S)) -> 29 | ~ Ps (LindenbaumConstruction step init). 30 | Proof. 31 | intros. 32 | 33 | assert (forall n m, n <= m -> Included _ (LindenbaumChain step init n) (LindenbaumChain step init m)). 34 | { 35 | clear - H0. 36 | intros. 37 | induction H. 38 | - intros ? ?; auto. 39 | - intros ? ?. 40 | apply H0; auto. 41 | } 42 | clear H0; rename H3 into H0. 43 | 44 | rewrite H; intros [l [? ?]]. 45 | unfold LindenbaumConstruction in H3. 46 | 47 | assert (exists n, Forall (LindenbaumChain step init n) l). 48 | { 49 | clear - H3 H0. 50 | induction H3. 51 | + exists 0; constructor. 52 | + destruct IHForall as [n1 ?]. 53 | destruct H as [n2 ?]. 54 | exists (max n1 n2). 55 | constructor. 56 | - apply (H0 n2); auto. 57 | apply Max.le_max_r. 58 | - revert H1; apply Forall_impl; intros. 59 | apply (H0 n1); auto. 60 | apply Max.le_max_l. 61 | } 62 | clear H3; rename H5 into H3. 63 | 64 | assert (forall n, ~ Ps (LindenbaumChain step init n)). 65 | { 66 | induction n. 67 | + auto. 68 | + apply H2; auto. 69 | } 70 | 71 | destruct H3 as [n ?]. 72 | specialize (H5 n). 73 | rewrite H in H5. 74 | apply H5; clear H5. 75 | exists l; auto. 76 | Qed. 77 | 78 | Definition Lindenbaum_spec_neg {A: Type}: forall (step: nat -> Ensemble A -> Ensemble A) (init: Ensemble A) a n, 79 | LindenbaumChain step init n a -> 80 | LindenbaumConstruction step init a. 81 | Proof. 82 | intros. 83 | exists n; auto. 84 | Qed. 85 | -------------------------------------------------------------------------------- /MinimumLogic/DeepEmbedded/KripkeSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Logic.lib.Ensembles_ext. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | Require Import Logic.GeneralLogic.Semantics.Kripke. 8 | Require Import Logic.MinimumLogic.Syntax. 9 | Require Import Logic.MinimumLogic.Semantics.Kripke. 10 | Require Import Logic.MinimumLogic.DeepEmbedded.MinimumLanguage. 11 | 12 | Import MinimumLanguage. 13 | 14 | Record frame: Type := { 15 | underlying_set:> Type; 16 | underlying_relation: relation underlying_set 17 | }. 18 | 19 | Declare Scope TheKripkeSemantics. 20 | Infix "<=" := (underlying_relation _): TheKripkeSemantics. 21 | 22 | Local Open Scope TheKripkeSemantics. 23 | 24 | Definition sem (f: frame) := @Ensemble (underlying_set f). 25 | 26 | Definition denotation {Var: Type} (F: frame) (eval: Var -> sem F): expr Var -> sem F := 27 | fix denotation (x: expr Var): sem F:= 28 | match x with 29 | | impp y z => @Semantics.impp F (underlying_relation F) (denotation y) (denotation z) 30 | | varp p => eval p 31 | end. 32 | 33 | Section KripkeSemantics. 34 | Context (Var: Type). 35 | 36 | Record Kmodel : Type := { 37 | underlying_frame :> frame; 38 | sem_var: Var -> sem underlying_frame 39 | }. 40 | 41 | Record model: Type := { 42 | underlying_model :> Kmodel; 43 | elm: underlying_model 44 | }. 45 | 46 | Instance L: Language := MinimumLanguage.L Var. 47 | Instance MD: Model := Build_Model model. 48 | 49 | Instance kMD: KripkeModel MD := 50 | Build_KripkeModel _ 51 | Kmodel 52 | (fun M => M) 53 | (fun M m => Build_model M m). 54 | 55 | Instance R (M: Kmodel): Relation (Kworlds M) := 56 | @underlying_relation M. 57 | 58 | Definition Kmodel_Monotonic: Kmodel -> Prop := fun M => 59 | forall v: Var, upwards_closed_Kdenote (sem_var M v). 60 | 61 | Definition Kmodel_PreOrder: Kmodel -> Prop := fun M => 62 | PreOrder (@Krelation _ (R M)). 63 | 64 | Instance SM: Semantics L MD := 65 | Build_Semantics L MD (fun x M => (denotation M (sem_var M) x) (elm M)). 66 | 67 | Instance kiSM (M: Kmodel) {_: Kmodel_Monotonic M} {_: Kmodel_PreOrder M}: 68 | KripkeIntuitionisticSemantics L MD M SM. 69 | Proof. 70 | hnf in H, H0. 71 | constructor; intros. 72 | induction x. 73 | + apply (Semantics.impp_closed _ _ IHx1 IHx2). 74 | + apply H. 75 | Qed. 76 | 77 | Instance kminSM (M: Kmodel): KripkeMinimumSemantics L MD M SM. 78 | Proof. 79 | apply Build_KripkeMinimumSemantics. 80 | intros; apply Same_set_refl. 81 | Defined. 82 | 83 | End KripkeSemantics. 84 | 85 | Arguments Kmodel_Monotonic {Var} _. 86 | Arguments Kmodel_PreOrder {Var} _. 87 | -------------------------------------------------------------------------------- /unused_files/trivial.v: -------------------------------------------------------------------------------- 1 | Require Import IntuitionisticLogic.base. 2 | Import LogicNotation. 3 | Local Open Scope IPC_scope. 4 | 5 | Section TrivialSemantic. 6 | 7 | Context {venv: Var_env}. 8 | 9 | Fixpoint denote (f: Var -> Prop) (t: Term) : Prop := 10 | match t with 11 | | andp t1 t2 => denote f t1 /\ denote f t2 12 | | orp t1 t2 => denote f t1 \/ denote f t2 13 | | impp t1 t2 => denote f t1 -> denote f t2 14 | | falsep => False 15 | | varp x => f x 16 | end. 17 | 18 | Definition Trivial_sem: Semantic := mk_sem (Var -> Prop) denote. 19 | 20 | End TrivialSemantic. 21 | 22 | Require Import IntuitionisticLogic.IPC. 23 | 24 | Lemma sound_Trivial_IPC: forall {venv: Var_env}, sound Trivial_sem IPC. 25 | Proof. 26 | unfold sound. 27 | intros. 28 | induction H; intros M CONTEXT. 29 | + apply CONTEXT. 30 | auto. 31 | + specialize (IHIPC_derive M CONTEXT). 32 | simpl in IHIPC_derive |- *. 33 | tauto. 34 | + specialize (IHIPC_derive M CONTEXT). 35 | simpl in IHIPC_derive |- *. 36 | tauto. 37 | + specialize (IHIPC_derive1 M CONTEXT). 38 | specialize (IHIPC_derive2 M CONTEXT). 39 | simpl in IHIPC_derive1, IHIPC_derive2 |- *. 40 | tauto. 41 | + specialize (IHIPC_derive1 M CONTEXT). 42 | destruct IHIPC_derive1. 43 | - assert (CONTEXT_a: forall t0 : Term, (ctx;; a) t0 = true -> M |= t0). 44 | Focus 1. { 45 | intros. 46 | unfold ExtendContext in H3. 47 | destruct (term_eq t0 a). 48 | + subst; exact H2. 49 | + apply CONTEXT; auto. 50 | } Unfocus. 51 | exact (IHIPC_derive2 M CONTEXT_a). 52 | - assert (CONTEXT_b: forall t0 : Term, (ctx;; b) t0 = true -> M |= t0). 53 | Focus 1. { 54 | intros. 55 | unfold ExtendContext in H3. 56 | destruct (term_eq t0 b). 57 | + subst; exact H2. 58 | + apply CONTEXT; auto. 59 | } Unfocus. 60 | exact (IHIPC_derive3 M CONTEXT_b). 61 | + specialize (IHIPC_derive M CONTEXT). 62 | simpl in IHIPC_derive |- *. 63 | tauto. 64 | + specialize (IHIPC_derive M CONTEXT). 65 | simpl in IHIPC_derive |- *. 66 | tauto. 67 | + specialize (IHIPC_derive1 M CONTEXT). 68 | specialize (IHIPC_derive2 M CONTEXT). 69 | simpl in IHIPC_derive1, IHIPC_derive2 |- *. 70 | tauto. 71 | + simpl; intros. 72 | assert (CONTEXT_a: forall t0 : Term, (ctx;; a) t0 = true -> M |= t0). 73 | Focus 1. { 74 | intros. 75 | unfold ExtendContext in H1. 76 | destruct (term_eq t0 a). 77 | + subst; exact H0. 78 | + apply CONTEXT; auto. 79 | } Unfocus. 80 | specialize (IHIPC_derive M CONTEXT_a). 81 | exact IHIPC_derive. 82 | + specialize (IHIPC_derive M CONTEXT). 83 | simpl in IHIPC_derive |- *. 84 | tauto. 85 | Qed. 86 | 87 | -------------------------------------------------------------------------------- /ModalLogic/Semantics/Flat.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.RelationClasses. 2 | Require Import Coq.Relations.Relation_Definitions. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.GeneralLogic.KripkeModel. 5 | Require Import Logic.ModalLogic.Model.KripkeModel. 6 | Require Import Logic.ModalLogic.Model.OrderedKripkeModel. 7 | Require Import Logic.MinimumLogic.Syntax. 8 | Require Import Logic.PropositionalLogic.Syntax. 9 | Require Import Logic.ModalLogic.Syntax. 10 | 11 | Local Open Scope logic_base. 12 | Local Open Scope syntax. 13 | Local Open Scope kripke_model. 14 | Import PropositionalLanguageNotation. 15 | Import ModalLanguageNotation. 16 | Import KripkeModelFamilyNotation. 17 | Import KripkeModelNotation_Intuitionistic. 18 | 19 | Module Semantics. 20 | 21 | Definition boxp {worlds: Type} {R: KM.Relation worlds} (X: Ensemble worlds): Ensemble worlds := 22 | fun m => forall n, KM.Krelation m n -> X n. 23 | 24 | Lemma boxp_closed 25 | {worlds: Type} 26 | {R1: KI.Relation worlds} 27 | {po_R1: PreOrder KI.Krelation} 28 | {R2: KM.Relation worlds} 29 | {ukmM: UpwardsClosedOrderedKripkeModel worlds}: 30 | forall (X: Ensemble worlds), 31 | upwards_closed_Kdenote X -> 32 | upwards_closed_Kdenote (boxp X). 33 | Proof. 34 | intros. 35 | hnf. 36 | intros m1 m2 ? ?. 37 | hnf in H1 |- *. 38 | intros n2 ?. 39 | destruct (KM_relation_up _ _ _ H0 H2) as [n1 [? ?]]. 40 | apply (H n1); auto. 41 | Qed. 42 | 43 | End Semantics. 44 | 45 | Module SemanticsMono. 46 | 47 | Program Definition boxp 48 | {worlds: Type} 49 | {R1: KI.Relation worlds} 50 | {po_R1: PreOrder KI.Krelation} 51 | {R2: KM.Relation worlds} 52 | {ukmM: UpwardsClosedOrderedKripkeModel worlds} 53 | (X: MonoEnsemble worlds): MonoEnsemble worlds := 54 | Semantics.boxp X. 55 | Next Obligation. 56 | apply (@Semantics.boxp_closed worlds R1 po_R1 R2 ukmM); 57 | apply (proj2_sig _). 58 | Defined. 59 | 60 | End SemanticsMono. 61 | 62 | Class FlatModalSemantics (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} (MD: Model) {kMD: KripkeModel MD} (M: Kmodel) {R1: KI.Relation (Kworlds M)} {R2: KM.Relation (Kworlds M)} (SM: Semantics L MD) : Type := { 63 | denote_boxp: forall x, Same_set _ (Kdenotation M (boxp x)) (Semantics.boxp (Kdenotation M x)) 64 | }. 65 | 66 | Lemma sat_boxp {L: Language} {minL: MinimumLanguage L} {mL: ModalLanguage L} {MD: Model} {kMD: KripkeModel MD} {M: Kmodel} {R1: KI.Relation (Kworlds M)} {R2: KM.Relation (Kworlds M)} {SM: Semantics L MD} {fmSM: FlatModalSemantics L MD M SM}: forall m x, KRIPKE: M , m |= boxp x <-> (forall n, KM.Krelation m n -> KRIPKE: M , n |= x). 67 | Proof. 68 | intros; simpl. 69 | unfold satisfies. 70 | destruct (denote_boxp x). 71 | split; [apply H | apply H0]. 72 | Qed. 73 | 74 | -------------------------------------------------------------------------------- /ModalLogic/Sound/Sound_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Logic.Classical_Pred_Type. 3 | Require Import Logic.lib.Ensembles_ext. 4 | Require Import Logic.GeneralLogic.Base. 5 | Require Import Logic.GeneralLogic.KripkeModel. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | Require Import Logic.MinimumLogic.Semantics.Trivial. 8 | Require Import Logic.PropositionalLogic.Syntax. 9 | Require Import Logic.PropositionalLogic.Semantics.Trivial. 10 | Require Import Logic.ModalLogic.Syntax. 11 | Require Import Logic.ModalLogic.Model.KripkeModel. 12 | Require Import Logic.ModalLogic.Model.OrderedKripkeModel. 13 | Require Import Logic.ModalLogic.Semantics.Kripke. 14 | 15 | Local Open Scope logic_base. 16 | Local Open Scope syntax. 17 | Local Open Scope kripke_model. 18 | Import PropositionalLanguageNotation. 19 | Import ModalLanguageNotation. 20 | Import KripkeModelFamilyNotation. 21 | 22 | Section Sound_Kripke. 23 | 24 | Context {L: Language} 25 | {minL: MinimumLanguage L} 26 | {pL: PropositionalLanguage L} 27 | {mL: ModalLanguage L} 28 | {MD: Model} 29 | {kMD: KripkeModel MD} 30 | {M: Kmodel} 31 | {R: Relation (Kworlds M)} 32 | {SM: Semantics L MD} 33 | {tminSM: TrivialMinimumSemantics L MD SM} 34 | {tpSM: TrivialPropositionalSemantics L MD SM} 35 | {kmSM: KripkeModalSemantics L MD M SM}. 36 | 37 | Lemma sound_axiom_K: 38 | forall x y (m: Kworlds M), 39 | KRIPKE: M, m |= boxp (x --> y) --> (boxp x --> boxp y). 40 | Proof. 41 | intros. 42 | rewrite !sat_impp, !sat_boxp. 43 | intros. 44 | specialize (H _ H1). 45 | specialize (H0 _ H1). 46 | rewrite sat_impp in H. 47 | auto. 48 | Qed. 49 | 50 | Lemma sound_rule_N: 51 | forall x, 52 | (forall (m: Kworlds M), KRIPKE: M, m |= x) -> 53 | (forall (m: Kworlds M), KRIPKE: M, m |= boxp x). 54 | Proof. 55 | intros. 56 | rewrite sat_boxp. 57 | intros; apply H; auto. 58 | Qed. 59 | 60 | Lemma sound_boxp_orp {pf_R: PartialFunctional KM.Krelation}: 61 | forall x y (m: Kworlds M), 62 | KRIPKE: M, m |= boxp (x || y) <--> (boxp x || boxp y). 63 | Proof. 64 | intros. 65 | unfold iffp. 66 | rewrite sat_andp, !sat_impp, !sat_orp, !sat_boxp. 67 | split; intros. 68 | + apply NNPP. 69 | intro. 70 | apply not_or_and in H0; destruct H0. 71 | apply not_all_ex_not in H0; destruct H0 as [n1 ?]. 72 | apply not_all_ex_not in H1; destruct H1 as [n2 ?]. 73 | apply imply_to_and in H0; destruct H0. 74 | apply imply_to_and in H1; destruct H1. 75 | pose proof partial_functionality _ _ _ H0 H1. 76 | subst n2; clear H1. 77 | specialize (H _ H0). 78 | rewrite sat_orp in H. 79 | tauto. 80 | + rewrite sat_orp. 81 | destruct H; [left | right]; auto. 82 | Qed. 83 | 84 | End Sound_Kripke. 85 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/DownUpSemantics_Fail.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Logic.lib.Coqlib. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.SeparationLogic.Syntax. 7 | Require Import Logic.GeneralLogic.KripkeModel. 8 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 9 | Require Import Logic.SeparationLogic.Model.OrderedSA. 10 | Require Import Logic.SeparationLogic.Semantics.WeakSemantics. 11 | Require Import Logic.SeparationLogic.Semantics.StrongSemantics. 12 | 13 | Local Open Scope logic_base. 14 | Local Open Scope syntax. 15 | Local Open Scope kripke_model. 16 | Import SeparationLogicNotation. 17 | Import KripkeModelFamilyNotation. 18 | Import KripkeModelNotation_Intuitionistic. 19 | 20 | Class SeparatingSemantics 21 | (L: Language) 22 | {sepconL: SepconLanguage L} 23 | {wandL: WandLanguage L} 24 | (MD: Model) 25 | {kMD: KripkeModel MD} 26 | (M: Kmodel) 27 | {R: Relation (Kworlds M)} 28 | {J: Join (Kworlds M)} 29 | (SM: Semantics L MD): Type := 30 | { 31 | denote_sepcon: forall x y, Same_set _ (Kdenotation M (x * y)) (StrongSemantics.sepcon (Kdenotation M x) (Kdenotation M y)); 32 | denote_wand: forall x y, Same_set _ (Kdenotation M (x -* y)) (StrongSemantics.wand (Kdenotation M x) (Kdenotation M y)) 33 | }. 34 | 35 | Lemma sat_sepcon 36 | {L: Language} 37 | {sepconL: SepconLanguage L} 38 | {wandL: WandLanguage L} 39 | {MD: Model} 40 | {kMD: KripkeModel MD} 41 | {M: Kmodel} 42 | {R: Relation (Kworlds M)} 43 | {J: Join (Kworlds M)} 44 | {SM: Semantics L MD} 45 | {fsSM: SeparatingSemantics L MD M SM}: 46 | forall m x y, 47 | KRIPKE: M , m |= x * y <-> 48 | exists m0 m1 m2, m0 <= m /\ 49 | join m1 m2 m0 /\ 50 | KRIPKE: M , m1 |= x /\ 51 | KRIPKE: M, m2 |= y. 52 | Proof. 53 | intros; simpl. 54 | unfold satisfies. 55 | destruct (denote_sepcon x y). 56 | split; [apply H | apply H0]. 57 | Qed. 58 | 59 | Lemma sat_wand 60 | {L: Language} 61 | {sepconL: SepconLanguage L} 62 | {wandL: WandLanguage L} 63 | {MD: Model} 64 | {kMD: KripkeModel MD} 65 | {M: Kmodel} 66 | {R: Relation (Kworlds M)} 67 | {J: Join (Kworlds M)} 68 | {SM: Semantics L MD} 69 | {fsSM: SeparatingSemantics L MD M SM}: 70 | forall m x y, 71 | KRIPKE: M , m |= x -* y <-> 72 | forall m0 m1 m2, m <= m0 -> 73 | join m0 m1 m2 -> 74 | KRIPKE: M , m1 |= x -> 75 | KRIPKE: M, m2 |= y. 76 | Proof. 77 | intros; simpl. 78 | unfold satisfies. 79 | destruct (denote_wand x y). 80 | split; [apply H | apply H0]. 81 | Qed. 82 | 83 | -------------------------------------------------------------------------------- /PropositionalLogic/DeepEmbedded/Deep.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.MinimumLogic.Syntax. 3 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 4 | Require Import Logic.PropositionalLogic.Syntax. 5 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 6 | 7 | Local Open Scope logic_base. 8 | Local Open Scope syntax. 9 | Import PropositionalLanguageNotation. 10 | 11 | Inductive expr : Type := 12 | | andp : expr -> expr -> expr 13 | | orp : expr -> expr -> expr 14 | | impp : expr -> expr -> expr 15 | | falsep : expr 16 | | varp : nat -> expr 17 | . 18 | 19 | Fixpoint beq e1 e2 := 20 | match e1, e2 with 21 | | falsep , falsep => true 22 | | varp x, varp y => EqNat.beq_nat x y 23 | | andp p11 p12, andp p21 p22 => andb (beq p11 p21) (beq p12 p22) 24 | | orp p11 p12, orp p21 p22 => andb (beq p11 p21) (beq p12 p22) 25 | | impp p11 p12, impp p21 p22 => andb (beq p11 p21) (beq p12 p22) 26 | | _, _ => false 27 | end. 28 | 29 | Theorem beq_eq : forall e1 e2, beq e1 e2 = true <-> e1 = e2. 30 | Proof. 31 | split. 32 | - generalize dependent e2. 33 | induction e1; intros; destruct e2; simpl in H; 34 | try congruence; auto using EqNat.beq_nat_true. 35 | all: apply andb_prop in H; destruct H; 36 | rewrite (IHe1_1 _ H); rewrite (IHe1_2 _ H0); reflexivity. 37 | - intros. subst e2. 38 | induction e1; simpl; auto using andb_true_intro, EqNat.beq_nat_refl. 39 | Qed. 40 | 41 | Local Instance L : Language := Build_Language expr . 42 | 43 | Local Instance minL : MinimumLanguage L := Build_MinimumLanguage L impp. 44 | 45 | Local Instance pL : PropositionalLanguage L := 46 | Build_PropositionalLanguage L andp orp falsep. 47 | 48 | Inductive provable: expr -> Prop := 49 | | modus_ponens: forall x y, provable (x --> y) -> provable x -> provable y 50 | | axiom1: forall x y, provable (x --> (y --> x)) 51 | | axiom2: forall x y z, provable ((x --> y --> z) --> (x --> y) --> (x --> z)) 52 | | andp_intros: forall x y, provable (x --> y --> x && y) 53 | | andp_elim1: forall x y, provable (x && y --> x) 54 | | andp_elim2: forall x y, provable (x && y --> y) 55 | | orp_intros1: forall x y, provable (x --> x || y) 56 | | orp_intros2: forall x y, provable (y --> x || y) 57 | | orp_elim: forall x y z, provable ((x --> z) --> (y --> z) --> (x || y --> z)) 58 | | falsep_elim: forall x, provable (FF --> x) 59 | . 60 | 61 | Local Instance GP: Provable L := Build_Provable _ provable. 62 | 63 | Local Instance minAX: MinimumAxiomatization L GP. 64 | Proof. 65 | constructor. 66 | + apply modus_ponens. 67 | + apply axiom1. 68 | + apply axiom2. 69 | Qed. 70 | 71 | Local Instance ipG: IntuitionisticPropositionalLogic L GP. 72 | Proof. 73 | constructor. 74 | + apply andp_intros. 75 | + apply andp_elim1. 76 | + apply andp_elim2. 77 | + apply orp_intros1. 78 | + apply orp_intros2. 79 | + apply orp_elim. 80 | + apply falsep_elim. 81 | Qed. 82 | -------------------------------------------------------------------------------- /ModalLogic/ProofTheory/ClassicalDerivedRules.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 3 | Require Import Logic.MinimumLogic.Syntax. 4 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 5 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 6 | Require Import Logic.MinimumLogic.ProofTheory.ExtensionTactic. 7 | Require Import Logic.PropositionalLogic.Syntax. 8 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 9 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 10 | Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett. 11 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 12 | Require Import Logic.PropositionalLogic.ProofTheory.RewriteClass. 13 | Require Import Logic.ModalLogic.Syntax. 14 | Require Import Logic.ModalLogic.ProofTheory.ModalLogic. 15 | Require Import Logic.ModalLogic.ProofTheory.RewriteClass. 16 | Require Import Logic.ModalLogic.ProofTheory.IntuitionisticDerivedRules. 17 | 18 | Local Open Scope logic_base. 19 | Local Open Scope syntax. 20 | Import PropositionalLanguageNotation. 21 | Import ModalLanguageNotation. 22 | 23 | Section ClassicalderivedRules. 24 | 25 | Context {L: Language} 26 | {minL: MinimumLanguage L} 27 | {pL: PropositionalLanguage L} 28 | {mL: ModalLanguage L} 29 | {Gamma: Provable L} 30 | {minAX: MinimumAxiomatization L Gamma} 31 | {ipAX: IntuitionisticPropositionalLogic L Gamma} 32 | {cpAX: ClassicalPropositionalLogic L Gamma} 33 | {KmAX: SystemK L Gamma}. 34 | 35 | Existing Instances Classical2GodelDummett GodelDummett2DeMorgan. 36 | 37 | Lemma diamondp_orp: forall x y, |-- diamondp (x || y) <--> (diamondp x || diamondp y). 38 | Proof. 39 | intros. 40 | apply solve_andp_intros; [| apply orp_diamondp]. 41 | unfold diamondp. 42 | rewrite <- demorgan_negp_andp. 43 | rewrite <- contrapositivePP. 44 | rewrite <- boxp_andp. 45 | rewrite demorgan_negp_orp. 46 | apply provable_impp_refl. 47 | Qed. 48 | 49 | Instance PropositionalTransparentModality2StrongPropositionalTransparentModality {pmGamma: PropositionalTransparentModality L Gamma}: StrongPropositionalTransparentModality L Gamma. 50 | Proof. 51 | constructor. 52 | intros. 53 | apply solve_andp_intros; [apply axiom_K |]. 54 | rewrite (impp2orp x y), (impp2orp (boxp x) (boxp y)). 55 | rewrite boxp_orp. 56 | apply solve_orp_impp; [| apply orp_intros2]. 57 | rewrite <- orp_intros1. 58 | apply (modus_ponens (boxp (x || ~~ x))). 59 | + rewrite boxp_orp. 60 | apply solve_orp_impp; [| apply axiom1]. 61 | AddSequentCalculus. 62 | rewrite provable_derivable. 63 | rewrite <- !deduction_theorem. 64 | apply deduction_falsep_elim. 65 | apply deduction_modus_ponens with (boxp x); solve_assum. 66 | + apply rule_N. 67 | apply excluded_middle. 68 | Qed. 69 | 70 | End ClassicalderivedRules. 71 | -------------------------------------------------------------------------------- /PropositionalLogic/Complete/Lindenbaum_Trivial.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.FunctionalExtensionality. 2 | Require Import Coq.Logic.Classical_Prop. 3 | Require Import Coq.Logic.Classical_Pred_Type. 4 | Require Import Logic.lib.Bijection. 5 | Require Import Logic.lib.Countable. 6 | Require Import Logic.lib.EnsemblesProperties. 7 | Require Import Logic.GeneralLogic.Base. 8 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 9 | Require Import Logic.GeneralLogic.Complete.Lindenbaum. 10 | Require Import Logic.GeneralLogic.Complete.Lindenbaum_Kripke. 11 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 12 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 13 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Trivial. 14 | Require Import Logic.MinimumLogic.Syntax. 15 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 16 | Require Import Logic.MinimumLogic.Complete.Lindenbaum_Kripke. 17 | Require Import Logic.MinimumLogic.Complete.ContextProperty_Kripke. 18 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 19 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 20 | Require Import Logic.PropositionalLogic.Syntax. 21 | Require Import Logic.PropositionalLogic.Complete.Lindenbaum_Kripke. 22 | Require Import Logic.PropositionalLogic.Complete.ContextProperty_Kripke. 23 | Require Import Logic.PropositionalLogic.Complete.ContextProperty_Trivial. 24 | 25 | Local Open Scope logic_base. 26 | Local Open Scope syntax. 27 | Import PropositionalLanguageNotation. 28 | 29 | Section Lindenbaum_Trivial. 30 | 31 | Context {L: Language} 32 | {minL: MinimumLanguage L} 33 | {pL: PropositionalLanguage L} 34 | {GammaP: Provable L} 35 | {GammaD: Derivable L} 36 | {SC: NormalSequentCalculus L GammaP GammaD} 37 | {bSC: BasicSequentCalculus L GammaD} 38 | {fwSC: FiniteWitnessedSequentCalculus L GammaD} 39 | {minSC: MinimumSequentCalculus L GammaD} 40 | {ipSC: IntuitionisticPropositionalSequentCalculus L GammaD} 41 | {cpSC: ClassicalPropositionalSequentCalculus L GammaD} 42 | {minAX: MinimumAxiomatization L GammaP} 43 | {ipAX: IntuitionisticPropositionalLogic L GammaP}. 44 | 45 | Lemma Lindenbaum_for_max_consistent: forall P, 46 | Lindenbaum_ensures P derivable_closed -> 47 | Lindenbaum_ensures P orp_witnessed -> 48 | Lindenbaum_ensures P consistent -> 49 | Lindenbaum_ensures P (maximal consistent). 50 | Proof. 51 | intros. 52 | hnf; intros. 53 | apply DDCS_MCS; auto. 54 | Qed. 55 | 56 | Lemma Lindenbaum_cannot_derive_ensures_max_consistent 57 | {AX: NormalAxiomatization L GammaP GammaD}: 58 | forall x, Lindenbaum_ensures (cannot_derive x) (maximal consistent). 59 | Proof. 60 | intros. 61 | apply Lindenbaum_for_max_consistent. 62 | - apply Lindenbaum_cannot_derive_ensures_derivable_closed. 63 | - apply Lindenbaum_cannot_derive_ensures_orp_witnessed. 64 | - apply Lindenbaum_cannot_derive_ensures_consistent. 65 | Qed. 66 | 67 | End Lindenbaum_Trivial. 68 | -------------------------------------------------------------------------------- /GeneralLogic/ProofTheory/BasicSequentCalculus.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Coqlib. 2 | Require Import Logic.lib.Ensembles_ext. 3 | Require Import Logic.GeneralLogic.Base. 4 | Require Import Logic.GeneralLogic.ProofTheory.TheoryOfSequentCalculus. 5 | 6 | Local Open Scope logic_base. 7 | 8 | Class NormalSequentCalculus 9 | (L: Language) (GammaP: Provable L) (GammaD: Derivable L): Type := { 10 | provable_derivable: forall x, provable x <-> derivable empty_context x 11 | }. 12 | 13 | Class BasicSequentCalculus (L: Language) (Gamma: Derivable L) := { 14 | deduction_weaken: forall Phi Psi x, Included _ Phi Psi -> Phi |-- x -> Psi |-- x; 15 | derivable_assum: forall Phi x, Ensembles.In _ Phi x -> Phi |-- x; 16 | deduction_subst: forall (Phi Psi: context) y, (forall x, Psi x -> Phi |-- x) -> Union _ Phi Psi |-- y -> Phi |-- y 17 | }. 18 | 19 | Class FiniteWitnessedSequentCalculus (L: Language) (Gamma: Derivable L) := { 20 | derivable_finite_witnessed: forall (Phi: context) (y: expr), Phi |-- y -> exists xs, Forall Phi xs /\ (fun x => In x xs) |-- y 21 | }. 22 | 23 | Section DerivableRulesFromSequentCalculus. 24 | 25 | Context {L: Language} 26 | {Gamma: Derivable L} 27 | {bSC: BasicSequentCalculus L Gamma}. 28 | 29 | Lemma deduction_subst1: forall Phi x y, Phi |-- x -> Phi;; x |-- y -> Phi |-- y. 30 | Proof. 31 | intros. 32 | apply deduction_subst with (Singleton _ x); auto. 33 | intros. 34 | inversion H1; subst. 35 | auto. 36 | Qed. 37 | 38 | Lemma derivable_trans: forall (Phi Psi: context) y, (forall x, Psi x -> Phi |-- x) -> Psi |-- y -> Phi |-- y. 39 | Proof. 40 | intros. 41 | eapply deduction_subst; eauto. 42 | eapply deduction_weaken; eauto. 43 | apply right_Included_Union. 44 | Qed. 45 | 46 | Lemma deduction_weaken1: forall Phi x y, 47 | Phi |-- y -> 48 | Phi;; x |-- y. 49 | Proof. 50 | intros. 51 | eapply deduction_weaken; eauto. 52 | intros ? ?; left; auto. 53 | Qed. 54 | 55 | Lemma derivable_assum1: forall (Phi: context) (x: expr), Phi;; x |-- x. 56 | Proof. 57 | intros. 58 | apply derivable_assum. 59 | right; constructor. 60 | Qed. 61 | 62 | Lemma contextual_derivable_finite_witnessed {fwSC: FiniteWitnessedSequentCalculus L Gamma}: forall (Phi Psi: context) (y: expr), Union _ Phi Psi |-- y -> exists xs, Forall Psi xs /\ Union _ Phi (fun x => In x xs) |-- y. 63 | Proof. 64 | apply DeductionWeaken_DerivableFiniteWitnessed_2_ContextualDerivableFiniteWitnessed. 65 | + hnf; intros; eapply deduction_weaken; eauto. 66 | + hnf; intros; eapply derivable_finite_witnessed; eauto. 67 | Qed. 68 | 69 | Lemma deduction_weaken0 {GammaP: Provable L} {SC: NormalSequentCalculus L GammaP Gamma}: forall Phi y, 70 | |-- y -> 71 | Phi |-- y. 72 | Proof. 73 | intros. 74 | rewrite provable_derivable in H. 75 | eapply deduction_weaken; eauto. 76 | intros ? []. 77 | Qed. 78 | 79 | End DerivableRulesFromSequentCalculus. 80 | 81 | Ltac solve_assum := 82 | (first [apply derivable_assum1 | assumption | apply deduction_weaken1; solve_assum] || fail 1000 "Cannot find the conclusion in assumption"). 83 | 84 | -------------------------------------------------------------------------------- /SeparationLogic/ProofTheory/RewriteClass.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.Morphisms. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Logic.lib.Coqlib. 4 | Require Import Logic.GeneralLogic.Base. 5 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 8 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 9 | Require Import Logic.PropositionalLogic.Syntax. 10 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 11 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 12 | Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett. 13 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 14 | Require Import Logic.PropositionalLogic.ProofTheory.RewriteClass. 15 | Require Import Logic.SeparationLogic.Syntax. 16 | Require Import Logic.SeparationLogic.ProofTheory.SeparationLogic. 17 | 18 | Local Open Scope logic_base. 19 | Local Open Scope syntax. 20 | Import PropositionalLanguageNotation. 21 | Import SeparationLogicNotation. 22 | 23 | Section RewriteClass. 24 | 25 | Context {L: Language} 26 | {minL: MinimumLanguage L} 27 | {sepconL: SepconLanguage L} 28 | {wandL: WandLanguage L} 29 | {Gamma: Provable L} 30 | {minAX: MinimumAxiomatization L Gamma} 31 | {sepconAX: SepconAxiomatization L Gamma} 32 | {wandAX: WandAxiomatization L Gamma}. 33 | 34 | Instance sepcon_proper_impp: Proper ((fun x y => |-- impp x y) ==> (fun x y => |-- impp x y) ==> (fun x y => |-- impp x y)) sepcon. 35 | Proof. 36 | hnf; intros x1 x2 ?. 37 | hnf; intros y1 y2 ?. 38 | apply sepcon_mono; auto. 39 | Qed. 40 | 41 | Instance wand_proper_impp: Proper ((fun x y => |-- impp x y) --> (fun x y => |-- impp x y) ==> (fun x y => |-- impp x y)) wand. 42 | Proof. 43 | hnf; intros x1 x2 ?. 44 | hnf; intros y1 y2 ?. 45 | unfold Basics.flip in H. 46 | apply wand_mono; auto. 47 | Qed. 48 | 49 | Context {pL: PropositionalLanguage L} 50 | {ipAX: IntuitionisticPropositionalLogic L Gamma}. 51 | 52 | Instance sepcon_proper_iffp: Proper ((fun x y => |-- iffp x y) ==> (fun x y => |-- iffp x y) ==> (fun x y => |-- iffp x y)) sepcon. 53 | Proof. 54 | hnf; intros x1 x2 ?. 55 | hnf; intros y1 y2 ?. 56 | apply solve_andp_intros. 57 | + apply sepcon_mono. 58 | - rewrite H; apply provable_impp_refl. 59 | - rewrite H0; apply provable_impp_refl. 60 | + apply sepcon_mono. 61 | - rewrite H; apply provable_impp_refl. 62 | - rewrite H0; apply provable_impp_refl. 63 | Qed. 64 | 65 | Instance wand_proper_iffp: Proper ((fun x y => |-- iffp x y) ==> (fun x y => |-- iffp x y) ==> (fun x y => |-- iffp x y)) wand. 66 | Proof. 67 | hnf; intros x1 x2 ?. 68 | hnf; intros y1 y2 ?. 69 | apply solve_andp_intros. 70 | + apply wand_mono. 71 | - rewrite H; apply provable_impp_refl. 72 | - rewrite H0; apply provable_impp_refl. 73 | + apply wand_mono. 74 | - rewrite H; apply provable_impp_refl. 75 | - rewrite H0; apply provable_impp_refl. 76 | Qed. 77 | 78 | End RewriteClass. 79 | 80 | Existing Instances sepcon_proper_impp wand_proper_impp sepcon_proper_iffp wand_proper_iffp. 81 | -------------------------------------------------------------------------------- /MinimumLogic/DeepEmbedded/MinimumLanguage.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.ProofIrrelevance. 2 | Require Import Coq.omega.Omega. 3 | Require Import Logic.lib.Bijection. 4 | Require Import Logic.lib.Countable. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | 8 | Local Open Scope logic_base. 9 | Local Open Scope syntax. 10 | 11 | Inductive expr {Var: Type}: Type := 12 | | impp : expr -> expr -> expr 13 | | varp : Var -> expr. 14 | 15 | Arguments expr Var: clear implicits. 16 | 17 | Instance L (Var: Type): Language := 18 | Build_Language (expr Var). 19 | 20 | Instance minL (Var: Type): MinimumLanguage (L Var) := 21 | Build_MinimumLanguage (L Var) impp. 22 | 23 | Definition rank {Var: Type}: expr Var -> nat := 24 | fix rank (x: expr Var): nat := 25 | match x with 26 | | impp y z => 1 + rank y + rank z 27 | | varp p => 0 28 | end. 29 | 30 | Definition formula_countable: forall Var, Countable Var -> Countable (expr Var). 31 | intros. 32 | assert (forall n, Countable (sig (fun x: expr Var => rank x <= n))). 33 | + induction n. 34 | - apply (@bijection_Countable _ Var); [| solve_Countable]. 35 | apply bijection_sym. 36 | apply (FBuild_bijection _ _ (fun p => exist (fun x: expr Var => rank x <= 0) (varp p) (le_n 0))). 37 | * hnf; intros. 38 | inversion H; auto. 39 | * hnf; intros. 40 | destruct b as [[] HH]; try solve [inversion HH]. 41 | exists v. 42 | eauto; f_equal; apply proof_irrelevance. 43 | - set (s := sig (fun x: expr Var => rank x <= n)). 44 | apply (@injection_Countable _ (s * s + Var)%type); [| solve_Countable]. 45 | 46 | apply (Build_injection _ _ (fun x y => 47 | match y with 48 | | inl (exist _ y _, exist _ z _) => proj1_sig x = impp y z 49 | | inr p => proj1_sig x = varp p 50 | end)). 51 | * hnf; intros. 52 | destruct a as [[y z | p] ?H]. 53 | (* 1 *) simpl in H. assert (rank y <= n) by omega. assert (rank z <= n) by omega. 54 | exists (inl (exist _ y H0, exist _ z H1)); auto. 55 | (* 2 *) exists (inr p); auto. 56 | * hnf; intros. 57 | destruct a as [[y z | p] ?H]; 58 | destruct b1 as [[[y1 ?H] [z1 ?H]] | p1]; try solve [inversion H]; 59 | destruct b2 as [[[y2 ?H] [z2 ?H]] | p2]; try solve [inversion H0]. 60 | (* 1 *) inversion H; inversion H0; subst; subst; repeat f_equal; apply proof_irrelevance. 61 | (* 2 *) inversion H; inversion H0; subst; subst; repeat f_equal; apply proof_irrelevance. 62 | * hnf; intros. 63 | destruct b as [[[y ?H] [z ?H]] | p]; 64 | destruct a1 as [[y1 z1 | p1] ?H]; try solve [inversion H]; 65 | destruct a2 as [[y2 z2 | p2] ?H]; try solve [inversion H0]. 66 | (* 1 *) inversion H; inversion H0; subst; subst; repeat f_equal; apply proof_irrelevance. 67 | (* 2 *) inversion H; inversion H0; subst; subst; repeat f_equal; apply proof_irrelevance. 68 | + apply (@injection_Countable _ (sigT (fun n => sig (fun x: expr Var => rank x <= n)))); [| solve_Countable; auto]. 69 | apply (FBuild_injection _ _ (fun x0 => existT (fun n => sig (fun x => rank x <= n)) (rank x0) (exist (fun x => rank x <= rank x0) x0 (le_n (rank x0))))). 70 | hnf; intros. 71 | simpl in H. 72 | inversion H; auto. 73 | Qed. 74 | 75 | -------------------------------------------------------------------------------- /examples/Imp.v: -------------------------------------------------------------------------------- 1 | (* The language and semantics in this file is mainly copied from software foundation. Benjamin C. Pierce, Arthur Azevedo de Amorim, Chris Casinghino, Marco Gaboardi, Michael Greenberg, Catalin Hritcu, Vilhelm Sjöberg, and Brent Yorgey. http://www.cis.upenn.edu/ bcpierce/sf. *) 2 | 3 | Require Import Coq.ZArith.ZArith. 4 | 5 | Section Imp. 6 | 7 | Context {Var: Type}. 8 | 9 | Definition state := Var -> Z. 10 | 11 | Definition update (st : state) (x : Var) (n : Z) (st': state): Prop := 12 | st' x = n /\ 13 | (forall x0, x0 <> x -> st x0 = st' x0). 14 | 15 | Inductive aexp : Type := 16 | | AVar : Var -> aexp 17 | | ANum : Z -> aexp 18 | | APlus : aexp -> aexp -> aexp 19 | | AMinus : aexp -> aexp -> aexp 20 | | AMult : aexp -> aexp -> aexp. 21 | 22 | Inductive bexp : Type := 23 | | BTrue : bexp 24 | | BFalse : bexp 25 | | BEq : aexp -> aexp -> bexp 26 | | BLe : aexp -> aexp -> bexp 27 | | BNot : bexp -> bexp 28 | | BAnd : bexp -> bexp -> bexp. 29 | 30 | Fixpoint aeval (st : state) (a : aexp) : Z := 31 | match a with 32 | | AVar x => st x 33 | | ANum n => n 34 | | APlus a1 a2 => (aeval st a1) + (aeval st a2) 35 | | AMinus a1 a2 => (aeval st a1) - (aeval st a2) 36 | | AMult a1 a2 => (aeval st a1) * (aeval st a2) 37 | end. 38 | 39 | Fixpoint beval (st : state) (b : bexp) : bool := 40 | match b with 41 | | BTrue => true 42 | | BFalse => false 43 | | BEq a1 a2 => Zeq_bool (aeval st a1) (aeval st a2) 44 | | BLe a1 a2 => Zle_bool (aeval st a1) (aeval st a2) 45 | | BNot b1 => negb (beval st b1) 46 | | BAnd b1 b2 => andb (beval st b1) (beval st b2) 47 | end. 48 | 49 | Inductive cmd : Type := 50 | | CSkip : cmd 51 | | CAss : Var -> aexp -> cmd 52 | | CSeq : cmd -> cmd -> cmd 53 | | CIf : bexp -> cmd -> cmd -> cmd 54 | | CWhile : bexp -> cmd -> cmd. 55 | 56 | Notation "'SKIP'" := 57 | CSkip. 58 | Notation "x '::=' a" := 59 | (CAss x a) (at level 60). 60 | Notation "c1 ;; c2" := 61 | (CSeq c1 c2) (at level 80, right associativity). 62 | Notation "'WHILE' b 'DO' c 'END'" := 63 | (CWhile b c) (at level 80, right associativity). 64 | Notation "'IFB' c1 'THEN' c2 'ELSE' c3 'FI'" := 65 | (CIf c1 c2 c3) (at level 80, right associativity). 66 | 67 | Reserved Notation " t '/' st '==>' t' '/' st' " 68 | (at level 40, st at level 39, t' at level 39). 69 | 70 | Inductive cstep : (cmd * state) -> (cmd * state) -> Prop := 71 | | CS_Ass : forall st st' i n a, 72 | aeval st a = n -> 73 | update st i n st' -> 74 | (i ::= a) / st ==> SKIP / st' 75 | | CS_SeqStep : forall st c1 c1' st' c2, 76 | c1 / st ==> c1' / st' -> 77 | (c1 ;; c2) / st ==> (c1' ;; c2) / st' 78 | | CS_SeqFinish : forall st c2, 79 | (SKIP ;; c2) / st ==> c2 / st 80 | | CS_IfTrue : forall st b c1 c2, 81 | beval st b = true -> 82 | IFB b THEN c1 ELSE c2 FI / st ==> c1 / st 83 | | CS_IfFalse : forall st b c1 c2, 84 | beval st b = false -> 85 | IFB b THEN c1 ELSE c2 FI / st ==> c2 / st 86 | | CS_WhileTrue : forall st b c1, 87 | beval st b = true -> 88 | (WHILE b DO c1 END) / st ==> (c1;; (WHILE b DO c1 END)) / st 89 | | CS_WhileFalse : forall st b c1, 90 | beval st b = false -> 91 | (WHILE b DO c1 END) / st ==> SKIP / st 92 | 93 | where " t '/' st '==>' t' '/' st' " := (cstep (t,st) (t',st')). 94 | -------------------------------------------------------------------------------- /MinimumLogic/Complete/Truth_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.FunctionalExtensionality. 2 | Require Import Coq.Logic.Classical_Prop. 3 | Require Import Coq.Logic.Classical_Pred_Type. 4 | Require Import Logic.lib.Bijection. 5 | Require Import Logic.lib.Countable. 6 | Require Import Logic.GeneralLogic.Base. 7 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 8 | Require Import Logic.GeneralLogic.KripkeModel. 9 | Require Import Logic.GeneralLogic.Semantics.Kripke. 10 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 11 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 12 | Require Import Logic.GeneralLogic.Complete.Lindenbaum. 13 | Require Import Logic.MinimumLogic.Syntax. 14 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 15 | Require Import Logic.MinimumLogic.Semantics.Kripke. 16 | 17 | Local Open Scope logic_base. 18 | Local Open Scope syntax. 19 | Local Open Scope kripke_model. 20 | Import KripkeModelFamilyNotation. 21 | Import KripkeModelNotation_Intuitionistic. 22 | 23 | Section TruthLemma. 24 | 25 | Context {L: Language} 26 | {minL: MinimumLanguage L} 27 | {Gamma: Derivable L} 28 | {bSC: BasicSequentCalculus L Gamma} 29 | {minSC: MinimumSequentCalculus L Gamma} 30 | {MD: Model} 31 | {kMD: KripkeModel MD} 32 | {M: Kmodel} 33 | {R: Relation (Kworlds M)} 34 | {SM: Semantics L MD} 35 | {kminSM: KripkeMinimumSemantics L MD M SM}. 36 | 37 | Context (cP: context -> Prop) 38 | (rel: bijection (Kworlds M) (sig cP)). 39 | 40 | Hypothesis H_R: forall m n Phi Psi, rel m Phi -> rel n Psi -> (m <= n <-> Included _ (proj1_sig Phi) (proj1_sig Psi)). 41 | 42 | Lemma truth_lemma_impp 43 | (AL_DC: at_least derivable_closed cP) 44 | (LIN_CD: forall x, Lindenbaum_constructable (cannot_derive x) cP) 45 | (x y: expr) 46 | (IHx: forall m Phi, rel m Phi -> (KRIPKE: M, m |= x <-> proj1_sig Phi x)) 47 | (IHy: forall m Phi, rel m Phi -> (KRIPKE: M, m |= y <-> proj1_sig Phi y)): 48 | forall m Phi, rel m Phi -> (KRIPKE: M, m |= x --> y <-> proj1_sig Phi (x --> y)). 49 | Proof. 50 | intros. 51 | rewrite sat_impp. 52 | split; intros. 53 | + rewrite derivable_closed_element_derivable by (apply AL_DC, (proj2_sig Phi)). 54 | rewrite <- deduction_theorem. 55 | apply NNPP; intro. 56 | apply LIN_CD in H1. 57 | destruct H1 as [Psi [? ?]]. 58 | apply H2; clear H2. 59 | assert (Included _ (proj1_sig Phi) (proj1_sig Psi)) by (intros ? ?; apply H1; left; auto). 60 | assert (proj1_sig Psi x) by (apply H1; right; constructor; auto). 61 | clear H1. 62 | destruct (su_bij _ _ rel Psi) as [n ?]. 63 | rewrite <- derivable_closed_element_derivable by (apply AL_DC, (proj2_sig Psi)). 64 | rewrite <- (IHx _ _ H1) in H3. 65 | rewrite <- (IHy _ _ H1). 66 | apply H0; auto. 67 | erewrite H_R by eauto. 68 | auto. 69 | + destruct (im_bij _ _ rel n) as [Psi ?]. 70 | rewrite (IHx _ _ H3) in H2. 71 | rewrite (IHy _ _ H3). 72 | rewrite derivable_closed_element_derivable in H2 |- * by (apply AL_DC, (proj2_sig Psi)). 73 | eapply deduction_modus_ponens; [exact H2 |]. 74 | rewrite <- derivable_closed_element_derivable by (apply AL_DC, (proj2_sig Psi)). 75 | erewrite H_R in H1 by eauto. 76 | apply H1; auto. 77 | Qed. 78 | 79 | End TruthLemma. 80 | 81 | 82 | -------------------------------------------------------------------------------- /MinimumLogic/ProofTheory/ExtensionTactic.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.lib.Coqlib. 2 | Require Import Logic.lib.Ensembles_ext. 3 | Require Export Logic.lib.register_typeclass. 4 | Require Import Logic.GeneralLogic.Base. 5 | Require Import Logic.GeneralLogic.ProofTheory.TheoryOfSequentCalculus. 6 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 7 | Require Import Logic.MinimumLogic.Syntax. 8 | Require Import Logic.MinimumLogic.ProofTheory.TheoryOfSequentCalculus. 9 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 10 | 11 | Inductive P2D_reg: Type :=. 12 | Inductive D2P_reg: Type :=. 13 | 14 | Ltac pose_proof_SC_instance n := 15 | let a := get_nth P2D_reg n in 16 | match a with 17 | | fun x: unit => ?T => 18 | try pose_proof_instance_as T x 19 | end. 20 | 21 | Ltac pose_proof_AX_instance n := 22 | let a := get_nth D2P_reg n in 23 | match a with 24 | | fun x: unit => ?T => 25 | try pose_proof_instance_as T x 26 | end. 27 | 28 | Ltac AddSequentCalculus := 29 | let AX := fresh "AX" in 30 | let GammaD := fresh "GammaD" in 31 | pose proof Provable2Derivable_Normal as AX; 32 | set (GammaD := Provable2Derivable) in AX; 33 | clearbody GammaD; 34 | rec_from_n (0%nat) pose_proof_SC_instance. 35 | 36 | Ltac AddAxiomatization := 37 | let SC := fresh "SC" in 38 | let GammaP := fresh "GammaP" in 39 | pose proof Derivable2Provable_Normal as SC; 40 | set (GammaP := Derivable2Provable) in SC; 41 | clearbody GammaP; 42 | rec_from_n (0%nat) pose_proof_AX_instance. 43 | 44 | Instance reg_Axiomatization2SequentCalculus_SC: 45 | RegisterClass P2D_reg (fun SC: unit => @Axiomatization2SequentCalculus_SC) 0. 46 | Qed. 47 | 48 | Instance reg_Axiomatization2SequentCalculus_bSC: 49 | RegisterClass P2D_reg (fun bSC: unit => @Axiomatization2SequentCalculus_bSC) 1. 50 | Qed. 51 | 52 | Instance reg_Axiomatization2SequentCalculus_fwSC: 53 | RegisterClass P2D_reg (fun fwSC: unit => @Axiomatization2SequentCalculus_fwSC) 2. 54 | Qed. 55 | 56 | Instance reg_Axiomatization2SequentCalculus_minSC: 57 | RegisterClass P2D_reg (fun minSC: unit => @Axiomatization2SequentCalculus_minSC) 3. 58 | Qed. 59 | 60 | Instance reg_SequentCalculus2Axiomatization_AX: 61 | RegisterClass D2P_reg (fun AX: unit => @SequentCalculus2Axiomatization_AX) 0. 62 | Qed. 63 | 64 | Instance reg_SequentCalculus2Axiomatization_minAX: 65 | RegisterClass D2P_reg (fun minAX: unit => @SequentCalculus2Axiomatization_minAX) 1. 66 | Qed. 67 | 68 | Section Test_AddSC. 69 | 70 | Context {L: Language} 71 | {minL: MinimumLanguage L} 72 | {Gamma: Provable L} 73 | {minAX: MinimumAxiomatization L Gamma}. 74 | 75 | Local Open Scope logic_base. 76 | Local Open Scope syntax. 77 | 78 | Lemma provable_impp_refl': forall (x: expr), |-- x --> x. 79 | Proof. 80 | AddSequentCalculus. 81 | Abort. 82 | 83 | End Test_AddSC. 84 | 85 | Section Test_AddAX. 86 | 87 | Context {L: Language} 88 | {minL: MinimumLanguage L} 89 | {Gamma: Derivable L} 90 | {bSC: BasicSequentCalculus L Gamma} 91 | {minSC: MinimumSequentCalculus L Gamma} 92 | {fwSC: FiniteWitnessedSequentCalculus L Gamma}. 93 | 94 | Local Open Scope logic_base. 95 | Local Open Scope syntax. 96 | 97 | Lemma derivable_axiom2': forall Phi (x y z: expr), Phi |-- (x --> y --> z) --> (x --> y) --> (x --> z). 98 | Proof. 99 | AddAxiomatization. 100 | Abort. 101 | 102 | End Test_AddAX. 103 | -------------------------------------------------------------------------------- /SeparationLogic/Model/UpwardsClosure.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Coqlib. 3 | Require Import Logic.GeneralLogic.KripkeModel. 4 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 5 | Require Import Logic.SeparationLogic.Model.OrderedSA. 6 | 7 | Local Open Scope kripke_model. 8 | Import KripkeModelNotation_Intuitionistic. 9 | 10 | Section UpwardsClosure. 11 | 12 | Context {worlds: Type} 13 | {R: Relation worlds} 14 | {po_R: PreOrder Krelation} 15 | {J: Join worlds} 16 | {SA: SeparationAlgebra worlds} 17 | {dSA: DownwardsClosedSeparationAlgebra worlds}. 18 | 19 | (** *Upwards CLosure*) 20 | Definition UpwardsClosure_J: Join worlds. 21 | Proof. intros m1 m2 m; exact (exists n, n <= m /\ join m1 m2 n). 22 | Defined. 23 | 24 | Definition UpwardsClosure_SA: 25 | @SeparationAlgebra worlds (UpwardsClosure_J). 26 | Proof. 27 | constructor. 28 | + intros. 29 | destruct H as [n [? ?]]. 30 | exists n. 31 | split; auto. 32 | apply join_comm; auto. 33 | + intros. 34 | rename mx into mx', my into my', mz into mz'. 35 | destruct H as [mxy' [? ?]]. 36 | destruct H0 as [mxyz' [? ?]]. 37 | destruct (join_Korder_down _ _ _ _ mz' H2 H) as [mxyz'' [? ?]]; [reflexivity |]. 38 | destruct (join_assoc _ _ _ _ _ H1 H3) as [myz' [? ?]]. 39 | exists myz'. 40 | split. 41 | - exists myz'; split; auto. 42 | reflexivity. 43 | - exists mxyz''; split; auto. 44 | etransitivity; eauto. 45 | Defined. 46 | 47 | Lemma UpwardsClosure_increasing: 48 | forall m, @increasing _ _ J m <-> @increasing _ _ (UpwardsClosure_J) m. 49 | Proof. 50 | intros. 51 | unfold increasing; split; intros. 52 | + destruct H0 as [n0 [? ?]]. 53 | etransitivity; eauto. 54 | + apply H. 55 | exists n'. 56 | split; auto. 57 | reflexivity. 58 | Qed. 59 | 60 | Definition UpwardsClosure_UpwardsClosed: 61 | @UpwardsClosedSeparationAlgebra worlds _ (UpwardsClosure_J). 62 | Proof. 63 | intros until m2; intros. 64 | exists m1, m2. 65 | split; [| split]; [| reflexivity | reflexivity]. 66 | destruct H as [n' [? ?]]. 67 | exists n'. 68 | split; auto; etransitivity; eauto. 69 | Defined. 70 | 71 | Definition UpwardsClosure_DownwardsClosed: 72 | @DownwardsClosedSeparationAlgebra worlds _ (UpwardsClosure_J). 73 | Proof. 74 | intros until n2; intros. 75 | simpl in *. 76 | destruct H as [n [? ?]]. 77 | destruct (join_Korder_down _ _ _ _ _ H2 H0 H1) as [n' [? ?]]. 78 | exists n; split; auto. 79 | exists n'; split; auto. 80 | Defined. 81 | 82 | Definition UpwardsClosure_USA {USA: UnitalSeparationAlgebra worlds}: 83 | @UnitalSeparationAlgebra worlds _ (UpwardsClosure_J). 84 | Proof. 85 | constructor. 86 | - intros. 87 | simpl. 88 | destruct (incr_exists n) as [u [? ?]]. 89 | destruct H as [n' [H1 H2]]. 90 | exists u; split; auto. 91 | + exists n'; split; auto. 92 | exists n; split; auto; reflexivity. 93 | + rewrite <- UpwardsClosure_increasing; auto. 94 | Defined. 95 | 96 | Definition UpwardsClosure_incrSA {incrSA: IncreasingSeparationAlgebra worlds}: 97 | @IncreasingSeparationAlgebra worlds _ (UpwardsClosure_J). 98 | Proof. 99 | constructor. 100 | simpl. 101 | intros. 102 | hnf; intros. 103 | destruct H as [m [? ?]]. 104 | etransitivity; eauto. 105 | eapply all_increasing; eauto. 106 | Qed. 107 | 108 | End UpwardsClosure. 109 | -------------------------------------------------------------------------------- /PropositionalLogic/ProofTheory/GodelDummett.v: -------------------------------------------------------------------------------- 1 | (* M. Dummett. A propositional calculus with denumerable matrix. J. Symbolic Logic, 24(2):97–106, 1959. *) 2 | (* K. G¨odel. On the intuitionistic propositional calculus. In S. Feferman, J. W. D. Jr, S. C. Kleene, G. H. Moore, R. M. Solovay, and J. van Heijenoort, editors, Collected Works, volume 1. Oxford University Press, 1986. *) 3 | 4 | Require Import Logic.GeneralLogic.Base. 5 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 6 | Require Import Logic.MinimumLogic.Syntax. 7 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 8 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 9 | Require Import Logic.MinimumLogic.ProofTheory.ExtensionTactic. 10 | Require Import Logic.PropositionalLogic.Syntax. 11 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 12 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 13 | 14 | Local Open Scope logic_base. 15 | Local Open Scope syntax. 16 | Import PropositionalLanguageNotation. 17 | 18 | Class GodelDummettPropositionalLogic (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} (Gamma: Provable L) {minAX: MinimumAxiomatization L Gamma} {ipAX: IntuitionisticPropositionalLogic L Gamma} := { 19 | impp_choice: forall x y, |-- (x --> y) || (y --> x) 20 | }. 21 | 22 | Section GodelDummett. 23 | 24 | Context {L: Language} 25 | {minL: MinimumLanguage L} 26 | {pL: PropositionalLanguage L} 27 | {Gamma: Provable L} 28 | {minAX: MinimumAxiomatization L Gamma} 29 | {ipAX: IntuitionisticPropositionalLogic L Gamma} 30 | {gdpAX: GodelDummettPropositionalLogic L Gamma}. 31 | (* 32 | Lemma derivable_impp_choice: forall (Phi: context) (x y: expr), 33 | Phi |-- (x --> y) || (y --> x). 34 | Proof. 35 | intros. 36 | pose proof impp_choice x. 37 | apply deduction_weaken0; auto. 38 | Qed. 39 | *) 40 | Instance GodelDummett2DeMorgan: DeMorganPropositionalLogic L Gamma. 41 | Proof. 42 | constructor. 43 | AddSequentCalculus. 44 | intros. 45 | rewrite provable_derivable. 46 | set (Phi := empty_context). 47 | clearbody Phi. 48 | 49 | pose proof impp_choice x (~~ x). 50 | apply deduction_weaken0 with (Phi0 := Phi) in H. 51 | 52 | assert (Phi |-- (x --> ~~ x) --> (x --> FF)). 53 | { 54 | rewrite <- deduction_theorem. 55 | rewrite <- deduction_theorem. 56 | eapply deduction_weaken with (Union _ (Union _ (Union _ Phi (Singleton _ (x --> ~~ x))) (Singleton _ x)) (Singleton _ x)). 57 | + intros y ?. 58 | destruct H0; [| right; auto]. 59 | destruct H0; [| right; auto]. 60 | left; auto. 61 | + rewrite deduction_theorem. 62 | rewrite deduction_theorem. 63 | apply derivable_assum1. 64 | } 65 | assert (Phi |-- (~~ x --> x) --> (~~ x --> FF)). 66 | { 67 | rewrite <- deduction_theorem. 68 | pose proof derivable_assum1 Phi (~~ x --> x). 69 | set (Psi := Union expr Phi (Singleton expr (~~ x --> x))) in H1 |- *; clearbody Psi. 70 | rewrite <- deduction_theorem in H1 |- *. 71 | pose proof derivable_assum1 Psi (~~ x). 72 | pose proof deduction_modus_ponens _ _ _ H1 H2. 73 | auto. 74 | } 75 | 76 | rewrite <- deduction_theorem in H0, H1. 77 | apply (deduction_orp_intros1 _ _ (~~ x --> FF)) in H0. 78 | apply (deduction_orp_intros2 _ (x --> FF)) in H1. 79 | rewrite deduction_theorem in H0, H1. 80 | pose proof deduction_orp_elim' _ _ _ _ H0 H1. 81 | pose proof deduction_modus_ponens _ _ _ H H2. 82 | auto. 83 | Qed. 84 | 85 | End GodelDummett. 86 | -------------------------------------------------------------------------------- /Extensions/ProofTheory/ModalSeparation.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.MinimumLogic.Syntax. 3 | Require Import Logic.PropositionalLogic.Syntax. 4 | Require Import Logic.ModalLogic.Syntax. 5 | Require Import Logic.SeparationLogic.Syntax. 6 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 7 | Require Import Logic.MinimumLogic.ProofTheory.RewriteClass. 8 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 9 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 10 | Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett. 11 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 12 | Require Import Logic.PropositionalLogic.ProofTheory.RewriteClass. 13 | Require Import Logic.ModalLogic.ProofTheory.ModalLogic. 14 | Require Import Logic.ModalLogic.ProofTheory.RewriteClass. 15 | Require Import Logic.SeparationLogic.ProofTheory.SeparationLogic. 16 | Require Import Logic.SeparationLogic.ProofTheory.DerivedRules. 17 | 18 | Local Open Scope logic_base. 19 | Local Open Scope syntax. 20 | Import PropositionalLanguageNotation. 21 | Import ModalLanguageNotation. 22 | Import SeparationLogicNotation. 23 | 24 | Class SeparationTransparentModality1 (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} {sepconL: SepconLanguage L} (Gamma: Provable L) := { 25 | sepcon_boxp: forall x y, |-- boxp x * boxp y --> boxp (x * y) 26 | }. 27 | 28 | Class SeparationTransparentModality2 (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} {sepconL: SepconLanguage L} (Gamma: Provable L) := { 29 | boxp_sepcon: forall x y, |-- boxp (x * y) --> boxp x * boxp y 30 | }. 31 | 32 | Class SeparationTransparentModality3 (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} {wandL: WandLanguage L} (Gamma: Provable L) := { 33 | wand_boxp: forall x y, |-- (boxp x -* boxp y) --> boxp (x -* y) 34 | }. 35 | 36 | Class SeparationTransparentModality4 (L: Language) {minL: MinimumLanguage L} {mL: ModalLanguage L} {wandL: WandLanguage L} (Gamma: Provable L) := { 37 | boxp_wand: forall x y, |-- boxp (x -* y) --> (boxp x -* boxp y) 38 | }. 39 | 40 | Instance SeparationTransparentModality14 (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {mL: ModalLanguage L} {sepconL: SepconLanguage L} {wandL: WandLanguage L} (Gamma: Provable L) {minAX: MinimumAxiomatization L Gamma} {ipGamma: IntuitionisticPropositionalLogic L Gamma} {KmGamma: SystemK L Gamma} {sepconAX: SepconAxiomatization L Gamma} {wandAX: WandAxiomatization L Gamma} {sm1Gamma: SeparationTransparentModality1 L Gamma}: 41 | SeparationTransparentModality4 L Gamma. 42 | Proof. 43 | constructor. 44 | intros. 45 | apply wand_sepcon_adjoint. 46 | rewrite sepcon_boxp. 47 | rewrite provable_wand_sepcon_modus_ponens1. 48 | apply provable_impp_refl. 49 | Qed. 50 | 51 | Instance SeparationTransparentModality41 (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} {mL: ModalLanguage L} {sepconL: SepconLanguage L} {wandL: WandLanguage L} (Gamma: Provable L) {minAX: MinimumAxiomatization L Gamma} {ipGamma: IntuitionisticPropositionalLogic L Gamma} {KmGamma: SystemK L Gamma} {sepconAX: SepconAxiomatization L Gamma} {wandAX: WandAxiomatization L Gamma} {sm4Gamma: SeparationTransparentModality4 L Gamma}: 52 | SeparationTransparentModality1 L Gamma. 53 | Proof. 54 | constructor. 55 | intros. 56 | apply wand_sepcon_adjoint. 57 | rewrite <- boxp_wand. 58 | eapply modus_ponens; [apply axiom_K |]. 59 | apply rule_N. 60 | apply wand_sepcon_adjoint. 61 | apply provable_impp_refl. 62 | Qed. 63 | -------------------------------------------------------------------------------- /HoareLogic/Sound_Frame.v: -------------------------------------------------------------------------------- 1 | Require Import Logic.GeneralLogic.Base. 2 | Require Import Logic.GeneralLogic.Semantics.Kripke. 3 | Require Import Logic.GeneralLogic.KripkeModel. 4 | Require Import Logic.MinimumLogic.Syntax. 5 | Require Import Logic.MinimumLogic.Semantics.Kripke. 6 | Require Import Logic.PropositionalLogic.Syntax. 7 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 8 | Require Import Logic.SeparationLogic.Syntax. 9 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 10 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 11 | Require Import Logic.HoareLogic.ImperativeLanguage. 12 | Require Import Logic.HoareLogic.ProgramState. 13 | Require Import Logic.HoareLogic.BigStepSemantics. 14 | Require Import Logic.HoareLogic.HoareTriple_BigStepSemantics. 15 | 16 | Local Open Scope logic_base. 17 | Local Open Scope syntax. 18 | Local Open Scope kripke_model. 19 | Import PropositionalLanguageNotation. 20 | Import SeparationLogicNotation. 21 | Import KripkeModelSingleNotation. 22 | Import KripkeModelNotation_Intuitionistic. 23 | 24 | Section soundness. 25 | 26 | Existing Instance unit_kMD. 27 | 28 | Context {P: ProgrammingLanguage} 29 | {MD: Model} 30 | {BSS: BigStepSemantics P model} 31 | {J: Join model} 32 | {R: Relation model} 33 | {po_R: PreOrder Krelation} 34 | {SA_BSS: SABigStepSemantics P model BSS}. 35 | 36 | Context {L: Language} 37 | {minL: MinimumLanguage L} 38 | {pL: PropositionalLanguage L} 39 | {sepconL: SepconLanguage L} 40 | {SM: Semantics L MD} 41 | {kiSM: KripkeIntuitionisticSemantics L MD tt SM} 42 | {fsepconSM: FlatSemantics.SepconSemantics L MD tt SM}. 43 | 44 | Lemma hoare_frame_partial_sound: forall c P Q F, 45 | triple_partial_valid P c Q -> 46 | triple_partial_valid (P * F) c (Q * F). 47 | Proof. 48 | intros. 49 | unfold triple_partial_valid in *. 50 | intros m' _n' ? ?. 51 | rewrite FlatSemantics.sat_sepcon in H0. 52 | destruct H0 as [m [mf [? [? ?]]]]. 53 | assert (SAFE: safe m c) by exact (H m Error H2). 54 | destruct (frame_property _ _ _ _ _ H0 H1) as [_n [nf [? [? ?]]]]. 55 | destruct _n' as [| | n']. 56 | + inversion H5; subst. 57 | revert H6; apply SAFE. 58 | + auto. 59 | + rewrite FlatSemantics.sat_sepcon. 60 | inversion H5; subst. 61 | - exfalso; revert H6; apply SAFE. 62 | - rename x into n. 63 | exists n, nf. 64 | split; [| split]; auto. 65 | * apply (H m _ H2 H6). 66 | * eapply sat_mono; eauto. 67 | Qed. 68 | 69 | Lemma hoare_frame_total_sound: forall c P Q F, 70 | triple_total_valid P c Q -> 71 | triple_total_valid (P * F) c (Q * F). 72 | Proof. 73 | intros. 74 | unfold triple_partial_valid in *. 75 | intros m' _n' ? ?. 76 | rewrite FlatSemantics.sat_sepcon in H0. 77 | destruct H0 as [m [mf [? [? ?]]]]. 78 | assert (SAFE: safe m c) by exact (H m Error H2). 79 | assert (TERM: term_norm m c) by exact (conj (H m Error H2) (H m NonTerminating H2)). 80 | destruct (frame_property _ _ _ _ _ H0 H1) as [_n [nf [? [? ?]]]]. 81 | destruct _n' as [| | n']. 82 | + inversion H5; subst. 83 | revert H6; apply SAFE. 84 | + inversion H5; subst. 85 | - revert H6; apply SAFE. 86 | - revert H6; apply TERM. 87 | + rewrite FlatSemantics.sat_sepcon. 88 | inversion H5; subst. 89 | - exfalso; revert H6; apply SAFE. 90 | - rename x into n. 91 | exists n, nf. 92 | split; [| split]; auto. 93 | * apply (H m _ H2 H6). 94 | * eapply sat_mono; eauto. 95 | Qed. 96 | 97 | End soundness. 98 | -------------------------------------------------------------------------------- /LogicGenerator/demo/implementation_1.v: -------------------------------------------------------------------------------- 1 | Require Import ZArith. 2 | 3 | Module NaiveLang. 4 | Definition expr := (nat -> option Z) -> Prop. 5 | Definition context := expr -> Prop. 6 | Definition impp (e1 e2 : expr) : expr := fun st => e1 st -> e2 st. 7 | Definition andp (e1 e2 : expr) : expr := fun st => e1 st /\ e2 st. 8 | Definition orp (e1 e2 : expr) : expr := fun st => e1 st \/ e2 st. 9 | Definition falsep : expr := fun st => False. 10 | 11 | Definition join : (nat -> option Z) -> (nat -> option Z) -> (nat -> option Z) -> Prop := 12 | fun x y z => 13 | forall p: nat, 14 | (exists v, x p = Some v /\ y p = None /\ z p = Some v) \/ 15 | (exists v, x p = None /\ y p = Some v /\ z p = Some v) \/ 16 | (x p = None /\ y p = None /\ z p = None). 17 | Definition sepcon (e1 e2 : expr) : expr := fun st => 18 | exists st1 st2, join st1 st2 st /\ e1 st1 /\ e2 st2. 19 | Definition emp : expr := fun st => 20 | forall p, st p = None. 21 | 22 | Definition provable (e : expr) : Prop := forall st, e st. 23 | End NaiveLang. 24 | 25 | Require Import interface_1. 26 | 27 | Module NaiveRule. 28 | Import NaiveLang. 29 | Include DerivedNames (NaiveLang). 30 | Lemma modus_ponens : 31 | forall x y : expr, provable (impp x y) -> provable x -> provable y. 32 | Proof. unfold provable, impp. auto. Qed. 33 | 34 | Lemma axiom1 : forall x y : expr, provable (impp x (impp y x)). 35 | Proof. unfold provable, impp. auto. Qed. 36 | 37 | Lemma axiom2 : forall x y z : expr, 38 | provable (impp (impp x (impp y z)) (impp (impp x y) (impp x z))). 39 | Proof. unfold provable, impp. auto. Qed. 40 | 41 | Lemma andp_intros : 42 | forall x y : expr, provable (impp x (impp y (andp x y))). 43 | Proof. unfold provable, impp, andp. auto. Qed. 44 | 45 | Lemma andp_elim1 : forall x y : expr, provable (impp (andp x y) x). 46 | Proof. unfold provable, impp, andp. tauto. Qed. 47 | 48 | Lemma andp_elim2 : forall x y : expr, provable (impp (andp x y) y). 49 | Proof. unfold provable, impp, andp. tauto. Qed. 50 | 51 | Lemma orp_intros1 : forall x y : expr, provable (impp x (orp x y)). 52 | Proof. unfold provable, impp, orp. auto. Qed. 53 | 54 | Lemma orp_intros2 : forall x y : expr, provable (impp y (orp x y)). 55 | Proof. unfold provable, impp, orp. auto. Qed. 56 | 57 | Lemma orp_elim : forall x y z : expr, 58 | provable (impp (impp x z) (impp (impp y z) (impp (orp x y) z))). 59 | Proof. unfold provable, impp, orp. tauto. Qed. 60 | 61 | Lemma falsep_elim : forall x : expr, provable (impp falsep x). 62 | Proof. unfold provable, impp, falsep. destruct 1. Qed. 63 | 64 | Lemma excluded_middle : forall x : expr, provable (orp x (negp x)). 65 | Proof. unfold provable, orp, negp, impp, falsep. intros; tauto. Qed. 66 | 67 | Axiom sepcon_comm: forall x y, provable (iffp (sepcon x y) (sepcon y x)). 68 | Axiom sepcon_assoc: forall x y z, 69 | provable (iffp (sepcon x (sepcon y z)) (sepcon (sepcon x y) z)). 70 | Axiom sepcon_mono : (forall x1 x2 y1 y2 : expr, provable (impp x1 x2) -> provable (impp y1 y2) -> provable (impp (sepcon x1 y1) (sepcon x2 y2))) . 71 | Axiom sepcon_emp : (forall x : expr, provable (iffp (sepcon x emp) x)) . 72 | Axiom falsep_sepcon_left : (forall x : expr, provable (impp (sepcon falsep x) falsep)) . 73 | Axiom orp_sepcon_left : (forall x y z : expr, provable (impp (sepcon (orp x y) z) (orp (sepcon x z) (sepcon y z)))) . 74 | End NaiveRule. 75 | 76 | Module T := LogicTheorem NaiveLang NaiveRule. 77 | Module Solver := IPSolver NaiveLang. 78 | Import T. 79 | Import Solver. 80 | 81 | 82 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/StrongSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Coq.Sets.Ensembles. 5 | Require Import Logic.lib.Coqlib. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 8 | Require Import Logic.SeparationLogic.Model.OrderedSA. 9 | 10 | Local Open Scope kripke_model. 11 | Import KripkeModelNotation_Intuitionistic. 12 | 13 | Module StrongSemantics. 14 | 15 | Definition sepcon {worlds: Type} {R: Relation worlds} {J: Join worlds} (X: Ensemble worlds) (Y: Ensemble worlds): Ensemble worlds := 16 | fun m => exists m0 m1 m2, m0 <= m /\ join m1 m2 m0 /\ X m1 /\ Y m2. 17 | 18 | Definition wand {worlds: Type} {R: Relation worlds} {J: Join worlds} (X: Ensemble worlds) (Y: Ensemble worlds): Ensemble worlds := 19 | fun m => forall m0 m1 m2, m <= m0 -> join m0 m1 m2 -> X m1 -> Y m2. 20 | 21 | Definition emp {worlds: Type} {R: Relation worlds} {J: Join worlds}: Ensemble worlds := increasing'. 22 | 23 | Lemma sepcon_closed 24 | {worlds: Type} 25 | {R: Relation worlds} 26 | {po_R: PreOrder Krelation} 27 | {J: Join worlds}: 28 | forall (X: Ensemble worlds) (Y: Ensemble worlds), 29 | upwards_closed_Kdenote X -> 30 | upwards_closed_Kdenote Y -> 31 | upwards_closed_Kdenote (sepcon X Y). 32 | Proof. 33 | intros. 34 | hnf; intros. 35 | hnf in H2 |- *. 36 | destruct H2 as [n0 [n1 [n2 [? [? [? ?]]]]]]. 37 | exists n0, n1, n2; split; [| split; [| split]]; auto. 38 | etransitivity; eauto. 39 | Qed. 40 | 41 | Lemma wand_closed 42 | {worlds: Type} 43 | {R: Relation worlds} 44 | {po_R: PreOrder Krelation} 45 | {J: Join worlds}: 46 | forall (X: Ensemble worlds) (Y: Ensemble worlds), 47 | upwards_closed_Kdenote X -> 48 | upwards_closed_Kdenote Y -> 49 | upwards_closed_Kdenote (wand X Y). 50 | Proof. 51 | intros. 52 | hnf; intros. 53 | hnf in H2 |- *. 54 | intros ? ? ? ?; apply H2. 55 | etransitivity; eauto. 56 | Qed. 57 | 58 | Lemma emp_closed 59 | {worlds: Type} 60 | {R: Relation worlds} 61 | {po_R: PreOrder Krelation} 62 | {J: Join worlds}: 63 | upwards_closed_Kdenote emp. 64 | Proof. 65 | intros. 66 | hnf; intros. 67 | hnf in H0 |- *. 68 | intros ? ?; apply H0. 69 | etransitivity; eauto. 70 | Qed. 71 | 72 | End StrongSemantics. 73 | 74 | Module StrongSemanticsMono. 75 | 76 | Program Definition sepcon 77 | {worlds: Type} 78 | {R: Relation worlds} 79 | {po_R: PreOrder Krelation} 80 | {J: Join worlds} 81 | (X Y: MonoEnsemble worlds): MonoEnsemble worlds := 82 | StrongSemantics.sepcon X Y. 83 | Next Obligation. 84 | apply (@StrongSemantics.sepcon_closed worlds R po_R J); 85 | apply (proj2_sig _). 86 | Defined. 87 | 88 | Program Definition wand 89 | {worlds: Type} 90 | {R: Relation worlds} 91 | {po_R: PreOrder Krelation} 92 | {J: Join worlds} 93 | (X Y: MonoEnsemble worlds): MonoEnsemble worlds := 94 | StrongSemantics.wand X Y. 95 | Next Obligation. 96 | apply (@StrongSemantics.wand_closed worlds R po_R J); 97 | apply (proj2_sig _). 98 | Defined. 99 | 100 | Program Definition emp 101 | {worlds: Type} 102 | {R: Relation worlds} 103 | {po_R: PreOrder Krelation} 104 | {J: Join worlds}: MonoEnsemble worlds := 105 | StrongSemantics.emp. 106 | Next Obligation. 107 | apply (@StrongSemantics.emp_closed worlds R po_R J); 108 | apply (proj2_sig _). 109 | Defined. 110 | 111 | End StrongSemanticsMono. 112 | -------------------------------------------------------------------------------- /SeparationLogic/Model/DownwardsClosure.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Logic.lib.Coqlib. 3 | Require Import Logic.GeneralLogic.KripkeModel. 4 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 5 | Require Import Logic.SeparationLogic.Model.OrderedSA. 6 | 7 | Local Open Scope kripke_model. 8 | Import KripkeModelNotation_Intuitionistic. 9 | 10 | Section DownwardsClosure. 11 | 12 | Context {worlds : Type} 13 | {R: Relation worlds} 14 | {po_R: PreOrder Krelation} 15 | {J: Join worlds} 16 | {SA: SeparationAlgebra worlds} 17 | {uSA: UpwardsClosedSeparationAlgebra worlds}. 18 | 19 | (** *Downwards CLosure*) 20 | 21 | Definition DownwardsClosure_J: Join worlds. 22 | Proof. exact (fun m1 m2 m: worlds => exists n1 n2, m1 <= n1 /\ m2 <= n2 /\ join n1 n2 m). 23 | Defined. 24 | 25 | Definition DownwardsClosure_SA: 26 | @SeparationAlgebra worlds (DownwardsClosure_J). 27 | Proof. 28 | constructor. 29 | + (* join_comm *) 30 | intros. 31 | destruct H as [n1 [n2 [? [? ?]]]]. 32 | exists n2, n1. 33 | split; [| split]; auto. 34 | apply join_comm; auto. 35 | + (* join_assoc *) 36 | intros. 37 | destruct H as [mx'' [my'' [? [? ?]]]]. 38 | destruct H0 as [mxy' [mz' [? [? ?]]]]. 39 | destruct (join_Korder_up _ _ _ _ H2 H0) as [mx' [my' [? [? ?]]]]. 40 | destruct (join_assoc _ _ _ _ _ H5 H4) as [myz' [? ?]]. 41 | exists myz'. 42 | split. 43 | - exists my', mz'; split; [| split]; auto. 44 | etransitivity; eauto. 45 | - exists mx', myz'; split; [| split]; auto. 46 | * etransitivity; eauto. 47 | * reflexivity. 48 | Defined. 49 | 50 | Lemma DownwardsClosure_increasing: forall m, @increasing' _ _ J m <-> @increasing _ _ (DownwardsClosure_J) m. 51 | Proof. 52 | intros. 53 | unfold increasing', increasing; split; intros. 54 | + destruct H0 as [m0 [n0 [? [? ?]]]]. 55 | etransitivity; [eassumption |]. 56 | eapply H; [| eassumption]. 57 | auto. 58 | + apply H. 59 | exists n, n0. 60 | split; [| split]; auto; reflexivity. 61 | Qed. 62 | 63 | Definition DownwardsClosure_DownwardsClosed: 64 | @DownwardsClosedSeparationAlgebra worlds _ (DownwardsClosure_J). 65 | Proof. 66 | intros until n2; intros. 67 | exists m. 68 | split; [| reflexivity]. 69 | destruct H as [m1' [m2' [? [? ?]]]]. 70 | exists m1', m2'. 71 | split; [| split]; auto; etransitivity; eauto. 72 | Qed. 73 | 74 | Definition DownwardsClosure_UpwardsClosed : @UpwardsClosedSeparationAlgebra worlds _ (DownwardsClosure_J). 75 | Proof. 76 | intros until m2; intros. 77 | simpl in *. 78 | destruct H as [n1 [n2 [? [? ?]]]]. 79 | destruct (join_Korder_up _ _ _ _ H2 H0) as [n1' [n2' [? [? ?]]]]. 80 | exists n1, n2; split; [| split]; auto. 81 | exists n1', n2'; split; [| split]; auto. 82 | Qed. 83 | 84 | Definition DownwardsClosure_USA {USA': UnitalSeparationAlgebra' worlds}: @UnitalSeparationAlgebra worlds _ (DownwardsClosure_J). 85 | Proof. 86 | constructor. 87 | intros. 88 | destruct (incr'_exists n) as [u [? ?]]. 89 | destruct H as [n' [H1 H2]]. 90 | exists u; split; auto. 91 | + exists n'; split; auto. 92 | exists u, n'; split; [| split]; auto; reflexivity. 93 | + rewrite <- DownwardsClosure_increasing; auto. 94 | Defined. 95 | 96 | Definition DownwardsClosure_incrSA {incrSA: IncreasingSeparationAlgebra worlds}: @IncreasingSeparationAlgebra worlds _ (DownwardsClosure_J). 97 | Proof. 98 | constructor. 99 | simpl. 100 | intros. 101 | hnf; intros. 102 | destruct H as [n1 [n2 [? [? ?]]]]. 103 | etransitivity; [eauto |]. 104 | eapply all_increasing; eauto. 105 | Qed. 106 | 107 | End DownwardsClosure. 108 | -------------------------------------------------------------------------------- /PropositionalLogic/Complete/Truth_Kripke.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.FunctionalExtensionality. 2 | Require Import Coq.Logic.Classical_Prop. 3 | Require Import Coq.Logic.Classical_Pred_Type. 4 | Require Import Logic.lib.Bijection. 5 | Require Import Logic.lib.Countable. 6 | Require Import Logic.GeneralLogic.Base. 7 | Require Import Logic.GeneralLogic.KripkeModel. 8 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 9 | Require Import Logic.GeneralLogic.Semantics.Kripke. 10 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 11 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 12 | Require Import Logic.MinimumLogic.Syntax. 13 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 14 | Require Import Logic.MinimumLogic.Semantics.Kripke. 15 | Require Import Logic.MinimumLogic.Complete.ContextProperty_Kripke. 16 | Require Import Logic.PropositionalLogic.Syntax. 17 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 18 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 19 | Require Import Logic.PropositionalLogic.Complete.ContextProperty_Kripke. 20 | 21 | Local Open Scope logic_base. 22 | Local Open Scope syntax. 23 | Local Open Scope kripke_model. 24 | Import PropositionalLanguageNotation. 25 | Import KripkeModelFamilyNotation. 26 | Import KripkeModelNotation_Intuitionistic. 27 | 28 | Section TruthLemma. 29 | 30 | Context {L: Language} 31 | {minL: MinimumLanguage L} 32 | {pL: PropositionalLanguage L} 33 | {Gamma: Derivable L} 34 | {bSC: BasicSequentCalculus L Gamma} 35 | {minSC: MinimumSequentCalculus L Gamma} 36 | {ipSC: IntuitionisticPropositionalSequentCalculus L Gamma} 37 | {MD: Model} 38 | {kMD: KripkeModel MD} 39 | {M: Kmodel} 40 | {R: Relation (Kworlds M)} 41 | {SM: Semantics L MD} 42 | {kminSM: KripkeMinimumSemantics L MD M SM} 43 | {kpSM: KripkePropositionalSemantics L MD M SM}. 44 | 45 | Context (P: context -> Prop) 46 | (rel: bijection (Kworlds M) (sig P)). 47 | 48 | Hypothesis H_R: forall m n Phi Psi, rel m Phi -> rel n Psi -> (m <= n <-> Included _ (proj1_sig Phi) (proj1_sig Psi)). 49 | 50 | Lemma truth_lemma_falsep (AL_CONSI: at_least consistent P): 51 | forall m Phi, rel m Phi -> (KRIPKE: M, m |= falsep <-> proj1_sig Phi falsep). 52 | Proof. 53 | intros. 54 | rewrite sat_falsep. 55 | pose proof proj2_sig Phi. 56 | pose proof AL_CONSI _ H0. 57 | rewrite consistent_spec in H1. 58 | split; [intros [] |]. 59 | intro; apply H1. 60 | apply derivable_assum; auto. 61 | Qed. 62 | 63 | Lemma truth_lemma_andp 64 | (AL_DC: at_least derivable_closed P) 65 | (x y: expr) 66 | (IHx: forall m Phi, rel m Phi -> (KRIPKE: M, m |= x <-> proj1_sig Phi x)) 67 | (IHy: forall m Phi, rel m Phi -> (KRIPKE: M, m |= y <-> proj1_sig Phi y)): 68 | forall m Phi, rel m Phi -> (KRIPKE: M, m |= x && y <-> proj1_sig Phi (x && y)). 69 | Proof. 70 | intros. 71 | rewrite sat_andp. 72 | rewrite DCS_andp_iff by (apply AL_DC, (proj2_sig Phi)). 73 | apply Morphisms_Prop.and_iff_morphism; auto. 74 | Qed. 75 | 76 | Lemma truth_lemma_orp 77 | (AL_DC: at_least derivable_closed P) 78 | (AL_OW: at_least orp_witnessed P) 79 | (x y: expr) 80 | (IHx: forall m Phi, rel m Phi -> (KRIPKE: M, m |= x <-> proj1_sig Phi x)) 81 | (IHy: forall m Phi, rel m Phi -> (KRIPKE: M, m |= y <-> proj1_sig Phi y)): 82 | forall m Phi, rel m Phi -> (KRIPKE: M, m |= x || y <-> proj1_sig Phi (x || y)). 83 | Proof. 84 | intros. 85 | rewrite sat_orp. 86 | rewrite DCS_orp_iff. 87 | 2: apply AL_DC, (proj2_sig Phi). 88 | 2: apply AL_OW, (proj2_sig Phi). 89 | apply Morphisms_Prop.or_iff_morphism; auto. 90 | Qed. 91 | 92 | End TruthLemma. 93 | 94 | 95 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/Down2Flat.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.RelationClasses. 2 | Require Import Coq.Relations.Relation_Definitions. 3 | Require Import Logic.lib.Coqlib. 4 | Require Import Logic.lib.Ensembles_ext. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | Require Import Logic.GeneralLogic.Semantics.Kripke. 8 | Require Import Logic.MinimumLogic.Syntax. 9 | Require Import Logic.MinimumLogic.Semantics.Kripke. 10 | Require Import Logic.PropositionalLogic.Syntax. 11 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 12 | Require Import Logic.SeparationLogic.Syntax. 13 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 14 | Require Import Logic.SeparationLogic.Model.OrderedSA. 15 | Require Import Logic.SeparationLogic.Model.UpwardsClosure. 16 | Require Import Logic.SeparationLogic.Semantics.WeakSemantics. 17 | Require Import Logic.SeparationLogic.Semantics.StrongSemantics. 18 | Require Import Logic.SeparationLogic.Semantics.DownwardsSemantics. 19 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 20 | 21 | Local Open Scope logic_base. 22 | Local Open Scope syntax. 23 | Local Open Scope kripke_model. 24 | Import PropositionalLanguageNotation. 25 | Import SeparationLogicNotation. 26 | Import KripkeModelFamilyNotation. 27 | Import KripkeModelNotation_Intuitionistic. 28 | 29 | Module Down2Flat. 30 | Section Down2Flat. 31 | 32 | Context {L: Language} 33 | {minL: MinimumLanguage L} 34 | {pL: PropositionalLanguage L} 35 | {sepconL: SepconLanguage L} 36 | {wandL: WandLanguage L} 37 | {MD: Model} 38 | {kMD: KripkeModel MD} 39 | {M: Kmodel} 40 | {R: Relation (Kworlds M)} 41 | {po_R: PreOrder Krelation} 42 | {J: Join (Kworlds M)} 43 | {SA: SeparationAlgebra (Kworlds M)} 44 | {dSA: DownwardsClosedSeparationAlgebra (Kworlds M)} 45 | {SM: Semantics L MD} 46 | {kiSM: KripkeIntuitionisticSemantics L MD M SM} 47 | {dsepconSM: DownwardsSemantics.SepconSemantics L MD M SM} 48 | {dwandSM: DownwardsSemantics.WandSemantics L MD M SM}. 49 | 50 | Definition fsepconSM: @FlatSemantics.SepconSemantics L _ MD _ M _ UpwardsClosure_J SM. 51 | Proof. 52 | hnf; intros. 53 | unfold WeakSemantics.sepcon. 54 | split; unfold Included, Ensembles.In; intros m ?. 55 | + rewrite (app_same_set (DownwardsSemantics.denote_sepcon _ _) m) in H. 56 | destruct H as [m0 [m1 [m2 [? [? [? ?]]]]]]. 57 | exists m1, m2. 58 | split; [| split]; auto. 59 | exists m0; split; auto. 60 | + rewrite (app_same_set (DownwardsSemantics.denote_sepcon _ _) m). 61 | destruct H as [m1 [m2 [[n [? ?]] [? ?]]]]. 62 | exists n, m1, m2. 63 | split; [| split; [| split]]; auto. 64 | Qed. 65 | 66 | Definition fwandSM: @FlatSemantics.WandSemantics L _ MD _ M _ UpwardsClosure_J SM. 67 | Proof. 68 | hnf; intros. 69 | unfold WeakSemantics.wand. 70 | split; unfold Included, Ensembles.In; intros m ?. 71 | + rewrite (app_same_set (DownwardsSemantics.denote_wand _ _) m) in H. 72 | intros. 73 | destruct H0 as [m2' [? ?]]. 74 | eapply sat_mono; eauto. 75 | eapply H; eauto. 76 | + rewrite (app_same_set (DownwardsSemantics.denote_wand _ _) m). 77 | hnf; intros. 78 | apply (H m1 m2); auto. 79 | exists m2; split; auto. 80 | reflexivity. 81 | Qed. 82 | 83 | Definition feSM {empL: EmpLanguage L} {USA: UnitalSeparationAlgebra (Kworlds M)} {dempSM: DownwardsSemantics.EmpSemantics L MD M SM}: @FlatSemantics.EmpSemantics L _ MD _ M _ UpwardsClosure_J SM. 84 | Proof. 85 | split; intros m; unfold Ensembles.In; unfold WeakSemantics.emp; 86 | rewrite <- UpwardsClosure_increasing; 87 | apply DownwardsSemantics.denote_emp. 88 | Qed. 89 | 90 | End Down2Flat. 91 | End Down2Flat. 92 | -------------------------------------------------------------------------------- /PropositionalLogic/DeepEmbedded/KripkeSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Logic.lib.Ensembles_ext. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | Require Import Logic.GeneralLogic.Semantics.Kripke. 8 | Require Import Logic.MinimumLogic.Syntax. 9 | Require Import Logic.MinimumLogic.Semantics.Kripke. 10 | Require Import Logic.PropositionalLogic.Syntax. 11 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 12 | Require Import Logic.PropositionalLogic.DeepEmbedded.PropositionalLanguage. 13 | 14 | Import PropositionalLanguage. 15 | 16 | Record frame: Type := { 17 | underlying_set:> Type; 18 | underlying_relation: relation underlying_set 19 | }. 20 | 21 | Declare Scope TheKripkeSemantics. 22 | Infix "<=" := (underlying_relation _): TheKripkeSemantics. 23 | 24 | Local Open Scope TheKripkeSemantics. 25 | 26 | Definition sem (f: frame) := @Ensemble (underlying_set f). 27 | 28 | Section KripkeSemantics. 29 | 30 | Context {Sigma: PropositionalVariables}. 31 | 32 | Definition denotation (F: frame) (eval: Var -> sem F): expr Sigma -> sem F := 33 | fix denotation (x: expr Sigma): sem F:= 34 | match x with 35 | | andp y z => @Semantics.andp F (denotation y) (denotation z) 36 | | orp y z => @Semantics.orp F (denotation y) (denotation z) 37 | | impp y z => @Semantics.impp F (underlying_relation F) (denotation y) (denotation z) 38 | | falsep => @Semantics.falsep F 39 | | varp p => eval p 40 | end. 41 | 42 | Record Kmodel : Type := { 43 | underlying_frame :> frame; 44 | sem_var: Var -> sem underlying_frame 45 | }. 46 | 47 | Record model: Type := { 48 | underlying_model :> Kmodel; 49 | elm: underlying_model 50 | }. 51 | 52 | Instance MD: Model := Build_Model model. 53 | 54 | Instance kMD: KripkeModel MD := 55 | Build_KripkeModel _ 56 | Kmodel 57 | (fun M => M) 58 | (fun M m => Build_model M m). 59 | 60 | Instance R (M: Kmodel): Relation (Kworlds M) := 61 | @underlying_relation M. 62 | 63 | Definition Kmodel_Monotonic: Kmodel -> Prop := fun M => 64 | forall v: Var, upwards_closed_Kdenote (sem_var M v). 65 | 66 | Definition Kmodel_PreOrder: Kmodel -> Prop := fun M => 67 | PreOrder (@Krelation _ (R M)). 68 | 69 | Definition Kmodel_Identity: Kmodel -> Prop := fun M => 70 | IdentityKripkeIntuitionisticModel (Kworlds M). 71 | 72 | Definition Kmodel_NoBranch: Kmodel -> Prop := fun M => 73 | NoBranchKripkeIntuitionisticModel (Kworlds M). 74 | 75 | Definition Kmodel_BranchJoin: Kmodel -> Prop := fun M => 76 | BranchJoinKripkeIntuitionisticModel (Kworlds M). 77 | 78 | Instance SM: Semantics L MD := 79 | Build_Semantics L MD (fun x M => (denotation M (sem_var M) x) (elm M)). 80 | 81 | Instance kiSM (M: Kmodel) {_: Kmodel_Monotonic M} {_: Kmodel_PreOrder M}: 82 | KripkeIntuitionisticSemantics L MD M SM. 83 | Proof. 84 | hnf in H, H0. 85 | constructor; intros. 86 | induction x. 87 | + apply Semantics.andp_closed; auto. 88 | + apply Semantics.orp_closed; auto. 89 | + apply (Semantics.impp_closed _ _ IHx1 IHx2). 90 | + apply Semantics.falsep_closed. 91 | + apply H. 92 | Qed. 93 | 94 | Instance kminSM (M: Kmodel): KripkeMinimumSemantics L MD M SM. 95 | Proof. 96 | apply Build_KripkeMinimumSemantics. 97 | intros; apply Same_set_refl. 98 | Defined. 99 | 100 | Instance kpSM (M: Kmodel): KripkePropositionalSemantics L MD M SM. 101 | Proof. 102 | apply Build_KripkePropositionalSemantics. 103 | + intros; apply Same_set_refl. 104 | + intros; apply Same_set_refl. 105 | + intros; apply Same_set_refl. 106 | Defined. 107 | 108 | End KripkeSemantics. 109 | -------------------------------------------------------------------------------- /ModalLogic/Sound/Sound_Flat.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Logic.Classical_Pred_Type. 3 | Require Import Logic.lib.Ensembles_ext. 4 | Require Import Logic.GeneralLogic.Base. 5 | Require Import Logic.GeneralLogic.KripkeModel. 6 | Require Import Logic.GeneralLogic.Semantics.Kripke. 7 | Require Import Logic.MinimumLogic.Syntax. 8 | Require Import Logic.MinimumLogic.Semantics.Kripke. 9 | Require Import Logic.PropositionalLogic.Syntax. 10 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 11 | Require Import Logic.ModalLogic.Syntax. 12 | Require Import Logic.ModalLogic.Model.KripkeModel. 13 | Require Import Logic.ModalLogic.Model.OrderedKripkeModel. 14 | Require Import Logic.ModalLogic.Semantics.Flat. 15 | 16 | Local Open Scope logic_base. 17 | Local Open Scope syntax. 18 | Local Open Scope kripke_model. 19 | Import PropositionalLanguageNotation. 20 | Import ModalLanguageNotation. 21 | Import KripkeModelFamilyNotation. 22 | Import KripkeModelNotation_Intuitionistic. 23 | 24 | Section Sound_Flat. 25 | 26 | Context {L: Language} 27 | {minL: MinimumLanguage L} 28 | {pL: PropositionalLanguage L} 29 | {mL: ModalLanguage L} 30 | {MD: Model} 31 | {kMD: KripkeModel MD} 32 | {M: Kmodel} 33 | {R1: KI.Relation (Kworlds M)} 34 | {po_R1: PreOrder KI.Krelation} 35 | {R2: KM.Relation (Kworlds M)} 36 | {ukmM: UpwardsClosedOrderedKripkeModel (Kworlds M)} 37 | {SM: Semantics L MD} 38 | {kiSM: KripkeIntuitionisticSemantics L MD M SM} 39 | {kminSM: KripkeMinimumSemantics L MD M SM} 40 | {kpSM: KripkePropositionalSemantics L MD M SM} 41 | {fmSM: FlatModalSemantics L MD M SM}. 42 | 43 | Lemma sound_axiom_K : 44 | forall x y (m: Kworlds M), 45 | KRIPKE: M, m |= boxp (x --> y) --> (boxp x --> boxp y). 46 | Proof. 47 | intros. 48 | rewrite sat_impp. 49 | intros m' ? ?. 50 | rewrite sat_impp. 51 | intros m'' ? ?. 52 | rewrite sat_boxp in H0, H2 |- *. 53 | intros n'' ?. 54 | destruct (KM_relation_up _ _ _ H1 H3) as [n' [? ?]]. 55 | specialize (H2 _ H3). 56 | specialize (H0 _ H5). 57 | rewrite sat_impp in H0. 58 | exact (H0 n'' H4 H2). 59 | Qed. 60 | 61 | Lemma sound_rule_N: 62 | forall x, 63 | (forall (m: Kworlds M), KRIPKE: M, m |= x) -> 64 | (forall (m: Kworlds M), KRIPKE: M, m |= boxp x). 65 | Proof. 66 | intros. 67 | rewrite sat_boxp. 68 | intros; apply H; auto. 69 | Qed. 70 | 71 | Lemma sound_boxp_orp {pf_R2: PartialFunctional KM.Krelation}: 72 | forall x y (m: Kworlds M), 73 | KRIPKE: M, m |= boxp (x || y) <--> (boxp x || boxp y). 74 | Proof. 75 | intros. 76 | unfold iffp. 77 | rewrite sat_andp, !sat_impp. 78 | split; intros ? ?. 79 | + clear m H. 80 | rewrite sat_orp. 81 | rewrite !sat_boxp. 82 | intros; apply NNPP. 83 | intro. 84 | apply not_or_and in H0; destruct H0. 85 | apply not_all_ex_not in H0; destruct H0 as [n1 ?]. 86 | apply not_all_ex_not in H1; destruct H1 as [n2 ?]. 87 | apply imply_to_and in H0; destruct H0. 88 | apply imply_to_and in H1; destruct H1. 89 | pose proof partial_functionality _ _ _ H0 H1. 90 | subst n2; clear H1. 91 | specialize (H _ H0). 92 | rewrite sat_orp in H. 93 | tauto. 94 | + rewrite sat_orp, !sat_boxp. 95 | intros; rewrite sat_orp. 96 | destruct H0; [left | right]; auto. 97 | Qed. 98 | 99 | (* (boxp x --> boxp y) --> (boxp (x --> y)) is not sound in non-classical transparent modal logic *) 100 | (* e.g. (boxp (x |--> 1) --> boxp (x |--> 1 * y |--> 1)) --> *) 101 | (* boxp (x |--> 1 --> x |--> 1 * y |--> 1) is not valid on monotonic heap *) 102 | 103 | End Sound_Flat. 104 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/Up2Flat.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Classes.RelationClasses. 2 | Require Import Coq.Relations.Relation_Definitions. 3 | Require Import Logic.lib.Coqlib. 4 | Require Import Logic.lib.Ensembles_ext. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.GeneralLogic.KripkeModel. 7 | Require Import Logic.GeneralLogic.Semantics.Kripke. 8 | Require Import Logic.MinimumLogic.Syntax. 9 | Require Import Logic.MinimumLogic.Semantics.Kripke. 10 | Require Import Logic.PropositionalLogic.Syntax. 11 | Require Import Logic.PropositionalLogic.Semantics.Kripke. 12 | Require Import Logic.SeparationLogic.Syntax. 13 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 14 | Require Import Logic.SeparationLogic.Model.OrderedSA. 15 | Require Import Logic.SeparationLogic.Model.DownwardsClosure. 16 | Require Import Logic.SeparationLogic.Semantics.WeakSemantics. 17 | Require Import Logic.SeparationLogic.Semantics.StrongSemantics. 18 | Require Import Logic.SeparationLogic.Semantics.UpwardsSemantics. 19 | Require Import Logic.SeparationLogic.Semantics.FlatSemantics. 20 | 21 | Local Open Scope logic_base. 22 | Local Open Scope syntax. 23 | Local Open Scope kripke_model. 24 | Import PropositionalLanguageNotation. 25 | Import SeparationLogicNotation. 26 | Import KripkeModelFamilyNotation. 27 | 28 | Module Up2Flat. 29 | Section Up2Flat. 30 | 31 | Context {L: Language} 32 | {minL: MinimumLanguage L} 33 | {pL: PropositionalLanguage L} 34 | {sepconL: SepconLanguage L} 35 | {wandL: WandLanguage L} 36 | {MD: Model} 37 | {kMD: KripkeModel MD} 38 | {M: Kmodel} 39 | {R: Relation (Kworlds M)} 40 | {po_R: PreOrder Krelation} 41 | {J: Join (Kworlds M)} 42 | {SA: SeparationAlgebra (Kworlds M)} 43 | {uSA: UpwardsClosedSeparationAlgebra (Kworlds M)} 44 | {SM: Semantics L MD} 45 | {kiSM: KripkeIntuitionisticSemantics L MD M SM} 46 | {usepconSM: UpwardsSemantics.SepconSemantics L MD M SM} 47 | {uwandSM: UpwardsSemantics.WandSemantics L MD M SM}. 48 | 49 | Definition fwandSM: @FlatSemantics.WandSemantics L wandL MD kMD M _ (DownwardsClosure_J) SM. 50 | Proof. 51 | hnf; intros. 52 | unfold WeakSemantics.wand. 53 | split; unfold Included, Ensembles.In; intros m ?. 54 | + rewrite (app_same_set (UpwardsSemantics.denote_wand _ _) m) in H. 55 | intros. 56 | destruct H0 as [m' [m1' [? [? ?]]]]. 57 | apply (H _ _ _ H0 H3). 58 | eapply sat_mono; eauto. 59 | + rewrite (app_same_set (UpwardsSemantics.denote_wand _ _) m). 60 | hnf; intros. 61 | apply (H m1 m2); auto. 62 | exists m0, m1. 63 | split; [| split]; auto. 64 | reflexivity. 65 | Qed. 66 | 67 | Definition fsepconSM: @FlatSemantics.SepconSemantics L sepconL MD kMD M _ (DownwardsClosure_J) SM. 68 | Proof. 69 | hnf; intros. 70 | unfold WeakSemantics.sepcon. 71 | split; unfold Included, Ensembles.In; intros m ?. 72 | + rewrite (app_same_set (UpwardsSemantics.denote_sepcon _ _) m) in H. 73 | destruct H as [m1 [m2 [? [? ?]]]]. 74 | exists m1, m2. 75 | split; [| split]; auto. 76 | exists m1, m2. 77 | split; [| split]; auto; reflexivity. 78 | + rewrite (app_same_set (UpwardsSemantics.denote_sepcon _ _) m). 79 | destruct H as [m1 [m2 [[n1 [n2 [? [? ?]]]] [? ?]]]]. 80 | exists n1, n2. 81 | split; [| split]; auto; eapply sat_mono; eauto. 82 | Qed. 83 | 84 | Definition feSM {empL: EmpLanguage L} {USA': UnitalSeparationAlgebra' (Kworlds M)} {uempSM: UpwardsSemantics.EmpSemantics L MD M SM}: @FlatSemantics.EmpSemantics L _ MD _ M _ (DownwardsClosure_J) SM. 85 | Proof. 86 | constructor; 87 | intros m; simpl; unfold Ensembles.In; unfold WeakSemantics.emp; 88 | rewrite <- DownwardsClosure_increasing; 89 | apply UpwardsSemantics.denote_emp. 90 | Qed. 91 | 92 | End Up2Flat. 93 | End Up2Flat. 94 | -------------------------------------------------------------------------------- /PropositionalLogic/Complete/Complete_Trivial.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.FunctionalExtensionality. 2 | Require Import Coq.Logic.Classical_Prop. 3 | Require Import Coq.Logic.Classical_Pred_Type. 4 | Require Import Logic.lib.Bijection. 5 | Require Import Logic.lib.Countable. 6 | Require Import Logic.GeneralLogic.Base. 7 | Require Import Logic.GeneralLogic.ProofTheory.BasicSequentCalculus. 8 | Require Import Logic.GeneralLogic.Complete.ContextProperty. 9 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Kripke. 10 | Require Import Logic.GeneralLogic.Complete.ContextProperty_Trivial. 11 | Require Import Logic.GeneralLogic.Complete.Lindenbaum. 12 | Require Import Logic.MinimumLogic.Syntax. 13 | Require Import Logic.MinimumLogic.ProofTheory.Minimum. 14 | Require Import Logic.MinimumLogic.Semantics.Trivial. 15 | Require Import Logic.MinimumLogic.Complete.ContextProperty_Kripke. 16 | Require Import Logic.PropositionalLogic.Syntax. 17 | Require Import Logic.PropositionalLogic.ProofTheory.Intuitionistic. 18 | Require Import Logic.PropositionalLogic.ProofTheory.DeMorgan. 19 | Require Import Logic.PropositionalLogic.ProofTheory.GodelDummett. 20 | Require Import Logic.PropositionalLogic.ProofTheory.Classical. 21 | Require Import Logic.PropositionalLogic.Semantics.Trivial. 22 | Require Import Logic.PropositionalLogic.Complete.ContextProperty_Kripke. 23 | Require Import Logic.PropositionalLogic.Complete.ContextProperty_Trivial. 24 | 25 | Local Open Scope logic_base. 26 | Local Open Scope syntax. 27 | Local Open Scope kripke_model. 28 | Import PropositionalLanguageNotation. 29 | Import KripkeModelFamilyNotation. 30 | 31 | Section Completeness. 32 | 33 | Context {L: Language} 34 | {minL: MinimumLanguage L} 35 | {pL: PropositionalLanguage L} 36 | {GammaP: Provable L} 37 | {GammaD: Derivable L} 38 | {bSC: BasicSequentCalculus L GammaD} 39 | {mpSC: MinimumSequentCalculus L GammaD} 40 | {ipSC: IntuitionisticPropositionalSequentCalculus L GammaD} 41 | {cpSC: ClassicalPropositionalSequentCalculus L GammaD} 42 | {minAX: MinimumAxiomatization L GammaP} 43 | {ipAX: IntuitionisticPropositionalLogic L GammaP} 44 | {MD: Model} 45 | {kMD: KripkeModel MD} 46 | {M: Kmodel} 47 | {SM: Semantics L MD} 48 | {tminSM: TrivialMinimumSemantics L MD SM} 49 | {tpSM: TrivialPropositionalSemantics L MD SM} 50 | {kMC: Kmodel -> Prop}. 51 | 52 | Context (cP: context -> Prop) 53 | (rel: bijection (Kworlds M) (sig cP)). 54 | 55 | Hypothesis AL_MC: at_least (maximal consistent) cP. 56 | Hypothesis LIN_CONSI: Lindenbaum_constructable consistent cP. 57 | Hypothesis TRUTH: forall x: expr, forall m Phi, rel m Phi -> (KRIPKE: M, m |= x <-> proj1_sig Phi x). 58 | Hypothesis CANON: kMC M. 59 | 60 | Lemma general_completeness: strongly_complete GammaD SM (KripkeModelClass _ kMC). 61 | Proof. 62 | intros. 63 | assert (forall Phi, consistent Phi -> satisfiable (KripkeModelClass _ kMC) Phi). 64 | 2: { 65 | clear M CANON rel TRUTH. 66 | hnf; intros. 67 | rewrite classical_derivable_spec. 68 | intro. 69 | specialize (H _ H1); clear H1. 70 | 71 | destruct H as [_ [[M m CANON] ?]]. 72 | pose proof (fun x0 (HH: Phi x0) => H x0 (Union_introl _ _ _ _ HH)). 73 | pose proof (H (~~ x) (Union_intror _ _ _ _ (In_singleton _ _))). 74 | specialize (H0 (KRIPKE: M, m)). 75 | clear H. 76 | 77 | specialize (H0 ltac:(constructor; auto) H1). 78 | unfold negp in H2; rewrite sat_impp, sat_falsep in H2. 79 | auto. 80 | } 81 | intros. 82 | apply LIN_CONSI in H. 83 | destruct H as [Psi ?]. 84 | destruct (su_bij _ _ rel Psi) as [m ?]. 85 | exists (KRIPKE: M, m). 86 | split. 87 | + constructor. 88 | apply CANON. 89 | + intros. 90 | erewrite TRUTH by eauto. 91 | apply H, H1. 92 | Qed. 93 | 94 | End Completeness. 95 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/FlatSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Logic.lib.Coqlib. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.SeparationLogic.Syntax. 7 | Require Import Logic.GeneralLogic.KripkeModel. 8 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 9 | Require Import Logic.SeparationLogic.Model.OrderedSA. 10 | Require Import Logic.SeparationLogic.Semantics.WeakSemantics. 11 | Require Import Logic.SeparationLogic.Semantics.StrongSemantics. 12 | 13 | Local Open Scope logic_base. 14 | Local Open Scope syntax. 15 | Local Open Scope kripke_model. 16 | Import SeparationLogicNotation. 17 | Import KripkeModelFamilyNotation. 18 | Import KripkeModelNotation_Intuitionistic. 19 | 20 | Class SepconSemantics 21 | (L: Language) 22 | {sepconL: SepconLanguage L} 23 | (MD: Model) 24 | {kMD: KripkeModel MD} 25 | (M: Kmodel) 26 | {R: Relation (Kworlds M)} 27 | {J: Join (Kworlds M)} 28 | (SM: Semantics L MD): Type := 29 | denote_sepcon: forall x y, Same_set _ (Kdenotation M (x * y)) (WeakSemantics.sepcon (Kdenotation M x) (Kdenotation M y)). 30 | 31 | Class WandSemantics 32 | (L: Language) 33 | {wandL: WandLanguage L} 34 | (MD: Model) 35 | {kMD: KripkeModel MD} 36 | (M: Kmodel) 37 | {R: Relation (Kworlds M)} 38 | {J: Join (Kworlds M)} 39 | (SM: Semantics L MD): Type := 40 | denote_wand: forall x y, Same_set _ (Kdenotation M (x -* y)) (WeakSemantics.wand (Kdenotation M x) (Kdenotation M y)). 41 | 42 | Class EmpSemantics 43 | (L: Language) 44 | {empL: EmpLanguage L} 45 | (MD: Model) 46 | {kMD: KripkeModel MD} 47 | (M: Kmodel) 48 | {R: Relation (Kworlds M)} 49 | {J: Join (Kworlds M)} 50 | (SM: Semantics L MD): Type := 51 | denote_emp: Same_set _ (Kdenotation M emp) WeakSemantics.emp. 52 | 53 | Lemma sat_sepcon 54 | {L: Language} 55 | {sepconL: SepconLanguage L} 56 | {MD: Model} 57 | {kMD: KripkeModel MD} 58 | {M: Kmodel} 59 | {R: Relation (Kworlds M)} 60 | {J: Join (Kworlds M)} 61 | {SM: Semantics L MD} 62 | {fsepconSM: SepconSemantics L MD M SM}: 63 | forall m x y, 64 | KRIPKE: M , m |= x * y <-> 65 | exists m1 m2, join m1 m2 m /\ 66 | KRIPKE: M , m1 |= x /\ 67 | KRIPKE: M, m2 |= y. 68 | Proof. 69 | intros; simpl. 70 | unfold satisfies. 71 | destruct (denote_sepcon x y). 72 | split; [apply H | apply H0]. 73 | Qed. 74 | 75 | Lemma sat_wand 76 | {L: Language} 77 | {wandL: WandLanguage L} 78 | {MD: Model} 79 | {kMD: KripkeModel MD} 80 | {M: Kmodel} 81 | {R: Relation (Kworlds M)} 82 | {J: Join (Kworlds M)} 83 | {SM: Semantics L MD} 84 | {fwandSM: WandSemantics L MD M SM}: 85 | forall m x y, 86 | KRIPKE: M , m |= x -* y <-> 87 | forall m1 m2, join m m1 m2 -> 88 | KRIPKE: M , m1 |= x -> 89 | KRIPKE: M, m2 |= y. 90 | Proof. 91 | intros; simpl. 92 | unfold satisfies. 93 | destruct (denote_wand x y). 94 | split; [apply H | apply H0]. 95 | Qed. 96 | 97 | Lemma sat_emp 98 | {L: Language} 99 | {empL: EmpLanguage L} 100 | {MD: Model} 101 | {kMD: KripkeModel MD} 102 | {M: Kmodel} 103 | {R: Relation (Kworlds M)} 104 | {J: Join (Kworlds M)} 105 | {SM: Semantics L MD} 106 | {fempSM: EmpSemantics L MD M SM}: 107 | forall (m: Kworlds M), KRIPKE: M, m |= emp <-> increasing m. 108 | Proof. 109 | intros; simpl. 110 | unfold satisfies. 111 | destruct denote_emp. 112 | split; [apply H | apply H0]. 113 | Qed. 114 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/DownwardsSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Logic.lib.Coqlib. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.SeparationLogic.Syntax. 7 | Require Import Logic.GeneralLogic.KripkeModel. 8 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 9 | Require Import Logic.SeparationLogic.Model.OrderedSA. 10 | Require Import Logic.SeparationLogic.Semantics.WeakSemantics. 11 | Require Import Logic.SeparationLogic.Semantics.StrongSemantics. 12 | 13 | Local Open Scope logic_base. 14 | Local Open Scope syntax. 15 | Local Open Scope kripke_model. 16 | Import SeparationLogicNotation. 17 | Import KripkeModelFamilyNotation. 18 | Import KripkeModelNotation_Intuitionistic. 19 | 20 | Class SepconSemantics 21 | (L: Language) 22 | {sepconL: SepconLanguage L} 23 | (MD: Model) 24 | {kMD: KripkeModel MD} 25 | (M: Kmodel) 26 | {R: Relation (Kworlds M)} 27 | {J: Join (Kworlds M)} 28 | (SM: Semantics L MD): Type := 29 | denote_sepcon: forall x y, Same_set _ (Kdenotation M (x * y)) (StrongSemantics.sepcon (Kdenotation M x) (Kdenotation M y)). 30 | 31 | Class WandSemantics 32 | (L: Language) 33 | {wandL: WandLanguage L} 34 | (MD: Model) 35 | {kMD: KripkeModel MD} 36 | (M: Kmodel) 37 | {R: Relation (Kworlds M)} 38 | {J: Join (Kworlds M)} 39 | (SM: Semantics L MD): Type := 40 | denote_wand: forall x y, Same_set _ (Kdenotation M (x -* y)) (WeakSemantics.wand (Kdenotation M x) (Kdenotation M y)). 41 | 42 | Class EmpSemantics 43 | (L: Language) 44 | {empL: EmpLanguage L} 45 | (MD: Model) 46 | {kMD: KripkeModel MD} 47 | (M: Kmodel) 48 | {R: Relation (Kworlds M)} 49 | {J: Join (Kworlds M)} 50 | (SM: Semantics L MD): Type := 51 | denote_emp: Same_set _ (Kdenotation M emp) WeakSemantics.emp. 52 | 53 | Lemma sat_sepcon 54 | {L: Language} 55 | {sepconL: SepconLanguage L} 56 | {MD: Model} 57 | {kMD: KripkeModel MD} 58 | {M: Kmodel} 59 | {R: Relation (Kworlds M)} 60 | {J: Join (Kworlds M)} 61 | {SM: Semantics L MD} 62 | {dsepconSM: SepconSemantics L MD M SM}: 63 | forall m x y, 64 | KRIPKE: M , m |= x * y <-> 65 | exists m0 m1 m2, m0 <= m /\ 66 | join m1 m2 m0 /\ 67 | KRIPKE: M , m1 |= x /\ 68 | KRIPKE: M, m2 |= y. 69 | Proof. 70 | intros; simpl. 71 | unfold satisfies. 72 | destruct (denote_sepcon x y). 73 | split; [apply H | apply H0]. 74 | Qed. 75 | 76 | Lemma sat_wand 77 | {L: Language} 78 | {wandL: WandLanguage L} 79 | {MD: Model} 80 | {kMD: KripkeModel MD} 81 | {M: Kmodel} 82 | {R: Relation (Kworlds M)} 83 | {J: Join (Kworlds M)} 84 | {SM: Semantics L MD} 85 | {dwandSM: WandSemantics L MD M SM}: 86 | forall m x y, 87 | KRIPKE: M , m |= x -* y <-> 88 | forall m1 m2, join m m1 m2 -> 89 | KRIPKE: M , m1 |= x -> 90 | KRIPKE: M, m2 |= y. 91 | Proof. 92 | intros; simpl. 93 | unfold satisfies. 94 | destruct (denote_wand x y). 95 | split; [apply H | apply H0]. 96 | Qed. 97 | 98 | Lemma sat_emp 99 | {L: Language} 100 | {empL: EmpLanguage L} 101 | {MD: Model} 102 | {kMD: KripkeModel MD} 103 | {M: Kmodel} 104 | {R: Relation (Kworlds M)} 105 | {J: Join (Kworlds M)} 106 | {SM: Semantics L MD} 107 | {dempSM: EmpSemantics L MD M SM}: 108 | forall (m: Kworlds M), KRIPKE: M, m |= emp <-> increasing m. 109 | Proof. 110 | intros; simpl. 111 | unfold satisfies. 112 | destruct denote_emp. 113 | split; [apply H | apply H0]. 114 | Qed. 115 | -------------------------------------------------------------------------------- /SeparationLogic/Semantics/UpwardsSemantics.v: -------------------------------------------------------------------------------- 1 | Require Import Coq.Logic.Classical_Prop. 2 | Require Import Coq.Classes.RelationClasses. 3 | Require Import Coq.Relations.Relation_Definitions. 4 | Require Import Logic.lib.Coqlib. 5 | Require Import Logic.GeneralLogic.Base. 6 | Require Import Logic.SeparationLogic.Syntax. 7 | Require Import Logic.GeneralLogic.KripkeModel. 8 | Require Import Logic.SeparationLogic.Model.SeparationAlgebra. 9 | Require Import Logic.SeparationLogic.Model.OrderedSA. 10 | Require Import Logic.SeparationLogic.Semantics.WeakSemantics. 11 | Require Import Logic.SeparationLogic.Semantics.StrongSemantics. 12 | 13 | Local Open Scope logic_base. 14 | Local Open Scope syntax. 15 | Local Open Scope kripke_model. 16 | Import SeparationLogicNotation. 17 | Import KripkeModelFamilyNotation. 18 | Import KripkeModelNotation_Intuitionistic. 19 | 20 | Class SepconSemantics 21 | (L: Language) 22 | {sepconL: SepconLanguage L} 23 | (MD: Model) 24 | {kMD: KripkeModel MD} 25 | (M: Kmodel) 26 | {R: Relation (Kworlds M)} 27 | {J: Join (Kworlds M)} 28 | (SM: Semantics L MD): Type := 29 | denote_sepcon: forall x y, Same_set _ (Kdenotation M (x * y)) (WeakSemantics.sepcon (Kdenotation M x) (Kdenotation M y)). 30 | 31 | Class WandSemantics 32 | (L: Language) 33 | {wandL: WandLanguage L} 34 | (MD: Model) 35 | {kMD: KripkeModel MD} 36 | (M: Kmodel) 37 | {R: Relation (Kworlds M)} 38 | {J: Join (Kworlds M)} 39 | (SM: Semantics L MD): Type := 40 | denote_wand: forall x y, Same_set _ (Kdenotation M (x -* y)) (StrongSemantics.wand (Kdenotation M x) (Kdenotation M y)). 41 | 42 | Class EmpSemantics 43 | (L: Language) 44 | {empL: EmpLanguage L} 45 | (MD: Model) 46 | {kMD: KripkeModel MD} 47 | (M: Kmodel) 48 | {R: Relation (Kworlds M)} 49 | {J: Join (Kworlds M)} 50 | (SM: Semantics L MD): Type := 51 | denote_emp: Same_set _ (Kdenotation M emp) StrongSemantics.emp. 52 | 53 | Lemma sat_sepcon 54 | {L: Language} 55 | {sepconL: SepconLanguage L} 56 | {MD: Model} 57 | {kMD: KripkeModel MD} 58 | {M: Kmodel} 59 | {R: Relation (Kworlds M)} 60 | {J: Join (Kworlds M)} 61 | {SM: Semantics L MD} 62 | {usepconSM: SepconSemantics L MD M SM}: 63 | forall m x y, 64 | KRIPKE: M , m |= x * y <-> 65 | exists m1 m2, join m1 m2 m /\ 66 | KRIPKE: M , m1 |= x /\ 67 | KRIPKE: M, m2 |= y. 68 | Proof. 69 | intros; simpl. 70 | unfold satisfies. 71 | destruct (denote_sepcon x y). 72 | split; [apply H | apply H0]. 73 | Qed. 74 | 75 | Lemma sat_wand 76 | {L: Language} 77 | {wandL: WandLanguage L} 78 | {MD: Model} 79 | {kMD: KripkeModel MD} 80 | {M: Kmodel} 81 | {R: Relation (Kworlds M)} 82 | {J: Join (Kworlds M)} 83 | {SM: Semantics L MD} 84 | {uwandSM: WandSemantics L MD M SM}: 85 | forall m x y, 86 | KRIPKE: M , m |= x -* y <-> 87 | forall m0 m1 m2, m <= m0 -> 88 | join m0 m1 m2 -> 89 | KRIPKE: M , m1 |= x -> 90 | KRIPKE: M, m2 |= y. 91 | Proof. 92 | intros; simpl. 93 | unfold satisfies. 94 | destruct (denote_wand x y). 95 | split; [apply H | apply H0]. 96 | Qed. 97 | 98 | Lemma sat_emp 99 | {L: Language} 100 | {empL: EmpLanguage L} 101 | {MD: Model} 102 | {kMD: KripkeModel MD} 103 | {M: Kmodel} 104 | {R: Relation (Kworlds M)} 105 | {J: Join (Kworlds M)} 106 | {SM: Semantics L MD} 107 | {uempSM: EmpSemantics L MD M SM}: 108 | forall (m: Kworlds M), KRIPKE: M, m |= emp <-> increasing' m. 109 | Proof. 110 | intros; simpl. 111 | unfold satisfies. 112 | destruct denote_emp. 113 | split; [apply H | apply H0]. 114 | Qed. 115 | --------------------------------------------------------------------------------