src/Pure/Isar/proof.ML
author wenzelm
Sat, 06 Jan 2001 21:29:29 +0100
changeset 10809 e827c779ae2e
parent 10553 7f239ef89c50
child 10830 d19f9f4c35ee
permissions -rw-r--r--
moved norm_hhf_tac to Pure/tactic.ML; adapted invoke_case;
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
8807
wenzelm
parents: 8722
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     5
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     6
Proof states and methods.
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     7
*)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
     8
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
     9
signature BASIC_PROOF =
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
    10
sig
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    11
  val RANGE: (int -> tactic) list -> int -> tactic
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
    12
  val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
    13
  val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
    14
end;
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
    15
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    16
signature PROOF =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    17
sig
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
    18
  include BASIC_PROOF
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    19
  type context
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    20
  type state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    21
  exception STATE of string * state
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
    22
  val check_result: string -> state -> 'a Seq.seq -> 'a Seq.seq
7011
7e8e9a26ba2c export init_state;
wenzelm
parents: 6996
diff changeset
    23
  val init_state: theory -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    24
  val context_of: state -> context
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    25
  val theory_of: state -> theory
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    26
  val sign_of: state -> Sign.sg
7924
5fee69b1f5fe warn_extra_tfrees;
wenzelm
parents: 7669
diff changeset
    27
  val warn_extra_tfrees: state -> state -> state
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
    28
  val reset_thms: string -> state -> state
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
    29
  val the_facts: state -> thm list
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    30
  val the_fact: state -> thm
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
    31
  val goal_facts: (state -> thm list) -> state -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    32
  val use_facts: state -> state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    33
  val reset_facts: state -> state
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    34
  val is_chain: state -> bool
6891
7bb02d03035d tuned print_state;
wenzelm
parents: 6887
diff changeset
    35
  val assert_forward: state -> state
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    36
  val assert_forward_or_chain: state -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    37
  val assert_backward: state -> state
8206
e50a130ec9af assert_no_chain;
wenzelm
parents: 8186
diff changeset
    38
  val assert_no_chain: state -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    39
  val enter_forward: state -> state
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
    40
  val show_hyps: bool ref
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
    41
  val pretty_thm: thm -> Pretty.T
7412
35ebe1452c10 removed the_fact;
wenzelm
parents: 7271
diff changeset
    42
  val pretty_thms: thm list -> Pretty.T
6529
0f4c2ebc5018 improved print_state;
wenzelm
parents: 6404
diff changeset
    43
  val verbose: bool ref
7201
59b9b7aec3c5 tuned print_state;
wenzelm
parents: 7176
diff changeset
    44
  val print_state: int -> state -> unit
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
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
    49
  val method_cases: (thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq) -> 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
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    52
  val export_thm: context -> thm -> thm
5936
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
    53
  val match_bind: (string list * string) list -> state -> state
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
    54
  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
    55
  val let_bind: (string list * string) list -> state -> state
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
    56
  val let_bind_i: (term list * term) list -> state -> state
6876
4ae9c47f2b6b have_thmss: more_ths;
wenzelm
parents: 6871
diff changeset
    57
  val simple_have_thms: string -> thm list -> state -> state
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
    58
  val have_thmss: ((string * context attribute list) *
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
    59
    (thm list * context attribute list) list) list -> state -> state
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
    60
  val with_thmss: ((string * context attribute list) *
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
    61
    (thm list * context attribute list) list) list -> state -> state
7412
35ebe1452c10 removed the_fact;
wenzelm
parents: 7271
diff changeset
    62
  val fix: (string list * string option) list -> state -> state
7665
1ab0c74cd748 get_goal: prop;
wenzelm
parents: 7632
diff changeset
    63
  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
    64
  val hard_asm_tac: int -> tactic
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    65
  val soft_asm_tac: int -> tactic
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    66
  val assm: ProofContext.exporter
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    67
    -> ((string * context attribute list) * (string * (string list * string list)) list) list
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
    68
    -> state -> state
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
    69
  val assm_i: ProofContext.exporter
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    70
    -> ((string * context attribute list) * (term * (term list * term list)) list) list
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    71
    -> state -> state
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    72
  val assume:
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    73
    ((string * context attribute list) * (string * (string list * string list)) list) list
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
    74
    -> state -> state
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    75
  val assume_i: ((string * context attribute list) * (term * (term list * term list)) list) list
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    76
    -> state -> state
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    77
  val presume:
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
    78
    ((string * context attribute list) * (string * (string list * string 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_i: ((string * context attribute list) * (term * (term list * term list)) list) list
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    81
    -> state -> state
8450
dc44d6533f0f invoke_case: include attributes;
wenzelm
parents: 8383
diff changeset
    82
  val invoke_case: string * context attribute list -> state -> state
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    83
  val theorem: bstring -> theory attribute list -> string * (string list * string list)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    84
    -> theory -> state
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    85
  val theorem_i: bstring -> theory attribute list -> term * (term list * term list)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    86
    -> theory -> state
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    87
  val lemma: bstring -> theory attribute list -> string * (string list * string list)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    88
    -> theory -> state
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    89
  val lemma_i: bstring -> theory attribute list -> term * (term list * term list)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
    90
    -> theory -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
    91
  val chain: state -> state
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
    92
  val from_facts: thm list -> state -> state
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
    93
  val show: (state -> state Seq.seq) -> string -> context attribute list
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
    94
    -> string * (string list * string list) -> state -> state
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
    95
  val show_i: (state -> state Seq.seq) -> string -> context attribute list
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
    96
    -> term * (term list * term list) -> state -> state
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
    97
  val have: (state -> state Seq.seq) -> string -> context attribute list
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
    98
    -> string * (string list * string list) -> state -> state
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
    99
  val have_i: (state -> state Seq.seq) -> string -> context attribute list
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   100
    -> term * (term list * term list) -> state -> state
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   101
  val at_bottom: state -> bool
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   102
  val local_qed: (state -> state Seq.seq)
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   103
    -> ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit) -> state -> state Seq.seq
10508
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   104
  val name_refN: string
6950
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   105
  val global_qed: (state -> state Seq.seq) -> state
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   106
    -> (theory * {kind: string, name: string, thm: thm}) Seq.seq
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   107
  val begin_block: state -> state
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   108
  val end_block: state -> state Seq.seq
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   109
  val next_block: state -> state
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   110
end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   111
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   112
signature PRIVATE_PROOF =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   113
sig
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   114
  include PROOF
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   115
  val put_data: Object.kind -> ('a -> Object.T) -> 'a -> state -> state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   116
end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   117
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   118
structure Proof: PRIVATE_PROOF =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   119
struct
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   120
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   121
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   122
(** proof state **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   123
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   124
type context = ProofContext.context;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   125
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   126
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   127
(* type goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   128
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   129
datatype kind =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   130
  Theorem of theory attribute list |    (*top-level theorem*)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   131
  Lemma of theory attribute list |      (*top-level lemma*)
10380
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   132
  Show of context attribute list |      (*intermediate result, solving subgoal*)
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   133
  Have of context attribute list ;       (*intermediate result*)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   134
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   135
val kind_name =
10380
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   136
  fn Theorem _ => "theorem" | Lemma _ => "lemma" | Show _ => "show" | Have _ => "have";
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   137
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   138
type goal =
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   139
 (kind *        (*result kind*)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   140
  string *      (*result name*)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   141
  term) *       (*result statement*)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   142
 (thm list *    (*use facts*)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   143
  thm);         (*goal: subgoals ==> statement*)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   144
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   145
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   146
(* type mode *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   147
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   148
datatype mode = Forward | ForwardChain | Backward;
7201
59b9b7aec3c5 tuned print_state;
wenzelm
parents: 7176
diff changeset
   149
val mode_name = (fn Forward => "state" | ForwardChain => "chain" | Backward => "prove");
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   150
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   151
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   152
(* datatype state *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   153
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   154
datatype node =
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   155
  Node of
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   156
   {context: context,
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   157
    facts: thm list option,
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   158
    mode: mode,
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   159
    goal: (goal * (state -> state Seq.seq)) option}
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   160
and state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   161
  State of
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   162
    node *              (*current*)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   163
    node list;          (*parents wrt. block structure*)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   164
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   165
fun make_node (context, facts, mode, goal) =
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   166
  Node {context = context, facts = facts, mode = mode, goal = goal};
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   167
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   168
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   169
exception STATE of string * state;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   170
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   171
fun err_malformed name state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   172
  raise STATE (name ^ ": internal error -- malformed proof state", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   173
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   174
fun check_result msg state sq =
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   175
  (case Seq.pull sq of
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   176
    None => raise STATE (msg, state)
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   177
  | Some s_sq => Seq.cons s_sq);
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   178
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   179
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   180
fun map_current f (State (Node {context, facts, mode, goal}, nodes)) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   181
  State (make_node (f (context, facts, mode, goal)), nodes);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   182
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   183
fun init_state thy =
5875
6aae55ae3473 renamed init_context to init;
wenzelm
parents: 5820
diff changeset
   184
  State (make_node (ProofContext.init thy, None, Forward, None), []);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   185
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   186
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   187
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   188
(** basic proof state operations **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   189
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   190
(* context *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   191
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   192
fun context_of (State (Node {context, ...}, _)) = context;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   193
val theory_of = ProofContext.theory_of o context_of;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   194
val sign_of = ProofContext.sign_of o context_of;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   195
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   196
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
   197
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   198
fun map_context_result f (state as State (Node {context, facts, mode, goal}, nodes)) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   199
  let val (context', result) = f context
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   200
  in (State (make_node (context', facts, mode, goal), nodes), result) end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   201
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   202
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   203
fun put_data kind f = map_context o ProofContext.put_data kind f;
7924
5fee69b1f5fe warn_extra_tfrees;
wenzelm
parents: 7669
diff changeset
   204
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
   205
val add_binds_i = map_context o ProofContext.add_binds_i;
6790
0a39f22f847a auto_bind_goal, auto_bind_facts;
wenzelm
parents: 6776
diff changeset
   206
val auto_bind_goal = map_context o ProofContext.auto_bind_goal;
6798
f6bc583a5776 tuned mode_name;
wenzelm
parents: 6790
diff changeset
   207
val auto_bind_facts = map_context oo ProofContext.auto_bind_facts;
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
   208
val put_thms = map_context o ProofContext.put_thms;
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
   209
val put_thmss = map_context o ProofContext.put_thmss;
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   210
val reset_thms = map_context o ProofContext.reset_thms;
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   211
val assumptions = ProofContext.assumptions o context_of;
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   212
val get_case = ProofContext.get_case o context_of;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   213
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   214
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   215
(* facts *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   216
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   217
fun the_facts (State (Node {facts = Some facts, ...}, _)) = facts
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   218
  | the_facts state = raise STATE ("No current facts available", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   219
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   220
fun the_fact state =
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   221
  (case the_facts state of
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   222
    [thm] => thm
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   223
  | _ => raise STATE ("Single fact expected", state));
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   224
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   225
fun assert_facts state = (the_facts state; state);
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   226
fun get_facts (State (Node {facts, ...}, _)) = facts;
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   227
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   228
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   229
val thisN = "this";
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   230
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   231
fun put_facts facts state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   232
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   233
  |> map_current (fn (ctxt, _, mode, goal) => (ctxt, facts, mode, goal))
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   234
  |> (case facts of None => reset_thms thisN | Some ths => put_thms (thisN, ths));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   235
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   236
val reset_facts = put_facts None;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   237
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   238
fun these_factss (state, named_factss) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   239
  state
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   240
  |> put_thmss named_factss
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   241
  |> put_facts (Some (flat (map #2 named_factss)));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   242
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   243
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   244
(* goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   245
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   246
local
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   247
  fun find i (state as State (Node {goal = Some goal, ...}, _)) = (context_of state, (i, goal))
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   248
    | find i (State (Node {goal = None, ...}, node :: nodes)) = find (i + 1) (State (node, nodes))
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   249
    | find _ (state as State (_, [])) = err_malformed "find_goal" state;
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   250
in val find_goal = find 0 end;
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   251
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   252
fun put_goal goal = map_current (fn (ctxt, facts, mode, _) => (ctxt, facts, mode, goal));
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   253
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   254
fun map_goal f g (State (Node {context, facts, mode, goal = Some goal}, nodes)) =
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   255
      State (make_node (f context, facts, mode, Some (g goal)), nodes)
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   256
  | map_goal f g (State (nd, node :: nodes)) =
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   257
      let val State (node', nodes') = map_goal f g (State (node, nodes))
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   258
      in map_context f (State (nd, node' :: nodes')) end
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   259
  | map_goal _ _ state = state;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   260
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   261
fun goal_facts get state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   262
  state
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   263
  |> map_goal I (fn ((result, (_, thm)), f) => ((result, (get state, thm)), f));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   264
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   265
fun use_facts state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   266
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   267
  |> goal_facts the_facts
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   268
  |> reset_facts;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   269
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   270
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   271
(* mode *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   272
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   273
fun get_mode (State (Node {mode, ...}, _)) = mode;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   274
fun put_mode mode = map_current (fn (ctxt, facts, _, goal) => (ctxt, facts, mode, goal));
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   275
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   276
val enter_forward = put_mode Forward;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   277
val enter_forward_chain = put_mode ForwardChain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   278
val enter_backward = put_mode Backward;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   279
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   280
fun assert_mode pred state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   281
  let val mode = get_mode state in
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   282
    if pred mode then state
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   283
    else raise STATE ("Illegal application of proof command in " ^ quote (mode_name mode) ^ " mode", state)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   284
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   285
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   286
fun is_chain state = get_mode state = ForwardChain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   287
val assert_forward = assert_mode (equal Forward);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   288
val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   289
val assert_backward = assert_mode (equal Backward);
8206
e50a130ec9af assert_no_chain;
wenzelm
parents: 8186
diff changeset
   290
val assert_no_chain = assert_mode (not_equal ForwardChain);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   291
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   292
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   293
(* blocks *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   294
6776
55f1e6b639a4 added the_fact, level;
wenzelm
parents: 6756
diff changeset
   295
fun level (State (_, nodes)) = length nodes;
55f1e6b639a4 added the_fact, level;
wenzelm
parents: 6756
diff changeset
   296
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   297
fun open_block (State (node, nodes)) = State (node, node :: nodes);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   298
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   299
fun new_block state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   300
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   301
  |> open_block
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   302
  |> put_goal None;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   303
7487
c0f9b956a3e7 close_block: removed ProofContext.transfer_used_names;
wenzelm
parents: 7478
diff changeset
   304
fun close_block (state as State (_, node :: nodes)) = State (node, nodes)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   305
  | close_block state = raise STATE ("Unbalanced block parentheses", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   306
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   307
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   308
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   309
(** print_state **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   310
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   311
val show_hyps = ProofContext.show_hyps;
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   312
val pretty_thm = ProofContext.pretty_thm;
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   313
7412
35ebe1452c10 removed the_fact;
wenzelm
parents: 7271
diff changeset
   314
fun pretty_thms [th] = pretty_thm th
7580
536499cf71af tuned pretty_thms;
wenzelm
parents: 7575
diff changeset
   315
  | pretty_thms ths = Pretty.blk (0, Pretty.fbreaks (map pretty_thm ths));
7412
35ebe1452c10 removed the_fact;
wenzelm
parents: 7271
diff changeset
   316
35ebe1452c10 removed the_fact;
wenzelm
parents: 7271
diff changeset
   317
6529
0f4c2ebc5018 improved print_state;
wenzelm
parents: 6404
diff changeset
   318
val verbose = ProofContext.verbose;
0f4c2ebc5018 improved print_state;
wenzelm
parents: 6404
diff changeset
   319
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   320
fun pretty_facts _ None = []
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   321
  | pretty_facts s (Some ths) =
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   322
      [Pretty.big_list (s ^ "this:") (map pretty_thm ths), Pretty.str ""];
6756
fe6eb161df3e improved print_state;
wenzelm
parents: 6752
diff changeset
   323
7201
59b9b7aec3c5 tuned print_state;
wenzelm
parents: 7176
diff changeset
   324
fun print_state nr (state as State (Node {context, facts, mode, goal = _}, nodes)) =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   325
  let
5945
63184e276c1d print_state: use begin_goal from Goals.current_goals_markers;
wenzelm
parents: 5936
diff changeset
   326
    val ref (_, _, begin_goal) = Goals.current_goals_markers;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   327
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   328
    fun levels_up 0 = ""
7575
e1e2d07287d8 improved output;
wenzelm
parents: 7556
diff changeset
   329
      | levels_up 1 = ", 1 level up"
e1e2d07287d8 improved output;
wenzelm
parents: 7556
diff changeset
   330
      | levels_up i = ", " ^ string_of_int i ^ " levels up";
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   331
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   332
    fun pretty_goal (_, (i, (((kind, name, _), (goal_facts, thm)), _))) =
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   333
      pretty_facts "using "
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   334
        (if mode <> Backward orelse null goal_facts then None else Some goal_facts) @
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   335
      [Pretty.str ("goal (" ^ kind_name kind ^ (if name = "" then "" else " " ^ name) ^
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   336
        levels_up (i div 2) ^ "):")] @
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   337
      Locale.pretty_goals_marker begin_goal (! goals_limit) thm;
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   338
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   339
    val ctxt_prts =
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   340
      if ! verbose orelse mode = Forward then ProofContext.pretty_context context
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   341
      else if mode = Backward then ProofContext.pretty_prems context
7575
e1e2d07287d8 improved output;
wenzelm
parents: 7556
diff changeset
   342
      else [];
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   343
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   344
    val prts =
8582
3051aa8aa412 tuned output;
wenzelm
parents: 8561
diff changeset
   345
     [Pretty.str ("proof (" ^ mode_name mode ^ "): step " ^ string_of_int nr ^
8561
2675e2f4dc61 tuned output;
wenzelm
parents: 8542
diff changeset
   346
        (if ! verbose then ", depth " ^ string_of_int (length nodes div 2)
2675e2f4dc61 tuned output;
wenzelm
parents: 8542
diff changeset
   347
        else "")), Pretty.str ""] @
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   348
     (if null ctxt_prts then [] else ctxt_prts @ [Pretty.str ""]) @
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   349
     (if ! verbose orelse mode = Forward then
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   350
       (pretty_facts "" facts @ pretty_goal (find_goal state))
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   351
      else if mode = ForwardChain then pretty_facts "picking " facts
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   352
      else pretty_goal (find_goal state))
8462
7f4e4e875c13 pretty chunks;
wenzelm
parents: 8450
diff changeset
   353
  in Pretty.writeln (Pretty.chunks prts) end;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   354
10360
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   355
fun pretty_goals main_goal state =
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   356
  let val (_, (_, ((_, (_, thm)), _))) = find_goal state
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   357
  in Locale.pretty_sub_goals main_goal (! goals_limit) thm end;
10320
26d4b84eb047 added pretty_goals;
wenzelm
parents: 9482
diff changeset
   358
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   359
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   360
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   361
(** proof steps **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   362
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   363
(* datatype method *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   364
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   365
datatype method =
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   366
  Method of thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq;
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   367
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   368
fun method tac = Method (fn facts => fn st => Seq.map (rpair []) (tac facts st));
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   369
val method_cases = Method;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   370
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   371
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   372
(* refine goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   373
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   374
local
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   375
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   376
fun check_sign sg state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   377
  if Sign.subsig (sg, sign_of state) then state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   378
  else raise STATE ("Bad signature of result: " ^ Sign.str_of_sg sg, state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   379
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   380
fun gen_refine current_context meth_fun state =
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   381
  let
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   382
    val (goal_ctxt, (_, ((result, (facts, thm)), f))) = find_goal state;
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   383
    val Method meth = meth_fun (if current_context then context_of state else goal_ctxt);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   384
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   385
    fun refn (thm', cases) =
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   386
      state
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   387
      |> check_sign (Thm.sign_of_thm thm')
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   388
      |> map_goal (ProofContext.add_cases cases) (K ((result, (facts, thm')), f));
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   389
  in Seq.map refn (meth facts thm) end;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   390
8234
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   391
in
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   392
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   393
val refine = gen_refine true;
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   394
val refine_end = gen_refine false;
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   395
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   396
end;
36a85a6c4852 refine_end;
wenzelm
parents: 8206
diff changeset
   397
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   398
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   399
(* tacticals *)
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   400
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   401
fun RANGE [] _ = all_tac
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   402
  | RANGE (tac :: tacs) i = RANGE tacs (i + 1) THEN tac i;
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   403
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   404
fun FINDGOAL tac st =
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   405
  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
   406
  in find (1, Thm.nprems_of st) st end;
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   407
8166
97414b447a02 added HEADGOAL;
wenzelm
parents: 8152
diff changeset
   408
fun HEADGOAL tac = tac 1;
97414b447a02 added HEADGOAL;
wenzelm
parents: 8152
diff changeset
   409
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   410
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   411
(* export results *)
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   412
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   413
fun export_goal print_rule raw_rule inner state =
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   414
  let
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   415
    val (outer, (_, ((result, (facts, thm)), f))) = find_goal state;
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   416
    val (exp_tac, tacs) = ProofContext.export_wrt true inner (Some outer);
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   417
    fun exp_rule rule =
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   418
      let
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   419
        val _ = print_rule rule;
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   420
        val thmq = FINDGOAL (Tactic.rtac rule THEN' RANGE tacs) thm;
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   421
      in Seq.map (fn th => map_goal I (K ((result, (facts, th)), f)) state) thmq end;
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   422
  in raw_rule |> exp_tac |> (Seq.flat o Seq.map exp_rule) end;
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   423
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   424
fun export_thm inner thm =
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   425
  let val (exp_tac, tacs) = ProofContext.export_wrt false inner None in
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   426
    (case Seq.chop (2, (exp_tac THEN RANGE tacs 1) thm) of
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   427
      ([thm'], _) => thm'
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   428
    | ([], _) => raise THM ("export: failed", 0, [thm])
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   429
    | _ => raise THM ("export: more than one result", 0, [thm]))
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   430
  end;
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   431
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   432
fun transfer_facts inner_state state =
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   433
  (case get_facts inner_state of
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   434
    None => Seq.single (reset_facts state)
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   435
  | Some thms =>
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   436
      let
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   437
        val (exp_tac, tacs) =
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   438
          ProofContext.export_wrt false (context_of inner_state) (Some (context_of state));
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   439
        val thmqs = map (exp_tac THEN RANGE tacs 1) thms;
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   440
      in Seq.map (fn ths => put_facts (Some ths) state) (Seq.commute thmqs) end);
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   441
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   442
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   443
(* prepare result *)
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   444
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   445
fun prep_result state t raw_thm =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   446
  let
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   447
    val ctxt = context_of state;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   448
    fun err msg = raise STATE (msg, state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   449
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   450
    val ngoals = Thm.nprems_of raw_thm;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   451
    val _ =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   452
      if ngoals = 0 then ()
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   453
      else (Locale.print_goals ngoals raw_thm; err (string_of_int ngoals ^ " unsolved goal(s)!"));
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   454
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   455
    val thm = raw_thm RS Drule.rev_triv_goal;
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   456
    val {hyps, prop, sign, ...} = Thm.rep_thm thm;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   457
    val tsig = Sign.tsig_of sign;
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   458
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   459
    val casms = flat (map #1 (assumptions state));
6996
1a28d968c5aa handle cgoal;
wenzelm
parents: 6982
diff changeset
   460
    val bad_hyps = Library.gen_rems Term.aconv (hyps, map (Thm.term_of o Drule.mk_cgoal) casms);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   461
  in
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   462
    if not (null bad_hyps) then
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   463
      err ("Additional hypotheses:\n" ^ cat_lines (map (Sign.string_of_term sign) bad_hyps))
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   464
    else if not (Pattern.matches (Sign.tsig_of (sign_of state)) (t, prop)) then
7605
8bbfcb54054e added reset_thms;
wenzelm
parents: 7580
diff changeset
   465
      err ("Proved a different theorem: " ^ Sign.string_of_term sign prop)
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   466
    else thm
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   467
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   468
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   469
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   470
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   471
(*** structured proof commands ***)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   472
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   473
(** context **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   474
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   475
(* bind *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   476
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   477
fun gen_bind f x state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   478
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   479
  |> assert_forward
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   480
  |> map_context (f x)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   481
  |> reset_facts;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   482
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   483
val match_bind = gen_bind (ProofContext.match_bind false);
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   484
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
   485
val let_bind = gen_bind (ProofContext.match_bind true);
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   486
val let_bind_i = gen_bind (ProofContext.match_bind_i true);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   487
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   488
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   489
(* have_thmss etc. *)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   490
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   491
fun have_thmss args state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   492
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   493
  |> assert_forward
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   494
  |> map_context_result (ProofContext.have_thmss args)
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   495
  |> these_factss;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   496
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   497
fun simple_have_thms name thms = have_thmss [((name, []), [(thms, [])])];
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   498
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   499
fun with_thmss args state =
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   500
  let val state' = state |> have_thmss args
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   501
  in state' |> simple_have_thms "" (the_facts state' @ the_facts state) end;
6876
4ae9c47f2b6b have_thmss: more_ths;
wenzelm
parents: 6871
diff changeset
   502
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   503
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   504
(* fix *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   505
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   506
fun gen_fix f xs state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   507
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   508
  |> assert_forward
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   509
  |> map_context (f xs)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   510
  |> reset_facts;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   511
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   512
val fix = gen_fix ProofContext.fix;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   513
val fix_i = gen_fix ProofContext.fix_i;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   514
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   515
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   516
(* assume *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   517
10446
e7a8fc009d37 norm_hhf_tac;
wenzelm
parents: 10406
diff changeset
   518
val hard_asm_tac = Tactic.etac Drule.triv_goal;
10809
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   519
val soft_asm_tac = Tactic.rtac Drule.triv_goal THEN' Tactic.norm_hhf_tac;
10446
e7a8fc009d37 norm_hhf_tac;
wenzelm
parents: 10406
diff changeset
   520
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   521
local
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   522
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   523
fun gen_assume f exp args state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   524
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   525
  |> assert_forward
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   526
  |> map_context_result (f exp args)
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   527
  |> (fn (st, (factss, prems)) =>
9196
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   528
    these_factss (st, factss)
1f6f66fe777a facts: handle multiple lists of arguments;
wenzelm
parents: 8991
diff changeset
   529
    |> put_thms ("prems", prems));
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   530
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   531
fun simple_exporter tac1 tac2 =
10809
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   532
  (Seq.single oo Drule.implies_intr_list, fn is_goal => fn n =>
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   533
    replicate n (Tactic.norm_hhf_tac THEN' (if is_goal then tac1 else tac2)));
6996
1a28d968c5aa handle cgoal;
wenzelm
parents: 6982
diff changeset
   534
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   535
in
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   536
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   537
val assm = gen_assume ProofContext.assume;
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   538
val assm_i = gen_assume ProofContext.assume_i;
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   539
val assume = assm (simple_exporter hard_asm_tac soft_asm_tac);
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   540
val assume_i = assm_i (simple_exporter hard_asm_tac soft_asm_tac);
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   541
val presume = assm (simple_exporter soft_asm_tac soft_asm_tac);
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   542
val presume_i = assm_i (simple_exporter soft_asm_tac soft_asm_tac);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   543
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   544
end;
442456b2a8bb assume: multiple args;
wenzelm
parents: 7201
diff changeset
   545
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   546
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   547
(* invoke_case *)
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   548
8450
dc44d6533f0f invoke_case: include attributes;
wenzelm
parents: 8383
diff changeset
   549
fun invoke_case (name, atts) state =
9292
c5875175751f invoke_case: bind_skolem;
wenzelm
parents: 9196
diff changeset
   550
  let
10809
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   551
    val (fixes, lets, asms) = ProofContext.apply_case (context_of state) (get_case state name);
9292
c5875175751f invoke_case: bind_skolem;
wenzelm
parents: 9196
diff changeset
   552
  in
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   553
    state
10809
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   554
    |> fix_i (map (fn (x, T) => ([x], Some T)) fixes)
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   555
    |> add_binds_i lets
e827c779ae2e moved norm_hhf_tac to Pure/tactic.ML;
wenzelm
parents: 10553
diff changeset
   556
    |> assume_i [((name, atts), map (fn t => (t, ([], []))) asms)]
8374
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   557
  end;
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   558
ffb2eb084078 generalized FINDGOAL, HEADGOAL;
wenzelm
parents: 8239
diff changeset
   559
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   560
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   561
(** goals **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   562
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   563
(* forward chaining *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   564
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   565
fun chain state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   566
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   567
  |> assert_forward
6848
3d82756e1af5 tuned print_state;
wenzelm
parents: 6798
diff changeset
   568
  |> assert_facts
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   569
  |> enter_forward_chain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   570
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   571
fun from_facts facts state =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   572
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   573
  |> put_facts (Some facts)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   574
  |> chain;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   575
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   576
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   577
(* setup goals *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   578
8991
dc70b797827f case 'antecedent';
wenzelm
parents: 8807
diff changeset
   579
val antN = "antecedent";
dc70b797827f case 'antecedent';
wenzelm
parents: 8807
diff changeset
   580
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   581
fun setup_goal opt_block prepp kind after_qed name atts raw_propp state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   582
  let
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
   583
    val (state', ([[prop]], gen_binds)) =
5936
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   584
      state
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   585
      |> assert_forward_or_chain
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   586
      |> enter_forward
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   587
      |> opt_block
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10446
diff changeset
   588
      |> map_context_result (fn ct => prepp (ct, [[raw_propp]]));
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   589
    val cprop = Thm.cterm_of (sign_of state') prop;
7556
f3e78ebcf6ba setup_goal: do not insert assumptions;
wenzelm
parents: 7487
diff changeset
   590
    val goal = Drule.mk_triv_goal cprop;
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   591
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   592
    val tvars = Term.term_tvars prop;
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   593
    val vars = Term.term_vars prop;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   594
  in
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   595
    if null tvars then ()
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   596
    else raise STATE ("Goal statement contains illegal schematic type variable(s): " ^
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   597
      commas (map (Syntax.string_of_vname o #1) tvars), state);
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   598
    if null vars then ()
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   599
    else warning ("Goal statement contains unbound schematic variable(s): " ^
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   600
      commas (map (Sign.string_of_term (sign_of state)) vars));
5936
406eb27fe53c match_bind(_i): 'as' patterns;
wenzelm
parents: 5918
diff changeset
   601
    state'
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   602
    |> put_goal (Some (((kind atts, name, prop), ([], goal)), after_qed o map_context gen_binds))
10406
1820abac64fe RuleCases.make true;
wenzelm
parents: 10380
diff changeset
   603
    |> map_context (ProofContext.add_cases (RuleCases.make true goal [antN]))
6790
0a39f22f847a auto_bind_goal, auto_bind_facts;
wenzelm
parents: 6776
diff changeset
   604
    |> auto_bind_goal prop
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   605
    |> (if is_chain state then use_facts else reset_facts)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   606
    |> new_block
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   607
    |> enter_backward
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   608
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   609
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   610
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   611
(*global goals*)
8095
wenzelm
parents: 7928
diff changeset
   612
fun global_goal prepp kind name atts x thy =
wenzelm
parents: 7928
diff changeset
   613
  setup_goal I prepp kind Seq.single name atts x (init_state thy);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   614
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   615
val theorem = global_goal ProofContext.bind_propp_schematic Theorem;
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   616
val theorem_i = global_goal ProofContext.bind_propp_schematic_i Theorem;
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   617
val lemma = global_goal ProofContext.bind_propp_schematic Lemma;
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   618
val lemma_i = global_goal ProofContext.bind_propp_schematic_i Lemma;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   619
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   620
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   621
(*local goals*)
8095
wenzelm
parents: 7928
diff changeset
   622
fun local_goal prepp kind f name atts args state =
7928
06a11f8cf573 improved handling of warn_extra_tfrees;
wenzelm
parents: 7924
diff changeset
   623
  state
8095
wenzelm
parents: 7928
diff changeset
   624
  |> setup_goal open_block prepp kind f name atts args
7928
06a11f8cf573 improved handling of warn_extra_tfrees;
wenzelm
parents: 7924
diff changeset
   625
  |> warn_extra_tfrees state;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   626
10380
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   627
val show   = local_goal ProofContext.bind_propp Show;
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   628
val show_i = local_goal ProofContext.bind_propp_i Show;
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   629
val have   = local_goal ProofContext.bind_propp Have;
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   630
val have_i = local_goal ProofContext.bind_propp_i Have;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   631
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   632
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   633
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   634
(** conclusions **)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   635
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   636
(* current goal *)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   637
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   638
fun current_goal (State (Node {context, goal = Some goal, ...}, _)) = (context, goal)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   639
  | current_goal state = raise STATE ("No current goal!", state);
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   640
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   641
fun assert_current_goal true (state as State (Node {goal = None, ...}, _)) =
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   642
      raise STATE ("No goal in this block!", state)
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   643
  | assert_current_goal false (state as State (Node {goal = Some _, ...}, _)) =
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   644
      raise STATE ("Goal present in this block!", state)
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   645
  | assert_current_goal _ state = state;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   646
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   647
fun assert_bottom true (state as State (_, _ :: _)) =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   648
      raise STATE ("Not at bottom of proof!", state)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   649
  | assert_bottom false (state as State (_, [])) =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   650
      raise STATE ("Already at bottom of proof!", state)
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   651
  | assert_bottom _ state = state;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   652
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   653
val at_bottom = can (assert_bottom true o close_block);
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   654
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   655
fun end_proof bot state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   656
  state
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   657
  |> assert_forward
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   658
  |> close_block
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   659
  |> assert_bottom bot
7011
7e8e9a26ba2c export init_state;
wenzelm
parents: 6996
diff changeset
   660
  |> assert_current_goal true
7e8e9a26ba2c export init_state;
wenzelm
parents: 6996
diff changeset
   661
  |> goal_facts (K []);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   662
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   663
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   664
(* local_qed *)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   665
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   666
fun finish_local (print_result, print_rule) state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   667
  let
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   668
    val (goal_ctxt, (((kind, name, t), (_, raw_thm)), after_qed)) = current_goal state;
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   669
    val outer_state = state |> close_block;
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   670
    val outer_ctxt = context_of outer_state;
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   671
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   672
    val result = prep_result state t raw_thm;
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   673
    val resultq = #1 (ProofContext.export_wrt false goal_ctxt (Some outer_ctxt)) result;
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   674
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   675
    val (atts, opt_solve) =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   676
      (case kind of
10380
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   677
        Show atts => (atts, export_goal print_rule result goal_ctxt)
e5370304d893 tuned names;
wenzelm
parents: 10360
diff changeset
   678
      | Have atts => (atts, Seq.single)
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   679
      | _ => err_malformed "finish_local" state);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   680
  in
6731
57e761134c85 cleaned comments;
wenzelm
parents: 6683
diff changeset
   681
    print_result {kind = kind_name kind, name = name, thm = result};
8617
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   682
    outer_state
33e2bd53aec3 support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents: 8582
diff changeset
   683
    |> auto_bind_facts name [ProofContext.generalize goal_ctxt outer_ctxt t]
9469
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   684
    |> (fn st => Seq.map (fn res =>
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   685
      have_thmss [((name, atts), [Thm.no_attributes [res]])] st) resultq)
8058d285b1cd export RANGE, hard_asm_tac, soft_asm_tac;
wenzelm
parents: 9292
diff changeset
   686
    |> (Seq.flat o Seq.map opt_solve)
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   687
    |> (Seq.flat o Seq.map after_qed)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   688
  end;
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   689
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   690
fun local_qed finalize print state =
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   691
  state
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   692
  |> end_proof false
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   693
  |> finalize
6982
4d2a3f35af93 added show_hyps flag;
wenzelm
parents: 6950
diff changeset
   694
  |> (Seq.flat o Seq.map (finish_local print));
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   695
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   696
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6262
diff changeset
   697
(* global_qed *)
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   698
10508
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   699
val name_refN = "name_ref";
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   700
6950
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   701
fun finish_global state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   702
  let
7176
a329a37ed91a local goals: after_qed;
wenzelm
parents: 7011
diff changeset
   703
    val (_, (((kind, name, t), (_, raw_thm)), _)) = current_goal state;   (*ignores after_qed!*)
10508
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   704
    val full_name = if name = "" then "" else Sign.full_name (sign_of state) name;
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   705
    val result =
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   706
      prep_result state t raw_thm
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   707
      |> Drule.standard
6306977d867b tag result with name reference to final binding (basically just a comment);
wenzelm
parents: 10464
diff changeset
   708
      |> Drule.tag_rule (name_refN, [full_name]);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   709
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   710
    val atts =
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   711
      (case kind of
6950
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   712
        Theorem atts => atts
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   713
      | Lemma atts => atts @ [Drule.tag_lemma]
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   714
      | _ => err_malformed "finish_global" state);
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   715
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 6030
diff changeset
   716
    val (thy', result') = PureThy.store_thm ((name, result), atts) (theory_of state);
6529
0f4c2ebc5018 improved print_state;
wenzelm
parents: 6404
diff changeset
   717
  in (thy', {kind = kind_name kind, name = name, thm = result'}) end;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   718
10553
7f239ef89c50 removed get_goal;
wenzelm
parents: 10508
diff changeset
   719
(*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
   720
fun global_qed finalize state =
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   721
  state
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   722
  |> end_proof true
6871
01866edde713 added check_result;
wenzelm
parents: 6853
diff changeset
   723
  |> finalize
6950
ab6d35b7283f global_qed: removed alt_name, alt_att;
wenzelm
parents: 6932
diff changeset
   724
  |> Seq.map finish_global;
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   725
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   726
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   727
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   728
(** blocks **)
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   729
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   730
(* begin_block *)
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   731
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   732
fun begin_block state =
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   733
  state
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   734
  |> assert_forward
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   735
  |> new_block
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   736
  |> open_block;
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   737
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   738
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   739
(* end_block *)
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   740
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   741
fun end_block state =
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   742
  state
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   743
  |> assert_forward
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   744
  |> close_block
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   745
  |> assert_current_goal false
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   746
  |> close_block
6932
77c14313af51 propp: 'concl' patterns;
wenzelm
parents: 6896
diff changeset
   747
  |> transfer_facts state;
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   748
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   749
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   750
(* next_block *)
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   751
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   752
fun next_block state =
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   753
  state
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   754
  |> assert_forward
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   755
  |> close_block
8718
3ba75b7e1168 next_block: reset_facts;
wenzelm
parents: 8670
diff changeset
   756
  |> new_block
3ba75b7e1168 next_block: reset_facts;
wenzelm
parents: 8670
diff changeset
   757
  |> reset_facts;
6896
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   758
4bdc3600ddae close_block: transfer_used_names;
wenzelm
parents: 6891
diff changeset
   759
5820
ff3c82b47603 Proof states and methods.
wenzelm
parents:
diff changeset
   760
end;
8152
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   761
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   762
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   763
structure BasicProof: BASIC_PROOF = Proof;
ce3387fafebb replaced FIRSTGOAL by FINDGOAL (backtracking!);
wenzelm
parents: 8095
diff changeset
   764
open BasicProof;