src/Pure/Isar/obtain.ML
changeset 36323 655e2d74de3a
parent 35845 e5980f0ad025
child 38875 c7a66b584147
equal deleted inserted replaced
36322:81cba3921ba5 36323:655e2d74de3a
    37 *)
    37 *)
    38 
    38 
    39 signature OBTAIN =
    39 signature OBTAIN =
    40 sig
    40 sig
    41   val thatN: string
    41   val thatN: string
    42   val obtain: string -> (binding * string option * mixfix) list ->
    42   val obtain: string -> (binding * typ option * mixfix) list ->
       
    43     (Thm.binding * (term * term list) list) list -> bool -> Proof.state -> Proof.state
       
    44   val obtain_cmd: string -> (binding * string option * mixfix) list ->
    43     (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
    45     (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
    44   val obtain_i: string -> (binding * typ option * mixfix) list ->
       
    45     (Thm.binding * (term * term list) list) list -> bool -> Proof.state -> Proof.state
       
    46   val result: (Proof.context -> tactic) -> thm list -> Proof.context ->
    46   val result: (Proof.context -> tactic) -> thm list -> Proof.context ->
    47     ((string * cterm) list * thm list) * Proof.context
    47     ((string * cterm) list * thm list) * Proof.context
    48   val guess: (binding * string option * mixfix) list -> bool -> Proof.state -> Proof.state
    48   val guess: (binding * typ option * mixfix) list -> bool -> Proof.state -> Proof.state
    49   val guess_i: (binding * typ option * mixfix) list -> bool -> Proof.state -> Proof.state
    49   val guess_cmd: (binding * string option * mixfix) list -> bool -> Proof.state -> Proof.state
    50 end;
    50 end;
    51 
    51 
    52 structure Obtain: OBTAIN =
    52 structure Obtain: OBTAIN =
    53 struct
    53 struct
    54 
    54 
   146         Term.list_all_free ([thesis_var], Logic.mk_implies (that_prop, thesis)));
   146         Term.list_all_free ([thesis_var], Logic.mk_implies (that_prop, thesis)));
   147 
   147 
   148     fun after_qed _ =
   148     fun after_qed _ =
   149       Proof.local_qed (NONE, false)
   149       Proof.local_qed (NONE, false)
   150       #> `Proof.the_fact #-> (fn rule =>
   150       #> `Proof.the_fact #-> (fn rule =>
   151         Proof.fix_i vars
   151         Proof.fix vars
   152         #> Proof.assm_i (obtain_export fix_ctxt rule (map (cert o Free) parms)) asms);
   152         #> Proof.assm (obtain_export fix_ctxt rule (map (cert o Free) parms)) asms);
   153   in
   153   in
   154     state
   154     state
   155     |> Proof.enter_forward
   155     |> Proof.enter_forward
   156     |> Proof.have_i NONE (K I) [(Thm.empty_binding, [(obtain_prop, [])])] int
   156     |> Proof.have NONE (K I) [(Thm.empty_binding, [(obtain_prop, [])])] int
   157     |> Proof.proof (SOME Method.succeed_text) |> Seq.hd
   157     |> Proof.proof (SOME Method.succeed_text) |> Seq.hd
   158     |> Proof.fix_i [(Binding.name thesisN, NONE, NoSyn)]
   158     |> Proof.fix [(Binding.name thesisN, NONE, NoSyn)]
   159     |> Proof.assume_i
   159     |> Proof.assume
   160       [((Binding.name that_name, [Context_Rules.intro_query NONE]), [(that_prop, [])])]
   160       [((Binding.name that_name, [Context_Rules.intro_query NONE]), [(that_prop, [])])]
   161     |> `Proof.the_facts
   161     |> `Proof.the_facts
   162     ||> Proof.chain_facts chain_facts
   162     ||> Proof.chain_facts chain_facts
   163     ||> Proof.show_i NONE after_qed [(Thm.empty_binding, [(thesis, [])])] false
   163     ||> Proof.show NONE after_qed [(Thm.empty_binding, [(thesis, [])])] false
   164     |-> Proof.refine_insert
   164     |-> Proof.refine_insert
   165   end;
   165   end;
   166 
   166 
   167 in
   167 in
   168 
   168 
   169 val obtain = gen_obtain Attrib.attribute ProofContext.read_vars ProofContext.read_propp;
   169 val obtain = gen_obtain (K I) ProofContext.cert_vars ProofContext.cert_propp;
   170 val obtain_i = gen_obtain (K I) ProofContext.cert_vars ProofContext.cert_propp;
   170 val obtain_cmd = gen_obtain Attrib.attribute ProofContext.read_vars ProofContext.read_propp;
   171 
   171 
   172 end;
   172 end;
   173 
   173 
   174 
   174 
   175 
   175 
   288           |> map (fn asm => (Term.betapplys (Term.list_abs (ps, asm), ts), []));
   288           |> map (fn asm => (Term.betapplys (Term.list_abs (ps, asm), ts), []));
   289         val _ = not (null asms) orelse error "Trivial result -- nothing guessed";
   289         val _ = not (null asms) orelse error "Trivial result -- nothing guessed";
   290       in
   290       in
   291         state'
   291         state'
   292         |> Proof.map_context (K ctxt')
   292         |> Proof.map_context (K ctxt')
   293         |> Proof.fix_i (map (fn ((x, T), mx) => (Binding.name x, SOME T, mx)) parms)
   293         |> Proof.fix (map (fn ((x, T), mx) => (Binding.name x, SOME T, mx)) parms)
   294         |> `Proof.context_of |-> (fn fix_ctxt => Proof.assm_i
   294         |> `Proof.context_of |-> (fn fix_ctxt => Proof.assm
   295           (obtain_export fix_ctxt rule (map cert ts)) [(Thm.empty_binding, asms)])
   295           (obtain_export fix_ctxt rule (map cert ts)) [(Thm.empty_binding, asms)])
   296         |> Proof.bind_terms Auto_Bind.no_facts
   296         |> Proof.bind_terms Auto_Bind.no_facts
   297       end;
   297       end;
   298 
   298 
   299     val goal = Var (("guess", 0), propT);
   299     val goal = Var (("guess", 0), propT);
   305       Proof.end_block #> guess_context (check_result ctxt thesis res);
   305       Proof.end_block #> guess_context (check_result ctxt thesis res);
   306   in
   306   in
   307     state
   307     state
   308     |> Proof.enter_forward
   308     |> Proof.enter_forward
   309     |> Proof.begin_block
   309     |> Proof.begin_block
   310     |> Proof.fix_i [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)]
   310     |> Proof.fix [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)]
   311     |> Proof.chain_facts chain_facts
   311     |> Proof.chain_facts chain_facts
   312     |> Proof.local_goal print_result (K I) (apsnd (rpair I))
   312     |> Proof.local_goal print_result (K I) (apsnd (rpair I))
   313       "guess" before_qed after_qed [(Thm.empty_binding, [Logic.mk_term goal, goal])]
   313       "guess" before_qed after_qed [(Thm.empty_binding, [Logic.mk_term goal, goal])]
   314     |> Proof.refine (Method.primitive_text (K (Goal.init (cert thesis)))) |> Seq.hd
   314     |> Proof.refine (Method.primitive_text (K (Goal.init (cert thesis)))) |> Seq.hd
   315   end;
   315   end;
   316 
   316 
   317 in
   317 in
   318 
   318 
   319 val guess = gen_guess ProofContext.read_vars;
   319 val guess = gen_guess ProofContext.cert_vars;
   320 val guess_i = gen_guess ProofContext.cert_vars;
   320 val guess_cmd = gen_guess ProofContext.read_vars;
   321 
   321 
   322 end;
   322 end;
   323 
   323 
   324 end;
   324 end;