src/Pure/Isar/specification.ML
author wenzelm
Sun, 17 Apr 2011 19:54:04 +0200
changeset 42375 774df7c59508
parent 42360 da8817d01e7c
child 42440 5e7a7343ab11
permissions -rw-r--r--
report Name_Space.declare/define, relatively to context; added "global" variants of context-dependent declarations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/specification.ML
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
     3
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
     4
Derived local theory specifications --- with type-inference and
18810
6dc5416368e9 swapped Toplevel.theory_context;
wenzelm
parents: 18786
diff changeset
     5
toplevel polymorphism.
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
     6
*)
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
     7
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
     8
signature SPECIFICATION =
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
     9
sig
20890
052bde912a51 moved pretty_consts to proof_display.ML;
wenzelm
parents: 20784
diff changeset
    10
  val print_consts: local_theory -> (string * typ -> bool) -> (string * typ) list -> unit
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    11
  val check_spec:
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    12
    (binding * typ option * mixfix) list -> (Attrib.binding * term) list -> Proof.context ->
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    13
    (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    14
  val read_spec:
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    15
    (binding * string option * mixfix) list -> (Attrib.binding * string) list -> Proof.context ->
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    16
    (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    17
  val check_free_spec:
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    18
    (binding * typ option * mixfix) list -> (Attrib.binding * term) list -> Proof.context ->
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    19
    (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    20
  val read_free_spec:
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    21
    (binding * string option * mixfix) list -> (Attrib.binding * string) list -> Proof.context ->
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    22
    (((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    23
  val check_specification: (binding * typ option * mixfix) list ->
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
    24
    (Attrib.binding * term list) list -> Proof.context ->
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    25
    (((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    26
  val read_specification: (binding * string option * mixfix) list ->
28084
a05ca48ef263 type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents: 28080
diff changeset
    27
    (Attrib.binding * string list) list -> Proof.context ->
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    28
    (((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    29
  val axiomatization: (binding * typ option * mixfix) list ->
28114
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
    30
    (Attrib.binding * term list) list -> theory ->
33703
50b6c07c0dd4 axiomatization: declare Spec_Rules, direct result;
wenzelm
parents: 33671
diff changeset
    31
    (term list * thm list list) * theory
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    32
  val axiomatization_cmd: (binding * string option * mixfix) list ->
28114
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
    33
    (Attrib.binding * string list) list -> theory ->
33703
50b6c07c0dd4 axiomatization: declare Spec_Rules, direct result;
wenzelm
parents: 33671
diff changeset
    34
    (term list * thm list list) * theory
35894
ab6dc4d86ea1 added Specification.axiom convenience;
wenzelm
parents: 35625
diff changeset
    35
  val axiom: Attrib.binding * term -> theory -> thm * theory
ab6dc4d86ea1 added Specification.axiom convenience;
wenzelm
parents: 35625
diff changeset
    36
  val axiom_cmd: Attrib.binding * string -> theory -> thm * theory
18954
ab48b6ac9327 type local_theory;
wenzelm
parents: 18880
diff changeset
    37
  val definition:
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    38
    (binding * typ option * mixfix) option * (Attrib.binding * term) ->
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
    39
    local_theory -> (term * (string * thm)) * local_theory
24927
48e08f37ce92 Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
wenzelm
parents: 24848
diff changeset
    40
  val definition_cmd:
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    41
    (binding * string option * mixfix) option * (Attrib.binding * string) ->
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
    42
    local_theory -> (term * (string * thm)) * local_theory
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    43
  val abbreviation: Syntax.mode -> (binding * typ option * mixfix) option * term ->
21532
8c162b766cef abbrevs: no result;
wenzelm
parents: 21450
diff changeset
    44
    local_theory -> local_theory
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29249
diff changeset
    45
  val abbreviation_cmd: Syntax.mode -> (binding * string option * mixfix) option * string ->
24927
48e08f37ce92 Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
wenzelm
parents: 24848
diff changeset
    46
    local_theory -> local_theory
35413
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
    47
  val type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> local_theory -> local_theory
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
    48
  val type_notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> local_theory -> local_theory
24949
5f00e3532418 generalized notation interface (add or del);
wenzelm
parents: 24927
diff changeset
    49
  val notation: bool -> Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory
5f00e3532418 generalized notation interface (add or del);
wenzelm
parents: 24927
diff changeset
    50
  val notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> local_theory -> local_theory
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
    51
  val theorems: string ->
28084
a05ca48ef263 type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents: 28080
diff changeset
    52
    (Attrib.binding * (thm list * Attrib.src list) list) list ->
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
    53
    local_theory -> (string * thm list) list * local_theory
26336
a0e2b706ce73 renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents: 25371
diff changeset
    54
  val theorems_cmd: string ->
28084
a05ca48ef263 type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents: 28080
diff changeset
    55
    (Attrib.binding * (Facts.ref * Attrib.src list) list) list ->
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
    56
    local_theory -> (string * thm list) list * local_theory
24986
1f902ded7f70 removed unused/impure quiet_mode;
wenzelm
parents: 24949
diff changeset
    57
  val theorem: string -> Method.text option ->
28084
a05ca48ef263 type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents: 28080
diff changeset
    58
    (thm list list -> local_theory -> local_theory) -> Attrib.binding ->
28710
e2064974c114 Dropped context element 'includes'.
ballarin
parents: 28703
diff changeset
    59
    Element.context_i list -> Element.statement_i ->
24452
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
    60
    bool -> local_theory -> Proof.state
24986
1f902ded7f70 removed unused/impure quiet_mode;
wenzelm
parents: 24949
diff changeset
    61
  val theorem_cmd: string -> Method.text option ->
28084
a05ca48ef263 type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents: 28080
diff changeset
    62
    (thm list list -> local_theory -> local_theory) -> Attrib.binding ->
28710
e2064974c114 Dropped context element 'includes'.
ballarin
parents: 28703
diff changeset
    63
    Element.context list -> Element.statement ->
24452
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
    64
    bool -> local_theory -> Proof.state
36317
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    65
  val schematic_theorem: string -> Method.text option ->
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    66
    (thm list list -> local_theory -> local_theory) -> Attrib.binding ->
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    67
    Element.context_i list -> Element.statement_i ->
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    68
    bool -> local_theory -> Proof.state
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    69
  val schematic_theorem_cmd: string -> Method.text option ->
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    70
    (thm list list -> local_theory -> local_theory) -> Attrib.binding ->
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    71
    Element.context list -> Element.statement ->
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
    72
    bool -> local_theory -> Proof.state
24452
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
    73
  val add_theorem_hook: (bool -> Proof.state -> Proof.state) -> Context.generic -> Context.generic
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
    74
end;
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
    75
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
    76
structure Specification: SPECIFICATION =
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
    77
struct
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
    78
20890
052bde912a51 moved pretty_consts to proof_display.ML;
wenzelm
parents: 20784
diff changeset
    79
(* diagnostics *)
052bde912a51 moved pretty_consts to proof_display.ML;
wenzelm
parents: 20784
diff changeset
    80
052bde912a51 moved pretty_consts to proof_display.ML;
wenzelm
parents: 20784
diff changeset
    81
fun print_consts _ _ [] = ()
33389
bb3a5fa94a91 modernized structure Proof_Display;
wenzelm
parents: 33386
diff changeset
    82
  | print_consts ctxt pred cs = Pretty.writeln (Proof_Display.pretty_consts ctxt pred cs);
20914
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
    83
19664
e1dc01a48a52 added const_syntax(_i);
wenzelm
parents: 19585
diff changeset
    84
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
    85
(* prepare specification *)
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
    86
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    87
local
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    88
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    89
fun close_forms ctxt i xs As =
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    90
  let
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    91
    fun add_free (Free (x, _)) = if Variable.is_fixed ctxt x then I else insert (op =) x
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    92
      | add_free _ = I;
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    93
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    94
    val commons = map #1 xs;
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    95
    val _ =
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    96
      (case duplicates (op =) commons of [] => ()
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    97
      | dups => error ("Duplicate local variables " ^ commas_quote dups));
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
    98
    val frees = rev ((fold o fold_aterms) add_free As (rev commons));
37145
01aa36932739 renamed structure TypeInfer to Type_Infer, keeping the old name as legacy alias for some time;
wenzelm
parents: 36610
diff changeset
    99
    val types = map (Type_Infer.param i o rpair []) (Name.invents Name.context Name.aT (length frees));
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   100
    val uniform_typing = the o AList.lookup (op =) (frees ~~ types);
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   101
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   102
    fun abs_body lev y (Abs (x, T, b)) = Abs (x, T, abs_body (lev + 1) y b)
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   103
      | abs_body lev y (t $ u) = abs_body lev y t $ abs_body lev y u
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   104
      | abs_body lev y (t as Free (x, T)) =
39288
f1ae2493d93f eliminated aliases of Type.constraint;
wenzelm
parents: 38388
diff changeset
   105
          if x = y then Type.constraint (uniform_typing x) (Type.constraint T (Bound lev))
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   106
          else t
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   107
      | abs_body _ _ a = a;
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   108
    fun close (y, U) B =
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   109
      let val B' = abs_body 0 y (Term.incr_boundvars 1 B)
42083
e1209fc7ecdc added Term.is_open and Term.is_dependent convenience, to cover common situations of loose bounds;
wenzelm
parents: 41472
diff changeset
   110
      in if Term.is_dependent B' then Term.all dummyT $ Abs (y, U, B') else B end;
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   111
    fun close_form A =
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   112
      let
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   113
        val occ_frees = rev (fold_aterms add_free A []);
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   114
        val bounds = xs @ map (rpair dummyT) (subtract (op =) commons occ_frees);
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   115
      in fold_rev close bounds A end;
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   116
  in map close_form As end;
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   117
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   118
fun prepare prep_vars parse_prop prep_att do_close raw_vars raw_specss ctxt =
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   119
  let
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   120
    val thy = Proof_Context.theory_of ctxt;
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   121
18670
c3f445b92aff uniform handling of fixes;
wenzelm
parents: 18640
diff changeset
   122
    val (vars, vars_ctxt) = ctxt |> prep_vars raw_vars;
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   123
    val (xs, params_ctxt) = vars_ctxt |> Proof_Context.add_fixes vars;
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   124
42265
ffdaa07cf6cf parallel parsing of big specifications;
wenzelm
parents: 42083
diff changeset
   125
    val Asss =
ffdaa07cf6cf parallel parsing of big specifications;
wenzelm
parents: 42083
diff changeset
   126
      (map o map) snd raw_specss
ffdaa07cf6cf parallel parsing of big specifications;
wenzelm
parents: 42083
diff changeset
   127
      |> (burrow o burrow) (Par_List.map_name "Specification.parse_prop" (parse_prop params_ctxt));
24734
ff617b6711f4 read/check_specification: free_dummy_patterns;
wenzelm
parents: 24724
diff changeset
   128
    val names = Variable.names_of (params_ctxt |> (fold o fold o fold) Variable.declare_term Asss)
ff617b6711f4 read/check_specification: free_dummy_patterns;
wenzelm
parents: 24724
diff changeset
   129
      |> fold Name.declare xs;
ff617b6711f4 read/check_specification: free_dummy_patterns;
wenzelm
parents: 24724
diff changeset
   130
    val Asss' = #1 ((fold_map o fold_map o fold_map) Term.free_dummy_patterns Asss names);
ff617b6711f4 read/check_specification: free_dummy_patterns;
wenzelm
parents: 24724
diff changeset
   131
    val idx = (fold o fold o fold) Term.maxidx_term Asss' ~1 + 1;
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   132
    val specs =
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   133
      (if do_close then
24734
ff617b6711f4 read/check_specification: free_dummy_patterns;
wenzelm
parents: 24724
diff changeset
   134
        #1 (fold_map
ff617b6711f4 read/check_specification: free_dummy_patterns;
wenzelm
parents: 24724
diff changeset
   135
            (fn Ass => fn i => (burrow (close_forms params_ctxt i []) Ass, i + 1)) Asss' idx)
ff617b6711f4 read/check_specification: free_dummy_patterns;
wenzelm
parents: 24724
diff changeset
   136
      else Asss')
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   137
      |> flat |> burrow (Syntax.check_props params_ctxt);
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   138
    val specs_ctxt = params_ctxt |> (fold o fold) Variable.declare_term specs;
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   139
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   140
    val Ts = specs_ctxt |> fold_map Proof_Context.inferred_param xs |> fst;
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   141
    val params = map2 (fn (b, _, mx) => fn T => ((b, T), mx)) vars Ts;
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   142
    val name_atts = map (fn ((name, atts), _) => (name, map (prep_att thy) atts)) (flat raw_specss);
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   143
  in ((params, name_atts ~~ specs), specs_ctxt) end;
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   144
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   145
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   146
fun single_spec (a, prop) = [(a, [prop])];
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   147
fun the_spec (a, [prop]) = (a, prop);
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   148
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   149
fun prep_spec prep_vars parse_prop prep_att do_close vars specs =
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   150
  prepare prep_vars parse_prop prep_att do_close
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   151
    vars (map single_spec specs) #>> apsnd (map the_spec);
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   152
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   153
in
21370
d9dd7b4e5e69 replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
wenzelm
parents: 21359
diff changeset
   154
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   155
fun check_spec x = prep_spec Proof_Context.cert_vars (K I) (K I) true x;
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   156
fun read_spec x = prep_spec Proof_Context.read_vars Syntax.parse_prop Attrib.intern_src true x;
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   157
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   158
fun check_free_spec x = prep_spec Proof_Context.cert_vars (K I) (K I) false x;
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   159
fun read_free_spec x = prep_spec Proof_Context.read_vars Syntax.parse_prop Attrib.intern_src false x;
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   160
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   161
fun check_specification vars specs =
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   162
  prepare Proof_Context.cert_vars (K I) (K I) true vars [specs];
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   163
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   164
fun read_specification vars specs =
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   165
  prepare Proof_Context.read_vars Syntax.parse_prop Attrib.intern_src true vars [specs];
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   166
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   167
end;
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   168
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   169
28114
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
   170
(* axiomatization -- within global theory *)
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   171
28114
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
   172
fun gen_axioms do_print prep raw_vars raw_specs thy =
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   173
  let
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   174
    val ((vars, specs), _) = prep raw_vars raw_specs (Proof_Context.init_global thy);
42357
3305f573294e tuned signature, disentangled dependencies;
wenzelm
parents: 42265
diff changeset
   175
    val xs = map (fn ((b, T), _) => (Variable.name b, T)) vars;
28114
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
   176
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
   177
    (*consts*)
33173
b8ca12f6681a eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
wenzelm
parents: 32856
diff changeset
   178
    val (consts, consts_thy) = thy |> fold_map Theory.specify_const vars;
28114
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
   179
    val subst = Term.subst_atomic (map Free xs ~~ consts);
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
   180
2637fb838f74 axiomatization is now global-only;
wenzelm
parents: 28093
diff changeset
   181
    (*axioms*)
30470
9ae8f9d78cd3 axiomatization: more precise treatment of binding;
wenzelm
parents: 30434
diff changeset
   182
    val (axioms, axioms_thy) = (specs, consts_thy) |-> fold_map (fn ((b, atts), props) =>
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 42360
diff changeset
   183
        fold_map Thm.add_axiom_global
30470
9ae8f9d78cd3 axiomatization: more precise treatment of binding;
wenzelm
parents: 30434
diff changeset
   184
          (map (apfst (fn a => Binding.map_name (K a) b))
42357
3305f573294e tuned signature, disentangled dependencies;
wenzelm
parents: 42265
diff changeset
   185
            (Global_Theory.name_multi (Variable.name b) (map subst props)))
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35894
diff changeset
   186
        #>> (fn ths => ((b, atts), [(map #2 ths, [])])));
30470
9ae8f9d78cd3 axiomatization: more precise treatment of binding;
wenzelm
parents: 30434
diff changeset
   187
9ae8f9d78cd3 axiomatization: more precise treatment of binding;
wenzelm
parents: 30434
diff changeset
   188
    (*facts*)
33703
50b6c07c0dd4 axiomatization: declare Spec_Rules, direct result;
wenzelm
parents: 33671
diff changeset
   189
    val (facts, facts_lthy) = axioms_thy
38388
94d5624dd1f7 Named_Target.theory_init
haftmann
parents: 38350
diff changeset
   190
      |> Named_Target.theory_init
33703
50b6c07c0dd4 axiomatization: declare Spec_Rules, direct result;
wenzelm
parents: 33671
diff changeset
   191
      |> Spec_Rules.add Spec_Rules.Unknown (consts, maps (maps #1 o #2) axioms)
50b6c07c0dd4 axiomatization: declare Spec_Rules, direct result;
wenzelm
parents: 33671
diff changeset
   192
      |> Local_Theory.notes axioms;
30470
9ae8f9d78cd3 axiomatization: more precise treatment of binding;
wenzelm
parents: 30434
diff changeset
   193
26595
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   194
    val _ =
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   195
      if not do_print then ()
33703
50b6c07c0dd4 axiomatization: declare Spec_Rules, direct result;
wenzelm
parents: 33671
diff changeset
   196
      else print_consts facts_lthy (K false) xs;
50b6c07c0dd4 axiomatization: declare Spec_Rules, direct result;
wenzelm
parents: 33671
diff changeset
   197
  in ((consts, map #2 facts), Local_Theory.exit_global facts_lthy) end;
18786
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   198
26595
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   199
val axiomatization = gen_axioms false check_specification;
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   200
val axiomatization_cmd = gen_axioms true read_specification;
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   201
35894
ab6dc4d86ea1 added Specification.axiom convenience;
wenzelm
parents: 35625
diff changeset
   202
fun axiom (b, ax) = axiomatization [] [(b, [ax])] #>> (hd o hd o snd);
ab6dc4d86ea1 added Specification.axiom convenience;
wenzelm
parents: 35625
diff changeset
   203
fun axiom_cmd (b, ax) = axiomatization_cmd [] [(b, [ax])] #>> (hd o hd o snd);
ab6dc4d86ea1 added Specification.axiom convenience;
wenzelm
parents: 35625
diff changeset
   204
18786
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   205
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   206
(* definition *)
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   207
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   208
fun gen_def do_print prep (raw_var, raw_spec) lthy =
18786
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   209
  let
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   210
    val (vars, [((raw_name, atts), prop)]) = fst (prep (the_list raw_var) [raw_spec] lthy);
35624
c4e29a0bb8c1 modernized structure Local_Defs;
wenzelm
parents: 35413
diff changeset
   211
    val (((x, T), rhs), prove) = Local_Defs.derived_def lthy true prop;
30434
9b94b1358b95 Thm.def_binding_optional;
wenzelm
parents: 30344
diff changeset
   212
    val var as (b, _) =
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   213
      (case vars of
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28941
diff changeset
   214
        [] => (Binding.name x, NoSyn)
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   215
      | [((b, _), mx)] =>
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   216
          let
42357
3305f573294e tuned signature, disentangled dependencies;
wenzelm
parents: 42265
diff changeset
   217
            val y = Variable.name b;
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   218
            val _ = x = y orelse
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   219
              error ("Head of definition " ^ quote x ^ " differs from declaration " ^ quote y ^
28941
128459bd72d2 new Binding module
haftmann
parents: 28880
diff changeset
   220
                Position.str_of (Binding.pos_of b));
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   221
          in (b, mx) end);
30434
9b94b1358b95 Thm.def_binding_optional;
wenzelm
parents: 30344
diff changeset
   222
    val name = Thm.def_binding_optional b raw_name;
33455
4da71b27b3fe declare Spec_Rules for most basic definitional packages;
wenzelm
parents: 33389
diff changeset
   223
    val ((lhs, (_, raw_th)), lthy2) = lthy
33765
47b5db097646 Specification.definition: Thm.definitionK marks exactly the high-level end-user result;
wenzelm
parents: 33756
diff changeset
   224
      |> Local_Theory.define (var, ((Binding.suffix_name "_raw" name, []), rhs));
33455
4da71b27b3fe declare Spec_Rules for most basic definitional packages;
wenzelm
parents: 33389
diff changeset
   225
4da71b27b3fe declare Spec_Rules for most basic definitional packages;
wenzelm
parents: 33389
diff changeset
   226
    val th = prove lthy2 raw_th;
4da71b27b3fe declare Spec_Rules for most basic definitional packages;
wenzelm
parents: 33389
diff changeset
   227
    val lthy3 = lthy2 |> Spec_Rules.add Spec_Rules.Equational ([lhs], [th]);
4da71b27b3fe declare Spec_Rules for most basic definitional packages;
wenzelm
parents: 33389
diff changeset
   228
33670
02b7738aef6a eliminated slightly odd kind argument of LocalTheory.note(s);
wenzelm
parents: 33644
diff changeset
   229
    val ([(def_name, [th'])], lthy4) = lthy3
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   230
      |> Local_Theory.notes_kind Thm.definitionK
33756
47b7c9e0bf6e replacing Predicate_Compile_Preproc_Const_Defs by more general Spec_Rules
bulwahn
parents: 33703
diff changeset
   231
        [((name, Code.add_default_eqn_attrib :: atts), [([th], [])])];
18786
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   232
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   233
    val lhs' = Morphism.term (Local_Theory.target_morphism lthy4) lhs;
26595
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   234
    val _ =
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   235
      if not do_print then ()
33455
4da71b27b3fe declare Spec_Rules for most basic definitional packages;
wenzelm
parents: 33389
diff changeset
   236
      else print_consts lthy4 (member (op =) (Term.add_frees lhs' [])) [(x, T)];
4da71b27b3fe declare Spec_Rules for most basic definitional packages;
wenzelm
parents: 33389
diff changeset
   237
  in ((lhs, (def_name, th')), lthy4) end;
18786
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   238
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   239
val definition = gen_def false check_free_spec;
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   240
val definition_cmd = gen_def true read_free_spec;
18786
591a37d48794 added definition(_i);
wenzelm
parents: 18771
diff changeset
   241
19080
46ba991e27d5 added abbreviation(_i);
wenzelm
parents: 18954
diff changeset
   242
46ba991e27d5 added abbreviation(_i);
wenzelm
parents: 18954
diff changeset
   243
(* abbreviation *)
46ba991e27d5 added abbreviation(_i);
wenzelm
parents: 18954
diff changeset
   244
26595
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   245
fun gen_abbrev do_print prep mode (raw_var, raw_prop) lthy =
19080
46ba991e27d5 added abbreviation(_i);
wenzelm
parents: 18954
diff changeset
   246
  let
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   247
    val ((vars, [(_, prop)]), _) =
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   248
      prep (the_list raw_var) [(Attrib.empty_binding, raw_prop)]
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   249
        (lthy |> Proof_Context.set_mode Proof_Context.mode_abbrev);
35624
c4e29a0bb8c1 modernized structure Local_Defs;
wenzelm
parents: 35413
diff changeset
   250
    val ((x, T), rhs) = Local_Defs.abs_def (#2 (Local_Defs.cert_def lthy prop));
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   251
    val var =
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   252
      (case vars of
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28941
diff changeset
   253
        [] => (Binding.name x, NoSyn)
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   254
      | [((b, _), mx)] =>
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   255
          let
42357
3305f573294e tuned signature, disentangled dependencies;
wenzelm
parents: 42265
diff changeset
   256
            val y = Variable.name b;
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   257
            val _ = x = y orelse
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   258
              error ("Head of abbreviation " ^ quote x ^ " differs from declaration " ^ quote y ^
28941
128459bd72d2 new Binding module
haftmann
parents: 28880
diff changeset
   259
                Position.str_of (Binding.pos_of b));
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   260
          in (b, mx) end);
21705
0f3ad56548bc definition/abbreviation: single argument;
wenzelm
parents: 21691
diff changeset
   261
    val lthy' = lthy
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   262
      |> Proof_Context.set_syntax_mode mode    (* FIXME ?!? *)
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   263
      |> Local_Theory.abbrev mode (var, rhs) |> snd
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   264
      |> Proof_Context.restore_syntax_mode lthy;
24724
0df74bb87a13 read/check_specification: proper type inference across multiple sections, result is in closed form;
wenzelm
parents: 24676
diff changeset
   265
26595
855893d4d75f print_consts only for external specifications;
wenzelm
parents: 26345
diff changeset
   266
    val _ = if not do_print then () else print_consts lthy' (K false) [(x, T)];
21532
8c162b766cef abbrevs: no result;
wenzelm
parents: 21450
diff changeset
   267
  in lthy' end;
19080
46ba991e27d5 added abbreviation(_i);
wenzelm
parents: 18954
diff changeset
   268
30482
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   269
val abbreviation = gen_abbrev false check_free_spec;
6e3c92de4a7d simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
wenzelm
parents: 30472
diff changeset
   270
val abbreviation_cmd = gen_abbrev true read_free_spec;
19080
46ba991e27d5 added abbreviation(_i);
wenzelm
parents: 18954
diff changeset
   271
19664
e1dc01a48a52 added const_syntax(_i);
wenzelm
parents: 19585
diff changeset
   272
21230
abfdce60b371 theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents: 21206
diff changeset
   273
(* notation *)
19664
e1dc01a48a52 added const_syntax(_i);
wenzelm
parents: 19585
diff changeset
   274
35413
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   275
local
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   276
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   277
fun gen_type_notation prep_type add mode args lthy =
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   278
  lthy |> Local_Theory.type_notation add mode (map (apfst (prep_type lthy)) args);
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   279
24949
5f00e3532418 generalized notation interface (add or del);
wenzelm
parents: 24927
diff changeset
   280
fun gen_notation prep_const add mode args lthy =
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   281
  lthy |> Local_Theory.notation add mode (map (apfst (prep_const lthy)) args);
19664
e1dc01a48a52 added const_syntax(_i);
wenzelm
parents: 19585
diff changeset
   282
35413
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   283
in
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   284
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   285
val type_notation = gen_type_notation (K I);
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   286
val type_notation_cmd = gen_type_notation (fn ctxt => Proof_Context.read_type_name ctxt false);
35413
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   287
24927
48e08f37ce92 Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
wenzelm
parents: 24848
diff changeset
   288
val notation = gen_notation (K I);
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   289
val notation_cmd = gen_notation (fn ctxt => Proof_Context.read_const ctxt false dummyT);
19664
e1dc01a48a52 added const_syntax(_i);
wenzelm
parents: 19585
diff changeset
   290
35413
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   291
end;
4c7cba1f7ce9 added type_notation command;
wenzelm
parents: 35399
diff changeset
   292
20914
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   293
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   294
(* fact statements *)
20914
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   295
26345
f70620a4cf81 renamed former get_thms(_silent) to get_fact(_silent);
wenzelm
parents: 26336
diff changeset
   296
fun gen_theorems prep_fact prep_att kind raw_facts lthy =
20914
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   297
  let
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   298
    val attrib = prep_att (Proof_Context.theory_of lthy);
20914
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   299
    val facts = raw_facts |> map (fn ((name, atts), bs) =>
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   300
      ((name, map attrib atts),
26345
f70620a4cf81 renamed former get_thms(_silent) to get_fact(_silent);
wenzelm
parents: 26336
diff changeset
   301
        bs |> map (fn (b, more_atts) => (prep_fact lthy b, map attrib more_atts))));
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   302
    val (res, lthy') = lthy |> Local_Theory.notes_kind kind facts;
33389
bb3a5fa94a91 modernized structure Proof_Display;
wenzelm
parents: 33386
diff changeset
   303
    val _ = Proof_Display.print_results true lthy' ((kind, ""), res);
20914
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   304
  in (res, lthy') end;
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   305
24927
48e08f37ce92 Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
wenzelm
parents: 24848
diff changeset
   306
val theorems = gen_theorems (K I) (K I);
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   307
val theorems_cmd = gen_theorems Proof_Context.get_fact Attrib.intern_src;
20914
3f065aa89792 added theorems(_i) -- with present_results;
wenzelm
parents: 20890
diff changeset
   308
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   309
21230
abfdce60b371 theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents: 21206
diff changeset
   310
(* complex goal statements *)
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   311
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   312
local
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   313
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   314
fun prep_statement prep_att prep_stmt elems concl ctxt =
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   315
  (case concl of
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   316
    Element.Shows shows =>
21230
abfdce60b371 theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents: 21206
diff changeset
   317
      let
28880
f6a547c5dbbf Enable switching to new locales during session.
ballarin
parents: 28877
diff changeset
   318
        val (propp, elems_ctxt) = prep_stmt elems (map snd shows) ctxt;
30472
9dea0866021c Assumption.local_prems_of;
wenzelm
parents: 30470
diff changeset
   319
        val prems = Assumption.local_prems_of elems_ctxt ctxt;
21450
f16c9e6401d1 theorem(_i): note assms of statement;
wenzelm
parents: 21435
diff changeset
   320
        val stmt = Attrib.map_specs prep_att (map fst shows ~~ propp);
21370
d9dd7b4e5e69 replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
wenzelm
parents: 21359
diff changeset
   321
        val goal_ctxt = fold (fold (Variable.auto_fixes o fst)) propp elems_ctxt;
32856
92d9555ac790 clarified Proof.refine_insert -- always "refine" to apply standard method treatment (of conjunctions);
wenzelm
parents: 32786
diff changeset
   322
      in ((prems, stmt, NONE), goal_ctxt) end
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   323
  | Element.Obtains obtains =>
21230
abfdce60b371 theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents: 21206
diff changeset
   324
      let
28862
53f13f763d4f tuned name bindings
haftmann
parents: 28858
diff changeset
   325
        val case_names = obtains |> map_index (fn (i, (b, _)) =>
42357
3305f573294e tuned signature, disentangled dependencies;
wenzelm
parents: 42265
diff changeset
   326
          if Binding.is_empty b then string_of_int (i + 1) else Variable.name b);
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   327
        val constraints = obtains |> map (fn (_, (vars, _)) =>
28710
e2064974c114 Dropped context element 'includes'.
ballarin
parents: 28703
diff changeset
   328
          Element.Constrains
42357
3305f573294e tuned signature, disentangled dependencies;
wenzelm
parents: 42265
diff changeset
   329
            (vars |> map_filter (fn (x, SOME T) => SOME (Variable.name x, T) | _ => NONE)));
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   330
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   331
        val raw_propp = obtains |> map (fn (_, (_, props)) => map (rpair []) props);
28880
f6a547c5dbbf Enable switching to new locales during session.
ballarin
parents: 28877
diff changeset
   332
        val (propp, elems_ctxt) = prep_stmt (elems @ constraints) raw_propp ctxt;
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   333
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   334
        val thesis = Object_Logic.fixed_judgment (Proof_Context.theory_of ctxt) Auto_Bind.thesisN;
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   335
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   336
        fun assume_case ((name, (vars, _)), asms) ctxt' =
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   337
          let
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   338
            val bs = map fst vars;
42357
3305f573294e tuned signature, disentangled dependencies;
wenzelm
parents: 42265
diff changeset
   339
            val xs = map Variable.name bs;
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   340
            val props = map fst asms;
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   341
            val (Ts, _) = ctxt'
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   342
              |> fold Variable.declare_term props
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   343
              |> fold_map Proof_Context.inferred_param xs;
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   344
            val asm = Term.list_all_free (xs ~~ Ts, Logic.list_implies (props, thesis));
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   345
          in
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   346
            ctxt' |> (snd o Proof_Context.add_fixes (map (fn b => (b, NONE, NoSyn)) bs));
21370
d9dd7b4e5e69 replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
wenzelm
parents: 21359
diff changeset
   347
            ctxt' |> Variable.auto_fixes asm
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   348
            |> Proof_Context.add_assms_i Assumption.assume_export
33369
470a7b233ee5 modernized structure Context_Rules;
wenzelm
parents: 33368
diff changeset
   349
              [((name, [Context_Rules.intro_query NONE]), [(asm, [])])]
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   350
            |>> (fn [(_, [th])] => th)
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   351
          end;
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   352
21658
5e31241e1e3c Attrib.internal: morphism;
wenzelm
parents: 21602
diff changeset
   353
        val atts = map (Attrib.internal o K)
33368
b1cf34f1855c modernized structure Rule_Cases;
wenzelm
parents: 33173
diff changeset
   354
          [Rule_Cases.consumes (~ (length obtains)), Rule_Cases.case_names case_names];
30472
9dea0866021c Assumption.local_prems_of;
wenzelm
parents: 30470
diff changeset
   355
        val prems = Assumption.local_prems_of elems_ctxt ctxt;
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28941
diff changeset
   356
        val stmt = [((Binding.empty, atts), [(thesis, [])])];
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   357
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   358
        val (facts, goal_ctxt) = elems_ctxt
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   359
          |> (snd o Proof_Context.add_fixes [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)])
21236
890fafbcf8b0 complex goal statements: misc cleanup;
wenzelm
parents: 21230
diff changeset
   360
          |> fold_map assume_case (obtains ~~ propp)
33644
5266a72e0889 eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
wenzelm
parents: 33519
diff changeset
   361
          |-> (fn ths =>
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   362
            Proof_Context.note_thmss "" [((Binding.name Obtain.thatN, []), [(ths, [])])] #>
33644
5266a72e0889 eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
wenzelm
parents: 33519
diff changeset
   363
            #2 #> pair ths);
32856
92d9555ac790 clarified Proof.refine_insert -- always "refine" to apply standard method treatment (of conjunctions);
wenzelm
parents: 32786
diff changeset
   364
      in ((prems, stmt, SOME facts), goal_ctxt) end);
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   365
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 37145
diff changeset
   366
structure Theorem_Hook = Generic_Data
24452
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
   367
(
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
   368
  type T = ((bool -> Proof.state -> Proof.state) * stamp) list;
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
   369
  val empty = [];
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
   370
  val extend = I;
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 39557
diff changeset
   371
  fun merge data : T = Library.merge (eq_snd op =) data;
24452
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
   372
);
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
   373
36317
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   374
fun gen_theorem schematic prep_att prep_stmt
28858
855e61829e22 removed traces of former 'includes' element;
wenzelm
parents: 28820
diff changeset
   375
    kind before_qed after_qed (name, raw_atts) raw_elems raw_concl int lthy =
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   376
  let
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   377
    val _ = Local_Theory.affirm lthy;
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   378
    val thy = Proof_Context.theory_of lthy;
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   379
21435
883337ea2f3b LocalTheory.axioms/notes/defs: proper kind;
wenzelm
parents: 21370
diff changeset
   380
    val attrib = prep_att thy;
883337ea2f3b LocalTheory.axioms/notes/defs: proper kind;
wenzelm
parents: 21370
diff changeset
   381
    val atts = map attrib raw_atts;
28710
e2064974c114 Dropped context element 'includes'.
ballarin
parents: 28703
diff changeset
   382
    val elems = raw_elems |> map (Element.map_ctxt_attrib attrib);
21450
f16c9e6401d1 theorem(_i): note assms of statement;
wenzelm
parents: 21435
diff changeset
   383
    val ((prems, stmt, facts), goal_ctxt) =
28880
f6a547c5dbbf Enable switching to new locales during session.
ballarin
parents: 28877
diff changeset
   384
      prep_statement attrib prep_stmt elems raw_concl lthy;
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   385
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   386
    fun after_qed' results goal_ctxt' =
21602
cb13024d0e36 Goal.norm/close_result;
wenzelm
parents: 21532
diff changeset
   387
      let val results' =
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   388
        burrow (map Goal.norm_result o Proof_Context.export goal_ctxt' lthy) results
21602
cb13024d0e36 Goal.norm/close_result;
wenzelm
parents: 21532
diff changeset
   389
      in
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   390
        lthy
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   391
        |> Local_Theory.notes_kind kind
33670
02b7738aef6a eliminated slightly odd kind argument of LocalTheory.note(s);
wenzelm
parents: 33644
diff changeset
   392
          (map2 (fn (a, _) => fn ths => (a, [(ths, [])])) stmt results')
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   393
        |> (fn (res, lthy') =>
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28941
diff changeset
   394
          if Binding.is_empty name andalso null atts then
33389
bb3a5fa94a91 modernized structure Proof_Display;
wenzelm
parents: 33386
diff changeset
   395
            (Proof_Display.print_results true lthy' ((kind, ""), res); lthy')
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   396
          else
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   397
            let
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   398
              val ([(res_name, _)], lthy'') = lthy'
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33670
diff changeset
   399
                |> Local_Theory.notes_kind kind [((name, atts), [(maps #2 res, [])])];
33389
bb3a5fa94a91 modernized structure Proof_Display;
wenzelm
parents: 33386
diff changeset
   400
              val _ = Proof_Display.print_results true lthy' ((kind, res_name), res);
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27858
diff changeset
   401
            in lthy'' end)
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   402
        |> after_qed results'
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   403
      end;
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   404
  in
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   405
    goal_ctxt
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   406
    |> Proof_Context.note_thmss "" [((Binding.name Auto_Bind.assmsN, []), [(prems, [])])]
21450
f16c9e6401d1 theorem(_i): note assms of statement;
wenzelm
parents: 21435
diff changeset
   407
    |> snd
36323
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 36317
diff changeset
   408
    |> Proof.theorem before_qed after_qed' (map snd stmt)
32856
92d9555ac790 clarified Proof.refine_insert -- always "refine" to apply standard method treatment (of conjunctions);
wenzelm
parents: 32786
diff changeset
   409
    |> (case facts of NONE => I | SOME ths => Proof.refine_insert ths)
36317
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   410
    |> tap (fn state => not schematic andalso Proof.schematic_goal state andalso
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   411
        error "Illegal schematic goal statement")
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 37145
diff changeset
   412
    |> Library.apply (map (fn (f, _) => f int) (rev (Theorem_Hook.get (Context.Proof goal_ctxt))))
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   413
  end;
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   414
21230
abfdce60b371 theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents: 21206
diff changeset
   415
in
abfdce60b371 theorem statements: incorporate Obtain.statement, tuned;
wenzelm
parents: 21206
diff changeset
   416
36317
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   417
val theorem = gen_theorem false (K I) Expression.cert_statement;
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   418
val theorem_cmd = gen_theorem false Attrib.intern_src Expression.read_statement;
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   419
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   420
val schematic_theorem = gen_theorem true (K I) Expression.cert_statement;
506d732cb522 explicit 'schematic_theorem' etc. for schematic theorem statements;
wenzelm
parents: 36106
diff changeset
   421
val schematic_theorem_cmd = gen_theorem true Attrib.intern_src Expression.read_statement;
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   422
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 37145
diff changeset
   423
fun add_theorem_hook f = Theorem_Hook.map (cons (f, stamp ()));
24452
93b113c5ac33 - theorem(_i) now also takes "interactive" flag as argument
berghofe
parents: 24219
diff changeset
   424
18620
fc8b5f275359 Theory specifications --- with type-inference, but no internal polymorphism.
wenzelm
parents:
diff changeset
   425
end;
21036
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   426
0eed532acfca added theorem(_i);
wenzelm
parents: 20914
diff changeset
   427
end;