Theory AnswerIndexedFamilies

theory AnswerIndexedFamilies
imports Main
begin

chapter ‹Answer-Indexed Families›

typedecl 'a state
consts L :: ‹'a state => 'a set›
datatype answer = T | F
type_synonym 'a AiF = ‹answer ⇒ 'a set›

fun and_AiF :: ‹'a AiF ⇒ 'a AiF ⇒ 'a AiF› (infixl ‹∧·› 60) where
  ‹(a ∧· b) T = a T ∩ b T›
| ‹(a ∧· b) F = a F ∪ b F›

fun or_AiF :: ‹'a AiF ⇒ 'a AiF ⇒ 'a AiF› (infixl ‹∨·› 59) where
  ‹(a ∨· b) T = a T ∪ b T›
| ‹(a ∨· b) F = a F ∩ b F›

fun not_AiF :: ‹'a AiF ⇒ 'a AiF› (‹¬· _›) where
  ‹(¬· a) T = a F›
| ‹(¬· a) F = a T›

fun univ_AiF :: ‹'a AiF› (‹T∙›) where
  ‹T∙ T = UNIV›
| ‹T∙ F = {}›

fun satisfying_AiF :: ‹'a ⇒ 'a state AiF› (‹sat∙›) where
  ‹sat∙ x T = {state. x ∈ L state}›
| ‹sat∙ x F = {state. x ∉ L state}›

section ‹Example: Propositional logic›

datatype (atoms_plogic: 'a) plogic =
    True_plogic                               (‹truep›)
  | Prop_plogic ‹'a›                            (‹propp'(_')›)
  | Not_plogic ‹'a plogic›                    (‹notp _› [85] 85)
  | Or_plogic  ‹'a plogic› ‹'a plogic›        (‹_ orp _› [82,82] 81)
  | And_plogic ‹'a plogic› ‹'a plogic›        (‹_ andp _› [82,82] 81)

fun plogic_semantics :: ‹'a plogic ⇒ 'a state AiF› (‹⟦_⟧p›) where
  ‹⟦ truep    ⟧p = T∙›
| ‹⟦ notp φ   ⟧p = ¬· ⟦φ⟧p›
| ‹⟦ propp(a) ⟧p = sat∙ a›
| ‹⟦ φ orp ψ  ⟧p = ⟦φ⟧p ∨· ⟦ψ⟧p›
| ‹⟦ φ andp ψ ⟧p = ⟦φ⟧p ∧· ⟦ψ⟧p›

definition false_p (‹falsep›) where
false_p_def [simp]: ‹falsep = notp truep›

definition implies_p :: ‹'a plogic ⇒ 'a plogic ⇒ 'a plogic› (‹_ impliesp _› [81,81] 80)  where
implies_p_def[simp]: ‹φ impliesp ψ = (notp φ orp ψ)›

subsection ‹Propositional logic lemmas›

lemma AiF_cases:  
  assumes ‹A T = B T› and ‹A F = B F›
  shows ‹A = B›
proof (rule ext)
  fix x show ‹A x = B x› by (cases ‹x›; simp add: assms) 
qed

lemma or_and_negation: ‹⟦ φ orp ψ ⟧p = ⟦ notp ((notp φ) andp (notp ψ)) ⟧p›
  by (rule AiF_cases; simp)

lemma and_or_negation: ‹⟦ φ andp ψ⟧p = ⟦ notp ((notp φ) orp (notp ψ)) ⟧p›
  by (rule AiF_cases; simp)

lemma de_morgan_1: ‹⟦ notp (φ andp ψ) ⟧p = ⟦ (notp φ) orp (notp ψ) ⟧p›
  by (rule AiF_cases; simp)

lemma de_morgan_2: ‹⟦ notp (φ orp ψ)  ⟧p = ⟦ (notp φ) andp (notp ψ) ⟧p›
  by (rule AiF_cases; simp)

subsection ‹Propositional logic equivalence›

fun plogic_semantics' :: ‹'a state ⇒ 'a plogic ⇒ bool› (infix ‹⊨p› 60) where
  ‹Γ ⊨p truep = True›
| ‹Γ ⊨p notp φ = (¬ Γ ⊨p φ)›
| ‹Γ ⊨p propp(a) = (a ∈ L Γ)›
| ‹Γ ⊨p φ orp ψ = (Γ ⊨p φ ∨ Γ ⊨p ψ)›
| ‹Γ ⊨p φ andp ψ = (Γ ⊨p φ ∧ Γ ⊨p ψ)›

lemma plogic_equivalence:
  shows ‹(  Γ  ⊨p φ ⟷ Γ ∈ ⟦φ⟧p T)›
  and   ‹(¬ Γ  ⊨p φ ⟷ Γ ∈ ⟦φ⟧p F)›
proof (induct ‹φ›)
qed (auto)

end