src/HOL/Tools/groebner.ML
changeset 67399 eab6ce8368fa
parent 67230 b2800da9eb8a
child 67405 e9ab4ad7bd15
equal deleted inserted replaced
67398:5eb932e604a2 67399:eab6ce8368fa
   521 
   521 
   522  fun getname v = case Thm.term_of v of
   522  fun getname v = case Thm.term_of v of
   523   Free(s,_) => s
   523   Free(s,_) => s
   524  | Var ((s,_),_) => s
   524  | Var ((s,_),_) => s
   525  | _ => "x"
   525  | _ => "x"
   526  fun mk_eq s t = Thm.apply (Thm.apply \<^cterm>\<open>op \<equiv> :: bool \<Rightarrow> _\<close> s) t
   526  fun mk_eq s t = Thm.apply (Thm.apply \<^cterm>\<open>(\<equiv>) :: bool \<Rightarrow> _\<close> s) t
   527  fun mk_exists ctxt v th = Drule.arg_cong_rule (ext ctxt (Thm.typ_of_cterm v))
   527  fun mk_exists ctxt v th = Drule.arg_cong_rule (ext ctxt (Thm.typ_of_cterm v))
   528    (Thm.abstract_rule (getname v) v th)
   528    (Thm.abstract_rule (getname v) v th)
   529  fun simp_ex_conv ctxt =
   529  fun simp_ex_conv ctxt =
   530    Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms simp_thms(39)})
   530    Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps @{thms simp_thms(39)})
   531 
   531 
   599           in if null gvs then lvs else tm::acc
   599           in if null gvs then lvs else tm::acc
   600           end
   600           end
   601     else tm::acc ;
   601     else tm::acc ;
   602 
   602 
   603 fun grobify_term vars tm =
   603 fun grobify_term vars tm =
   604 ((if not (member (op aconvc) vars tm) then raise CTERM ("Not a variable", [tm]) else
   604 ((if not (member (aconvc) vars tm) then raise CTERM ("Not a variable", [tm]) else
   605      [(@1, map (fn i => if i aconvc tm then 1 else 0) vars)])
   605      [(@1, map (fn i => if i aconvc tm then 1 else 0) vars)])
   606 handle  CTERM _ =>
   606 handle  CTERM _ =>
   607  ((let val x = dest_const tm
   607  ((let val x = dest_const tm
   608  in if x = @0 then [] else [(x,map (K 0) vars)]
   608  in if x = @0 then [] else [(x,map (K 0) vars)]
   609  end)
   609  end)
   821   val (vars,bod) = strip_exists tm
   821   val (vars,bod) = strip_exists tm
   822   val cjs = striplist (dest_binary \<^cterm>\<open>HOL.conj\<close>) bod
   822   val cjs = striplist (dest_binary \<^cterm>\<open>HOL.conj\<close>) bod
   823   val th1 = (the (get_first (try (isolate_variable vars)) cjs)
   823   val th1 = (the (get_first (try (isolate_variable vars)) cjs)
   824              handle Option.Option => raise CTERM ("unwind_polys_conv",[tm]))
   824              handle Option.Option => raise CTERM ("unwind_polys_conv",[tm]))
   825   val eq = Thm.lhs_of th1
   825   val eq = Thm.lhs_of th1
   826   val bod' = list_mk_binop \<^cterm>\<open>HOL.conj\<close> (eq::(remove op aconvc eq cjs))
   826   val bod' = list_mk_binop \<^cterm>\<open>HOL.conj\<close> (eq::(remove (aconvc) eq cjs))
   827   val th2 = conj_ac_rule (mk_eq bod bod')
   827   val th2 = conj_ac_rule (mk_eq bod bod')
   828   val th3 =
   828   val th3 =
   829     Thm.transitive th2
   829     Thm.transitive th2
   830       (Drule.binop_cong_rule \<^cterm>\<open>HOL.conj\<close> th1
   830       (Drule.binop_cong_rule \<^cterm>\<open>HOL.conj\<close> th1
   831         (Thm.reflexive (Thm.dest_arg (Thm.rhs_of th2))))
   831         (Thm.reflexive (Thm.dest_arg (Thm.rhs_of th2))))
   898   | Const (\<^const_name>\<open>Ex\<close>, _) $ _ => find_body bounds (Thm.dest_arg tm)
   898   | Const (\<^const_name>\<open>Ex\<close>, _) $ _ => find_body bounds (Thm.dest_arg tm)
   899   | Const (\<^const_name>\<open>HOL.conj\<close>, _) $ _ $ _ => find_args bounds tm
   899   | Const (\<^const_name>\<open>HOL.conj\<close>, _) $ _ $ _ => find_args bounds tm
   900   | Const (\<^const_name>\<open>HOL.disj\<close>, _) $ _ $ _ => find_args bounds tm
   900   | Const (\<^const_name>\<open>HOL.disj\<close>, _) $ _ $ _ => find_args bounds tm
   901   | Const (\<^const_name>\<open>HOL.implies\<close>, _) $ _ $ _ => find_args bounds tm
   901   | Const (\<^const_name>\<open>HOL.implies\<close>, _) $ _ $ _ => find_args bounds tm
   902   | \<^term>\<open>Pure.imp\<close> $_$_ => find_args bounds tm
   902   | \<^term>\<open>Pure.imp\<close> $_$_ => find_args bounds tm
   903   | Const("op ==",_)$_$_ => find_args bounds tm  (* FIXME proper const name *)
   903   | Const("(==)",_)$_$_ => find_args bounds tm  (* FIXME proper const name *)
   904   | \<^term>\<open>Trueprop\<close>$_ => find_term bounds (Thm.dest_arg tm)
   904   | \<^term>\<open>Trueprop\<close>$_ => find_term bounds (Thm.dest_arg tm)
   905   | _ => raise TERM ("find_term", []))
   905   | _ => raise TERM ("find_term", []))
   906 and find_args bounds tm =
   906 and find_args bounds tm =
   907   let val (t, u) = Thm.dest_binop tm
   907   let val (t, u) = Thm.dest_binop tm
   908   in (find_term bounds t handle TERM _ => find_term bounds u) end
   908   in (find_term bounds t handle TERM _ => find_term bounds u) end