Theory CSP_PTick_Monotonicities

(***********************************************************************************
 * Copyright (c) 2025 Université Paris-Saclay
 *
 * Author: Benoît Ballenghien, Université Paris-Saclay,
 *         CNRS, ENS Paris-Saclay, LMF
 *
 * 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
 *
 * * 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.
 *
 * 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 HOLDER 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.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 ***********************************************************************************)


chapter ‹Monotonicity Properties›

(*<*)
theory CSP_PTick_Monotonicities
  imports Sequential_Composition_Generalized_Cont
    Synchronization_Product_Generalized_Cont
begin
  (*>*)


subsection ‹Sequential Composition›

lemma mono_Seqptick_FD : ‹P ⊑FD P' ⟹ (⋀r. Q r ⊑FD Q' r) ⟹ P ;✓ Q ⊑FD P' ;✓ Q'›
proof (rule trans_FD[of _ ‹P' ;✓ Q›])
  show ‹P ⊑FD P' ⟹ (⋀r. Q r ⊑FD Q' r) ⟹ P ;✓ Q ⊑FD P' ;✓ Q›
    unfolding refine_defs Seqptick_projs
    by (auto simp add: subset_iff T_F_spec[symmetric])
next
  show ‹P ⊑FD P' ⟹ (⋀r. Q r ⊑FD Q' r) ⟹ P' ;✓ Q ⊑FD P' ;✓ Q'›
    unfolding less_eq_processptick_def Seqptick_projs
    by (simp add: subset_iff T_F_spec[symmetric]) metis
qed

lemma mono_Seqptick_DT : ‹P ⊑DT P' ⟹ (⋀r. Q r ⊑DT Q' r) ⟹ P ;✓ Q ⊑DT P' ;✓ Q'›
proof (rule trans_DT[of _ ‹P' ;✓ Q›])
  show ‹P ;✓ Q ⊑DT P' ;✓ Q› if ‹P ⊑DT P'›
  proof (rule trace_divergence_refine_optimizedI)
    from ‹P ⊑DT P'› show ‹s ∈ 𝒟 (P' ;✓ Q) ⟹ s ∈ 𝒟 (P ;✓ Q)› for s
      by (auto simp add: refine_defs Seqptick_projs)
  next
    from ‹P ⊑DT P'› show ‹s ∈ 𝒯 (P' ;✓ Q) ⟹ s ∈ 𝒯 (P ;✓ Q)› for s
      by (auto simp add: Seqptick_projs refine_defs)
  qed
next
  show ‹(⋀r. Q r ⊑DT Q' r) ⟹ P' ;✓ Q ⊑DT P' ;✓ Q'›
    by (simp add: refine_defs Seqptick_projs) blast
qed


lemma mono_Seqptick_F_right : ‹(⋀r. Q r ⊑F Q' r) ⟹ P ;✓ Q ⊑F P ;✓ Q'›
  by (auto simp add: failure_refine_def Seqptick_projs) blast

lemma mono_Seqptick_D_right : ‹(⋀r. Q r ⊑D Q' r) ⟹ P ;✓ Q ⊑D P ;✓ Q'›
  by (simp add: divergence_refine_def Seqptick_projs) blast

lemma  mono_Seqptick_T_right : ‹(⋀r. Q r ⊑T Q' r) ⟹ P ;✓ Q ⊑T P ;✓ Q'›
  by (simp add: trace_refine_def Seqptick_projs) blast

text ‹Left Sequence monotonicity doesn't hold for term‹(⊑F)›, term‹(⊑D)› and term‹(⊑T)›.›

lemmas monos_Seqptick = mono_Seqptick mono_Seqptick_FD mono_Seqptick_DT
  mono_Seqptick_F_right mono_Seqptick_D_right mono_Seqptick_T_right



subsection ‹Multiple Sequential Composition›

lemma mono_MultiSeqptick :
  ‹(⋀x r. x ∈ set L ⟹ P x r ⊑ Q x r) ⟹
   (SEQ✓ l ∈@ L. P l) r ⊑ (SEQ✓ l ∈@ L. Q l) r›
  by (induct L arbitrary: r, simp_all add: fun_belowI mono_Seqptick)

lemma mono_MultiSeqptick_FD :
  ‹(⋀x r. x ∈ set L ⟹ P x r ⊑FD Q x r) ⟹
   (SEQ✓ l ∈@ L. P l) r ⊑FD (SEQ✓ l ∈@ L. Q l) r›
  and mono_MultiSeqptick_DT :
  ‹(⋀x r. x ∈ set L ⟹ P x r ⊑DT Q x r) ⟹
   (SEQ✓ l ∈@ L. P l) r ⊑DT (SEQ✓ l ∈@ L. Q l) r›
  by (induct L arbitrary: r, simp_all add: monos_Seqptick)

lemmas monos_MultiSeqptick =
  mono_MultiSeqptick mono_MultiSeqptick_FD mono_MultiSeqptick_FD



subsection ‹Synchronization Product›

context Syncptick_locale begin

lemma mono_Syncptick_DT :
  ‹P ⊑DT P' ⟹ Q ⊑DT Q' ⟹ P ⟦A⟧✓ Q ⊑DT P' ⟦A⟧✓ Q'›
  by (simp add: refine_defs T_Syncptick D_Syncptick) blast

lemma mono_Syncptick_FD : ‹P ⟦A⟧✓ Q ⊑FD P' ⟦A⟧✓ Q'›
  if ‹P ⊑FD P'› and ‹Q ⊑FD Q'›
proof -
  from ‹P ⊑FD P'› ‹Q ⊑FD Q'› have ‹P ⊑DT P'› ‹Q ⊑DT Q'›
    by (simp_all add: le_ref2T refine_defs)
  with mono_Syncptick_DT have ‹P ⟦A⟧✓ Q ⊑DT P' ⟦A⟧✓ Q'› by blast
  hence * : ‹P ⟦A⟧✓ Q ⊑D P' ⟦A⟧✓ Q'› by (simp add: leDT_imp_leD)
  show ‹P ⟦A⟧✓ Q ⊑FD P' ⟦A⟧✓ Q'›
  proof (rule leF_leD_imp_leFD[OF _ "*"],
      unfold failure_refine_def, safe)
    fix t X assume ‹(t, X) ∈ ℱ (P' ⟦A⟧✓ Q')›
    then consider ‹t ∈ 𝒟 (P' ⟦A⟧✓ Q')›
      | (fail) t_P t_Q X_P X_Q
      where ‹(t_P, X_P) ∈ ℱ P'› ‹(t_Q, X_Q) ∈ ℱ Q'›
        ‹t setinterleaves✓⇘tick_join⇙ ((t_P, t_Q), A)›
        ‹X ⊆ super_ref_Syncptick tick_join X_P A X_Q›
      unfolding Syncptick_projs by blast
    thus ‹(t, X) ∈ ℱ (P ⟦A⟧✓ Q)›
    proof cases
      show ‹t ∈ 𝒟 (P' ⟦A⟧✓ Q') ⟹ (t, X) ∈ ℱ (P ⟦A⟧✓ Q)›
        using "*" D_F unfolding divergence_refine_def by blast
    next
      case fail
      from fail(1, 2) ‹P ⊑FD P'› ‹Q ⊑FD Q'›
      have ‹(t_P, X_P) ∈ ℱ P› ‹(t_Q, X_Q) ∈ ℱ Q›
        unfolding refine_defs by auto
      with fail(3, 4) show ‹(t, X) ∈ ℱ (P ⟦A⟧✓ Q)›
        by (auto simp add: F_Syncptick)
    qed
  qed
qed




lemmas monos_Syncptick = mono_Syncptick mono_Syncptick_FD mono_Syncptick_DT


end


subsection ‹Multiple Synchronization Product›

lemma mono_MultiSyncptick :
  ‹(⋀l. l ∈ set L ⟹ P l ⊑ Q l) ⟹ ⟦S⟧✓ l ∈@ L. P l ⊑ ⟦S⟧✓ l ∈@ L. Q l›
  by (induct L rule: induct_list012)
    (simp_all add: SyncRlist.mono_Syncptick mono_Renaming)

lemma mono_MultiSyncptick_FD :
  ‹(⋀l. l ∈ set L ⟹ P l ⊑FD Q l) ⟹ ⟦S⟧✓ l ∈@ L. P l ⊑FD ⟦S⟧✓ l ∈@ L. Q l›
  by (induct L rule: induct_list012)
    (simp_all add: SyncRlist.mono_Syncptick_FD mono_Renaming_FD)


lemma mono_MultiSyncptick_DT :
  ‹(⋀l. l ∈ set L ⟹ P l ⊑DT Q l) ⟹ ⟦S⟧✓ l ∈@ L. P l ⊑DT ⟦S⟧✓ l ∈@ L. Q l›
  by (induct L rule: induct_list012)
    (simp_all add: SyncRlist.mono_Syncptick_DT mono_Renaming_DT)


lemmas monos_MultiSyncptick =
  mono_MultiSyncptick mono_MultiSyncptick_FD mono_MultiSyncptick_DT




(*<*)
end
  (*>*)