src/Pure/Isar/method.ML
changeset 6091 e3cdbd929a24
parent 5921 50005d6ba609
child 6104 55c7f8f0bb4d
equal deleted inserted replaced
6090:78c068b838ff 6091:e3cdbd929a24
    12 end;
    12 end;
    13 
    13 
    14 signature METHOD =
    14 signature METHOD =
    15 sig
    15 sig
    16   include BASIC_METHOD
    16   include BASIC_METHOD
    17   val LIFT: tactic -> thm -> (thm * (indexname * term) list * (string * tthm list) list) Seq.seq
    17   val LIFT: tactic -> thm -> (thm * (indexname * term) list * (string * thm list) list) Seq.seq
    18   val METHOD: (tthm list -> tactic) -> Proof.method
    18   val METHOD: (thm list -> tactic) -> Proof.method
    19   val METHOD0: tactic -> Proof.method
    19   val METHOD0: tactic -> Proof.method
    20   val fail: Proof.method
    20   val fail: Proof.method
    21   val succeed: Proof.method
    21   val succeed: Proof.method
    22   val trivial: Proof.method
    22   val trivial: Proof.method
    23   val assumption: Proof.method
    23   val assumption: Proof.method
    24   val forward_chain: thm list -> thm list -> thm Seq.seq
    24   val forward_chain: thm list -> thm list -> thm Seq.seq
    25   val rule_tac: tthm list -> tthm list -> int -> tactic
    25   val rule_tac: thm list -> thm list -> int -> tactic
    26   val rule: tthm list -> Proof.method
    26   val rule: thm list -> Proof.method
    27   exception METHOD_FAIL of (string * Position.T) * exn
    27   exception METHOD_FAIL of (string * Position.T) * exn
    28   val method: theory -> Args.src -> Proof.context -> Proof.method
    28   val method: theory -> Args.src -> Proof.context -> Proof.method
    29   val add_methods: (bstring * (Args.src -> Proof.context -> Proof.method) * string) list
    29   val add_methods: (bstring * (Args.src -> Proof.context -> Proof.method) * string) list
    30     -> theory -> theory
    30     -> theory -> theory
    31   val syntax: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list)) ->
    31   val syntax: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list)) ->
    38   val default_sectioned_args: Proof.context attribute ->
    38   val default_sectioned_args: Proof.context attribute ->
    39     (Args.T list -> Proof.context attribute * Args.T list) list ->
    39     (Args.T list -> Proof.context attribute * Args.T list) list ->
    40     (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    40     (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    41   val only_sectioned_args: (Args.T list -> Proof.context attribute * Args.T list) list ->
    41   val only_sectioned_args: (Args.T list -> Proof.context attribute * Args.T list) list ->
    42     (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    42     (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    43   val thms_args: (tthm list -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    43   val thms_args: (thm list -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    44   datatype text =
    44   datatype text =
    45     Basic of (Proof.context -> Proof.method) |
    45     Basic of (Proof.context -> Proof.method) |
    46     Source of Args.src |
    46     Source of Args.src |
    47     Then of text list |
    47     Then of text list |
    48     Orelse of text list |
    48     Orelse of text list |
    57   val end_block: Proof.state -> Proof.state Seq.seq
    57   val end_block: Proof.state -> Proof.state Seq.seq
    58   val terminal_proof: text -> Proof.state -> Proof.state Seq.seq
    58   val terminal_proof: text -> Proof.state -> Proof.state Seq.seq
    59   val trivial_proof: Proof.state -> Proof.state Seq.seq
    59   val trivial_proof: Proof.state -> Proof.state Seq.seq
    60   val default_proof: Proof.state -> Proof.state Seq.seq
    60   val default_proof: Proof.state -> Proof.state Seq.seq
    61   val qed: bstring option -> theory attribute list option -> Proof.state
    61   val qed: bstring option -> theory attribute list option -> Proof.state
    62     -> theory * (string * string * tthm)
    62     -> theory * (string * string * thm)
    63   val setup: (theory -> theory) list
    63   val setup: (theory -> theory) list
    64 end;
    64 end;
    65 
    65 
    66 structure Method: METHOD =
    66 structure Method: METHOD =
    67 struct
    67 struct
    84 
    84 
    85 (* trivial, assumption *)
    85 (* trivial, assumption *)
    86 
    86 
    87 fun trivial_tac [] = K all_tac
    87 fun trivial_tac [] = K all_tac
    88   | trivial_tac facts =
    88   | trivial_tac facts =
    89       let
    89       let val r = ~ (length facts);
    90         val thms = Attribute.thms_of facts;
    90       in metacuts_tac facts THEN' rotate_tac r end;
    91         val r = ~ (length facts);
       
    92       in metacuts_tac thms THEN' rotate_tac r end;
       
    93 
    91 
    94 val trivial = METHOD (ALLGOALS o trivial_tac);
    92 val trivial = METHOD (ALLGOALS o trivial_tac);
    95 val assumption = METHOD (fn facts => FIRSTGOAL (trivial_tac facts THEN' assume_tac));
    93 val assumption = METHOD (fn facts => FIRSTGOAL (trivial_tac facts THEN' assume_tac));
    96 
    94 
    97 val asm_finish = METHOD (K (TRYALL assume_tac));
    95 val asm_finish = METHOD (K (TRYALL assume_tac));
   107       | multi_res i (th :: ths) = Seq.flat (Seq.map (res th i) (multi_res (i + 1) ths))
   105       | multi_res i (th :: ths) = Seq.flat (Seq.map (res th i) (multi_res (i + 1) ths))
   108   in multi_res 1 facts end;
   106   in multi_res 1 facts end;
   109 
   107 
   110 fun forward_chain facts rules = Seq.flat (Seq.map (multi_resolve facts) (Seq.of_list rules));
   108 fun forward_chain facts rules = Seq.flat (Seq.map (multi_resolve facts) (Seq.of_list rules));
   111 
   109 
   112 fun rule_tac rules [] = resolve_tac (Attribute.thms_of rules)
   110 fun rule_tac rules [] = resolve_tac rules
   113   | rule_tac erules facts =
   111   | rule_tac erules facts =
   114       let
   112       let
   115         val rules = forward_chain (Attribute.thms_of facts) (Attribute.thms_of erules);
   113         val rules = forward_chain facts erules;
   116         fun tac i state = Seq.flat (Seq.map (fn rule => Tactic.rtac rule i state) rules);
   114         fun tac i state = Seq.flat (Seq.map (fn rule => Tactic.rtac rule i state) rules);
   117       in tac end;
   115       in tac end;
   118 
   116 
   119 fun rule rules = METHOD (FIRSTGOAL o rule_tac rules);
   117 fun rule rules = METHOD (FIRSTGOAL o rule_tac rules);
   120 
   118 
   207 
   205 
   208 fun sect ss = Scan.first (map (fn s => Scan.lift (s --| Args.$$$ ":")) ss);
   206 fun sect ss = Scan.first (map (fn s => Scan.lift (s --| Args.$$$ ":")) ss);
   209 fun thms ss = Scan.unless (sect ss) Attrib.local_thms;
   207 fun thms ss = Scan.unless (sect ss) Attrib.local_thms;
   210 fun thmss ss = Scan.repeat (thms ss) >> flat;
   208 fun thmss ss = Scan.repeat (thms ss) >> flat;
   211 
   209 
   212 fun apply att (ctxt, ths) = Attribute.applys ((ctxt, ths), [att]);
   210 fun apply att (ctxt, ths) = Thm.applys_attributes ((ctxt, ths), [att]);
   213 
   211 
   214 fun section ss = (sect ss -- thmss ss) :-- (fn (att, ths) => Scan.depend (fn ctxt =>
   212 fun section ss = (sect ss -- thmss ss) :-- (fn (att, ths) => Scan.depend (fn ctxt =>
   215   Scan.succeed (apply att (ctxt, ths)))) >> #2;
   213   Scan.succeed (apply att (ctxt, ths)))) >> #2;
   216 
   214 
   217 fun sectioned args ss = args ss -- Scan.repeat (section ss);
   215 fun sectioned args ss = args ss -- Scan.repeat (section ss);