src/HOLCF/Fixrec.thy
author huffman
Sun, 06 Nov 2005 01:21:37 +0100
changeset 18097 d196d84c306f
parent 18096 574aa0487069
child 18110 08ec4f1f116d
permissions -rw-r--r--
add case syntax stuff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     1
(*  Title:      HOLCF/Fixrec.thy
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     2
    ID:         $Id$
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     3
    Author:     Amber Telfer and Brian Huffman
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     4
*)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     5
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     6
header "Package for defining recursive functions in HOLCF"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     7
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
     8
theory Fixrec
16551
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
     9
imports Sprod Ssum Up One Tr Fix
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 16401
diff changeset
    10
uses ("fixrec_package.ML")
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    11
begin
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    12
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    13
subsection {* Maybe monad type *}
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    14
16776
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
    15
defaultsort cpo
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
    16
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    17
types 'a maybe = "one ++ 'a u"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    18
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    19
constdefs
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    20
  fail :: "'a maybe"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    21
  "fail \<equiv> sinl\<cdot>ONE"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    22
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    23
  return :: "'a \<rightarrow> 'a maybe"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    24
  "return \<equiv> sinr oo up"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    25
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    26
lemma maybeE:
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    27
  "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; p = fail \<Longrightarrow> Q; \<And>x. p = return\<cdot>x \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    28
apply (unfold fail_def return_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    29
apply (rule_tac p=p in ssumE, simp)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    30
apply (rule_tac p=x in oneE, simp, simp)
16754
1b979f8b7e8e renamed upE1 to upE
huffman
parents: 16551
diff changeset
    31
apply (rule_tac p=y in upE, simp, simp)
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    32
done
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    33
18097
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    34
subsubsection {* Monadic bind operator *}
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    35
18097
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    36
constdefs
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    37
  bind :: "'a maybe \<rightarrow> ('a \<rightarrow> 'b maybe) \<rightarrow> 'b maybe"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    38
  "bind \<equiv> \<Lambda> m f. sscase\<cdot>sinl\<cdot>(fup\<cdot>f)\<cdot>m"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    39
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    40
syntax ">>=" :: "['a maybe, 'a \<rightarrow> 'b maybe] \<Rightarrow> 'b maybe" (infixl ">>=" 50)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    41
translations "m >>= f" == "bind\<cdot>m\<cdot>f"
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    42
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    43
nonterminals
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    44
  maybebind maybebinds
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    45
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    46
syntax 
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    47
  "_MBIND"  :: "pttrn \<Rightarrow> 'a maybe \<Rightarrow> maybebind"         ("(2_ <-/ _)" 10)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    48
  ""        :: "maybebind \<Rightarrow> maybebinds"                ("_")
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    49
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    50
  "_MBINDS" :: "[maybebind, maybebinds] \<Rightarrow> maybebinds"  ("_;/ _")
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    51
  "_MDO"    :: "[maybebinds, 'a maybe] \<Rightarrow> 'a maybe"     ("(do _;/ (_))" 10)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    52
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    53
translations
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    54
  "_MDO (_MBINDS b bs) e" == "_MDO b (_MDO bs e)"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    55
  "do (x,y) <- m; e" == "m >>= (LAM <x,y>. e)" 
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    56
  "do x <- m; e"            == "m >>= (LAM x. e)"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    57
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    58
text {* monad laws *}
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    59
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    60
lemma bind_strict [simp]: "UU >>= f = UU"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    61
by (simp add: bind_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    62
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    63
lemma bind_fail [simp]: "fail >>= f = fail"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    64
by (simp add: bind_def fail_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    65
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    66
lemma left_unit [simp]: "(return\<cdot>a) >>= k = k\<cdot>a"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    67
by (simp add: bind_def return_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    68
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    69
lemma right_unit [simp]: "m >>= return = m"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    70
by (rule_tac p=m in maybeE, simp_all)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    71
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    72
lemma bind_assoc [simp]:
16779
ac1dc3d4746a changed orientation of bind_assoc rule
huffman
parents: 16776
diff changeset
    73
 "(do b <- (do a <- m; k\<cdot>a); h\<cdot>b) = (do a <- m; b <- k\<cdot>a; h\<cdot>b)"
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    74
by (rule_tac p=m in maybeE, simp_all)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    75
18097
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    76
subsubsection {* Run operator *}
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    77
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    78
constdefs
16776
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
    79
  run:: "'a::pcpo maybe \<rightarrow> 'a"
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    80
  "run \<equiv> sscase\<cdot>\<bottom>\<cdot>(fup\<cdot>ID)"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    81
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    82
text {* rewrite rules for run *}
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    83
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    84
lemma run_strict [simp]: "run\<cdot>\<bottom> = \<bottom>"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    85
by (simp add: run_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    86
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    87
lemma run_fail [simp]: "run\<cdot>fail = \<bottom>"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    88
by (simp add: run_def fail_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    89
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    90
lemma run_return [simp]: "run\<cdot>(return\<cdot>x) = x"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    91
by (simp add: run_def return_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    92
18097
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    93
subsubsection {* Monad plus operator *}
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
    94
18097
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    95
constdefs
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    96
  mplus :: "'a maybe \<rightarrow> 'a maybe \<rightarrow> 'a maybe"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    97
  "mplus \<equiv> \<Lambda> m1 m2. sscase\<cdot>(\<Lambda> x. m2)\<cdot>(fup\<cdot>return)\<cdot>m1"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    98
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
    99
syntax "+++" :: "['a maybe, 'a maybe] \<Rightarrow> 'a maybe" (infixr "+++" 65)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   100
translations "m1 +++ m2" == "mplus\<cdot>m1\<cdot>m2"
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   101
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   102
text {* rewrite rules for mplus *}
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   103
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   104
lemma mplus_strict [simp]: "\<bottom> +++ m = \<bottom>"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   105
by (simp add: mplus_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   106
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   107
lemma mplus_fail [simp]: "fail +++ m = m"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   108
by (simp add: mplus_def fail_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   109
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   110
lemma mplus_return [simp]: "return\<cdot>x +++ m = return\<cdot>x"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   111
by (simp add: mplus_def return_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   112
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   113
lemma mplus_fail2 [simp]: "m +++ fail = m"
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   114
by (rule_tac p=m in maybeE, simp_all)
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   115
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   116
lemma mplus_assoc: "(x +++ y) +++ z = x +++ (y +++ z)"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   117
by (rule_tac p=x in maybeE, simp_all)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   118
18097
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   119
subsubsection {* Fatbar combinator *}
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   120
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   121
constdefs
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   122
  fatbar :: "('a \<rightarrow> 'b maybe) \<rightarrow> ('a \<rightarrow> 'b maybe) \<rightarrow> ('a \<rightarrow> 'b maybe)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   123
  "fatbar \<equiv> \<Lambda> a b x. a\<cdot>x +++ b\<cdot>x"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   124
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   125
syntax
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   126
  "\<parallel>" :: "['a \<rightarrow> 'b maybe, 'a \<rightarrow> 'b maybe] \<Rightarrow> 'a \<rightarrow> 'b maybe" (infixr "\<parallel>" 60)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   127
translations
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   128
  "m1 \<parallel> m2" == "fatbar\<cdot>m1\<cdot>m2"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   129
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   130
lemma fatbar1: "m\<cdot>x = \<bottom> \<Longrightarrow> (m \<parallel> ms)\<cdot>x = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   131
by (simp add: fatbar_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   132
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   133
lemma fatbar2: "m\<cdot>x = fail \<Longrightarrow> (m \<parallel> ms)\<cdot>x = ms\<cdot>x"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   134
by (simp add: fatbar_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   135
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   136
lemma fatbar3: "m\<cdot>x = return\<cdot>y \<Longrightarrow> (m \<parallel> ms)\<cdot>x = return\<cdot>y"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   137
by (simp add: fatbar_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   138
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   139
lemmas fatbar_simps = fatbar1 fatbar2 fatbar3
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   140
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   141
subsection {* Pattern combinators *}
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   142
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   143
types ('a,'b,'c) pattern = "'b \<rightarrow> 'a \<rightarrow> 'c maybe"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   144
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   145
constdefs
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   146
  wild_pat :: "('a, 'b, 'b) pattern"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   147
  "wild_pat \<equiv> \<Lambda> r a. return\<cdot>r"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   148
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   149
  var_pat :: "('a, 'a \<rightarrow> 'b, 'b) pattern"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   150
  "var_pat \<equiv> \<Lambda> r a. return\<cdot>(r\<cdot>a)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   151
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   152
  as_pat :: "('a, 'b, 'c) pattern \<Rightarrow> ('a, 'a \<rightarrow> 'b, 'c) pattern"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   153
  "as_pat p \<equiv> \<Lambda> r a. p\<cdot>(r\<cdot>a)\<cdot>a"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   154
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   155
lemma wild_pat [simp]: "wild_pat\<cdot>r\<cdot>a = return\<cdot>r"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   156
by (simp add: wild_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   157
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   158
lemma var_pat [simp]: "var_pat\<cdot>r\<cdot>a = return\<cdot>(r\<cdot>a)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   159
by (simp add: var_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   160
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   161
lemma as_pat [simp]: "as_pat p\<cdot>r\<cdot>a = p\<cdot>(r\<cdot>a)\<cdot>a"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   162
by (simp add: as_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   163
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   164
subsection {* Case syntax *}
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   165
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   166
nonterminals
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   167
  Case_syn  Cases_syn
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   168
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   169
syntax
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   170
  "_Case_syntax":: "['a, Cases_syn] => 'b"               ("(Case _ of/ _)" 10)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   171
  "_Case1"      :: "['a, 'b] => Case_syn"                ("(2_ =>/ _)" 10)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   172
  ""            :: "Case_syn => Cases_syn"               ("_")
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   173
  "_Case2"      :: "[Case_syn, Cases_syn] => Cases_syn"  ("_/ | _")
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   174
  "_as_pattern" :: "[idt, 'a] \<Rightarrow> 'a"                     (infixr "as" 10)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   175
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   176
syntax (xsymbols)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   177
  "_Case1"      :: "['a, 'b] => Case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   178
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   179
syntax
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   180
  "_match"   :: "'a \<Rightarrow> Case_syn" (* or Cases_syn *)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   181
  "_as"      :: "[pttrn, Case_syn] \<Rightarrow> Case_syn"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   182
  "_matches" :: "['a, Case_syn, 'a list] \<Rightarrow> Case_syn"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   183
  "_cons"    :: "['a, 'a list] \<Rightarrow> 'a list"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   184
  "_nil"     :: "'a list"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   185
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   186
translations
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   187
  "_Case_syntax x (_match m)"     == "run\<cdot>(m\<cdot>x)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   188
  "_Case2 (_match c) (_match cs)" == "_match (c \<parallel> cs)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   189
  "_Case1 dummy_pattern r"        == "_match (wild_pat\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   190
  "_as x (_match (p\<cdot>t))"          == "_match ((as_pat p)\<cdot>(\<Lambda> x. t))"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   191
  "_Case1 (_as_pattern x e) r"    == "_as x (_Case1 e r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   192
  "_Case1 x t"                    == "_match (var_pat\<cdot>(\<Lambda> x. t))"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   193
  "_Case1 (f\<cdot>e) r" == "_matches f (_Case1 e r) _nil"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   194
  "_matches (f\<cdot>e) (_match (p\<cdot>r)) ps" == "_matches f (_Case1 e r) (_cons p ps)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   195
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   196
lemma run_fatbar1: "m\<cdot>x = \<bottom> \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   197
by (simp add: fatbar_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   198
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   199
lemma run_fatbar2: "m\<cdot>x = fail \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = run\<cdot>(ms\<cdot>x)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   200
by (simp add: fatbar_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   201
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   202
lemma run_fatbar3: "m\<cdot>x = return\<cdot>y \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = y"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   203
by (simp add: fatbar_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   204
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   205
lemmas run_fatbar_simps [simp] = run_fatbar1 run_fatbar2 run_fatbar3
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   206
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   207
subsection {* Pattern combinators for built-in types *}
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   208
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   209
constdefs
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   210
  cpair_pat :: "_"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   211
  "cpair_pat p1 p2 \<equiv> \<Lambda> r1 \<langle>x1,x2\<rangle>. bind\<cdot>(p1\<cdot>r1\<cdot>x1)\<cdot>(\<Lambda> r2. p2\<cdot>r2\<cdot>x2)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   212
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   213
  spair_pat :: "_"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   214
  "spair_pat p1 p2 \<equiv> \<Lambda> r (:x,y:). cpair_pat p1 p2\<cdot>r\<cdot>\<langle>x,y\<rangle>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   215
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   216
  sinl_pat :: "_"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   217
  "sinl_pat p \<equiv> \<Lambda> r a. case a of sinl\<cdot>x \<Rightarrow> p\<cdot>r\<cdot>x | sinr\<cdot>y \<Rightarrow> fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   218
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   219
  sinr_pat :: "_"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   220
  "sinr_pat p \<equiv> \<Lambda> r a. case a of sinl\<cdot>x \<Rightarrow> fail | sinr\<cdot>y \<Rightarrow> p\<cdot>r\<cdot>y"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   221
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   222
  up_pat :: "_"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   223
  "up_pat p \<equiv> \<Lambda> r a. case a of up\<cdot>x \<Rightarrow> p\<cdot>r\<cdot>x"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   224
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   225
  Def_pat :: "'a::type \<Rightarrow> ('a lift, 'b, 'b) pattern"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   226
  "Def_pat x \<equiv> \<Lambda> r. FLIFT y. if x = y then return\<cdot>r else fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   227
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   228
  ONE_pat :: "_"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   229
  "ONE_pat \<equiv> \<Lambda> r ONE. return\<cdot>r"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   230
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   231
  TT_pat :: "(tr, _, _) pattern"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   232
  "TT_pat \<equiv> \<Lambda> r b. If b then return\<cdot>r else fail fi"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   233
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   234
  FF_pat :: "(tr, _, _) pattern"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   235
  "FF_pat \<equiv> \<Lambda> r b. If b then fail else return\<cdot>r fi"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   236
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   237
translations
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   238
  "_matches cpair (_match (p1\<cdot>r)) (_cons p2 _nil)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   239
    == "_match ((cpair_pat p1 p2)\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   240
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   241
  "_matches spair (_match (p1\<cdot>r)) (_cons p2 _nil)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   242
    == "_match ((spair_pat p1 p2)\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   243
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   244
translations
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   245
  "_matches sinl (_match (p1\<cdot>r)) _nil" == "_match ((sinl_pat p1)\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   246
  "_matches sinr (_match (p1\<cdot>r)) _nil" == "_match ((sinr_pat p1)\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   247
  "_matches up (_match (p1\<cdot>r)) _nil" == "_match ((up_pat p1)\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   248
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   249
translations
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   250
  "_Case1 (Def x) r" == "_match (Def_pat x\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   251
  "_Case1 ONE r" == "_match (ONE_pat\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   252
  "_Case1 TT r" == "_match (TT_pat\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   253
  "_Case1 FF r" == "_match (FF_pat\<cdot>r)"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   254
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   255
lemma cpair_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   256
  "p1\<cdot>r\<cdot>x = \<bottom> \<Longrightarrow> cpair_pat p1 p2\<cdot>r\<cdot><x,y> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   257
  "p1\<cdot>r\<cdot>x = fail \<Longrightarrow> cpair_pat p1 p2\<cdot>r\<cdot><x,y> = fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   258
  "p1\<cdot>r\<cdot>x = return\<cdot>r' \<Longrightarrow> cpair_pat p1 p2\<cdot>r\<cdot><x,y> = p2\<cdot>r'\<cdot>y"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   259
by (simp_all add: cpair_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   260
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   261
lemma spair_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   262
  "spair_pat p1 p2\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   263
  "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> spair_pat p1 p2\<cdot>r\<cdot>(:x, y:) = cpair_pat p1 p2\<cdot>r\<cdot>\<langle>x, y\<rangle>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   264
by (simp_all add: spair_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   265
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   266
lemma sinl_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   267
  "sinl_pat p\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   268
  "x \<noteq> \<bottom> \<Longrightarrow> sinl_pat p\<cdot>r\<cdot>(sinl\<cdot>x) = p\<cdot>r\<cdot>x"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   269
  "x \<noteq> \<bottom> \<Longrightarrow> sinl_pat p\<cdot>r\<cdot>(sinr\<cdot>x) = fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   270
by (simp_all add: sinl_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   271
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   272
lemma sinr_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   273
  "sinr_pat p\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   274
  "x \<noteq> \<bottom> \<Longrightarrow> sinr_pat p\<cdot>r\<cdot>(sinl\<cdot>x) = fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   275
  "x \<noteq> \<bottom> \<Longrightarrow> sinr_pat p\<cdot>r\<cdot>(sinr\<cdot>x) = p\<cdot>r\<cdot>x"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   276
by (simp_all add: sinr_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   277
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   278
lemma up_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   279
  "up_pat p\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   280
  "up_pat p\<cdot>r\<cdot>(up\<cdot>x) = p\<cdot>r\<cdot>x"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   281
by (simp_all add: up_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   282
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   283
lemma Def_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   284
  "Def_pat x\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   285
  "Def_pat x\<cdot>r\<cdot>(Def x) = return\<cdot>r"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   286
  "x \<noteq> y \<Longrightarrow> Def_pat x\<cdot>r\<cdot>(Def y) = fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   287
by (simp_all add: Def_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   288
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   289
lemma ONE_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   290
  "ONE_pat\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   291
  "ONE_pat\<cdot>r\<cdot>ONE = return\<cdot>r"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   292
by (simp_all add: ONE_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   293
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   294
lemma TT_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   295
  "TT_pat\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   296
  "TT_pat\<cdot>r\<cdot>TT = return\<cdot>r"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   297
  "TT_pat\<cdot>r\<cdot>FF = fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   298
by (simp_all add: TT_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   299
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   300
lemma FF_pat_simps [simp]:
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   301
  "FF_pat\<cdot>r\<cdot>\<bottom> = \<bottom>"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   302
  "FF_pat\<cdot>r\<cdot>TT = fail"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   303
  "FF_pat\<cdot>r\<cdot>FF = return\<cdot>r"
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   304
by (simp_all add: FF_pat_def)
d196d84c306f add case syntax stuff
huffman
parents: 18096
diff changeset
   305
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   306
subsection {* Match functions for built-in types *}
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   307
16776
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   308
defaultsort pcpo
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   309
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   310
constdefs
16776
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   311
  match_UU :: "'a \<rightarrow> unit maybe"
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   312
  "match_UU \<equiv> \<Lambda> x. fail"
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   313
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   314
  match_cpair :: "'a::cpo \<times> 'b::cpo \<rightarrow> ('a \<times> 'b) maybe"
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   315
  "match_cpair \<equiv> csplit\<cdot>(\<Lambda> x y. return\<cdot><x,y>)"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   316
16551
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   317
  match_spair :: "'a \<otimes> 'b \<rightarrow> ('a \<times> 'b) maybe"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   318
  "match_spair \<equiv> ssplit\<cdot>(\<Lambda> x y. return\<cdot><x,y>)"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   319
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   320
  match_sinl :: "'a \<oplus> 'b \<rightarrow> 'a maybe"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   321
  "match_sinl \<equiv> sscase\<cdot>return\<cdot>(\<Lambda> y. fail)"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   322
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   323
  match_sinr :: "'a \<oplus> 'b \<rightarrow> 'b maybe"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   324
  "match_sinr \<equiv> sscase\<cdot>(\<Lambda> x. fail)\<cdot>return"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   325
16776
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   326
  match_up :: "'a::cpo u \<rightarrow> 'a maybe"
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   327
  "match_up \<equiv> fup\<cdot>return"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   328
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   329
  match_ONE :: "one \<rightarrow> unit maybe"
18094
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   330
  "match_ONE \<equiv> \<Lambda> ONE. return\<cdot>()"
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   331
 
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   332
  match_TT :: "tr \<rightarrow> unit maybe"
18094
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   333
  "match_TT \<equiv> \<Lambda> b. If b then return\<cdot>() else fail fi"
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   334
 
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   335
  match_FF :: "tr \<rightarrow> unit maybe"
18094
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   336
  "match_FF \<equiv> \<Lambda> b. If b then fail else return\<cdot>() fi"
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   337
16776
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   338
lemma match_UU_simps [simp]:
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   339
  "match_UU\<cdot>x = fail"
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   340
by (simp add: match_UU_def)
a3899ac14a1c generalized types of monadic operators to class cpo; added match function for UU
huffman
parents: 16758
diff changeset
   341
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   342
lemma match_cpair_simps [simp]:
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   343
  "match_cpair\<cdot><x,y> = return\<cdot><x,y>"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   344
by (simp add: match_cpair_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   345
16551
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   346
lemma match_spair_simps [simp]:
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   347
  "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> match_spair\<cdot>(:x,y:) = return\<cdot><x,y>"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   348
  "match_spair\<cdot>\<bottom> = \<bottom>"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   349
by (simp_all add: match_spair_def)
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   350
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   351
lemma match_sinl_simps [simp]:
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   352
  "x \<noteq> \<bottom> \<Longrightarrow> match_sinl\<cdot>(sinl\<cdot>x) = return\<cdot>x"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   353
  "x \<noteq> \<bottom> \<Longrightarrow> match_sinl\<cdot>(sinr\<cdot>x) = fail"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   354
  "match_sinl\<cdot>\<bottom> = \<bottom>"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   355
by (simp_all add: match_sinl_def)
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   356
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   357
lemma match_sinr_simps [simp]:
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   358
  "x \<noteq> \<bottom> \<Longrightarrow> match_sinr\<cdot>(sinr\<cdot>x) = return\<cdot>x"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   359
  "x \<noteq> \<bottom> \<Longrightarrow> match_sinr\<cdot>(sinl\<cdot>x) = fail"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   360
  "match_sinr\<cdot>\<bottom> = \<bottom>"
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   361
by (simp_all add: match_sinr_def)
7abf8a713613 added match functions for spair, sinl, sinr
huffman
parents: 16463
diff changeset
   362
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   363
lemma match_up_simps [simp]:
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   364
  "match_up\<cdot>(up\<cdot>x) = return\<cdot>x"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   365
  "match_up\<cdot>\<bottom> = \<bottom>"
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   366
by (simp_all add: match_up_def)
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   367
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   368
lemma match_ONE_simps [simp]:
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   369
  "match_ONE\<cdot>ONE = return\<cdot>()"
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   370
  "match_ONE\<cdot>\<bottom> = \<bottom>"
18094
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   371
by (simp_all add: match_ONE_def)
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   372
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   373
lemma match_TT_simps [simp]:
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   374
  "match_TT\<cdot>TT = return\<cdot>()"
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   375
  "match_TT\<cdot>FF = fail"
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   376
  "match_TT\<cdot>\<bottom> = \<bottom>"
18094
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   377
by (simp_all add: match_TT_def)
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   378
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   379
lemma match_FF_simps [simp]:
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   380
  "match_FF\<cdot>FF = return\<cdot>()"
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   381
  "match_FF\<cdot>TT = fail"
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   382
  "match_FF\<cdot>\<bottom> = \<bottom>"
18094
404f298220af simplify definitions
huffman
parents: 16779
diff changeset
   383
by (simp_all add: match_FF_def)
16460
72a08d509d62 added match functions for ONE, TT, and FF; added theorem mplus_fail2
huffman
parents: 16417
diff changeset
   384
16401
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   385
subsection {* Mutual recursion *}
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   386
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   387
text {*
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   388
  The following rules are used to prove unfolding theorems from
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   389
  fixed-point definitions of mutually recursive functions.
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   390
*}
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   391
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   392
lemma cpair_equalI: "\<lbrakk>x \<equiv> cfst\<cdot>p; y \<equiv> csnd\<cdot>p\<rbrakk> \<Longrightarrow> <x,y> \<equiv> p"
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   393
by (simp add: surjective_pairing_Cprod2)
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   394
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   395
lemma cpair_eqD1: "<x,y> = <x',y'> \<Longrightarrow> x = x'"
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   396
by simp
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   397
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   398
lemma cpair_eqD2: "<x,y> = <x',y'> \<Longrightarrow> y = y'"
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   399
by simp
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   400
16463
342d74ca8815 fixrec shows unsolved subgoals when proofs of rewrites fail
huffman
parents: 16460
diff changeset
   401
text {* lemma for proving rewrite rules *}
342d74ca8815 fixrec shows unsolved subgoals when proofs of rewrites fail
huffman
parents: 16460
diff changeset
   402
342d74ca8815 fixrec shows unsolved subgoals when proofs of rewrites fail
huffman
parents: 16460
diff changeset
   403
lemma ssubst_lhs: "\<lbrakk>t = s; P s = Q\<rbrakk> \<Longrightarrow> P t = Q"
342d74ca8815 fixrec shows unsolved subgoals when proofs of rewrites fail
huffman
parents: 16460
diff changeset
   404
by simp
342d74ca8815 fixrec shows unsolved subgoals when proofs of rewrites fail
huffman
parents: 16460
diff changeset
   405
16401
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   406
ML {*
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   407
val cpair_equalI = thm "cpair_equalI";
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   408
val cpair_eqD1 = thm "cpair_eqD1";
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   409
val cpair_eqD2 = thm "cpair_eqD2";
16463
342d74ca8815 fixrec shows unsolved subgoals when proofs of rewrites fail
huffman
parents: 16460
diff changeset
   410
val ssubst_lhs = thm "ssubst_lhs";
16401
57c35ede00b9 fixrec package now handles mutually-recursive definitions
huffman
parents: 16229
diff changeset
   411
*}
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   412
16758
c32334d98fcd fix typo
huffman
parents: 16754
diff changeset
   413
subsection {* Initializing the fixrec package *}
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   414
16229
77cae9c8e73e use fixrec_package.ML
huffman
parents: 16221
diff changeset
   415
use "fixrec_package.ML"
16221
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   416
879400e029bf New theory with lemmas for the fixrec package
huffman
parents:
diff changeset
   417
end