301 | map_goal f g (State (nd, node :: nodes)) = |
301 | map_goal f g (State (nd, node :: nodes)) = |
302 let val State (node', nodes') = map_goal f g (State (node, nodes)) |
302 let val State (node', nodes') = map_goal f g (State (node, nodes)) |
303 in map_context f (State (nd, node' :: nodes')) end |
303 in map_context f (State (nd, node' :: nodes')) end |
304 | map_goal _ _ state = state; |
304 | map_goal _ _ state = state; |
305 |
305 |
|
306 fun set_goal goal = map_goal I (fn (statement, using, _, before_qed, after_qed) => |
|
307 (statement, using, goal, before_qed, after_qed)); |
|
308 |
306 fun using_facts using = map_goal I (fn (statement, _, goal, before_qed, after_qed) => |
309 fun using_facts using = map_goal I (fn (statement, _, goal, before_qed, after_qed) => |
307 (statement, using, goal, before_qed, after_qed)); |
310 (statement, using, goal, before_qed, after_qed)); |
308 |
311 |
309 local |
312 local |
310 fun find i state = |
313 fun find i state = |
369 else if mode = Chain then pretty_facts "picking " context facts |
372 else if mode = Chain then pretty_facts "picking " context facts |
370 else prt_goal (try find_goal state)) |
373 else prt_goal (try find_goal state)) |
371 end; |
374 end; |
372 |
375 |
373 fun pretty_goals main state = |
376 fun pretty_goals main state = |
374 let val (ctxt, (_, {goal, ...})) = find_goal state |
377 let val (ctxt, (_, goal)) = get_goal state |
375 in pretty_goals_local ctxt "" (false, main) (! Display.goals_limit) goal end; |
378 in pretty_goals_local ctxt "" (false, main) (! Display.goals_limit) goal end; |
376 |
379 |
377 |
380 |
378 |
381 |
379 (** proof steps **) |
382 (** proof steps **) |
406 (ProofContext.add_cases false (no_goal_cases goal @ goal_cases goal') #> |
409 (ProofContext.add_cases false (no_goal_cases goal @ goal_cases goal') #> |
407 ProofContext.add_cases true meth_cases) |
410 ProofContext.add_cases true meth_cases) |
408 (K (statement, using, goal', before_qed, after_qed))) |
411 (K (statement, using, goal', before_qed, after_qed))) |
409 end; |
412 end; |
410 |
413 |
|
414 fun select_goals n meth state = |
|
415 let val goal = #2 (#2 (get_goal state)) in |
|
416 state |
|
417 |> Seq.lift set_goal |
|
418 (Seq.maps (Tactic.precise_conjunction_tac 1 n) (Goal.extract 1 n goal)) |
|
419 |> Seq.maps meth |
|
420 |> Seq.maps (fn state' => state' |
|
421 |> Seq.lift set_goal (Goal.retrofit 1 n (#2 (#2 (get_goal state'))) goal)) |
|
422 |> Seq.maps (apply_method true (K Method.succeed)) |
|
423 end; |
|
424 |
411 fun apply_text cc text state = |
425 fun apply_text cc text state = |
412 let |
426 let |
413 val thy = theory_of state; |
427 val thy = theory_of state; |
414 |
428 |
415 fun eval (Method.Basic m) = apply_method cc m |
429 fun eval (Method.Basic m) = apply_method cc m |
416 | eval (Method.Source src) = apply_method cc (Method.method thy src) |
430 | eval (Method.Source src) = apply_method cc (Method.method thy src) |
417 | eval (Method.Then txts) = Seq.EVERY (map eval txts) |
431 | eval (Method.Then txts) = Seq.EVERY (map eval txts) |
418 | eval (Method.Orelse txts) = Seq.FIRST (map eval txts) |
432 | eval (Method.Orelse txts) = Seq.FIRST (map eval txts) |
419 | eval (Method.Try txt) = Seq.TRY (eval txt) |
433 | eval (Method.Try txt) = Seq.TRY (eval txt) |
420 | eval (Method.Repeat1 txt) = Seq.REPEAT1 (eval txt); |
434 | eval (Method.Repeat1 txt) = Seq.REPEAT1 (eval txt) |
|
435 | eval (Method.SelectGoals (n, txt)) = select_goals n (eval txt); |
421 in eval text state end; |
436 in eval text state end; |
422 |
437 |
423 in |
438 in |
424 |
439 |
425 val refine = apply_text true; |
440 val refine = apply_text true; |
441 if can Logic.unprotect (Logic.strip_assums_concl goal) then |
456 if can Logic.unprotect (Logic.strip_assums_concl goal) then |
442 Tactic.etac Drule.protectI i |
457 Tactic.etac Drule.protectI i |
443 else all_tac))); |
458 else all_tac))); |
444 |
459 |
445 fun refine_goal print_rule inner raw_rule state = |
460 fun refine_goal print_rule inner raw_rule state = |
446 let val (outer, (_, {statement, using, goal, before_qed, after_qed})) = find_goal state in |
461 let val (outer, (_, goal)) = get_goal state in |
447 raw_rule |
462 raw_rule |
448 |> ProofContext.goal_exports inner outer |
463 |> ProofContext.goal_exports inner outer |
449 |> Seq.maps (fn rule => |
464 |> Seq.maps (fn rule => |
450 (print_rule outer rule; |
465 (print_rule outer rule; |
451 goal |
466 Seq.lift set_goal (FINDGOAL (refine_tac rule) goal) state)) |
452 |> FINDGOAL (refine_tac rule) |
|
453 |> Seq.map (fn goal' => |
|
454 map_goal I (K (statement, using, goal', before_qed, after_qed)) state))) |
|
455 end; |
467 end; |
456 |
468 |
457 in |
469 in |
458 |
470 |
459 fun refine_goals print_rule inner raw_rules = |
471 fun refine_goals print_rule inner raw_rules = |