Theory UML_Boolean
theory UML_Boolean
imports "../UML_PropertyProfiles"
begin
subsection‹Fundamental Predicates on Basic Types: Strict (Referential) Equality›
text‹
Here is a first instance of a definition of strict value equality---for
the special case of the type @{typ "('𝔄)Boolean"}, it is just
the strict extension of the logical
equality:
›
overloading StrictRefEq ≡ "StrictRefEq :: [('𝔄)Boolean,('𝔄)Boolean] ⇒ ('𝔄)Boolean"
begin
definition StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n[code_unfold] :
"(x::('𝔄)Boolean) ≐ y ≡ λ τ. if (υ x) τ = true τ ∧ (υ y) τ = true τ
then (x ≜ y)τ
else invalid τ"
end
text‹which implies elementary properties like:›
lemma [simp,code_unfold] : "(true ≐ false) = false"
by(simp add:StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n)
lemma [simp,code_unfold] : "(false ≐ true) = false"
by(simp add:StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n)
lemma null_non_false [simp,code_unfold]:"(null ≐ false) = false"
apply(rule ext, simp add: StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n StrongEq_def false_def)
by (metis drop.simps cp_valid false_def is_none_code(2) Option.is_none_def valid4
bot_option_def null_fun_def null_option_def)
lemma null_non_true [simp,code_unfold]:"(null ≐ true) = false"
apply(rule ext, simp add: StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n StrongEq_def false_def)
by(simp add: true_def bot_option_def null_fun_def null_option_def)
lemma false_non_null [simp,code_unfold]:"(false ≐ null) = false"
apply(rule ext, simp add: StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n StrongEq_def false_def)
by(metis drop.simps cp_valid false_def is_none_code(2) Option.is_none_def valid4
bot_option_def null_fun_def null_option_def )
lemma true_non_null [simp,code_unfold]:"(true ≐ null) = false"
apply(rule ext, simp add: StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n StrongEq_def false_def)
by(simp add: true_def bot_option_def null_fun_def null_option_def)
text‹With respect to strictness properties and miscelleaneous side-calculi,
strict referential equality behaves on booleans as described in the
@{term "profile_bin⇩S⇩t⇩r⇩o⇩n⇩g⇩E⇩q_⇩v_⇩v"}:›
interpretation StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n : profile_bin⇩S⇩t⇩r⇩o⇩n⇩g⇩E⇩q_⇩v_⇩v "λ x y. (x::('𝔄)Boolean) ≐ y"
by unfold_locales (auto simp:StrictRefEq⇩B⇩o⇩o⇩l⇩e⇩a⇩n)
text‹In particular, it is strict, cp-preserving and const-preserving. In particular,
it generates the simplifier rules for terms like:›
lemma "(invalid ≐ false) = invalid" by(simp)
lemma "(invalid ≐ true) = invalid" by(simp)
lemma "(false ≐ invalid) = invalid" by(simp)
lemma "(true ≐ invalid) = invalid" by(simp)
lemma "((invalid::('𝔄)Boolean) ≐ invalid) = invalid" by(simp)
text‹Thus, the weak equality is \emph{not} reflexive.›
subsection‹Test Statements on Boolean Operations.›
text‹Here follows a list of code-examples, that explain the meanings
of the above definitions by compilation to code and execution to @{term "True"}.›
text‹Elementary computations on Boolean›
Assert "τ ⊨ υ(true)"
Assert "τ ⊨ δ(false)"
Assert "τ |≠ δ(null)"
Assert "τ |≠ δ(invalid)"
Assert "τ ⊨ υ((null::('𝔄)Boolean))"
Assert "τ |≠ υ(invalid)"
Assert "τ ⊨ (true and true)"
Assert "τ ⊨ (true and true ≜ true)"
Assert "τ ⊨ ((null or null) ≜ null)"
Assert "τ ⊨ ((null or null) ≐ null)"
Assert "τ ⊨ ((true ≜ false) ≜ false)"
Assert "τ ⊨ ((invalid ≜ false) ≜ false)"
Assert "τ ⊨ ((invalid ≐ false) ≜ invalid)"
Assert "τ ⊨ (true <> false)"
Assert "τ ⊨ (false <> true)"
end