78 | SOME _ => fns) ts [] |
78 | SOME _ => fns) ts [] |
79 |
79 |
80 fun replacenegnorms cv t = case term_of t of |
80 fun replacenegnorms cv t = case term_of t of |
81 @{term "op + :: real => _"}$_$_ => binop_conv (replacenegnorms cv) t |
81 @{term "op + :: real => _"}$_$_ => binop_conv (replacenegnorms cv) t |
82 | @{term "op * :: real => _"}$_$_ => |
82 | @{term "op * :: real => _"}$_$_ => |
83 if dest_ratconst (Thm.dest_arg1 t) </ Rat.zero then arg_conv cv t else reflexive t |
83 if dest_ratconst (Thm.dest_arg1 t) </ Rat.zero then arg_conv cv t else Thm.reflexive t |
84 | _ => reflexive t |
84 | _ => Thm.reflexive t |
85 fun flip v eq = |
85 fun flip v eq = |
86 if FuncUtil.Ctermfunc.defined eq v |
86 if FuncUtil.Ctermfunc.defined eq v |
87 then FuncUtil.Ctermfunc.update (v, Rat.neg (FuncUtil.Ctermfunc.apply eq v)) eq else eq |
87 then FuncUtil.Ctermfunc.update (v, Rat.neg (FuncUtil.Ctermfunc.apply eq v)) eq else eq |
88 fun allsubsets s = case s of |
88 fun allsubsets s = case s of |
89 [] => [[]] |
89 [] => [[]] |
209 then_conv apply_pthd) ct |
209 then_conv apply_pthd) ct |
210 | EQUAL => (apply_pth9 then_conv |
210 | EQUAL => (apply_pth9 then_conv |
211 ((apply_ptha then_conv vector_add_conv) else_conv |
211 ((apply_ptha then_conv vector_add_conv) else_conv |
212 arg_conv vector_add_conv then_conv apply_pthd)) ct) |
212 arg_conv vector_add_conv then_conv apply_pthd)) ct) |
213 end |
213 end |
214 | _ => reflexive ct)) |
214 | _ => Thm.reflexive ct)) |
215 |
215 |
216 fun vector_canon_conv ct = case term_of ct of |
216 fun vector_canon_conv ct = case term_of ct of |
217 Const(@{const_name plus},_)$_$_ => |
217 Const(@{const_name plus},_)$_$_ => |
218 let |
218 let |
219 val ((p,l),r) = Thm.dest_comb ct |>> Thm.dest_comb |
219 val ((p,l),r) = Thm.dest_comb ct |>> Thm.dest_comb |
340 val lctab = vector_lincombs (map snd (filter (not o fst) ntms)) |
340 val lctab = vector_lincombs (map snd (filter (not o fst) ntms)) |
341 val (fxns, ctxt') = Variable.variant_fixes (replicate (length lctab) "x") ctxt |
341 val (fxns, ctxt') = Variable.variant_fixes (replicate (length lctab) "x") ctxt |
342 fun instantiate_cterm' ty tms = Drule.cterm_rule (Drule.instantiate' ty tms) |
342 fun instantiate_cterm' ty tms = Drule.cterm_rule (Drule.instantiate' ty tms) |
343 fun mk_norm t = Thm.capply (instantiate_cterm' [SOME (ctyp_of_term t)] [] @{cpat "norm :: (?'a :: real_normed_vector) => real"}) t |
343 fun mk_norm t = Thm.capply (instantiate_cterm' [SOME (ctyp_of_term t)] [] @{cpat "norm :: (?'a :: real_normed_vector) => real"}) t |
344 fun mk_equals l r = Thm.capply (Thm.capply (instantiate_cterm' [SOME (ctyp_of_term l)] [] @{cpat "op == :: ?'a =>_"}) l) r |
344 fun mk_equals l r = Thm.capply (Thm.capply (instantiate_cterm' [SOME (ctyp_of_term l)] [] @{cpat "op == :: ?'a =>_"}) l) r |
345 val asl = map2 (fn (t,_) => fn n => assume (mk_equals (mk_norm t) (cterm_of (ProofContext.theory_of ctxt') (Free(n,@{typ real}))))) lctab fxns |
345 val asl = map2 (fn (t,_) => fn n => Thm.assume (mk_equals (mk_norm t) (cterm_of (ProofContext.theory_of ctxt') (Free(n,@{typ real}))))) lctab fxns |
346 val replace_conv = try_conv (rewrs_conv asl) |
346 val replace_conv = try_conv (rewrs_conv asl) |
347 val replace_rule = fconv_rule (funpow 2 arg_conv (replacenegnorms replace_conv)) |
347 val replace_rule = fconv_rule (funpow 2 arg_conv (replacenegnorms replace_conv)) |
348 val ges' = |
348 val ges' = |
349 fold_rev (fn th => fn ths => conjunct1(norm_mp th)::ths) |
349 fold_rev (fn th => fn ths => conjunct1(norm_mp th)::ths) |
350 asl (map replace_rule ges) |
350 asl (map replace_rule ges) |
351 val gts' = map replace_rule gts |
351 val gts' = map replace_rule gts |
352 val nubs = map (conjunct2 o norm_mp) asl |
352 val nubs = map (conjunct2 o norm_mp) asl |
353 val th1 = real_vector_combo_prover ctxt' translator (nubs,ges',gts') |
353 val th1 = real_vector_combo_prover ctxt' translator (nubs,ges',gts') |
354 val shs = filter (member (fn (t,th) => t aconvc cprop_of th) asl) (#hyps (crep_thm th1)) |
354 val shs = filter (member (fn (t,th) => t aconvc cprop_of th) asl) (#hyps (crep_thm th1)) |
355 val th11 = hd (Variable.export ctxt' ctxt [fold implies_intr shs th1]) |
355 val th11 = hd (Variable.export ctxt' ctxt [fold Thm.implies_intr shs th1]) |
356 val cps = map (swap o Thm.dest_equals) (cprems_of th11) |
356 val cps = map (swap o Thm.dest_equals) (cprems_of th11) |
357 val th12 = instantiate ([], cps) th11 |
357 val th12 = instantiate ([], cps) th11 |
358 val th13 = fold Thm.elim_implies (map (reflexive o snd) cps) th12; |
358 val th13 = fold Thm.elim_implies (map (Thm.reflexive o snd) cps) th12; |
359 in hd (Variable.export ctxt' ctxt [th13]) |
359 in hd (Variable.export ctxt' ctxt [th13]) |
360 end |
360 end |
361 in val real_vector_ineq_prover = real_vector_ineq_prover |
361 in val real_vector_ineq_prover = real_vector_ineq_prover |
362 end; |
362 end; |
363 |
363 |
388 fun pure ctxt = fst o RealArith.gen_prover_real_arith ctxt (real_vector_prover ctxt); |
388 fun pure ctxt = fst o RealArith.gen_prover_real_arith ctxt (real_vector_prover ctxt); |
389 fun norm_arith ctxt ct = |
389 fun norm_arith ctxt ct = |
390 let |
390 let |
391 val ctxt' = Variable.declare_term (term_of ct) ctxt |
391 val ctxt' = Variable.declare_term (term_of ct) ctxt |
392 val th = init_conv ctxt' ct |
392 val th = init_conv ctxt' ct |
393 in equal_elim (Drule.arg_cong_rule @{cterm Trueprop} (symmetric th)) |
393 in Thm.equal_elim (Drule.arg_cong_rule @{cterm Trueprop} (Thm.symmetric th)) |
394 (pure ctxt' (Thm.rhs_of th)) |
394 (pure ctxt' (Thm.rhs_of th)) |
395 end |
395 end |
396 |
396 |
397 fun norm_arith_tac ctxt = |
397 fun norm_arith_tac ctxt = |
398 clarify_tac HOL_cs THEN' |
398 clarify_tac HOL_cs THEN' |