thys/Rec_Def.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 10 Jan 2019 13:18:07 +0000
changeset 296 3fee65a40838
parent 292 293e9c6f22e1
permissions -rwxr-xr-x
updated to Isabelle 2018
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
292
293e9c6f22e1 Added myself to the comments at the start of all files
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 288
diff changeset
     1
(* Title: thys/Rec_Def.thy
293e9c6f22e1 Added myself to the comments at the start of all files
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 288
diff changeset
     2
   Author: Jian Xu, Xingyuan Zhang, and Christian Urban
293e9c6f22e1 Added myself to the comments at the start of all files
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 288
diff changeset
     3
   Modifications: Sebastiaan Joosten
293e9c6f22e1 Added myself to the comments at the start of all files
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 288
diff changeset
     4
*)
293e9c6f22e1 Added myself to the comments at the start of all files
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 288
diff changeset
     5
163
67063c5365e1 changed theory names to uppercase
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 70
diff changeset
     6
theory Rec_Def
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
imports Main
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
begin
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    10
datatype recf =  z
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    11
              |  s
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    12
              |  id nat nat
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    13
              |  Cn nat recf "recf list"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    14
              |  Pr nat recf recf
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    15
              |  Mn nat recf 
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    17
definition pred_of_nl :: "nat list \<Rightarrow> nat list"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    18
  where
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    19
  "pred_of_nl xs = butlast xs @ [last xs - 1]"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    20
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    21
function rec_exec :: "recf \<Rightarrow> nat list \<Rightarrow> nat"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    22
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    23
  "rec_exec z xs = 0" |
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    24
  "rec_exec s xs = (Suc (xs ! 0))" |
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    25
  "rec_exec (id m n) xs = (xs ! n)" |
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    26
  "rec_exec (Cn n f gs) xs = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    27
     rec_exec f (map (\<lambda> a. rec_exec a xs) gs)" | 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    28
  "rec_exec (Pr n f g) xs = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    29
     (if last xs = 0 then rec_exec f (butlast xs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    30
      else rec_exec g (butlast xs @ (last xs - 1) # [rec_exec (Pr n f g) (butlast xs @ [last xs - 1])]))" |
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    31
  "rec_exec (Mn n f) xs = (LEAST x. rec_exec f (xs @ [x]) = 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    32
by pat_completeness auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    33
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    34
termination
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    35
apply(relation "measures [\<lambda> (r, xs). size r, (\<lambda> (r, xs). last xs)]")
288
a9003e6d0463 Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 248
diff changeset
    36
apply(auto simp add: less_Suc_eq_le intro: trans_le_add2 size_list_estimation'[THEN trans_le_add1])
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    37
done
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    39
inductive terminate :: "recf \<Rightarrow> nat list \<Rightarrow> bool"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    40
  where
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    41
  termi_z: "terminate z [n]"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    42
| termi_s: "terminate s [n]"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    43
| termi_id: "\<lbrakk>n < m; length xs = m\<rbrakk> \<Longrightarrow> terminate (id m n) xs"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    44
| termi_cn: "\<lbrakk>terminate f (map (\<lambda>g. rec_exec g xs) gs); 
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    45
              \<forall>g \<in> set gs. terminate g xs; length xs = n\<rbrakk> \<Longrightarrow> terminate (Cn n f gs) xs"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    46
| termi_pr: "\<lbrakk>\<forall> y < x. terminate g (xs @ y # [rec_exec (Pr n f g) (xs @ [y])]);
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    47
              terminate f xs;
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    48
              length xs = n\<rbrakk> 
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    49
              \<Longrightarrow> terminate (Pr n f g) (xs @ [x])"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    50
| termi_mn: "\<lbrakk>length xs = n; terminate f (xs @ [r]); 
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
    51
              rec_exec f (xs @ [r]) = 0;
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    52
              \<forall> i < r. terminate f (xs @ [i]) \<and> rec_exec f (xs @ [i]) > 0\<rbrakk> \<Longrightarrow> terminate (Mn n f) xs"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
end