src/Pure/assumption.ML
author wenzelm
Wed, 21 Jan 2009 22:26:49 +0100
changeset 29605 f2924219125e
parent 29579 cb520b766e00
child 30471 178de3995e91
permissions -rw-r--r--
eliminated obsolete var morphism;
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
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     4
Local assumptions, parameterized by export rules.
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
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
     9
  type export
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
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    12
  val assume: cterm -> thm
21577
3ff126ca39b4 assms_of: cterm;
wenzelm
parents: 21517
diff changeset
    13
  val assms_of: Proof.context -> cterm list
20296
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    14
  val prems_of: Proof.context -> thm list
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    15
  val extra_hyps: Proof.context -> thm -> term list
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    16
  val add_assms: export -> cterm list -> Proof.context -> thm list * Proof.context
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    17
  val add_assumes: cterm list -> Proof.context -> thm list * Proof.context
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    18
  val add_view: Proof.context -> cterm list -> Proof.context -> Proof.context
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
    19
  val export: bool -> Proof.context -> Proof.context -> thm -> thm
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    20
  val export_term: Proof.context -> Proof.context -> term -> term
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
    21
  val export_morphism: Proof.context -> Proof.context -> morphism
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    22
end;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    23
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    24
structure Assumption: ASSUMPTION =
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    25
struct
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    26
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    27
(** basic rules **)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    28
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    29
type export = bool -> cterm list -> (thm -> thm) * (term -> term);
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    30
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    31
(*
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    32
    [A]
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    33
     :
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    34
     B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    35
  --------
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    36
  #A ==> B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    37
*)
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    38
fun assume_export is_goal asms =
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    39
  (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
    40
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    41
(*
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    42
    [A]
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    43
     :
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    44
     B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    45
  -------
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    46
  A ==> B
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    47
*)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    48
fun presume_export _ = assume_export false;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    49
21605
4e7307e229b3 qualified MetaSimplifier.norm_hhf(_protect);
wenzelm
parents: 21577
diff changeset
    50
val assume = MetaSimplifier.norm_hhf o Thm.assume;
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    51
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
(** local context data **)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    55
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    56
datatype data = Data of
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    57
 {assms: (export * cterm list) list,    (*assumes and views: A ==> _*)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    58
  prems: thm list};                     (*prems: A |- A*)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    59
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    60
fun make_data (assms, prems) = Data {assms = assms, prems = prems};
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    61
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    62
structure Data = ProofDataFun
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    63
(
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    64
  type T = data;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    65
  fun init _ = make_data ([], []);
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    66
);
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    67
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    68
fun map_data f = Data.map (fn Data {assms, prems} => make_data (f (assms, prems)));
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    69
fun rep_data ctxt = Data.get ctxt |> (fn Data args => args);
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    70
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    71
val assumptions_of = #assms o rep_data;
21577
3ff126ca39b4 assms_of: cterm;
wenzelm
parents: 21517
diff changeset
    72
val assms_of = maps #2 o assumptions_of;
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    73
val prems_of = #prems o rep_data;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    74
21577
3ff126ca39b4 assms_of: cterm;
wenzelm
parents: 21517
diff changeset
    75
fun extra_hyps ctxt th = subtract (op aconv) (map Thm.term_of (assms_of ctxt)) (Thm.hyps_of th);
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    76
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    77
26392
748b263f0e40 setup for dynamic "prems" (legacy);
wenzelm
parents: 22846
diff changeset
    78
(* named prems -- legacy feature *)
748b263f0e40 setup for dynamic "prems" (legacy);
wenzelm
parents: 22846
diff changeset
    79
26435
bdce320cd426 eliminated delayed theory setup
wenzelm
parents: 26392
diff changeset
    80
val _ = Context.>>
29579
cb520b766e00 binding replaces bstring
haftmann
parents: 28965
diff changeset
    81
  (Context.map_theory (PureThy.add_thms_dynamic (Binding.name "prems",
26463
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
    82
    fn Context.Theory _ => [] | Context.Proof ctxt => prems_of ctxt)));
26392
748b263f0e40 setup for dynamic "prems" (legacy);
wenzelm
parents: 22846
diff changeset
    83
748b263f0e40 setup for dynamic "prems" (legacy);
wenzelm
parents: 22846
diff changeset
    84
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    85
(* add assumptions *)
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    86
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    87
fun add_assms export new_asms =
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    88
  let val new_prems = map assume new_asms in
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    89
    map_data (fn (asms, prems) => (asms @ [(export, new_asms)], prems @ new_prems)) #>
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    90
    pair new_prems
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    91
  end;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    92
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    93
val add_assumes = add_assms assume_export;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    94
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    95
fun add_view outer view = map_data (fn (asms, prems) =>
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    96
  let
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    97
    val (asms1, asms2) = chop (length (assumptions_of outer)) asms;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    98
    val asms' = asms1 @ [(assume_export, view)] @ asms2;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
    99
  in (asms', prems) end);
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   100
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   101
20296
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
   102
(* export *)
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   103
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   104
fun diff_assms inner outer =
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   105
  Library.drop (length (assumptions_of outer), assumptions_of inner);
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   106
20296
753fad9f6e03 simplified export: no Seq.seq;
wenzelm
parents: 20222
diff changeset
   107
fun export is_goal inner outer =
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   108
  let val asms = diff_assms inner outer in
21605
4e7307e229b3 qualified MetaSimplifier.norm_hhf(_protect);
wenzelm
parents: 21577
diff changeset
   109
    MetaSimplifier.norm_hhf_protect
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   110
    #> fold_rev (fn (e, As) => #1 (e is_goal As)) asms
21605
4e7307e229b3 qualified MetaSimplifier.norm_hhf(_protect);
wenzelm
parents: 21577
diff changeset
   111
    #> MetaSimplifier.norm_hhf_protect
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   112
  end;
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   113
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   114
fun export_term inner outer =
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   115
  fold_rev (fn (e, As) => #2 (e false As)) (diff_assms inner outer);
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   116
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   117
fun export_morphism inner outer =
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   118
  let
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   119
    val thm = export false inner outer;
21679
06715e253686 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
   120
    val term = export_term inner outer;
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   121
    val typ = Logic.type_map term;
29605
f2924219125e eliminated obsolete var morphism;
wenzelm
parents: 29579
diff changeset
   122
  in Morphism.morphism {binding = I, typ = typ, term = term, fact = map thm} end;
21517
b165c9120702 added export_morphism;
wenzelm
parents: 20296
diff changeset
   123
20222
e2b876cd9e29 Local assumptions, parameterized by export rules.
wenzelm
parents:
diff changeset
   124
end;