src/HOL/BNF/Tools/bnf_fp.ML
author blanchet
Wed, 26 Sep 2012 10:00:59 +0200
changeset 49582 557302525778
parent 49581 4e5bd3883429
child 49584 4339aa335355
permissions -rw-r--r--
renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49509
163914705f8d renamed top-level theory from "Codatatype" to "BNF"
blanchet
parents: 49507
diff changeset
     1
(*  Title:      HOL/BNF/Tools/bnf_fp.ML
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
    Copyright   2012
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     4
49389
blanchet
parents: 49368
diff changeset
     5
Shared library for the datatype and codatatype constructions.
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     6
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     7
49457
1d2825673cec renamed "bnf_fp_util.ML" to "bnf_fp.ML"
blanchet
parents: 49456
diff changeset
     8
signature BNF_FP =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
sig
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    10
  val time: Timer.real_timer -> string -> Timer.real_timer
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    11
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    12
  val IITN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    13
  val LevN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    14
  val algN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    15
  val behN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    16
  val bisN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    17
  val carTN: string
49338
blanchet
parents: 49337
diff changeset
    18
  val caseN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    19
  val coN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    20
  val coinductN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    21
  val corecN: string
49338
blanchet
parents: 49337
diff changeset
    22
  val corecsN: string
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    23
  val ctorN: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    24
  val ctor_dtorN: string
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    25
  val ctor_dtor_unfoldsN: string
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    26
  val ctor_dtor_corecsN: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    27
  val ctor_exhaustN: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    28
  val ctor_induct2N: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    29
  val ctor_inductN: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    30
  val ctor_injectN: string
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    31
  val ctor_foldN: string
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    32
  val ctor_fold_uniqueN: string
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    33
  val ctor_foldsN: string
49541
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49536
diff changeset
    34
  val ctor_mapN: string
49543
53b3c532a082 renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents: 49542
diff changeset
    35
  val ctor_map_uniqueN: string
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    36
  val ctor_recN: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    37
  val ctor_recsN: string
49518
b377da40244b renamed LFP low-level rel property to have ctor not dtor in its name
blanchet
parents: 49516
diff changeset
    38
  val ctor_relN: string
49544
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
    39
  val ctor_set_inclN: string
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
    40
  val ctor_set_set_inclN: string
49518
b377da40244b renamed LFP low-level rel property to have ctor not dtor in its name
blanchet
parents: 49516
diff changeset
    41
  val ctor_srelN: string
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    42
  val disc_unfold_iffN: string
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    43
  val disc_unfoldsN: string
49484
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49482
diff changeset
    44
  val disc_corec_iffN: string
49338
blanchet
parents: 49337
diff changeset
    45
  val disc_corecsN: string
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    46
  val dtorN: string
49582
557302525778 renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
blanchet
parents: 49581
diff changeset
    47
  val dtor_coinductN: string
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    48
  val dtor_corecN: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    49
  val dtor_corecsN: string
49518
b377da40244b renamed LFP low-level rel property to have ctor not dtor in its name
blanchet
parents: 49516
diff changeset
    50
  val dtor_ctorN: string
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    51
  val dtor_exhaustN: string
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
    52
  val dtor_injectN: string
49545
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
    53
  val dtor_mapN: string
49581
4e5bd3883429 renamed "dtor_coinduct" etc. to "dtor_map_coinduct"
blanchet
parents: 49545
diff changeset
    54
  val dtor_map_coinductN: string
4e5bd3883429 renamed "dtor_coinduct" etc. to "dtor_map_coinduct"
blanchet
parents: 49545
diff changeset
    55
  val dtor_map_strong_coinductN: string
49543
53b3c532a082 renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents: 49542
diff changeset
    56
  val dtor_map_uniqueN: string
49545
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
    57
  val dtor_relN: string
49544
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
    58
  val dtor_set_inclN: string
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
    59
  val dtor_set_set_inclN: string
49518
b377da40244b renamed LFP low-level rel property to have ctor not dtor in its name
blanchet
parents: 49516
diff changeset
    60
  val dtor_srelN: string
49545
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
    61
  val dtor_srel_coinductN: string
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
    62
  val dtor_srel_strong_coinductN: string
49582
557302525778 renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
blanchet
parents: 49581
diff changeset
    63
  val dtor_strong_coinductN: string
49516
d4859efc1096 renamed "rel_simp" to "dtor_rel" and similarly for "srel"
blanchet
parents: 49510
diff changeset
    64
  val dtor_unfoldN: string
d4859efc1096 renamed "rel_simp" to "dtor_rel" and similarly for "srel"
blanchet
parents: 49510
diff changeset
    65
  val dtor_unfold_uniqueN: string
d4859efc1096 renamed "rel_simp" to "dtor_rel" and similarly for "srel"
blanchet
parents: 49510
diff changeset
    66
  val dtor_unfoldsN: string
49020
f379cf5d71bd more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents: 49019
diff changeset
    67
  val exhaustN: string
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    68
  val foldN: string
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    69
  val foldsN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    70
  val hsetN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    71
  val hset_recN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    72
  val inductN: string
49019
fc4decdba5ce more work on BNF sugar
blanchet
parents: 48975
diff changeset
    73
  val injectN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    74
  val isNodeN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    75
  val lsbisN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    76
  val map_uniqueN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    77
  val min_algN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    78
  val morN: string
49020
f379cf5d71bd more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents: 49019
diff changeset
    79
  val nchotomyN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    80
  val recN: string
49338
blanchet
parents: 49337
diff changeset
    81
  val recsN: string
49536
898aea2e7a94 started work on generation of "rel" theorems
blanchet
parents: 49518
diff changeset
    82
  val relsN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    83
  val rvN: string
49536
898aea2e7a94 started work on generation of "rel" theorems
blanchet
parents: 49518
diff changeset
    84
  val sel_corecsN: string
898aea2e7a94 started work on generation of "rel" theorems
blanchet
parents: 49518
diff changeset
    85
  val sel_relsN: string
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    86
  val sel_unfoldsN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    87
  val set_inclN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    88
  val set_set_inclN: string
49438
5bc80d96241e group "simps" together
blanchet
parents: 49425
diff changeset
    89
  val simpsN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    90
  val strTN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    91
  val str_initN: string
49499
464812bef4d9 renamed "upto" coinduction "strong"
blanchet
parents: 49498
diff changeset
    92
  val strongN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    93
  val sum_bdN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    94
  val sum_bdTN: string
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    95
  val unfoldN: string
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
    96
  val unfoldsN: string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    97
  val uniqueN: string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    98
49542
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
    99
  val mk_ctor_setsN: int -> string
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
   100
  val mk_dtor_set_inductN: int -> string
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
   101
  val mk_dtor_setsN: int -> string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   102
  val mk_exhaustN: string -> string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   103
  val mk_injectN: string -> string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   104
  val mk_nchotomyN: string -> string
49542
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
   105
  val mk_setsN: int -> string
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   106
  val mk_set_inductN: int -> string
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   107
49498
acc583e14167 tuned variable names
blanchet
parents: 49484
diff changeset
   108
  val mk_common_name: string list -> string
49327
541d818d2ff3 put an underscore between names, for compatibility with old package (and also because it makes sense)
blanchet
parents: 49308
diff changeset
   109
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   110
  val split_conj_thm: thm -> thm list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   111
  val split_conj_prems: int -> thm -> thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   112
49330
276ff43ee0b1 reuse generated names (they look better + slightly more efficient)
blanchet
parents: 49327
diff changeset
   113
  val retype_free: typ -> term -> term
276ff43ee0b1 reuse generated names (they look better + slightly more efficient)
blanchet
parents: 49327
diff changeset
   114
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   115
  val mk_sumTN: typ list -> typ
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   116
  val mk_sumTN_balanced: typ list -> typ
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   117
49368
df359ce891ac added induct tactic
blanchet
parents: 49342
diff changeset
   118
  val id_const: typ -> term
df359ce891ac added induct tactic
blanchet
parents: 49342
diff changeset
   119
  val id_abs: typ -> term
df359ce891ac added induct tactic
blanchet
parents: 49342
diff changeset
   120
49121
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   121
  val Inl_const: typ -> typ -> term
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   122
  val Inr_const: typ -> typ -> term
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   123
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   124
  val mk_Inl: typ -> term -> term
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   125
  val mk_Inr: typ -> term -> term
49121
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   126
  val mk_InN: typ list -> term -> int -> term
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   127
  val mk_InN_balanced: typ -> int -> term -> int -> term
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   128
  val mk_sum_case: term * term -> term
49129
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   129
  val mk_sum_caseN: term list -> term
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   130
  val mk_sum_caseN_balanced: term list -> term
49121
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   131
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   132
  val dest_sumT: typ -> typ * typ
49176
6d29d2db5f88 construct high-level iterator RHS
blanchet
parents: 49169
diff changeset
   133
  val dest_sumTN: int -> typ -> typ list
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   134
  val dest_sumTN_balanced: int -> typ -> typ list
49176
6d29d2db5f88 construct high-level iterator RHS
blanchet
parents: 49169
diff changeset
   135
  val dest_tupleT: int -> typ -> typ list
6d29d2db5f88 construct high-level iterator RHS
blanchet
parents: 49169
diff changeset
   136
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   137
  val mk_Field: term -> term
49275
ce87d6a901eb split sum types in corecursor definition
blanchet
parents: 49264
diff changeset
   138
  val mk_If: term -> term -> term -> term
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   139
  val mk_union: term * term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   140
49125
5fc5211cf104 implemented "mk_exhaust_tac"
blanchet
parents: 49121
diff changeset
   141
  val mk_sumEN: int -> thm
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   142
  val mk_sumEN_balanced: int -> thm
49335
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   143
  val mk_sumEN_tupled_balanced: int list -> thm
49130
3c26e17b2849 implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents: 49129
diff changeset
   144
  val mk_sum_casesN: int -> int -> thm
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   145
  val mk_sum_casesN_balanced: int -> int -> thm
49125
5fc5211cf104 implemented "mk_exhaust_tac"
blanchet
parents: 49121
diff changeset
   146
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   147
  val fixpoint: ('a * 'a -> bool) -> ('a list -> 'a list) -> 'a list -> 'a list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   148
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   149
  val fp_bnf: (mixfix list -> (string * sort) list option -> binding list ->
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   150
    typ list * typ list list -> BNF_Def.BNF list -> local_theory -> 'a) ->
49169
937a0fadddfb honor mixfix specifications
blanchet
parents: 49156
diff changeset
   151
    binding list -> mixfix list -> (string * sort) list -> ((string * sort) * typ) list ->
49226
510c6d4a73ec fixed and enabled iterator/recursor theorems
blanchet
parents: 49225
diff changeset
   152
    local_theory -> BNF_Def.BNF list * 'a
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   153
  val fp_bnf_cmd: (mixfix list -> (string * sort) list option -> binding list ->
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   154
    typ list * typ list list -> BNF_Def.BNF list -> local_theory -> 'a) ->
49134
846264f80f16 optionally provide extra dead variables to the FP constructions
blanchet
parents: 49132
diff changeset
   155
    binding list * (string list * string list) -> local_theory -> 'a
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   156
end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   157
49457
1d2825673cec renamed "bnf_fp_util.ML" to "bnf_fp.ML"
blanchet
parents: 49456
diff changeset
   158
structure BNF_FP : BNF_FP =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   159
struct
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   160
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   161
open BNF_Comp
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   162
open BNF_Def
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   163
open BNF_Util
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   164
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   165
val timing = true;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   166
fun time timer msg = (if timing
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   167
  then warning (msg ^ ": " ^ ATP_Util.string_from_time (Timer.checkRealTimer timer))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   168
  else (); Timer.startRealTimer ());
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   169
49223
blanchet
parents: 49222
diff changeset
   170
val preN = "pre_"
blanchet
parents: 49222
diff changeset
   171
val rawN = "raw_"
49218
d01a5c918298 renamed xxxBNF to pre_xxx
blanchet
parents: 49207
diff changeset
   172
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   173
val coN = "co"
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   174
val unN = "un"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   175
val algN = "alg"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   176
val IITN = "IITN"
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   177
val foldN = "fold"
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   178
val foldsN = foldN ^ "s"
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   179
val unfoldN = unN ^ foldN
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   180
val unfoldsN = unfoldN ^ "s"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   181
val uniqueN = "_unique"
49438
5bc80d96241e group "simps" together
blanchet
parents: 49425
diff changeset
   182
val simpsN = "simps"
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   183
val ctorN = "ctor"
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   184
val dtorN = "dtor"
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   185
val ctor_foldN = ctorN ^ "_" ^ foldN
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   186
val ctor_foldsN = ctor_foldN ^ "s"
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   187
val dtor_unfoldN = dtorN ^ "_" ^ unfoldN
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   188
val dtor_unfoldsN = dtor_unfoldN ^ "s"
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   189
val ctor_fold_uniqueN = ctor_foldN ^ uniqueN
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   190
val dtor_unfold_uniqueN = dtor_unfoldN ^ uniqueN
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   191
val ctor_dtor_unfoldsN = ctorN ^ "_" ^ dtor_unfoldN ^ "s"
49541
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49536
diff changeset
   192
val ctor_mapN = ctorN ^ "_" ^ mapN
32fb6e4c7f4b renamed "map_simps" to "{c,d}tor_maps"
blanchet
parents: 49536
diff changeset
   193
val dtor_mapN = dtorN ^ "_" ^ mapN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   194
val map_uniqueN = mapN ^ uniqueN
49543
53b3c532a082 renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents: 49542
diff changeset
   195
val ctor_map_uniqueN = ctorN ^ "_" ^ map_uniqueN
53b3c532a082 renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents: 49542
diff changeset
   196
val dtor_map_uniqueN = dtorN ^ "_" ^ map_uniqueN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   197
val min_algN = "min_alg"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   198
val morN = "mor"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   199
val bisN = "bis"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   200
val lsbisN = "lsbis"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   201
val sum_bdTN = "sbdT"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   202
val sum_bdN = "sbd"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   203
val carTN = "carT"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   204
val strTN = "strT"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   205
val isNodeN = "isNode"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   206
val LevN = "Lev"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   207
val rvN = "recover"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   208
val behN = "beh"
49542
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
   209
fun mk_setsN i = mk_setN i ^ "s"
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
   210
val mk_ctor_setsN = prefix (ctorN ^ "_") o mk_setsN
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
   211
val mk_dtor_setsN = prefix (dtorN ^ "_") o mk_setsN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   212
fun mk_set_inductN i = mk_setN i ^ "_induct"
49542
b39354db8629 renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents: 49541
diff changeset
   213
val mk_dtor_set_inductN = prefix (dtorN ^ "_") o mk_set_inductN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   214
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   215
val str_initN = "str_init"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   216
val recN = "rec"
49342
8ea4bad49ed5 rough and ready induction
blanchet
parents: 49338
diff changeset
   217
val recsN = recN ^ "s"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   218
val corecN = coN ^ recN
49342
8ea4bad49ed5 rough and ready induction
blanchet
parents: 49338
diff changeset
   219
val corecsN = corecN ^ "s"
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   220
val ctor_recN = ctorN ^ "_" ^ recN
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   221
val ctor_recsN = ctor_recN ^ "s"
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   222
val dtor_corecN = dtorN ^ "_" ^ corecN
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   223
val dtor_corecsN = dtor_corecN ^ "s"
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   224
val ctor_dtor_corecsN = ctorN ^ "_" ^ dtor_corecN ^ "s"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   225
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   226
val ctor_dtorN = ctorN ^ "_" ^ dtorN
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   227
val dtor_ctorN = dtorN ^ "_" ^ ctorN
49020
f379cf5d71bd more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents: 49019
diff changeset
   228
val nchotomyN = "nchotomy"
f379cf5d71bd more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents: 49019
diff changeset
   229
fun mk_nchotomyN s = s ^ "_" ^ nchotomyN
49019
fc4decdba5ce more work on BNF sugar
blanchet
parents: 48975
diff changeset
   230
val injectN = "inject"
fc4decdba5ce more work on BNF sugar
blanchet
parents: 48975
diff changeset
   231
fun mk_injectN s = s ^ "_" ^ injectN
49020
f379cf5d71bd more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents: 49019
diff changeset
   232
val exhaustN = "exhaust"
f379cf5d71bd more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents: 49019
diff changeset
   233
fun mk_exhaustN s = s ^ "_" ^ exhaustN
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   234
val ctor_injectN = mk_injectN ctorN
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   235
val ctor_exhaustN = mk_exhaustN ctorN
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   236
val dtor_injectN = mk_injectN dtorN
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   237
val dtor_exhaustN = mk_exhaustN dtorN
49545
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
   238
val ctor_relN = ctorN ^ "_" ^ relN
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
   239
val dtor_relN = dtorN ^ "_" ^ relN
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
   240
val ctor_srelN = ctorN ^ "_" ^ srelN
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
   241
val dtor_srelN = dtorN ^ "_" ^ srelN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   242
val inductN = "induct"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   243
val coinductN = coN ^ inductN
49501
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   244
val ctor_inductN = ctorN ^ "_" ^ inductN
acc9635a644a renamed "fld"/"unf" to "ctor"/"dtor"
blanchet
parents: 49499
diff changeset
   245
val ctor_induct2N = ctor_inductN ^ "2"
49581
4e5bd3883429 renamed "dtor_coinduct" etc. to "dtor_map_coinduct"
blanchet
parents: 49545
diff changeset
   246
val dtor_map_coinductN = dtor_mapN ^ "_" ^ coinductN
49582
557302525778 renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
blanchet
parents: 49581
diff changeset
   247
val dtor_coinductN = dtorN ^ "_" ^ coinductN
49545
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
   248
val dtor_srel_coinductN = dtor_srelN ^ "_" ^ coinductN
49499
464812bef4d9 renamed "upto" coinduction "strong"
blanchet
parents: 49498
diff changeset
   249
val strongN = "strong_"
49581
4e5bd3883429 renamed "dtor_coinduct" etc. to "dtor_map_coinduct"
blanchet
parents: 49545
diff changeset
   250
val dtor_map_strong_coinductN = dtor_mapN ^ "_" ^ strongN ^ coinductN
49582
557302525778 renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
blanchet
parents: 49581
diff changeset
   251
val dtor_strong_coinductN = dtorN ^ "_" ^ strongN ^ coinductN
49545
8bb6e2d7346b renamed coinduction principles to have "dtor" in the name
blanchet
parents: 49544
diff changeset
   252
val dtor_srel_strong_coinductN = dtor_srelN ^ "_" ^ strongN ^ coinductN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   253
val hsetN = "Hset"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   254
val hset_recN = hsetN ^ "_rec"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   255
val set_inclN = "set_incl"
49544
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
   256
val ctor_set_inclN = ctorN ^ "_" ^ set_inclN
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
   257
val dtor_set_inclN = dtorN ^ "_" ^ set_inclN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   258
val set_set_inclN = "set_set_incl"
49544
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
   259
val ctor_set_set_inclN = ctorN ^ "_" ^ set_set_inclN
24094fa47e0d renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents: 49543
diff changeset
   260
val dtor_set_set_inclN = dtorN ^ "_" ^ set_set_inclN
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   261
49338
blanchet
parents: 49337
diff changeset
   262
val caseN = "case"
49342
8ea4bad49ed5 rough and ready induction
blanchet
parents: 49338
diff changeset
   263
val discN = "disc"
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   264
val disc_unfoldsN = discN ^ "_" ^ unfoldsN
49342
8ea4bad49ed5 rough and ready induction
blanchet
parents: 49338
diff changeset
   265
val disc_corecsN = discN ^ "_" ^ corecsN
49482
e6d6869eed08 generate coiter_iff and corec_iff theorems
blanchet
parents: 49463
diff changeset
   266
val iffN = "_iff"
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   267
val disc_unfold_iffN = discN ^ "_" ^ unfoldN ^ iffN
49484
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49482
diff changeset
   268
val disc_corec_iffN = discN ^ "_" ^ corecN ^ iffN
49536
898aea2e7a94 started work on generation of "rel" theorems
blanchet
parents: 49518
diff changeset
   269
val relsN = relN ^ "s"
49342
8ea4bad49ed5 rough and ready induction
blanchet
parents: 49338
diff changeset
   270
val selN = "sel"
49536
898aea2e7a94 started work on generation of "rel" theorems
blanchet
parents: 49518
diff changeset
   271
val sel_relsN = selN ^ "_" ^ relsN
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49502
diff changeset
   272
val sel_unfoldsN = selN ^ "_" ^ unfoldsN
49342
8ea4bad49ed5 rough and ready induction
blanchet
parents: 49338
diff changeset
   273
val sel_corecsN = selN ^ "_" ^ corecsN
49338
blanchet
parents: 49337
diff changeset
   274
49498
acc583e14167 tuned variable names
blanchet
parents: 49484
diff changeset
   275
val mk_common_name = space_implode "_";
49327
541d818d2ff3 put an underscore between names, for compatibility with old package (and also because it makes sense)
blanchet
parents: 49308
diff changeset
   276
49330
276ff43ee0b1 reuse generated names (they look better + slightly more efficient)
blanchet
parents: 49327
diff changeset
   277
fun retype_free T (Free (s, _)) = Free (s, T);
276ff43ee0b1 reuse generated names (they look better + slightly more efficient)
blanchet
parents: 49327
diff changeset
   278
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   279
fun dest_sumT (Type (@{type_name sum}, [T, T'])) = (T, T');
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   280
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   281
fun dest_sumTN 1 T = [T]
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   282
  | dest_sumTN n (Type (@{type_name sum}, [T, T'])) = T :: dest_sumTN (n - 1) T';
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   283
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   284
val dest_sumTN_balanced = Balanced_Tree.dest dest_sumT;
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   285
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   286
(* TODO: move something like this to "HOLogic"? *)
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   287
fun dest_tupleT 0 @{typ unit} = []
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   288
  | dest_tupleT 1 T = [T]
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   289
  | dest_tupleT n (Type (@{type_name prod}, [T, T'])) = T :: dest_tupleT (n - 1) T';
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   290
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   291
val mk_sumTN = Library.foldr1 mk_sumT;
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   292
val mk_sumTN_balanced = Balanced_Tree.make mk_sumT;
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   293
49368
df359ce891ac added induct tactic
blanchet
parents: 49342
diff changeset
   294
fun id_const T = Const (@{const_name id}, T --> T);
df359ce891ac added induct tactic
blanchet
parents: 49342
diff changeset
   295
fun id_abs T = Abs (Name.uu, T, Bound 0);
df359ce891ac added induct tactic
blanchet
parents: 49342
diff changeset
   296
49121
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   297
fun Inl_const LT RT = Const (@{const_name Inl}, LT --> mk_sumT (LT, RT));
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   298
fun mk_Inl RT t = Inl_const (fastype_of t) RT $ t;
49121
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   299
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   300
fun Inr_const LT RT = Const (@{const_name Inr}, RT --> mk_sumT (LT, RT));
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   301
fun mk_Inr LT t = Inr_const LT (fastype_of t) $ t;
49121
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   302
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   303
fun mk_InN [_] t 1 = t
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   304
  | mk_InN (_ :: Ts) t 1 = mk_Inl (mk_sumTN Ts) t
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   305
  | mk_InN (LT :: Ts) t m = mk_Inr LT (mk_InN Ts t (m - 1))
49121
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   306
  | mk_InN Ts t _ = raise (TYPE ("mk_InN", Ts, [t]));
9e0acaa470ab more work on FP sugar
blanchet
parents: 49119
diff changeset
   307
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   308
fun mk_InN_balanced sum_T n t k =
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   309
  let
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   310
    fun repair_types T (Const (s as @{const_name Inl}, _) $ t) = repair_inj_types T s fst t
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   311
      | repair_types T (Const (s as @{const_name Inr}, _) $ t) = repair_inj_types T s snd t
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   312
      | repair_types _ t = t
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   313
    and repair_inj_types T s get t =
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   314
      let val T' = get (dest_sumT T) in
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   315
        Const (s, T' --> T) $ repair_types T' t
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   316
      end;
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   317
  in
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   318
    Balanced_Tree.access {left = mk_Inl dummyT, right = mk_Inr dummyT, init = t} n k
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   319
    |> repair_types sum_T
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   320
  end;
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   321
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   322
fun mk_sum_case (f, g) =
49129
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   323
  let
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   324
    val fT = fastype_of f;
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   325
    val gT = fastype_of g;
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   326
  in
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   327
    Const (@{const_name sum_case},
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   328
      fT --> gT --> mk_sumT (domain_type fT, domain_type gT) --> range_type fT) $ f $ g
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   329
  end;
b5413cb7d860 define "case" constant
blanchet
parents: 49128
diff changeset
   330
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   331
val mk_sum_caseN = Library.foldr1 mk_sum_case;
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   332
val mk_sum_caseN_balanced = Balanced_Tree.make mk_sum_case;
49176
6d29d2db5f88 construct high-level iterator RHS
blanchet
parents: 49169
diff changeset
   333
49275
ce87d6a901eb split sum types in corecursor definition
blanchet
parents: 49264
diff changeset
   334
fun mk_If p t f =
ce87d6a901eb split sum types in corecursor definition
blanchet
parents: 49264
diff changeset
   335
  let val T = fastype_of t;
ce87d6a901eb split sum types in corecursor definition
blanchet
parents: 49264
diff changeset
   336
  in Const (@{const_name If}, HOLogic.boolT --> T --> T --> T) $ p $ t $ f end;
ce87d6a901eb split sum types in corecursor definition
blanchet
parents: 49264
diff changeset
   337
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   338
fun mk_Field r =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   339
  let val T = fst (dest_relT (fastype_of r));
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   340
  in Const (@{const_name Field}, mk_relT (T, T) --> HOLogic.mk_setT T) $ r end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   341
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   342
val mk_union = HOLogic.mk_binop @{const_name sup};
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   343
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   344
(*dangerous; use with monotonic, converging functions only!*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   345
fun fixpoint eq f X = if subset eq (f X, X) then X else fixpoint eq f (f X);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   346
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   347
(* stolen from "~~/src/HOL/Tools/Datatype/datatype_aux.ML" *)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   348
fun split_conj_thm th =
49119
1f605c36869c more work on FP sugar
blanchet
parents: 49075
diff changeset
   349
  ((th RS conjunct1) :: split_conj_thm (th RS conjunct2)) handle THM _ => [th];
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   350
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   351
fun split_conj_prems limit th =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   352
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   353
    fun split n i th =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   354
      if i = n then th else split n (i + 1) (conjI RSN (i, th)) handle THM _ => th;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   355
  in split limit 1 th end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   356
49255
2ecc533d6697 use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents: 49240
diff changeset
   357
fun mk_sumEN 1 = @{thm one_pointE}
49240
f7e75b802ef2 stabilized generation of parameterized theorem
traytel
parents: 49231
diff changeset
   358
  | mk_sumEN 2 = @{thm sumE}
f7e75b802ef2 stabilized generation of parameterized theorem
traytel
parents: 49231
diff changeset
   359
  | mk_sumEN n =
f7e75b802ef2 stabilized generation of parameterized theorem
traytel
parents: 49231
diff changeset
   360
    (fold (fn i => fn thm => @{thm obj_sum_step} RSN (i, thm)) (2 upto n - 1) @{thm obj_sumE}) OF
f7e75b802ef2 stabilized generation of parameterized theorem
traytel
parents: 49231
diff changeset
   361
      replicate n (impI RS allI);
49125
5fc5211cf104 implemented "mk_exhaust_tac"
blanchet
parents: 49121
diff changeset
   362
49335
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   363
fun mk_obj_sumEN_balanced n =
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   364
  Balanced_Tree.make (fn (thm1, thm2) => thm1 RSN (1, thm2 RSN (2, @{thm obj_sumE_f})))
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   365
    (replicate n asm_rl);
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   366
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   367
fun mk_sumEN_balanced' n all_impIs = mk_obj_sumEN_balanced n OF all_impIs RS @{thm obj_one_pointE};
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   368
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   369
fun mk_sumEN_balanced 1 = @{thm one_pointE} (*optimization*)
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   370
  | mk_sumEN_balanced 2 = @{thm sumE} (*optimization*)
49335
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   371
  | mk_sumEN_balanced n = mk_sumEN_balanced' n (replicate n (impI RS allI));
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   372
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   373
fun mk_tupled_allIN 0 = @{thm unit_all_impI}
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   374
  | mk_tupled_allIN 1 = @{thm impI[THEN allI]}
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   375
  | mk_tupled_allIN 2 = @{thm prod_all_impI} (*optimization*)
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   376
  | mk_tupled_allIN n = mk_tupled_allIN (n - 1) RS @{thm prod_all_impI_step};
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   377
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   378
fun mk_sumEN_tupled_balanced ms =
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   379
  let val n = length ms in
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   380
    if forall (curry (op =) 1) ms then mk_sumEN_balanced n
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   381
    else mk_sumEN_balanced' n (map mk_tupled_allIN ms)
096967bf3940 added sumEN_tupled_balanced
blanchet
parents: 49330
diff changeset
   382
  end;
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   383
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   384
fun mk_sum_casesN 1 1 = refl
49130
3c26e17b2849 implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents: 49129
diff changeset
   385
  | mk_sum_casesN _ 1 = @{thm sum.cases(1)}
3c26e17b2849 implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents: 49129
diff changeset
   386
  | mk_sum_casesN 2 2 = @{thm sum.cases(2)}
49264
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   387
  | mk_sum_casesN n k = trans OF [@{thm sum_case_step(2)}, mk_sum_casesN (n - 1) (k - 1)];
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   388
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   389
fun mk_sum_step base step thm =
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   390
  if Thm.eq_thm_prop (thm, refl) then base else trans OF [step, thm];
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   391
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   392
fun mk_sum_casesN_balanced 1 1 = refl
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   393
  | mk_sum_casesN_balanced n k =
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   394
    Balanced_Tree.access {left = mk_sum_step @{thm sum.cases(1)} @{thm sum_case_step(1)},
9059e0dbdbc1 implemented and use "mk_sum_casesN_balanced"
blanchet
parents: 49255
diff changeset
   395
      right = mk_sum_step @{thm sum.cases(2)} @{thm sum_case_step(2)}, init = refl} n k;
49130
3c26e17b2849 implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents: 49129
diff changeset
   396
49141
aca966dc18f6 added comment for Dmitriy
blanchet
parents: 49134
diff changeset
   397
(* FIXME: because of "@ lhss", the output could contain type variables that are not in the input;
aca966dc18f6 added comment for Dmitriy
blanchet
parents: 49134
diff changeset
   398
   also, "fp_sort" should put the "resBs" first and in the order in which they appear *)
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   399
fun fp_sort lhss NONE Ass = Library.sort (Term_Ord.typ_ord o pairself TFree)
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   400
    (subtract (op =) lhss (fold (fold (insert (op =))) Ass [])) @ lhss
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   401
  | fp_sort lhss (SOME resBs) Ass =
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   402
    (subtract (op =) lhss (filter (fn T => exists (fn Ts => member (op =) Ts T) Ass) resBs)) @ lhss;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   403
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   404
fun mk_fp_bnf timer construct resBs bs sort lhss bnfs deadss livess unfold_set lthy =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   405
  let
49498
acc583e14167 tuned variable names
blanchet
parents: 49484
diff changeset
   406
    val name = mk_common_name (map Binding.name_of bs);
49425
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   407
    fun qualify i =
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   408
      let val namei = name ^ nonzero_string_of_int i;
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   409
      in Binding.qualify true namei end;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   410
49132
81487fc17185 added robustness
blanchet
parents: 49130
diff changeset
   411
    val Ass = map (map dest_TFree) livess;
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   412
    val resDs = (case resBs of NONE => [] | SOME Ts => fold (subtract (op =)) Ass Ts);
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   413
    val Ds = fold (fold Term.add_tfreesT) deadss [];
49132
81487fc17185 added robustness
blanchet
parents: 49130
diff changeset
   414
49156
2a361e09101b error message only in case of an error
traytel
parents: 49141
diff changeset
   415
    val _ = (case Library.inter (op =) Ds lhss of [] => ()
49132
81487fc17185 added robustness
blanchet
parents: 49130
diff changeset
   416
      | A :: _ => error ("Nonadmissible type recursion (cannot take fixed point of dead type \
81487fc17185 added robustness
blanchet
parents: 49130
diff changeset
   417
        \variable " ^ quote (Syntax.string_of_typ lthy (TFree A)) ^ ")"));
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   418
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   419
    val timer = time (timer "Construction of BNFs");
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   420
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   421
    val ((kill_poss, _), (bnfs', (unfold_set', lthy'))) =
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   422
      normalize_bnfs qualify Ass Ds sort bnfs unfold_set lthy;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   423
49132
81487fc17185 added robustness
blanchet
parents: 49130
diff changeset
   424
    val Dss = map3 (append oo map o nth) livess kill_poss deadss;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   425
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   426
    val ((bnfs'', deadss), lthy'') =
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   427
      fold_map3 (seal_bnf unfold_set') (map (Binding.prefix_name preN) bs) Dss bnfs' lthy'
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   428
      |>> split_list;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   429
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   430
    val timer = time (timer "Normalization & sealing of BNFs");
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   431
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   432
    val res = construct resBs bs (map TFree resDs, deadss) bnfs'' lthy'';
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   433
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   434
    val timer = time (timer "FP construction in total");
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   435
  in
49308
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents: 49275
diff changeset
   436
    timer; (bnfs'', res)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   437
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   438
49169
937a0fadddfb honor mixfix specifications
blanchet
parents: 49156
diff changeset
   439
fun fp_bnf construct bs mixfixes resBs eqs lthy =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   440
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   441
    val timer = time (Timer.startRealTimer ());
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   442
    val (lhss, rhss) = split_list eqs;
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   443
    val sort = fp_sort lhss (SOME resBs);
49425
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   444
    fun qualify b = Binding.qualify true (Binding.name_of (Binding.prefix_name rawN b));
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   445
    val ((bnfs, (Dss, Ass)), (unfold_set, lthy')) = apfst (apsnd split_list o split_list)
49425
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   446
      (fold_map2 (fn b => bnf_of_typ Smart_Inline (qualify b) sort) bs rhss
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   447
        (empty_unfolds, lthy));
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   448
  in
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   449
    mk_fp_bnf timer (construct mixfixes) (SOME resBs) bs sort lhss bnfs Dss Ass unfold_set lthy'
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   450
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   451
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   452
fun fp_bnf_cmd construct (bs, (raw_lhss, raw_bnfs)) lthy =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   453
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   454
    val timer = time (Timer.startRealTimer ());
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   455
    val lhss = map (dest_TFree o Syntax.read_typ lthy) raw_lhss;
49185
073d7d1b7488 respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents: 49176
diff changeset
   456
    val sort = fp_sort lhss NONE;
49425
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   457
    fun qualify b = Binding.qualify true (Binding.name_of (Binding.prefix_name rawN b));
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   458
    val ((bnfs, (Dss, Ass)), (unfold_set, lthy')) = apfst (apsnd split_list o split_list)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   459
      (fold_map2 (fn b => fn rawT =>
49425
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   460
        (bnf_of_typ Smart_Inline (qualify b) sort (Syntax.read_typ lthy rawT)))
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   461
      bs raw_bnfs (empty_unfolds, lthy));
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   462
  in
49502
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   463
    snd (mk_fp_bnf timer
92a7c1842c78 tuned a few ML names
blanchet
parents: 49501
diff changeset
   464
      (construct (map (K NoSyn) bs)) NONE bs sort lhss bnfs Dss Ass unfold_set lthy')
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   465
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   466
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   467
end;