use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use std::collections::{HashMap, HashSet};
use super::types::{
BeliefRevisionOp, Bisimulation, CanonicalModel, EpistemicModel, FiniteTrace, GradedModel,
KripkeFrame, KripkeModel, MaximalConsistentSet, ModalFormula, ModalSystem, MuCalculusEval,
PdlModel, PdlProgram, PublicAnnouncement, SahlqvistClass,
};
pub fn app(f: Expr, a: Expr) -> Expr {
Expr::App(Box::new(f), Box::new(a))
}
pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
app(app(f, a), b)
}
pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
app(app2(f, a, b), c)
}
pub fn cst(s: &str) -> Expr {
Expr::Const(Name::str(s), vec![])
}
pub fn prop() -> Expr {
Expr::Sort(Level::zero())
}
pub fn type0() -> Expr {
Expr::Sort(Level::succ(Level::zero()))
}
pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
}
pub fn arrow(a: Expr, b: Expr) -> Expr {
pi(BinderInfo::Default, "_", a, b)
}
pub fn bvar(n: u32) -> Expr {
Expr::BVar(n)
}
pub fn nat_ty() -> Expr {
cst("Nat")
}
pub fn bool_ty() -> Expr {
cst("Bool")
}
pub fn kripke_frame_ty() -> Expr {
type0()
}
pub fn kripke_model_ty() -> Expr {
type0()
}
pub fn world_ty() -> Expr {
type0()
}
pub fn accessibility_relation_ty() -> Expr {
arrow(cst("World"), arrow(cst("World"), prop()))
}
pub fn valuation_ty() -> Expr {
arrow(nat_ty(), arrow(cst("World"), bool_ty()))
}
pub fn modal_formula_ty() -> Expr {
type0()
}
pub fn modal_satisfaction_ty() -> Expr {
arrow(
cst("KripkeModel"),
arrow(cst("World"), arrow(cst("ModalFormula"), prop())),
)
}
pub fn frame_validity_ty() -> Expr {
arrow(cst("KripkeFrame"), arrow(cst("ModalFormula"), prop()))
}
pub fn class_validity_ty() -> Expr {
arrow(
arrow(cst("KripkeFrame"), prop()),
arrow(cst("ModalFormula"), prop()),
)
}
pub fn reflexive_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn transitive_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn symmetric_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn serial_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn euclidean_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn confluent_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn dense_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn directed_frame_ty() -> Expr {
arrow(cst("KripkeFrame"), prop())
}
pub fn axiom_k_ty() -> Expr {
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
pub fn axiom_t_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn axiom4_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn axiom_b_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn axiom5_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn axiom_d_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn axiom_lob_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn nec_rule_ty() -> Expr {
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
pub fn soundness_k_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn completeness_k_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn soundness_t_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn completeness_t_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn soundness_s4_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn completeness_s4_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn soundness_s5_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn completeness_s5_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn canonical_frame_ty() -> Expr {
arrow(cst("ModalLogic"), cst("KripkeFrame"))
}
pub fn canonical_model_ty() -> Expr {
arrow(cst("ModalLogic"), cst("KripkeModel"))
}
pub fn canonical_truth_lemma_ty() -> Expr {
arrow(cst("ModalLogic"), arrow(cst("ModalFormula"), prop()))
}
pub fn maximal_consistent_set_ty() -> Expr {
arrow(cst("ModalLogic"), type0())
}
pub fn lindenbaum_ty() -> Expr {
arrow(cst("ModalLogic"), prop())
}
pub fn frame_correspondence_ty() -> Expr {
arrow(
cst("ModalFormula"),
arrow(arrow(cst("KripkeFrame"), prop()), prop()),
)
}
pub fn sahlqvist_formula_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn sahlqvist_correspondence_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn sahlqvist_completeness_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn epistemic_knowledge_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn common_knowledge_ty() -> Expr {
arrow(
cst("AgentGroup"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn distributed_knowledge_ty() -> Expr {
arrow(
cst("AgentGroup"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn doxastic_belief_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn positive_introspection_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), prop()))
}
pub fn negative_introspection_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), prop()))
}
pub fn obligation_op_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn permission_op_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn prohibition_op_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn deontic_conflict_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn ross_paradox_ty() -> Expr {
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
pub fn gl_provability_ty() -> Expr {
type0()
}
pub fn solovay_completeness_ty() -> Expr {
prop()
}
pub fn godel_diagonal_ty() -> Expr {
prop()
}
pub fn gl_fixed_point_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn gl_frame_class_ty() -> Expr {
prop()
}
pub fn public_announcement_ty() -> Expr {
arrow(
cst("ModalFormula"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn announcement_knowledge_law_ty() -> Expr {
arrow(
nat_ty(),
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop())),
)
}
pub fn action_model_ty() -> Expr {
type0()
}
pub fn product_update_ty() -> Expr {
arrow(
cst("KripkeModel"),
arrow(cst("ActionModel"), cst("KripkeModel")),
)
}
pub fn mud_puzzle_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn multimodal_formula_ty() -> Expr {
type0()
}
pub fn product_frame_ty() -> Expr {
arrow(
cst("KripkeFrame"),
arrow(cst("KripkeFrame"), cst("KripkeFrame")),
)
}
pub fn fusion_logic_ty() -> Expr {
arrow(
cst("ModalLogic"),
arrow(cst("ModalLogic"), cst("ModalLogic")),
)
}
pub fn interaction_axiom_ty() -> Expr {
type0()
}
pub fn tense_logic_ty() -> Expr {
type0()
}
pub fn filtration_ty() -> Expr {
arrow(
cst("KripkeModel"),
arrow(cst("ModalFormula"), cst("KripkeModel")),
)
}
pub fn finite_model_property_ty() -> Expr {
arrow(cst("ModalLogic"), prop())
}
pub fn modal_decidability_ty() -> Expr {
arrow(cst("ModalLogic"), prop())
}
pub fn subformula_property_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn k_fmp_ty() -> Expr {
prop()
}
pub fn s4_fmp_ty() -> Expr {
prop()
}
pub fn pdl_program_ty() -> Expr {
type0()
}
pub fn pdl_box_ty() -> Expr {
arrow(
cst("PDLProgram"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn pdl_diamond_ty() -> Expr {
arrow(
cst("PDLProgram"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn pdl_test_ty() -> Expr {
arrow(cst("ModalFormula"), cst("PDLProgram"))
}
pub fn pdl_sequence_axiom_ty() -> Expr {
arrow(
cst("PDLProgram"),
arrow(cst("PDLProgram"), arrow(cst("ModalFormula"), prop())),
)
}
pub fn pdl_choice_axiom_ty() -> Expr {
arrow(
cst("PDLProgram"),
arrow(cst("PDLProgram"), arrow(cst("ModalFormula"), prop())),
)
}
pub fn pdl_iteration_axiom_ty() -> Expr {
arrow(cst("PDLProgram"), arrow(cst("ModalFormula"), prop()))
}
pub fn game_logic_diamond_ty() -> Expr {
arrow(cst("Game"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn game_logic_box_ty() -> Expr {
arrow(cst("Game"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn game_ty() -> Expr {
type0()
}
pub fn ltl_next_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn ltl_until_ty() -> Expr {
arrow(
cst("ModalFormula"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn ltl_globally_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn ltl_finally_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn ctl_ex_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn ctl_ax_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn ctl_eu_ty() -> Expr {
arrow(
cst("ModalFormula"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn ctl_au_ty() -> Expr {
arrow(
cst("ModalFormula"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn atl_coalition_ty() -> Expr {
arrow(
cst("AgentGroup"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn concurrent_game_structure_ty() -> Expr {
type0()
}
pub fn nominal_ty() -> Expr {
type0()
}
pub fn hybrid_at_ty() -> Expr {
arrow(
cst("Nominal"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn hybrid_binder_ty() -> Expr {
arrow(
cst("Nominal"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn hybrid_axiom_at_ty() -> Expr {
arrow(cst("Nominal"), arrow(cst("ModalFormula"), prop()))
}
pub fn hybrid_paste_axiom_ty() -> Expr {
arrow(cst("Nominal"), arrow(cst("ModalFormula"), prop()))
}
pub fn neighborhood_fn_ty() -> Expr {
arrow(cst("World"), type0())
}
pub fn classical_modal_box_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn monotone_neighborhood_ty() -> Expr {
arrow(cst("World"), prop())
}
pub fn axiom_m_ty() -> Expr {
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
pub fn axiom_c_ty() -> Expr {
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
pub fn axiom_n_ty() -> Expr {
prop()
}
pub fn justification_term_ty() -> Expr {
type0()
}
pub fn justification_op_ty() -> Expr {
arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop()))
}
pub fn justification_app_axiom_ty() -> Expr {
arrow(
cst("JustificationTerm"),
arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop())),
)
}
pub fn justification_sum_axiom_ty() -> Expr {
arrow(
cst("JustificationTerm"),
arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop())),
)
}
pub fn justification_verification_ty() -> Expr {
arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop()))
}
pub fn realization_theorem_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn gls_axiom_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn arithmetical_soundness_ty() -> Expr {
prop()
}
pub fn arithmetical_interp_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ArithSentence"))
}
pub fn solovay_second_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn mu_formula_ty() -> Expr {
type0()
}
pub fn mu_least_fp_ty() -> Expr {
arrow(
cst("PropVar"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn nu_greatest_fp_ty() -> Expr {
arrow(
cst("PropVar"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn knaster_tarski_modal_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn mu_calculus_decidable_ty() -> Expr {
prop()
}
pub fn alternation_hierarchy_ty() -> Expr {
prop()
}
pub fn context_ty() -> Expr {
type0()
}
pub fn two_dim_satisfaction_ty() -> Expr {
arrow(
cst("KripkeModel"),
arrow(
cst("Context"),
arrow(cst("World"), arrow(cst("ModalFormula"), prop())),
),
)
}
pub fn kaplan_dthat_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn actually_op_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn fixedly_op_ty() -> Expr {
arrow(cst("ModalFormula"), cst("ModalFormula"))
}
pub fn necessity_type_ty() -> Expr {
arrow(type0(), type0())
}
pub fn box_intro_ty() -> Expr {
arrow(type0(), type0())
}
pub fn box_elim_ty() -> Expr {
arrow(type0(), arrow(type0(), type0()))
}
pub fn locked_context_ty() -> Expr {
type0()
}
pub fn topological_space_ty() -> Expr {
type0()
}
pub fn interior_op_ty() -> Expr {
arrow(
cst("TopologicalSpace"),
arrow(cst("ModalFormula"), cst("ModalFormula")),
)
}
pub fn mckinsey_tarski_ty() -> Expr {
prop()
}
pub fn dense_in_itself_ty() -> Expr {
arrow(cst("TopologicalSpace"), prop())
}
pub fn topological_validity_ty() -> Expr {
arrow(cst("ModalFormula"), prop())
}
pub fn foml_formula_ty() -> Expr {
type0()
}
pub fn barcan_formula_ty() -> Expr {
arrow(cst("FOMLFormula"), prop())
}
pub fn converse_barcan_ty() -> Expr {
arrow(cst("FOMLFormula"), prop())
}
pub fn varying_domain_ty() -> Expr {
arrow(cst("KripkeFrame"), type0())
}
pub fn constant_domain_ty() -> Expr {
arrow(cst("KripkeFrame"), type0())
}
pub fn existence_predicate_ty() -> Expr {
arrow(cst("World"), prop())
}
pub fn minimal_modal_logic_e_ty() -> Expr {
type0()
}
pub fn axiom_e_ty() -> Expr {
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
pub fn monotonic_modal_logic_ty() -> Expr {
type0()
}
pub fn regular_modal_logic_ty() -> Expr {
type0()
}
pub fn congruence_rule_ty() -> Expr {
arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
pub fn stit_op_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn deliberative_stit_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn achievement_stit_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn deontic_stit_ty() -> Expr {
arrow(nat_ty(), arrow(cst("ModalFormula"), prop()))
}
pub fn graded_diamond_ty() -> Expr {
arrow(cst("Nat"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn graded_box_ty() -> Expr {
arrow(cst("Nat"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn probabilistic_modality_ty() -> Expr {
arrow(cst("Real"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
pub fn coalgebra_functor_ty() -> Expr {
arrow(type0(), type0())
}
pub fn modal_coalgebra_ty() -> Expr {
arrow(cst("CoalgebraFunctor"), arrow(type0(), type0()))
}
pub fn belief_set_ty() -> Expr {
type0()
}
pub fn belief_revision_ty() -> Expr {
arrow(
cst("BeliefSet"),
arrow(cst("ModalFormula"), cst("BeliefSet")),
)
}
pub fn belief_contraction_ty() -> Expr {
arrow(
cst("BeliefSet"),
arrow(cst("ModalFormula"), cst("BeliefSet")),
)
}
pub fn agm_success_ty() -> Expr {
arrow(cst("BeliefSet"), arrow(cst("ModalFormula"), prop()))
}
pub fn agm_consistency_ty() -> Expr {
arrow(cst("BeliefSet"), arrow(cst("ModalFormula"), prop()))
}
pub fn build_modal_logic_env(env: &mut Environment) {
let axioms: &[(&str, Expr)] = &[
("KripkeFrame", kripke_frame_ty()),
("KripkeModel", kripke_model_ty()),
("World", world_ty()),
("AccessibilityRelation", accessibility_relation_ty()),
("Valuation", valuation_ty()),
("ModalFormula", modal_formula_ty()),
("ModalLogic", type0()),
("Agent", nat_ty()),
("AgentGroup", type0()),
("ModalSat", modal_satisfaction_ty()),
("FrameValid", frame_validity_ty()),
("ClassValid", class_validity_ty()),
("ReflexiveFrame", reflexive_frame_ty()),
("TransitiveFrame", transitive_frame_ty()),
("SymmetricFrame", symmetric_frame_ty()),
("SerialFrame", serial_frame_ty()),
("EuclideanFrame", euclidean_frame_ty()),
("ConfluentFrame", confluent_frame_ty()),
("DenseFrame", dense_frame_ty()),
("DirectedFrame", directed_frame_ty()),
("AxiomK", axiom_k_ty()),
("AxiomT", axiom_t_ty()),
("Axiom4", axiom4_ty()),
("AxiomB", axiom_b_ty()),
("Axiom5", axiom5_ty()),
("AxiomD", axiom_d_ty()),
("AxiomLob", axiom_lob_ty()),
("NecRule", nec_rule_ty()),
("soundness_k", soundness_k_ty()),
("completeness_k", completeness_k_ty()),
("soundness_t", soundness_t_ty()),
("completeness_t", completeness_t_ty()),
("soundness_s4", soundness_s4_ty()),
("completeness_s4", completeness_s4_ty()),
("soundness_s5", soundness_s5_ty()),
("completeness_s5", completeness_s5_ty()),
("CanonicalFrame", canonical_frame_ty()),
("CanonicalModel", canonical_model_ty()),
("canonical_truth_lemma", canonical_truth_lemma_ty()),
("MaximalConsistentSet", maximal_consistent_set_ty()),
("lindenbaum", lindenbaum_ty()),
("FrameCorrespondence", frame_correspondence_ty()),
("SahlqvistFormula", sahlqvist_formula_ty()),
("sahlqvist_correspondence", sahlqvist_correspondence_ty()),
("sahlqvist_completeness", sahlqvist_completeness_ty()),
("EpistemicK", epistemic_knowledge_ty()),
("CommonKnowledge", common_knowledge_ty()),
("DistributedKnowledge", distributed_knowledge_ty()),
("DoxasticB", doxastic_belief_ty()),
("positive_introspection", positive_introspection_ty()),
("negative_introspection", negative_introspection_ty()),
("ObligationOp", obligation_op_ty()),
("PermissionOp", permission_op_ty()),
("ProhibitionOp", prohibition_op_ty()),
("DeonticConflict", deontic_conflict_ty()),
("RossParadox", ross_paradox_ty()),
("GLProvability", gl_provability_ty()),
("solovay_completeness", solovay_completeness_ty()),
("godel_diagonal", godel_diagonal_ty()),
("gl_fixed_point", gl_fixed_point_ty()),
("gl_frame_class", gl_frame_class_ty()),
("PublicAnnouncement", public_announcement_ty()),
(
"announcement_knowledge_law",
announcement_knowledge_law_ty(),
),
("ActionModel", action_model_ty()),
("ProductUpdate", product_update_ty()),
("MudPuzzle", mud_puzzle_ty()),
("MultimodalFormula", multimodal_formula_ty()),
("ProductFrame", product_frame_ty()),
("FusionLogic", fusion_logic_ty()),
("InteractionAxiom", interaction_axiom_ty()),
("TenseLogic", tense_logic_ty()),
("Filtration", filtration_ty()),
("FiniteModelProperty", finite_model_property_ty()),
("ModalDecidability", modal_decidability_ty()),
("SubformulaProperty", subformula_property_ty()),
("k_fmp", k_fmp_ty()),
("s4_fmp", s4_fmp_ty()),
("PDLProgram", pdl_program_ty()),
("PDLBox", pdl_box_ty()),
("PDLDiamond", pdl_diamond_ty()),
("PDLTest", pdl_test_ty()),
("pdl_sequence_axiom", pdl_sequence_axiom_ty()),
("pdl_choice_axiom", pdl_choice_axiom_ty()),
("pdl_iteration_axiom", pdl_iteration_axiom_ty()),
("GameLogicDiamond", game_logic_diamond_ty()),
("GameLogicBox", game_logic_box_ty()),
("Game", game_ty()),
("LTLNext", ltl_next_ty()),
("LTLUntil", ltl_until_ty()),
("LTLGlobally", ltl_globally_ty()),
("LTLFinally", ltl_finally_ty()),
("CTLEX", ctl_ex_ty()),
("CTLAX", ctl_ax_ty()),
("CTLEU", ctl_eu_ty()),
("CTLAU", ctl_au_ty()),
("ATLCoalition", atl_coalition_ty()),
("ConcurrentGameStructure", concurrent_game_structure_ty()),
("Nominal", nominal_ty()),
("HybridAt", hybrid_at_ty()),
("HybridBinder", hybrid_binder_ty()),
("hybrid_axiom_at", hybrid_axiom_at_ty()),
("hybrid_paste_axiom", hybrid_paste_axiom_ty()),
("NeighborhoodFn", neighborhood_fn_ty()),
("ClassicalModalBox", classical_modal_box_ty()),
("MonotoneNeighborhood", monotone_neighborhood_ty()),
("AxiomM", axiom_m_ty()),
("AxiomC", axiom_c_ty()),
("AxiomN", axiom_n_ty()),
("JustificationTerm", justification_term_ty()),
("JustificationOp", justification_op_ty()),
("justification_app_axiom", justification_app_axiom_ty()),
("justification_sum_axiom", justification_sum_axiom_ty()),
(
"justification_verification",
justification_verification_ty(),
),
("realization_theorem", realization_theorem_ty()),
("gls_axiom", gls_axiom_ty()),
("arithmetical_soundness", arithmetical_soundness_ty()),
("ArithSentence", type0()),
("arithmetical_interp", arithmetical_interp_ty()),
("solovay_second", solovay_second_ty()),
("MuFormula", mu_formula_ty()),
("PropVar", nat_ty()),
("mu_least_fp", mu_least_fp_ty()),
("nu_greatest_fp", nu_greatest_fp_ty()),
("knaster_tarski_modal", knaster_tarski_modal_ty()),
("mu_calculus_decidable", mu_calculus_decidable_ty()),
("alternation_hierarchy", alternation_hierarchy_ty()),
("Context", context_ty()),
("two_dim_satisfaction", two_dim_satisfaction_ty()),
("kaplan_dthat", kaplan_dthat_ty()),
("actually_op", actually_op_ty()),
("fixedly_op", fixedly_op_ty()),
("necessity_type", necessity_type_ty()),
("box_intro", box_intro_ty()),
("box_elim", box_elim_ty()),
("LockedContext", locked_context_ty()),
("TopologicalSpace", topological_space_ty()),
("InteriorOp", interior_op_ty()),
("mckinsey_tarski", mckinsey_tarski_ty()),
("dense_in_itself", dense_in_itself_ty()),
("topological_validity", topological_validity_ty()),
("FOMLFormula", foml_formula_ty()),
("barcan_formula", barcan_formula_ty()),
("converse_barcan", converse_barcan_ty()),
("varying_domain", varying_domain_ty()),
("constant_domain", constant_domain_ty()),
("existence_predicate", existence_predicate_ty()),
("MinimalModalLogicE", minimal_modal_logic_e_ty()),
("AxiomE", axiom_e_ty()),
("MonotonicModalLogic", monotonic_modal_logic_ty()),
("RegularModalLogic", regular_modal_logic_ty()),
("congruence_rule", congruence_rule_ty()),
("STITOp", stit_op_ty()),
("DeliberativeSTIT", deliberative_stit_ty()),
("AchievementSTIT", achievement_stit_ty()),
("DeonticSTIT", deontic_stit_ty()),
("GradedDiamond", graded_diamond_ty()),
("GradedBox", graded_box_ty()),
("ProbabilisticModality", probabilistic_modality_ty()),
("CoalgebraFunctor", coalgebra_functor_ty()),
("ModalCoalgebra", modal_coalgebra_ty()),
("Real", type0()),
("BeliefSet", belief_set_ty()),
("belief_revision", belief_revision_ty()),
("belief_contraction", belief_contraction_ty()),
("agm_success", agm_success_ty()),
("agm_consistency", agm_consistency_ty()),
];
for (name, ty) in axioms {
env.add(Declaration::Axiom {
name: Name::str(*name),
univ_params: vec![],
ty: ty.clone(),
})
.ok();
}
}
pub type PropVar = u32;
pub fn classify_sahlqvist(phi: &ModalFormula) -> SahlqvistClass {
match phi {
ModalFormula::Implies(ant, cons) => {
if is_sahlqvist_antecedent(ant) && is_positive(cons) {
SahlqvistClass::Full
} else {
SahlqvistClass::NotSahlqvist
}
}
_ if is_positive(phi) => SahlqvistClass::Consequent,
_ => SahlqvistClass::NotSahlqvist,
}
}
pub fn is_sahlqvist_antecedent(phi: &ModalFormula) -> bool {
match phi {
ModalFormula::Atom(_) | ModalFormula::Top | ModalFormula::Bot => true,
ModalFormula::Not(psi) => is_positive(psi),
ModalFormula::And(a, b) => is_sahlqvist_antecedent(a) && is_sahlqvist_antecedent(b),
ModalFormula::Diamond(_, psi) => is_sahlqvist_antecedent(psi),
ModalFormula::Box(_, psi) => is_sahlqvist_antecedent(psi),
_ => false,
}
}
pub fn is_positive(phi: &ModalFormula) -> bool {
match phi {
ModalFormula::Atom(_) | ModalFormula::Top | ModalFormula::Bot => true,
ModalFormula::Not(_) => false,
ModalFormula::And(a, b) | ModalFormula::Or(a, b) | ModalFormula::Implies(a, b) => {
is_positive(a) && is_positive(b)
}
ModalFormula::Box(_, psi) | ModalFormula::Diamond(_, psi) => is_positive(psi),
}
}
pub fn compute_bisimulation(m1: &KripkeModel, m2: &KripkeModel) -> Bisimulation {
let mut bisim = Bisimulation::new();
for w in 0..m1.frame.n_worlds {
for v in 0..m2.frame.n_worlds {
let agree = m1
.valuation
.keys()
.all(|&p| m1.prop_true(p, w) == m2.prop_true(p, v));
if agree {
bisim.add_pair(w, v);
}
}
}
bisim
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_kripke_frame_reflexive() {
let mut frame = KripkeFrame::new(3, 1);
frame.make_reflexive(0);
assert!(frame.is_reflexive(0));
assert!(frame.is_symmetric(0));
frame.add_edge(0, 0, 1);
assert!(!frame.is_symmetric(0));
}
#[test]
fn test_kripke_frame_transitive() {
let mut frame = KripkeFrame::new(3, 1);
frame.add_edge(0, 0, 1);
frame.add_edge(0, 1, 2);
assert!(!frame.is_transitive(0));
frame.make_transitive(0);
assert!(frame.is_transitive(0));
assert!(frame.accessible(0, 0, 2));
}
#[test]
fn test_kripke_model_satisfaction() {
let mut frame = KripkeFrame::new(2, 1);
frame.add_edge(0, 0, 1);
let mut model = KripkeModel::new(frame);
model.set_true(0, 1);
let box_p = ModalFormula::necessity(ModalFormula::atom(0));
assert!(model.satisfies(0, &box_p));
let dia_p = ModalFormula::possibility(ModalFormula::atom(0));
assert!(!model.satisfies(1, &dia_p));
}
#[test]
fn test_s4_frame_validation() {
let mut frame = KripkeFrame::new(3, 1);
frame.make_reflexive(0);
frame.add_edge(0, 0, 1);
frame.add_edge(0, 1, 2);
frame.make_transitive(0);
assert!(ModalSystem::S4.frame_validates(&frame, 0));
assert!(!ModalSystem::S5.frame_validates(&frame, 0));
}
#[test]
fn test_modal_formula_depth() {
let p = ModalFormula::atom(0);
let box_p = ModalFormula::necessity(p.clone());
let box_box_p = ModalFormula::necessity(box_p.clone());
assert_eq!(p.modal_depth(), 0);
assert_eq!(box_p.modal_depth(), 1);
assert_eq!(box_box_p.modal_depth(), 2);
}
#[test]
fn test_canonical_model_construction() {
let mut canon = CanonicalModel::new();
let mcs0 = MaximalConsistentSet::new(
0,
vec![
ModalFormula::atom(0),
ModalFormula::necessity(ModalFormula::atom(1)),
],
);
let mcs1 = MaximalConsistentSet::new(1, vec![ModalFormula::atom(1)]);
canon.add_world(mcs0);
canon.add_world(mcs1);
canon.build_accessibility();
assert_eq!(canon.size(), 2);
assert!(canon.accessibility.contains(&(0, 1)));
}
#[test]
fn test_epistemic_model_knows() {
let mut model = EpistemicModel::new(3, 1);
model.add_edge(0, 0, 0);
model.add_edge(0, 0, 1);
model.valuation.entry(0).or_default().insert(0);
model.valuation.entry(0).or_default().insert(1);
let p = ModalFormula::atom(0);
assert!(model.knows(0, 0, &p));
}
#[test]
fn test_public_announcement_update() {
let mut model = EpistemicModel::new(3, 1);
model.make_equivalence_relations();
model.valuation.entry(0).or_default().insert(0);
model.valuation.entry(0).or_default().insert(1);
let ann = PublicAnnouncement::new(ModalFormula::atom(0));
let updated = ann.update(&model);
assert_eq!(updated.n_worlds, 2);
}
#[test]
fn test_build_modal_logic_env() {
let mut env = Environment::new();
build_modal_logic_env(&mut env);
assert!(env.get(&Name::str("KripkeFrame")).is_some());
assert!(env.get(&Name::str("AxiomLob")).is_some());
assert!(env.get(&Name::str("sahlqvist_completeness")).is_some());
assert!(env.get(&Name::str("ProductUpdate")).is_some());
assert!(env.get(&Name::str("PDLBox")).is_some());
assert!(env.get(&Name::str("LTLUntil")).is_some());
assert!(env.get(&Name::str("ATLCoalition")).is_some());
assert!(env.get(&Name::str("HybridAt")).is_some());
assert!(env.get(&Name::str("AxiomM")).is_some());
assert!(env.get(&Name::str("JustificationOp")).is_some());
assert!(env.get(&Name::str("mu_least_fp")).is_some());
assert!(env.get(&Name::str("barcan_formula")).is_some());
assert!(env.get(&Name::str("GradedDiamond")).is_some());
assert!(env.get(&Name::str("belief_revision")).is_some());
}
#[test]
fn test_pdl_model_sequence() {
let mut frame = KripkeFrame::new(3, 2);
frame.add_edge(0, 0, 1);
frame.add_edge(1, 1, 2);
let mut kripke = KripkeModel::new(frame);
kripke.set_true(0, 2);
let pdl = PdlModel::new(kripke, 2);
let alpha = PdlProgram::Atomic(0);
let beta = PdlProgram::Atomic(1);
let seq = PdlProgram::Sequence(Box::new(alpha), Box::new(beta));
let reachable = pdl.reachable(0, &seq);
assert!(reachable.contains(&2));
assert_eq!(reachable.len(), 1);
let p = ModalFormula::atom(0);
assert!(pdl.box_program(0, &seq, &p));
}
#[test]
fn test_pdl_model_star() {
let mut frame = KripkeFrame::new(4, 1);
frame.add_edge(0, 0, 1);
frame.add_edge(0, 1, 2);
frame.add_edge(0, 2, 3);
let kripke = KripkeModel::new(frame);
let pdl = PdlModel::new(kripke, 1);
let alpha = PdlProgram::Atomic(0);
let star = PdlProgram::Star(Box::new(alpha));
let reachable = pdl.reachable(0, &star);
assert_eq!(reachable.len(), 4);
for w in 0..4 {
assert!(reachable.contains(&w));
}
}
#[test]
fn test_finite_trace_ltl() {
let mut trace = FiniteTrace::new();
let mut s0 = HashMap::new();
s0.insert(0u32, true);
trace.push(s0);
let mut s1 = HashMap::new();
s1.insert(0u32, false);
trace.push(s1);
let mut s2 = HashMap::new();
s2.insert(0u32, true);
trace.push(s2);
let p = ModalFormula::atom(0);
let finally_p = ModalFormula::Diamond(0, Box::new(p.clone()));
assert!(trace.check(&finally_p));
let globally_p = ModalFormula::Box(0, Box::new(p.clone()));
assert!(!trace.check(&globally_p));
let next_p = ModalFormula::Box(1, Box::new(p.clone()));
assert!(!trace.check(&next_p));
assert!(trace.satisfies(2, &globally_p));
}
#[test]
fn test_graded_model() {
let mut frame = KripkeFrame::new(5, 1);
for v in 1..=4 {
frame.add_edge(0, 0, v);
}
let mut kripke = KripkeModel::new(frame);
for w in 1..=3 {
kripke.set_true(0, w);
}
let model = GradedModel::new(kripke);
let p = ModalFormula::atom(0);
assert!(model.graded_diamond(0, 3, &p));
assert!(!model.graded_diamond(0, 4, &p));
assert!(model.graded_box(0, 1, &p));
assert!(!model.graded_box(0, 0, &p));
assert_eq!(model.count_satisfying(0, &p), 3);
}
#[test]
fn test_belief_revision_agm() {
let mut bro = BeliefRevisionOp::new();
let p = ModalFormula::atom(0);
let q = ModalFormula::atom(1);
let neg_p = ModalFormula::not(p.clone());
bro.add_belief(p.clone(), 5);
bro.add_belief(q.clone(), 3);
bro.add_belief(neg_p.clone(), 1);
assert!(bro.believes(&p));
assert_eq!(bro.size(), 3);
let revised = bro.revise(&p);
assert!(revised.believes(&p));
assert!(!revised.believes(&neg_p));
let contracted = bro.contract(&p);
assert!(!contracted.believes(&p));
assert!(contracted.believes(&q));
}
#[test]
fn test_mu_calculus_reachability() {
let mut frame = KripkeFrame::new(3, 1);
frame.add_edge(0, 0, 1);
frame.add_edge(0, 1, 2);
let mut kripke = KripkeModel::new(frame);
kripke.set_true(0, 2);
let eval = MuCalculusEval::new(kripke);
let goal = ModalFormula::atom(0);
let reachable = eval.reachability(&goal);
assert!(reachable.contains(&0));
assert!(reachable.contains(&1));
assert!(reachable.contains(&2));
}
#[test]
fn test_mu_calculus_safety() {
let mut frame = KripkeFrame::new(3, 1);
frame.add_edge(0, 0, 1);
frame.add_edge(0, 0, 2);
let mut kripke = KripkeModel::new(frame);
kripke.set_true(0, 0);
kripke.set_true(0, 1);
let eval = MuCalculusEval::new(kripke);
let safe = ModalFormula::atom(0);
let safe_worlds = eval.safety(&safe);
assert!(!safe_worlds.contains(&0));
assert!(safe_worlds.contains(&1));
assert!(!safe_worlds.contains(&2));
}
}