src/HOL/Tools/Meson/meson.ML
changeset 58963 26bf09b95dda
parent 58957 c9e744ea8a38
child 59058 a78612c67ec0
equal deleted inserted replaced
58960:4bee6d8c1500 58963:26bf09b95dda
    28   val abs_extensionalize_conv : Proof.context -> conv
    28   val abs_extensionalize_conv : Proof.context -> conv
    29   val abs_extensionalize_thm : Proof.context -> thm -> thm
    29   val abs_extensionalize_thm : Proof.context -> thm -> thm
    30   val make_clauses_unsorted: Proof.context -> thm list -> thm list
    30   val make_clauses_unsorted: Proof.context -> thm list -> thm list
    31   val make_clauses: Proof.context -> thm list -> thm list
    31   val make_clauses: Proof.context -> thm list -> thm list
    32   val make_horns: thm list -> thm list
    32   val make_horns: thm list -> thm list
    33   val best_prolog_tac: (thm -> int) -> thm list -> tactic
    33   val best_prolog_tac: Proof.context -> (thm -> int) -> thm list -> tactic
    34   val depth_prolog_tac: thm list -> tactic
    34   val depth_prolog_tac: Proof.context -> thm list -> tactic
    35   val gocls: thm list -> thm list
    35   val gocls: thm list -> thm list
    36   val skolemize_prems_tac : Proof.context -> thm list -> int -> tactic
    36   val skolemize_prems_tac : Proof.context -> thm list -> int -> tactic
    37   val MESON:
    37   val MESON:
    38     tactic -> (thm list -> thm list) -> (thm list -> tactic) -> Proof.context
    38     tactic -> (thm list -> thm list) -> (thm list -> tactic) -> Proof.context
    39     -> int -> tactic
    39     -> int -> tactic
   501   if exists (fn prem => has_reps (rhyps(prem,[]))) (prems_of st)
   501   if exists (fn prem => has_reps (rhyps(prem,[]))) (prems_of st)
   502   then  Seq.empty  else  Seq.single st;
   502   then  Seq.empty  else  Seq.single st;
   503 
   503 
   504 
   504 
   505 (* net_resolve_tac actually made it slower... *)
   505 (* net_resolve_tac actually made it slower... *)
   506 fun prolog_step_tac horns i =
   506 fun prolog_step_tac ctxt horns i =
   507     (assume_tac i APPEND resolve_tac horns i) THEN check_tac THEN
   507     (assume_tac ctxt i APPEND resolve_tac horns i) THEN check_tac THEN
   508     TRYALL_eq_assume_tac;
   508     TRYALL_eq_assume_tac;
   509 
   509 
   510 (*Sums the sizes of the subgoals, ignoring hypotheses (ancestors)*)
   510 (*Sums the sizes of the subgoals, ignoring hypotheses (ancestors)*)
   511 fun addconcl prem sz = size_of_term (Logic.strip_assums_concl prem) + sz;
   511 fun addconcl prem sz = size_of_term (Logic.strip_assums_concl prem) + sz;
   512 
   512 
   688       (distinct Thm.eq_thm_prop (fold_rev (add_contras clause_rules) ths []));
   688       (distinct Thm.eq_thm_prop (fold_rev (add_contras clause_rules) ths []));
   689 
   689 
   690 (*Could simply use nprems_of, which would count remaining subgoals -- no
   690 (*Could simply use nprems_of, which would count remaining subgoals -- no
   691   discrimination as to their size!  With BEST_FIRST, fails for problem 41.*)
   691   discrimination as to their size!  With BEST_FIRST, fails for problem 41.*)
   692 
   692 
   693 fun best_prolog_tac sizef horns =
   693 fun best_prolog_tac ctxt sizef horns =
   694     BEST_FIRST (has_fewer_prems 1, sizef) (prolog_step_tac horns 1);
   694     BEST_FIRST (has_fewer_prems 1, sizef) (prolog_step_tac ctxt horns 1);
   695 
   695 
   696 fun depth_prolog_tac horns =
   696 fun depth_prolog_tac ctxt horns =
   697     DEPTH_FIRST (has_fewer_prems 1) (prolog_step_tac horns 1);
   697     DEPTH_FIRST (has_fewer_prems 1) (prolog_step_tac ctxt horns 1);
   698 
   698 
   699 (*Return all negative clauses, as possible goal clauses*)
   699 (*Return all negative clauses, as possible goal clauses*)
   700 fun gocls cls = name_thms "Goal#" (map make_goal (neg_clauses cls));
   700 fun gocls cls = name_thms "Goal#" (map make_goal (neg_clauses cls));
   701 
   701 
   702 fun skolemize_prems_tac ctxt prems =
   702 fun skolemize_prems_tac ctxt prems =
   721 fun best_meson_tac sizef ctxt =
   721 fun best_meson_tac sizef ctxt =
   722   MESON all_tac (make_clauses ctxt)
   722   MESON all_tac (make_clauses ctxt)
   723     (fn cls =>
   723     (fn cls =>
   724          THEN_BEST_FIRST (resolve_tac (gocls cls) 1)
   724          THEN_BEST_FIRST (resolve_tac (gocls cls) 1)
   725                          (has_fewer_prems 1, sizef)
   725                          (has_fewer_prems 1, sizef)
   726                          (prolog_step_tac (make_horns cls) 1))
   726                          (prolog_step_tac ctxt (make_horns cls) 1))
   727     ctxt
   727     ctxt
   728 
   728 
   729 (*First, breaks the goal into independent units*)
   729 (*First, breaks the goal into independent units*)
   730 fun safe_best_meson_tac ctxt =
   730 fun safe_best_meson_tac ctxt =
   731   SELECT_GOAL (TRY (safe_tac ctxt) THEN TRYALL (best_meson_tac size_of_subgoals ctxt));
   731   SELECT_GOAL (TRY (safe_tac ctxt) THEN TRYALL (best_meson_tac size_of_subgoals ctxt));
   732 
   732 
   733 (** Depth-first search version **)
   733 (** Depth-first search version **)
   734 
   734 
   735 fun depth_meson_tac ctxt =
   735 fun depth_meson_tac ctxt =
   736   MESON all_tac (make_clauses ctxt)
   736   MESON all_tac (make_clauses ctxt)
   737     (fn cls => EVERY [resolve_tac (gocls cls) 1, depth_prolog_tac (make_horns cls)])
   737     (fn cls => EVERY [resolve_tac (gocls cls) 1, depth_prolog_tac ctxt (make_horns cls)])
   738     ctxt
   738     ctxt
   739 
   739 
   740 (** Iterative deepening version **)
   740 (** Iterative deepening version **)
   741 
   741 
   742 (*This version does only one inference per call;
   742 (*This version does only one inference per call;
   745     let val (horn0s, _) = (*0 subgoals vs 1 or more*)
   745     let val (horn0s, _) = (*0 subgoals vs 1 or more*)
   746             take_prefix Thm.no_prems horns
   746             take_prefix Thm.no_prems horns
   747         val nrtac = net_resolve_tac horns
   747         val nrtac = net_resolve_tac horns
   748     in  fn i => eq_assume_tac i ORELSE
   748     in  fn i => eq_assume_tac i ORELSE
   749                 match_tac ctxt horn0s i ORELSE  (*no backtracking if unit MATCHES*)
   749                 match_tac ctxt horn0s i ORELSE  (*no backtracking if unit MATCHES*)
   750                 ((assume_tac i APPEND nrtac i) THEN check_tac)
   750                 ((assume_tac ctxt i APPEND nrtac i) THEN check_tac)
   751     end;
   751     end;
   752 
   752 
   753 fun iter_deepen_prolog_tac ctxt horns =
   753 fun iter_deepen_prolog_tac ctxt horns =
   754     ITER_DEEPEN iter_deepen_limit (has_fewer_prems 1) (prolog_step_tac' ctxt horns);
   754     ITER_DEEPEN iter_deepen_limit (has_fewer_prems 1) (prolog_step_tac' ctxt horns);
   755 
   755