src/HOL/Datatype_Examples/Misc_N2M.thy
author wenzelm
Sun, 02 Nov 2014 18:21:45 +0100
changeset 58889 5b7a9633cfa8
parent 58396 7b60e4e74430
child 61260 e6f03fae14d5
permissions -rw-r--r--
modernized header uniformly as section;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58385
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
     1
(*  Title:      HOL/Datatype_Examples/Misc_N2M.thy
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
     3
    Copyright   2014
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
     4
58396
blanchet
parents: 58385
diff changeset
     5
Miscellaneous tests for the nested-to-mutual reduction.
58385
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
     6
*)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
     7
58889
5b7a9633cfa8 modernized header uniformly as section;
wenzelm
parents: 58396
diff changeset
     8
section \<open>Miscellaneous Tests for the Nested-to-Mutual Reduction\<close>
58385
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
     9
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    10
theory Misc_N2M
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    11
imports "~~/src/HOL/Library/BNF_Axiomatization"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    12
begin
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    13
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    14
locale misc
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    15
begin
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    16
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    17
datatype 'a li = Ni | Co 'a "'a li"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    18
datatype 'a tr = Tr "'a \<Rightarrow> 'a tr li"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    19
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    20
primrec (nonexhaustive)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    21
  f_tl :: "'a \<Rightarrow> 'a tr li \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    22
  f_t :: "'a \<Rightarrow> 'a tr \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    23
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    24
  "f_tl _ Ni = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    25
  "f_t a (Tr ts) = 1 + f_tl a (ts a)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    26
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    27
datatype ('a, 'b) l = N | C 'a 'b "('a, 'b) l"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    28
datatype ('a, 'b) t = T "(('a, 'b) t, 'a) l" "(('a, 'b) t, 'b) l"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    29
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    30
primrec (nonexhaustive)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    31
  f_tl2 :: "(('a, 'a) t, 'a) l \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    32
  f_t2 :: "('a, 'a) t \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    33
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    34
  "f_tl2 N = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    35
  "f_t2 (T ts us) = f_tl2 ts + f_tl2 us"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    36
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    37
primrec  (nonexhaustive)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    38
  g_tla :: "(('a, 'b) t, 'a) l \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    39
  g_tlb :: "(('a, 'b) t, 'b) l \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    40
  g_t :: "('a, 'b) t \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    41
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    42
  "g_tla N = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    43
  "g_tlb N = 1" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    44
  "g_t (T ts us) = g_tla ts + g_tlb us"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    45
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    46
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    47
datatype
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    48
  'a l1 = N1 | C1 'a "'a l1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    49
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    50
datatype
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    51
  ('a, 'b) t1 = T1 'a 'b "('a, 'b) t1 l1" "(nat \<times> ('a, 'b) t1) l1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    52
  ('a, 'b) t2 = T2 "('a, 'b) t1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    53
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    54
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    55
  h1_tl1 :: "(nat, 'a) t1 l1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    56
  h1_natl1 :: "(nat \<times> (nat, 'a) t1) l1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    57
  h1_t1 :: "(nat, 'a) t1 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    58
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    59
  "h1_tl1 N1 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    60
  "h1_tl1 (C1 t ts) = h1_t1 t + h1_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    61
  "h1_natl1 N1 = Suc 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    62
  "h1_natl1 (C1 n ts) = fst n + h1_natl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    63
  "h1_t1 (T1 n _ ts _) = n + h1_tl1 ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    64
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    65
end
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    66
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    67
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    68
bnf_axiomatization ('a, 'b) M0 [wits: "('a, 'b) M0"]
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    69
bnf_axiomatization ('a, 'b) N0 [wits: "('a, 'b) N0"]
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    70
bnf_axiomatization ('a, 'b) K0 [wits: "('a, 'b) K0"]
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    71
bnf_axiomatization ('a, 'b) L0 [wits: "('a, 'b) L0"]
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    72
bnf_axiomatization ('a, 'b, 'c) G0 [wits: "('a, 'b, 'c) G0"]
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    73
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    74
locale (*co*)mplicated
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    75
begin
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    76
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    77
datatype 'a M = CM "('a, 'a M) M0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    78
datatype 'a N = CN "('a N, 'a) N0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    79
datatype ('a, 'b) K = CK "('a, ('a, 'b) L) K0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    80
         and ('a, 'b) L = CL "('b, ('a, 'b) K) L0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    81
datatype 'a G = CG "('a, ('a G, 'a G N) K, ('a G M, 'a G) L) G0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    82
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    83
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    84
    fG :: "'a G \<Rightarrow> 'a G"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    85
and fK :: "('a G, 'a G N) K \<Rightarrow> ('a G, 'a G N) K"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    86
and fL :: "('a G, 'a G N) L \<Rightarrow> ('a G, 'a G N) L"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    87
and fM :: "'a G M \<Rightarrow> 'a G M" where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    88
  "fG (CG x) = CG (map_G0 id fK (map_L fM fG) x)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    89
| "fK (CK y) = CK (map_K0 fG fL y)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    90
| "fL (CL z) = CL (map_L0 (map_N fG) fK z)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    91
| "fM (CM w) = CM (map_M0 fG fM w)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    92
thm fG_def fK_def fL_def fM_def fG.simps fK.simps fL.simps fM.simps
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    93
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    94
end
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    95
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    96
locale complicated
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    97
begin
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    98
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
    99
codatatype 'a M = CM "('a, 'a M) M0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   100
codatatype 'a N = CN "('a N, 'a) N0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   101
codatatype ('a, 'b) K = CK "('a, ('a, 'b) L) K0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   102
         and ('a, 'b) L = CL "('b, ('a, 'b) K) L0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   103
codatatype 'a G = CG "('a, ('a G, 'a G N) K, ('a G M, 'a G) L) G0"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   104
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   105
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   106
    fG :: "'a G \<Rightarrow> 'a G"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   107
and fK :: "('a G, 'a G N) K \<Rightarrow> ('a G, 'a G N) K"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   108
and fL :: "('a G, 'a G N) L \<Rightarrow> ('a G, 'a G N) L"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   109
and fM :: "'a G M \<Rightarrow> 'a G M" where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   110
  "fG x = CG (map_G0 id fK (map_L fM fG) (un_CG x))"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   111
| "fK y = CK (map_K0 fG fL (un_CK y))"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   112
| "fL z = CL (map_L0 (map_N fG) fK (un_CL z))"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   113
| "fM w = CM (map_M0 fG fM (un_CM w))"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   114
thm fG_def fK_def fL_def fM_def fG.simps fK.simps fL.simps fM.simps
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   115
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   116
end
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   117
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   118
datatype ('a, 'b) F1 = F1 'a 'b
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   119
datatype F2 = F2 "((unit, nat) F1, F2) F1" | F2'
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   120
datatype 'a kk1 = K1 'a | K2 "'a kk2" and 'a kk2 = K3 "'a kk1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   121
datatype 'a ll1 = L1 'a | L2 "'a ll2 kk2" and 'a ll2 = L3 "'a ll1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   122
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   123
datatype_compat F1
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   124
datatype_compat F2
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   125
datatype_compat kk1 kk2
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   126
datatype_compat ll1 ll2
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   127
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   128
58396
blanchet
parents: 58385
diff changeset
   129
subsection \<open>Deep Nesting\<close>
58385
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   130
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   131
datatype 'a tree = Empty | Node 'a "'a tree list"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   132
datatype_compat tree
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   133
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   134
datatype 'a ttree = TEmpty | TNode 'a "'a ttree list tree"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   135
datatype_compat ttree
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   136
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   137
datatype 'a tttree = TEmpty | TNode 'a "'a tttree list ttree list tree"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   138
datatype_compat tttree
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   139
(*
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   140
datatype 'a ttttree = TEmpty | TNode 'a "'a ttttree list tttree list ttree list tree"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   141
datatype_compat ttttree
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   142
*)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   143
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   144
datatype ('a,'b)complex = 
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   145
  C1 nat "'a ttree" 
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   146
| C2 "('a,'b)complex list tree tree" 'b "('a,'b)complex" "('a,'b)complex2 ttree list"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   147
and ('a,'b)complex2 = D1 "('a,'b)complex ttree"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   148
datatype_compat complex complex2
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   149
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   150
datatype 'a F = F1 'a | F2 "'a F"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   151
datatype 'a G = G1 'a | G2 "'a G F"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   152
datatype H = H1 | H2 "H G"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   153
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   154
datatype_compat F
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   155
datatype_compat G
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   156
datatype_compat H
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   157
58396
blanchet
parents: 58385
diff changeset
   158
blanchet
parents: 58385
diff changeset
   159
subsection \<open>Primrec cache\<close>
58385
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   160
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   161
datatype 'a l = N | C 'a "'a l"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   162
datatype ('a, 'b) t = T 'a 'b "('a, 'b) t l"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   163
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   164
context linorder
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   165
begin
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   166
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   167
(* slow *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   168
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   169
  f1_tl :: "(nat, 'a) t l \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   170
  f1_t :: "(nat, 'a) t \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   171
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   172
  "f1_tl N = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   173
  "f1_tl (C t ts) = f1_t t + f1_tl ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   174
  "f1_t (T n _ ts) = n + f1_tl ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   175
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   176
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   177
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   178
  f2_t :: "(nat, 'b) t \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   179
  f2_tl :: "(nat, 'b) t l \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   180
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   181
  "f2_tl N = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   182
  "f2_tl (C t ts) = f2_t t + f2_tl ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   183
  "f2_t (T n _ ts) = n + f2_tl ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   184
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   185
end
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   186
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   187
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   188
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   189
  g1_t :: "('a, int) t \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   190
  g1_tl :: "('a, int) t l \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   191
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   192
  "g1_t (T _ _ ts) = g1_tl ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   193
  "g1_tl N = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   194
  "g1_tl (C _ ts) = g1_tl ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   195
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   196
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   197
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   198
  g2_t :: "(int, int) t \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   199
  g2_tl :: "(int, int) t l \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   200
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   201
  "g2_t (T _ _ ts) = g2_tl ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   202
  "g2_tl N = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   203
  "g2_tl (C _ ts) = g2_tl ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   204
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   205
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   206
datatype
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   207
  'a l1 = N1 | C1 'a "'a l2" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   208
  'a l2 = N2 | C2 'a "'a l1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   209
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   210
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   211
  sum_l1 :: "'a::{zero,plus} l1 \<Rightarrow> 'a" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   212
  sum_l2 :: "'a::{zero,plus} l2 \<Rightarrow> 'a"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   213
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   214
  "sum_l1 N1 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   215
  "sum_l1 (C1 n ns) = n + sum_l2 ns" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   216
  "sum_l2 N2 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   217
  "sum_l2 (C2 n ns) = n + sum_l1 ns"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   218
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   219
datatype
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   220
  ('a, 'b) t1 = T1 'a 'b "('a, 'b) t1 l1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   221
  ('a, 'b) t2 = T2 "('a, 'b) t1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   222
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   223
(* slow *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   224
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   225
  h1_tl1 :: "(nat, 'a) t1 l1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   226
  h1_tl2 :: "(nat, 'a) t1 l2 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   227
  h1_t1 :: "(nat, 'a) t1 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   228
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   229
  "h1_tl1 N1 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   230
  "h1_tl1 (C1 t ts) = h1_t1 t + h1_tl2 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   231
  "h1_tl2 N2 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   232
  "h1_tl2 (C2 t ts) = h1_t1 t + h1_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   233
  "h1_t1 (T1 n _ ts) = n + h1_tl1 ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   234
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   235
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   236
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   237
  h2_tl1 :: "(nat, 'a) t1 l1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   238
  h2_tl2 :: "(nat, 'a) t1 l2 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   239
  h2_t1 :: "(nat, 'a) t1 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   240
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   241
  "h2_tl1 N1 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   242
  "h2_tl1 (C1 t ts) = h2_t1 t + h2_tl2 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   243
  "h2_tl2 N2 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   244
  "h2_tl2 (C2 t ts) = h2_t1 t + h2_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   245
  "h2_t1 (T1 n _ ts) = n + h2_tl1 ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   246
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   247
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   248
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   249
  h3_tl2 :: "(nat, 'a) t1 l2 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   250
  h3_tl1 :: "(nat, 'a) t1 l1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   251
  h3_t1 :: "(nat, 'a) t1 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   252
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   253
  "h3_tl1 N1 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   254
  "h3_tl1 (C1 t ts) = h3_t1 t + h3_tl2 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   255
  "h3_tl2 N2 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   256
  "h3_tl2 (C2 t ts) = h3_t1 t + h3_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   257
  "h3_t1 (T1 n _ ts) = n + h3_tl1 ts"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   258
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   259
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   260
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   261
  i1_tl2 :: "(nat, 'a) t1 l2 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   262
  i1_tl1 :: "(nat, 'a) t1 l1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   263
  i1_t1 :: "(nat, 'a) t1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   264
  i1_t2 :: "(nat, 'a) t2 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   265
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   266
  "i1_tl1 N1 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   267
  "i1_tl1 (C1 t ts) = i1_t1 t + i1_tl2 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   268
  "i1_tl2 N2 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   269
  "i1_tl2 (C2 t ts) = i1_t1 t + i1_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   270
  "i1_t1 (T1 n _ ts) = n + i1_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   271
  "i1_t2 (T2 t) = i1_t1 t"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   272
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   273
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   274
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   275
  j1_t2 :: "(nat, 'a) t2 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   276
  j1_t1 :: "(nat, 'a) t1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   277
  j1_tl1 :: "(nat, 'a) t1 l1 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   278
  j1_tl2 :: "(nat, 'a) t1 l2 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   279
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   280
  "j1_tl1 N1 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   281
  "j1_tl1 (C1 t ts) = j1_t1 t + j1_tl2 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   282
  "j1_tl2 N2 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   283
  "j1_tl2 (C2 t ts) = j1_t1 t + j1_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   284
  "j1_t1 (T1 n _ ts) = n + j1_tl1 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   285
  "j1_t2 (T2 t) = j1_t1 t"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   286
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   287
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   288
datatype 'a l3 = N3 | C3 'a "'a l3"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   289
datatype 'a l4 = N4 | C4 'a "'a l4"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   290
datatype ('a, 'b) t3 = T3 'a 'b "('a, 'b) t3 l3" "('a, 'b) t3 l4"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   291
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   292
(* slow *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   293
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   294
  k1_tl3 :: "(nat, 'a) t3 l3 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   295
  k1_tl4 :: "(nat, 'a) t3 l4 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   296
  k1_t3 :: "(nat, 'a) t3 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   297
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   298
  "k1_tl3 N3 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   299
  "k1_tl3 (C3 t ts) = k1_t3 t + k1_tl3 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   300
  "k1_tl4 N4 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   301
  "k1_tl4 (C4 t ts) = k1_t3 t + k1_tl4 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   302
  "k1_t3 (T3 n _ ts us) = n + k1_tl3 ts + k1_tl4 us"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   303
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   304
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   305
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   306
  k2_tl4 :: "(nat, int) t3 l4 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   307
  k2_tl3 :: "(nat, int) t3 l3 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   308
  k2_t3 :: "(nat, int) t3 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   309
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   310
  "k2_tl4 N4 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   311
  "k2_tl4 (C4 t ts) = k2_t3 t + k2_tl4 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   312
  "k2_tl3 N3 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   313
  "k2_tl3 (C3 t ts) = k2_t3 t + k2_tl3 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   314
  "k2_t3 (T3 n _ ts us) = n + k2_tl3 ts + k2_tl4 us"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   315
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   316
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   317
datatype ('a, 'b) l5 = N5 | C5 'a 'b "('a, 'b) l5"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   318
datatype ('a, 'b) l6 = N6 | C6 'a 'b "('a, 'b) l6"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   319
datatype ('a, 'b, 'c) t4 = T4 'a 'b "(('a, 'b, 'c) t4, 'b) l5" "(('a, 'b, 'c) t4, 'c) l6"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   320
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   321
(* slow *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   322
primrec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   323
  l1_tl5 :: "((nat, 'a, 'b) t4, 'a) l5 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   324
  l1_tl6 :: "((nat, 'a, 'b) t4, 'b) l6 \<Rightarrow> nat" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   325
  l1_t4 :: "(nat, 'a, 'b) t4 \<Rightarrow> nat"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   326
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   327
  "l1_tl5 N5 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   328
  "l1_tl5 (C5 t _ ts) = l1_t4 t + l1_tl5 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   329
  "l1_tl6 N6 = 0" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   330
  "l1_tl6 (C6 t _ ts) = l1_t4 t + l1_tl6 ts" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   331
  "l1_t4 (T4 n _ ts us) = n + l1_tl5 ts + l1_tl6 us"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   332
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   333
58396
blanchet
parents: 58385
diff changeset
   334
subsection \<open>Primcorec Cache\<close>
58385
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   335
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   336
codatatype 'a col = N | C 'a "'a col"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   337
codatatype ('a, 'b) cot = T 'a 'b "('a, 'b) cot col"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   338
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   339
context linorder
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   340
begin
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   341
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   342
(* slow *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   343
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   344
  f1_cotcol :: "nat \<Rightarrow> (nat, 'a) cot col" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   345
  f1_cot :: "nat \<Rightarrow> (nat, 'a) cot"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   346
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   347
  "n = 0 \<Longrightarrow> f1_cotcol n = N" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   348
  "_ \<Longrightarrow> f1_cotcol n = C (f1_cot n) (f1_cotcol n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   349
  "f1_cot n = T n undefined (f1_cotcol n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   350
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   351
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   352
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   353
  f2_cotcol :: "nat \<Rightarrow> (nat, 'b) cot col" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   354
  f2_cot :: "nat \<Rightarrow> (nat, 'b) cot"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   355
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   356
  "n = 0 \<Longrightarrow> f2_cotcol n = N" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   357
  "_ \<Longrightarrow> f2_cotcol n = C (f2_cot n) (f2_cotcol n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   358
  "f2_cot n = T n undefined (f2_cotcol n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   359
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   360
end
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   361
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   362
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   363
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   364
  g1_cot :: "int \<Rightarrow> (int, 'a) cot" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   365
  g1_cotcol :: "int \<Rightarrow> (int, 'a) cot col"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   366
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   367
  "g1_cot n = T n undefined (g1_cotcol n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   368
  "n = 0 \<Longrightarrow> g1_cotcol n = N" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   369
  "_ \<Longrightarrow> g1_cotcol n = C (g1_cot n) (g1_cotcol n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   370
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   371
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   372
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   373
  g2_cot :: "int \<Rightarrow> (int, int) cot" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   374
  g2_cotcol :: "int \<Rightarrow> (int, int) cot col"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   375
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   376
  "g2_cot n = T n undefined (g2_cotcol n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   377
  "n = 0 \<Longrightarrow> g2_cotcol n = N" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   378
  "_ \<Longrightarrow> g2_cotcol n = C (g2_cot n) (g2_cotcol n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   379
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   380
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   381
codatatype
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   382
  'a col1 = N1 | C1 'a "'a col2" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   383
  'a col2 = N2 | C2 'a "'a col1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   384
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   385
codatatype
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   386
  ('a, 'b) cot1 = T1 'a 'b "('a, 'b) cot1 col1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   387
  ('a, 'b) cot2 = T2 "('a, 'b) cot1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   388
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   389
(* slow *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   390
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   391
  h1_cotcol1 :: "nat \<Rightarrow> (nat, 'a) cot1 col1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   392
  h1_cotcol2 :: "nat \<Rightarrow> (nat, 'a) cot1 col2" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   393
  h1_cot1 :: "nat \<Rightarrow> (nat, 'a) cot1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   394
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   395
  "h1_cotcol1 n = C1 (h1_cot1 n) (h1_cotcol2 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   396
  "h1_cotcol2 n = C2 (h1_cot1 n) (h1_cotcol1 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   397
  "h1_cot1 n = T1 n undefined (h1_cotcol1 n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   398
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   399
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   400
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   401
  h2_cotcol1 :: "nat \<Rightarrow> (nat, 'a) cot1 col1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   402
  h2_cotcol2 :: "nat \<Rightarrow> (nat, 'a) cot1 col2" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   403
  h2_cot1 :: "nat \<Rightarrow> (nat, 'a) cot1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   404
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   405
  "h2_cotcol1 n = C1 (h2_cot1 n) (h2_cotcol2 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   406
  "h2_cotcol2 n = C2 (h2_cot1 n) (h2_cotcol1 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   407
  "h2_cot1 n = T1 n undefined (h2_cotcol1 n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   408
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   409
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   410
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   411
  h3_cotcol2 :: "nat \<Rightarrow> (nat, 'a) cot1 col2" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   412
  h3_cotcol1 :: "nat \<Rightarrow> (nat, 'a) cot1 col1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   413
  h3_cot1 :: "nat \<Rightarrow> (nat, 'a) cot1"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   414
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   415
  "h3_cotcol1 n = C1 (h3_cot1 n) (h3_cotcol2 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   416
  "h3_cotcol2 n = C2 (h3_cot1 n) (h3_cotcol1 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   417
  "h3_cot1 n = T1 n undefined (h3_cotcol1 n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   418
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   419
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   420
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   421
  i1_cotcol2 :: "nat \<Rightarrow> (nat, 'a) cot1 col2" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   422
  i1_cotcol1 :: "nat \<Rightarrow> (nat, 'a) cot1 col1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   423
  i1_cot1 :: "nat \<Rightarrow> (nat, 'a) cot1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   424
  i1_cot2 :: "nat \<Rightarrow> (nat, 'a) cot2"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   425
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   426
  "i1_cotcol1 n = C1 (i1_cot1 n) (i1_cotcol2 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   427
  "i1_cotcol2 n = C2 (i1_cot1 n) (i1_cotcol1 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   428
  "i1_cot1 n = T1 n undefined (i1_cotcol1 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   429
  "i1_cot2 n = T2 (i1_cot1 n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   430
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   431
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   432
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   433
  j1_cot2 :: "nat \<Rightarrow> (nat, 'a) cot2" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   434
  j1_cot1 :: "nat \<Rightarrow> (nat, 'a) cot1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   435
  j1_cotcol1 :: "nat \<Rightarrow> (nat, 'a) cot1 col1" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   436
  j1_cotcol2 :: "nat \<Rightarrow> (nat, 'a) cot1 col2"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   437
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   438
  "j1_cotcol1 n = C1 (j1_cot1 n) (j1_cotcol2 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   439
  "j1_cotcol2 n = C2 (j1_cot1 n) (j1_cotcol1 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   440
  "j1_cot1 n = T1 n undefined (j1_cotcol1 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   441
  "j1_cot2 n = T2 (j1_cot1 n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   442
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   443
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   444
codatatype 'a col3 = N3 | C3 'a "'a col3"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   445
codatatype 'a col4 = N4 | C4 'a "'a col4"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   446
codatatype ('a, 'b) cot3 = T3 'a 'b "('a, 'b) cot3 col3" "('a, 'b) cot3 col4"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   447
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   448
(* slow *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   449
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   450
  k1_cotcol3 :: "nat \<Rightarrow> (nat, 'a) cot3 col3" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   451
  k1_cotcol4 :: "nat \<Rightarrow> (nat, 'a) cot3 col4" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   452
  k1_cot3 :: "nat \<Rightarrow> (nat, 'a) cot3"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   453
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   454
  "k1_cotcol3 n = C3 (k1_cot3 n) (k1_cotcol3 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   455
  "k1_cotcol4 n = C4 (k1_cot3 n) (k1_cotcol4 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   456
  "k1_cot3 n = T3 n undefined (k1_cotcol3 n) (k1_cotcol4 n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   457
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   458
(* should be fast *)
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   459
primcorec
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   460
  k2_cotcol4 :: "nat \<Rightarrow> (nat, 'a) cot3 col4" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   461
  k2_cotcol3 :: "nat \<Rightarrow> (nat, 'a) cot3 col3" and
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   462
  k2_cot3 :: "nat \<Rightarrow> (nat, 'a) cot3"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   463
where
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   464
  "k2_cotcol4 n = C4 (k2_cot3 n) (k2_cotcol4 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   465
  "k2_cotcol3 n = C3 (k2_cot3 n) (k2_cotcol3 n)" |
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   466
  "k2_cot3 n = T3 n undefined (k2_cotcol3 n) (k2_cotcol4 n)"
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   467
9cbef70cff8e regression tests for n2m
traytel
parents:
diff changeset
   468
end