src/HOL/UNITY/Comp/TimerArray.thy
author wenzelm
Wed May 12 16:44:49 2010 +0200 (2010-05-12)
changeset 36866 426d5781bb25
parent 35416 d8d7d1b785af
child 37936 1e4c5015a72e
permissions -rw-r--r--
modernized specifications;
paulson@11194
     1
(*  Title:      HOL/UNITY/TimerArray.thy
paulson@11194
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@11194
     3
    Copyright   1998  University of Cambridge
paulson@11194
     4
paulson@11194
     5
A trivial example of reasoning about an array of processes
paulson@11194
     6
*)
paulson@11194
     7
paulson@18556
     8
theory TimerArray imports "../UNITY_Main" begin
paulson@11194
     9
paulson@11194
    10
types 'a state = "nat * 'a"   (*second component allows new variables*)
paulson@11194
    11
wenzelm@36866
    12
definition count :: "'a state => nat"
wenzelm@36866
    13
  where "count s = fst s"
paulson@11194
    14
  
wenzelm@36866
    15
definition decr  :: "('a state * 'a state) set"
wenzelm@36866
    16
  where "decr = (UN n uu. {((Suc n, uu), (n,uu))})"
paulson@11194
    17
  
wenzelm@36866
    18
definition Timer :: "'a state program"
wenzelm@36866
    19
  where "Timer = mk_total_program (UNIV, {decr}, UNIV)"
paulson@11194
    20
paulson@13786
    21
paulson@13786
    22
declare Timer_def [THEN def_prg_Init, simp]
paulson@13786
    23
paulson@13786
    24
declare count_def [simp] decr_def [simp]
paulson@13786
    25
paulson@13786
    26
(*Demonstrates induction, but not used in the following proof*)
paulson@13786
    27
lemma Timer_leadsTo_zero: "Timer : UNIV leadsTo {s. count s = 0}"
paulson@13786
    28
apply (rule_tac f = count in lessThan_induct, simp)
paulson@13786
    29
apply (case_tac "m")
paulson@13786
    30
 apply (force intro!: subset_imp_leadsTo)
paulson@13786
    31
apply (unfold Timer_def, ensures_tac "decr")
paulson@13786
    32
done
paulson@13786
    33
paulson@13786
    34
lemma Timer_preserves_snd [iff]: "Timer : preserves snd"
paulson@13786
    35
apply (rule preservesI)
paulson@16184
    36
apply (unfold Timer_def, safety)
paulson@13786
    37
done
paulson@13786
    38
paulson@13786
    39
paulson@13786
    40
declare PLam_stable [simp]
paulson@13786
    41
paulson@13786
    42
lemma TimerArray_leadsTo_zero:
paulson@13786
    43
     "finite I  
paulson@13786
    44
      ==> (plam i: I. Timer) : UNIV leadsTo {(s,uu). ALL i:I. s i = 0}"
paulson@13786
    45
apply (erule_tac A'1 = "%i. lift_set i ({0} <*> UNIV)" 
paulson@13786
    46
       in finite_stable_completion [THEN leadsTo_weaken])
paulson@13786
    47
apply auto
paulson@13786
    48
(*Safety property, already reduced to the single Timer case*)
paulson@13786
    49
 prefer 2
paulson@16184
    50
 apply (simp add: Timer_def, safety) 
paulson@13786
    51
(*Progress property for the array of Timers*)
paulson@13786
    52
apply (rule_tac f = "sub i o fst" in lessThan_induct)
paulson@13786
    53
apply (case_tac "m")
paulson@13786
    54
(*Annoying need to massage the conditions to have the form (... <*> UNIV)*)
paulson@13786
    55
apply (auto intro: subset_imp_leadsTo 
paulson@13786
    56
        simp add: insert_absorb 
paulson@13786
    57
                  lift_set_Un_distrib [symmetric] lessThan_Suc [symmetric] 
paulson@13786
    58
               Times_Un_distrib1 [symmetric] Times_Diff_distrib1 [symmetric])
paulson@13786
    59
apply (rename_tac "n")
paulson@13786
    60
apply (rule PLam_leadsTo_Basis)
paulson@13786
    61
apply (auto simp add: lessThan_Suc [symmetric])
paulson@16184
    62
apply (unfold Timer_def mk_total_program_def, safety) 
paulson@13812
    63
apply (rule_tac act = decr in totalize_transientI, auto)
paulson@13786
    64
done
paulson@13786
    65
paulson@11194
    66
end