ported "Misc_Codata" to new syntax
authorblanchet
Wed, 05 Sep 2012 15:40:26 +0200
changeset 49158 ba50a6853a6c
parent 49157 6407346b74c7
child 49159 7af3f9f41783
ported "Misc_Codata" to new syntax
src/HOL/Codatatype/Examples/Misc_Codata.thy
src/HOL/Codatatype/Examples/Misc_Data.thy
--- a/src/HOL/Codatatype/Examples/Misc_Codata.thy	Wed Sep 05 15:40:13 2012 +0200
+++ b/src/HOL/Codatatype/Examples/Misc_Codata.thy	Wed Sep 05 15:40:26 2012 +0200
@@ -12,55 +12,56 @@
 imports "../Codatatype"
 begin
 
-codata_raw simple: 'a = "unit + unit + unit + unit"
+codata simple = X1 | X2 | X3 | X4
+
+codata simple' = X1' unit | X2' unit | X3' unit | X4' unit
 
-codata_raw stream: 's = "'a \<times> 's"
+codata 'a stream = Stream 'a "'a stream"
+
+codata 'a mylist = MyNil | MyCons 'a "'a mylist"
+
+codata ('b, 'c, 'd, 'e) some_passive =
+  SP1 "('b, 'c, 'd, 'e) some_passive" | SP2 'b | SP3 'c | SP4 'd | SP5 'e
 
-codata_raw llist: 'llist = "unit + 'a \<times> 'llist"
+codata lambda =
+  Var string |
+  App lambda lambda |
+  Abs string lambda |
+  Let "(string \<times> lambda) fset" lambda
 
-codata_raw some_passive: 'a = "'a + 'b + 'c + 'd + 'e"
+codata 'a par_lambda =
+  PVar 'a |
+  PApp "'a par_lambda" "'a par_lambda" |
+  PAbs 'a "'a par_lambda" |
+  PLet "('a \<times> 'a par_lambda) fset" "'a par_lambda"
 
 (*
   ('a, 'b1, 'b2) F1 = 'a * 'b1 + 'a * 'b2
   ('a, 'b1, 'b2) F2 = unit + 'b1 * 'b2
 *)
 
-codata_raw F1: 'b1 = "'a \<times> 'b1 + 'a \<times> 'b2"
-and F2: 'b2 = "unit + 'b1 * 'b2"
+codata 'a J1 = J11 'a "'a J1" | J12 'a "'a J2"
+   and 'a J2 = J21 | J22 "'a J1" "'a J2"
 
-codata_raw EXPR:   'E = "'T + 'T \<times> 'E"
-and TERM:   'T = "'F + 'F \<times> 'T"
-and FACTOR: 'F = "'a + 'b + 'E"
+codata 'a tree = TEmpty | TNode 'a "'a forest"
+   and 'a forest = FNil | FCons "'a tree" "'a forest"
 
-codata_raw llambda:
-  'trm = "string +
-          'trm \<times> 'trm +
-          string \<times> 'trm +
-          (string \<times> 'trm) fset \<times> 'trm"
+codata 'a tree' = TEmpty' | TNode' "'a branch" "'a branch"
+   and 'a branch = Branch 'a "'a tree'"
 
-codata_raw par_llambda:
-  'trm = "'a +
-          'trm \<times> 'trm +
-          'a \<times> 'trm +
-          ('a \<times> 'trm) fset \<times> 'trm"
+codata ('a, 'b) exp = Term "('a, 'b) trm" | Sum "('a, 'b) trm" "('a, 'b) exp"
+   and ('a, 'b) trm = Factor "('a, 'b) factor" | Prod "('a, 'b) factor" "('a, 'b) trm"
+   and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp"
 
-(*
-  'a tree = Empty | Node of 'a * 'a forest      ('b = unit + 'a * 'c)
-  'a forest = Nil | Cons of 'a tree * 'a forest ('c = unit + 'b * 'c)
-*)
+codata_raw some_killing: 'A = "'a \<Rightarrow> 'b \<Rightarrow> ('A + 'B)"
+       and in_here: 'B = "'b \<times> 'a + 'c"
 
-codata_raw tree:     'tree = "unit + 'a \<times> 'forest"
-and forest: 'forest = "unit + 'tree \<times> 'forest"
-
-codata_raw CPS: 'a = "'b + 'b \<Rightarrow> 'a"
-
-codata_raw fun_rhs: 'a = "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow> 'a"
-
-codata_raw fun_rhs': 'a = "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow> 'b10 \<Rightarrow>
-                    'b11 \<Rightarrow> 'b12 \<Rightarrow> 'b13 \<Rightarrow> 'b14 \<Rightarrow> 'b15 \<Rightarrow> 'b16 \<Rightarrow> 'b17 \<Rightarrow> 'b18 \<Rightarrow> 'b19 \<Rightarrow> 'b20 \<Rightarrow> 'a"
-
-codata_raw some_killing: 'a = "'b \<Rightarrow> 'd \<Rightarrow> ('a + 'c)"
-and in_here: 'c = "'d \<times> 'b + 'e"
+(* FIXME
+codata ('a, 'b, 'c) some_killing =
+  SK "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing + ('a, 'b, 'c) in_here"
+ and ('a, 'b, 'c) in_here =
+  IH1 'b 'a | IH2 'c
+*)
 
 codata_raw some_killing': 'a = "'b \<Rightarrow> 'd \<Rightarrow> ('a + 'c)"
 and in_here': 'c = "'d + 'e"
@@ -70,25 +71,39 @@
 
 codata_raw less_killing: 'a = "'b \<Rightarrow> 'c"
 
-codata_raw
-    wit3_F1: 'b1 = "'a1 \<times> 'b1 \<times> 'b2"
-and wit3_F2: 'b2 = "'a2 \<times> 'b2"
-and wit3_F3: 'b3 = "'a1 \<times> 'a2 \<times> 'b1 + 'a3 \<times> 'a1 \<times> 'a2 \<times> 'b1"
+codata 'b cps = CPS1 'b | CPS2 "'b \<Rightarrow> 'b cps"
+
+codata ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs =
+  FR "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow>
+      ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs"
 
-codata_raw
-    coind_wit1: 'a = "'c \<times> 'a \<times> 'b \<times> 'd"
-and coind_wit2: 'd = "'d \<times> 'e + 'c \<times> 'g"
-and ind_wit:    'b = "unit + 'c"
+codata ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
+        'b18, 'b19, 'b20) fun_rhs' =
+  FR' "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow> 'b10 \<Rightarrow> 'b11 \<Rightarrow> 'b12 \<Rightarrow> 'b13 \<Rightarrow> 'b14 \<Rightarrow>
+       'b15 \<Rightarrow> 'b16 \<Rightarrow> 'b17 \<Rightarrow> 'b18 \<Rightarrow> 'b19 \<Rightarrow> 'b20 \<Rightarrow>
+       ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
+        'b18, 'b19, 'b20) fun_rhs'"
+
+codata ('a, 'b, 'c) wit3_F1 = W1 'a "('a, 'b, 'c) wit3_F1" "('a, 'b, 'c) wit3_F2"
+   and ('a, 'b, 'c) wit3_F2 = W2 'b "('a, 'b, 'c) wit3_F2"
+   and ('a, 'b, 'c) wit3_F3 = W31 'a 'b "('a, 'b, 'c) wit3_F1" | W32 'c 'a 'b "('a, 'b, 'c) wit3_F1"
+
+codata ('c, 'e, 'g) coind_wit1 =
+       CW1 'c "('c, 'e, 'g) coind_wit1" "('c, 'e, 'g) ind_wit" "('c, 'e, 'g) coind_wit2"
+   and ('c, 'e, 'g) coind_wit2 =
+       CW21 "('c, 'e, 'g) coind_wit2" 'e | CW22 'c 'g
+   and ('c, 'e, 'g) ind_wit =
+       IW1 | IW2 'c
 
 (* SLOW, MEMORY-HUNGRY
-codata_raw K1': 'K1 = "'K2 + 'a list"
-and K2': 'K2 = "'K3 + 'c fset"
-and K3': 'K3 = "'K3 + 'K4 + 'K4 \<times> 'K5"
-and K4': 'K4 = "'K5 + 'a list list list"
-and K5': 'K5 = "'K6"
-and K6': 'K6 = "'K7"
-and K7': 'K7 = "'K8"
-and K8': 'K8 = "'K1 list"
+codata ('a, 'c) D1 = A1 "('a, 'c) D2" | B1 "'a list"
+   and ('a, 'c) D2 = A2 "('a, 'c) D3" | B2 "'c list"
+   and ('a, 'c) D3 = A3 "('a, 'c) D3" | B3 "('a, 'c) D4" | C3 "('a, 'c) D4" "('a, 'c) D5"
+   and ('a, 'c) D4 = A4 "('a, 'c) D5" | B4 "'a list list list"
+   and ('a, 'c) D5 = A5 "('a, 'c) D6"
+   and ('a, 'c) D6 = A6 "('a, 'c) D7"
+   and ('a, 'c) D7 = A7 "('a, 'c) D8"
+   and ('a, 'c) D8 = A8 "('a, 'c) D1 list"
 *)
 
 end
--- a/src/HOL/Codatatype/Examples/Misc_Data.thy	Wed Sep 05 15:40:13 2012 +0200
+++ b/src/HOL/Codatatype/Examples/Misc_Data.thy	Wed Sep 05 15:40:26 2012 +0200
@@ -52,7 +52,7 @@
  and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp"
 
 data_raw some_killing: 'A = "'a \<Rightarrow> 'b \<Rightarrow> ('A + 'B)"
-and in_here: 'B = "'b \<times> 'a + 'c"
+     and in_here: 'B = "'b \<times> 'a + 'c"
 
 (* FIXME
 data ('a, 'b, 'c) some_killing =