src/HOL/BNF/Tools/bnf_util.ML
author traytel
Wed, 18 Dec 2013 11:03:40 +0100
changeset 54841 af71b753c459
parent 54601 91a1e4aa7c80
child 54900 136fe16e726a
permissions -rw-r--r--
express weak pullback property of bnfs only in terms of the relator
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49509
163914705f8d renamed top-level theory from "Codatatype" to "BNF"
blanchet
parents: 49504
diff changeset
     1
(*  Title:      HOL/BNF/Tools/bnf_util.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
49282
c057e1b39f16 renamed "BNF_Library" to "BNF_Util"
blanchet
parents: 49255
diff changeset
     5
Library for bounded natural functors.
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
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     8
signature BNF_UTIL =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
sig
54008
b15cfc2864de refactoring -- splitting between constructor sugar dependencies and true BNF dependencies
blanchet
parents: 53888
diff changeset
    10
  include CTR_SUGAR_UTIL
b15cfc2864de refactoring -- splitting between constructor sugar dependencies and true BNF dependencies
blanchet
parents: 53888
diff changeset
    11
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    12
  val map6: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    13
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    14
  val map7: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    15
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    16
  val map8: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    17
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list -> 'i list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    18
  val map9: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    19
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    20
    'i list -> 'j list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    21
  val map10: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'k) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    22
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    23
    'i list -> 'j list -> 'k list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    24
  val map11: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'k -> 'l) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    25
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    26
    'i list -> 'j list -> 'k list -> 'l list
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    27
  val map12: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'k -> 'l -> 'm) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    28
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    29
    'i list -> 'j list -> 'k list -> 'l list -> 'm list
53705
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
    30
  val map13: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'k -> 'l -> 'm -> 'n) ->
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
    31
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list ->
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
    32
    'i list -> 'j list -> 'k list -> 'l list -> 'm list -> 'n list
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    33
  val fold_map4: ('a -> 'b -> 'c -> 'd -> 'e -> 'f * 'e) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    34
    'a list -> 'b list -> 'c list -> 'd list -> 'e -> 'f list * 'e
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    35
  val fold_map5: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g * 'f) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    36
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f -> 'g list * 'f
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    37
  val fold_map6: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h * 'g) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    38
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g -> 'h list * 'g
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    39
  val fold_map7: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i * 'h) ->
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    40
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h -> 'i list * 'h
51758
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
    41
  val fold_map8: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j * 'i) ->
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
    42
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list -> 'i ->
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
    43
    'j list * 'i
51767
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
    44
  val fold_map9: ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'k * 'j) ->
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
    45
    'a list -> 'b list -> 'c list -> 'd list -> 'e list -> 'f list -> 'g list -> 'h list ->
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
    46
    'i list -> 'j -> 'k list * 'j
51903
126f8d11f873 move function to library
blanchet
parents: 51894
diff changeset
    47
  val split_list4: ('a * 'b * 'c * 'd) list -> 'a list * 'b list * 'c list * 'd list
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54601
diff changeset
    48
  val split_list5: ('a * 'b * 'c * 'd * 'e) list -> 'a list * 'b list * 'c list * 'd list * 'e list
54008
b15cfc2864de refactoring -- splitting between constructor sugar dependencies and true BNF dependencies
blanchet
parents: 53888
diff changeset
    49
  val find_indices: ('b * 'a -> bool) -> 'a list -> 'b list -> int list
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    50
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    51
  val mk_TFreess: int list -> Proof.context -> typ list list * Proof.context
49177
db8ce685073f introduced and used "mk_Freesss", and simplified "mk_Freess(')"
blanchet
parents: 49176
diff changeset
    52
  val mk_Freesss: string -> typ list list list -> Proof.context ->
db8ce685073f introduced and used "mk_Freesss", and simplified "mk_Freess(')"
blanchet
parents: 49176
diff changeset
    53
    term list list list * Proof.context
49200
73f9aede57a4 correctly curry recursor arguments
blanchet
parents: 49178
diff changeset
    54
  val mk_Freessss: string -> typ list list list list -> Proof.context ->
73f9aede57a4 correctly curry recursor arguments
blanchet
parents: 49178
diff changeset
    55
    term list list list list * Proof.context
53034
6067703399ad moved library function where it belongs, and used Dmitriy's inside-out implementation
blanchet
parents: 52985
diff changeset
    56
  val nonzero_string_of_int: int -> string
51762
219a3063ed29 derive "map_cong"
blanchet
parents: 51760
diff changeset
    57
  val retype_free: typ -> term -> term
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    58
53036
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
    59
  val binder_fun_types: typ -> typ list
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
    60
  val body_fun_type: typ -> typ
52280
blanchet
parents: 52279
diff changeset
    61
  val num_binder_types: typ -> int
53037
blanchet
parents: 53036
diff changeset
    62
  val strip_fun_type: typ -> typ list * typ
49395
323414474c1f use strip_typeN in bnf_def (instead of repairing strip_type)
traytel
parents: 49366
diff changeset
    63
  val strip_typeN: int -> typ -> typ list * typ
323414474c1f use strip_typeN in bnf_def (instead of repairing strip_type)
traytel
parents: 49366
diff changeset
    64
49463
83ac281bcdc2 provide predicator, define relator
blanchet
parents: 49434
diff changeset
    65
  val mk_pred2T: typ -> typ -> typ
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    66
  val mk_relT: typ * typ -> typ
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    67
  val dest_relT: typ -> typ * typ
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
    68
  val dest_pred2T: typ -> typ * typ
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    69
  val mk_sumT: typ * typ -> typ
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    70
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    71
  val ctwo: term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    72
  val fst_const: typ -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    73
  val snd_const: typ -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    74
  val Id_const: typ -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    75
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    76
  val mk_Ball: term -> term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    77
  val mk_Bex: term -> term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    78
  val mk_Card_order: term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    79
  val mk_Field: term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    80
  val mk_Gr: term -> term -> term
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
    81
  val mk_Grp: term -> term -> term
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    82
  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
    83
  val mk_Union: typ -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    84
  val mk_card_binop: string -> (typ * typ -> typ) -> term -> term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    85
  val mk_card_of: term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    86
  val mk_card_order: term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    87
  val mk_cexp: term -> term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    88
  val mk_cinfinite: term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    89
  val mk_collect: term list -> typ -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    90
  val mk_converse: term -> term
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
    91
  val mk_conversep: term -> term
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    92
  val mk_cprod: term -> term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    93
  val mk_csum: term -> term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    94
  val mk_dir_image: term -> term -> term
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52545
diff changeset
    95
  val mk_fun_rel: term -> term -> term
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    96
  val mk_image: term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    97
  val mk_in: term list -> term list -> typ -> term
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
    98
  val mk_leq: term -> term -> term
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    99
  val mk_ordLeq: term -> term -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   100
  val mk_rel_comp: term * term -> term
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   101
  val mk_rel_compp: term * term -> term
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   102
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   103
  (*parameterized terms*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   104
  val mk_nthN: int -> term -> int -> term
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   105
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   106
  (*parameterized thms*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   107
  val mk_Un_upper: int -> int -> thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   108
  val mk_conjIN: int -> thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   109
  val mk_conjunctN: int -> int -> thm
49337
538687a77075 set up things for (co)induction sugar
blanchet
parents: 49298
diff changeset
   110
  val conj_dests: int -> thm -> thm list
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   111
  val mk_nthI: int -> int -> thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   112
  val mk_nth_conv: int -> int -> thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   113
  val mk_ordLeq_csum: int -> int -> thm -> thm
49366
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49342
diff changeset
   114
  val mk_UnIN: int -> int -> thm
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   115
49585
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   116
  val Pair_eqD: thm
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   117
  val Pair_eqI: thm
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   118
  val ctrans: thm
49585
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   119
  val id_apply: thm
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   120
  val meta_mp: thm
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   121
  val meta_spec: thm
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   122
  val o_apply: thm
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49484
diff changeset
   123
  val set_mp: thm
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49484
diff changeset
   124
  val set_rev_mp: thm
49490
394870e51d18 tuned antiquotations
traytel
parents: 49488
diff changeset
   125
  val subset_UNIV: thm
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   126
  val mk_sym: thm -> thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   127
  val mk_trans: thm -> thm -> thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   128
49605
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   129
  val is_triv_implies: thm -> bool
49484
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   130
  val is_refl: thm -> bool
49605
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   131
  val is_concl_refl: thm -> bool
49484
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   132
  val no_refl: thm list -> thm list
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   133
  val no_reflexive: thm list -> thm list
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   134
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49490
diff changeset
   135
  val fold_thms: Proof.context -> thm list -> thm -> thm
49463
83ac281bcdc2 provide predicator, define relator
blanchet
parents: 49434
diff changeset
   136
52079
291bb1f4af29 tuned signature;
wenzelm
parents: 51903
diff changeset
   137
  val parse_binding_colon: binding parser
291bb1f4af29 tuned signature;
wenzelm
parents: 51903
diff changeset
   138
  val parse_opt_binding_colon: binding parser
54601
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   139
  val parse_type_args_named_constrained: (binding option * (string * string option)) list parser
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   140
  val parse_map_rel_bindings: (binding * binding) parser
49434
433dc7e028c8 separated registration of BNFs from bnf_def (BNFs are now stored only for bnf_def and (co)data commands)
traytel
parents: 49425
diff changeset
   141
49835
31f32ec4d766 discontinued typedef with alternative name;
wenzelm
parents: 49833
diff changeset
   142
  val typedef: binding * (string * sort) list * mixfix -> term ->
49228
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   143
    (binding * binding) option -> tactic -> local_theory -> (string * Typedef.info) * local_theory
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   144
end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   145
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   146
structure BNF_Util : BNF_UTIL =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   147
struct
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   148
54008
b15cfc2864de refactoring -- splitting between constructor sugar dependencies and true BNF dependencies
blanchet
parents: 53888
diff changeset
   149
open Ctr_Sugar_Util
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   150
54008
b15cfc2864de refactoring -- splitting between constructor sugar dependencies and true BNF dependencies
blanchet
parents: 53888
diff changeset
   151
(* Library proper *)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   152
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   153
fun map6 _ [] [] [] [] [] [] = []
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   154
  | map6 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) (x6::x6s) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   155
    f x1 x2 x3 x4 x5 x6 :: map6 f x1s x2s x3s x4s x5s x6s
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   156
  | map6 _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   157
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   158
fun map7 _ [] [] [] [] [] [] [] = []
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   159
  | map7 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) (x6::x6s) (x7::x7s) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   160
    f x1 x2 x3 x4 x5 x6 x7 :: map7 f x1s x2s x3s x4s x5s x6s x7s
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   161
  | map7 _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   162
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   163
fun map8 _ [] [] [] [] [] [] [] [] = []
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   164
  | map8 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) (x6::x6s) (x7::x7s) (x8::x8s) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   165
    f x1 x2 x3 x4 x5 x6 x7 x8 :: map8 f x1s x2s x3s x4s x5s x6s x7s x8s
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   166
  | map8 _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   167
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   168
fun map9 _ [] [] [] [] [] [] [] [] [] = []
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   169
  | map9 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   170
      (x6::x6s) (x7::x7s) (x8::x8s) (x9::x9s) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   171
    f x1 x2 x3 x4 x5 x6 x7 x8 x9 :: map9 f x1s x2s x3s x4s x5s x6s x7s x8s x9s
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   172
  | map9 _ _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   173
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   174
fun map10 _ [] [] [] [] [] [] [] [] [] [] = []
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   175
  | map10 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   176
      (x6::x6s) (x7::x7s) (x8::x8s) (x9::x9s) (x10::x10s) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   177
    f x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 :: map10 f x1s x2s x3s x4s x5s x6s x7s x8s x9s x10s
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   178
  | map10 _ _ _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   179
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   180
fun map11 _ [] [] [] [] [] [] [] [] [] [] [] = []
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   181
  | map11 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   182
      (x6::x6s) (x7::x7s) (x8::x8s) (x9::x9s) (x10::x10s) (x11::x11s) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   183
    f x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 :: map11 f x1s x2s x3s x4s x5s x6s x7s x8s x9s x10s x11s
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   184
  | map11 _ _ _ _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   185
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   186
fun map12 _ [] [] [] [] [] [] [] [] [] [] [] [] = []
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   187
  | map12 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   188
      (x6::x6s) (x7::x7s) (x8::x8s) (x9::x9s) (x10::x10s) (x11::x11s) (x12::x12s) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   189
    f x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 ::
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   190
      map12 f x1s x2s x3s x4s x5s x6s x7s x8s x9s x10s x11s x12s
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   191
  | map12 _ _ _ _ _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   192
53705
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
   193
fun map13 _ [] [] [] [] [] [] [] [] [] [] [] [] [] = []
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
   194
  | map13 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s)
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
   195
      (x6::x6s) (x7::x7s) (x8::x8s) (x9::x9s) (x10::x10s) (x11::x11s) (x12::x12s) (x13::x13s) =
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
   196
    f x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 ::
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
   197
      map13 f x1s x2s x3s x4s x5s x6s x7s x8s x9s x10s x11s x12s x13s
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
   198
  | map13 _ _ _ _ _ _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
f58e289eceba enrich data structure
blanchet
parents: 53263
diff changeset
   199
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   200
fun fold_map4 _ [] [] [] [] acc = ([], acc)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   201
  | fold_map4 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) acc =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   202
    let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   203
      val (x, acc') = f x1 x2 x3 x4 acc;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   204
      val (xs, acc'') = fold_map4 f x1s x2s x3s x4s acc';
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   205
    in (x :: xs, acc'') end
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   206
  | fold_map4 _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   207
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   208
fun fold_map5 _ [] [] [] [] [] acc = ([], acc)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   209
  | fold_map5 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) acc =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   210
    let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   211
      val (x, acc') = f x1 x2 x3 x4 x5 acc;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   212
      val (xs, acc'') = fold_map5 f x1s x2s x3s x4s x5s acc';
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   213
    in (x :: xs, acc'') end
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   214
  | fold_map5 _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   215
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   216
fun fold_map6 _ [] [] [] [] [] [] acc = ([], acc)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   217
  | fold_map6 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) (x6::x6s) acc =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   218
    let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   219
      val (x, acc') = f x1 x2 x3 x4 x5 x6 acc;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   220
      val (xs, acc'') = fold_map6 f x1s x2s x3s x4s x5s x6s acc';
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   221
    in (x :: xs, acc'') end
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   222
  | fold_map6 _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   223
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   224
fun fold_map7 _ [] [] [] [] [] [] [] acc = ([], acc)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   225
  | fold_map7 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) (x6::x6s) (x7::x7s) acc =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   226
    let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   227
      val (x, acc') = f x1 x2 x3 x4 x5 x6 x7 acc;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   228
      val (xs, acc'') = fold_map7 f x1s x2s x3s x4s x5s x6s x7s acc';
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   229
    in (x :: xs, acc'') end
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   230
  | fold_map7 _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   231
51758
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   232
fun fold_map8 _ [] [] [] [] [] [] [] [] acc = ([], acc)
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   233
  | fold_map8 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) (x6::x6s) (x7::x7s) (x8::x8s)
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   234
      acc =
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   235
    let
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   236
      val (x, acc') = f x1 x2 x3 x4 x5 x6 x7 x8 acc;
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   237
      val (xs, acc'') = fold_map8 f x1s x2s x3s x4s x5s x6s x7s x8s acc';
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   238
    in (x :: xs, acc'') end
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   239
  | fold_map8 _ _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
55963309557b honor user-specified name for map function
blanchet
parents: 51757
diff changeset
   240
51767
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   241
fun fold_map9 _ [] [] [] [] [] [] [] [] [] acc = ([], acc)
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   242
  | fold_map9 f (x1::x1s) (x2::x2s) (x3::x3s) (x4::x4s) (x5::x5s) (x6::x6s) (x7::x7s) (x8::x8s)
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   243
      (x9::x9s) acc =
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   244
    let
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   245
      val (x, acc') = f x1 x2 x3 x4 x5 x6 x7 x8 x9 acc;
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   246
      val (xs, acc'') = fold_map9 f x1s x2s x3s x4s x5s x6s x7s x8s x9s acc';
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   247
    in (x :: xs, acc'') end
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   248
  | fold_map9 _ _ _ _ _ _ _ _ _ _ _ = raise ListPair.UnequalLengths;
bbcdd8519253 honor user-specified name for relator + generalize syntax
blanchet
parents: 51762
diff changeset
   249
51903
126f8d11f873 move function to library
blanchet
parents: 51894
diff changeset
   250
fun split_list4 [] = ([], [], [], [])
126f8d11f873 move function to library
blanchet
parents: 51894
diff changeset
   251
  | split_list4 ((x1, x2, x3, x4) :: xs) =
126f8d11f873 move function to library
blanchet
parents: 51894
diff changeset
   252
    let val (xs1, xs2, xs3, xs4) = split_list4 xs;
126f8d11f873 move function to library
blanchet
parents: 51894
diff changeset
   253
    in (x1 :: xs1, x2 :: xs2, x3 :: xs3, x4 :: xs4) end;
126f8d11f873 move function to library
blanchet
parents: 51894
diff changeset
   254
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54601
diff changeset
   255
fun split_list5 [] = ([], [], [], [], [])
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54601
diff changeset
   256
  | split_list5 ((x1, x2, x3, x4, x5) :: xs) =
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54601
diff changeset
   257
    let val (xs1, xs2, xs3, xs4, xs5) = split_list5 xs;
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54601
diff changeset
   258
    in (x1 :: xs1, x2 :: xs2, x3 :: xs3, x4 :: xs4, x5 :: xs5) end;
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54601
diff changeset
   259
51790
22517d04d20b more intuitive syntax for equality-style discriminators of nullary constructors
blanchet
parents: 51787
diff changeset
   260
val parse_binding_colon = parse_binding --| @{keyword ":"};
22517d04d20b more intuitive syntax for equality-style discriminators of nullary constructors
blanchet
parents: 51787
diff changeset
   261
val parse_opt_binding_colon = Scan.optional parse_binding_colon Binding.empty;
49434
433dc7e028c8 separated registration of BNFs from bnf_def (BNFs are now stored only for bnf_def and (co)data commands)
traytel
parents: 49425
diff changeset
   262
54601
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   263
val parse_type_arg_constrained =
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   264
  Parse.type_ident -- Scan.option (@{keyword "::"} |-- Parse.!!! Parse.sort);
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   265
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   266
val parse_type_arg_named_constrained =
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   267
   (Parse.minus --| @{keyword ":"} >> K NONE || parse_opt_binding_colon >> SOME) --
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   268
   parse_type_arg_constrained;
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   269
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   270
val parse_type_args_named_constrained =
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   271
  parse_type_arg_constrained >> (single o pair (SOME Binding.empty)) ||
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   272
  @{keyword "("} |-- Parse.!!! (Parse.list1 parse_type_arg_named_constrained --| @{keyword ")"}) ||
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   273
  Scan.succeed [];
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   274
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   275
val parse_map_rel_binding = Parse.short_ident --| @{keyword ":"} -- parse_binding;
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   276
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   277
val no_map_rel = (Binding.empty, Binding.empty);
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   278
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   279
fun extract_map_rel ("map", b) = apfst (K b)
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   280
  | extract_map_rel ("rel", b) = apsnd (K b)
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   281
  | extract_map_rel (s, _) = error ("Unknown label " ^ quote s ^ " (expected \"map\" or \"rel\")");
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   282
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   283
val parse_map_rel_bindings =
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   284
  @{keyword "("} |-- Scan.repeat parse_map_rel_binding --| @{keyword ")"}
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   285
    >> (fn ps => fold extract_map_rel ps no_map_rel) ||
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   286
  Scan.succeed no_map_rel;
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   287
91a1e4aa7c80 command for axiomatic declaration of bnfs---allow theoreticians to fix an arbitrary type with functorial structure and work abstractly on it
traytel
parents: 54544
diff changeset
   288
49228
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   289
(*TODO: is this really different from Typedef.add_typedef_global?*)
53263
d4784d3d3a54 rationalized bindings
blanchet
parents: 53040
diff changeset
   290
fun typedef (b, Ts, mx) set opt_morphs tac lthy =
49228
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   291
  let
53263
d4784d3d3a54 rationalized bindings
blanchet
parents: 53040
diff changeset
   292
    (*Work around loss of qualification in "typedef" axioms by replicating it in the name*)
d4784d3d3a54 rationalized bindings
blanchet
parents: 53040
diff changeset
   293
    val b' = fold_rev Binding.prefix_name (map (suffix "_" o fst) (#2 (Binding.dest b))) b;
49228
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   294
    val ((name, info), (lthy, lthy_old)) =
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   295
      lthy
53263
d4784d3d3a54 rationalized bindings
blanchet
parents: 53040
diff changeset
   296
      |> Typedef.add_typedef (b', Ts, mx) set opt_morphs tac
49228
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   297
      ||> `Local_Theory.restore;
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   298
    val phi = Proof_Context.export_morphism lthy_old lthy;
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   299
  in
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   300
    ((name, Typedef.transform_info phi info), lthy)
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   301
  end;
e43910ccee74 open typedefs everywhere in the package
traytel
parents: 49212
diff changeset
   302
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   303
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   304
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   305
(* Term construction *)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   306
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   307
(** Fresh variables **)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   308
49425
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   309
fun nonzero_string_of_int 0 = ""
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   310
  | nonzero_string_of_int n = string_of_int n;
f27f83f71e94 cleaned up internal naming scheme for bnfs
traytel
parents: 49395
diff changeset
   311
49298
36e551d3af3b support for sort constraints in new (co)data commands
blanchet
parents: 49282
diff changeset
   312
val mk_TFreess = fold_map mk_TFrees;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   313
49177
db8ce685073f introduced and used "mk_Freesss", and simplified "mk_Freess(')"
blanchet
parents: 49176
diff changeset
   314
fun mk_Freesss x Tsss = fold_map2 mk_Freess (mk_names (length Tsss) x) Tsss;
49200
73f9aede57a4 correctly curry recursor arguments
blanchet
parents: 49178
diff changeset
   315
fun mk_Freessss x Tssss = fold_map2 mk_Freesss (mk_names (length Tssss) x) Tssss;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   316
51894
traytel
parents: 51893
diff changeset
   317
fun retype_free T (Free (s, _)) = Free (s, T)
traytel
parents: 51893
diff changeset
   318
  | retype_free _ t = raise TERM ("retype_free", [t]);
51762
219a3063ed29 derive "map_cong"
blanchet
parents: 51760
diff changeset
   319
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   320
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   321
(** Types **)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   322
52280
blanchet
parents: 52279
diff changeset
   323
(*stolen from ~~/src/HOL/Tools/Nitpick/nitpick_hol.ML*)
blanchet
parents: 52279
diff changeset
   324
fun num_binder_types (Type (@{type_name fun}, [_, T2])) =
blanchet
parents: 52279
diff changeset
   325
    1 + num_binder_types T2
blanchet
parents: 52279
diff changeset
   326
  | num_binder_types _ = 0
blanchet
parents: 52279
diff changeset
   327
53036
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
   328
(*maps [T1,...,Tn]--->T to ([T1,T2,...,Tn], T)*)
49395
323414474c1f use strip_typeN in bnf_def (instead of repairing strip_type)
traytel
parents: 49366
diff changeset
   329
fun strip_typeN 0 T = ([], T)
323414474c1f use strip_typeN in bnf_def (instead of repairing strip_type)
traytel
parents: 49366
diff changeset
   330
  | strip_typeN n (Type (@{type_name fun}, [T, T'])) = strip_typeN (n - 1) T' |>> cons T
49463
83ac281bcdc2 provide predicator, define relator
blanchet
parents: 49434
diff changeset
   331
  | strip_typeN _ T = raise TYPE ("strip_typeN", [T], []);
49395
323414474c1f use strip_typeN in bnf_def (instead of repairing strip_type)
traytel
parents: 49366
diff changeset
   332
53036
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
   333
(*maps [T1,...,Tn]--->T-->U to ([T1,T2,...,Tn], T-->U), where U is not a function type*)
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
   334
fun strip_fun_type T = strip_typeN (num_binder_types T - 1) T;
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
   335
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
   336
val binder_fun_types = fst o strip_fun_type;
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
   337
val body_fun_type = snd o strip_fun_type;
7dd103c29f9d added more functions to BNF library
blanchet
parents: 53035
diff changeset
   338
49463
83ac281bcdc2 provide predicator, define relator
blanchet
parents: 49434
diff changeset
   339
fun mk_pred2T T U = mk_predT [T, U];
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   340
val mk_relT = HOLogic.mk_setT o HOLogic.mk_prodT;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   341
val dest_relT = HOLogic.dest_prodT o HOLogic.dest_setT;
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   342
val dest_pred2T = apsnd Term.domain_type o Term.dest_funT;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   343
fun mk_sumT (LT, RT) = Type (@{type_name Sum_Type.sum}, [LT, RT]);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   344
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   345
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   346
(** Constants **)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   347
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   348
fun fst_const T = Const (@{const_name fst}, T --> fst (HOLogic.dest_prodT T));
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   349
fun snd_const T = Const (@{const_name snd}, T --> snd (HOLogic.dest_prodT T));
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   350
fun Id_const T = Const (@{const_name Id}, mk_relT (T, T));
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   351
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   352
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   353
(** Operators **)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   354
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   355
fun mk_converse R =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   356
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   357
    val RT = dest_relT (fastype_of R);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   358
    val RST = mk_relT (snd RT, fst RT);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   359
  in Const (@{const_name converse}, fastype_of R --> RST) $ R end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   360
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   361
fun mk_rel_comp (R, S) =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   362
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   363
    val RT = fastype_of R;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   364
    val ST = fastype_of S;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   365
    val RST = mk_relT (fst (dest_relT RT), snd (dest_relT ST));
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   366
  in Const (@{const_name relcomp}, RT --> ST --> RST) $ R $ S end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   367
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   368
fun mk_Gr A f =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   369
  let val ((AT, BT), FT) = `dest_funT (fastype_of f);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   370
  in Const (@{const_name Gr}, HOLogic.mk_setT AT --> FT --> mk_relT (AT, BT)) $ A $ f end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   371
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   372
fun mk_conversep R =
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   373
  let
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   374
    val RT = dest_pred2T (fastype_of R);
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   375
    val RST = mk_pred2T (snd RT) (fst RT);
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   376
  in Const (@{const_name conversep}, fastype_of R --> RST) $ R end;
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   377
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   378
fun mk_rel_compp (R, S) =
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   379
  let
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   380
    val RT = fastype_of R;
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   381
    val ST = fastype_of S;
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   382
    val RST = mk_pred2T (fst (dest_pred2T RT)) (snd (dest_pred2T ST));
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   383
  in Const (@{const_name relcompp}, RT --> ST --> RST) $ R $ S end;
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   384
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   385
fun mk_Grp A f =
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   386
  let val ((AT, BT), FT) = `dest_funT (fastype_of f);
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   387
  in Const (@{const_name Grp}, HOLogic.mk_setT AT --> FT --> mk_pred2T AT BT) $ A $ f end;
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   388
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   389
fun mk_image f =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   390
  let val (T, U) = dest_funT (fastype_of f);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   391
  in Const (@{const_name image},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   392
    (T --> U) --> (HOLogic.mk_setT T) --> (HOLogic.mk_setT U)) $ f end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   393
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   394
fun mk_Ball X f =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   395
  Const (@{const_name Ball}, fastype_of X --> fastype_of f --> HOLogic.boolT) $ X $ f;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   396
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   397
fun mk_Bex X f =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   398
  Const (@{const_name Bex}, fastype_of X --> fastype_of f --> HOLogic.boolT) $ X $ f;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   399
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   400
fun mk_UNION X f =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   401
  let val (T, U) = dest_funT (fastype_of f);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   402
  in Const (@{const_name SUPR}, fastype_of X --> (T --> U) --> U) $ X $ f end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   403
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   404
fun mk_Union T =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   405
  Const (@{const_name Sup}, HOLogic.mk_setT (HOLogic.mk_setT T) --> HOLogic.mk_setT T);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   406
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   407
fun mk_Field r =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   408
  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
   409
  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
   410
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   411
fun mk_card_order bd =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   412
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   413
    val T = fastype_of bd;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   414
    val AT = fst (dest_relT T);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   415
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   416
    Const (@{const_name card_order_on}, HOLogic.mk_setT AT --> T --> HOLogic.boolT) $
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   417
      (HOLogic.mk_UNIV AT) $ bd
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   418
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   419
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   420
fun mk_Card_order bd =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   421
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   422
    val T = fastype_of bd;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   423
    val AT = fst (dest_relT T);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   424
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   425
    Const (@{const_name card_order_on}, HOLogic.mk_setT AT --> T --> HOLogic.boolT) $
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   426
      mk_Field bd $ bd
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   427
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   428
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   429
fun mk_cinfinite bd =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   430
  Const (@{const_name cinfinite}, fastype_of bd --> HOLogic.boolT) $ bd;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   431
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   432
fun mk_ordLeq t1 t2 =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   433
  HOLogic.mk_mem (HOLogic.mk_prod (t1, t2),
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   434
    Const (@{const_name ordLeq}, mk_relT (fastype_of t1, fastype_of t2)));
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   435
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   436
fun mk_card_of A =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   437
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   438
    val AT = fastype_of A;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   439
    val T = HOLogic.dest_setT AT;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   440
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   441
    Const (@{const_name card_of}, AT --> mk_relT (T, T)) $ A
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   442
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   443
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   444
fun mk_dir_image r f =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   445
  let val (T, U) = dest_funT (fastype_of f);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   446
  in Const (@{const_name dir_image}, mk_relT (T, T) --> (T --> U) --> mk_relT (U, U)) $ r $ f end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   447
52719
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52545
diff changeset
   448
fun mk_fun_rel R S =
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52545
diff changeset
   449
  let
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52545
diff changeset
   450
    val ((RA, RB), RT) = `dest_pred2T (fastype_of R);
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52545
diff changeset
   451
    val ((SA, SB), ST) = `dest_pred2T (fastype_of S);
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52545
diff changeset
   452
  in Const (@{const_name fun_rel}, RT --> ST --> mk_pred2T (RA --> SA) (RB --> SB)) $ R $ S end;
480a3479fa47 transfer rule for map (not yet registered as a transfer rule)
traytel
parents: 52545
diff changeset
   453
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   454
(*FIXME: "x"?*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   455
(*(nth sets i) must be of type "T --> 'ai set"*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   456
fun mk_in As sets T =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   457
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   458
    fun in_single set A =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   459
      let val AT = fastype_of A;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   460
      in Const (@{const_name less_eq},
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   461
        AT --> AT --> HOLogic.boolT) $ (set $ Free ("x", T)) $ A end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   462
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   463
    if length sets > 0
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   464
    then HOLogic.mk_Collect ("x", T, foldr1 (HOLogic.mk_conj) (map2 in_single sets As))
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   465
    else HOLogic.mk_UNIV T
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   466
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   467
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51861
diff changeset
   468
fun mk_leq t1 t2 =
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   469
  Const (@{const_name less_eq}, (fastype_of t1) --> (fastype_of t2) --> HOLogic.boolT) $ t1 $ t2;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   470
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   471
fun mk_card_binop binop typop t1 t2 =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   472
  let
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   473
    val (T1, relT1) = `(fst o dest_relT) (fastype_of t1);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   474
    val (T2, relT2) = `(fst o dest_relT) (fastype_of t2);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   475
  in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   476
    Const (binop, relT1 --> relT2 --> mk_relT (typop (T1, T2), typop (T1, T2))) $ t1 $ t2
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   477
  end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   478
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   479
val mk_csum = mk_card_binop @{const_name csum} mk_sumT;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   480
val mk_cprod = mk_card_binop @{const_name cprod} HOLogic.mk_prodT;
52545
d2ad6eae514f Func -> Func_option, Ffunc -> Func (avoids dependence of codatatypes on the option type)
traytel
parents: 52280
diff changeset
   481
val mk_cexp = mk_card_binop @{const_name cexp} (op --> o swap);
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   482
val ctwo = @{term ctwo};
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   483
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   484
fun mk_collect xs defT =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   485
  let val T = (case xs of [] => defT | (x::_) => fastype_of x);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   486
  in Const (@{const_name collect}, HOLogic.mk_setT T --> T) $ (HOLogic.mk_set T xs) end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   487
52985
9e22d6264277 generalized library function
traytel
parents: 52963
diff changeset
   488
fun find_indices eq xs ys = map_filter I
9e22d6264277 generalized library function
traytel
parents: 52963
diff changeset
   489
  (map_index (fn (i, y) => if member eq xs y then SOME i else NONE) ys);
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   490
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   491
fun mk_trans thm1 thm2 = trans OF [thm1, thm2];
52913
2d2d9d1de1a9 theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents: 52719
diff changeset
   492
fun mk_sym thm = thm RS sym;
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   493
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   494
(*TODO: antiquote heavily used theorems once*)
49585
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   495
val Pair_eqD = @{thm iffD1[OF Pair_eq]};
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   496
val Pair_eqI = @{thm iffD2[OF Pair_eq]};
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   497
val ctrans = @{thm ordLeq_transitive};
49585
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   498
val id_apply = @{thm id_apply};
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   499
val meta_mp = @{thm meta_mp};
5c4a12550491 generate high-level "maps", "sets", and "rels" properties
blanchet
parents: 49536
diff changeset
   500
val meta_spec = @{thm meta_spec};
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   501
val o_apply = @{thm o_apply};
49488
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49484
diff changeset
   502
val set_mp = @{thm set_mp};
02eb07152998 use iffD* instead of (s)subst instantiated with identity; tuned antiquotations;
traytel
parents: 49484
diff changeset
   503
val set_rev_mp = @{thm set_rev_mp};
49490
394870e51d18 tuned antiquotations
traytel
parents: 49488
diff changeset
   504
val subset_UNIV = @{thm subset_UNIV};
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   505
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   506
fun mk_nthN 1 t 1 = t
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   507
  | mk_nthN _ t 1 = HOLogic.mk_fst t
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   508
  | mk_nthN 2 t 2 = HOLogic.mk_snd t
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   509
  | mk_nthN n t m = mk_nthN (n - 1) (HOLogic.mk_snd t) (m - 1);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   510
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   511
fun mk_nth_conv n m =
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   512
  let
54544
7d23f8e501d4 killed more needless thms
blanchet
parents: 54540
diff changeset
   513
    fun thm b = if b then @{thm fstI} else @{thm sndI}
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   514
    fun mk_nth_conv _ 1 1 = refl
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   515
      | mk_nth_conv _ _ 1 = @{thm fst_conv}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   516
      | mk_nth_conv _ 2 2 = @{thm snd_conv}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   517
      | mk_nth_conv b _ 2 = @{thm snd_conv} RS thm b
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   518
      | mk_nth_conv b n m = mk_nth_conv false (n - 1) (m - 1) RS thm b;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   519
  in mk_nth_conv (not (m = n)) n m end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   520
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   521
fun mk_nthI 1 1 = @{thm TrueE[OF TrueI]}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   522
  | mk_nthI n m = fold (curry op RS) (replicate (m - 1) @{thm sndI})
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   523
    (if m = n then @{thm TrueE[OF TrueI]} else @{thm fstI});
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   524
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   525
fun mk_conjunctN 1 1 = @{thm TrueE[OF TrueI]}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   526
  | mk_conjunctN _ 1 = conjunct1
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   527
  | mk_conjunctN 2 2 = conjunct2
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   528
  | mk_conjunctN n m = conjunct2 RS (mk_conjunctN (n - 1) (m - 1));
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   529
49337
538687a77075 set up things for (co)induction sugar
blanchet
parents: 49298
diff changeset
   530
fun conj_dests n thm = map (fn k => thm RS mk_conjunctN n k) (1 upto n);
538687a77075 set up things for (co)induction sugar
blanchet
parents: 49298
diff changeset
   531
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   532
fun mk_conjIN 1 = @{thm TrueE[OF TrueI]}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   533
  | mk_conjIN n = mk_conjIN (n - 1) RSN (2, conjI);
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   534
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   535
fun mk_ordLeq_csum 1 1 thm = thm
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   536
  | mk_ordLeq_csum _ 1 thm = @{thm ordLeq_transitive} OF [thm, @{thm ordLeq_csum1}]
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   537
  | mk_ordLeq_csum 2 2 thm = @{thm ordLeq_transitive} OF [thm, @{thm ordLeq_csum2}]
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   538
  | mk_ordLeq_csum n m thm = @{thm ordLeq_transitive} OF
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   539
    [mk_ordLeq_csum (n - 1) (m - 1) thm, @{thm ordLeq_csum2[OF Card_order_csum]}];
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   540
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   541
local
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   542
  fun mk_Un_upper' 0 = subset_refl
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   543
    | mk_Un_upper' 1 = @{thm Un_upper1}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   544
    | mk_Un_upper' k = Library.foldr (op RS o swap)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   545
      (replicate (k - 1) @{thm subset_trans[OF Un_upper1]}, @{thm Un_upper1});
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   546
in
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   547
  fun mk_Un_upper 1 1 = subset_refl
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   548
    | mk_Un_upper n 1 = mk_Un_upper' (n - 2) RS @{thm subset_trans[OF Un_upper1]}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   549
    | mk_Un_upper n m = mk_Un_upper' (n - m) RS @{thm subset_trans[OF Un_upper2]};
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   550
end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   551
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   552
local
49366
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49342
diff changeset
   553
  fun mk_UnIN' 0 = @{thm UnI2}
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49342
diff changeset
   554
    | mk_UnIN' m = mk_UnIN' (m - 1) RS @{thm UnI1};
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   555
in
49366
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49342
diff changeset
   556
  fun mk_UnIN 1 1 = @{thm TrueE[OF TrueI]}
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49342
diff changeset
   557
    | mk_UnIN n 1 = Library.foldr1 (op RS o swap) (replicate (n - 1) @{thm UnI1})
3edd1c90f6e6 renamed "mk_UnN" to "mk_UnIN"
blanchet
parents: 49342
diff changeset
   558
    | mk_UnIN n m = mk_UnIN' (n - m)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   559
end;
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   560
49605
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   561
fun is_triv_implies thm =
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   562
  op aconv (Logic.dest_implies (Thm.prop_of thm))
49484
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   563
  handle TERM _ => false;
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   564
49605
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   565
fun is_refl_prop t =
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   566
  op aconv (HOLogic.dest_eq (HOLogic.dest_Trueprop t))
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   567
  handle TERM _ => false;
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   568
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   569
val is_refl = is_refl_prop o Thm.prop_of;
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   570
val is_concl_refl = is_refl_prop o Logic.strip_imp_concl o Thm.prop_of;
ea566f5e1724 avoid another brand of trivial "disc_rel" theorems (which made the simplifier loop for all single-constructor types)
blanchet
parents: 49585
diff changeset
   571
49484
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   572
val no_refl = filter_out is_refl;
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   573
val no_reflexive = filter_out Thm.is_reflexive;
0194a18f80cf finished "disc_coiter_iff" etc. generation
blanchet
parents: 49463
diff changeset
   574
49504
df9b897fb254 renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents: 49490
diff changeset
   575
fun fold_thms ctxt thms = Local_Defs.fold ctxt (distinct Thm.eq_thm_prop thms);
49463
83ac281bcdc2 provide predicator, define relator
blanchet
parents: 49434
diff changeset
   576
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   577
end;