src/HOL/HOLCF/Tools/domaindef.ML
author wenzelm
Tue, 13 Mar 2012 20:04:24 +0100
changeset 46909 3c73a121a387
parent 44169 bdcc11b2fdc8
child 46949 94aa7b81bcf6
permissions -rw-r--r--
more explicit indication of def names;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42151
4da4fc77664b tuned headers;
wenzelm
parents: 41436
diff changeset
     1
(*  Title:      HOL/HOLCF/Tools/domaindef.ML
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     3
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     4
Defining representable domains using algebraic deflations.
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     5
*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     6
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
     7
signature DOMAINDEF =
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     8
sig
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     9
  type rep_info =
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    10
    {
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    11
      emb_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    12
      prj_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    13
      defl_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    14
      liftemb_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    15
      liftprj_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    16
      liftdefl_def : thm,
40494
db8a09daba7b add class liftdomain, for bifinite domains where DEFL('a u) = u_defl('a)
huffman
parents: 40491
diff changeset
    17
      DEFL : thm
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    18
    }
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    19
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
    20
  val add_domaindef: bool -> binding option -> binding * (string * sort) list * mixfix ->
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    21
    term -> (binding * binding) option -> theory ->
40772
c8b52f9e1680 rename Pcpodef.thy to Cpodef.thy;
huffman
parents: 40575
diff changeset
    22
    (Typedef.info * Cpodef.cpo_info * Cpodef.pcpo_info * rep_info) * theory
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    23
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
    24
  val domaindef_cmd: (bool * binding) * (binding * (string * string option) list * mixfix) * string
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    25
    * (binding * binding) option -> theory -> theory
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    26
end
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    27
41296
6aaf80ea9715 switch to transparent ascription, to avoid warning messages
huffman
parents: 41292
diff changeset
    28
structure Domaindef : DOMAINDEF =
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    29
struct
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    30
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    31
open HOLCF_Library
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    32
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    33
infixr 6 ->>
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    34
infix -->>
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    35
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    36
(** type definitions **)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    37
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    38
type rep_info =
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    39
  {
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    40
    emb_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    41
    prj_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    42
    defl_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    43
    liftemb_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    44
    liftprj_def : thm,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    45
    liftdefl_def : thm,
40494
db8a09daba7b add class liftdomain, for bifinite domains where DEFL('a u) = u_defl('a)
huffman
parents: 40491
diff changeset
    46
    DEFL : thm
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    47
  }
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    48
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    49
(* building types and terms *)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    50
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    51
val udomT = @{typ udom}
41287
029a6fc1bfb8 type 'defl' takes a type parameter again (cf. b525988432e9)
huffman
parents: 41228
diff changeset
    52
val deflT = @{typ "udom defl"}
41292
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
    53
val udeflT = @{typ "udom u defl"}
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    54
fun emb_const T = Const (@{const_name emb}, T ->> udomT)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    55
fun prj_const T = Const (@{const_name prj}, udomT ->> T)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    56
fun defl_const T = Const (@{const_name defl}, Term.itselfT T --> deflT)
41292
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
    57
fun liftemb_const T = Const (@{const_name liftemb}, mk_upT T ->> mk_upT udomT)
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
    58
fun liftprj_const T = Const (@{const_name liftprj}, mk_upT udomT ->> mk_upT T)
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
    59
fun liftdefl_const T = Const (@{const_name liftdefl}, Term.itselfT T --> udeflT)
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    60
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    61
fun mk_u_map t =
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    62
  let
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    63
    val (T, U) = dest_cfunT (fastype_of t)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    64
    val u_map_type = (T ->> U) ->> (mk_upT T ->> mk_upT U)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    65
    val u_map_const = Const (@{const_name u_map}, u_map_type)
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    66
  in
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
    67
    mk_capply (u_map_const, t)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    68
  end
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    69
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    70
fun mk_cast (t, x) =
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    71
  capply_const (udomT, udomT)
41287
029a6fc1bfb8 type 'defl' takes a type parameter again (cf. b525988432e9)
huffman
parents: 41228
diff changeset
    72
  $ (capply_const (deflT, udomT ->> udomT) $ @{term "cast :: udom defl -> udom -> udom"} $ t)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    73
  $ x
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    74
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    75
(* manipulating theorems *)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    76
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    77
(* proving class instances *)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    78
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
    79
fun gen_add_domaindef
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    80
      (prep_term: Proof.context -> 'a -> term)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    81
      (def: bool)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    82
      (name: binding)
44080
53d95b52954c HOLCF: fix warnings about unreferenced identifiers
huffman
parents: 42381
diff changeset
    83
      (typ as (tname, raw_args, _) : binding * (string * sort) list * mixfix)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    84
      (raw_defl: 'a)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    85
      (opt_morphs: (binding * binding) option)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    86
      (thy: theory)
40772
c8b52f9e1680 rename Pcpodef.thy to Cpodef.thy;
huffman
parents: 40575
diff changeset
    87
    : (Typedef.info * Cpodef.cpo_info * Cpodef.pcpo_info * rep_info) * theory =
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    88
  let
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    89
    val _ = Theory.requires thy "Domain" "domaindefs"
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    90
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    91
    (*rhs*)
36153
1ac501e16a6a replaced slightly odd Typedecl.predeclare_constraints by plain declaration of type arguments -- also avoid "recursive" declaration of type constructor, which can cause problems with sequential definitions B.foo = A.foo;
wenzelm
parents: 35994
diff changeset
    92
    val tmp_ctxt =
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
    93
      Proof_Context.init_global thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    94
      |> fold (Variable.declare_typ o TFree) raw_args
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    95
    val defl = prep_term tmp_ctxt raw_defl
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    96
    val tmp_ctxt = tmp_ctxt |> Variable.declare_constraints defl
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    97
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    98
    val deflT = Term.fastype_of defl
41287
029a6fc1bfb8 type 'defl' takes a type parameter again (cf. b525988432e9)
huffman
parents: 41228
diff changeset
    99
    val _ = if deflT = @{typ "udom defl"} then ()
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   100
            else error ("Not type defl: " ^ quote (Syntax.string_of_typ tmp_ctxt deflT))
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   101
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   102
    (*lhs*)
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   103
    val lhs_tfrees = map (Proof_Context.check_tfree tmp_ctxt) raw_args
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   104
    val full_tname = Sign.full_name thy tname
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   105
    val newT = Type (full_tname, map TFree lhs_tfrees)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   106
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   107
    (*morphisms*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   108
    val morphs = opt_morphs
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   109
      |> the_default (Binding.prefix_name "Rep_" name, Binding.prefix_name "Abs_" name)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   110
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   111
    (*set*)
44169
bdcc11b2fdc8 make HOLCF work with separate set type
huffman
parents: 44080
diff changeset
   112
    val set = @{term "defl_set :: udom defl => udom set"} $ defl
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   113
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   114
    (*pcpodef*)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   115
    val tac1 = rtac @{thm defl_set_bottom} 1
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   116
    val tac2 = rtac @{thm adm_defl_set} 1
35904
0c13e28e5e41 fix ML warnings in repdef.ML
huffman
parents: 35840
diff changeset
   117
    val ((info, cpo_info, pcpo_info), thy) = thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   118
      |> Cpodef.add_pcpodef def (SOME name) typ set (SOME morphs) (tac1, tac2)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   119
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   120
    (*definitions*)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   121
    val Rep_const = Const (#Rep_name (#1 info), newT --> udomT)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   122
    val Abs_const = Const (#Abs_name (#1 info), udomT --> newT)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   123
    val emb_eqn = Logic.mk_equals (emb_const newT, cabs_const (newT, udomT) $ Rep_const)
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
   124
    val prj_eqn = Logic.mk_equals (prj_const newT, cabs_const (udomT, newT) $
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   125
      Abs ("x", udomT, Abs_const $ mk_cast (defl, Bound 0)))
39989
ad60d7311f43 renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents: 39986
diff changeset
   126
    val defl_eqn = Logic.mk_equals (defl_const newT,
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   127
      Abs ("x", Term.itselfT newT, defl))
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   128
    val liftemb_eqn =
41292
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
   129
      Logic.mk_equals (liftemb_const newT, mk_u_map (emb_const newT))
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   130
    val liftprj_eqn =
41292
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
   131
      Logic.mk_equals (liftprj_const newT, mk_u_map (prj_const newT))
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   132
    val liftdefl_eqn =
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   133
      Logic.mk_equals (liftdefl_const newT,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   134
        Abs ("t", Term.itselfT newT,
41436
480978f80eae rename constant pdefl to liftdefl_of
huffman
parents: 41296
diff changeset
   135
          mk_capply (@{const liftdefl_of}, defl_const newT $ Logic.mk_type newT)))
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   136
46909
3c73a121a387 more explicit indication of def names;
wenzelm
parents: 44169
diff changeset
   137
    val name_def = Thm.def_binding name
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   138
    val emb_bind = (Binding.prefix_name "emb_" name_def, [])
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   139
    val prj_bind = (Binding.prefix_name "prj_" name_def, [])
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   140
    val defl_bind = (Binding.prefix_name "defl_" name_def, [])
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   141
    val liftemb_bind = (Binding.prefix_name "liftemb_" name_def, [])
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   142
    val liftprj_bind = (Binding.prefix_name "liftprj_" name_def, [])
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   143
    val liftdefl_bind = (Binding.prefix_name "liftdefl_" name_def, [])
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   144
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   145
    (*instantiate class rep*)
35904
0c13e28e5e41 fix ML warnings in repdef.ML
huffman
parents: 35840
diff changeset
   146
    val lthy = thy
41292
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
   147
      |> Class.instantiation ([full_tname], lhs_tfrees, @{sort domain})
35904
0c13e28e5e41 fix ML warnings in repdef.ML
huffman
parents: 35840
diff changeset
   148
    val ((_, (_, emb_ldef)), lthy) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   149
        Specification.definition (NONE, (emb_bind, emb_eqn)) lthy
35904
0c13e28e5e41 fix ML warnings in repdef.ML
huffman
parents: 35840
diff changeset
   150
    val ((_, (_, prj_ldef)), lthy) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   151
        Specification.definition (NONE, (prj_bind, prj_eqn)) lthy
39989
ad60d7311f43 renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents: 39986
diff changeset
   152
    val ((_, (_, defl_ldef)), lthy) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   153
        Specification.definition (NONE, (defl_bind, defl_eqn)) lthy
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   154
    val ((_, (_, liftemb_ldef)), lthy) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   155
        Specification.definition (NONE, (liftemb_bind, liftemb_eqn)) lthy
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   156
    val ((_, (_, liftprj_ldef)), lthy) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   157
        Specification.definition (NONE, (liftprj_bind, liftprj_eqn)) lthy
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   158
    val ((_, (_, liftdefl_ldef)), lthy) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   159
        Specification.definition (NONE, (liftdefl_bind, liftdefl_eqn)) lthy
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   160
    val ctxt_thy = Proof_Context.init_global (Proof_Context.theory_of lthy)
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   161
    val emb_def = singleton (Proof_Context.export lthy ctxt_thy) emb_ldef
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   162
    val prj_def = singleton (Proof_Context.export lthy ctxt_thy) prj_ldef
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   163
    val defl_def = singleton (Proof_Context.export lthy ctxt_thy) defl_ldef
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   164
    val liftemb_def = singleton (Proof_Context.export lthy ctxt_thy) liftemb_ldef
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   165
    val liftprj_def = singleton (Proof_Context.export lthy ctxt_thy) liftprj_ldef
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   166
    val liftdefl_def = singleton (Proof_Context.export lthy ctxt_thy) liftdefl_ldef
33826
7f12ab745298 make repdef work without (open) option
huffman
parents: 33812
diff changeset
   167
    val type_definition_thm =
41228
e1fce873b814 renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
wenzelm
parents: 40832
diff changeset
   168
      Raw_Simplifier.rewrite_rule
35994
9cc3df9a606e Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents: 35904
diff changeset
   169
        (the_list (#set_def (#2 info)))
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   170
        (#type_definition (#2 info))
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   171
    val typedef_thms =
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   172
      [type_definition_thm, #below_def cpo_info, emb_def, prj_def, defl_def,
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   173
      liftemb_def, liftprj_def, liftdefl_def]
35904
0c13e28e5e41 fix ML warnings in repdef.ML
huffman
parents: 35840
diff changeset
   174
    val thy = lthy
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   175
      |> Class.prove_instantiation_instance
41292
2b7bc8d9fd6e use deflations over type 'udom u' to represent predomains;
huffman
parents: 41290
diff changeset
   176
          (K (Tactic.rtac (@{thm typedef_domain_class} OF typedef_thms) 1))
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   177
      |> Local_Theory.exit_global
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   178
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   179
    (*other theorems*)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   180
    val defl_thm' = Thm.transfer thy defl_def
39989
ad60d7311f43 renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents: 39986
diff changeset
   181
    val (DEFL_thm, thy) = thy
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   182
      |> Sign.add_path (Binding.name_of name)
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 38348
diff changeset
   183
      |> Global_Theory.add_thm
39989
ad60d7311f43 renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents: 39986
diff changeset
   184
         ((Binding.prefix_name "DEFL_" name,
ad60d7311f43 renamed type and constant 'sfp' to 'defl'; replaced syntax SFP('a) with DEFL('a)
huffman
parents: 39986
diff changeset
   185
          Drule.zero_var_indexes (@{thm typedef_DEFL} OF [defl_thm'])), [])
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   186
      ||> Sign.restore_naming thy
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   187
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   188
    val rep_info =
40491
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   189
      { emb_def = emb_def, prj_def = prj_def, defl_def = defl_def,
6de5839e2fb3 add 'predomain' class: unpointed version of bifinite
huffman
parents: 40038
diff changeset
   190
        liftemb_def = liftemb_def, liftprj_def = liftprj_def,
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   191
        liftdefl_def = liftdefl_def, DEFL = DEFL_thm }
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   192
  in
35904
0c13e28e5e41 fix ML warnings in repdef.ML
huffman
parents: 35840
diff changeset
   193
    ((info, cpo_info, pcpo_info, rep_info), thy)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   194
  end
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   195
  handle ERROR msg =>
42381
309ec68442c6 added Binding.print convenience, which includes quote already;
wenzelm
parents: 42361
diff changeset
   196
    cat_error msg ("The error(s) above occurred in domaindef " ^ Binding.print name)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   197
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
   198
fun add_domaindef def opt_name typ defl opt_morphs thy =
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   199
  let
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   200
    val name = the_default (#1 typ) opt_name
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   201
  in
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
   202
    gen_add_domaindef Syntax.check_term def name typ defl opt_morphs thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   203
  end
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   204
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
   205
fun domaindef_cmd ((def, name), (b, raw_args, mx), A, morphs) thy =
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   206
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   207
    val ctxt = Proof_Context.init_global thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   208
    val args = map (apsnd (Typedecl.read_constraint ctxt)) raw_args
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   209
  in snd (gen_add_domaindef Syntax.read_term def name (b, args, mx) A morphs thy) end
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   210
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   211
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   212
(** outer syntax **)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   213
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
   214
val domaindef_decl =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   215
  Scan.optional (Parse.$$$ "(" |--
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   216
      ((Parse.$$$ "open" >> K false) -- Scan.option Parse.binding ||
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   217
        Parse.binding >> (fn s => (true, SOME s)))
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   218
        --| Parse.$$$ ")") (true, NONE) --
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   219
    (Parse.type_args_constrained -- Parse.binding) --
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   220
    Parse.opt_mixfix -- (Parse.$$$ "=" |-- Parse.term) --
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   221
    Scan.option (Parse.$$$ "morphisms" |-- Parse.!!! (Parse.binding -- Parse.binding))
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   222
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
   223
fun mk_domaindef ((((((def, opt_name), (args, t)), mx), A), morphs)) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   224
  domaindef_cmd ((def, the_default t opt_name), (t, args, mx), A, morphs)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   225
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   226
val _ =
40575
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
   227
  Outer_Syntax.command "domaindef" "HOLCF definition of domains from deflations" Keyword.thy_decl
b9a86f15e763 rename 'repdef' to 'domaindef'
huffman
parents: 40510
diff changeset
   228
    (domaindef_decl >>
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   229
      (Toplevel.print oo (Toplevel.theory o mk_domaindef)))
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   230
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   231
end