(***************************************************************************** * HOL-TestGen --- theorem-prover based test case generation * http://www.brucker.ch/projects/hol-testgen/ * * This file is part of HOL-TestGen. * * Copyright (c) 2005-2012 ETH Zurich, Switzerland * 2008-2015 Achim D. Brucker, Germany * 2009-2017 Université Paris-Sud, France * 2015-2017 The University of Sheffield, UK * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * * Neither the name of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************) section\Parallel Composition\ theory ParallelComposition imports ElementaryPolicies begin text\ The following combinators are based on the idea that two policies are executed in parallel. Since both input and the output can differ, we chose to pair them. The new input pair will often contain repetitions, which can be reduced using the domain-restriction and domain-reduction operators. Using additional range-modifying operators such as $\nabla$, decide which result argument is chosen; this might be the first or the latter or, in case that $\beta = \gamma$, and $\beta$ underlies a lattice structure, the supremum or infimum of both, or, an arbitrary combination of them. In any case, although we have strictly speaking a pairing of decisions and not a nesting of them, we will apply the same notational conventions as for the latter, i.e. as for flattening. \ subsection\Parallel Combinators: Foundations\ text \ There are four possible semantics how the decision can be combined, thus there are four parallel composition operators. For each of them, we prove several properties. \ definition prod_orA ::"['\\'\, '\ \'\] \ ('\\'\ \ '\\'\)" (infixr "\\<^sub>\\<^sub>A" 55) where "p1 \\<^sub>\\<^sub>A p2 = (\(x,y). (case p1 x of \allow d1\ \(case p2 y of \allow d2\ \ \allow(d1,d2)\ | \deny d2\ \ \allow(d1,d2)\ | \ \ \) | \deny d1\\(case p2 y of \allow d2\ \ \allow(d1,d2)\ | \deny d2\ \ \deny (d1,d2)\ | \ \ \) | \ \ \))" lemma prod_orA_mt[simp]:"p \\<^sub>\\<^sub>A \ = \" apply (rule ext) apply (simp add: prod_orA_def) apply (auto) apply (simp split: option.splits decision.splits) done lemma mt_prod_orA[simp]:"\ \\<^sub>\\<^sub>A p = \" apply (rule ext) apply (simp add: prod_orA_def) done lemma prod_orA_quasi_commute: "p2 \\<^sub>\\<^sub>A p1 = (((\(x,y). (y,x)) o_f (p1 \\<^sub>\\<^sub>A p2))) o (\(a,b).(b,a))" apply (rule ext) apply (simp add: prod_orA_def policy_range_comp_def o_def) apply (auto)[1] apply (simp split: option.splits decision.splits) done definition prod_orD ::"['\ \ '\, '\ \ '\] \ ('\ \ '\ \ '\ \ '\ )" (infixr "\\<^sub>\\<^sub>D" 55) where "p1 \\<^sub>\\<^sub>D p2 = (\(x,y). (case p1 x of \allow d1\ \(case p2 y of \allow d2\ \ \allow(d1,d2)\ | \deny d2\ \ \deny(d1,d2)\ | \ \ \) | \deny d1\\(case p2 y of \allow d2\ \ \deny(d1,d2)\ | \deny d2\ \ \deny (d1,d2)\ | \ \ \) | \ \ \))" lemma prod_orD_mt[simp]:"p \\<^sub>\\<^sub>D \ = \" apply (rule ext) apply (simp add: prod_orD_def) apply (auto)[1] apply (simp split: option.splits decision.splits) done lemma mt_prod_orD[simp]:"\ \\<^sub>\\<^sub>D p = \" apply (rule ext) apply (simp add: prod_orD_def) done lemma prod_orD_quasi_commute: "p2 \\<^sub>\\<^sub>D p1 = (((\(x,y). (y,x)) o_f (p1 \\<^sub>\\<^sub>D p2))) o (\(a,b).(b,a))" apply (rule ext) apply (simp add: prod_orD_def policy_range_comp_def o_def) apply (auto)[1] apply (simp split: option.splits decision.splits) done text\ The following two combinators are by definition non-commutative, but still strict. \ definition prod_1 :: "['\\'\, '\ \'\] \ ('\\'\ \ '\\'\)" (infixr "\\<^sub>1" 55) where "p1 \\<^sub>1 p2 \ (\(x,y). (case p1 x of \allow d1\\(case p2 y of \allow d2\ \ \allow(d1,d2)\ | \deny d2\ \ \allow(d1,d2)\ | \ \ \) | \deny d1\ \(case p2 y of \allow d2\ \ \deny(d1,d2)\ | \deny d2\ \ \deny(d1,d2)\ | \ \ \) |\ \ \))" lemma prod_1_mt[simp]:"p \\<^sub>1 \ = \" apply (rule ext) apply (simp add: prod_1_def) apply (auto)[1] apply (simp split: option.splits decision.splits) done lemma mt_prod_1[simp]:"\ \\<^sub>1 p = \" apply (rule ext) apply (simp add: prod_1_def) done definition prod_2 :: "['\\'\, '\ \'\] \ ('\\'\ \ '\\'\)" (infixr "\\<^sub>2" 55) where "p1 \\<^sub>2 p2 \ (\(x,y). (case p1 x of \allow d1\ \(case p2 y of \allow d2\ \ \allow(d1,d2)\ | \deny d2\ \ \deny (d1,d2)\ | \ \ \) | \deny d1\\(case p2 y of \allow d2\ \ \allow(d1,d2)\ | \deny d2\ \ \deny (d1,d2)\ | \ \ \) |\ \\))" lemma prod_2_mt[simp]:"p \\<^sub>2 \ = \" apply (rule ext) apply (simp add: prod_2_def) apply (auto)[1] apply (simp split: option.splits decision.splits) done lemma mt_prod_2[simp]:"\ \\<^sub>2 p = \" apply (rule ext) apply (simp add: prod_2_def) done definition prod_1_id ::"['\\'\, '\\'\] \ ('\ \ '\\'\)" (infixr "\\<^sub>1\<^sub>I" 55) where "p \\<^sub>1\<^sub>I q = (p \\<^sub>1 q) o (\x. (x,x))" lemma prod_1_id_mt[simp]:"p \\<^sub>1\<^sub>I \ = \" apply (rule ext) apply (simp add: prod_1_id_def) done lemma mt_prod_1_id[simp]:"\ \\<^sub>1\<^sub>I p = \" apply (rule ext) apply (simp add: prod_1_id_def prod_1_def) done definition prod_2_id ::"['\\'\, '\\'\] \ ('\ \ '\\'\)" (infixr "\\<^sub>2\<^sub>I" 55) where"p \\<^sub>2\<^sub>I q = (p \\<^sub>2 q) o (\x. (x,x))" lemma prod_2_id_mt[simp]:"p \\<^sub>2\<^sub>I \ = \" apply (rule ext) apply (simp add: prod_2_id_def) done lemma mt_prod_2_id[simp]:"\ \\<^sub>2\<^sub>I p = \" apply (rule ext) apply (simp add: prod_2_id_def prod_2_def) done subsection\Combinators for Transition Policies\ text \ For constructing transition policies, two additional combinators are required: one combines state transitions by pairing the states, the other works equivalently on general maps. \ definition parallel_map :: "('\ \ '\) \ ('\ \ '\) \ ('\ \ '\ \ '\ \ '\)" (infixr "\\<^sub>M" 60) where "p1 \\<^sub>M p2 = (\ (x,y). case p1 x of \d1\ \ (case p2 y of \d2\ \ \(d1,d2)\ | \ \ \) | \ \ \)" definition parallel_st :: "('i \ '\ \ '\) \ ('i \ '\' \ '\') \ ('i \ '\ \ '\' \ '\ \ '\')" (infixr "\\<^sub>S" 60) where "p1 \\<^sub>S p2 = (p1 \\<^sub>M p2) o (\ (a,b,c). ((a,b),a,c))" subsection\Range Splitting\ text\ The following combinator is a special case of both a parallel composition operator and a range splitting operator. Its primary use case is when combining a policy with state transitions. \ definition comp_ran_split :: "[('\ \ '\) \ ('\ \'\), 'd \ '\] \ ('d \ '\) \ ('\ \ '\)" (infixr "\\<^sub>\" 100) where "P \\<^sub>\ p \ \x. case p (fst x) of \allow y\ \ (case ((fst P) (snd x)) of \ \ \ | \z\ \ \allow (y,z)\) | \deny y\ \ (case ((snd P) (snd x)) of \ \ \ | \z\ \ \deny (y,z)\) | \ \ \" text\An alternative characterisation of the operator is as follows:\ lemma comp_ran_split_charn: "(f, g) \\<^sub>\ p = ( (((p \ Allow)\\<^sub>\\<^sub>A (A\<^sub>p f)) \ ((p \ Deny) \\<^sub>\\<^sub>A (D\<^sub>p g))))" apply (rule ext) apply (simp add: comp_ran_split_def map_add_def o_def ran_restrict_def image_def Allow_def Deny_def dom_restrict_def prod_orA_def allow_pfun_def deny_pfun_def split:option.splits decision.splits) apply (auto) done subsection \Distributivity of the parallel combinators\ lemma distr_or1_a: "(F = F1 \ F2) \ (((N \\<^sub>1 F) o f) = (((N \\<^sub>1 F1) o f) \ ((N \\<^sub>1 F2) o f))) " apply (rule ext) apply (simp add: prod_1_def map_add_def split: decision.splits option.splits) subgoal for x apply (case_tac "f x") apply (simp_all add: prod_1_def map_add_def split: decision.splits option.splits) done done lemma distr_or1: "(F = F1 \ F2) \ ((g o_f ((N \\<^sub>1 F) o f)) = ((g o_f ((N \\<^sub>1 F1) o f)) \ (g o_f ((N \\<^sub>1 F2) o f)))) " apply (rule ext)+ apply (simp add: prod_1_def map_add_def policy_range_comp_def split: decision.splits option.splits) subgoal for x apply (case_tac "f x") apply (simp_all add: prod_1_def map_add_def split: decision.splits option.splits) done done lemma distr_or2_a: "(F = F1 \ F2) \ (((N \\<^sub>2 F) o f) = (((N \\<^sub>2 F1) o f) \ ((N \\<^sub>2 F2) o f))) " apply (rule ext) apply (simp add: prod_2_id_def prod_2_def map_add_def split: decision.splits option.splits) subgoal for x apply (case_tac "f x") apply (simp_all add: prod_2_def map_add_def split: decision.splits option.splits) done done lemma distr_or2: "(F = F1 \ F2) \ ((r o_f ((N \\<^sub>2 F) o f)) = ((r o_f ((N \\<^sub>2 F1) o f)) \ (r o_f ((N \\<^sub>2 F2) o f)))) " apply (rule ext) apply (simp add: prod_2_id_def prod_2_def map_add_def policy_range_comp_def split: decision.splits option.splits) subgoal for x apply (case_tac "f x") apply (simp_all add: prod_2_def map_add_def split: decision.splits option.splits) done done lemma distr_orA: "(F = F1 \ F2) \ ((g o_f ((N \\<^sub>\\<^sub>A F) o f)) = ((g o_f ((N \\<^sub>\\<^sub>A F1) o f)) \ (g o_f ((N \\<^sub>\\<^sub>A F2) o f)))) " apply (rule ext)+ apply (simp add: prod_orA_def map_add_def policy_range_comp_def split: decision.splits option.splits) subgoal for x apply (case_tac "f x") apply (simp_all add: map_add_def split: decision.splits option.splits) done done lemma distr_orD: "(F = F1 \ F2) \ ((g o_f ((N \\<^sub>\\<^sub>D F) o f)) = ((g o_f ((N \\<^sub>\\<^sub>D F1) o f)) \ (g o_f ((N \\<^sub>\\<^sub>D F2) o f)))) " apply (rule ext)+ apply (simp add: prod_orD_def map_add_def policy_range_comp_def split: decision.splits option.splits) subgoal for x apply (case_tac "f x") apply (simp_all add: map_add_def split: decision.splits option.splits) done done lemma coerc_assoc: "(r o_f P) o d = r o_f (P o d)" apply (simp add: policy_range_comp_def) apply (rule ext) apply (simp split: option.splits decision.splits) done lemmas ParallelDefs = prod_orA_def prod_orD_def prod_1_def prod_2_def parallel_map_def parallel_st_def comp_ran_split_def end