30 |
30 |
31 fun dest_binary ct ct' = |
31 fun dest_binary ct ct' = |
32 if is_binop ct ct' then Thm.dest_binop ct' |
32 if is_binop ct ct' then Thm.dest_binop ct' |
33 else raise CTERM ("dest_binary: bad binop", [ct, ct']) |
33 else raise CTERM ("dest_binary: bad binop", [ct, ct']) |
34 |
34 |
35 val minus_rat = Rat.neg; |
|
36 val denominator_rat = Rat.dest #> snd #> Rat.of_int; |
35 val denominator_rat = Rat.dest #> snd #> Rat.of_int; |
37 fun int_of_rat a = |
36 fun int_of_rat a = |
38 case Rat.dest a of (i,1) => i | _ => error "int_of_rat: not an int"; |
37 case Rat.dest a of (i,1) => i | _ => error "int_of_rat: not an int"; |
39 val lcm_rat = fn x => fn y => Rat.of_int (Integer.lcm (int_of_rat x) (int_of_rat y)); |
38 val lcm_rat = fn x => fn y => Rat.of_int (Integer.lcm (int_of_rat x) (int_of_rat y)); |
40 |
39 |
129 |
128 |
130 fun reduce1 cm (pol,hpol) = |
129 fun reduce1 cm (pol,hpol) = |
131 case pol of |
130 case pol of |
132 [] => error "reduce1" |
131 [] => error "reduce1" |
133 | cm1::cms => ((let val (c,m) = mdiv cm cm1 in |
132 | cm1::cms => ((let val (c,m) = mdiv cm cm1 in |
134 (grob_cmul (minus_rat c,m) cms, |
133 (grob_cmul (~ c, m) cms, |
135 Mmul((minus_rat c,m),hpol)) end) |
134 Mmul ((~ c,m),hpol)) end) |
136 handle ERROR _ => error "reduce1"); |
135 handle ERROR _ => error "reduce1"); |
137 |
136 |
138 (* Try this for all polynomials in a basis. *) |
137 (* Try this for all polynomials in a basis. *) |
139 fun tryfind f l = |
138 fun tryfind f l = |
140 case l of |
139 case l of |
167 | (_,([],h)) => ([],h) |
166 | (_,([],h)) => ([],h) |
168 | ((cm1::ptl1,his1),(cm2::ptl2,his2)) => |
167 | ((cm1::ptl1,his1),(cm2::ptl2,his2)) => |
169 (grob_sub (grob_cmul (mdiv cm cm1) ptl1) |
168 (grob_sub (grob_cmul (mdiv cm cm1) ptl1) |
170 (grob_cmul (mdiv cm cm2) ptl2), |
169 (grob_cmul (mdiv cm cm2) ptl2), |
171 Add(Mmul(mdiv cm cm1,his1), |
170 Add(Mmul(mdiv cm cm1,his1), |
172 Mmul(mdiv (minus_rat(fst cm),snd cm) cm2,his2))); |
171 Mmul(mdiv (~ (fst cm),snd cm) cm2,his2))); |
173 |
172 |
174 (* Make a polynomial monic. *) |
173 (* Make a polynomial monic. *) |
175 |
174 |
176 fun monic (pol,hist) = |
175 fun monic (pol,hist) = |
177 if null pol then (pol,hist) else |
176 if null pol then (pol,hist) else |
709 Conv.fconv_rule ((Conv.arg_conv o Conv.arg_conv) (Conv.binop_conv ring_normalize_conv)) nth |
708 Conv.fconv_rule ((Conv.arg_conv o Conv.arg_conv) (Conv.binop_conv ring_normalize_conv)) nth |
710 val th2 = funpow deg (idom_rule ctxt o HOLogic.conj_intr ctxt th1) neq_01 |
709 val th2 = funpow deg (idom_rule ctxt o HOLogic.conj_intr ctxt th1) neq_01 |
711 in (vars,l,cert,th2) |
710 in (vars,l,cert,th2) |
712 end) |
711 end) |
713 val cert_pos = map (fn (i,p) => (i,filter (fn (c,_) => c > @0) p)) cert |
712 val cert_pos = map (fn (i,p) => (i,filter (fn (c,_) => c > @0) p)) cert |
714 val cert_neg = map (fn (i,p) => (i,map (fn (c,m) => (minus_rat c,m)) |
713 val cert_neg = map (fn (i,p) => (i,map (fn (c,m) => (~ c,m)) |
715 (filter (fn (c,_) => c < @0) p))) cert |
714 (filter (fn (c,_) => c < @0) p))) cert |
716 val herts_pos = map (fn (i,p) => (i,holify_polynomial vars p)) cert_pos |
715 val herts_pos = map (fn (i,p) => (i,holify_polynomial vars p)) cert_pos |
717 val herts_neg = map (fn (i,p) => (i,holify_polynomial vars p)) cert_neg |
716 val herts_neg = map (fn (i,p) => (i,holify_polynomial vars p)) cert_neg |
718 fun thm_fn pols = |
717 fun thm_fn pols = |
719 if null pols then Thm.reflexive(mk_const @0) else |
718 if null pols then Thm.reflexive(mk_const @0) else |