Attic/rec_def.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 10 Jan 2019 12:51:24 +0000
changeset 294 6836da75b3ac
parent 127 469c26d19f8e
permissions -rw-r--r--
updated to Isabelle 2016-1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory rec_def
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
imports Main
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
section {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
  Recursive functions
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  Datatype of recursive operators.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
datatype recf = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
 -- {* The zero function, which always resturns @{text "0"} as result. *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
  z | 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
 -- {* The successor function, which increments its arguments. *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  s | 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
 -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
  The projection function, where @{text "id i j"} returns the @{text "j"}-th
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  argment out of the @{text "i"} arguments.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
  id nat nat | 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
 -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  The compostion operator, where "@{text "Cn n f [g1; g2; \<dots> ;gm]"} 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  computes @{text "f (g1(x1, x2, \<dots>, xn), g2(x1, x2, \<dots>, xn), \<dots> , 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  gm(x1, x2, \<dots> , xn))"} for input argments @{text "x1, \<dots>, xn"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  Cn nat recf "recf list" | 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
-- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  The primitive resursive operator, where @{text "Pr n f g"} computes:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  @{text "Pr n f g (x1, x2, \<dots>, xn-1, 0) = f(x1, \<dots>, xn-1)"} 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  and @{text "Pr n f g (x1, x2, \<dots>, xn-1, k') = g(x1, x2, \<dots>, xn-1, k, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
                                                  Pr n f g (x1, \<dots>, xn-1, k))"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  Pr nat recf recf | 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
-- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  The minimization operator, where @{text "Mn n f (x1, x2, \<dots> , xn)"} 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  computes the first i such that @{text "f (x1, \<dots>, xn, i) = 0"} and for all
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  @{text "j"}, @{text "f (x1, x2, \<dots>, xn, j) > 0"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  Mn nat recf 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
text {* 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
  The semantis of recursive operators is given by an inductively defined
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  relation as follows, where  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  @{text "rec_calc_rel R [x1, x2, \<dots>, xn] r"} means the computation of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  @{text "R"} over input arguments @{text "[x1, x2, \<dots>, xn"} terminates
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
  and gives rise to a result @{text "r"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
inductive rec_calc_rel :: "recf \<Rightarrow> nat list \<Rightarrow> nat \<Rightarrow> bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  calc_z: "rec_calc_rel z [n] 0" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
  calc_s: "rec_calc_rel s [n] (Suc n)" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  calc_id: "\<lbrakk>length args = i; j < i; args!j = r\<rbrakk> \<Longrightarrow> rec_calc_rel (id i j) args r" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  calc_cn: "\<lbrakk>length args = n;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
             \<forall> k < length gs. rec_calc_rel (gs ! k) args (rs ! k);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
             length rs = length gs; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
             rec_calc_rel f rs r\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
            \<Longrightarrow> rec_calc_rel (Cn n f gs) args r" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
  calc_pr_zero: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
           "\<lbrakk>length args = n;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
             rec_calc_rel f args r0 \<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
            \<Longrightarrow> rec_calc_rel (Pr n f g) (args @ [0]) r0" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
  calc_pr_ind: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
           \<lbrakk> length args = n;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
             rec_calc_rel (Pr n f g) (args @ [k]) rk; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
             rec_calc_rel g (args @ [k] @ [rk]) rk'\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
            \<Longrightarrow> rec_calc_rel (Pr n f g) (args @ [Suc k]) rk'"  |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  calc_mn: "\<lbrakk>length args = n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
             rec_calc_rel f (args@[r]) 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
             \<forall> i < r. (\<exists> ri. rec_calc_rel f (args@[i]) ri \<and> ri \<noteq> 0)\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
            \<Longrightarrow> rec_calc_rel (Mn n f) args r" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
inductive_cases calc_pr_reverse:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
              "rec_calc_rel (Pr n f g) (lm) rSucy"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
inductive_cases calc_z_reverse: "rec_calc_rel z lm x"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
inductive_cases calc_s_reverse: "rec_calc_rel s lm x"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
inductive_cases calc_id_reverse: "rec_calc_rel (id m n) lm x"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
inductive_cases calc_cn_reverse: "rec_calc_rel (Cn n f gs) lm x"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
inductive_cases calc_mn_reverse:"rec_calc_rel (Mn n f) lm x"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
end