src/HOLCF/Tools/pcpodef.ML
author wenzelm
Sun, 07 Feb 2010 19:33:34 +0100
changeset 35021 c839a4c670c6
parent 33680 a47277e09012
child 35129 ed24ba6f69aa
permissions -rw-r--r--
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31738
7b9b9ba532ca discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31725
diff changeset
     1
(*  Title:      HOLCF/Tools/pcpodef.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
31738
7b9b9ba532ca discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31725
diff changeset
     8
signature PCPODEF =
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,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    12
      lub: thm, thelub: thm, compact: thm }
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    13
  type pcpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    14
    { Rep_strict: thm, Abs_strict: thm, Rep_strict_iff: thm, Abs_strict_iff: thm,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    15
      Rep_defined: thm, Abs_defined: thm }
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    16
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    17
  val add_podef: bool -> binding option -> binding * string list * mixfix ->
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    18
    term -> (binding * binding) option -> tactic -> theory ->
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    19
    (Typedef.info * thm) * theory
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    20
  val add_cpodef: bool -> binding option -> binding * string list * mixfix ->
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    21
    term -> (binding * binding) option -> tactic * tactic -> theory ->
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    22
    (Typedef.info * cpo_info) * theory
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
    23
  val add_pcpodef: bool -> binding option -> binding * string list * mixfix ->
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    24
    term -> (binding * binding) option -> tactic * tactic -> theory ->
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    25
    (Typedef.info * cpo_info * pcpo_info) * theory
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    26
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    27
  val cpodef_proof: (bool * binding) * (binding * string list * mixfix) * term
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    28
    * (binding * binding) option -> theory -> Proof.state
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    29
  val cpodef_proof_cmd: (bool * binding) * (binding * string list * mixfix) * string
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    30
    * (binding * binding) option -> theory -> Proof.state
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
    31
  val pcpodef_proof: (bool * binding) * (binding * string list * mixfix) * term
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
    32
    * (binding * binding) option -> theory -> Proof.state
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
    33
  val pcpodef_proof_cmd: (bool * binding) * (binding * string list * mixfix) * string
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
    34
    * (binding * binding) option -> theory -> Proof.state
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    35
end;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    36
31738
7b9b9ba532ca discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31725
diff changeset
    37
structure Pcpodef :> PCPODEF =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    38
struct
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    39
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    40
(** type definitions **)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    41
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    42
type cpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    43
  { below_def: thm, adm: thm, cont_Rep: thm, cont_Abs: thm,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    44
    lub: thm, thelub: thm, compact: thm }
23152
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 pcpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    47
  { Rep_strict: thm, Abs_strict: thm, Rep_strict_iff: thm, Abs_strict_iff: thm,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    48
    Rep_defined: thm, Abs_defined: thm }
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    49
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    50
(* building terms *)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    51
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
    52
fun adm_const T = Const (@{const_name adm}, (T --> HOLogic.boolT) --> HOLogic.boolT);
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    53
fun mk_adm (x, T, P) = adm_const T $ absfree (x, T, P);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    54
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    55
fun below_const T = Const (@{const_name below}, T --> T --> HOLogic.boolT);
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    56
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    57
(* manipulating theorems *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    58
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    59
fun fold_adm_mem thm NONE = thm
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    60
  | fold_adm_mem thm (SOME set_def) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    61
    let val rule = @{lemma "A == B ==> adm (%x. x : B) ==> adm (%x. x : A)" by simp}
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    62
    in rule OF [set_def, thm] end;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    63
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    64
fun fold_UU_mem thm NONE = thm
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    65
  | fold_UU_mem thm (SOME set_def) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    66
    let val rule = @{lemma "A == B ==> UU : B ==> UU : A" by simp}
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    67
    in rule OF [set_def, thm] end;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    68
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    69
(* proving class instances *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    70
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    71
fun prove_cpo
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    72
      (name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    73
      (newT: typ)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    74
      (Rep_name: binding, Abs_name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    75
      (type_definition: thm)  (* type_definition Rep Abs A *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    76
      (set_def: thm option)   (* A == set *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    77
      (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    78
      (admissible: thm)       (* adm (%x. x : set) *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    79
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    80
    =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    81
  let
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    82
    val admissible' = fold_adm_mem admissible set_def;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    83
    val cpo_thms = map (Thm.transfer thy) [type_definition, below_def, admissible'];
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    84
    val (full_tname, Ts) = dest_Type newT;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    85
    val lhs_sorts = map (snd o dest_TFree) Ts;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    86
    val thy2 =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    87
      thy
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    88
      |> AxClass.prove_arity (full_tname, lhs_sorts, @{sort cpo})
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    89
          (Tactic.rtac (@{thm typedef_cpo} OF cpo_thms) 1);
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
    90
    (* transfer thms so that they will know about the new cpo instance *)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    91
    val cpo_thms' = map (Thm.transfer thy2) cpo_thms;
35021
c839a4c670c6 renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents: 33680
diff changeset
    92
    fun make thm = Drule.export_without_context (thm OF cpo_thms');
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    93
    val ([adm, cont_Rep, cont_Abs, lub, thelub, compact], thy3) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    94
      thy2
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    95
      |> Sign.add_path (Binding.name_of name)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    96
      |> PureThy.add_thms
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    97
        ([((Binding.prefix_name "adm_" name, admissible'), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    98
          ((Binding.prefix_name "cont_" Rep_name, make @{thm typedef_cont_Rep}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
    99
          ((Binding.prefix_name "cont_" Abs_name, make @{thm typedef_cont_Abs}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   100
          ((Binding.prefix_name "lub_" name, make @{thm typedef_lub}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   101
          ((Binding.prefix_name "thelub_" name, make @{thm typedef_thelub}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   102
          ((Binding.prefix_name "compact_" name, make @{thm typedef_compact}), [])])
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   103
      ||> Sign.parent_path;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   104
    val cpo_info : cpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   105
      { below_def = below_def, adm = admissible', cont_Rep = cont_Rep,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   106
        cont_Abs = cont_Abs, lub = lub, thelub = thelub, compact = compact };
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   107
  in
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   108
    (cpo_info, thy3)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   109
  end;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   110
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   111
fun prove_pcpo
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   112
      (name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   113
      (newT: typ)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   114
      (Rep_name: binding, Abs_name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   115
      (type_definition: thm)  (* type_definition Rep Abs A *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   116
      (set_def: thm option)   (* A == set *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   117
      (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   118
      (UU_mem: thm)           (* UU : set *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   119
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   120
    =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   121
  let
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   122
    val UU_mem' = fold_UU_mem UU_mem set_def;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   123
    val pcpo_thms = map (Thm.transfer thy) [type_definition, below_def, UU_mem'];
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   124
    val (full_tname, Ts) = dest_Type newT;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   125
    val lhs_sorts = map (snd o dest_TFree) Ts;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   126
    val thy2 = thy
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   127
      |> AxClass.prove_arity (full_tname, lhs_sorts, @{sort pcpo})
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   128
        (Tactic.rtac (@{thm typedef_pcpo} OF pcpo_thms) 1);
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   129
    val pcpo_thms' = map (Thm.transfer thy2) pcpo_thms;
35021
c839a4c670c6 renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents: 33680
diff changeset
   130
    fun make thm = Drule.export_without_context (thm OF pcpo_thms');
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   131
    val ([Rep_strict, Abs_strict, Rep_strict_iff, Abs_strict_iff,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   132
          Rep_defined, Abs_defined], thy3) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   133
      thy2
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   134
      |> Sign.add_path (Binding.name_of name)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   135
      |> PureThy.add_thms
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   136
        ([((Binding.suffix_name "_strict" Rep_name, make @{thm typedef_Rep_strict}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   137
          ((Binding.suffix_name "_strict" Abs_name, make @{thm typedef_Abs_strict}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   138
          ((Binding.suffix_name "_strict_iff" Rep_name, make @{thm typedef_Rep_strict_iff}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   139
          ((Binding.suffix_name "_strict_iff" Abs_name, make @{thm typedef_Abs_strict_iff}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   140
          ((Binding.suffix_name "_defined" Rep_name, make @{thm typedef_Rep_defined}), []),
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   141
          ((Binding.suffix_name "_defined" Abs_name, make @{thm typedef_Abs_defined}), [])])
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   142
      ||> Sign.parent_path;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   143
    val pcpo_info =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   144
      { Rep_strict = Rep_strict, Abs_strict = Abs_strict,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   145
        Rep_strict_iff = Rep_strict_iff, Abs_strict_iff = Abs_strict_iff,
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   146
        Rep_defined = Rep_defined, Abs_defined = Abs_defined };
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   147
  in
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   148
    (pcpo_info, thy3)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   149
  end;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   150
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   151
(* prepare_cpodef *)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   152
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   153
fun declare_type_name a =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   154
  Variable.declare_constraints (Logic.mk_type (TFree (a, dummyS)));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   155
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   156
fun prepare prep_term name (t, vs, mx) raw_set opt_morphs thy =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   157
  let
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   158
    val _ = Theory.requires thy "Pcpodef" "pcpodefs";
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   159
    val ctxt = ProofContext.init thy;
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   160
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   161
    (*rhs*)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   162
    val set = prep_term (ctxt |> fold declare_type_name vs) raw_set;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   163
    val setT = Term.fastype_of set;
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   164
    val rhs_tfrees = Term.add_tfrees set [];
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   165
    val oldT = HOLogic.dest_setT setT handle TYPE _ =>
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 24867
diff changeset
   166
      error ("Not a set type: " ^ quote (Syntax.string_of_typ ctxt setT));
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   167
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   168
    (*lhs*)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   169
    val defS = Sign.defaultS thy;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   170
    val lhs_tfrees = map (fn v => (v, the_default defS (AList.lookup (op =) rhs_tfrees v))) vs;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   171
    val tname = Binding.map_name (Syntax.type_name mx) t;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   172
    val full_tname = Sign.full_name thy tname;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   173
    val newT = Type (full_tname, map TFree lhs_tfrees);
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   174
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   175
    val morphs = opt_morphs
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   176
      |> the_default (Binding.prefix_name "Rep_" name, Binding.prefix_name "Abs_" name);
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   177
  in
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   178
    (newT, oldT, set, morphs)
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   179
  end
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   180
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   181
fun add_podef def opt_name typ set opt_morphs tac thy =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   182
  let
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   183
    val name = the_default (#1 typ) opt_name;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   184
    val ((full_tname, info as {type_definition, set_def, Rep_name, ...}), thy2) = thy
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   185
      |> Typedef.add_typedef def opt_name typ set opt_morphs tac;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   186
    val oldT = #rep_type info;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   187
    val newT = #abs_type info;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   188
    val lhs_tfrees = map dest_TFree (snd (dest_Type newT));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   189
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   190
    val RepC = Const (Rep_name, newT --> oldT);
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   191
    val below_eqn = Logic.mk_equals (below_const newT,
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   192
      Abs ("x", newT, Abs ("y", newT, below_const oldT $ (RepC $ Bound 1) $ (RepC $ Bound 0))));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   193
    val lthy3 = thy2
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   194
      |> Theory_Target.instantiation ([full_tname], lhs_tfrees, @{sort po});
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   195
    val ((_, (_, below_ldef)), lthy4) = lthy3
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   196
      |> Specification.definition (NONE,
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   197
          ((Binding.prefix_name "below_" (Binding.suffix_name "_def" name), []), below_eqn));
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   198
    val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy4);
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   199
    val below_def = singleton (ProofContext.export lthy4 ctxt_thy) below_ldef;
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   200
    val thy5 = lthy4
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   201
      |> Class.prove_instantiation_instance
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   202
          (K (Tactic.rtac (@{thm typedef_po} OF [type_definition, below_def]) 1))
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33646
diff changeset
   203
      |> Local_Theory.exit_global;
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   204
  in ((info, below_def), thy5) end;
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   205
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   206
fun prepare_cpodef
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   207
      (prep_term: Proof.context -> 'a -> term)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   208
      (def: bool)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   209
      (name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   210
      (typ: binding * string list * mixfix)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   211
      (raw_set: 'a)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   212
      (opt_morphs: (binding * binding) option)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   213
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   214
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info) * theory) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   215
  let
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   216
    val (newT, oldT, set, morphs as (Rep_name, Abs_name)) =
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   217
      prepare prep_term name typ raw_set opt_morphs thy;
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   218
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   219
    val goal_nonempty =
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   220
      HOLogic.mk_Trueprop (HOLogic.mk_exists ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   221
    val goal_admissible =
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   222
      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
   223
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   224
    fun cpodef_result nonempty admissible thy =
28073
5e9f00f4f209 adapted to class instantiation compliance
haftmann
parents: 27691
diff changeset
   225
      let
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   226
        val ((info as {type_definition, set_def, ...}, below_def), thy2) = thy
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   227
          |> add_podef def (SOME name) typ set opt_morphs (Tactic.rtac nonempty 1);
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   228
        val (cpo_info, thy3) = thy2
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   229
          |> prove_cpo name newT morphs type_definition set_def below_def admissible;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   230
      in
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   231
        ((info, cpo_info), thy3)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   232
      end;
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   233
  in
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   234
    (goal_nonempty, goal_admissible, cpodef_result)
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   235
  end
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   236
  handle ERROR msg =>
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   237
    cat_error msg ("The error(s) above occurred in cpodef " ^ quote (Binding.str_of name));
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   238
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   239
fun prepare_pcpodef
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   240
      (prep_term: Proof.context -> 'a -> term)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   241
      (def: bool)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   242
      (name: binding)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   243
      (typ: binding * string list * mixfix)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   244
      (raw_set: 'a)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   245
      (opt_morphs: (binding * binding) option)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   246
      (thy: theory)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   247
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info * pcpo_info) * theory) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   248
  let
33678
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   249
    val (newT, oldT, set, morphs as (Rep_name, Abs_name)) =
2a2014cbb2a6 cleaned up, removed unneeded call to Syntax.check_term
huffman
parents: 33646
diff changeset
   250
      prepare prep_term name typ raw_set opt_morphs thy;
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   251
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   252
    val goal_UU_mem =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   253
      HOLogic.mk_Trueprop (HOLogic.mk_mem (Const (@{const_name UU}, oldT), set));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   254
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   255
    val goal_admissible =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   256
      HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   257
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   258
    fun pcpodef_result UU_mem admissible thy =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   259
      let
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   260
        val tac = Tactic.rtac exI 1 THEN Tactic.rtac UU_mem 1;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   261
        val ((info as {type_definition, set_def, ...}, below_def), thy2) = thy
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   262
          |> add_podef def (SOME name) typ set opt_morphs tac;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   263
        val (cpo_info, thy3) = thy2
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   264
          |> prove_cpo name newT morphs type_definition set_def below_def admissible;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   265
        val (pcpo_info, thy4) = thy3
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   266
          |> prove_pcpo name newT morphs type_definition set_def below_def UU_mem;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   267
      in
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   268
        ((info, cpo_info, pcpo_info), thy4)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   269
      end;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   270
  in
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   271
    (goal_UU_mem, goal_admissible, pcpodef_result)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   272
  end
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   273
  handle ERROR msg =>
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   274
    cat_error msg ("The error(s) above occurred in pcpodef " ^ quote (Binding.str_of name));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   275
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   276
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   277
(* tactic interface *)
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   278
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   279
fun add_cpodef def opt_name typ set opt_morphs (tac1, tac2) thy =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   280
  let
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   281
    val name = the_default (#1 typ) opt_name;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   282
    val (goal1, goal2, cpodef_result) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   283
      prepare_cpodef Syntax.check_term def name typ set opt_morphs thy;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   284
    val thm1 = Goal.prove_global thy [] [] goal1 (K tac1)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   285
      handle ERROR msg => cat_error msg
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   286
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   287
    val thm2 = Goal.prove_global thy [] [] goal2 (K tac2)
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   288
      handle ERROR msg => cat_error msg
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   289
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set));
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   290
  in cpodef_result thm1 thm2 thy end;
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   291
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   292
fun add_pcpodef def opt_name typ set opt_morphs (tac1, tac2) thy =
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   293
  let
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   294
    val name = the_default (#1 typ) opt_name;
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   295
    val (goal1, goal2, pcpodef_result) =
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   296
      prepare_pcpodef Syntax.check_term def name typ set opt_morphs thy;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   297
    val thm1 = Goal.prove_global thy [] [] goal1 (K tac1)
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   298
      handle ERROR msg => cat_error msg
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   299
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set));
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   300
    val thm2 = Goal.prove_global thy [] [] goal2 (K tac2)
33645
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   301
      handle ERROR msg => cat_error msg
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   302
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set));
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   303
  in pcpodef_result thm1 thm2 thy end;
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   304
562635ab559b use Drule.standard (following typedef package), add pcpodef tactic interface
huffman
parents: 33553
diff changeset
   305
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   306
(* proof interface *)
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   307
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   308
local
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   309
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   310
fun gen_cpodef_proof prep_term ((def, name), typ, set, opt_morphs) thy =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   311
  let
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   312
    val (goal1, goal2, make_result) =
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   313
      prepare_cpodef prep_term def name typ set opt_morphs thy;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   314
    fun after_qed [[th1, th2]] = ProofContext.theory (snd o make_result th1 th2);
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   315
  in Proof.theorem_i NONE after_qed [[(goal1, []), (goal2, [])]] (ProofContext.init thy) end;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   316
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   317
fun gen_pcpodef_proof prep_term ((def, name), typ, set, opt_morphs) thy =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   318
  let
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   319
    val (goal1, goal2, make_result) =
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   320
      prepare_pcpodef prep_term def name typ set opt_morphs thy;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   321
    fun after_qed [[th1, th2]] = ProofContext.theory (snd o make_result th1 th2);
29063
7619f0561cd7 pcpodef package: state two goals, instead of encoded conjunction;
wenzelm
parents: 29060
diff changeset
   322
  in Proof.theorem_i NONE after_qed [[(goal1, []), (goal2, [])]] (ProofContext.init thy) end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   323
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   324
in
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   325
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   326
fun cpodef_proof x = gen_cpodef_proof Syntax.check_term x;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   327
fun cpodef_proof_cmd x = gen_cpodef_proof Syntax.read_term x;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   328
33646
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   329
fun pcpodef_proof x = gen_pcpodef_proof Syntax.check_term x;
d2f3104ca3d2 improved ML interface to pcpodef
huffman
parents: 33645
diff changeset
   330
fun pcpodef_proof_cmd x = gen_pcpodef_proof Syntax.read_term x;
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   331
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   332
end;
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   333
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   334
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   335
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   336
(** outer syntax **)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   337
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   338
local structure P = OuterParse and K = OuterKeyword in
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   339
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   340
val typedef_proof_decl =
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   341
  Scan.optional (P.$$$ "(" |--
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   342
      ((P.$$$ "open" >> K false) -- Scan.option P.binding || P.binding >> (fn s => (true, SOME s)))
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   343
        --| P.$$$ ")") (true, NONE) --
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   344
    (P.type_args -- P.binding) -- P.opt_infix -- (P.$$$ "=" |-- P.term) --
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   345
    Scan.option (P.$$$ "morphisms" |-- P.!!! (P.binding -- P.binding));
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   346
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   347
fun mk_pcpodef_proof pcpo ((((((def, opt_name), (vs, t)), mx), A), morphs)) =
29060
d7bde0b4bf72 tuned signature: pcpodef_proof, pcpodef_proof_cmd etc.;
wenzelm
parents: 28965
diff changeset
   348
  (if pcpo then pcpodef_proof_cmd else cpodef_proof_cmd)
30345
76fd85bbf139 more uniform handling of binding in packages;
wenzelm
parents: 29585
diff changeset
   349
    ((def, the_default (Binding.map_name (Syntax.type_name mx) t) opt_name), (t, vs, mx), A, morphs);
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   350
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   351
val _ =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   352
  OuterSyntax.command "pcpodef" "HOLCF type definition (requires admissibility proof)" K.thy_goal
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   353
    (typedef_proof_decl >>
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   354
      (Toplevel.print oo (Toplevel.theory_to_proof o mk_pcpodef_proof true)));
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   355
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   356
val _ =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   357
  OuterSyntax.command "cpodef" "HOLCF type definition (requires admissibility proof)" K.thy_goal
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   358
    (typedef_proof_decl >>
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   359
      (Toplevel.print oo (Toplevel.theory_to_proof o mk_pcpodef_proof false)));
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   360
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   361
end;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   362
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   363
end;