src/HOL/BNF_Examples/Misc_Codatatype.thy
author blanchet
Mon, 08 Sep 2014 15:12:35 +0200
changeset 58228 7f5d72a681a2
parent 55484 9deb5066508f
permissions -rw-r--r--
test sorts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55075
b3d0a02a756d dissolved BNF session
blanchet
parents: 55071
diff changeset
     1
(*  Title:      HOL/BNF_Examples/Misc_Codatatype.thy
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     3
    Author:     Andrei Popescu, TU Muenchen
52323
a11bbb5fef56 fixed failure in coinduction rule tactic
blanchet
parents: 51804
diff changeset
     4
    Author:     Jasmin Blanchette, TU Muenchen
a11bbb5fef56 fixed failure in coinduction rule tactic
blanchet
parents: 51804
diff changeset
     5
    Copyright   2012, 2013
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     6
53122
bc87b7af4767 renamed theory files to be closer to (new) command names
blanchet
parents: 52323
diff changeset
     7
Miscellaneous codatatype definitions.
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     8
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
53122
bc87b7af4767 renamed theory files to be closer to (new) command names
blanchet
parents: 52323
diff changeset
    10
header {* Miscellaneous Codatatype Definitions *}
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    11
53122
bc87b7af4767 renamed theory files to be closer to (new) command names
blanchet
parents: 52323
diff changeset
    12
theory Misc_Codatatype
55129
26bd1cba3ab5 killed 'More_BNFs' by moving its various bits where they (now) belong
blanchet
parents: 55076
diff changeset
    13
imports "~~/src/HOL/Library/FSet"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    14
begin
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    15
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    16
codatatype simple = X1 | X2 | X3 | X4
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    17
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    18
codatatype simple' = X1' unit | X2' unit | X3' unit | X4' unit
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    19
52323
a11bbb5fef56 fixed failure in coinduction rule tactic
blanchet
parents: 51804
diff changeset
    20
codatatype simple'' = X1'' nat int | X2''
a11bbb5fef56 fixed failure in coinduction rule tactic
blanchet
parents: 51804
diff changeset
    21
54193
bc07627c5dcd added 'primcorec' examples
blanchet
parents: 53591
diff changeset
    22
codatatype 'a stream = Stream (shd: 'a) (stl: "'a stream")
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    23
54193
bc07627c5dcd added 'primcorec' examples
blanchet
parents: 53591
diff changeset
    24
codatatype 'a mylist = MyNil | MyCons (myhd: 'a) (mytl: "'a mylist")
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    25
58228
7f5d72a681a2 test sorts
blanchet
parents: 55484
diff changeset
    26
codatatype ('b, 'c :: ord, 'd, 'e) some_passive =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    27
  SP1 "('b, 'c, 'd, 'e) some_passive" | SP2 'b | SP3 'c | SP4 'd | SP5 'e
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    28
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    29
codatatype lambda =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    30
  Var string |
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    31
  App lambda lambda |
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    32
  Abs string lambda |
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    33
  Let "(string \<times> lambda) fset" lambda
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    34
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    35
codatatype 'a par_lambda =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    36
  PVar 'a |
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    37
  PApp "'a par_lambda" "'a par_lambda" |
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    38
  PAbs 'a "'a par_lambda" |
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    39
  PLet "('a \<times> 'a par_lambda) fset" "'a par_lambda"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    40
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    41
(*
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    42
  ('a, 'b1, 'b2) F1 = 'a * 'b1 + 'a * 'b2
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    43
  ('a, 'b1, 'b2) F2 = unit + 'b1 * 'b2
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    44
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    45
53591
b6e2993fd0d3 don't wrongly destroy sum types in coiterators
blanchet
parents: 53588
diff changeset
    46
codatatype 'a p = P "'a + 'a p"
b6e2993fd0d3 don't wrongly destroy sum types in coiterators
blanchet
parents: 53588
diff changeset
    47
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    48
codatatype 'a J1 = J11 'a "'a J1" | J12 'a "'a J2"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    49
and 'a J2 = J21 | J22 "'a J1" "'a J2"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    50
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    51
codatatype 'a tree = TEmpty | TNode 'a "'a forest"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    52
and 'a forest = FNil | FCons "'a tree" "'a forest"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    53
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    54
codatatype 'a tree' = TEmpty' | TNode' "'a branch" "'a branch"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    55
and 'a branch = Branch 'a "'a tree'"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    56
55484
9deb5066508f added examples/tests
blanchet
parents: 55129
diff changeset
    57
codatatype 'a bin_rose_tree = BRTree 'a "'a bin_rose_tree mylist" "'a bin_rose_tree mylist"
9deb5066508f added examples/tests
blanchet
parents: 55129
diff changeset
    58
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    59
codatatype ('a, 'b) exp = Term "('a, 'b) trm" | Sum "('a, 'b) trm" "('a, 'b) exp"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    60
and ('a, 'b) trm = Factor "('a, 'b) factor" | Prod "('a, 'b) factor" "('a, 'b) trm"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    61
and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    62
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    63
codatatype ('a, 'b, 'c) some_killing =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    64
  SK "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing + ('a, 'b, 'c) in_here"
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    65
and ('a, 'b, 'c) in_here =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    66
  IH1 'b 'a | IH2 'c
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    67
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    68
codatatype ('a, 'b, 'c) some_killing' =
49617
7ec6471f8388 modernized examples
blanchet
parents: 49591
diff changeset
    69
  SK' "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing' + ('a, 'b, 'c) in_here'"
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    70
and ('a, 'b, 'c) in_here' =
49617
7ec6471f8388 modernized examples
blanchet
parents: 49591
diff changeset
    71
  IH1' 'b | IH2' 'c
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    72
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    73
codatatype ('a, 'b, 'c) some_killing'' =
49617
7ec6471f8388 modernized examples
blanchet
parents: 49591
diff changeset
    74
  SK'' "'a \<Rightarrow> ('a, 'b, 'c) in_here''"
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    75
and ('a, 'b, 'c) in_here'' =
49617
7ec6471f8388 modernized examples
blanchet
parents: 49591
diff changeset
    76
  IH1'' 'b 'a | IH2'' 'c
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    77
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    78
codatatype ('b, 'c) less_killing = LK "'b \<Rightarrow> 'c"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    79
53588
11a77e4aa98b more robust tactic to cover another corner case (added as example);
traytel
parents: 53122
diff changeset
    80
codatatype 'b poly_unit = U "'b \<Rightarrow> 'b poly_unit"
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    81
codatatype 'b cps = CPS1 'b | CPS2 "'b \<Rightarrow> 'b cps"
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    82
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    83
codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    84
  FR "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow>
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    85
      ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs"
49102
ce2ef34eb828 added examples for testing of coinductive witnesses
traytel
parents: 49074
diff changeset
    86
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    87
codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    88
        'b18, 'b19, 'b20) fun_rhs' =
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    89
  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>
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    90
       'b15 \<Rightarrow> 'b16 \<Rightarrow> 'b17 \<Rightarrow> 'b18 \<Rightarrow> 'b19 \<Rightarrow> 'b20 \<Rightarrow>
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    91
       ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17,
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    92
        'b18, 'b19, 'b20) fun_rhs'"
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    93
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    94
codatatype ('a, 'b, 'c) wit3_F1 = W1 'a "('a, 'b, 'c) wit3_F1" "('a, 'b, 'c) wit3_F2"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    95
and ('a, 'b, 'c) wit3_F2 = W2 'b "('a, 'b, 'c) wit3_F2"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    96
and ('a, 'b, 'c) wit3_F3 = W31 'a 'b "('a, 'b, 'c) wit3_F1" | W32 'c 'a 'b "('a, 'b, 'c) wit3_F1"
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    97
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
    98
codatatype ('c, 'e, 'g) coind_wit1 =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
    99
       CW1 'c "('c, 'e, 'g) coind_wit1" "('c, 'e, 'g) ind_wit" "('c, 'e, 'g) coind_wit2"
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   100
and ('c, 'e, 'g) coind_wit2 =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
   101
       CW21 "('c, 'e, 'g) coind_wit2" 'e | CW22 'c 'g
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   102
and ('c, 'e, 'g) ind_wit =
49158
ba50a6853a6c ported "Misc_Codata" to new syntax
blanchet
parents: 49115
diff changeset
   103
       IW1 | IW2 'c
49102
ce2ef34eb828 added examples for testing of coinductive witnesses
traytel
parents: 49074
diff changeset
   104
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   105
codatatype ('b, 'a) bar = BAR "'a \<Rightarrow> 'b"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   106
codatatype ('a, 'b, 'c, 'd) foo = FOO "'d + 'b \<Rightarrow> 'c + 'a"
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49158
diff changeset
   107
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   108
codatatype 'a dead_foo = A
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   109
codatatype ('a, 'b) use_dead_foo = Y "'a" "'b dead_foo"
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49158
diff changeset
   110
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   111
(* SLOW, MEMORY-HUNGRY
51804
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   112
codatatype ('a, 'c) D1 = A1 "('a, 'c) D2" | B1 "'a list"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   113
and ('a, 'c) D2 = A2 "('a, 'c) D3" | B2 "'c list"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   114
and ('a, 'c) D3 = A3 "('a, 'c) D3" | B3 "('a, 'c) D4" | C3 "('a, 'c) D4" "('a, 'c) D5"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   115
and ('a, 'c) D4 = A4 "('a, 'c) D5" | B4 "'a list list list"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   116
and ('a, 'c) D5 = A5 "('a, 'c) D6"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   117
and ('a, 'c) D6 = A6 "('a, 'c) D7"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   118
and ('a, 'c) D7 = A7 "('a, 'c) D8"
be6e703908f4 renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents: 49617
diff changeset
   119
and ('a, 'c) D8 = A8 "('a, 'c) D1 list"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   120
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   121
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   122
end