src/HOL/Tools/groebner.ML
changeset 59970 e9f73d87d904
parent 59586 ddf6deaadfe8
child 60752 b48830b670a1
equal deleted inserted replaced
59969:bcccad156236 59970:e9f73d87d904
   675 fun mk_add th1 = Thm.combination (Drule.arg_cong_rule ring_add_tm th1);
   675 fun mk_add th1 = Thm.combination (Drule.arg_cong_rule ring_add_tm th1);
   676 
   676 
   677 fun refute ctxt tm =
   677 fun refute ctxt tm =
   678  if tm aconvc false_tm then assume_Trueprop tm else
   678  if tm aconvc false_tm then assume_Trueprop tm else
   679  ((let
   679  ((let
   680    val (nths0,eths0) = List.partition (is_neg o concl) (HOLogic.conj_elims (assume_Trueprop tm))
   680    val (nths0,eths0) = List.partition (is_neg o concl) (HOLogic.conj_elims ctxt (assume_Trueprop tm))
   681    val  nths = filter (is_eq o Thm.dest_arg o concl) nths0
   681    val  nths = filter (is_eq o Thm.dest_arg o concl) nths0
   682    val eths = filter (is_eq o concl) eths0
   682    val eths = filter (is_eq o concl) eths0
   683   in
   683   in
   684    if null eths then
   684    if null eths then
   685     let
   685     let
   686       val th1 = end_itlist (fn th1 => fn th2 => idom_rule ctxt (HOLogic.conj_intr th1 th2)) nths
   686       val th1 = end_itlist (fn th1 => fn th2 => idom_rule ctxt (HOLogic.conj_intr ctxt th1 th2)) nths
   687       val th2 =
   687       val th2 =
   688         Conv.fconv_rule
   688         Conv.fconv_rule
   689           ((Conv.arg_conv #> Conv.arg_conv) (Conv.binop_conv ring_normalize_conv)) th1
   689           ((Conv.arg_conv #> Conv.arg_conv) (Conv.binop_conv ring_normalize_conv)) th1
   690       val conc = th2 |> concl |> Thm.dest_arg
   690       val conc = th2 |> concl |> Thm.dest_arg
   691       val (l,_) = conc |> dest_eq
   691       val (l,_) = conc |> dest_eq
   701           val (l,cert) = grobner_weak vars pols
   701           val (l,cert) = grobner_weak vars pols
   702       in (vars,l,cert,neq_01)
   702       in (vars,l,cert,neq_01)
   703       end
   703       end
   704      else
   704      else
   705       let
   705       let
   706        val nth = end_itlist (fn th1 => fn th2 => idom_rule ctxt (HOLogic.conj_intr th1 th2)) nths
   706        val nth = end_itlist (fn th1 => fn th2 => idom_rule ctxt (HOLogic.conj_intr ctxt th1 th2)) nths
   707        val (vars,pol::pols) =
   707        val (vars,pol::pols) =
   708           grobify_equations(list_mk_conj(Thm.dest_arg(concl nth)::map concl eths))
   708           grobify_equations(list_mk_conj(Thm.dest_arg(concl nth)::map concl eths))
   709        val (deg,l,cert) = grobner_strong vars pols pol
   709        val (deg,l,cert) = grobner_strong vars pols pol
   710        val th1 =
   710        val th1 =
   711         Conv.fconv_rule ((Conv.arg_conv o Conv.arg_conv) (Conv.binop_conv ring_normalize_conv)) nth
   711         Conv.fconv_rule ((Conv.arg_conv o Conv.arg_conv) (Conv.binop_conv ring_normalize_conv)) nth
   712        val th2 = funpow deg (idom_rule ctxt o HOLogic.conj_intr th1) neq_01
   712        val th2 = funpow deg (idom_rule ctxt o HOLogic.conj_intr ctxt th1) neq_01
   713       in (vars,l,cert,th2)
   713       in (vars,l,cert,th2)
   714       end)
   714       end)
   715     val cert_pos = map (fn (i,p) => (i,filter (fn (c,_) => c >/ rat_0) p)) cert
   715     val cert_pos = map (fn (i,p) => (i,filter (fn (c,_) => c >/ rat_0) p)) cert
   716     val cert_neg = map (fn (i,p) => (i,map (fn (c,m) => (minus_rat c,m))
   716     val cert_neg = map (fn (i,p) => (i,map (fn (c,m) => (minus_rat c,m))
   717                                             (filter (fn (c,_) => c </ rat_0) p))) cert
   717                                             (filter (fn (c,_) => c </ rat_0) p))) cert
   722         end_itlist mk_add
   722         end_itlist mk_add
   723             (map (fn (i,p) => Drule.arg_cong_rule (Thm.apply ring_mul_tm p)
   723             (map (fn (i,p) => Drule.arg_cong_rule (Thm.apply ring_mul_tm p)
   724               (nth eths i |> mk_meta_eq)) pols)
   724               (nth eths i |> mk_meta_eq)) pols)
   725     val th1 = thm_fn herts_pos
   725     val th1 = thm_fn herts_pos
   726     val th2 = thm_fn herts_neg
   726     val th2 = thm_fn herts_neg
   727     val th3 = HOLogic.conj_intr(mk_add (Thm.symmetric th1) th2 |> mk_object_eq) noteqth
   727     val th3 = HOLogic.conj_intr ctxt (mk_add (Thm.symmetric th1) th2 |> mk_object_eq) noteqth
   728     val th4 =
   728     val th4 =
   729       Conv.fconv_rule ((Conv.arg_conv o Conv.arg_conv o Conv.binop_conv) ring_normalize_conv)
   729       Conv.fconv_rule ((Conv.arg_conv o Conv.arg_conv o Conv.binop_conv) ring_normalize_conv)
   730         (neq_rule l th3)
   730         (neq_rule l th3)
   731     val (l, _) = dest_eq(Thm.dest_arg(concl th4))
   731     val (l, _) = dest_eq(Thm.dest_arg(concl th4))
   732    in Thm.implies_intr (Thm.apply cTrp tm)
   732    in Thm.implies_intr (Thm.apply cTrp tm)
   929 
   929 
   930 fun ring_tac add_ths del_ths ctxt =
   930 fun ring_tac add_ths del_ths ctxt =
   931   Object_Logic.full_atomize_tac ctxt
   931   Object_Logic.full_atomize_tac ctxt
   932   THEN' presimplify ctxt add_ths del_ths
   932   THEN' presimplify ctxt add_ths del_ths
   933   THEN' CSUBGOAL (fn (p, i) =>
   933   THEN' CSUBGOAL (fn (p, i) =>
   934     rtac (let val form = Object_Logic.dest_judgment p
   934     rtac (let val form = Object_Logic.dest_judgment ctxt p
   935           in case get_ring_ideal_convs ctxt form of
   935           in case get_ring_ideal_convs ctxt form of
   936            NONE => Thm.reflexive form
   936            NONE => Thm.reflexive form
   937           | SOME thy => #ring_conv thy ctxt form
   937           | SOME thy => #ring_conv thy ctxt form
   938           end) i
   938           end) i
   939       handle TERM _ => no_tac
   939       handle TERM _ => no_tac