3 *) |
3 *) |
4 |
4 |
5 header{* A formalization of Ferrante and Rackoff's procedure with polynomial parameters, see Paper in CALCULEMUS 2008 *} |
5 header{* A formalization of Ferrante and Rackoff's procedure with polynomial parameters, see Paper in CALCULEMUS 2008 *} |
6 |
6 |
7 theory Parametric_Ferrante_Rackoff |
7 theory Parametric_Ferrante_Rackoff |
8 imports |
8 imports Reflected_Multivariate_Polynomial Dense_Linear_Order DP_Library |
9 Reflected_Multivariate_Polynomial |
|
10 Dense_Linear_Order |
|
11 "~~/src/HOL/Library/Efficient_Nat" |
9 "~~/src/HOL/Library/Efficient_Nat" |
12 begin |
10 begin |
13 |
11 |
14 subsection {* Terms *} |
12 subsection {* Terms *} |
15 |
13 |
2438 have "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p" ..} |
2436 have "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p" ..} |
2439 ultimately have th': "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p) \<longleftrightarrow> ?F" by blast |
2437 ultimately have th': "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p) \<longleftrightarrow> ?F" by blast |
2440 from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis . |
2438 from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis . |
2441 qed |
2439 qed |
2442 |
2440 |
2443 text {* Rest of the implementation *} |
|
2444 |
|
2445 primrec alluopairs:: "'a list \<Rightarrow> ('a \<times> 'a) list" where |
|
2446 "alluopairs [] = []" |
|
2447 | "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)" |
|
2448 |
|
2449 lemma alluopairs_set1: "set (alluopairs xs) \<le> {(x,y). x\<in> set xs \<and> y\<in> set xs}" |
|
2450 by (induct xs, auto) |
|
2451 |
|
2452 lemma alluopairs_set: |
|
2453 "\<lbrakk>x\<in> set xs ; y \<in> set xs\<rbrakk> \<Longrightarrow> (x,y) \<in> set (alluopairs xs) \<or> (y,x) \<in> set (alluopairs xs) " |
|
2454 by (induct xs, auto) |
|
2455 |
|
2456 lemma alluopairs_ex: |
|
2457 assumes Pc: "\<forall> x \<in> set xs. \<forall>y\<in> set xs. P x y = P y x" |
|
2458 shows "(\<exists> x \<in> set xs. \<exists> y \<in> set xs. P x y) = (\<exists> (x,y) \<in> set (alluopairs xs). P x y)" |
|
2459 proof |
|
2460 assume "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" |
|
2461 then obtain x y where x: "x \<in> set xs" and y:"y \<in> set xs" and P: "P x y" by blast |
|
2462 from alluopairs_set[OF x y] P Pc x y show"\<exists>(x, y)\<in>set (alluopairs xs). P x y" |
|
2463 by auto |
|
2464 next |
|
2465 assume "\<exists>(x, y)\<in>set (alluopairs xs). P x y" |
|
2466 then obtain "x" and "y" where xy:"(x,y) \<in> set (alluopairs xs)" and P: "P x y" by blast+ |
|
2467 from xy have "x \<in> set xs \<and> y\<in> set xs" using alluopairs_set1 by blast |
|
2468 with P show "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" by blast |
|
2469 qed |
|
2470 |
|
2471 lemma simpfm_lin: assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" |
2441 lemma simpfm_lin: assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" |
2472 shows "qfree p \<Longrightarrow> islin (simpfm p)" |
2442 shows "qfree p \<Longrightarrow> islin (simpfm p)" |
2473 by (induct p rule: simpfm.induct, auto simp add: conj_lin disj_lin) |
2443 by (induct p rule: simpfm.induct, auto simp add: conj_lin disj_lin) |
2474 |
2444 |
2475 definition |
2445 definition |
2514 with mp_nb pp_nb |
2484 with mp_nb pp_nb |
2515 have th1: "bound0 (disj ?mp (disj ?pp (evaldjf (simpfm o (msubst ?q)) ?Up )))" by (simp add: disj_nb) |
2485 have th1: "bound0 (disj ?mp (disj ?pp (evaldjf (simpfm o (msubst ?q)) ?Up )))" by (simp add: disj_nb) |
2516 from decr0_qf[OF th1] have thqf: "qfree (ferrack p)" by (simp add: ferrack_def Let_def) |
2486 from decr0_qf[OF th1] have thqf: "qfree (ferrack p)" by (simp add: ferrack_def Let_def) |
2517 have "?lhs \<longleftrightarrow> (\<exists>x. Ifm vs (x#bs) ?q)" by simp |
2487 have "?lhs \<longleftrightarrow> (\<exists>x. Ifm vs (x#bs) ?q)" by simp |
2518 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> (\<exists>(c, t)\<in>set ?U. \<exists>(d, s)\<in>set ?U. ?I (msubst (simpfm p) ((c, t), d, s)))" using fr_eq_msubst[OF lq, of vs bs x] by simp |
2488 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> (\<exists>(c, t)\<in>set ?U. \<exists>(d, s)\<in>set ?U. ?I (msubst (simpfm p) ((c, t), d, s)))" using fr_eq_msubst[OF lq, of vs bs x] by simp |
2519 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> (\<exists> (x,y) \<in> set ?Up. ?I ((simpfm o (msubst ?q)) (x,y)))" using alluopairs_ex[OF th0] by simp |
2489 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> (\<exists> (x,y) \<in> set ?Up. ?I ((simpfm o (msubst ?q)) (x,y)))" using alluopairs_bex[OF th0] by simp |
2520 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (evaldjf (simpfm o (msubst ?q)) ?Up)" |
2490 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (evaldjf (simpfm o (msubst ?q)) ?Up)" |
2521 by (simp add: evaldjf_ex) |
2491 by (simp add: evaldjf_ex) |
2522 also have "\<dots> \<longleftrightarrow> ?I (disj ?mp (disj ?pp (evaldjf (simpfm o (msubst ?q)) ?Up)))" by simp |
2492 also have "\<dots> \<longleftrightarrow> ?I (disj ?mp (disj ?pp (evaldjf (simpfm o (msubst ?q)) ?Up)))" by simp |
2523 also have "\<dots> \<longleftrightarrow> ?rhs" using decr0[OF th1, of vs x bs] |
2493 also have "\<dots> \<longleftrightarrow> ?rhs" using decr0[OF th1, of vs x bs] |
2524 apply (simp add: ferrack_def Let_def) |
2494 apply (simp add: ferrack_def Let_def) |
2855 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists>(b, a)\<in>set ?U. \<exists>(d, c)\<in>set ?U. ?I (msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))))" |
2825 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists>(b, a)\<in>set ?U. \<exists>(d, c)\<in>set ?U. ?I (msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))))" |
2856 using fr_eq_msubst2[OF lq, of vs bs x] by simp |
2826 using fr_eq_msubst2[OF lq, of vs bs x] by simp |
2857 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists> x\<in>set ?U. \<exists> y \<in>set ?U. ?I (?s (x,y)))" |
2827 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists> x\<in>set ?U. \<exists> y \<in>set ?U. ?I (?s (x,y)))" |
2858 by (simp add: split_def) |
2828 by (simp add: split_def) |
2859 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists> (x,y) \<in> set ?Up. ?I (?s (x,y)))" |
2829 also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists> (x,y) \<in> set ?Up. ?I (?s (x,y)))" |
2860 using alluopairs_ex[OF th0] by simp |
2830 using alluopairs_bex[OF th0] by simp |
2861 also have "\<dots> \<longleftrightarrow> ?I ?R" |
2831 also have "\<dots> \<longleftrightarrow> ?I ?R" |
2862 by (simp add: list_disj_def evaldjf_ex split_def) |
2832 by (simp add: list_disj_def evaldjf_ex split_def) |
2863 also have "\<dots> \<longleftrightarrow> ?rhs" |
2833 also have "\<dots> \<longleftrightarrow> ?rhs" |
2864 unfolding ferrack2_def |
2834 unfolding ferrack2_def |
2865 apply (cases "?mp = T") |
2835 apply (cases "?mp = T") |