Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Isabelle/Archive-of-Formal-Proofs/thys/Complx/   (Sammlung formaler Beweise Version 2026-5©)  Datei vom 29.4.2026 mit Größe 17 kB image not shown  

Quelle  SmallStep.thy

  Sprache: Isabelle
 

(*
 * Copyright 2016, Data61, CSIRO
 *
 * This software may be distributed and modified according to the terms of
 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
 * See "LICENSE_BSD2.txt" for details.
 *
 * @TAG(DATA61_BSD)
 *)

section COMPLX small-step semantics
theory SmallStep
imports Language
begin

text The procedure environment
type_synonym ('s,'p,'f) body = "'p ==> ('s,'p,'f) com option"

text State types
datatype ('s,'f) xstate = Normal 's | Fault 'f | Stuck

lemma rtrancl_mono_proof[mono]:
   "(a b. x a b y a b) ==> rtranclp x a b rtranclp y a b"
   apply (rule impI, rotate_tac, induct rule: rtranclp.induct)
    apply simp_all
   apply (metis rtranclp.intros)
   done


primrec redex:: "('s,'p,'f)com ==> ('s,'p,'f)com"
where
"redex Skip = Skip" |
"redex (Basic f) = (Basic f)" |
"redex (Spec r) = (Spec r)" |
"redex (Seq c1 c2) = redex c1" |
"redex (Cond b c1 c2) = (Cond b c1 c2)" |
"redex (While b c) = (While b c)" |
"redex (Call p) = (Call p)" |
"redex (DynCom d) = (DynCom d)" |
"redex (Guard f b c) = (Guard f b c)" |
"redex (Throw) = Throw" |
"redex (Catch c1 c2) = redex c1" |
"redex (Await b c) = Await b c" |
"redex (Parallel cs) = Parallel cs"

subsection Small-Step Computation: Γ (c, s) (c', s')

text The final configuration is either of the form (Skip,_) for normal
 , or @{term "(Throw,Normal s)"} in case the program was started in
  @{term "Normal"} state and terminated abruptly. Explicit abrupt states are removed
  the language definition and thus do not need to be propogated.


type_synonym ('s,'p,'f) config = "('s,'p,'f)com × ('s,'f) xstate"

definition final:: "('s,'p,'f) config ==> bool" where
"final cfg = (fst cfg=Skip (fst cfg=Throw (s. snd cfg=Normal s)))"

primrec atom_com :: "🍋('s,'p,'f) body ==> ('s, 'p, 'f) com ==> bool" where
  "atom_com Skip = True" | 
  "atom_com (Basic f) = True" | 
  "atom_com (Spec r) = True" | 
  "atom_com (Seq c1 c2) = (atom_com c1 atom_com c2)" | 
  "atom_com (Cond b c1 c2) = (atom_com c1 atom_com c2)" | 
  "atom_com (While b c) = atom_com c" | 
 (* Change to  atom_com (Call p) = atom_com (\<Theta> p)
  Butow do we pass function body from step? *)

  "atom_com (Call p) = False" |
  "atom_com (DynCom f) = (s::'s. atom_com (f s))" | 
  "atom_com (Guard f g c) = atom_com c" | 
  "atom_com Throw = True" | 
  "atom_com (Catch c1 c2) = (atom_com c1 atom_com c2)" | 
  "atom_com (Parallel cs) = False" | 
  "atom_com (Await b c) = False"


inductive
      "step"::"[('s,'p,'f) body, ('s,'p,'f) config,('s,'p,'f) config] ==> bool"
                                (_ (_ / _) [81,81,81100)
  and "step_rtrancl" :: "[('s,'p,'f) body, ('s,'p,'f) config,('s,'p,'f) config] ==> bool"
                                (_ (_ */ _) [81,81,81100)
  for Γ::"('s,'p,'f) body"
where
   a * b (step Γ)** a b"
| Basic: (Basic f,Normal s) (Skip,Normal (f s))"

| Spec: "(s,t) r ==> Γ (Spec r,Normal s) (Skip,Normal t)"
| SpecStuck: "t. (s,t) r ==> Γ (Spec r,Normal s) (Skip,Stuck)"

| Guard: "sg ==> Γ (Guard f g c,Normal s) (c,Normal s)"
  
| GuardFault: "sg ==> Γ (Guard f g c,Normal s) (Skip,Fault f)"


| Seq: (c1,s) (c1',s')
        ==>
        Γ (Seq c1 c2,s) (Seq c1' c2, s')"
| SeqSkip: (Seq Skip c2,s) (c2, s)"
| SeqThrow: (Seq Throw c2,Normal s) (Throw, Normal s)"

| CondTrue:  "sb ==> Γ (Cond b c1 c2,Normal s) (c1,Normal s)"
| CondFalse: "sb ==> Γ (Cond b c1 c2,Normal s) (c2,Normal s)"

| WhileTrue: "[sb]
              ==>
              Γ (While b c,Normal s) (Seq c (While b c),Normal s)"

| WhileFalse: "[sb]
               ==>
               Γ (While b c,Normal s) (Skip,Normal s)"

| Call: "Γ p=Some b ==>
         Γ (Call p,Normal s) (b,Normal s)"

| CallUndefined: "Γ p=None ==>
         Γ (Call p,Normal s) (Skip,Stuck)"

| DynCom: (DynCom c,Normal s) (c s,Normal s)"

| Catch: "[Γ (c1,s) (c1',s')]
          ==>
          Γ (Catch c1 c2,s) (Catch c1' c2,s')"

| CatchSkip: (Catch Skip c2,s) (Skip,s)"
| CatchThrow: (Catch Throw c2,Normal s) (c2,Normal s)"

| FaultProp:  "[cSkip; redex c = c] ==> Γ (c,Fault f) (Skip,Fault f)"
| StuckProp:  "[cSkip; redex c = c] ==> Γ (c,Stuck) (Skip,Stuck)"


| Parallel: "[ i < length cs; Γ (cs!i, s) (c', s') ]
            ==> Γ (Parallel cs, s) (Parallel (cs[i := c']), s')"

| ParSkip: "[ c set cs. c = Skip ] ==> Γ (Parallel cs, s) (Skip, s)"
(* If exception is thrown, the parallel execution may either abort
   immediately (rule ParThrow) or keep executing (rule Parallel) *)

| ParThrow: "[ Throw set cs ] ==> Γ (Parallel cs, s) (Throw, s)"


| Await: "[ s b; Γ (c, Normal s) * (c', Normal s');
           atom_com c; c' = Skip c' = Throw ]
          ==> Γ (Await b c, Normal s) (c', Normal s')"
| AwaitStuck: 
         "[ s b; Γ (c, Normal s) * (c', Stuck) ;
           atom_com c]
          ==> Γ (Await b c, Normal s) (Skip, Stuck)" 
| AwaitFault: 
         "[ s b; Γ (c, Normal s) * (c', Fault f) ;
           atom_com c]
          ==> Γ (Await b c, Normal s) (Skip, Fault f)" 
| AwaitNonAtom: 
         " ¬ atom_com c
          ==> Γ (Await b c, Normal s) (Skip, Stuck)"


lemmas step_induct = step.induct [of _ "(c,s)" "(c',s')", split_format (complete), case_names
Basic Spec SpecStuck Guard GuardFault Seq SeqSkip SeqThrow CondTrue CondFalse
WhileTrue WhileFalse Call CallUndefined DynCom Catch CatchThrow CatchSkip
FaultProp StuckProp Parallel ParSkip Await, induct set]

text The execution of a command is blocked if it cannot make progress, but is not in a final
 . It is the intention that cfg. Γ (c, s) cfg) final (c, s) blocked Γ c s, but
  do not prove this.


function(sequential) blocked :: "('s,'p,'f) body ==> ('s,'p,'f) com ==> ('s,'f)xstate ==> bool" where
  "blocked Γ (Seq (Await b c1) c2) (Normal s) = (s b)"
"blocked Γ (Catch (Await b c1) c2) (Normal s) = (s b)"
"blocked Γ (Await b c) (Normal s) = (s b (c' s'. Γ (c, Normal s) * (c', Normal s') ¬ final (c', Normal s')))"
"blocked Γ (Parallel cs) (Normal s) = (t set cs. blocked Γ t (Normal s) final (t, Normal s))"
"blocked Γ _ _ = False"
by (pat_completeness, auto)

inductive_cases step_elim_cases [cases set]:
 (Skip,s) u"
 (Guard f g c,s) u"
 (Basic f,s) u"
 (Spec r,s) u"
 (Seq c1 c2,s) u"
 (Cond b c1 c2,s) u"
 (While b c,s) u"
 (Call p,s) u"
 (DynCom c,s) u"
 (Throw,s) u"
 (Catch c1 c2,s) u"
 (Parallel cs,s) u"
 (Await b e,s) u"


inductive_cases step_Normal_elim_cases [cases set]:
 (Skip,Normal s) u"
 (Guard f g c,Normal s) u"
 (Basic f,Normal s) u"
 (Spec r,Normal s) u"
 (Seq c1 c2,Normal s) u"
 (Cond b c1 c2,Normal s) u"
 (While b c,Normal s) u"
 (Call p,Normal s) u"
 (DynCom c,Normal s) u"
 (Throw,Normal s) u"
 (Catch c1 c2,Normal s) u"
 (Parallel cs,Normal s) u"
 (Await b e,Normal s) u"


abbreviation 
 "step_trancl" :: "[('s,'p,'f) body, ('s,'p,'f) config,('s,'p,'f) config] ==> bool"
                                (_ (_ +/ _) [81,81,81100)
 where
  cf0 + cf1 (CONST step Γ)++ cf0 cf1"

abbreviation 
 "step_n_trancl" :: "[('s,'p,'f) body, ('s,'p,'f) config,nat,('s,'p,'f) config] ==> bool"
                                (_ (_ n_/ _) [81,81,81,81100)
 where
  cf0 nn cf1 (CONST step Γ ^^ n) cf0 cf1"

lemma no_step_final: 
  assumes step: (c,s) (c',s')"
  shows "final (c,s) ==> P"
using step
by induct (auto simp add: final_def)

lemma no_step_final':
  assumes step: cfg cfg'"
  shows "final cfg ==> P"
using step
  by (cases cfg, cases cfg') (auto intro: no_step_final)

lemma no_steps_final:
v * w ==> final v ==> w = v"
  apply (cases v)
  apply simp
  apply  (erule converse_rtranclpE)
   apply simp
   apply (erule (1) no_step_final')
 done

lemma step_Fault: 
  assumes step:  (c, s) (c', s')"
  shows "f. s=Fault f ==> s'=Fault f"
using step

by (induct) auto

lemma step_Stuck: 
  assumes step:  (c, s) (c', s')"
  shows "f. s=Stuck ==> s'=Stuck"
using step
by (induct) auto

lemma SeqSteps: 
  assumes steps: cfg1* cfg2"
  shows " c1 s c1' s'. [cfg1 = (c1,s);cfg2=(c1',s')]
          ==> Γ (Seq c1 c2,s) * (Seq c1' c2, s')"
using steps
proof (induct rule: converse_rtranclp_induct [case_names Refl Trans])
  case Refl
  thus ?case
    by simp
next
  case (Trans cfg1 cfg'')
  have step:  cfg1 cfg''" by fact
  have steps:  cfg'' * cfg2" by fact
  have cfg1"cfg1 = (c1, s)" and cfg2"cfg2 = (c1', s')"  by fact+
  obtain c1'' s'' where cfg'': "cfg''=(c1'',s'')"
    by (cases cfg'') auto
  from step cfg1 cfg'' 
  have  (c1,s) (c1'',s'')"
    by simp
  hence  (Seq c1 c2,s) (Seq c1'' c2,s'')"
    by (rule step.Seq)
  also from Trans.hyps (3) [OF cfg'' cfg2]
  have  (Seq c1'' c2, s'') * (Seq c1' c2, s')" .
  finally show ?case .
qed


lemma CatchSteps: 
  assumes steps: cfg1* cfg2"
  shows " c1 s c1' s'. [cfg1 = (c1,s); cfg2=(c1',s')]
          ==> Γ (Catch c1 c2,s) * (Catch c1' c2, s')"
using steps
proof (induct rule: converse_rtranclp_induct [case_names Refl Trans])
  case Refl
  thus ?case
    by simp
next
  case (Trans cfg1 cfg'')
  have step:  cfg1 cfg''" by fact
  have steps:  cfg'' * cfg2" by fact
  have cfg1"cfg1 = (c1, s)" and cfg2"cfg2 = (c1', s')"  by fact+
  obtain c1'' s'' where cfg'': "cfg''=(c1'',s'')"
    by (cases cfg'') auto
  from step cfg1 cfg'' 
  have s:  (c1,s) (c1'',s'')"
    by simp
  hence  (Catch c1 c2,s) (Catch c1'' c2,s'')"
    by (rule step.Catch)
  also from Trans.hyps (3) [OF cfg'' cfg2]
  have  (Catch c1'' c2, s'') * (Catch c1' c2, s')" .
  finally show ?case .      
qed


lemma steps_Fault:  (c, Fault f) * (Skip, Fault f)"
proof (induct c)
  case (Seq c1 c2)
  have steps_c1 (c1, Fault f) * (Skip, Fault f)" by fact
  have steps_c2 (c2, Fault f) * (Skip, Fault f)" by fact
  from SeqSteps [OF steps_c1 refl refl]
  have  (Seq c1 c2, Fault f) * (Seq Skip c2, Fault f)".
  also
  have  (Seq Skip c2, Fault f) (c2, Fault f)" by (rule SeqSkip)
  also note steps_c2
  finally show ?case by simp
next
  case (Catch c1 c2)
  have steps_c1 (c1, Fault f) * (Skip, Fault f)" by fact
  from CatchSteps [OF steps_c1 refl refl]
  have  (Catch c1 c2, Fault f) * (Catch Skip c2, Fault f)".
  also
  have  (Catch Skip c2, Fault f) (Skip, Fault f)" by (rule CatchSkip) 
  finally show ?case by simp
qed (fastforce intro: step.intros)+

lemma steps_Stuck:  (c, Stuck) * (Skip, Stuck)"
proof (induct c)
  case (Seq c1 c2)
  have steps_c1 (c1, Stuck) * (Skip, Stuck)" by fact
  have steps_c2 (c2, Stuck) * (Skip, Stuck)" by fact
  from SeqSteps [OF steps_c1 refl refl]
  have  (Seq c1 c2, Stuck) * (Seq Skip c2, Stuck)".
  also
  have  (Seq Skip c2, Stuck) (c2, Stuck)" by (rule SeqSkip)
  also note steps_c2
  finally show ?case by simp
next
  case (Catch c1 c2)
  have steps_c1 (c1, Stuck) * (Skip, Stuck)" by fact
  from CatchSteps [OF steps_c1 refl refl]
  have  (Catch c1 c2, Stuck) * (Catch Skip c2, Stuck)" .
  also
  have  (Catch Skip c2, Stuck) (Skip, Stuck)" by (rule CatchSkip) 
  finally show ?case by simp
qed (fastforce intro: step.intros)+

lemma step_Fault_prop: 
  assumes step:  (c, s) (c', s')"
  shows "f. s=Fault f ==> s'=Fault f"
using step
by (induct) auto

lemma step_Stuck_prop: 
  assumes step:  (c, s) (c', s')"
  shows "s=Stuck ==> s'=Stuck"
using step
by (induct) auto

lemma steps_Fault_prop: 
  assumes step:  (c, s) * (c', s')"
  shows "s=Fault f ==> s'=Fault f"
using step
proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])
  case Refl thus ?case by simp
next
  case (Trans c s c'' s'')
  thus ?case
    by (auto intro: step_Fault_prop)
qed

lemma steps_Stuck_prop: 
  assumes step:  (c, s) * (c', s')"
  shows "s=Stuck ==> s'=Stuck"
using step
proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])
  case Refl thus ?case by simp
next
  case (Trans c s c'' s'')
  thus ?case
    by (auto intro: step_Stuck_prop)
qed

end

Messung V0.5 in Prozent
C=84 H=96 G=90

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.