src/Pure/Isar/proof.ML
author ballarin
Mon, 08 Aug 2005 22:14:04 +0200
changeset 17034 b4d9b87c102e
parent 16813 67140ae50e77
child 17112 736f4b7841a8
permissions -rw-r--r--
After_qed takes result argument.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/proof.ML
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     4
15757
fc64a89dc0ee tuned comments;
wenzelm
parents: 15722
diff changeset
     5
The Isar/VM proof language interpreter.
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     6
*)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     7
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
     8
signature BASIC_PROOF =
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
     9
sig
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
    10
  val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
    11
  val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
    12
end;
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
    13
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    14
signature PROOF =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    15
sig
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
    16
  include BASIC_PROOF
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    17
  type context
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    18
  type state
14129
d4e2ab7cc86b Exported function get_mode.
berghofe
parents: 13869
diff changeset
    19
  datatype mode = Forward | ForwardChain | Backward
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    20
  exception STATE of string * state
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
    21
  val check_result: string -> state -> 'a Seq.seq -> 'a Seq.seq
12045
bfaa23b19f47 theorem(_i): locale elements;
wenzelm
parents: 12015
diff changeset
    22
  val init_state: theory -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    23
  val context_of: state -> context
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    24
  val theory_of: state -> theory
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
    25
  val sign_of: state -> theory    (*obsolete*)
13377
cc8245843abc export map_context;
wenzelm
parents: 13335
diff changeset
    26
  val map_context: (context -> context) -> state -> state
7924
5fee69b1f5fe warn_extra_tfrees;
wenzelm
parents: 7669
diff changeset
    27
  val warn_extra_tfrees: state -> state -> state
14554
b9cd48af3512 export put_thms;
wenzelm
parents: 14548
diff changeset
    28
  val put_thms: string * thm list -> state -> state
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
    29
  val reset_thms: string -> state -> state
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
    30
  val the_facts: state -> thm list
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    31
  val the_fact: state -> thm
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
    32
  val thisN: string
11079
a378479996f7 val get_goal: state -> context * (thm list * thm);
wenzelm
parents: 10938
diff changeset
    33
  val get_goal: state -> context * (thm list * thm)
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
    34
  val goal_facts: (state -> thm list) -> state -> state
14129
d4e2ab7cc86b Exported function get_mode.
berghofe
parents: 13869
diff changeset
    35
  val get_mode: state -> mode
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    36
  val is_chain: state -> bool
6891
7bb02d03035d tuned print_state;
wenzelm
parents: 6887
diff changeset
    37
  val assert_forward: state -> state
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    38
  val assert_forward_or_chain: state -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    39
  val assert_backward: state -> state
8206
e50a130ec9af assert_no_chain;
wenzelm
parents: 8186
diff changeset
    40
  val assert_no_chain: state -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    41
  val enter_forward: state -> state
16539
60adb8b28377 added depth_of;
wenzelm
parents: 16450
diff changeset
    42
  val show_main_goal: bool ref
6529
0f4c2ebc5018 improved print_state;
wenzelm
parents: 6404
diff changeset
    43
  val verbose: bool ref
12423
7fd447422dee tuned print_state interfaces;
wenzelm
parents: 12308
diff changeset
    44
  val pretty_state: int -> state -> Pretty.T list
10360
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
    45
  val pretty_goals: bool -> state -> Pretty.T list
6776
55f1e6b639a4 added the_fact, level;
wenzelm
parents: 6756
diff changeset
    46
  val level: state -> int
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    47
  type method
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
    48
  val method: (thm list -> tactic) -> method
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
    49
  val method_cases: (thm list -> RuleCases.tactic) -> method
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    50
  val refine: (context -> method) -> state -> state Seq.seq
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
    51
  val refine_end: (context -> method) -> state -> state Seq.seq
5936
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
    52
  val match_bind: (string list * string) list -> state -> state
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
    53
  val match_bind_i: (term list * term) list -> state -> state
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
    54
  val let_bind: (string list * string) list -> state -> state
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
    55
  val let_bind_i: (term list * term) list -> state -> state
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
    56
  val simple_note_thms: string -> thm list -> state -> state
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
    57
  val note_thmss: ((bstring * context attribute list) *
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15452
diff changeset
    58
    (thmref * context attribute list) list) list -> state -> state
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
    59
  val note_thmss_i: ((bstring * context attribute list) *
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
    60
    (thm list * context attribute list) list) list -> state -> state
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
    61
  val with_thmss: ((bstring * context attribute list) *
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15452
diff changeset
    62
    (thmref * context attribute list) list) list -> state -> state
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
    63
  val with_thmss_i: ((bstring * context attribute list) *
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
    64
    (thm list * context attribute list) list) list -> state -> state
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15452
diff changeset
    65
  val using_thmss: ((thmref * context attribute list) list) list -> state -> state
12930
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
    66
  val using_thmss_i: ((thm list * context attribute list) list) list -> state -> state
7412
35ebe1452c10 removed the_fact;
wenzelm
parents: 7271
diff changeset
    67
  val fix: (string list * string option) list -> state -> state
7665
1ab0c74cd748 get_goal: prop;
wenzelm
parents: 7632
diff changeset
    68
  val fix_i: (string list * typ option) list -> state -> state
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    69
  val assm: ProofContext.exporter
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    70
    -> ((string * context attribute list) * (string * (string list * string list)) list) list
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
    71
    -> state -> state
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    72
  val assm_i: ProofContext.exporter
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    73
    -> ((string * context attribute list) * (term * (term list * term list)) list) list
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    74
    -> state -> state
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    75
  val assume:
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    76
    ((string * context attribute list) * (string * (string list * string list)) list) list
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
    77
    -> state -> state
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    78
  val assume_i: ((string * context attribute list) * (term * (term list * term list)) list) list
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    79
    -> state -> state
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    80
  val presume:
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    81
    ((string * context attribute list) * (string * (string list * string list)) list) list
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    82
    -> state -> state
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    83
  val presume_i: ((string * context attribute list) * (term * (term list * term list)) list) list
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    84
    -> state -> state
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
    85
  val def: string -> context attribute list -> string *  (string * string list) -> state -> state
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
    86
  val def_i: string -> context attribute list -> string * (term * term list) -> state -> state
11793
5f0ab6f5c280 support impromptu terminology of cases parameters;
wenzelm
parents: 11742
diff changeset
    87
  val invoke_case: string * string option list * context attribute list -> state -> state
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
    88
  val multi_theorem: string -> (thm list * thm list -> theory -> theory) ->
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    89
    (cterm list -> context -> context -> thm -> thm) ->
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
    90
    (xstring * (Attrib.src list * Attrib.src list list)) option ->
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
    91
    bstring * theory attribute list -> Locale.element Locale.elem_expr list
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
    92
    -> ((bstring * theory attribute list) * (string * (string list * string list)) list) list
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
    93
    -> theory -> state
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
    94
  val multi_theorem_i: string -> (thm list * thm list -> theory -> theory) ->
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
    95
    (cterm list -> context -> context -> thm -> thm) ->
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
    96
    (string * (Attrib.src list * Attrib.src list list)) option
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
    97
    -> bstring * theory attribute list
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
    98
    -> Locale.element_i Locale.elem_expr list
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
    99
    -> ((bstring * theory attribute list) * (term * (term list * term list)) list) list
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   100
    -> theory -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   101
  val chain: state -> state
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
   102
  val from_facts: thm list -> state -> state
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   103
  val show: (bool -> state -> state) -> (thm list -> state -> state Seq.seq) -> bool
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   104
    -> ((string * context attribute list) * (string * (string list * string list)) list) list
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   105
    -> bool -> state -> state
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   106
  val show_i: (bool -> state -> state) -> (thm list -> state -> state Seq.seq) -> bool
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   107
    -> ((string * context attribute list) * (term * (term list * term list)) list) list
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   108
    -> bool -> state -> state
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   109
  val have: (thm list -> state -> state Seq.seq) -> bool
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   110
    -> ((string * context attribute list) * (string * (string list * string list)) list) list
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   111
    -> state -> state
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   112
  val have_i: (thm list -> state -> state Seq.seq) -> bool
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   113
    -> ((string * context attribute list) * (term * (term list * term list)) list) list
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   114
    -> state -> state
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   115
  val at_bottom: state -> bool
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   116
  val local_qed: (state -> state Seq.seq)
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   117
    -> (context -> string * (string * thm list) list -> unit) * (context -> thm -> unit)
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   118
    -> state -> state Seq.seq
6950
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   119
  val global_qed: (state -> state Seq.seq) -> state
12244
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   120
    -> (theory * ((string * string) * (string * thm list) list)) Seq.seq
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   121
  val begin_block: state -> state
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   122
  val next_block: state -> state
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   123
  val end_block: state -> state Seq.seq
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   124
end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   125
13377
cc8245843abc export map_context;
wenzelm
parents: 13335
diff changeset
   126
structure Proof: PROOF =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   127
struct
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   128
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   129
type context = ProofContext.context;
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   130
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   131
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   132
(** proof state **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   133
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   134
(* type goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   135
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   136
datatype kind =
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   137
  Theorem of {kind: string,
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   138
    theory_spec: (bstring * theory attribute list) * theory attribute list list,
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   139
    locale_spec: (string * (Attrib.src list * Attrib.src list list)) option,
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   140
    view: cterm list * cterm list,  (* target view and includes view *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   141
    export: cterm list -> context -> context -> thm -> thm} |
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   142
                                   (* exporter to be used in finish_global *)
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   143
  Show of context attribute list list |
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   144
  Have of context attribute list list;
15099
6d8619440ea0 Some comments added.
ballarin
parents: 14981
diff changeset
   145
13415
63462ccc6fac tuned view;
wenzelm
parents: 13399
diff changeset
   146
fun kind_name _ (Theorem {kind = s, theory_spec = ((a, _), _),
15596
8665d08085df First version of global registration command.
ballarin
parents: 15574
diff changeset
   147
        locale_spec = NONE, ...}) = s ^ (if a = "" then "" else " " ^ a)
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   148
  | kind_name thy (Theorem {kind = s, theory_spec = ((a, _), _),
15596
8665d08085df First version of global registration command.
ballarin
parents: 15574
diff changeset
   149
        locale_spec = SOME (name, _), ...}) =
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   150
      s ^ " (in " ^ Locale.extern thy name ^ ")" ^ (if a = "" then "" else " " ^ a)
12015
68b2a53161e6 theorem: locale argument;
wenzelm
parents: 12010
diff changeset
   151
  | kind_name _ (Show _) = "show"
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   152
  | kind_name _ (Have _) = "have";
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   153
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   154
type goal =
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   155
 (kind *             (*result kind*)
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   156
  string list *      (*result names*)
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   157
  term list list) *  (*result statements*)
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   158
 (thm list *         (*use facts*)
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   159
  thm);              (*goal: subgoals ==> statement*)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   160
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   161
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   162
(* type mode *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   163
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   164
datatype mode = Forward | ForwardChain | Backward;
7201
59b9b7aec3c5 tuned print_state;
wenzelm
parents: 7176
diff changeset
   165
val mode_name = (fn Forward => "state" | ForwardChain => "chain" | Backward => "prove");
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   166
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   167
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   168
(* datatype state *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   169
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   170
datatype node =
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   171
  Node of
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   172
   {context: context,
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   173
    facts: thm list option,
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   174
    mode: mode,
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   175
    goal: (goal * (after_qed * bool)) option}
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   176
and state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   177
  State of
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   178
    node *              (*current*)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   179
    node list           (*parents wrt. block structure*)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   180
and after_qed =
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   181
  AfterQed of
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   182
   (thm list -> state -> state Seq.seq) *
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   183
   (thm list * thm list -> theory -> theory);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   184
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   185
fun make_node (context, facts, mode, goal) =
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   186
  Node {context = context, facts = facts, mode = mode, goal = goal};
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   187
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   188
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   189
exception STATE of string * state;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   190
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   191
fun err_malformed name state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   192
  raise STATE (name ^ ": internal error -- malformed proof state", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   193
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   194
fun check_result msg state sq =
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   195
  (case Seq.pull sq of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   196
    NONE => raise STATE (msg, state)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   197
  | SOME s_sq => Seq.cons s_sq);
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   198
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   199
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   200
fun map_current f (State (Node {context, facts, mode, goal}, nodes)) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   201
  State (make_node (f (context, facts, mode, goal)), nodes);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   202
12045
bfaa23b19f47 theorem(_i): locale elements;
wenzelm
parents: 12015
diff changeset
   203
fun init_state thy =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   204
  State (make_node (ProofContext.init thy, NONE, Forward, NONE), []);
12045
bfaa23b19f47 theorem(_i): locale elements;
wenzelm
parents: 12015
diff changeset
   205
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   206
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   207
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   208
(** basic proof state operations **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   209
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   210
(* context *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   211
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   212
fun context_of (State (Node {context, ...}, _)) = context;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   213
val theory_of = ProofContext.theory_of o context_of;
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   214
val sign_of = theory_of;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   215
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   216
fun map_context f = map_current (fn (ctxt, facts, mode, goal) => (f ctxt, facts, mode, goal));
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   217
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   218
fun map_context_result f (state as State (Node {context, facts, mode, goal}, nodes)) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   219
  let val (context', result) = f context
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   220
  in (State (make_node (context', facts, mode, goal), nodes), result) end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   221
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   222
7924
5fee69b1f5fe warn_extra_tfrees;
wenzelm
parents: 7669
diff changeset
   223
val warn_extra_tfrees = map_context o ProofContext.warn_extra_tfrees o context_of;
10809
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   224
val add_binds_i = map_context o ProofContext.add_binds_i;
6790
0a39f22f847a auto_bind_goal, auto_bind_facts;
wenzelm
parents: 6776
diff changeset
   225
val auto_bind_goal = map_context o ProofContext.auto_bind_goal;
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   226
val auto_bind_facts = map_context o ProofContext.auto_bind_facts;
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
   227
val put_thms = map_context o ProofContext.put_thms;
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
   228
val put_thmss = map_context o ProofContext.put_thmss;
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   229
val reset_thms = map_context o ProofContext.reset_thms;
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   230
val get_case = ProofContext.get_case o context_of;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   231
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   232
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   233
(* facts *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   234
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   235
fun the_facts (State (Node {facts = SOME facts, ...}, _)) = facts
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   236
  | the_facts state = raise STATE ("No current facts available", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   237
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   238
fun the_fact state =
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   239
  (case the_facts state of
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   240
    [thm] => thm
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   241
  | _ => raise STATE ("Single fact expected", state));
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   242
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   243
fun assert_facts state = (the_facts state; state);
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   244
fun get_facts (State (Node {facts, ...}, _)) = facts;
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   245
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   246
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   247
val thisN = "this";
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   248
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   249
fun put_facts facts state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   250
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   251
  |> map_current (fn (ctxt, _, mode, goal) => (ctxt, facts, mode, goal))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   252
  |> (case facts of NONE => reset_thms thisN | SOME ths => put_thms (thisN, ths));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   253
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   254
val reset_facts = put_facts NONE;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   255
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   256
fun these_factss (state, named_factss) =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   257
  state |> put_facts (SOME (List.concat (map snd named_factss)));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   258
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   259
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   260
(* goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   261
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   262
local
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   263
  fun find i (state as State (Node {goal = SOME goal, ...}, _)) = (context_of state, (i, goal))
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   264
    | find i (State (Node {goal = NONE, ...}, node :: nodes)) = find (i + 1) (State (node, nodes))
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   265
    | find _ (state as State (_, [])) = err_malformed "find_goal" state;
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   266
in val find_goal = find 0 end;
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   267
11079
a378479996f7 val get_goal: state -> context * (thm list * thm);
wenzelm
parents: 10938
diff changeset
   268
fun get_goal state =
a378479996f7 val get_goal: state -> context * (thm list * thm);
wenzelm
parents: 10938
diff changeset
   269
  let val (ctxt, (_, ((_, x), _))) = find_goal state
a378479996f7 val get_goal: state -> context * (thm list * thm);
wenzelm
parents: 10938
diff changeset
   270
  in (ctxt, x) end;
a378479996f7 val get_goal: state -> context * (thm list * thm);
wenzelm
parents: 10938
diff changeset
   271
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   272
fun put_goal goal = map_current (fn (ctxt, facts, mode, _) => (ctxt, facts, mode, goal));
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   273
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   274
fun map_goal f g (State (Node {context, facts, mode, goal = SOME goal}, nodes)) =
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   275
      State (make_node (f context, facts, mode, SOME (g goal)), nodes)
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   276
  | map_goal f g (State (nd, node :: nodes)) =
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   277
      let val State (node', nodes') = map_goal f g (State (node, nodes))
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   278
      in map_context f (State (nd, node' :: nodes')) end
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   279
  | map_goal _ _ state = state;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   280
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   281
fun goal_facts get state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   282
  state
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   283
  |> map_goal I (fn ((result, (_, thm)), f) => ((result, (get state, thm)), f));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   284
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   285
fun use_facts state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   286
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   287
  |> goal_facts the_facts
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   288
  |> reset_facts;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   289
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   290
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   291
(* mode *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   292
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   293
fun get_mode (State (Node {mode, ...}, _)) = mode;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   294
fun put_mode mode = map_current (fn (ctxt, facts, _, goal) => (ctxt, facts, mode, goal));
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   295
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   296
val enter_forward = put_mode Forward;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   297
val enter_forward_chain = put_mode ForwardChain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   298
val enter_backward = put_mode Backward;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   299
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   300
fun assert_mode pred state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   301
  let val mode = get_mode state in
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   302
    if pred mode then state
12010
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   303
    else raise STATE ("Illegal application of proof command in "
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   304
      ^ quote (mode_name mode) ^ " mode", state)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   305
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   306
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   307
fun is_chain state = get_mode state = ForwardChain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   308
val assert_forward = assert_mode (equal Forward);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   309
val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   310
val assert_backward = assert_mode (equal Backward);
8206
e50a130ec9af assert_no_chain;
wenzelm
parents: 8186
diff changeset
   311
val assert_no_chain = assert_mode (not_equal ForwardChain);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   312
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   313
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   314
(* blocks *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   315
6776
55f1e6b639a4 added the_fact, level;
wenzelm
parents: 6756
diff changeset
   316
fun level (State (_, nodes)) = length nodes;
55f1e6b639a4 added the_fact, level;
wenzelm
parents: 6756
diff changeset
   317
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   318
fun open_block (State (node, nodes)) = State (node, node :: nodes);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   319
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   320
fun new_block state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   321
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   322
  |> open_block
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   323
  |> put_goal NONE;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   324
7487
c0f9b956a3e7 close_block: removed ProofContext.transfer_used_names;
wenzelm
parents: 7478
diff changeset
   325
fun close_block (state as State (_, node :: nodes)) = State (node, nodes)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   326
  | close_block state = raise STATE ("Unbalanced block parentheses", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   327
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   328
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   329
12423
7fd447422dee tuned print_state interfaces;
wenzelm
parents: 12308
diff changeset
   330
(** pretty_state **)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   331
13869
18112403c809 toggled show_main_goal
nipkow
parents: 13698
diff changeset
   332
val show_main_goal = ref false;
16539
60adb8b28377 added depth_of;
wenzelm
parents: 16450
diff changeset
   333
val verbose = ProofContext.verbose;
13698
d7ef5a3b3591 added show_main_goal
nipkow
parents: 13596
diff changeset
   334
16539
60adb8b28377 added depth_of;
wenzelm
parents: 16450
diff changeset
   335
14876
477c414000f8 pretty_thm/goals_aux, pretty_flexpair: pp;
wenzelm
parents: 14564
diff changeset
   336
val pretty_goals_local = Display.pretty_goals_aux o ProofContext.pp;
12085
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   337
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   338
fun pretty_facts _ _ NONE = []
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   339
  | pretty_facts s ctxt (SOME ths) =
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   340
      [Pretty.big_list (s ^ "this:") (map (ProofContext.pretty_thm ctxt) ths), Pretty.str ""];
6756
fe6eb161df3e improved print_state;
wenzelm
parents: 6752
diff changeset
   341
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   342
fun pretty_state nr (state as State (Node {context = ctxt, facts, mode, goal = _}, nodes)) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   343
  let
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   344
    val ref (_, _, begin_goal) = Display.current_goals_markers;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   345
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   346
    fun levels_up 0 = ""
7575
e1e2d07287d8 improved output;
wenzelm
parents: 7556
diff changeset
   347
      | levels_up 1 = ", 1 level up"
e1e2d07287d8 improved output;
wenzelm
parents: 7556
diff changeset
   348
      | levels_up i = ", " ^ string_of_int i ^ " levels up";
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   349
11556
8e0768929662 print_state: subgoals;
wenzelm
parents: 11549
diff changeset
   350
    fun subgoals 0 = ""
8e0768929662 print_state: subgoals;
wenzelm
parents: 11549
diff changeset
   351
      | subgoals 1 = ", 1 subgoal"
8e0768929662 print_state: subgoals;
wenzelm
parents: 11549
diff changeset
   352
      | subgoals n = ", " ^ string_of_int n ^ " subgoals";
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   353
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   354
    fun prt_names names =
12242
282a92bc5655 multi_theorem: common statement header (covers *all* results);
wenzelm
parents: 12223
diff changeset
   355
      (case filter_out (equal "") names of [] => ""
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   356
      | nms => " " ^ enclose "(" ")" (space_implode " and " (Library.take (7, nms) @
12308
4e7c3f45a083 print_state: up to 7 result names;
wenzelm
parents: 12244
diff changeset
   357
          (if length nms > 7 then ["..."] else []))));
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   358
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   359
    fun prt_goal (_, (i, (((kind, names, _), (goal_facts, thm)), _))) =
12085
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   360
      pretty_facts "using " ctxt
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   361
        (if mode <> Backward orelse null goal_facts then NONE else SOME goal_facts) @
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   362
      [Pretty.str ("goal (" ^ kind_name (theory_of state) kind ^ prt_names names ^
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   363
          levels_up (i div 2) ^ subgoals (Thm.nprems_of thm) ^ "):")] @
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   364
      pretty_goals_local ctxt begin_goal (true, ! show_main_goal) (! Display.goals_limit) thm;
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   365
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   366
    val ctxt_prts =
12085
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   367
      if ! verbose orelse mode = Forward then ProofContext.pretty_context ctxt
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   368
      else if mode = Backward then ProofContext.pretty_asms ctxt
7575
e1e2d07287d8 improved output;
wenzelm
parents: 7556
diff changeset
   369
      else [];
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   370
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   371
    val prts =
8582
3051aa8aa412 tuned output;
wenzelm
parents: 8561
diff changeset
   372
     [Pretty.str ("proof (" ^ mode_name mode ^ "): step " ^ string_of_int nr ^
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   373
        (if ! verbose then ", depth " ^ string_of_int (length nodes div 2 - 1)
8561
2675e2f4dc61 tuned output;
wenzelm
parents: 8542
diff changeset
   374
        else "")), Pretty.str ""] @
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   375
     (if null ctxt_prts then [] else ctxt_prts @ [Pretty.str ""]) @
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   376
     (if ! verbose orelse mode = Forward then
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   377
       (pretty_facts "" ctxt facts @ prt_goal (find_goal state))
12085
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   378
      else if mode = ForwardChain then pretty_facts "picking " ctxt facts
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   379
      else prt_goal (find_goal state))
12423
7fd447422dee tuned print_state interfaces;
wenzelm
parents: 12308
diff changeset
   380
  in prts end;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   381
12085
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   382
fun pretty_goals main state =
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   383
  let val (ctxt, (_, ((_, (_, thm)), _))) = find_goal state
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   384
  in pretty_goals_local ctxt "" (false, main) (! Display.goals_limit) thm end;
10320
26d4b84eb047 added pretty_goals;
wenzelm
parents: 9482
diff changeset
   385
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   386
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   387
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   388
(** proof steps **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   389
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   390
(* datatype method *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   391
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   392
datatype method = Method of thm list -> RuleCases.tactic;
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   393
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   394
fun method tac = Method (fn facts => fn st => Seq.map (rpair []) (tac facts st));
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   395
val method_cases = Method;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   396
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   397
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   398
(* refine goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   399
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   400
local
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   401
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   402
fun goalN i = "goal" ^ string_of_int i;
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   403
fun goals st = map goalN (1 upto Thm.nprems_of st);
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   404
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   405
fun no_goal_cases st = map (rpair NONE) (goals st);
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   406
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   407
fun goal_cases st =
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   408
  RuleCases.make true NONE (Thm.theory_of_thm st, Thm.prop_of st) (goals st);
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   409
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   410
fun check_theory thy state =
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   411
  if subthy (thy, theory_of state) then state
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   412
  else raise STATE ("Bad theory of method result: " ^ Context.str_of_thy thy, state);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   413
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   414
fun gen_refine current_context meth_fun state =
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   415
  let
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   416
    val (goal_ctxt, (_, ((result, (facts, st)), x))) = find_goal state;
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   417
    val Method meth = meth_fun (if current_context then context_of state else goal_ctxt);
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   418
  in
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   419
    meth facts st |> Seq.map (fn (st', meth_cases) =>
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   420
      state
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   421
      |> check_theory (Thm.theory_of_thm st')
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   422
      |> map_goal
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   423
          (ProofContext.add_cases (no_goal_cases st @ goal_cases st' @ meth_cases))
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   424
          (K ((result, (facts, st')), x)))
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   425
  end;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   426
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   427
in
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   428
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   429
val refine = gen_refine true;
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   430
val refine_end = gen_refine false;
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   431
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   432
end;
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   433
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   434
11917
9a0a736d820b moved RANGE to tctical.ML;
wenzelm
parents: 11906
diff changeset
   435
(* goal addressing *)
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   436
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   437
fun FINDGOAL tac st =
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   438
  let fun find (i, n) = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1, n))
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   439
  in find (1, Thm.nprems_of st) st end;
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   440
8166
97414b447a02 added HEADGOAL;
wenzelm
parents: 8152
diff changeset
   441
fun HEADGOAL tac = tac 1;
97414b447a02 added HEADGOAL;
wenzelm
parents: 8152
diff changeset
   442
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   443
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   444
(* export results *)
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   445
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   446
fun refine_tac rule =
12703
af5fec8a418f refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents: 12698
diff changeset
   447
  Tactic.norm_hhf_tac THEN' Tactic.rtac rule THEN_ALL_NEW (SUBGOAL (fn (goal, i) =>
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   448
    if can Logic.dest_goal (Logic.strip_assums_concl goal) then
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   449
      Tactic.etac Drule.triv_goal i
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   450
    else all_tac));
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   451
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   452
fun export_goal inner print_rule raw_rule state =
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   453
  let
12971
92195e8c6208 tuned feedback of goal forms;
wenzelm
parents: 12959
diff changeset
   454
    val (outer, (_, ((result, (facts, thm)), x))) = find_goal state;
12010
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   455
    val exp_tac = ProofContext.export true inner outer;
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   456
    fun exp_rule rule =
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   457
      let
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   458
        val _ = print_rule outer rule;
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   459
        val thmq = FINDGOAL (refine_tac rule) thm;
12971
92195e8c6208 tuned feedback of goal forms;
wenzelm
parents: 12959
diff changeset
   460
      in Seq.map (fn th => map_goal I (K ((result, (facts, th)), x)) state) thmq end;
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   461
  in raw_rule |> exp_tac |> (Seq.flat o Seq.map exp_rule) end;
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   462
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   463
fun export_goals inner print_rule raw_rules =
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   464
  Seq.EVERY (map (export_goal inner print_rule) raw_rules);
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   465
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   466
fun transfer_facts inner_state state =
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   467
  (case get_facts inner_state of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   468
    NONE => Seq.single (reset_facts state)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   469
  | SOME thms =>
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   470
      let
12010
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   471
        val exp_tac = ProofContext.export false (context_of inner_state) (context_of state);
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   472
        val thmqs = map exp_tac thms;
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   473
      in Seq.map (fn ths => put_facts (SOME ths) state) (Seq.commute thmqs) end);
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   474
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   475
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   476
(* prepare result *)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   477
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   478
fun prep_result state ts raw_th =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   479
  let
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   480
    val ctxt = context_of state;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   481
    fun err msg = raise STATE (msg, state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   482
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   483
    val ngoals = Thm.nprems_of raw_th;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   484
    val _ =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   485
      if ngoals = 0 then ()
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   486
      else (err (Pretty.string_of (Pretty.chunks
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   487
        (pretty_goals_local ctxt "" (true, !show_main_goal) (! Display.goals_limit) raw_th @
12085
235576bea937 pretty_goals_local: observes context syntax;
wenzelm
parents: 12065
diff changeset
   488
          [Pretty.str (string_of_int ngoals ^ " unsolved goal(s)!")]))));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   489
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   490
    val {hyps, thy, ...} = Thm.rep_thm raw_th;
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   491
    val tsig = Sign.tsig_of thy;
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   492
    val casms = List.concat (map #1 (ProofContext.assumptions_of (context_of state)));
11816
545aab7410ac simplified exporter interface;
wenzelm
parents: 11793
diff changeset
   493
    val bad_hyps = Library.gen_rems Term.aconv (hyps, map Thm.term_of casms);
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   494
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   495
    val th = raw_th RS Drule.rev_triv_goal;
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   496
    val ths = Drule.conj_elim_precise (length ts) th
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   497
      handle THM _ => err "Main goal structure corrupted";
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   498
  in
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   499
    conditional (not (null bad_hyps)) (fn () => err ("Additional hypotheses:\n" ^
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   500
        cat_lines (map (ProofContext.string_of_term ctxt) bad_hyps)));
12808
a529b4b91888 RuleCases.make interface based on term instead of thm;
wenzelm
parents: 12760
diff changeset
   501
    conditional (exists (not o Pattern.matches tsig) (ts ~~ map Thm.prop_of ths)) (fn () =>
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   502
      err ("Proved a different theorem: " ^ Pretty.string_of (ProofContext.pretty_thm ctxt th)));
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   503
    ths
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   504
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   505
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   506
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   507
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   508
(*** structured proof commands ***)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   509
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   510
(** context **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   511
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   512
(* bind *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   513
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   514
local
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   515
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   516
fun gen_bind f args state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   517
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   518
  |> assert_forward
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   519
  |> map_context (f args)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   520
  |> reset_facts;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   521
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   522
in
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   523
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   524
val match_bind = gen_bind (ProofContext.match_bind false);
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   525
val match_bind_i = gen_bind (ProofContext.match_bind_i false);
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   526
val let_bind = gen_bind (ProofContext.match_bind true);
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   527
val let_bind_i = gen_bind (ProofContext.match_bind_i true);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   528
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   529
end;
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   530
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   531
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   532
(* note_thmss *)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   533
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   534
local
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   535
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   536
fun gen_note_thmss f args state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   537
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   538
  |> assert_forward
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   539
  |> map_context_result (f args)
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   540
  |> these_factss;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   541
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   542
in
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   543
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   544
val note_thmss = gen_note_thmss ProofContext.note_thmss;
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   545
val note_thmss_i = gen_note_thmss ProofContext.note_thmss_i;
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   546
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   547
fun simple_note_thms name thms = note_thmss_i [((name, []), [(thms, [])])];
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   548
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   549
end;
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   550
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   551
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   552
(* with_thmss *)
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   553
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   554
local
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   555
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   556
fun gen_with_thmss f args state =
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   557
  let val state' = state |> f args
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   558
  in state' |> simple_note_thms "" (the_facts state' @ the_facts state) end;
6876
4ae9c47f2b6b have_thmss: more_ths;
wenzelm
parents: 6871
diff changeset
   559
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   560
in
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   561
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   562
val with_thmss = gen_with_thmss note_thmss;
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   563
val with_thmss_i = gen_with_thmss note_thmss_i;
12714
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   564
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   565
end;
61af28328417 have_thmss vs. have_thmss_i;
wenzelm
parents: 12703
diff changeset
   566
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   567
12930
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   568
(* using_thmss *)
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   569
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   570
local
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   571
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   572
fun gen_using_thmss f args state =
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   573
  state
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   574
  |> assert_backward
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   575
  |> map_context_result (f (map (pair ("", [])) args))
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   576
  |> (fn (st, named_facts) =>
12971
92195e8c6208 tuned feedback of goal forms;
wenzelm
parents: 12959
diff changeset
   577
    let val (_, (_, ((result, (facts, thm)), x))) = find_goal st;
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   578
    in st |> map_goal I (K ((result, (facts @ List.concat (map snd named_facts), thm)), x)) end);
12930
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   579
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   580
in
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   581
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   582
val using_thmss = gen_using_thmss ProofContext.note_thmss;
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   583
val using_thmss_i = gen_using_thmss ProofContext.note_thmss_i;
12930
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   584
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   585
end;
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   586
c1f3ff5feff1 added using_thmss(_i);
wenzelm
parents: 12808
diff changeset
   587
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   588
(* fix *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   589
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   590
local
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   591
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   592
fun gen_fix f args state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   593
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   594
  |> assert_forward
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   595
  |> map_context (f args)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   596
  |> reset_facts;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   597
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   598
in
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   599
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   600
val fix = gen_fix ProofContext.fix;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   601
val fix_i = gen_fix ProofContext.fix_i;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   602
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   603
end;
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   604
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   605
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   606
(* assume and presume *)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   607
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   608
local
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   609
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   610
fun gen_assume f exp args state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   611
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   612
  |> assert_forward
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   613
  |> map_context_result (f exp args)
11924
b6def266cbb9 simplified ProofContext.assume interface;
wenzelm
parents: 11917
diff changeset
   614
  |> these_factss;
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   615
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   616
in
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   617
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   618
val assm = gen_assume ProofContext.assume;
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   619
val assm_i = gen_assume ProofContext.assume_i;
11917
9a0a736d820b moved RANGE to tctical.ML;
wenzelm
parents: 11906
diff changeset
   620
val assume = assm ProofContext.export_assume;
9a0a736d820b moved RANGE to tctical.ML;
wenzelm
parents: 11906
diff changeset
   621
val assume_i = assm_i ProofContext.export_assume;
9a0a736d820b moved RANGE to tctical.ML;
wenzelm
parents: 11906
diff changeset
   622
val presume = assm ProofContext.export_presume;
9a0a736d820b moved RANGE to tctical.ML;
wenzelm
parents: 11906
diff changeset
   623
val presume_i = assm_i ProofContext.export_presume;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   624
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   625
end;
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   626
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   627
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   628
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   629
(** local definitions **)
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   630
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   631
local
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   632
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   633
fun gen_def fix prep_term prep_pats raw_name atts (x, (raw_rhs, raw_pats)) state =
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   634
  let
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   635
    val _ = assert_forward state;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   636
    val ctxt = context_of state;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   637
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   638
    (*rhs*)
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   639
    val name = if raw_name = "" then Thm.def_name x else raw_name;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   640
    val rhs = prep_term ctxt raw_rhs;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   641
    val T = Term.fastype_of rhs;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   642
    val pats = prep_pats T (ProofContext.declare_term rhs ctxt) raw_pats;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   643
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   644
    (*lhs*)
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   645
    val lhs = ProofContext.bind_skolem ctxt [x] (Free (x, T));
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   646
  in
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   647
    state
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   648
    |> fix [([x], NONE)]
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   649
    |> match_bind_i [(pats, rhs)]
11917
9a0a736d820b moved RANGE to tctical.ML;
wenzelm
parents: 11906
diff changeset
   650
    |> assm_i ProofContext.export_def [((name, atts), [(Logic.mk_equals (lhs, rhs), ([], []))])]
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   651
  end;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   652
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   653
in
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   654
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   655
val def = gen_def fix ProofContext.read_term ProofContext.read_term_pats;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   656
val def_i = gen_def fix_i ProofContext.cert_term ProofContext.cert_term_pats;
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   657
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   658
end;
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   659
11891
99569e5f0ab5 moved local defs to proof.ML (for locales);
wenzelm
parents: 11816
diff changeset
   660
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   661
(* invoke_case *)
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   662
11793
5f0ab6f5c280 support impromptu terminology of cases parameters;
wenzelm
parents: 11742
diff changeset
   663
fun invoke_case (name, xs, atts) state =
9292
c5875175751f invoke_case: bind_skolem;
wenzelm
parents: 9196
diff changeset
   664
  let
10830
d19f9f4c35ee avoid renaming of params in cases;
wenzelm
parents: 10809
diff changeset
   665
    val (state', (lets, asms)) =
11793
5f0ab6f5c280 support impromptu terminology of cases parameters;
wenzelm
parents: 11742
diff changeset
   666
      map_context_result (ProofContext.apply_case (get_case state name xs)) state;
13425
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
   667
    val assumptions = asms |> map (fn (a, ts) =>
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   668
      ((NameSpace.qualified name a, atts), map (rpair ([], [])) ts));
9292
c5875175751f invoke_case: bind_skolem;
wenzelm
parents: 9196
diff changeset
   669
  in
10830
d19f9f4c35ee avoid renaming of params in cases;
wenzelm
parents: 10809
diff changeset
   670
    state'
10809
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   671
    |> add_binds_i lets
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   672
    |> map_context (ProofContext.no_base_names o ProofContext.qualified_names)
13425
119ae829ad9b support for split assumptions in cases (hyps vs. prems);
wenzelm
parents: 13415
diff changeset
   673
    |> assume_i assumptions
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   674
    |> map_context (ProofContext.restore_naming (context_of state))
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14554
diff changeset
   675
    |> (fn st => simple_note_thms name (the_facts st) st)
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   676
  end;
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   677
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   678
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   679
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   680
(** goals **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   681
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   682
(* forward chaining *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   683
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   684
fun chain state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   685
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   686
  |> assert_forward
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   687
  |> assert_facts
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   688
  |> enter_forward_chain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   689
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   690
fun from_facts facts state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   691
  state
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   692
  |> put_facts (SOME facts)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   693
  |> chain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   694
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   695
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   696
(* setup goals *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   697
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   698
local
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   699
11549
e7265e70fd7c renamed "antecedent" case to "rule_context";
wenzelm
parents: 11525
diff changeset
   700
val rule_contextN = "rule_context";
8991
dc70b797827f case 'antecedent';
wenzelm
parents: 8807
diff changeset
   701
12971
92195e8c6208 tuned feedback of goal forms;
wenzelm
parents: 12959
diff changeset
   702
fun setup_goal opt_block prepp autofix kind after_qed pr names raw_propp state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   703
  let
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   704
    val (state', (propss, gen_binds)) =
5936
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   705
      state
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   706
      |> assert_forward_or_chain
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   707
      |> enter_forward
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   708
      |> opt_block
12534
5729b8cac4e1 use Locale.read/cert_context_statement;
wenzelm
parents: 12511
diff changeset
   709
      |> map_context_result (fn ctxt => prepp (ctxt, raw_propp));
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   710
    val thy' = theory_of state';
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   711
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   712
    val AfterQed (after_local, after_global) = after_qed;
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   713
    val after_qed' = AfterQed (fn results => after_local results o map_context gen_binds, after_global);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   714
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   715
    val props = List.concat propss;
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   716
    val cprop = Thm.cterm_of thy' (Logic.mk_conjunction_list props);
7556
f3e78ebcf6ba setup_goal: do not insert assumptions;
wenzelm
parents: 7487
diff changeset
   717
    val goal = Drule.mk_triv_goal cprop;
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   718
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   719
    val tvars = foldr Term.add_term_tvars [] props;
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   720
    val vars = foldr Term.add_term_vars [] props;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   721
  in
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   722
    if null tvars then ()
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   723
    else raise STATE ("Goal statement contains illegal schematic type variable(s): " ^
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   724
      commas (map (Syntax.string_of_vname o #1) tvars), state);
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   725
    if null vars then ()
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   726
    else warning ("Goal statement contains unbound schematic variable(s): " ^
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   727
      commas (map (ProofContext.string_of_term (context_of state')) vars));
5936
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   728
    state'
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   729
    |> map_context (autofix props)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   730
    |> put_goal (SOME (((kind, names, propss), ([], goal)), (after_qed', pr)))
12167
74f92a43bac3 empty rule_context for multiple goals;
wenzelm
parents: 12146
diff changeset
   731
    |> map_context (ProofContext.add_cases
12808
a529b4b91888 RuleCases.make interface based on term instead of thm;
wenzelm
parents: 12760
diff changeset
   732
     (if length props = 1 then
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   733
      RuleCases.make true NONE (Thm.theory_of_thm goal, Thm.prop_of goal) [rule_contextN]
16146
4cf0af7ca7c9 method_cases: RuleCases.T option;
wenzelm
parents: 15979
diff changeset
   734
      else [(rule_contextN, NONE)]))
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   735
    |> auto_bind_goal props
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   736
    |> (if is_chain state then use_facts else reset_facts)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   737
    |> new_block
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   738
    |> enter_backward
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   739
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   740
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   741
fun global_goal prep kind after_global export raw_locale a elems concl thy =
12503
52994bfef01b Locale.activate_context;
wenzelm
parents: 12423
diff changeset
   742
  let
12549
65f03a3f7998 tuned interface of ProofContext.generalize;
wenzelm
parents: 12534
diff changeset
   743
    val init = init_state thy;
13399
c136276dc847 support locale ``views'' (for cumulative predicates);
wenzelm
parents: 13377
diff changeset
   744
    val (opt_name, view, locale_ctxt, elems_ctxt, propp) =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   745
      prep (Option.map fst raw_locale) elems (map snd concl) (context_of init);
12503
52994bfef01b Locale.activate_context;
wenzelm
parents: 12423
diff changeset
   746
  in
12549
65f03a3f7998 tuned interface of ProofContext.generalize;
wenzelm
parents: 12534
diff changeset
   747
    init
65f03a3f7998 tuned interface of ProofContext.generalize;
wenzelm
parents: 12534
diff changeset
   748
    |> open_block
12511
901c6c477907 tuned locale interface;
wenzelm
parents: 12503
diff changeset
   749
    |> map_context (K locale_ctxt)
12065
5f7f44d5e3dd theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   750
    |> open_block
12511
901c6c477907 tuned locale interface;
wenzelm
parents: 12503
diff changeset
   751
    |> map_context (K elems_ctxt)
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   752
    |> setup_goal I ProofContext.bind_propp_schematic_i ProofContext.fix_frees
13415
63462ccc6fac tuned view;
wenzelm
parents: 13399
diff changeset
   753
      (Theorem {kind = kind,
63462ccc6fac tuned view;
wenzelm
parents: 13399
diff changeset
   754
        theory_spec = (a, map (snd o fst) concl),
15973
wenzelm
parents: 15757
diff changeset
   755
        locale_spec = (case raw_locale of NONE => NONE | SOME (_, x) => SOME (the opt_name, x)),
15596
8665d08085df First version of global registration command.
ballarin
parents: 15574
diff changeset
   756
        view = view,
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   757
        export = export})
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   758
      (AfterQed (K Seq.single, after_global))
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   759
      true (map (fst o fst) concl) propp
12065
5f7f44d5e3dd theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   760
  end;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   761
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   762
fun local_goal' prepp kind (check: bool -> state -> state) after_local pr args int state =
7928
06a11f8cf573 improved handling of warn_extra_tfrees;
wenzelm
parents: 7924
diff changeset
   763
  state
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   764
  |> setup_goal open_block prepp (K I) (kind (map (snd o fst) args))
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   765
    (AfterQed (after_local, K I)) pr (map (fst o fst) args) (map snd args)
10936
a0dc597d9173 show(_i): check goal;
wenzelm
parents: 10830
diff changeset
   766
  |> warn_extra_tfrees state
a0dc597d9173 show(_i): check goal;
wenzelm
parents: 10830
diff changeset
   767
  |> check int;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   768
12971
92195e8c6208 tuned feedback of goal forms;
wenzelm
parents: 12959
diff changeset
   769
fun local_goal prepp kind f pr args = local_goal' prepp kind (K I) f pr args false;
10936
a0dc597d9173 show(_i): check goal;
wenzelm
parents: 10830
diff changeset
   770
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   771
in
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   772
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   773
val multi_theorem = global_goal Locale.read_context_statement;
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   774
val multi_theorem_i = global_goal Locale.cert_context_statement;
10936
a0dc597d9173 show(_i): check goal;
wenzelm
parents: 10830
diff changeset
   775
val show = local_goal' ProofContext.bind_propp Show;
a0dc597d9173 show(_i): check goal;
wenzelm
parents: 10830
diff changeset
   776
val show_i = local_goal' ProofContext.bind_propp_i Show;
a0dc597d9173 show(_i): check goal;
wenzelm
parents: 10830
diff changeset
   777
val have = local_goal ProofContext.bind_propp Have;
10380
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   778
val have_i = local_goal ProofContext.bind_propp_i Have;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   779
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   780
end;
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   781
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   782
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   783
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   784
(** conclusions **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   785
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   786
(* current goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   787
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   788
fun current_goal (State (Node {context, goal = SOME goal, ...}, _)) = (context, goal)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   789
  | current_goal state = raise STATE ("No current goal!", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   790
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   791
fun assert_current_goal true (state as State (Node {goal = NONE, ...}, _)) =
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   792
      raise STATE ("No goal in this block!", state)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   793
  | assert_current_goal false (state as State (Node {goal = SOME _, ...}, _)) =
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   794
      raise STATE ("Goal present in this block!", state)
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   795
  | assert_current_goal _ state = state;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   796
12010
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   797
fun assert_bottom b (state as State (_, nodes)) =
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   798
  let val bot = (length nodes <= 2) in
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   799
    if b andalso not bot then raise STATE ("Not at bottom of proof!", state)
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   800
    else if not b andalso bot then raise STATE ("Already at bottom of proof!", state)
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   801
    else state
e1d4df962ac9 theorem(_i): locale argument;
wenzelm
parents: 12000
diff changeset
   802
  end;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   803
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   804
val at_bottom = can (assert_bottom true o close_block);
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   805
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   806
fun end_proof bot state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   807
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   808
  |> assert_forward
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   809
  |> close_block
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   810
  |> assert_bottom bot
7011
7e8e9a26ba2c export init_state;
wenzelm
parents: 6996
diff changeset
   811
  |> assert_current_goal true
7e8e9a26ba2c export init_state;
wenzelm
parents: 6996
diff changeset
   812
  |> goal_facts (K []);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   813
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   814
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   815
(* local_qed *)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   816
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   817
fun finish_local (print_result, print_rule) state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   818
  let
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   819
    val (goal_ctxt, (((kind, names, tss), (_, raw_thm)), (AfterQed (after_local, _), pr))) =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   820
      current_goal state;
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   821
    val outer_state = state |> close_block;
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   822
    val outer_ctxt = context_of outer_state;
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   823
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   824
    val ts = List.concat tss;
12146
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   825
    val results = prep_result state ts raw_thm;
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   826
    val resultq =
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   827
      results |> map (ProofContext.export false goal_ctxt outer_ctxt)
8e02a45f77e2 added multi_theorem(_i);
wenzelm
parents: 12096
diff changeset
   828
      |> Seq.commute |> Seq.map (Library.unflat tss);
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   829
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   830
    val (attss, opt_solve) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   831
      (case kind of
12971
92195e8c6208 tuned feedback of goal forms;
wenzelm
parents: 12959
diff changeset
   832
        Show attss => (attss,
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   833
          export_goals goal_ctxt (if pr then print_rule else (K (K ()))) results)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   834
      | Have attss => (attss, Seq.single)
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   835
      | _ => err_malformed "finish_local" state);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   836
  in
12971
92195e8c6208 tuned feedback of goal forms;
wenzelm
parents: 12959
diff changeset
   837
    conditional pr (fn () => print_result goal_ctxt
16450
66667013ca6e RuleCases.tactic;
wenzelm
parents: 16169
diff changeset
   838
      (kind_name (theory_of state) kind, names ~~ Library.unflat tss results));
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   839
    outer_state
12549
65f03a3f7998 tuned interface of ProofContext.generalize;
wenzelm
parents: 12534
diff changeset
   840
    |> auto_bind_facts (ProofContext.generalize goal_ctxt outer_ctxt ts)
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   841
    |> (fn st => Seq.map (fn res =>
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   842
      note_thmss_i ((names ~~ attss) ~~ map (single o Thm.no_attributes) res) st) resultq)
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   843
    |> (Seq.flat o Seq.map opt_solve)
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   844
    |> (Seq.flat o Seq.map (after_local results))
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   845
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   846
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   847
fun local_qed finalize print state =
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   848
  state
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   849
  |> end_proof false
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   850
  |> finalize
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   851
  |> (Seq.flat o Seq.map (finish_local print));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   852
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   853
12703
af5fec8a418f refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents: 12698
diff changeset
   854
(* global_qed *)
12065
5f7f44d5e3dd theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   855
6950
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   856
fun finish_global state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   857
  let
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   858
    val (goal_ctxt, (((kind, names, tss), (_, raw_thm)), (AfterQed (_, after_global), _))) =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   859
      current_goal state;
12065
5f7f44d5e3dd theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   860
    val locale_ctxt = context_of (state |> close_block);
5f7f44d5e3dd theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   861
    val theory_ctxt = context_of (state |> close_block |> close_block);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   862
    val {kind = k, theory_spec = ((name, atts), attss),
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   863
        locale_spec, view = (target_view, elems_view), export} =
13399
c136276dc847 support locale ``views'' (for cumulative predicates);
wenzelm
parents: 13377
diff changeset
   864
      (case kind of Theorem x => x | _ => err_malformed "finish_global" state);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   865
    val locale_name = Option.map fst locale_spec;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   866
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   867
    val ts = List.concat tss;
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   868
    val locale_results = map (export elems_view goal_ctxt locale_ctxt)
13377
cc8245843abc export map_context;
wenzelm
parents: 13335
diff changeset
   869
      (prep_result state ts raw_thm);
14215
ebf291f3b449 Improvements to Isar/Locales: premises generated by "includes" elements
ballarin
parents: 14129
diff changeset
   870
13377
cc8245843abc export map_context;
wenzelm
parents: 13335
diff changeset
   871
    val results = map (Drule.strip_shyps_warning o
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   872
      export target_view locale_ctxt theory_ctxt) locale_results;
12703
af5fec8a418f refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents: 12698
diff changeset
   873
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   874
    val (theory', results') =
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   875
      theory_of state
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   876
      |> (case locale_spec of NONE => I
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   877
                            | SOME (loc, (loc_atts, loc_attss)) => fn thy =>
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   878
        if length names <> length loc_attss then
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   879
          raise THEORY ("Bad number of locale attributes", [thy])
13335
7995b3f4ca5e tuned Locale.add_thmss;
wenzelm
parents: 13297
diff changeset
   880
        else (thy, locale_ctxt)
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   881
          |> Locale.add_thmss k loc ((names ~~ Library.unflat tss locale_results) ~~ loc_attss)
13335
7995b3f4ca5e tuned Locale.add_thmss;
wenzelm
parents: 13297
diff changeset
   882
          |> (fn ((thy', ctxt'), res) =>
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   883
            if name = "" andalso null loc_atts then thy'
13335
7995b3f4ca5e tuned Locale.add_thmss;
wenzelm
parents: 13297
diff changeset
   884
            else (thy', ctxt')
15696
1da4ce092c0b First release of interpretation commands.
ballarin
parents: 15624
diff changeset
   885
              |> (#1 o #1 o Locale.add_thmss k loc [((name, List.concat (map #2 res)), loc_atts)])))
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   886
      |> Locale.smart_note_thmss k locale_name
12703
af5fec8a418f refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents: 12698
diff changeset
   887
        ((names ~~ attss) ~~ map (single o Thm.no_attributes) (Library.unflat tss results))
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   888
      |> (fn (thy, res) => (thy, res)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15696
diff changeset
   889
          |>> (#1 o Locale.smart_note_thmss k locale_name
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15533
diff changeset
   890
            [((name, atts), [(List.concat (map #2 res), [])])]));
17034
b4d9b87c102e After_qed takes result argument.
ballarin
parents: 16813
diff changeset
   891
  in (after_global (locale_results, results) theory', ((k, name), results')) end;
12959
bf48fd86a732 clarified localized multi statements;
wenzelm
parents: 12930
diff changeset
   892
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   893
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   894
(*note: clients should inspect first result only, as backtracking may destroy theory*)
6950
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   895
fun global_qed finalize state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   896
  state
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   897
  |> end_proof true
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   898
  |> finalize
12065
5f7f44d5e3dd theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   899
  |> Seq.map finish_global;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   900
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   901
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   902
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   903
(** blocks **)
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   904
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   905
fun begin_block state =
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   906
  state
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   907
  |> assert_forward
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   908
  |> new_block
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   909
  |> open_block;
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   910
16813
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   911
fun next_block state =
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   912
  state
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   913
  |> assert_forward
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   914
  |> close_block
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   915
  |> new_block
67140ae50e77 removed ad-hoc atp_hook, cal_atp;
wenzelm
parents: 16539
diff changeset
   916
  |> reset_facts;
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   917
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   918
fun end_block state =
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   919
  state
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   920
  |> assert_forward
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   921
  |> close_block
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   922
  |> assert_current_goal false
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   923
  |> close_block
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   924
  |> transfer_facts state;
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   925
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   926
end;
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   927
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   928
structure BasicProof: BASIC_PROOF = Proof;
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   929
open BasicProof;