Theory UML_Pair
theory UML_Pair
imports "../UML_PropertyProfiles"
begin
section‹Collection Type Pairs: Operations \label{sec:collection_pairs}›
text‹The OCL standard provides the concept of \emph{Tuples}, \ie{} a family of record-types
with projection functions. In FeatherWeight OCL, only the theory of a special case is
developped, namely the type of Pairs, which is, however, sufficient for all applications
since it can be used to mimick all tuples. In particular, it can be used to express operations
with multiple arguments, roles of n-ary associations, ...›
subsection‹Semantic Properties of the Type Constructor›
lemma A[simp]:"Rep_Pair⇩b⇩a⇩s⇩e x ≠ None ⟹ Rep_Pair⇩b⇩a⇩s⇩e x ≠ null ⟹ (fst ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e x⌉⌉) ≠ bot"
by(insert Rep_Pair⇩b⇩a⇩s⇩e[of x],auto simp:null_option_def bot_option_def)
lemma A'[simp]:" x ≠ bot ⟹ x ≠ null ⟹ (fst ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e x⌉⌉) ≠ bot"
apply(insert Rep_Pair⇩b⇩a⇩s⇩e[of x], simp add: bot_Pair⇩b⇩a⇩s⇩e_def null_Pair⇩b⇩a⇩s⇩e_def)
apply(auto simp:null_option_def bot_option_def)
apply(erule contrapos_np[of "x = Abs_Pair⇩b⇩a⇩s⇩e None"])
apply(subst Rep_Pair⇩b⇩a⇩s⇩e_inject[symmetric], simp)
apply(subst Pair⇩b⇩a⇩s⇩e.Abs_Pair⇩b⇩a⇩s⇩e_inverse, simp_all,simp add: bot_option_def)
apply(erule contrapos_np[of "x = Abs_Pair⇩b⇩a⇩s⇩e ⌊None⌋"])
apply(subst Rep_Pair⇩b⇩a⇩s⇩e_inject[symmetric], simp)
apply(subst Pair⇩b⇩a⇩s⇩e.Abs_Pair⇩b⇩a⇩s⇩e_inverse, simp_all,simp add: null_option_def bot_option_def)
done
lemma B[simp]:"Rep_Pair⇩b⇩a⇩s⇩e x ≠ None ⟹ Rep_Pair⇩b⇩a⇩s⇩e x ≠ null ⟹ (snd ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e x⌉⌉) ≠ bot"
by(insert Rep_Pair⇩b⇩a⇩s⇩e[of x],auto simp:null_option_def bot_option_def)
lemma B'[simp]:"x ≠ bot ⟹ x ≠ null ⟹ (snd ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e x⌉⌉) ≠ bot"
apply(insert Rep_Pair⇩b⇩a⇩s⇩e[of x], simp add: bot_Pair⇩b⇩a⇩s⇩e_def null_Pair⇩b⇩a⇩s⇩e_def)
apply(auto simp:null_option_def bot_option_def)
apply(erule contrapos_np[of "x = Abs_Pair⇩b⇩a⇩s⇩e None"])
apply(subst Rep_Pair⇩b⇩a⇩s⇩e_inject[symmetric], simp)
apply(subst Pair⇩b⇩a⇩s⇩e.Abs_Pair⇩b⇩a⇩s⇩e_inverse, simp_all,simp add: bot_option_def)
apply(erule contrapos_np[of "x = Abs_Pair⇩b⇩a⇩s⇩e ⌊None⌋"])
apply(subst Rep_Pair⇩b⇩a⇩s⇩e_inject[symmetric], simp)
apply(subst Pair⇩b⇩a⇩s⇩e.Abs_Pair⇩b⇩a⇩s⇩e_inverse, simp_all,simp add: null_option_def bot_option_def)
done
subsection‹Fundamental Properties of Strict Equality \label{sec:pair-strict-eq}›
text‹After the part of foundational operations on sets, we detail here equality on sets.
Strong equality is inherited from the OCL core, but we have to consider
the case of the strict equality. We decide to overload strict equality in the
same way we do for other value's in OCL:›
overloading
StrictRefEq ≡ "StrictRefEq :: [('𝔄,'α::null,'β::null)Pair,('𝔄,'α::null,'β::null)Pair] ⇒ ('𝔄)Boolean"
begin
definition StrictRefEq⇩P⇩a⇩i⇩r :
"((x::('𝔄,'α::null,'β::null)Pair) ≐ y) ≡ (λ τ. if (υ x) τ = true τ ∧ (υ y) τ = true τ
then (x ≜ y)τ
else invalid τ)"
end
text‹Property proof in terms of @{term "profile_bin⇩S⇩t⇩r⇩o⇩n⇩g⇩E⇩q_⇩v_⇩v"}›
interpretation StrictRefEq⇩P⇩a⇩i⇩r : profile_bin⇩S⇩t⇩r⇩o⇩n⇩g⇩E⇩q_⇩v_⇩v "λ x y. (x::('𝔄,'α::null,'β::null)Pair) ≐ y"
by unfold_locales (auto simp: StrictRefEq⇩P⇩a⇩i⇩r)
subsection‹Standard Operations Definitions›
text‹This part provides a collection of operators for the Pair type.›
subsubsection‹Definition: Pair Constructor›
definition OclPair::"('𝔄, 'α) val ⇒
('𝔄, 'β) val ⇒
('𝔄,'α::null,'β::null) Pair" (‹Pair{(_),(_)}›)
where "Pair{X,Y} ≡ (λ τ. if (υ X) τ = true τ ∧ (υ Y) τ = true τ
then Abs_Pair⇩b⇩a⇩s⇩e ⌊⌊(X τ, Y τ)⌋⌋
else invalid τ)"
interpretation OclPair : profile_bin⇩v_⇩v
OclPair "λ x y. Abs_Pair⇩b⇩a⇩s⇩e ⌊⌊(x, y)⌋⌋"
apply(unfold_locales, auto simp: OclPair_def bot_Pair⇩b⇩a⇩s⇩e_def null_Pair⇩b⇩a⇩s⇩e_def)
by(auto simp: Abs_Pair⇩b⇩a⇩s⇩e_inject null_option_def bot_option_def)
subsubsection‹Definition: First›
definition OclFirst::" ('𝔄,'α::null,'β::null) Pair ⇒ ('𝔄, 'α) val" (‹ _ .First'(')›)
where "X .First() ≡ (λ τ. if (δ X) τ = true τ
then fst ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e (X τ)⌉⌉
else invalid τ)"
interpretation OclFirst : profile_mono⇩d OclFirst "λx. fst ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e (x)⌉⌉"
by unfold_locales (auto simp: OclFirst_def)
subsubsection‹Definition: Second›
definition OclSecond::" ('𝔄,'α::null,'β::null) Pair ⇒ ('𝔄, 'β) val" (‹_ .Second'(')›)
where "X .Second() ≡ (λ τ. if (δ X) τ = true τ
then snd ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e (X τ)⌉⌉
else invalid τ)"
interpretation OclSecond : profile_mono⇩d OclSecond "λx. snd ⌈⌈Rep_Pair⇩b⇩a⇩s⇩e (x)⌉⌉"
by unfold_locales (auto simp: OclSecond_def)
subsection‹Logical Properties›
lemma 1 : "τ ⊨ υ Y ⟹ τ ⊨ Pair{X,Y} .First() ≜ X"
apply(case_tac "¬(τ ⊨ υ X)")
apply(erule foundation7'[THEN iffD2, THEN foundation15[THEN iffD2,
THEN StrongEq_L_subst2_rev]],simp_all add:foundation18')
apply(auto simp: OclValid_def valid_def defined_def StrongEq_def OclFirst_def OclPair_def
true_def false_def invalid_def bot_fun_def null_fun_def)
apply(auto simp: Abs_Pair⇩b⇩a⇩s⇩e_inject null_option_def bot_option_def bot_Pair⇩b⇩a⇩s⇩e_def null_Pair⇩b⇩a⇩s⇩e_def)
by(simp add: Abs_Pair⇩b⇩a⇩s⇩e_inverse)
lemma 2 : "τ ⊨ υ X ⟹ τ ⊨ Pair{X,Y} .Second() ≜ Y"
apply(case_tac "¬(τ ⊨ υ Y)")
apply(erule foundation7'[THEN iffD2, THEN foundation15[THEN iffD2,
THEN StrongEq_L_subst2_rev]],simp_all add:foundation18')
apply(auto simp: OclValid_def valid_def defined_def StrongEq_def OclSecond_def OclPair_def
true_def false_def invalid_def bot_fun_def null_fun_def)
apply(auto simp: Abs_Pair⇩b⇩a⇩s⇩e_inject null_option_def bot_option_def bot_Pair⇩b⇩a⇩s⇩e_def null_Pair⇩b⇩a⇩s⇩e_def)
by(simp add: Abs_Pair⇩b⇩a⇩s⇩e_inverse)
subsection‹Algebraic Execution Properties›
lemma proj1_exec [simp, code_unfold] : "Pair{X,Y} .First() = (if (υ Y) then X else invalid endif)"
apply(rule ext, rename_tac "τ", simp add: foundation22[symmetric])
apply(case_tac "¬(τ ⊨ υ Y)")
apply(erule foundation7'[THEN iffD2,
THEN foundation15[THEN iffD2,
THEN StrongEq_L_subst2_rev]],simp_all)
apply(subgoal_tac "τ ⊨ υ Y")
apply(erule foundation13[THEN iffD2, THEN StrongEq_L_subst2_rev], simp_all)
by(erule 1)
lemma proj2_exec [simp, code_unfold] : "Pair{X,Y} .Second() = (if (υ X) then Y else invalid endif)"
apply(rule ext, rename_tac "τ", simp add: foundation22[symmetric])
apply(case_tac "¬(τ ⊨ υ X)")
apply(erule foundation7'[THEN iffD2, THEN foundation15[THEN iffD2,
THEN StrongEq_L_subst2_rev]],simp_all)
apply(subgoal_tac "τ ⊨ υ X")
apply(erule foundation13[THEN iffD2, THEN StrongEq_L_subst2_rev], simp_all)
by(erule 2)
subsection‹Test Statements›
instantiation Pair⇩b⇩a⇩s⇩e :: (equal,equal)equal
begin
definition "HOL.equal k l ⟷ (k::('a::equal,'b::equal)Pair⇩b⇩a⇩s⇩e) = l"
instance by standard (rule equal_Pair⇩b⇩a⇩s⇩e_def)
end
lemma equal_Pair⇩b⇩a⇩s⇩e_code [code]:
"HOL.equal k (l::('a::{equal,null},'b::{equal,null})Pair⇩b⇩a⇩s⇩e) ⟷ Rep_Pair⇩b⇩a⇩s⇩e k = Rep_Pair⇩b⇩a⇩s⇩e l"
by (auto simp add: equal Pair⇩b⇩a⇩s⇩e.Rep_Pair⇩b⇩a⇩s⇩e_inject)
Assert "τ ⊨ invalid .First() ≜ invalid "
Assert "τ ⊨ null .First() ≜ invalid "
Assert "τ ⊨ null .Second() ≜ invalid .Second() "
Assert "τ ⊨ Pair{invalid, true} ≜ invalid "
Assert "τ ⊨ υ(Pair{null, true}.First())"
Assert "τ ⊨ (Pair{null, true}).First() ≜ null "
Assert "τ ⊨ (Pair{null, Pair{true,invalid}}).First() ≜ invalid "
end