src/Pure/Isar/interpretation.ML
author haftmann
Wed, 02 Dec 2015 19:14:57 +0100
changeset 61775 ec11275fb263
parent 61774 029162bc9793
child 61823 5daa82ba4078
permissions -rw-r--r--
alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     1
(*  Title:      Pure/Isar/interpretation.ML
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     2
    Author:     Clemens Ballarin, TU Muenchen
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     4
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     5
Locale interpretation.
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     6
*)
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     7
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     8
signature INTERPRETATION =
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
     9
sig
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    10
  type 'a defines = (Attrib.binding * ((binding * mixfix) * 'a)) list
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    11
  type 'a rewrites = (Attrib.binding * 'a) list
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    12
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    13
  (*interpretation in proofs*)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    14
  val interpret: Expression.expression_i -> term rewrites -> bool -> Proof.state -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    15
  val interpret_cmd: Expression.expression -> string rewrites -> bool -> Proof.state -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    16
61771
acc532690ee1 tuned whitespace
haftmann
parents: 61708
diff changeset
    17
  (*algebraic view*)
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    18
  val global_interpretation: Expression.expression_i ->
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    19
    term defines -> term rewrites -> theory -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    20
  val global_sublocale: string -> Expression.expression_i ->
61676
872b2ee75359 tuned whitespace
haftmann
parents: 61673
diff changeset
    21
    term defines -> term rewrites -> theory -> Proof.state
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    22
  val global_sublocale_cmd: xstring * Position.T -> Expression.expression ->
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    23
    string defines -> string rewrites -> theory -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    24
  val sublocale: Expression.expression_i ->
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    25
    term defines -> term rewrites -> local_theory -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    26
  val sublocale_cmd: Expression.expression ->
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    27
    string defines -> string rewrites -> local_theory -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    28
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    29
  (*local-theory-based view*)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    30
  val ephemeral_interpretation: Expression.expression_i ->
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    31
    term rewrites -> local_theory -> Proof.state
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
    32
  val permanent_interpretation: Expression.expression_i ->
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    33
    term defines -> term rewrites -> local_theory -> Proof.state
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
    34
  val permanent_interpretation_cmd: Expression.expression ->
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    35
    string defines -> string rewrites -> local_theory -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    36
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    37
  (*mixed Isar interface*)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    38
  val interpretation: Expression.expression_i -> term rewrites -> local_theory -> Proof.state
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    39
  val interpretation_cmd: Expression.expression -> string rewrites ->
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
    40
    local_theory -> Proof.state
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    41
end;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    42
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    43
structure Interpretation : INTERPRETATION =
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    44
struct
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    45
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    46
(** common interpretation machinery **)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    47
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    48
type 'a defines = (Attrib.binding * ((binding * mixfix) * 'a)) list
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    49
type 'a rewrites = (Attrib.binding * 'a) list
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    50
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
    51
(* reading of locale expressions with rewrite morphisms *)
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
    52
61672
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
    53
local
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    54
61775
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    55
fun augment_with_def prep_term deps ((name, atts), ((b, mx), raw_rhs)) lthy =
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
    56
  let
61775
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    57
    val rhs = prep_term lthy raw_rhs;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    58
    val lthy' = Variable.declare_term rhs lthy;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    59
    val ((_, (_, def)), lthy'') =
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    60
      Local_Theory.define ((b, mx), ((Thm.def_binding_optional b name, atts), rhs)) lthy';
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    61
  in (def, lthy'') end;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    62
61775
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    63
fun augment_with_defs prep_term [] deps ctxt = ([], ctxt)
61691
91854ba66adb clarified contexts by factoring out reading and definition of mixins
haftmann
parents: 61684
diff changeset
    64
      (*quasi-inhomogeneous type: definitions demand local theory rather than bare proof context*)
61775
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    65
  | augment_with_defs prep_term raw_defs deps lthy =
61691
91854ba66adb clarified contexts by factoring out reading and definition of mixins
haftmann
parents: 61684
diff changeset
    66
      let
61775
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    67
        val (_, inner_lthy) =
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    68
          Local_Theory.open_target lthy
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    69
          ||> fold Locale.activate_declarations deps;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    70
        val (inner_defs, inner_lthy') =
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    71
          fold_map (augment_with_def prep_term deps) raw_defs inner_lthy;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    72
        val lthy' =
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    73
          inner_lthy'
61708
4de2380ae3ab explicit nested local theory for definitions, however retaining arcane low-level fiddling with background theory
haftmann
parents: 61698
diff changeset
    74
          |> Local_Theory.close_target;
4de2380ae3ab explicit nested local theory for definitions, however retaining arcane low-level fiddling with background theory
haftmann
parents: 61698
diff changeset
    75
        val def_eqns =
61775
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    76
          map (singleton (Proof_Context.export inner_lthy' lthy') o Thm.symmetric) inner_defs
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    77
      in (def_eqns, lthy') end;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    78
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    79
fun prep_eqns prep_props prep_attr [] deps ctxt = ([], [])
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    80
  | prep_eqns prep_props prep_attr raw_eqns deps ctxt =
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    81
      let
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    82
        val ctxt' = fold Locale.activate_declarations deps ctxt;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    83
        val eqns =
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    84
          (Variable.export_terms ctxt' ctxt o prep_props ctxt' o map snd) raw_eqns;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    85
        val attrss = map (apsnd (map (prep_attr ctxt)) o fst) raw_eqns;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    86
      in (eqns, attrss) end;
61691
91854ba66adb clarified contexts by factoring out reading and definition of mixins
haftmann
parents: 61684
diff changeset
    87
61774
029162bc9793 prefer conventional read/check distinction over manual check
haftmann
parents: 61773
diff changeset
    88
fun prep_interpretation prep_expr prep_term prep_props prep_attr
61691
91854ba66adb clarified contexts by factoring out reading and definition of mixins
haftmann
parents: 61684
diff changeset
    89
  expression raw_defs raw_eqns initial_ctxt =
91854ba66adb clarified contexts by factoring out reading and definition of mixins
haftmann
parents: 61684
diff changeset
    90
  let
91854ba66adb clarified contexts by factoring out reading and definition of mixins
haftmann
parents: 61684
diff changeset
    91
    val ((propss, deps, export), expr_ctxt) = prep_expr expression initial_ctxt;
61775
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    92
    val (def_eqns, def_ctxt) =
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    93
      augment_with_defs prep_term raw_defs deps expr_ctxt;
ec11275fb263 alternating parsing and defining of rewrite definitions: formally correct treatment of polymorphism
haftmann
parents: 61774
diff changeset
    94
    val (eqns, attrss) = prep_eqns prep_props prep_attr raw_eqns deps def_ctxt;
61672
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
    95
    val goal_ctxt = fold Variable.auto_fixes eqns def_ctxt;
61772
2f33f6cc964d formally correct context for export, which got screwed up in 87203a0f0041
haftmann
parents: 61771
diff changeset
    96
    val export' = Variable.export_morphism goal_ctxt expr_ctxt;
61672
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
    97
  in (((propss, deps, export, export'), (def_eqns, eqns, attrss)), goal_ctxt) end;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
    98
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
    99
in
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   100
61698
c4a6edbfec49 make SML/NJ happy;
wenzelm
parents: 61691
diff changeset
   101
fun cert_interpretation expression =
61774
029162bc9793 prefer conventional read/check distinction over manual check
haftmann
parents: 61773
diff changeset
   102
  prep_interpretation Expression.cert_goal_expression Syntax.check_term
029162bc9793 prefer conventional read/check distinction over manual check
haftmann
parents: 61773
diff changeset
   103
    Syntax.check_props (K I) expression;
61672
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   104
61698
c4a6edbfec49 make SML/NJ happy;
wenzelm
parents: 61691
diff changeset
   105
fun read_interpretation expression =
61774
029162bc9793 prefer conventional read/check distinction over manual check
haftmann
parents: 61773
diff changeset
   106
  prep_interpretation Expression.read_goal_expression Syntax.read_term
029162bc9793 prefer conventional read/check distinction over manual check
haftmann
parents: 61773
diff changeset
   107
    Syntax.read_props Attrib.check_src expression;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   108
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   109
end;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   110
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   111
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   112
(* interpretation machinery *)
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   113
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   114
local
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   115
61672
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   116
fun meta_rewrite eqns ctxt =
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   117
  (map (Local_Defs.meta_rewrite_rule ctxt #> Drule.abs_def) (maps snd eqns), ctxt);
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   118
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   119
fun note_eqns_register note activate deps witss def_eqns eqns attrss export export' ctxt =
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   120
  let
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   121
    val facts = (Attrib.empty_binding, [(map (Morphism.thm (export' $> export)) def_eqns, [])])
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   122
      :: map2 (fn attrs => fn eqn => (attrs, [([Morphism.thm (export' $> export) eqn], [])])) attrss eqns;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   123
    val (eqns', ctxt') = ctxt
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   124
      |> note Thm.theoremK facts
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   125
      |-> meta_rewrite;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   126
    val dep_morphs = map2 (fn (dep, morph) => fn wits =>
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   127
      (dep, morph $> Element.satisfy_morphism (map (Element.transform_witness export') wits))) deps witss;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   128
    fun activate' dep_morph ctxt = activate dep_morph
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   129
      (Option.map (rpair true) (Element.eq_morphism (Proof_Context.theory_of ctxt) eqns')) export ctxt;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   130
  in
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   131
    ctxt'
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   132
    |> fold activate' dep_morphs
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   133
  end;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   134
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   135
in
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   136
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   137
fun generic_interpretation_with_defs prep_interpretation setup_proof note add_registration
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   138
    expression raw_defs raw_eqns initial_ctxt =
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   139
  let
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   140
    val (((propss, deps, export, export'), (def_eqns, eqns, attrss)), goal_ctxt) =
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   141
      prep_interpretation expression raw_defs raw_eqns initial_ctxt;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   142
    fun after_qed witss eqns =
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   143
      note_eqns_register note add_registration deps witss def_eqns eqns attrss export export';
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   144
  in setup_proof after_qed propss eqns goal_ctxt end;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   145
61672
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   146
fun generic_interpretation prep_interpretation setup_proof note add_registration expression =
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   147
  generic_interpretation_with_defs prep_interpretation setup_proof note add_registration expression [];
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   148
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   149
end;
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   150
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   151
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   152
(** interfaces **)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   153
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   154
(* interpretation in proofs *)
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   155
61672
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   156
local
87203a0f0041 tuned -- share implementations as far as appropriate
haftmann
parents: 61670
diff changeset
   157
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   158
fun gen_interpret prep_interpretation expression raw_eqns int state =
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   159
  let
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   160
    val _ = Proof.assert_forward_or_chain state;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   161
    val ctxt = Proof.context_of state;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   162
    fun lift_after_qed after_qed witss eqns =
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   163
      Proof.map_context (after_qed witss eqns) #> Proof.reset_facts;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   164
    fun setup_proof after_qed propss eqns goal_ctxt =
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   165
      Element.witness_local_proof_eqs (lift_after_qed after_qed) "interpret"
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   166
        propss eqns goal_ctxt int state;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   167
  in
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   168
    generic_interpretation prep_interpretation setup_proof
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   169
      Attrib.local_notes (Context.proof_map ooo Locale.add_registration) expression raw_eqns ctxt
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   170
  end;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   171
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   172
in
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   173
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   174
fun interpret expression = gen_interpret cert_interpretation expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   175
fun interpret_cmd raw_expression = gen_interpret read_interpretation raw_expression;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   176
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   177
end;
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   178
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   179
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   180
(* algebraic-view *)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   181
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   182
local
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   183
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   184
fun gen_global_interpretation prep_interpretation expression
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   185
    raw_defs raw_eqns thy = 
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   186
  let
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   187
    val lthy = Named_Target.theory_init thy;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   188
    fun setup_proof after_qed =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   189
      Element.witness_proof_eqs
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   190
        (fn wits => fn eqs => after_qed wits eqs #> Local_Theory.exit);
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   191
  in
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   192
    lthy |>
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   193
      generic_interpretation_with_defs prep_interpretation setup_proof
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   194
        Local_Theory.notes_kind Local_Theory.subscription expression raw_defs raw_eqns
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   195
  end;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   196
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   197
fun gen_global_sublocale prep_loc prep_interpretation
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   198
    raw_locale expression raw_defs raw_eqns thy =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   199
  let
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   200
    val lthy = Named_Target.init (prep_loc thy raw_locale) thy;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   201
    fun setup_proof after_qed =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   202
      Element.witness_proof_eqs
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   203
        (fn wits => fn eqs => after_qed wits eqs #> Local_Theory.exit);
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   204
  in
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   205
    lthy |>
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   206
      generic_interpretation_with_defs prep_interpretation setup_proof
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   207
        Local_Theory.notes_kind Local_Theory.subscription expression raw_defs raw_eqns
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   208
  end;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   209
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   210
fun subscribe_locale_only lthy =
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   211
  let
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   212
    val _ =
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   213
      if Named_Target.is_theory lthy
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   214
      then error "Not possible on level of global theory"
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   215
      else ();
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   216
  in Local_Theory.subscription end;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   217
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   218
fun gen_sublocale prep_interpretation expression raw_defs raw_eqns lthy =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   219
  generic_interpretation_with_defs prep_interpretation Element.witness_proof_eqs
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   220
    Local_Theory.notes_kind (subscribe_locale_only lthy) expression raw_defs raw_eqns lthy;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   221
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   222
in
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   223
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   224
fun global_interpretation expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   225
  gen_global_interpretation cert_interpretation expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   226
fun global_sublocale expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   227
  gen_global_sublocale (K I) cert_interpretation expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   228
fun global_sublocale_cmd raw_expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   229
  gen_global_sublocale Locale.check read_interpretation raw_expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   230
fun sublocale expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   231
  gen_sublocale cert_interpretation expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   232
fun sublocale_cmd raw_expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   233
  gen_sublocale read_interpretation raw_expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   234
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   235
end;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   236
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   237
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   238
(* local-theory-based view *)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   239
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   240
local
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   241
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   242
fun gen_permanent_interpretation prep_interpretation expression raw_defs raw_eqns =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   243
  Local_Theory.assert_bottom true
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   244
  #> generic_interpretation_with_defs prep_interpretation Element.witness_proof_eqs
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   245
    Local_Theory.notes_kind Local_Theory.subscription expression raw_defs raw_eqns
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   246
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   247
in
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   248
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   249
fun ephemeral_interpretation expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   250
  generic_interpretation cert_interpretation Element.witness_proof_eqs
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   251
    Local_Theory.notes_kind Locale.activate_fragment expression;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   252
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   253
fun permanent_interpretation expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   254
  gen_permanent_interpretation cert_interpretation expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   255
fun permanent_interpretation_cmd raw_expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   256
  gen_permanent_interpretation read_interpretation raw_expression;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   257
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   258
end;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   259
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   260
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   261
(* mixed Isar interface *)
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   262
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   263
local
61670
301e0b4ecd45 coalesce permanent_interpretation.ML with interpretation.ML
haftmann
parents: 61669
diff changeset
   264
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   265
fun subscribe_or_activate lthy =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   266
  if Named_Target.is_theory lthy
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   267
  then Local_Theory.subscription
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   268
  else Locale.activate_fragment;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   269
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   270
fun gen_local_theory_interpretation prep_interpretation expression raw_eqns lthy =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   271
  generic_interpretation prep_interpretation Element.witness_proof_eqs
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   272
    Local_Theory.notes_kind (subscribe_or_activate lthy) expression raw_eqns lthy;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   273
61673
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   274
in
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   275
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   276
fun interpretation expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   277
  gen_local_theory_interpretation cert_interpretation expression;
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   278
fun interpretation_cmd raw_expression =
fd4ac1530d63 represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents: 61672
diff changeset
   279
  gen_local_theory_interpretation read_interpretation raw_expression;
61669
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   280
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   281
end;
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   282
27ca6147e3b3 separate ML module for interpretation
haftmann
parents:
diff changeset
   283
end;