src/HOL/HOLCF/Tools/cpodef.ML
author wenzelm
Sat, 23 May 2015 17:19:37 +0200
changeset 60299 5ae2a2e74c93
parent 59936 b8ffc3dc9e24
child 60754 02924903a6fd
permissions -rw-r--r--
clarified NEWS: document_files are officially required since Isabelle2014, but the absence was tolerated as legacy feature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42151
4da4fc77664b tuned headers;
wenzelm
parents: 41429
diff changeset
     1
(*  Title:      HOL/HOLCF/Tools/cpodef.ML
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     Brian Huffman
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     3
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     4
Primitive domain definitions for HOLCF, similar to Gordon/HOL-style
31738
7b9b9ba532ca discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31725
diff changeset
     5
typedef (see also ~~/src/HOL/Tools/typedef.ML).
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     6
*)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     7
40772
c8b52f9e1680 rename Pcpodef.thy to Cpodef.thy;
huffman
parents: 40770
diff changeset
     8
signature CPODEF =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     9
sig
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    10
  type cpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    11
    { below_def: thm, adm: thm, cont_Rep: thm, cont_Abs: thm,
41028
0acff85f95c7 cpodef no longer generates lemma is_lub_foo, since it is redundant with lub_foo
huffman
parents: 40889
diff changeset
    12
      lub: thm, compact: thm }
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    13
  type pcpo_info =
41029
f7d8cfa6e7fc pcpodef no longer generates _defined lemmas, use _bottom_iff lemmas instead
huffman
parents: 41028
diff changeset
    14
    { Rep_strict: thm, Abs_strict: thm,
f7d8cfa6e7fc pcpodef no longer generates _defined lemmas, use _bottom_iff lemmas instead
huffman
parents: 41028
diff changeset
    15
      Rep_bottom_iff: thm, Abs_bottom_iff: thm }
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    16
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    17
  val add_podef: binding * (string * sort) list * mixfix ->
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
    18
    term -> (binding * binding) option -> (Proof.context -> tactic) -> theory ->
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    19
    (Typedef.info * thm) * theory
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    20
  val add_cpodef: binding * (string * sort) list * mixfix ->
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
    21
    term -> (binding * binding) option -> (Proof.context -> tactic) * (Proof.context -> tactic) ->
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
    22
    theory -> (Typedef.info * cpo_info) * theory
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    23
  val add_pcpodef: binding * (string * sort) list * mixfix ->
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
    24
    term -> (binding * binding) option -> (Proof.context -> tactic) * (Proof.context -> tactic) ->
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
    25
    theory -> (Typedef.info * cpo_info * pcpo_info) * theory
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    26
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    27
  val cpodef_proof:
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    28
    (binding * (string * sort) list * mixfix) * term
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    29
    * (binding * binding) option -> theory -> Proof.state
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    30
  val cpodef_proof_cmd:
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    31
    (binding * (string * string option) list * mixfix) * string
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    32
    * (binding * binding) option -> theory -> Proof.state
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    33
  val pcpodef_proof:
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    34
    (binding * (string * sort) list * mixfix) * term
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
    35
    * (binding * binding) option -> theory -> Proof.state
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    36
  val pcpodef_proof_cmd:
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
    37
    (binding * (string * string option) list * mixfix) * string
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
    38
    * (binding * binding) option -> theory -> Proof.state
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    39
end
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    40
41296
6aaf80ea9715 switch to transparent ascription, to avoid warning messages
huffman
parents: 41029
diff changeset
    41
structure Cpodef : CPODEF =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    42
struct
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    43
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    44
(** type definitions **)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    45
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    46
type cpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    47
  { below_def: thm, adm: thm, cont_Rep: thm, cont_Abs: thm,
41028
0acff85f95c7 cpodef no longer generates lemma is_lub_foo, since it is redundant with lub_foo
huffman
parents: 40889
diff changeset
    48
    lub: thm, compact: thm }
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    49
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    50
type pcpo_info =
41029
f7d8cfa6e7fc pcpodef no longer generates _defined lemmas, use _bottom_iff lemmas instead
huffman
parents: 41028
diff changeset
    51
  { Rep_strict: thm, Abs_strict: thm,
f7d8cfa6e7fc pcpodef no longer generates _defined lemmas, use _bottom_iff lemmas instead
huffman
parents: 41028
diff changeset
    52
    Rep_bottom_iff: thm, Abs_bottom_iff: thm }
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    53
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    54
(* building terms *)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    55
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    56
fun adm_const T = Const (@{const_name adm}, (T --> HOLogic.boolT) --> HOLogic.boolT)
44241
7943b69f0188 modernized signature of Term.absfree/absdummy;
wenzelm
parents: 44080
diff changeset
    57
fun mk_adm (x, T, P) = adm_const T $ absfree (x, T) P
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    58
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    59
fun below_const T = Const (@{const_name below}, T --> T --> HOLogic.boolT)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    60
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    61
(* proving class instances *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    62
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    63
fun prove_cpo
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    64
      (name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    65
      (newT: typ)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    66
      (Rep_name: binding, Abs_name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    67
      (type_definition: thm)  (* type_definition Rep Abs A *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    68
      (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    69
      (admissible: thm)       (* adm (%x. x : set) *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    70
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    71
    =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    72
  let
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
    73
    val cpo_thms = map (Thm.transfer thy) [type_definition, below_def, admissible]
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    74
    val (full_tname, Ts) = dest_Type newT
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    75
    val lhs_sorts = map (snd o dest_TFree) Ts
52732
b4da1f2ec73f standardized aliases;
wenzelm
parents: 51685
diff changeset
    76
    val tac = rtac (@{thm typedef_cpo} OF cpo_thms) 1
51685
385ef6706252 more standard module name Axclass (according to file name);
wenzelm
parents: 51671
diff changeset
    77
    val thy = Axclass.prove_arity (full_tname, lhs_sorts, @{sort cpo}) (K tac) thy
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
    78
    (* transfer thms so that they will know about the new cpo instance *)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    79
    val cpo_thms' = map (Thm.transfer thy) cpo_thms
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    80
    fun make thm = Drule.zero_var_indexes (thm OF cpo_thms')
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    81
    val cont_Rep = make @{thm typedef_cont_Rep}
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    82
    val cont_Abs = make @{thm typedef_cont_Abs}
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    83
    val lub = make @{thm typedef_lub}
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    84
    val compact = make @{thm typedef_compact}
35902
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
    85
    val (_, thy) =
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
    86
      thy
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    87
      |> 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: 38756
diff changeset
    88
      |> Global_Theory.add_thms
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
    89
        ([((Binding.prefix_name "adm_"      name, admissible), []),
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
    90
          ((Binding.prefix_name "cont_" Rep_name, cont_Rep  ), []),
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
    91
          ((Binding.prefix_name "cont_" Abs_name, cont_Abs  ), []),
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
    92
          ((Binding.prefix_name "lub_"      name, lub       ), []),
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
    93
          ((Binding.prefix_name "compact_"  name, compact   ), [])])
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
    94
      ||> Sign.parent_path
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    95
    val cpo_info : cpo_info =
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
    96
      { below_def = below_def, adm = admissible, cont_Rep = cont_Rep,
41028
0acff85f95c7 cpodef no longer generates lemma is_lub_foo, since it is redundant with lub_foo
huffman
parents: 40889
diff changeset
    97
        cont_Abs = cont_Abs, lub = lub, compact = compact }
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    98
  in
35902
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
    99
    (cpo_info, thy)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   100
  end
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   101
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   102
fun prove_pcpo
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   103
      (name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   104
      (newT: typ)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   105
      (Rep_name: binding, Abs_name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   106
      (type_definition: thm)  (* type_definition Rep Abs A *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   107
      (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
41429
cf5f025bc3c7 renamed constant 'UU' to 'bottom', keeping 'UU' as alternative input syntax;
huffman
parents: 41296
diff changeset
   108
      (bottom_mem: thm)       (* bottom : set *)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   109
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   110
    =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   111
  let
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
   112
    val pcpo_thms = map (Thm.transfer thy) [type_definition, below_def, bottom_mem]
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   113
    val (full_tname, Ts) = dest_Type newT
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   114
    val lhs_sorts = map (snd o dest_TFree) Ts
52732
b4da1f2ec73f standardized aliases;
wenzelm
parents: 51685
diff changeset
   115
    val tac = rtac (@{thm typedef_pcpo} OF pcpo_thms) 1
51685
385ef6706252 more standard module name Axclass (according to file name);
wenzelm
parents: 51671
diff changeset
   116
    val thy = Axclass.prove_arity (full_tname, lhs_sorts, @{sort pcpo}) (K tac) thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   117
    val pcpo_thms' = map (Thm.transfer thy) pcpo_thms
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   118
    fun make thm = Drule.zero_var_indexes (thm OF pcpo_thms')
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   119
    val Rep_strict = make @{thm typedef_Rep_strict}
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   120
    val Abs_strict = make @{thm typedef_Abs_strict}
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   121
    val Rep_bottom_iff = make @{thm typedef_Rep_bottom_iff}
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   122
    val Abs_bottom_iff = make @{thm typedef_Abs_bottom_iff}
35902
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
   123
    val (_, thy) =
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
   124
      thy
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   125
      |> 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: 38756
diff changeset
   126
      |> Global_Theory.add_thms
35902
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
   127
        ([((Binding.suffix_name "_strict"     Rep_name, Rep_strict), []),
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
   128
          ((Binding.suffix_name "_strict"     Abs_name, Abs_strict), []),
40321
d065b195ec89 rename lemmas *_defined_iff and *_strict_iff to *_bottom_iff
huffman
parents: 39557
diff changeset
   129
          ((Binding.suffix_name "_bottom_iff" Rep_name, Rep_bottom_iff), []),
41029
f7d8cfa6e7fc pcpodef no longer generates _defined lemmas, use _bottom_iff lemmas instead
huffman
parents: 41028
diff changeset
   130
          ((Binding.suffix_name "_bottom_iff" Abs_name, Abs_bottom_iff), [])])
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   131
      ||> Sign.parent_path
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   132
    val pcpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   133
      { Rep_strict = Rep_strict, Abs_strict = Abs_strict,
41029
f7d8cfa6e7fc pcpodef no longer generates _defined lemmas, use _bottom_iff lemmas instead
huffman
parents: 41028
diff changeset
   134
        Rep_bottom_iff = Rep_bottom_iff, Abs_bottom_iff = Abs_bottom_iff }
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   135
  in
35902
81608655c69e fix ML warnings in pcpodef.ML
huffman
parents: 35840
diff changeset
   136
    (pcpo_info, thy)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   137
  end
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   138
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   139
(* prepare_cpodef *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   140
44080
53d95b52954c HOLCF: fix warnings about unreferenced identifiers
huffman
parents: 42381
diff changeset
   141
fun prepare prep_term name (tname, raw_args, _) raw_set opt_morphs thy =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   142
  let
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   143
    (*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
   144
    val tmp_ctxt =
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   145
      Proof_Context.init_global thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   146
      |> fold (Variable.declare_typ o TFree) raw_args
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   147
    val set = prep_term tmp_ctxt raw_set
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   148
    val tmp_ctxt' = tmp_ctxt |> Variable.declare_term set
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35742
diff changeset
   149
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   150
    val setT = Term.fastype_of set
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   151
    val oldT = HOLogic.dest_setT setT handle TYPE _ =>
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   152
      error ("Not a set type: " ^ quote (Syntax.string_of_typ tmp_ctxt setT))
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   153
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   154
    (*lhs*)
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   155
    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
   156
    val full_tname = Sign.full_name thy tname
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   157
    val newT = Type (full_tname, map TFree lhs_tfrees)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   158
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   159
    val morphs = opt_morphs
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   160
      |> the_default (Binding.prefix_name "Rep_" name, Binding.prefix_name "Abs_" name)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   161
  in
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   162
    (newT, oldT, set, morphs)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   163
  end
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   164
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   165
fun add_podef typ set opt_morphs tac thy =
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   166
  let
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   167
    val name = #1 typ
44080
53d95b52954c HOLCF: fix warnings about unreferenced identifiers
huffman
parents: 42381
diff changeset
   168
    val ((full_tname, info as ({Rep_name, ...}, {type_definition, ...})), thy) = thy
58239
1c5bc387bd4c added flag to 'typedef' to allow concealed definitions
blanchet
parents: 56895
diff changeset
   169
      |> Typedef.add_typedef_global false typ set opt_morphs tac
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   170
    val oldT = #rep_type (#1 info)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   171
    val newT = #abs_type (#1 info)
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   172
    val lhs_tfrees = map dest_TFree (snd (dest_Type newT))
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   173
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   174
    val RepC = Const (Rep_name, newT --> oldT)
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   175
    val below_eqn = Logic.mk_equals (below_const newT,
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   176
      Abs ("x", newT, Abs ("y", newT, below_const oldT $ (RepC $ Bound 1) $ (RepC $ Bound 0))))
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   177
    val ((_, (_, below_ldef)), lthy) = thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   178
      |> Class.instantiation ([full_tname], lhs_tfrees, @{sort po})
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   179
      |> Specification.definition (NONE,
46909
3c73a121a387 more explicit indication of def names;
wenzelm
parents: 44241
diff changeset
   180
          ((Binding.prefix_name "below_" (Thm.def_binding name), []), below_eqn))
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   181
    val ctxt_thy = Proof_Context.init_global (Proof_Context.theory_of lthy)
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   182
    val below_def = singleton (Proof_Context.export lthy ctxt_thy) below_ldef
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   183
    val thy = lthy
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   184
      |> Class.prove_instantiation_exit
52732
b4da1f2ec73f standardized aliases;
wenzelm
parents: 51685
diff changeset
   185
          (K (rtac (@{thm typedef_po} OF [type_definition, below_def]) 1))
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   186
  in ((info, below_def), thy) end
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   187
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   188
fun prepare_cpodef
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   189
      (prep_term: Proof.context -> 'a -> term)
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35742
diff changeset
   190
      (typ: binding * (string * sort) list * mixfix)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   191
      (raw_set: 'a)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   192
      (opt_morphs: (binding * binding) option)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   193
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   194
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info) * theory) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   195
  let
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   196
    val name = #1 typ
44080
53d95b52954c HOLCF: fix warnings about unreferenced identifiers
huffman
parents: 42381
diff changeset
   197
    val (newT, oldT, set, morphs) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   198
      prepare prep_term name typ raw_set opt_morphs thy
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   199
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   200
    val goal_nonempty =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   201
      HOLogic.mk_Trueprop (HOLogic.mk_exists ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)))
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   202
    val goal_admissible =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   203
      HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)))
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   204
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   205
    fun cpodef_result nonempty admissible thy =
28073
5e9f00f4f209 adapted to class instantiation compliance
haftmann
parents: 27691
diff changeset
   206
      let
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
   207
        val ((info as (_, {type_definition, ...}), below_def), thy) = thy
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
   208
          |> add_podef typ set opt_morphs (fn _ => rtac nonempty 1)
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   209
        val (cpo_info, thy) = thy
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
   210
          |> prove_cpo name newT morphs type_definition below_def admissible
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   211
      in
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   212
        ((info, cpo_info), thy)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   213
      end
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   214
  in
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   215
    (goal_nonempty, goal_admissible, cpodef_result)
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   216
  end
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   217
  handle ERROR msg =>
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   218
    cat_error msg ("The error(s) above occurred in cpodef " ^ Binding.print (#1 typ))
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   219
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   220
fun prepare_pcpodef
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   221
      (prep_term: Proof.context -> 'a -> term)
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35742
diff changeset
   222
      (typ: binding * (string * sort) list * mixfix)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   223
      (raw_set: 'a)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   224
      (opt_morphs: (binding * binding) option)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   225
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   226
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info * pcpo_info) * theory) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   227
  let
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   228
    val name = #1 typ
44080
53d95b52954c HOLCF: fix warnings about unreferenced identifiers
huffman
parents: 42381
diff changeset
   229
    val (newT, oldT, set, morphs) =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   230
      prepare prep_term name typ raw_set opt_morphs thy
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   231
41429
cf5f025bc3c7 renamed constant 'UU' to 'bottom', keeping 'UU' as alternative input syntax;
huffman
parents: 41296
diff changeset
   232
    val goal_bottom_mem =
cf5f025bc3c7 renamed constant 'UU' to 'bottom', keeping 'UU' as alternative input syntax;
huffman
parents: 41296
diff changeset
   233
      HOLogic.mk_Trueprop (HOLogic.mk_mem (Const (@{const_name bottom}, oldT), set))
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   234
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   235
    val goal_admissible =
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   236
      HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)))
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   237
41429
cf5f025bc3c7 renamed constant 'UU' to 'bottom', keeping 'UU' as alternative input syntax;
huffman
parents: 41296
diff changeset
   238
    fun pcpodef_result bottom_mem admissible thy =
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   239
      let
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
   240
        fun tac _ = rtac exI 1 THEN rtac bottom_mem 1
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
   241
        val ((info as (_, {type_definition, ...}), below_def), thy) = thy
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   242
          |> add_podef typ set opt_morphs tac
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   243
        val (cpo_info, thy) = thy
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
   244
          |> prove_cpo name newT morphs type_definition below_def admissible
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   245
        val (pcpo_info, thy) = thy
49833
1d80798e8d8a discontinued typedef with implicit set_def;
wenzelm
parents: 49759
diff changeset
   246
          |> prove_pcpo name newT morphs type_definition below_def bottom_mem
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   247
      in
40889
0317c902dbfa tuned cpodef code
huffman
parents: 40832
diff changeset
   248
        ((info, cpo_info, pcpo_info), thy)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   249
      end
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   250
  in
41429
cf5f025bc3c7 renamed constant 'UU' to 'bottom', keeping 'UU' as alternative input syntax;
huffman
parents: 41296
diff changeset
   251
    (goal_bottom_mem, goal_admissible, pcpodef_result)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   252
  end
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   253
  handle ERROR msg =>
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   254
    cat_error msg ("The error(s) above occurred in pcpodef " ^ Binding.print (#1 typ))
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   255
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   256
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   257
(* tactic interface *)
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   258
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   259
fun add_cpodef typ set opt_morphs (tac1, tac2) thy =
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   260
  let
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   261
    val (goal1, goal2, cpodef_result) =
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   262
      prepare_cpodef Syntax.check_term typ set opt_morphs thy
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
   263
    val thm1 = Goal.prove_global thy [] [] goal1 (tac1 o #context)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   264
      handle ERROR msg => cat_error msg
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   265
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set))
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
   266
    val thm2 = Goal.prove_global thy [] [] goal2 (tac2 o #context)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   267
      handle ERROR msg => cat_error msg
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   268
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set))
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   269
  in cpodef_result thm1 thm2 thy end
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   270
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   271
fun add_pcpodef typ set opt_morphs (tac1, tac2) thy =
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   272
  let
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   273
    val (goal1, goal2, pcpodef_result) =
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   274
      prepare_pcpodef Syntax.check_term typ set opt_morphs thy
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
   275
    val thm1 = Goal.prove_global thy [] [] goal1 (tac1 o #context)
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   276
      handle ERROR msg => cat_error msg
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   277
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set))
58959
1f195ed99941 proper proof context for typedef;
wenzelm
parents: 58936
diff changeset
   278
    val thm2 = Goal.prove_global thy [] [] goal2 (tac2 o #context)
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   279
      handle ERROR msg => cat_error msg
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   280
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set))
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   281
  in pcpodef_result thm1 thm2 thy end
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   282
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   283
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   284
(* proof interface *)
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   285
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   286
local
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   287
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35742
diff changeset
   288
fun gen_cpodef_proof prep_term prep_constraint
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   289
    ((b, raw_args, mx), set, opt_morphs) thy =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   290
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   291
    val ctxt = Proof_Context.init_global thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   292
    val args = map (apsnd (prep_constraint ctxt)) raw_args
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   293
    val (goal1, goal2, make_result) =
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   294
      prepare_cpodef prep_term (b, args, mx) set opt_morphs thy
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   295
    fun after_qed [[th1, th2]] = Proof_Context.background_theory (snd o make_result th1 th2)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   296
      | after_qed _ = raise Fail "cpodef_proof"
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   297
  in Proof.theorem NONE after_qed [[(goal1, []), (goal2, [])]] ctxt end
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   298
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35742
diff changeset
   299
fun gen_pcpodef_proof prep_term prep_constraint
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   300
    ((b, raw_args, mx), set, opt_morphs) thy =
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   301
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   302
    val ctxt = Proof_Context.init_global thy
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   303
    val args = map (apsnd (prep_constraint ctxt)) raw_args
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   304
    val (goal1, goal2, make_result) =
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   305
      prepare_pcpodef prep_term (b, args, mx) set opt_morphs thy
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42151
diff changeset
   306
    fun after_qed [[th1, th2]] = Proof_Context.background_theory (snd o make_result th1 th2)
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   307
      | after_qed _ = raise Fail "pcpodef_proof"
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   308
  in Proof.theorem NONE after_qed [[(goal1, []), (goal2, [])]] ctxt end
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   309
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   310
in
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   311
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   312
fun cpodef_proof x = gen_cpodef_proof Syntax.check_term (K I) x
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   313
fun cpodef_proof_cmd x = gen_cpodef_proof Syntax.read_term Typedecl.read_constraint x
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   314
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   315
fun pcpodef_proof x = gen_pcpodef_proof Syntax.check_term (K I) x
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   316
fun pcpodef_proof_cmd x = gen_pcpodef_proof Syntax.read_term Typedecl.read_constraint x
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   317
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   318
end
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   319
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   320
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   321
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   322
(** outer syntax **)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   323
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   324
val typedef_proof_decl =
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   325
  (Parse.type_args_constrained -- Parse.binding) -- Parse.opt_mixfix --
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   326
  (@{keyword "="} |-- Parse.term) --
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   327
  Scan.option
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   328
    (@{keyword "morphisms"} |-- Parse.!!! (Parse.binding -- Parse.binding))
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   329
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   330
fun mk_pcpodef_proof pcpo ((((args, t), mx), A), morphs) =
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   331
  (if pcpo then pcpodef_proof_cmd else cpodef_proof_cmd)
49759
ecf1d5d87e5e removed support for set constant definitions in HOLCF {cpo,pcpo,domain}def commands;
huffman
parents: 46961
diff changeset
   332
    ((t, args, mx), A, morphs)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   333
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   334
val _ =
59936
b8ffc3dc9e24 @{command_spec} is superseded by @{command_keyword};
wenzelm
parents: 58959
diff changeset
   335
  Outer_Syntax.command @{command_keyword pcpodef}
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46949
diff changeset
   336
    "HOLCF type definition (requires admissibility proof)"
56895
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56249
diff changeset
   337
    (typedef_proof_decl >> (Toplevel.theory_to_proof o mk_pcpodef_proof true))
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   338
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   339
val _ =
59936
b8ffc3dc9e24 @{command_spec} is superseded by @{command_keyword};
wenzelm
parents: 58959
diff changeset
   340
  Outer_Syntax.command @{command_keyword cpodef}
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46949
diff changeset
   341
    "HOLCF type definition (requires admissibility proof)"
56895
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56249
diff changeset
   342
    (typedef_proof_decl >> (Toplevel.theory_to_proof o mk_pcpodef_proof false))
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   343
40832
4352ca878c41 remove gratuitous semicolons from ML code
huffman
parents: 40774
diff changeset
   344
end