thys/Hoare_tm2.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 03 Apr 2014 15:28:01 +0100
changeset 17 86918b45b2e6
parent 16 0352ad5ee9c5
child 19 087d82632852
permissions -rw-r--r--
added a version using finfuns
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
header {* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
  Separation logic for Turing Machines
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
     5
theory Hoare_tm2
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
imports Hoare_gen 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
        My_block 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
        Data_slot
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
        "~~/src/HOL/Library/FinFun_Syntax"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
begin
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
fun pretty_terms ctxt trms =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
  Pretty.block (Pretty.commas (map (Syntax.pretty_term ctxt) trms))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
structure StepRules = Named_Thms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  (val name = @{binding "step"}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
   val description = "Theorems for hoare rules for every step")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
structure FwdRules = Named_Thms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  (val name = @{binding "fwd"}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
   val description = "Theorems for fwd derivation of seperation implication")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
setup {* StepRules.setup *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
setup {* FwdRules.setup *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
method_setup prune = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  {* Scan.succeed (SIMPLE_METHOD' o (K (K prune_params_tac))) *} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  "pruning parameters"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
lemma int_add_C: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  "x + (y::int) = y + x"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
lemma int_add_A : "(x + y) + z = x + (y + (z::int))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
lemma int_add_LC: "x + (y + (z::int)) = y + (x + z)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
lemmas int_add_ac = int_add_A int_add_C int_add_LC
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
section {* Operational Semantics of TM *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
datatype taction = W0 | W1 | L | R
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
type_synonym tstate = nat
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
datatype Block = Oc | Bk
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
(* the successor state when tape symbol is Bk or Oc, respectively *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
type_synonym tm_inst = "(taction \<times> tstate) \<times> (taction \<times> tstate)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
(* - number of faults (nat)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
   - TM program (nat \<rightharpoonup> tm_inst)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
   - current state (nat)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
   - position of head (int)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
   - tape (int \<rightharpoonup> Block)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
*)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
type_synonym tconf = "nat \<times> (nat \<Rightarrow>f tm_inst option) \<times> nat \<times> int \<times> (int \<Rightarrow>f Block option)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
(* updates the position/tape according to an action *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
fun 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
  next_tape :: "taction \<Rightarrow> (int \<times>  (int \<Rightarrow>f Block option)) \<Rightarrow> (int \<times>  (int \<Rightarrow>f Block option))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  "next_tape W0 (pos, m) = (pos, m(pos $:= Some Bk))" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
  "next_tape W1 (pos, m) = (pos, m(pos $:= Some Oc))" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
  "next_tape L  (pos, m) = (pos - 1, m)" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
  "next_tape R  (pos, m) = (pos + 1, m)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
fun tstep :: "tconf \<Rightarrow> tconf"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  where "tstep (faults, prog, pc, pos, m) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
              (case (prog $ pc) of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
                  Some ((action0, pc0), (action1, pc1)) \<Rightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
                     case (m $ pos) of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
                       Some Bk \<Rightarrow> (faults, prog, pc0, next_tape action0 (pos, m)) |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
                       Some Oc \<Rightarrow> (faults, prog, pc1, next_tape action1 (pos, m)) |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
                       None \<Rightarrow> (faults + 1, prog, pc, pos, m)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
                | None \<Rightarrow> (faults + 1, prog, pc, pos, m))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
lemma tstep_splits: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
  "(P (tstep s)) = ((\<forall> faults prog pc pos m action0 pc0 action1 pc1. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
                          s = (faults, prog, pc, pos, m) \<longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
                          prog $ pc = Some ((action0, pc0), (action1, pc1)) \<longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
                          m $ pos = Some Bk \<longrightarrow> P (faults, prog, pc0, next_tape action0 (pos, m))) \<and>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
                    (\<forall> faults prog pc pos m action0 pc0 action1 pc1. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
                          s = (faults, prog, pc, pos, m) \<longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
                          prog $ pc = Some ((action0, pc0), (action1, pc1)) \<longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
                          m $ pos = Some Oc \<longrightarrow> P (faults, prog, pc1, next_tape action1 (pos, m))) \<and>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
                    (\<forall> faults prog pc pos m action0 pc0 action1 pc1. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
                          s = (faults, prog, pc, pos, m) \<longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
                          prog $ pc = Some ((action0, pc0), (action1, pc1)) \<longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
                          m $ pos = None \<longrightarrow> P (faults + 1, prog, pc, pos, m)) \<and>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
                    (\<forall> faults prog pc pos m . 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
                          s =  (faults, prog, pc, pos, m) \<longrightarrow>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
                          prog $ pc  = None \<longrightarrow> P (faults + 1, prog, pc, pos, m))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
                   )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
  by (cases s) (auto split: option.splits Block.splits)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
datatype tresource = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
    TM int Block      (* at the position int of the tape is a Bl or Oc *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
  | TC nat tm_inst    (* at the address nat is a certain instruction *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
  | TAt nat           (* TM is at state nat*)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
  | TPos int          (* head of TM is at position int *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
  | TFaults nat       (* there are nat faults *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
definition "tprog_set prog = {TC i inst | i inst. prog $ i = Some inst}"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
definition "tpc_set pc = {TAt pc}"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
definition "tmem_set m = {TM i n | i n. m $ i = Some n}"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
definition "tpos_set pos = {TPos pos}"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
definition "tfaults_set faults = {TFaults faults}"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
lemmas tpn_set_def = tprog_set_def tpc_set_def tmem_set_def tfaults_set_def tpos_set_def
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
fun trset_of :: "tconf \<Rightarrow> tresource set"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
  where "trset_of (faults, prog, pc, pos, m) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
               tprog_set prog \<union> tpc_set pc \<union> tpos_set pos \<union> tmem_set m \<union> tfaults_set faults"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
interpretation tm: sep_exec tstep trset_of .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
section {* Assembly language for TMs and its program logic *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
subsection {* The assembly language *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
datatype tpg = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
   TInstr tm_inst
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
 | TLabel nat
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
 | TSeq tpg tpg
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
 | TLocal "nat \<Rightarrow> tpg"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
notation TLocal (binder "TL " 10)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
abbreviation 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
  tprog_instr :: "tm_inst \<Rightarrow> tpg" ("\<guillemotright> _" [61] 61)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
where "\<guillemotright> i \<equiv> TInstr i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
abbreviation tprog_seq :: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
  "tpg \<Rightarrow> tpg \<Rightarrow> tpg" (infixr ";" 52)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
where "c1 ; c2 \<equiv> TSeq c1 c2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
definition "sg e = (\<lambda>s. s = e)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
type_synonym tassert = "tresource set \<Rightarrow> bool"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
abbreviation 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
  t_hoare :: "tassert \<Rightarrow> tassert  \<Rightarrow> tassert \<Rightarrow> bool" ("(\<lbrace>(1_)\<rbrace>/ (_)/ \<lbrace>(1_)\<rbrace>)" 50)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
  "\<lbrace>p\<rbrace> c \<lbrace>q\<rbrace> == sep_exec.Hoare_gen tstep trset_of p c q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
abbreviation it_hoare ::
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
  "('a::sep_algebra \<Rightarrow> tresource set \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> (tresource set \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
      ("(1_).(\<lbrace>(1_)\<rbrace>/ (_)/ \<lbrace>(1_)\<rbrace>)" 50)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
where "I. \<lbrace>P\<rbrace> c \<lbrace>Q\<rbrace> == sep_exec.IHoare tstep trset_of I P c Q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
(*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
primrec tpg_len :: "tpg \<Rightarrow> nat" where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
  "tpg_len (TInstr ai) = 1" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
  "tpg_len (TSeq p1 p2) = tpg_len p1 + tpg_len " |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
  "tpg_len (TLocal fp) = tpg_len (fp 0)" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
  "tpg_len (TLabel l) = 0" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
*)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
primrec tassemble_to :: "tpg \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> tassert" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
  where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
  "tassemble_to (TInstr ai) i j = (sg ({TC i ai}) ** <(j = i + 1)>)" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
  "tassemble_to (TSeq p1 p2) i j = (EXS j'. (tassemble_to p1 i j') ** (tassemble_to p2 j' j))" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
  "tassemble_to (TLocal fp) i j  = (EXS l. (tassemble_to (fp l) i j))" | 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
  "tassemble_to (TLabel l) i j = <(i = j \<and> j = l)>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
declare tassemble_to.simps [simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
lemmas tasmp = tassemble_to.simps (2, 3, 4)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
abbreviation 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
  tasmb_to :: "nat \<Rightarrow> tpg \<Rightarrow> nat \<Rightarrow> tassert" ("_ :[ _ ]: _" [60, 60, 60] 60)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
  where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
  "i :[ tpg ]: j \<equiv> tassemble_to tpg i j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
lemma EXS_intro: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
  assumes h: "(P x) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
  shows "(EXS x. P(x)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
  by (smt h pred_ex_def sep_conj_impl)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
lemma EXS_elim: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
  assumes "(EXS x. P x) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
  obtains x where "P x s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
  by (metis assms pred_ex_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
lemma EXS_eq:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
  fixes x
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
  assumes h: "Q (p x)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
  and h1: "\<And> y s. \<lbrakk>p y s\<rbrakk> \<Longrightarrow> y = x"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
  shows "p x = (EXS x. p x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
proof
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
  fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
  show "p x s = (EXS x. p x) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
  proof
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
    assume "p x s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
    thus "(EXS x. p x) s" by (auto simp:pred_ex_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
    assume "(EXS x. p x) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
    thus "p x s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
    proof(rule EXS_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
      fix y
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
      assume "p y s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
      from this[unfolded h1[OF this]] show "p x s" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
definition "tpg_fold tpgs = foldr TSeq (butlast tpgs) (last tpgs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
lemma tpg_fold_sg: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
  "tpg_fold [tpg] = tpg"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
  by (simp add:tpg_fold_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
lemma tpg_fold_cons: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
  assumes h: "tpgs \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
  shows "tpg_fold (tpg#tpgs) = (tpg; (tpg_fold tpgs))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
  using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
proof(induct tpgs arbitrary:tpg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
  case (Cons tpg1 tpgs1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
  thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
  proof(cases "tpgs1 = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
    thus ?thesis by (simp add:tpg_fold_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
    proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
      have eq_1: "butlast (tpg # tpg1 # tpgs1) = tpg # (butlast (tpg1 # tpgs1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
        by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
      from False have eq_2: "last (tpg # tpg1 # tpgs1) = last (tpg1 # tpgs1)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
        by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
      have eq_3: "foldr (op ;) (tpg # butlast (tpg1 # tpgs1)) (last (tpg1 # tpgs1)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
            (tpg ; (foldr (op ;) (butlast (tpg1 # tpgs1)) (last (tpg1 # tpgs1))))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
        by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
        apply (subst (1) tpg_fold_def, unfold eq_1 eq_2 eq_3)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
        by (fold tpg_fold_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
qed auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
lemmas tpg_fold_simps = tpg_fold_sg tpg_fold_cons
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
lemma tpg_fold_app:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
  assumes h1: "tpgs1 \<noteq> []" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
  and h2: "tpgs2 \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
  shows "i:[(tpg_fold (tpgs1 @ tpgs2))]:j = i:[(tpg_fold (tpgs1); tpg_fold tpgs2)]:j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  using h1 h2
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
proof(induct tpgs1 arbitrary: i j tpgs2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
  case (Cons tpg1' tpgs1')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
  thus ?case (is "?L = ?R")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
  proof(cases "tpgs1' = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
    from h2 have "(tpgs1' @ tpgs2) \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
      by (metis Cons.prems(2) Nil_is_append_conv) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
    have "?L = (i :[ tpg_fold (tpg1' # (tpgs1' @ tpgs2)) ]: j )" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
    also have "\<dots> =  (i:[(tpg1'; (tpg_fold (tpgs1' @ tpgs2)))]:j )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
      by (simp add:tpg_fold_cons[OF `(tpgs1' @ tpgs2) \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
    also have "\<dots> = ?R"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
    proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
      have "(EXS j'. i :[ tpg1' ]: j' \<and>* j' :[ tpg_fold (tpgs1' @ tpgs2) ]: j) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
              (EXS j'. (EXS j'a. i :[ tpg1' ]: j'a \<and>* j'a :[ tpg_fold tpgs1' ]: j') \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
                               j' :[ tpg_fold tpgs2 ]: j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
      proof(default+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
        fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
        assume "(EXS j'. i :[ tpg1' ]: j' \<and>* j' :[ tpg_fold (tpgs1' @ tpgs2) ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
        thus "(EXS j'. (EXS j'a. i :[ tpg1' ]: j'a \<and>* j'a :[ tpg_fold tpgs1' ]: j') \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
                  j' :[ tpg_fold tpgs2 ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
        proof(elim EXS_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
          fix j'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
          assume "(i :[ tpg1' ]: j' \<and>* j' :[ tpg_fold (tpgs1' @ tpgs2) ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
          from this[unfolded Cons(1)[OF False Cons(3)] tassemble_to.simps]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
          show "(EXS j'. (EXS j'a. i :[ tpg1' ]: j'a \<and>* j'a :[ tpg_fold tpgs1' ]: j') \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
                           j' :[ tpg_fold tpgs2 ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
          proof(elim sep_conjE EXS_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
            fix x y j'a xa ya
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
            assume h: "(i :[ tpg1' ]: j') x"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
                      "x ## y" "s = x + y"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
                      "(j' :[ tpg_fold tpgs1' ]: j'a) xa"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
                      "(j'a :[ tpg_fold tpgs2 ]: j) ya"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
                      " xa ## ya" "y = xa + ya"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
            show "(EXS j'. (EXS j'a. i :[ tpg1' ]: j'a \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
                                j'a :[ tpg_fold tpgs1' ]: j') \<and>* j' :[ tpg_fold tpgs2 ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
               (is "(EXS j'. (?P j' \<and>* ?Q j')) s")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
            proof(rule EXS_intro[where x = "j'a"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
              from `(j'a :[ tpg_fold tpgs2 ]: j) ya` have "(?Q j'a) ya" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
              moreover have "(?P j'a) (x + xa)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
              proof(rule EXS_intro[where x = j'])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
                have "x + xa = x + xa" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
                moreover from `x ## y` `y = xa + ya` `xa ## ya` 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
                have "x ## xa" by (metis sep_disj_addD) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
                moreover note `(i :[ tpg1' ]: j') x` `(j' :[ tpg_fold tpgs1' ]: j'a) xa`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
                ultimately show "(i :[ tpg1' ]: j' \<and>* j' :[ tpg_fold tpgs1' ]: j'a) (x + xa)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
                  by (auto intro!:sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
              qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
              moreover from `x##y` `y = xa + ya` `xa ## ya` 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
              have "(x + xa) ## ya"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
                by (metis sep_disj_addI1 sep_disj_commuteI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
              moreover from `s = x + y` `y = xa + ya`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
              have "s = (x + xa) + ya"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
                by (metis h(2) h(6) sep_add_assoc sep_disj_addD1 sep_disj_addD2) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
              ultimately show "(?P j'a \<and>* ?Q j'a) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
                by (auto intro!:sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
            qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
          qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
        qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
        fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
        assume "(EXS j'. (EXS j'a. i :[ tpg1' ]: j'a \<and>* j'a :[ tpg_fold tpgs1' ]: j') \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
                                    j' :[ tpg_fold tpgs2 ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
        thus "(EXS j'. i :[ tpg1' ]: j' \<and>* j' :[ tpg_fold (tpgs1' @ tpgs2) ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
        proof(elim EXS_elim sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
          fix j' x y j'a xa ya
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
          assume h: "(j' :[ tpg_fold tpgs2 ]: j) y"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
                    "x ## y" "s = x + y" "(i :[ tpg1' ]: j'a) xa"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
                    "(j'a :[ tpg_fold tpgs1' ]: j') ya" "xa ## ya" "x = xa + ya"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
          show "(EXS j'. i :[ tpg1' ]: j' \<and>* j' :[ tpg_fold (tpgs1' @ tpgs2) ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
          proof(rule EXS_intro[where x = j'a])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
            from `(i :[ tpg1' ]: j'a) xa` have "(i :[ tpg1' ]: j'a) xa" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
            moreover have "(j'a :[ tpg_fold (tpgs1' @ tpgs2) ]: j) (ya + y)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
            proof(unfold Cons(1)[OF False Cons(3)] tassemble_to.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
              show "(EXS j'. j'a :[ tpg_fold tpgs1' ]: j' \<and>* j' :[ tpg_fold tpgs2 ]: j) (ya + y)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
              proof(rule EXS_intro[where x = "j'"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
                from `x ## y` `x = xa + ya` `xa ## ya`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
                have "ya ## y" by (metis sep_add_disjD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
                moreover have "ya + y = ya + y" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
                moreover note `(j'a :[ tpg_fold tpgs1' ]: j') ya` 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
                               `(j' :[ tpg_fold tpgs2 ]: j) y`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
                ultimately show "(j'a :[ tpg_fold tpgs1' ]: j' \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
                                 j' :[ tpg_fold tpgs2 ]: j) (ya + y)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
                  by (auto intro!:sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   343
              qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
            qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
            moreover from `s = x + y` `x = xa + ya`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
            have "s = xa + (ya + y)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
              by (metis h(2) h(6) sep_add_assoc sep_add_disjD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
            moreover from `xa ## ya` `x ## y` `x = xa + ya`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
            have "xa ## (ya + y)" by (metis sep_disj_addI3) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
            ultimately show "(i :[ tpg1' ]: j'a \<and>* j'a :[ tpg_fold (tpgs1' @ tpgs2) ]: j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
              by (auto intro!:sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
          qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
        qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
      thus ?thesis 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
        by (simp add:tassemble_to.simps, unfold tpg_fold_cons[OF False], 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
             unfold tassemble_to.simps, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
    finally show ?thesis . 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
    thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
      by (simp add:tpg_fold_cons[OF Cons(3)] tpg_fold_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
  qed 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
qed auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
subsection {* Assertions and program logic for this assembly language *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
definition "st l = sg (tpc_set l)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
definition "ps p = sg (tpos_set p)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
definition "tm a v = sg ({TM a v})"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
definition "one i = tm i Oc"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
definition "zero i= tm i Bk"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
definition "any i = (EXS v. tm i v)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
declare trset_of.simps[simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
lemma stimes_sgD: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
  "(sg x \<and>* q) s \<Longrightarrow> q (s - x) \<and> x \<subseteq> s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
  apply(erule_tac sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
  apply(unfold set_ins_def sg_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
  by (metis Diff_Int Diff_cancel Diff_empty Un_Diff sup.cobounded1 sup_bot.left_neutral sup_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
lemma stD: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
  "(st i \<and>* r) (trset_of (ft, prog, i', pos, mem)) \<Longrightarrow> i' = i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
  assume "(st i \<and>* r) (trset_of (ft, prog, i', pos, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
  from stimes_sgD [OF this[unfolded st_def], unfolded trset_of.simps]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
  have "tpc_set i \<subseteq> tprog_set prog \<union> tpc_set i' \<union> tpos_set pos \<union>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
            tmem_set mem \<union> tfaults_set ft" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
    by (unfold tpn_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
lemma psD: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
  "(ps p \<and>* r) (trset_of (ft, prog, i', pos, mem)) \<Longrightarrow> pos = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
  assume "(ps p ** r) (trset_of (ft, prog, i', pos, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
  from stimes_sgD [OF this[unfolded ps_def], unfolded trset_of.simps]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
  have "tpos_set p \<subseteq> tprog_set prog \<union> tpc_set i' \<union> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
                       tpos_set pos \<union> tmem_set mem \<union> tfaults_set ft"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
    by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
    by (unfold tpn_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
lemma codeD: "(st i ** sg {TC i inst} ** r) (trset_of (ft, prog, i', pos, mem))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
       \<Longrightarrow> prog $ i = Some inst"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
  assume "(st i ** sg {TC i inst} ** r) (trset_of (ft, prog, i', pos, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
  thus ?thesis
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   413
    apply(unfold sep_conj_def set_ins_def sg_def trset_of.simps tpn_set_def) 
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
    by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   417
lemma memD: "((tm a v) ** r) (trset_of (ft, prog, i, pos, mem))  \<Longrightarrow> mem $ a = Some v"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
  assume "((tm a v) ** r) (trset_of (ft, prog, i, pos, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
  from stimes_sgD[OF this[unfolded trset_of.simps tpn_set_def tm_def]]
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   421
  have "{TM a v} \<subseteq> {TC i inst |i inst. prog $ i = Some inst} \<union> {TAt i} \<union> 
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   422
    {TPos pos} \<union> {TM i n |i n. mem $ i = Some n} \<union> {TFaults ft}" by simp
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
  thus ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
lemma t_hoare_seq: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
  assumes a1: "\<And> i j. \<lbrace>st i \<and>* p\<rbrace> i:[c1]:j \<lbrace>st j \<and>* q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
  and     a2: "\<And> j k. \<lbrace>st j ** q\<rbrace> j:[c2]:k \<lbrace>st k ** r\<rbrace>" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
  shows "\<lbrace>st i \<and>* p\<rbrace> i:[(c1 ; c2)]:k \<lbrace>st k \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
proof(subst tassemble_to.simps, rule tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
  fix j'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
  show "\<lbrace>st i \<and>* p\<rbrace>  i:[ c1 ]:j' \<and>* j':[ c2 ]:k \<lbrace>st k \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
  proof(rule tm.composition)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
    from a1 show "\<lbrace>st i \<and>* p\<rbrace>  i:[ c1 ]:j' \<lbrace>st j' \<and>* q\<rbrace>" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
    from a2 show "\<lbrace>st j' \<and>* q\<rbrace>  j':[ c2 ]:k \<lbrace>st k \<and>* r\<rbrace>" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
lemma t_hoare_seq1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
  assumes a1: "\<And>j'. \<lbrace>st i \<and>* p\<rbrace> i:[c1]:j' \<lbrace>st j' \<and>* q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
  assumes a2: "\<And>j'. \<lbrace>st j' \<and>* q\<rbrace> j':[c2]:k \<lbrace>st k' \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
  shows "\<lbrace>st i \<and>* p\<rbrace> i:[(c1 ; c2)]:k \<lbrace>st k' \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
proof(subst tassemble_to.simps, rule tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
  fix j'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
  show "\<lbrace>st i \<and>* p\<rbrace>  i:[ c1 ]:j' \<and>* j':[ c2 ]:k \<lbrace>st k' \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
  proof(rule tm.composition)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
    from a1 show "\<lbrace>st i \<and>* p\<rbrace>  i:[ c1 ]:j' \<lbrace>st j' \<and>* q\<rbrace>" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
    from a2 show " \<lbrace>st j' \<and>* q\<rbrace>  j':[ c2 ]:k \<lbrace>st k' \<and>* r\<rbrace>" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
lemma t_hoare_seq2:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
  assumes h: "\<And>j. \<lbrace>st i ** p\<rbrace> i:[c1]:j \<lbrace>st k' \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
  shows "\<lbrace>st i ** p\<rbrace> i:[(c1 ; c2)]:j \<lbrace>st k' ** r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
  apply (unfold tassemble_to.simps, rule tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
  by (rule tm.code_extension, rule h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
lemma t_hoare_local: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
  assumes h: "(\<And>l. \<lbrace>st i \<and>* p\<rbrace>  i :[ c l ]: j \<lbrace>st k \<and>* q\<rbrace>)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
  shows "\<lbrace>st i ** p\<rbrace> i:[TLocal c]:j \<lbrace>st k ** q\<rbrace>" using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
  by (unfold tassemble_to.simps, intro tm.code_exI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   465
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
lemma t_hoare_label: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
  assumes "\<And>l. l = i \<Longrightarrow> \<lbrace>st l \<and>* p\<rbrace>  l:[ c l ]:j \<lbrace>st k \<and>* q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
  shows "\<lbrace>st i \<and>* p\<rbrace> i:[(TLabel l; c l)]:j \<lbrace>st k \<and>* q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
using assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
by (unfold tassemble_to.simps, intro tm.code_exI tm.code_condI, clarify, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
primrec t_split_cmd :: "tpg \<Rightarrow> (tpg \<times> tpg option)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
  where "t_split_cmd (\<guillemotright>inst) = (\<guillemotright>inst, None)" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
        "t_split_cmd (TLabel l) = (TLabel l, None)" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
        "t_split_cmd (TSeq c1 c2) = (case (t_split_cmd c2) of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
                                      (c21, Some c22) \<Rightarrow> (TSeq c1 c21, Some c22) |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
                                      (c21, None) \<Rightarrow> (c1, Some c21))" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
        "t_split_cmd (TLocal c) = (TLocal c, None)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
definition "t_last_cmd tpg = snd (t_split_cmd tpg)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   482
declare t_last_cmd_def [simp]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   483
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   484
definition "t_blast_cmd tpg = fst (t_split_cmd tpg)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   485
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   486
declare t_blast_cmd_def [simp]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   488
lemma "t_last_cmd (c1; c2; TLabel l) = Some (TLabel l)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   489
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   490
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
lemma "t_blast_cmd (c1; c2; TLabel l) = (c1; c2)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   492
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   494
lemma t_split_cmd_eq:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
  assumes "t_split_cmd c = (c1, Some c2)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
  shows "i:[c]:j = i:[(c1; c2)]:j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
  using assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   498
proof(induct c arbitrary: c1 c2 i j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   499
  case (TSeq cx cy)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   500
  from `t_split_cmd (cx ; cy) = (c1, Some c2)`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   501
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   502
    apply (simp split:prod.splits option.splits)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   503
    apply (cases cy, auto split:prod.splits option.splits)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   504
    proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   505
      fix a
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   506
      assume h: "t_split_cmd cy = (a, Some c2)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   507
      show "i :[ (cx ; cy) ]: j = i :[ ((cx ; a) ; c2) ]: j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   508
        apply (simp only: tassemble_to.simps(2) TSeq(2)[OF h] sep_conj_exists)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   509
        apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
        by (simp add:pred_ex_def, default, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   511
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   512
qed auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   513
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
lemma t_hoare_label_last_pre: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   515
  assumes h1: "t_split_cmd c = (c', Some (TLabel l))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
  and h2: "l = j \<Longrightarrow> \<lbrace>p\<rbrace> i:[c']:j \<lbrace>q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   517
  shows "\<lbrace>p\<rbrace> i:[c]:j \<lbrace>q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   518
by (unfold t_split_cmd_eq[OF h1], 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
    simp only:tassemble_to.simps sep_conj_cond, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
    intro tm.code_exI tm.code_condI, insert h2, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
lemma t_hoare_label_last: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   523
  assumes h1: "t_last_cmd c = Some (TLabel l)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   524
  and h2: "l = j \<Longrightarrow> \<lbrace>p\<rbrace> i:[t_blast_cmd c]:j \<lbrace>q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
  shows "\<lbrace>p\<rbrace> i:[c]:j \<lbrace>q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   526
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   527
    have "t_split_cmd c = (t_blast_cmd c, t_last_cmd c)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
      by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
  from t_hoare_label_last_pre[OF this[unfolded h1]] h2
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
  show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   532
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   534
subsection {* Basic assertions for TM *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
(* ones between tape position i and j *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
function ones :: "int \<Rightarrow> int \<Rightarrow> tassert" where
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
  "ones i j = (if j < i then <(i = j + 1)> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
               else (one i) \<and>* ones (i + 1) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   540
by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   541
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
termination 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
  by (relation "measure(\<lambda> (i::int, j). nat (j - i + 1))") auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
lemma ones_base_simp: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
  "j < i \<Longrightarrow> ones i j = <(i = j + 1)>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   549
lemma ones_step_simp: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
  "\<not> j < i \<Longrightarrow> ones i j =  ((one i) \<and>* ones (i + 1) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
lemmas ones_simps = ones_base_simp ones_step_simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
declare ones.simps [simp del] ones_simps [simp]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
lemma ones_induct [case_names Base Step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
  assumes h1: "\<And> i j. j < i \<Longrightarrow> P i j (<(i = j + (1::int))>)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   559
  and h2: "\<And> i j. \<lbrakk>\<not> j < i; P (i + 1) j (ones (i + 1) j)\<rbrakk> \<Longrightarrow> P i j ((one i) \<and>* ones (i + 1) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   560
  shows "P i j (ones i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   561
proof(induct i j rule:ones.induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   562
  fix i j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   563
  assume ih: "(\<not> j < i \<Longrightarrow> P (i + 1) j (ones (i + 1) j))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   564
  show "P i j (ones i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
  proof(cases "j < i")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
    with h1 [OF True]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   568
    show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   569
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   570
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
    from h2 [OF False] and ih[OF False]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
    have "P i j (one i \<and>* ones (i + 1) j)" by blast
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   573
    with False show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   574
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   575
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   576
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   577
function ones' ::  "int \<Rightarrow> int \<Rightarrow> tassert" where
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
  "ones' i j = (if j < i then <(i = j + 1)> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   579
                else ones' i (j - 1) \<and>* one j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   580
by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   581
termination by (relation "measure(\<lambda> (i::int, j). nat (j - i + 1))") auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   582
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
lemma ones_rev: "\<not> j < i \<Longrightarrow> (ones i j) = ((ones i (j - 1)) ** one j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
proof(induct i j rule:ones_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   585
  case Base
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   586
  thus ?case by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   587
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   588
  case (Step i j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   589
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   590
  proof(cases "j < i + 1")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   591
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   592
    with Step show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   593
      by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   594
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   595
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   596
    with Step show ?thesis 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   597
      by (auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   598
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   599
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   600
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   601
lemma ones_rev_induct [case_names Base Step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
  assumes h1: "\<And> i j. j < i \<Longrightarrow> P i j (<(i = j + (1::int))>)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   603
  and h2: "\<And> i j. \<lbrakk>\<not> j < i; P i (j - 1) (ones i (j - 1))\<rbrakk> \<Longrightarrow> P i j ((ones i (j - 1)) ** one j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   604
  shows "P i j (ones i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   605
proof(induct i j rule:ones'.induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   606
  fix i j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   607
  assume ih: "(\<not> j < i \<Longrightarrow> P i (j - 1) (ones i (j - 1)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   608
  show "P i j (ones i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   609
  proof(cases "j < i")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   610
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   611
    with h1 [OF True]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   612
    show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   613
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   614
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   615
    from h2 [OF False] and ih[OF False]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   616
    have "P i j (ones i (j - 1) \<and>* one j)" by blast
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   617
    with ones_rev and False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   618
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   619
      by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   620
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   621
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   622
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   623
function zeros :: "int \<Rightarrow> int \<Rightarrow> tassert" where
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   624
  "zeros i j = (if j < i then <(i = j + 1)> else
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   625
                (zero i) ** zeros (i + 1) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   626
by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   627
termination by (relation "measure(\<lambda> (i::int, j). nat (j - i + 1))") auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   628
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   629
lemma zeros_base_simp: "j < i \<Longrightarrow> zeros i j = <(i = j + 1)>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   630
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   631
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   632
lemma zeros_step_simp: "\<not> j < i \<Longrightarrow> zeros i j = ((zero i) ** zeros (i + 1) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   633
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   634
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   635
declare zeros.simps [simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
lemmas zeros_simps [simp] = zeros_base_simp zeros_step_simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   637
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   638
lemma zeros_induct [case_names Base Step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639
  assumes h1: "\<And> i j. j < i \<Longrightarrow> P i j (<(i = j + (1::int))>)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   640
  and h2: "\<And> i j. \<lbrakk>\<not> j < i; P (i + 1) j (zeros (i + 1) j)\<rbrakk> \<Longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   641
                                   P i j ((zero i) ** zeros (i + 1) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   642
  shows "P i j (zeros i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   643
proof(induct i j rule:zeros.induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   644
  fix i j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   645
  assume ih: "(\<not> j < i \<Longrightarrow> P (i + 1) j (zeros (i + 1) j))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   646
  show "P i j (zeros i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   647
  proof(cases "j < i")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   648
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   649
    with h1 [OF True]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   650
    show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   651
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   652
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   653
    from h2 [OF False] and ih[OF False]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   654
    have "P i j (zero i \<and>* zeros (i + 1) j)" by blast
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   655
    with False show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   656
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   657
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   658
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   659
lemma zeros_rev: "\<not> j < i \<Longrightarrow> (zeros i j) = ((zeros i (j - 1)) \<and>* zero j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   660
proof(induct i j rule:zeros_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   661
  case (Base i j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   662
  thus ?case by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   663
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   664
  case (Step i j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   665
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   666
  proof(cases "j < i + 1")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   667
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   668
    with Step show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   669
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   670
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   671
    with Step show ?thesis by (auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   672
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   673
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   674
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   675
lemma zeros_rev_induct [case_names Base Step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   676
  assumes h1: "\<And> i j. j < i \<Longrightarrow> P i j (<(i = j + (1::int))>)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   677
  and h2: "\<And> i j. \<lbrakk>\<not> j < i; P i (j - 1) (zeros i (j - 1))\<rbrakk> \<Longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   678
                       P i j ((zeros i (j - 1)) ** zero j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   679
  shows "P i j (zeros i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   680
proof(induct i j rule:ones'.induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   681
  fix i j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   682
  assume ih: "(\<not> j < i \<Longrightarrow> P i (j - 1) (zeros i (j - 1)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   683
  show "P i j (zeros i j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   684
  proof(cases "j < i")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   685
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   686
    with h1 [OF True]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   687
    show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   688
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   689
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   690
    from h2 [OF False] and ih[OF False]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   691
    have "P i j (zeros i (j - 1) \<and>* zero j)" by blast
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   692
    with zeros_rev and False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   693
    show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   694
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   695
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   696
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   697
definition "rep i j k = ((ones i (i + (int k))) \<and>* <(j = i + int k)>)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   698
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   699
fun reps :: "int \<Rightarrow> int \<Rightarrow> nat list\<Rightarrow> tassert"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   700
  where
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   701
  "reps i j [] = <(i = j + 1)>" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   702
  "reps i j [k] = (ones i (i + int k) ** <(j = i + int k)>)" |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   703
  "reps i j (k # ks) = (ones i (i + int k) ** zero (i + int k + 1) ** reps (i + int k + 2) j ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   704
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   705
lemma reps_simp3: "ks \<noteq> [] \<Longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   706
  reps i j (k # ks) = (ones i (i + int k) ** zero (i + int k + 1) ** reps (i + int k + 2) j ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   707
  by (cases ks, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   708
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   709
definition "reps_sep_len ks = (if length ks \<le> 1 then 0 else (length ks) - 1)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   710
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   711
definition "reps_ctnt_len ks = (\<Sum> k \<leftarrow> ks. (1 + k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   712
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   713
definition "reps_len ks = (reps_sep_len ks) + (reps_ctnt_len ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   714
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   715
definition "splited xs ys zs = ((xs = ys @ zs) \<and> (ys \<noteq> []) \<and> (zs \<noteq> []))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   716
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   717
lemma list_split: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   718
  assumes h: "k # ks = ys @ zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   719
      and h1: "ys \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   720
  shows "(ys = [k] \<and> zs = ks) \<or> (\<exists> ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> ks = ys' @ zs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   721
proof(cases ys)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   722
  case Nil
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   723
  with h1 show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   724
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   725
  case (Cons y' ys')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   726
  with h have "k#ks = y'#(ys' @ zs)" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   727
  hence hh: "y' = k" "ks = ys' @ zs" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   728
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   729
  proof(cases "ys' = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   730
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   731
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   732
    proof(rule disjI2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   733
      show " \<exists>ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> ks = ys' @ zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   734
      proof(rule exI[where x = ys'])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   735
        from False hh Cons show "ys' \<noteq> [] \<and> ys = k # ys' \<and> ks = ys' @ zs" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   736
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   737
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   738
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   739
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   740
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   741
    proof(rule disjI1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   742
      from hh True Cons
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   743
      show "ys = [k] \<and> zs = ks" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   744
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   745
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   746
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   747
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   748
lemma splited_cons[elim_format]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   749
  assumes h: "splited (k # ks) ys zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   750
  shows "(ys = [k] \<and> zs = ks) \<or> (\<exists> ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> splited ks ys' zs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   751
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   752
  from h have "k # ks = ys @ zs" "ys \<noteq> [] " unfolding splited_def by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   753
  from list_split[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   754
  have "ys = [k] \<and> zs = ks \<or> (\<exists>ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> ks = ys' @ zs)" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   755
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   756
  proof
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   757
    assume " ys = [k] \<and> zs = ks" thus ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   758
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   759
    assume "\<exists>ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> ks = ys' @ zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   760
    then obtain ys' where hh: "ys' \<noteq> []" "ys = k # ys'" "ks = ys' @ zs" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   761
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   762
    proof(rule disjI2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   763
      show "\<exists>ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> splited ks ys' zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   764
      proof(rule exI[where x = ys'])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   765
        from h have "zs \<noteq> []" by (unfold splited_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   766
        with hh(1) hh(3)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   767
        have "splited ks ys' zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   768
          by (unfold splited_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   769
        with hh(1) hh(2) show "ys' \<noteq> [] \<and> ys = k # ys' \<and> splited ks ys' zs" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   770
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   771
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   772
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   773
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   774
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   775
lemma splited_cons_elim:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   776
  assumes h: "splited (k # ks) ys zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   777
  and h1: "\<lbrakk>ys = [k]; zs = ks\<rbrakk> \<Longrightarrow> P"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   778
  and h2: "\<And> ys'. \<lbrakk>ys' \<noteq> []; ys = k#ys'; splited ks ys' zs\<rbrakk> \<Longrightarrow> P"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   779
  shows P
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   780
proof(rule splited_cons[OF h])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   781
  assume "ys = [k] \<and> zs = ks \<or> (\<exists>ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> splited ks ys' zs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   782
  thus P
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   783
  proof
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   784
    assume hh: "ys = [k] \<and> zs = ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   785
    show P
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   786
    proof(rule h1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   787
      from hh show "ys = [k]" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   788
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   789
      from hh show "zs = ks" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   790
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   791
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   792
    assume "\<exists>ys'. ys' \<noteq> [] \<and> ys = k # ys' \<and> splited ks ys' zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   793
    then obtain ys' where hh: "ys' \<noteq> []" "ys = k # ys'"  "splited ks ys' zs" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   794
    from h2[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   795
    show P .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   796
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   797
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   798
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   799
lemma list_nth_expand:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   800
  "i < length xs \<Longrightarrow> xs = take i xs @ [xs!i] @ drop (Suc i) xs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   801
  by (metis Cons_eq_appendI append_take_drop_id drop_Suc_conv_tl eq_Nil_appendI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   802
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   803
lemma reps_len_nil: "reps_len [] = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   804
   by (auto simp:reps_len_def reps_sep_len_def reps_ctnt_len_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   805
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   806
lemma reps_len_sg: "reps_len [k] = 1 + k"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   807
  by (auto simp:reps_len_def reps_sep_len_def reps_ctnt_len_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   808
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   809
lemma reps_len_cons: "ks \<noteq> [] \<Longrightarrow> (reps_len (k # ks)) = 2 + k + reps_len ks "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   810
proof(induct ks arbitrary:k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   811
  case (Cons n ns)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   812
  thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   813
    by(cases "ns = []", 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   814
      auto simp:reps_len_def reps_sep_len_def reps_ctnt_len_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   815
qed auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   816
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   817
lemma reps_len_correct:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   818
  assumes h: "(reps i j ks) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   819
  shows "j = i + int (reps_len ks) - 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   820
  using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   821
proof(induct ks arbitrary:i j s)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   822
  case Nil
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   823
  thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   824
    by (auto simp:reps_len_nil pasrt_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   825
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   826
  case (Cons n ns)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   827
  thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   828
  proof(cases "ns = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   829
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   830
    from Cons(2)[unfolded reps_simp3[OF False]]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   831
    obtain s' where "(reps (i + int n + 2) j ns) s'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   832
      by (auto elim!:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   833
    from Cons.hyps[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   834
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   835
      by (unfold reps_len_cons[OF False], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   836
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   837
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   838
    with Cons(2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   839
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   840
      by (auto simp:reps_len_sg pasrt_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   841
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   842
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   843
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   844
lemma reps_len_expand: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   845
  shows "(EXS j. (reps i j ks)) = (reps i (i + int (reps_len ks) - 1) ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   846
proof(default+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   847
  fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   848
  assume "(EXS j. reps i j ks) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   849
  with reps_len_correct show "reps i (i + int (reps_len ks) - 1) ks s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   850
    by (auto simp:pred_ex_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   851
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   852
  fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   853
  assume "reps i (i + int (reps_len ks) - 1) ks s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   854
  thus "(EXS j. reps i j ks) s"  by (auto simp:pred_ex_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   855
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   856
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   857
lemma reps_len_expand1: "(EXS j. (reps i j ks \<and>* r)) = (reps i (i + int (reps_len ks) - 1) ks \<and>* r)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   858
by (metis reps_len_def reps_len_expand sep.mult_commute sep_conj_exists1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   859
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   860
lemma reps_splited:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   861
  assumes h: "splited xs ys zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   862
  shows "reps i j xs = (reps i (i + int (reps_len ys) - 1) ys \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   863
                        zero (i + int (reps_len ys)) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   864
                        reps (i + int (reps_len ys) + 1) j zs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   865
  using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   866
proof(induct xs arbitrary: i j ys zs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   867
  case Nil
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   868
  thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   869
    by (unfold splited_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   870
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   871
  case (Cons k ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   872
  from Cons(2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   873
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   874
  proof(rule splited_cons_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   875
    assume h: "ys = [k]" "zs = ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   876
    with Cons(2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   877
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   878
    proof(cases "ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   879
      case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   880
      with Cons(2) have False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   881
        by (simp add:splited_def, cases ys, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   882
      thus ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   883
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   884
      case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   885
      have ss: "i + int k + 1 = i + (1 + int k)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   886
           "i + int k + 2 = 2 + (i + int k)" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   887
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   888
        by (unfold h(1), unfold reps_simp3[OF False] reps.simps(2) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   889
            reps_len_sg, auto simp:sep_conj_ac,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   890
            unfold ss h(2), simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   891
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   892
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   893
    fix ys'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   894
    assume h: "ys' \<noteq> []" "ys = k # ys'" "splited ks ys' zs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   895
    hence nnks: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   896
      by (unfold splited_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   897
    have ss: "i + int k + 2 + int (reps_len ys') = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   898
              i + (2 + (int k + int (reps_len ys')))" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   899
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   900
      by (simp add: reps_simp3[OF nnks] reps_simp3[OF h(1)] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   901
                    Cons(1)[OF h(3)] h(2) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   902
                    reps_len_cons[OF h(1)]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   903
                    sep_conj_ac, subst ss, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   904
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   905
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   906
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   907
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   908
subsection {* A theory of list extension *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   909
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   910
definition "list_ext n xs = xs @ replicate ((Suc n) - length xs) 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   911
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   912
lemma list_ext_len_eq: "length (list_ext a xs) = length xs + (Suc a - length xs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   913
  by (metis length_append length_replicate list_ext_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   914
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   915
lemma list_ext_len: "a < length (list_ext a xs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   916
  by (unfold list_ext_len_eq, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   917
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   918
lemma list_ext_lt: "a < length xs \<Longrightarrow> list_ext a xs = xs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   919
  by (smt append_Nil2 list_ext_def replicate_0)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   920
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   921
lemma list_ext_lt_get: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   922
  assumes h: "a' < length xs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   923
  shows "(list_ext a xs)!a' = xs!a'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   924
proof(cases "a < length xs")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   925
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   926
  with h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   927
  show ?thesis by (auto simp:list_ext_lt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   928
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   929
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   930
  with h show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   931
    apply (unfold list_ext_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   932
    by (metis nth_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   933
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   934
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   935
lemma list_ext_get_upd: "((list_ext a xs)[a:=v])!a = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   936
  by (metis list_ext_len nth_list_update_eq)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   937
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   938
lemma nth_app: "length xs \<le> a \<Longrightarrow> (xs @ ys)!a = ys!(a - length xs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   939
  by (metis not_less nth_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   940
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   941
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   942
lemma list_ext_tail:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   943
  assumes h1: "length xs \<le> a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   944
  and h2: "length xs \<le> a'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   945
  and h3: "a' \<le> a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   946
  shows "(list_ext a xs)!a' = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   947
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   948
  from h1 h2
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   949
  have "a' - length xs < length (replicate (Suc a - length xs) 0)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   950
    by (metis diff_less_mono h3 le_imp_less_Suc length_replicate)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   951
  moreover from h1 have "replicate (Suc a - length xs) 0 \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   952
    by (smt empty_replicate)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   953
  ultimately have "(replicate (Suc a - length xs) 0)!(a' - length xs) = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   954
    by (metis length_replicate nth_replicate)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   955
  moreover have "(xs @ (replicate (Suc a - length xs) 0))!a' = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   956
            (replicate (Suc a - length xs) 0)!(a' - length xs)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   957
    by (rule nth_app[OF h2])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   958
  ultimately show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   959
    by (auto simp:list_ext_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   960
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   961
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   962
lemmas list_ext_simps = list_ext_lt_get list_ext_lt list_ext_len list_ext_len_eq
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   963
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   964
lemma listsum_upd_suc:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   965
  "a < length ks \<Longrightarrow> listsum (map Suc (ks[a := Suc (ks ! a)]))= (Suc (listsum (map Suc ks)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   966
by (smt elem_le_listsum_nat 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   967
     length_list_update list_ext_get_upd 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   968
     list_update_overwrite listsum_update_nat map_update 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   969
     nth_equalityI nth_list_update nth_map)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   970
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   971
lemma reps_len_suc:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   972
  assumes "a < length ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   973
  shows "reps_len (ks[a:=Suc(ks!a)]) = 1 + reps_len ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   974
proof(cases "length ks \<le> 1")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   975
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   976
  with `a < length ks` 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   977
  obtain k where "ks = [k]" "a = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   978
    by (smt length_0_conv length_Suc_conv)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   979
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   980
      apply (unfold `ks = [k]` `a = 0`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   981
      by (unfold reps_len_def reps_sep_len_def reps_ctnt_len_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   982
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   983
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   984
  have "Suc = (op + (Suc 0))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   985
    by (default, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   986
  with listsum_upd_suc[OF `a < length ks`] False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   987
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   988
     by (unfold reps_len_def reps_sep_len_def reps_ctnt_len_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   989
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   990
  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   991
lemma ks_suc_len:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   992
  assumes h1: "(reps i j ks) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   993
  and h2: "ks!a = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   994
  and h3: "a < length ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   995
  and h4: "(reps i j' (ks[a:=Suc v])) s'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   996
  shows "j' = j + int (reps_len (list_ext a ks)) - int (reps_len ks) + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   997
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   998
  from reps_len_correct[OF h1, unfolded list_ext_len_eq]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   999
       reps_len_correct[OF h4, unfolded list_ext_len_eq] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1000
       reps_len_suc[OF `a < length ks`] h2 h3
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1001
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1002
    by (unfold list_ext_lt[OF `a < length ks`], auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1003
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1004
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1005
lemma ks_ext_len:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1006
  assumes h1: "(reps i j ks) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1007
  and h3: "length ks \<le> a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1008
  and h4: "reps i j' (list_ext a ks) s'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1009
  shows "j' = j + int (reps_len (list_ext a ks)) - int (reps_len ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1010
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1011
  from reps_len_correct[OF h1, unfolded  list_ext_len_eq]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1012
    and reps_len_correct[OF h4, unfolded list_ext_len_eq]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1013
  h3
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1014
  show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1015
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1016
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1017
definition 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1018
  "reps' i j ks = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1019
     (if ks = [] then (<(i = j + 1)>)  else (reps i (j - 1) ks \<and>* zero j))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1020
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1021
lemma reps'_expand: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1022
  assumes h: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1023
  shows "(EXS j. reps' i j ks) = reps' i (i + int (reps_len ks)) ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1024
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1025
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1026
  proof(default+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1027
    fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1028
    assume "(EXS j. reps' i j ks) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1029
    with h have "(EXS j. reps i (j - 1) ks \<and>* zero j) s" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1030
      by (simp add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1031
    hence "(reps i (i + int (reps_len ks) - 1) ks \<and>* zero (i + int (reps_len ks))) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1032
    proof(elim EXS_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1033
      fix j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1034
      assume "(reps i (j - 1) ks \<and>* zero j) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1035
      then obtain s1 s2 where "s = s1 + s2" "s1 ## s2" "reps i (j - 1) ks s1" "zero j s2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1036
        by (auto elim!:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1037
      from reps_len_correct[OF this(3)]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1038
      have "j = i + int (reps_len ks)" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1039
      with `reps i (j - 1) ks s1` have "reps i (i + int (reps_len ks) - 1) ks s1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1040
        by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1041
      moreover from `j = i + int (reps_len ks)` and `zero j s2`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1042
      have "zero (i + int (reps_len ks)) s2" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1043
      ultimately show "(reps i (i + int (reps_len ks) - 1) ks \<and>* zero (i + int (reps_len ks))) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1044
        using `s = s1 + s2` `s1 ## s2` by (auto intro!:sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1045
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1046
    thus "reps' i (i + int (reps_len ks)) ks s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1047
      by (simp add:h reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1048
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1049
    fix s 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1050
    assume "reps' i (i + int (reps_len ks)) ks s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1051
    thus "(EXS j. reps' i j ks) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1052
      by (auto intro!:EXS_intro)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1053
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1054
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1055
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1056
lemma reps'_len_correct: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1057
  assumes h: "(reps' i j ks) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1058
  and h1: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1059
  shows "(j = i + int (reps_len ks))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1060
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1061
  from h1 have "reps' i j ks s = (reps i (j - 1) ks \<and>* zero j) s" by (simp add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1062
  from h[unfolded this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1063
  obtain s' where "reps i (j - 1) ks s'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1064
    by (auto elim!:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1065
  from reps_len_correct[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1066
  show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1067
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1068
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1069
lemma reps'_append:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1070
  "reps' i j (ks1 @ ks2) = (EXS m. (reps' i (m - 1) ks1 \<and>* reps' m j ks2))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1071
proof(cases "ks1 = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1072
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1073
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1074
    by (auto simp:reps'_def pred_ex_def pasrt_def set_ins_def sep_conj_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1075
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1076
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1077
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1078
  proof(cases "ks2 = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1079
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1080
    from `ks1 \<noteq> []` and `ks2 \<noteq> []` 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1081
    have "splited (ks1 @ ks2) ks1 ks2" by (auto simp:splited_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1082
    from reps_splited[OF this, of i "j - 1"]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1083
    have eq_1: "reps i (j - 1) (ks1 @ ks2) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1084
           (reps i (i + int (reps_len ks1) - 1) ks1 \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1085
           zero (i + int (reps_len ks1)) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1086
           reps (i + int (reps_len ks1) + 1) (j - 1) ks2)" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1087
    from `ks1 \<noteq> []`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1088
    have eq_2: "reps' i j (ks1 @ ks2) = (reps i (j - 1) (ks1 @ ks2) \<and>* zero j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1089
      by (unfold reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1090
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1091
    proof(default+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1092
      fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1093
      assume "reps' i j (ks1 @ ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1094
      show "(EXS m. reps' i (m - 1) ks1 \<and>* reps' m j ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1095
      proof(rule EXS_intro[where x = "i + int(reps_len ks1) + 1"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1096
        from `reps' i j (ks1 @ ks2) s`[unfolded eq_2 eq_1]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1097
        and `ks1 \<noteq> []` `ks2 \<noteq> []`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1098
        show "(reps' i (i + int (reps_len ks1) + 1 - 1) ks1 \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1099
                         reps' (i + int (reps_len ks1) + 1) j ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1100
          by (unfold reps'_def, simp, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1101
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1102
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1103
      fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1104
      assume "(EXS m. reps' i (m - 1) ks1 \<and>* reps' m j ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1105
      thus "reps' i j (ks1 @ ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1106
      proof(elim EXS_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1107
        fix m
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1108
        assume "(reps' i (m - 1) ks1 \<and>* reps' m j ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1109
        then obtain s1 s2 where h: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1110
          "s = s1 + s2" "s1 ## s2" "reps' i (m - 1) ks1 s1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1111
          " reps' m j ks2 s2" by (auto elim!:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1112
        from reps'_len_correct[OF this(3) `ks1 \<noteq> []`]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1113
        have eq_m: "m = i + int (reps_len ks1) + 1" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1114
        have "((reps i (i + int (reps_len ks1) - 1) ks1 \<and>* zero (i + int (reps_len ks1))) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1115
               ((reps (i + int (reps_len ks1) + 1) (j - 1) ks2) \<and>* zero j)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1116
          (is "(?P \<and>* ?Q) s") 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1117
        proof(rule sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1118
          from h(3) eq_m `ks1 \<noteq> []` show "?P s1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1119
            by (simp add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1120
        next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1121
          from h(4) eq_m `ks2 \<noteq> []` show "?Q s2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1122
            by (simp add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1123
        next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1124
          from h(2) show "s1 ## s2" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1125
        next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1126
          from h(1) show "s = s1 + s2" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1127
        qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1128
        thus "reps' i j (ks1 @ ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1129
          by (unfold eq_2 eq_1, auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1130
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1131
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1132
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1133
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1134
    have "-1 + j = j - 1" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1135
    with `ks1 \<noteq> []` True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1136
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1137
      apply (auto simp:reps'_def pred_ex_def pasrt_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1138
      apply (unfold `-1 + j = j - 1`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1139
      by (fold sep_empty_def, simp only:sep_conj_empty)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1140
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1141
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1142
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1143
lemma reps'_sg: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1144
  "reps' i j [k] = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1145
       (<(j = i + int k + 1)> \<and>* ones i (i + int k) \<and>* zero j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1146
  apply (unfold reps'_def, default, auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1147
  by (sep_cancel+, simp add:pasrt_def)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1148
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1149
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1150
section {* Basic macros for TM *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1151
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1152
definition "write_zero = (TL exit. \<guillemotright>((W0, exit), (W0, exit)); TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1153
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1154
lemma st_upd: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1155
  assumes pre: "(st i' ** r) (trset_of (f, x, i, y, z))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1156
  shows "(st i'' ** r) (trset_of (f, x,  i'', y, z))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1157
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1158
  from stimes_sgD[OF pre[unfolded st_def], unfolded trset_of.simps, unfolded stD[OF pre]]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1159
  have "r (tprog_set x \<union> tpc_set i' \<union> tpos_set y \<union> tmem_set z \<union> tfaults_set f - tpc_set i')"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1160
    by blast
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1161
  moreover have 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1162
    "(tprog_set x \<union> tpc_set i' \<union> tpos_set y \<union> tmem_set z \<union> tfaults_set f - tpc_set i') =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1163
     (tprog_set x \<union> tpos_set y \<union> tmem_set z \<union> tfaults_set f)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1164
    by (unfold tpn_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1165
  ultimately have r_rest: "r (tprog_set x \<union> tpos_set y \<union> tmem_set z \<union> tfaults_set f)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1166
    by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1167
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1168
  proof(rule sep_conjI[where Q = r, OF _ r_rest])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1169
    show "st i'' (tpc_set i'')" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1170
      by (unfold st_def sg_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1171
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1172
    show "tpc_set i'' ## tprog_set x \<union> tpos_set y \<union> tmem_set z \<union> tfaults_set f"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1173
      by (unfold tpn_set_def sep_disj_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1174
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1175
    show "trset_of (f, x, i'', y, z) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1176
             tpc_set i'' + (tprog_set x \<union> tpos_set y \<union> tmem_set z \<union> tfaults_set f)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1177
      by (unfold trset_of.simps plus_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1178
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1179
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1180
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1181
lemma pos_upd: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1182
  assumes pre: "(ps i ** r) (trset_of (f, x, y, i', z))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1183
  shows "(ps j ** r) (trset_of (f, x, y, j, z))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1184
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1185
  from stimes_sgD[OF pre[unfolded ps_def], unfolded trset_of.simps, unfolded psD[OF pre]]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1186
  have "r (tprog_set x \<union> tpc_set y \<union> tpos_set i \<union> tmem_set z \<union> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1187
              tfaults_set f - tpos_set i)" (is "r ?xs")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1188
    by blast
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1189
  moreover have 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1190
    "?xs = tprog_set x \<union> tpc_set y  \<union> tmem_set z \<union> tfaults_set f"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1191
    by (unfold tpn_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1192
  ultimately have r_rest: "r \<dots>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1193
    by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1194
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1195
  proof(rule sep_conjI[where Q = r, OF _ r_rest])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1196
    show "ps j (tpos_set j)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1197
      by (unfold ps_def sg_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1198
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1199
    show "tpos_set j ## tprog_set x \<union> tpc_set y \<union> tmem_set z \<union> tfaults_set f"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1200
      by (unfold tpn_set_def sep_disj_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1201
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1202
    show "trset_of (f, x, y, j, z) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1203
             tpos_set j + (tprog_set x \<union> tpc_set y \<union> tmem_set z \<union> tfaults_set f)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1204
      by (unfold trset_of.simps plus_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1205
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1206
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1207
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1208
lemma TM_in_simp: "({TM a v} \<subseteq> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1209
                      tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> tmem_set mem \<union> tfaults_set f) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1210
                             ({TM a v} \<subseteq> tmem_set mem)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1211
  by (unfold tpn_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1212
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1213
lemma tmem_set_upd: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1214
  "{TM a v} \<subseteq> tmem_set mem \<Longrightarrow> 
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1215
        tmem_set (mem(a $:=Some v')) = ((tmem_set mem) - {TM a v}) \<union> {TM a v'}"
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1216
apply(unfold tpn_set_def) 
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1217
apply(auto)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1218
apply (metis finfun_upd_apply option.inject)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1219
apply (metis finfun_upd_apply_other)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1220
by (metis finfun_upd_apply_other option.inject)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1221
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1222
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1223
lemma tmem_set_disj: "{TM a v} \<subseteq> tmem_set mem \<Longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1224
                            {TM a v'} \<inter>  (tmem_set mem - {TM a v}) = {}"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1225
  by (unfold tpn_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1226
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1227
lemma smem_upd: "((tm a v) ** r) (trset_of (f, x, y, z, mem))  \<Longrightarrow> 
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1228
                    ((tm a v') ** r) (trset_of (f, x, y, z, mem(a $:= Some v')))"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1229
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1230
  have eq_s: "(tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> tmem_set mem \<union> tfaults_set f - {TM a v}) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1231
    (tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> (tmem_set mem - {TM a v}) \<union> tfaults_set f)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1232
    by (unfold tpn_set_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1233
  assume g: "(tm a v \<and>* r) (trset_of (f, x, y, z, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1234
  from this[unfolded trset_of.simps tm_def]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1235
  have h: "(sg {TM a v} \<and>* r) (tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> tmem_set mem \<union> tfaults_set f)" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1236
  hence h0: "r (tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> (tmem_set mem - {TM a v}) \<union> tfaults_set f)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1237
    by(sep_drule stimes_sgD, clarify, unfold eq_s, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1238
  from h TM_in_simp have "{TM a v} \<subseteq> tmem_set mem"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1239
    by(sep_drule stimes_sgD, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1240
  from tmem_set_upd [OF this] tmem_set_disj[OF this]
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1241
  have h2: "tmem_set (mem(a $:= Some v')) = {TM a v'} \<union> (tmem_set mem - {TM a v})" 
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1242
           "{TM a v'} \<inter> (tmem_set mem - {TM a v}) = {}" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1243
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1244
  proof -
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1245
    have "(tm a v' ** r) (tmem_set (mem(a $:= Some v')) \<union> tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> tfaults_set f)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1246
    proof(rule sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1247
      show "tm a v' ({TM a v'})" by (unfold tm_def sg_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1248
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1249
      from h0 show "r (tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> (tmem_set mem - {TM a v}) \<union> tfaults_set f)" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1250
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1251
      show "{TM a v'} ## tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> (tmem_set mem - {TM a v}) \<union> tfaults_set f"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1252
      proof -
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1253
        from g have " mem $ a = Some v"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1254
          by(sep_frule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1255
        thus "?thesis"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1256
          by(unfold tpn_set_def set_ins_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1257
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1258
    next
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1259
      show "tmem_set (mem(a $:= Some v')) \<union> tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> tfaults_set f =
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1260
    {TM a v'} + (tprog_set x \<union> tpc_set y \<union> tpos_set z \<union> (tmem_set mem - {TM a v}) \<union> tfaults_set f)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1261
        by (unfold h2(1) set_ins_def eq_s, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1262
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1263
    thus ?thesis 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1264
      apply (unfold trset_of.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1265
      by (metis sup_commute sup_left_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1266
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1267
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1268
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1269
lemma hoare_write_zero: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1270
  "\<lbrace>st i ** ps p ** tm p v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1271
     i:[write_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1272
   \<lbrace>st j ** ps p ** tm p Bk\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1273
proof(unfold write_zero_def, intro t_hoare_local, rule t_hoare_label_last, simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1274
  show "\<lbrace>st i \<and>* ps p \<and>* tm p v\<rbrace>  i :[ \<guillemotright> ((W0, j), W0, j) ]: j \<lbrace>st j \<and>* ps p \<and>* tm p Bk\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1275
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1276
        intro tm.code_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1277
    assume eq_j: "j = Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1278
    show "\<lbrace>st i \<and>* ps p \<and>* tm p v\<rbrace>  sg {TC i ((W0, Suc i), W0, Suc i)} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1279
          \<lbrace>st (Suc i) \<and>* ps p \<and>* tm p Bk\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1280
    proof(fold eq_j, unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1281
      fix ft prog cs i' mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1282
      assume h: "(r \<and>* ps p \<and>* st i \<and>* tm p v \<and>* sg {TC i ((W0, j), W0, j)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1283
              (trset_of (ft, prog, cs, i', mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1284
      from h have "prog $ i = Some ((W0, j), W0, j)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1285
        apply(rule_tac r = "r \<and>* ps p \<and>* tm p v" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1286
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1287
      from h and this have stp:
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1288
        "tm.run 1 (ft, prog, cs, i', mem) = (ft, prog, j, i', mem(i' $:= Some Bk))" (is "?x = ?y")
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1289
        apply(sep_frule psD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1290
        apply(sep_frule stD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1291
        apply(sep_frule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1292
        by(cases v, unfold tm.run_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1293
      from h have "i' = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1294
        by(sep_drule psD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1295
      with h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1296
      have "(r \<and>* ps p \<and>* st j \<and>* tm p Bk \<and>* sg {TC i ((W0, j), W0, j)}) (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1297
        apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1298
        apply(sep_drule pos_upd, sep_drule st_upd, sep_drule smem_upd)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1299
        apply(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1300
        done
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1301
      thus "\<exists>k. (r \<and>* ps p \<and>* st j \<and>* tm p Bk \<and>* sg {TC i ((W0, j), W0, j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1302
             (trset_of (tm.run (Suc k) (ft, prog, cs, i', mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1303
        apply (rule_tac x = 0 in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1304
        by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1305
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1306
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1307
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1308
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1309
lemma hoare_write_zero_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1310
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1311
  shows  "\<lbrace>st i ** ps p ** tm q v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1312
            i:[write_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1313
          \<lbrace>st j ** ps p ** tm q Bk\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1314
  by (unfold assms, rule hoare_write_zero)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1315
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1316
definition "write_one = (TL exit. \<guillemotright>((W1, exit), (W1, exit)); TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1317
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1318
lemma hoare_write_one: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1319
  "\<lbrace>st i ** ps p ** tm p v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1320
     i:[write_one]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1321
   \<lbrace>st j ** ps p ** tm p Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1322
proof(unfold write_one_def, intro t_hoare_local, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1323
  fix l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1324
  show "\<lbrace>st i \<and>* ps p \<and>* tm p v\<rbrace>  i :[ \<guillemotright> ((W1, j), W1, j) ]: j \<lbrace>st j \<and>* ps p \<and>* tm p Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1325
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1326
        rule_tac tm.code_condI, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1327
    let ?j = "Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1328
    show "\<lbrace>ps p \<and>* st i \<and>* tm p v\<rbrace>  sg {TC i ((W1, ?j), W1, ?j)} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1329
          \<lbrace>ps p \<and>* st ?j \<and>* tm p Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1330
    proof(unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1331
      fix ft prog cs i' mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1332
      assume h: "(r \<and>* ps p \<and>* st i \<and>* tm p v \<and>* sg {TC i ((W1, ?j), W1, ?j)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1333
              (trset_of (ft, prog, cs, i', mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1334
      from h have "prog $ i = Some ((W1, ?j), W1, ?j)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1335
        apply(rule_tac r = "r \<and>* ps p \<and>* tm p v" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1336
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1337
      from h and this have stp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1338
        "tm.run 1 (ft, prog, cs, i', mem) = 
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1339
                     (ft, prog, ?j, i', mem(i' $:= Some Oc))" (is "?x = ?y")
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1340
        apply(sep_frule psD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1341
        apply(sep_frule stD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1342
        apply(sep_frule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1343
        by(cases v, unfold tm.run_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1344
      from h have "i' = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1345
        by(sep_drule psD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1346
      with h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1347
      have "(r \<and>* ps p \<and>* st ?j \<and>* tm p Oc \<and>* sg {TC i ((W1, ?j), W1, ?j)}) (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1348
        apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1349
        apply(sep_drule pos_upd, sep_drule st_upd, sep_drule smem_upd)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1350
        apply(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1351
        done
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1352
      thus "\<exists>k. (r \<and>* ps p \<and>* st ?j \<and>* tm p Oc \<and>* sg {TC i ((W1, ?j), W1, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1353
             (trset_of (tm.run (Suc k) (ft, prog, cs, i', mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1354
        apply (rule_tac x = 0 in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1355
        by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1356
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1357
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1358
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1359
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1360
lemma hoare_write_one_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1361
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1362
  shows  "\<lbrace>st i ** ps p ** tm q v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1363
              i:[write_one]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1364
          \<lbrace>st j ** ps p ** tm q Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1365
  by (unfold assms, rule hoare_write_one)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1366
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1367
definition "move_left = (TL exit . \<guillemotright>((L, exit), (L, exit)); TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1368
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1369
lemma hoare_move_left: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1370
  "\<lbrace>st i ** ps p ** tm p v2\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1371
     i:[move_left]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1372
   \<lbrace>st j ** ps (p - 1) **  tm p v2\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1373
proof(unfold move_left_def, intro t_hoare_local, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1374
  fix l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1375
  show "\<lbrace>st i \<and>* ps p \<and>* tm p v2\<rbrace>  i :[ \<guillemotright> ((L, l), L, l) ]: l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1376
        \<lbrace>st l \<and>* ps (p - 1) \<and>* tm p v2\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1377
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1378
      intro tm.code_condI, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1379
    let ?j = "Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1380
    show "\<lbrace>ps p \<and>* st i \<and>* tm p v2\<rbrace>  sg {TC i ((L, ?j), L, ?j)} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1381
          \<lbrace>st ?j \<and>* tm p v2 \<and>* ps (p - 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1382
    proof(unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1383
      fix ft prog cs i' mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1384
      assume h: "(r \<and>* ps p \<and>* st i \<and>* tm p v2 \<and>* sg {TC i ((L, ?j), L, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1385
                       (trset_of (ft, prog, cs, i',  mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1386
      from h have "prog $ i = Some ((L, ?j), L, ?j)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1387
        apply(rule_tac r = "r \<and>* ps p \<and>* tm p v2" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1388
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1389
      from h and this have stp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1390
        "tm.run 1 (ft, prog, cs, i', mem) = (ft, prog, ?j, i' - 1, mem)" (is "?x = ?y")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1391
        apply(sep_frule psD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1392
        apply(sep_frule stD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1393
        apply(sep_frule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1394
        apply(unfold tm.run_def, case_tac v2, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1395
        done
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1396
      from h have "i' = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1397
        by(sep_drule psD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1398
      with h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1399
      have "(r \<and>* st ?j \<and>* tm p v2 \<and>* ps (p - 1) \<and>* sg {TC i ((L, ?j), L, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1400
               (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1401
        apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1402
        apply(sep_drule pos_upd, sep_drule st_upd, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1403
      proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1404
        assume "(st ?j \<and>* ps (p - 1) \<and>* r \<and>* tm p v2 \<and>* sg {TC i ((L, ?j), L, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1405
                   (trset_of (ft, prog, ?j, p - 1, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1406
        thus "(r \<and>* st ?j \<and>* tm p v2 \<and>* ps (p - 1) \<and>* sg {TC i ((L, ?j), L, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1407
                    (trset_of (ft, prog, ?j, p - 1, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1408
          by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1409
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1410
      thus "\<exists>k. (r \<and>* st ?j \<and>* tm p v2 \<and>* ps (p - 1) \<and>* sg {TC i ((L, ?j), L, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1411
             (trset_of (tm.run (Suc k) (ft, prog, cs, i', mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1412
        apply (rule_tac x = 0 in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1413
        by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1414
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1415
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1416
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1417
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1418
lemma hoare_move_left_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1419
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1420
  shows "\<lbrace>st i ** ps p ** tm q v2\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1421
            i:[move_left]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1422
         \<lbrace>st j ** ps (p - 1) **  tm q v2\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1423
  by (unfold assms, rule hoare_move_left)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1424
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1425
definition "move_right = (TL exit . \<guillemotright>((R, exit), (R, exit)); TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1426
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1427
lemma hoare_move_right: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1428
  "\<lbrace>st i ** ps p ** tm p v1 \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1429
     i:[move_right]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1430
   \<lbrace>st j ** ps (p + 1) ** tm p v1 \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1431
proof(unfold move_right_def, intro t_hoare_local, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1432
  fix l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1433
  show "\<lbrace>st i \<and>* ps p \<and>* tm p v1\<rbrace>  i :[ \<guillemotright> ((R, l), R, l) ]: l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1434
        \<lbrace>st l \<and>* ps (p + 1) \<and>* tm p v1\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1435
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1436
      intro tm.code_condI, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1437
    let ?j = "Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1438
    show "\<lbrace>ps p \<and>* st i \<and>* tm p v1\<rbrace>  sg {TC i ((R, ?j), R, ?j)} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1439
          \<lbrace>st ?j \<and>* tm p v1 \<and>* ps (p + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1440
    proof(unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1441
      fix ft prog cs i' mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1442
      assume h: "(r \<and>* ps p \<and>* st i \<and>* tm p v1 \<and>* sg {TC i ((R, ?j), R, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1443
                       (trset_of (ft, prog, cs, i',  mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1444
      from h have "prog $ i = Some ((R, ?j), R, ?j)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1445
        apply(rule_tac r = "r \<and>* ps p \<and>* tm p v1" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1446
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1447
      from h and this have stp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1448
        "tm.run 1 (ft, prog, cs, i', mem) = (ft, prog, ?j, i'+ 1, mem)" (is "?x = ?y")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1449
        apply(sep_frule psD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1450
        apply(sep_frule stD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1451
        apply(sep_frule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1452
        apply(unfold tm.run_def, case_tac v1, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1453
        done
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1454
      from h have "i' = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1455
        by(sep_drule psD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1456
      with h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1457
      have "(r \<and>* st ?j \<and>* tm p v1 \<and>* ps (p + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1458
                sg {TC i ((R, ?j), R, ?j)}) (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1459
        apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1460
        apply(sep_drule pos_upd, sep_drule st_upd, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1461
      proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1462
        assume "(st ?j \<and>* ps (p + 1) \<and>* r \<and>* tm p v1 \<and>* sg {TC i ((R, ?j), R, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1463
                   (trset_of (ft, prog, ?j, p + 1, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1464
        thus "(r \<and>* st ?j \<and>* tm p v1 \<and>* ps (p + 1) \<and>* sg {TC i ((R, ?j), R, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1465
                    (trset_of (ft, prog, ?j, p + 1, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1466
          by (simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1467
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1468
      thus "\<exists>k. (r \<and>* st ?j \<and>* tm p v1 \<and>* ps (p + 1) \<and>* sg {TC i ((R, ?j), R, ?j)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1469
             (trset_of (tm.run (Suc k) (ft, prog, cs, i', mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1470
        apply (rule_tac x = 0 in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1471
        by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1472
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1473
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1474
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1475
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1476
lemma hoare_move_right_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1477
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1478
  shows "\<lbrace>st i ** ps p ** tm q v1 \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1479
           i:[move_right]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1480
         \<lbrace>st j ** ps (p + 1) ** tm q v1 \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1481
  by (unfold assms, rule hoare_move_right)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1482
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1483
definition "if_one e = (TL exit . \<guillemotright>((W0, exit), (W1, e)); TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1484
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1485
lemma hoare_if_one_true: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1486
  "\<lbrace>st i ** ps p ** one p\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1487
     i:[if_one e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1488
   \<lbrace>st e ** ps p ** one p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1489
proof(unfold if_one_def, intro t_hoare_local, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1490
  fix l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1491
  show " \<lbrace>st i \<and>* ps p \<and>* one p\<rbrace>  i :[ \<guillemotright> ((W0, l), W1, e) ]: l \<lbrace>st e \<and>* ps p \<and>* one p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1492
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1493
        intro tm.code_condI, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1494
    let ?j = "Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1495
    show "\<lbrace>one p \<and>* ps p \<and>* st i\<rbrace>  sg {TC i ((W0, ?j), W1, e)} \<lbrace>one p \<and>* ps p \<and>* st e\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1496
    proof(unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1497
      fix ft prog cs pc mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1498
      assume h: "(r \<and>* one p \<and>* ps p \<and>* st i \<and>* sg {TC i ((W0, ?j), W1, e)}) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1499
        (trset_of (ft, prog, cs, pc, mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1500
      from h have k1: "prog $ i = Some ((W0, ?j), W1, e)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1501
        apply(rule_tac r = "r \<and>* one p \<and>* ps p" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1502
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1503
      from h have k2: "pc = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1504
        by(sep_drule psD, simp)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1505
      from h and this have k3: "mem $ pc = Some Oc"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1506
        apply(unfold one_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1507
        by(sep_drule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1508
      from h k1 k2 k3 have stp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1509
        "tm.run 1 (ft, prog, cs, pc, mem) = (ft, prog, e, pc, mem)" (is "?x = ?y")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1510
        apply(sep_drule stD)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1511
        apply(unfold tm.run_def)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1512
        apply(auto)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1513
        by (metis finfun_upd_triv)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1514
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1515
      from h k2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1516
      have "(r \<and>* one p \<and>* ps p \<and>* st e \<and>* sg {TC i ((W0, ?j), W1, e)})  (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1517
        apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1518
        by(sep_drule st_upd, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1519
      thus "\<exists>k.(r \<and>* one p \<and>* ps p \<and>* st e \<and>* sg {TC i ((W0, ?j), W1, e)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1520
             (trset_of (tm.run (Suc k) (ft, prog, cs, pc, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1521
        apply (rule_tac x = 0 in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1522
        by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1523
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1524
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1525
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1526
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1527
text {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1528
  The following problematic lemma is not provable now 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1529
  lemma hoare_self: "\<lbrace>p\<rbrace> i :[ap]: j \<lbrace>p\<rbrace>" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1530
  apply(simp add: tm.Hoare_gen_def, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1531
  apply(rule_tac x = 0 in exI, simp add: tm.run_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1532
  done
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1533
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1534
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1535
lemma hoare_if_one_true_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1536
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1537
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1538
  "\<lbrace>st i ** ps p ** one q\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1539
     i:[if_one e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1540
   \<lbrace>st e ** ps p ** one q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1541
  by (unfold assms, rule hoare_if_one_true)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1542
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1543
lemma hoare_if_one_true1: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1544
  "\<lbrace>st i ** ps p ** one p\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1545
     i:[(if_one e; c)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1546
   \<lbrace>st e ** ps p ** one p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1547
proof(unfold tassemble_to.simps, rule tm.code_exI, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1548
       simp add: sep_conj_ac tm.Hoare_gen_def, clarify)  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1549
  fix j' ft prog cs pos mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1550
  assume h: "(r \<and>* one p \<and>* ps p \<and>* st i \<and>* j' :[ c ]: j \<and>* i :[ if_one e ]: j') 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1551
    (trset_of (ft, prog, cs, pos, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1552
  from tm.frame_rule[OF hoare_if_one_true]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1553
  have "\<And> r. \<lbrace>st i \<and>* ps p \<and>* one p \<and>* r\<rbrace>  i :[ if_one e ]: j' \<lbrace>st e \<and>* ps p \<and>* one p \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1554
    by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1555
  from this[unfolded tm.Hoare_gen_def tassemble_to.simps, rule_format, of "j' :[ c ]: j"] h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1556
  have "\<exists> k. (r \<and>* one p \<and>* ps p \<and>* st e \<and>* i :[ if_one e ]: j' \<and>* j' :[ c ]: j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1557
    (trset_of (tm.run (Suc k) (ft, prog, cs, pos, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1558
    by(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1559
  thus "\<exists>k. (r \<and>* one p \<and>* ps p \<and>* st e \<and>* j' :[ c ]: j \<and>* i :[ if_one e ]: j') 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1560
    (trset_of (tm.run (Suc k) (ft, prog, cs, pos, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1561
    by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1562
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1563
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1564
lemma hoare_if_one_true1_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1565
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1566
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1567
  "\<lbrace>st i ** ps p ** one q\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1568
     i:[(if_one e; c)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1569
   \<lbrace>st e ** ps p ** one q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1570
  by (unfold assms, rule hoare_if_one_true1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1571
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1572
lemma hoare_if_one_false: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1573
  "\<lbrace>st i ** ps p ** zero p\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1574
       i:[if_one e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1575
   \<lbrace>st j ** ps p ** zero p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1576
proof(unfold if_one_def, intro t_hoare_local, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1577
  show "\<lbrace>st i \<and>* ps p \<and>* zero p\<rbrace>  i :[ (\<guillemotright> ((W0, j), W1, e)) ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1578
        \<lbrace>st j \<and>* ps p \<and>* zero p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1579
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1580
        intro tm.code_condI, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1581
    let ?j = "Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1582
    show "\<lbrace>ps p \<and>* st i \<and>* zero p\<rbrace>  sg {TC i ((W0, ?j), W1, e)} \<lbrace>ps p \<and>*  zero p \<and>* st ?j \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1583
    proof(unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1584
      fix ft prog cs pc mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1585
      assume h: "(r \<and>* ps p \<and>* st i \<and>* zero p \<and>* sg {TC i ((W0, ?j), W1, e)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1586
        (trset_of (ft, prog, cs, pc, mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1587
      from h have k1: "prog $ i = Some ((W0, ?j), W1, e)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1588
        apply(rule_tac r = "r \<and>* zero p \<and>* ps p" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1589
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1590
      from h have k2: "pc = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1591
        by(sep_drule psD, simp)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1592
      from h and this have k3: "mem $ pc = Some Bk"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1593
        apply(unfold zero_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1594
        by(sep_drule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1595
      from h k1 k2 k3 have stp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1596
        "tm.run 1 (ft, prog, cs, pc, mem) = (ft, prog, ?j, pc, mem)" (is "?x = ?y")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1597
        apply(sep_drule stD)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1598
        apply(unfold tm.run_def)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1599
        apply(auto)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1600
        by (metis finfun_upd_triv)
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1601
      from h k2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1602
      have "(r \<and>* zero p \<and>* ps p \<and>* st ?j \<and>* sg {TC i ((W0, ?j), W1, e)})  (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1603
        apply (unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1604
        by (sep_drule st_upd[where i''="?j"], auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1605
      thus "\<exists>k. (r \<and>* ps p \<and>* zero p \<and>* st ?j \<and>*  sg {TC i ((W0, ?j), W1, e)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1606
             (trset_of (tm.run (Suc k) (ft, prog, cs, pc, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1607
        by(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1608
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1609
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1610
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1611
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1612
lemma hoare_if_one_false_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1613
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1614
  shows "\<lbrace>st i ** ps p ** zero q\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1615
             i:[if_one e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1616
         \<lbrace>st j ** ps p ** zero q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1617
  by (unfold assms, rule hoare_if_one_false)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1618
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1619
definition "if_zero e = (TL exit . \<guillemotright>((W0, e), (W1, exit)); TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1620
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1621
lemma hoare_if_zero_true: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1622
  "\<lbrace>st i ** ps p ** zero p\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1623
     i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1624
   \<lbrace>st e ** ps p ** zero p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1625
proof(unfold if_zero_def, intro t_hoare_local, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1626
  fix l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1627
  show "\<lbrace>st i \<and>* ps p \<and>* zero p\<rbrace>  i :[ \<guillemotright> ((W0, e), W1, l) ]: l \<lbrace>st e \<and>* ps p \<and>* zero p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1628
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1629
        intro tm.code_condI, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1630
    let ?j = "Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1631
    show "\<lbrace>ps p \<and>* st i \<and>* zero p\<rbrace>  sg {TC i ((W0, e), W1, ?j)} \<lbrace>ps p \<and>* st e \<and>* zero p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1632
    proof(unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1633
      fix ft prog cs pc mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1634
      assume h: "(r \<and>* ps p \<and>* st i \<and>* zero p \<and>* sg {TC i ((W0, e), W1, ?j)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1635
        (trset_of (ft, prog, cs, pc, mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1636
      from h have k1: "prog $ i = Some ((W0, e), W1, ?j)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1637
        apply(rule_tac r = "r \<and>* zero p \<and>* ps p" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1638
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1639
      from h have k2: "pc = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1640
        by(sep_drule psD, simp)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1641
      from h and this have k3: "mem $ pc = Some Bk"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1642
        apply(unfold zero_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1643
        by(sep_drule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1644
      from h k1 k2 k3 have stp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1645
        "tm.run 1 (ft, prog, cs, pc, mem) = (ft, prog, e, pc, mem)" (is "?x = ?y")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1646
        apply(sep_drule stD)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1647
        apply(unfold tm.run_def)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1648
        apply(auto)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1649
        by (metis finfun_upd_triv)  
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1650
      from h k2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1651
      have "(r \<and>* zero p \<and>* ps p \<and>* st e \<and>* sg {TC i ((W0, e), W1, ?j)})  (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1652
        apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1653
        by(sep_drule st_upd, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1654
      thus "\<exists>k. (r \<and>* ps p \<and>* st e \<and>* zero p \<and>* sg {TC i ((W0, e), W1, ?j)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1655
             (trset_of (tm.run (Suc k) (ft, prog, cs, pc, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1656
        by(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1657
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1658
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1659
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1660
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1661
lemma hoare_if_zero_true_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1662
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1663
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1664
  "\<lbrace>st i ** ps p ** zero q\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1665
     i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1666
   \<lbrace>st e ** ps p ** zero q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1667
  by (unfold assms, rule hoare_if_zero_true)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1668
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1669
lemma hoare_if_zero_true1: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1670
  "\<lbrace>st i ** ps p ** zero p\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1671
     i:[(if_zero e; c)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1672
   \<lbrace>st e ** ps p ** zero p\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1673
 proof(unfold tassemble_to.simps, rule tm.code_exI, simp add: sep_conj_ac 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1674
        tm.Hoare_gen_def, clarify)  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1675
  fix j' ft prog cs pos mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1676
  assume h: "(r \<and>* ps p \<and>* st i \<and>* zero p \<and>* j' :[ c ]: j \<and>* i :[ if_zero e ]: j') 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1677
    (trset_of (ft, prog, cs, pos, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1678
  from tm.frame_rule[OF hoare_if_zero_true]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1679
  have "\<And> r. \<lbrace>st i \<and>* ps p \<and>* zero p \<and>* r\<rbrace>  i :[ if_zero e ]: j' \<lbrace>st e \<and>* ps p \<and>* zero p \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1680
    by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1681
  from this[unfolded tm.Hoare_gen_def tassemble_to.simps, rule_format, of "j' :[ c ]: j"] h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1682
  have "\<exists> k. (r \<and>* zero p \<and>* ps p \<and>* st e \<and>* i :[ if_zero e ]: j' \<and>* j' :[ c ]: j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1683
    (trset_of (tm.run (Suc k) (ft, prog, cs, pos, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1684
    by(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1685
  thus "\<exists>k. (r \<and>* ps p \<and>* st e \<and>* zero p \<and>* j' :[ c ]: j \<and>* i :[ if_zero e ]: j')  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1686
    (trset_of (tm.run (Suc k) (ft, prog, cs, pos, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1687
    by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1688
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1689
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1690
lemma hoare_if_zero_true1_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1691
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1692
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1693
  "\<lbrace>st i ** ps p ** zero q\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1694
     i:[(if_zero e; c)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1695
   \<lbrace>st e ** ps p ** zero q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1696
  by (unfold assms, rule hoare_if_zero_true1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1697
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1698
lemma hoare_if_zero_false: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1699
  "\<lbrace>st i ** ps p ** tm p Oc\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1700
     i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1701
   \<lbrace>st j ** ps p ** tm p Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1702
proof(unfold if_zero_def, intro t_hoare_local, rule t_hoare_label_last, simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1703
  fix l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1704
  show "\<lbrace>st i \<and>* ps p \<and>* tm p Oc\<rbrace>  i :[ \<guillemotright> ((W0, e), W1, l) ]: l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1705
        \<lbrace>st l \<and>* ps p \<and>* tm p Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1706
  proof(unfold tassemble_to.simps, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1707
      intro tm.code_condI, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1708
    let ?j = "Suc i"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1709
    show "\<lbrace>ps p \<and>* st i \<and>* tm p Oc\<rbrace>  sg {TC i ((W0, e), W1, ?j)} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1710
          \<lbrace>ps p \<and>* st ?j \<and>* tm p Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1711
    proof(unfold tassemble_to.simps tm.Hoare_gen_def sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1712
      fix ft prog cs pc mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1713
      assume h: "(r \<and>* ps p \<and>* st i \<and>* tm p Oc \<and>* sg {TC i ((W0, e), W1, ?j)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1714
        (trset_of (ft, prog, cs, pc, mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1715
      from h have k1: "prog $ i = Some ((W0, e), W1, ?j)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1716
        apply(rule_tac r = "r \<and>* tm p Oc \<and>* ps p" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1717
        by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1718
      from h have k2: "pc = p"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1719
        by(sep_drule psD, simp)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1720
      from h and this have k3: "mem $ pc = Some Oc"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1721
        by(sep_drule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1722
      from h k1 k2 k3 have stp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1723
        "tm.run 1 (ft, prog, cs, pc, mem) = (ft, prog, ?j, pc, mem)" (is "?x = ?y")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1724
        apply(sep_drule stD)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1725
        apply(unfold tm.run_def)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1726
        apply(auto)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1727
        by (metis finfun_upd_triv)
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1728
      from h k2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1729
      have "(r \<and>* tm p Oc \<and>* ps p \<and>* st ?j \<and>* sg {TC i ((W0, e), W1, ?j)})  (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1730
        apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1731
        by(sep_drule st_upd, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1732
      thus "\<exists>k. (r \<and>* ps p \<and>* st ?j \<and>* tm p Oc \<and>* sg {TC i ((W0, e), W1, ?j)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1733
             (trset_of (tm.run (Suc k) (ft, prog, cs, pc, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1734
        by(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1735
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1736
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1737
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1738
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1739
lemma hoare_if_zero_false_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1740
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1741
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1742
  "\<lbrace>st i ** ps p ** tm q Oc\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1743
     i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1744
   \<lbrace>st j ** ps p ** tm q Oc\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1745
  by (unfold assms, rule hoare_if_zero_false)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1746
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1747
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1748
definition "jmp e = \<guillemotright>((W0, e), (W1, e))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1749
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1750
lemma hoare_jmp: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1751
  "\<lbrace>st i \<and>* ps p \<and>* tm p v\<rbrace>  i:[jmp e]:j \<lbrace>st e \<and>* ps p \<and>* tm p v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1752
proof(unfold jmp_def tm.Hoare_gen_def tassemble_to.simps sep_conj_ac, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1753
  fix ft prog cs pos mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1754
  assume h: "(r \<and>* ps p \<and>* st i \<and>* tm p v \<and>* <(j = i + 1)> \<and>* sg {TC i ((W0, e), W1, e)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1755
    (trset_of (ft, prog, cs, pos, mem))"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1756
  from h have k1: "prog $ i = Some ((W0, e), W1, e)"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1757
    apply(rule_tac r = "r \<and>* <(j = i + 1)> \<and>* tm p v \<and>* ps p" in codeD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1758
    by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1759
  from h have k2: "p = pos"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1760
    by(sep_drule psD, simp)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1761
  from h k2 have k3: "mem $ pos = Some v"
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1762
    by(sep_drule memD, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1763
  from h k1 k2 k3 have 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1764
    stp: "tm.run 1 (ft, prog, cs, pos, mem) = (ft, prog, e, pos, mem)" (is "?x = ?y")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1765
    apply(sep_drule stD)
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1766
    apply(unfold tm.run_def)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1767
    apply(cases "mem $ pos")
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1768
    apply(simp)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1769
    apply(cases v)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1770
    apply(auto)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1771
    apply (metis finfun_upd_triv)
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1772
    by (metis finfun_upd_triv)
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1773
  from h k2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1774
  have "(r \<and>* ps p \<and>* st e \<and>* tm p v \<and>* <(j = i + 1)> \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1775
           sg {TC i ((W0, e), W1, e)}) (trset_of ?x)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1776
    apply(unfold stp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1777
    by(sep_drule st_upd, simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1778
  thus "\<exists> k. (r \<and>* ps p \<and>* st e \<and>* tm p v \<and>* <(j = i + 1)> \<and>* sg {TC i ((W0, e), W1, e)})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1779
             (trset_of (tm.run (Suc k) (ft, prog, cs, pos, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1780
    apply (rule_tac x = 0 in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1781
    by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1782
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1783
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1784
lemma hoare_jmp_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1785
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1786
  shows "\<lbrace>st i \<and>* ps p \<and>* tm q v\<rbrace>  i:[jmp e]:j \<lbrace>st e \<and>* ps p \<and>* tm q v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1787
  by (unfold assms, rule hoare_jmp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1788
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1789
lemma hoare_jmp1: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1790
  "\<lbrace>st i \<and>* ps p \<and>* tm p v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1791
     i:[(jmp e; c)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1792
   \<lbrace>st e \<and>* ps p \<and>* tm p v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1793
proof(unfold  tassemble_to.simps, rule tm.code_exI, simp 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1794
              add: sep_conj_ac tm.Hoare_gen_def, clarify)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1795
  fix j' ft prog cs pos mem r
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1796
  assume h: "(r \<and>* ps p \<and>* st i \<and>* tm p v \<and>* j' :[ c ]: j \<and>* i :[ jmp e ]: j') 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1797
    (trset_of (ft, prog, cs, pos, mem))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1798
  from tm.frame_rule[OF hoare_jmp]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1799
  have "\<And> r. \<lbrace>st i \<and>* ps p \<and>* tm p v \<and>* r\<rbrace>  i :[ jmp e ]: j' \<lbrace>st e \<and>* ps p \<and>* tm p v \<and>* r\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1800
    by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1801
  from this[unfolded tm.Hoare_gen_def tassemble_to.simps, rule_format, of "j' :[ c ]: j"] h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1802
  have "\<exists> k. (r \<and>* tm p v \<and>* ps p \<and>* st e \<and>* i :[ jmp e ]: j' \<and>* j' :[ c ]: j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1803
    (trset_of (tm.run (Suc k) (ft, prog, cs, pos, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1804
    by(auto simp: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1805
  thus "\<exists>k. (r \<and>* ps p \<and>* st e \<and>* tm p v \<and>* j' :[ c ]: j \<and>* i :[ jmp e ]: j')  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1806
    (trset_of (tm.run (Suc k) (ft, prog, cs, pos, mem)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1807
    by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1808
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1809
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1810
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1811
lemma hoare_jmp1_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1812
  assumes "p = q"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1813
  shows "\<lbrace>st i \<and>* ps p \<and>* tm q v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1814
            i:[(jmp e; c)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1815
         \<lbrace>st e \<and>* ps p \<and>* tm q v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1816
  by (unfold assms, rule hoare_jmp1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1817
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1818
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1819
lemma condI: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1820
  assumes h1: b
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1821
  and h2: "b \<Longrightarrow> p s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1822
  shows "(<b> \<and>* p) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1823
  by (metis (full_types) cond_true_eq1 h1 h2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1824
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1825
lemma condE:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1826
  assumes "(<b> \<and>* p) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1827
  obtains "b" and "p s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1828
proof(atomize_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1829
  from condD[OF assms]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1830
  show "b \<and> p s" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1831
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1832
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1833
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1834
section {* Tactics *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1835
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1836
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1837
  val trace_step = Attrib.setup_config_bool @{binding trace_step} (K false)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1838
  val trace_fwd = Attrib.setup_config_bool @{binding trace_fwd} (K false)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1839
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1840
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1841
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1842
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1843
  val tracing  = (fn ctxt => fn str =>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1844
                   if (Config.get ctxt trace_step) then tracing str else ())
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1845
  fun not_pred p = fn s => not (p s)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1846
  fun break_sep_conj (Const (@{const_name sep_conj},_) $ t1 $ t2 $ _) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1847
         (break_sep_conj t1) @ (break_sep_conj t2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1848
    | break_sep_conj (Const (@{const_name sep_conj},_) $ t1 $ t2) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1849
            (break_sep_conj t1) @ (break_sep_conj t2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1850
                   (* dig through eta exanded terms: *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1851
    | break_sep_conj (Abs (_, _, t $ Bound 0)) = break_sep_conj t
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1852
    | break_sep_conj t = [t];
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1853
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1854
  val empty_env = (Vartab.empty, Vartab.empty)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1855
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1856
  fun match_env ctxt pat trm env = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1857
            Pattern.match (ctxt |> Proof_Context.theory_of) (pat, trm) env
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1858
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1859
  fun match ctxt pat trm = match_env ctxt pat trm empty_env;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1860
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1861
  val inst = Envir.subst_term;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1862
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1863
  fun term_of_thm thm = thm |>  prop_of |> HOLogic.dest_Trueprop
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1864
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1865
  fun get_cmd ctxt code = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1866
      let val pat = term_of @{cpat "_:[(?cmd)]:_"}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1867
          val pat1 = term_of @{cpat "?cmd::tpg"}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1868
          val env = match ctxt pat code
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1869
      in inst env pat1 end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1870
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1871
  fun is_seq_term (Const (@{const_name TSeq}, _) $ _ $ _) = true
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1872
    | is_seq_term _ = false
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1873
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1874
  fun get_hcmd  (Const (@{const_name TSeq}, _) $ hcmd $ _) = hcmd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1875
    | get_hcmd hcmd = hcmd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1876
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1877
  fun last [a]  = a |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1878
      last (a::b) = last b
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1879
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1880
  fun but_last [a] = [] |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1881
      but_last (a::b) = a::(but_last b)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1882
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1883
  fun foldr f [] = (fn x => x) |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1884
      foldr f (x :: xs) = (f x) o  (foldr f xs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1885
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1886
  fun concat [] = [] |
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1887
      concat (x :: xs) = x @ concat xs
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1888
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1889
  fun match_any ctxt pats tm = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1890
              fold 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1891
                 (fn pat => fn b => (b orelse Pattern.matches 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1892
                          (ctxt |> Proof_Context.theory_of) (pat, tm))) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1893
                 pats false
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1894
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1895
  fun is_ps_term (Const (@{const_name ps}, _) $ _) = true
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1896
    | is_ps_term _ = false
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1897
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1898
  fun string_of_term ctxt t = t |> Syntax.pretty_term ctxt |> Pretty.str_of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1899
  fun string_of_cterm ctxt ct = ct |> term_of |> string_of_term ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1900
  fun pterm ctxt t =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1901
          t |> string_of_term ctxt |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1902
  fun pcterm ctxt ct = ct |> string_of_cterm ctxt |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1903
  fun string_for_term ctxt t =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1904
       Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1905
                   (print_mode_value ())) (Syntax.string_of_term ctxt) t
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1906
         |> String.translate (fn c => if Char.isPrint c then str c else "")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1907
         |> Sledgehammer_Util.simplify_spaces  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1908
  fun string_for_cterm ctxt ct = ct |> term_of |> string_for_term ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1909
  fun attemp tac = fn i => fn st => (tac i st) handle exn => Seq.empty
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1910
  fun try_tac tac = fn i => fn st => (tac i st) handle exn => (Seq.single st)       
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1911
 (* aux end *) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1912
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1913
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1914
ML {* (* Functions specific to Hoare triples *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1915
  fun get_pre ctxt t = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1916
    let val pat = term_of @{cpat "\<lbrace>?P\<rbrace> ?c \<lbrace>?Q\<rbrace>"} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1917
        val env = match ctxt pat t 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1918
    in inst env (term_of @{cpat "?P::tresource set \<Rightarrow> bool"}) end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1919
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1920
  fun can_process ctxt t = ((get_pre ctxt t; true) handle _ => false)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1921
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1922
  fun get_post ctxt t = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1923
    let val pat = term_of @{cpat "\<lbrace>?P\<rbrace> ?c \<lbrace>?Q\<rbrace>"} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1924
        val env = match ctxt pat t 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1925
    in inst env (term_of @{cpat "?Q::tresource set \<Rightarrow> bool"}) end;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1926
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1927
  fun get_mid ctxt t = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1928
    let val pat = term_of @{cpat "\<lbrace>?P\<rbrace> ?c \<lbrace>?Q\<rbrace>"} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1929
        val env = match ctxt pat t 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1930
    in inst env (term_of @{cpat "?c::tresource set \<Rightarrow> bool"}) end;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1931
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1932
  fun is_pc_term (Const (@{const_name st}, _) $ _) = true
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1933
    | is_pc_term _ = false
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1934
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1935
  fun mk_pc_term x =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1936
     Const (@{const_name st}, @{typ "nat \<Rightarrow> tresource set \<Rightarrow> bool"}) $ Free (x, @{typ "nat"})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1937
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1938
  val sconj_term = term_of @{cterm "sep_conj::tassert \<Rightarrow> tassert \<Rightarrow> tassert"}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1939
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1940
  fun mk_ps_term x =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1941
     Const (@{const_name ps}, @{typ "int \<Rightarrow> tresource set \<Rightarrow> bool"}) $ Free (x, @{typ "int"})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1942
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1943
  fun atomic tac  = ((SOLVED' tac) ORELSE' (K all_tac))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1944
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1945
  fun map_simpset f = Context.proof_map (Simplifier.map_ss f)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1946
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1947
  fun pure_sep_conj_ac_tac ctxt = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1948
         (auto_tac (map_simpset (fn ss => ss addsimps @{thms sep_conj_ac}) ctxt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1949
          |> SELECT_GOAL)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1950
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1951
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1952
  fun potential_facts ctxt prop = Facts.could_unify (Proof_Context.facts_of ctxt) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1953
                                       ((Term.strip_all_body prop) |> Logic.strip_imp_concl);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1954
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1955
  fun some_fact_tac ctxt = SUBGOAL (fn (goal, i) => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1956
                                      (Method.insert_tac (potential_facts ctxt goal) i) THEN
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1957
                                      (pure_sep_conj_ac_tac ctxt i));
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1958
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1959
  fun sep_conj_ac_tac ctxt = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1960
     (SOLVED' (auto_tac (ctxt |> map_simpset (fn ss => ss addsimps @{thms sep_conj_ac}))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1961
       |> SELECT_GOAL)) ORELSE' (atomic (some_fact_tac ctxt))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1962
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1963
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1964
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1965
type HoareTriple = {
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1966
  binding: binding,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1967
  can_process: Proof.context -> term -> bool,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1968
  get_pre: Proof.context -> term -> term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1969
  get_mid: Proof.context -> term -> term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1970
  get_post: Proof.context -> term -> term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1971
  is_pc_term: term -> bool,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1972
  mk_pc_term: string -> term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1973
  sconj_term: term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1974
  sep_conj_ac_tac: Proof.context -> int -> tactic,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1975
  hoare_seq1: thm,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1976
  hoare_seq2: thm,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1977
  pre_stren: thm,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1978
  post_weaken: thm,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1979
  frame_rule: thm
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1980
}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1981
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1982
  val tm_triple = {binding = @{binding "tm_triple"}, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1983
                   can_process = can_process,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1984
                   get_pre = get_pre,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1985
                   get_mid = get_mid,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1986
                   get_post = get_post,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1987
                   is_pc_term = is_pc_term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1988
                   mk_pc_term = mk_pc_term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1989
                   sconj_term = sconj_term,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1990
                   sep_conj_ac_tac = sep_conj_ac_tac,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1991
                   hoare_seq1 = @{thm t_hoare_seq1},
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1992
                   hoare_seq2 = @{thm t_hoare_seq2},
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1993
                   pre_stren = @{thm tm.pre_stren},
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1994
                   post_weaken = @{thm tm.post_weaken},
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1995
                   frame_rule = @{thm tm.frame_rule}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1996
                  }:HoareTriple
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1997
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1998
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1999
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2000
  val _ = data_slot "HoareTriples" "HoareTriple list" "[]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2001
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2002
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2003
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2004
  val _ = HoareTriples_store [tm_triple]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2005
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2006
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2007
ML {* (* aux1 functions *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2008
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2009
fun focus_params t ctxt =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2010
  let
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2011
    val (xs, Ts) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2012
      split_list (Term.variant_frees t (Term.strip_all_vars t));  (*as they are printed :-*)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2013
    (* val (xs', ctxt') = variant_fixes xs ctxt; *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2014
    (* val ps = xs' ~~ Ts; *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2015
    val ps = xs ~~ Ts
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2016
    val (_, ctxt'') = ctxt |> Variable.add_fixes xs
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2017
  in ((xs, ps), ctxt'') end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2018
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2019
fun focus_concl ctxt t =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2020
  let
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2021
    val ((xs, ps), ctxt') = focus_params t ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2022
    val t' = Term.subst_bounds (rev (map Free ps), Term.strip_all_body t);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2023
  in (t' |> Logic.strip_imp_concl, ctxt') end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2024
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2025
  fun get_concl ctxt (i, state) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2026
              nth (Thm.prems_of state) (i - 1) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2027
                            |> focus_concl ctxt |> (fn (x, _) => x |> HOLogic.dest_Trueprop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2028
 (* aux1 end *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2029
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2030
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2031
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2032
  fun indexing xs = upto (0, length xs - 1) ~~ xs
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2033
  fun select_idxs idxs ps = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2034
      map_index (fn (i, e) => if (member (op =) idxs i) then [e] else []) ps |> flat
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2035
  fun select_out_idxs idxs ps = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2036
      map_index (fn (i, e) => if (member (op =) idxs i) then [] else [e]) ps |> flat
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2037
  fun match_pres ctxt mf env ps qs = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2038
      let  fun sel_match mf env [] qs = [(env, [])]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2039
             | sel_match mf env (p::ps) qs = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2040
                  let val pm = map (fn (i, q) => [(i, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2041
                                      let val _ = tracing ctxt "Matching:"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2042
                                          val _ = [p, q] |>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2043
                                            (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2044
                                          val r = mf p q env 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2045
                                      in r end)]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2046
                                      handle _ => (
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2047
                                      let val _ = tracing ctxt "Failed matching:"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2048
                                          val _ = [p, q] |>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2049
                                            (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2050
                                      in [] end)) qs |> flat
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2051
                      val r = pm |> map (fn (i, env') => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2052
                                let val qs' = filter_out (fn (j, q) => j = i) qs
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2053
                                in  sel_match mf env' ps qs' |> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2054
                                      map (fn (env'', idxs) => (env'', i::idxs)) end) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2055
                        |> flat
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2056
            in r end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2057
   in sel_match mf env ps (indexing qs) end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2058
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2059
  fun provable tac ctxt goal = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2060
          let 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2061
              val _ = tracing ctxt "Provable trying to prove:"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2062
              val _ = [goal] |> (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2063
          in
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2064
             (Goal.prove ctxt [] [] goal (fn {context, ...} => tac context 1); true)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2065
                        handle exn => false
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2066
          end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2067
  fun make_sense tac ctxt thm_assms env  = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2068
                thm_assms |>  map (inst env) |> forall (provable tac ctxt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2069
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2070
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2071
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2072
  fun triple_for ctxt goal = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2073
    filter (fn trpl => (#can_process trpl) ctxt goal) (HoareTriples.get (Proof_Context.theory_of ctxt)) |> hd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2074
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2075
  fun step_terms_for thm goal ctxt = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2076
    let
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2077
       val _ = tracing ctxt "This is the new version of step_terms_for!"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2078
       val _ = tracing ctxt "Tring to find triple processor: TP"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2079
       val TP = triple_for ctxt goal
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2080
       val _ = #binding TP |> Binding.name_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2081
       fun mk_sep_conj tms = foldr (fn tm => fn rtm => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2082
              ((#sconj_term TP)$tm$rtm)) (but_last tms) (last tms)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2083
       val thm_concl = thm |> prop_of 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2084
                 |> Logic.strip_imp_concl |> HOLogic.dest_Trueprop 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2085
       val thm_assms = thm |> prop_of 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2086
           |> Logic.strip_imp_prems 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2087
       val cmd_pat = thm_concl |> #get_mid TP ctxt |> get_cmd ctxt 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2088
       val cmd = goal |> #get_mid TP ctxt |> get_cmd ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2089
       val _ = tracing ctxt "matching command ... "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2090
       val _ = tracing ctxt "cmd_pat = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2091
       val _ = pterm ctxt cmd_pat
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2092
       val (hcmd, env1, is_last) =  (cmd, match ctxt cmd_pat cmd, true)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2093
             handle exn => (cmd |> get_hcmd, match ctxt cmd_pat (cmd |> get_hcmd), false)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2094
       val _ = tracing ctxt "hcmd ="
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2095
       val _ = pterm ctxt hcmd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2096
       val _ = tracing ctxt "match command succeed! "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2097
       val _ = tracing ctxt "pres ="
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2098
       val pres = goal |> #get_pre TP ctxt |> break_sep_conj 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2099
       val _ = pres |> (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2100
       val _ = tracing ctxt "pre_pats ="
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2101
       val pre_pats = thm_concl |> #get_pre TP ctxt |> inst env1 |> break_sep_conj
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2102
       val _ = pre_pats |> (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2103
       val _ = tracing ctxt "post_pats ="
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2104
       val post_pats = thm_concl |> #get_post TP ctxt |> inst env1 |> break_sep_conj
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2105
       val _ = post_pats |> (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2106
       val _ = tracing ctxt "Calculating sols"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2107
       val sols = match_pres ctxt (match_env ctxt) env1 pre_pats pres 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2108
       val _ = tracing ctxt "End calculating sols, sols ="
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2109
       val _ = tracing ctxt (@{make_string} sols)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2110
       val _ = tracing ctxt "Calulating env2 and idxs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2111
       val (env2, idxs) = filter (fn (env, idxs) => make_sense (#sep_conj_ac_tac TP) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2112
                             ctxt thm_assms env) sols |> hd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2113
       val _ = tracing ctxt "End calculating env2 and idxs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2114
       val _ = tracing ctxt "mterms ="
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2115
       val mterms = select_idxs idxs pres |> map (inst env2) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2116
       val _ = mterms |> (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2117
       val _ = tracing ctxt "nmterms = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2118
       val nmterms = select_out_idxs idxs pres |> map (inst env2) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2119
       val _ = nmterms |> (pretty_terms ctxt) |> Pretty.str_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2120
       val pre_cond = pre_pats |> map (inst env2) |> mk_sep_conj
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2121
       val post_cond = post_pats |> map (inst env2) |> mk_sep_conj 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2122
       val post_cond_npc  = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2123
               post_cond |> break_sep_conj |> filter (not_pred (#is_pc_term TP)) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2124
               |> (fn x => x @ nmterms) |> mk_sep_conj |> cterm_of (Proof_Context.theory_of ctxt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2125
       fun mk_frame cond rest  = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2126
             if rest = [] then cond else ((#sconj_term TP)$ cond) $ (mk_sep_conj rest)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2127
       val pre_cond_frame = mk_frame pre_cond nmterms |> cterm_of (Proof_Context.theory_of ctxt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2128
       fun post_cond_frame j' = post_cond |> break_sep_conj |> filter (not_pred (#is_pc_term TP)) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2129
               |> (fn x => [#mk_pc_term TP j']@x) |> mk_sep_conj
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2130
               |> (fn x => mk_frame x nmterms)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2131
               |> cterm_of (Proof_Context.theory_of ctxt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2132
       val need_frame = (nmterms <> [])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2133
    in 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2134
         (post_cond_npc,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2135
          pre_cond_frame, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2136
          post_cond_frame, need_frame, is_last)       
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2137
    end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2138
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2139
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2140
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2141
  fun step_tac ctxt thm i state = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2142
     let  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2143
       val _ = tracing ctxt "This is the new version of step_tac"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2144
       val (goal, ctxt) = nth (Thm.prems_of state) (i - 1) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2145
                  |> focus_concl ctxt 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2146
                  |> (apfst HOLogic.dest_Trueprop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2147
       val _ = tracing ctxt "step_tac: goal = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2148
       val _ = goal |> pterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2149
       val _ = tracing ctxt "Start to calculate intermediate terms ... "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2150
       val (post_cond_npc, pre_cond_frame, post_cond_frame, need_frame, is_last) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2151
                        = step_terms_for thm goal ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2152
       val _ = tracing ctxt "Tring to find triple processor: TP"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2153
       val TP = triple_for ctxt goal
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2154
       val _ = #binding TP |> Binding.name_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2155
       fun mk_sep_conj tms = foldr (fn tm => fn rtm => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2156
              ((#sconj_term TP)$tm$rtm)) (but_last tms) (last tms)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2157
       val _ = tracing ctxt "Calculate intermediate terms finished! "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2158
       val post_cond_npc_str = post_cond_npc |> string_for_cterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2159
       val pre_cond_frame_str = pre_cond_frame |> string_for_cterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2160
       val _ = tracing ctxt "step_tac: post_cond_npc = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2161
       val _ = post_cond_npc |> pcterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2162
       val _ = tracing ctxt "step_tac: pre_cond_frame = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2163
       val _ = pre_cond_frame |> pcterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2164
       fun tac1 i state = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2165
             if is_last then (K all_tac) i state else
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2166
              res_inst_tac ctxt [(("q", 0), post_cond_npc_str)] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2167
                                          (#hoare_seq1 TP) i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2168
       fun tac2 i state = res_inst_tac ctxt [(("p", 0), pre_cond_frame_str)] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2169
                                          (#pre_stren TP) i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2170
       fun foc_tac post_cond_frame ctxt i state  =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2171
           let
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2172
               val goal = get_concl ctxt (i, state)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2173
               val pc_term = goal |> #get_post TP ctxt |> break_sep_conj 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2174
                                |> filter (#is_pc_term TP) |> hd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2175
               val (_$Free(j', _)) = pc_term
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2176
               val psd = post_cond_frame j'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2177
               val str_psd = psd |> string_for_cterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2178
               val _ = tracing ctxt "foc_tac: psd = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2179
               val _ = psd |> pcterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2180
           in 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2181
               res_inst_tac ctxt [(("q", 0), str_psd)] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2182
                                          (#post_weaken TP) i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2183
           end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2184
     val frame_tac = if need_frame then (rtac (#frame_rule TP)) else (K all_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2185
     val print_tac = if (Config.get ctxt trace_step) then Tactical.print_tac else (K all_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2186
     val tac = (tac1 THEN' (K (print_tac "tac1 success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2187
               (tac2 THEN' (K (print_tac "tac2 success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2188
               ((foc_tac post_cond_frame ctxt) THEN' (K (print_tac "foc_tac success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2189
               (frame_tac  THEN' (K (print_tac "frame_tac success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2190
               (((rtac thm) THEN_ALL_NEW (#sep_conj_ac_tac TP ctxt)) THEN' (K (print_tac "rtac thm success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2191
               (K (ALLGOALS (atomic (#sep_conj_ac_tac TP ctxt)))) THEN'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2192
               (* (#sep_conj_ac_tac TP ctxt) THEN' (#sep_conj_ac_tac TP ctxt) THEN'  *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2193
               (K prune_params_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2194
   in 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2195
        tac i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2196
   end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2197
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2198
  fun unfold_cell_tac ctxt = (Local_Defs.unfold_tac ctxt @{thms one_def zero_def})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2199
  fun fold_cell_tac ctxt = (Local_Defs.fold_tac ctxt @{thms one_def zero_def})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2200
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2201
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2202
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2203
  fun sg_step_tac thms ctxt =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2204
     let val sg_step_tac' =  (map (fn thm  => attemp (step_tac ctxt thm)) thms)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2205
                               (* @ [attemp (goto_tac ctxt)]  *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2206
                              |> FIRST'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2207
         val sg_step_tac'' = (K (unfold_cell_tac ctxt)) THEN' sg_step_tac' THEN' (K (fold_cell_tac ctxt))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2208
     in
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2209
         sg_step_tac' ORELSE' sg_step_tac''
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2210
     end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2211
  fun steps_tac thms ctxt i = REPEAT (sg_step_tac thms ctxt i) THEN (prune_params_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2212
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2213
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2214
method_setup hstep = {* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2215
  Attrib.thms >> (fn thms => fn ctxt =>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2216
                    (SIMPLE_METHOD' (fn i => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2217
                       sg_step_tac (thms@(StepRules.get ctxt)) ctxt i)))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2218
  *} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2219
  "One step symbolic execution using step theorems."
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2220
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2221
method_setup hsteps = {* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2222
  Attrib.thms >> (fn thms => fn ctxt =>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2223
                    (SIMPLE_METHOD' (fn i => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2224
                       steps_tac (thms@(StepRules.get ctxt)) ctxt i)))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2225
  *} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2226
  "Sequential symbolic execution using step theorems."
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2227
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2228
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2229
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2230
  fun goto_tac ctxt thm i state = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2231
     let  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2232
       val (goal, ctxt) = nth (Thm.prems_of state) (i - 1) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2233
                             |> focus_concl ctxt |> (apfst HOLogic.dest_Trueprop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2234
       val _ = tracing ctxt "goto_tac: goal = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2235
       val _ = goal |> string_of_term ctxt |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2236
       val (post_cond_npc, pre_cond_frame, post_cond_frame, need_frame, is_last) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2237
                        = step_terms_for thm goal ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2238
       val _ = tracing ctxt "Tring to find triple processor: TP"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2239
       val TP = triple_for ctxt goal
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2240
       val _ = #binding TP |> Binding.name_of |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2241
       val _ = tracing ctxt "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2242
       val post_cond_npc_str = post_cond_npc |> string_for_cterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2243
       val pre_cond_frame_str = pre_cond_frame |> string_for_cterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2244
       val _ = tracing ctxt "goto_tac: post_cond_npc = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2245
       val _ = post_cond_npc_str |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2246
       val _ = tracing ctxt "goto_tac: pre_cond_frame = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2247
       val _ = pre_cond_frame_str |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2248
       fun tac1 i state = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2249
             if is_last then (K all_tac) i state else
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2250
              res_inst_tac ctxt [] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2251
                                          (#hoare_seq2 TP) i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2252
       fun tac2 i state = res_inst_tac ctxt [(("p", 0), pre_cond_frame_str)] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2253
                                          (#pre_stren TP) i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2254
       fun foc_tac post_cond_frame ctxt i state  =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2255
           let
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2256
               val goal = get_concl ctxt (i, state)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2257
               val pc_term = goal |> #get_post TP ctxt |> break_sep_conj 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2258
                                |> filter (#is_pc_term TP) |> hd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2259
               val (_$Free(j', _)) = pc_term
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2260
               val psd = post_cond_frame j'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2261
               val str_psd = psd |> string_for_cterm ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2262
               val _ = tracing ctxt "goto_tac: psd = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2263
               val _ = str_psd |> tracing ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2264
           in 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2265
               res_inst_tac ctxt [(("q", 0), str_psd)] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2266
                                          (#post_weaken TP) i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2267
           end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2268
     val frame_tac = if need_frame then (rtac (#frame_rule TP)) else (K all_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2269
     val _ = tracing ctxt "goto_tac: starting to apply tacs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2270
     val print_tac = if (Config.get ctxt trace_step) then Tactical.print_tac else (K all_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2271
     val tac = (tac1 THEN' (K (print_tac "tac1 success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2272
               (tac2 THEN' (K (print_tac "tac2 success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2273
               ((foc_tac post_cond_frame ctxt) THEN' (K (print_tac "foc_tac success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2274
               (frame_tac THEN' (K (print_tac "frame_tac success"))) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2275
               ((((rtac thm) THEN_ALL_NEW (#sep_conj_ac_tac TP ctxt))) THEN'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2276
                 (K (print_tac "rtac success"))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2277
               ) THEN' 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2278
               (K (ALLGOALS (atomic (#sep_conj_ac_tac TP ctxt)))) THEN'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2279
               (K prune_params_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2280
   in 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2281
        tac i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2282
   end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2283
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2284
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2285
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2286
  fun sg_goto_tac thms ctxt =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2287
     let val sg_goto_tac' =  (map (fn thm  => attemp (goto_tac ctxt thm)) thms)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2288
                              |> FIRST'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2289
         val sg_goto_tac'' = (K (unfold_cell_tac ctxt)) THEN' sg_goto_tac' THEN' (K (fold_cell_tac ctxt))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2290
     in
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2291
         sg_goto_tac' ORELSE' sg_goto_tac''
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2292
     end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2293
  fun gotos_tac thms ctxt i = REPEAT (sg_goto_tac thms ctxt i) THEN (prune_params_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2294
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2295
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2296
method_setup hgoto = {* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2297
  Attrib.thms >> (fn thms => fn ctxt =>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2298
                    (SIMPLE_METHOD' (fn i => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2299
                       sg_goto_tac (thms@(StepRules.get ctxt)) ctxt i)))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2300
  *} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2301
  "One step symbolic execution using goto theorems."
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2302
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2303
subsection {* Tactic for forward reasoning *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2304
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2305
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2306
fun mk_msel_rule ctxt conclusion idx term =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2307
let 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2308
  val cjt_count = term |> break_sep_conj |> length
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2309
  fun variants nctxt names = fold_map Name.variant names nctxt;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2310
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2311
  val (state, nctxt0) = Name.variant "s" (Variable.names_of ctxt);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2312
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2313
  fun sep_conj_prop cjts =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2314
        FunApp.fun_app_free
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2315
          (FunApp.fun_app_foldr SepConj.sep_conj_term cjts) state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2316
        |> HOLogic.mk_Trueprop;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2317
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2318
  (* concatenate string and string of an int *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2319
  fun conc_str_int str int = str ^ Int.toString int;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2320
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2321
  (* make the conjunct names *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2322
  val (cjts, _) = ListExtra.range 1 cjt_count
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2323
                  |> map (conc_str_int "a") |> variants nctxt0;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2324
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2325
 fun skel_sep_conj names (Const (@{const_name sep_conj}, _) $ t1 $ t2 $ y) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2326
     (let val nm1 = take (length (break_sep_conj t1)) names 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2327
          val nm2 = drop (length (break_sep_conj t1)) names
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2328
          val t1' = skel_sep_conj nm1 t1 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2329
          val t2' = skel_sep_conj nm2 t2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2330
      in (SepConj.sep_conj_term $ t1' $ t2' $ y) end)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2331
  | skel_sep_conj names (Const (@{const_name sep_conj}, _) $ t1 $ t2) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2332
     (let val nm1 = take (length (break_sep_conj t1)) names 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2333
          val nm2 = drop (length (break_sep_conj t1)) names
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2334
          val t1' = skel_sep_conj nm1 t1 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2335
          val t2' = skel_sep_conj nm2 t2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2336
     in (SepConj.sep_conj_term $ t1' $ t2') end)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2337
   | skel_sep_conj names (Abs (x, y, t $ Bound 0)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2338
                  let val t' = (skel_sep_conj names t) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2339
                      val ty' = t' |> type_of |> domain_type
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2340
                  in (Abs (x, ty', (t' $ Bound 0))) end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2341
  | skel_sep_conj names t = Free (hd names, SepConj.sep_conj_term |> type_of |> domain_type);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2342
  val _ = tracing ctxt "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2343
  val oskel = skel_sep_conj cjts term;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2344
  val _ = tracing ctxt "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2345
  val ttt = oskel |> type_of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2346
  val _ = tracing ctxt "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2347
  val orig = FunApp.fun_app_free oskel state |> HOLogic.mk_Trueprop
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2348
  val _ = tracing ctxt "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2349
  val is_selected = member (fn (x, y) => x = y) idx
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2350
  val all_idx = ListExtra.range 0 cjt_count
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2351
  val selected_idx = idx
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2352
  val unselected_idx = filter_out is_selected all_idx
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2353
  val selected = map (nth cjts) selected_idx
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2354
  val unselected = map (nth cjts) unselected_idx
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2355
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2356
  fun fun_app_foldr f [a,b] = FunApp.fun_app_free (FunApp.fun_app_free f a) b
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2357
  | fun_app_foldr f [a] = Free (a, SepConj.sep_conj_term |> type_of |> domain_type)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2358
  | fun_app_foldr f (x::xs) = (FunApp.fun_app_free f x) $ (fun_app_foldr f xs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2359
  | fun_app_foldr _ _ = raise Fail "fun_app_foldr";
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2360
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2361
  val reordered_skel = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2362
      if unselected = [] then (fun_app_foldr SepConj.sep_conj_term selected)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2363
          else (SepConj.sep_conj_term $ (fun_app_foldr SepConj.sep_conj_term selected)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2364
                        $ (fun_app_foldr SepConj.sep_conj_term unselected))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2365
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2366
  val reordered =  FunApp.fun_app_free reordered_skel state  |> HOLogic.mk_Trueprop
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2367
  val goal = Logic.mk_implies
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2368
               (if conclusion then (orig, reordered) else (reordered, orig));
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2369
  val rule =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2370
   Goal.prove ctxt [] [] goal (fn _ => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2371
        auto_tac (ctxt |> map_simpset (fn ss => ss addsimps @{thms sep_conj_ac})))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2372
         |> Drule.export_without_context
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2373
in
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2374
   rule
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2375
end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2376
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2377
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2378
lemma fwd_rule: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2379
  assumes "\<And> s . U s \<longrightarrow> V s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2380
  shows "(U ** RR) s \<Longrightarrow> (V ** RR) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2381
  by (metis assms sep_globalise)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2382
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2383
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2384
  fun sg_sg_fwd_tac ctxt thm pos i state = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2385
  let  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2386
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2387
  val tracing  = (fn str =>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2388
                   if (Config.get ctxt trace_fwd) then Output.tracing str else ())
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2389
  fun pterm t =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2390
          t |> string_of_term ctxt |> tracing
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2391
  fun pcterm ct = ct |> string_of_cterm ctxt |> tracing
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2392
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2393
  fun atm thm = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2394
  let
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2395
  (* val thm = thm |> Drule.forall_intr_vars *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2396
  val res =  thm |> cprop_of |> Object_Logic.atomize
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2397
  val res' = Raw_Simplifier.rewrite_rule [res] thm
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2398
  in res' end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2399
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2400
  fun find_idx ctxt pats terms = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2401
     let val result = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2402
              map (fn pat => (find_index (fn trm => ((match ctxt pat trm; true)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2403
                                              handle _ => false)) terms)) pats
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2404
     in (assert_all (fn x => x >= 0) result (K "match of precondition failed"));
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2405
         result
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2406
     end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2407
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2408
  val goal = nth (Drule.cprems_of state) (i - 1) |> term_of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2409
  val _ = tracing "goal = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2410
  val _ = goal |> pterm
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2411
  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2412
  val ctxt_orig = ctxt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2413
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2414
  val ((ps, goal), ctxt) = Variable.focus goal ctxt_orig
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2415
  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2416
  val prems = goal |> Logic.strip_imp_prems 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2417
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2418
  val cprem = nth prems (pos - 1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2419
  val (_ $ (the_prem $ _)) = cprem
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2420
  val cjts = the_prem |> break_sep_conj
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2421
  val thm_prems = thm |> cprems_of |> hd |> Thm.dest_arg |> Thm.dest_fun
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2422
  val thm_assms = thm |> cprems_of |> tl |> map term_of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2423
  val thm_cjts = thm_prems |> term_of |> break_sep_conj
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2424
  val thm_trm = thm |> prop_of
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2425
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2426
  val _ = tracing "cjts = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2427
  val _ = cjts |> map pterm
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2428
  val _ = tracing "thm_cjts = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2429
  val _ = thm_cjts |> map pterm
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2430
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2431
  val _ = tracing "Calculating sols"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2432
  val sols = match_pres ctxt (match_env ctxt) empty_env thm_cjts cjts
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2433
  val _ = tracing "End calculating sols, sols ="
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2434
  val _ = tracing (@{make_string} sols)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2435
  val _ = tracing "Calulating env2 and idxs"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2436
  val (env2, idx) = filter (fn (env, idxs) => make_sense sep_conj_ac_tac ctxt thm_assms env) sols |> hd
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2437
  val ([thm'_trm], ctxt') = thm_trm |> inst env2 |> single 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2438
                            |> (fn trms => Variable.import_terms true trms ctxt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2439
  val thm'_prem  = Logic.strip_imp_prems thm'_trm |> hd 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2440
  val thm'_concl = Logic.strip_imp_concl thm'_trm 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2441
  val thm'_prem = (Goal.prove ctxt' [] [thm'_prem] thm'_concl 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2442
                  (fn {context, prems = [prem]} =>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2443
                      (rtac (prem RS thm)  THEN_ALL_NEW (sep_conj_ac_tac ctxt)) 1))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2444
  val [thm'] = Variable.export ctxt' ctxt_orig [thm'_prem]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2445
  val trans_rule = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2446
       mk_msel_rule ctxt true idx the_prem
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2447
  val _ = tracing "trans_rule = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2448
  val _ = trans_rule |> cprop_of |> pcterm
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2449
  val app_rule = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2450
      if (length cjts = length thm_cjts) then thm' else
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2451
       ((thm' |> atm) RS @{thm fwd_rule})
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2452
  val _ = tracing "app_rule = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2453
  val _ = app_rule |> cprop_of |> pcterm
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2454
  val print_tac = if (Config.get ctxt trace_fwd) then Tactical.print_tac else (K all_tac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2455
  val the_tac = (dtac trans_rule THEN' (K (print_tac "dtac1 success"))) THEN'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2456
                ((dtac app_rule THEN' (K (print_tac "dtac2 success"))))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2457
in
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2458
  (the_tac i state) handle _ => no_tac state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2459
end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2460
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2461
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2462
ML {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2463
  fun sg_fwd_tac ctxt thm i state = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2464
  let  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2465
    val goal = nth (Drule.cprems_of state) (i - 1)          
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2466
    val prems = goal |> term_of |> Term.strip_all_body |> Logic.strip_imp_prems 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2467
    val posx = ListExtra.range 1 (length prems)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2468
  in
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2469
      ((map (fn pos => attemp (sg_sg_fwd_tac ctxt thm pos)) posx) |> FIRST') i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2470
  end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2471
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2472
  fun fwd_tac ctxt thms i state =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2473
       ((map (fn thm => sg_fwd_tac ctxt thm) thms) |> FIRST') i state
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2474
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2475
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2476
method_setup fwd = {* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2477
  Attrib.thms >> (fn thms => fn ctxt =>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2478
                    (SIMPLE_METHOD' (fn i => 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2479
                       fwd_tac ctxt (thms@(FwdRules.get ctxt))  i)))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2480
  *} 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2481
  "Forward derivation of separation implication"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2482
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2483
text {* Testing the fwd tactic *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2484
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2485
lemma ones_abs:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2486
  assumes "(ones u v \<and>* ones w x) s" "w = v + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2487
  shows "ones u x s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2488
  using assms(1) unfolding assms(2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2489
proof(induct u v arbitrary: x s rule:ones_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2490
  case (Base i j x s)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2491
  thus ?case by (auto elim!:condE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2492
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2493
  case (Step i j x s)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2494
  hence h: "\<And> x s. (ones (i + 1) j \<and>* ones (j + 1) x) s \<longrightarrow> ones (i + 1) x s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2495
    by metis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2496
  hence "(ones (i + 1) x \<and>* one i) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2497
    by (rule fwd_rule, insert Step(3), auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2498
  thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2499
    by (smt condD ones.simps sep_conj_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2500
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2501
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2502
lemma one_abs: "(one m) s \<Longrightarrow> (ones m m) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2503
 by (smt cond_true_eq2 ones.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2504
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2505
lemma ones_reps_abs: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2506
  assumes "ones m n s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2507
          "m \<le> n"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2508
  shows "(reps m n [nat (n - m)]) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2509
  using assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2510
  by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2511
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2512
lemma reps_reps'_abs: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2513
  assumes "(reps m n xs \<and>* zero u) s" "u = n + 1" "xs \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2514
  shows "(reps' m u xs) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2515
  unfolding assms using assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2516
  by (unfold reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2517
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2518
lemma reps'_abs:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2519
  assumes "(reps' m n xs \<and>* reps' u v ys) s" "u = n + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2520
  shows "(reps' m v (xs @ ys)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2521
  apply (unfold reps'_append, rule_tac x = u in EXS_intro)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2522
  by (insert assms, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2523
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2524
lemmas abs_ones = one_abs ones_abs
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2525
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2526
lemmas abs_reps' = ones_reps_abs reps_reps'_abs reps'_abs
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2527
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2528
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2529
section {* Modular TM programming and verification *}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2530
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2531
definition "right_until_zero = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2532
                 (TL start exit. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2533
                  TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2534
                     if_zero exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2535
                     move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2536
                     jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2537
                  TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2538
                 )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2539
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2540
lemma ones_false [simp]: "j < i - 1 \<Longrightarrow> (ones i j) = sep_false"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2541
  by (simp add:pasrt_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2542
  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2543
lemma hoare_right_until_zero: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2544
  "\<lbrace>st i ** ps u ** ones u (v - 1) ** zero v \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2545
     i:[right_until_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2546
   \<lbrace>st j ** ps v ** ones u (v - 1) ** zero v \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2547
proof(unfold right_until_zero_def, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2548
      intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2549
      rule t_hoare_label_last, simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2550
  fix la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2551
  let ?body = "i :[ (if_zero la ; move_right ; jmp i) ]: la"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2552
  let ?j = la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2553
  show "\<lbrace>st i \<and>* ps u \<and>* ones u (v - 1) \<and>* zero v\<rbrace>  ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2554
        \<lbrace>st ?j \<and>* ps v \<and>* ones u (v - 1) \<and>* zero v\<rbrace>" (is "?P u (v - 1) (ones u (v - 1))")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2555
  proof(induct "u" "v - 1" rule:ones_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2556
    case (Base k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2557
    moreover have "\<lbrace>st i \<and>* ps v \<and>* zero v\<rbrace> ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2558
                   \<lbrace>st ?j \<and>* ps v \<and>* zero v\<rbrace>" by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2559
    ultimately show ?case by (auto intro!:tm.pre_condI simp:sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2560
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2561
    case (Step k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2562
    moreover have "\<lbrace>st i \<and>* ps k \<and>* (one k \<and>* ones (k + 1) (v - 1)) \<and>* zero v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2563
                     i :[ (if_zero ?j ; move_right ; jmp i) ]: ?j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2564
                   \<lbrace>st ?j \<and>* ps v \<and>* (one k \<and>* ones (k + 1) (v - 1)) \<and>* zero v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2565
    proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2566
      have s1: "\<lbrace>st i \<and>* ps k \<and>* (one k \<and>* ones (k + 1) (v - 1)) \<and>* zero v\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2567
                          ?body 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2568
                \<lbrace>st i \<and>* ps (k + 1) \<and>* one k \<and>* ones (k + 1) (v - 1) \<and>* zero v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2569
      proof(cases "k + 1 \<ge> v")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2570
        case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2571
        with Step(1) have "v = k + 1" by arith
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2572
        thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2573
          apply(simp add: one_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2574
          by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2575
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2576
        case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2577
        hence eq_ones: "ones (k + 1) (v - 1) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2578
                         (one (k + 1) \<and>* ones ((k + 1) + 1) (v - 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2579
          by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2580
        show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2581
          apply(simp only: eq_ones)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2582
          by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2583
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2584
      note Step(2)[step]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2585
      have s2: "\<lbrace>st i \<and>* ps (k + 1) \<and>* one k \<and>* ones (k + 1) (v - 1) \<and>* zero v\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2586
                        ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2587
                \<lbrace>st ?j \<and>* ps v \<and>* one k \<and>* ones (k + 1) (v - 1) \<and>* zero v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2588
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2589
      from tm.sequencing [OF s1 s2, step] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2590
      show ?thesis 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2591
        by (auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2592
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2593
    ultimately show ?case by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2594
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2595
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2596
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2597
lemma hoare_right_until_zero_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2598
  assumes "u = v" "w = x - 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2599
  shows  "\<lbrace>st i ** ps u ** ones v w ** zero x \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2600
              i:[right_until_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2601
          \<lbrace>st j ** ps x ** ones v w ** zero x \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2602
  by (unfold assms, rule hoare_right_until_zero)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2603
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2604
definition "left_until_zero = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2605
                 (TL start exit. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2606
                  TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2607
                    if_zero exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2608
                    move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2609
                    jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2610
                  TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2611
                 )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2612
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2613
lemma hoare_left_until_zero: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2614
  "\<lbrace>st i ** ps v ** zero u ** ones (u + 1) v \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2615
     i:[left_until_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2616
   \<lbrace>st j ** ps u ** zero u ** ones (u + 1) v \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2617
proof(unfold left_until_zero_def, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2618
      intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2619
      rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2620
  fix la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2621
  let ?body = "i :[ (if_zero la ; move_left ; jmp i) ]: la"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2622
  let ?j = la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2623
  show "\<lbrace>st i \<and>* ps v \<and>* zero u \<and>* ones (u + 1) v\<rbrace> ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2624
        \<lbrace>st ?j \<and>* ps u \<and>* zero u \<and>* ones (u + 1) v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2625
  proof(induct "u+1" v  rule:ones_rev_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2626
    case (Base k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2627
    thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2628
      by (simp add:sep_conj_cond, intro tm.pre_condI, simp, hstep)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2629
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2630
    case (Step k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2631
    have "\<lbrace>st i \<and>* ps k \<and>* zero u \<and>* ones (u + 1) (k - 1) \<and>* one k\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2632
               ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2633
          \<lbrace>st ?j \<and>* ps u \<and>* zero u \<and>* ones (u + 1) (k - 1) \<and>* one k\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2634
    proof(rule tm.sequencing[where q = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2635
           "st i \<and>* ps (k - 1) \<and>* zero u \<and>* ones (u + 1) (k - 1) \<and>* one k"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2636
      show "\<lbrace>st i \<and>* ps k \<and>* zero u \<and>* ones (u + 1) (k - 1) \<and>* one k\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2637
                ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2638
            \<lbrace>st i \<and>* ps (k - 1) \<and>* zero u \<and>* ones (u + 1) (k - 1) \<and>* one k\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2639
      proof(induct "u + 1" "k - 1" rule:ones_rev_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2640
        case Base with Step(1) have "k = u + 1" by arith
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2641
        thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2642
          by (simp, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2643
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2644
        case Step
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2645
        show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2646
          apply (unfold ones_rev[OF Step(1)], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2647
          apply (unfold one_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2648
          by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2649
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2650
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2651
      note Step(2) [step]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2652
      show "\<lbrace>st i \<and>* ps (k - 1) \<and>* zero u \<and>* ones (u + 1) (k - 1) \<and>* one k\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2653
                ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2654
            \<lbrace>st ?j \<and>* ps u \<and>* zero u \<and>* ones (u + 1) (k - 1) \<and>* one k\<rbrace>" by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2655
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2656
    thus ?case by (unfold ones_rev[OF Step(1)], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2657
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2658
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2659
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2660
lemma hoare_left_until_zero_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2661
  assumes "u = x" "w = v + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2662
  shows  "\<lbrace>st i ** ps u ** zero v ** ones w x \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2663
               i:[left_until_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2664
          \<lbrace>st j ** ps v ** zero v ** ones w x \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2665
  by (unfold assms, rule hoare_left_until_zero)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2666
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2667
definition "right_until_one = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2668
                 (TL start exit. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2669
                  TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2670
                     if_one exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2671
                     move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2672
                     jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2673
                  TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2674
                 )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2675
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2676
lemma hoare_right_until_one: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2677
  "\<lbrace>st i ** ps u ** zeros u (v - 1) ** one v \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2678
     i:[right_until_one]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2679
   \<lbrace>st j ** ps v ** zeros u (v - 1) ** one v \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2680
proof(unfold right_until_one_def, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2681
      intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2682
      rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2683
  fix la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2684
  let ?body = "i :[ (if_one la ; move_right ; jmp i) ]: la"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2685
  let ?j = la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2686
  show "\<lbrace>st i \<and>* ps u \<and>* zeros u (v - 1) \<and>* one v\<rbrace> ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2687
       \<lbrace>st ?j \<and>* ps v \<and>* zeros u (v - 1) \<and>* one v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2688
  proof(induct u "v - 1" rule:zeros_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2689
    case (Base k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2690
    thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2691
      by (simp add:sep_conj_cond, intro tm.pre_condI, simp, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2692
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2693
    case (Step k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2694
    have "\<lbrace>st i \<and>* ps k \<and>* zero k \<and>* zeros (k + 1) (v - 1) \<and>* one v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2695
            ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2696
          \<lbrace>st ?j \<and>* ps v \<and>* zero k \<and>* zeros (k + 1) (v - 1) \<and>* one v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2697
    proof(rule tm.sequencing[where q = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2698
           "st i \<and>* ps (k + 1) \<and>* zero k \<and>* zeros (k + 1) (v - 1) \<and>* one v"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2699
      show "\<lbrace>st i \<and>* ps k \<and>* zero k \<and>* zeros (k + 1) (v - 1) \<and>* one v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2700
               ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2701
           \<lbrace>st i \<and>* ps (k + 1) \<and>* zero k \<and>* zeros (k + 1) (v - 1) \<and>* one v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2702
      proof(induct "k + 1" "v - 1" rule:zeros_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2703
        case Base
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2704
        with Step(1) have eq_v: "k + 1 = v" by arith
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2705
        from Base show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2706
          apply (simp add:sep_conj_cond, intro tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2707
          apply (hstep, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2708
          by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2709
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2710
        case Step
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2711
        thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2712
          by (simp, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2713
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2714
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2715
      note Step(2)[step]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2716
        show "\<lbrace>st i \<and>* ps (k + 1) \<and>* zero k \<and>* zeros (k + 1) (v - 1) \<and>* one v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2717
                ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2718
              \<lbrace>st ?j \<and>* ps v \<and>* zero k \<and>* zeros (k + 1) (v - 1) \<and>* one v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2719
          by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2720
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2721
    thus ?case by (auto simp: sep_conj_ac Step(1))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2722
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2723
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2724
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2725
lemma hoare_right_until_one_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2726
  assumes "u = v" "w = x - 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2727
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2728
  "\<lbrace>st i ** ps u ** zeros v w ** one x \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2729
     i:[right_until_one]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2730
   \<lbrace>st j **  ps x ** zeros v w ** one x \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2731
  by (unfold assms, rule hoare_right_until_one)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2732
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2733
definition "left_until_one = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2734
                 (TL start exit. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2735
                  TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2736
                    if_one exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2737
                    move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2738
                    jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2739
                  TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2740
                 )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2741
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2742
lemma hoare_left_until_one: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2743
  "\<lbrace>st i ** ps v ** one u ** zeros (u + 1) v \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2744
     i:[left_until_one]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2745
   \<lbrace>st j ** ps u ** one u ** zeros (u + 1) v \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2746
proof(unfold left_until_one_def, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2747
      intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2748
      rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2749
  fix la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2750
  let ?body = "i :[ (if_one la ; move_left ; jmp i) ]: la"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2751
  let ?j = la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2752
  show "\<lbrace>st i \<and>* ps v \<and>* one u \<and>* zeros (u + 1) v\<rbrace> ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2753
        \<lbrace>st ?j \<and>* ps u \<and>* one u \<and>* zeros (u + 1) v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2754
  proof(induct u v rule: ones'.induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2755
    fix ia ja
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2756
    assume h: "\<not> ja < ia \<Longrightarrow>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2757
             \<lbrace>st i \<and>* ps (ja - 1) \<and>* one ia \<and>* zeros (ia + 1) (ja - 1)\<rbrace> ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2758
             \<lbrace>st ?j \<and>* ps ia \<and>* one ia \<and>* zeros (ia + 1) (ja - 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2759
    show "\<lbrace>st i \<and>* ps ja \<and>* one ia \<and>* zeros (ia + 1) ja\<rbrace>  ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2760
      \<lbrace>st ?j \<and>* ps ia \<and>* one ia \<and>* zeros (ia + 1) ja\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2761
    proof(cases "ja < ia")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2762
      case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2763
      note lt = False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2764
      from h[OF this] have [step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2765
        "\<lbrace>st i \<and>* ps (ja - 1) \<and>* one ia \<and>* zeros (ia + 1) (ja - 1)\<rbrace> ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2766
         \<lbrace>st ?j \<and>* ps ia \<and>* one ia \<and>* zeros (ia + 1) (ja - 1)\<rbrace>" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2767
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2768
      proof(cases "ja = ia")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2769
        case True 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2770
        moreover
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2771
        have "\<lbrace>st i \<and>* ps ja \<and>* one ja\<rbrace> ?body \<lbrace>st ?j \<and>* ps ja \<and>* one ja\<rbrace>" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2772
          by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2773
        ultimately show ?thesis by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2774
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2775
        case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2776
        with lt have k1: "ia < ja" by auto       
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2777
        from zeros_rev[of "ja" "ia + 1"] this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2778
        have eq_zeros: "zeros (ia + 1) ja = (zeros (ia + 1) (ja - 1) \<and>* zero ja)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2779
          by simp        
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2780
        have s1: "\<lbrace>st i \<and>* ps ja \<and>* one ia \<and>* zeros (ia + 1) (ja - 1) \<and>* zero ja\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2781
                      ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2782
                  \<lbrace>st i \<and>* ps (ja - 1) \<and>* one ia \<and>* zeros (ia + 1) (ja - 1) \<and>* zero ja\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2783
        proof(cases "ia + 1 \<ge> ja")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2784
          case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2785
          from k1 True have "ja = ia + 1" by arith
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2786
          moreover have "\<lbrace>st i \<and>* ps (ia + 1) \<and>* one (ia + 1 - 1) \<and>* zero (ia + 1)\<rbrace>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2787
            i :[ (if_one ?j ; move_left ; jmp i) ]: ?j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2788
                \<lbrace>st i \<and>* ps (ia + 1 - 1) \<and>* one (ia + 1 - 1) \<and>* zero (ia + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2789
            by (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2790
          ultimately show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2791
            by (simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2792
        next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2793
          case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2794
          from zeros_rev[of "ja - 1" "ia + 1"] False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2795
          have k: "zeros (ia + 1) (ja - 1) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2796
                      (zeros (ia + 1) (ja - 1 - 1) \<and>* zero (ja - 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2797
            by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2798
          show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2799
            apply (unfold k, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2800
            by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2801
        qed      
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2802
        have s2: "\<lbrace>st i \<and>* ps (ja - 1) \<and>* one ia \<and>* zeros (ia + 1) (ja - 1) \<and>* zero ja\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2803
                      ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2804
                  \<lbrace>st ?j \<and>* ps ia \<and>* one ia \<and>* zeros (ia + 1) (ja - 1) \<and>* zero ja\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2805
          by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2806
        from tm.sequencing[OF s1 s2, step]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2807
        show ?thesis 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2808
          apply (unfold eq_zeros)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2809
          by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2810
      qed (* ccc *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2811
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2812
      case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2813
      thus ?thesis by (auto intro:tm.hoare_sep_false)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2814
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2815
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2816
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2817
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2818
lemma hoare_left_until_one_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2819
  assumes "u = x" "w = v + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2820
  shows  "\<lbrace>st i ** ps u ** one v ** zeros w x \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2821
              i:[left_until_one]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2822
          \<lbrace>st j ** ps v ** one v ** zeros w x \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2823
  by (unfold assms, rule hoare_left_until_one)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2824
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2825
definition "left_until_double_zero = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2826
            (TL start exit.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2827
              TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2828
              if_zero exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2829
              left_until_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2830
              move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2831
              if_one start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2832
              TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2833
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2834
declare ones.simps[simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2835
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2836
lemma reps_simps3: "ks \<noteq> [] \<Longrightarrow> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2837
  reps i j (k # ks) = (ones i (i + int k) ** zero (i + int k + 1) ** reps (i + int k + 2) j ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2838
by(case_tac ks, simp, simp add: reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2839
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2840
lemma cond_eqI:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2841
  assumes h: "b \<Longrightarrow> r = s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2842
  shows "(<b> ** r) = (<b> ** s)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2843
proof(cases b)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2844
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2845
  from h[OF this] show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2846
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2847
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2848
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2849
    by (unfold sep_conj_def set_ins_def pasrt_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2850
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2851
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2852
lemma reps_rev: "ks \<noteq> [] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2853
       \<Longrightarrow> reps i j (ks @ [k]) =  (reps i (j - int (k + 1) - 1 ) ks \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2854
                                          zero (j - int (k + 1)) \<and>* ones (j - int k) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2855
proof(induct ks arbitrary: i j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2856
  case Nil
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2857
  thus ?case by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2858
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2859
  case (Cons a ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2860
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2861
  proof(cases "ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2862
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2863
    thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2864
    proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2865
      have eq_cond: "(j = i + int a + 2 + int k) = (-2 + (j - int k) = i + int a)" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2866
      have "(<(-2 + (j - int k) = i + int a)> \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2867
            one i \<and>* ones (i + 1) (i + int a) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2868
            zero (i + int a + 1) \<and>* one (i + int a + 2) \<and>* ones (3 + (i + int a)) (i + int a + 2 + int k))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2869
            =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2870
            (<(-2 + (j - int k) = i + int a)> \<and>* one i \<and>* ones (i + 1) (i + int a) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2871
            zero (j - (1 + int k)) \<and>* one (j - int k) \<and>* ones (j - int k + 1) j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2872
        (is "(<?X> \<and>* ?L) = (<?X> \<and>* ?R)")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2873
      proof(rule cond_eqI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2874
        assume h: "-2 + (j - int k) = i + int a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2875
        hence eqs:  "i + int a + 1 = j - (1 + int k)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2876
                    "i + int a + 2 = j - int k"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2877
                    "3 + (i + int a) = j - int k + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2878
                    "(i + int a + 2 + int k) = j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2879
        by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2880
        show "?L = ?R"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2881
          by (unfold eqs, auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2882
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2883
      with True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2884
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2885
        apply (simp del:ones_simps reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2886
        apply (simp add:sep_conj_cond eq_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2887
        by (auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2888
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2889
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2890
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2891
    from Cons(1)[OF False, of "i + int a + 2" j] this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2892
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2893
      by(simp add: reps_simps3 sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2894
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2895
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2896
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2897
lemma hoare_if_one_reps:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2898
  assumes nn: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2899
  shows "\<lbrace>st i ** ps v ** reps u v ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2900
           i:[if_one e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2901
        \<lbrace>st e ** ps v ** reps u v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2902
proof(rule rev_exhaust[of ks])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2903
  assume "ks = []" with nn show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2904
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2905
  fix y ys
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2906
  assume eq_ks: "ks = ys @ [y]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2907
  show " \<lbrace>st i \<and>* ps v \<and>* reps u v ks\<rbrace>  i :[ if_one e ]: j \<lbrace>st e \<and>* ps v \<and>* reps u v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2908
  proof(cases "ys = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2909
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2910
    have "\<lbrace>st i \<and>* ps v \<and>* reps u v (ys @ [y])\<rbrace>  i :[ if_one e ]: j \<lbrace>st e \<and>* ps v \<and>* reps u v (ys @ [y])\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2911
      apply(unfold reps_rev[OF False], simp del:ones_simps add:ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2912
      by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2913
    thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2914
      by (simp add:eq_ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2915
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2916
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2917
    with eq_ks
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2918
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2919
      apply (simp del:ones_simps add:ones_rev sep_conj_cond, intro tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2920
      by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2921
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2922
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2923
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2924
lemma hoare_if_one_reps_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2925
  assumes nn: "ks \<noteq> []" "u = w"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2926
  shows "\<lbrace>st i ** ps u ** reps v w ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2927
           i:[if_one e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2928
        \<lbrace>st e ** ps u ** reps v w ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2929
  by (unfold `u = w`, rule hoare_if_one_reps[OF `ks \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2930
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2931
lemma hoare_if_zero_ones_false[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2932
  assumes "\<not> w < u" "v = w"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2933
  shows  "\<lbrace>st i \<and>* ps v \<and>* ones u w\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2934
             i :[if_zero e]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2935
          \<lbrace>st j \<and>* ps v \<and>* ones u w\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2936
  by (unfold `v = w` ones_rev[OF `\<not> w < u`], hstep)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2937
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2938
lemma hoare_left_until_double_zero_nil[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2939
  assumes "u = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2940
  shows   "\<lbrace>st i ** ps u ** zero v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2941
                  i:[left_until_double_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2942
           \<lbrace>st j ** ps u ** zero v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2943
  apply (unfold `u = v` left_until_double_zero_def, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2944
      intro t_hoare_local t_hoare_label, clarsimp, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2945
      rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2946
  by (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2947
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2948
lemma hoare_if_zero_reps_false:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2949
  assumes nn: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2950
  shows "\<lbrace>st i ** ps v ** reps u v ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2951
           i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2952
        \<lbrace>st j ** ps v ** reps u v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2953
proof(rule rev_exhaust[of ks])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2954
  assume "ks = []" with nn show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2955
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2956
  fix y ys
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2957
  assume eq_ks: "ks = ys @ [y]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2958
  show " \<lbrace>st i \<and>* ps v \<and>* reps u v ks\<rbrace>  i :[ if_zero e ]: j \<lbrace>st j \<and>* ps v \<and>* reps u v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2959
  proof(cases "ys = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2960
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2961
    have "\<lbrace>st i \<and>* ps v \<and>* reps u v (ys @ [y])\<rbrace>  i :[ if_zero e ]: j \<lbrace>st j \<and>* ps v \<and>* reps u v (ys @ [y])\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2962
      apply(unfold reps_rev[OF False], simp del:ones_simps add:ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2963
      by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2964
    thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2965
      by (simp add:eq_ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2966
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2967
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2968
    with eq_ks
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2969
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2970
      apply (simp del:ones_simps add:ones_rev sep_conj_cond, intro tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2971
      by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2972
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2973
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2974
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2975
lemma hoare_if_zero_reps_false_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2976
  assumes "ks \<noteq> []" "u = w"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2977
  shows "\<lbrace>st i ** ps u ** reps v w ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2978
           i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2979
        \<lbrace>st j ** ps u ** reps v w ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2980
  by (unfold `u = w`, rule hoare_if_zero_reps_false[OF `ks \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2981
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2982
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2983
lemma hoare_if_zero_reps_false1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2984
  assumes nn: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2985
  shows "\<lbrace>st i ** ps u ** reps u v ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2986
           i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2987
        \<lbrace>st j ** ps u ** reps u v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2988
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2989
  from nn obtain y ys where eq_ys: "ks = y#ys"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2990
    by (metis neq_Nil_conv)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2991
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2992
    apply (unfold eq_ys)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2993
    by (case_tac ys, (simp, hsteps)+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2994
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2995
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2996
lemma hoare_if_zero_reps_false1_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2997
  assumes nn: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2998
  and h: "u = w"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2999
  shows "\<lbrace>st i ** ps u ** reps w v ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3000
           i:[if_zero e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3001
        \<lbrace>st j ** ps u ** reps w v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3002
  by (unfold h, rule hoare_if_zero_reps_false1[OF `ks \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3003
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3004
lemma hoare_left_until_double_zero: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3005
  assumes h: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3006
  shows   "\<lbrace>st i ** ps v ** zero u ** zero (u + 1) ** reps (u+2) v ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3007
                  i:[left_until_double_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3008
           \<lbrace>st j ** ps u ** zero u ** zero (u + 1) ** reps (u+2) v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3009
proof(unfold left_until_double_zero_def, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3010
      intro t_hoare_local t_hoare_label, clarsimp, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3011
      rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3012
  fix la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3013
  let ?body = "i :[ (if_zero la ; left_until_zero ; move_left ; if_one i) ]: j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3014
  let ?j = j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3015
  show "\<lbrace>st i \<and>* ps v \<and>* zero u \<and>* zero (u + 1) \<and>* reps (u + 2) v ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3016
           ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3017
        \<lbrace>st ?j \<and>* ps u \<and>* zero u \<and>* zero (u + 1) \<and>* reps (u + 2) v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3018
    using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3019
  proof(induct ks arbitrary: v rule:rev_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3020
    case Nil
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3021
    with h show ?case by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3022
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3023
    case (snoc k ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3024
    show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3025
    proof(cases "ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3026
      case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3027
      have eq_ones: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3028
        "ones (u + 2) (u + 2 + int k) = (ones (u + 2) (u + 1 + int k) \<and>* one (u + 2 + int k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3029
        by (smt ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3030
      have eq_ones': "(one (u + 2) \<and>* ones (3 + u) (u + 2 + int k)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3031
            (one (u + 2 + int k) \<and>* ones (u + 2) (u + 1 + int k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3032
        by (smt eq_ones ones.simps sep.mult_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3033
      thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3034
        apply (insert True, simp del:ones_simps add:sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3035
        apply (rule tm.pre_condI, simp del:ones_simps, unfold eq_ones)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3036
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3037
        apply (rule_tac p = "st j' \<and>* ps (u + 2 + int k) \<and>* zero u \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3038
                             zero (u + 1) \<and>* ones (u + 2) (u + 2 + int k)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3039
                  in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3040
        by (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3041
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3042
      case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3043
      from False have spt: "splited (ks @ [k]) ks [k]" by (unfold splited_def, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3044
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3045
        apply (unfold reps_splited[OF spt], simp del:ones_simps add:sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3046
        apply (rule tm.pre_condI, simp del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3047
        apply (rule_tac q = "st i \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3048
               ps (1 + (u + int (reps_len ks))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3049
               zero u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3050
               zero (u + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3051
               reps (u + 2) (1 + (u + int (reps_len ks))) ks \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3052
               zero (u + 2 + int (reps_len ks)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3053
               ones (3 + (u + int (reps_len ks))) (3 + (u + int (reps_len ks)) + int k)" in
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3054
               tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3055
        apply hsteps[1]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3056
        by (hstep snoc(1))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3057
    qed 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3058
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3059
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3060
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3061
lemma hoare_left_until_double_zero_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3062
  assumes h1: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3063
      and h: "u = y" "w = v + 1" "x = v + 2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3064
  shows   "\<lbrace>st i ** ps u ** zero v ** zero w ** reps x y ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3065
                  i:[left_until_double_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3066
           \<lbrace>st j ** ps v ** zero v ** zero w ** reps x y ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3067
  by (unfold h, rule hoare_left_until_double_zero[OF h1])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3068
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3069
lemma hoare_jmp_reps1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3070
  assumes "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3071
  shows  "\<lbrace> st i \<and>* ps u \<and>* reps u v ks\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3072
                 i:[jmp e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3073
          \<lbrace> st e \<and>* ps u \<and>* reps u v ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3074
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3075
  from assms obtain k ks' where Cons:"ks = k#ks'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3076
    by (metis neq_Nil_conv)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3077
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3078
  proof(cases "ks' = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3079
    case True with Cons
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3080
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3081
      apply(simp add:sep_conj_cond reps.simps, intro tm.pre_condI, simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3082
      by (hgoto hoare_jmp_gen)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3083
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3084
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3085
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3086
      apply (unfold `ks = k#ks'` reps_simp3[OF False], simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3087
      by (hgoto hoare_jmp[where p = u])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3088
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3089
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3090
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3091
lemma hoare_jmp_reps1_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3092
  assumes "ks \<noteq> []" "u = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3093
  shows  "\<lbrace> st i \<and>* ps u \<and>* reps v w ks\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3094
                 i:[jmp e]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3095
          \<lbrace> st e \<and>* ps u \<and>* reps v w ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3096
  by (unfold assms, rule hoare_jmp_reps1[OF `ks \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3097
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3098
lemma hoare_jmp_reps:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3099
      "\<lbrace> st i \<and>* ps u \<and>* reps u v ks \<and>* tm (v + 1) x \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3100
                 i:[(jmp e; c)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3101
       \<lbrace> st e \<and>* ps u \<and>* reps u v ks \<and>* tm (v + 1) x \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3102
proof(cases "ks")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3103
  case Nil
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3104
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3105
    by (simp add:sep_conj_cond, intro tm.pre_condI, simp, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3106
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3107
  case (Cons k ks')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3108
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3109
  proof(cases "ks' = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3110
    case True with Cons
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3111
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3112
      apply(simp add:sep_conj_cond, intro tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3113
      by (hgoto hoare_jmp[where p = u])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3114
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3115
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3116
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3117
      apply (unfold `ks = k#ks'` reps_simp3[OF False], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3118
      by (hgoto hoare_jmp[where p = u])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3119
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3120
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3121
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3122
definition "shift_right =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3123
            (TL start exit.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3124
              TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3125
                 if_zero exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3126
                 write_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3127
                 move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3128
                 right_until_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3129
                 write_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3130
                 move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3131
                 jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3132
              TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3133
            )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3134
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3135
lemma hoare_shift_right_cons:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3136
  assumes h: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3137
  shows "\<lbrace>st i \<and>* ps u ** reps u v ks \<and>* zero (v + 1) \<and>* zero (v + 2) \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3138
            i:[shift_right]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3139
         \<lbrace>st j ** ps (v + 2) ** zero u ** reps (u + 1) (v + 1) ks ** zero (v + 2) \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3140
proof(unfold shift_right_def, intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3141
      rule t_hoare_label_last, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3142
  fix la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3143
  have eq_ones: "\<And> u k. (one (u + int k + 1) \<and>* ones (u + 1) (u + int k)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3144
                                   (one (u + 1) \<and>* ones (2 + u) (u + 1 + int k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3145
    by (smt cond_true_eq2 ones.simps ones_rev sep.mult_assoc sep.mult_commute 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3146
               sep.mult_left_commute sep_conj_assoc sep_conj_commute 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3147
               sep_conj_cond1 sep_conj_cond2 sep_conj_cond3 sep_conj_left_commute
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3148
               sep_conj_trivial_strip2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3149
  show "\<lbrace>st i \<and>* ps u \<and>* reps u v ks \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3150
         i :[ (if_zero la ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3151
               write_zero ; move_right ; right_until_zero ; write_one ; move_right ; jmp i) ]: la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3152
         \<lbrace>st la \<and>* ps (v + 2) \<and>* zero u \<and>* reps (u + 1) (v + 1) ks \<and>* zero (v + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3153
    using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3154
  proof(induct ks arbitrary:i u v)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3155
    case (Cons k ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3156
    thus ?case 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3157
    proof(cases "ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3158
      let ?j = la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3159
      case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3160
      let ?body = "i :[ (if_zero ?j ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3161
                      write_zero ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3162
                      move_right ; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3163
                      right_until_zero ; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3164
                      write_one ; move_right ; jmp i) ]: ?j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3165
      have first_interation: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3166
           "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* ones (u + 1) (u + int k) \<and>* zero (u + int k + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3167
                                                                             zero (u + int k + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3168
                ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3169
            \<lbrace>st i \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3170
             ps (u + int k + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3171
             one (u + int k + 1) \<and>* ones (u + 1) (u + int k) \<and>* zero u \<and>* zero (u + int k + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3172
        apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3173
        by (simp add:sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3174
      hence "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* ones (u + 1) (u + int k) \<and>* zero (u + int k + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3175
                                                                             zero (u + int k + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3176
                   ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3177
             \<lbrace>st ?j \<and>* ps (u + int k + 2) \<and>* zero u \<and>* one (u + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3178
                         ones (2 + u) (u + 1 + int k) \<and>* zero (u + int k + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3179
      proof(rule tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3180
        show "\<lbrace>st i \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3181
               ps (u + int k + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3182
               one (u + int k + 1) \<and>* ones (u + 1) (u + int k) \<and>* zero u \<and>* zero (u + int k + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3183
                      ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3184
              \<lbrace>st ?j \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3185
               ps (u + int k + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3186
               zero u \<and>* one (u + 1) \<and>* ones (2 + u) (u + 1 + int k) \<and>* zero (u + int k + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3187
          apply (hgoto hoare_if_zero_true_gen)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3188
          by (simp add:sep_conj_ac eq_ones)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3189
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3190
      with True 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3191
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3192
        by (simp, simp only:sep_conj_cond, intro tm.pre_condI, auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3193
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3194
      case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3195
      let ?j = la
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3196
      let ?body = "i :[ (if_zero ?j ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3197
                        write_zero ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3198
                        move_right ; right_until_zero ; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3199
                        write_one ; move_right ; jmp i) ]: ?j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3200
      have eq_ones': 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3201
         "(one (u + int k + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3202
           ones (u + 1) (u + int k) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3203
           zero u \<and>* reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3204
                   =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3205
           (zero u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3206
             ones (u + 1) (u + int k) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3207
             one (u + int k + 1) \<and>* reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3208
        by (simp add:eq_ones sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3209
      have "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* ones (u + 1) (u + int k) \<and>* zero (u + int k + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3210
                 reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3211
                    ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3212
            \<lbrace>st i \<and>* ps (u + int k + 2) \<and>* zero u \<and>* ones (u + 1) (u + int k) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3213
                 one (u + int k + 1) \<and>* reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3214
        apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3215
        by (auto simp:sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3216
      hence "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* ones (u + 1) (u + int k) \<and>* zero (u + int k + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3217
                 reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3218
                     ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3219
            \<lbrace>st ?j \<and>* ps (v + 2) \<and>* zero u \<and>* one (u + 1) \<and>* ones (2 + u) (u + 1 + int k) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3220
                 zero (2 + (u + int k)) \<and>* reps (3 + (u + int k)) (v + 1) ks \<and>* zero (v + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3221
      proof(rule tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3222
        have eq_ones': 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3223
          "\<And> u k. (one (u + int k + 1) \<and>* ones (u + 1) (u + int k) \<and>* zero (u + int k + 2)) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3224
             (one (u + 1) \<and>* zero (2 + (u + int k)) \<and>* ones (2 + u) (u + 1 + int k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3225
          by (smt eq_ones sep.mult_assoc sep_conj_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3226
        show "\<lbrace>st i \<and>* ps (u + int k + 2) \<and>* zero u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3227
                    ones (u + 1) (u + int k) \<and>* one (u + int k + 1) \<and>* reps (u + int k + 2) v ks \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3228
                    zero (v + 1) \<and>* zero (v + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3229
                      ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3230
              \<lbrace>st ?j \<and>* ps (v + 2) \<and>* zero u \<and>* one (u + 1) \<and>* ones (2 + u) (u + 1 + int k) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3231
                      zero (2 + (u + int k)) \<and>* reps (3 + (u + int k)) (v + 1) ks \<and>* zero (v + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3232
          apply (hsteps Cons.hyps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3233
          by (simp add:sep_conj_ac eq_ones, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3234
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3235
      thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3236
        by (unfold reps_simp3[OF False], auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3237
    qed 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3238
  qed auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3239
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3240
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3241
lemma hoare_shift_right_cons_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3242
  assumes h: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3243
  and h1: "u = v" "x = w + 1" "y = w + 2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3244
  shows "\<lbrace>st i \<and>* ps u ** reps v w ks \<and>* zero x \<and>* zero y \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3245
            i:[shift_right]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3246
         \<lbrace>st j ** ps y ** zero v ** reps (v + 1) x ks ** zero y\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3247
  by (unfold h1, rule hoare_shift_right_cons[OF h])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3248
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3249
lemma shift_right_nil [step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3250
  assumes "u = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3251
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3252
       "\<lbrace> st i \<and>* ps u \<and>* zero v \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3253
               i:[shift_right]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3254
        \<lbrace> st j \<and>* ps u \<and>* zero v \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3255
  by (unfold assms shift_right_def, intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3256
          rule t_hoare_label_last, simp+, hstep)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3257
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3258
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3259
text {*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3260
  @{text "clear_until_zero"} is useful to implement @{text "drag"}.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3261
*}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3262
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3263
definition "clear_until_zero = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3264
             (TL start exit.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3265
              TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3266
                 if_zero exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3267
                 write_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3268
                 move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3269
                 jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3270
              TLabel exit)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3271
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3272
lemma  hoare_clear_until_zero[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3273
         "\<lbrace>st i ** ps u ** ones u v ** zero (v + 1)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3274
              i :[clear_until_zero]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3275
          \<lbrace>st j ** ps (v + 1) ** zeros u v ** zero (v + 1)\<rbrace> "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3276
proof(unfold clear_until_zero_def, intro t_hoare_local, rule t_hoare_label,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3277
    rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3278
  let ?body = "i :[ (if_zero j ; write_zero ; move_right ; jmp i) ]: j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3279
  show "\<lbrace>st i \<and>* ps u \<and>* ones u v \<and>* zero (v + 1)\<rbrace> ?body 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3280
        \<lbrace>st j \<and>* ps (v + 1) \<and>* zeros u v \<and>* zero (v + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3281
  proof(induct u v rule: zeros.induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3282
    fix ia ja
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3283
    assume h: "\<not> ja < ia \<Longrightarrow>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3284
             \<lbrace>st i \<and>* ps (ia + 1) \<and>* ones (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>  ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3285
             \<lbrace>st j \<and>* ps (ja + 1) \<and>* zeros (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3286
    show "\<lbrace>st i \<and>* ps ia \<and>* ones ia ja \<and>* zero (ja + 1)\<rbrace> ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3287
           \<lbrace>st j \<and>* ps (ja + 1) \<and>* zeros ia ja \<and>* zero (ja + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3288
    proof(cases "ja < ia")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3289
      case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3290
      thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3291
        by (simp add: ones.simps zeros.simps sep_conj_ac, simp only:sep_conj_cond,
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3292
               intro tm.pre_condI, simp, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3293
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3294
      case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3295
      note h[OF False, step]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3296
      from False have ones_eq: "ones ia ja = (one ia \<and>* ones (ia + 1) ja)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3297
        by(simp add: ones.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3298
      from False have zeros_eq: "zeros ia ja = (zero ia \<and>* zeros (ia + 1) ja)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3299
        by(simp add: zeros.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3300
      have s1: "\<lbrace>st i \<and>* ps ia \<and>* one ia \<and>* ones (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>  ?body 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3301
                 \<lbrace>st i \<and>* ps (ia + 1) \<and>* zero ia \<and>* ones (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3302
      proof(cases "ja < ia + 1")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3303
        case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3304
        from True False have "ja = ia" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3305
        thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3306
          apply(simp add: ones.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3307
          by (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3308
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3309
        case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3310
        from False have "ones (ia + 1) ja = (one (ia + 1) \<and>* ones (ia + 1 + 1) ja)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3311
          by(simp add: ones.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3312
        thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3313
          by (simp, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3314
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3315
      have s2: "\<lbrace>st i \<and>* ps (ia + 1) \<and>* zero ia \<and>* ones (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3316
                ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3317
                \<lbrace>st j \<and>* ps (ja + 1) \<and>* zero ia \<and>* zeros (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3318
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3319
      from tm.sequencing[OF s1 s2] have 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3320
        "\<lbrace>st i \<and>* ps ia \<and>* one ia \<and>* ones (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>  ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3321
        \<lbrace>st j \<and>* ps (ja + 1) \<and>* zero ia \<and>* zeros (ia + 1) ja \<and>* zero (ja + 1)\<rbrace>" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3322
      thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3323
        unfolding ones_eq zeros_eq by(simp add: sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3324
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3325
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3326
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3327
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3328
lemma  hoare_clear_until_zero_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3329
  assumes "u = v" "x = w + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3330
  shows "\<lbrace>st i ** ps u ** ones v w ** zero x\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3331
              i :[clear_until_zero]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3332
        \<lbrace>st j ** ps x ** zeros v w ** zero x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3333
  by (unfold assms, rule hoare_clear_until_zero)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3334
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3335
definition "shift_left = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3336
            (TL start exit.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3337
              TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3338
                 if_zero exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3339
                 move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3340
                 write_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3341
                 right_until_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3342
                 move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3343
                 write_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3344
                 move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3345
                 move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3346
                 jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3347
              TLabel exit)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3348
           "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3349
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3350
declare ones_simps[simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3351
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3352
lemma hoare_move_left_reps[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3353
  assumes "ks \<noteq> []" "u = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3354
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3355
    "\<lbrace>st i ** ps u ** reps v w ks\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3356
         i:[move_left]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3357
     \<lbrace>st j ** ps (u - 1) **  reps v w ks\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3358
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3359
  from `ks \<noteq> []` obtain y ys where eq_ks: "ks = y#ys"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3360
    by (metis neq_Nil_conv)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3361
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3362
    apply (unfold assms eq_ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3363
    apply (case_tac ys, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3364
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3365
      have "(ones v (v + int y)) = (one v \<and>* ones (v + 1) (v + int y))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3366
        by (smt ones_step_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3367
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3368
    apply (unfold this, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3369
    by (simp add:this, hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3370
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3371
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3372
lemma hoare_shift_left_cons:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3373
  assumes h: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3374
  shows "\<lbrace>st i \<and>* ps u \<and>* tm (u - 1) x \<and>* reps u v ks \<and>* zero (v + 1) \<and>* zero (v + 2) \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3375
                                   i:[shift_left]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3376
         \<lbrace>st j \<and>* ps (v + 2) \<and>* reps (u - 1) (v - 1) ks \<and>* zero v \<and>* zero (v + 1) \<and>* zero (v + 2) \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3377
proof(unfold shift_left_def, intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3378
      rule t_hoare_label_last, simp+, clarify, prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3379
  show " \<lbrace>st i \<and>* ps u \<and>* tm (u - 1) x \<and>* reps u v ks \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3380
             i :[ (if_zero j ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3381
                   move_left ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3382
                   write_one ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3383
                   right_until_zero ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3384
                   move_left ; write_zero ; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3385
                   move_right ; move_right ; jmp i) ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3386
         \<lbrace>st j \<and>* ps (v + 2) \<and>* reps (u - 1) (v - 1) ks \<and>* zero v \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3387
    using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3388
  proof(induct ks arbitrary:i u v x)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3389
    case (Cons k ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3390
    thus ?case 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3391
    proof(cases "ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3392
      let ?body = "i :[ (if_zero j ;  move_left ; write_one ; right_until_zero ;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3393
                   move_left ; write_zero ; move_right ; move_right ; jmp i) ]: j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3394
      case True 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3395
      have "\<lbrace>st i \<and>* ps u \<and>* tm (u - 1) x \<and>* (one u \<and>* ones (u + 1) (u + int k)) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3396
                                          zero (u + int k + 1) \<and>* zero (u + int k + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3397
                         ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3398
            \<lbrace>st j \<and>* ps (u + int k + 2) \<and>* (one (u - 1) \<and>* ones u (u - 1 + int k)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3399
                       zero (u + int k) \<and>* zero (u + int k + 1) \<and>* zero (u + int k + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3400
      apply(rule tm.sequencing [where q = "st i \<and>* ps (u + int k + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3401
                (one (u - 1) \<and>* ones u (u - 1 + int k)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3402
                zero (u + int k) \<and>* zero (u + int k + 1) \<and>* zero (u + int k + 2)"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3403
          apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3404
          apply (rule_tac p = "st j' \<and>* ps (u - 1) \<and>* ones (u - 1) (u + int k) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3405
                                zero (u + int k + 1) \<and>* zero (u + int k + 2)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3406
            in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3407
          apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3408
          my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3409
            have "(ones (u - 1) (u + int k)) = (ones (u - 1) (u + int k - 1) \<and>* one (u + int k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3410
              by (smt ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3411
          my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3412
          apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3413
          apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3414
          apply (simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3415
          apply (smt ones.simps sep.mult_assoc sep_conj_commuteI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3416
          apply (simp add:sep_conj_ac)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3417
          apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3418
          apply (smt ones.simps sep.mult_left_commute sep_conj_commuteI this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3419
          by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3420
        with True show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3421
        by (simp add:ones_simps, simp only:sep_conj_cond, intro tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3422
    next 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3423
      case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3424
      let ?body = "i :[ (if_zero j ; move_left ; write_one ;right_until_zero ; move_left ; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3425
                                write_zero ; move_right ; move_right ; jmp i) ]: j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3426
      have "\<lbrace>st i \<and>* ps u \<and>* tm (u - 1) x \<and>* one u \<and>* ones (u + 1) (u + int k) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3427
                zero (u + int k + 1) \<and>* reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3428
                ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3429
            \<lbrace>st j \<and>* ps (v + 2) \<and>* one (u - 1) \<and>* ones u (u - 1 + int k) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3430
                        zero (u + int k) \<and>* reps (1 + (u + int k)) (v - 1) ks \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3431
                                              zero v \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3432
        apply (rule tm.sequencing[where q = "st i \<and>* ps (u + int k + 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3433
                  zero (u + int k + 1) \<and>* reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3434
                  zero (v + 2) \<and>* one (u - 1) \<and>* ones u (u - 1 + int k) \<and>* zero (u + int k)"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3435
        apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3436
        apply (rule_tac p = "st j' \<and>* ps (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3437
                               ones (u - 1) (u + int k) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3438
                               zero (u + int k + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3439
                               reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3440
            " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3441
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3442
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3443
          have "(ones (u - 1) (u + int k)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3444
            (ones (u - 1) (u + int k - 1) \<and>* one (u + int k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3445
            by (smt ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3446
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3447
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3448
        apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3449
        apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3450
        apply (smt ones.simps sep.mult_assoc sep_conj_commuteI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3451
        apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3452
        apply (smt ones.simps this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3453
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3454
          have eq_u: "1 + (u + int k) = u + int k + 1" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3455
          from Cons.hyps[OF `ks \<noteq> []`, of i "u + int k + 2" Bk v, folded zero_def] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3456
          have "\<lbrace>st i \<and>* ps (u + int k + 2) \<and>* zero (u + int k + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3457
                            reps (u + int k + 2) v ks \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3458
                               ?body
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3459
                      \<lbrace>st j \<and>* ps (v + 2) \<and>*  reps (1 + (u + int k)) (v - 1) ks \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3460
                                                zero v \<and>* zero (v + 1) \<and>* zero (v + 2)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3461
          by (simp add:eq_u)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3462
        my_block_end my_note hh[step] = this 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3463
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3464
      thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3465
        by (unfold reps_simp3[OF False], auto simp:sep_conj_ac ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3466
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3467
  qed auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3468
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3469
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3470
lemma hoare_shift_left_cons_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3471
  assumes h: "ks \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3472
          "v = u - 1" "w = u" "y = x + 1" "z = x + 2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3473
  shows "\<lbrace>st i \<and>* ps u \<and>* tm v vv \<and>* reps w x ks \<and>* tm y Bk \<and>* tm z Bk\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3474
                                   i:[shift_left]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3475
         \<lbrace>st j \<and>* ps z \<and>* reps v (x - 1) ks \<and>* zero x \<and>* zero y \<and>* zero z \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3476
  by (unfold assms, fold zero_def, rule hoare_shift_left_cons[OF `ks \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3477
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3478
definition "bone c1 c2 = (TL exit l_one.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3479
                                if_one l_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3480
                                  (c1;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3481
                                   jmp exit);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3482
                                TLabel l_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3483
                                      c2;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3484
                                TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3485
                              )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3486
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3487
lemma hoare_bone_1_out:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3488
  assumes h: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3489
        "\<And> i j . \<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3490
                         i:[c1]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3491
                  \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3492
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3493
  shows "\<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3494
              i:[(bone c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3495
         \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3496
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3497
apply (unfold bone_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3498
apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3499
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3500
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3501
by (rule h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3502
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3503
lemma hoare_bone_1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3504
  assumes h: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3505
        "\<And> i j . \<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3506
                         i:[c1]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3507
                  \<lbrace>st j \<and>* ps v \<and>* tm v x \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3508
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3509
  shows "\<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3510
              i:[(bone c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3511
         \<lbrace>st j \<and>* ps v \<and>* tm v x \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3512
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3513
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3514
  note h[step]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3515
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3516
    apply (unfold bone_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3517
    apply (rule t_hoare_label_last, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3518
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3519
    apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3520
    by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3521
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3522
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3523
lemma hoare_bone_2:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3524
  assumes h: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3525
        "\<And> i j . \<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3526
                         i:[c2]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3527
                  \<lbrace>st j \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3528
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3529
  shows "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3530
              i:[(bone c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3531
         \<lbrace>st j \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3532
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3533
apply (unfold bone_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3534
apply (rule_tac q = "st la \<and>* ps u \<and>* one u \<and>* p" in tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3535
apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3536
apply (subst tassemble_to.simps(2), intro tm.code_exI, intro tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3537
apply (subst tassemble_to.simps(2), intro tm.code_exI, intro tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3538
apply (subst tassemble_to.simps(2), intro tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3539
apply (subst tassemble_to.simps(4), intro tm.code_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3540
apply (subst tassemble_to.simps(2), intro tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3541
apply (subst tassemble_to.simps(4), simp add:sep_conj_cond, rule tm.code_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3542
by (rule h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3543
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3544
lemma hoare_bone_2_out:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3545
  assumes h: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3546
        "\<And> i j . \<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3547
                         i:[c2]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3548
                  \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3549
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3550
  shows "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3551
              i:[(bone c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3552
         \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3553
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3554
apply (unfold bone_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3555
apply (rule_tac q = "st la \<and>* ps u \<and>* one u \<and>* p" in tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3556
apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3557
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3558
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3559
apply (subst tassemble_to.simps(2), intro tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3560
apply (subst tassemble_to.simps(4), rule tm.code_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3561
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3562
by (rule h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3563
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3564
definition "bzero c1 c2 = (TL exit l_zero.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3565
                                if_zero l_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3566
                                  (c1;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3567
                                   jmp exit);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3568
                                TLabel l_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3569
                                      c2;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3570
                                TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3571
                              )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3572
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3573
lemma hoare_bzero_1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3574
  assumes h[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3575
        "\<And> i j . \<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3576
                         i:[c1]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3577
                 \<lbrace>st j \<and>* ps v \<and>* tm v x \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3578
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3579
  shows "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3580
              i:[(bzero c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3581
         \<lbrace>st j \<and>* ps v \<and>* tm v x \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3582
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3583
apply (unfold bzero_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3584
apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3585
apply (rule_tac c = " ((c1 ; jmp l) ; TLabel la ; c2 ; TLabel l)" in t_hoare_label_last, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3586
apply (subst tassemble_to.simps(2), intro tm.code_exI, intro tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3587
by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3588
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3589
lemma hoare_bzero_1_out:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3590
  assumes h[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3591
        "\<And> i j . \<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3592
                         i:[c1]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3593
                 \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3594
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3595
  shows "\<lbrace>st i \<and>* ps u \<and>* one u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3596
              i:[(bzero c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3597
         \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3598
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3599
apply (unfold bzero_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3600
apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3601
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3602
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3603
by (rule h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3604
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3605
lemma hoare_bzero_2:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3606
  assumes h: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3607
        "\<And> i j. \<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3608
                         i:[c2]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3609
                 \<lbrace>st j \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3610
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3611
  shows "\<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3612
              i:[(bzero c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3613
         \<lbrace>st j \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3614
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3615
  apply (unfold bzero_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3616
  apply (rule_tac q = "st la \<and>* ps u \<and>* zero u \<and>* p" in tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3617
  apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3618
  apply (subst tassemble_to.simps(2), intro tm.code_exI, intro tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3619
  apply (subst tassemble_to.simps(2), intro tm.code_exI, intro tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3620
  apply (subst tassemble_to.simps(2), intro tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3621
  apply (subst tassemble_to.simps(4))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3622
  apply (rule tm.code_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3623
  apply (subst tassemble_to.simps(2))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3624
  apply (rule tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3625
  apply (subst tassemble_to.simps(4), simp add:sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3626
  apply (rule tm.code_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3627
  by (rule h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3628
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3629
lemma hoare_bzero_2_out:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3630
  assumes h: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3631
        "\<And> i j . \<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3632
                         i:[c2]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3633
                  \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3634
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3635
  shows "\<lbrace>st i \<and>* ps u \<and>* zero u \<and>* p\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3636
              i:[(bzero c1 c2)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3637
         \<lbrace>st e \<and>* q \<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3638
        "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3639
apply (unfold bzero_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3640
apply (rule_tac q = "st la \<and>* ps u \<and>* zero u \<and>* p" in tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3641
apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3642
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3643
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3644
apply (subst tassemble_to.simps(2), intro tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3645
apply (subst tassemble_to.simps(4), rule tm.code_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3646
apply (subst tassemble_to.simps(2), intro tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3647
by (rule h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3648
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3649
definition "skip_or_set = bone (write_one; move_right; move_right)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3650
                               (right_until_zero; move_right)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3651
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3652
lemma reps_len_split: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3653
  assumes "xs \<noteq> []" "ys \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3654
  shows "reps_len (xs @ ys) = reps_len xs + reps_len ys + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3655
  using assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3656
proof(induct xs arbitrary:ys)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3657
  case (Cons x1 xs1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3658
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3659
  proof(cases "xs1 = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3660
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3661
    thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3662
      by (simp add:reps_len_cons[OF `ys \<noteq> []`] reps_len_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3663
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3664
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3665
    hence " xs1 @ ys \<noteq> []" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3666
    thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3667
      apply (simp add:reps_len_cons[OF `xs1@ys \<noteq> []`] reps_len_cons[OF `xs1 \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3668
      by (simp add: Cons.hyps[OF `xs1 \<noteq> []` `ys \<noteq> []`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3669
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3670
qed auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3671
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3672
lemma hoare_skip_or_set_set:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3673
  "\<lbrace> st i \<and>* ps u \<and>* zero u \<and>* zero (u + 1) \<and>* tm (u + 2) x\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3674
         i:[skip_or_set]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3675
   \<lbrace> st j \<and>* ps (u + 2) \<and>* one u \<and>* zero (u + 1) \<and>* tm (u + 2) x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3676
  apply(unfold skip_or_set_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3677
  apply(rule_tac q = "st j \<and>* ps (u + 2) \<and>* tm (u + 2) x \<and>* one u \<and>* zero (u + 1)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3678
    in tm.post_weaken)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3679
  apply(rule hoare_bone_1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3680
  apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3681
  by (auto simp:sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3682
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3683
lemma hoare_skip_or_set_set_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3684
  assumes "u = v" "w = v + 1" "x = v + 2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3685
  shows "\<lbrace>st i \<and>* ps u \<and>* zero v \<and>* zero w \<and>* tm x xv\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3686
                   i:[skip_or_set]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3687
         \<lbrace>st j \<and>* ps x \<and>* one v \<and>* zero w \<and>* tm x xv\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3688
  by (unfold assms, rule hoare_skip_or_set_set)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3689
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3690
lemma hoare_skip_or_set_skip:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3691
  "\<lbrace> st i \<and>* ps u \<and>* reps u v [k] \<and>* zero (v + 1)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3692
         i:[skip_or_set]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3693
   \<lbrace> st j \<and>*  ps (v + 2) \<and>* reps u v [k] \<and>* zero (v + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3694
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3695
   show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3696
     apply(unfold skip_or_set_def, unfold reps.simps, simp add:sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3697
     apply(rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3698
     apply(rule_tac p = "st i \<and>* ps u \<and>* one u \<and>* ones (u + 1) (u + int k) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3699
                             zero (u + int k + 1)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3700
                   in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3701
     apply (rule_tac q = "st j \<and>* ps (u + int k + 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3702
                          one u \<and>* ones (u + 1) (u + int k) \<and>* zero (u + int k + 1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3703
              " in tm.post_weaken)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3704
     apply (rule hoare_bone_2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3705
     apply (rule_tac p = " st i \<and>* ps u \<and>* ones u (u + int k) \<and>* zero (u + int k + 1) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3706
       " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3707
     apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3708
     apply (simp add:sep_conj_ac, sep_cancel+, auto simp:sep_conj_ac ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3709
     by (sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3710
 qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3711
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3712
lemma hoare_skip_or_set_skip_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3713
  assumes "u = v" "x = w + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3714
  shows  "\<lbrace> st i \<and>* ps u \<and>* reps v w [k] \<and>* zero x\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3715
                  i:[skip_or_set]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3716
          \<lbrace> st j \<and>*  ps (w + 2) \<and>* reps v w [k] \<and>* zero x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3717
  by (unfold assms, rule hoare_skip_or_set_skip)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3718
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3719
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3720
definition "if_reps_z e = (move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3721
                              bone (move_left; jmp e) (move_left)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3722
                             )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3723
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3724
lemma hoare_if_reps_z_true:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3725
  assumes h: "k = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3726
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3727
   "\<lbrace>st i \<and>* ps u \<and>* reps u v [k] \<and>* zero (v + 1)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3728
      i:[if_reps_z e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3729
    \<lbrace>st e \<and>* ps u \<and>* reps u v [k] \<and>* zero (v + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3730
  apply (unfold reps.simps, simp add:sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3731
  apply (rule tm.pre_condI, simp add:h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3732
  apply (unfold if_reps_z_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3733
  apply (simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3734
  apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3735
  apply (rule_tac p = "st j' \<and>* ps (u + 1) \<and>* zero (u + 1) \<and>* one u" in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3736
  apply (rule hoare_bone_1_out)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3737
  by (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3738
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3739
lemma hoare_if_reps_z_true_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3740
  assumes "k = 0" "u = v" "x = w + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3741
  shows "\<lbrace>st i \<and>* ps u \<and>* reps v w [k] \<and>* zero x\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3742
                  i:[if_reps_z e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3743
         \<lbrace>st e \<and>* ps u \<and>* reps v w [k] \<and>* zero x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3744
  by (unfold assms, rule hoare_if_reps_z_true, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3745
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3746
lemma hoare_if_reps_z_false:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3747
  assumes h: "k \<noteq> 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3748
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3749
   "\<lbrace>st i \<and>* ps u \<and>* reps u v [k]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3750
      i:[if_reps_z e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3751
    \<lbrace>st j \<and>* ps u \<and>* reps u v [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3752
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3753
  from h obtain k' where "k = Suc k'" by (metis not0_implies_Suc)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3754
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3755
    apply (unfold `k = Suc k'`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3756
    apply (simp add:sep_conj_cond, rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3757
    apply (unfold if_reps_z_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3758
    apply (simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3759
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3760
    apply (rule_tac p = "st j' \<and>* ps (u + 1) \<and>* one (u + 1) \<and>* one u \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3761
                          ones (2 + u) (u + (1 + int k'))" in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3762
    apply (rule_tac hoare_bone_2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3763
    by (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3764
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3765
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3766
lemma hoare_if_reps_z_false_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3767
  assumes h: "k \<noteq> 0" "u = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3768
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3769
   "\<lbrace>st i \<and>* ps u \<and>* reps v w [k]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3770
      i:[if_reps_z e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3771
    \<lbrace>st j \<and>* ps u \<and>* reps v w [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3772
  by (unfold assms, rule hoare_if_reps_z_false[OF `k \<noteq> 0`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3773
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3774
definition "if_reps_nz e = (move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3775
                              bzero (move_left; jmp e) (move_left)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3776
                           )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3777
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3778
lemma EXS_postI: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3779
  assumes "\<lbrace>P\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3780
            c
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3781
           \<lbrace>Q x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3782
  shows "\<lbrace>P\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3783
          c
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3784
        \<lbrace>EXS x. Q x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3785
by (metis EXS_intro assms tm.hoare_adjust)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3786
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3787
lemma hoare_if_reps_nz_true:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3788
  assumes h: "k \<noteq> 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3789
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3790
   "\<lbrace>st i \<and>* ps u \<and>* reps u v [k]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3791
      i:[if_reps_nz e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3792
    \<lbrace>st e \<and>* ps u \<and>* reps u v [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3793
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3794
  from h obtain k' where "k = Suc k'" by (metis not0_implies_Suc)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3795
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3796
    apply (unfold `k = Suc k'`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3797
    apply (unfold reps.simps, simp add:sep_conj_cond, rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3798
    apply (unfold if_reps_nz_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3799
    apply (simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3800
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3801
    apply (rule_tac p = "st j' \<and>* ps (u + 1) \<and>* one (u + 1) \<and>* one u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3802
                            ones (2 + u) (u + (1 + int k'))" in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3803
    apply (rule hoare_bzero_1_out)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3804
    by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3805
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3806
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3807
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3808
lemma hoare_if_reps_nz_true_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3809
  assumes h: "k \<noteq> 0" "u = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3810
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3811
   "\<lbrace>st i \<and>* ps u \<and>* reps v w [k]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3812
      i:[if_reps_nz e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3813
    \<lbrace>st e \<and>* ps u \<and>* reps v w [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3814
  by (unfold assms, rule hoare_if_reps_nz_true[OF `k\<noteq> 0`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3815
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3816
lemma hoare_if_reps_nz_false:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3817
  assumes h: "k = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3818
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3819
   "\<lbrace>st i \<and>* ps u \<and>* reps u v [k] \<and>* zero (v + 1)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3820
      i:[if_reps_nz e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3821
    \<lbrace>st j \<and>* ps u \<and>* reps u v [k] \<and>* zero (v + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3822
  apply (simp add:h sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3823
  apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3824
  apply (unfold if_reps_nz_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3825
  apply (simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3826
  apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3827
  apply (rule_tac p = "st j' \<and>* ps (u + 1) \<and>*  zero (u + 1) \<and>* one u" in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3828
  apply (rule hoare_bzero_2)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3829
  by (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3830
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3831
lemma hoare_if_reps_nz_false_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3832
  assumes h: "k = 0" "u = v" "x = w + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3833
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3834
   "\<lbrace>st i \<and>* ps u \<and>* reps v w [k] \<and>* zero x\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3835
      i:[if_reps_nz e]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3836
    \<lbrace>st j \<and>* ps u \<and>* reps v w [k] \<and>* zero x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3837
  by (unfold assms, rule hoare_if_reps_nz_false, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3838
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3839
definition "skip_or_sets n = tpg_fold (replicate n skip_or_set)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3840
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3841
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3842
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3843
lemma hoare_skip_or_sets_set:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3844
  shows "\<lbrace>st i \<and>* ps u \<and>* zeros u (u + int (reps_len (replicate (Suc n) 0))) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3845
                                  tm (u + int (reps_len (replicate (Suc n) 0)) + 1) x\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3846
            i:[skip_or_sets (Suc n)]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3847
         \<lbrace>st j \<and>* ps (u + int (reps_len (replicate (Suc n) 0)) + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3848
                     reps' u  (u + int (reps_len (replicate (Suc n) 0))) (replicate (Suc n) 0) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3849
                                 tm (u + int (reps_len (replicate (Suc n) 0)) + 1) x \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3850
proof(induct n arbitrary:i j u x)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3851
  case 0
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3852
  from 0 show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3853
    apply (simp add:reps'_def reps_len_def reps_ctnt_len_def reps_sep_len_def reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3854
    apply (unfold skip_or_sets_def, simp add:tpg_fold_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3855
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3856
    by (auto simp:sep_conj_ac, smt cond_true_eq2 ones.simps sep_conj_left_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3857
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3858
    case (Suc n)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3859
    { fix n
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3860
      have "listsum (replicate n (Suc 0)) = n"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3861
        by (induct n, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3862
    } note eq_sum = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3863
    have eq_len: "\<And>n. n \<noteq> 0 \<Longrightarrow> reps_len (replicate (Suc n) 0) = reps_len (replicate n 0) + 2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3864
      by (simp add:reps_len_def reps_sep_len_def reps_ctnt_len_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3865
    have eq_zero: "\<And> u v. (zeros u (u + int (v + 2))) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3866
           (zeros u (u + (int v)) \<and>* zero (u + (int v) + 1) \<and>* zero (u + (int v) + 2))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3867
      by (smt sep.mult_assoc zeros_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3868
    hence eq_z: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3869
      "zeros u (u + int (reps_len (replicate (Suc (Suc n)) 0)))  = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3870
       (zeros u (u + int (reps_len (replicate (Suc n) 0))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3871
       zero ((u + int (reps_len (replicate (Suc n) 0))) + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3872
       zero ((u + int (reps_len (replicate (Suc n) 0))) + 2))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3873
      " by (simp only:eq_len)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3874
    have hh: "\<And>x. (replicate (Suc (Suc n)) x) = (replicate (Suc n) x) @ [x]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3875
      by (metis replicate_Suc replicate_append_same)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3876
    have hhh: "replicate (Suc n) skip_or_set \<noteq> []" "[skip_or_set] \<noteq> []" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3877
    have eq_code: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3878
          "(i :[ skip_or_sets (Suc (Suc n)) ]: j) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3879
           (i :[ (skip_or_sets (Suc n); skip_or_set) ]: j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3880
    proof(unfold skip_or_sets_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3881
      show "i :[ tpg_fold (replicate (Suc (Suc n)) skip_or_set) ]: j =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3882
               i :[ (tpg_fold (replicate (Suc n) skip_or_set) ; skip_or_set) ]: j"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3883
        apply (insert tpg_fold_app[OF hhh, of i j], unfold hh)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3884
        by (simp only:tpg_fold_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3885
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3886
    have "Suc n \<noteq> 0" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3887
    show ?case 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3888
      apply (unfold eq_z eq_code)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3889
      apply (hstep Suc(1))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3890
      apply (unfold eq_len[OF `Suc n \<noteq> 0`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3891
      apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3892
      apply (auto simp:sep_conj_ac)[1]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3893
      apply (sep_cancel+, prune) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3894
      apply (fwd abs_ones)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3895
      apply ((fwd abs_reps')+, simp add:int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3896
      by (metis replicate_append_same)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3897
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3898
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3899
lemma hoare_skip_or_sets_set_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3900
  assumes h: "p2 = p1" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3901
             "p3 = p1 + int (reps_len (replicate (Suc n) 0))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3902
             "p4 = p3 + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3903
  shows "\<lbrace>st i \<and>* ps p1 \<and>* zeros p2 p3 \<and>* tm p4 x\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3904
            i:[skip_or_sets (Suc n)]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3905
         \<lbrace>st j \<and>* ps p4 \<and>* reps' p2  p3 (replicate (Suc n) 0) \<and>* tm p4 x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3906
  apply (unfold h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3907
  by (rule hoare_skip_or_sets_set)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3908
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3909
declare reps.simps[simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3910
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3911
lemma hoare_skip_or_sets_skip:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3912
  assumes h: "n < length ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3913
  shows "\<lbrace>st i \<and>* ps u \<and>* reps' u v (take n ks) \<and>* reps' (v + 1) w [ks!n] \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3914
            i:[skip_or_sets (Suc n)]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3915
         \<lbrace>st j \<and>* ps (w+1) \<and>* reps' u v (take n ks) \<and>* reps' (v + 1) w [ks!n]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3916
  using h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3917
proof(induct n arbitrary: i j u v w ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3918
  case 0
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3919
  show ?case 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3920
    apply (subst (1 5) reps'_def, simp add:sep_conj_cond, intro tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3921
    apply (unfold skip_or_sets_def, simp add:tpg_fold_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3922
    apply (unfold reps'_def, simp del:reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3923
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3924
    by (sep_cancel+, smt+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3925
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3926
  case (Suc n)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3927
  from `Suc n < length ks` have "n < length ks" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3928
  note h =  Suc(1) [OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3929
  show ?case 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3930
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3931
      from `Suc n < length ks` 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3932
      have eq_take: "take (Suc n) ks = take n ks @ [ks!n]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3933
        by (metis not_less_eq not_less_iff_gr_or_eq take_Suc_conv_app_nth)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3934
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3935
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3936
    apply (subst reps'_append, simp add:sep_conj_exists, rule tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3937
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3938
      have "(i :[ skip_or_sets (Suc (Suc n)) ]: j) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3939
                 (i :[ (skip_or_sets (Suc n); skip_or_set )]: j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3940
      proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3941
        have eq_rep: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3942
          "(replicate (Suc (Suc n)) skip_or_set) = ((replicate (Suc n) skip_or_set) @ [skip_or_set])"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3943
          by (metis replicate_Suc replicate_append_same)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3944
        have "replicate (Suc n) skip_or_set \<noteq> []" "[skip_or_set] \<noteq> []" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3945
        from tpg_fold_app[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3946
        show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3947
          by (unfold skip_or_sets_def eq_rep, simp del:replicate.simps add:tpg_fold_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3948
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3949
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3950
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3951
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3952
       fix i j m 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3953
       have "\<lbrace>st i \<and>* ps u \<and>* (reps' u (m - 1) (take n ks) \<and>* reps' m v [ks ! n])\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3954
                            i :[ (skip_or_sets (Suc n)) ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3955
             \<lbrace>st j \<and>* ps (v + 1) \<and>* (reps' u (m - 1) (take n ks) \<and>* reps' m v [ks ! n])\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3956
                  apply (rule h[THEN tm.hoare_adjust])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3957
                  by (sep_cancel+, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3958
    my_block_end my_note h_c1 = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3959
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3960
      fix j' j m 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3961
      have "\<lbrace>st j' \<and>* ps (v + 1) \<and>* reps' (v + 1) w [ks ! Suc n]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3962
                          j' :[ skip_or_set ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3963
            \<lbrace>st j \<and>* ps (w + 1) \<and>* reps' (v + 1) w [ks ! Suc n]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3964
        apply (unfold reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3965
        apply (rule hoare_skip_or_set_skip[THEN tm.hoare_adjust])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3966
        by (sep_cancel+, smt)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3967
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3968
    apply (hstep h_c1 this)+ 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3969
    by ((fwd abs_reps'), simp, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3970
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3971
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3972
lemma hoare_skip_or_sets_skip_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3973
  assumes h: "n < length ks" "u = v" "x = w + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3974
  shows "\<lbrace>st i \<and>* ps u \<and>* reps' v w (take n ks) \<and>* reps' x y [ks!n] \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3975
            i:[skip_or_sets (Suc n)]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3976
         \<lbrace>st j \<and>* ps (y+1) \<and>* reps' v w (take n ks) \<and>* reps' x y [ks!n]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3977
  by (unfold assms, rule hoare_skip_or_sets_skip[OF `n < length ks`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3978
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3979
lemma fam_conj_interv_simp:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3980
    "(fam_conj {(ia::int)<..} p) = ((p (ia + 1)) \<and>* fam_conj {ia + 1 <..} p)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3981
by (smt Collect_cong fam_conj_insert_simp greaterThan_def 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3982
        greaterThan_eq_iff greaterThan_iff insertI1 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3983
        insert_compr lessThan_iff mem_Collect_eq)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3984
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3985
lemma zeros_fam_conj:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3986
  assumes "u \<le> v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3987
  shows "(zeros u v \<and>* fam_conj {v<..} zero) = fam_conj {u - 1<..} zero"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3988
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3989
  have "{u - 1<..v} ## {v <..}" by (auto simp:set_ins_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3990
  from fam_conj_disj_simp[OF this, symmetric]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3991
  have "(fam_conj {u - 1<..v} zero \<and>* fam_conj {v<..} zero) = fam_conj ({u - 1<..v} + {v<..}) zero" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3992
  moreover 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3993
  from `u \<le> v` have eq_set: "{u - 1 <..} = {u - 1 <..v} + {v <..}" by (auto simp:set_ins_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3994
  moreover have "fam_conj {u - 1<..v} zero = zeros u v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3995
  proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3996
    have "({u - 1<..v}) = ({u .. v})" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3997
    moreover {
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3998
      fix u v 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3999
      assume "u  \<le> (v::int)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4000
      hence "fam_conj {u .. v} zero = zeros u v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4001
      proof(induct rule:ones_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4002
        case (Base i j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4003
        thus ?case by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4004
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4005
        case (Step i j)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4006
        thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4007
        proof(cases "i = j") 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4008
          case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4009
          show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4010
            by (unfold True, simp add:fam_conj_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4011
        next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4012
          case False 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4013
          with `i \<le> j` have hh: "i + 1 \<le> j" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4014
          hence eq_set: "{i..j} = (insert i {i + 1 .. j})"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4015
            by (smt simp_from_to)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4016
          have "i \<notin> {i + 1 .. j}" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4017
          from fam_conj_insert_simp[OF this, folded eq_set]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4018
          have "fam_conj {i..j} zero = (zero i \<and>* fam_conj {i + 1..j} zero)" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4019
          with Step(2)[OF hh] Step
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4020
          show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4021
        qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4022
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4023
    } 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4024
    moreover note this[OF `u  \<le> v`]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4025
    ultimately show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4026
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4027
  ultimately show ?thesis by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4028
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4029
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4030
declare replicate.simps [simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4031
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4032
lemma hoare_skip_or_sets_comb:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4033
  assumes "length ks \<le> n"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4034
  shows "\<lbrace>st i \<and>* ps u \<and>* reps u v ks \<and>* fam_conj {v<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4035
                i:[skip_or_sets (Suc n)]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4036
         \<lbrace>st j \<and>* ps ((v + int (reps_len (list_ext n ks)) - int (reps_len ks))+ 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4037
          reps' u (v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1) (list_ext n ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4038
          fam_conj {(v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1)<..} zero \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4039
proof(cases "ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4040
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4041
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4042
    apply (subst True, simp only:reps.simps sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4043
    apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4044
    apply (rule_tac p = "st i \<and>* ps (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4045
            zeros (v + 1) (v + 1 + int (reps_len (replicate (Suc n) 0))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4046
            tm (v + 2 + int (reps_len (replicate (Suc n) 0))) Bk \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4047
            fam_conj {(v + 2 + int (reps_len (replicate (Suc n) 0)))<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4048
      " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4049
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4050
    apply (auto simp:sep_conj_ac)[1]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4051
    apply (auto simp:sep_conj_ac)[2]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4052
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4053
      from True have "(list_ext n ks) = (replicate (Suc n) 0)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4054
        by (metis append_Nil diff_zero list.size(3) list_ext_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4055
    my_block_end my_note le_red = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4056
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4057
      from True have "(reps_len ks) = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4058
        by (metis reps_len_nil)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4059
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4060
    apply (unfold this le_red, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4061
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4062
      have "v + 2 + int (reps_len (replicate (Suc n) 0)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4063
            v + int (reps_len (replicate (Suc n) 0)) + 2" by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4064
    my_block_end my_note eq_len = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4065
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4066
    apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4067
    apply (fold zero_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4068
    apply (subst fam_conj_interv_simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4069
    apply (simp only:int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4070
    apply (simp only:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4071
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4072
      have "v + 1 \<le> (2 + (v + int (reps_len (replicate (Suc n) 0))))" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4073
      from zeros_fam_conj[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4074
      have "(fam_conj {v<..} zero) = (zeros (v + 1) (2 + (v + int (reps_len (replicate (Suc n) 0)))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4075
                                        fam_conj {2 + (v + int (reps_len (replicate (Suc n) 0)))<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4076
        by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4077
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4078
    apply (subst (asm) this, simp only:int_add_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4079
    by (smt cond_true_eq2 sep.mult_assoc sep.mult_commute 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4080
            sep.mult_left_commute sep_conj_assoc sep_conj_commute 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4081
         sep_conj_left_commute zeros.simps zeros_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4082
next 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4083
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4084
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4085
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4086
      have "(i:[skip_or_sets (Suc n)]:j) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4087
              (i:[(skip_or_sets (length ks);  skip_or_sets (Suc n - length ks))]:j)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4088
        apply (unfold skip_or_sets_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4089
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4090
          have "(replicate (Suc n) skip_or_set) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4091
                   (replicate (length ks) skip_or_set @ (replicate (Suc n - length ks) skip_or_set))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4092
            by (smt assms replicate_add)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4093
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4094
        apply (unfold this, rule tpg_fold_app, simp add:False)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4095
        by (insert `length ks \<le> n`, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4096
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4097
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4098
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4099
      from False have "length ks = (Suc (length ks - 1))" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4100
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4101
    apply (subst (1) this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4102
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4103
      from False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4104
      have "(reps u v ks \<and>* fam_conj {v<..} zero) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4105
            (reps' u (v + 1) ks \<and>* fam_conj {v+1<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4106
        apply (unfold reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4107
        by (subst fam_conj_interv_simp, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4108
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4109
    apply (unfold this) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4110
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4111
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4112
      have "\<lbrace>st i \<and>* ps u \<and>* reps' u (v + 1) ks \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4113
                i :[ skip_or_sets (Suc (length ks - 1))]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4114
            \<lbrace>st j \<and>* ps (v + 2) \<and>* reps' u (v + 1) ks \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4115
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4116
          have "ks = take (length ks - 1) ks @ [ks!(length ks - 1)]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4117
            by (smt False drop_0 drop_eq_Nil id_take_nth_drop)  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4118
        my_block_end my_note eq_ks = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4119
        apply (subst (1) this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4120
        apply (unfold reps'_append, simp add:sep_conj_exists, rule tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4121
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4122
          from False have "(length ks - Suc 0) < length ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4123
            by (smt `length ks = Suc (length ks - 1)`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4124
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4125
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4126
        apply (subst eq_ks, unfold reps'_append, simp only:sep_conj_exists)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4127
        by (rule_tac x = m in EXS_intro, simp add:sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4128
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4129
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4130
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4131
      fix u n
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4132
      have "(fam_conj {u <..} zero) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4133
         (zeros (u + 1) (u + int n + 1) \<and>* tm (u + int n + 2) Bk \<and>* fam_conj {(u + int n + 2)<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4134
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4135
          have "u + 1 \<le> (u + int n + 2)" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4136
          from zeros_fam_conj[OF this, symmetric]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4137
          have "fam_conj {u<..} zero = (zeros (u + 1) (u + int n + 2) \<and>* fam_conj {u + int n + 2<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4138
            by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4139
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4140
        apply (subst this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4141
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4142
          have "(zeros (u + 1) (u + int n + 2)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4143
                   ((zeros (u + 1) (u + int n + 1) \<and>* tm (u + int n + 2) Bk))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4144
            by (smt zero_def zeros_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4145
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4146
        by (unfold this, auto simp:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4147
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4148
    apply (subst (1) this[of _ "(reps_len (replicate (Suc (n - length ks)) 0))"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4149
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4150
      from `length ks \<le> n`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4151
      have "Suc n - length ks = Suc (n - length ks)" by auto 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4152
    my_block_end my_note eq_suc = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4153
    apply (subst this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4154
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4155
    apply (simp add: sep_conj_ac this, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4156
    apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4157
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4158
      have "(int (reps_len (replicate (Suc (n - length ks)) 0))) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4159
            (int (reps_len (list_ext n ks)) - int (reps_len ks) - 1)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4160
        apply (unfold list_ext_def eq_suc)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4161
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4162
          have "replicate (Suc (n - length ks)) 0 \<noteq> []" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4163
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4164
        by (unfold reps_len_split[OF False this], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4165
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4166
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4167
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4168
      from `length ks \<le> n`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4169
      have "(ks @ replicate (Suc (n - length ks)) 0) =  (list_ext n ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4170
        by (unfold list_ext_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4171
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4172
    apply (unfold this, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4173
    apply (subst fam_conj_interv_simp, unfold zero_def, simp, simp add:int_add_ac sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4174
    by (sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4175
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4176
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4177
lemma hoare_skip_or_sets_comb_gen:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4178
  assumes "length ks \<le> n" "u = v" "w = x"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4179
  shows "\<lbrace>st i \<and>* ps u \<and>* reps v w ks \<and>* fam_conj {x<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4180
                i:[skip_or_sets (Suc n)]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4181
         \<lbrace>st j \<and>* ps ((x + int (reps_len (list_ext n ks)) - int (reps_len ks))+ 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4182
          reps' u (x + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1) (list_ext n ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4183
          fam_conj {(x + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1)<..} zero \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4184
  by (unfold assms, rule hoare_skip_or_sets_comb[OF `length ks \<le> n`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4185
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4186
definition "locate n = (skip_or_sets (Suc n);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4187
                        move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4188
                        move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4189
                        left_until_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4190
                        move_right
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4191
                       )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4192
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4193
lemma list_ext_tail_expand:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4194
  assumes h: "length ks \<le> a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4195
  shows "list_ext a ks = take a (list_ext a ks) @ [(list_ext a ks)!a]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4196
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4197
  let ?l = "list_ext a ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4198
  from h have eq_len: "length ?l = Suc a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4199
    by (smt list_ext_len_eq)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4200
  hence "?l \<noteq> []" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4201
  hence "?l = take (length ?l - 1) ?l @ [?l!(length ?l - 1)]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4202
    by (metis `length (list_ext a ks) = Suc a` diff_Suc_1 le_refl 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4203
                    lessI take_Suc_conv_app_nth take_all)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4204
  from this[unfolded eq_len]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4205
  show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4206
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4207
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4208
lemma reps'_nn_expand:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4209
  assumes "xs \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4210
  shows "(reps' u v xs) = (reps u (v - 1) xs \<and>* zero v)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4211
  by (metis assms reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4212
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4213
lemma sep_conj_st1: "(p \<and>* st t \<and>* q) = (st t \<and>* p \<and>* q)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4214
  by (simp only:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4215
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4216
lemma sep_conj_st2: "(p \<and>* st t) = (st t \<and>* p)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4217
  by (simp only:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4218
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4219
lemma sep_conj_st3: "((st t \<and>* p) \<and>* r) = (st t \<and>* p \<and>* r)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4220
  by (simp only:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4221
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4222
lemma sep_conj_st4: "(EXS x. (st t \<and>* r x)) = ((st t) \<and>* (EXS x. r x))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4223
  apply (unfold pred_ex_def, default+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4224
  apply (safe)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4225
  apply (sep_cancel, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4226
  by (auto elim!: sep_conjE intro!:sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4227
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4228
lemmas sep_conj_st = sep_conj_st1 sep_conj_st2 sep_conj_st3 sep_conj_st4
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4229
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4230
lemma sep_conj_cond3 : "(<cond1> \<and>* <cond2>) = <(cond1 \<and> cond2)>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4231
  by (smt cond_eqI cond_true_eq sep_conj_commute sep_conj_empty)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4232
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4233
lemma sep_conj_cond4 : "(<cond1> \<and>* <cond2> \<and>* r) = (<(cond1 \<and> cond2)> \<and>* r)"
17
86918b45b2e6 added a version using finfuns
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  4234
by (metis Hoare_tm2.sep_conj_cond3 sep_conj_assoc)
16
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4235
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4236
lemmas sep_conj_cond = sep_conj_cond3 sep_conj_cond4 sep_conj_cond 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4237
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4238
lemma hoare_left_until_zero_reps: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4239
  "\<lbrace>st i ** ps v ** zero u ** reps (u + 1) v [k]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4240
        i:[left_until_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4241
   \<lbrace>st j ** ps u ** zero u ** reps (u + 1) v [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4242
  apply (unfold reps.simps, simp only:sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4243
  apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4244
  by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4245
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4246
lemma hoare_left_until_zero_reps_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4247
  assumes "u = x" "w = v + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4248
  shows "\<lbrace>st i ** ps u ** zero v ** reps w x [k]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4249
                i:[left_until_zero]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4250
         \<lbrace>st j ** ps v ** zero v ** reps w x [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4251
  by (unfold assms, rule hoare_left_until_zero_reps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4252
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4253
lemma reps_lenE:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4254
  assumes "reps u v ks s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4255
  shows "( <(v = u + int (reps_len ks) - 1)> \<and>* reps u v ks ) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4256
proof(rule condI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4257
  from reps_len_correct[OF assms] show "v = u + int (reps_len ks) - 1" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4258
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4259
  from assms show "reps u v ks s" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4260
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4261
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4262
lemma condI1: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4263
  assumes "p s" "b"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4264
  shows "(<b> \<and>* p) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4265
proof(rule condI[OF assms(2)])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4266
  from  assms(1) show "p s" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4267
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4268
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4269
lemma hoare_locate_set:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4270
  assumes "length ks \<le> n"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4271
  shows "\<lbrace>st i \<and>* zero (u - 1) \<and>* ps u \<and>* reps u v ks \<and>* fam_conj {v<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4272
                i:[locate n]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4273
         \<lbrace>st j \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4274
             (EXS m w. ps m \<and>* reps' u (m - 1) (take n (list_ext n ks)) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4275
                         reps m w [(list_ext n ks)!n] \<and>* fam_conj {w<..} zero)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4276
proof(cases "take n (list_ext n ks) = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4277
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4278
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4279
    apply (unfold locate_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4280
    apply (hstep hoare_skip_or_sets_comb_gen)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4281
    apply (subst (3) list_ext_tail_expand[OF `length ks \<le> n`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4282
    apply (subst (1) reps'_append, simp add:sep_conj_exists)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4283
    apply (rule tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4284
    apply (subst (1) reps'_nn_expand[OF False]) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4285
    apply (rule_tac p = "st j' \<and>* <(m = u + int (reps_len (take n (list_ext n ks))) + 1)> \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4286
            ps (v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4287
            ((reps u (m - 1 - 1) (take n (list_ext n ks)) \<and>* zero (m - 1)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4288
             reps' m (v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4289
              [list_ext n ks ! n]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4290
            fam_conj
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4291
             {v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1<..}
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4292
             zero \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4293
            zero (u - 1)" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4294
      in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4295
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4296
      have "[list_ext n ks ! n] \<noteq> []" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4297
      from reps'_nn_expand[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4298
      have "(reps' m (v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1) [list_ext n ks ! n]) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4299
                (reps m (v + (int (reps_len (list_ext n ks)) - int (reps_len ks))) [list_ext n ks ! n] \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4300
                   zero (v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1))" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4301
        by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4302
    my_block_end 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4303
    apply (subst this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4304
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4305
      have "(fam_conj {v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 1<..} zero) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4306
             (zero (v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4307
              fam_conj {v + int (reps_len (list_ext n ks)) - int (reps_len ks) + 2<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4308
        by (subst fam_conj_interv_simp, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4309
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4310
    apply (unfold this) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4311
    apply (simp only:sep_conj_st)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4312
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4313
    apply (auto simp:sep_conj_ac)[1]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4314
    apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4315
    apply (rule_tac x = m in EXS_intro)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4316
    apply (rule_tac x = "m + int (list_ext n ks ! n)" in EXS_intro)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4317
    apply (simp add:sep_conj_ac del:ones_simps, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4318
    apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4319
    apply (erule_tac condE, clarsimp, simp add:sep_conj_ac int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4320
    apply (fwd abs_reps')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4321
    apply (fwd abs_reps')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4322
    apply (simp add:sep_conj_ac int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4323
    apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4324
    apply (subst (asm) reps'_def, subst fam_conj_interv_simp, subst fam_conj_interv_simp, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4325
           simp add:sep_conj_ac int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4326
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4327
      fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4328
      assume h: "(reps (1 + (u + int (reps_len (take n (list_ext n ks)))))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4329
             (v + (- int (reps_len ks) + int (reps_len (list_ext n ks)))) [list_ext n ks ! n]) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4330
      (is "?P s")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4331
      from reps_len_correct[OF this] list_ext_tail_expand[OF `length ks \<le> n`]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4332
      have hh: "v + (- int (reps_len ks) + 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4333
                    int (reps_len (take n (list_ext n ks) @ [list_ext n ks ! n]))) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4334
                  1 + (u + int (reps_len (take n (list_ext n ks)))) + 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4335
                       int (reps_len [list_ext n ks ! n]) - 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4336
        by metis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4337
      have "[list_ext n ks ! n] \<noteq> []" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4338
      from hh[unfolded reps_len_split[OF False this]]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4339
      have "v  =  u + (int (reps_len ks)) - 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4340
        by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4341
      from condI1[where p = ?P, OF h this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4342
      have "(<(v = u + int (reps_len ks) - 1)> \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4343
             reps (1 + (u + int (reps_len (take n (list_ext n ks)))))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4344
             (v + (- int (reps_len ks) + int (reps_len (list_ext n ks)))) [list_ext n ks ! n]) s" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4345
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4346
    apply (fwd this, (subst (asm) sep_conj_cond)+, erule condE, simp add:sep_conj_ac int_add_ac
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4347
              reps_len_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4348
    apply (fwd reps_lenE, (subst (asm) sep_conj_cond)+, erule condE, simp add:sep_conj_ac int_add_ac
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4349
            reps_len_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4350
    by (fwd reps_lenE, (subst (asm) sep_conj_cond)+, erule condE, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4351
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4352
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4353
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4354
    apply (unfold locate_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4355
    apply (hstep hoare_skip_or_sets_comb)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4356
    apply (subst (3) list_ext_tail_expand[OF `length ks \<le> n`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4357
    apply (subst (1) reps'_append, simp add:sep_conj_exists)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4358
    apply (rule tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4359
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4360
      from True `length ks \<le> n`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4361
      have "ks = []" "n = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4362
        apply (metis le0 le_antisym length_0_conv less_nat_zero_code list_ext_len take_eq_Nil)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4363
        by (smt True length_take list.size(3) list_ext_len)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4364
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4365
    apply (unfold True this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4366
    apply (simp add:reps'_def list_ext_def reps.simps reps_len_def reps_sep_len_def 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4367
                 reps_ctnt_len_def
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4368
      del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4369
    apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4370
    apply (rule tm.pre_condI, simp del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4371
    apply (subst fam_conj_interv_simp, simp add:sep_conj_st del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4372
    apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4373
    apply (auto simp:sep_conj_ac)[1]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4374
    apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4375
    apply (rule_tac x = "(v + int (listsum (replicate (Suc 0) (Suc 0))))" in EXS_intro)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4376
    apply (simp only:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4377
    apply (auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4378
    apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4379
    apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4380
    by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4381
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4382
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4383
lemma hoare_locate_set_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4384
  assumes "length ks \<le> n" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4385
           "u = v - 1" "v = w" "x = y"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4386
  shows "\<lbrace>st i \<and>* zero u \<and>* ps v \<and>* reps w x ks \<and>* fam_conj {y<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4387
                i:[locate n]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4388
         \<lbrace>st j \<and>* zero u \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4389
             (EXS m w. ps m \<and>* reps' v (m - 1) (take n (list_ext n ks)) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4390
                         reps m w [(list_ext n ks)!n] \<and>* fam_conj {w<..} zero)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4391
  by (unfold assms, rule hoare_locate_set[OF `length ks \<le> n`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4392
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4393
lemma hoare_locate_skip: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4394
  assumes h: "n < length ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4395
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4396
   "\<lbrace>st i \<and>* ps u \<and>* zero (u - 1) \<and>* reps' u (v - 1) (take n ks) \<and>* reps' v w [ks!n] \<and>* tm (w + 1) x\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4397
      i:[locate n]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4398
    \<lbrace>st j \<and>* ps v \<and>* zero (u - 1) \<and>* reps' u (v - 1) (take n ks) \<and>* reps' v w [ks!n] \<and>* tm (w + 1) x\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4399
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4400
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4401
    apply (unfold locate_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4402
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4403
    apply (subst (2 4) reps'_def, simp add:reps.simps sep_conj_cond del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4404
    apply (intro tm.pre_condI, simp del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4405
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4406
    apply (case_tac "(take n ks) = []", simp add:reps'_def sep_conj_cond del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4407
    apply (rule tm.pre_condI, simp del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4408
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4409
    apply (simp del:ones_simps add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4410
    by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4411
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4412
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4413
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4414
lemma hoare_locate_skip_gen[step]: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4415
  assumes "n < length ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4416
          "v = u - 1" "w = u" "x = y - 1" "z' = z + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4417
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4418
   "\<lbrace>st i \<and>* ps u \<and>* tm v Bk \<and>* reps' w x (take n ks) \<and>* reps' y z [ks!n] \<and>* tm z' vx\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4419
      i:[locate n]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4420
    \<lbrace>st j \<and>* ps y \<and>* tm v Bk \<and>* reps' w x (take n ks) \<and>* reps' y z [ks!n] \<and>* tm z' vx\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4421
  by (unfold assms, fold zero_def, rule hoare_locate_skip[OF `n < length ks`])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4422
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4423
definition "Inc a = locate a; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4424
                    right_until_zero; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4425
                    move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4426
                    shift_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4427
                    move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4428
                    left_until_double_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4429
                    write_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4430
                    left_until_double_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4431
                    move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4432
                    move_right
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4433
                    "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4434
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4435
lemma ones_int_expand: "(ones m (m + int k)) = (one m \<and>* ones (m + 1) (m + int k))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4436
  by (simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4437
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4438
lemma reps_splitedI:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4439
  assumes h1: "(reps u v ks1 \<and>* zero (v + 1) \<and>* reps (v + 2) w ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4440
  and h2: "ks1 \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4441
  and h3: "ks2 \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4442
  shows "(reps u w (ks1 @ ks2)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4443
proof - 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4444
  from h2 h3
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4445
  have "splited (ks1 @ ks2) ks1 ks2" by (auto simp:splited_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4446
  from h1 obtain s1 where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4447
    "(reps u v ks1) s1" by (auto elim:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4448
  from h1 obtain s2 where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4449
    "(reps (v + 2) w ks2) s2" by (auto elim:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4450
  from reps_len_correct[OF `(reps u v ks1) s1`] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4451
  have eq_v: "v = u + int (reps_len ks1) - 1" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4452
  from reps_len_correct[OF `(reps (v + 2) w ks2) s2`]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4453
  have eq_w: "w = v + 2 + int (reps_len ks2) - 1" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4454
  from h1
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4455
  have "(reps u (u + int (reps_len ks1) - 1) ks1 \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4456
         zero (u + int (reps_len ks1)) \<and>* reps (u + int (reps_len ks1) + 1) w ks2) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4457
    apply (unfold eq_v eq_w[unfolded eq_v])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4458
    by (sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4459
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4460
    by(unfold reps_splited[OF `splited (ks1 @ ks2) ks1 ks2`], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4461
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4462
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4463
lemma reps_sucI:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4464
  assumes h: "(reps u v (xs@[x]) \<and>* one (1 + v)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4465
  shows "(reps u (1 + v) (xs@[Suc x])) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4466
proof(cases "xs = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4467
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4468
  from h obtain s' where "(reps u v (xs@[x])) s'" by (auto elim:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4469
  from reps_len_correct[OF this] have " v = u + int (reps_len (xs @ [x])) - 1" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4470
  with True have eq_v: "v = u + int x" by (simp add:reps_len_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4471
  have eq_one1: "(one (1 + (u + int x)) \<and>* ones (u + 1) (u + int x)) = ones (u + 1) (1 + (u + int x))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4472
    by (smt ones_rev sep.mult_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4473
  from h show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4474
    apply (unfold True, simp add:eq_v reps.simps sep_conj_cond sep_conj_ac ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4475
    by (sep_cancel+, simp add: eq_one1, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4476
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4477
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4478
  from h obtain s1 s2 where hh: "(reps u v (xs@[x])) s1" "s = s1 + s2" "s1 ## s2" "one (1 + v) s2"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4479
    by (auto elim:sep_conjE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4480
  from hh(1)[unfolded reps_rev[OF False]]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4481
  obtain s11 s12 s13 where hhh:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4482
    "(reps u (v - int (x + 1) - 1) xs) s11"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4483
    "(zero (v - int (x + 1))) s12" "(ones (v - int x) v) s13"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4484
    "s11 ## (s12 + s13)" "s12 ## s13" "s1 = s11 + s12 + s13"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4485
    apply (atomize_elim)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4486
    apply(elim sep_conjE)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4487
    apply (rule_tac x = xa in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4488
    apply (rule_tac x = xaa in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4489
    apply (rule_tac x = ya in exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4490
    apply (intro conjI, assumption+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4491
    by (auto simp:set_ins_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4492
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4493
  proof(rule reps_splitedI[where v = "(v - int (x + 1) - 1)"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4494
    show "(reps u (v - int (x + 1) - 1) xs \<and>* zero (v - int (x + 1) - 1 + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4495
                                    reps (v - int (x + 1) - 1 + 2) (1 + v) [Suc x]) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4496
    proof(rule sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4497
      from hhh(1) show "reps u (v - int (x + 1) - 1) xs s11" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4498
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4499
      show "(zero (v - int (x + 1) - 1 + 1) \<and>* reps (v - int (x + 1) - 1 + 2) (1 + v) [Suc x]) (s12 + (s13 + s2))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4500
      proof(rule sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4501
        from hhh(2) show "zero (v - int (x + 1) - 1 + 1) s12" by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4502
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4503
        from hh(4) hhh(3)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4504
        show "reps (v - int (x + 1) - 1 + 2) (1 + v) [Suc x] (s13 + s2)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4505
          apply (simp add:reps.simps del:ones_simps add:ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4506
          by (smt hh(3) hh(4) hhh(4) hhh(5) hhh(6) sep_add_disjD sep_conjI sep_disj_addI1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4507
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4508
        show "s12 ## s13 + s2" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4509
          by (metis hh(3) hhh(4) hhh(5) hhh(6) sep_add_commute sep_add_disjD 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4510
              sep_add_disjI2 sep_disj_addD sep_disj_addD1 sep_disj_addI1 sep_disj_commuteI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4511
      next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4512
        show "s12 + (s13 + s2) = s12 + (s13 + s2)" by metis 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4513
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4514
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4515
      show "s11 ## s12 + (s13 + s2)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4516
        by (metis hh(3) hhh(4) hhh(5) hhh(6) sep_disj_addD1 sep_disj_addI1 sep_disj_addI3)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4517
    next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4518
      show "s = s11 + (s12 + (s13 + s2))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4519
        by (smt hh(2) hh(3) hhh(4) hhh(5) hhh(6) sep_add_assoc sep_add_commute 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4520
             sep_add_disjD sep_add_disjI2 sep_disj_addD1 sep_disj_addD2 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4521
              sep_disj_addI1 sep_disj_addI3 sep_disj_commuteI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4522
    qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4523
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4524
    from False show "xs \<noteq> []" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4525
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4526
    show "[Suc x] \<noteq> []" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4527
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4528
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4529
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4530
lemma cond_expand: "(<cond> \<and>* p) s = (cond \<and> (p s))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4531
  by (metis (full_types) condD pasrt_def sep_conj_commuteI 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4532
             sep_conj_sep_emptyI sep_empty_def sep_globalise)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4533
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4534
lemma ones_rev1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4535
  assumes "\<not> (1 + n) < m"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4536
  shows "(ones m n \<and>* one (1 + n)) = (ones m (1 + n))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4537
  by (insert ones_rev[OF assms, simplified], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4538
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4539
lemma reps_one_abs:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4540
  assumes "(reps u v [k] \<and>* one w) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4541
          "w = v + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4542
  shows "(reps u w [Suc k]) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4543
  using assms unfolding assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4544
  apply (simp add:reps.simps sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4545
  apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4546
  apply (erule condE, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4547
  by (simp add:ones_rev sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4548
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4549
lemma reps'_reps_abs:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4550
  assumes "(reps' u v xs \<and>* reps w x ys) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4551
          "w = v + 1"  "ys \<noteq> []"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4552
  shows "(reps u x (xs@ys)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4553
proof(cases "xs = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4554
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4555
  with assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4556
  have h: "splited (xs@ys) xs ys" by (simp add:splited_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4557
  from assms(1)[unfolded assms(2)]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4558
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4559
    apply (unfold reps_splited[OF h])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4560
    apply (insert False, unfold reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4561
    apply (fwd reps_lenE, (subst (asm) sep_conj_cond)+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4562
    by (erule condE, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4563
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4564
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4565
  with assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4566
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4567
    apply (simp add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4568
    by (erule condE, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4569
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4570
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4571
lemma reps_one_abs1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4572
  assumes "(reps u v (xs@[k]) \<and>* one w) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4573
          "w = v + 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4574
  shows "(reps u w (xs@[Suc k])) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4575
proof(cases "xs = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4576
  case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4577
  with assms reps_one_abs
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4578
  show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4579
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4580
  case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4581
  hence "splited (xs@[k]) xs [k]" by (simp add:splited_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4582
  from assms(1)[unfolded reps_splited[OF this] assms(2)]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4583
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4584
    apply (fwd reps_one_abs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4585
    apply (fwd reps_reps'_abs) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4586
    apply (fwd reps'_reps_abs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4587
    by (simp add:assms)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4588
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4589
  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4590
lemma tm_hoare_inc00: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4591
  assumes h: "a < length ks \<and> ks ! a = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4592
  shows "\<lbrace>st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u ia ks \<and>* fam_conj {ia<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4593
    i :[ Inc a ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4594
    \<lbrace>st j \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4595
     ps u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4596
     zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4597
     zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4598
     reps u (ia + int (reps_len (list_ext a ks)) - int (reps_len ks) + 1) (ks[a := Suc v]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4599
     fam_conj {(ia + int (reps_len (list_ext a ks)) - int (reps_len ks) + 1)<..} zero\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4600
  (is "\<lbrace> ?P \<rbrace> ?code \<lbrace> ?Q \<rbrace>")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4601
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4602
  from h have "a < length ks" "ks ! a = v" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4603
  from list_nth_expand[OF `a < length ks`]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4604
  have eq_ks: "ks = take a ks @ [ks!a] @ drop (Suc a) ks" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4605
  from `a < length ks` have "ks \<noteq> []" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4606
  hence "(reps u ia ks \<and>* zero (ia + 1)) = reps' u (ia + 1) ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4607
    by (simp add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4608
  also from eq_ks have "\<dots> = reps' u (ia + 1) (take a ks @ [ks!a] @ drop (Suc a) ks)" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4609
  also have "\<dots>  = (EXS m. reps' u (m - 1) (take a ks) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4610
                     reps' m (ia + 1) (ks ! a # drop (Suc a) ks))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4611
    by (simp add:reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4612
  also have "\<dots> = (EXS m. reps' u (m - 1) (take a ks) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4613
                     reps' m (ia + 1) ([ks ! a] @ drop (Suc a) ks))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4614
    by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4615
  also have "\<dots> = (EXS m ma. reps' u (m - 1) (take a ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4616
                       reps' m (ma - 1) [ks ! a] \<and>* reps' ma (ia + 1) (drop (Suc a) ks))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4617
    by (simp only:reps'_append sep_conj_exists)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4618
  finally have eq_s: "(reps u ia ks \<and>* zero (ia + 1)) = \<dots>" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4619
  { fix m ma
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4620
    have eq_u: "-1 + u = u - 1" by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4621
    have " \<lbrace>st i \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4622
            ps u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4623
            zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4624
            zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4625
            (reps' u (m - 1) (take a ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4626
             reps' m (ma - 1) [ks ! a] \<and>* reps' ma (ia + 1) (drop (Suc a) ks)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4627
            fam_conj {ia + 1<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4628
           i :[ Inc a ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4629
           \<lbrace>st j \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4630
            ps u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4631
            zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4632
            zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4633
            reps u (ia + int (reps_len (list_ext a ks)) - int (reps_len ks) + 1) (ks[a := Suc v]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4634
            fam_conj {ia + int (reps_len (list_ext a ks)) - int (reps_len ks) + 1<..} zero\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4635
    proof(cases "(drop (Suc a) ks) = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4636
      case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4637
      { fix hc
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4638
        have eq_1: "(1 + (m + int (ks ! a))) = (m + int (ks ! a) + 1)" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4639
        have eq_2: "take a ks @ [Suc (ks ! a)] = ks[a := Suc v]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4640
          apply (subst (3) eq_ks, unfold True, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4641
          by (metis True append_Nil2 eq_ks h upd_conv_take_nth_drop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4642
        assume h: "(fam_conj {1 + (m + int (ks ! a))<..} zero \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4643
                      reps u (1 + (m + int (ks ! a))) (take a ks @ [Suc (ks ! a)])) hc"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4644
        hence "(fam_conj {m + int (ks ! a) + 1<..} zero \<and>* reps u (m + int (ks ! a) + 1) (ks[a := Suc v])) hc"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4645
          by (unfold eq_1 eq_2 , sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4646
      } note eq_fam = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4647
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4648
        apply (unfold Inc_def, subst (3) reps'_def, simp add:True sep_conj_cond)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4649
        apply (intro tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4650
        apply (subst fam_conj_interv_simp, simp, subst (3) zero_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4651
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4652
        apply (subst reps'_sg, simp add:sep_conj_cond del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4653
        apply (rule tm.pre_condI, simp del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4654
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4655
        apply (rule_tac p = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4656
          st j' \<and>* ps (1 + (m + int (ks ! a))) \<and>* zero (u - 1) \<and>* zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4657
                   reps u (1 + (m + int (ks ! a))) (take a ks @ [Suc (ks!a)]) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4658
                            \<and>* fam_conj {1 + (m + int (ks ! a))<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4659
          " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4660
        apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4661
        apply (simp add:sep_conj_ac list_ext_lt[OF `a < length ks`], sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4662
        apply (fwd eq_fam, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4663
        apply (simp del:ones_simps add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4664
        apply (sep_cancel+, prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4665
        apply ((fwd abs_reps')+, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4666
        apply (fwd reps_one_abs abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4667
        apply (subst (asm) reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4668
        by (subst fam_conj_interv_simp, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4669
    next 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4670
      case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4671
      then obtain k' ks' where eq_drop: "drop (Suc a) ks = [k']@ks'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4672
        by (metis append_Cons append_Nil list.exhaust)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4673
      from `a < length ks`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4674
      have eq_ks: "ks[a := Suc v] = (take a ks @ [Suc (ks ! a)]) @ (drop (Suc a) ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4675
        apply (fold `ks!a = v`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4676
        by (metis append_Cons append_Nil append_assoc upd_conv_take_nth_drop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4677
      show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4678
        apply (unfold Inc_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4679
        apply (unfold Inc_def eq_drop reps'_append, simp add:sep_conj_exists del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4680
        apply (rule tm.precond_exI, subst (2) reps'_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4681
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4682
        apply (subst (1) ones_int_expand)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4683
        apply (rule tm.pre_condI, simp del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4684
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4685
        (* apply (hsteps hoare_locate_skip_gen[OF `a < length ks`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4686
        apply (subst reps'_sg, simp add:sep_conj_cond del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4687
        apply (rule tm.pre_condI, simp del:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4688
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4689
        apply (rule_tac p = "st j' \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4690
                ps (2 + (m + int (ks ! a))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4691
                reps (2 + (m + int (ks ! a))) ia (drop (Suc a) ks) \<and>* zero (ia + 1) \<and>* zero (ia + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4692
                reps u (m + int (ks ! a)) (take a ks @ [ks!a]) \<and>* zero (1 + (m + int (ks ! a))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4693
                zero (u - 2) \<and>* zero (u - 1) \<and>* fam_conj {ia + 2<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4694
          " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4695
        apply (hsteps hoare_shift_right_cons_gen[OF False]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4696
                hoare_left_until_double_zero_gen[OF False])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4697
        apply (rule_tac p = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4698
          "st j' \<and>* ps (1 + (m + int (ks ! a))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4699
          zero (u - 2) \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4700
          reps u (1 + (m + int (ks ! a))) (take a ks @ [Suc (ks ! a)]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4701
          zero (2 + (m + int (ks ! a))) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4702
          reps (3 + (m + int (ks ! a))) (ia + 1) (drop (Suc a) ks) \<and>* fam_conj {ia + 1<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4703
          " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4704
        apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4705
        apply (simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4706
        apply (unfold list_ext_lt[OF `a < length ks`], simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4707
        apply (fwd abs_reps')+ 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4708
        apply(fwd reps'_reps_abs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4709
        apply (subst eq_ks, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4710
        apply (sep_cancel+) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4711
        apply (thin_tac "mb = 4 + (m + (int (ks ! a) + int k'))")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4712
        apply (thin_tac "ma = 2 + (m + int (ks ! a))", prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4713
        apply (simp add: int_add_ac sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4714
        apply (fwd reps_one_abs1, subst fam_conj_interv_simp, simp, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4715
        apply (fwd abs_ones)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4716
        apply (fwd abs_reps')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4717
        apply (fwd abs_reps')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4718
        apply (fwd abs_reps')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4719
        apply (fwd abs_reps')
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4720
        apply (unfold eq_drop, simp add:int_add_ac sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4721
        apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4722
        apply (fwd  reps'_abs[where xs = "take a ks"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4723
        apply (fwd reps'_abs[where xs = "[k']"])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4724
        apply (unfold reps'_def, simp add:int_add_ac sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4725
        apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4726
        by (subst (asm) fam_conj_interv_simp, simp, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4727
      qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4728
  } note h = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4729
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4730
    apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4731
    apply (rule_tac p = "st i \<and>*  ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4732
                              (reps u ia ks \<and>* zero (ia + 1)) \<and>* fam_conj {ia + 1<..} zero" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4733
      in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4734
    apply (unfold eq_s, simp only:sep_conj_exists)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4735
    apply (intro tm.precond_exI h)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4736
    by (sep_cancel+, unfold eq_s, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4737
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4738
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4739
declare ones_simps [simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4740
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4741
lemma tm_hoare_inc01:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4742
  assumes "length ks \<le> a \<and> v = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4743
  shows 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4744
   "\<lbrace>st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u ia ks \<and>* fam_conj {ia<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4745
       i :[ Inc a ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4746
    \<lbrace>st j \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4747
     ps u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4748
     zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4749
     zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4750
     reps u (ia + int (reps_len (list_ext a ks)) - int (reps_len ks) + 1) ((list_ext a ks)[a := Suc v]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4751
     fam_conj {(ia + int (reps_len (list_ext a ks)) - int (reps_len ks) + 1)<..} zero\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4752
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4753
  from assms have "length ks \<le> a" "v = 0" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4754
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4755
    apply (rule_tac p = "
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4756
      st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* (reps u ia ks \<and>* <(ia = u + int (reps_len ks) - 1)>) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4757
             fam_conj {ia<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4758
      " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4759
    apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4760
    apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4761
    apply (unfold Inc_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4762
    apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4763
    (* apply (hstep hoare_locate_set_gen[OF `length ks \<le> a`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4764
    apply (simp only:sep_conj_exists)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4765
    apply (intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4766
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4767
      fix m w
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4768
      have "reps m w [list_ext a ks ! a] =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4769
            (ones m (m + int (list_ext a ks ! a)) \<and>* <(w = m + int (list_ext a ks ! a))>)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4770
        by (simp add:reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4771
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4772
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4773
    apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4774
    apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4775
    apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4776
    apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4777
    apply (subst fam_conj_interv_simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4778
    apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4779
    apply (rule_tac p = "st j' \<and>* ps (m + int (list_ext a ks ! a) + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4780
                           zero (u - 2) \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4781
                           reps u (m + int (list_ext a ks ! a) + 1) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4782
                                ((take a (list_ext a ks))@[Suc (list_ext a ks ! a)]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4783
                           fam_conj {(m + int (list_ext a ks ! a) + 1)<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4784
                         " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4785
    apply (hsteps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4786
    apply (simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4787
    apply (unfold `v = 0`, prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4788
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4789
      from `length ks \<le> a` have "list_ext a ks ! a = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4790
        by (metis le_refl list_ext_tail)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4791
      from `length ks \<le> a` have "a < length (list_ext a ks)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4792
        by (metis list_ext_len)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4793
      from reps_len_suc[OF this] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4794
      have eq_len: "int (reps_len (list_ext a ks)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4795
                        int (reps_len (list_ext a ks[a := Suc (list_ext a ks ! a)])) - 1" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4796
        by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4797
      fix m w hc
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4798
      assume h: "(fam_conj {m + int (list_ext a ks ! a) + 1<..} zero \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4799
                 reps u (m + int (list_ext a ks ! a) + 1) (take a (list_ext a ks) @ [Suc (list_ext a ks ! a)]))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4800
                 hc"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4801
      then obtain s where 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4802
        "(reps u (m + int (list_ext a ks ! a) + 1) (take a (list_ext a ks) @ [Suc (list_ext a ks ! a)])) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4803
        by (auto dest!:sep_conjD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4804
      from reps_len_correct[OF this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4805
      have "m  = u + int (reps_len (take a (list_ext a ks) @ [Suc (list_ext a ks ! a)])) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4806
                        - int (list_ext a ks ! a) - 2" by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4807
      from h [unfolded this]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4808
      have "(fam_conj {u + int (reps_len (list_ext a ks))<..} zero \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4809
           reps u (u + int (reps_len (list_ext a ks))) (list_ext a ks[a := Suc 0]))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4810
           hc"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4811
        apply (unfold eq_len, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4812
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4813
          from `a < length (list_ext a ks)`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4814
          have "take a (list_ext a ks) @ [Suc (list_ext a ks ! a)] = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4815
                list_ext a ks[a := Suc (list_ext a ks ! a)]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4816
            by (smt `list_ext a ks ! a = 0` assms length_take list_ext_tail_expand list_update_length)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4817
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4818
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4819
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4820
          have "-1 + (u + int (reps_len (list_ext a ks[a := Suc (list_ext a ks ! a)]))) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4821
                u + (int (reps_len (list_ext a ks[a := Suc (list_ext a ks ! a)])) - 1)" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4822
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4823
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4824
        apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4825
        by (unfold `(list_ext a ks ! a) = 0`, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4826
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4827
    apply (rule this, assumption)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4828
    apply (simp only:sep_conj_ac, sep_cancel+)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4829
    apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4830
    apply (fwd reps_one_abs) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4831
    apply (fwd reps'_reps_abs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4832
    apply (simp add:int_add_ac sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4833
    apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4834
    apply (subst fam_conj_interv_simp, simp add:sep_conj_ac, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4835
    apply (fwd reps_lenE, (subst (asm) sep_conj_cond)+, erule condE, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4836
    by (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4837
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4838
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4839
definition "Dec a e  = (TL continue. 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4840
                          (locate a; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4841
                           if_reps_nz continue;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4842
                           left_until_double_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4843
                           move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4844
                           move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4845
                           jmp e);
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4846
                          (TLabel continue;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4847
                           right_until_zero; 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4848
                           move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4849
                           write_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4850
                           move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4851
                           move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4852
                           shift_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4853
                           move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4854
                           move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4855
                           move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4856
                           left_until_double_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4857
                           move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4858
                           move_right))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4859
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4860
lemma cond_eq: "((<b> \<and>* p) s) = (b \<and> (p s))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4861
proof
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4862
  assume "(<b> \<and>* p) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4863
  from condD[OF this] show " b \<and> p s" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4864
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4865
  assume "b \<and> p s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4866
  hence b and "p s" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4867
  from `b` have "(<b>) 0" by (auto simp:pasrt_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4868
  moreover have "s = 0 + s" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4869
  moreover have "0 ## s" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4870
  moreover note `p s`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4871
  ultimately show "(<b> \<and>* p) s" by (auto intro!:sep_conjI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4872
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4873
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4874
lemma tm_hoare_dec_fail00:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4875
  assumes "a < length ks \<and> ks ! a = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4876
  shows "\<lbrace>st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u ia ks \<and>* fam_conj {ia<..} zero\<rbrace>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4877
             i :[ Dec a e ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4878
         \<lbrace>st e \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4879
          reps u (ia + int (reps_len (list_ext a ks)) - int (reps_len ks)) (list_ext a ks[a := 0]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4880
          fam_conj {ia + int (reps_len (list_ext a ks)) - int (reps_len ks) <..} zero\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4881
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4882
  from assms have "a < length ks" "ks!a = 0" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4883
  from list_nth_expand[OF `a < length ks`]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4884
  have eq_ks: "ks = take a ks @ [ks ! a] @ drop (Suc a) ks" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4885
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4886
  proof(cases " drop (Suc a) ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4887
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4888
    then obtain k' ks' where eq_drop: "drop (Suc a) ks = [k']@ks'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4889
      by (metis append_Cons append_Nil list.exhaust)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4890
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4891
      apply (unfold Dec_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4892
      apply (subst tassemble_to.simps(2), rule tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4893
      apply (subst (1) eq_ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4894
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4895
        have "(reps u ia (take a ks @ [ks ! a] @ drop (Suc a) ks) \<and>* fam_conj {ia<..} zero) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4896
              (reps' u (ia + 1) ((take a ks @ [ks ! a]) @ drop (Suc a) ks) \<and>* fam_conj {ia + 1<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4897
          apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4898
          by (unfold reps'_def, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4899
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4900
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4901
      apply (subst reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4902
      apply (unfold eq_drop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4903
      apply (subst (2) reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4904
      apply (simp only:sep_conj_exists, intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4905
      apply (subst (2) reps'_def, simp add:reps.simps ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4906
      apply (subst reps'_append, simp only:sep_conj_exists, intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4907
      apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4908
      (* apply (hstep hoare_locate_skip_gen[OF `a < length ks`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4909
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4910
        fix m mb
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4911
        have "(reps' mb (m - 1) [ks ! a]) = (reps mb (m - 2) [ks!a] \<and>* zero (m - 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4912
          by (simp add:reps'_def, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4913
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4914
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4915
      apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4916
      (* apply (hstep hoare_if_reps_nz_false_gen[OF `ks!a = 0`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4917
      apply (simp only:reps.simps(2), simp add:`ks!a = 0`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4918
      apply (rule_tac p = "st j'b \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4919
        ps mb \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4920
        reps u mb ((take a ks)@[ks ! a]) \<and>* <(m - 2 = mb)> \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4921
        zero (m - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4922
        zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4923
        one m \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4924
        zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4925
        ones (m + 1) (m + int k') \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4926
        <(-2 + ma = m + int k')> \<and>* zero (ma - 1) \<and>* reps' ma (ia + 1) ks' \<and>* fam_conj {ia + 1<..} zero"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4927
        in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4928
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4929
      apply (simp add:sep_conj_ac, sep_cancel+) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4930
      apply (subgoal_tac "m + int k' = ma - 2", simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4931
      apply (fwd abs_ones)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4932
      apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4933
      apply (erule condE, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4934
      apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4935
      apply (subgoal_tac "ma = m + int k' + 2", simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4936
      apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4937
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4938
        from `a < length ks`
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4939
        have "list_ext a ks = ks" by (auto simp:list_ext_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4940
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4941
      apply (simp add:this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4942
      apply (subst eq_ks, simp add:eq_drop `ks!a = 0`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4943
      apply (subst (asm) reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4944
      apply (subst fam_conj_interv_simp, simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4945
      apply (metis append_Cons assms eq_Nil_appendI eq_drop eq_ks list_update_id)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4946
      apply (clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4947
      apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4948
      apply (erule condE, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4949
      apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4950
      apply (erule condE, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4951
      apply (simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4952
      apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4953
      by (fwd reps'_reps_abs, simp add:`ks!a = 0`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4954
  next 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4955
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4956
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4957
      apply (unfold Dec_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4958
      apply (subst tassemble_to.simps(2), rule tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4959
      apply (subst (1) eq_ks, unfold True, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4960
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4961
        have "(reps u ia (take a ks @ [ks ! a]) \<and>* fam_conj {ia<..} zero) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4962
              (reps' u (ia + 1) (take a ks @ [ks ! a]) \<and>* fam_conj {ia + 1<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4963
          apply (unfold reps'_def, subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4964
          by (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4965
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4966
      apply (subst (1) this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4967
      apply (subst reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4968
      apply (simp only:sep_conj_exists, intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4969
      apply (subst fam_conj_interv_simp, simp) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4970
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4971
        have "(zero (2 + ia)) = (tm (2 + ia) Bk)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4972
          by (simp add:zero_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4973
      my_block_end my_note eq_z = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4974
      apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4975
      (* apply (hstep hoare_locate_skip_gen[OF `a < length ks`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4976
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4977
        fix m 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4978
        have "(reps' m (ia + 1) [ks ! a]) = (reps m ia [ks!a] \<and>* zero (ia + 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4979
          by (simp add:reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4980
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4981
      apply (unfold this, prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4982
      apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4983
      (* apply (hstep hoare_if_reps_nz_false_gen[OF `ks!a = 0`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4984
      apply (simp only:reps.simps(2), simp add:`ks!a = 0`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4985
      apply (rule_tac p = "st j'b \<and>* ps m \<and>* (reps u m ((take a ks)@[ks!a]) \<and>* <(ia = m)>) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4986
                              \<and>* zero (ia + 1) \<and>* zero (u - 1) \<and>*  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4987
                              zero (2 + ia) \<and>* zero (u - 2) \<and>* fam_conj {2 + ia<..} zero"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4988
        in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4989
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4990
      apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4991
      apply ((subst (asm) sep_conj_cond)+, erule condE, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4992
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4993
        from `a < length ks`  have "list_ext a ks = ks" by (metis list_ext_lt) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4994
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4995
      apply (unfold this, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4996
      apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4997
      apply (subst fam_conj_interv_simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4998
      apply (simp only:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4999
      apply (subst eq_ks, unfold True `ks!a = 0`, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5000
      apply (metis True append_Nil2 assms eq_ks list_update_same_conv) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5001
      apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5002
      apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5003
      apply (erule condE, simp, thin_tac "ia = m")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5004
      apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5005
      apply (simp add:sep_conj_ac int_add_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5006
      apply (unfold reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5007
      by (metis sep.mult_commute)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5008
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5009
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5010
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5011
lemma tm_hoare_dec_fail01:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5012
  assumes "length ks \<le> a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5013
  shows "\<lbrace>st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u ia ks \<and>* fam_conj {ia<..} zero\<rbrace>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5014
                       i :[ Dec a e ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5015
         \<lbrace>st e \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5016
          reps u (ia + int (reps_len (list_ext a ks)) - int (reps_len ks)) (list_ext a ks[a := 0]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5017
          fam_conj {ia + int (reps_len (list_ext a ks)) - int (reps_len ks) <..} zero\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5018
  apply (unfold Dec_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5019
  apply (subst tassemble_to.simps(2), rule tm.code_exI, rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5020
  apply (rule_tac p = "st i \<and>* ps u \<and>* zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5021
                       zero (u - 1) \<and>* reps u ia ks \<and>* fam_conj {ia<..} zero \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5022
                       <(ia = u + int (reps_len ks) - 1)>" in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5023
  apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5024
  (* apply (hstep hoare_locate_set_gen[OF `length ks \<le> a`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5025
  apply (simp only:sep_conj_exists, intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5026
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5027
    from assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5028
    have "list_ext a ks ! a = 0" by (metis le_refl list_ext_tail) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5029
  my_block_end my_note is_z = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5030
  apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5031
  apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5032
  (* apply (hstep hoare_if_reps_nz_false_gen[OF is_z]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5033
  apply (unfold is_z)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5034
  apply (subst (1) reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5035
  apply (rule_tac p = "st j'b \<and>* ps m \<and>*  reps u m (take a (list_ext a ks) @ [0]) \<and>* zero (w + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5036
                         <(w = m + int 0)> \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5037
                         fam_conj {w + 1<..} zero \<and>* zero (u - 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5038
                         <(ia = u + int (reps_len ks) - 1)>" in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5039
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5040
    have "(take a (list_ext a ks)) @ [0] \<noteq> []" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5041
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5042
  apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5043
  (* apply (hsteps hoare_left_until_double_zero_gen[OF this]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5044
  apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5045
  apply prune
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5046
  apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5047
  apply (elim condE, simp add:sep_conj_ac, prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5048
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5049
    fix m w ha
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5050
    assume h1: "w = m \<and> ia = u + int (reps_len ks) - 1"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5051
      and  h: "(ps u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5052
              st e \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5053
              zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5054
              zero (m + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5055
              fam_conj {m + 1<..} zero \<and>* zero (u - 2) \<and>* reps u m (take a (list_ext a ks) @ [0])) ha"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5056
    from h1 have eq_w: "w = m" and eq_ia: "ia = u + int (reps_len ks) - 1" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5057
    from h obtain s' where "reps u m (take a (list_ext a ks) @ [0]) s'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5058
      by (auto dest!:sep_conjD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5059
    from reps_len_correct[OF this] 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5060
    have eq_m: "m = u + int (reps_len (take a (list_ext a ks) @ [0])) - 1" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5061
    from h[unfolded eq_m, simplified]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5062
    have "(ps u \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5063
                st e \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5064
                zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5065
                zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5066
                fam_conj {u + (-1 + int (reps_len (list_ext a ks)))<..} zero \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5067
                reps u (u + (-1 + int (reps_len (list_ext a ks)))) (list_ext a ks[a := 0])) ha"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5068
      apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5069
      apply (subst fam_conj_interv_simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5070
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5071
        from `length ks \<le> a` have "list_ext a ks[a := 0] = list_ext a ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5072
          by (metis is_z list_update_id)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5073
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5074
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5075
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5076
        from `length ks \<le> a` is_z 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5077
        have "take a (list_ext a ks) @ [0] = list_ext a ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5078
          by (metis list_ext_tail_expand)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5079
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5080
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5081
      by (simp add:sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5082
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5083
  apply (rule this, assumption)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5084
  apply (sep_cancel+)[1]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5085
  apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5086
  apply (erule condE, prune, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5087
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5088
    fix s m
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5089
    assume "(reps' u (m - 1) (take a (list_ext a ks)) \<and>* ones m m \<and>* zero (m + 1)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5090
    hence "reps' u (m + 1) (take a (list_ext a ks) @ [0]) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5091
      apply (unfold reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5092
      apply (rule_tac x = m in EXS_intro)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5093
      by (subst (2) reps'_def, simp add:reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5094
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5095
  apply (rotate_tac 1, fwd this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5096
  apply (subst (asm) reps'_def, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5097
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5098
    fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5099
    assume h: "(st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5100
                   reps u ia ks \<and>* fam_conj {ia<..} zero) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5101
    then obtain s' where "reps u ia ks s'" by (auto dest!:sep_conjD)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5102
    from reps_len_correct[OF this] have eq_ia: "ia = u + int (reps_len ks) - 1" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5103
    from h
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5104
    have "(st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u ia ks \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5105
           fam_conj {ia<..} zero \<and>* <(ia = u + int (reps_len ks) - 1)>) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5106
      by (unfold eq_ia, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5107
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5108
  by (rule this, assumption)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5109
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5110
lemma t_hoare_label1: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5111
      "(\<And>l. l = i \<Longrightarrow> \<lbrace>st l \<and>* p\<rbrace>  l :[ c l ]: j \<lbrace>st k \<and>* q\<rbrace>) \<Longrightarrow>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5112
             \<lbrace>st l \<and>* p \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5113
               i:[(TLabel l; c l)]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5114
             \<lbrace>st k \<and>* q\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5115
by (unfold tassemble_to.simps, intro tm.code_exI tm.code_condI, clarify, auto)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5116
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5117
lemma tm_hoare_dec_fail1:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5118
  assumes "a < length ks \<and> ks ! a = 0 \<or> length ks \<le> a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5119
  shows "\<lbrace>st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u ia ks \<and>* fam_conj {ia<..} zero\<rbrace>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5120
                      i :[ Dec a e ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5121
         \<lbrace>st e \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5122
          reps u (ia + int (reps_len (list_ext a ks)) - int (reps_len ks)) (list_ext a ks[a := 0]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5123
         fam_conj {ia + int (reps_len (list_ext a ks)) - int (reps_len ks) <..} zero\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5124
  using assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5125
proof
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5126
  assume "a < length ks \<and> ks ! a = 0"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5127
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5128
    by (rule tm_hoare_dec_fail00)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5129
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5130
  assume "length ks \<le> a"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5131
  thus ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5132
    by (rule tm_hoare_dec_fail01)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5133
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5134
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5135
lemma shift_left_nil_gen[step]:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5136
  assumes "u = v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5137
  shows "\<lbrace>st i \<and>* ps u \<and>* zero v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5138
              i :[shift_left]:j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5139
         \<lbrace>st j \<and>* ps u \<and>* zero v\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5140
 apply(unfold assms shift_left_def, intro t_hoare_local t_hoare_label, clarify, 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5141
                 rule t_hoare_label_last, simp, clarify, prune, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5142
 by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5143
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5144
lemma tm_hoare_dec_suc1: 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5145
  assumes "a < length ks \<and> ks ! a = Suc v"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5146
  shows "\<lbrace>st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u ia ks \<and>* fam_conj {ia<..} zero\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5147
                    i :[ Dec a e ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5148
         \<lbrace>st j \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5149
             reps u (ia - 1) (list_ext a ks[a := v]) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5150
             fam_conj {ia - 1<..} zero\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5151
proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5152
  from assms have "a < length ks" " ks ! a = Suc v" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5153
  from list_nth_expand[OF `a < length ks`]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5154
  have eq_ks: "ks = take a ks @ [ks ! a] @ drop (Suc a) ks" .
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5155
  show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5156
  proof(cases " drop (Suc a) ks = []")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5157
    case False
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5158
    then obtain k' ks' where eq_drop: "drop (Suc a) ks = [k']@ks'"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5159
      by (metis append_Cons append_Nil list.exhaust)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5160
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5161
      apply (unfold Dec_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5162
      apply (subst tassemble_to.simps(2), rule tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5163
      apply (subst (1) eq_ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5164
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5165
        have "(reps u ia (take a ks @ [ks ! a] @ drop (Suc a) ks) \<and>* fam_conj {ia<..} zero) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5166
              (reps' u (ia + 1) ((take a ks @ [ks ! a]) @ drop (Suc a) ks) \<and>* fam_conj {ia + 1<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5167
          apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5168
          by (unfold reps'_def, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5169
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5170
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5171
      apply (subst reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5172
      apply (unfold eq_drop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5173
      apply (subst (2) reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5174
      apply (simp only:sep_conj_exists, intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5175
      apply (subst (2) reps'_def, simp add:reps.simps ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5176
      apply (subst reps'_append, simp only:sep_conj_exists, intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5177
      apply (rule_tac q =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5178
       "st l \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5179
        ps mb \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5180
        zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5181
        reps' u (mb - 1) (take a ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5182
        reps' mb (m - 1) [ks ! a] \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5183
        one m \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5184
        zero (u - 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5185
        ones (m + 1) (m + int k') \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5186
        <(-2 + ma = m + int k')> \<and>* zero (ma - 1) \<and>* reps' ma (ia + 1) ks' \<and>* fam_conj {ia + 1<..} zero"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5187
      in tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5188
      apply (rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5189
      apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5190
      (* apply (hstep hoare_locate_skip_gen[OF `a < length ks`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5191
      apply (subst (2) reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5192
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5193
        fix i j l m mb
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5194
        from `ks!a = (Suc v)` have "ks!a \<noteq> 0" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5195
        from hoare_if_reps_nz_true[OF this, where u = mb and v = "m - 2"]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5196
        have "\<lbrace>st i \<and>* ps mb \<and>* reps mb (-2 + m) [ks ! a]\<rbrace>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5197
                        i :[ if_reps_nz l ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5198
              \<lbrace>st l \<and>* ps mb \<and>* reps mb (-2 + m) [ks ! a]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5199
          by smt
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5200
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5201
      apply (hgoto this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5202
      apply (simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5203
      apply (subst reps'_def, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5204
      apply (rule tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5205
      apply (rule t_hoare_label1, simp, prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5206
      apply (subst (2) reps'_def, simp add:reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5207
      apply (rule_tac p = "st j' \<and>* ps mb \<and>* zero (u - 1) \<and>* reps' u (mb - 1) (take a ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5208
        ((ones mb (mb + int (ks ! a)) \<and>* <(-2 + m = mb + int (ks ! a))>) \<and>* zero (mb + int (ks ! a) + 1)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5209
          one (mb + int (ks ! a) + 2) \<and>* zero (u - 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5210
          ones (mb + int (ks ! a) + 3) (mb + int (ks ! a) + int k' + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5211
        <(-2 + ma = m + int k')> \<and>* zero (ma - 1) \<and>* reps' ma (ia + 1) ks' \<and>* fam_conj {ia + 1<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5212
        " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5213
      apply hsteps 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5214
      (* apply (simp add:sep_conj_ac) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5215
      apply (unfold `ks!a = Suc v`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5216
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5217
        fix mb
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5218
        have "(ones mb (mb + int (Suc v))) = (ones mb (mb + int v) \<and>* one (mb + int (Suc v)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5219
          by (simp add:ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5220
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5221
      apply (unfold this, prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5222
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5223
      apply (rule_tac p = "st j'a \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5224
               ps (mb + int (Suc v) + 2) \<and>* zero (mb + int (Suc v) + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5225
               reps (mb + int (Suc v) + 2) ia (drop (Suc a) ks) \<and>* zero (ia + 1) \<and>* zero (ia + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5226
        zero (mb + int (Suc v)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5227
        ones mb (mb + int v) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5228
        zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5229
        reps' u (mb - 1) (take a ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5230
        zero (u - 2) \<and>* fam_conj {ia + 2<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5231
        " in tm.pre_stren) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5232
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5233
      (* apply (hsteps hoare_shift_left_cons_gen[OF False]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5234
      apply (rule_tac p = "st j'a \<and>* ps (ia - 1) \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5235
                           reps u (ia - 1) (take a ks @ [v] @ drop (Suc a) ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5236
                           zero ia \<and>* zero (ia + 1) \<and>* zero (ia + 2) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5237
                           fam_conj {ia + 2<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5238
        " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5239
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5240
      apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5241
      apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5242
      apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5243
      apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5244
      apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5245
      apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5246
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5247
        have "take a ks @ v # drop (Suc a) ks = list_ext a ks[a := v]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5248
        proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5249
          from `a < length ks` have "list_ext a ks = ks" by (metis list_ext_lt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5250
          hence "list_ext a ks[a:=v] = ks[a:=v]" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5251
          moreover from `a < length ks` have "ks[a:=v] = take a ks @ v # drop (Suc a) ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5252
            by (metis upd_conv_take_nth_drop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5253
          ultimately show ?thesis by metis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5254
        qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5255
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5256
      apply (unfold this, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5257
      apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5258
      apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5259
      apply (simp add:sep_conj_ac int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5260
      apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5261
      apply (subst (asm) reps'_def, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5262
      apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5263
      apply (erule condE, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5264
      apply (simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5265
      apply (fwd abs_ones)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5266
      apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5267
      apply (subst (asm) reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5268
      apply (subst (asm) fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5269
      apply (simp add:sep_conj_ac int_add_ac eq_drop reps'_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5270
      apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5271
      apply (erule condE, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5272
      by (simp add:sep_conj_ac int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5273
  next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5274
    case True
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5275
    show ?thesis
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5276
      apply (unfold Dec_def, intro t_hoare_local)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5277
      apply (subst tassemble_to.simps(2), rule tm.code_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5278
      apply (subst (1) eq_ks, simp add:True)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5279
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5280
        have "(reps u ia (take a ks @ [ks ! a]) \<and>* fam_conj {ia<..} zero) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5281
              (reps' u (ia + 1) (take a ks @ [ks ! a]) \<and>* fam_conj {ia + 1<..} zero)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5282
          apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5283
          by (unfold reps'_def, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5284
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5285
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5286
      apply (subst reps'_append)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5287
      apply (simp only:sep_conj_exists, intro tm.precond_exI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5288
      apply (rule_tac q = "st l \<and>* ps m \<and>* zero (u - 1) \<and>* reps' u (m - 1) (take a ks) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5289
            reps' m (ia + 1) [ks ! a] \<and>* zero (2 + ia) \<and>* zero (u - 2) \<and>* fam_conj {2 + ia<..} zero"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5290
             in tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5291
      apply (rule tm.code_extension)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5292
      apply (subst fam_conj_interv_simp, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5293
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5294
      (* apply (hstep hoare_locate_skip_gen[OF `a < length ks`]) *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5295
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5296
        fix m
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5297
        have "(reps' m (ia + 1) [ks ! a]) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5298
              (reps m ia [ks!a] \<and>* zero (ia + 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5299
          by (unfold reps'_def, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5300
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5301
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5302
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5303
        fix i j l m
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5304
        from `ks!a = (Suc v)` have "ks!a \<noteq> 0" by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5305
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5306
      apply (hgoto hoare_if_reps_nz_true_gen)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5307
      apply (rule tm.code_extension1)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5308
      apply (rule t_hoare_label1, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5309
      apply (thin_tac "la = j'", prune)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5310
      apply (subst (1) reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5311
      apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5312
      apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5313
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5314
      apply (unfold `ks!a = Suc v`)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5315
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5316
        fix m
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5317
        have "(ones m (m + int (Suc v))) = (ones m (m + int v) \<and>* one (m + int (Suc v)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5318
          by (simp add:ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5319
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5320
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5321
      apply hsteps 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5322
      apply (rule_tac p = "st j'a \<and>* ps (m + int v) \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5323
                           reps u (m + int v) (take a ks @ [v]) \<and>* zero (m + (1 + int v)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5324
                           zero (2 + (m + int v)) \<and>* zero (3 + (m + int v)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5325
                           fam_conj {3 + (m + int v)<..} zero
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5326
        " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5327
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5328
      apply (simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5329
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5330
        have "take a ks @ [v] = list_ext a ks[a := v]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5331
        proof -
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5332
          from True `a < length ks` have "ks = take a ks @ [ks!a]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5333
            by (metis append_Nil2 eq_ks)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5334
          hence "ks[a:=v] = take a ks @ [v]"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5335
            by (metis True `a < length ks` upd_conv_take_nth_drop)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5336
          moreover from `a < length ks` have "list_ext a ks = ks"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5337
            by (metis list_ext_lt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5338
          ultimately show ?thesis by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5339
        qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5340
      my_block_end my_note eq_l = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5341
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5342
      apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5343
      apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5344
      apply (subst fam_conj_interv_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5345
      apply (simp add:sep_conj_ac, sep_cancel, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5346
      apply (simp add:sep_conj_ac int_add_ac)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5347
      apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5348
      apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5349
      apply (fwd reps'_reps_abs)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5350
      by (simp add:eq_l)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5351
  qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5352
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5353
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5354
definition "cfill_until_one = (TL start exit.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5355
                                TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5356
                                  if_one exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5357
                                  write_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5358
                                  move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5359
                                  jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5360
                                TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5361
                               )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5362
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5363
lemma hoare_cfill_until_one:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5364
   "\<lbrace>st i \<and>* ps v \<and>* one (u - 1) \<and>* zeros u v\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5365
              i :[ cfill_until_one ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5366
    \<lbrace>st j \<and>* ps (u - 1) \<and>* ones (u - 1) v \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5367
proof(induct u v rule:zeros_rev_induct)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5368
  case (Base x y)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5369
  thus ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5370
    apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5371
    apply (rule tm.pre_condI, simp add:ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5372
    apply (unfold cfill_until_one_def, intro t_hoare_local t_hoare_label, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5373
    by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5374
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5375
  case (Step x y)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5376
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5377
    apply (rule_tac q = "st i \<and>* ps (y - 1) \<and>* one (x - 1) \<and>* zeros x (y - 1) \<and>* one y" in tm.sequencing)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5378
    apply (subst cfill_until_one_def, intro t_hoare_local t_hoare_label, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5379
    apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5380
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5381
      fix i j l
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5382
      have "\<lbrace>st i \<and>* ps (y - 1) \<and>* one (x - 1) \<and>* zeros x (y - 1)\<rbrace>  
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5383
              i :[ jmp l ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5384
            \<lbrace>st l \<and>* ps (y - 1) \<and>* one (x - 1) \<and>* zeros x (y - 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5385
        apply (case_tac "(y - 1) < x", simp add:zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5386
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5387
        apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5388
        apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5389
        apply (drule_tac zeros_rev, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5390
        by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5391
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5392
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5393
    (* The next half *)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5394
    apply (hstep Step(2), simp add:sep_conj_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5395
    by (insert Step(1), simp add:ones_rev sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5396
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5397
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5398
definition "cmove = (TL start exit.
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5399
                       TLabel start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5400
                         left_until_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5401
                         left_until_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5402
                         move_left;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5403
                         if_zero exit;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5404
                         move_right;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5405
                         write_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5406
                         right_until_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5407
                         right_until_zero;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5408
                         write_one;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5409
                         jmp start;
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5410
                     TLabel exit
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5411
                    )"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5412
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5413
declare zeros.simps [simp del] zeros_simps[simp del]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5414
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5415
lemma hoare_cmove:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5416
  assumes "w \<le> k"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5417
  shows "\<lbrace>st i \<and>* ps (v + 2 + int w) \<and>* zero (u - 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5418
              reps u (v - int w) [k - w] \<and>* zeros (v - int w + 1) (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5419
              one (v + 2) \<and>* ones (v + 3) (v + 2 + int w) \<and>* zeros (v + 3 + int w)  (v + int(reps_len [k]) + 1)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5420
                                 i :[cmove]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5421
          \<lbrace>st j \<and>* ps (u - 1) \<and>* zero (u - 1) \<and>* reps u u [0] \<and>* zeros (u + 1) (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5422
                                                                  reps (v + 2) (v + int (reps_len [k]) + 1) [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5423
  using assms
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5424
proof(induct "k - w" arbitrary: w)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5425
  case (0 w)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5426
  hence "w = k" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5427
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5428
    apply (simp add: `w = k` del:zeros.simps zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5429
    apply (unfold cmove_def, intro t_hoare_local t_hoare_label, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5430
    apply (simp add:reps_len_def reps_sep_len_def reps_ctnt_len_def del:zeros_simps zeros.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5431
    apply (rule_tac p = "st i \<and>* ps (v + 2 + int k) \<and>* zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5432
                         reps u u [0] \<and>* zeros (u + 1) (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5433
                         ones (v + 2) (v + 2 + int k) \<and>* zeros (v + 3 + int k) (2 + (v + int k)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5434
                         <(u = v - int k)>" 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5435
      in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5436
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5437
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5438
      have "\<lbrace>st i \<and>* ps (v + 2 + int k) \<and>* zeros (u + 1) (v + 1) \<and>* ones (v + 2) (v + 2 + int k) 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5439
                                                             \<and>* <(u = v - int k)>\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5440
                  i :[ left_until_zero ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5441
            \<lbrace>st j \<and>* ps (v + 1) \<and>* zeros (u + 1) (v + 1) \<and>* ones (v + 2) (v + 2 + int k)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5442
                                                             \<and>* <(u = v - int k)>\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5443
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5444
        apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5445
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5446
          have "(zeros (v - int k + 1) (v + 1)) = (zeros (v - int k + 1) v \<and>* zero (v + 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5447
            by (simp only:zeros_rev, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5448
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5449
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5450
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5451
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5452
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5453
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5454
      fix i j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5455
      have "\<lbrace>st i \<and>* ps (v + 1) \<and>* reps u u [0] \<and>* zeros (u + 1) (v + 1)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5456
                i :[left_until_one]:j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5457
            \<lbrace>st j \<and>* ps u \<and>* reps u u [0] \<and>* zeros (u + 1) (v + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5458
        apply (simp add:reps.simps ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5459
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5460
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5461
    apply (hsteps this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5462
    apply ((subst (asm) sep_conj_cond)+, erule condE, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5463
    apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5464
    apply (simp only:sep_conj_ac int_add_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5465
    apply (simp add:int_add_ac sep_conj_ac zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5466
    apply (simp add:sep_conj_ac int_add_ac, sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5467
    apply (fwd reps_lenE)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5468
    apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5469
    apply (erule condE, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5470
    apply (subgoal_tac "v  = u + int k + int (reps_len [0]) - 1", clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5471
    apply (simp add:reps_len_sg)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5472
    apply (fwd abs_ones)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5473
    apply (fwd abs_reps')+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5474
    apply (simp add:sep_conj_ac int_add_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5475
    apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5476
    apply (simp add:reps.simps, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5477
    by (clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5478
next
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5479
  case (Suc k' w)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5480
  from `Suc k' = k - w` `w \<le> k` 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5481
  have h: "k' = k - (Suc w)" "Suc w \<le> k" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5482
  show ?case
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5483
    apply (rule tm.sequencing[OF _ Suc(1)[OF h(1, 2)]])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5484
    apply (unfold cmove_def, intro t_hoare_local t_hoare_label, rule t_hoare_label_last, simp+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5485
    apply (simp add:reps_len_def reps_sep_len_def reps_ctnt_len_def del:zeros_simps zeros.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5486
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5487
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5488
      have "\<lbrace>st i \<and>* ps (v + 2 + int w) \<and>* zeros (v - int w + 1) (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5489
                               one (v + 2) \<and>* ones (v + 3) (v + 2 + int w) \<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5490
                    i :[left_until_zero]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5491
            \<lbrace>st j \<and>* ps (v + 1) \<and>* zeros (v - int w + 1) (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5492
                               one (v + 2) \<and>* ones (v + 3) (v + 2 + int w) \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5493
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5494
          have "(one (v + 2) \<and>* ones (v + 3) (v + 2 + int w)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5495
                 ones (v + 2) (v + 2 + int w)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5496
            by (simp only:ones_simps, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5497
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5498
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5499
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5500
          have "(zeros (v - int w + 1) (v + 1)) = (zeros (v - int w + 1) v \<and>*  zero (v + 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5501
            by (simp only:zeros_rev, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5502
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5503
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5504
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5505
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5506
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5507
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5508
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5509
      have "\<lbrace>st i \<and>* ps (v + 1) \<and>* reps u (v - int w) [k - w] \<and>* zeros (v - int w + 1) (v + 1)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5510
                 i :[left_until_one]: j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5511
            \<lbrace>st j \<and>* ps (v - int w) \<and>* reps u (v - int w) [k - w] \<and>* zeros (v - int w + 1) (v + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5512
        apply (simp add:reps.simps ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5513
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5514
        apply (rule tm.pre_condI, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5515
        apply (subgoal_tac "u + int (k - w) = v - int w", simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5516
        defer
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5517
        apply simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5518
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5519
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5520
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5521
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5522
      have "(reps u (v - int w) [k - w]) = (reps u (v - (1 + int w)) [k - Suc w] \<and>* one (v - int w))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5523
        apply (subst (1 2) reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5524
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5525
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5526
          have "((v - int w = u + int (k - w))) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5527
                (v - (1 + int w) = u + int (k - Suc w))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5528
            apply auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5529
            apply (smt Suc.prems h(2))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5530
            by (smt Suc.prems h(2))
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5531
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5532
        apply (simp add:this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5533
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5534
          fix b p q
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5535
          assume "(b \<Longrightarrow> (p::tassert) = q)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5536
          have "(<b> \<and>* p) = (<b> \<and>* q)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5537
            by (metis `b \<Longrightarrow> p = q` cond_eqI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5538
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5539
        apply (rule this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5540
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5541
          assume "v - (1 + int w) = u + int (k - Suc w)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5542
          hence "v = 1 + int w +  u + int (k - Suc w)" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5543
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5544
        apply (simp add:this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5545
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5546
          have "\<not> (u + int (k - w)) < u" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5547
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5548
        apply (unfold ones_rev[OF this])
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5549
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5550
          from Suc (2, 3) have "(u + int (k - w) - 1) = (u + int (k - Suc w))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5551
            by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5552
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5553
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5554
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5555
          from Suc (2, 3) have "(u + int (k - w)) =  (1 + (u + int (k - Suc w)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5556
            by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5557
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5558
        by (unfold this, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5559
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5560
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5561
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5562
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5563
      have "\<lbrace>st i \<and>* ps (v - int w) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5564
                        (reps u (v - (1 + int w)) [k - Suc w] \<and>* one (v - int w))\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5565
                 i :[ move_left]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5566
            \<lbrace>st j \<and>* ps (v - (1 + int w)) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5567
                        (reps u (v - (1 + int w)) [k - Suc w] \<and>* one (v - int w))\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5568
        apply (simp add:reps.simps ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5569
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5570
        apply (rule tm.pre_condI, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5571
        apply (subgoal_tac " u + int (k - Suc w) = v - (1 + int w)", simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5572
        defer
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5573
        apply simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5574
        apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5575
        by (simp add:sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5576
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5577
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5578
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5579
      fix i' j'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5580
      have "\<lbrace>st i' \<and>* ps (v - (1 + int w)) \<and>* reps u (v - (1 + int w)) [k - Suc w]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5581
               i' :[ if_zero j ]: j'
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5582
            \<lbrace>st j' \<and>* ps (v - (1 + int w)) \<and>* reps u (v - (1 + int w)) [k - Suc w]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5583
        apply (simp add:reps.simps ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5584
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5585
        apply (rule tm.pre_condI, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5586
        apply (subgoal_tac " u + int (k - Suc w) = v - (1 + int w)", simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5587
        defer
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5588
        apply simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5589
        by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5590
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5591
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5592
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5593
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5594
      have "\<lbrace>st i \<and>* ps (v - (1 + int w)) \<and>*  reps u (v - (1 + int w)) [k - Suc w]\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5595
                i :[ move_right ]: j 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5596
            \<lbrace>st j \<and>* ps (v - int w) \<and>*  reps u (v - (1 + int w)) [k - Suc w] \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5597
        apply (simp add:reps.simps ones_rev)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5598
        apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5599
        apply (rule tm.pre_condI, clarsimp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5600
        apply (subgoal_tac " u + int (k - Suc w) =  v - (1 + int w)", simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5601
        defer
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5602
        apply simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5603
        by hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5604
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5605
    apply (hsteps this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5606
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5607
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5608
      have "\<lbrace>st i \<and>* ps (v - int w) \<and>*  one (v + 2) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5609
                         zero (v - int w) \<and>* zeros (v - int w + 1) (v + 1)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5610
                 i :[right_until_one]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5611
            \<lbrace>st j \<and>* ps (v + 2) \<and>*  one (v + 2) \<and>*  zero (v - int w) \<and>* zeros (v - int w + 1) (v + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5612
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5613
          have "(zero (v - int w) \<and>* zeros (v - int w + 1) (v + 1)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5614
                    (zeros (v - int w) (v + 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5615
            by (simp add:zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5616
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5617
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5618
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5619
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5620
    apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5621
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5622
      from Suc(2, 3) have "w < k" by auto
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5623
      hence "(zeros (v + 3 + int w) (2 + (v + int k))) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5624
                  (zero (v + 3 + int w) \<and>* zeros (4 + (v + int w)) (2 + (v + int k)))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5625
        by (simp add:zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5626
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5627
    apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5628
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5629
      fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5630
      have "\<lbrace>st i \<and>* ps (v + 2) \<and>* zero (v + 3 + int w) \<and>* zeros (4 + (v + int w)) (2 + (v + int k)) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5631
                                                        one (v + 2) \<and>* ones (v + 3) (v + 2 + int w)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5632
                i :[right_until_zero]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5633
            \<lbrace>st j \<and>* ps (v + 3 + int w) \<and>* zero (v + 3 + int w) \<and>* zeros (4 + (v + int w)) (2 + (v + int k)) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5634
                                                        one (v + 2) \<and>* ones (v + 3) (v + 2 + int w)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5635
        my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5636
          have "(one (v + 2) \<and>* ones (v + 3) (v + 2 + int w)) =
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5637
                (ones (v + 2) (v + 2 + int w))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5638
            by (simp add:ones_simps, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5639
        my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5640
        apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5641
        by hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5642
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5643
    apply (hsteps this, simp only:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5644
    apply (sep_cancel+, simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5645
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5646
      fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5647
      assume "(zero (v - int w) \<and>* zeros (v - int w + 1) (v + 1)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5648
      hence "zeros (v - int w) (v + 1) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5649
        by (simp add:zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5650
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5651
    apply (fwd this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5652
    my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5653
      fix s
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5654
      assume "(one (v + 3 + int w) \<and>* ones (v + 3) (v + 2 + int w)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5655
      hence "ones (v + 3) (3 + (v + int w)) s"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5656
        by (simp add:ones_rev sep_conj_ac, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5657
    my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5658
    apply (fwd this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5659
    by (simp add:sep_conj_ac, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5660
qed
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5661
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5662
definition "cinit = (right_until_zero; move_right; write_one)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5663
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5664
definition "copy = (cinit; cmove; move_right; move_right; right_until_one; move_left; move_left; cfill_until_one)"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5665
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5666
lemma hoare_copy:
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5667
  shows
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5668
   "\<lbrace>st i \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u v [k] \<and>* zero (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5669
                                                     zeros (v + 2) (v + int(reps_len [k]) + 1)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5670
                                  i :[copy]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5671
    \<lbrace>st j \<and>* ps u \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>* reps u v [k] \<and>* zero (v + 1) \<and>* 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5672
                                                      reps (v + 2) (v + int (reps_len [k]) + 1) [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5673
  apply (unfold copy_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5674
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5675
    fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5676
    have 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5677
       "\<lbrace>st i \<and>* ps u \<and>* reps u v [k] \<and>* zero (v + 1) \<and>* zeros (v + 2) (v + int(reps_len [k]) + 1)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5678
                      i :[cinit]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5679
        \<lbrace>st j \<and>* ps (v + 2) \<and>* reps u v [k] \<and>* zero (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5680
                                           one (v + 2) \<and>* zeros (v + 3) (v + int(reps_len [k]) + 1)\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5681
      apply (unfold cinit_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5682
      apply (simp add:reps.simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5683
      apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5684
      apply (rule tm.pre_condI, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5685
      apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5686
      apply (simp add:sep_conj_ac)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5687
      my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5688
        have "(zeros (u + int k + 2) (u + int k + int (reps_len [k]) + 1)) = 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5689
              (zero (u + int k + 2) \<and>*  zeros (u + int k + 3) (u + int k + int (reps_len [k]) + 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5690
          by (smt reps_len_sg zeros_step_simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5691
      my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5692
      apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5693
      apply hstep
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5694
      by (simp add:sep_conj_ac, sep_cancel+, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5695
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5696
  apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5697
  apply (rule_tac p = "st j' \<and>* ps (v + 2) \<and>* reps u v [k] \<and>* zero (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5698
          one (v + 2) \<and>* zeros (v + 3) (v + int (reps_len [k]) + 1) \<and>* zero (u - 2) \<and>* zero (u - 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5699
            <(v = u + int (reps_len [k]) - 1)>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5700
    " in tm.pre_stren)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5701
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5702
    fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5703
    from hoare_cmove[where w = 0 and k = k and i = i and j = j and v = v and u = u]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5704
    have "\<lbrace>st i \<and>* ps (v + 2) \<and>* zero (u - 1) \<and>* reps u v [k] \<and>* zero (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5705
                                            one (v + 2) \<and>* zeros (v + 3) (v + int(reps_len [k]) + 1)\<rbrace>
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5706
                      i :[cmove]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5707
          \<lbrace>st j \<and>* ps (u - 1) \<and>* zero (u - 1) \<and>* reps u u [0] \<and>* zeros (u + 1) (v + 1) \<and>*
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5708
                                                       reps (v + 2) (v + int (reps_len [k]) + 1) [k]\<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5709
      by (auto simp:ones_simps zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5710
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5711
  apply (hstep this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5712
  apply (hstep, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5713
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5714
    have "reps u u [0] = one u" by (simp add:reps.simps ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5715
  my_block_end my_note eq_repsz = this
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5716
  apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5717
  apply (hstep)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5718
  apply (subst reps.simps, simp add: ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5719
  apply hsteps
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5720
  apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5721
  apply (rule tm.pre_condI, simp del:zeros.simps zeros_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5722
  apply (thin_tac "int (reps_len [k]) = 1 + int k \<and> v = u + int (reps_len [k]) - 1")
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5723
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5724
    have "(zeros (u + 1) (u + int k + 1)) = (zeros (u + 1) (u + int k) \<and>* zero (u + int k + 1))"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5725
      by (simp only:zeros_rev, smt)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5726
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5727
  apply (unfold this)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5728
  apply (hstep, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5729
  my_block
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5730
    fix i j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5731
    from hoare_cfill_until_one[where v = "u + int k" and u = "u + 1"]
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5732
    have "\<lbrace>st i \<and>* ps (u + int k) \<and>* one u \<and>* zeros (u + 1) (u + int k)\<rbrace> 
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5733
              i :[ cfill_until_one ]: j
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5734
          \<lbrace>st j \<and>* ps u \<and>* ones u (u + int k) \<rbrace>"
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5735
      by simp
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5736
  my_block_end
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5737
  apply (hstep this, simp add:sep_conj_ac reps.simps ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5738
  apply (simp add:sep_conj_ac reps.simps ones_simps)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5739
  apply (subst sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5740
  apply (subst (asm) sep_conj_cond)+
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5741
  apply (rule condI)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5742
  apply (erule condE, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5743
  apply (simp add: reps_len_def reps_sep_len_def reps_ctnt_len_def)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5744
  apply (sep_cancel+)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5745
  by (erule condE, simp)
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5746
0352ad5ee9c5 added an attempt to change TMs to use FinFuns.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5747
end