src/Pure/assumption.ML
author wenzelm
Tue, 31 Dec 2013 14:29:16 +0100
changeset 54883 dd04a8b654fc
parent 54740 91f54d386680
child 54984 da70ab8531f4
permissions -rw-r--r--
proper context for norm_hhf and derived operations; clarified tool context in some boundary cases;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/assumption.ML
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     3
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
     4
Context assumptions, parameterized by export rules.
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     5
*)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     6
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     7
signature ASSUMPTION =
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     8
sig
35716
9dd4747d9591 tuned signature;
wenzelm
parents: 33957
diff changeset
     9
  type export = bool -> cterm list -> (thm -> thm) * (term -> term)
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    10
  val assume_export: export
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    11
  val presume_export: export
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
    12
  val assume: Proof.context -> cterm -> thm
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    13
  val all_assms_of: Proof.context -> cterm list
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    14
  val all_prems_of: Proof.context -> thm list
54567
cfe53047dc16 more uniform / rigid checking of Goal.prove_common vs. Proof.conclude_goal -- NB: Goal.prove_common cannot check hyps right now, e.g. due to undeclared Simplifier prems;
wenzelm
parents: 47236
diff changeset
    15
  val check_hyps: Proof.context -> thm -> thm
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    16
  val local_assms_of: Proof.context -> Proof.context -> cterm list
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    17
  val local_prems_of: Proof.context -> Proof.context -> thm list
20296
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    18
  val add_assms: export -> cterm list -> Proof.context -> thm list * Proof.context
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    19
  val add_assumes: cterm list -> Proof.context -> thm list * Proof.context
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    20
  val export: bool -> Proof.context -> Proof.context -> thm -> thm
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    21
  val export_term: Proof.context -> Proof.context -> term -> term
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
    22
  val export_morphism: Proof.context -> Proof.context -> morphism
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    23
end;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    24
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    25
structure Assumption: ASSUMPTION =
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    26
struct
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    27
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    28
(** basic rules **)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    29
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    30
type export = bool -> cterm list -> (thm -> thm) * (term -> term);
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    31
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    32
(*
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    33
    [A]
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    34
     :
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    35
     B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    36
  --------
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    37
  #A ==> B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    38
*)
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    39
fun assume_export is_goal asms =
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    40
  (if is_goal then Drule.implies_intr_protected asms else Drule.implies_intr_list asms, fn t => t);
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    41
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    42
(*
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    43
    [A]
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    44
     :
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    45
     B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    46
  -------
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    47
  A ==> B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    48
*)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    49
fun presume_export _ = assume_export false;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    50
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
    51
fun assume ctxt = Raw_Simplifier.norm_hhf ctxt o Thm.assume;
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    52
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    53
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    54
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    55
(** local context data **)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    56
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    57
datatype data = Data of
30479
wenzelm
parents: 30471
diff changeset
    58
 {assms: (export * cterm list) list,    (*assumes: A ==> _*)
47236
973ab740a25d tuned comment;
wenzelm
parents: 46493
diff changeset
    59
  prems: thm list};                     (*prems: A |- norm_hhf A*)
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    60
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    61
fun make_data (assms, prems) = Data {assms = assms, prems = prems};
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    62
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 30479
diff changeset
    63
structure Data = Proof_Data
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    64
(
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    65
  type T = data;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    66
  fun init _ = make_data ([], []);
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    67
);
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    68
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    69
fun map_data f = Data.map (fn Data {assms, prems} => make_data (f (assms, prems)));
45650
wenzelm
parents: 45289
diff changeset
    70
fun rep_data ctxt = Data.get ctxt |> (fn Data rep => rep);
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    71
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    72
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    73
(* all assumptions *)
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    74
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    75
val all_assumptions_of = #assms o rep_data;
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    76
val all_assms_of = maps #2 o all_assumptions_of;
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    77
val all_prems_of = #prems o rep_data;
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    78
54567
cfe53047dc16 more uniform / rigid checking of Goal.prove_common vs. Proof.conclude_goal -- NB: Goal.prove_common cannot check hyps right now, e.g. due to undeclared Simplifier prems;
wenzelm
parents: 47236
diff changeset
    79
fun check_hyps ctxt th =
cfe53047dc16 more uniform / rigid checking of Goal.prove_common vs. Proof.conclude_goal -- NB: Goal.prove_common cannot check hyps right now, e.g. due to undeclared Simplifier prems;
wenzelm
parents: 47236
diff changeset
    80
  let
cfe53047dc16 more uniform / rigid checking of Goal.prove_common vs. Proof.conclude_goal -- NB: Goal.prove_common cannot check hyps right now, e.g. due to undeclared Simplifier prems;
wenzelm
parents: 47236
diff changeset
    81
    val extra_hyps = subtract (op aconv) (map Thm.term_of (all_assms_of ctxt)) (Thm.hyps_of th);
cfe53047dc16 more uniform / rigid checking of Goal.prove_common vs. Proof.conclude_goal -- NB: Goal.prove_common cannot check hyps right now, e.g. due to undeclared Simplifier prems;
wenzelm
parents: 47236
diff changeset
    82
    val _ = null extra_hyps orelse
cfe53047dc16 more uniform / rigid checking of Goal.prove_common vs. Proof.conclude_goal -- NB: Goal.prove_common cannot check hyps right now, e.g. due to undeclared Simplifier prems;
wenzelm
parents: 47236
diff changeset
    83
      error ("Additional hypotheses:\n" ^ cat_lines (map (Syntax.string_of_term ctxt) extra_hyps));
cfe53047dc16 more uniform / rigid checking of Goal.prove_common vs. Proof.conclude_goal -- NB: Goal.prove_common cannot check hyps right now, e.g. due to undeclared Simplifier prems;
wenzelm
parents: 47236
diff changeset
    84
  in th end;
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    85
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    86
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    87
(* local assumptions *)
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    88
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    89
fun local_assumptions_of inner outer =
33957
e9afca2118d4 normalized uncurry take/drop
haftmann
parents: 33955
diff changeset
    90
  drop (length (all_assumptions_of outer)) (all_assumptions_of inner);
26392
748b263f0e40 setup for dynamic "prems" (legacy);
wenzelm
parents: 22846
diff changeset
    91
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    92
val local_assms_of = maps #2 oo local_assumptions_of;
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    93
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
    94
fun local_prems_of inner outer =
33957
e9afca2118d4 normalized uncurry take/drop
haftmann
parents: 33955
diff changeset
    95
  drop (length (all_prems_of outer)) (all_prems_of inner);
26392
748b263f0e40 setup for dynamic "prems" (legacy);
wenzelm
parents: 22846
diff changeset
    96
748b263f0e40 setup for dynamic "prems" (legacy);
wenzelm
parents: 22846
diff changeset
    97
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    98
(* add assumptions *)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    99
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
   100
fun add_assms export new_asms ctxt =
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
   101
  let val new_prems = map (assume ctxt) new_asms in
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
   102
    ctxt
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
   103
    |> map_data (fn (asms, prems) => (asms @ [(export, new_asms)], prems @ new_prems))
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
   104
    |> pair new_prems
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   105
  end;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   106
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   107
val add_assumes = add_assms assume_export;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   108
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   109
20296
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
   110
(* export *)
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   111
20296
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
   112
fun export is_goal inner outer =
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
   113
  Raw_Simplifier.norm_hhf_protect inner #>
30479
wenzelm
parents: 30471
diff changeset
   114
  fold_rev (fn (e, As) => #1 (e is_goal As)) (local_assumptions_of inner outer) #>
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54740
diff changeset
   115
  Raw_Simplifier.norm_hhf_protect outer;
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   116
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   117
fun export_term inner outer =
30471
178de3995e91 renamed assms_of to all_assms_of, and prems_of to all_prems_of;
wenzelm
parents: 29605
diff changeset
   118
  fold_rev (fn (e, As) => #2 (e false As)) (local_assumptions_of inner outer);
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   119
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   120
fun export_morphism inner outer =
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   121
  let
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   122
    val thm = export false inner outer;
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   123
    val term = export_term inner outer;
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   124
    val typ = Logic.type_map term;
54740
91f54d386680 maintain morphism names for diagnostic purposes;
wenzelm
parents: 54567
diff changeset
   125
  in
91f54d386680 maintain morphism names for diagnostic purposes;
wenzelm
parents: 54567
diff changeset
   126
    Morphism.morphism "Assumption.export"
91f54d386680 maintain morphism names for diagnostic purposes;
wenzelm
parents: 54567
diff changeset
   127
      {binding = [], typ = [typ], term = [term], fact = [map thm]}
91f54d386680 maintain morphism names for diagnostic purposes;
wenzelm
parents: 54567
diff changeset
   128
  end;
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   129
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   130
end;