src/HOL/ex/Reflected_Presburger.thy
changeset 23477 f4b83f03cac9
parent 23315 df3a7e9ebadb
child 23515 3e7f62e68fe4
equal deleted inserted replaced
23476:839db6346cc8 23477:f4b83f03cac9
     1 theory Reflected_Presburger
     1 theory Reflected_Presburger
     2   imports GCD Main EfficientNat
     2 imports GCD Main EfficientNat
     3   uses ("coopereif.ML") ("coopertac.ML")
     3 uses ("coopereif.ML") ("coopertac.ML")
     4   begin
     4 begin
     5 
     5 
     6 lemma allpairs_set: "set (allpairs Pair xs ys) = {(x,y). x\<in> set xs \<and> y \<in> set ys}"
     6 lemma allpairs_set: "set (allpairs Pair xs ys) = {(x,y). x\<in> set xs \<and> y \<in> set ys}"
     7 by (induct xs) auto
     7 by (induct xs) auto
     8 
     8 
     9 
     9 
   461   "numadd (a,b) = Add a b"
   461   "numadd (a,b) = Add a b"
   462 
   462 
   463 lemma numadd: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
   463 lemma numadd: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
   464 apply (induct t s rule: numadd.induct, simp_all add: Let_def)
   464 apply (induct t s rule: numadd.induct, simp_all add: Let_def)
   465 apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
   465 apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
   466 by (case_tac "n1 = n2", simp_all add: ring_eq_simps)
   466  apply (case_tac "n1 = n2")
   467 (simp add: ring_eq_simps(1)[symmetric]) 
   467   apply(simp_all add: ring_simps)
       
   468 apply(simp add: left_distrib[symmetric])
       
   469 done
   468 
   470 
   469 lemma numadd_nb: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
   471 lemma numadd_nb: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
   470 by (induct t s rule: numadd.induct, auto simp add: Let_def)
   472 by (induct t s rule: numadd.induct, auto simp add: Let_def)
   471 
   473 
   472 recdef nummul "measure size"
   474 recdef nummul "measure size"
   474   "nummul (Add a b) = (\<lambda> i. numadd (nummul a i, nummul b i))"
   476   "nummul (Add a b) = (\<lambda> i. numadd (nummul a i, nummul b i))"
   475   "nummul (Mul c t) = (\<lambda> i. nummul t (i*c))"
   477   "nummul (Mul c t) = (\<lambda> i. nummul t (i*c))"
   476   "nummul t = (\<lambda> i. Mul i t)"
   478   "nummul t = (\<lambda> i. Mul i t)"
   477 
   479 
   478 lemma nummul: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
   480 lemma nummul: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
   479 by (induct t rule: nummul.induct, auto simp add: ring_eq_simps numadd)
   481 by (induct t rule: nummul.induct, auto simp add: ring_simps numadd)
   480 
   482 
   481 lemma nummul_nb: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
   483 lemma nummul_nb: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
   482 by (induct t rule: nummul.induct, auto simp add: numadd_nb)
   484 by (induct t rule: nummul.induct, auto simp add: numadd_nb)
   483 
   485 
   484 constdefs numneg :: "num \<Rightarrow> num"
   486 constdefs numneg :: "num \<Rightarrow> num"
   905   have spl: "zsplit0 a = (?c,?r)" by simp
   907   have spl: "zsplit0 a = (?c,?r)" by simp
   906   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   908   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   907   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   909   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   908   let ?N = "\<lambda> t. Inum (i#bs) t"
   910   let ?N = "\<lambda> t. Inum (i#bs) t"
   909   from prems Ia nb  show ?case 
   911   from prems Ia nb  show ?case 
   910     by (auto simp add: Let_def split_def ring_eq_simps) (cases "?r",auto)
   912     by (auto simp add: Let_def split_def ring_simps) (cases "?r",auto)
   911 next
   913 next
   912   case (6 a)  
   914   case (6 a)  
   913   let ?c = "fst (zsplit0 a)"
   915   let ?c = "fst (zsplit0 a)"
   914   let ?r = "snd (zsplit0 a)"
   916   let ?r = "snd (zsplit0 a)"
   915   have spl: "zsplit0 a = (?c,?r)" by simp
   917   have spl: "zsplit0 a = (?c,?r)" by simp
   916   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   918   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   917   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   919   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   918   let ?N = "\<lambda> t. Inum (i#bs) t"
   920   let ?N = "\<lambda> t. Inum (i#bs) t"
   919   from prems Ia nb  show ?case 
   921   from prems Ia nb  show ?case 
   920     by (auto simp add: Let_def split_def ring_eq_simps) (cases "?r",auto)
   922     by (auto simp add: Let_def split_def ring_simps) (cases "?r",auto)
   921 next
   923 next
   922   case (7 a)  
   924   case (7 a)  
   923   let ?c = "fst (zsplit0 a)"
   925   let ?c = "fst (zsplit0 a)"
   924   let ?r = "snd (zsplit0 a)"
   926   let ?r = "snd (zsplit0 a)"
   925   have spl: "zsplit0 a = (?c,?r)" by simp
   927   have spl: "zsplit0 a = (?c,?r)" by simp
   926   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   928   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   927   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   929   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   928   let ?N = "\<lambda> t. Inum (i#bs) t"
   930   let ?N = "\<lambda> t. Inum (i#bs) t"
   929   from prems Ia nb  show ?case 
   931   from prems Ia nb  show ?case 
   930     by (auto simp add: Let_def split_def ring_eq_simps) (cases "?r",auto)
   932     by (auto simp add: Let_def split_def ring_simps) (cases "?r",auto)
   931 next
   933 next
   932   case (8 a)  
   934   case (8 a)  
   933   let ?c = "fst (zsplit0 a)"
   935   let ?c = "fst (zsplit0 a)"
   934   let ?r = "snd (zsplit0 a)"
   936   let ?r = "snd (zsplit0 a)"
   935   have spl: "zsplit0 a = (?c,?r)" by simp
   937   have spl: "zsplit0 a = (?c,?r)" by simp
   936   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   938   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   937   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   939   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   938   let ?N = "\<lambda> t. Inum (i#bs) t"
   940   let ?N = "\<lambda> t. Inum (i#bs) t"
   939   from prems Ia nb  show ?case 
   941   from prems Ia nb  show ?case 
   940     by (auto simp add: Let_def split_def ring_eq_simps) (cases "?r",auto)
   942     by (auto simp add: Let_def split_def ring_simps) (cases "?r",auto)
   941 next
   943 next
   942   case (9 a)  
   944   case (9 a)  
   943   let ?c = "fst (zsplit0 a)"
   945   let ?c = "fst (zsplit0 a)"
   944   let ?r = "snd (zsplit0 a)"
   946   let ?r = "snd (zsplit0 a)"
   945   have spl: "zsplit0 a = (?c,?r)" by simp
   947   have spl: "zsplit0 a = (?c,?r)" by simp
   946   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   948   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   947   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   949   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   948   let ?N = "\<lambda> t. Inum (i#bs) t"
   950   let ?N = "\<lambda> t. Inum (i#bs) t"
   949   from prems Ia nb  show ?case 
   951   from prems Ia nb  show ?case 
   950     by (auto simp add: Let_def split_def ring_eq_simps) (cases "?r",auto)
   952     by (auto simp add: Let_def split_def ring_simps) (cases "?r",auto)
   951 next
   953 next
   952   case (10 a)  
   954   case (10 a)  
   953   let ?c = "fst (zsplit0 a)"
   955   let ?c = "fst (zsplit0 a)"
   954   let ?r = "snd (zsplit0 a)"
   956   let ?r = "snd (zsplit0 a)"
   955   have spl: "zsplit0 a = (?c,?r)" by simp
   957   have spl: "zsplit0 a = (?c,?r)" by simp
   956   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   958   from zsplit0_I[OF spl, where x="i" and bs="bs"] 
   957   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   959   have Ia:"Inum (i # bs) a = Inum (i #bs) (CX ?c ?r)" and nb: "numbound0 ?r" by auto 
   958   let ?N = "\<lambda> t. Inum (i#bs) t"
   960   let ?N = "\<lambda> t. Inum (i#bs) t"
   959   from prems Ia nb  show ?case 
   961   from prems Ia nb  show ?case 
   960     by (auto simp add: Let_def split_def ring_eq_simps) (cases "?r",auto)
   962     by (auto simp add: Let_def split_def ring_simps) (cases "?r",auto)
   961 next
   963 next
   962   case (11 j a)  
   964   case (11 j a)  
   963   let ?c = "fst (zsplit0 a)"
   965   let ?c = "fst (zsplit0 a)"
   964   let ?r = "snd (zsplit0 a)"
   966   let ?r = "snd (zsplit0 a)"
   965   have spl: "zsplit0 a = (?c,?r)" by simp
   967   have spl: "zsplit0 a = (?c,?r)" by simp
  1262       assume 
  1264       assume 
  1263 	"i dvd c * x - c*(k*d) + Inum (x # bs) e"
  1265 	"i dvd c * x - c*(k*d) + Inum (x # bs) e"
  1264       (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt")
  1266       (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt")
  1265       hence "\<exists> (l::int). ?rt = i * l" by (simp add: dvd_def)
  1267       hence "\<exists> (l::int). ?rt = i * l" by (simp add: dvd_def)
  1266       hence "\<exists> (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" 
  1268       hence "\<exists> (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" 
  1267 	by (simp add: ring_eq_simps di_def)
  1269 	by (simp add: ring_simps di_def)
  1268       hence "\<exists> (l::int). c*x+ ?I x e = i*(l + c*k*di)"
  1270       hence "\<exists> (l::int). c*x+ ?I x e = i*(l + c*k*di)"
  1269 	by (simp add: ring_eq_simps)
  1271 	by (simp add: ring_simps)
  1270       hence "\<exists> (l::int). c*x+ ?I x e = i*l" by blast
  1272       hence "\<exists> (l::int). c*x+ ?I x e = i*l" by blast
  1271       thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) 
  1273       thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) 
  1272     next
  1274     next
  1273       assume 
  1275       assume 
  1274 	"i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e")
  1276 	"i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e")
  1275       hence "\<exists> (l::int). c*x+?e = i*l" by (simp add: dvd_def)
  1277       hence "\<exists> (l::int). c*x+?e = i*l" by (simp add: dvd_def)
  1276       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp
  1278       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp
  1277       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def)
  1279       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def)
  1278       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: ring_eq_simps)
  1280       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: ring_simps)
  1279       hence "\<exists> (l::int). c*x - c * (k*d) +?e = i*l"
  1281       hence "\<exists> (l::int). c*x - c * (k*d) +?e = i*l"
  1280 	by blast
  1282 	by blast
  1281       thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def)
  1283       thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def)
  1282     qed
  1284     qed
  1283 next
  1285 next
  1289       assume 
  1291       assume 
  1290 	"i dvd c * x - c*(k*d) + Inum (x # bs) e"
  1292 	"i dvd c * x - c*(k*d) + Inum (x # bs) e"
  1291       (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt")
  1293       (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt")
  1292       hence "\<exists> (l::int). ?rt = i * l" by (simp add: dvd_def)
  1294       hence "\<exists> (l::int). ?rt = i * l" by (simp add: dvd_def)
  1293       hence "\<exists> (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" 
  1295       hence "\<exists> (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" 
  1294 	by (simp add: ring_eq_simps di_def)
  1296 	by (simp add: ring_simps di_def)
  1295       hence "\<exists> (l::int). c*x+ ?I x e = i*(l + c*k*di)"
  1297       hence "\<exists> (l::int). c*x+ ?I x e = i*(l + c*k*di)"
  1296 	by (simp add: ring_eq_simps)
  1298 	by (simp add: ring_simps)
  1297       hence "\<exists> (l::int). c*x+ ?I x e = i*l" by blast
  1299       hence "\<exists> (l::int). c*x+ ?I x e = i*l" by blast
  1298       thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) 
  1300       thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) 
  1299     next
  1301     next
  1300       assume 
  1302       assume 
  1301 	"i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e")
  1303 	"i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e")
  1302       hence "\<exists> (l::int). c*x+?e = i*l" by (simp add: dvd_def)
  1304       hence "\<exists> (l::int). c*x+?e = i*l" by (simp add: dvd_def)
  1303       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp
  1305       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp
  1304       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def)
  1306       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def)
  1305       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: ring_eq_simps)
  1307       hence "\<exists> (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: ring_simps)
  1306       hence "\<exists> (l::int). c*x - c * (k*d) +?e = i*l"
  1308       hence "\<exists> (l::int). c*x - c * (k*d) +?e = i*l"
  1307 	by blast
  1309 	by blast
  1308       thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def)
  1310       thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def)
  1309     qed
  1311     qed
  1310 qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="x - k*d" and b'="x"])
  1312 qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="x - k*d" and b'="x"])
  1353   have "Ifm bbs (x#bs) (mirror (Dvd j (CX c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp
  1355   have "Ifm bbs (x#bs) (mirror (Dvd j (CX c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp
  1354     also have "\<dots> = (j dvd (- (c*x - ?e)))"
  1356     also have "\<dots> = (j dvd (- (c*x - ?e)))"
  1355     by (simp only: zdvd_zminus_iff)
  1357     by (simp only: zdvd_zminus_iff)
  1356   also have "\<dots> = (j dvd (c* (- x)) + ?e)"
  1358   also have "\<dots> = (j dvd (c* (- x)) + ?e)"
  1357     apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib)
  1359     apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib)
  1358     by (simp add: ring_eq_simps)
  1360     by (simp add: ring_simps)
  1359   also have "\<dots> = Ifm bbs ((- x)#bs) (Dvd j (CX c e))"
  1361   also have "\<dots> = Ifm bbs ((- x)#bs) (Dvd j (CX c e))"
  1360     using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"]
  1362     using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"]
  1361     by simp
  1363     by simp
  1362   finally show ?case .
  1364   finally show ?case .
  1363 next
  1365 next
  1365   have "Ifm bbs (x#bs) (mirror (Dvd j (CX c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp
  1367   have "Ifm bbs (x#bs) (mirror (Dvd j (CX c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp
  1366     also have "\<dots> = (j dvd (- (c*x - ?e)))"
  1368     also have "\<dots> = (j dvd (- (c*x - ?e)))"
  1367     by (simp only: zdvd_zminus_iff)
  1369     by (simp only: zdvd_zminus_iff)
  1368   also have "\<dots> = (j dvd (c* (- x)) + ?e)"
  1370   also have "\<dots> = (j dvd (c* (- x)) + ?e)"
  1369     apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib)
  1371     apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib)
  1370     by (simp add: ring_eq_simps)
  1372     by (simp add: ring_simps)
  1371   also have "\<dots> = Ifm bbs ((- x)#bs) (Dvd j (CX c e))"
  1373   also have "\<dots> = Ifm bbs ((- x)#bs) (Dvd j (CX c e))"
  1372     using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"]
  1374     using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"]
  1373     by simp
  1375     by simp
  1374   finally show ?case by simp
  1376   finally show ?case by simp
  1375 qed (auto simp add: numbound0_I[where bs="bs" and b="x" and b'="- x"] nth_pos2)
  1377 qed (auto simp add: numbound0_I[where bs="bs" and b="x" and b'="- x"] nth_pos2)
  1437     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1439     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1438       by simp
  1440       by simp
  1439     hence "(l*x + (l div c) * Inum (x # bs) e < 0) =
  1441     hence "(l*x + (l div c) * Inum (x # bs) e < 0) =
  1440           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e < 0)"
  1442           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e < 0)"
  1441       by simp
  1443       by simp
  1442     also have "\<dots> = ((l div c) * (c*x + Inum (x # bs) e) < (l div c) * 0)" by (simp add: ring_eq_simps)
  1444     also have "\<dots> = ((l div c) * (c*x + Inum (x # bs) e) < (l div c) * 0)" by (simp add: ring_simps)
  1443     also have "\<dots> = (c*x + Inum (x # bs) e < 0)"
  1445     also have "\<dots> = (c*x + Inum (x # bs) e < 0)"
  1444     using mult_less_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp
  1446     using mult_less_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp
  1445   finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] be  by simp
  1447   finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] be  by simp
  1446 next
  1448 next
  1447   case (6 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1449   case (6 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1455     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1457     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1456       by simp
  1458       by simp
  1457     hence "(l*x + (l div c) * Inum (x# bs) e \<le> 0) =
  1459     hence "(l*x + (l div c) * Inum (x# bs) e \<le> 0) =
  1458           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \<le> 0)"
  1460           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \<le> 0)"
  1459       by simp
  1461       by simp
  1460     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) \<le> ((l div c)) * 0)" by (simp add: ring_eq_simps)
  1462     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) \<le> ((l div c)) * 0)" by (simp add: ring_simps)
  1461     also have "\<dots> = (c*x + Inum (x # bs) e \<le> 0)"
  1463     also have "\<dots> = (c*x + Inum (x # bs) e \<le> 0)"
  1462     using mult_le_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp
  1464     using mult_le_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp
  1463   finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"]  be by simp
  1465   finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"]  be by simp
  1464 next
  1466 next
  1465   case (7 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1467   case (7 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1473     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1475     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1474       by simp
  1476       by simp
  1475     hence "(l*x + (l div c)* Inum (x # bs) e > 0) =
  1477     hence "(l*x + (l div c)* Inum (x # bs) e > 0) =
  1476           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e > 0)"
  1478           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e > 0)"
  1477       by simp
  1479       by simp
  1478     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) > ((l div c)) * 0)" by (simp add: ring_eq_simps)
  1480     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) > ((l div c)) * 0)" by (simp add: ring_simps)
  1479     also have "\<dots> = (c * x + Inum (x # bs) e > 0)"
  1481     also have "\<dots> = (c * x + Inum (x # bs) e > 0)"
  1480     using zero_less_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp
  1482     using zero_less_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp
  1481   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"]  be  by simp
  1483   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"]  be  by simp
  1482 next
  1484 next
  1483   case (8 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1485   case (8 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1492       by simp
  1494       by simp
  1493     hence "(l*x + (l div c)* Inum (x # bs) e \<ge> 0) =
  1495     hence "(l*x + (l div c)* Inum (x # bs) e \<ge> 0) =
  1494           ((c*(l div c))*x + (l div c)* Inum (x # bs) e \<ge> 0)"
  1496           ((c*(l div c))*x + (l div c)* Inum (x # bs) e \<ge> 0)"
  1495       by simp
  1497       by simp
  1496     also have "\<dots> = ((l div c)*(c*x + Inum (x # bs) e) \<ge> ((l div c)) * 0)" 
  1498     also have "\<dots> = ((l div c)*(c*x + Inum (x # bs) e) \<ge> ((l div c)) * 0)" 
  1497       by (simp add: ring_eq_simps)
  1499       by (simp add: ring_simps)
  1498     also have "\<dots> = (c*x + Inum (x # bs) e \<ge> 0)" using ldcp 
  1500     also have "\<dots> = (c*x + Inum (x # bs) e \<ge> 0)" using ldcp 
  1499       zero_le_mult_iff [where a="l div c" and b="c*x + Inum (x # bs) e"] by simp
  1501       zero_le_mult_iff [where a="l div c" and b="c*x + Inum (x # bs) e"] by simp
  1500   finally show ?case using be numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"]  
  1502   finally show ?case using be numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"]  
  1501     by simp
  1503     by simp
  1502 next
  1504 next
  1511     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1513     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1512       by simp
  1514       by simp
  1513     hence "(l * x + (l div c) * Inum (x # bs) e = 0) =
  1515     hence "(l * x + (l div c) * Inum (x # bs) e = 0) =
  1514           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e = 0)"
  1516           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e = 0)"
  1515       by simp
  1517       by simp
  1516     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) = ((l div c)) * 0)" by (simp add: ring_eq_simps)
  1518     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) = ((l div c)) * 0)" by (simp add: ring_simps)
  1517     also have "\<dots> = (c * x + Inum (x # bs) e = 0)"
  1519     also have "\<dots> = (c * x + Inum (x # bs) e = 0)"
  1518     using mult_eq_0_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp
  1520     using mult_eq_0_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp
  1519   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"]  be  by simp
  1521   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"]  be  by simp
  1520 next
  1522 next
  1521   case (4 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1523   case (4 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+
  1529     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1531     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1530       by simp
  1532       by simp
  1531     hence "(l * x + (l div c) * Inum (x # bs) e \<noteq> 0) =
  1533     hence "(l * x + (l div c) * Inum (x # bs) e \<noteq> 0) =
  1532           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \<noteq> 0)"
  1534           ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \<noteq> 0)"
  1533       by simp
  1535       by simp
  1534     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) \<noteq> ((l div c)) * 0)" by (simp add: ring_eq_simps)
  1536     also have "\<dots> = ((l div c) * (c * x + Inum (x # bs) e) \<noteq> ((l div c)) * 0)" by (simp add: ring_simps)
  1535     also have "\<dots> = (c * x + Inum (x # bs) e \<noteq> 0)"
  1537     also have "\<dots> = (c * x + Inum (x # bs) e \<noteq> 0)"
  1536     using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp
  1538     using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp
  1537   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"]  be  by simp
  1539   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"]  be  by simp
  1538 next
  1540 next
  1539   case (9 j c e) hence cp: "c>0" and be: "numbound0 e" and jp: "j > 0" and d': "c dvd l" by simp+
  1541   case (9 j c e) hence cp: "c>0" and be: "numbound0 e" and jp: "j > 0" and d': "c dvd l" by simp+
  1545       by (simp add: zdiv_self[OF cnz])
  1547       by (simp add: zdiv_self[OF cnz])
  1546     have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
  1548     have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
  1547     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1549     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1548       by simp
  1550       by simp
  1549     hence "(\<exists> (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\<exists> (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)"  by simp
  1551     hence "(\<exists> (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\<exists> (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)"  by simp
  1550     also have "\<dots> = (\<exists> (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: ring_eq_simps)
  1552     also have "\<dots> = (\<exists> (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: ring_simps)
  1551     also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e - j * k = 0)"
  1553     also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e - j * k = 0)"
  1552     using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp
  1554     using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp
  1553   also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e = j * k)" by simp
  1555   also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e = j * k)" by simp
  1554   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be  mult_strict_mono[OF ldcp jp ldcp ] by (simp add: dvd_def)
  1556   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be  mult_strict_mono[OF ldcp jp ldcp ] by (simp add: dvd_def)
  1555 next
  1557 next
  1562       by (simp add: zdiv_self[OF cnz])
  1564       by (simp add: zdiv_self[OF cnz])
  1563     have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
  1565     have "c * (l div c) = c* (l div c) + l mod c" using d' zdvd_iff_zmod_eq_0[where m="c" and n="l"] by simp
  1564     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1566     hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
  1565       by simp
  1567       by simp
  1566     hence "(\<exists> (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\<exists> (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)"  by simp
  1568     hence "(\<exists> (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\<exists> (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)"  by simp
  1567     also have "\<dots> = (\<exists> (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: ring_eq_simps)
  1569     also have "\<dots> = (\<exists> (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: ring_simps)
  1568     also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e - j * k = 0)"
  1570     also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e - j * k = 0)"
  1569     using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp
  1571     using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp
  1570   also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e = j * k)" by simp
  1572   also have "\<dots> = (\<exists> (k::int). c * x + Inum (x # bs) e = j * k)" by simp
  1571   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be  mult_strict_mono[OF ldcp jp ldcp ] by (simp add: dvd_def)
  1573   finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be  mult_strict_mono[OF ldcp jp ldcp ] by (simp add: dvd_def)
  1572 qed (simp_all add: nth_pos2 numbound0_I[where bs="bs" and b="(l * x)" and b'="x"])
  1574 qed (simp_all add: nth_pos2 numbound0_I[where bs="bs" and b="(l * x)" and b'="x"])
  1611       have nob: "\<not> (\<exists> j\<in> {1 ..d}. x =  - ?e + j)" by auto 
  1613       have nob: "\<not> (\<exists> j\<in> {1 ..d}. x =  - ?e + j)" by auto 
  1612       from H p have "x + ?e > 0 \<and> x + ?e \<le> d" by (simp add: c1)
  1614       from H p have "x + ?e > 0 \<and> x + ?e \<le> d" by (simp add: c1)
  1613       hence "x + ?e \<ge> 1 \<and> x + ?e \<le> d"  by simp
  1615       hence "x + ?e \<ge> 1 \<and> x + ?e \<le> d"  by simp
  1614       hence "\<exists> (j::int) \<in> {1 .. d}. j = x + ?e" by simp
  1616       hence "\<exists> (j::int) \<in> {1 .. d}. j = x + ?e" by simp
  1615       hence "\<exists> (j::int) \<in> {1 .. d}. x = (- ?e + j)" 
  1617       hence "\<exists> (j::int) \<in> {1 .. d}. x = (- ?e + j)" 
  1616 	by (simp add: ring_eq_simps)
  1618 	by (simp add: ring_simps)
  1617       with nob have ?case by auto}
  1619       with nob have ?case by auto}
  1618     ultimately show ?case by blast
  1620     ultimately show ?case by blast
  1619 next
  1621 next
  1620   case (8 c e) hence p: "Ifm bbs (x #bs) (Ge (CX c e))" and c1: "c=1" and bn:"numbound0 e" 
  1622   case (8 c e) hence p: "Ifm bbs (x #bs) (Ge (CX c e))" and c1: "c=1" and bn:"numbound0 e" 
  1621     using dvd1_eq1[where x="c"] by simp+
  1623     using dvd1_eq1[where x="c"] by simp+
  1630       from prems(11)[simplified simp_thms Inum.simps \<beta>.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="x" and bs="bs"]] 
  1632       from prems(11)[simplified simp_thms Inum.simps \<beta>.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="x" and bs="bs"]] 
  1631       have nob: "\<not> (\<exists> j\<in> {1 ..d}. x =  - ?e - 1 + j)" by auto 
  1633       have nob: "\<not> (\<exists> j\<in> {1 ..d}. x =  - ?e - 1 + j)" by auto 
  1632       from H p have "x + ?e \<ge> 0 \<and> x + ?e < d" by (simp add: c1)
  1634       from H p have "x + ?e \<ge> 0 \<and> x + ?e < d" by (simp add: c1)
  1633       hence "x + ?e +1 \<ge> 1 \<and> x + ?e + 1 \<le> d"  by simp
  1635       hence "x + ?e +1 \<ge> 1 \<and> x + ?e + 1 \<le> d"  by simp
  1634       hence "\<exists> (j::int) \<in> {1 .. d}. j = x + ?e + 1" by simp
  1636       hence "\<exists> (j::int) \<in> {1 .. d}. j = x + ?e + 1" by simp
  1635       hence "\<exists> (j::int) \<in> {1 .. d}. x= - ?e - 1 + j" by (simp add: ring_eq_simps)
  1637       hence "\<exists> (j::int) \<in> {1 .. d}. x= - ?e - 1 + j" by (simp add: ring_simps)
  1636       with nob have ?case by simp }
  1638       with nob have ?case by simp }
  1637     ultimately show ?case by blast
  1639     ultimately show ?case by blast
  1638 next
  1640 next
  1639   case (3 c e) hence p: "Ifm bbs (x #bs) (Eq (CX c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
  1641   case (3 c e) hence p: "Ifm bbs (x #bs) (Eq (CX c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
  1640     let ?e = "Inum (x # bs) e"
  1642     let ?e = "Inum (x # bs) e"
  1641     let ?v="(Sub (C -1) e)"
  1643     let ?v="(Sub (C -1) e)"
  1642     have vb: "?v \<in> set (\<beta> (Eq (CX c e)))" by simp
  1644     have vb: "?v \<in> set (\<beta> (Eq (CX c e)))" by simp
  1643     from p have "x= - ?e" by (simp add: c1) with prems(11) show ?case using dp
  1645     from p have "x= - ?e" by (simp add: c1) with prems(11) show ?case using dp
  1644       by simp (erule ballE[where x="1"],
  1646       by simp (erule ballE[where x="1"],
  1645 	simp_all add:ring_eq_simps numbound0_I[OF bn,where b="x"and b'="a"and bs="bs"])
  1647 	simp_all add:ring_simps numbound0_I[OF bn,where b="x"and b'="a"and bs="bs"])
  1646 next
  1648 next
  1647   case (4 c e)hence p: "Ifm bbs (x #bs) (NEq (CX c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
  1649   case (4 c e)hence p: "Ifm bbs (x #bs) (NEq (CX c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
  1648     let ?e = "Inum (x # bs) e"
  1650     let ?e = "Inum (x # bs) e"
  1649     let ?v="Neg e"
  1651     let ?v="Neg e"
  1650     have vb: "?v \<in> set (\<beta> (NEq (CX c e)))" by simp
  1652     have vb: "?v \<in> set (\<beta> (NEq (CX c e)))" by simp