src/Pure/Isar/obtain.ML
author wenzelm
Wed, 10 Jun 2015 14:46:31 +0200
changeset 60414 f25f2f2ba48c
parent 60408 1fd46ced2fa8
child 60415 9d37b2330ee3
permissions -rw-r--r--
support for "if prems" in local goal statements;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/obtain.ML
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
     3
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
     4
The 'obtain' and 'guess' language elements -- generalized existence at
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
     5
the level of proof texts: 'obtain' involves a proof that certain
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
     6
fixes/assumes may be introduced into the present context; 'guess' is
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
     7
similar, but derives these elements from the course of reasoning!
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
     8
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
     9
  <chain_facts>
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    10
  obtain x where "A x" <proof> ==
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    11
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    12
  have "!!thesis. (!!x. A x ==> thesis) ==> thesis"
12970
c9b1838a2cc0 improved messages;
wenzelm
parents: 12404
diff changeset
    13
  proof succeed
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
    14
    fix thesis
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    15
    assume that [intro?]: "!!x. A x ==> thesis"
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    16
    <chain_facts>
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    17
    show thesis
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    18
      apply (insert that)
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    19
      <proof>
12970
c9b1838a2cc0 improved messages;
wenzelm
parents: 12404
diff changeset
    20
  qed
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    21
  fix x assm <<obtain_export>> "A x"
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    22
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    23
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    24
  <chain_facts>
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    25
  guess x <proof body> <proof end> ==
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    26
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    27
  {
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    28
    fix thesis
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    29
    <chain_facts> have "PROP ?guess"
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    30
      apply magic      -- {* turns goal into "thesis ==> #thesis" *}
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    31
      <proof body>
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    32
      apply_end magic  -- {* turns final "(!!x. P x ==> thesis) ==> #thesis" into
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    33
        "#((!!x. A x ==> thesis) ==> thesis)" which is a finished goal state *}
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    34
      <proof end>
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    35
  }
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    36
  fix x assm <<obtain_export>> "A x"
8094
62b45a2e6ecb ObtainFun;
wenzelm
parents: 7923
diff changeset
    37
*)
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    38
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    39
signature OBTAIN =
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    40
sig
21229
9c96c1ec235f moved statement to specification.ML;
wenzelm
parents: 20804
diff changeset
    41
  val thatN: string
36323
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
    42
  val obtain: string -> (binding * typ option * mixfix) list ->
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
    43
    (Thm.binding * (term * term list) list) list -> bool -> Proof.state -> Proof.state
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
    44
  val obtain_cmd: string -> (binding * string option * mixfix) list ->
30211
556d1810cdad Thm.binding;
wenzelm
parents: 29581
diff changeset
    45
    (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    46
  val result: (Proof.context -> tactic) -> thm list -> Proof.context ->
32199
82c4c570310a Variable.focus: named parameters;
wenzelm
parents: 32091
diff changeset
    47
    ((string * cterm) list * thm list) * Proof.context
36323
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
    48
  val guess: (binding * typ option * mixfix) list -> bool -> Proof.state -> Proof.state
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
    49
  val guess_cmd: (binding * string option * mixfix) list -> bool -> Proof.state -> Proof.state
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    50
end;
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    51
10379
93630e0c5ae9 improved handling of "that": insert into goal, only declare as Pure "intro";
wenzelm
parents: 9481
diff changeset
    52
structure Obtain: OBTAIN =
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    53
struct
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
    54
18670
c3f445b92aff uniform handling of fixes;
wenzelm
parents: 18643
diff changeset
    55
(** obtain_export **)
c3f445b92aff uniform handling of fixes;
wenzelm
parents: 18643
diff changeset
    56
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    57
(*
18897
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
    58
  [x, A x]
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
    59
     :
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
    60
     B
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
    61
  --------
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
    62
     B
18870
020e242c02a0 tuned comments;
wenzelm
parents: 18769
diff changeset
    63
*)
21686
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    64
fun eliminate_term ctxt xs tm =
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    65
  let
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    66
    val vs = map (dest_Free o Thm.term_of) xs;
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    67
    val bads = Term.fold_aterms (fn t as Free v =>
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    68
      if member (op =) vs v then insert (op aconv) t else I | _ => I) tm [];
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    69
    val _ = null bads orelse
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    70
      error ("Result contains obtained parameters: " ^
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 22568
diff changeset
    71
        space_implode " " (map (Syntax.string_of_term ctxt) bads));
21686
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    72
  in tm end;
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    73
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
    74
fun eliminate ctxt rule xs As thm =
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
    75
  let
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
    76
    val _ = eliminate_term ctxt xs (Thm.full_prop_of thm);
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
    77
    val _ = Object_Logic.is_judgment ctxt (Thm.concl_of thm) orelse
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    78
      error "Conclusion in obtained context must be object-logic judgment";
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    79
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
    80
    val ((_, [thm']), ctxt') = Variable.import true [thm] ctxt;
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    81
    val prems = Drule.strip_imp_prems (#prop (Thm.crep_thm thm'));
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
    82
  in
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    83
    ((Drule.implies_elim_list thm' (map Thm.assume prems)
60315
c08adefc98ea more explicit context;
wenzelm
parents: 59970
diff changeset
    84
        |> Drule.implies_intr_list (map (Drule.norm_hhf_cterm ctxt') As)
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    85
        |> Drule.forall_intr_list xs)
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    86
      COMP rule)
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
    87
    |> Drule.implies_intr_list prems
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
    88
    |> singleton (Variable.export ctxt' ctxt)
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
    89
  end;
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
    90
21686
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    91
fun obtain_export ctxt rule xs _ As =
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    92
  (eliminate ctxt rule xs As, eliminate_term ctxt xs);
4f5f6c685ab4 export: added explicit term operation;
wenzelm
parents: 21605
diff changeset
    93
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
    94
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
    95
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    96
(** obtain **)
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    97
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
    98
fun bind_judgment ctxt name =
18670
c3f445b92aff uniform handling of fixes;
wenzelm
parents: 18643
diff changeset
    99
  let
42501
2b8c34f53388 eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents: 42496
diff changeset
   100
    val ([x], ctxt') = Proof_Context.add_fixes [(Binding.name name, NONE, NoSyn)] ctxt;
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 59623
diff changeset
   101
    val (t as _ $ Free v) = Object_Logic.fixed_judgment ctxt x;
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   102
  in ((v, t), ctxt') end;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   103
18897
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
   104
val thatN = "that";
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
   105
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   106
local
8094
62b45a2e6ecb ObtainFun;
wenzelm
parents: 7923
diff changeset
   107
60379
51d9dcd71ad7 tuned signature;
wenzelm
parents: 60377
diff changeset
   108
fun gen_obtain prep_att prep_var prep_propp
18897
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
   109
    name raw_vars raw_asms int state =
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   110
  let
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
   111
    val _ = Proof.assert_forward_or_chain state;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   112
    val ctxt = Proof.context_of state;
17357
ee2bdca144c7 tuned Isar proof elements;
wenzelm
parents: 17111
diff changeset
   113
    val chain_facts = if can Proof.assert_chain state then Proof.the_facts state else [];
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   114
8543
f54926bded7b handle general case: params and hyps of thesis;
wenzelm
parents: 8109
diff changeset
   115
    (*obtain vars*)
60392
599bff6c8c9e clarified context;
wenzelm
parents: 60391
diff changeset
   116
    val ((xs', vars), fix_ctxt) = ctxt
599bff6c8c9e clarified context;
wenzelm
parents: 60391
diff changeset
   117
      |> fold_map prep_var raw_vars
599bff6c8c9e clarified context;
wenzelm
parents: 60391
diff changeset
   118
      |-> (fn vars => Proof_Context.add_fixes vars ##>> pair vars);
42494
eef1a23c9077 tuned signature -- eliminated odd comment;
wenzelm
parents: 42490
diff changeset
   119
    val xs = map (Variable.check_name o #1) vars;
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   120
8543
f54926bded7b handle general case: params and hyps of thesis;
wenzelm
parents: 8109
diff changeset
   121
    (*obtain asms*)
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   122
    val (propss, binds) = prep_propp fix_ctxt (map snd raw_asms);
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   123
    val props = flat propss;
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   124
    val declare_asms =
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   125
      fold Variable.declare_term props #>
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   126
      fold Variable.bind_term binds;
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
   127
    val asms =
60392
599bff6c8c9e clarified context;
wenzelm
parents: 60391
diff changeset
   128
      map (fn ((b, raw_atts), _) => (b, map (prep_att fix_ctxt) raw_atts)) raw_asms ~~
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   129
      map (map (rpair [])) propss;
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10379
diff changeset
   130
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
   131
    (*obtain params*)
60407
53ef7b78e78a tuned signature;
wenzelm
parents: 60406
diff changeset
   132
    val (params, params_ctxt) =
53ef7b78e78a tuned signature;
wenzelm
parents: 60406
diff changeset
   133
      declare_asms fix_ctxt |> fold_map Proof_Context.inferred_param xs' |>> map Free;
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
   134
    val cparams = map (Thm.cterm_of params_ctxt) params;
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   135
    val binds' = (map o apsnd) (fold_rev Term.dependent_lambda_name (xs ~~ params)) binds;
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
   136
60401
16cf5090d3a6 clarified term bindings;
wenzelm
parents: 60392
diff changeset
   137
    val _ = Variable.warn_extra_tfrees fix_ctxt params_ctxt;
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   138
12970
c9b1838a2cc0 improved messages;
wenzelm
parents: 12404
diff changeset
   139
    (*obtain statements*)
43324
2b47822868e4 discontinued Name.variant to emphasize that this is old-style / indirect;
wenzelm
parents: 42501
diff changeset
   140
    val thesisN = singleton (Name.variant_list xs) Auto_Bind.thesisN;
60392
599bff6c8c9e clarified context;
wenzelm
parents: 60391
diff changeset
   141
    val (thesis_var, thesis) = #1 (bind_judgment params_ctxt thesisN);
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
   142
18897
b31293969d4f obtain(_i): optional name for 'that';
wenzelm
parents: 18870
diff changeset
   143
    val that_name = if name = "" then thatN else name;
10582
49ebade930ea fixed binding of parameters;
wenzelm
parents: 10464
diff changeset
   144
    val that_prop =
45328
e5b33eecbf6e tuned signature;
wenzelm
parents: 45327
diff changeset
   145
      Logic.list_rename_params xs
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60407
diff changeset
   146
        (fold_rev Logic.all params (Logic.list_implies (props, thesis)));
12970
c9b1838a2cc0 improved messages;
wenzelm
parents: 12404
diff changeset
   147
    val obtain_prop =
45328
e5b33eecbf6e tuned signature;
wenzelm
parents: 45327
diff changeset
   148
      Logic.list_rename_params [Auto_Bind.thesisN]
46215
0da9433f959e discontinued old-style Term.list_all_free in favour of plain Logic.all;
wenzelm
parents: 45390
diff changeset
   149
        (Logic.all (Free thesis_var) (Logic.mk_implies (that_prop, thesis)));
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   150
18124
a310c78298f9 simplified after_qed;
wenzelm
parents: 18040
diff changeset
   151
    fun after_qed _ =
17357
ee2bdca144c7 tuned Isar proof elements;
wenzelm
parents: 17111
diff changeset
   152
      Proof.local_qed (NONE, false)
29383
223f18cfbb32 qed/after_qed: singleton result;
wenzelm
parents: 29006
diff changeset
   153
      #> `Proof.the_fact #-> (fn rule =>
36323
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
   154
        Proof.fix vars
60389
ea3a699964aa avoid duplicate warning due to Variable.warn_extra_tfrees;
wenzelm
parents: 60388
diff changeset
   155
        #> Proof.map_context declare_asms
60387
76359ff1090f more careful treatment of term bindings in 'obtain' proof body;
wenzelm
parents: 60383
diff changeset
   156
        #> Proof.assm (obtain_export params_ctxt rule cparams) asms);
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   157
  in
8094
62b45a2e6ecb ObtainFun;
wenzelm
parents: 7923
diff changeset
   158
    state
9468
9adbcf6375c1 turned into plain context element;
wenzelm
parents: 9293
diff changeset
   159
    |> Proof.enter_forward
60414
f25f2f2ba48c support for "if prems" in local goal statements;
wenzelm
parents: 60408
diff changeset
   160
    |> Proof.have NONE (K I) [] [] [(Thm.empty_binding, [(obtain_prop, [])])] int
60401
16cf5090d3a6 clarified term bindings;
wenzelm
parents: 60392
diff changeset
   161
    |> Proof.map_context (fold Variable.bind_term binds')
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   162
    |> Proof.proof (SOME Method.succeed_text) |> Seq.hd
36323
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
   163
    |> Proof.fix [(Binding.name thesisN, NONE, NoSyn)]
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
   164
    |> Proof.assume
33369
470a7b233ee5 modernized structure Context_Rules;
wenzelm
parents: 33368
diff changeset
   165
      [((Binding.name that_name, [Context_Rules.intro_query NONE]), [(that_prop, [])])]
16842
wenzelm
parents: 16787
diff changeset
   166
    |> `Proof.the_facts
17357
ee2bdca144c7 tuned Isar proof elements;
wenzelm
parents: 17111
diff changeset
   167
    ||> Proof.chain_facts chain_facts
60414
f25f2f2ba48c support for "if prems" in local goal statements;
wenzelm
parents: 60408
diff changeset
   168
    ||> Proof.show NONE after_qed [] [] [(Thm.empty_binding, [(thesis, [])])] false
18907
f984f22f1cb4 Proof.refine_insert;
wenzelm
parents: 18897
diff changeset
   169
    |-> Proof.refine_insert
7674
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   170
  end;
99305245f6bd The 'obtain' language element -- achieves (eliminated) existential
wenzelm
parents:
diff changeset
   171
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   172
in
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   173
60388
0c9d2a4f589d clarified Proof_Context.cert_propp/read_propp;
wenzelm
parents: 60387
diff changeset
   174
val obtain = gen_obtain (K I) Proof_Context.cert_var Proof_Context.cert_propp;
0c9d2a4f589d clarified Proof_Context.cert_propp/read_propp;
wenzelm
parents: 60387
diff changeset
   175
val obtain_cmd = gen_obtain Attrib.attribute_cmd Proof_Context.read_var Proof_Context.read_propp;
8094
62b45a2e6ecb ObtainFun;
wenzelm
parents: 7923
diff changeset
   176
62b45a2e6ecb ObtainFun;
wenzelm
parents: 7923
diff changeset
   177
end;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   178
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   179
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   180
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   181
(** tactical result **)
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   182
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   183
fun check_result ctxt thesis th =
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   184
  (case Thm.prems_of th of
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   185
    [prem] =>
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   186
      if Thm.concl_of th aconv thesis andalso
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   187
        Logic.strip_assums_concl prem aconv thesis then th
32091
30e2ffbba718 proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents: 31794
diff changeset
   188
      else error ("Guessed a different clause:\n" ^ Display.string_of_thm ctxt th)
38875
c7a66b584147 tuned messages: discontinued spurious full-stops (messages are occasionally composed unexpectedly);
wenzelm
parents: 36323
diff changeset
   189
  | [] => error "Goal solved -- nothing guessed"
32091
30e2ffbba718 proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents: 31794
diff changeset
   190
  | _ => error ("Guess split into several cases:\n" ^ Display.string_of_thm ctxt th));
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   191
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   192
fun result tac facts ctxt =
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   193
  let
33386
ff29d1549aca modernized structure AutoBind;
wenzelm
parents: 33369
diff changeset
   194
    val ((thesis_var, thesis), thesis_ctxt) = bind_judgment ctxt Auto_Bind.thesisN;
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   195
    val st = Goal.init (Thm.cterm_of ctxt thesis);
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   196
    val rule =
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59573
diff changeset
   197
      (case SINGLE (Method.insert_tac facts 1 THEN tac thesis_ctxt) st of
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   198
        NONE => raise THM ("Obtain.result: tactic failed", 0, facts)
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 52456
diff changeset
   199
      | SOME th =>
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 52456
diff changeset
   200
          check_result thesis_ctxt thesis (Raw_Simplifier.norm_hhf thesis_ctxt (Goal.conclude th)));
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   201
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   202
    val closed_rule = Thm.forall_intr (Thm.cterm_of ctxt (Free thesis_var)) rule;
31794
71af1fd6a5e4 renamed Variable.import_thms to Variable.import (back again cf. ed7aa5a350ef -- Alice is no longer supported);
wenzelm
parents: 30763
diff changeset
   203
    val ((_, [rule']), ctxt') = Variable.import false [closed_rule] ctxt;
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59573
diff changeset
   204
    val obtain_rule =
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   205
      Thm.forall_elim (Thm.cterm_of ctxt (Logic.varify_global (Free thesis_var))) rule';
42495
1af81b70cf09 clarified Variable.focus vs. Variable.focus_cterm -- eliminated clone;
wenzelm
parents: 42494
diff changeset
   206
    val ((params, stmt), fix_ctxt) = Variable.focus_cterm (Thm.cprem_of obtain_rule 1) ctxt';
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   207
    val (prems, ctxt'') =
32199
82c4c570310a Variable.focus: named parameters;
wenzelm
parents: 32091
diff changeset
   208
      Assumption.add_assms (obtain_export fix_ctxt obtain_rule (map #2 params))
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   209
        (Drule.strip_imp_prems stmt) fix_ctxt;
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   210
  in ((params, prems), ctxt'') end;
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   211
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   212
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   213
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   214
(** guess **)
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   215
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   216
local
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   217
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   218
fun unify_params vars thesis_var raw_rule ctxt =
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   219
  let
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 42357
diff changeset
   220
    val thy = Proof_Context.theory_of ctxt;
39134
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 38875
diff changeset
   221
    val string_of_term = Syntax.string_of_term (Config.put show_types true ctxt);
17891
7a6c4d60a913 tuned error msg;
wenzelm
parents: 17858
diff changeset
   222
32091
30e2ffbba718 proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents: 31794
diff changeset
   223
    fun err msg th = error (msg ^ ":\n" ^ Display.string_of_thm ctxt th);
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   224
19978
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   225
    val maxidx = fold (Term.maxidx_typ o snd o fst) vars ~1;
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   226
    val rule = Thm.incr_indexes (maxidx + 1) raw_rule;
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   227
33368
b1cf34f1855c modernized structure Rule_Cases;
wenzelm
parents: 32966
diff changeset
   228
    val params = Rule_Cases.strip_params (Logic.nth_prem (1, Thm.prop_of rule));
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   229
    val m = length vars;
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   230
    val n = length params;
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   231
    val _ = m <= n orelse err "More variables than parameters in obtained rule" rule;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   232
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   233
    fun unify ((x, T), (y, U)) (tyenv, max) = Sign.typ_unify thy (T, U) (tyenv, max)
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   234
      handle Type.TUNIFY =>
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   235
        err ("Failed to unify variable " ^
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   236
          string_of_term (Free (x, Envir.norm_type tyenv T)) ^ " against parameter " ^
49660
de49d9b4d7bc more explicit Syntax_Trans.mark_bound_abs/mark_bound_body: preserve type information for show_markup;
wenzelm
parents: 47815
diff changeset
   237
          string_of_term (Syntax_Trans.mark_bound_abs (y, Envir.norm_type tyenv U)) ^ " in") rule;
33957
e9afca2118d4 normalized uncurry take/drop
haftmann
parents: 33955
diff changeset
   238
    val (tyenv, _) = fold unify (map #1 vars ~~ take m params)
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   239
      (Vartab.empty, Int.max (maxidx, Thm.maxidx_of rule));
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   240
    val norm_type = Envir.norm_type tyenv;
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   241
19978
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   242
    val xs = map (apsnd norm_type o fst) vars;
33957
e9afca2118d4 normalized uncurry take/drop
haftmann
parents: 33955
diff changeset
   243
    val ys = map (apsnd norm_type) (drop m params);
20085
c5d60752587f replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents: 20004
diff changeset
   244
    val ys' = map Name.internal (Name.variant_list (map fst xs) (map fst ys)) ~~ map #2 ys;
59623
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   245
    val terms = map (Drule.mk_term o Thm.cterm_of ctxt o Free) (xs @ ys');
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   246
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   247
    val instT =
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   248
      fold (Term.add_tvarsT o #2) params []
59623
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   249
      |> map (TVar #> (fn T => apply2 (Thm.ctyp_of ctxt) (T, norm_type T)));
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   250
    val closed_rule = rule
59623
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   251
      |> Thm.forall_intr (Thm.cterm_of ctxt (Free thesis_var))
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   252
      |> Thm.instantiate (instT, []);
17891
7a6c4d60a913 tuned error msg;
wenzelm
parents: 17858
diff changeset
   253
31794
71af1fd6a5e4 renamed Variable.import_thms to Variable.import (back again cf. ed7aa5a350ef -- Alice is no longer supported);
wenzelm
parents: 30763
diff changeset
   254
    val ((_, rule' :: terms'), ctxt') = Variable.import false (closed_rule :: terms) ctxt;
19978
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   255
    val vars' =
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   256
      map (dest_Free o Thm.term_of o Drule.dest_term) terms' ~~
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   257
      (map snd vars @ replicate (length ys) NoSyn);
59623
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   258
    val rule'' = Thm.forall_elim (Thm.cterm_of ctxt' (Logic.varify_global (Free thesis_var))) rule';
19978
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   259
  in ((vars', rule''), ctxt') end;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   260
28080
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 24920
diff changeset
   261
fun inferred_type (binding, _, mx) ctxt =
4723eb2456ce explicit type Name.binding for higher-specification elements;
wenzelm
parents: 24920
diff changeset
   262
  let
42494
eef1a23c9077 tuned signature -- eliminated odd comment;
wenzelm
parents: 42490
diff changeset
   263
    val x = Variable.check_name binding;
60407
53ef7b78e78a tuned signature;
wenzelm
parents: 60406
diff changeset
   264
    val ((_, T), ctxt') = Proof_Context.inferred_param x ctxt
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   265
  in ((x, T, mx), ctxt') end;
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   266
20004
e6d3f2b031e6 guess: proper context for polymorphic parameters;
wenzelm
parents: 19978
diff changeset
   267
fun polymorphic ctxt vars =
19897
fe661eb3b0e7 ProofContext: moved variable operations to struct Variable;
wenzelm
parents: 19844
diff changeset
   268
  let val Ts = map Logic.dest_type (Variable.polymorphic ctxt (map (Logic.mk_type o #2) vars))
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   269
  in map2 (fn (x, _, mx) => fn T => ((x, T), mx)) vars Ts end;
18693
8ae076ee5e19 guess: used fixed inferred_type of vars;
wenzelm
parents: 18678
diff changeset
   270
60379
51d9dcd71ad7 tuned signature;
wenzelm
parents: 60377
diff changeset
   271
fun gen_guess prep_var raw_vars int state =
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   272
  let
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   273
    val _ = Proof.assert_forward_or_chain state;
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   274
    val ctxt = Proof.context_of state;
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   275
    val chain_facts = if can Proof.assert_chain state then Proof.the_facts state else [];
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   276
33386
ff29d1549aca modernized structure AutoBind;
wenzelm
parents: 33369
diff changeset
   277
    val (thesis_var, thesis) = #1 (bind_judgment ctxt Auto_Bind.thesisN);
60379
51d9dcd71ad7 tuned signature;
wenzelm
parents: 60377
diff changeset
   278
    val vars = ctxt
51d9dcd71ad7 tuned signature;
wenzelm
parents: 60377
diff changeset
   279
      |> fold_map prep_var raw_vars |-> fold_map inferred_type
51d9dcd71ad7 tuned signature;
wenzelm
parents: 60377
diff changeset
   280
      |> fst |> polymorphic ctxt;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   281
19978
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   282
    fun guess_context raw_rule state' =
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   283
      let
19978
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   284
        val ((parms, rule), ctxt') =
20308
ddb7e7129481 added tactical result;
wenzelm
parents: 20224
diff changeset
   285
          unify_params vars thesis_var raw_rule (Proof.context_of state');
42501
2b8c34f53388 eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents: 42496
diff changeset
   286
        val (xs, _) = Variable.add_fixes (map (#1 o #1) parms) ctxt';
2b8c34f53388 eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents: 42496
diff changeset
   287
        val ps = xs ~~ map (#2 o #1) parms;
2b8c34f53388 eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents: 42496
diff changeset
   288
        val ts = map Free ps;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   289
        val asms =
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   290
          Logic.strip_assums_hyp (Logic.nth_prem (1, Thm.prop_of rule))
46219
426ed18eba43 discontinued old-style Term.list_abs in favour of plain Term.abs;
wenzelm
parents: 46215
diff changeset
   291
          |> map (fn asm => (Term.betapplys (fold_rev Term.abs ps asm, ts), []));
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   292
        val _ = not (null asms) orelse error "Trivial result -- nothing guessed";
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   293
      in
19978
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   294
        state'
df19a7876183 obtain_export: Thm.generalize;
wenzelm
parents: 19906
diff changeset
   295
        |> Proof.map_context (K ctxt')
36323
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
   296
        |> Proof.fix (map (fn ((x, T), mx) => (Binding.name x, SOME T, mx)) parms)
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
   297
        |> `Proof.context_of |-> (fn fix_ctxt => Proof.assm
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   298
          (obtain_export fix_ctxt rule (map (Thm.cterm_of ctxt) ts))
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59573
diff changeset
   299
            [(Thm.empty_binding, asms)])
60401
16cf5090d3a6 clarified term bindings;
wenzelm
parents: 60392
diff changeset
   300
        |> Proof.map_context (fold Variable.unbind_term Auto_Bind.no_facts)
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   301
      end;
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   302
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   303
    val goal = Var (("guess", 0), propT);
56932
11a4001b06c6 more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents: 56897
diff changeset
   304
    val pos = Position.thread_data ();
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   305
    fun print_result ctxt' (k, [(s, [_, th])]) =
56932
11a4001b06c6 more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents: 56897
diff changeset
   306
      Proof_Display.print_results int pos ctxt' (k, [(s, [th])]);
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 52456
diff changeset
   307
    val before_qed =
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 52456
diff changeset
   308
      Method.primitive_text (fn ctxt =>
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 52456
diff changeset
   309
        Goal.conclude #> Raw_Simplifier.norm_hhf ctxt #>
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 52456
diff changeset
   310
          (fn th => Goal.protect 0 (Conjunction.intr (Drule.mk_term (Thm.cprop_of th)) th)));
19779
5c77dfb74c7b guess: more careful about local polymorphism;
wenzelm
parents: 19585
diff changeset
   311
    fun after_qed [[_, res]] =
29383
223f18cfbb32 qed/after_qed: singleton result;
wenzelm
parents: 29006
diff changeset
   312
      Proof.end_block #> guess_context (check_result ctxt thesis res);
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   313
  in
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   314
    state
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   315
    |> Proof.enter_forward
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   316
    |> Proof.begin_block
36323
655e2d74de3a modernized naming conventions of main Isar proof elements;
wenzelm
parents: 35845
diff changeset
   317
    |> Proof.fix [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)]
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   318
    |> Proof.chain_facts chain_facts
60406
12cc54fac9b0 allow for_fixes for 'have', 'show' etc.;
wenzelm
parents: 60404
diff changeset
   319
    |> Proof.internal_goal print_result Proof_Context.mode_schematic "guess"
60414
f25f2f2ba48c support for "if prems" in local goal statements;
wenzelm
parents: 60408
diff changeset
   320
      (SOME before_qed) after_qed [] [] [(Thm.empty_binding, [(Logic.mk_term goal, []), (goal, [])])]
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59573
diff changeset
   321
    |> Proof.refine (Method.primitive_text (fn _ => fn _ =>
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   322
        Goal.init (Thm.cterm_of ctxt thesis))) |> Seq.hd
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   323
  end;
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   324
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   325
in
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   326
60379
51d9dcd71ad7 tuned signature;
wenzelm
parents: 60377
diff changeset
   327
val guess = gen_guess Proof_Context.cert_var;
51d9dcd71ad7 tuned signature;
wenzelm
parents: 60377
diff changeset
   328
val guess_cmd = gen_guess Proof_Context.read_var;
17858
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   329
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   330
end;
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   331
bc4db8cfd92f added 'guess', which derives the obtained context from the course of reasoning;
wenzelm
parents: 17357
diff changeset
   332
end;